@portabletext/editor 1.1.0 → 1.1.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 (64) hide show
  1. package/lib/index.d.mts +13 -12
  2. package/lib/index.d.ts +13 -12
  3. package/lib/index.esm.js +6 -10
  4. package/lib/index.esm.js.map +1 -1
  5. package/lib/index.js +6 -10
  6. package/lib/index.js.map +1 -1
  7. package/lib/index.mjs +6 -10
  8. package/lib/index.mjs.map +1 -1
  9. package/package.json +3 -17
  10. package/src/editor/Editable.tsx +21 -19
  11. package/src/editor/PortableTextEditor.tsx +19 -20
  12. package/src/editor/__tests__/PortableTextEditor.test.tsx +2 -3
  13. package/src/editor/__tests__/RangeDecorations.test.tsx +4 -5
  14. package/src/editor/__tests__/insert-block.test.tsx +2 -2
  15. package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +1 -1
  16. package/src/editor/__tests__/utils.ts +0 -1
  17. package/src/editor/components/Element.tsx +15 -17
  18. package/src/editor/components/Leaf.tsx +12 -12
  19. package/src/editor/components/SlateContainer.tsx +2 -2
  20. package/src/editor/components/Synchronizer.tsx +3 -3
  21. package/src/editor/hooks/usePortableTextEditor.ts +1 -1
  22. package/src/editor/hooks/usePortableTextEditorSelection.tsx +1 -1
  23. package/src/editor/hooks/useSyncValue.ts +3 -7
  24. package/src/editor/nodes/DefaultAnnotation.tsx +1 -2
  25. package/src/editor/nodes/DefaultObject.tsx +1 -1
  26. package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +1 -4
  27. package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +1 -1
  28. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +1 -3
  29. package/src/editor/plugins/createWithEditableAPI.ts +8 -8
  30. package/src/editor/plugins/createWithHotKeys.ts +8 -12
  31. package/src/editor/plugins/createWithInsertBreak.ts +4 -4
  32. package/src/editor/plugins/createWithInsertData.ts +7 -8
  33. package/src/editor/plugins/createWithMaxBlocks.ts +1 -1
  34. package/src/editor/plugins/createWithObjectKeys.ts +3 -3
  35. package/src/editor/plugins/createWithPatches.ts +6 -8
  36. package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -2
  37. package/src/editor/plugins/createWithPortableTextBlockStyle.ts +3 -3
  38. package/src/editor/plugins/createWithPortableTextLists.ts +3 -4
  39. package/src/editor/plugins/createWithPortableTextMarkModel.ts +6 -8
  40. package/src/editor/plugins/createWithPortableTextSelections.ts +7 -7
  41. package/src/editor/plugins/createWithSchemaTypes.ts +4 -4
  42. package/src/editor/plugins/createWithUndoRedo.ts +3 -7
  43. package/src/editor/plugins/createWithUtils.ts +6 -6
  44. package/src/editor/plugins/index.ts +3 -3
  45. package/src/types/editor.ts +33 -33
  46. package/src/types/options.ts +3 -3
  47. package/src/types/slate.ts +4 -4
  48. package/src/utils/__tests__/dmpToOperations.test.ts +3 -3
  49. package/src/utils/__tests__/operationToPatches.test.ts +1 -1
  50. package/src/utils/__tests__/patchToOperations.test.ts +1 -1
  51. package/src/utils/__tests__/ranges.test.ts +1 -1
  52. package/src/utils/applyPatch.ts +10 -12
  53. package/src/utils/getPortableTextMemberSchemaTypes.ts +8 -8
  54. package/src/utils/operationToPatches.ts +5 -9
  55. package/src/utils/paths.ts +5 -5
  56. package/src/utils/ranges.ts +4 -5
  57. package/src/utils/selection.ts +2 -2
  58. package/src/utils/ucs2Indices.ts +2 -2
  59. package/src/utils/validateValue.ts +3 -3
  60. package/src/utils/values.ts +7 -8
  61. package/src/utils/weakMaps.ts +2 -2
  62. package/src/utils/withChanges.ts +1 -1
  63. package/src/utils/withUndoRedo.ts +1 -1
  64. package/src/utils/withoutPatching.ts +1 -1
package/lib/index.js CHANGED
@@ -708,7 +708,6 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = { display: "inline-block" }, El
708
708
  };
709
709
  function DefaultAnnotation(props) {
710
710
  const handleClick = react.useCallback(
711
- // eslint-disable-next-line no-alert
712
711
  () => alert(JSON.stringify(props.annotation)),
713
712
  [props.annotation]
714
713
  );
@@ -2440,7 +2439,7 @@ function toInt(num) {
2440
2439
  const debug$i = debugWithName("applyPatches"), debugVerbose$4 = debug$i.enabled && !0;
2441
2440
  function createApplyPatch(schemaTypes) {
2442
2441
  let previousPatch;
2443
- return function(editor, patch) {
2442
+ return (editor, patch) => {
2444
2443
  let changed = !1;
2445
2444
  debugVerbose$4 && (debug$i(
2446
2445
  `
@@ -3602,7 +3601,7 @@ function createWithSchemaTypes({
3602
3601
  keyGenerator
3603
3602
  }) {
3604
3603
  return function(editor) {
3605
- editor.isTextBlock = (value) => types.isPortableTextTextBlock(value) && value._type === schemaTypes.block.name, editor.isTextSpan = (value) => types.isPortableTextSpan(value) && value._type == schemaTypes.span.name, editor.isListBlock = (value) => types.isPortableTextListBlock(value) && value._type === schemaTypes.block.name, editor.isVoid = (element) => schemaTypes.block.name !== element._type && (schemaTypes.blockObjects.map((obj) => obj.name).includes(element._type) || schemaTypes.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => schemaTypes.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
3604
+ editor.isTextBlock = (value) => types.isPortableTextTextBlock(value) && value._type === schemaTypes.block.name, editor.isTextSpan = (value) => types.isPortableTextSpan(value) && value._type === schemaTypes.span.name, editor.isListBlock = (value) => types.isPortableTextListBlock(value) && value._type === schemaTypes.block.name, editor.isVoid = (element) => schemaTypes.block.name !== element._type && (schemaTypes.blockObjects.map((obj) => obj.name).includes(element._type) || schemaTypes.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => schemaTypes.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
3606
3605
  const { normalizeNode } = editor;
3607
3606
  return editor.normalizeNode = (entry) => {
3608
3607
  const [node, path] = entry;
@@ -3640,7 +3639,7 @@ function createWithUtils({
3640
3639
  return;
3641
3640
  }
3642
3641
  const { focus } = selection, focusOffset = focus.offset, charsBefore = textNode.text.slice(0, focusOffset), charsAfter = textNode.text.slice(focusOffset, -1), isEmpty = (str) => str.match(/\s/g), whiteSpaceBeforeIndex = charsBefore.split("").reverse().findIndex((str) => isEmpty(str)), newStartOffset = whiteSpaceBeforeIndex > -1 ? charsBefore.length - whiteSpaceBeforeIndex : 0, whiteSpaceAfterIndex = charsAfter.split("").findIndex((obj) => isEmpty(obj)), newEndOffset = charsBefore.length + (whiteSpaceAfterIndex > -1 ? whiteSpaceAfterIndex : charsAfter.length + 1);
3643
- if (!(newStartOffset === newEndOffset || isNaN(newStartOffset) || isNaN(newEndOffset))) {
3642
+ if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
3644
3643
  debug$9("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
3645
3644
  anchor: { ...selection.anchor, offset: newStartOffset },
3646
3645
  focus: { ...selection.focus, offset: newEndOffset }
@@ -4242,10 +4241,7 @@ function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTyp
4242
4241
  return newNode.children = newNode.children.map(
4243
4242
  (child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
4244
4243
  ...child,
4245
- marks: child.marks && child.marks.includes(oldKey) ? (
4246
- // eslint-disable-next-line max-nested-callbacks
4247
- [...child.marks].filter((mark) => mark !== oldKey).concat(newKey)
4248
- ) : child.marks
4244
+ marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
4249
4245
  } : child
4250
4246
  ), { ...def, _key: newKey };
4251
4247
  });
@@ -4764,7 +4760,7 @@ class PortableTextEditor extends react.Component {
4764
4760
  return this.editable.getValue();
4765
4761
  };
4766
4762
  render() {
4767
- const { onChange, value, children, patches$, incomingPatches$ } = this.props, { change$ } = this, _patches$ = incomingPatches$ || patches$, maxBlocks = typeof this.props.maxBlocks > "u" ? void 0 : parseInt(this.props.maxBlocks.toString(), 10) || void 0, readOnly = !!this.props.readOnly, keyGenerator = this.props.keyGenerator || defaultKeyGenerator;
4763
+ const { onChange, value, children, patches$, incomingPatches$ } = this.props, { change$ } = this, _patches$ = incomingPatches$ || patches$, maxBlocks = typeof this.props.maxBlocks > "u" ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10) || void 0, readOnly = !!this.props.readOnly, keyGenerator = this.props.keyGenerator || defaultKeyGenerator;
4768
4764
  return /* @__PURE__ */ jsxRuntime.jsx(
4769
4765
  SlateContainer,
4770
4766
  {
@@ -5175,7 +5171,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
5175
5171
  return;
5176
5172
  }
5177
5173
  }
5178
- setRangeDecorationsState([]);
5174
+ rangeDecorationState.length > 0 && setRangeDecorationsState([]);
5179
5175
  },
5180
5176
  [portableTextEditor, rangeDecorations, schemaTypes, slateEditor]
5181
5177
  );