@portabletext/editor 1.50.8 → 1.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/lib/_chunks-cjs/{util.slice-blocks.cjs → selection-point.cjs} +26 -18
  2. package/lib/_chunks-cjs/selection-point.cjs.map +1 -0
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +13 -10
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +46 -46
  6. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +21 -17
  8. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
  9. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +10 -10
  10. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
  11. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +5 -5
  12. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
  13. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
  14. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  15. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +7 -14
  16. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  17. package/lib/_chunks-es/{util.slice-blocks.js → selection-point.js} +26 -18
  18. package/lib/_chunks-es/selection-point.js.map +1 -0
  19. package/lib/_chunks-es/selector.get-text-before.js +13 -10
  20. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  21. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +21 -21
  22. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  23. package/lib/_chunks-es/selector.is-selection-expanded.js +14 -10
  24. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
  25. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +2 -2
  26. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
  27. package/lib/_chunks-es/util.is-equal-selection-points.js +1 -1
  28. package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
  29. package/lib/_chunks-es/util.selection-point-to-block-offset.js +4 -11
  30. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  31. package/lib/behaviors/index.cjs.map +1 -1
  32. package/lib/behaviors/index.d.cts +25 -2010
  33. package/lib/behaviors/index.d.ts +25 -2010
  34. package/lib/behaviors/index.js.map +1 -1
  35. package/lib/index.cjs +515 -393
  36. package/lib/index.cjs.map +1 -1
  37. package/lib/index.d.cts +361 -34
  38. package/lib/index.d.ts +361 -34
  39. package/lib/index.js +471 -349
  40. package/lib/index.js.map +1 -1
  41. package/lib/plugins/index.cjs +11 -11
  42. package/lib/plugins/index.cjs.map +1 -1
  43. package/lib/plugins/index.d.cts +32 -1986
  44. package/lib/plugins/index.d.ts +32 -1986
  45. package/lib/plugins/index.js +1 -1
  46. package/lib/selectors/index.cjs +11 -7
  47. package/lib/selectors/index.cjs.map +1 -1
  48. package/lib/selectors/index.d.cts +2 -2648
  49. package/lib/selectors/index.d.ts +2 -2648
  50. package/lib/selectors/index.js +7 -3
  51. package/lib/selectors/index.js.map +1 -1
  52. package/lib/utils/index.cjs +25 -14
  53. package/lib/utils/index.cjs.map +1 -1
  54. package/lib/utils/index.d.cts +0 -2647
  55. package/lib/utils/index.d.ts +0 -2647
  56. package/lib/utils/index.js +14 -3
  57. package/lib/utils/index.js.map +1 -1
  58. package/package.json +14 -14
  59. package/src/behaviors/behavior.abstract.delete.ts +0 -2
  60. package/src/behaviors/behavior.abstract.insert.ts +8 -8
  61. package/src/behaviors/behavior.abstract.ts +0 -113
  62. package/src/behaviors/behavior.core.block-element.ts +9 -3
  63. package/src/behaviors/behavior.core.dnd.ts +328 -1
  64. package/src/behaviors/behavior.perform-event.ts +10 -0
  65. package/src/behaviors/behavior.types.action.ts +2 -0
  66. package/src/behaviors/behavior.types.event.ts +5 -0
  67. package/src/behaviors/behavior.types.guard.ts +2 -0
  68. package/src/converters/converter.portable-text.ts +2 -7
  69. package/src/converters/converter.text-html.ts +1 -3
  70. package/src/converters/converter.text-plain.ts +3 -5
  71. package/src/editor/Editable.tsx +6 -133
  72. package/src/editor/editor-machine.ts +15 -10
  73. package/src/editor/editor-selector.ts +0 -2
  74. package/src/editor/editor-snapshot.ts +0 -18
  75. package/src/internal-utils/create-test-snapshot.ts +0 -2
  76. package/src/internal-utils/event-position.ts +42 -30
  77. package/src/internal-utils/selection-block-keys.ts +7 -7
  78. package/src/internal-utils/selection-elements.ts +108 -0
  79. package/src/internal-utils/selection-focus-text.ts +13 -9
  80. package/src/internal-utils/selection-text.ts +9 -78
  81. package/src/internal-utils/terse-pt.test.ts +108 -26
  82. package/src/internal-utils/terse-pt.ts +132 -14
  83. package/src/operations/behavior.operation.decorator.add.ts +0 -2
  84. package/src/operations/behavior.operation.delete.ts +18 -13
  85. package/src/operations/behavior.operation.insert.block.ts +5 -1
  86. package/src/selection/selection-point.ts +22 -0
  87. package/src/selectors/selector.get-anchor-block.ts +6 -6
  88. package/src/selectors/selector.get-anchor-child.ts +6 -6
  89. package/src/selectors/selector.get-selected-spans.ts +16 -19
  90. package/src/selectors/selector.get-selected-text-blocks.ts +11 -19
  91. package/src/selectors/selector.get-selection-end-block.ts +30 -0
  92. package/src/selectors/selector.get-selection-start-block.ts +30 -0
  93. package/src/selectors/selector.get-text-before.ts +15 -16
  94. package/src/selectors/selector.get-trimmed-selection.ts +15 -21
  95. package/src/selectors/selector.is-point-after-selection.ts +11 -19
  96. package/src/selectors/selector.is-point-before-selection.ts +11 -19
  97. package/src/selectors/selectors.ts +23 -39
  98. package/src/utils/util.block-offset.ts +6 -7
  99. package/src/utils/util.child-selection-point-to-block-offset.ts +6 -7
  100. package/src/utils/util.selection-point-to-block-offset.ts +5 -6
  101. package/src/utils/util.slice-blocks.ts +11 -20
  102. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
  103. package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
  104. package/src/internal-utils/inline-object-selection.ts +0 -115
@@ -1,14 +1,25 @@
1
- import { sliceBlocks, isSpan } from "../_chunks-es/util.slice-blocks.js";
2
- import { blockOffsetToSpanSelectionPoint, getBlockStartPoint, getTextBlockText, isKeyedSegment, reverseSelection, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
1
+ import { sliceBlocks, isSpan } from "../_chunks-es/selection-point.js";
2
+ import { blockOffsetToSpanSelectionPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, getTextBlockText, isKeyedSegment, spanSelectionPointToBlockOffset } from "../_chunks-es/selection-point.js";
3
3
  import { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset } from "../_chunks-es/util.child-selection-point-to-block-offset.js";
4
4
  import { isEqualSelectionPoints } from "../_chunks-es/util.is-equal-selection-points.js";
5
5
  import { getBlockEndPoint, isEmptyTextBlock } from "../_chunks-es/util.is-equal-selection-points.js";
6
- import { getSelectionEndPoint, getSelectionStartPoint, isSelectionCollapsed, selectionPointToBlockOffset } from "../_chunks-es/util.selection-point-to-block-offset.js";
6
+ import { isSelectionCollapsed, selectionPointToBlockOffset } from "../_chunks-es/util.selection-point-to-block-offset.js";
7
7
  import { isTextBlock } from "../_chunks-es/util.merge-text-blocks.js";
8
8
  import { mergeTextBlocks } from "../_chunks-es/util.merge-text-blocks.js";
9
9
  function isEqualSelections(a, b) {
10
10
  return !a && !b ? !0 : !a || !b ? !1 : isEqualSelectionPoints(a.anchor, b.anchor) && isEqualSelectionPoints(a.focus, b.focus);
11
11
  }
12
+ function reverseSelection(selection) {
13
+ return selection && (selection.backward ? {
14
+ anchor: selection.focus,
15
+ focus: selection.anchor,
16
+ backward: !1
17
+ } : {
18
+ anchor: selection.focus,
19
+ focus: selection.anchor,
20
+ backward: !0
21
+ });
22
+ }
12
23
  function splitTextBlock({
13
24
  context,
14
25
  block,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n blocks: [block],\n }).at(0)\n const after = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n blocks: [block],\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","schema","selection","path","_key","offset","blocks","after","isSpan","text","isTextBlock"],"mappings":";;;;;;;;AAMgBA,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACTO,SAASC,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAEzD,MAAA,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,YAAY;AAAA,IACzBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBC,WAAW;AAAA,QACTd,QAAQ;AAAA,UACNe,MAAM,CAAC;AAAA,YAACC,MAAMZ,MAAMY;AAAAA,aAAO,YAAY;AAAA,YAACA,MAAMV,WAAWU;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QACV;AAAA,QACAhB,OAAOI;AAAAA,MAAAA;AAAAA,IAEX;AAAA,IACAa,QAAQ,CAACd,KAAK;AAAA,EACf,CAAA,EAAEI,GAAG,CAAC,GACDW,QAAQP,YAAY;AAAA,IACxBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBC,WAAW;AAAA,QACTd,QAAQK;AAAAA,QACRJ,OAAO;AAAA,UACLc,MAAM,CAAC;AAAA,YAACC,MAAMZ,MAAMY;AAAAA,aAAO,YAAY;AAAA,YAACA,MAAMP,UAAUO;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQG,OAAOjB,SAASM,SAAS,IAAIA,UAAUY,KAAKX,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IAEJ;AAAA,IACAQ,QAAQ,CAACd,KAAK;AAAA,EAAA,CACf,EAAEI,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACQ,UAIZ,EAACG,CAAAA,YAAYnB,SAASQ,MAAM,KAAK,CAACW,YAAYnB,SAASgB,KAAK;AAIzD,WAAA;AAAA,MAACR;AAAAA,MAAQQ;AAAAA,IAAK;AACvB;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n blocks: [block],\n }).at(0)\n const after = sliceBlocks({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n blocks: [block],\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","reverseSelection","selection","backward","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","schema","path","_key","offset","blocks","after","isSpan","text","isTextBlock"],"mappings":";;;;;;;;AAMgBA,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACdO,SAASC,iBAEdC,WAA+C;AAC1CA,SAAAA,cAIDA,UAAUC,WACL;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA,IAIP;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA;AAEd;ACfO,SAASC,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAEzD,MAAA,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,YAAY;AAAA,IACzBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQ;AAAA,UACNiB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,aAAO,YAAY;AAAA,YAACA,MAAMT,WAAWS;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QACV;AAAA,QACAlB,OAAOO;AAAAA,MAAAA;AAAAA,IAEX;AAAA,IACAY,QAAQ,CAACb,KAAK;AAAA,EACf,CAAA,EAAEI,GAAG,CAAC,GACDU,QAAQN,YAAY;AAAA,IACxBT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQQ;AAAAA,QACRP,OAAO;AAAA,UACLgB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,aAAO,YAAY;AAAA,YAACA,MAAMN,UAAUM;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQG,OAAOhB,SAASM,SAAS,IAAIA,UAAUW,KAAKV,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IAEJ;AAAA,IACAO,QAAQ,CAACb,KAAK;AAAA,EAAA,CACf,EAAEI,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACO,UAIZ,EAACG,CAAAA,YAAYlB,SAASQ,MAAM,KAAK,CAACU,YAAYlB,SAASe,KAAK;AAIzD,WAAA;AAAA,MAACP;AAAAA,MAAQO;AAAAA,IAAK;AACvB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.50.8",
3
+ "version": "1.52.0",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -68,27 +68,27 @@
68
68
  ],
69
69
  "dependencies": {
70
70
  "@portabletext/to-html": "^2.0.14",
71
- "@xstate/react": "^5.0.4",
71
+ "@xstate/react": "^5.0.5",
72
72
  "debug": "^4.4.1",
73
73
  "get-random-values-esm": "^1.0.2",
74
74
  "immer": "^10.1.1",
75
75
  "lodash": "^4.17.21",
76
76
  "lodash.startcase": "^4.4.0",
77
77
  "react-compiler-runtime": "19.1.0-rc.1",
78
- "slate": "0.114.0",
78
+ "slate": "0.115.1",
79
79
  "slate-dom": "^0.114.0",
80
80
  "slate-react": "0.114.2",
81
- "use-effect-event": "^1.0.2",
82
- "xstate": "^5.19.3",
83
- "@portabletext/patches": "1.1.4",
84
- "@portabletext/block-tools": "1.1.28"
81
+ "use-effect-event": "^2.0.0",
82
+ "xstate": "^5.19.4",
83
+ "@portabletext/block-tools": "1.1.29",
84
+ "@portabletext/patches": "1.1.4"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@portabletext/toolkit": "^2.0.17",
88
88
  "@sanity/diff-match-patch": "^3.2.0",
89
89
  "@sanity/pkg-utils": "^7.2.3",
90
- "@sanity/schema": "^3.90.0",
91
- "@sanity/types": "^3.90.0",
90
+ "@sanity/schema": "^3.91.0",
91
+ "@sanity/types": "^3.91.0",
92
92
  "@testing-library/jest-dom": "^6.6.3",
93
93
  "@testing-library/react": "^16.3.0",
94
94
  "@types/debug": "^4.1.12",
@@ -99,8 +99,8 @@
99
99
  "@typescript-eslint/eslint-plugin": "^8.33.0",
100
100
  "@typescript-eslint/parser": "^8.33.0",
101
101
  "@vitejs/plugin-react": "^4.4.1",
102
- "@vitest/browser": "^3.1.4",
103
- "@vitest/coverage-istanbul": "^3.1.4",
102
+ "@vitest/browser": "^3.2.1",
103
+ "@vitest/coverage-istanbul": "^3.2.1",
104
104
  "babel-plugin-react-compiler": "19.1.0-rc.1",
105
105
  "eslint": "8.57.1",
106
106
  "eslint-plugin-react-hooks": "0.0.0-experimental-f9ae0a4c-20250527",
@@ -110,13 +110,13 @@
110
110
  "rxjs": "^7.8.2",
111
111
  "typescript": "5.8.3",
112
112
  "vite": "^6.2.5",
113
- "vitest": "^3.1.4",
113
+ "vitest": "^3.2.1",
114
114
  "vitest-browser-react": "^0.2.0",
115
115
  "racejar": "1.2.5"
116
116
  },
117
117
  "peerDependencies": {
118
- "@sanity/schema": "^3.90.0",
119
- "@sanity/types": "^3.90.0",
118
+ "@sanity/schema": "^3.91.0",
119
+ "@sanity/types": "^3.91.0",
120
120
  "react": "^16.9 || ^17 || ^18 || ^19",
121
121
  "rxjs": "^7.8.2"
122
122
  },
@@ -80,8 +80,6 @@ export const abstractDeleteBehaviors = [
80
80
  beta: {
81
81
  activeAnnotations: [],
82
82
  activeDecorators: [],
83
- hasTag: () => false,
84
- internalDrag: undefined,
85
83
  },
86
84
  context: {
87
85
  converters: [],
@@ -14,7 +14,7 @@ export const abstractInsertBehaviors = [
14
14
  type: 'insert.block',
15
15
  block,
16
16
  placement: index === 0 ? 'before' : 'after',
17
- select: 'end',
17
+ select: event.select ?? 'end',
18
18
  }),
19
19
  ),
20
20
  ],
@@ -29,7 +29,7 @@ export const abstractInsertBehaviors = [
29
29
  type: 'insert.block',
30
30
  block,
31
31
  placement: 'after',
32
- select: 'end',
32
+ select: event.select ?? 'end',
33
33
  }),
34
34
  ),
35
35
  ],
@@ -57,7 +57,7 @@ export const abstractInsertBehaviors = [
57
57
  type: 'insert.block',
58
58
  block: event.blocks[0],
59
59
  placement: 'auto',
60
- select: 'end',
60
+ select: event.select ?? 'end',
61
61
  }),
62
62
  ]
63
63
  : isEmptyTextBlock(snapshot.context, focusTextBlock.node)
@@ -66,7 +66,7 @@ export const abstractInsertBehaviors = [
66
66
  type: 'insert.block',
67
67
  block,
68
68
  placement: index === 0 ? 'auto' : 'after',
69
- select: 'end',
69
+ select: event.select ?? 'end',
70
70
  }),
71
71
  )
72
72
  : event.blocks.flatMap((block, index) =>
@@ -83,7 +83,7 @@ export const abstractInsertBehaviors = [
83
83
  type: 'insert.block',
84
84
  block,
85
85
  placement: 'auto',
86
- select: 'end',
86
+ select: event.select ?? 'end',
87
87
  }),
88
88
  ]
89
89
  : index === event.blocks.length - 1
@@ -96,7 +96,7 @@ export const abstractInsertBehaviors = [
96
96
  type: 'insert.block',
97
97
  block,
98
98
  placement: 'auto',
99
- select: 'end',
99
+ select: event.select ?? 'end',
100
100
  }),
101
101
  ]
102
102
  : [
@@ -104,7 +104,7 @@ export const abstractInsertBehaviors = [
104
104
  type: 'insert.block',
105
105
  block,
106
106
  placement: 'after',
107
- select: 'end',
107
+ select: event.select ?? 'end',
108
108
  }),
109
109
  ],
110
110
  ),
@@ -120,7 +120,7 @@ export const abstractInsertBehaviors = [
120
120
  type: 'insert.block',
121
121
  block,
122
122
  placement: index === 0 ? 'auto' : 'after',
123
- select: 'end',
123
+ select: event.select ?? 'end',
124
124
  }),
125
125
  ),
126
126
  ],
@@ -198,120 +198,7 @@ export const abstractBehaviors = [
198
198
  ],
199
199
  ],
200
200
  }),
201
- defineBehavior({
202
- on: 'drag.drop',
203
- guard: ({snapshot, event}) => {
204
- const dragOrigin = snapshot.beta.internalDrag?.origin
205
- const dropPosition = event.position.selection
206
- const droppingOnDragOrigin = dragOrigin
207
- ? selectors.isOverlappingSelection(dropPosition)({
208
- ...snapshot,
209
- context: {
210
- ...snapshot.context,
211
- selection: dragOrigin.selection,
212
- },
213
- })
214
- : false
215
- return droppingOnDragOrigin
216
- },
217
- actions: [],
218
- }),
219
- defineBehavior({
220
- on: 'drag.drop',
221
- actions: [
222
- ({event}) => [
223
- raise({
224
- type: 'select',
225
- at: event.position.selection,
226
- }),
227
- raise({
228
- type: 'deserialize',
229
- originEvent: event,
230
- }),
231
- ],
232
- ],
233
- }),
234
- defineBehavior({
235
- on: 'deserialization.success',
236
- guard: ({snapshot, event}) => {
237
- if (
238
- event.originEvent.type !== 'drag.drop' ||
239
- snapshot.beta.internalDrag === undefined
240
- ) {
241
- return false
242
- }
243
201
 
244
- const dragOrigin = snapshot.beta.internalDrag.origin
245
- const dropPosition = event.originEvent.position.selection
246
- const droppingOnDragOrigin = dragOrigin
247
- ? selectors.isOverlappingSelection(dropPosition)({
248
- ...snapshot,
249
- context: {
250
- ...snapshot.context,
251
- selection: dragOrigin.selection,
252
- },
253
- })
254
- : false
255
-
256
- const draggingEntireBlocks = selectors.isSelectingEntireBlocks({
257
- ...snapshot,
258
- context: {
259
- ...snapshot.context,
260
- selection: dragOrigin.selection,
261
- },
262
- })
263
-
264
- const draggedBlocks = selectors.getSelectedBlocks({
265
- ...snapshot,
266
- context: {
267
- ...snapshot.context,
268
- selection: dragOrigin.selection,
269
- },
270
- })
271
-
272
- if (!droppingOnDragOrigin) {
273
- return {
274
- draggingEntireBlocks,
275
- draggedBlocks,
276
- dragOrigin,
277
- originEvent: event.originEvent,
278
- }
279
- }
280
-
281
- return false
282
- },
283
- actions: [
284
- (
285
- {event},
286
- {draggingEntireBlocks, draggedBlocks, dragOrigin, originEvent},
287
- ) => [
288
- ...(draggingEntireBlocks
289
- ? draggedBlocks.map((block) =>
290
- raise({
291
- type: 'delete.block',
292
- at: block.path,
293
- }),
294
- )
295
- : [
296
- raise({
297
- type: 'delete',
298
- at: dragOrigin.selection,
299
- }),
300
- ]),
301
- raise({
302
- type: 'insert.blocks',
303
- blocks: event.data,
304
- placement: draggingEntireBlocks
305
- ? originEvent.position.block === 'start'
306
- ? 'before'
307
- : originEvent.position.block === 'end'
308
- ? 'after'
309
- : 'auto'
310
- : 'auto',
311
- }),
312
- ],
313
- ],
314
- }),
315
202
  /**
316
203
  * If we are pasting text/plain into a text block then we can probably
317
204
  * assume that the intended behavior is that the pasted text inherits
@@ -1,3 +1,4 @@
1
+ import {getDragSelection} from '../internal-utils/drag-selection'
1
2
  import type {EventPositionBlock} from '../internal-utils/event-position'
2
3
  import {corePriority} from '../priority/priority.core'
3
4
  import {createEditorPriority} from '../priority/priority.types'
@@ -31,17 +32,22 @@ export function createCoreBlockElementBehaviorsConfig({
31
32
  return false
32
33
  }
33
34
 
34
- const dragOrigin = snapshot.beta.internalDrag?.origin
35
+ const dragOrigin = event.dragOrigin
35
36
 
36
37
  if (!dragOrigin) {
37
38
  return false
38
39
  }
39
40
 
41
+ const dragSelection = getDragSelection({
42
+ eventSelection: dragOrigin.selection,
43
+ snapshot,
44
+ })
45
+
40
46
  const draggedBlocks = selectors.getSelectedBlocks({
41
47
  ...snapshot,
42
48
  context: {
43
49
  ...snapshot.context,
44
- selection: dragOrigin.selection,
50
+ selection: dragSelection,
45
51
  },
46
52
  })
47
53
 
@@ -55,7 +61,7 @@ export function createCoreBlockElementBehaviorsConfig({
55
61
  ...snapshot,
56
62
  context: {
57
63
  ...snapshot.context,
58
- selection: dragOrigin.selection,
64
+ selection: dragSelection,
59
65
  },
60
66
  })
61
67