@portabletext/editor 1.36.0 → 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 (70) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +25 -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 +25 -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 +14 -13
  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/editor/sync-machine.ts +1 -0
  48. package/src/index.ts +48 -12
  49. package/src/internal-utils/create-test-snapshot.ts +1 -1
  50. package/src/plugins/plugin.decorator-shortcut.ts +1 -1
  51. package/src/plugins/plugin.markdown.tsx +1 -0
  52. package/src/selectors/index.ts +0 -8
  53. package/src/selectors/selector.get-active-annotations.test.ts +1 -1
  54. package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
  55. package/src/selectors/selector.get-selected-spans.test.ts +2 -1
  56. package/src/selectors/selector.get-selection-end-point.ts +1 -1
  57. package/src/selectors/selector.get-selection-start-point.ts +1 -1
  58. package/src/selectors/selector.get-selection-text.test.ts +1 -1
  59. package/src/selectors/selector.get-selection.ts +2 -1
  60. package/src/selectors/selector.get-value.ts +1 -1
  61. package/src/selectors/selector.is-active-decorator.test.ts +1 -1
  62. package/src/types/editor.ts +6 -16
  63. package/src/types/slate.ts +1 -1
  64. package/src/utils/index.ts +0 -1
  65. package/src/utils/util.block-offsets-to-selection.ts +1 -1
  66. package/src/utils/util.is-span.ts +1 -1
  67. package/src/utils/util.is-text-block.ts +1 -1
  68. package/src/utils/util.merge-text-blocks.ts +1 -1
  69. package/src/utils/util.slice-blocks.ts +1 -1
  70. package/src/utils/util.split-text-block.ts +4 -2
package/src/index.ts CHANGED
@@ -4,17 +4,7 @@ export type {
4
4
  PortableTextChild,
5
5
  PortableTextSpan,
6
6
  } from '@sanity/types'
7
- export type {
8
- Behavior,
9
- BehaviorActionIntend,
10
- BehaviorActionIntendSet,
11
- BehaviorEvent,
12
- BehaviorGuard,
13
- NativeBehaviorEvent,
14
- SyntheticBehaviorEvent,
15
- } from './behaviors/index'
16
7
  export type {Editor, EditorConfig, EditorEvent} from './editor/create-editor'
17
- export type {SlateEditor} from './editor/create-slate-editor'
18
8
  export {
19
9
  defineSchema,
20
10
  type BaseDefinition,
@@ -43,6 +33,52 @@ export {PortableTextEditor} from './editor/PortableTextEditor'
43
33
  export type {PortableTextEditorProps} from './editor/PortableTextEditor'
44
34
  export {EditorEventListener} from './editor-event-listener'
45
35
  export type {BlockOffset} from './types/block-offset'
46
- export * from './types/editor'
47
- export type {PortableTextMemberSchemaTypes} from './types/editor'
36
+ export type {
37
+ EditableAPIDeleteOptions,
38
+ EditableAPI,
39
+ EditorSelectionPoint,
40
+ EditorSelection,
41
+ MutationChange,
42
+ PatchChange,
43
+ ValueChange,
44
+ SelectionChange,
45
+ FocusChange,
46
+ UnsetChange,
47
+ BlurChange,
48
+ LoadingChange,
49
+ ReadyChange,
50
+ ErrorChange,
51
+ InvalidValueResolution,
52
+ InvalidValue,
53
+ UndoChange,
54
+ RedoChange,
55
+ ConnectionChange,
56
+ EditorChange,
57
+ EditorChanges,
58
+ OnPasteResult,
59
+ OnPasteResultOrPromise,
60
+ PasteData,
61
+ OnPasteFn,
62
+ OnBeforeInputFn,
63
+ OnCopyFn,
64
+ PatchObservable,
65
+ BlockRenderProps,
66
+ BlockChildRenderProps,
67
+ BlockAnnotationRenderProps,
68
+ BlockDecoratorRenderProps,
69
+ BlockListItemRenderProps,
70
+ RenderBlockFunction,
71
+ RenderChildFunction,
72
+ RenderEditableFunction,
73
+ RenderAnnotationFunction,
74
+ RenderPlaceholderFunction,
75
+ RenderStyleFunction,
76
+ BlockStyleRenderProps,
77
+ RenderListItemFunction,
78
+ RenderDecoratorFunction,
79
+ ScrollSelectionIntoViewFunction,
80
+ RangeDecorationOnMovedDetails,
81
+ RangeDecoration,
82
+ PortableTextMemberSchemaTypes,
83
+ } from './types/editor'
48
84
  export type {HotkeyOptions} from './types/options'
@@ -1,5 +1,5 @@
1
+ import type {EditorSnapshot} from '..'
1
2
  import {compileSchemaDefinition, defineSchema} from '../editor/define-schema'
2
- import type {EditorSnapshot} from '../selectors'
3
3
  import {createTestKeyGenerator} from './test-key-generator'
4
4
 
5
5
  export function createTestSnapshot(snapshot: {
@@ -10,8 +10,8 @@ import {
10
10
  import {createDecoratorPairBehavior} from '../behaviors/behavior.decorator-pair'
11
11
  import {defineBehavior} from '../behaviors/behavior.types'
12
12
  import type {Editor} from '../editor/create-editor'
13
+ import type {EditorSchema} from '../editor/define-schema'
13
14
  import {useEditor} from '../editor/editor-provider'
14
- import type {EditorSchema} from '../selectors'
15
15
  import type {BlockOffset} from '../types/block-offset'
16
16
  import * as utils from '../utils'
17
17
 
@@ -67,6 +67,7 @@ export type MarkdownPluginConfig = MarkdownBehaviorsConfig & {
67
67
  * </EditorProvider>
68
68
  * )
69
69
  * }
70
+ * ```
70
71
  */
71
72
  export function MarkdownPlugin(props: {config: MarkdownPluginConfig}) {
72
73
  const editor = useEditor()
@@ -1,11 +1,3 @@
1
- export type {EditorSchema} from '../editor/define-schema'
2
- export type {EditorSelector} from '../editor/editor-selector'
3
- export type {EditorContext, EditorSnapshot} from '../editor/editor-snapshot'
4
- export type {
5
- EditorSelection,
6
- EditorSelectionPoint,
7
- PortableTextMemberSchemaTypes,
8
- } from '../types/editor'
9
1
  export {getActiveAnnotations} from './selector.get-active-annotations'
10
2
  export {getActiveListItem} from './selector.get-active-list-item'
11
3
  export {getActiveStyle} from './selector.get-active-style'
@@ -1,7 +1,7 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
2
  import {expect, test} from 'vitest'
3
+ import type {EditorSelection} from '..'
3
4
  import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
4
- import type {EditorSelection} from '../utils'
5
5
  import {getActiveAnnotations} from './selector.get-active-annotations'
6
6
 
7
7
  function snapshot(value: Array<PortableTextBlock>, selection: EditorSelection) {
@@ -1,8 +1,8 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
2
  import {describe, expect, test} from 'vitest'
3
+ import type {EditorSelection} from '..'
3
4
  import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
4
5
  import {createTestKeyGenerator} from '../internal-utils/test-key-generator'
5
- import type {EditorSelection} from '../utils'
6
6
  import {getCaretWordSelection} from './selector.get-caret-word-selection'
7
7
 
8
8
  const keyGenerator = createTestKeyGenerator()
@@ -1,7 +1,8 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
2
  import {describe, expect, test} from 'vitest'
3
- import {getSelectedSpans, type EditorSelection} from '.'
3
+ import type {EditorSelection} from '..'
4
4
  import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
5
+ import {getSelectedSpans} from './selector.get-selected-spans'
5
6
 
6
7
  const fooBar = {
7
8
  _type: 'block',
@@ -1,5 +1,5 @@
1
+ import type {EditorSelectionPoint} from '..'
1
2
  import type {EditorSelector} from '../editor/editor-selector'
2
- import type {EditorSelectionPoint} from '../utils'
3
3
 
4
4
  /**
5
5
  * @public
@@ -1,5 +1,5 @@
1
+ import type {EditorSelectionPoint} from '..'
1
2
  import type {EditorSelector} from '../editor/editor-selector'
2
- import type {EditorSelectionPoint} from '../utils'
3
3
 
4
4
  /**
5
5
  * @public
@@ -1,6 +1,6 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
2
  import {expect, test} from 'vitest'
3
- import type {EditorSelection} from '.'
3
+ import type {EditorSelection} from '..'
4
4
  import {compileSchemaDefinition, defineSchema} from '../editor/define-schema'
5
5
  import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
6
6
  import {getSelectionText} from './selector.get-selection-text'
@@ -1,4 +1,5 @@
1
- import type {EditorSelection, EditorSelector} from './_exports'
1
+ import type {EditorSelection} from '..'
2
+ import type {EditorSelector} from '../editor/editor-selector'
2
3
 
3
4
  /**
4
5
  * @public
@@ -1,5 +1,5 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
- import type {EditorSelector} from './_exports'
2
+ import type {EditorSelector} from '../editor/editor-selector'
3
3
 
4
4
  /**
5
5
  * @public
@@ -1,5 +1,5 @@
1
1
  import {expect, test} from 'vitest'
2
- import type {EditorSelection} from '.'
2
+ import type {EditorSelection} from '..'
3
3
  import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
4
4
  import {isActiveDecorator} from './selector.is-active-decorator'
5
5
 
@@ -24,11 +24,7 @@ import type {
24
24
  RefObject,
25
25
  } from 'react'
26
26
  import type {Observable, Subject} from 'rxjs'
27
- import type {
28
- Descendant,
29
- Node as SlateNode,
30
- Operation as SlateOperation,
31
- } from 'slate'
27
+ import type {Descendant, Operation as SlateOperation} from 'slate'
32
28
  import type {DOMNode} from 'slate-dom'
33
29
  import type {ReactEditor} from 'slate-react'
34
30
  import type {PortableTextEditableProps} from '../editor/Editable'
@@ -97,18 +93,12 @@ export interface EditableAPI {
97
93
  undo: () => void
98
94
  }
99
95
 
100
- /** @internal */
101
- export type EditorNode = SlateNode & {
102
- _key: string
103
- _type: string
104
- }
105
- /** @internal */
106
- export type HistoryItem = {
96
+ type HistoryItem = {
107
97
  operations: SlateOperation[]
108
98
  timestamp: Date
109
99
  }
110
- /** @internal */
111
- export interface History {
100
+
101
+ interface History {
112
102
  redos: HistoryItem[]
113
103
  undos: HistoryItem[]
114
104
  }
@@ -121,7 +111,7 @@ export type EditorSelection = {
121
111
  focus: EditorSelectionPoint
122
112
  backward?: boolean
123
113
  } | null
124
- /** @internal */
114
+
125
115
  export interface PortableTextSlateEditor extends ReactEditor {
126
116
  _key: 'editor'
127
117
  _type: 'editor'
@@ -528,7 +518,7 @@ export interface RangeDecoration {
528
518
  payload?: Record<string, unknown>
529
519
  }
530
520
 
531
- /** @internal */
521
+ /** @beta */
532
522
  export type PortableTextMemberSchemaTypes = {
533
523
  annotations: (ObjectSchemaType & {i18nTitleKey?: string})[]
534
524
  block: ObjectSchemaType
@@ -1,7 +1,7 @@
1
1
  import type {PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
2
2
  import type {BaseEditor, Descendant} from 'slate'
3
3
  import type {ReactEditor} from 'slate-react'
4
- import type {PortableTextSlateEditor} from '..'
4
+ import type {PortableTextSlateEditor} from './editor'
5
5
 
6
6
  export interface VoidElement {
7
7
  _type: string
@@ -1,4 +1,3 @@
1
- export type {EditorSelection, EditorSelectionPoint} from '../types/editor'
2
1
  export {
3
2
  blockOffsetToSpanSelectionPoint,
4
3
  spanSelectionPointToBlockOffset,
@@ -1,5 +1,5 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
- import type {EditorSelection} from '../selectors'
2
+ import type {EditorSelection} from '..'
3
3
  import type {BlockOffset} from '../types/block-offset'
4
4
  import {blockOffsetToSpanSelectionPoint} from './util.block-offset'
5
5
 
@@ -1,5 +1,5 @@
1
1
  import type {PortableTextChild, PortableTextSpan} from '@sanity/types'
2
- import type {EditorContext} from '../selectors'
2
+ import type {EditorContext} from '..'
3
3
 
4
4
  /**
5
5
  * @public
@@ -1,5 +1,5 @@
1
1
  import type {PortableTextBlock, PortableTextTextBlock} from '@sanity/types'
2
- import type {EditorContext} from '../selectors'
2
+ import type {EditorContext} from '..'
3
3
 
4
4
  /**
5
5
  * @public
@@ -1,6 +1,6 @@
1
1
  import type {PortableTextTextBlock} from '@sanity/types'
2
+ import type {EditorContext} from '..'
2
3
  import {parseBlock} from '../internal-utils/parse-blocks'
3
- import type {EditorContext} from '../selectors'
4
4
  import {isTextBlock} from './util.is-text-block'
5
5
 
6
6
  /**
@@ -4,7 +4,7 @@ import {
4
4
  isPortableTextTextBlock,
5
5
  type PortableTextBlock,
6
6
  } from '@sanity/types'
7
- import type {EditorSelection} from '../selectors'
7
+ import type {EditorSelection} from '..'
8
8
 
9
9
  /**
10
10
  * @public
@@ -1,7 +1,9 @@
1
1
  import type {PortableTextTextBlock} from '@sanity/types'
2
- import {isTextBlock, sliceBlocks, type EditorSelectionPoint} from '.'
3
- import type {EditorContext} from '../selectors'
2
+ import type {EditorSelectionPoint} from '..'
3
+ import type {EditorContext} from '../editor/editor-snapshot'
4
4
  import {isSpan} from './util.is-span'
5
+ import {isTextBlock} from './util.is-text-block'
6
+ import {sliceBlocks} from './util.slice-blocks'
5
7
 
6
8
  /**
7
9
  * @beta