@portabletext/editor 1.50.8 → 1.52.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/{util.slice-blocks.cjs → selection-point.cjs} +26 -18
- package/lib/_chunks-cjs/selection-point.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +13 -10
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +46 -46
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +21 -17
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +10 -10
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +5 -5
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +7 -14
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/{util.slice-blocks.js → selection-point.js} +26 -18
- package/lib/_chunks-es/selection-point.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +13 -10
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +21 -21
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js +14 -10
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +2 -2
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +4 -11
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +25 -2010
- package/lib/behaviors/index.d.ts +25 -2010
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +515 -393
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +361 -34
- package/lib/index.d.ts +361 -34
- package/lib/index.js +471 -349
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +11 -11
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +32 -1986
- package/lib/plugins/index.d.ts +32 -1986
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +11 -7
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +2 -2648
- package/lib/selectors/index.d.ts +2 -2648
- package/lib/selectors/index.js +7 -3
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +25 -14
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +0 -2647
- package/lib/utils/index.d.ts +0 -2647
- package/lib/utils/index.js +14 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +14 -14
- package/src/behaviors/behavior.abstract.delete.ts +0 -2
- package/src/behaviors/behavior.abstract.insert.ts +8 -8
- package/src/behaviors/behavior.abstract.ts +0 -113
- package/src/behaviors/behavior.core.block-element.ts +9 -3
- package/src/behaviors/behavior.core.dnd.ts +328 -1
- package/src/behaviors/behavior.perform-event.ts +10 -0
- package/src/behaviors/behavior.types.action.ts +2 -0
- package/src/behaviors/behavior.types.event.ts +5 -0
- package/src/behaviors/behavior.types.guard.ts +2 -0
- package/src/converters/converter.portable-text.ts +2 -7
- package/src/converters/converter.text-html.ts +1 -3
- package/src/converters/converter.text-plain.ts +3 -5
- package/src/editor/Editable.tsx +6 -133
- package/src/editor/editor-machine.ts +15 -10
- package/src/editor/editor-selector.ts +0 -2
- package/src/editor/editor-snapshot.ts +0 -18
- package/src/internal-utils/create-test-snapshot.ts +0 -2
- package/src/internal-utils/event-position.ts +42 -30
- package/src/internal-utils/selection-block-keys.ts +7 -7
- package/src/internal-utils/selection-elements.ts +108 -0
- package/src/internal-utils/selection-focus-text.ts +13 -9
- package/src/internal-utils/selection-text.ts +9 -78
- package/src/internal-utils/terse-pt.test.ts +108 -26
- package/src/internal-utils/terse-pt.ts +132 -14
- package/src/operations/behavior.operation.decorator.add.ts +0 -2
- package/src/operations/behavior.operation.delete.ts +18 -13
- package/src/operations/behavior.operation.insert.block.ts +5 -1
- package/src/selection/selection-point.ts +22 -0
- package/src/selectors/selector.get-anchor-block.ts +6 -6
- package/src/selectors/selector.get-anchor-child.ts +6 -6
- package/src/selectors/selector.get-selected-spans.ts +16 -19
- package/src/selectors/selector.get-selected-text-blocks.ts +11 -19
- package/src/selectors/selector.get-selection-end-block.ts +30 -0
- package/src/selectors/selector.get-selection-start-block.ts +30 -0
- package/src/selectors/selector.get-text-before.ts +15 -16
- package/src/selectors/selector.get-trimmed-selection.ts +15 -21
- package/src/selectors/selector.is-point-after-selection.ts +11 -19
- package/src/selectors/selector.is-point-before-selection.ts +11 -19
- package/src/selectors/selectors.ts +23 -39
- package/src/utils/util.block-offset.ts +6 -7
- package/src/utils/util.child-selection-point-to-block-offset.ts +6 -7
- package/src/utils/util.selection-point-to-block-offset.ts +5 -6
- package/src/utils/util.slice-blocks.ts +11 -20
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
- package/src/internal-utils/inline-object-selection.ts +0 -115
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var selectionPoint = require("./selection-point.cjs");
|
|
3
3
|
function getBlockEndPoint({
|
|
4
4
|
context,
|
|
5
5
|
block
|
|
6
6
|
}) {
|
|
7
|
-
if (
|
|
7
|
+
if (selectionPoint.isTextBlock(context, block.node)) {
|
|
8
8
|
const lastChild = block.node.children[block.node.children.length - 1];
|
|
9
9
|
if (lastChild)
|
|
10
10
|
return {
|
|
11
11
|
path: [...block.path, "children", {
|
|
12
12
|
_key: lastChild._key
|
|
13
13
|
}],
|
|
14
|
-
offset:
|
|
14
|
+
offset: selectionPoint.isSpan$1(context, lastChild) ? lastChild.text.length : 0
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
return {
|
|
@@ -20,9 +20,9 @@ function getBlockEndPoint({
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
function isEmptyTextBlock(context, block) {
|
|
23
|
-
if (!
|
|
23
|
+
if (!selectionPoint.isTextBlock(context, block))
|
|
24
24
|
return !1;
|
|
25
|
-
const onlyText = block.children.every((child) =>
|
|
25
|
+
const onlyText = block.children.every((child) => selectionPoint.isSpan$1(context, child)), blockText = selectionPoint.getTextBlockText(block);
|
|
26
26
|
return onlyText && blockText === "";
|
|
27
27
|
}
|
|
28
28
|
function isEqualSelectionPoints(a, b) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.is-equal-selection-points.cjs","sources":["../../src/utils/util.get-block-end-point.ts","../../src/utils/util.is-empty-text-block.ts","../../src/utils/util.is-equal-selection-points.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n const lastChild = block.node.children[block.node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...block.path, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock,\n) {\n if (!isTextBlock(context, block)) {\n return false\n }\n\n const onlyText = block.children.every((child) => isSpan(context, child))\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n"],"names":["getBlockEndPoint","context","block","isTextBlock","node","lastChild","children","length","path","_key","offset","isSpan","text","isEmptyTextBlock","onlyText","every","child","blockText","getTextBlockText","isEqualSelectionPoints","a","b","JSON","stringify"],"mappings":";;AAQO,SAASA,iBAAiB;AAAA,EAC/BC;AAAAA,EACAC;AAOF,GAAyB;AACvB,MAAIC,
|
|
1
|
+
{"version":3,"file":"util.is-equal-selection-points.cjs","sources":["../../src/utils/util.get-block-end-point.ts","../../src/utils/util.is-empty-text-block.ts","../../src/utils/util.is-equal-selection-points.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n const lastChild = block.node.children[block.node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...block.path, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock,\n) {\n if (!isTextBlock(context, block)) {\n return false\n }\n\n const onlyText = block.children.every((child) => isSpan(context, child))\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n"],"names":["getBlockEndPoint","context","block","isTextBlock","node","lastChild","children","length","path","_key","offset","isSpan","text","isEmptyTextBlock","onlyText","every","child","blockText","getTextBlockText","isEqualSelectionPoints","a","b","JSON","stringify"],"mappings":";;AAQO,SAASA,iBAAiB;AAAA,EAC/BC;AAAAA,EACAC;AAOF,GAAyB;AACvB,MAAIC,2BAAYF,SAASC,MAAME,IAAI,GAAG;AAC9BC,UAAAA,YAAYH,MAAME,KAAKE,SAASJ,MAAME,KAAKE,SAASC,SAAS,CAAC;AAEhEF,QAAAA;AACK,aAAA;AAAA,QACLG,MAAM,CAAC,GAAGN,MAAMM,MAAM,YAAY;AAAA,UAACC,MAAMJ,UAAUI;AAAAA,QAAAA,CAAK;AAAA,QACxDC,QAAQC,eAAOV,SAAAA,SAASI,SAAS,IAAIA,UAAUO,KAAKL,SAAS;AAAA,MAC/D;AAAA,EAAA;AAIG,SAAA;AAAA,IACLC,MAAMN,MAAMM;AAAAA,IACZE,QAAQ;AAAA,EACV;AACF;ACzBgBG,SAAAA,iBACdZ,SACAC,OACA;AACI,MAAA,CAACC,eAAAA,YAAYF,SAASC,KAAK;AACtB,WAAA;AAGT,QAAMY,WAAWZ,MAAMI,SAASS,MAAOC,CAAUL,UAAAA,wBAAOV,SAASe,KAAK,CAAC,GACjEC,YAAYC,eAAAA,iBAAiBhB,KAAK;AAExC,SAAOY,YAAYG,cAAc;AACnC;ACfgBE,SAAAA,uBACdC,GACAC,GACA;AACA,SACED,EAAEV,WAAWW,EAAEX,UAAUY,KAAKC,UAAUH,EAAEZ,IAAI,MAAMc,KAAKC,UAAUF,EAAEb,IAAI;AAE7E;;;;"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var selectionPoint = require("./selection-point.cjs");
|
|
3
3
|
function isTextBlock(context, block) {
|
|
4
|
-
return
|
|
4
|
+
return selectionPoint.isTypedObject(block) && block._type === context.schema.block.name;
|
|
5
5
|
}
|
|
6
6
|
function mergeTextBlocks({
|
|
7
7
|
context,
|
|
8
8
|
targetBlock,
|
|
9
9
|
incomingBlock
|
|
10
10
|
}) {
|
|
11
|
-
const parsedIncomingBlock =
|
|
11
|
+
const parsedIncomingBlock = selectionPoint.parseBlock({
|
|
12
12
|
context,
|
|
13
13
|
block: incomingBlock,
|
|
14
14
|
options: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.merge-text-blocks.cjs","sources":["../../src/utils/util.is-text-block.ts","../../src/utils/util.merge-text-blocks.ts"],"sourcesContent":["import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {isTypedObject} from '../internal-utils/asserters'\n\n/**\n * @public\n */\nexport function isTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextTextBlock {\n return isTypedObject(block) && block._type === context.schema.block.name\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {parseBlock} from '../internal-utils/parse-blocks'\nimport {isTextBlock} from './util.is-text-block'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {refreshKeys: true, validateFields: true},\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n"],"names":["isTextBlock","context","block","isTypedObject","_type","schema","name","mergeTextBlocks","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","options","refreshKeys","validateFields","children","markDefs"],"mappings":";;AAOgBA,SAAAA,YACdC,SACAC,OACgC;AAChC,SAAOC
|
|
1
|
+
{"version":3,"file":"util.merge-text-blocks.cjs","sources":["../../src/utils/util.is-text-block.ts","../../src/utils/util.merge-text-blocks.ts"],"sourcesContent":["import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {isTypedObject} from '../internal-utils/asserters'\n\n/**\n * @public\n */\nexport function isTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextTextBlock {\n return isTypedObject(block) && block._type === context.schema.block.name\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {parseBlock} from '../internal-utils/parse-blocks'\nimport {isTextBlock} from './util.is-text-block'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {refreshKeys: true, validateFields: true},\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n"],"names":["isTextBlock","context","block","isTypedObject","_type","schema","name","mergeTextBlocks","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","options","refreshKeys","validateFields","children","markDefs"],"mappings":";;AAOgBA,SAAAA,YACdC,SACAC,OACgC;AAChC,SAAOC,6BAAcD,KAAK,KAAKA,MAAME,UAAUH,QAAQI,OAAOH,MAAMI;AACtE;ACJO,SAASC,gBAAgB;AAAA,EAC9BN;AAAAA,EACAO;AAAAA,EACAC;AAKF,GAAG;AACD,QAAMC,sBAAsBC,eAAAA,WAAW;AAAA,IACrCV;AAAAA,IACAC,OAAOO;AAAAA,IACPG,SAAS;AAAA,MAACC,aAAa;AAAA,MAAMC,gBAAgB;AAAA,IAAA;AAAA,EAAI,CAClD;AAED,SAAI,CAACJ,uBAAuB,CAACV,YAAYC,SAASS,mBAAmB,IAC5DF,cAGF;AAAA,IACL,GAAGA;AAAAA,IACHO,UAAU,CAAC,GAAGP,YAAYO,UAAU,GAAGL,oBAAoBK,QAAQ;AAAA,IACnEC,UAAU,CACR,GAAIR,YAAYQ,YAAY,CAAA,GAC5B,GAAIN,oBAAoBM,YAAY,CAAG,CAAA;AAAA,EAE3C;AACF;;;"}
|
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
function getSelectionEndPoint(selection) {
|
|
4
|
-
return selection ? selection.backward ? selection.anchor : selection.focus : null;
|
|
5
|
-
}
|
|
6
|
-
function getSelectionStartPoint(selection) {
|
|
7
|
-
return selection ? selection.backward ? selection.focus : selection.anchor : null;
|
|
8
|
-
}
|
|
2
|
+
var selectionPoint = require("./selection-point.cjs"), util_childSelectionPointToBlockOffset = require("./util.child-selection-point-to-block-offset.cjs");
|
|
9
3
|
function isSelectionCollapsed(selection) {
|
|
10
4
|
return selection ? JSON.stringify(selection.anchor.path) === JSON.stringify(selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
|
|
11
5
|
}
|
|
12
6
|
function selectionPointToBlockOffset({
|
|
13
7
|
context,
|
|
14
|
-
selectionPoint
|
|
8
|
+
selectionPoint: selectionPoint$1
|
|
15
9
|
}) {
|
|
16
|
-
|
|
10
|
+
const blockKey = selectionPoint.getBlockKeyFromSelectionPoint(selectionPoint$1);
|
|
11
|
+
return selectionPoint$1.path.length === 1 && blockKey !== void 0 ? {
|
|
17
12
|
path: [{
|
|
18
|
-
_key:
|
|
13
|
+
_key: blockKey
|
|
19
14
|
}],
|
|
20
|
-
offset: selectionPoint.offset
|
|
15
|
+
offset: selectionPoint$1.offset
|
|
21
16
|
} : util_childSelectionPointToBlockOffset.childSelectionPointToBlockOffset({
|
|
22
17
|
context,
|
|
23
|
-
selectionPoint
|
|
18
|
+
selectionPoint: selectionPoint$1
|
|
24
19
|
});
|
|
25
20
|
}
|
|
26
|
-
exports.getSelectionEndPoint = getSelectionEndPoint;
|
|
27
|
-
exports.getSelectionStartPoint = getSelectionStartPoint;
|
|
28
21
|
exports.isSelectionCollapsed = isSelectionCollapsed;
|
|
29
22
|
exports.selectionPointToBlockOffset = selectionPointToBlockOffset;
|
|
30
23
|
//# sourceMappingURL=util.selection-point-to-block-offset.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.selection-point-to-block-offset.cjs","sources":["../../src/utils/util.
|
|
1
|
+
{"version":3,"file":"util.selection-point-to-block-offset.cjs","sources":["../../src/utils/util.is-selection-collapsed.ts","../../src/utils/util.selection-point-to-block-offset.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n JSON.stringify(selection.anchor.path) ===\n JSON.stringify(selection.focus.path) &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n","import type {EditorContext} from '../editor/editor-snapshot'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'\n\n/**\n * @public\n */\nexport function selectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n\n if (selectionPoint.path.length === 1 && blockKey !== undefined) {\n return {\n path: [{_key: blockKey}],\n offset: selectionPoint.offset,\n }\n }\n\n return childSelectionPointToBlockOffset({\n context,\n selectionPoint,\n })\n}\n"],"names":["isSelectionCollapsed","selection","JSON","stringify","anchor","path","focus","offset","selectionPointToBlockOffset","context","selectionPoint","blockKey","getBlockKeyFromSelectionPoint","length","undefined","_key","childSelectionPointToBlockOffset"],"mappings":";;AAKO,SAASA,qBAAqBC,WAA4B;AAC/D,SAAKA,YAKHC,KAAKC,UAAUF,UAAUG,OAAOC,IAAI,MAClCH,KAAKC,UAAUF,UAAUK,MAAMD,IAAI,KACrCJ,UAAUG,OAAOG,WAAWN,UAAUK,MAAMC,SANrC;AAQX;ACNO,SAASC,4BAA4B;AAAA,EAC1CC;AAAAA,EACAC,gBAAAA;AAIF,GAA4B;AACpBC,QAAAA,WAAWC,6CAA8BF,gBAAc;AAE7D,SAAIA,iBAAeL,KAAKQ,WAAW,KAAKF,aAAaG,SAC5C;AAAA,IACLT,MAAM,CAAC;AAAA,MAACU,MAAMJ;AAAAA,IAAAA,CAAS;AAAA,IACvBJ,QAAQG,iBAAeH;AAAAA,MAIpBS,uEAAiC;AAAA,IACtCP;AAAAA,IACAC,gBAAAA;AAAAA,EAAAA,CACD;AACH;;;"}
|
|
@@ -229,9 +229,6 @@ function parseObject({
|
|
|
229
229
|
...values
|
|
230
230
|
};
|
|
231
231
|
}
|
|
232
|
-
function isKeyedSegment(segment) {
|
|
233
|
-
return typeof segment == "object" && segment !== null && "_key" in segment;
|
|
234
|
-
}
|
|
235
232
|
function blockOffsetToSpanSelectionPoint({
|
|
236
233
|
context,
|
|
237
234
|
blockOffset,
|
|
@@ -288,7 +285,7 @@ function spanSelectionPointToBlockOffset({
|
|
|
288
285
|
selectionPoint
|
|
289
286
|
}) {
|
|
290
287
|
let offset = 0;
|
|
291
|
-
const blockKey =
|
|
288
|
+
const blockKey = getBlockKeyFromSelectionPoint(selectionPoint), spanKey = getChildKeyFromSelectionPoint(selectionPoint);
|
|
292
289
|
if (!(!blockKey || !spanKey)) {
|
|
293
290
|
for (const block of context.value)
|
|
294
291
|
if (block._key === blockKey && isTextBlock(context, block)) {
|
|
@@ -320,23 +317,21 @@ function getBlockStartPoint({
|
|
|
320
317
|
offset: 0
|
|
321
318
|
};
|
|
322
319
|
}
|
|
320
|
+
function getSelectionEndPoint(selection) {
|
|
321
|
+
return selection ? selection.backward ? selection.anchor : selection.focus : null;
|
|
322
|
+
}
|
|
323
|
+
function getSelectionStartPoint(selection) {
|
|
324
|
+
return selection ? selection.backward ? selection.focus : selection.anchor : null;
|
|
325
|
+
}
|
|
323
326
|
function getTextBlockText(block) {
|
|
324
327
|
return block.children.map((child) => child.text ?? "").join("");
|
|
325
328
|
}
|
|
329
|
+
function isKeyedSegment(segment) {
|
|
330
|
+
return typeof segment == "object" && segment !== null && "_key" in segment;
|
|
331
|
+
}
|
|
326
332
|
function isSpan(context, child) {
|
|
327
333
|
return child._type === context.schema.span.name;
|
|
328
334
|
}
|
|
329
|
-
function reverseSelection(selection) {
|
|
330
|
-
return selection && (selection.backward ? {
|
|
331
|
-
anchor: selection.focus,
|
|
332
|
-
focus: selection.anchor,
|
|
333
|
-
backward: !1
|
|
334
|
-
} : {
|
|
335
|
-
anchor: selection.focus,
|
|
336
|
-
focus: selection.anchor,
|
|
337
|
-
backward: !0
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
335
|
function sliceBlocks({
|
|
341
336
|
context,
|
|
342
337
|
blocks
|
|
@@ -347,7 +342,7 @@ function sliceBlocks({
|
|
|
347
342
|
let startBlock;
|
|
348
343
|
const middleBlocks = [];
|
|
349
344
|
let endBlock;
|
|
350
|
-
const startPoint = context.selection
|
|
345
|
+
const startPoint = getSelectionStartPoint(context.selection), endPoint = getSelectionEndPoint(context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), startChildKey = getChildKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint), endChildKey = getChildKeyFromSelectionPoint(endPoint);
|
|
351
346
|
if (!startBlockKey || !endBlockKey)
|
|
352
347
|
return slice;
|
|
353
348
|
for (const block of blocks) {
|
|
@@ -425,9 +420,23 @@ function sliceBlocks({
|
|
|
425
420
|
}
|
|
426
421
|
return [...startBlock ? [startBlock] : [], ...middleBlocks, ...endBlock ? [endBlock] : []];
|
|
427
422
|
}
|
|
423
|
+
function getBlockKeyFromSelectionPoint(point) {
|
|
424
|
+
const blockPathSegment = point.path.at(0);
|
|
425
|
+
if (isKeyedSegment(blockPathSegment))
|
|
426
|
+
return blockPathSegment._key;
|
|
427
|
+
}
|
|
428
|
+
function getChildKeyFromSelectionPoint(point) {
|
|
429
|
+
const childPathSegment = point.path.at(2);
|
|
430
|
+
if (isKeyedSegment(childPathSegment))
|
|
431
|
+
return childPathSegment._key;
|
|
432
|
+
}
|
|
428
433
|
export {
|
|
429
434
|
blockOffsetToSpanSelectionPoint,
|
|
435
|
+
getBlockKeyFromSelectionPoint,
|
|
430
436
|
getBlockStartPoint,
|
|
437
|
+
getChildKeyFromSelectionPoint,
|
|
438
|
+
getSelectionEndPoint,
|
|
439
|
+
getSelectionStartPoint,
|
|
431
440
|
getTextBlockText,
|
|
432
441
|
isKeyedSegment,
|
|
433
442
|
isListBlock,
|
|
@@ -441,8 +450,7 @@ export {
|
|
|
441
450
|
parseBlocks,
|
|
442
451
|
parseInlineObject,
|
|
443
452
|
parseTextBlock,
|
|
444
|
-
reverseSelection,
|
|
445
453
|
sliceBlocks,
|
|
446
454
|
spanSelectionPointToBlockOffset
|
|
447
455
|
};
|
|
448
|
-
//# sourceMappingURL=
|
|
456
|
+
//# sourceMappingURL=selection-point.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection-point.js","sources":["../../src/internal-utils/asserters.ts","../../src/internal-utils/parse-blocks.ts","../../src/utils/util.block-offset.ts","../../src/utils/util.get-block-start-point.ts","../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.get-text-block-text.ts","../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.is-span.ts","../../src/utils/util.slice-blocks.ts","../../src/selection/selection-point.ts"],"sourcesContent":["import type {TypedObject} from '@sanity/types'\n\nexport function isTypedObject(object: unknown): object is TypedObject {\n return isRecord(object) && typeof object._type === 'string'\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n","import type {\n PortableTextBlock,\n PortableTextListBlock,\n PortableTextObject,\n PortableTextSpan,\n PortableTextTextBlock,\n TypedObject,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTypedObject} from './asserters'\n\nexport function parseBlocks({\n context,\n blocks,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n blocks: unknown\n options: {\n refreshKeys: boolean\n validateFields: boolean\n }\n}): Array<PortableTextBlock> {\n if (!Array.isArray(blocks)) {\n return []\n }\n\n return blocks.flatMap((block) => {\n const parsedBlock = parseBlock({context, block, options})\n\n return parsedBlock ? [parsedBlock] : []\n })\n}\n\nexport function parseBlock({\n context,\n block,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n block: unknown\n options: {\n refreshKeys: boolean\n validateFields: boolean\n }\n}): PortableTextBlock | undefined {\n return (\n parseTextBlock({block, context, options}) ??\n parseBlockObject({blockObject: block, context, options})\n )\n}\n\nexport function parseBlockObject({\n blockObject,\n context,\n options,\n}: {\n blockObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(blockObject)) {\n return undefined\n }\n\n const schemaType = context.schema.blockObjects.find(\n ({name}) => name === blockObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: blockObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function isListBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextListBlock {\n return (\n isTextBlock(context, block) &&\n block.level !== undefined &&\n block.listItem !== undefined\n )\n}\n\nexport function isTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextTextBlock {\n return (\n parseTextBlock({\n block,\n context: {schema: context.schema, keyGenerator: () => ''},\n options: {refreshKeys: false, validateFields: false},\n }) !== undefined\n )\n}\n\nexport function parseTextBlock({\n block,\n context,\n options,\n}: {\n block: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextTextBlock | undefined {\n if (!isTypedObject(block)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(block)) {\n if (\n key !== '_type' &&\n key !== '_key' &&\n key !== 'children' &&\n key !== 'markDefs' &&\n key !== 'style' &&\n key !== 'listItem' &&\n key !== 'level'\n ) {\n customFields[key] = block[key]\n }\n }\n\n if (block._type !== context.schema.block.name) {\n return undefined\n }\n\n const _key = options.refreshKeys\n ? context.keyGenerator()\n : typeof block._key === 'string'\n ? block._key\n : context.keyGenerator()\n\n const unparsedMarkDefs: Array<unknown> = Array.isArray(block.markDefs)\n ? block.markDefs\n : []\n const markDefKeyMap = new Map<string, string>()\n const markDefs = unparsedMarkDefs.flatMap((markDef) => {\n if (!isTypedObject(markDef)) {\n return []\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === markDef._type,\n )\n\n if (!schemaType) {\n return []\n }\n\n if (typeof markDef._key !== 'string') {\n // If the `markDef` doesn't have a `_key` then we don't know what spans\n // it belongs to and therefore we have to discard it.\n return []\n }\n\n const parsedAnnotation = parseObject({\n object: markDef,\n context: {\n schemaType,\n keyGenerator: context.keyGenerator,\n },\n options,\n })\n\n if (!parsedAnnotation) {\n return []\n }\n\n markDefKeyMap.set(markDef._key, parsedAnnotation._key)\n\n return [parsedAnnotation]\n })\n\n const unparsedChildren: Array<unknown> = Array.isArray(block.children)\n ? block.children\n : []\n\n const children = unparsedChildren\n .map(\n (child) =>\n parseSpan({span: child, context, markDefKeyMap, options}) ??\n parseInlineObject({inlineObject: child, context, options}),\n )\n .filter((child) => child !== undefined)\n\n const parsedBlock: PortableTextTextBlock = {\n _type: context.schema.block.name,\n _key,\n children:\n children.length > 0\n ? children\n : [\n {\n _key: context.keyGenerator(),\n _type: context.schema.span.name,\n text: '',\n marks: [],\n },\n ],\n markDefs,\n ...(options.validateFields ? {} : customFields),\n }\n\n if (\n typeof block.style === 'string' &&\n context.schema.styles.find((style) => style.name === block.style)\n ) {\n parsedBlock.style = block.style\n } else {\n const defaultStyle = context.schema.styles.at(0)?.name\n\n if (defaultStyle !== undefined) {\n parsedBlock.style = defaultStyle\n } else {\n console.error('Expected default style')\n }\n }\n\n if (\n typeof block.listItem === 'string' &&\n context.schema.lists.find((list) => list.name === block.listItem)\n ) {\n parsedBlock.listItem = block.listItem\n }\n\n if (typeof block.level === 'number') {\n parsedBlock.level = block.level\n }\n\n return parsedBlock\n}\n\nexport function isSpan(\n context: Pick<EditorContext, 'schema'>,\n child: unknown,\n): child is PortableTextSpan {\n return (\n parseSpan({\n span: child,\n markDefKeyMap: new Map(),\n context: {schema: context.schema, keyGenerator: () => ''},\n options: {refreshKeys: false, validateFields: false},\n }) !== undefined\n )\n}\n\nexport function parseSpan({\n span,\n context,\n markDefKeyMap,\n options,\n}: {\n span: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n markDefKeyMap: Map<string, string>\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextSpan | undefined {\n if (!isTypedObject(span)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(span)) {\n if (\n key !== '_type' &&\n key !== '_key' &&\n key !== 'text' &&\n key !== 'marks'\n ) {\n customFields[key] = span[key]\n }\n }\n\n // In reality, the span schema name is always 'span', but we only the check here anyway\n if (span._type !== context.schema.span.name || span._type !== 'span') {\n return undefined\n }\n\n const unparsedMarks: Array<unknown> = Array.isArray(span.marks)\n ? span.marks\n : []\n const marks = unparsedMarks.flatMap((mark) => {\n if (typeof mark !== 'string') {\n return []\n }\n\n const markDefKey = markDefKeyMap.get(mark)\n\n if (markDefKey !== undefined) {\n return [markDefKey]\n }\n\n if (\n context.schema.decorators.some((decorator) => decorator.name === mark)\n ) {\n return [mark]\n }\n\n return []\n })\n\n return {\n _type: 'span',\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof span._key === 'string'\n ? span._key\n : context.keyGenerator(),\n text: typeof span.text === 'string' ? span.text : '',\n marks,\n ...(options.validateFields ? {} : customFields),\n }\n}\n\nexport function parseInlineObject({\n inlineObject,\n context,\n options,\n}: {\n inlineObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(inlineObject)) {\n return undefined\n }\n\n const schemaType = context.schema.inlineObjects.find(\n ({name}) => name === inlineObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: inlineObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function parseAnnotation({\n annotation,\n context,\n options,\n}: {\n annotation: TypedObject\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(annotation)) {\n return undefined\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === annotation._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: annotation,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nfunction parseObject({\n object,\n context,\n options,\n}: {\n object: TypedObject\n context: Pick<EditorContext, 'keyGenerator'> & {\n schemaType: EditorSchema['blockObjects'][0]\n }\n options: {refreshKeys: boolean; validateFields: boolean}\n}): PortableTextObject {\n const {_type, _key, ...customFields} = object\n\n // Validates all props on the object and only takes those that match\n // the name of a field\n const values = options.validateFields\n ? context.schemaType.fields.reduce<Record<string, unknown>>(\n (fieldValues, field) => {\n const fieldValue = object[field.name]\n\n if (fieldValue !== undefined) {\n fieldValues[field.name] = fieldValue\n }\n\n return fieldValues\n },\n {},\n )\n : customFields\n\n return {\n _type: context.schemaType.name,\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof object._key === 'string'\n ? object._key\n : context.keyGenerator(),\n ...values,\n }\n}\n","import type {KeyedSegment} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n context,\n blockOffset,\n direction,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint:\n | {path: [KeyedSegment, 'children', KeyedSegment]; offset: number}\n | undefined\n let skippedInlineObject = false\n\n for (const block of context.value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (direction === 'forward') {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n\n continue\n }\n\n if (!isSpan(context, child)) {\n skippedInlineObject = true\n continue\n }\n\n if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {\n if (skippedInlineObject) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n }\n break\n }\n\n if (offsetLeft > child.text.length) {\n offsetLeft -= child.text.length\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n\n offsetLeft -= child.text.length\n\n if (offsetLeft !== 0) {\n break\n }\n }\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n const spanKey = getChildKeyFromSelectionPoint(selectionPoint)\n\n if (!blockKey || !spanKey) {\n return undefined\n }\n\n for (const block of context.value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (child._key === spanKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n return {\n path: [...block.path, 'children', {_key: block.node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionStartPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.focus : selection.anchor\n ) as TEditorSelectionPoint\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","import type {KeyedSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: unknown): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {PortableTextChild, PortableTextSpan} from '@sanity/types'\nimport type {EditorContext} from '..'\n\n/**\n * @public\n */\nexport function isSpan(\n context: Pick<EditorContext, 'schema'>,\n child: PortableTextChild,\n): child is PortableTextSpan {\n return child._type === context.schema.span.name\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport {getSelectionEndPoint, getSelectionStartPoint} from '../utils'\n\n/**\n * @public\n */\nexport function sliceBlocks({\n context,\n blocks,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n blocks: Array<PortableTextBlock>\n}): Array<PortableTextBlock> {\n const slice: Array<PortableTextBlock> = []\n\n if (!context.selection) {\n return slice\n }\n\n let startBlock: PortableTextBlock | undefined\n const middleBlocks: PortableTextBlock[] = []\n let endBlock: PortableTextBlock | undefined\n\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return slice\n }\n\n for (const block of blocks) {\n if (!isTextBlock(context, block)) {\n if (block._key === startBlockKey && block._key === endBlockKey) {\n startBlock = block\n break\n }\n }\n\n if (block._key === startBlockKey) {\n if (!isTextBlock(context, block)) {\n startBlock = block\n continue\n }\n\n if (startChildKey) {\n for (const child of block.children) {\n if (child._key === startChildKey) {\n if (isSpan(context, child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n startBlock = {\n ...block,\n children: [\n {\n ...child,\n text,\n },\n ],\n }\n } else {\n startBlock = {\n ...block,\n children: [child],\n }\n }\n\n if (startChildKey === endChildKey) {\n break\n }\n continue\n }\n\n if (startBlock && isTextBlock(context, startBlock)) {\n if (\n endChildKey &&\n child._key === endChildKey &&\n isSpan(context, child)\n ) {\n startBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n startBlock.children.push(child)\n }\n\n if (\n block._key === endBlockKey &&\n endChildKey &&\n child._key === endChildKey\n ) {\n break\n }\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n startBlock = block\n\n if (startBlockKey === endBlockKey) {\n break\n }\n }\n\n if (block._key === endBlockKey) {\n if (!isTextBlock(context, block)) {\n endBlock = block\n break\n }\n\n if (endChildKey) {\n endBlock = {\n ...block,\n children: [],\n }\n\n for (const child of block.children) {\n if (endBlock && isTextBlock(context, endBlock)) {\n if (child._key === endChildKey && isSpan(context, child)) {\n endBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n\n break\n }\n\n endBlock.children.push(child)\n\n if (endChildKey && child._key === endChildKey) {\n break\n }\n }\n }\n\n break\n }\n\n endBlock = block\n\n break\n }\n\n if (startBlock) {\n middleBlocks.push(block)\n }\n }\n\n return [\n ...(startBlock ? [startBlock] : []),\n ...middleBlocks,\n ...(endBlock ? [endBlock] : []),\n ]\n}\n","import type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from '../utils'\n\nexport function getBlockKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const blockPathSegment = point.path.at(0)\n\n if (isKeyedSegment(blockPathSegment)) {\n return blockPathSegment._key\n }\n\n return undefined\n}\n\nexport function getChildKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const childPathSegment = point.path.at(2)\n\n if (isKeyedSegment(childPathSegment)) {\n return childPathSegment._key\n }\n\n return undefined\n}\n"],"names":["isTypedObject","object","isRecord","_type","value","parseBlocks","context","blocks","options","Array","isArray","flatMap","block","parsedBlock","parseBlock","parseTextBlock","parseBlockObject","blockObject","schemaType","schema","blockObjects","find","name","parseObject","keyGenerator","isListBlock","isTextBlock","level","undefined","listItem","refreshKeys","validateFields","customFields","key","Object","keys","_key","unparsedMarkDefs","markDefs","markDefKeyMap","Map","markDef","annotations","parsedAnnotation","set","children","map","child","parseSpan","span","parseInlineObject","inlineObject","filter","length","text","marks","style","styles","defaultStyle","at","console","error","lists","list","isSpan","mark","markDefKey","get","decorators","some","decorator","inlineObjects","parseAnnotation","annotation","values","fields","reduce","fieldValues","field","fieldValue","blockOffsetToSpanSelectionPoint","blockOffset","direction","offsetLeft","offset","selectionPoint","skippedInlineObject","path","spanSelectionPointToBlockOffset","blockKey","getBlockKeyFromSelectionPoint","spanKey","getChildKeyFromSelectionPoint","getBlockStartPoint","node","getSelectionEndPoint","selection","backward","anchor","focus","getSelectionStartPoint","getTextBlockText","join","isKeyedSegment","segment","sliceBlocks","slice","startBlock","middleBlocks","endBlock","startPoint","endPoint","startBlockKey","startChildKey","endBlockKey","endChildKey","push","point","blockPathSegment","childPathSegment"],"mappings":"AAEO,SAASA,cAAcC,QAAwC;AACpE,SAAOC,SAASD,MAAM,KAAK,OAAOA,OAAOE,SAAU;AACrD;AAEA,SAASD,SAASE,OAAkD;AAClE,SAAO,CAAC,CAACA,UAAU,OAAOA,SAAU,YAAY,OAAOA,SAAU;AACnE;ACIO,SAASC,YAAY;AAAA,EAC1BC;AAAAA,EACAC;AAAAA,EACAC;AAQF,GAA6B;AAC3B,SAAKC,MAAMC,QAAQH,MAAM,IAIlBA,OAAOI,QAASC,CAAU,UAAA;AAC/B,UAAMC,cAAcC,WAAW;AAAA,MAACR;AAAAA,MAASM;AAAAA,MAAOJ;AAAAA,IAAAA,CAAQ;AAExD,WAAOK,cAAc,CAACA,WAAW,IAAI,CAAE;AAAA,EACxC,CAAA,IAPQ,CAAE;AAQb;AAEO,SAASC,WAAW;AAAA,EACzBR;AAAAA,EACAM;AAAAA,EACAJ;AAQF,GAAkC;AAChC,SACEO,eAAe;AAAA,IAACH;AAAAA,IAAON;AAAAA,IAASE;AAAAA,E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BAAAA;AAEX;AAAA,IAAA;AAGE+F,kBACFC,aAAaQ,KAAKxG,KAAK;AAAA,EAAA;AAI3B,SAAO,CACL,GAAI+F,aAAa,CAACA,UAAU,IAAI,CAAA,GAChC,GAAGC,cACH,GAAIC,WAAW,CAACA,QAAQ,IAAI,CAAA,CAAG;AAEnC;ACzKO,SAASnB,8BAA8B2B,OAA6B;AACzE,QAAMC,mBAAmBD,MAAM9B,KAAK5B,GAAG,CAAC;AAExC,MAAI4C,eAAee,gBAAgB;AACjC,WAAOA,iBAAiBlF;AAI5B;AAEO,SAASwD,8BAA8ByB,OAA6B;AACzE,QAAME,mBAAmBF,MAAM9B,KAAK5B,GAAG,CAAC;AAExC,MAAI4C,eAAegB,gBAAgB;AACjC,WAAOA,iBAAiBnF;AAI5B;"}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getSelectionText } from "./selector.is-selection-expanded.js";
|
|
1
|
+
import { getSelectionStartPoint, getBlockStartPoint } from "./selection-point.js";
|
|
2
|
+
import { getFocusBlock, getSelectionText } from "./selector.is-selection-expanded.js";
|
|
3
3
|
const getBlockTextBefore = (snapshot) => {
|
|
4
4
|
if (!snapshot.context.selection)
|
|
5
5
|
return "";
|
|
6
|
-
const
|
|
6
|
+
const startPoint = getSelectionStartPoint(snapshot.context.selection), block = getFocusBlock({
|
|
7
|
+
context: {
|
|
8
|
+
...snapshot.context,
|
|
9
|
+
selection: {
|
|
10
|
+
anchor: startPoint,
|
|
11
|
+
focus: startPoint
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
7
15
|
if (!block)
|
|
8
16
|
return "";
|
|
9
17
|
const startOfBlock = getBlockStartPoint({
|
|
10
18
|
context: snapshot.context,
|
|
11
|
-
block
|
|
12
|
-
node: block,
|
|
13
|
-
path: [{
|
|
14
|
-
_key: block._key
|
|
15
|
-
}]
|
|
16
|
-
}
|
|
19
|
+
block
|
|
17
20
|
});
|
|
18
21
|
return getSelectionText({
|
|
19
22
|
context: {
|
|
20
23
|
...snapshot.context,
|
|
21
24
|
selection: {
|
|
22
25
|
anchor: startOfBlock,
|
|
23
|
-
focus:
|
|
26
|
+
focus: startPoint
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector.get-text-before.js","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {
|
|
1
|
+
{"version":3,"file":"selector.get-text-before.js","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionStartPoint} from '../utils'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getSelectionText} from './selector.get-selection-text'\nimport {getFocusBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n"],"names":["getBlockTextBefore","snapshot","context","selection","startPoint","getSelectionStartPoint","block","getFocusBlock","anchor","focus","startOfBlock","getBlockStartPoint","getSelectionText"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAa,aAAA;AAClE,MAAA,CAACA,SAASC,QAAQC;AACb,WAAA;AAGT,QAAMC,aAAaC,uBAAuBJ,SAASC,QAAQC,SAAS,GAC9DG,QAAQC,cAAc;AAAA,IAE1BL,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQJ;AAAAA,QACRK,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AAED,MAAI,CAACE;AACI,WAAA;AAGT,QAAMI,eAAeC,mBAAmB;AAAA,IACtCT,SAASD,SAASC;AAAAA,IAClBI;AAAAA,EAAAA,CACD;AAED,SAAOM,iBAAiB;AAAA,IAEtBV,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQE;AAAAA,QACRD,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import { isTextBlock, isSpan$1 as isSpan,
|
|
2
|
-
import { getSelectedBlocks, getFocusSpan, isSelectionCollapsed, getFocusTextBlock,
|
|
1
|
+
import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, isTextBlock, isSpan$1 as isSpan, isSpan as isSpan$1, spanSelectionPointToBlockOffset, getBlockStartPoint, blockOffsetToSpanSelectionPoint, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1 } from "./selection-point.js";
|
|
2
|
+
import { getSelectionStartPoint, getSelectedBlocks, getFocusSpan, isSelectionCollapsed, getFocusTextBlock, getPreviousInlineObject, getSelectionText, isSelectionExpanded, getFocusChild, getSelectionStartBlock, getSelectionEndBlock } from "./selector.is-selection-expanded.js";
|
|
3
3
|
import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./util.is-equal-selection-points.js";
|
|
4
4
|
import { isKeySegment, isPortableTextSpan } from "@sanity/types";
|
|
5
|
-
const
|
|
5
|
+
const getSelectionEndPoint = (snapshot) => {
|
|
6
|
+
if (snapshot.context.selection)
|
|
7
|
+
return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
|
|
8
|
+
}, getSelectedSpans = (snapshot) => {
|
|
6
9
|
if (!snapshot.context.selection)
|
|
7
10
|
return [];
|
|
8
|
-
const selectedSpans = [], startPoint = snapshot
|
|
11
|
+
const selectedSpans = [], startPoint = getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
|
|
12
|
+
if (!startPoint || !endPoint)
|
|
13
|
+
return selectedSpans;
|
|
14
|
+
const startBlockKey = getBlockKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
9
15
|
if (!startBlockKey || !endBlockKey)
|
|
10
16
|
return selectedSpans;
|
|
11
|
-
const startSpanKey =
|
|
17
|
+
const startSpanKey = getChildKeyFromSelectionPoint(startPoint), endSpanKey = getChildKeyFromSelectionPoint(endPoint);
|
|
12
18
|
let startBlockFound = !1;
|
|
13
19
|
for (const block of snapshot.context.value)
|
|
14
20
|
if (block._key === startBlockKey && (startBlockFound = !0), !!isTextBlock(snapshot.context, block)) {
|
|
@@ -120,9 +126,6 @@ const getSelectedSpans = (snapshot) => {
|
|
|
120
126
|
const firstStyle = firstTextBlock.style;
|
|
121
127
|
if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
|
|
122
128
|
return firstStyle;
|
|
123
|
-
}, getSelectionEndPoint = (snapshot) => {
|
|
124
|
-
if (snapshot.context.selection)
|
|
125
|
-
return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
|
|
126
129
|
}, getNextInlineObject = (snapshot) => {
|
|
127
130
|
const focusTextBlock = getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
|
|
128
131
|
if (!focusTextBlock || !selectionEndPointChildKey)
|
|
@@ -220,21 +223,21 @@ const getSelectedSpans = (snapshot) => {
|
|
|
220
223
|
}, getSelectedTextBlocks = (snapshot) => {
|
|
221
224
|
if (!snapshot.context.selection)
|
|
222
225
|
return [];
|
|
223
|
-
const selectedTextBlocks = [],
|
|
224
|
-
if (!
|
|
226
|
+
const selectedTextBlocks = [], startPoint = getSelectionStartPoint$1(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
227
|
+
if (!startBlockKey || !endBlockKey)
|
|
225
228
|
return selectedTextBlocks;
|
|
226
229
|
for (const block of snapshot.context.value) {
|
|
227
|
-
if (block._key ===
|
|
230
|
+
if (block._key === startBlockKey) {
|
|
228
231
|
if (isTextBlock(snapshot.context, block) && selectedTextBlocks.push({
|
|
229
232
|
node: block,
|
|
230
233
|
path: [{
|
|
231
234
|
_key: block._key
|
|
232
235
|
}]
|
|
233
|
-
}),
|
|
236
|
+
}), startBlockKey === endBlockKey)
|
|
234
237
|
break;
|
|
235
238
|
continue;
|
|
236
239
|
}
|
|
237
|
-
if (block._key ===
|
|
240
|
+
if (block._key === endBlockKey) {
|
|
238
241
|
isTextBlock(snapshot.context, block) && selectedTextBlocks.push({
|
|
239
242
|
node: block,
|
|
240
243
|
path: [{
|
|
@@ -254,10 +257,7 @@ const getSelectedSpans = (snapshot) => {
|
|
|
254
257
|
}, getTrimmedSelection = (snapshot) => {
|
|
255
258
|
if (!snapshot.context.selection)
|
|
256
259
|
return snapshot.context.selection;
|
|
257
|
-
const startPoint = getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
|
|
258
|
-
if (!startPoint || !endPoint)
|
|
259
|
-
return snapshot.context.selection;
|
|
260
|
-
const startBlockKey = isKeyedSegment(startPoint.path[0]) ? startPoint.path[0]._key : null, startChildKey = isKeyedSegment(startPoint.path[2]) ? startPoint.path[2]._key : null, endBlockKey = isKeyedSegment(endPoint.path[0]) ? endPoint.path[0]._key : null, endChildKey = isKeyedSegment(endPoint.path[2]) ? endPoint.path[2]._key : null;
|
|
260
|
+
const startPoint = getSelectionStartPoint$1(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), startChildKey = getChildKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint), endChildKey = getChildKeyFromSelectionPoint(endPoint);
|
|
261
261
|
if (!startBlockKey || !endBlockKey)
|
|
262
262
|
return snapshot.context.selection;
|
|
263
263
|
let startBlockFound = !1, adjustedStartPoint, trimStartPoint = !1, adjustedEndPoint, trimEndPoint = !1, previousPotentialEndpoint;
|
|
@@ -382,7 +382,7 @@ function isPointAfterSelection(point) {
|
|
|
382
382
|
return (snapshot) => {
|
|
383
383
|
if (!snapshot.context.selection)
|
|
384
384
|
return !1;
|
|
385
|
-
const
|
|
385
|
+
const endPoint = getSelectionEndPoint$1(snapshot.context.selection), endBlockKey = getBlockKeyFromSelectionPoint(endPoint), endChildKey = getChildKeyFromSelectionPoint(endPoint), pointBlockKey = getBlockKeyFromSelectionPoint(point), pointChildKey = getChildKeyFromSelectionPoint(point);
|
|
386
386
|
if (!pointBlockKey || !endBlockKey)
|
|
387
387
|
return !1;
|
|
388
388
|
let after = !1;
|
|
@@ -400,7 +400,7 @@ function isPointAfterSelection(point) {
|
|
|
400
400
|
after = !0;
|
|
401
401
|
break;
|
|
402
402
|
}
|
|
403
|
-
after = point.offset >
|
|
403
|
+
after = point.offset > endPoint.offset;
|
|
404
404
|
break;
|
|
405
405
|
}
|
|
406
406
|
if (child._key === pointChildKey)
|
|
@@ -417,7 +417,7 @@ function isPointBeforeSelection(point) {
|
|
|
417
417
|
return (snapshot) => {
|
|
418
418
|
if (!snapshot.context.selection)
|
|
419
419
|
return !1;
|
|
420
|
-
const
|
|
420
|
+
const startPoint = getSelectionStartPoint$1(snapshot.context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), startChildKey = getChildKeyFromSelectionPoint(startPoint), pointBlockKey = getBlockKeyFromSelectionPoint(point), pointChildKey = getChildKeyFromSelectionPoint(point);
|
|
421
421
|
if (!pointBlockKey || !startBlockKey)
|
|
422
422
|
return !1;
|
|
423
423
|
let before = !1;
|
|
@@ -435,7 +435,7 @@ function isPointBeforeSelection(point) {
|
|
|
435
435
|
before = !0;
|
|
436
436
|
break;
|
|
437
437
|
}
|
|
438
|
-
before = point.offset <
|
|
438
|
+
before = point.offset < startPoint.offset;
|
|
439
439
|
break;
|
|
440
440
|
}
|
|
441
441
|
if (child._key === startChildKey)
|