@portabletext/editor 1.49.13 → 1.50.1
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/behaviors/index.d.cts +3 -0
- package/lib/behaviors/index.d.ts +3 -0
- package/lib/index.cjs +17 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +10 -1
- package/lib/index.d.ts +10 -1
- package/lib/index.js +17 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -0
- package/lib/plugins/index.d.ts +3 -0
- package/lib/selectors/index.cjs +95 -1
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +28 -0
- package/lib/selectors/index.d.ts +28 -0
- package/lib/selectors/index.js +97 -3
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.cts +3 -0
- package/lib/utils/index.d.ts +3 -0
- package/package.json +5 -5
- package/src/editor/__tests__/PortableTextEditor.test.tsx +1 -0
- package/src/editor/components/render-text-block.tsx +15 -0
- package/src/editor/editor-machine.ts +3 -0
- package/src/operations/behavior.operation.insert.block.ts +20 -0
- package/src/selectors/index.ts +1 -0
- package/src/selectors/selector.get-list-state.test.ts +202 -0
- package/src/selectors/selector.get-list-state.ts +175 -0
- package/src/types/editor.ts +2 -1
- package/src/types/paths.ts +1 -0
package/lib/plugins/index.d.cts
CHANGED
|
@@ -2901,6 +2901,9 @@ export declare function OneLinePlugin(): JSX.Element
|
|
|
2901
2901
|
declare type PatchesEvent = {
|
|
2902
2902
|
type: 'patches'
|
|
2903
2903
|
patches: Array<Patch>
|
|
2904
|
+
/**
|
|
2905
|
+
* @deprecated Unused by the editor
|
|
2906
|
+
*/
|
|
2904
2907
|
snapshot: Array<PortableTextBlock> | undefined
|
|
2905
2908
|
}
|
|
2906
2909
|
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -2901,6 +2901,9 @@ export declare function OneLinePlugin(): JSX.Element
|
|
|
2901
2901
|
declare type PatchesEvent = {
|
|
2902
2902
|
type: 'patches'
|
|
2903
2903
|
patches: Array<Patch>
|
|
2904
|
+
/**
|
|
2905
|
+
* @deprecated Unused by the editor
|
|
2906
|
+
*/
|
|
2904
2907
|
snapshot: Array<PortableTextBlock> | undefined
|
|
2905
2908
|
}
|
|
2906
2909
|
|
package/lib/selectors/index.cjs
CHANGED
|
@@ -49,7 +49,100 @@ const getAnchorBlock = (snapshot) => {
|
|
|
49
49
|
start,
|
|
50
50
|
end
|
|
51
51
|
} : void 0;
|
|
52
|
-
}
|
|
52
|
+
};
|
|
53
|
+
function getListState({
|
|
54
|
+
path
|
|
55
|
+
}) {
|
|
56
|
+
return (snapshot) => {
|
|
57
|
+
const selection = {
|
|
58
|
+
anchor: {
|
|
59
|
+
path,
|
|
60
|
+
offset: 0
|
|
61
|
+
},
|
|
62
|
+
focus: {
|
|
63
|
+
path,
|
|
64
|
+
offset: 0
|
|
65
|
+
}
|
|
66
|
+
}, focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
|
|
67
|
+
context: {
|
|
68
|
+
...snapshot.context,
|
|
69
|
+
selection
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
if (!focusTextBlock || focusTextBlock.node.listItem === void 0 || focusTextBlock.node.level === void 0)
|
|
73
|
+
return;
|
|
74
|
+
const previousListItem = getPreviousListItem({
|
|
75
|
+
listItem: focusTextBlock.node.listItem,
|
|
76
|
+
level: focusTextBlock.node.level
|
|
77
|
+
})({
|
|
78
|
+
...snapshot,
|
|
79
|
+
context: {
|
|
80
|
+
...snapshot.context,
|
|
81
|
+
selection
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
if (!previousListItem)
|
|
85
|
+
return {
|
|
86
|
+
index: 1
|
|
87
|
+
};
|
|
88
|
+
if (previousListItem.node.listItem !== focusTextBlock.node.listItem)
|
|
89
|
+
return {
|
|
90
|
+
index: 1
|
|
91
|
+
};
|
|
92
|
+
if (previousListItem.node.level !== void 0 && previousListItem.node.level < focusTextBlock.node.level)
|
|
93
|
+
return {
|
|
94
|
+
index: 1
|
|
95
|
+
};
|
|
96
|
+
const previousListItemListState = getListState({
|
|
97
|
+
path: previousListItem.path
|
|
98
|
+
})(snapshot);
|
|
99
|
+
return previousListItemListState === void 0 ? {
|
|
100
|
+
index: 1
|
|
101
|
+
} : {
|
|
102
|
+
index: previousListItemListState.index + 1
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function getPreviousListItem({
|
|
107
|
+
listItem,
|
|
108
|
+
level
|
|
109
|
+
}) {
|
|
110
|
+
return (snapshot) => {
|
|
111
|
+
const previousBlock = selector_isSelectionExpanded.getPreviousBlock({
|
|
112
|
+
context: {
|
|
113
|
+
...snapshot.context
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
if (previousBlock && util_sliceBlocks.isTextBlock(snapshot.context, previousBlock.node) && !(previousBlock.node.listItem === void 0 || previousBlock.node.level === void 0) && previousBlock.node.listItem === listItem) {
|
|
117
|
+
if (previousBlock.node.level === level)
|
|
118
|
+
return {
|
|
119
|
+
node: previousBlock.node,
|
|
120
|
+
path: previousBlock.path
|
|
121
|
+
};
|
|
122
|
+
if (!(previousBlock.node.level < level))
|
|
123
|
+
return getPreviousListItem({
|
|
124
|
+
listItem,
|
|
125
|
+
level
|
|
126
|
+
})({
|
|
127
|
+
...snapshot,
|
|
128
|
+
context: {
|
|
129
|
+
...snapshot.context,
|
|
130
|
+
selection: {
|
|
131
|
+
anchor: {
|
|
132
|
+
path: previousBlock.path,
|
|
133
|
+
offset: 0
|
|
134
|
+
},
|
|
135
|
+
focus: {
|
|
136
|
+
path: previousBlock.path,
|
|
137
|
+
offset: 0
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const getSelection = (snapshot) => snapshot.context.selection, getValue = (snapshot) => snapshot.context.value;
|
|
53
146
|
exports.getActiveAnnotations = selector_isSelectingEntireBlocks.getActiveAnnotations;
|
|
54
147
|
exports.getActiveListItem = selector_isSelectingEntireBlocks.getActiveListItem;
|
|
55
148
|
exports.getActiveStyle = selector_isSelectingEntireBlocks.getActiveStyle;
|
|
@@ -95,6 +188,7 @@ exports.getAnchorChild = getAnchorChild;
|
|
|
95
188
|
exports.getAnchorSpan = getAnchorSpan;
|
|
96
189
|
exports.getAnchorTextBlock = getAnchorTextBlock;
|
|
97
190
|
exports.getBlockOffsets = getBlockOffsets;
|
|
191
|
+
exports.getListState = getListState;
|
|
98
192
|
exports.getSelection = getSelection;
|
|
99
193
|
exports.getValue = getValue;
|
|
100
194
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -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 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,CA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,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
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-list-state.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 {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock, getPreviousBlock} from './selectors'\n\n/**\n * @beta\n * Represents the List state of a block.\n */\nexport type ListState = {\n index: number\n}\n\n/**\n * @beta\n * Given the `path` of a block, this selector will return the `ListState` of\n * the block.\n */\nexport function getListState({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<ListState | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const previousListItem = getPreviousListItem({\n listItem: focusTextBlock.node.listItem,\n level: focusTextBlock.node.level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!previousListItem) {\n return {\n index: 1,\n }\n }\n\n if (previousListItem.node.listItem !== focusTextBlock.node.listItem) {\n return {\n index: 1,\n }\n }\n\n if (\n previousListItem.node.level !== undefined &&\n previousListItem.node.level < focusTextBlock.node.level\n ) {\n return {\n index: 1,\n }\n }\n\n const previousListItemListState = getListState({\n path: previousListItem.path,\n })(snapshot)\n\n if (previousListItemListState === undefined) {\n return {\n index: 1,\n }\n }\n\n return {\n index: previousListItemListState.index + 1,\n }\n }\n}\n\nfunction getPreviousListItem({\n listItem,\n level,\n}: {\n listItem: string\n level: number\n}): EditorSelector<\n | {\n node: PortableTextTextBlock\n path: [{_key: string}]\n }\n | undefined\n> {\n return (snapshot) => {\n const previousBlock = getPreviousBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n },\n })\n\n if (!previousBlock) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, previousBlock.node)) {\n return undefined\n }\n\n if (\n previousBlock.node.listItem === undefined ||\n previousBlock.node.level === undefined\n ) {\n return undefined\n }\n\n if (previousBlock.node.listItem !== listItem) {\n return undefined\n }\n\n if (previousBlock.node.level === level) {\n return {\n node: previousBlock.node,\n path: previousBlock.path,\n }\n }\n\n if (previousBlock.node.level < level) {\n return undefined\n }\n\n return getPreviousListItem({\n listItem,\n level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: {\n path: previousBlock.path,\n offset: 0,\n },\n focus: {\n path: previousBlock.path,\n offset: 0,\n },\n },\n },\n })\n }\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","getListState","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","previousListItem","getPreviousListItem","index","previousListItemListState","previousBlock","getPreviousBlock","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,GC3Ba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,oBAAoB;AAAA,UACzBH;AAAAA,UACAC;AAAAA,QAAAA,CACD,EAAE;AAAA,UACD,GAAGrC;AAAAA,UACHE,SAAS;AAAA,YACP,GAAGF,SAASE;AAAAA,YACZC,WAAW;AAAA,cACTE,QAAQ;AAAA,gBACNC,MAAMoC,cAAcpC;AAAAA,gBACpB0B,QAAQ;AAAA,cACV;AAAA,cACAC,OAAO;AAAA,gBACL3B,MAAMoC,cAAcpC;AAAAA,gBACpB0B,QAAQ;AAAA,cAAA;AAAA,YACV;AAAA,UACF;AAAA,QACF,CACD;AAAA,IAAA;AAAA,EACH;AACF;ACxKaY,MAAAA,eAAiD5C,CACrDA,aAAAA,SAASE,QAAQC,WCDb0C,WACX7C,CAEOA,aAAAA,SAASE,QAAQQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -317,6 +317,12 @@ declare type BlockOffset = {
|
|
|
317
317
|
offset: number
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
+
declare type BlockPath = [
|
|
321
|
+
{
|
|
322
|
+
_key: string
|
|
323
|
+
},
|
|
324
|
+
]
|
|
325
|
+
|
|
320
326
|
declare type BlockWithOptionalKey =
|
|
321
327
|
| TextBlockWithOptionalKey
|
|
322
328
|
| ObjectBlockWithOptionalKey
|
|
@@ -2630,6 +2636,17 @@ export declare const getLastBlock: EditorSelector<
|
|
|
2630
2636
|
| undefined
|
|
2631
2637
|
>
|
|
2632
2638
|
|
|
2639
|
+
/**
|
|
2640
|
+
* @beta
|
|
2641
|
+
* Given the `path` of a block, this selector will return the `ListState` of
|
|
2642
|
+
* the block.
|
|
2643
|
+
*/
|
|
2644
|
+
export declare function getListState({
|
|
2645
|
+
path,
|
|
2646
|
+
}: {
|
|
2647
|
+
path: BlockPath
|
|
2648
|
+
}): EditorSelector<ListState | undefined>
|
|
2649
|
+
|
|
2633
2650
|
/**
|
|
2634
2651
|
* @public
|
|
2635
2652
|
*/
|
|
@@ -2897,6 +2914,14 @@ declare type KeyboardBehaviorEvent =
|
|
|
2897
2914
|
>
|
|
2898
2915
|
}
|
|
2899
2916
|
|
|
2917
|
+
/**
|
|
2918
|
+
* @beta
|
|
2919
|
+
* Represents the List state of a block.
|
|
2920
|
+
*/
|
|
2921
|
+
declare type ListState = {
|
|
2922
|
+
index: number
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2900
2925
|
declare type MIMEType = `${string}/${string}`
|
|
2901
2926
|
|
|
2902
2927
|
declare type MouseBehaviorEvent = {
|
|
@@ -2981,6 +3006,9 @@ declare type ObjectBlockWithOptionalKey = Omit<PortableTextObject, '_key'> & {
|
|
|
2981
3006
|
declare type PatchesEvent = {
|
|
2982
3007
|
type: 'patches'
|
|
2983
3008
|
patches: Array<Patch>
|
|
3009
|
+
/**
|
|
3010
|
+
* @deprecated Unused by the editor
|
|
3011
|
+
*/
|
|
2984
3012
|
snapshot: Array<PortableTextBlock> | undefined
|
|
2985
3013
|
}
|
|
2986
3014
|
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -317,6 +317,12 @@ declare type BlockOffset = {
|
|
|
317
317
|
offset: number
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
+
declare type BlockPath = [
|
|
321
|
+
{
|
|
322
|
+
_key: string
|
|
323
|
+
},
|
|
324
|
+
]
|
|
325
|
+
|
|
320
326
|
declare type BlockWithOptionalKey =
|
|
321
327
|
| TextBlockWithOptionalKey
|
|
322
328
|
| ObjectBlockWithOptionalKey
|
|
@@ -2630,6 +2636,17 @@ export declare const getLastBlock: EditorSelector<
|
|
|
2630
2636
|
| undefined
|
|
2631
2637
|
>
|
|
2632
2638
|
|
|
2639
|
+
/**
|
|
2640
|
+
* @beta
|
|
2641
|
+
* Given the `path` of a block, this selector will return the `ListState` of
|
|
2642
|
+
* the block.
|
|
2643
|
+
*/
|
|
2644
|
+
export declare function getListState({
|
|
2645
|
+
path,
|
|
2646
|
+
}: {
|
|
2647
|
+
path: BlockPath
|
|
2648
|
+
}): EditorSelector<ListState | undefined>
|
|
2649
|
+
|
|
2633
2650
|
/**
|
|
2634
2651
|
* @public
|
|
2635
2652
|
*/
|
|
@@ -2897,6 +2914,14 @@ declare type KeyboardBehaviorEvent =
|
|
|
2897
2914
|
>
|
|
2898
2915
|
}
|
|
2899
2916
|
|
|
2917
|
+
/**
|
|
2918
|
+
* @beta
|
|
2919
|
+
* Represents the List state of a block.
|
|
2920
|
+
*/
|
|
2921
|
+
declare type ListState = {
|
|
2922
|
+
index: number
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2900
2925
|
declare type MIMEType = `${string}/${string}`
|
|
2901
2926
|
|
|
2902
2927
|
declare type MouseBehaviorEvent = {
|
|
@@ -2981,6 +3006,9 @@ declare type ObjectBlockWithOptionalKey = Omit<PortableTextObject, '_key'> & {
|
|
|
2981
3006
|
declare type PatchesEvent = {
|
|
2982
3007
|
type: 'patches'
|
|
2983
3008
|
patches: Array<Patch>
|
|
3009
|
+
/**
|
|
3010
|
+
* @deprecated Unused by the editor
|
|
3011
|
+
*/
|
|
2984
3012
|
snapshot: Array<PortableTextBlock> | undefined
|
|
2985
3013
|
}
|
|
2986
3014
|
|
package/lib/selectors/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { getSelectionEndPoint } from "../_chunks-es/selector.is-selecting-entire
|
|
|
2
2
|
import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFocusInlineObject, getNextInlineObject, getSelectedSpans, getSelectedTextBlocks, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
3
3
|
import { isKeyedSegment, isTextBlock, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
|
|
4
4
|
import { isPortableTextSpan } from "@sanity/types";
|
|
5
|
-
import { getSelectionStartPoint } from "../_chunks-es/selector.is-selection-expanded.js";
|
|
6
|
-
import { getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan,
|
|
5
|
+
import { getSelectionStartPoint, getFocusTextBlock, getPreviousBlock } from "../_chunks-es/selector.is-selection-expanded.js";
|
|
6
|
+
import { getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getLastBlock, getNextBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-selection-expanded.js";
|
|
7
7
|
import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
|
|
8
8
|
const getAnchorBlock = (snapshot) => {
|
|
9
9
|
const key = snapshot.context.selection && isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
@@ -53,7 +53,100 @@ const getAnchorBlock = (snapshot) => {
|
|
|
53
53
|
start,
|
|
54
54
|
end
|
|
55
55
|
} : void 0;
|
|
56
|
-
}
|
|
56
|
+
};
|
|
57
|
+
function getListState({
|
|
58
|
+
path
|
|
59
|
+
}) {
|
|
60
|
+
return (snapshot) => {
|
|
61
|
+
const selection = {
|
|
62
|
+
anchor: {
|
|
63
|
+
path,
|
|
64
|
+
offset: 0
|
|
65
|
+
},
|
|
66
|
+
focus: {
|
|
67
|
+
path,
|
|
68
|
+
offset: 0
|
|
69
|
+
}
|
|
70
|
+
}, focusTextBlock = getFocusTextBlock({
|
|
71
|
+
context: {
|
|
72
|
+
...snapshot.context,
|
|
73
|
+
selection
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (!focusTextBlock || focusTextBlock.node.listItem === void 0 || focusTextBlock.node.level === void 0)
|
|
77
|
+
return;
|
|
78
|
+
const previousListItem = getPreviousListItem({
|
|
79
|
+
listItem: focusTextBlock.node.listItem,
|
|
80
|
+
level: focusTextBlock.node.level
|
|
81
|
+
})({
|
|
82
|
+
...snapshot,
|
|
83
|
+
context: {
|
|
84
|
+
...snapshot.context,
|
|
85
|
+
selection
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
if (!previousListItem)
|
|
89
|
+
return {
|
|
90
|
+
index: 1
|
|
91
|
+
};
|
|
92
|
+
if (previousListItem.node.listItem !== focusTextBlock.node.listItem)
|
|
93
|
+
return {
|
|
94
|
+
index: 1
|
|
95
|
+
};
|
|
96
|
+
if (previousListItem.node.level !== void 0 && previousListItem.node.level < focusTextBlock.node.level)
|
|
97
|
+
return {
|
|
98
|
+
index: 1
|
|
99
|
+
};
|
|
100
|
+
const previousListItemListState = getListState({
|
|
101
|
+
path: previousListItem.path
|
|
102
|
+
})(snapshot);
|
|
103
|
+
return previousListItemListState === void 0 ? {
|
|
104
|
+
index: 1
|
|
105
|
+
} : {
|
|
106
|
+
index: previousListItemListState.index + 1
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function getPreviousListItem({
|
|
111
|
+
listItem,
|
|
112
|
+
level
|
|
113
|
+
}) {
|
|
114
|
+
return (snapshot) => {
|
|
115
|
+
const previousBlock = getPreviousBlock({
|
|
116
|
+
context: {
|
|
117
|
+
...snapshot.context
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
if (previousBlock && isTextBlock(snapshot.context, previousBlock.node) && !(previousBlock.node.listItem === void 0 || previousBlock.node.level === void 0) && previousBlock.node.listItem === listItem) {
|
|
121
|
+
if (previousBlock.node.level === level)
|
|
122
|
+
return {
|
|
123
|
+
node: previousBlock.node,
|
|
124
|
+
path: previousBlock.path
|
|
125
|
+
};
|
|
126
|
+
if (!(previousBlock.node.level < level))
|
|
127
|
+
return getPreviousListItem({
|
|
128
|
+
listItem,
|
|
129
|
+
level
|
|
130
|
+
})({
|
|
131
|
+
...snapshot,
|
|
132
|
+
context: {
|
|
133
|
+
...snapshot.context,
|
|
134
|
+
selection: {
|
|
135
|
+
anchor: {
|
|
136
|
+
path: previousBlock.path,
|
|
137
|
+
offset: 0
|
|
138
|
+
},
|
|
139
|
+
focus: {
|
|
140
|
+
path: previousBlock.path,
|
|
141
|
+
offset: 0
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const getSelection = (snapshot) => snapshot.context.selection, getValue = (snapshot) => snapshot.context.value;
|
|
57
150
|
export {
|
|
58
151
|
getActiveAnnotations,
|
|
59
152
|
getActiveListItem,
|
|
@@ -74,6 +167,7 @@ export {
|
|
|
74
167
|
getFocusSpan,
|
|
75
168
|
getFocusTextBlock,
|
|
76
169
|
getLastBlock,
|
|
170
|
+
getListState,
|
|
77
171
|
getNextBlock,
|
|
78
172
|
getNextInlineObject,
|
|
79
173
|
getPreviousBlock,
|
|
@@ -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 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,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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;"}
|
|
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-list-state.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 {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock, getPreviousBlock} from './selectors'\n\n/**\n * @beta\n * Represents the List state of a block.\n */\nexport type ListState = {\n index: number\n}\n\n/**\n * @beta\n * Given the `path` of a block, this selector will return the `ListState` of\n * the block.\n */\nexport function getListState({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<ListState | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const previousListItem = getPreviousListItem({\n listItem: focusTextBlock.node.listItem,\n level: focusTextBlock.node.level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!previousListItem) {\n return {\n index: 1,\n }\n }\n\n if (previousListItem.node.listItem !== focusTextBlock.node.listItem) {\n return {\n index: 1,\n }\n }\n\n if (\n previousListItem.node.level !== undefined &&\n previousListItem.node.level < focusTextBlock.node.level\n ) {\n return {\n index: 1,\n }\n }\n\n const previousListItemListState = getListState({\n path: previousListItem.path,\n })(snapshot)\n\n if (previousListItemListState === undefined) {\n return {\n index: 1,\n }\n }\n\n return {\n index: previousListItemListState.index + 1,\n }\n }\n}\n\nfunction getPreviousListItem({\n listItem,\n level,\n}: {\n listItem: string\n level: number\n}): EditorSelector<\n | {\n node: PortableTextTextBlock\n path: [{_key: string}]\n }\n | undefined\n> {\n return (snapshot) => {\n const previousBlock = getPreviousBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n },\n })\n\n if (!previousBlock) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, previousBlock.node)) {\n return undefined\n }\n\n if (\n previousBlock.node.listItem === undefined ||\n previousBlock.node.level === undefined\n ) {\n return undefined\n }\n\n if (previousBlock.node.listItem !== listItem) {\n return undefined\n }\n\n if (previousBlock.node.level === level) {\n return {\n node: previousBlock.node,\n path: previousBlock.path,\n }\n }\n\n if (previousBlock.node.level < level) {\n return undefined\n }\n\n return getPreviousListItem({\n listItem,\n level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: {\n path: previousBlock.path,\n offset: 0,\n },\n focus: {\n path: previousBlock.path,\n offset: 0,\n },\n },\n },\n })\n }\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","getListState","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","previousListItem","getPreviousListItem","index","previousListItemListState","previousBlock","getPreviousBlock","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,IA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;AAAA,UACzBH;AAAAA,UACAC;AAAAA,QAAAA,CACD,EAAE;AAAA,UACD,GAAGrC;AAAAA,UACHE,SAAS;AAAA,YACP,GAAGF,SAASE;AAAAA,YACZC,WAAW;AAAA,cACTE,QAAQ;AAAA,gBACNC,MAAMoC,cAAcpC;AAAAA,gBACpB0B,QAAQ;AAAA,cACV;AAAA,cACAC,OAAO;AAAA,gBACL3B,MAAMoC,cAAcpC;AAAAA,gBACpB0B,QAAQ;AAAA,cAAA;AAAA,YACV;AAAA,UACF;AAAA,QACF,CACD;AAAA,IAAA;AAAA,EACH;AACF;ACxKaY,MAAAA,eAAiD5C,CACrDA,aAAAA,SAASE,QAAQC,WCDb0C,WACX7C,CAEOA,aAAAA,SAASE,QAAQQ;"}
|
package/lib/utils/index.d.cts
CHANGED
|
@@ -2767,6 +2767,9 @@ declare type ObjectBlockWithOptionalKey = Omit<PortableTextObject, '_key'> & {
|
|
|
2767
2767
|
declare type PatchesEvent = {
|
|
2768
2768
|
type: 'patches'
|
|
2769
2769
|
patches: Array<Patch>
|
|
2770
|
+
/**
|
|
2771
|
+
* @deprecated Unused by the editor
|
|
2772
|
+
*/
|
|
2770
2773
|
snapshot: Array<PortableTextBlock> | undefined
|
|
2771
2774
|
}
|
|
2772
2775
|
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -2767,6 +2767,9 @@ declare type ObjectBlockWithOptionalKey = Omit<PortableTextObject, '_key'> & {
|
|
|
2767
2767
|
declare type PatchesEvent = {
|
|
2768
2768
|
type: 'patches'
|
|
2769
2769
|
patches: Array<Patch>
|
|
2770
|
+
/**
|
|
2771
|
+
* @deprecated Unused by the editor
|
|
2772
|
+
*/
|
|
2770
2773
|
snapshot: Array<PortableTextBlock> | undefined
|
|
2771
2774
|
}
|
|
2772
2775
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.50.1",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"slate-react": "0.114.2",
|
|
80
80
|
"use-effect-event": "^1.0.2",
|
|
81
81
|
"xstate": "^5.19.2",
|
|
82
|
-
"@portabletext/
|
|
83
|
-
"@portabletext/
|
|
82
|
+
"@portabletext/block-tools": "1.1.26",
|
|
83
|
+
"@portabletext/patches": "1.1.3"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@portabletext/toolkit": "^2.0.17",
|
|
@@ -95,8 +95,8 @@
|
|
|
95
95
|
"@types/lodash.startcase": "^4.4.9",
|
|
96
96
|
"@types/react": "^19.1.3",
|
|
97
97
|
"@types/react-dom": "^19.1.3",
|
|
98
|
-
"@typescript-eslint/eslint-plugin": "^8.32.
|
|
99
|
-
"@typescript-eslint/parser": "^8.32.
|
|
98
|
+
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
|
99
|
+
"@typescript-eslint/parser": "^8.32.1",
|
|
100
100
|
"@vitejs/plugin-react": "^4.4.1",
|
|
101
101
|
"@vitest/browser": "^3.1.3",
|
|
102
102
|
"@vitest/coverage-istanbul": "^3.1.3",
|
|
@@ -122,6 +122,21 @@ export function RenderTextBlock(props: {
|
|
|
122
122
|
data-block-key={props.textBlock._key}
|
|
123
123
|
data-block-name={props.textBlock._type}
|
|
124
124
|
data-block-type="text"
|
|
125
|
+
{...(props.textBlock.listItem !== undefined
|
|
126
|
+
? {
|
|
127
|
+
'data-list-item': props.textBlock.listItem,
|
|
128
|
+
}
|
|
129
|
+
: {})}
|
|
130
|
+
{...(props.textBlock.level !== undefined
|
|
131
|
+
? {
|
|
132
|
+
'data-level': props.textBlock.level,
|
|
133
|
+
}
|
|
134
|
+
: {})}
|
|
135
|
+
{...(props.textBlock.style !== undefined
|
|
136
|
+
? {
|
|
137
|
+
'data-style': props.textBlock.style,
|
|
138
|
+
}
|
|
139
|
+
: {})}
|
|
125
140
|
>
|
|
126
141
|
{dragPositionBlock === 'start' ? <DropIndicator /> : null}
|
|
127
142
|
<div ref={blockRef}>
|
|
@@ -220,6 +220,26 @@ export function insertBlock({
|
|
|
220
220
|
if (editor.isTextBlock(endBlock) && editor.isTextBlock(block)) {
|
|
221
221
|
const selectionStartPoint = Range.start(currentSelection)
|
|
222
222
|
|
|
223
|
+
if (isEqualToEmptyEditor([endBlock], schema)) {
|
|
224
|
+
const currentSelection = editor.selection
|
|
225
|
+
|
|
226
|
+
Transforms.insertNodes(editor, [block], {
|
|
227
|
+
at: endBlockPath,
|
|
228
|
+
select: false,
|
|
229
|
+
})
|
|
230
|
+
Transforms.removeNodes(editor, {at: Path.next(endBlockPath)})
|
|
231
|
+
|
|
232
|
+
if (select === 'start') {
|
|
233
|
+
Transforms.select(editor, selectionStartPoint)
|
|
234
|
+
} else if (select === 'end') {
|
|
235
|
+
Transforms.select(editor, Editor.end(editor, endBlockPath))
|
|
236
|
+
} else {
|
|
237
|
+
Transforms.select(editor, currentSelection)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
|
|
223
243
|
if (select === 'end') {
|
|
224
244
|
Transforms.insertFragment(editor, [block], {
|
|
225
245
|
voids: true,
|
package/src/selectors/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export {getAnchorTextBlock} from './selector.get-anchor-text-block'
|
|
|
8
8
|
export {getBlockOffsets} from './selector.get-block-offsets'
|
|
9
9
|
export {getCaretWordSelection} from './selector.get-caret-word-selection'
|
|
10
10
|
export {getFocusInlineObject} from './selector.get-focus-inline-object'
|
|
11
|
+
export {getListState} from './selector.get-list-state'
|
|
11
12
|
export {getNextInlineObject} from './selector.get-next-inline-object'
|
|
12
13
|
export {getPreviousInlineObject} from './selector.get-previous-inline-object'
|
|
13
14
|
export {getSelectedSlice} from './selector.get-selected-slice'
|