@portabletext/editor 1.42.0 → 1.43.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 (38) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +522 -418
  2. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-active-style.cjs +14 -0
  4. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +2 -2
  6. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
  7. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  8. package/lib/_chunks-es/editor-provider.js +527 -423
  9. package/lib/_chunks-es/editor-provider.js.map +1 -1
  10. package/lib/_chunks-es/selector.is-active-style.js +15 -1
  11. package/lib/_chunks-es/selector.is-active-style.js.map +1 -1
  12. package/lib/_chunks-es/selector.is-overlapping-selection.js +2 -2
  13. package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
  14. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  15. package/lib/behaviors/index.d.cts +11 -11
  16. package/lib/behaviors/index.d.ts +11 -11
  17. package/lib/index.d.cts +1 -1
  18. package/lib/index.d.ts +1 -1
  19. package/lib/plugins/index.d.cts +1 -1
  20. package/lib/plugins/index.d.ts +1 -1
  21. package/lib/selectors/index.cjs +3 -8
  22. package/lib/selectors/index.cjs.map +1 -1
  23. package/lib/selectors/index.d.cts +1 -1
  24. package/lib/selectors/index.d.ts +1 -1
  25. package/lib/selectors/index.js +5 -11
  26. package/lib/selectors/index.js.map +1 -1
  27. package/lib/utils/index.d.cts +1 -1
  28. package/lib/utils/index.d.ts +1 -1
  29. package/package.json +7 -7
  30. package/src/behavior-actions/behavior.actions.ts +6 -0
  31. package/src/behaviors/behavior.default.ts +67 -1
  32. package/src/behaviors/behavior.perform-event.ts +266 -0
  33. package/src/editor/editor-machine.ts +31 -254
  34. package/src/editor/with-applying-behavior-actions.ts +13 -4
  35. package/src/internal-utils/parse-blocks.ts +14 -0
  36. package/src/plugins/plugin.markdown.test.tsx +64 -0
  37. package/src/selectors/selector.get-active-annotations.test.ts +28 -0
  38. package/src/selectors/selector.get-active-annotations.ts +15 -2
@@ -255,11 +255,12 @@ export declare const coreBehaviors: Behavior_2<
255
255
  | 'deserialize'
256
256
  | 'deserialization.failure'
257
257
  | 'deserialization.success'
258
+ | 'focus'
258
259
  | 'delete'
259
260
  | 'select'
260
261
  | '*'
261
262
  | 'blur'
262
- | 'focus'
263
+ | 'focus.*'
263
264
  | 'style.*'
264
265
  | 'block.*'
265
266
  | 'delete.*'
@@ -271,7 +272,6 @@ export declare const coreBehaviors: Behavior_2<
271
272
  | 'data transfer.*'
272
273
  | 'decorator.*'
273
274
  | 'deserialization.*'
274
- | 'focus.*'
275
275
  | 'insert.*'
276
276
  | 'list item.*'
277
277
  | 'serialization.*'
@@ -673,11 +673,12 @@ export declare function createCodeEditorBehaviors(
673
673
  | 'deserialize'
674
674
  | 'deserialization.failure'
675
675
  | 'deserialization.success'
676
+ | 'focus'
676
677
  | 'delete'
677
678
  | 'select'
678
679
  | '*'
679
680
  | 'blur'
680
- | 'focus'
681
+ | 'focus.*'
681
682
  | 'style.*'
682
683
  | 'block.*'
683
684
  | 'delete.*'
@@ -689,7 +690,6 @@ export declare function createCodeEditorBehaviors(
689
690
  | 'data transfer.*'
690
691
  | 'decorator.*'
691
692
  | 'deserialization.*'
692
- | 'focus.*'
693
693
  | 'insert.*'
694
694
  | 'list item.*'
695
695
  | 'serialization.*'
@@ -1091,11 +1091,12 @@ export declare function createEmojiPickerBehaviors<TEmojiMatch>(
1091
1091
  | 'deserialize'
1092
1092
  | 'deserialization.failure'
1093
1093
  | 'deserialization.success'
1094
+ | 'focus'
1094
1095
  | 'delete'
1095
1096
  | 'select'
1096
1097
  | '*'
1097
1098
  | 'blur'
1098
- | 'focus'
1099
+ | 'focus.*'
1099
1100
  | 'style.*'
1100
1101
  | 'block.*'
1101
1102
  | 'delete.*'
@@ -1107,7 +1108,6 @@ export declare function createEmojiPickerBehaviors<TEmojiMatch>(
1107
1108
  | 'data transfer.*'
1108
1109
  | 'decorator.*'
1109
1110
  | 'deserialization.*'
1110
- | 'focus.*'
1111
1111
  | 'insert.*'
1112
1112
  | 'list item.*'
1113
1113
  | 'serialization.*'
@@ -1509,11 +1509,12 @@ export declare function createLinkBehaviors(
1509
1509
  | 'deserialize'
1510
1510
  | 'deserialization.failure'
1511
1511
  | 'deserialization.success'
1512
+ | 'focus'
1512
1513
  | 'delete'
1513
1514
  | 'select'
1514
1515
  | '*'
1515
1516
  | 'blur'
1516
- | 'focus'
1517
+ | 'focus.*'
1517
1518
  | 'style.*'
1518
1519
  | 'block.*'
1519
1520
  | 'delete.*'
@@ -1525,7 +1526,6 @@ export declare function createLinkBehaviors(
1525
1526
  | 'data transfer.*'
1526
1527
  | 'decorator.*'
1527
1528
  | 'deserialization.*'
1528
- | 'focus.*'
1529
1529
  | 'insert.*'
1530
1530
  | 'list item.*'
1531
1531
  | 'serialization.*'
@@ -1969,11 +1969,12 @@ export declare function createMarkdownBehaviors(
1969
1969
  | 'deserialize'
1970
1970
  | 'deserialization.failure'
1971
1971
  | 'deserialization.success'
1972
+ | 'focus'
1972
1973
  | 'delete'
1973
1974
  | 'select'
1974
1975
  | '*'
1975
1976
  | 'blur'
1976
- | 'focus'
1977
+ | 'focus.*'
1977
1978
  | 'style.*'
1978
1979
  | 'block.*'
1979
1980
  | 'delete.*'
@@ -1985,7 +1986,6 @@ export declare function createMarkdownBehaviors(
1985
1986
  | 'data transfer.*'
1986
1987
  | 'decorator.*'
1987
1988
  | 'deserialization.*'
1988
- | 'focus.*'
1989
1989
  | 'insert.*'
1990
1990
  | 'list item.*'
1991
1991
  | 'serialization.*'
@@ -3024,7 +3024,7 @@ declare const editorMachine: StateMachine<
3024
3024
  }
3025
3025
  'handle behavior event': {
3026
3026
  type: 'handle behavior event'
3027
- params: NonReducibleUnknown
3027
+ params: unknown
3028
3028
  }
3029
3029
  }>,
3030
3030
  never,
@@ -255,11 +255,12 @@ export declare const coreBehaviors: Behavior_2<
255
255
  | 'deserialize'
256
256
  | 'deserialization.failure'
257
257
  | 'deserialization.success'
258
+ | 'focus'
258
259
  | 'delete'
259
260
  | 'select'
260
261
  | '*'
261
262
  | 'blur'
262
- | 'focus'
263
+ | 'focus.*'
263
264
  | 'style.*'
264
265
  | 'block.*'
265
266
  | 'delete.*'
@@ -271,7 +272,6 @@ export declare const coreBehaviors: Behavior_2<
271
272
  | 'data transfer.*'
272
273
  | 'decorator.*'
273
274
  | 'deserialization.*'
274
- | 'focus.*'
275
275
  | 'insert.*'
276
276
  | 'list item.*'
277
277
  | 'serialization.*'
@@ -673,11 +673,12 @@ export declare function createCodeEditorBehaviors(
673
673
  | 'deserialize'
674
674
  | 'deserialization.failure'
675
675
  | 'deserialization.success'
676
+ | 'focus'
676
677
  | 'delete'
677
678
  | 'select'
678
679
  | '*'
679
680
  | 'blur'
680
- | 'focus'
681
+ | 'focus.*'
681
682
  | 'style.*'
682
683
  | 'block.*'
683
684
  | 'delete.*'
@@ -689,7 +690,6 @@ export declare function createCodeEditorBehaviors(
689
690
  | 'data transfer.*'
690
691
  | 'decorator.*'
691
692
  | 'deserialization.*'
692
- | 'focus.*'
693
693
  | 'insert.*'
694
694
  | 'list item.*'
695
695
  | 'serialization.*'
@@ -1091,11 +1091,12 @@ export declare function createEmojiPickerBehaviors<TEmojiMatch>(
1091
1091
  | 'deserialize'
1092
1092
  | 'deserialization.failure'
1093
1093
  | 'deserialization.success'
1094
+ | 'focus'
1094
1095
  | 'delete'
1095
1096
  | 'select'
1096
1097
  | '*'
1097
1098
  | 'blur'
1098
- | 'focus'
1099
+ | 'focus.*'
1099
1100
  | 'style.*'
1100
1101
  | 'block.*'
1101
1102
  | 'delete.*'
@@ -1107,7 +1108,6 @@ export declare function createEmojiPickerBehaviors<TEmojiMatch>(
1107
1108
  | 'data transfer.*'
1108
1109
  | 'decorator.*'
1109
1110
  | 'deserialization.*'
1110
- | 'focus.*'
1111
1111
  | 'insert.*'
1112
1112
  | 'list item.*'
1113
1113
  | 'serialization.*'
@@ -1509,11 +1509,12 @@ export declare function createLinkBehaviors(
1509
1509
  | 'deserialize'
1510
1510
  | 'deserialization.failure'
1511
1511
  | 'deserialization.success'
1512
+ | 'focus'
1512
1513
  | 'delete'
1513
1514
  | 'select'
1514
1515
  | '*'
1515
1516
  | 'blur'
1516
- | 'focus'
1517
+ | 'focus.*'
1517
1518
  | 'style.*'
1518
1519
  | 'block.*'
1519
1520
  | 'delete.*'
@@ -1525,7 +1526,6 @@ export declare function createLinkBehaviors(
1525
1526
  | 'data transfer.*'
1526
1527
  | 'decorator.*'
1527
1528
  | 'deserialization.*'
1528
- | 'focus.*'
1529
1529
  | 'insert.*'
1530
1530
  | 'list item.*'
1531
1531
  | 'serialization.*'
@@ -1969,11 +1969,12 @@ export declare function createMarkdownBehaviors(
1969
1969
  | 'deserialize'
1970
1970
  | 'deserialization.failure'
1971
1971
  | 'deserialization.success'
1972
+ | 'focus'
1972
1973
  | 'delete'
1973
1974
  | 'select'
1974
1975
  | '*'
1975
1976
  | 'blur'
1976
- | 'focus'
1977
+ | 'focus.*'
1977
1978
  | 'style.*'
1978
1979
  | 'block.*'
1979
1980
  | 'delete.*'
@@ -1985,7 +1986,6 @@ export declare function createMarkdownBehaviors(
1985
1986
  | 'data transfer.*'
1986
1987
  | 'decorator.*'
1987
1988
  | 'deserialization.*'
1988
- | 'focus.*'
1989
1989
  | 'insert.*'
1990
1990
  | 'list item.*'
1991
1991
  | 'serialization.*'
@@ -3024,7 +3024,7 @@ declare const editorMachine: StateMachine<
3024
3024
  }
3025
3025
  'handle behavior event': {
3026
3026
  type: 'handle behavior event'
3027
- params: NonReducibleUnknown
3027
+ params: unknown
3028
3028
  }
3029
3029
  }>,
3030
3030
  never,
package/lib/index.d.cts CHANGED
@@ -1154,7 +1154,7 @@ declare const editorMachine: StateMachine<
1154
1154
  }
1155
1155
  'handle behavior event': {
1156
1156
  type: 'handle behavior event'
1157
- params: NonReducibleUnknown
1157
+ params: unknown
1158
1158
  }
1159
1159
  }>,
1160
1160
  never,
package/lib/index.d.ts CHANGED
@@ -1154,7 +1154,7 @@ declare const editorMachine: StateMachine<
1154
1154
  }
1155
1155
  'handle behavior event': {
1156
1156
  type: 'handle behavior event'
1157
- params: NonReducibleUnknown
1157
+ params: unknown
1158
1158
  }
1159
1159
  }>,
1160
1160
  never,
@@ -944,7 +944,7 @@ declare const editorMachine: StateMachine<
944
944
  }
945
945
  'handle behavior event': {
946
946
  type: 'handle behavior event'
947
- params: NonReducibleUnknown
947
+ params: unknown
948
948
  }
949
949
  }>,
950
950
  never,
@@ -944,7 +944,7 @@ declare const editorMachine: StateMachine<
944
944
  }
945
945
  'handle behavior event': {
946
946
  type: 'handle behavior event'
947
- params: NonReducibleUnknown
947
+ params: unknown
948
948
  }
949
949
  }>,
950
950
  never,
@@ -1,12 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var selector_isActiveStyle = require("../_chunks-cjs/selector.is-active-style.cjs"), types = require("@sanity/types"), selector_isOverlappingSelection = require("../_chunks-cjs/selector.is-overlapping-selection.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), selector_getFocusInlineObject = require("../_chunks-cjs/selector.get-focus-inline-object.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs");
4
- const getActiveAnnotations = (snapshot) => {
5
- if (!snapshot.context.selection)
6
- return [];
7
- const selectedBlocks = selector_isOverlappingSelection.getSelectedBlocks(snapshot), selectedSpans = selector_isActiveStyle.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
- }, getAnchorBlock = (snapshot) => {
3
+ var selector_isActiveStyle = require("../_chunks-cjs/selector.is-active-style.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), types = require("@sanity/types"), selector_isOverlappingSelection = require("../_chunks-cjs/selector.is-overlapping-selection.cjs"), selector_getFocusInlineObject = require("../_chunks-cjs/selector.get-focus-inline-object.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs");
4
+ const getAnchorBlock = (snapshot) => {
10
5
  const key = snapshot.context.selection && util_sliceBlocks.isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
11
6
  return node && key ? {
12
7
  node,
@@ -55,6 +50,7 @@ const getActiveAnnotations = (snapshot) => {
55
50
  end
56
51
  } : void 0;
57
52
  }, getSelection = (snapshot) => snapshot.context.selection, getValue = (snapshot) => snapshot.context.value;
53
+ exports.getActiveAnnotations = selector_isActiveStyle.getActiveAnnotations;
58
54
  exports.getActiveListItem = selector_isActiveStyle.getActiveListItem;
59
55
  exports.getActiveStyle = selector_isActiveStyle.getActiveStyle;
60
56
  exports.getSelectedSpans = selector_isActiveStyle.getSelectedSpans;
@@ -93,7 +89,6 @@ exports.isSelectionCollapsed = selector_isOverlappingSelection.isSelectionCollap
93
89
  exports.isSelectionExpanded = selector_isOverlappingSelection.isSelectionExpanded;
94
90
  exports.getFocusInlineObject = selector_getFocusInlineObject.getFocusInlineObject;
95
91
  exports.getBlockTextBefore = selector_getTextBefore.getBlockTextBefore;
96
- exports.getActiveAnnotations = getActiveAnnotations;
97
92
  exports.getAnchorBlock = getAnchorBlock;
98
93
  exports.getAnchorChild = getAnchorChild;
99
94
  exports.getAnchorSpan = getAnchorSpan;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.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 {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isPortableTextTextBlock(anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getActiveAnnotations","snapshot","context","selection","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getAnchorBlock","key","isKeyedSegment","anchor","path","undefined","value","find","getAnchorTextBlock","anchorBlock","getAnchorChild","children","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue"],"mappings":";;;AAQO,MAAMA,uBACXC,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX,QAAMC,iBAAiBC,gCAAAA,kBAAkBJ,QAAQ,GAC3CK,gBAAgBC,wCAAiBN,QAAQ;AAE/C,SAAIK,cAAcE,WAAW,IACpB,KAGiBJ,eAAeK,QAASC,CAChDC,UAAAA,MAAAA,wBAAwBD,MAAME,IAAI,IAAKF,MAAME,KAAKC,YAAY,CAAM,IAAA,CACtE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AA,IAAI,CAAA;AAAA,EAAA,IAC1DI;AACN,GC3BaO,gBAGRhC,CAAa,aAAA;AACViC,QAAAA,cAAcH,eAAe9B,QAAQ;AAE3C,SAAOiC,eAAeC,MAAAA,mBAAmBD,YAAYtB,IAAI,IACrD;AAAA,IAACA,MAAMsB,YAAYtB;AAAAA,IAAMa,MAAMS,YAAYT;AAAAA,EAAAA,IAC3CC;AACN,GCRaU,kBAERnC,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMkC,sBAAsBC,gCAAAA,uBAAuBrC,QAAQ,GACrDsC,oBAAoBC,qDAAqBvC,QAAQ;AAEnD,MAAA,CAACoC,uBAAuB,CAACE;AAC3B;AAGIE,QAAAA,QAAQC,iBAAAA,gCAAsC;AAAA,IAClDf,OAAO1B,SAASC,QAAQyB;AAAAA,IACxBgB,gBAAgBN;AAAAA,EAAAA,CACjB,GACKO,MAAMF,iDAAsC;AAAA,IAChDf,OAAO1B,SAASC,QAAQyB;AAAAA,IACxBgB,gBAAgBJ;AAAAA,EAAAA,CACjB;AAED,SAAOE,SAASG,MAAM;AAAA,IAACH;AAAAA,IAAOG;AAAAA,EAAAA,IAAOlB;AACvC,GC3BamB,eAAiD5C,CACrDA,aAAAA,SAASC,QAAQC,WCDb2C,WACX7C,CAEOA,aAAAA,SAASC,QAAQyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isPortableTextTextBlock(anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","key","context","selection","isKeyedSegment","anchor","path","_key","undefined","node","value","find","block","getAnchorTextBlock","anchorBlock","isPortableTextTextBlock","getAnchorChild","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue"],"mappings":";;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,iBAAAA,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMC,CAAAA,UAAUA,MAAML,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GCVaK,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,MAAAA,wBAAwBD,YAAYL,IAAI,IAC1D;AAAA,IAACA,MAAMK,YAAYL;AAAAA,IAAMH,MAAMQ,YAAYR;AAAAA,EAAAA,IAC3CE;AACN,GCVaQ,iBAMRhB,CAAa,aAAA;AACVc,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMb,MAAMD,SAASE,QAAQC,aACzBC,iBAAAA,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTa,YAAYL,KAAKQ,SAASN,KAAMO,CAAAA,SAASA,KAAKX,SAASN,GAAG,IAC1DO;AAEJ,SAAOC,QAAQR,MACX;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC,GAAGQ,YAAYR,MAAM,YAAY;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAC1DO;AACN,GC3BaW,gBAGRnB,CAAa,aAAA;AACVoB,QAAAA,cAAcJ,eAAehB,QAAQ;AAE3C,SAAOoB,eAAeC,MAAAA,mBAAmBD,YAAYX,IAAI,IACrD;AAAA,IAACA,MAAMW,YAAYX;AAAAA,IAAMH,MAAMc,YAAYd;AAAAA,EAAAA,IAC3CE;AACN,GCRac,kBAERtB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASE,QAAQC;AACpB;AAGF,QAAMoB,sBAAsBC,gCAAAA,uBAAuBxB,QAAQ,GACrDyB,oBAAoBC,qDAAqB1B,QAAQ;AAEnD,MAAA,CAACuB,uBAAuB,CAACE;AAC3B;AAGIE,QAAAA,QAAQC,iBAAAA,gCAAsC;AAAA,IAClDlB,OAAOV,SAASE,QAAQQ;AAAAA,IACxBmB,gBAAgBN;AAAAA,EAAAA,CACjB,GACKO,MAAMF,iDAAsC;AAAA,IAChDlB,OAAOV,SAASE,QAAQQ;AAAAA,IACxBmB,gBAAgBJ;AAAAA,EAAAA,CACjB;AAED,SAAOE,SAASG,MAAM;AAAA,IAACH;AAAAA,IAAOG;AAAAA,EAAAA,IAAOtB;AACvC,GC3BauB,eAAiD/B,CACrDA,aAAAA,SAASE,QAAQC,WCDb6B,WACXhC,CAEOA,aAAAA,SAASE,QAAQQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -850,7 +850,7 @@ declare const editorMachine: StateMachine<
850
850
  }
851
851
  'handle behavior event': {
852
852
  type: 'handle behavior event'
853
- params: NonReducibleUnknown
853
+ params: unknown
854
854
  }
855
855
  }>,
856
856
  never,
@@ -850,7 +850,7 @@ declare const editorMachine: StateMachine<
850
850
  }
851
851
  'handle behavior event': {
852
852
  type: 'handle behavior event'
853
- params: NonReducibleUnknown
853
+ params: unknown
854
854
  }
855
855
  }>,
856
856
  never,
@@ -1,17 +1,11 @@
1
- import { getSelectedSpans } from "../_chunks-es/selector.is-active-style.js";
2
- import { getActiveListItem, getActiveStyle, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isSelectingEntireBlocks } from "../_chunks-es/selector.is-active-style.js";
3
- import { isPortableTextTextBlock, isPortableTextSpan } from "@sanity/types";
4
- import { getSelectedBlocks, getSelectionStartPoint, getSelectionEndPoint } from "../_chunks-es/selector.is-overlapping-selection.js";
5
- import { getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedSlice, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-overlapping-selection.js";
1
+ import { getActiveAnnotations, getActiveListItem, getActiveStyle, getSelectedSpans, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isSelectingEntireBlocks } from "../_chunks-es/selector.is-active-style.js";
6
2
  import { isKeyedSegment, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
3
+ import { isPortableTextTextBlock, isPortableTextSpan } from "@sanity/types";
4
+ import { getSelectionStartPoint, getSelectionEndPoint } from "../_chunks-es/selector.is-overlapping-selection.js";
5
+ import { getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-overlapping-selection.js";
7
6
  import { getFocusInlineObject } from "../_chunks-es/selector.get-focus-inline-object.js";
8
7
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
9
- const getActiveAnnotations = (snapshot) => {
10
- if (!snapshot.context.selection)
11
- return [];
12
- const selectedBlocks = getSelectedBlocks(snapshot), selectedSpans = getSelectedSpans(snapshot);
13
- return selectedSpans.length === 0 ? [] : selectedBlocks.flatMap((block) => isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => selectedSpans.some((span) => span.node.marks?.includes(markDef._key)));
14
- }, getAnchorBlock = (snapshot) => {
8
+ const getAnchorBlock = (snapshot) => {
15
9
  const key = snapshot.context.selection && isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
16
10
  return node && key ? {
17
11
  node,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.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 {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isPortableTextTextBlock(anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getActiveAnnotations","snapshot","context","selection","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getAnchorBlock","key","isKeyedSegment","anchor","path","undefined","value","find","getAnchorTextBlock","anchorBlock","getAnchorChild","children","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue"],"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,iBAERpB,CAAa,aAAA;AAChB,QAAMqB,MAAMrB,SAASC,QAAQC,aACzBoB,eAAetB,SAASC,QAAQC,UAAUqB,OAAOC,KAAK,CAAC,CAAC,IACtDxB,SAASC,QAAQC,UAAUqB,OAAOC,KAAK,CAAC,EAAEL,OAE5CM,QAEEd,OAAOU,MACTrB,SAASC,QAAQyB,MAAMC,KAAMlB,CAAAA,UAAUA,MAAMU,SAASE,GAAG,IACzDI;AAEJ,SAAOd,QAAQU,MAAM;AAAA,IAACV;AAAAA,IAAMa,MAAM,CAAC;AAAA,MAACL,MAAME;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKI;AACrD,GCVaG,qBAER5B,CAAa,aAAA;AACV6B,QAAAA,cAAcT,eAAepB,QAAQ;AAE3C,SAAO6B,eAAenB,wBAAwBmB,YAAYlB,IAAI,IAC1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ACH;AAAAA,IAAOG;AAAAA,EAAAA,IAAOlB;AACvC,GC3BamB,eAAiD5C,CACrDA,aAAAA,SAASC,QAAQC,WCDb2C,WACX7C,CAEOA,aAAAA,SAASC,QAAQyB;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isPortableTextTextBlock(anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","key","context","selection","isKeyedSegment","anchor","path","_key","undefined","node","value","find","block","getAnchorTextBlock","anchorBlock","isPortableTextTextBlock","getAnchorChild","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue"],"mappings":";;;;;;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,eAAeJ,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,CAAC,IACtDN,SAASE,QAAQC,UAAUE,OAAOC,KAAK,CAAC,EAAEC,OAE5CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMC,CAAAA,UAAUA,MAAML,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GCVaK,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,wBAAwBD,YAAYL,IAAI,IAC1D;AAAA,IAACA,MAAMK,YAAYL;AAAAA,IAAMH,MAAMQ,YAAYR;AAAAA,EAAAA,IAC3CE;AACN,GCVaQ,iBAMRhB,CAAa,aAAA;AACVc,QAAAA,cAAcD,mBAAmBb,QA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const editorMachine: StateMachine<
919
919
  }
920
920
  'handle behavior event': {
921
921
  type: 'handle behavior event'
922
- params: NonReducibleUnknown
922
+ params: unknown
923
923
  }
924
924
  }>,
925
925
  never,
@@ -919,7 +919,7 @@ declare const editorMachine: StateMachine<
919
919
  }
920
920
  'handle behavior event': {
921
921
  type: 'handle behavior event'
922
- params: NonReducibleUnknown
922
+ params: unknown
923
923
  }
924
924
  }>,
925
925
  never,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.42.0",
3
+ "version": "1.43.0",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -79,15 +79,15 @@
79
79
  "slate-react": "0.112.1",
80
80
  "use-effect-event": "^1.0.2",
81
81
  "xstate": "^5.19.2",
82
- "@portabletext/block-tools": "1.1.14",
82
+ "@portabletext/block-tools": "1.1.15",
83
83
  "@portabletext/patches": "1.1.3"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@portabletext/toolkit": "^2.0.17",
87
87
  "@sanity/diff-match-patch": "^3.2.0",
88
- "@sanity/pkg-utils": "^7.1.1",
89
- "@sanity/schema": "^3.80.1",
90
- "@sanity/types": "^3.80.1",
88
+ "@sanity/pkg-utils": "^7.2.0",
89
+ "@sanity/schema": "^3.81.0",
90
+ "@sanity/types": "^3.81.0",
91
91
  "@testing-library/jest-dom": "^6.6.3",
92
92
  "@testing-library/react": "^16.2.0",
93
93
  "@types/debug": "^4.1.12",
@@ -115,8 +115,8 @@
115
115
  "racejar": "1.2.3"
116
116
  },
117
117
  "peerDependencies": {
118
- "@sanity/schema": "^3.80.1",
119
- "@sanity/types": "^3.80.1",
118
+ "@sanity/schema": "^3.81.0",
119
+ "@sanity/types": "^3.81.0",
120
120
  "react": "^16.9 || ^17 || ^18 || ^19",
121
121
  "rxjs": "^7.8.2"
122
122
  },
@@ -1,3 +1,4 @@
1
+ import {omit} from 'lodash'
1
2
  import type {InternalBehaviorAction} from '../behaviors/behavior.types.action'
2
3
  import type {EditorContext} from '../editor/editor-snapshot'
3
4
  import {
@@ -13,6 +14,7 @@ import {
13
14
  historyRedoActionImplementation,
14
15
  historyUndoActionImplementation,
15
16
  } from '../editor/plugins/createWithUndoRedo'
17
+ import {debugWithName} from '../internal-utils/debug'
16
18
  import type {PickFromUnion} from '../type-utils'
17
19
  import {blockSetBehaviorActionImplementation} from './behavior.action.block.set'
18
20
  import {blockUnsetBehaviorActionImplementation} from './behavior.action.block.unset'
@@ -57,6 +59,8 @@ import {
57
59
  toggleStyleActionImplementation,
58
60
  } from './behavior.action.style'
59
61
 
62
+ const debug = debugWithName('behaviors:action')
63
+
60
64
  export type BehaviorActionImplementationContext = Pick<
61
65
  EditorContext,
62
66
  'keyGenerator' | 'schema'
@@ -130,6 +134,8 @@ export function performAction({
130
134
  context: BehaviorActionImplementationContext
131
135
  action: InternalBehaviorAction
132
136
  }) {
137
+ debug(JSON.stringify(omit(action, ['editor']), null, 2))
138
+
133
139
  switch (action.type) {
134
140
  case 'annotation.add': {
135
141
  behaviorActionImplementations['annotation.add']({
@@ -1,5 +1,6 @@
1
+ import {isTextBlock} from '../internal-utils/parse-blocks'
1
2
  import * as selectors from '../selectors'
2
- import {blockOffsetsToSelection} from '../utils'
3
+ import {blockOffsetsToSelection, getTextBlockText} from '../utils'
3
4
  import {raiseInsertSoftBreak} from './behavior.default.raise-soft-break'
4
5
  import {raise} from './behavior.types.action'
5
6
  import {defineBehavior} from './behavior.types.behavior'
@@ -387,6 +388,71 @@ export const defaultBehaviors = [
387
388
  ],
388
389
  ],
389
390
  }),
391
+ /**
392
+ * If we are pasting text/plain into a text block then we can probably
393
+ * assume that the intended behavior is that the pasted text inherits
394
+ * formatting from the text it's pasted into.
395
+ */
396
+ defineBehavior({
397
+ on: 'deserialization.success',
398
+ guard: ({snapshot, event}) => {
399
+ const focusTextBlock = selectors.getFocusTextBlock(snapshot)
400
+
401
+ if (
402
+ focusTextBlock &&
403
+ event.mimeType === 'text/plain' &&
404
+ event.originEvent.type === 'clipboard.paste'
405
+ ) {
406
+ const activeDecorators = snapshot.context.activeDecorators
407
+ const activeAnnotations = selectors.getActiveAnnotations(snapshot)
408
+
409
+ return {
410
+ activeAnnotations,
411
+ activeDecorators,
412
+ textRuns: event.data.flatMap((block) =>
413
+ isTextBlock(snapshot.context.schema, block)
414
+ ? [getTextBlockText(block)]
415
+ : [],
416
+ ),
417
+ }
418
+ }
419
+
420
+ return false
421
+ },
422
+ actions: [
423
+ (_, {activeAnnotations, activeDecorators, textRuns}) =>
424
+ textRuns.flatMap((textRun, index) =>
425
+ index !== textRuns.length - 1
426
+ ? [
427
+ raise({
428
+ type: 'insert.span',
429
+ text: textRun,
430
+ decorators: activeDecorators,
431
+ annotations: activeAnnotations.map(
432
+ ({_key, _type, ...value}) => ({
433
+ name: _type,
434
+ value,
435
+ }),
436
+ ),
437
+ }),
438
+ raise({type: 'insert.break'}),
439
+ ]
440
+ : [
441
+ raise({
442
+ type: 'insert.span',
443
+ text: textRun,
444
+ decorators: activeDecorators,
445
+ annotations: activeAnnotations.map(
446
+ ({_key, _type, ...value}) => ({
447
+ name: _type,
448
+ value,
449
+ }),
450
+ ),
451
+ }),
452
+ ],
453
+ ),
454
+ ],
455
+ }),
390
456
  defineBehavior({
391
457
  on: 'deserialization.success',
392
458
  actions: [