@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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var selector_isActiveStyle = require("../_chunks-cjs/selector.is-active-style.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), types = require("@sanity/types"), util_reverseSelection = require("../_chunks-cjs/util.reverse-selection.cjs");
3
+ var selector_isAtTheStartOfBlock = require("../_chunks-cjs/selector.is-at-the-start-of-block.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), types = require("@sanity/types"), util_reverseSelection = require("../_chunks-cjs/util.reverse-selection.cjs");
4
4
  const getSelectedSlice = ({
5
5
  context
6
6
  }) => util_sliceBlocks.sliceBlocks({
@@ -77,28 +77,30 @@ function isPointBeforeSelection(point) {
77
77
  return before;
78
78
  };
79
79
  }
80
- exports.getActiveListItem = selector_isActiveStyle.getActiveListItem;
81
- exports.getActiveStyle = selector_isActiveStyle.getActiveStyle;
82
- exports.getFirstBlock = selector_isActiveStyle.getFirstBlock;
83
- exports.getFocusBlock = selector_isActiveStyle.getFocusBlock;
84
- exports.getFocusBlockObject = selector_isActiveStyle.getFocusBlockObject;
85
- exports.getFocusChild = selector_isActiveStyle.getFocusChild;
86
- exports.getFocusListBlock = selector_isActiveStyle.getFocusListBlock;
87
- exports.getFocusSpan = selector_isActiveStyle.getFocusSpan;
88
- exports.getFocusTextBlock = selector_isActiveStyle.getFocusTextBlock;
89
- exports.getLastBlock = selector_isActiveStyle.getLastBlock;
90
- exports.getNextBlock = selector_isActiveStyle.getNextBlock;
91
- exports.getPreviousBlock = selector_isActiveStyle.getPreviousBlock;
92
- exports.getSelectedBlocks = selector_isActiveStyle.getSelectedBlocks;
93
- exports.getSelectedSpans = selector_isActiveStyle.getSelectedSpans;
94
- exports.getSelectionEndBlock = selector_isActiveStyle.getSelectionEndBlock;
95
- exports.getSelectionStartBlock = selector_isActiveStyle.getSelectionStartBlock;
96
- exports.isActiveAnnotation = selector_isActiveStyle.isActiveAnnotation;
97
- exports.isActiveDecorator = selector_isActiveStyle.isActiveDecorator;
98
- exports.isActiveListItem = selector_isActiveStyle.isActiveListItem;
99
- exports.isActiveStyle = selector_isActiveStyle.isActiveStyle;
100
- exports.isSelectionCollapsed = selector_isActiveStyle.isSelectionCollapsed;
101
- exports.isSelectionExpanded = selector_isActiveStyle.isSelectionExpanded;
80
+ exports.getActiveListItem = selector_isAtTheStartOfBlock.getActiveListItem;
81
+ exports.getActiveStyle = selector_isAtTheStartOfBlock.getActiveStyle;
82
+ exports.getFirstBlock = selector_isAtTheStartOfBlock.getFirstBlock;
83
+ exports.getFocusBlock = selector_isAtTheStartOfBlock.getFocusBlock;
84
+ exports.getFocusBlockObject = selector_isAtTheStartOfBlock.getFocusBlockObject;
85
+ exports.getFocusChild = selector_isAtTheStartOfBlock.getFocusChild;
86
+ exports.getFocusListBlock = selector_isAtTheStartOfBlock.getFocusListBlock;
87
+ exports.getFocusSpan = selector_isAtTheStartOfBlock.getFocusSpan;
88
+ exports.getFocusTextBlock = selector_isAtTheStartOfBlock.getFocusTextBlock;
89
+ exports.getLastBlock = selector_isAtTheStartOfBlock.getLastBlock;
90
+ exports.getNextBlock = selector_isAtTheStartOfBlock.getNextBlock;
91
+ exports.getPreviousBlock = selector_isAtTheStartOfBlock.getPreviousBlock;
92
+ exports.getSelectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks;
93
+ exports.getSelectedSpans = selector_isAtTheStartOfBlock.getSelectedSpans;
94
+ exports.getSelectionEndBlock = selector_isAtTheStartOfBlock.getSelectionEndBlock;
95
+ exports.getSelectionStartBlock = selector_isAtTheStartOfBlock.getSelectionStartBlock;
96
+ exports.isActiveAnnotation = selector_isAtTheStartOfBlock.isActiveAnnotation;
97
+ exports.isActiveDecorator = selector_isAtTheStartOfBlock.isActiveDecorator;
98
+ exports.isActiveListItem = selector_isAtTheStartOfBlock.isActiveListItem;
99
+ exports.isActiveStyle = selector_isAtTheStartOfBlock.isActiveStyle;
100
+ exports.isAtTheEndOfBlock = selector_isAtTheStartOfBlock.isAtTheEndOfBlock;
101
+ exports.isAtTheStartOfBlock = selector_isAtTheStartOfBlock.isAtTheStartOfBlock;
102
+ exports.isSelectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed;
103
+ exports.isSelectionExpanded = selector_isAtTheStartOfBlock.isSelectionExpanded;
102
104
  exports.getBlockTextBefore = selector_getTextBefore.getBlockTextBefore;
103
105
  exports.getSelectionText = selector_getTextBefore.getSelectionText;
104
106
  exports.getSelectedSlice = getSelectedSlice;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const endBlockKey = isKeySegment(selection.focus.path[0])\n ? selection.focus.path[0]._key\n : undefined\n const endChildKey = isKeySegment(selection.focus.path[2])\n ? selection.focus.path[2]._key\n : undefined\n\n if (!pointBlockKey || !endBlockKey) {\n return false\n }\n\n let after = false\n\n for (const block of snapshot.context.value) {\n if (block._key === endBlockKey) {\n if (block._key !== pointBlockKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !endChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (child._key !== pointChildKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this child\n\n after = point.offset > selection.focus.offset\n break\n }\n\n if (child._key === pointChildKey) {\n break\n }\n }\n }\n\n if (block._key === pointBlockKey) {\n break\n }\n }\n\n return after\n }\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const startBlockKey = isKeySegment(selection.anchor.path[0])\n ? selection.anchor.path[0]._key\n : undefined\n const startChildKey = isKeySegment(selection.anchor.path[2])\n ? selection.anchor.path[2]._key\n : undefined\n\n if (!pointBlockKey || !startBlockKey) {\n return false\n }\n\n let before = false\n\n for (const block of snapshot.context.value) {\n if (block._key === pointBlockKey) {\n if (block._key !== startBlockKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !startChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === pointChildKey) {\n if (child._key !== startChildKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this child\n\n before = point.offset < selection.anchor.offset\n break\n }\n\n if (child._key === startChildKey) {\n break\n }\n }\n }\n\n if (block._key === startBlockKey) {\n break\n }\n }\n\n return before\n }\n}\n"],"names":["getSelectedSlice","context","sliceBlocks","blocks","value","selection","isPointAfterSelection","point","snapshot","reverseSelection","pointBlockKey","isKeySegment","path","_key","undefined","pointChildKey","endBlockKey","focus","endChildKey","after","block","isPortableTextTextBlock","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before"],"mappings":";;;AAOO,MAAMA,mBAA6DA,CAAC;AAAA,EACzEC;AACF,MACSC,6BAAY;AAAA,EAACC,QAAQF,QAAQG;AAAAA,E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":["../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const endBlockKey = isKeySegment(selection.focus.path[0])\n ? selection.focus.path[0]._key\n : undefined\n const endChildKey = isKeySegment(selection.focus.path[2])\n ? selection.focus.path[2]._key\n : undefined\n\n if (!pointBlockKey || !endBlockKey) {\n return false\n }\n\n let after = false\n\n for (const block of snapshot.context.value) {\n if (block._key === endBlockKey) {\n if (block._key !== pointBlockKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !endChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (child._key !== pointChildKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this child\n\n after = point.offset > selection.focus.offset\n break\n }\n\n if (child._key === pointChildKey) {\n break\n }\n }\n }\n\n if (block._key === pointBlockKey) {\n break\n }\n }\n\n return after\n }\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = reverseSelection(snapshot.context.selection)\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const startBlockKey = isKeySegment(selection.anchor.path[0])\n ? selection.anchor.path[0]._key\n : undefined\n const startChildKey = isKeySegment(selection.anchor.path[2])\n ? selection.anchor.path[2]._key\n : undefined\n\n if (!pointBlockKey || !startBlockKey) {\n return false\n }\n\n let before = false\n\n for (const block of snapshot.context.value) {\n if (block._key === pointBlockKey) {\n if (block._key !== startBlockKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !startChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === pointChildKey) {\n if (child._key !== startChildKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this child\n\n before = point.offset < selection.anchor.offset\n break\n }\n\n if (child._key === startChildKey) {\n break\n }\n }\n }\n\n if (block._key === startBlockKey) {\n break\n }\n }\n\n return before\n }\n}\n"],"names":["getSelectedSlice","context","sliceBlocks","blocks","value","selection","isPointAfterSelection","point","snapshot","reverseSelection","pointBlockKey","isKeySegment","path","_key","undefined","pointChildKey","endBlockKey","focus","endChildKey","after","block","isPortableTextTextBlock","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before"],"mappings":";;;AAOO,MAAMA,mBAA6DA,CAAC;AAAA,EACzEC;AACF,MACSC,6BAAY;AAAA,EAACC,QAAQF,QAAQG;AAAAA,EAAOC,WAAWJ,QAAQI;AAAS,CAAC;ACFnE,SAASC,sBACdC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AAQI;AACb,aAAA;AAGT,UAAMA,YAAYI,sBAAAA,iBAAiBD,SAASP,QAAQI,SAAS,GAEvDK,gBAAgBC,MAAAA,aAAaJ,MAAMK,KAAK,CAAC,CAAC,IAC5CL,MAAMK,KAAK,CAAC,EAAEC,OACdC,QACEC,gBAAgBJ,MAAAA,aAAaJ,MAAMK,KAAK,CAAC,CAAC,IAC5CL,MAAMK,KAAK,CAAC,EAAEC,OACdC,QAEEY,gBAAgBf,MAAAA,aAAaN,UAAUsB,OAAOf,KAAK,CAAC,CAAC,IACvDP,UAAUsB,OAAOf,KAAK,CAAC,EAAEC,OACzBC,QACEc,gBAAgBjB,MAAAA,aAAaN,UAAUsB,OAAOf,KAAK,CAAC,CAAC,IACvDP,UAAUsB,OAAOf,KAAK,CAAC,EAAEC,OACzBC;AAEA,QAAA,CAACJ,iBAAiB,CAACgB;AACd,aAAA;AAGT,QAAIG,SAAS;AAEFT,eAAAA,SAASZ,SAASP,QAAQG,OAAO;AACtCgB,UAAAA,MAAMP,SAASH,eAAe;AAC5BU,YAAAA,MAAMP,SAASa,eAAe;AACvB,mBAAA;AACT;AAAA,QAAA;AASF,YAJI,CAACL,MAAAA,wBAAwBD,KAAK,KAI9B,CAACL,iBAAiB,CAACa;AACrB;AAGSN,mBAAAA,SAASF,MAAMG,UAAU;AAC9BD,cAAAA,MAAMT,SAASE,eAAe;AAC5BO,gBAAAA,MAAMT,SAASe,eAAe;AACvB,uBAAA;AACT;AAAA,YAAA;AAKOrB,qBAAAA,MAAMiB,SAASnB,UAAUsB,OAAOH;AACzC;AAAA,UAAA;AAGF,cAAIF,MAAMT,SAASe;AACjB;AAAA,QAAA;AAAA,MAEJ;AAGF,UAAIR,MAAMP,SAASa;AACjB;AAAA,IAAA;AAIGG,WAAAA;AAAAA,EACT;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -315,6 +315,22 @@ export declare function isActiveListItem(
315
315
  */
316
316
  export declare function isActiveStyle(style: string): EditorSelector<boolean>
317
317
 
318
+ /**
319
+ * @public
320
+ */
321
+ export declare function isAtTheEndOfBlock(block: {
322
+ node: PortableTextBlock
323
+ path: [KeyedSegment]
324
+ }): EditorSelector<boolean>
325
+
326
+ /**
327
+ * @public
328
+ */
329
+ export declare function isAtTheStartOfBlock(block: {
330
+ node: PortableTextBlock
331
+ path: [KeyedSegment]
332
+ }): EditorSelector<boolean>
333
+
318
334
  /**
319
335
  * @public
320
336
  */
@@ -315,6 +315,22 @@ export declare function isActiveListItem(
315
315
  */
316
316
  export declare function isActiveStyle(style: string): EditorSelector<boolean>
317
317
 
318
+ /**
319
+ * @public
320
+ */
321
+ export declare function isAtTheEndOfBlock(block: {
322
+ node: PortableTextBlock
323
+ path: [KeyedSegment]
324
+ }): EditorSelector<boolean>
325
+
326
+ /**
327
+ * @public
328
+ */
329
+ export declare function isAtTheStartOfBlock(block: {
330
+ node: PortableTextBlock
331
+ path: [KeyedSegment]
332
+ }): EditorSelector<boolean>
333
+
318
334
  /**
319
335
  * @public
320
336
  */
@@ -1,4 +1,4 @@
1
- import { getActiveListItem, getActiveStyle, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getPreviousBlock, getSelectedBlocks, getSelectedSpans, getSelectionEndBlock, getSelectionStartBlock, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-active-style.js";
1
+ import { getActiveListItem, getActiveStyle, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getPreviousBlock, getSelectedBlocks, getSelectedSpans, getSelectionEndBlock, getSelectionStartBlock, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-at-the-start-of-block.js";
2
2
  import { sliceBlocks } from "../_chunks-es/util.slice-blocks.js";
3
3
  import { getBlockTextBefore, getSelectionText } from "../_chunks-es/selector.get-text-before.js";
4
4
  import { isKeySegment, isPortableTextTextBlock } from "@sanity/types";
@@ -103,6 +103,8 @@ export {
103
103
  isActiveDecorator,
104
104
  isActiveListItem,
105
105
  isActiveStyle,
106
+ isAtTheEndOfBlock,
107
+ isAtTheStartOfBlock,
106
108
  isPointAfterSelection,
107
109
  isPointBeforeSelection,
108
110
  isSelectionCollapsed,
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var util_isEmptyTextBlock = require("../_chunks-cjs/util.is-empty-text-block.cjs"), util_reverseSelection = require("../_chunks-cjs/util.reverse-selection.cjs"), util_isKeyedSegment = require("../_chunks-cjs/util.is-keyed-segment.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs");
3
+ var util_isEmptyTextBlock = require("../_chunks-cjs/util.is-empty-text-block.cjs"), util_isEqualSelectionPoints = require("../_chunks-cjs/util.is-equal-selection-points.cjs"), util_reverseSelection = require("../_chunks-cjs/util.reverse-selection.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs");
4
4
  exports.blockOffsetToSpanSelectionPoint = util_isEmptyTextBlock.blockOffsetToSpanSelectionPoint;
5
5
  exports.getTextBlockText = util_isEmptyTextBlock.getTextBlockText;
6
6
  exports.isEmptyTextBlock = util_isEmptyTextBlock.isEmptyTextBlock;
7
7
  exports.spanSelectionPointToBlockOffset = util_isEmptyTextBlock.spanSelectionPointToBlockOffset;
8
- exports.getBlockStartPoint = util_reverseSelection.getBlockStartPoint;
8
+ exports.getBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint;
9
+ exports.getBlockStartPoint = util_isEqualSelectionPoints.getBlockStartPoint;
10
+ exports.isEqualSelectionPoints = util_isEqualSelectionPoints.isEqualSelectionPoints;
11
+ exports.isKeyedSegment = util_isEqualSelectionPoints.isKeyedSegment;
9
12
  exports.reverseSelection = util_reverseSelection.reverseSelection;
10
- exports.isKeyedSegment = util_isKeyedSegment.isKeyedSegment;
11
13
  exports.sliceBlocks = util_sliceBlocks.sliceBlocks;
12
14
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
@@ -38,6 +38,17 @@ export declare type EditorSelectionPoint = {
38
38
  offset: number
39
39
  }
40
40
 
41
+ /**
42
+ * @public
43
+ */
44
+ export declare function getBlockEndPoint({
45
+ node,
46
+ path,
47
+ }: {
48
+ node: PortableTextBlock
49
+ path: [KeyedSegment]
50
+ }): EditorSelectionPoint
51
+
41
52
  /**
42
53
  * @public
43
54
  */
@@ -59,6 +70,14 @@ export declare function getTextBlockText(block: PortableTextTextBlock): string
59
70
  */
60
71
  export declare function isEmptyTextBlock(block: PortableTextBlock): boolean
61
72
 
73
+ /**
74
+ * @public
75
+ */
76
+ export declare function isEqualSelectionPoints(
77
+ a: EditorSelectionPoint,
78
+ b: EditorSelectionPoint,
79
+ ): boolean
80
+
62
81
  /**
63
82
  * @public
64
83
  */
@@ -38,6 +38,17 @@ export declare type EditorSelectionPoint = {
38
38
  offset: number
39
39
  }
40
40
 
41
+ /**
42
+ * @public
43
+ */
44
+ export declare function getBlockEndPoint({
45
+ node,
46
+ path,
47
+ }: {
48
+ node: PortableTextBlock
49
+ path: [KeyedSegment]
50
+ }): EditorSelectionPoint
51
+
41
52
  /**
42
53
  * @public
43
54
  */
@@ -59,6 +70,14 @@ export declare function getTextBlockText(block: PortableTextTextBlock): string
59
70
  */
60
71
  export declare function isEmptyTextBlock(block: PortableTextBlock): boolean
61
72
 
73
+ /**
74
+ * @public
75
+ */
76
+ export declare function isEqualSelectionPoints(
77
+ a: EditorSelectionPoint,
78
+ b: EditorSelectionPoint,
79
+ ): boolean
80
+
62
81
  /**
63
82
  * @public
64
83
  */
@@ -1,12 +1,14 @@
1
1
  import { blockOffsetToSpanSelectionPoint, getTextBlockText, isEmptyTextBlock, spanSelectionPointToBlockOffset } from "../_chunks-es/util.is-empty-text-block.js";
2
- import { getBlockStartPoint, reverseSelection } from "../_chunks-es/util.reverse-selection.js";
3
- import { isKeyedSegment } from "../_chunks-es/util.is-keyed-segment.js";
2
+ import { getBlockEndPoint, getBlockStartPoint, isEqualSelectionPoints, isKeyedSegment } from "../_chunks-es/util.is-equal-selection-points.js";
3
+ import { reverseSelection } from "../_chunks-es/util.reverse-selection.js";
4
4
  import { sliceBlocks } from "../_chunks-es/util.slice-blocks.js";
5
5
  export {
6
6
  blockOffsetToSpanSelectionPoint,
7
+ getBlockEndPoint,
7
8
  getBlockStartPoint,
8
9
  getTextBlockText,
9
10
  isEmptyTextBlock,
11
+ isEqualSelectionPoints,
10
12
  isKeyedSegment,
11
13
  reverseSelection,
12
14
  sliceBlocks,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.25.0",
3
+ "version": "1.26.1",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -73,15 +73,15 @@
73
73
  "slate-react": "0.112.1",
74
74
  "use-effect-event": "^1.0.2",
75
75
  "xstate": "^5.19.2",
76
- "@portabletext/block-tools": "1.1.2",
76
+ "@portabletext/block-tools": "1.1.3",
77
77
  "@portabletext/patches": "1.1.2"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@portabletext/toolkit": "^2.0.16",
81
81
  "@sanity/diff-match-patch": "^3.2.0",
82
82
  "@sanity/pkg-utils": "^7.0.2",
83
- "@sanity/schema": "^3.71.1",
84
- "@sanity/types": "^3.71.1",
83
+ "@sanity/schema": "^3.71.2",
84
+ "@sanity/types": "^3.71.2",
85
85
  "@testing-library/jest-dom": "^6.6.3",
86
86
  "@testing-library/react": "^16.2.0",
87
87
  "@types/debug": "^4.1.12",
@@ -109,8 +109,8 @@
109
109
  "racejar": "1.1.1"
110
110
  },
111
111
  "peerDependencies": {
112
- "@sanity/schema": "^3.71.1",
113
- "@sanity/types": "^3.71.1",
112
+ "@sanity/schema": "^3.71.2",
113
+ "@sanity/types": "^3.71.2",
114
114
  "react": "^16.9 || ^17 || ^18 || ^19",
115
115
  "rxjs": "^7.8.1"
116
116
  },
@@ -52,10 +52,10 @@ export function insertBlock({
52
52
  Transforms.insertNodes(editor, block, {at: focusBlockPath})
53
53
  } else {
54
54
  Editor.insertNode(editor, block)
55
- }
56
55
 
57
- if (focusBlock && isEqualToEmptyEditor([focusBlock], schema)) {
58
- Transforms.removeNodes(editor, {at: focusBlockPath})
56
+ if (focusBlock && isEqualToEmptyEditor([focusBlock], schema)) {
57
+ Transforms.removeNodes(editor, {at: focusBlockPath})
58
+ }
59
59
  }
60
60
  }
61
61
  }
@@ -0,0 +1,23 @@
1
+ import {Transforms} from 'slate'
2
+ import {toSlateRange} from '../internal-utils/ranges'
3
+ import type {BehaviorActionImplementation} from './behavior.actions'
4
+
5
+ export const blockSetBehaviorActionImplementation: BehaviorActionImplementation<
6
+ 'block.set'
7
+ > = ({action}) => {
8
+ const location = toSlateRange(
9
+ {
10
+ anchor: {path: action.at, offset: 0},
11
+ focus: {path: action.at, offset: 0},
12
+ },
13
+ action.editor,
14
+ )
15
+
16
+ if (!location) {
17
+ return
18
+ }
19
+
20
+ const {at, editor, type, ...payload} = action
21
+
22
+ Transforms.setNodes(action.editor, payload, {at: location})
23
+ }
@@ -0,0 +1,21 @@
1
+ import {Transforms} from 'slate'
2
+ import {toSlateRange} from '../internal-utils/ranges'
3
+ import type {BehaviorActionImplementation} from './behavior.actions'
4
+
5
+ export const blockUnsetBehaviorActionImplementation: BehaviorActionImplementation<
6
+ 'block.unset'
7
+ > = ({action}) => {
8
+ const location = toSlateRange(
9
+ {
10
+ anchor: {path: action.at, offset: 0},
11
+ focus: {path: action.at, offset: 0},
12
+ },
13
+ action.editor,
14
+ )
15
+
16
+ if (!location) {
17
+ return
18
+ }
19
+
20
+ Transforms.unsetNodes(action.editor, action.props, {at: location})
21
+ }
@@ -1,5 +1,5 @@
1
1
  import {isEqual} from 'lodash'
2
- import {Editor, Node, Path, Range, Transforms} from 'slate'
2
+ import {Editor, Node, Path, Transforms} from 'slate'
3
3
  import type {SlateTextBlock, VoidElement} from '../types/slate'
4
4
  import type {BehaviorActionImplementation} from './behavior.actions'
5
5
 
@@ -14,24 +14,6 @@ export const insertBreakActionImplementation: BehaviorActionImplementation<
14
14
  return
15
15
  }
16
16
 
17
- const [focusSpan] = Array.from(
18
- Editor.nodes(editor, {
19
- mode: 'lowest',
20
- at: editor.selection.focus,
21
- match: (n) => editor.isTextSpan(n),
22
- voids: false,
23
- }),
24
- )[0] ?? [undefined]
25
- const focusDecorators =
26
- focusSpan?.marks?.filter((mark) =>
27
- schema.decorators.some((decorator) => decorator.value === mark),
28
- ) ?? []
29
- const focusAnnotations =
30
- focusSpan?.marks?.filter(
31
- (mark) =>
32
- !schema.decorators.some((decorator) => decorator.value === mark),
33
- ) ?? []
34
-
35
17
  const anchorBlockPath = editor.selection.anchor.path.slice(0, 1)
36
18
  const focusBlockPath = editor.selection.focus.path.slice(0, 1)
37
19
  const focusBlock = Node.descendant(editor, focusBlockPath) as
@@ -39,58 +21,9 @@ export const insertBreakActionImplementation: BehaviorActionImplementation<
39
21
  | VoidElement
40
22
 
41
23
  if (editor.isTextBlock(focusBlock)) {
42
- const [start, end] = Range.edges(editor.selection)
43
- const lastFocusBlockChild =
44
- focusBlock.children[focusBlock.children.length - 1]
45
- const atTheEndOfBlock = isEqual(start, {
46
- path: [...focusBlockPath, focusBlock.children.length - 1],
47
- offset: editor.isTextSpan(lastFocusBlockChild)
48
- ? lastFocusBlockChild.text.length
49
- : 0,
50
- })
51
- const atTheStartOfBlock = isEqual(end, {
52
- path: [...focusBlockPath, 0],
53
- offset: 0,
54
- })
55
-
56
- if (atTheEndOfBlock && Range.isCollapsed(editor.selection)) {
57
- Editor.insertNode(
58
- editor,
59
- editor.pteCreateTextBlock({
60
- decorators: [],
61
- listItem: focusBlock.listItem,
62
- level: focusBlock.level,
63
- }),
64
- )
65
-
66
- return
67
- }
68
-
69
- if (atTheStartOfBlock && Range.isCollapsed(editor.selection)) {
70
- Editor.insertNode(
71
- editor,
72
- editor.pteCreateTextBlock({
73
- decorators: focusAnnotations.length === 0 ? focusDecorators : [],
74
- listItem: focusBlock.listItem,
75
- level: focusBlock.level,
76
- }),
77
- )
78
-
79
- const [nextBlockPath] = Path.next(focusBlockPath)
80
-
81
- Transforms.select(editor, {
82
- anchor: {path: [nextBlockPath, 0], offset: 0},
83
- focus: {path: [nextBlockPath, 0], offset: 0},
84
- })
85
-
86
- return
87
- }
88
-
89
24
  const selectionAcrossBlocks = anchorBlockPath[0] !== focusBlockPath[0]
90
25
 
91
- const isInTheMiddleOfNode = !atTheStartOfBlock && !atTheEndOfBlock
92
-
93
- if (isInTheMiddleOfNode && !selectionAcrossBlocks) {
26
+ if (!selectionAcrossBlocks) {
94
27
  Editor.withoutNormalizing(editor, () => {
95
28
  if (!editor.selection) {
96
29
  return
@@ -0,0 +1,33 @@
1
+ import {parseBlock} from '../internal-utils/parse-blocks'
2
+ import {toSlateValue} from '../internal-utils/values'
3
+ import {insertBlock} from './behavior.action-utils.insert-block'
4
+ import type {BehaviorActionImplementation} from './behavior.actions'
5
+
6
+ export const insertBlockActionImplementation: BehaviorActionImplementation<
7
+ 'insert.block'
8
+ > = ({context, action}) => {
9
+ const parsedBlock = parseBlock({
10
+ block: action.block,
11
+ context,
12
+ options: {refreshKeys: false},
13
+ })
14
+
15
+ if (!parsedBlock) {
16
+ throw new Error(`Failed to parse block ${JSON.stringify(action.block)}`)
17
+ }
18
+
19
+ const fragment = toSlateValue([parsedBlock], {schemaTypes: context.schema})[0]
20
+
21
+ if (!fragment) {
22
+ throw new Error(
23
+ `Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`,
24
+ )
25
+ }
26
+
27
+ insertBlock({
28
+ block: fragment,
29
+ placement: action.placement,
30
+ editor: action.editor,
31
+ schema: context.schema,
32
+ })
33
+ }
@@ -28,6 +28,8 @@ import {KEY_TO_VALUE_ELEMENT} from '../internal-utils/weakMaps'
28
28
  import type {PickFromUnion} from '../type-utils'
29
29
  import {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'
30
30
  import {insertBlock} from './behavior.action-utils.insert-block'
31
+ import {blockSetBehaviorActionImplementation} from './behavior.action.block.set'
32
+ import {blockUnsetBehaviorActionImplementation} from './behavior.action.block.unset'
31
33
  import {dataTransferSetActionImplementation} from './behavior.action.data-transfer-set'
32
34
  import {insertBlockObjectActionImplementation} from './behavior.action.insert-block-object'
33
35
  import {insertBlocksActionImplementation} from './behavior.action.insert-blocks'
@@ -37,6 +39,7 @@ import {
37
39
  } from './behavior.action.insert-break'
38
40
  import {insertInlineObjectActionImplementation} from './behavior.action.insert-inline-object'
39
41
  import {insertSpanActionImplementation} from './behavior.action.insert-span'
42
+ import {insertBlockActionImplementation} from './behavior.action.insert.block'
40
43
  import {
41
44
  addListItemActionImplementation,
42
45
  removeListItemActionImplementation,
@@ -74,6 +77,8 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
74
77
  'annotation.add': addAnnotationActionImplementation,
75
78
  'annotation.remove': removeAnnotationActionImplementation,
76
79
  'annotation.toggle': toggleAnnotationActionImplementation,
80
+ 'block.set': blockSetBehaviorActionImplementation,
81
+ 'block.unset': blockUnsetBehaviorActionImplementation,
77
82
  'blur': ({action}) => {
78
83
  ReactEditor.blur(action.editor)
79
84
  },
@@ -161,6 +166,7 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
161
166
  },
162
167
  })
163
168
  },
169
+ 'insert.block': insertBlockActionImplementation,
164
170
  'insert.blocks': insertBlocksActionImplementation,
165
171
  'insert.block object': insertBlockObjectActionImplementation,
166
172
  'insert.break': insertBreakActionImplementation,
@@ -322,13 +328,6 @@ export function performAction({
322
328
  })
323
329
  break
324
330
  }
325
- case 'select': {
326
- behaviorActionImplementations.select({
327
- context,
328
- action,
329
- })
330
- break
331
- }
332
331
  default: {
333
332
  performDefaultAction({context, action})
334
333
  }
@@ -364,6 +363,20 @@ function performDefaultAction({
364
363
  })
365
364
  break
366
365
  }
366
+ case 'block.set': {
367
+ behaviorActionImplementations['block.set']({
368
+ context,
369
+ action,
370
+ })
371
+ break
372
+ }
373
+ case 'block.unset': {
374
+ behaviorActionImplementations['block.unset']({
375
+ context,
376
+ action,
377
+ })
378
+ break
379
+ }
367
380
  case 'blur': {
368
381
  behaviorActionImplementations.blur({
369
382
  context,
@@ -448,6 +461,13 @@ function performDefaultAction({
448
461
  })
449
462
  break
450
463
  }
464
+ case 'insert.block': {
465
+ behaviorActionImplementations['insert.block']({
466
+ context,
467
+ action,
468
+ })
469
+ break
470
+ }
451
471
  case 'insert.blocks': {
452
472
  behaviorActionImplementations['insert.blocks']({
453
473
  context,
@@ -609,12 +629,11 @@ function performDefaultAction({
609
629
  })
610
630
  break
611
631
  }
612
- case 'text block.unset': {
632
+ default: {
613
633
  behaviorActionImplementations['text block.unset']({
614
634
  context,
615
635
  action,
616
636
  })
617
- break
618
637
  }
619
638
  }
620
639
  }