@portabletext/editor 1.55.3 → 1.55.5

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,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var selectionPoint = require("../_chunks-cjs/selection-point.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_isEqualSelectionPoints = require("../_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("../_chunks-cjs/util.selection-point-to-block-offset.cjs"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
3
+ var selectionPoint = require("../_chunks-cjs/selection-point.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_isEqualSelectionPoints = require("../_chunks-cjs/util.is-equal-selection-points.cjs"), util_sliceTextBlock = require("../_chunks-cjs/util.slice-text-block.cjs"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
4
4
  function isEqualSelections(a, b) {
5
5
  return !a && !b ? !0 : !a || !b ? !1 : util_isEqualSelectionPoints.isEqualSelectionPoints(a.anchor, b.anchor) && util_isEqualSelectionPoints.isEqualSelectionPoints(a.focus, b.focus);
6
6
  }
@@ -23,7 +23,7 @@ function splitTextBlock({
23
23
  const firstChild = block.children.at(0), lastChild = block.children.at(block.children.length - 1);
24
24
  if (!firstChild || !lastChild)
25
25
  return;
26
- const before = selectionPoint.sliceBlocks({
26
+ const before = util_sliceTextBlock.sliceTextBlock({
27
27
  context: {
28
28
  schema: context.schema,
29
29
  selection: {
@@ -38,8 +38,8 @@ function splitTextBlock({
38
38
  focus: point
39
39
  }
40
40
  },
41
- blocks: [block]
42
- }).at(0), after = selectionPoint.sliceBlocks({
41
+ block
42
+ }), after = util_sliceTextBlock.sliceTextBlock({
43
43
  context: {
44
44
  schema: context.schema,
45
45
  selection: {
@@ -54,13 +54,12 @@ function splitTextBlock({
54
54
  }
55
55
  }
56
56
  },
57
- blocks: [block]
58
- }).at(0);
59
- if (!(!before || !after) && !(!util_mergeTextBlocks.isTextBlock(context, before) || !util_mergeTextBlocks.isTextBlock(context, after)))
60
- return {
61
- before,
62
- after
63
- };
57
+ block
58
+ });
59
+ return {
60
+ before,
61
+ after
62
+ };
64
63
  }
65
64
  exports.blockOffsetToSpanSelectionPoint = selectionPoint.blockOffsetToSpanSelectionPoint;
66
65
  exports.getBlockStartPoint = selectionPoint.getBlockStartPoint;
@@ -78,8 +77,8 @@ exports.childSelectionPointToBlockOffset = util_childSelectionPointToBlockOffset
78
77
  exports.getBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint;
79
78
  exports.isEmptyTextBlock = util_isEqualSelectionPoints.isEmptyTextBlock;
80
79
  exports.isEqualSelectionPoints = util_isEqualSelectionPoints.isEqualSelectionPoints;
81
- exports.isSelectionCollapsed = util_selectionPointToBlockOffset.isSelectionCollapsed;
82
- exports.selectionPointToBlockOffset = util_selectionPointToBlockOffset.selectionPointToBlockOffset;
80
+ exports.isSelectionCollapsed = util_sliceTextBlock.isSelectionCollapsed;
81
+ exports.selectionPointToBlockOffset = util_sliceTextBlock.selectionPointToBlockOffset;
83
82
  exports.isTextBlock = util_mergeTextBlocks.isTextBlock;
84
83
  exports.mergeTextBlocks = util_mergeTextBlocks.mergeTextBlocks;
85
84
  exports.isEqualSelections = isEqualSelections;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.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 {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n blocks: [block],\n }).at(0)\n const after = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n blocks: [block],\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","reverseSelection","selection","backward","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","schema","path","_key","offset","blocks","after","isSpan","text","isTextBlock"],"mappings":";;;AAMO,SAASA,kBAAkBC,GAAoBC,GAAoB;AACxE,SAAI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,4BAAAA,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,4BAAAA,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACdO,SAASC,iBAEdC,WAA+C;AAC/C,SAAKA,cAIDA,UAAUC,WACL;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA,IAIP;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA;AAEd;ACfO,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;AAE7D,MAAI,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,eAAAA,YAAY;AAAA,IACzBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQ;AAAA,UACNiB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMT,WAAWS;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QAAA;AAAA,QAEVlB,OAAOO;AAAAA,MAAAA;AAAAA,IACT;AAAA,IAEFY,QAAQ,CAACb,KAAK;AAAA,EAAA,CACf,EAAEI,GAAG,CAAC,GACDU,QAAQN,eAAAA,YAAY;AAAA,IACxBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQQ;AAAAA,QACRP,OAAO;AAAA,UACLgB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMN,UAAUM;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQG,eAAAA,OAAOhB,SAASM,SAAS,IAAIA,UAAUW,KAAKV,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IACF;AAAA,IAEFO,QAAQ,CAACb,KAAK;AAAA,EAAA,CACf,EAAEI,GAAG,CAAC;AAEP,MAAI,EAAA,CAACG,UAAU,CAACO,UAIZ,EAAA,CAACG,qBAAAA,YAAYlB,SAASQ,MAAM,KAAK,CAACU,qBAAAA,YAAYlB,SAASe,KAAK;AAIhE,WAAO;AAAA,MAACP;AAAAA,MAAQO;AAAAA,IAAAA;AAClB;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.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 {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\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 {sliceTextBlock} from './util.slice-text-block'\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 = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n block,\n })\n const after = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n block,\n })\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","reverseSelection","selection","backward","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceTextBlock","schema","path","_key","offset","after","isSpan","text"],"mappings":";;;AAMO,SAASA,kBAAkBC,GAAoBC,GAAoB;AACxE,SAAI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,4BAAAA,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,4BAAAA,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACdO,SAASC,iBAEdC,WAA+C;AAC/C,SAAKA,cAIDA,UAAUC,WACL;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA,IAIP;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA;AAEd;AChBO,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;AAE7D,MAAI,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,oBAAAA,eAAe;AAAA,IAC5BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQ;AAAA,UACNiB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMT,WAAWS;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QAAA;AAAA,QAEVlB,OAAOO;AAAAA,MAAAA;AAAAA,IACT;AAAA,IAEFD;AAAAA,EAAAA,CACD,GACKa,QAAQL,mCAAe;AAAA,IAC3BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQQ;AAAAA,QACRP,OAAO;AAAA,UACLgB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMN,UAAUM;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQE,eAAAA,OAAOf,SAASM,SAAS,IAAIA,UAAUU,KAAKT,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IACF;AAAA,IAEFN;AAAAA,EAAAA,CACD;AAED,SAAO;AAAA,IAACO;AAAAA,IAAQM;AAAAA,EAAAA;AAClB;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,11 +1,11 @@
1
- import { sliceBlocks, isSpan } from "../_chunks-es/selection-point.js";
2
- import { blockOffsetToSpanSelectionPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, getTextBlockText, isKeyedSegment, spanSelectionPointToBlockOffset } from "../_chunks-es/selection-point.js";
1
+ import { isSpan } from "../_chunks-es/selection-point.js";
2
+ import { blockOffsetToSpanSelectionPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, getTextBlockText, isKeyedSegment, sliceBlocks, spanSelectionPointToBlockOffset } from "../_chunks-es/selection-point.js";
3
3
  import { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset } from "../_chunks-es/util.child-selection-point-to-block-offset.js";
4
4
  import { isEqualSelectionPoints } from "../_chunks-es/util.is-equal-selection-points.js";
5
5
  import { getBlockEndPoint, isEmptyTextBlock } from "../_chunks-es/util.is-equal-selection-points.js";
6
- import { isSelectionCollapsed, selectionPointToBlockOffset } from "../_chunks-es/util.selection-point-to-block-offset.js";
7
- import { isTextBlock } from "../_chunks-es/util.merge-text-blocks.js";
8
- import { mergeTextBlocks } from "../_chunks-es/util.merge-text-blocks.js";
6
+ import { sliceTextBlock } from "../_chunks-es/util.slice-text-block.js";
7
+ import { isSelectionCollapsed, selectionPointToBlockOffset } from "../_chunks-es/util.slice-text-block.js";
8
+ import { isTextBlock, mergeTextBlocks } from "../_chunks-es/util.merge-text-blocks.js";
9
9
  function isEqualSelections(a, b) {
10
10
  return !a && !b ? !0 : !a || !b ? !1 : isEqualSelectionPoints(a.anchor, b.anchor) && isEqualSelectionPoints(a.focus, b.focus);
11
11
  }
@@ -28,7 +28,7 @@ function splitTextBlock({
28
28
  const firstChild = block.children.at(0), lastChild = block.children.at(block.children.length - 1);
29
29
  if (!firstChild || !lastChild)
30
30
  return;
31
- const before = sliceBlocks({
31
+ const before = sliceTextBlock({
32
32
  context: {
33
33
  schema: context.schema,
34
34
  selection: {
@@ -43,8 +43,8 @@ function splitTextBlock({
43
43
  focus: point
44
44
  }
45
45
  },
46
- blocks: [block]
47
- }).at(0), after = sliceBlocks({
46
+ block
47
+ }), after = sliceTextBlock({
48
48
  context: {
49
49
  schema: context.schema,
50
50
  selection: {
@@ -59,13 +59,12 @@ function splitTextBlock({
59
59
  }
60
60
  }
61
61
  },
62
- blocks: [block]
63
- }).at(0);
64
- if (!(!before || !after) && !(!isTextBlock(context, before) || !isTextBlock(context, after)))
65
- return {
66
- before,
67
- after
68
- };
62
+ block
63
+ });
64
+ return {
65
+ before,
66
+ after
67
+ };
69
68
  }
70
69
  export {
71
70
  blockOffsetToBlockSelectionPoint,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.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 {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n blocks: [block],\n }).at(0)\n const after = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n blocks: [block],\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","reverseSelection","selection","backward","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","schema","path","_key","offset","blocks","after","isSpan","text","isTextBlock"],"mappings":";;;;;;;;AAMO,SAASA,kBAAkBC,GAAoBC,GAAoB;AACxE,SAAI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACdO,SAASC,iBAEdC,WAA+C;AAC/C,SAAKA,cAIDA,UAAUC,WACL;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA,IAIP;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA;AAEd;ACfO,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;AAE7D,MAAI,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,YAAY;AAAA,IACzBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQ;AAAA,UACNiB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMT,WAAWS;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QAAA;AAAA,QAEVlB,OAAOO;AAAAA,MAAAA;AAAAA,IACT;AAAA,IAEFY,QAAQ,CAACb,KAAK;AAAA,EAAA,CACf,EAAEI,GAAG,CAAC,GACDU,QAAQN,YAAY;AAAA,IACxBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQQ;AAAAA,QACRP,OAAO;AAAA,UACLgB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMN,UAAUM;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQG,OAAOhB,SAASM,SAAS,IAAIA,UAAUW,KAAKV,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IACF;AAAA,IAEFO,QAAQ,CAACb,KAAK;AAAA,EAAA,CACf,EAAEI,GAAG,CAAC;AAEP,MAAI,EAAA,CAACG,UAAU,CAACO,UAIZ,EAAA,CAACG,YAAYlB,SAASQ,MAAM,KAAK,CAACU,YAAYlB,SAASe,KAAK;AAIhE,WAAO;AAAA,MAACP;AAAAA,MAAQO;AAAAA,IAAAA;AAClB;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.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 {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\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 {sliceTextBlock} from './util.slice-text-block'\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 = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n block,\n })\n const after = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n block,\n })\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","reverseSelection","selection","backward","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceTextBlock","schema","path","_key","offset","after","isSpan","text"],"mappings":";;;;;;;;AAMO,SAASA,kBAAkBC,GAAoBC,GAAoB;AACxE,SAAI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACdO,SAASC,iBAEdC,WAA+C;AAC/C,SAAKA,cAIDA,UAAUC,WACL;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA,IAIP;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA;AAEd;AChBO,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;AAE7D,MAAI,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,eAAe;AAAA,IAC5BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQ;AAAA,UACNiB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMT,WAAWS;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QAAA;AAAA,QAEVlB,OAAOO;AAAAA,MAAAA;AAAAA,IACT;AAAA,IAEFD;AAAAA,EAAAA,CACD,GACKa,QAAQL,eAAe;AAAA,IAC3BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQQ;AAAAA,QACRP,OAAO;AAAA,UACLgB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMN,UAAUM;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQE,OAAOf,SAASM,SAAS,IAAIA,UAAUU,KAAKT,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IACF;AAAA,IAEFN;AAAAA,EAAAA,CACD;AAED,SAAO;AAAA,IAACO;AAAAA,IAAQM;AAAAA,EAAAA;AAClB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.55.3",
3
+ "version": "1.55.5",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -80,15 +80,15 @@
80
80
  "slate-react": "0.117.1",
81
81
  "use-effect-event": "^1.0.2",
82
82
  "xstate": "^5.20.0",
83
- "@portabletext/block-tools": "1.1.31",
83
+ "@portabletext/block-tools": "1.1.32",
84
84
  "@portabletext/patches": "1.1.5"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@portabletext/toolkit": "^2.0.17",
88
88
  "@sanity/diff-match-patch": "^3.2.0",
89
89
  "@sanity/pkg-utils": "^7.8.5",
90
- "@sanity/schema": "^3.93.0",
91
- "@sanity/types": "^3.93.0",
90
+ "@sanity/schema": "^3.94.2",
91
+ "@sanity/types": "^3.94.2",
92
92
  "@testing-library/react": "^16.3.0",
93
93
  "@types/debug": "^4.1.12",
94
94
  "@types/lodash": "^4.17.16",
@@ -97,7 +97,7 @@
97
97
  "@types/react-dom": "^19.1.6",
98
98
  "@typescript-eslint/eslint-plugin": "^8.34.0",
99
99
  "@typescript-eslint/parser": "^8.34.0",
100
- "@vitejs/plugin-react": "^4.5.2",
100
+ "@vitejs/plugin-react": "^4.6.0",
101
101
  "@vitest/browser": "^3.2.4",
102
102
  "@vitest/coverage-istanbul": "^3.2.4",
103
103
  "babel-plugin-react-compiler": "19.1.0-rc.2",
@@ -110,12 +110,12 @@
110
110
  "typescript": "5.8.3",
111
111
  "vite": "^6.2.5",
112
112
  "vitest": "^3.2.4",
113
- "vitest-browser-react": "^0.3.0",
114
- "racejar": "1.2.8"
113
+ "vitest-browser-react": "^1.0.0",
114
+ "racejar": "1.2.9"
115
115
  },
116
116
  "peerDependencies": {
117
- "@sanity/schema": "^3.93.0",
118
- "@sanity/types": "^3.93.0",
117
+ "@sanity/schema": "^3.94.2",
118
+ "@sanity/types": "^3.94.2",
119
119
  "react": "^16.9 || ^17 || ^18 || ^19",
120
120
  "rxjs": "^7.8.2"
121
121
  },
@@ -1,6 +1,7 @@
1
1
  import {isTextBlock, parseBlock} from '../internal-utils/parse-blocks'
2
2
  import * as selectors from '../selectors'
3
3
  import * as utils from '../utils'
4
+ import {sliceTextBlock} from '../utils/util.slice-text-block'
4
5
  import {raise} from './behavior.types.action'
5
6
  import {defineBehavior} from './behavior.types.behavior'
6
7
 
@@ -102,16 +103,13 @@ export const abstractSplitBehaviors = [
102
103
  }
103
104
 
104
105
  const newTextBlock = parseBlock({
105
- block: selectors
106
- .getSelectedValue({
107
- ...snapshot,
108
- context: {
109
- ...snapshot.context,
110
- selection: newTextBlockSelection,
111
- value: [focusTextBlock.node],
112
- },
113
- })
114
- .at(0),
106
+ block: sliceTextBlock({
107
+ context: {
108
+ ...snapshot.context,
109
+ selection: newTextBlockSelection,
110
+ },
111
+ block: focusTextBlock.node,
112
+ }),
115
113
  context: snapshot.context,
116
114
  options: {refreshKeys: true, validateFields: true},
117
115
  })
@@ -0,0 +1,162 @@
1
+ import type {
2
+ PortableTextObject,
3
+ PortableTextSpan,
4
+ PortableTextTextBlock,
5
+ } from '@sanity/types'
6
+ import {describe, expect, test} from 'vitest'
7
+ import {keyGenerator} from '..'
8
+ import {compileSchemaDefinition, defineSchema} from '../editor/editor-schema'
9
+ import {sliceTextBlock} from './util.slice-text-block'
10
+
11
+ const schema = compileSchemaDefinition(
12
+ defineSchema({
13
+ inlineObjects: [{name: 'stock-ticker'}],
14
+ }),
15
+ )
16
+
17
+ function createSpan(span: Partial<PortableTextSpan>) {
18
+ return {
19
+ _type: 'span',
20
+ _key: span._key ?? keyGenerator(),
21
+ text: span.text ?? '',
22
+ marks: span.marks ?? [],
23
+ }
24
+ }
25
+
26
+ function createInlineObject(inlineObject: Partial<PortableTextObject>) {
27
+ return {
28
+ _type: 'stock-ticker',
29
+ _key: inlineObject._key ?? keyGenerator(),
30
+ ...inlineObject,
31
+ }
32
+ }
33
+
34
+ function createBlock(
35
+ block: Partial<PortableTextTextBlock>,
36
+ ): PortableTextTextBlock {
37
+ return {
38
+ _type: 'block',
39
+ _key: block._key ?? keyGenerator(),
40
+ children: block.children ?? [createSpan({})],
41
+ markDefs: block.markDefs ?? [],
42
+ style: block.style ?? 'normal',
43
+ ...block,
44
+ }
45
+ }
46
+
47
+ describe(sliceTextBlock.name, () => {
48
+ test('empty block', () => {
49
+ const span = createSpan({})
50
+ const block = createBlock({
51
+ children: [span],
52
+ })
53
+
54
+ expect(
55
+ sliceTextBlock({
56
+ context: {
57
+ schema,
58
+ selection: {
59
+ anchor: {
60
+ path: [{_key: block._key}, 'children', {_key: span._key}],
61
+ offset: 0,
62
+ },
63
+ focus: {
64
+ path: [{_key: block._key}, 'children', {_key: span._key}],
65
+ offset: 0,
66
+ },
67
+ },
68
+ },
69
+ block,
70
+ }),
71
+ ).toEqual(block)
72
+ })
73
+
74
+ test('middle', () => {
75
+ const span = createSpan({
76
+ text: 'foo bar baz',
77
+ })
78
+ const block = createBlock({
79
+ children: [span],
80
+ })
81
+
82
+ expect(
83
+ sliceTextBlock({
84
+ context: {
85
+ schema,
86
+ selection: {
87
+ anchor: {
88
+ path: [{_key: block._key}, 'children', {_key: span._key}],
89
+ offset: 4,
90
+ },
91
+ focus: {
92
+ path: [{_key: block._key}, 'children', {_key: span._key}],
93
+ offset: 7,
94
+ },
95
+ },
96
+ },
97
+ block,
98
+ }),
99
+ ).toEqual({
100
+ ...block,
101
+ children: [
102
+ {
103
+ ...span,
104
+ text: 'bar',
105
+ },
106
+ ],
107
+ })
108
+ })
109
+
110
+ test('multiple children', () => {
111
+ const fooSpan = createSpan({
112
+ text: 'foo',
113
+ marks: ['strong'],
114
+ })
115
+ const barSpan = createSpan({
116
+ text: 'bar',
117
+ marks: ['em'],
118
+ })
119
+ const bazSpan = createSpan({
120
+ text: 'baz',
121
+ marks: ['underline'],
122
+ })
123
+ const stockTicker = createInlineObject({
124
+ symbol: 'AAPL',
125
+ })
126
+ const block = createBlock({
127
+ children: [fooSpan, barSpan, stockTicker, bazSpan],
128
+ })
129
+
130
+ expect(
131
+ sliceTextBlock({
132
+ context: {
133
+ schema,
134
+ selection: {
135
+ anchor: {
136
+ path: [{_key: block._key}, 'children', {_key: barSpan._key}],
137
+ offset: 1,
138
+ },
139
+ focus: {
140
+ path: [{_key: block._key}, 'children', {_key: bazSpan._key}],
141
+ offset: 1,
142
+ },
143
+ },
144
+ },
145
+ block,
146
+ }),
147
+ ).toEqual({
148
+ ...block,
149
+ children: [
150
+ {
151
+ ...barSpan,
152
+ text: 'ar',
153
+ },
154
+ stockTicker,
155
+ {
156
+ ...bazSpan,
157
+ text: 'b',
158
+ },
159
+ ],
160
+ })
161
+ })
162
+ })
@@ -0,0 +1,89 @@
1
+ import type {PortableTextChild, PortableTextTextBlock} from '@sanity/types'
2
+ import type {EditorContext} from '..'
3
+ import {isSpan} from '../internal-utils/parse-blocks'
4
+ import {
5
+ getBlockKeyFromSelectionPoint,
6
+ getChildKeyFromSelectionPoint,
7
+ } from '../selection/selection-point'
8
+ import {getSelectionEndPoint} from './util.get-selection-end-point'
9
+ import {getSelectionStartPoint} from './util.get-selection-start-point'
10
+
11
+ export function sliceTextBlock({
12
+ context,
13
+ block,
14
+ }: {
15
+ context: Pick<EditorContext, 'schema' | 'selection'>
16
+ block: PortableTextTextBlock
17
+ }): PortableTextTextBlock {
18
+ const startPoint = getSelectionStartPoint(context.selection)
19
+ const endPoint = getSelectionEndPoint(context.selection)
20
+
21
+ if (!startPoint || !endPoint) {
22
+ return block
23
+ }
24
+
25
+ const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)
26
+ const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)
27
+
28
+ if (startBlockKey !== endBlockKey || startBlockKey !== block._key) {
29
+ return block
30
+ }
31
+
32
+ const startChildKey = getChildKeyFromSelectionPoint(startPoint)
33
+ const endChildKey = getChildKeyFromSelectionPoint(endPoint)
34
+
35
+ if (!startChildKey || !endChildKey) {
36
+ return block
37
+ }
38
+
39
+ let startChildFound = false
40
+ const children: Array<PortableTextChild> = []
41
+
42
+ for (const child of block.children) {
43
+ if (child._key === startChildKey) {
44
+ startChildFound = true
45
+
46
+ if (isSpan(context, child)) {
47
+ const text =
48
+ child._key === endChildKey
49
+ ? child.text.slice(startPoint.offset, endPoint.offset)
50
+ : child.text.slice(startPoint.offset)
51
+
52
+ children.push({
53
+ ...child,
54
+ text,
55
+ })
56
+ } else {
57
+ children.push(child)
58
+ }
59
+
60
+ if (startChildKey === endChildKey) {
61
+ break
62
+ }
63
+
64
+ continue
65
+ }
66
+
67
+ if (child._key === endChildKey) {
68
+ if (isSpan(context, child)) {
69
+ children.push({
70
+ ...child,
71
+ text: child.text.slice(0, endPoint.offset),
72
+ })
73
+ } else {
74
+ children.push(child)
75
+ }
76
+
77
+ break
78
+ }
79
+
80
+ if (startChildFound) {
81
+ children.push(child)
82
+ }
83
+ }
84
+
85
+ return {
86
+ ...block,
87
+ children,
88
+ }
89
+ }
@@ -2,8 +2,7 @@ import type {PortableTextTextBlock} from '@sanity/types'
2
2
  import type {EditorSelectionPoint} from '..'
3
3
  import type {EditorContext} from '../editor/editor-snapshot'
4
4
  import {isSpan} from './util.is-span'
5
- import {isTextBlock} from './util.is-text-block'
6
- import {sliceBlocks} from './util.slice-blocks'
5
+ import {sliceTextBlock} from './util.slice-text-block'
7
6
 
8
7
  /**
9
8
  * @beta
@@ -24,7 +23,7 @@ export function splitTextBlock({
24
23
  return undefined
25
24
  }
26
25
 
27
- const before = sliceBlocks({
26
+ const before = sliceTextBlock({
28
27
  context: {
29
28
  schema: context.schema,
30
29
  selection: {
@@ -35,9 +34,9 @@ export function splitTextBlock({
35
34
  focus: point,
36
35
  },
37
36
  },
38
- blocks: [block],
39
- }).at(0)
40
- const after = sliceBlocks({
37
+ block,
38
+ })
39
+ const after = sliceTextBlock({
41
40
  context: {
42
41
  schema: context.schema,
43
42
  selection: {
@@ -48,16 +47,8 @@ export function splitTextBlock({
48
47
  },
49
48
  },
50
49
  },
51
- blocks: [block],
52
- }).at(0)
53
-
54
- if (!before || !after) {
55
- return undefined
56
- }
57
-
58
- if (!isTextBlock(context, before) || !isTextBlock(context, after)) {
59
- return undefined
60
- }
50
+ block,
51
+ })
61
52
 
62
53
  return {before, after}
63
54
  }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var selectionPoint = require("./selection-point.cjs"), util_childSelectionPointToBlockOffset = require("./util.child-selection-point-to-block-offset.cjs");
3
- function isSelectionCollapsed(selection) {
4
- return selection ? JSON.stringify(selection.anchor.path) === JSON.stringify(selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
5
- }
6
- function selectionPointToBlockOffset({
7
- context,
8
- selectionPoint: selectionPoint$1
9
- }) {
10
- const blockKey = selectionPoint.getBlockKeyFromSelectionPoint(selectionPoint$1);
11
- return selectionPoint$1.path.length === 1 && blockKey !== void 0 ? {
12
- path: [{
13
- _key: blockKey
14
- }],
15
- offset: selectionPoint$1.offset
16
- } : util_childSelectionPointToBlockOffset.childSelectionPointToBlockOffset({
17
- context,
18
- selectionPoint: selectionPoint$1
19
- });
20
- }
21
- exports.isSelectionCollapsed = isSelectionCollapsed;
22
- exports.selectionPointToBlockOffset = selectionPointToBlockOffset;
23
- //# sourceMappingURL=util.selection-point-to-block-offset.cjs.map
@@ -1 +0,0 @@
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,EAAAA,gBACAC;AAIF,GAA4B;AAC1B,QAAMC,WAAWC,eAAAA,8BAA8BF,gBAAc;AAE7D,SAAIA,iBAAeL,KAAKQ,WAAW,KAAKF,aAAaG,SAC5C;AAAA,IACLT,MAAM,CAAC;AAAA,MAACU,MAAMJ;AAAAA,IAAAA,CAAS;AAAA,IACvBJ,QAAQG,iBAAeH;AAAAA,EAAAA,IAIpBS,uEAAiC;AAAA,IACtCP;AAAAA,IAAAA,gBACAC;AAAAA,EAAAA,CACD;AACH;;;"}
@@ -1,25 +0,0 @@
1
- import { getBlockKeyFromSelectionPoint } from "./selection-point.js";
2
- import { childSelectionPointToBlockOffset } from "./util.child-selection-point-to-block-offset.js";
3
- function isSelectionCollapsed(selection) {
4
- return selection ? JSON.stringify(selection.anchor.path) === JSON.stringify(selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
5
- }
6
- function selectionPointToBlockOffset({
7
- context,
8
- selectionPoint
9
- }) {
10
- const blockKey = getBlockKeyFromSelectionPoint(selectionPoint);
11
- return selectionPoint.path.length === 1 && blockKey !== void 0 ? {
12
- path: [{
13
- _key: blockKey
14
- }],
15
- offset: selectionPoint.offset
16
- } : childSelectionPointToBlockOffset({
17
- context,
18
- selectionPoint
19
- });
20
- }
21
- export {
22
- isSelectionCollapsed,
23
- selectionPointToBlockOffset
24
- };
25
- //# sourceMappingURL=util.selection-point-to-block-offset.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.selection-point-to-block-offset.js","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;AAIF,GAA4B;AAC1B,QAAMC,WAAWC,8BAA8BF,cAAc;AAE7D,SAAIA,eAAeL,KAAKQ,WAAW,KAAKF,aAAaG,SAC5C;AAAA,IACLT,MAAM,CAAC;AAAA,MAACU,MAAMJ;AAAAA,IAAAA,CAAS;AAAA,IACvBJ,QAAQG,eAAeH;AAAAA,EAAAA,IAIpBS,iCAAiC;AAAA,IACtCP;AAAAA,IACAC;AAAAA,EAAAA,CACD;AACH;"}