@portabletext/editor 2.14.4 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/{selector.is-active-style.cjs → selector.is-at-the-start-of-block.cjs} +90 -94
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -0
- package/lib/_chunks-dts/behavior.types.action.d.cts +4 -0
- package/lib/_chunks-dts/behavior.types.action.d.ts +4 -0
- package/lib/_chunks-es/{selector.is-active-style.js → selector.is-at-the-start-of-block.js} +90 -94
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
- package/lib/index.cjs +163 -81
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +84 -2
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +33 -33
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +2 -2
- package/lib/utils/index.d.cts +2 -2
- package/package.json +3 -3
- package/src/editor/editor-dom.ts +99 -0
- package/src/internal-utils/operation-to-patches.ts +39 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
package/lib/selectors/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var
|
|
3
|
+
var selector_isAtTheStartOfBlock = require("../_chunks-cjs/selector.is-at-the-start-of-block.cjs"), util_getTextBlockText = require("../_chunks-cjs/util.get-text-block-text.cjs"), schema = require("@portabletext/schema"), types = require("@sanity/types"), selector_getSelectionText = require("../_chunks-cjs/selector.get-selection-text.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs");
|
|
4
4
|
const getAnchorBlock = (snapshot) => {
|
|
5
5
|
if (!snapshot.context.selection)
|
|
6
6
|
return;
|
|
@@ -39,7 +39,7 @@ const getAnchorBlock = (snapshot) => {
|
|
|
39
39
|
}, getBlockOffsets = (snapshot) => {
|
|
40
40
|
if (!snapshot.context.selection)
|
|
41
41
|
return;
|
|
42
|
-
const selectionStartPoint = selector_getSelectionText.getSelectionStartPoint(snapshot), selectionEndPoint =
|
|
42
|
+
const selectionStartPoint = selector_getSelectionText.getSelectionStartPoint(snapshot), selectionEndPoint = selector_isAtTheStartOfBlock.getSelectionEndPoint(snapshot);
|
|
43
43
|
if (!selectionStartPoint || !selectionEndPoint)
|
|
44
44
|
return;
|
|
45
45
|
const start = util_getTextBlockText.spanSelectionPointToBlockOffset({
|
|
@@ -90,7 +90,7 @@ function getListIndex({
|
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
const getNextInlineObjects = (snapshot) => {
|
|
93
|
-
const focusTextBlock = selector_getSelectionText.getFocusTextBlock(snapshot), selectionEndPoint =
|
|
93
|
+
const focusTextBlock = selector_getSelectionText.getFocusTextBlock(snapshot), selectionEndPoint = selector_isAtTheStartOfBlock.getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
|
|
94
94
|
if (!focusTextBlock || !selectionEndPointChildKey)
|
|
95
95
|
return [];
|
|
96
96
|
let endPointChildFound = !1;
|
|
@@ -154,36 +154,36 @@ const getNextInlineObjects = (snapshot) => {
|
|
|
154
154
|
}
|
|
155
155
|
});
|
|
156
156
|
}, getValue = (snapshot) => snapshot.context.value;
|
|
157
|
-
exports.getActiveAnnotations =
|
|
158
|
-
exports.getActiveListItem =
|
|
159
|
-
exports.getActiveStyle =
|
|
160
|
-
exports.getCaretWordSelection =
|
|
161
|
-
exports.getFirstBlock =
|
|
162
|
-
exports.getFocusBlockObject =
|
|
163
|
-
exports.getFocusInlineObject =
|
|
164
|
-
exports.getFocusListBlock =
|
|
165
|
-
exports.getLastBlock =
|
|
166
|
-
exports.getMarkState =
|
|
167
|
-
exports.getNextBlock =
|
|
168
|
-
exports.getNextInlineObject =
|
|
169
|
-
exports.getPreviousBlock =
|
|
170
|
-
exports.getSelectedBlocks =
|
|
171
|
-
exports.getSelectedSpans =
|
|
172
|
-
exports.getSelectedTextBlocks =
|
|
173
|
-
exports.getSelectionEndBlock =
|
|
174
|
-
exports.getSelectionEndPoint =
|
|
175
|
-
exports.getSelectionStartBlock =
|
|
176
|
-
exports.getTrimmedSelection =
|
|
177
|
-
exports.isActiveAnnotation =
|
|
178
|
-
exports.isActiveDecorator =
|
|
179
|
-
exports.isActiveListItem =
|
|
180
|
-
exports.isActiveStyle =
|
|
181
|
-
exports.isAtTheEndOfBlock =
|
|
182
|
-
exports.isAtTheStartOfBlock =
|
|
183
|
-
exports.isOverlappingSelection =
|
|
184
|
-
exports.isPointAfterSelection =
|
|
185
|
-
exports.isPointBeforeSelection =
|
|
186
|
-
exports.isSelectingEntireBlocks =
|
|
157
|
+
exports.getActiveAnnotations = selector_isAtTheStartOfBlock.getActiveAnnotations;
|
|
158
|
+
exports.getActiveListItem = selector_isAtTheStartOfBlock.getActiveListItem;
|
|
159
|
+
exports.getActiveStyle = selector_isAtTheStartOfBlock.getActiveStyle;
|
|
160
|
+
exports.getCaretWordSelection = selector_isAtTheStartOfBlock.getCaretWordSelection;
|
|
161
|
+
exports.getFirstBlock = selector_isAtTheStartOfBlock.getFirstBlock;
|
|
162
|
+
exports.getFocusBlockObject = selector_isAtTheStartOfBlock.getFocusBlockObject;
|
|
163
|
+
exports.getFocusInlineObject = selector_isAtTheStartOfBlock.getFocusInlineObject;
|
|
164
|
+
exports.getFocusListBlock = selector_isAtTheStartOfBlock.getFocusListBlock;
|
|
165
|
+
exports.getLastBlock = selector_isAtTheStartOfBlock.getLastBlock;
|
|
166
|
+
exports.getMarkState = selector_isAtTheStartOfBlock.getMarkState;
|
|
167
|
+
exports.getNextBlock = selector_isAtTheStartOfBlock.getNextBlock;
|
|
168
|
+
exports.getNextInlineObject = selector_isAtTheStartOfBlock.getNextInlineObject;
|
|
169
|
+
exports.getPreviousBlock = selector_isAtTheStartOfBlock.getPreviousBlock;
|
|
170
|
+
exports.getSelectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks;
|
|
171
|
+
exports.getSelectedSpans = selector_isAtTheStartOfBlock.getSelectedSpans;
|
|
172
|
+
exports.getSelectedTextBlocks = selector_isAtTheStartOfBlock.getSelectedTextBlocks;
|
|
173
|
+
exports.getSelectionEndBlock = selector_isAtTheStartOfBlock.getSelectionEndBlock;
|
|
174
|
+
exports.getSelectionEndPoint = selector_isAtTheStartOfBlock.getSelectionEndPoint;
|
|
175
|
+
exports.getSelectionStartBlock = selector_isAtTheStartOfBlock.getSelectionStartBlock;
|
|
176
|
+
exports.getTrimmedSelection = selector_isAtTheStartOfBlock.getTrimmedSelection;
|
|
177
|
+
exports.isActiveAnnotation = selector_isAtTheStartOfBlock.isActiveAnnotation;
|
|
178
|
+
exports.isActiveDecorator = selector_isAtTheStartOfBlock.isActiveDecorator;
|
|
179
|
+
exports.isActiveListItem = selector_isAtTheStartOfBlock.isActiveListItem;
|
|
180
|
+
exports.isActiveStyle = selector_isAtTheStartOfBlock.isActiveStyle;
|
|
181
|
+
exports.isAtTheEndOfBlock = selector_isAtTheStartOfBlock.isAtTheEndOfBlock;
|
|
182
|
+
exports.isAtTheStartOfBlock = selector_isAtTheStartOfBlock.isAtTheStartOfBlock;
|
|
183
|
+
exports.isOverlappingSelection = selector_isAtTheStartOfBlock.isOverlappingSelection;
|
|
184
|
+
exports.isPointAfterSelection = selector_isAtTheStartOfBlock.isPointAfterSelection;
|
|
185
|
+
exports.isPointBeforeSelection = selector_isAtTheStartOfBlock.isPointBeforeSelection;
|
|
186
|
+
exports.isSelectingEntireBlocks = selector_isAtTheStartOfBlock.isSelectingEntireBlocks;
|
|
187
187
|
exports.getFocusBlock = selector_getSelectionText.getFocusBlock;
|
|
188
188
|
exports.getFocusChild = selector_getSelectionText.getFocusChild;
|
|
189
189
|
exports.getFocusSpan = selector_getSelectionText.getFocusSpan;
|
|
@@ -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-list-state.ts","../../src/selectors/selector.get-next-inline-objects.ts","../../src/selectors/selector.get-previous-inline-objects.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-selection-end-child.ts","../../src/selectors/selector.get-selection-start-child.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | 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 {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\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 {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | 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 {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\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 = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @beta\n * @deprecated Use the precomputed `data-list-index` on text blocks instead.\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | 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 targetListItem = focusTextBlock.node.listItem\n const targetLevel = focusTextBlock.node.level\n const targetKey = focusTextBlock.node._key\n\n // Find the target block's index\n const targetIndex = snapshot.blockIndexMap.get(targetKey)\n\n if (targetIndex === undefined) {\n return undefined\n }\n\n // Walk backwards from the target block and count consecutive list items\n // of the same type and level\n let listIndex = 1 // Start at 1 for the target block itself\n\n for (let i = targetIndex - 1; i >= 0; i--) {\n const block = snapshot.context.value[i]\n\n if (!isTextBlock(snapshot.context, block)) {\n // Non-text block breaks the sequence\n break\n }\n\n if (block.listItem === undefined || block.level === undefined) {\n // Non-list item breaks the sequence\n break\n }\n\n if (block.listItem !== targetListItem) {\n // Different list type breaks the sequence\n break\n }\n\n if (block.level < targetLevel) {\n // Lower level breaks the sequence\n break\n }\n\n if (block.level === targetLevel) {\n // Same level - continue counting\n listIndex++\n }\n\n // Higher level items don't affect the count for the target level\n }\n\n return listIndex\n }\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * @public\n */\nexport const getNextInlineObjects: EditorSelector<\n Array<{\n node: PortableTextObject\n path: ChildPath\n }>\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n const selectionEndPointChildKey =\n selectionEndPoint && isKeySegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return []\n }\n\n let endPointChildFound = false\n const inlineObjects: Array<{\n node: PortableTextObject\n path: ChildPath\n }> = []\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpan(snapshot.context, child) && endPointChildFound) {\n inlineObjects.push({\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n })\n break\n }\n }\n\n return inlineObjects\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObjects: EditorSelector<\n Array<{\n node: PortableTextObject\n path: ChildPath\n }>\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return []\n }\n\n const inlineObjects: Array<{\n node: PortableTextObject\n path: ChildPath\n }> = []\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObjects.push({\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n })\n }\n }\n\n return inlineObjects\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n * @deprecated Renamed to `getSelectedValue`.\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return getSelectedValue(snapshot)\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionEndChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!endPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionStartChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n if (!startPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\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","context","selection","key","getBlockKeyFromSelectionPoint","anchor","index","blockIndexMap","get","undefined","node","value","at","path","_key","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","find","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","spanSelectionPointToBlockOffset","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","targetListItem","targetLevel","targetKey","targetIndex","listIndex","i","block","getNextInlineObjects","selectionEndPointChildKey","isKeySegment","endPointChildFound","inlineObjects","child","isSpan","push","getPreviousInlineObjects","selectionStartPointChildKey","getSelectedSlice","getSelectedValue","getSelection","getSelectionEndChild","endPoint","getFocusChild","getSelectionStartChild","startPoint","getValue"],"mappings":";;;AAQO,MAAMA,iBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,sBAAAA,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GACrEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAChDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAAC;AAAA,MAACC,MAAMX;AAAAA,IAAAA,CAAI;AAAA,EAAA,IAAKM;AACrD,GCZaM,qBAERf,CAAAA,aAAa;AAChB,QAAMgB,cAAcjB,eAAeC,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BACX3D,CAAAA,aAEO4D,0BAAAA,iBAAiB5D,QAAQ,GCLrB6D,eAAiD7D,CAAAA,aACrDA,SAASC,QAAQC,WCEb4D,uBAMR9D,CAAAA,aAAa;AAChB,QAAM+D,WAAWjC,sBAAAA,qBAAqB9B,SAASC,QAAQC,SAAS;AAEhE,MAAK6D;AAIL,WAAOC,wCAAc;AAAA,MACnB,GAAGhE;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQ0D;AAAAA,UACR1B,OAAO0B;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GCvBaE,yBAMRjE,CAAAA,aAAa;AAChB,QAAMkE,aAAatC,sBAAAA,uBAAuB5B,SAASC,QAAQC,SAAS;AAEpE,MAAKgE;AAIL,WAAOF,wCAAc;AAAA,MACnB,GAAGhE;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQ6D;AAAAA,UACR7B,OAAO6B;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GC1BaC,WACXnE,CAAAA,aAEOA,SAASC,QAAQU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
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-next-inline-objects.ts","../../src/selectors/selector.get-previous-inline-objects.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-selection-end-child.ts","../../src/selectors/selector.get-selection-start-child.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | 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 {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\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 {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | 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 {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\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 = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @beta\n * @deprecated Use the precomputed `data-list-index` on text blocks instead.\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | 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 targetListItem = focusTextBlock.node.listItem\n const targetLevel = focusTextBlock.node.level\n const targetKey = focusTextBlock.node._key\n\n // Find the target block's index\n const targetIndex = snapshot.blockIndexMap.get(targetKey)\n\n if (targetIndex === undefined) {\n return undefined\n }\n\n // Walk backwards from the target block and count consecutive list items\n // of the same type and level\n let listIndex = 1 // Start at 1 for the target block itself\n\n for (let i = targetIndex - 1; i >= 0; i--) {\n const block = snapshot.context.value[i]\n\n if (!isTextBlock(snapshot.context, block)) {\n // Non-text block breaks the sequence\n break\n }\n\n if (block.listItem === undefined || block.level === undefined) {\n // Non-list item breaks the sequence\n break\n }\n\n if (block.listItem !== targetListItem) {\n // Different list type breaks the sequence\n break\n }\n\n if (block.level < targetLevel) {\n // Lower level breaks the sequence\n break\n }\n\n if (block.level === targetLevel) {\n // Same level - continue counting\n listIndex++\n }\n\n // Higher level items don't affect the count for the target level\n }\n\n return listIndex\n }\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * @public\n */\nexport const getNextInlineObjects: EditorSelector<\n Array<{\n node: PortableTextObject\n path: ChildPath\n }>\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n const selectionEndPointChildKey =\n selectionEndPoint && isKeySegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return []\n }\n\n let endPointChildFound = false\n const inlineObjects: Array<{\n node: PortableTextObject\n path: ChildPath\n }> = []\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpan(snapshot.context, child) && endPointChildFound) {\n inlineObjects.push({\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n })\n break\n }\n }\n\n return inlineObjects\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObjects: EditorSelector<\n Array<{\n node: PortableTextObject\n path: ChildPath\n }>\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return []\n }\n\n const inlineObjects: Array<{\n node: PortableTextObject\n path: ChildPath\n }> = []\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObjects.push({\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n })\n }\n }\n\n return inlineObjects\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n * @deprecated Renamed to `getSelectedValue`.\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return getSelectedValue(snapshot)\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionEndChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!endPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionStartChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n if (!startPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\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","context","selection","key","getBlockKeyFromSelectionPoint","anchor","index","blockIndexMap","get","undefined","node","value","at","path","_key","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","find","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","spanSelectionPointToBlockOffset","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","targetListItem","targetLevel","targetKey","targetIndex","listIndex","i","block","getNextInlineObjects","selectionEndPointChildKey","isKeySegment","endPointChildFound","inlineObjects","child","isSpan","push","getPreviousInlineObjects","selectionStartPointChildKey","getSelectedSlice","getSelectedValue","getSelection","getSelectionEndChild","endPoint","getFocusChild","getSelectionStartChild","startPoint","getValue"],"mappings":";;;AAQO,MAAMA,iBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,sBAAAA,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GACrEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAChDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAAC;AAAA,MAACC,MAAMX;AAAAA,IAAAA,CAAI;AAAA,EAAA,IAAKM;AACrD,GCZaM,qBAERf,CAAAA,aAAa;AAChB,QAAMgB,cAAcjB,eAAeC,QAAQ;AAE3C,SAAOgB,eAAeC,OAAAA,YAAYjB,SAASC,SAASe,YAAYN,IAAI,IAChE;AAAA,IAACA,MAAMM,YAAYN;AAAAA,IAAMG,MAAMG,YAAYH;AAAAA,EAAAA,IAC3CJ;AACN,GCRaS,iBAMRlB,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMc,cAAcD,mBAAmBf,QAAQ;AAE/C,MAAI,CAACgB;AACH;AAGF,QAAMb,MAAMgB,sBAAAA,8BAA8BnB,SAASC,QAAQC,UAAUG,MAAM,GAErEK,OAAOP,MACTa,YAAYN,KAAKU,SAASC,KAAMC,UAASA,KAAKR,SAASX,GAAG,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AChB,QAAMkE,aAAatC,sBAAAA,uBAAuB5B,SAASC,QAAQC,SAAS;AAEpE,MAAKgE;AAIL,WAAOF,wCAAc;AAAA,MACnB,GAAGhE;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQ6D;AAAAA,UACR7B,OAAO6B;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GC1BaC,WACXnE,CAAAA,aAEOA,SAASC,QAAQU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/selectors/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getSelectionEndPoint } from "../_chunks-es/selector.is-
|
|
2
|
-
import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlockObject, getFocusInlineObject, getFocusListBlock, getLastBlock, getMarkState, getNextBlock, getNextInlineObject, getPreviousBlock, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectionEndBlock, getSelectionStartBlock, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-
|
|
1
|
+
import { getSelectionEndPoint } from "../_chunks-es/selector.is-at-the-start-of-block.js";
|
|
2
|
+
import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlockObject, getFocusInlineObject, getFocusListBlock, getLastBlock, getMarkState, getNextBlock, getNextInlineObject, getPreviousBlock, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectionEndBlock, getSelectionStartBlock, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-at-the-start-of-block.js";
|
|
3
3
|
import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, spanSelectionPointToBlockOffset, getSelectionEndPoint as getSelectionEndPoint$1, getSelectionStartPoint as getSelectionStartPoint$1 } from "../_chunks-es/util.get-text-block-text.js";
|
|
4
4
|
import { isTextBlock, isSpan } from "@portabletext/schema";
|
|
5
5
|
import { isPortableTextSpan, isKeySegment } from "@sanity/types";
|
package/lib/utils/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BlockOffset, BlockPath, ChildPath, EditorContext, EditorSelection, EditorSelectionPoint } from "../_chunks-dts/behavior.types.action.cjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _sanity_types9 from "@sanity/types";
|
|
3
3
|
import { KeyedSegment, PortableTextBlock, PortableTextTextBlock } from "@sanity/types";
|
|
4
4
|
import { isSpan, isTextBlock } from "@portabletext/schema";
|
|
5
5
|
/**
|
|
@@ -143,7 +143,7 @@ declare function mergeTextBlocks({
|
|
|
143
143
|
context: Pick<EditorContext, 'keyGenerator' | 'schema'>;
|
|
144
144
|
targetBlock: PortableTextTextBlock;
|
|
145
145
|
incomingBlock: PortableTextTextBlock;
|
|
146
|
-
}): PortableTextTextBlock<
|
|
146
|
+
}): PortableTextTextBlock<_sanity_types9.PortableTextObject | _sanity_types9.PortableTextSpan>;
|
|
147
147
|
/**
|
|
148
148
|
* @public
|
|
149
149
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"@types/node": "^20",
|
|
102
102
|
"@types/react": "^19.2.0",
|
|
103
103
|
"@types/react-dom": "^19.2.0",
|
|
104
|
-
"@vitejs/plugin-react": "^
|
|
104
|
+
"@vitejs/plugin-react": "^5.0.4",
|
|
105
105
|
"@vitest/browser": "^3.2.4",
|
|
106
106
|
"@vitest/coverage-istanbul": "^3.2.4",
|
|
107
107
|
"babel-plugin-react-compiler": "1.0.0",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"vitest-browser-react": "^1.0.1",
|
|
120
120
|
"@portabletext/sanity-bridge": "1.1.14",
|
|
121
121
|
"@portabletext/test": "^0.0.0",
|
|
122
|
-
"racejar": "1.3.
|
|
122
|
+
"racejar": "1.3.2"
|
|
123
123
|
},
|
|
124
124
|
"peerDependencies": {
|
|
125
125
|
"@portabletext/sanity-bridge": "^1.1.14",
|
package/src/editor/editor-dom.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {Editor} from 'slate'
|
|
|
2
2
|
import {DOMEditor} from 'slate-dom'
|
|
3
3
|
import type {BehaviorEvent} from '../behaviors/behavior.types.event'
|
|
4
4
|
import {toSlateRange} from '../internal-utils/to-slate-range'
|
|
5
|
+
import {getSelectionEndBlock, getSelectionStartBlock} from '../selectors'
|
|
5
6
|
import type {PickFromUnion} from '../type-utils'
|
|
6
7
|
import type {PortableTextSlateEditor} from '../types/editor'
|
|
7
8
|
import type {EditorSnapshot} from './editor-snapshot'
|
|
@@ -9,6 +10,10 @@ import type {EditorSnapshot} from './editor-snapshot'
|
|
|
9
10
|
export type EditorDom = {
|
|
10
11
|
getBlockNodes: (snapshot: EditorSnapshot) => Array<Node>
|
|
11
12
|
getChildNodes: (snapshot: EditorSnapshot) => Array<Node>
|
|
13
|
+
getEditorElement: () => Element | undefined
|
|
14
|
+
getSelectionRect: (snapshot: EditorSnapshot) => DOMRect | null
|
|
15
|
+
getStartBlockElement: (snapshot: EditorSnapshot) => Element | null
|
|
16
|
+
getEndBlockElement: (snapshot: EditorSnapshot) => Element | null
|
|
12
17
|
/**
|
|
13
18
|
* Let the Editor set the drag ghost. This is to be sure that it will get
|
|
14
19
|
* properly removed again when the drag ends.
|
|
@@ -33,6 +38,11 @@ export function createEditorDom(
|
|
|
33
38
|
return {
|
|
34
39
|
getBlockNodes: (snapshot) => getBlockNodes(slateEditor, snapshot),
|
|
35
40
|
getChildNodes: (snapshot) => getChildNodes(slateEditor, snapshot),
|
|
41
|
+
getEditorElement: () => getEditorElement(slateEditor),
|
|
42
|
+
getSelectionRect: (snapshot) => getSelectionRect(snapshot),
|
|
43
|
+
getStartBlockElement: (snapshot) =>
|
|
44
|
+
getStartBlockElement(slateEditor, snapshot),
|
|
45
|
+
getEndBlockElement: (snapshot) => getEndBlockElement(slateEditor, snapshot),
|
|
36
46
|
setDragGhost: ({event, ghost}) => setDragGhost({sendBack, event, ghost}),
|
|
37
47
|
}
|
|
38
48
|
}
|
|
@@ -99,6 +109,95 @@ function getChildNodes(
|
|
|
99
109
|
}
|
|
100
110
|
}
|
|
101
111
|
|
|
112
|
+
function getEditorElement(slateEditor: PortableTextSlateEditor) {
|
|
113
|
+
try {
|
|
114
|
+
return DOMEditor.toDOMNode(slateEditor, slateEditor)
|
|
115
|
+
} catch {
|
|
116
|
+
return undefined
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function getSelectionRect(snapshot: EditorSnapshot) {
|
|
121
|
+
if (!snapshot.context.selection) {
|
|
122
|
+
return null
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const selection = window.getSelection()
|
|
127
|
+
|
|
128
|
+
if (!selection) {
|
|
129
|
+
return null
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const range = selection.getRangeAt(0)
|
|
133
|
+
return range.getBoundingClientRect()
|
|
134
|
+
} catch {
|
|
135
|
+
return null
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function getStartBlockElement(
|
|
140
|
+
slateEditor: PortableTextSlateEditor,
|
|
141
|
+
snapshot: EditorSnapshot,
|
|
142
|
+
) {
|
|
143
|
+
const startBlock = getSelectionStartBlock(snapshot)
|
|
144
|
+
|
|
145
|
+
if (!startBlock) {
|
|
146
|
+
return null
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const startBlockNode = getBlockNodes(slateEditor, {
|
|
150
|
+
...snapshot,
|
|
151
|
+
context: {
|
|
152
|
+
...snapshot.context,
|
|
153
|
+
selection: {
|
|
154
|
+
anchor: {
|
|
155
|
+
path: startBlock.path,
|
|
156
|
+
offset: 0,
|
|
157
|
+
},
|
|
158
|
+
focus: {
|
|
159
|
+
path: startBlock.path,
|
|
160
|
+
offset: 0,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
})?.at(0)
|
|
165
|
+
|
|
166
|
+
return startBlockNode && startBlockNode instanceof Element
|
|
167
|
+
? startBlockNode
|
|
168
|
+
: null
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function getEndBlockElement(
|
|
172
|
+
slateEditor: PortableTextSlateEditor,
|
|
173
|
+
snapshot: EditorSnapshot,
|
|
174
|
+
) {
|
|
175
|
+
const endBlock = getSelectionEndBlock(snapshot)
|
|
176
|
+
|
|
177
|
+
if (!endBlock) {
|
|
178
|
+
return null
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const endBlockNode = getBlockNodes(slateEditor, {
|
|
182
|
+
...snapshot,
|
|
183
|
+
context: {
|
|
184
|
+
...snapshot.context,
|
|
185
|
+
selection: {
|
|
186
|
+
anchor: {
|
|
187
|
+
path: endBlock.path,
|
|
188
|
+
offset: 0,
|
|
189
|
+
},
|
|
190
|
+
focus: {
|
|
191
|
+
path: endBlock.path,
|
|
192
|
+
offset: 0,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
})?.at(0)
|
|
197
|
+
|
|
198
|
+
return endBlockNode && endBlockNode instanceof Element ? endBlockNode : null
|
|
199
|
+
}
|
|
200
|
+
|
|
102
201
|
function setDragGhost({
|
|
103
202
|
sendBack,
|
|
104
203
|
event,
|
|
@@ -11,6 +11,7 @@ import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
|
11
11
|
import type {Path, PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
|
|
12
12
|
import {get, isUndefined, omitBy} from 'lodash'
|
|
13
13
|
import {
|
|
14
|
+
Element,
|
|
14
15
|
Text,
|
|
15
16
|
type Descendant,
|
|
16
17
|
type InsertNodeOperation,
|
|
@@ -122,6 +123,44 @@ export function setNodePatch(
|
|
|
122
123
|
const blockKey = block._key
|
|
123
124
|
const childKey = child._key
|
|
124
125
|
const patches: Patch[] = []
|
|
126
|
+
|
|
127
|
+
if (Element.isElement(child)) {
|
|
128
|
+
// The child is an inline object. This needs to be treated
|
|
129
|
+
// differently since all custom properties are stored on a `value`
|
|
130
|
+
// object.
|
|
131
|
+
|
|
132
|
+
const _key = operation.newProperties._key
|
|
133
|
+
|
|
134
|
+
if (_key !== undefined) {
|
|
135
|
+
patches.push(
|
|
136
|
+
set(_key, [
|
|
137
|
+
{_key: blockKey},
|
|
138
|
+
'children',
|
|
139
|
+
block.children.indexOf(child),
|
|
140
|
+
'_key',
|
|
141
|
+
]),
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const properties =
|
|
146
|
+
'value' in operation.newProperties &&
|
|
147
|
+
typeof operation.newProperties.value === 'object'
|
|
148
|
+
? (operation.newProperties.value as Record<string, unknown>)
|
|
149
|
+
: ({} satisfies Record<string, unknown>)
|
|
150
|
+
|
|
151
|
+
const keys = Object.keys(properties)
|
|
152
|
+
|
|
153
|
+
for (const key of keys) {
|
|
154
|
+
const value = properties[key]
|
|
155
|
+
|
|
156
|
+
patches.push(
|
|
157
|
+
set(value, [{_key: blockKey}, 'children', {_key: childKey}, key]),
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return patches
|
|
162
|
+
}
|
|
163
|
+
|
|
125
164
|
const keys = Object.keys(operation.newProperties)
|
|
126
165
|
keys.forEach((keyName) => {
|
|
127
166
|
// Special case for setting _key on a child. We have to target it by index and not the _key.
|