@portabletext/editor 1.25.0 → 1.26.1

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 (87) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +131 -36
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +8 -8
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/{selector.is-active-style.cjs → selector.is-at-the-start-of-block.cjs} +29 -3
  6. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -0
  7. package/lib/_chunks-cjs/util.is-empty-text-block.cjs +2 -2
  8. package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -1
  9. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +46 -0
  10. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -0
  11. package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -16
  12. package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
  13. package/lib/_chunks-es/behavior.core.js +99 -4
  14. package/lib/_chunks-es/behavior.core.js.map +1 -1
  15. package/lib/_chunks-es/selector.get-text-before.js +2 -2
  16. package/lib/_chunks-es/{selector.is-active-style.js → selector.is-at-the-start-of-block.js} +29 -2
  17. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
  18. package/lib/_chunks-es/util.is-empty-text-block.js +1 -1
  19. package/lib/_chunks-es/util.is-equal-selection-points.js +47 -0
  20. package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -0
  21. package/lib/_chunks-es/util.reverse-selection.js +0 -16
  22. package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
  23. package/lib/behaviors/index.cjs +27 -27
  24. package/lib/behaviors/index.cjs.map +1 -1
  25. package/lib/behaviors/index.d.cts +413 -0
  26. package/lib/behaviors/index.d.ts +413 -0
  27. package/lib/behaviors/index.js +1 -1
  28. package/lib/index.cjs +184 -116
  29. package/lib/index.cjs.map +1 -1
  30. package/lib/index.d.cts +1653 -222
  31. package/lib/index.d.ts +1653 -222
  32. package/lib/index.js +180 -112
  33. package/lib/index.js.map +1 -1
  34. package/lib/selectors/index.cjs +25 -23
  35. package/lib/selectors/index.cjs.map +1 -1
  36. package/lib/selectors/index.d.cts +16 -0
  37. package/lib/selectors/index.d.ts +16 -0
  38. package/lib/selectors/index.js +3 -1
  39. package/lib/utils/index.cjs +5 -3
  40. package/lib/utils/index.cjs.map +1 -1
  41. package/lib/utils/index.d.cts +19 -0
  42. package/lib/utils/index.d.ts +19 -0
  43. package/lib/utils/index.js +4 -2
  44. package/package.json +6 -6
  45. package/src/behavior-actions/behavior.action-utils.insert-block.ts +3 -3
  46. package/src/behavior-actions/behavior.action.block.set.ts +23 -0
  47. package/src/behavior-actions/behavior.action.block.unset.ts +21 -0
  48. package/src/behavior-actions/behavior.action.insert-break.ts +2 -69
  49. package/src/behavior-actions/behavior.action.insert.block.ts +33 -0
  50. package/src/behavior-actions/behavior.actions.ts +28 -9
  51. package/src/behaviors/behavior.core.insert-break.ts +122 -0
  52. package/src/behaviors/behavior.core.ts +6 -2
  53. package/src/behaviors/behavior.types.ts +16 -1
  54. package/src/converters/converter.json.ts +4 -4
  55. package/src/converters/converter.portable-text.deserialize.test.ts +1 -1
  56. package/src/converters/converter.portable-text.ts +9 -5
  57. package/src/converters/converter.text-html.deserialize.test.ts +1 -1
  58. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  59. package/src/converters/converter.text-html.ts +4 -4
  60. package/src/converters/converter.text-plain.test.ts +1 -1
  61. package/src/converters/converter.text-plain.ts +3 -3
  62. package/src/converters/{converter.ts → converter.types.ts} +6 -0
  63. package/src/editor/__tests__/handleClick.test.tsx +2 -2
  64. package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +1 -1
  65. package/src/editor/create-editor.ts +4 -1
  66. package/src/editor/editor-machine.ts +8 -2
  67. package/src/editor/editor-snapshot.ts +1 -1
  68. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +12 -12
  69. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +29 -36
  70. package/src/editor/plugins/create-with-event-listeners.ts +3 -0
  71. package/src/editor/plugins/createWithObjectKeys.ts +18 -2
  72. package/src/editor/plugins/createWithPortableTextMarkModel.ts +3 -0
  73. package/src/internal-utils/parse-blocks.ts +36 -6
  74. package/src/selectors/index.ts +2 -0
  75. package/src/selectors/selector.is-at-the-end-of-block.ts +22 -0
  76. package/src/selectors/selector.is-at-the-start-of-block.ts +25 -0
  77. package/src/selectors/selector.is-selection-collapsed.ts +6 -2
  78. package/src/utils/index.ts +2 -0
  79. package/src/utils/util.get-block-end-point.ts +34 -0
  80. package/src/utils/util.is-equal-selection-points.ts +13 -0
  81. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
  82. package/lib/_chunks-cjs/util.is-keyed-segment.cjs +0 -6
  83. package/lib/_chunks-cjs/util.is-keyed-segment.cjs.map +0 -1
  84. package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
  85. package/lib/_chunks-es/util.is-keyed-segment.js +0 -7
  86. package/lib/_chunks-es/util.is-keyed-segment.js.map +0 -1
  87. /package/src/converters/{converters.ts → converters.core.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var util_reverseSelection = require("./util.reverse-selection.cjs"), util_isKeyedSegment = require("./util.is-keyed-segment.cjs"), types = require("@sanity/types");
2
+ var util_isEqualSelectionPoints = require("./util.is-equal-selection-points.cjs"), util_reverseSelection = require("./util.reverse-selection.cjs"), types = require("@sanity/types");
3
3
  const getSelectionText = ({
4
4
  context
5
5
  }) => {
@@ -14,24 +14,24 @@ const getSelectionText = ({
14
14
  if (!forwardSelection)
15
15
  return text;
16
16
  for (const block of value)
17
- if (!(util_isKeyedSegment.isKeyedSegment(forwardSelection.anchor.path[0]) && block._key !== forwardSelection.anchor.path[0]._key) && types.isPortableTextTextBlock(block)) {
17
+ if (!(util_isEqualSelectionPoints.isKeyedSegment(forwardSelection.anchor.path[0]) && block._key !== forwardSelection.anchor.path[0]._key) && types.isPortableTextTextBlock(block)) {
18
18
  for (const child of block.children)
19
19
  if (types.isPortableTextSpan(child)) {
20
- if (util_isKeyedSegment.isKeyedSegment(forwardSelection.anchor.path[2]) && child._key === forwardSelection.anchor.path[2]._key && util_isKeyedSegment.isKeyedSegment(forwardSelection.focus.path[2]) && child._key === forwardSelection.focus.path[2]._key) {
20
+ if (util_isEqualSelectionPoints.isKeyedSegment(forwardSelection.anchor.path[2]) && child._key === forwardSelection.anchor.path[2]._key && util_isEqualSelectionPoints.isKeyedSegment(forwardSelection.focus.path[2]) && child._key === forwardSelection.focus.path[2]._key) {
21
21
  text = text + child.text.slice(forwardSelection.anchor.offset, forwardSelection.focus.offset);
22
22
  break;
23
23
  }
24
- if (util_isKeyedSegment.isKeyedSegment(forwardSelection.anchor.path[2]) && child._key === forwardSelection.anchor.path[2]._key) {
24
+ if (util_isEqualSelectionPoints.isKeyedSegment(forwardSelection.anchor.path[2]) && child._key === forwardSelection.anchor.path[2]._key) {
25
25
  text = text + child.text.slice(forwardSelection.anchor.offset);
26
26
  continue;
27
27
  }
28
- if (util_isKeyedSegment.isKeyedSegment(forwardSelection.focus.path[2]) && child._key === forwardSelection.focus.path[2]._key) {
28
+ if (util_isEqualSelectionPoints.isKeyedSegment(forwardSelection.focus.path[2]) && child._key === forwardSelection.focus.path[2]._key) {
29
29
  text = text + child.text.slice(0, forwardSelection.focus.offset);
30
30
  break;
31
31
  }
32
32
  text.length > 0 && (text = text + child.text);
33
33
  }
34
- if (util_isKeyedSegment.isKeyedSegment(forwardSelection.focus.path[0]) && block._key === forwardSelection.focus.path[0]._key)
34
+ if (util_isEqualSelectionPoints.isKeyedSegment(forwardSelection.focus.path[0]) && block._key === forwardSelection.focus.path[0]._key)
35
35
  break;
36
36
  }
37
37
  return text;
@@ -40,10 +40,10 @@ const getSelectionText = ({
40
40
  }) => {
41
41
  if (!context.selection)
42
42
  return "";
43
- const point = (context.selection.backward ? util_reverseSelection.reverseSelection(context.selection) : context.selection).anchor, key = util_isKeyedSegment.isKeyedSegment(point.path[0]) ? point.path[0]._key : void 0, block = key ? context.value.find((block2) => block2._key === key) : void 0;
43
+ const point = (context.selection.backward ? util_reverseSelection.reverseSelection(context.selection) : context.selection).anchor, key = util_isEqualSelectionPoints.isKeyedSegment(point.path[0]) ? point.path[0]._key : void 0, block = key ? context.value.find((block2) => block2._key === key) : void 0;
44
44
  if (!block)
45
45
  return "";
46
- const startOfBlock = util_reverseSelection.getBlockStartPoint({
46
+ const startOfBlock = util_isEqualSelectionPoints.getBlockStartPoint({
47
47
  node: block,
48
48
  path: [{
49
49
  _key: block._key
@@ -1 +1 @@
1
- {"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = ({context}) => {\n let text = ''\n\n const {value, selection} = context\n\n if (!value || !selection) {\n return text\n }\n\n const forwardSelection = selection.backward\n ? reverseSelection(selection)\n : selection\n\n if (!forwardSelection) {\n return text\n }\n\n for (const block of value) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[0]) &&\n block._key !== forwardSelection.anchor.path[0]._key\n ) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (isPortableTextSpan(child)) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key &&\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text =\n text +\n child.text.slice(\n forwardSelection.anchor.offset,\n forwardSelection.focus.offset,\n )\n\n break\n }\n\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key\n ) {\n text = text + child.text.slice(forwardSelection.anchor.offset)\n continue\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text = text + child.text.slice(0, forwardSelection.focus.offset)\n break\n }\n\n if (text.length > 0) {\n text = text + child.text\n }\n }\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[0]) &&\n block._key === forwardSelection.focus.path[0]._key\n ) {\n break\n }\n }\n\n return text\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {reverseSelection} from '../utils/util.reverse-selection'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = ({context}) => {\n if (!context.selection) {\n return ''\n }\n\n const selection = context.selection.backward\n ? reverseSelection(context.selection)\n : context.selection\n const point = selection.anchor\n const key = isKeyedSegment(point.path[0]) ? point.path[0]._key : undefined\n\n const block = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n node: block,\n path: [{_key: block._key}],\n })\n\n return getSelectionText({\n context: {\n ...context,\n value: context.value,\n selection: {\n anchor: startOfBlock,\n focus: point,\n },\n },\n })\n}\n"],"names":["getSelectionText","context","text","value","selection","forwardSelection","backward","reverseSelection","block","isKeyedSegment","anchor","path","_key","isPortableTextTextBlock","child","children","isPortableTextSpan","focus","slice","offset","length","getBlockTextBefore","point","key","undefined","find","startOfBlock","getBlockStartPoint","node"],"mappings":";;AAQO,MAAMA,mBAA2CA,CAAC;AAAA,EAACC;AAAO,MAAM;AACrE,MAAIC,OAAO;AAEL,QAAA;AAAA,IAACC;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AKkB,SAAS,MAChBlB,OAAOA,OAAOY,MAAMZ;AAAAA,QAAAA;AAK1B,UACEO,oBAAeJ,eAAAA,iBAAiBY,MAAMN,KAAK,CAAC,CAAC,KAC7CH,MAAMI,SAASP,iBAAiBY,MAAMN,KAAK,CAAC,EAAEC;AAE9C;AAAA,IAAA;AAIGV,SAAAA;AACT,GC7EamB,qBAA6CA,CAAC;AAAA,EAACpB;AAAO,MAAM;AACvE,MAAI,CAACA,QAAQG;AACJ,WAAA;AAMT,QAAMkB,SAHYrB,QAAQG,UAAUE,WAChCC,uCAAiBN,QAAQG,SAAS,IAClCH,QAAQG,WACYM,QAClBa,MAAMd,oBAAAA,eAAea,MAAMX,KAAK,CAAC,CAAC,IAAIW,MAAMX,KAAK,CAAC,EAAEC,OAAOY,QAE3DhB,QAAQe,MACVtB,QAAQE,MAAMsB,KAAMjB,CAAAA,WAAUA,OAAMI,SAASW,GAAG,IAChDC;AAEJ,MAAI,CAAChB;AACI,WAAA;AAGT,QAAMkB,eAAeC,sBAAAA,mBAAmB;AAAA,IACtCC,MAAMpB;AAAAA,IACNG,MAAM,CAAC;AAAA,MAACC,MAAMJ,MAAMI;AAAAA,IAAK,CAAA;AAAA,EAAA,CAC1B;AAED,SAAOZ,iBAAiB;AAAA,IACtBC,SAAS;AAAA,MACP,GAAGA;AAAAA,MACHE,OAAOF,QAAQE;AAAAA,MACfC,WAAW;AAAA,QACTM,QAAQgB;AAAAA,QACRT,OAAOK;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;;;"}
1
+ {"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = ({context}) => {\n let text = ''\n\n const {value, selection} = context\n\n if (!value || !selection) {\n return text\n }\n\n const forwardSelection = selection.backward\n ? reverseSelection(selection)\n : selection\n\n if (!forwardSelection) {\n return text\n }\n\n for (const block of value) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[0]) &&\n block._key !== forwardSelection.anchor.path[0]._key\n ) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (isPortableTextSpan(child)) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key &&\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text =\n text +\n child.text.slice(\n forwardSelection.anchor.offset,\n forwardSelection.focus.offset,\n )\n\n break\n }\n\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key\n ) {\n text = text + child.text.slice(forwardSelection.anchor.offset)\n continue\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text = text + child.text.slice(0, forwardSelection.focus.offset)\n break\n }\n\n if (text.length > 0) {\n text = text + child.text\n }\n }\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[0]) &&\n block._key === forwardSelection.focus.path[0]._key\n ) {\n break\n }\n }\n\n return text\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {reverseSelection} from '../utils/util.reverse-selection'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = ({context}) => {\n if (!context.selection) {\n return ''\n }\n\n const selection = context.selection.backward\n ? reverseSelection(context.selection)\n : context.selection\n const point = selection.anchor\n const key = isKeyedSegment(point.path[0]) ? point.path[0]._key : undefined\n\n const block = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n node: block,\n path: [{_key: block._key}],\n })\n\n return getSelectionText({\n context: {\n ...context,\n value: context.value,\n selection: {\n anchor: startOfBlock,\n focus: point,\n },\n },\n })\n}\n"],"names":["getSelectionText","context","text","value","selection","forwardSelection","backward","reverseSelection","block","isKeyedSegment","anchor","path","_key","isPortableTextTextBlock","child","children","isPortableTextSpan","focus","slice","offset","length","getBlockTextBefore","point","key","undefined","find","startOfBlock","getBlockStartPoint","node"],"mappings":";;AAQO,MAAMA,mBAA2CA,CAAC;AAAA,EAACC;AAAO,MAAM;AACrE,MAAIC,OAAO;AAEL,QAAA;AAAA,IAACC;AAAAA,IAAOC;AAAAA,EAAAA,IAAaH;AAEvB,MAAA,CAACE,SAAS,CAACC;AACNF,WAAAA;AAGT,QAAMG,mBAAmBD,UAAUE,WAC/BC,sBAAAA,iBAAiBH,SAAS,IAC1BA;AAEJ,MAAI,CAACC;AACIH,WAAAA;AAGT,aAAWM,SAASL;AAClB,QACEM,6CAAeJ,iBAAiBK,OAAOC,KAAK,CAAC,CAAC,KAC9CH,MAAMI,SAASP,iBAAiBK,OAAOC,KAAK,CAAC,EAAEC,SAK5CC,MAAAA,wBAAwBL,KAAK,GAIlC;AAAA,iBAAWM,SAASN,MAAMO;AACpBC,YAAAA,MAAAA,mBAAmBF,KAAK,GAAG;AAC7B,cACEL,4BAAeJ,eAAAA,iBAAiBK,OAAOC,KAAK,CAAC,CAAC,KAC9CG,MAAMF,SAASP,iBAAiBK,OAAOC,KAAK,CAAC,EAAEC,QAC/CH,4BAAAA,eAAeJ,iBAAiBY,MAAMN,KAAK,CAAC,CAAC,KAC7CG,MAAMF,SAASP,iBAAiBY,MAAMN,KAAK,CAAC,EAAEC,MAC9C;AAEEV,mBAAAA,OACAY,MAAMZ,KAAKgB,MACTb,iBAAiBK,OAAOS,QACxBd,iBAAiBY,MAAME,MACzB;AAE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OZ,iBAAiB;AAAA,IACtBC,SAAS;AAAA,MACP,GAAGA;AAAAA,MACHE,OAAOF,QAAQE;AAAAA,MACfC,WAAW;AAAA,QACTM,QAAQgB;AAAAA,QACRT,OAAOK;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;;;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var types = require("@sanity/types");
2
+ var types = require("@sanity/types"), util_isEqualSelectionPoints = require("./util.is-equal-selection-points.cjs");
3
3
  function createGuards({
4
4
  schema
5
5
  }) {
@@ -340,7 +340,7 @@ function isActiveAnnotation(annotation) {
340
340
  }
341
341
  const isSelectionCollapsed = ({
342
342
  context
343
- }) => JSON.stringify(context.selection?.anchor.path) === JSON.stringify(context.selection?.focus.path) && context.selection?.anchor.offset === context.selection?.focus.offset, isSelectionExpanded = ({
343
+ }) => context.selection ? JSON.stringify(context.selection.anchor.path) === JSON.stringify(context.selection.focus.path) && context.selection?.anchor.offset === context.selection?.focus.offset : !1, isSelectionExpanded = ({
344
344
  context
345
345
  }) => !isSelectionCollapsed({
346
346
  context
@@ -360,6 +360,30 @@ function isActiveListItem(listItem) {
360
360
  function isActiveStyle(style) {
361
361
  return (snapshot) => getActiveStyle(snapshot) === style;
362
362
  }
363
+ function isAtTheEndOfBlock(block) {
364
+ return ({
365
+ context
366
+ }) => {
367
+ if (!context.selection || !isSelectionCollapsed({
368
+ context
369
+ }))
370
+ return !1;
371
+ const blockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint(block);
372
+ return util_isEqualSelectionPoints.isEqualSelectionPoints(context.selection.focus, blockEndPoint);
373
+ };
374
+ }
375
+ function isAtTheStartOfBlock(block) {
376
+ return ({
377
+ context
378
+ }) => {
379
+ if (!context.selection || !isSelectionCollapsed({
380
+ context
381
+ }))
382
+ return !1;
383
+ const blockStartPoint = util_isEqualSelectionPoints.getBlockStartPoint(block);
384
+ return util_isEqualSelectionPoints.isEqualSelectionPoints(context.selection.focus, blockStartPoint);
385
+ };
386
+ }
363
387
  exports.createGuards = createGuards;
364
388
  exports.getActiveListItem = getActiveListItem;
365
389
  exports.getActiveStyle = getActiveStyle;
@@ -381,6 +405,8 @@ exports.isActiveAnnotation = isActiveAnnotation;
381
405
  exports.isActiveDecorator = isActiveDecorator;
382
406
  exports.isActiveListItem = isActiveListItem;
383
407
  exports.isActiveStyle = isActiveStyle;
408
+ exports.isAtTheEndOfBlock = isAtTheEndOfBlock;
409
+ exports.isAtTheStartOfBlock = isAtTheStartOfBlock;
384
410
  exports.isSelectionCollapsed = isSelectionCollapsed;
385
411
  exports.isSelectionExpanded = isSelectionExpanded;
386
- //# sourceMappingURL=selector.is-active-style.cjs.map
412
+ //# sourceMappingURL=selector.is-at-the-start-of-block.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selector.is-at-the-start-of-block.cjs","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({schema}: {schema: EditorSchema}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = ({\n context,\n}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }> = []\n\n const startPoint = context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n const endPoint = context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n\n const startBlockKey = isKeySegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeySegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startSpanKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endSpanKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n for (const block of context.value) {\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (selectedSpans.length > 0) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import {isPortableTextTextBlock} 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 function isActiveAnnotation(\n annotation: string,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return false\n }\n\n if (\n selectedSpans.some(\n (span) => !span.node.marks || span.node.marks?.length === 0,\n )\n ) {\n return false\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectedSpans.every((span) => {\n const spanMarkDefs =\n span.node.marks?.flatMap((mark) => {\n const markDef = selectionMarkDefs.find(\n (markDef) => markDef._key === mark,\n )\n\n return markDef ? [markDef._type] : []\n }) ?? []\n\n return spanMarkDefs.includes(annotation)\n })\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = ({context}) => {\n if (!context.selection) {\n return false\n }\n\n return (\n JSON.stringify(context.selection.anchor.path) ===\n JSON.stringify(context.selection.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = ({context}) => {\n return !isSelectionCollapsed({context})\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n return snapshot.context.activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheEndOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockEndPoint = utils.getBlockEndPoint(block)\n\n return utils.isEqualSelectionPoints(context.selection.focus, blockEndPoint)\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheStartOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockStartPoint = utils.getBlockStartPoint(block)\n\n return utils.isEqualSelectionPoints(\n context.selection.focus,\n blockStartPoint,\n )\n }\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","getFocusBlock","context","key","selection","isKeySegment","focus","path","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","anchor","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getActiveListItem","selectedTextBlocks","map","filter","firstTextBlock","at","firstListItem","listItem","every","getActiveStyle","firstStyle","style","getSelectedSpans","selectedSpans","startPoint","endPoint","startBlockKey","endBlockKey","startSpanKey","endSpanKey","child","isActiveAnnotation","annotation","snapshot","some","marks","selectionMarkDefs","flatMap","markDefs","mark","markDef","includes","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","isActiveDecorator","decorator","activeDecorators","isActiveListItem","isActiveStyle","isAtTheEndOfBlock","blockEndPoint","utils","getBlockEndPoint","isEqualSelectionPoints","isAtTheStartOfBlock","blockStartPoint","getBlockStartPoint"],"mappings":";;AAaO,SAASA,aAAa;AAAA,E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EAC7D;AACF;ACdO,SAASE,iBAAiBjC,UAA2C;AAClEgB,SAAAA,CAAAA,aACiBvB,kBAAkBuB,QAAQ,MAEvBhB;AAE9B;ACNO,SAASkC,cAAc9B,OAAwC;AAC5DY,SAAAA,CAAAA,aACcd,eAAec,QAAQ,MAEpBZ;AAE3B;ACJO,SAAS+B,kBAAkB3F,OAGN;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQE,aAAa,CAACwE,qBAAqB;AAAA,MAAC1E;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGHqF,UAAAA,gBAAgBC,4BAAMC,iBAAiB9F,KAAK;AAElD,WAAO6F,4BAAME,uBAAuBxF,QAAQE,UAAUE,OAAOiF,aAAa;AAAA,EAC5E;AACF;ACbO,SAASI,oBAAoBhG,OAGR;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQE,aAAa,CAACwE,qBAAqB;AAAA,MAAC1E;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGH0F,UAAAA,kBAAkBJ,4BAAMK,mBAAmBlG,KAAK;AAEtD,WAAO6F,4BAAME,uBACXxF,QAAQE,UAAUE,OAClBsF,eACF;AAAA,EACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var types = require("@sanity/types"), util_isKeyedSegment = require("./util.is-keyed-segment.cjs");
2
+ var types = require("@sanity/types"), util_isEqualSelectionPoints = require("./util.is-equal-selection-points.cjs");
3
3
  function blockOffsetToSpanSelectionPoint({
4
4
  value,
5
5
  blockOffset
@@ -37,7 +37,7 @@ function spanSelectionPointToBlockOffset({
37
37
  selectionPoint
38
38
  }) {
39
39
  let offset = 0;
40
- const blockKey = util_isKeyedSegment.isKeyedSegment(selectionPoint.path[0]) ? selectionPoint.path[0]._key : void 0, spanKey = util_isKeyedSegment.isKeyedSegment(selectionPoint.path[2]) ? selectionPoint.path[2]._key : void 0;
40
+ const blockKey = util_isEqualSelectionPoints.isKeyedSegment(selectionPoint.path[0]) ? selectionPoint.path[0]._key : void 0, spanKey = util_isEqualSelectionPoints.isKeyedSegment(selectionPoint.path[2]) ? selectionPoint.path[2]._key : void 0;
41
41
  if (!(!blockKey || !spanKey)) {
42
42
  for (const block of value)
43
43
  if (block._key === blockKey && types.isPortableTextTextBlock(block)) {
@@ -1 +1 @@
1
- {"version":3,"file":"util.is-empty-text-block.cjs","sources":["../../src/utils/util.block-offset.ts","../../src/utils/util.get-text-block-text.ts","../../src/utils/util.is-empty-text-block.ts"],"sourcesContent":["import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {BlockOffset} from '../behaviors/behavior.types'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n value,\n blockOffset,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint:\n | {path: [KeyedSegment, 'children', KeyedSegment]; offset: number}\n | undefined\n\n for (const block of value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (offsetLeft === 0) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n break\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = isKeyedSegment(selectionPoint.path[0])\n ? selectionPoint.path[0]._key\n : undefined\n const spanKey = isKeyedSegment(selectionPoint.path[2])\n ? selectionPoint.path[2]._key\n : undefined\n\n if (!blockKey || !spanKey) {\n return undefined\n }\n\n for (const block of value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (child._key === spanKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(block: PortableTextBlock) {\n if (!isPortableTextTextBlock(block)) {\n return false\n }\n\n const onlyText = block.children.every(isPortableTextSpan)\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n"],"names":["blockOffsetToSpanSelectionPoint","value","blockOffset","offsetLeft","offset","selectionPoint","block","_key","path","isPortableTextTextBlock","child","children","isPortableTextSpan","text","length","spanSelectionPointToBlockOffset","blockKey","isKeyedSegment","undefined","spanKey","getTextBlockText","map","join","isEmptyTextBlock","onlyText","every","blockText"],"mappings":";;AAaO,SAASA,gCAAgC;AAAA,EAC9CC;AAAAA,EACAC;AAIF,GAAG;AACGC,MAAAA,aAAaD,YAAYE,QACzBC;AAIJ,aAAWC,SAASL;AACdK,QAAAA,MAAMC,SAASL,YAAYM,KAAK,CAAC,EAAED,QAIlCE,8BAAwBH,KAAK;AAIlC,iBAAWI,SAASJ,MAAMK;AACnBC,YAAAA,MAAAA,mBAAmBF,KA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,CAAAA,UAAUA,MAAMG,QAAQ,EAAE,EAAES,KAAK,EAAE;AAChE;ACGO,SAASC,iBAAiBjB,OAA0B;AACrD,MAAA,CAACG,8BAAwBH,KAAK;AACzB,WAAA;AAGHkB,QAAAA,WAAWlB,MAAMK,SAASc,MAAMb,MAAAA,kBAAkB,GAClDc,YAAYN,iBAAiBd,KAAK;AAExC,SAAOkB,YAAYE,cAAc;AACnC;;;;;"}
1
+ {"version":3,"file":"util.is-empty-text-block.cjs","sources":["../../src/utils/util.block-offset.ts","../../src/utils/util.get-text-block-text.ts","../../src/utils/util.is-empty-text-block.ts"],"sourcesContent":["import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {BlockOffset} from '../behaviors/behavior.types'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n value,\n blockOffset,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint:\n | {path: [KeyedSegment, 'children', KeyedSegment]; offset: number}\n | undefined\n\n for (const block of value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (offsetLeft === 0) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n break\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = isKeyedSegment(selectionPoint.path[0])\n ? selectionPoint.path[0]._key\n : undefined\n const spanKey = isKeyedSegment(selectionPoint.path[2])\n ? selectionPoint.path[2]._key\n : undefined\n\n if (!blockKey || !spanKey) {\n return undefined\n }\n\n for (const block of value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (child._key === spanKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(block: PortableTextBlock) {\n if (!isPortableTextTextBlock(block)) {\n return false\n }\n\n const onlyText = block.children.every(isPortableTextSpan)\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n"],"names":["blockOffsetToSpanSelectionPoint","value","blockOffset","offsetLeft","offset","selectionPoint","block","_key","path","isPortableTextTextBlock","child","children","isPortableTextSpan","text","length","spanSelectionPointToBlockOffset","blockKey","isKeyedSegment","undefined","spanKey","getTextBlockText","map","join","isEmptyTextBlock","onlyText","every","blockText"],"mappings":";;AAaO,SAASA,gCAAgC;AAAA,EAC9CC;AAAAA,EACAC;AAIF,GAAG;AACGC,MAAAA,aAAaD,YAAYE,QACzBC;AAIJ,aAAWC,SAASL;AACdK,QAAAA,MAAMC,SAASL,YAAYM,KAAK,CAAC,EAAED,QAIlCE,8BAAwBH,KAAK;AAIlC,iBAAWI,SAASJ,MAAMK;AACnBC,YAAAA,MAAAA,mBAAmBF,KAAK,GAI7B;AAAA,c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AMG,QAAQ,EAAE,EAAES,KAAK,EAAE;AAChE;ACGO,SAASC,iBAAiBjB,OAA0B;AACrD,MAAA,CAACG,8BAAwBH,KAAK;AACzB,WAAA;AAGHkB,QAAAA,WAAWlB,MAAMK,SAASc,MAAMb,MAAAA,kBAAkB,GAClDc,YAAYN,iBAAiBd,KAAK;AAExC,SAAOkB,YAAYE,cAAc;AACnC;;;;;"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var types = require("@sanity/types");
3
+ function isKeyedSegment(segment) {
4
+ return typeof segment == "object" && segment !== null && "_key" in segment;
5
+ }
6
+ function getBlockEndPoint({
7
+ node,
8
+ path
9
+ }) {
10
+ if (types.isPortableTextTextBlock(node)) {
11
+ const lastChild = node.children[node.children.length - 1];
12
+ if (lastChild)
13
+ return {
14
+ path: [...path, "children", {
15
+ _key: lastChild._key
16
+ }],
17
+ offset: types.isPortableTextSpan(lastChild) ? lastChild.text.length : 0
18
+ };
19
+ }
20
+ return {
21
+ path,
22
+ offset: 0
23
+ };
24
+ }
25
+ function getBlockStartPoint({
26
+ node,
27
+ path
28
+ }) {
29
+ return types.isPortableTextTextBlock(node) ? {
30
+ path: [...path, "children", {
31
+ _key: node.children[0]._key
32
+ }],
33
+ offset: 0
34
+ } : {
35
+ path,
36
+ offset: 0
37
+ };
38
+ }
39
+ function isEqualSelectionPoints(a, b) {
40
+ return a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path);
41
+ }
42
+ exports.getBlockEndPoint = getBlockEndPoint;
43
+ exports.getBlockStartPoint = getBlockStartPoint;
44
+ exports.isEqualSelectionPoints = isEqualSelectionPoints;
45
+ exports.isKeyedSegment = isKeyedSegment;
46
+ //# sourceMappingURL=util.is-equal-selection-points.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.is-equal-selection-points.cjs","sources":["../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.get-block-end-point.ts","../../src/utils/util.get-block-start-point.ts","../../src/utils/util.is-equal-selection-points.ts"],"sourcesContent":["import type {KeyedSegment, PathSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n const lastChild = node.children[node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...path, 'children', {_key: lastChild._key}],\n offset: isPortableTextSpan(lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n return {\n path: [...path, 'children', {_key: node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n"],"names":["isKeyedSegment","segment","getBlockEndPoint","node","path","isPortableTextTextBlock","lastChild","children","length","_key","offset","isPortableTextSpan","text","getBlockStartPoint","isEqualSelectionPoints","a","b","JSON","stringify"],"mappings":";;AAKO,SAASA,eAAeC,SAA+C;AAC5E,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;ACIO,SAASC,iBAAiB;AAAA,EAC/BC;AAAAA,EACAC;AAIF,GAAyB;AACnBC,MAAAA,MAAAA,wBAAwBF,IAAI,GAAG;AACjC,UAAMG,YAAYH,KAAKI,SAASJ,KAAKI,SAASC,SAAS,CAAC;AAEpDF,QAAAA;AACK,aAAA;AAAA,QACLF,MAAM,CAAC,GAAGA,MAAM,YAAY;AAAA,UAACK,MAAMH,UAAUG;AAAAA,QAAAA,CAAK;AAAA,QAClDC,QAAQC,MAAmBL,mBAAAA,SAAS,IAAIA,UAAUM,KAAKJ,SAAS;AAAA,MAClE;AAAA,EAAA;AAIG,SAAA;AAAA,IACLJ;AAAAA,IACAM,QAAQ;AAAA,EACV;AACF;ACvBO,SAASG,mBAAmB;AAAA,EACjCV;AAAAA,EACAC;AAIF,GAAyB;AACnBC,SAAAA,MAAAA,wBAAwBF,IAAI,IACvB;AAAA,IACLC,MAAM,CAAC,GAAGA,MAAM,YAAY;AAAA,MAACK,MAAMN,KAAKI,SAAS,CAAC,EAAEE;AAAAA,IAAAA,CAAK;AAAA,IACzDC,QAAQ;AAAA,EAAA,IAIL;AAAA,IACLN;AAAAA,IACAM,QAAQ;AAAA,EACV;AACF;ACvBgBI,SAAAA,uBACdC,GACAC,GACA;AACA,SACED,EAAEL,WAAWM,EAAEN,UAAUO,KAAKC,UAAUH,EAAEX,IAAI,MAAMa,KAAKC,UAAUF,EAAEZ,IAAI;AAE7E;;;;;"}
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var types = require("@sanity/types");
3
- function getBlockStartPoint({
4
- node,
5
- path
6
- }) {
7
- return types.isPortableTextTextBlock(node) ? {
8
- path: [...path, "children", {
9
- _key: node.children[0]._key
10
- }],
11
- offset: 0
12
- } : {
13
- path,
14
- offset: 0
15
- };
16
- }
17
2
  function reverseSelection(selection) {
18
3
  return selection.backward ? {
19
4
  anchor: selection.focus,
@@ -25,6 +10,5 @@ function reverseSelection(selection) {
25
10
  backward: !0
26
11
  };
27
12
  }
28
- exports.getBlockStartPoint = getBlockStartPoint;
29
13
  exports.reverseSelection = reverseSelection;
30
14
  //# sourceMappingURL=util.reverse-selection.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.reverse-selection.cjs","sources":["../../src/utils/util.get-block-start-point.ts","../../src/utils/util.reverse-selection.ts"],"sourcesContent":["import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n return {\n path: [...path, 'children', {_key: node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection(\n selection: NonNullable<EditorSelection>,\n): NonNullable<EditorSelection> {\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n }\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n }\n}\n"],"names":["getBlockStartPoint","node","path","isPortableTextTextBlock","_key","children","offset","reverseSelection","selection","backward","anchor","focus"],"mappings":";;AAUO,SAASA,mBAAmB;AAAA,EACjCC;AAAAA,EACAC;AAIF,GAAyB;AACnBC,SAAAA,MAAAA,wBAAwBF,IAAI,IACvB;AAAA,IACLC,MAAM,CAAC,GAAGA,MAAM,YAAY;AAAA,MAACE,MAAMH,KAAKI,SAAS,CAAC,EAAED;AAAAA,IAAAA,CAAK;AAAA,IACzDE,QAAQ;AAAA,EAAA,IAIL;AAAA,IACLJ;AAAAA,IACAI,QAAQ;AAAA,EACV;AACF;ACvBO,SAASC,iBACdC,WAC8B;AAC9B,SAAIA,UAAUC,WACL;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EAAA,IAIP;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EACZ;AACF;;;"}
1
+ {"version":3,"file":"util.reverse-selection.cjs","sources":["../../src/utils/util.reverse-selection.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection(\n selection: NonNullable<EditorSelection>,\n): NonNullable<EditorSelection> {\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n }\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n }\n}\n"],"names":["reverseSelection","selection","backward","anchor","focus"],"mappings":";AAKO,SAASA,iBACdC,WAC8B;AAC9B,SAAIA,UAAUC,WACL;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EAAA,IAIP;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EACZ;AACF;;"}
@@ -1,4 +1,4 @@
1
- import { isActiveAnnotation, getFocusBlockObject, getNextBlock, getPreviousBlock, isSelectionCollapsed, getFocusTextBlock, isActiveDecorator, isActiveListItem, getFocusSpan, getFocusListBlock, getSelectedBlocks, createGuards, isActiveStyle } from "./selector.is-active-style.js";
1
+ import { isActiveAnnotation, getFocusBlockObject, getNextBlock, getPreviousBlock, isSelectionCollapsed, getFocusTextBlock, isActiveDecorator, isAtTheEndOfBlock, getFocusSpan, isAtTheStartOfBlock, isActiveListItem, getFocusListBlock, getSelectedBlocks, createGuards, isActiveStyle } from "./selector.is-at-the-start-of-block.js";
2
2
  import { isPortableTextTextBlock } from "@sanity/types";
3
3
  import { isEmptyTextBlock } from "./util.is-empty-text-block.js";
4
4
  function isCustomBehaviorEvent(event) {
@@ -389,6 +389,100 @@ const arrowDownOnLonelyBlockObject = {
389
389
  ...deserializeEvent,
390
390
  dataTransfer: event.dataTransfer
391
391
  })]]
392
+ }, atTheEndOfTextBlock = {
393
+ on: "insert.break",
394
+ guard: ({
395
+ context
396
+ }) => {
397
+ const focusTextBlock = getFocusTextBlock({
398
+ context
399
+ }), selectionCollapsed = isSelectionCollapsed({
400
+ context
401
+ });
402
+ if (!context.selection || !focusTextBlock || !selectionCollapsed)
403
+ return !1;
404
+ const atTheEndOfBlock = isAtTheEndOfBlock(focusTextBlock)({
405
+ context
406
+ }), focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
407
+ return atTheEndOfBlock ? {
408
+ focusListItem,
409
+ focusLevel
410
+ } : !1;
411
+ },
412
+ actions: [({
413
+ context
414
+ }, {
415
+ focusListItem,
416
+ focusLevel
417
+ }) => [raise({
418
+ type: "insert.block",
419
+ block: {
420
+ _type: context.schema.block.name,
421
+ _key: context.keyGenerator(),
422
+ children: [{
423
+ _key: context.keyGenerator(),
424
+ _type: context.schema.span.name,
425
+ text: "",
426
+ marks: []
427
+ }],
428
+ markDefs: [],
429
+ listItem: focusListItem,
430
+ level: focusLevel,
431
+ style: context.schema.styles[0]?.value
432
+ },
433
+ placement: "after"
434
+ })]]
435
+ }, atTheStartOfTextBlock = {
436
+ on: "insert.break",
437
+ guard: ({
438
+ context
439
+ }) => {
440
+ const focusTextBlock = getFocusTextBlock({
441
+ context
442
+ }), selectionCollapsed = isSelectionCollapsed({
443
+ context
444
+ });
445
+ if (!context.selection || !focusTextBlock || !selectionCollapsed)
446
+ return !1;
447
+ const focusSpan = getFocusSpan({
448
+ context
449
+ }), focusDecorators = focusSpan?.node.marks?.filter((mark) => context.schema.decorators.some((decorator) => decorator.value === mark) ?? []), focusAnnotations = focusSpan?.node.marks?.filter((mark) => !context.schema.decorators.some((decorator) => decorator.value === mark)) ?? [], focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
450
+ return isAtTheStartOfBlock(focusTextBlock)({
451
+ context
452
+ }) ? {
453
+ focusAnnotations,
454
+ focusDecorators,
455
+ focusListItem,
456
+ focusLevel
457
+ } : !1;
458
+ },
459
+ actions: [({
460
+ context
461
+ }, {
462
+ focusAnnotations,
463
+ focusDecorators,
464
+ focusListItem,
465
+ focusLevel
466
+ }) => [raise({
467
+ type: "insert.block",
468
+ block: {
469
+ _key: context.keyGenerator(),
470
+ _type: context.schema.block.name,
471
+ children: [{
472
+ _key: context.keyGenerator(),
473
+ _type: context.schema.span.name,
474
+ marks: focusAnnotations.length === 0 ? focusDecorators : [],
475
+ text: ""
476
+ }],
477
+ listItem: focusListItem,
478
+ level: focusLevel,
479
+ style: context.schema.styles[0]?.value
480
+ },
481
+ placement: "before"
482
+ })]]
483
+ }, coreInsertBreakBehaviors = {
484
+ atTheEndOfTextBlock,
485
+ atTheStartOfTextBlock
392
486
  }, MAX_LIST_LEVEL = 10, toggleListItemOff = {
393
487
  on: "list item.toggle",
394
488
  guard: ({
@@ -610,17 +704,18 @@ const arrowDownOnLonelyBlockObject = {
610
704
  toggleStyleOn
611
705
  }, softReturn = {
612
706
  on: "insert.soft break",
613
- actions: [() => [{
707
+ actions: [() => [raise({
614
708
  type: "insert.text",
615
709
  text: `
616
710
  `
617
- }]]
618
- }, coreBehaviors = [softReturn, coreAnnotationBehaviors.toggleAnnotationOff, coreAnnotationBehaviors.toggleAnnotationOn, coreDecoratorBehaviors.toggleDecoratorOff, coreDecoratorBehaviors.toggleDecoratorOn, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, coreDeserializeBehavior, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.toggleListItemOff, coreListBehaviors.toggleListItemOn, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreSerializeBehaviors.serialize, coreSerializeBehaviors["serialization.success"], coreStyleBehaviors.toggleStyleOff, coreStyleBehaviors.toggleStyleOn], coreBehavior = {
711
+ })]]
712
+ }, coreBehaviors = [softReturn, coreAnnotationBehaviors.toggleAnnotationOff, coreAnnotationBehaviors.toggleAnnotationOn, coreDecoratorBehaviors.toggleDecoratorOff, coreDecoratorBehaviors.toggleDecoratorOn, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, coreDeserializeBehavior, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.toggleListItemOff, coreListBehaviors.toggleListItemOn, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreInsertBreakBehaviors.atTheEndOfTextBlock, coreInsertBreakBehaviors.atTheStartOfTextBlock, coreSerializeBehaviors.serialize, coreSerializeBehaviors["serialization.success"], coreStyleBehaviors.toggleStyleOff, coreStyleBehaviors.toggleStyleOn], coreBehavior = {
619
713
  softReturn,
620
714
  annotation: coreAnnotationBehaviors,
621
715
  decorators: coreDecoratorBehaviors,
622
716
  deserialize: coreDeserializeBehavior,
623
717
  blockObjects: coreBlockObjectBehaviors,
718
+ insertBreak: coreInsertBreakBehaviors,
624
719
  lists: coreListBehaviors,
625
720
  ...coreSerializeBehaviors,
626
721
  style: coreSerializeBehaviors