@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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import {Patch} from '@portabletext/patches'
2
- import {
2
+ import type {
3
3
  ArrayDefinition,
4
4
  ArraySchemaType,
5
5
  BlockDecoratorDefinition,
@@ -12,31 +12,32 @@ import {
12
12
  PortableTextChild,
13
13
  PortableTextListBlock,
14
14
  PortableTextObject,
15
- PortableTextSpan,
16
- PortableTextTextBlock,
17
15
  SpanSchemaType,
18
16
  TypedObject,
19
17
  } from '@sanity/types'
20
- import {
18
+ import {PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
19
+ import type {
21
20
  BaseSyntheticEvent,
22
21
  ClipboardEvent as ClipboardEvent_2,
23
- Component,
24
22
  FocusEvent as FocusEvent_2,
23
+ KeyboardEvent as KeyboardEvent_2,
24
+ ReactElement,
25
+ RefObject,
26
+ } from 'react'
27
+ import {
28
+ Component,
25
29
  ForwardRefExoticComponent,
26
30
  HTMLProps,
27
31
  JSX as JSX_2,
28
- KeyboardEvent as KeyboardEvent_2,
29
32
  MutableRefObject,
30
33
  PropsWithChildren,
31
- ReactElement,
32
34
  RefAttributes,
33
- RefObject,
34
35
  TextareaHTMLAttributes,
35
36
  } from 'react'
36
- import {Observable, Subject} from 'rxjs'
37
- import {Descendant, Node as Node_2, Operation} from 'slate'
38
- import {ReactEditor} from 'slate-react'
39
- import {DOMNode} from 'slate-react/dist/utils/dom'
37
+ import type {Observable, Subject} from 'rxjs'
38
+ import type {Descendant, Node as Node_2, Operation} from 'slate'
39
+ import type {ReactEditor} from 'slate-react'
40
+ import type {DOMNode} from 'slate-react/dist/utils/dom'
40
41
 
41
42
  /** @beta */
42
43
  export declare interface BlockAnnotationRenderProps {
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import {Patch} from '@portabletext/patches'
2
- import {
2
+ import type {
3
3
  ArrayDefinition,
4
4
  ArraySchemaType,
5
5
  BlockDecoratorDefinition,
@@ -12,31 +12,32 @@ import {
12
12
  PortableTextChild,
13
13
  PortableTextListBlock,
14
14
  PortableTextObject,
15
- PortableTextSpan,
16
- PortableTextTextBlock,
17
15
  SpanSchemaType,
18
16
  TypedObject,
19
17
  } from '@sanity/types'
20
- import {
18
+ import {PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
19
+ import type {
21
20
  BaseSyntheticEvent,
22
21
  ClipboardEvent as ClipboardEvent_2,
23
- Component,
24
22
  FocusEvent as FocusEvent_2,
23
+ KeyboardEvent as KeyboardEvent_2,
24
+ ReactElement,
25
+ RefObject,
26
+ } from 'react'
27
+ import {
28
+ Component,
25
29
  ForwardRefExoticComponent,
26
30
  HTMLProps,
27
31
  JSX as JSX_2,
28
- KeyboardEvent as KeyboardEvent_2,
29
32
  MutableRefObject,
30
33
  PropsWithChildren,
31
- ReactElement,
32
34
  RefAttributes,
33
- RefObject,
34
35
  TextareaHTMLAttributes,
35
36
  } from 'react'
36
- import {Observable, Subject} from 'rxjs'
37
- import {Descendant, Node as Node_2, Operation} from 'slate'
38
- import {ReactEditor} from 'slate-react'
39
- import {DOMNode} from 'slate-react/dist/utils/dom'
37
+ import type {Observable, Subject} from 'rxjs'
38
+ import type {Descendant, Node as Node_2, Operation} from 'slate'
39
+ import type {ReactEditor} from 'slate-react'
40
+ import type {DOMNode} from 'slate-react/dist/utils/dom'
40
41
 
41
42
  /** @beta */
42
43
  export declare interface BlockAnnotationRenderProps {
package/lib/index.esm.js CHANGED
@@ -724,7 +724,6 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = { display: "inline-block" }, El
724
724
  };
725
725
  function DefaultAnnotation(props) {
726
726
  const handleClick = useCallback(
727
- // eslint-disable-next-line no-alert
728
727
  () => alert(JSON.stringify(props.annotation)),
729
728
  [props.annotation]
730
729
  );
@@ -2456,7 +2455,7 @@ function toInt(num) {
2456
2455
  const debug$i = debugWithName("applyPatches"), debugVerbose$4 = debug$i.enabled && !0;
2457
2456
  function createApplyPatch(schemaTypes) {
2458
2457
  let previousPatch;
2459
- return function(editor, patch) {
2458
+ return (editor, patch) => {
2460
2459
  let changed = !1;
2461
2460
  debugVerbose$4 && (debug$i(
2462
2461
  `
@@ -3618,7 +3617,7 @@ function createWithSchemaTypes({
3618
3617
  keyGenerator
3619
3618
  }) {
3620
3619
  return function(editor) {
3621
- editor.isTextBlock = (value) => isPortableTextTextBlock(value) && value._type === schemaTypes.block.name, editor.isTextSpan = (value) => isPortableTextSpan$1(value) && value._type == schemaTypes.span.name, editor.isListBlock = (value) => 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;
3620
+ editor.isTextBlock = (value) => isPortableTextTextBlock(value) && value._type === schemaTypes.block.name, editor.isTextSpan = (value) => isPortableTextSpan$1(value) && value._type === schemaTypes.span.name, editor.isListBlock = (value) => 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;
3622
3621
  const { normalizeNode } = editor;
3623
3622
  return editor.normalizeNode = (entry) => {
3624
3623
  const [node, path] = entry;
@@ -3656,7 +3655,7 @@ function createWithUtils({
3656
3655
  return;
3657
3656
  }
3658
3657
  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);
3659
- if (!(newStartOffset === newEndOffset || isNaN(newStartOffset) || isNaN(newEndOffset))) {
3658
+ if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
3660
3659
  debug$9("pteExpandToWord: Expanding to focused word"), Transforms.setSelection(editor, {
3661
3660
  anchor: { ...selection.anchor, offset: newStartOffset },
3662
3661
  focus: { ...selection.focus, offset: newEndOffset }
@@ -4258,10 +4257,7 @@ function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTyp
4258
4257
  return newNode.children = newNode.children.map(
4259
4258
  (child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
4260
4259
  ...child,
4261
- marks: child.marks && child.marks.includes(oldKey) ? (
4262
- // eslint-disable-next-line max-nested-callbacks
4263
- [...child.marks].filter((mark) => mark !== oldKey).concat(newKey)
4264
- ) : child.marks
4260
+ marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
4265
4261
  } : child
4266
4262
  ), { ...def, _key: newKey };
4267
4263
  });
@@ -4780,7 +4776,7 @@ class PortableTextEditor extends Component {
4780
4776
  return this.editable.getValue();
4781
4777
  };
4782
4778
  render() {
4783
- 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;
4779
+ 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;
4784
4780
  return /* @__PURE__ */ jsx(
4785
4781
  SlateContainer,
4786
4782
  {
@@ -5191,7 +5187,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
5191
5187
  return;
5192
5188
  }
5193
5189
  }
5194
- setRangeDecorationsState([]);
5190
+ rangeDecorationState.length > 0 && setRangeDecorationsState([]);
5195
5191
  },
5196
5192
  [portableTextEditor, rangeDecorations, schemaTypes, slateEditor]
5197
5193
  );