@portabletext/editor 1.36.1 → 1.36.2

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 (69) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +24 -13
  2. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  4. package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
  5. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  6. package/lib/_chunks-es/editor-provider.js +24 -13
  7. package/lib/_chunks-es/editor-provider.js.map +1 -1
  8. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  9. package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
  10. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  11. package/lib/behaviors/index.d.cts +7 -10
  12. package/lib/behaviors/index.d.ts +7 -10
  13. package/lib/index.cjs +140 -104
  14. package/lib/index.cjs.map +1 -1
  15. package/lib/index.d.cts +13 -26
  16. package/lib/index.d.ts +13 -26
  17. package/lib/index.js +142 -106
  18. package/lib/index.js.map +1 -1
  19. package/lib/plugins/index.cjs.map +1 -1
  20. package/lib/plugins/index.d.cts +2 -7
  21. package/lib/plugins/index.d.ts +2 -7
  22. package/lib/plugins/index.js.map +1 -1
  23. package/lib/selectors/index.cjs.map +1 -1
  24. package/lib/selectors/index.d.cts +8 -13
  25. package/lib/selectors/index.d.ts +8 -13
  26. package/lib/selectors/index.js.map +1 -1
  27. package/lib/utils/index.cjs.map +1 -1
  28. package/lib/utils/index.d.cts +3 -6
  29. package/lib/utils/index.d.ts +3 -6
  30. package/lib/utils/index.js.map +1 -1
  31. package/package.json +9 -8
  32. package/src/behavior-actions/behavior.actions.ts +2 -2
  33. package/src/behaviors/behavior.decorator-pair.ts +2 -1
  34. package/src/behaviors/index.ts +0 -8
  35. package/src/converters/converter.text-html.deserialize.test.ts +1 -1
  36. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  37. package/src/converters/converter.text-html.ts +8 -0
  38. package/src/converters/converter.text-plain.test.ts +1 -1
  39. package/src/converters/converter.text-plain.ts +8 -0
  40. package/src/editor/Editable.tsx +1 -1
  41. package/src/editor/__tests__/PortableTextEditor.test.tsx +16 -20
  42. package/src/editor/components/Element.tsx +26 -18
  43. package/src/editor/components/drop-indicator.tsx +14 -0
  44. package/src/editor/components/{DraggableBlock.tsx → use-draggable.ts} +42 -163
  45. package/src/editor/components/use-droppable.ts +135 -0
  46. package/src/editor/create-slate-editor.tsx +0 -3
  47. package/src/index.ts +48 -12
  48. package/src/internal-utils/create-test-snapshot.ts +1 -1
  49. package/src/plugins/plugin.decorator-shortcut.ts +1 -1
  50. package/src/plugins/plugin.markdown.tsx +1 -0
  51. package/src/selectors/index.ts +0 -8
  52. package/src/selectors/selector.get-active-annotations.test.ts +1 -1
  53. package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
  54. package/src/selectors/selector.get-selected-spans.test.ts +2 -1
  55. package/src/selectors/selector.get-selection-end-point.ts +1 -1
  56. package/src/selectors/selector.get-selection-start-point.ts +1 -1
  57. package/src/selectors/selector.get-selection-text.test.ts +1 -1
  58. package/src/selectors/selector.get-selection.ts +2 -1
  59. package/src/selectors/selector.get-value.ts +1 -1
  60. package/src/selectors/selector.is-active-decorator.test.ts +1 -1
  61. package/src/types/editor.ts +6 -16
  62. package/src/types/slate.ts +1 -1
  63. package/src/utils/index.ts +0 -1
  64. package/src/utils/util.block-offsets-to-selection.ts +1 -1
  65. package/src/utils/util.is-span.ts +1 -1
  66. package/src/utils/util.is-text-block.ts +1 -1
  67. package/src/utils/util.merge-text-blocks.ts +1 -1
  68. package/src/utils/util.slice-blocks.ts +1 -1
  69. package/src/utils/util.split-text-block.ts +4 -2
@@ -2493,14 +2493,21 @@ const converterJson = {
2493
2493
  deserialize: ({
2494
2494
  snapshot,
2495
2495
  event
2496
- }) => ({
2497
- type: "deserialization.success",
2498
- data: blockTools.htmlToBlocks(event.data, snapshot.context.schema.portableText, {
2496
+ }) => {
2497
+ const blocks = blockTools.htmlToBlocks(event.data, snapshot.context.schema.portableText, {
2499
2498
  keyGenerator: snapshot.context.keyGenerator,
2500
2499
  unstable_whitespaceOnPasteMode: snapshot.context.schema.block.options.unstable_whitespaceOnPasteMode
2501
- }),
2502
- mimeType: "text/html"
2503
- })
2500
+ });
2501
+ return blocks.length === 0 ? {
2502
+ type: "deserialization.failure",
2503
+ mimeType: "text/html",
2504
+ reason: "No blocks deserialized"
2505
+ } : {
2506
+ type: "deserialization.success",
2507
+ data: blocks,
2508
+ mimeType: "text/html"
2509
+ };
2510
+ }
2504
2511
  }, converterTextPlain = {
2505
2512
  mimeType: "text/plain",
2506
2513
  serialize: ({
@@ -2526,12 +2533,16 @@ const converterJson = {
2526
2533
  snapshot,
2527
2534
  event
2528
2535
  }) => {
2529
- const textToHtml = `<html><body>${escapeHtml(event.data).split(/\n{2,}/).map((line) => line ? `<p>${line.replace(/(?:\r\n|\r|\n)/g, "<br/>")}</p>` : "<p></p>").join("")}</body></html>`;
2530
- return {
2536
+ const textToHtml = `<html><body>${escapeHtml(event.data).split(/\n{2,}/).map((line) => line ? `<p>${line.replace(/(?:\r\n|\r|\n)/g, "<br/>")}</p>` : "<p></p>").join("")}</body></html>`, blocks = blockTools.htmlToBlocks(textToHtml, snapshot.context.schema.portableText, {
2537
+ keyGenerator: snapshot.context.keyGenerator
2538
+ });
2539
+ return blocks.length === 0 ? {
2540
+ type: "deserialization.failure",
2541
+ mimeType: "text/plain",
2542
+ reason: "No blocks deserialized"
2543
+ } : {
2531
2544
  type: "deserialization.success",
2532
- data: blockTools.htmlToBlocks(textToHtml, snapshot.context.schema.portableText, {
2533
- keyGenerator: snapshot.context.keyGenerator
2534
- }),
2545
+ data: blocks,
2535
2546
  mimeType: "text/plain"
2536
2547
  };
2537
2548
  }
@@ -4450,7 +4461,7 @@ const blockSetBehaviorActionImplementation = ({
4450
4461
  "deserialization.failure": ({
4451
4462
  action
4452
4463
  }) => {
4453
- console.warn(`Deserialization of ${action.mimeType} failed with reason ${action.reason}`);
4464
+ console.warn(`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`);
4454
4465
  },
4455
4466
  "deserialization.success": ({
4456
4467
  context,
@@ -4583,7 +4594,7 @@ const blockSetBehaviorActionImplementation = ({
4583
4594
  "serialization.failure": ({
4584
4595
  action
4585
4596
  }) => {
4586
- console.warn(`Serialization of ${action.mimeType} failed with reason ${action.reason}`);
4597
+ console.warn(`Serialization of ${action.mimeType} failed with reason "${action.reason}"`);
4587
4598
  },
4588
4599
  "serialization.success": ({
4589
4600
  context,