@portabletext/editor 1.27.0 → 1.28.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.
Files changed (34) hide show
  1. package/README.md +5 -5
  2. package/lib/_chunks-cjs/plugin.event-listener.cjs +302 -43
  3. package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
  4. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +88 -88
  5. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  6. package/lib/_chunks-es/plugin.event-listener.js +302 -43
  7. package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
  8. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +88 -88
  9. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  10. package/lib/index.cjs +22 -21
  11. package/lib/index.cjs.map +1 -1
  12. package/lib/index.d.cts +257 -0
  13. package/lib/index.d.ts +257 -0
  14. package/lib/index.js +22 -21
  15. package/lib/index.js.map +1 -1
  16. package/lib/selectors/index.cjs +15 -3
  17. package/lib/selectors/index.cjs.map +1 -1
  18. package/lib/selectors/index.d.cts +18 -0
  19. package/lib/selectors/index.d.ts +18 -0
  20. package/lib/selectors/index.js +17 -4
  21. package/lib/selectors/index.js.map +1 -1
  22. package/package.json +3 -3
  23. package/src/behavior-actions/behavior.action.insert-break.ts +93 -83
  24. package/src/editor/PortableTextEditor.tsx +288 -1
  25. package/src/editor/components/DefaultObject.tsx +21 -0
  26. package/src/editor/components/Element.tsx +5 -5
  27. package/src/editor/components/Leaf.tsx +1 -6
  28. package/src/selectors/index.ts +4 -2
  29. package/src/selectors/selector.get-active-annotations.test.ts +122 -0
  30. package/src/selectors/selector.get-active-annotations.ts +30 -0
  31. package/src/selectors/selector.get-selection.ts +8 -0
  32. package/src/selectors/selector.get-value.ts +11 -0
  33. package/src/editor/nodes/DefaultAnnotation.tsx +0 -20
  34. package/src/editor/nodes/DefaultObject.tsx +0 -18
@@ -1,12 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var selector_isAtTheStartOfBlock = require("../_chunks-cjs/selector.is-at-the-start-of-block.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), types = require("@sanity/types"), util_reverseSelection = require("../_chunks-cjs/util.reverse-selection.cjs");
4
- const getSelectedSlice = ({
3
+ var types = require("@sanity/types"), selector_isAtTheStartOfBlock = require("../_chunks-cjs/selector.is-at-the-start-of-block.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), util_reverseSelection = require("../_chunks-cjs/util.reverse-selection.cjs");
4
+ const getActiveAnnotations = (snapshot) => {
5
+ if (!snapshot.context.selection)
6
+ return [];
7
+ const selectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks(snapshot), selectedSpans = selector_isAtTheStartOfBlock.getSelectedSpans(snapshot);
8
+ return selectedSpans.length === 0 ? [] : selectedBlocks.flatMap((block) => types.isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => selectedSpans.some((span) => span.node.marks?.includes(markDef._key)));
9
+ }, getSelectedSlice = ({
5
10
  context
6
11
  }) => util_sliceBlocks.sliceBlocks({
7
12
  blocks: context.value,
8
13
  selection: context.selection
9
- });
14
+ }), getSelection = ({
15
+ context
16
+ }) => context.selection, getValue = ({
17
+ context
18
+ }) => context.value;
10
19
  function isPointAfterSelection(point) {
11
20
  return (snapshot) => {
12
21
  if (!snapshot.context.selection)
@@ -103,7 +112,10 @@ exports.isSelectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed
103
112
  exports.isSelectionExpanded = selector_isAtTheStartOfBlock.isSelectionExpanded;
104
113
  exports.getBlockTextBefore = selector_getTextBefore.getBlockTextBefore;
105
114
  exports.getSelectionText = selector_getTextBefore.getSelectionText;
115
+ exports.getActiveAnnotations = getActiveAnnotations;
106
116
  exports.getSelectedSlice = getSelectedSlice;
117
+ exports.getSelection = getSelection;
118
+ exports.getValue = getValue;
107
119
  exports.isPointAfterSelection = isPointAfterSelection;
108
120
  exports.isPointBeforeSelection = isPointBeforeSelection;
109
121
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const endBlockKey = isKeySegment(selection.focus.path[0])\n ? selection.focus.path[0]._key\n : undefined\n const endChildKey = isKeySegment(selection.focus.path[2])\n ? selection.focus.path[2]._key\n : undefined\n\n if (!pointBlockKey || !endBlockKey) {\n return false\n }\n\n let after = false\n\n for (const block of snapshot.context.value) {\n if (block._key === endBlockKey) {\n if (block._key !== pointBlockKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !endChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (child._key !== pointChildKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this child\n\n after = point.offset > selection.focus.offset\n break\n }\n\n if (child._key === pointChildKey) {\n break\n }\n }\n }\n\n if (block._key === pointBlockKey) {\n break\n }\n }\n\n return after\n }\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const startBlockKey = isKeySegment(selection.anchor.path[0])\n ? selection.anchor.path[0]._key\n : undefined\n const startChildKey = isKeySegment(selection.anchor.path[2])\n ? selection.anchor.path[2]._key\n : undefined\n\n if (!pointBlockKey || !startBlockKey) {\n return false\n }\n\n let before = false\n\n for (const block of snapshot.context.value) {\n if (block._key === pointBlockKey) {\n if (block._key !== startBlockKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !startChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === pointChildKey) {\n if (child._key !== startChildKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this child\n\n before = point.offset < selection.anchor.offset\n break\n }\n\n if (child._key === startChildKey) {\n break\n }\n }\n }\n\n if (block._key === startBlockKey) {\n break\n }\n }\n\n return before\n }\n}\n"],"names":["getSelectedSlice","context","sliceBlocks","blocks","value","selection","isPointAfterSelection","point","snapshot","reverseSelection","pointBlockKey","isKeySegment","path","_key","undefined","pointChildKey","endBlockKey","focus","endChildKey","after","block","isPortableTextTextBlock","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before"],"mappings":";;;AAOO,MAAMA,mBAA6DA,CAAC;AAAA,EACzEC;AACF,MACSC,6BAAY;AAAA,EAACC,QAAQF,QAAQG;AAAAA,EAAOC,WAAWJ,QAAQI;AAAS,CAAC;ACFnE,SAASC,sBACdC,OACyB;AACzB,SAAQC,CAAa,aAAA;AACf,QAAA,CAACA,SAASP,QAAQI;AACb,aAAA;AAGT,UAAMA,YAAYI,sBAAAA,iBAAiBD,SAASP,QAAQI,SAAS,GAEvDK,gBAAgBC,MAAAA,aAAaJ,MAAMK,KAAK,CAAC,CAAC,IAC5CL,MAAMK,KAAK,CAAC,EAAEC,OACdC,QACEC,gBAAgBJ,MAAAA,aAAaJ,MAAMK,KAAK,CAAC,CAAC,IAC5CL,MAAMK,KAAK,CAAC,EAAEC,OACdC,QAEEE,cAAcL,MAAAA,aAAaN,UAAUY,MAAML,KAAK,CAAC,CAAC,IACpDP,UAAUY,MAAML,KAAK,CAAC,EAAEC,OACxBC,QACEI,cAAcP,MAAAA,aAAaN,UAAUY,MAAML,KAAK,CAAC,CAAC,IACpDP,UAAUY,MAAML,KAAK,CAAC,EAAEC,OACxBC;AAEA,QAAA,CAACJ,iBAAiB,CAACM;AACd,aAAA;AAGT,QAAIG,QAAQ;AAEDC,eAAAA,SAASZ,SAASP,QAAQG,OAAO;AACtCgB,UAAAA,MAAMP,SAASG,aAAa;AAC1BI,YAAAA,MAAMP,SAASH,eAAe;AACxB,kBAAA;AACR;AAAA,QAAA;AASF,YAJI,CAACW,MAAAA,wBAAwBD,KAAK,KAI9B,CAACL,iBAAiB,CAACG;AACrB;AAGSI,mBAAAA,SAASF,MAAMG,UAAU;AAC9BD,cAAAA,MAAMT,SAASK,aAAa;AAC1BI,gBAAAA,MAAMT,SAASE,eAAe;AACxB,sBAAA;AACR;AAAA,YAAA;AAKMR,oBAAAA,MAAMi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AA;AAGF,cAAIF,MAAMT,SAASe;AACjB;AAAA,QAAA;AAAA,MAEJ;AAGF,UAAIR,MAAMP,SAASa;AACjB;AAAA,IAAA;AAIGG,WAAAA;AAAAA,EACT;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["import {isPortableTextTextBlock, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return []\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n selectedSpans.some((span) => span.node.marks?.includes(markDef._key)),\n )\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import type {EditorSelection, EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = ({context}) => {\n return context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return context.value\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const endBlockKey = isKeySegment(selection.focus.path[0])\n ? selection.focus.path[0]._key\n : undefined\n const endChildKey = isKeySegment(selection.focus.path[2])\n ? selection.focus.path[2]._key\n : undefined\n\n if (!pointBlockKey || !endBlockKey) {\n return false\n }\n\n let after = false\n\n for (const block of snapshot.context.value) {\n if (block._key === endBlockKey) {\n if (block._key !== pointBlockKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !endChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (child._key !== pointChildKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this child\n\n after = point.offset > selection.focus.offset\n break\n }\n\n if (child._key === pointChildKey) {\n break\n }\n }\n }\n\n if (block._key === pointBlockKey) {\n break\n }\n }\n\n return after\n }\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const startBlockKey = isKeySegment(selection.anchor.path[0])\n ? selection.anchor.path[0]._key\n : undefined\n const startChildKey = isKeySegment(selection.anchor.path[2])\n ? selection.anchor.path[2]._key\n : undefined\n\n if (!pointBlockKey || !startBlockKey) {\n return false\n }\n\n let before = false\n\n for (const block of snapshot.context.value) {\n if (block._key === pointBlockKey) {\n if (block._key !== startBlockKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !startChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === pointChildKey) {\n if (child._key !== startChildKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this child\n\n before = point.offset < selection.anchor.offset\n break\n }\n\n if (child._key === startChildKey) {\n break\n }\n }\n }\n\n if (block._key === startBlockKey) {\n break\n }\n }\n\n return before\n }\n}\n"],"names":["getActiveAnnotations","snapshot","context","selection","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getSelectedSlice","sliceBlocks","blocks","value","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","path","undefined","pointChildKey","endBlockKey","focus","endChildKey","after","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before"],"mappings":";;;AAQO,MAAMA,uBACXC,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX,QAAMC,iBAAiBC,6BAAAA,kBAAkBJ,QAAQ,GAC3CK,gBAAgBC,8CAAiBN,QAAQ;AAE/C,SAAIK,cAAcE,WAAW,IACpB,KAGiBJ,eAAeK,QAASC,CAChDC,UAAAA,MAAAA,wBAAwBD,MAAME,IAAI,IAAKF,MAAME,KAAKC,YAAY,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ACW;AACrB;AAGSN,mBAAAA,SAAS7B,MAAM8B,UAAU;AAC9BD,cAAAA,MAAMnB,SAASc,eAAe;AAC5BK,gBAAAA,MAAMnB,SAASyB,eAAe;AACvB,uBAAA;AACT;AAAA,YAAA;AAKOjB,qBAAAA,MAAMa,SAAStC,UAAUyC,OAAOH;AACzC;AAAA,UAAA;AAGF,cAAIF,MAAMnB,SAASyB;AACjB;AAAA,QAAA;AAAA,MAEJ;AAGF,UAAInC,MAAMU,SAASuB;AACjB;AAAA,IAAA;AAIGG,WAAAA;AAAAA,EACT;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -108,6 +108,13 @@ export declare type EditorSnapshot = {
108
108
  context: EditorContext
109
109
  }
110
110
 
111
+ /**
112
+ * @public
113
+ */
114
+ export declare const getActiveAnnotations: EditorSelector<
115
+ Array<PortableTextObject>
116
+ >
117
+
111
118
  /**
112
119
  * @public
113
120
  */
@@ -262,6 +269,12 @@ export declare const getSelectedSpans: EditorSelector<
262
269
  }>
263
270
  >
264
271
 
272
+ /**
273
+ * @public
274
+ */
275
+ declare const getSelection_2: EditorSelector<EditorSelection>
276
+ export {getSelection_2 as getSelection}
277
+
265
278
  /**
266
279
  * @public
267
280
  */
@@ -289,6 +302,11 @@ export declare const getSelectionStartBlock: EditorSelector<
289
302
  */
290
303
  export declare const getSelectionText: EditorSelector<string>
291
304
 
305
+ /**
306
+ * @public
307
+ */
308
+ export declare const getValue: EditorSelector<Array<PortableTextBlock>>
309
+
292
310
  /**
293
311
  * @public
294
312
  */
@@ -108,6 +108,13 @@ export declare type EditorSnapshot = {
108
108
  context: EditorContext
109
109
  }
110
110
 
111
+ /**
112
+ * @public
113
+ */
114
+ export declare const getActiveAnnotations: EditorSelector<
115
+ Array<PortableTextObject>
116
+ >
117
+
111
118
  /**
112
119
  * @public
113
120
  */
@@ -262,6 +269,12 @@ export declare const getSelectedSpans: EditorSelector<
262
269
  }>
263
270
  >
264
271
 
272
+ /**
273
+ * @public
274
+ */
275
+ declare const getSelection_2: EditorSelector<EditorSelection>
276
+ export {getSelection_2 as getSelection}
277
+
265
278
  /**
266
279
  * @public
267
280
  */
@@ -289,6 +302,11 @@ export declare const getSelectionStartBlock: EditorSelector<
289
302
  */
290
303
  export declare const getSelectionText: EditorSelector<string>
291
304
 
305
+ /**
306
+ * @public
307
+ */
308
+ export declare const getValue: EditorSelector<Array<PortableTextBlock>>
309
+
292
310
  /**
293
311
  * @public
294
312
  */
@@ -1,14 +1,24 @@
1
- import { getActiveListItem, getActiveStyle, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getPreviousBlock, getSelectedBlocks, getSelectedSpans, getSelectionEndBlock, getSelectionStartBlock, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-at-the-start-of-block.js";
1
+ import { isPortableTextTextBlock, isKeySegment } from "@sanity/types";
2
+ import { getSelectedBlocks, getSelectedSpans } from "../_chunks-es/selector.is-at-the-start-of-block.js";
3
+ import { getActiveListItem, getActiveStyle, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getPreviousBlock, getSelectionEndBlock, getSelectionStartBlock, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-at-the-start-of-block.js";
2
4
  import { sliceBlocks } from "../_chunks-es/util.slice-blocks.js";
3
5
  import { getBlockTextBefore, getSelectionText } from "../_chunks-es/selector.get-text-before.js";
4
- import { isKeySegment, isPortableTextTextBlock } from "@sanity/types";
5
6
  import { reverseSelection } from "../_chunks-es/util.reverse-selection.js";
6
- const getSelectedSlice = ({
7
+ const getActiveAnnotations = (snapshot) => {
8
+ if (!snapshot.context.selection)
9
+ return [];
10
+ const selectedBlocks = getSelectedBlocks(snapshot), selectedSpans = getSelectedSpans(snapshot);
11
+ return selectedSpans.length === 0 ? [] : selectedBlocks.flatMap((block) => isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => selectedSpans.some((span) => span.node.marks?.includes(markDef._key)));
12
+ }, getSelectedSlice = ({
7
13
  context
8
14
  }) => sliceBlocks({
9
15
  blocks: context.value,
10
16
  selection: context.selection
11
- });
17
+ }), getSelection = ({
18
+ context
19
+ }) => context.selection, getValue = ({
20
+ context
21
+ }) => context.value;
12
22
  function isPointAfterSelection(point) {
13
23
  return (snapshot) => {
14
24
  if (!snapshot.context.selection)
@@ -80,6 +90,7 @@ function isPointBeforeSelection(point) {
80
90
  };
81
91
  }
82
92
  export {
93
+ getActiveAnnotations,
83
94
  getActiveListItem,
84
95
  getActiveStyle,
85
96
  getBlockTextBefore,
@@ -96,9 +107,11 @@ export {
96
107
  getSelectedBlocks,
97
108
  getSelectedSlice,
98
109
  getSelectedSpans,
110
+ getSelection,
99
111
  getSelectionEndBlock,
100
112
  getSelectionStartBlock,
101
113
  getSelectionText,
114
+ getValue,
102
115
  isActiveAnnotation,
103
116
  isActiveDecorator,
104
117
  isActiveListItem,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const endBlockKey = isKeySegment(selection.focus.path[0])\n ? selection.focus.path[0]._key\n : undefined\n const endChildKey = isKeySegment(selection.focus.path[2])\n ? selection.focus.path[2]._key\n : undefined\n\n if (!pointBlockKey || !endBlockKey) {\n return false\n }\n\n let after = false\n\n for (const block of snapshot.context.value) {\n if (block._key === endBlockKey) {\n if (block._key !== pointBlockKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !endChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (child._key !== pointChildKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this child\n\n after = point.offset > selection.focus.offset\n break\n }\n\n if (child._key === pointChildKey) {\n break\n }\n }\n }\n\n if (block._key === pointBlockKey) {\n break\n }\n }\n\n return after\n }\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const startBlockKey = isKeySegment(selection.anchor.path[0])\n ? selection.anchor.path[0]._key\n : undefined\n const startChildKey = isKeySegment(selection.anchor.path[2])\n ? selection.anchor.path[2]._key\n : undefined\n\n if (!pointBlockKey || !startBlockKey) {\n return false\n }\n\n let before = false\n\n for (const block of snapshot.context.value) {\n if (block._key === pointBlockKey) {\n if (block._key !== startBlockKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !startChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === pointChildKey) {\n if (child._key !== startChildKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this child\n\n before = point.offset < selection.anchor.offset\n break\n }\n\n if (child._key === startChildKey) {\n break\n }\n }\n }\n\n if (block._key === startBlockKey) {\n break\n }\n }\n\n return before\n }\n}\n"],"names":["getSelectedSlice","context","sliceBlocks","blocks","value","selection","isPointAfterSelection","point","snapshot","reverseSelection","pointBlockKey","isKeySegment","path","_key","undefined","pointChildKey","endBlockKey","focus","endChildKey","after","block","isPortableTextTextBlock","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before"],"mappings":";;;;;AAOO,MAAMA,mBAA6DA,CAAC;AAAA,EACzEC;AACF,MACSC,YAAY;AAAA,EAACC,QAAQF,QAAQG;AAAAA,EAAOC,WAAWJ,QAAQI;AAAS,CAAC;ACFnE,SAASC,sBACdC,OACyB;AACzB,SAAQC,CAAa,aAAA;AACf,QAAA,CAACA,SAASP,QAAQI;AACb,aAAA;AAGT,UAAMA,YAAYI,iBAAiBD,SAASP,QAAQI,SAAS,GAEvDK,gBAAgBC,aAAaJ,MAAMK,KAAK,CAAC,CAAC,IAC5CL,MAAMK,KAAK,CAAC,EAAEC,OACdC,QACEC,gBAAgBJ,aAAaJ,MAAMK,KAAK,CAAC,CAAC,IAC5CL,MAAMK,KAAK,CAAC,EAAEC,OACdC,QAEEE,cAAcL,aAAaN,UAAUY,MAAML,KAAK,CAAC,CAAC,IACpDP,UAAUY,MAAML,KAAK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,OAAOf,KAAK,CAAC,EAAEC,OACzBC;AAEA,QAAA,CAACJ,iBAAiB,CAACgB;AACd,aAAA;AAGT,QAAIG,SAAS;AAEFT,eAAAA,SAASZ,SAASP,QAAQG,OAAO;AACtCgB,UAAAA,MAAMP,SAASH,eAAe;AAC5BU,YAAAA,MAAMP,SAASa,eAAe;AACvB,mBAAA;AACT;AAAA,QAAA;AASF,YAJI,CAACL,wBAAwBD,KAAK,KAI9B,CAACL,iBAAiB,CAACa;AACrB;AAGSN,mBAAAA,SAASF,MAAMG,UAAU;AAC9BD,cAAAA,MAAMT,SAASE,eAAe;AAC5BO,gBAAAA,MAAMT,SAASe,eAAe;AACvB,uBAAA;AACT;AAAA,YAAA;AAKOrB,qBAAAA,MAAMiB,SAASnB,UAAUsB,OAAOH;AACzC;AAAA,UAAA;AAGF,cAAIF,MAAMT,SAASe;AACjB;AAAA,QAAA;AAAA,MAEJ;AAGF,UAAIR,MAAMP,SAASa;AACjB;AAAA,IAAA;AAIGG,WAAAA;AAAAA,EACT;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["import {isPortableTextTextBlock, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return []\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n selectedSpans.some((span) => span.node.marks?.includes(markDef._key)),\n )\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import type {EditorSelection, EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = ({context}) => {\n return context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return context.value\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const endBlockKey = isKeySegment(selection.focus.path[0])\n ? selection.focus.path[0]._key\n : undefined\n const endChildKey = isKeySegment(selection.focus.path[2])\n ? selection.focus.path[2]._key\n : undefined\n\n if (!pointBlockKey || !endBlockKey) {\n return false\n }\n\n let after = false\n\n for (const block of snapshot.context.value) {\n if (block._key === endBlockKey) {\n if (block._key !== pointBlockKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !endChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (child._key !== pointChildKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this child\n\n after = point.offset > selection.focus.offset\n break\n }\n\n if (child._key === pointChildKey) {\n break\n }\n }\n }\n\n if (block._key === pointBlockKey) {\n break\n }\n }\n\n return after\n }\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const startBlockKey = isKeySegment(selection.anchor.path[0])\n ? selection.anchor.path[0]._key\n : undefined\n const startChildKey = isKeySegment(selection.anchor.path[2])\n ? selection.anchor.path[2]._key\n : undefined\n\n if (!pointBlockKey || !startBlockKey) {\n return false\n }\n\n let before = false\n\n for (const block of snapshot.context.value) {\n if (block._key === pointBlockKey) {\n if (block._key !== startBlockKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !startChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === pointChildKey) {\n if (child._key !== startChildKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this child\n\n before = point.offset < selection.anchor.offset\n break\n }\n\n if (child._key === startChildKey) {\n break\n }\n }\n }\n\n if (block._key === startBlockKey) {\n break\n }\n }\n\n return before\n }\n}\n"],"names":["getActiveAnnotations","snapshot","context","selection","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getSelectedSlice","sliceBlocks","blocks","value","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","path","undefined","pointChildKey","endBlockKey","focus","endChildKey","after","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before"],"mappings":";;;;;;AAQO,MAAMA,uBACXC,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX,QAAMC,iBAAiBC,kBAAkBJ,QAAQ,GAC3CK,gBAAgBC,iBAAiBN,QAAQ;AAE/C,SAAIK,cAAcE,WAAW,IACpB,KAGiBJ,eAAeK,QAASC,CAChDC,UAAAA,wBAAwBD,MAAME,IAAI,IAAKF,MAAME,KAAKC,YAAY,CAAM,IAAA,CACtE,CAAA,EAEyBC,OAAQC,CAAAA,YAC/BT,cAAcU,KAAMC,CAAAA,SAASA,KAAKL,KAAKM,OAAOC,SAASJ,QAAQK,IAAI,CAAC,CACtE;AACF,GCtBaC,mBAA6DA,CAAC;AAAA,EACzEnB;AACF,MACSoB,YAAY;AAAA,EAACC,QAAQrB,QAAQsB;AAAAA,EAAOrB,WAAWD,QAAQC;AAAS,CAAC,GCL7DsB,eAAgDA,CAAC;AAAA,EAACvB;AAAO,MAC7DA,QAAQC,WCAJuB,WAAqDA,CAAC;AAAA,EACjExB;AACF,MACSA,QAAQsB;ACDV,SAASG,sBACdC,OACyB;AACzB,SAAQ3B,CAAa,aAAA;AACf,QAAA,CAACA,SAASC,QAAQC;AACb,aAAA;AAGT,UAAMA,YAAY0B,iBAAiB5B,SAASC,QAAQC,SAAS,GAEvD2B,gBAAgBC,aAAaH,MAAMI,KAAK,CAAC,CAAC,IAC5CJ,MAAMI,KAAK,CAAC,EAAEZ,OACda,QACEC,gBAAgBH,aAAaH,MAAMI,KAAK,CAAC,CAAC,IAC5CJ,MAAMI,KAAK,CAAC,EAAEZ,OACda,QAEEE,cAAcJ,aAAa5B,UAAUiC,MAAMJ,KAAK,CAAC,CAAC,IACp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gBd,aAAa5B,UAAUyC,OAAOZ,KAAK,CAAC,CAAC,IACvD7B,UAAUyC,OAAOZ,KAAK,CAAC,EAAEZ,OACzBa;AAEA,QAAA,CAACH,iBAAiB,CAACa;AACd,aAAA;AAGT,QAAIG,SAAS;AAEFpC,eAAAA,SAAST,SAASC,QAAQsB,OAAO;AACtCd,UAAAA,MAAMU,SAASU,eAAe;AAC5BpB,YAAAA,MAAMU,SAASuB,eAAe;AACvB,mBAAA;AACT;AAAA,QAAA;AASF,YAJI,CAAChC,wBAAwBD,KAAK,KAI9B,CAACwB,iBAAiB,CAACW;AACrB;AAGSN,mBAAAA,SAAS7B,MAAM8B,UAAU;AAC9BD,cAAAA,MAAMnB,SAASc,eAAe;AAC5BK,gBAAAA,MAAMnB,SAASyB,eAAe;AACvB,uBAAA;AACT;AAAA,YAAA;AAKOjB,qBAAAA,MAAMa,SAAStC,UAAUyC,OAAOH;AACzC;AAAA,UAAA;AAGF,cAAIF,MAAMnB,SAASyB;AACjB;AAAA,QAAA;AAAA,MAEJ;AAGF,UAAInC,MAAMU,SAASuB;AACjB;AAAA,IAAA;AAIGG,WAAAA;AAAAA,EACT;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.27.0",
3
+ "version": "1.28.0",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -75,7 +75,7 @@
75
75
  "lodash.startcase": "^4.4.0",
76
76
  "react-compiler-runtime": "19.0.0-beta-27714ef-20250124",
77
77
  "slate": "0.112.0",
78
- "slate-dom": "^0.111.0",
78
+ "slate-dom": "^0.112.2",
79
79
  "slate-react": "0.112.1",
80
80
  "use-effect-event": "^1.0.2",
81
81
  "xstate": "^5.19.2",
@@ -85,7 +85,7 @@
85
85
  "devDependencies": {
86
86
  "@portabletext/toolkit": "^2.0.16",
87
87
  "@sanity/diff-match-patch": "^3.2.0",
88
- "@sanity/pkg-utils": "^7.0.3",
88
+ "@sanity/pkg-utils": "^7.0.4",
89
89
  "@sanity/schema": "^3.72.1",
90
90
  "@sanity/types": "^3.72.1",
91
91
  "@testing-library/jest-dom": "^6.6.3",
@@ -24,109 +24,119 @@ export const insertBreakActionImplementation: BehaviorActionImplementation<
24
24
  const selectionAcrossBlocks = anchorBlockPath[0] !== focusBlockPath[0]
25
25
 
26
26
  if (!selectionAcrossBlocks) {
27
- Editor.withoutNormalizing(editor, () => {
28
- if (!editor.selection) {
29
- return
30
- }
27
+ Transforms.splitNodes(editor, {
28
+ at: editor.selection,
29
+ })
31
30
 
32
- Transforms.splitNodes(editor, {
33
- at: editor.selection,
34
- })
31
+ const [nextBlock, nextBlockPath] = Editor.node(
32
+ editor,
33
+ Path.next(focusBlockPath),
34
+ {depth: 1},
35
+ )
35
36
 
36
- const [nextNode, nextNodePath] = Editor.node(
37
+ const nextChild = Node.child(nextBlock, 0)
38
+ const firstChildIsInlineObject = !editor.isTextSpan(nextChild)
39
+
40
+ if (firstChildIsInlineObject) {
41
+ // If the first child in the next block is an inline object then we
42
+ // add an empty span right before it to a place to put the cursor.
43
+ // This is a Slate constraint that we have to adhere to.
44
+ Transforms.insertNodes(
37
45
  editor,
38
- Path.next(focusBlockPath),
39
- {depth: 1},
46
+ {
47
+ _key: context.keyGenerator(),
48
+ _type: 'span',
49
+ text: '',
50
+ marks: [],
51
+ },
52
+ {
53
+ at: [nextBlockPath[0], 0],
54
+ },
40
55
  )
56
+ }
41
57
 
42
- Transforms.setSelection(editor, {
43
- anchor: {path: [...nextNodePath, 0], offset: 0},
44
- focus: {path: [...nextNodePath, 0], offset: 0},
45
- })
46
-
47
- /**
48
- * Assign new keys to markDefs that are now split across two blocks
49
- */
50
- if (
51
- editor.isTextBlock(nextNode) &&
52
- nextNode.markDefs &&
53
- nextNode.markDefs.length > 0
54
- ) {
55
- const newMarkDefKeys = new Map<string, string>()
56
-
57
- const prevNodeSpans = Array.from(
58
- Node.children(editor, focusBlockPath),
59
- )
60
- .map((entry) => entry[0])
61
- .filter((node) => editor.isTextSpan(node))
62
- const children = Node.children(editor, nextNodePath)
58
+ Transforms.setSelection(editor, {
59
+ anchor: {path: [...nextBlockPath, 0], offset: 0},
60
+ focus: {path: [...nextBlockPath, 0], offset: 0},
61
+ })
63
62
 
64
- for (const [child, childPath] of children) {
65
- if (!editor.isTextSpan(child)) {
66
- continue
67
- }
63
+ /**
64
+ * Assign new keys to markDefs that are now split across two blocks
65
+ */
66
+ if (
67
+ editor.isTextBlock(nextBlock) &&
68
+ nextBlock.markDefs &&
69
+ nextBlock.markDefs.length > 0
70
+ ) {
71
+ const newMarkDefKeys = new Map<string, string>()
72
+
73
+ const prevNodeSpans = Array.from(Node.children(editor, focusBlockPath))
74
+ .map((entry) => entry[0])
75
+ .filter((node) => editor.isTextSpan(node))
76
+ const children = Node.children(editor, nextBlockPath)
77
+
78
+ for (const [child, childPath] of children) {
79
+ if (!editor.isTextSpan(child)) {
80
+ continue
81
+ }
68
82
 
69
- const marks = child.marks ?? []
70
-
71
- // Go through the marks of the span and figure out if any of
72
- // them refer to annotations that are also present in the
73
- // previous block
74
- for (const mark of marks) {
75
- if (
76
- schema.decorators.some((decorator) => decorator.value === mark)
77
- ) {
78
- continue
79
- }
80
-
81
- if (
82
- prevNodeSpans.some((prevNodeSpan) =>
83
- prevNodeSpan.marks?.includes(mark),
84
- ) &&
85
- !newMarkDefKeys.has(mark)
86
- ) {
87
- // This annotation is both present in the previous block
88
- // and this block, so let's assign a new key to it
89
- newMarkDefKeys.set(mark, keyGenerator())
90
- }
91
- }
83
+ const marks = child.marks ?? []
92
84
 
93
- const newMarks = marks.map(
94
- (mark) => newMarkDefKeys.get(mark) ?? mark,
95
- )
85
+ // Go through the marks of the span and figure out if any of
86
+ // them refer to annotations that are also present in the
87
+ // previous block
88
+ for (const mark of marks) {
89
+ if (
90
+ schema.decorators.some((decorator) => decorator.value === mark)
91
+ ) {
92
+ continue
93
+ }
96
94
 
97
- // No need to update the marks if they are the same
98
- if (!isEqual(marks, newMarks)) {
99
- Transforms.setNodes(
100
- editor,
101
- {marks: newMarks},
102
- {
103
- at: childPath,
104
- },
105
- )
95
+ if (
96
+ prevNodeSpans.some((prevNodeSpan) =>
97
+ prevNodeSpan.marks?.includes(mark),
98
+ ) &&
99
+ !newMarkDefKeys.has(mark)
100
+ ) {
101
+ // This annotation is both present in the previous block
102
+ // and this block, so let's assign a new key to it
103
+ newMarkDefKeys.set(mark, keyGenerator())
106
104
  }
107
105
  }
108
106
 
109
- // Time to update all the markDefs that need a new key because
110
- // they've been split across blocks
111
- const newMarkDefs = nextNode.markDefs.map((markDef) => ({
112
- ...markDef,
113
- _key: newMarkDefKeys.get(markDef._key) ?? markDef._key,
114
- }))
107
+ const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark)
115
108
 
116
- // No need to update the markDefs if they are the same
117
- if (!isEqual(nextNode.markDefs, newMarkDefs)) {
109
+ // No need to update the marks if they are the same
110
+ if (!isEqual(marks, newMarks)) {
118
111
  Transforms.setNodes(
119
112
  editor,
120
- {markDefs: newMarkDefs},
113
+ {marks: newMarks},
121
114
  {
122
- at: nextNodePath,
123
- match: (node) => editor.isTextBlock(node),
115
+ at: childPath,
124
116
  },
125
117
  )
126
118
  }
127
119
  }
128
- })
129
- editor.onChange()
120
+
121
+ // Time to update all the markDefs that need a new key because
122
+ // they've been split across blocks
123
+ const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
124
+ ...markDef,
125
+ _key: newMarkDefKeys.get(markDef._key) ?? markDef._key,
126
+ }))
127
+
128
+ // No need to update the markDefs if they are the same
129
+ if (!isEqual(nextBlock.markDefs, newMarkDefs)) {
130
+ Transforms.setNodes(
131
+ editor,
132
+ {markDefs: newMarkDefs},
133
+ {
134
+ at: nextBlockPath,
135
+ match: (node) => editor.isTextBlock(node),
136
+ },
137
+ )
138
+ }
139
+ }
130
140
  return
131
141
  }
132
142
  }