@portabletext/editor 1.48.7 → 1.48.9
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 +20 -8
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +5 -5
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +99 -68
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +7 -4
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +41 -45
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +29 -23
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +15 -15
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +258 -38
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +21 -10
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +5 -6
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +75 -45
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +7 -4
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +43 -47
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +30 -26
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +15 -16
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +258 -38
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +5 -5
- package/lib/behaviors/index.d.ts +5 -5
- package/lib/index.cjs +45 -21
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +44 -21
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.js +16 -7
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +3 -3
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +2 -6
- package/lib/selectors/index.d.ts +2 -6
- package/lib/selectors/index.js +5 -5
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +30 -24
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +37 -31
- package/lib/utils/index.d.ts +37 -31
- package/lib/utils/index.js +30 -24
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behavior-actions/behavior.action.block.unset.ts +1 -1
- package/src/behavior-actions/behavior.action.decorator.add.ts +20 -5
- package/src/behaviors/behavior.abstract.decorator.ts +1 -1
- package/src/behaviors/behavior.abstract.delete.ts +1 -1
- package/src/behaviors/behavior.abstract.insert.ts +2 -2
- package/src/behaviors/behavior.abstract.select.ts +16 -4
- package/src/behaviors/behavior.abstract.split.ts +9 -6
- package/src/behaviors/behavior.core.block-objects.ts +5 -5
- package/src/behaviors/behavior.core.insert-break.ts +16 -4
- package/src/behaviors/behavior.core.lists.ts +4 -6
- package/src/behaviors/behavior.decorator-pair.ts +13 -4
- package/src/behaviors/behavior.default.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +5 -5
- package/src/converters/converter.portable-text.ts +1 -1
- package/src/converters/converter.text-html.ts +1 -1
- package/src/converters/converter.text-plain.ts +4 -4
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +10 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +12 -19
- package/src/internal-utils/__tests__/dmpToOperations.test.ts +13 -12
- package/src/internal-utils/drag-selection.ts +16 -4
- package/src/internal-utils/event-position.ts +20 -8
- package/src/internal-utils/parse-blocks.ts +17 -5
- package/src/internal-utils/validateValue.ts +6 -6
- package/src/plugins/plugin.decorator-shortcut.ts +2 -2
- package/src/selectors/selector.get-active-annotations.ts +5 -2
- package/src/selectors/selector.get-active-list-item.ts +4 -3
- package/src/selectors/selector.get-active-style.ts +4 -3
- package/src/selectors/selector.get-anchor-text-block.ts +3 -6
- package/src/selectors/selector.get-block-offsets.ts +2 -2
- package/src/selectors/selector.get-caret-word-selection.ts +11 -5
- package/src/selectors/selector.get-selected-slice.ts +1 -1
- package/src/selectors/selector.get-selected-spans.ts +11 -15
- package/src/selectors/selector.get-selected-text-blocks.ts +3 -3
- package/src/selectors/selector.get-selection-text.ts +3 -3
- package/src/selectors/selector.get-text-before.ts +5 -2
- package/src/selectors/selector.get-trimmed-selection.ts +20 -14
- package/src/selectors/selector.is-active-annotation.ts +4 -2
- package/src/selectors/selector.is-active-decorator.test.ts +3 -3
- package/src/selectors/selector.is-at-the-end-of-block.ts +4 -1
- package/src/selectors/selector.is-at-the-start-of-block.ts +4 -1
- package/src/selectors/selector.is-point-after-selection.ts +7 -6
- package/src/selectors/selector.is-point-before-selection.ts +7 -6
- package/src/selectors/selector.is-selecting-entire-blocks.ts +8 -2
- package/src/selectors/selectors.ts +25 -28
- package/src/utils/util.block-offset-to-block-selection-point.ts +4 -4
- package/src/utils/util.block-offset-to-selection-point.ts +5 -5
- package/src/utils/util.block-offset.test.ts +219 -156
- package/src/utils/util.block-offset.ts +14 -17
- package/src/utils/util.block-offsets-to-selection.ts +5 -5
- package/src/utils/util.child-selection-point-to-block-offset.ts +7 -10
- package/src/utils/util.get-block-end-point.ts +15 -15
- package/src/utils/util.get-block-start-point.ts +13 -12
- package/src/utils/util.is-empty-text-block.ts +9 -8
- package/src/utils/util.selection-point-to-block-offset.ts +4 -4
- package/src/utils/util.slice-blocks.test.ts +178 -121
- package/src/utils/util.slice-blocks.ts +25 -24
- package/src/utils/util.split-text-block.ts +18 -12
- package/lib/_chunks-cjs/parse-blocks.cjs +0 -205
- package/lib/_chunks-cjs/parse-blocks.cjs.map +0 -1
- package/lib/_chunks-es/parse-blocks.js +0 -206
- package/lib/_chunks-es/parse-blocks.js.map +0 -1
- package/src/behavior-actions/behavior.guards.ts +0 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","key","context","selection","isKeyedSegment","anchor","path","_key","undefined","node","value","find","block","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue"],"mappings":";;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,iBAAAA,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMC,CAAAA,UAAUA,MAAML,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GCbaK,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,iBAAAA,YAAYf,SAASE,SAASY,YAAYL,IAAI,IAChE;AAAA,IAACA,MAAMK,YAAYL;AAAAA,IAAMH,MAAMQ,YAAYR;AAAAA,EAAAA,IAC3CE;AACN,GCPaQ,iBAMRhB,CAAa,aAAA;AACVc,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMb,MAAMD,SAASE,QAAQC,aACzBC,iBAAAA,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTa,YAAYL,KAAKQ,SAASN,KAAMO,CAAAA,SAASA,KAAKX,SAASN,GAAG,IAC1DO;AAEJ,SAAOC,QAAQR,MACX;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC,GAAGQ,YAAYR,MAAM,YAAY;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAC1DO;AACN,GC3BaW,gBAGRnB,CAAa,aAAA;AACVoB,QAAAA,cAAcJ,eAAehB,QAAQ;AAE3C,SAAOoB,eAAeC,MAAAA,mBAAmBD,YAAYX,IAAI,IACrD;AAAA,IAACA,MAAMW,YAAYX;AAAAA,IAAMH,MAAMc,YAAYd;AAAAA,EAAAA,IAC3CE;AACN,GCRac,kBAERtB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASE,QAAQC;AACpB;AAGF,QAAMoB,sBAAsBC,gCAAAA,uBAAuBxB,QAAQ,GACrDyB,oBAAoBC,qDAAqB1B,QAAQ;AAEnD,MAAA,CAACuB,uBAAuB,CAACE;AAC3B;AAGIE,QAAAA,QAAQC,iBAAAA,gCAAsC;AAAA,IAClD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBN;AAAAA,EAAAA,CACjB,GACKO,MAAMF,iDAAsC;AAAA,IAChD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBJ;AAAAA,EAAAA,CACjB;AAED,SAAOE,SAASG,MAAM;AAAA,IAACH;AAAAA,IAAOG;AAAAA,EAAAA,IAAOtB;AACvC,GC3BauB,eAAiD/B,CACrDA,aAAAA,SAASE,QAAQC,WCDb6B,WACXhC,CAEOA,aAAAA,SAASE,QAAQQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -6,16 +6,12 @@ import type {
|
|
|
6
6
|
BlockStyleDefinition,
|
|
7
7
|
ObjectSchemaType,
|
|
8
8
|
Path,
|
|
9
|
-
PortableTextChild,
|
|
10
|
-
} from '@sanity/types'
|
|
11
|
-
import {
|
|
12
|
-
KeyedSegment,
|
|
13
9
|
PortableTextBlock,
|
|
10
|
+
PortableTextChild,
|
|
14
11
|
PortableTextListBlock,
|
|
15
|
-
PortableTextObject,
|
|
16
|
-
PortableTextSpan,
|
|
17
12
|
PortableTextTextBlock,
|
|
18
13
|
} from '@sanity/types'
|
|
14
|
+
import {KeyedSegment, PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
19
15
|
import type {
|
|
20
16
|
FocusEvent as FocusEvent_2,
|
|
21
17
|
KeyboardEvent as KeyboardEvent_2,
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -6,16 +6,12 @@ import type {
|
|
|
6
6
|
BlockStyleDefinition,
|
|
7
7
|
ObjectSchemaType,
|
|
8
8
|
Path,
|
|
9
|
-
PortableTextChild,
|
|
10
|
-
} from '@sanity/types'
|
|
11
|
-
import {
|
|
12
|
-
KeyedSegment,
|
|
13
9
|
PortableTextBlock,
|
|
10
|
+
PortableTextChild,
|
|
14
11
|
PortableTextListBlock,
|
|
15
|
-
PortableTextObject,
|
|
16
|
-
PortableTextSpan,
|
|
17
12
|
PortableTextTextBlock,
|
|
18
13
|
} from '@sanity/types'
|
|
14
|
+
import {KeyedSegment, PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
19
15
|
import type {
|
|
20
16
|
FocusEvent as FocusEvent_2,
|
|
21
17
|
KeyboardEvent as KeyboardEvent_2,
|
package/lib/selectors/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getActiveAnnotations, getActiveListItem, getActiveStyle, getSelectedSpans, getSelectedTextBlocks, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
2
|
-
import { isKeyedSegment, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
|
|
3
|
-
import {
|
|
2
|
+
import { isKeyedSegment, isTextBlock, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
|
|
3
|
+
import { isPortableTextSpan } from "@sanity/types";
|
|
4
4
|
import { getSelectionStartPoint, getSelectionEndPoint } from "../_chunks-es/selector.is-overlapping-selection.js";
|
|
5
5
|
import { getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-overlapping-selection.js";
|
|
6
6
|
import { getFocusInlineObject } from "../_chunks-es/selector.get-focus-inline-object.js";
|
|
@@ -15,7 +15,7 @@ const getAnchorBlock = (snapshot) => {
|
|
|
15
15
|
} : void 0;
|
|
16
16
|
}, getAnchorTextBlock = (snapshot) => {
|
|
17
17
|
const anchorBlock = getAnchorBlock(snapshot);
|
|
18
|
-
return anchorBlock &&
|
|
18
|
+
return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node) ? {
|
|
19
19
|
node: anchorBlock.node,
|
|
20
20
|
path: anchorBlock.path
|
|
21
21
|
} : void 0;
|
|
@@ -43,10 +43,10 @@ const getAnchorBlock = (snapshot) => {
|
|
|
43
43
|
if (!selectionStartPoint || !selectionEndPoint)
|
|
44
44
|
return;
|
|
45
45
|
const start = spanSelectionPointToBlockOffset({
|
|
46
|
-
|
|
46
|
+
context: snapshot.context,
|
|
47
47
|
selectionPoint: selectionStartPoint
|
|
48
48
|
}), end = spanSelectionPointToBlockOffset({
|
|
49
|
-
|
|
49
|
+
context: snapshot.context,
|
|
50
50
|
selectionPoint: selectionEndPoint
|
|
51
51
|
});
|
|
52
52
|
return start && end ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","key","context","selection","isKeyedSegment","anchor","path","_key","undefined","node","value","find","block","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue"],"mappings":";;;;;;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMC,CAAAA,UAAUA,MAAML,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GCbaK,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,YAAYf,SAASE,SAASY,YAAYL,IAAI,IAChE;AAAA,IAACA,MAAMK,YAAYL;AAAAA,IAAMH,MAAMQ,YAAYR;AAAAA,EAAAA,IAC3CE;AACN,GCPaQ,iBAMRhB,CAAa,aAAA;AACVc,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMb,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTa,YAAYL,KAAKQ,SAASN,KAAMO,CAAAA,SAASA,KAAKX,SAASN,GAAG,IAC1DO;AAEJ,SAAOC,QAAQR,MACX;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC,GAAGQ,YAAYR,MAAM,YAAY;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAC1DO;AACN,GC3BaW,gBAGRnB,CAAa,aAAA;AACVoB,QAAAA,cAAcJ,eAAehB,QAAQ;AAE3C,SAAOoB,eAAeC,mBAAmBD,YAAYX,IAAI,IACrD;AAAA,IAACA,MAAMW,YAAYX;AAAAA,IAAMH,MAAMc,YAAYd;AAAAA,EAAAA,IAC3CE;AACN,GCRac,kBAERtB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASE,QAAQC;AACpB;AAGF,QAAMoB,sBAAsBC,uBAAuBxB,QAAQ,GACrDyB,oBAAoBC,qBAAqB1B,QAAQ;AAEnD,MAAA,CAACuB,uBAAuB,CAACE;AAC3B;AAGIE,QAAAA,QAAQC,gCAAsC;AAAA,IAClD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBN;AAAAA,EAAAA,CACjB,GACKO,MAAMF,gCAAsC;AAAA,IAChD1B,SAASF,SAASE;AAAAA,IAClB2B,gBAAgBJ;AAAAA,EAAAA,CACjB;AAED,SAAOE,SAASG,MAAM;AAAA,IAACH;AAAAA,IAAOG;AAAAA,EAAAA,IAAOtB;AACvC,GC3BauB,eAAiD/B,CACrDA,aAAAA,SAASE,QAAQC,WCDb6B,WACXhC,CAEOA,aAAAA,SAASE,QAAQQ;"}
|
package/lib/utils/index.cjs
CHANGED
|
@@ -13,31 +13,37 @@ function splitTextBlock({
|
|
|
13
13
|
if (!firstChild || !lastChild)
|
|
14
14
|
return;
|
|
15
15
|
const before = util_sliceBlocks.sliceBlocks({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
context: {
|
|
17
|
+
schema: context.schema,
|
|
18
|
+
selection: {
|
|
19
|
+
anchor: {
|
|
20
|
+
path: [{
|
|
21
|
+
_key: block._key
|
|
22
|
+
}, "children", {
|
|
23
|
+
_key: firstChild._key
|
|
24
|
+
}],
|
|
25
|
+
offset: 0
|
|
26
|
+
},
|
|
27
|
+
focus: point
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
blocks: [block]
|
|
28
31
|
}).at(0), after = util_sliceBlocks.sliceBlocks({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
context: {
|
|
33
|
+
schema: context.schema,
|
|
34
|
+
selection: {
|
|
35
|
+
anchor: point,
|
|
36
|
+
focus: {
|
|
37
|
+
path: [{
|
|
38
|
+
_key: block._key
|
|
39
|
+
}, "children", {
|
|
40
|
+
_key: lastChild._key
|
|
41
|
+
}],
|
|
42
|
+
offset: util_sliceBlocks.isSpan$1(context, lastChild) ? lastChild.text.length : 0
|
|
43
|
+
}
|
|
39
44
|
}
|
|
40
|
-
}
|
|
45
|
+
},
|
|
46
|
+
blocks: [block]
|
|
41
47
|
}).at(0);
|
|
42
48
|
if (!(!before || !after) && !(!util_mergeTextBlocks.isTextBlock(context, before) || !util_mergeTextBlocks.isTextBlock(context, after)))
|
|
43
49
|
return {
|
|
@@ -52,7 +58,7 @@ exports.getTextBlockText = util_sliceBlocks.getTextBlockText;
|
|
|
52
58
|
exports.isEmptyTextBlock = util_sliceBlocks.isEmptyTextBlock;
|
|
53
59
|
exports.isEqualSelectionPoints = util_sliceBlocks.isEqualSelectionPoints;
|
|
54
60
|
exports.isKeyedSegment = util_sliceBlocks.isKeyedSegment;
|
|
55
|
-
exports.isSpan = util_sliceBlocks.isSpan;
|
|
61
|
+
exports.isSpan = util_sliceBlocks.isSpan$1;
|
|
56
62
|
exports.reverseSelection = util_sliceBlocks.reverseSelection;
|
|
57
63
|
exports.sliceBlocks = util_sliceBlocks.sliceBlocks;
|
|
58
64
|
exports.spanSelectionPointToBlockOffset = util_sliceBlocks.spanSelectionPointToBlockOffset;
|
package/lib/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n blocks: [block],\n }).at(0)\n const after = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n blocks: [block],\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","schema","selection","path","_key","offset","blocks","after","isSpan","text","isTextBlock"],"mappings":";;;AAMgBA,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,iBAAAA,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,wCAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACTO,SAASC,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAEzD,MAAA,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,iBAAAA,YAAY;AAAA,IACzBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBC,WAAW;AAAA,QACTd,QAAQ;AAAA,UACNe,MAAM,CAAC;AAAA,YAACC,MAAMZ,MAAMY;AAAAA,aAAO,YAAY;AAAA,YAACA,MAAMV,WAAWU;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QACV;AAAA,QACAhB,OAAOI;AAAAA,MAAAA;AAAAA,IAEX;AAAA,IACAa,QAAQ,CAACd,KAAK;AAAA,EACf,CAAA,EAAEI,GAAG,CAAC,GACDW,QAAQP,iBAAAA,YAAY;AAAA,IACxBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBC,WAAW;AAAA,QACTd,QAAQK;AAAAA,QACRJ,OAAO;AAAA,UACLc,MAAM,CAAC;AAAA,YAACC,MAAMZ,MAAMY;AAAAA,aAAO,YAAY;AAAA,YAACA,MAAMP,UAAUO;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQG,iBAAOjB,SAAAA,SAASM,SAAS,IAAIA,UAAUY,KAAKX,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IAEJ;AAAA,IACAQ,QAAQ,CAACd,KAAK;AAAA,EAAA,CACf,EAAEI,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACQ,UAIZ,EAACG,CAAAA,qBAAAA,YAAYnB,SAASQ,MAAM,KAAK,CAACW,qBAAYnB,YAAAA,SAASgB,KAAK;AAIzD,WAAA;AAAA,MAACR;AAAAA,MAAQQ;AAAAA,IAAK;AACvB;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/utils/index.d.cts
CHANGED
|
@@ -4,18 +4,15 @@ import type {
|
|
|
4
4
|
BlockDecoratorDefinition,
|
|
5
5
|
BlockListDefinition,
|
|
6
6
|
BlockStyleDefinition,
|
|
7
|
+
KeyedSegment,
|
|
7
8
|
ObjectSchemaType,
|
|
8
9
|
Path,
|
|
10
|
+
PortableTextBlock,
|
|
9
11
|
PortableTextChild,
|
|
10
12
|
PortableTextListBlock,
|
|
11
13
|
PortableTextTextBlock,
|
|
12
14
|
} from '@sanity/types'
|
|
13
|
-
import {
|
|
14
|
-
KeyedSegment,
|
|
15
|
-
PortableTextBlock,
|
|
16
|
-
PortableTextObject,
|
|
17
|
-
PortableTextSpan,
|
|
18
|
-
} from '@sanity/types'
|
|
15
|
+
import {PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
19
16
|
import type {
|
|
20
17
|
FocusEvent as FocusEvent_2,
|
|
21
18
|
KeyboardEvent as KeyboardEvent_2,
|
|
@@ -321,11 +318,11 @@ declare type BlockOffset = {
|
|
|
321
318
|
* @public
|
|
322
319
|
*/
|
|
323
320
|
export declare function blockOffsetsToSelection({
|
|
324
|
-
|
|
321
|
+
context,
|
|
325
322
|
offsets,
|
|
326
323
|
backward,
|
|
327
324
|
}: {
|
|
328
|
-
|
|
325
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
329
326
|
offsets: {
|
|
330
327
|
anchor: BlockOffset
|
|
331
328
|
focus: BlockOffset
|
|
@@ -337,10 +334,10 @@ export declare function blockOffsetsToSelection({
|
|
|
337
334
|
* @public
|
|
338
335
|
*/
|
|
339
336
|
export declare function blockOffsetToBlockSelectionPoint({
|
|
340
|
-
|
|
337
|
+
context,
|
|
341
338
|
blockOffset,
|
|
342
339
|
}: {
|
|
343
|
-
|
|
340
|
+
context: Pick<EditorContext, 'value'>
|
|
344
341
|
blockOffset: BlockOffset
|
|
345
342
|
}): EditorSelectionPoint | undefined
|
|
346
343
|
|
|
@@ -348,11 +345,11 @@ export declare function blockOffsetToBlockSelectionPoint({
|
|
|
348
345
|
* @public
|
|
349
346
|
*/
|
|
350
347
|
export declare function blockOffsetToSelectionPoint({
|
|
351
|
-
|
|
348
|
+
context,
|
|
352
349
|
blockOffset,
|
|
353
350
|
direction,
|
|
354
351
|
}: {
|
|
355
|
-
|
|
352
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
356
353
|
blockOffset: BlockOffset
|
|
357
354
|
direction: 'forward' | 'backward'
|
|
358
355
|
}): EditorSelectionPoint | undefined
|
|
@@ -361,11 +358,11 @@ export declare function blockOffsetToSelectionPoint({
|
|
|
361
358
|
* @public
|
|
362
359
|
*/
|
|
363
360
|
export declare function blockOffsetToSpanSelectionPoint({
|
|
364
|
-
|
|
361
|
+
context,
|
|
365
362
|
blockOffset,
|
|
366
363
|
direction,
|
|
367
364
|
}: {
|
|
368
|
-
|
|
365
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
369
366
|
blockOffset: BlockOffset
|
|
370
367
|
direction: 'forward' | 'backward'
|
|
371
368
|
}):
|
|
@@ -383,10 +380,10 @@ declare type BlockWithOptionalKey =
|
|
|
383
380
|
* @public
|
|
384
381
|
*/
|
|
385
382
|
export declare function childSelectionPointToBlockOffset({
|
|
386
|
-
|
|
383
|
+
context,
|
|
387
384
|
selectionPoint,
|
|
388
385
|
}: {
|
|
389
|
-
|
|
386
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
390
387
|
selectionPoint: EditorSelectionPoint
|
|
391
388
|
}): BlockOffset | undefined
|
|
392
389
|
|
|
@@ -5214,22 +5211,28 @@ declare type ExtractNamespace<TType extends string> =
|
|
|
5214
5211
|
* @public
|
|
5215
5212
|
*/
|
|
5216
5213
|
export declare function getBlockEndPoint({
|
|
5217
|
-
|
|
5218
|
-
|
|
5214
|
+
context,
|
|
5215
|
+
block,
|
|
5219
5216
|
}: {
|
|
5220
|
-
|
|
5221
|
-
|
|
5217
|
+
context: Pick<EditorContext, 'schema'>
|
|
5218
|
+
block: {
|
|
5219
|
+
node: PortableTextBlock
|
|
5220
|
+
path: [KeyedSegment]
|
|
5221
|
+
}
|
|
5222
5222
|
}): EditorSelectionPoint
|
|
5223
5223
|
|
|
5224
5224
|
/**
|
|
5225
5225
|
* @public
|
|
5226
5226
|
*/
|
|
5227
5227
|
export declare function getBlockStartPoint({
|
|
5228
|
-
|
|
5229
|
-
|
|
5228
|
+
context,
|
|
5229
|
+
block,
|
|
5230
5230
|
}: {
|
|
5231
|
-
|
|
5232
|
-
|
|
5231
|
+
context: Pick<EditorContext, 'schema'>
|
|
5232
|
+
block: {
|
|
5233
|
+
node: PortableTextBlock
|
|
5234
|
+
path: [KeyedSegment]
|
|
5235
|
+
}
|
|
5233
5236
|
}): EditorSelectionPoint
|
|
5234
5237
|
|
|
5235
5238
|
/**
|
|
@@ -5322,7 +5325,10 @@ declare type InvalidValueResolution = {
|
|
|
5322
5325
|
/**
|
|
5323
5326
|
* @public
|
|
5324
5327
|
*/
|
|
5325
|
-
export declare function isEmptyTextBlock(
|
|
5328
|
+
export declare function isEmptyTextBlock(
|
|
5329
|
+
context: Pick<EditorContext, 'schema'>,
|
|
5330
|
+
block: PortableTextBlock,
|
|
5331
|
+
): boolean
|
|
5326
5332
|
|
|
5327
5333
|
/**
|
|
5328
5334
|
* @public
|
|
@@ -5584,10 +5590,10 @@ export declare function reverseSelection<
|
|
|
5584
5590
|
* @public
|
|
5585
5591
|
*/
|
|
5586
5592
|
export declare function selectionPointToBlockOffset({
|
|
5587
|
-
|
|
5593
|
+
context,
|
|
5588
5594
|
selectionPoint,
|
|
5589
5595
|
}: {
|
|
5590
|
-
|
|
5596
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
5591
5597
|
selectionPoint: EditorSelectionPoint
|
|
5592
5598
|
}): BlockOffset | undefined
|
|
5593
5599
|
|
|
@@ -5607,21 +5613,21 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
|
5607
5613
|
* @public
|
|
5608
5614
|
*/
|
|
5609
5615
|
export declare function sliceBlocks({
|
|
5616
|
+
context,
|
|
5610
5617
|
blocks,
|
|
5611
|
-
selection,
|
|
5612
5618
|
}: {
|
|
5619
|
+
context: Pick<EditorContext, 'schema' | 'selection'>
|
|
5613
5620
|
blocks: Array<PortableTextBlock>
|
|
5614
|
-
selection: EditorSelection
|
|
5615
5621
|
}): Array<PortableTextBlock>
|
|
5616
5622
|
|
|
5617
5623
|
/**
|
|
5618
5624
|
* @public
|
|
5619
5625
|
*/
|
|
5620
5626
|
export declare function spanSelectionPointToBlockOffset({
|
|
5621
|
-
|
|
5627
|
+
context,
|
|
5622
5628
|
selectionPoint,
|
|
5623
5629
|
}: {
|
|
5624
|
-
|
|
5630
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
5625
5631
|
selectionPoint: EditorSelectionPoint
|
|
5626
5632
|
}): BlockOffset | undefined
|
|
5627
5633
|
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -4,18 +4,15 @@ import type {
|
|
|
4
4
|
BlockDecoratorDefinition,
|
|
5
5
|
BlockListDefinition,
|
|
6
6
|
BlockStyleDefinition,
|
|
7
|
+
KeyedSegment,
|
|
7
8
|
ObjectSchemaType,
|
|
8
9
|
Path,
|
|
10
|
+
PortableTextBlock,
|
|
9
11
|
PortableTextChild,
|
|
10
12
|
PortableTextListBlock,
|
|
11
13
|
PortableTextTextBlock,
|
|
12
14
|
} from '@sanity/types'
|
|
13
|
-
import {
|
|
14
|
-
KeyedSegment,
|
|
15
|
-
PortableTextBlock,
|
|
16
|
-
PortableTextObject,
|
|
17
|
-
PortableTextSpan,
|
|
18
|
-
} from '@sanity/types'
|
|
15
|
+
import {PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
19
16
|
import type {
|
|
20
17
|
FocusEvent as FocusEvent_2,
|
|
21
18
|
KeyboardEvent as KeyboardEvent_2,
|
|
@@ -321,11 +318,11 @@ declare type BlockOffset = {
|
|
|
321
318
|
* @public
|
|
322
319
|
*/
|
|
323
320
|
export declare function blockOffsetsToSelection({
|
|
324
|
-
|
|
321
|
+
context,
|
|
325
322
|
offsets,
|
|
326
323
|
backward,
|
|
327
324
|
}: {
|
|
328
|
-
|
|
325
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
329
326
|
offsets: {
|
|
330
327
|
anchor: BlockOffset
|
|
331
328
|
focus: BlockOffset
|
|
@@ -337,10 +334,10 @@ export declare function blockOffsetsToSelection({
|
|
|
337
334
|
* @public
|
|
338
335
|
*/
|
|
339
336
|
export declare function blockOffsetToBlockSelectionPoint({
|
|
340
|
-
|
|
337
|
+
context,
|
|
341
338
|
blockOffset,
|
|
342
339
|
}: {
|
|
343
|
-
|
|
340
|
+
context: Pick<EditorContext, 'value'>
|
|
344
341
|
blockOffset: BlockOffset
|
|
345
342
|
}): EditorSelectionPoint | undefined
|
|
346
343
|
|
|
@@ -348,11 +345,11 @@ export declare function blockOffsetToBlockSelectionPoint({
|
|
|
348
345
|
* @public
|
|
349
346
|
*/
|
|
350
347
|
export declare function blockOffsetToSelectionPoint({
|
|
351
|
-
|
|
348
|
+
context,
|
|
352
349
|
blockOffset,
|
|
353
350
|
direction,
|
|
354
351
|
}: {
|
|
355
|
-
|
|
352
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
356
353
|
blockOffset: BlockOffset
|
|
357
354
|
direction: 'forward' | 'backward'
|
|
358
355
|
}): EditorSelectionPoint | undefined
|
|
@@ -361,11 +358,11 @@ export declare function blockOffsetToSelectionPoint({
|
|
|
361
358
|
* @public
|
|
362
359
|
*/
|
|
363
360
|
export declare function blockOffsetToSpanSelectionPoint({
|
|
364
|
-
|
|
361
|
+
context,
|
|
365
362
|
blockOffset,
|
|
366
363
|
direction,
|
|
367
364
|
}: {
|
|
368
|
-
|
|
365
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
369
366
|
blockOffset: BlockOffset
|
|
370
367
|
direction: 'forward' | 'backward'
|
|
371
368
|
}):
|
|
@@ -383,10 +380,10 @@ declare type BlockWithOptionalKey =
|
|
|
383
380
|
* @public
|
|
384
381
|
*/
|
|
385
382
|
export declare function childSelectionPointToBlockOffset({
|
|
386
|
-
|
|
383
|
+
context,
|
|
387
384
|
selectionPoint,
|
|
388
385
|
}: {
|
|
389
|
-
|
|
386
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
390
387
|
selectionPoint: EditorSelectionPoint
|
|
391
388
|
}): BlockOffset | undefined
|
|
392
389
|
|
|
@@ -5214,22 +5211,28 @@ declare type ExtractNamespace<TType extends string> =
|
|
|
5214
5211
|
* @public
|
|
5215
5212
|
*/
|
|
5216
5213
|
export declare function getBlockEndPoint({
|
|
5217
|
-
|
|
5218
|
-
|
|
5214
|
+
context,
|
|
5215
|
+
block,
|
|
5219
5216
|
}: {
|
|
5220
|
-
|
|
5221
|
-
|
|
5217
|
+
context: Pick<EditorContext, 'schema'>
|
|
5218
|
+
block: {
|
|
5219
|
+
node: PortableTextBlock
|
|
5220
|
+
path: [KeyedSegment]
|
|
5221
|
+
}
|
|
5222
5222
|
}): EditorSelectionPoint
|
|
5223
5223
|
|
|
5224
5224
|
/**
|
|
5225
5225
|
* @public
|
|
5226
5226
|
*/
|
|
5227
5227
|
export declare function getBlockStartPoint({
|
|
5228
|
-
|
|
5229
|
-
|
|
5228
|
+
context,
|
|
5229
|
+
block,
|
|
5230
5230
|
}: {
|
|
5231
|
-
|
|
5232
|
-
|
|
5231
|
+
context: Pick<EditorContext, 'schema'>
|
|
5232
|
+
block: {
|
|
5233
|
+
node: PortableTextBlock
|
|
5234
|
+
path: [KeyedSegment]
|
|
5235
|
+
}
|
|
5233
5236
|
}): EditorSelectionPoint
|
|
5234
5237
|
|
|
5235
5238
|
/**
|
|
@@ -5322,7 +5325,10 @@ declare type InvalidValueResolution = {
|
|
|
5322
5325
|
/**
|
|
5323
5326
|
* @public
|
|
5324
5327
|
*/
|
|
5325
|
-
export declare function isEmptyTextBlock(
|
|
5328
|
+
export declare function isEmptyTextBlock(
|
|
5329
|
+
context: Pick<EditorContext, 'schema'>,
|
|
5330
|
+
block: PortableTextBlock,
|
|
5331
|
+
): boolean
|
|
5326
5332
|
|
|
5327
5333
|
/**
|
|
5328
5334
|
* @public
|
|
@@ -5584,10 +5590,10 @@ export declare function reverseSelection<
|
|
|
5584
5590
|
* @public
|
|
5585
5591
|
*/
|
|
5586
5592
|
export declare function selectionPointToBlockOffset({
|
|
5587
|
-
|
|
5593
|
+
context,
|
|
5588
5594
|
selectionPoint,
|
|
5589
5595
|
}: {
|
|
5590
|
-
|
|
5596
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
5591
5597
|
selectionPoint: EditorSelectionPoint
|
|
5592
5598
|
}): BlockOffset | undefined
|
|
5593
5599
|
|
|
@@ -5607,21 +5613,21 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
|
5607
5613
|
* @public
|
|
5608
5614
|
*/
|
|
5609
5615
|
export declare function sliceBlocks({
|
|
5616
|
+
context,
|
|
5610
5617
|
blocks,
|
|
5611
|
-
selection,
|
|
5612
5618
|
}: {
|
|
5619
|
+
context: Pick<EditorContext, 'schema' | 'selection'>
|
|
5613
5620
|
blocks: Array<PortableTextBlock>
|
|
5614
|
-
selection: EditorSelection
|
|
5615
5621
|
}): Array<PortableTextBlock>
|
|
5616
5622
|
|
|
5617
5623
|
/**
|
|
5618
5624
|
* @public
|
|
5619
5625
|
*/
|
|
5620
5626
|
export declare function spanSelectionPointToBlockOffset({
|
|
5621
|
-
|
|
5627
|
+
context,
|
|
5622
5628
|
selectionPoint,
|
|
5623
5629
|
}: {
|
|
5624
|
-
|
|
5630
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
5625
5631
|
selectionPoint: EditorSelectionPoint
|
|
5626
5632
|
}): BlockOffset | undefined
|
|
5627
5633
|
|