@portabletext/editor 1.40.4 → 1.41.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.
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
3
  var util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), util_selectionPointToBlockOffset = require("../_chunks-cjs/util.selection-point-to-block-offset.cjs"), util_isSelectionCollapsed = require("../_chunks-cjs/util.is-selection-collapsed.cjs"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
4
+ function getSelectionStartPoint(selection) {
5
+ return selection ? selection.backward ? selection.focus : selection.anchor : null;
6
+ }
4
7
  function isEqualSelections(a, b) {
5
8
  return !a && !b ? !0 : !a || !b ? !1 : util_sliceBlocks.isEqualSelectionPoints(a.anchor, b.anchor) && util_sliceBlocks.isEqualSelectionPoints(a.focus, b.focus);
6
9
  }
@@ -61,9 +64,11 @@ exports.blockOffsetToSelectionPoint = util_selectionPointToBlockOffset.blockOffs
61
64
  exports.blockOffsetsToSelection = util_selectionPointToBlockOffset.blockOffsetsToSelection;
62
65
  exports.childSelectionPointToBlockOffset = util_selectionPointToBlockOffset.childSelectionPointToBlockOffset;
63
66
  exports.selectionPointToBlockOffset = util_selectionPointToBlockOffset.selectionPointToBlockOffset;
67
+ exports.getSelectionEndPoint = util_isSelectionCollapsed.getSelectionEndPoint;
64
68
  exports.isSelectionCollapsed = util_isSelectionCollapsed.isSelectionCollapsed;
65
69
  exports.isTextBlock = util_mergeTextBlocks.isTextBlock;
66
70
  exports.mergeTextBlocks = util_mergeTextBlocks.mergeTextBlocks;
71
+ exports.getSelectionStartPoint = getSelectionStartPoint;
67
72
  exports.isEqualSelections = isEqualSelections;
68
73
  exports.splitTextBlock = splitTextBlock;
69
74
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n }).at(0)\n const after = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","blocks","selection","path","_key","offset","after","isSpan","text","isTextBlock"],"mappings":";;;AAMgBA,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,iBAAAA,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,wCAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACTO,SAASC,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAEzD,MAAA,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,iBAAAA,YAAY;AAAA,IACzBC,QAAQ,CAACT,KAAK;AAAA,IACdU,WAAW;AAAA,MACTd,QAAQ;AAAA,QACNe,MAAM,CAAC;AAAA,UAACC,MAAMZ,MAAMY;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMV,WAAWU;AAAAA,QAAAA,CAAK;AAAA,QAC9DC,QAAQ;AAAA,MACV;AAAA,MACAhB,OAAOI;AAAAA,IAAAA;AAAAA,EAEV,CAAA,EAAEG,GAAG,CAAC,GACDU,QAAQN,iBAAAA,YAAY;AAAA,IACxBC,QAAQ,CAACT,KAAK;AAAA,IACdU,WAAW;AAAA,MACTd,QAAQK;AAAAA,MACRJ,OAAO;AAAA,QACLc,MAAM,CAAC;AAAA,UAACC,MAAMZ,MAAMY;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMP,UAAUO;AAAAA,QAAAA,CAAK;AAAA,QAC7DC,QAAQE,iBAAOhB,OAAAA,SAASM,SAAS,IAAIA,UAAUW,KAAKV,SAAS;AAAA,MAAA;AAAA,IAC/D;AAAA,EACF,CACD,EAAEF,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACO,UAIZ,EAACG,CAAAA,qBAAAA,YAAYlB,SAASQ,MAAM,KAAK,CAACU,qBAAYlB,YAAAA,SAASe,KAAK;AAIzD,WAAA;AAAA,MAACP;AAAAA,MAAQO;AAAAA,IAAK;AACvB;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["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 {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n }).at(0)\n const after = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["getSelectionStartPoint","selection","backward","focus","anchor","isEqualSelections","a","b","isEqualSelectionPoints","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","blocks","path","_key","offset","after","isSpan","text","isTextBlock"],"mappings":";;;AAKO,SAASA,uBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,QAAQF,UAAUG,SAJ1C;AAMX;ACbgBC,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,iBAAAA,uBAAuBF,EAAEF,QAAQG,EAAEH,MAAM,KACzCI,wCAAuBF,EAAEH,OAAOI,EAAEJ,KAAK;AAE3C;ACTO,SAASM,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAEzD,MAAA,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,iBAAAA,YAAY;AAAA,IACzBC,QAAQ,CAACT,KAAK;AAAA,IACdV,WAAW;AAAA,MACTG,QAAQ;AAAA,QACNiB,MAAM,CAAC;AAAA,UAACC,MAAMX,MAAMW;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMT,WAAWS;AAAAA,QAAAA,CAAK;AAAA,QAC9DC,QAAQ;AAAA,MACV;AAAA,MACApB,OAAOS;AAAAA,IAAAA;AAAAA,EAEV,CAAA,EAAEG,GAAG,CAAC,GACDS,QAAQL,iBAAAA,YAAY;AAAA,IACxBC,QAAQ,CAACT,KAAK;AAAA,IACdV,WAAW;AAAA,MACTG,QAAQQ;AAAAA,MACRT,OAAO;AAAA,QACLkB,MAAM,CAAC;AAAA,UAACC,MAAMX,MAAMW;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMN,UAAUM;AAAAA,QAAAA,CAAK;AAAA,QAC7DC,QAAQE,iBAAOf,OAAAA,SAASM,SAAS,IAAIA,UAAUU,KAAKT,SAAS;AAAA,MAAA;AAAA,IAC/D;AAAA,EACF,CACD,EAAEF,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACM,UAIZ,EAACG,CAAAA,qBAAAA,YAAYjB,SAASQ,MAAM,KAAK,CAACS,qBAAYjB,YAAAA,SAASc,KAAK;AAIzD,WAAA;AAAA,MAACN;AAAAA,MAAQM;AAAAA,IAAK;AACvB;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -22048,6 +22048,28 @@ export declare function getBlockStartPoint({
22048
22048
  path: [KeyedSegment]
22049
22049
  }): EditorSelectionPoint
22050
22050
 
22051
+ /**
22052
+ * @public
22053
+ */
22054
+ export declare function getSelectionEndPoint<
22055
+ TEditorSelection extends NonNullable<EditorSelection> | null,
22056
+ TEditorSelectionPoint extends
22057
+ EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>
22058
+ ? EditorSelectionPoint
22059
+ : null,
22060
+ >(selection: TEditorSelection): TEditorSelectionPoint
22061
+
22062
+ /**
22063
+ * @public
22064
+ */
22065
+ export declare function getSelectionStartPoint<
22066
+ TEditorSelection extends NonNullable<EditorSelection> | null,
22067
+ TEditorSelectionPoint extends
22068
+ EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>
22069
+ ? EditorSelectionPoint
22070
+ : null,
22071
+ >(selection: TEditorSelection): TEditorSelectionPoint
22072
+
22051
22073
  /**
22052
22074
  * @public
22053
22075
  */
@@ -22048,6 +22048,28 @@ export declare function getBlockStartPoint({
22048
22048
  path: [KeyedSegment]
22049
22049
  }): EditorSelectionPoint
22050
22050
 
22051
+ /**
22052
+ * @public
22053
+ */
22054
+ export declare function getSelectionEndPoint<
22055
+ TEditorSelection extends NonNullable<EditorSelection> | null,
22056
+ TEditorSelectionPoint extends
22057
+ EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>
22058
+ ? EditorSelectionPoint
22059
+ : null,
22060
+ >(selection: TEditorSelection): TEditorSelectionPoint
22061
+
22062
+ /**
22063
+ * @public
22064
+ */
22065
+ export declare function getSelectionStartPoint<
22066
+ TEditorSelection extends NonNullable<EditorSelection> | null,
22067
+ TEditorSelectionPoint extends
22068
+ EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>
22069
+ ? EditorSelectionPoint
22070
+ : null,
22071
+ >(selection: TEditorSelection): TEditorSelectionPoint
22072
+
22051
22073
  /**
22052
22074
  * @public
22053
22075
  */
@@ -1,9 +1,12 @@
1
1
  import { isEqualSelectionPoints, sliceBlocks, isSpan } from "../_chunks-es/util.slice-blocks.js";
2
2
  import { blockOffsetToSpanSelectionPoint, getBlockEndPoint, getBlockStartPoint, getTextBlockText, isEmptyTextBlock, isKeyedSegment, reverseSelection, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
3
3
  import { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset, selectionPointToBlockOffset } from "../_chunks-es/util.selection-point-to-block-offset.js";
4
- import { isSelectionCollapsed } from "../_chunks-es/util.is-selection-collapsed.js";
4
+ import { getSelectionEndPoint, isSelectionCollapsed } from "../_chunks-es/util.is-selection-collapsed.js";
5
5
  import { isTextBlock } from "../_chunks-es/util.merge-text-blocks.js";
6
6
  import { mergeTextBlocks } from "../_chunks-es/util.merge-text-blocks.js";
7
+ function getSelectionStartPoint(selection) {
8
+ return selection ? selection.backward ? selection.focus : selection.anchor : null;
9
+ }
7
10
  function isEqualSelections(a, b) {
8
11
  return !a && !b ? !0 : !a || !b ? !1 : isEqualSelectionPoints(a.anchor, b.anchor) && isEqualSelectionPoints(a.focus, b.focus);
9
12
  }
@@ -56,6 +59,8 @@ export {
56
59
  childSelectionPointToBlockOffset,
57
60
  getBlockEndPoint,
58
61
  getBlockStartPoint,
62
+ getSelectionEndPoint,
63
+ getSelectionStartPoint,
59
64
  getTextBlockText,
60
65
  isEmptyTextBlock,
61
66
  isEqualSelectionPoints,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n }).at(0)\n const after = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","blocks","selection","path","_key","offset","after","isSpan","text","isTextBlock"],"mappings":";;;;;;AAMgBA,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACTO,SAASC,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAEzD,MAAA,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,YAAY;AAAA,IACzBC,QAAQ,CAACT,KAAK;AAAA,IACdU,WAAW;AAAA,MACTd,QAAQ;AAAA,QACNe,MAAM,CAAC;AAAA,UAACC,MAAMZ,MAAMY;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMV,WAAWU;AAAAA,QAAAA,CAAK;AAAA,QAC9DC,QAAQ;AAAA,MACV;AAAA,MACAhB,OAAOI;AAAAA,IAAAA;AAAAA,EAEV,CAAA,EAAEG,GAAG,CAAC,GACDU,QAAQN,YAAY;AAAA,IACxBC,QAAQ,CAACT,KAAK;AAAA,IACdU,WAAW;AAAA,MACTd,QAAQK;AAAAA,MACRJ,OAAO;AAAA,QACLc,MAAM,CAAC;AAAA,UAACC,MAAMZ,MAAMY;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMP,UAAUO;AAAAA,QAAAA,CAAK;AAAA,QAC7DC,QAAQE,OAAOhB,SAASM,SAAS,IAAIA,UAAUW,KAAKV,SAAS;AAAA,MAAA;AAAA,IAC/D;AAAA,EACF,CACD,EAAEF,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACO,UAIZ,EAACG,CAAAA,YAAYlB,SAASQ,MAAM,KAAK,CAACU,YAAYlB,SAASe,KAAK;AAIzD,WAAA;AAAA,MAACP;AAAAA,MAAQO;AAAAA,IAAK;AACvB;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["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 {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n }).at(0)\n const after = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["getSelectionStartPoint","selection","backward","focus","anchor","isEqualSelections","a","b","isEqualSelectionPoints","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","blocks","path","_key","offset","after","isSpan","text","isTextBlock"],"mappings":";;;;;;AAKO,SAASA,uBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,QAAQF,UAAUG,SAJ1C;AAMX;ACbgBC,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,uBAAuBF,EAAEF,QAAQG,EAAEH,MAAM,KACzCI,uBAAuBF,EAAEH,OAAOI,EAAEJ,KAAK;AAE3C;ACTO,SAASM,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAEzD,MAAA,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,YAAY;AAAA,IACzBC,QAAQ,CAACT,KAAK;AAAA,IACdV,WAAW;AAAA,MACTG,QAAQ;AAAA,QACNiB,MAAM,CAAC;AAAA,UAACC,MAAMX,MAAMW;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMT,WAAWS;AAAAA,QAAAA,CAAK;AAAA,QAC9DC,QAAQ;AAAA,MACV;AAAA,MACApB,OAAOS;AAAAA,IAAAA;AAAAA,EAEV,CAAA,EAAEG,GAAG,CAAC,GACDS,QAAQL,YAAY;AAAA,IACxBC,QAAQ,CAACT,KAAK;AAAA,IACdV,WAAW;AAAA,MACTG,QAAQQ;AAAAA,MACRT,OAAO;AAAA,QACLkB,MAAM,CAAC;AAAA,UAACC,MAAMX,MAAMW;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMN,UAAUM;AAAAA,QAAAA,CAAK;AAAA,QAC7DC,QAAQE,OAAOf,SAASM,SAAS,IAAIA,UAAUU,KAAKT,SAAS;AAAA,MAAA;AAAA,IAC/D;AAAA,EACF,CACD,EAAEF,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACM,UAIZ,EAACG,CAAAA,YAAYjB,SAASQ,MAAM,KAAK,CAACS,YAAYjB,SAASc,KAAK;AAIzD,WAAA;AAAA,MAACN;AAAAA,MAAQM;AAAAA,IAAK;AACvB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.40.4",
3
+ "version": "1.41.0",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -112,7 +112,7 @@
112
112
  "vite": "^6.2.0",
113
113
  "vitest": "^3.0.8",
114
114
  "vitest-browser-react": "^0.1.1",
115
- "racejar": "1.2.2"
115
+ "racejar": "1.2.3"
116
116
  },
117
117
  "peerDependencies": {
118
118
  "@sanity/schema": "^3.80.1",
@@ -25,19 +25,32 @@ export const converterTextPlain = defineConverter({
25
25
 
26
26
  const data = blocks
27
27
  .map((block) => {
28
- if (!isPortableTextTextBlock(block)) {
29
- return ''
30
- }
28
+ if (isPortableTextTextBlock(block)) {
29
+ return block.children
30
+ .map((child) => {
31
+ if (child._type === snapshot.context.schema.span.name) {
32
+ return child.text
33
+ }
31
34
 
32
- return block.children
33
- .map((child) => {
34
- if (child._type === snapshot.context.schema.span.name) {
35
- return child.text
36
- }
35
+ return snapshot.beta.hasTag('dragging internally')
36
+ ? `[${
37
+ snapshot.context.schema.inlineObjects.find(
38
+ (inlineObjectType) =>
39
+ inlineObjectType.name === child._type,
40
+ )?.title ?? 'Object'
41
+ }]`
42
+ : ''
43
+ })
44
+ .join('')
45
+ }
37
46
 
38
- return ''
39
- })
40
- .join('')
47
+ return snapshot.beta.hasTag('dragging internally')
48
+ ? `[${
49
+ snapshot.context.schema.blockObjects.find(
50
+ (blockObjectType) => blockObjectType.name === block._type,
51
+ )?.title ?? 'Object'
52
+ }]`
53
+ : ''
41
54
  })
42
55
  .filter((block) => block !== '')
43
56
  .join('\n\n')