@portabletext/editor 3.3.0 → 3.3.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 (46) hide show
  1. package/lib/_chunks-dts/index.d.ts +1705 -69
  2. package/lib/_chunks-es/use-editor.js +8 -4
  3. package/lib/_chunks-es/use-editor.js.map +1 -1
  4. package/lib/index.d.ts +1 -1
  5. package/lib/index.js +9047 -511
  6. package/lib/index.js.map +1 -1
  7. package/lib/plugins/index.d.ts +1 -1
  8. package/package.json +4 -4
  9. package/src/behaviors/behavior.perform-event.ts +1 -1
  10. package/src/editor/PortableTextEditor.tsx +3 -1
  11. package/src/editor/create-editor.ts +2 -1
  12. package/src/editor/create-slate-editor.tsx +1 -1
  13. package/src/editor/editor-dom.ts +1 -1
  14. package/src/editor/editor-machine.ts +1 -1
  15. package/src/editor/editor-selector.ts +1 -1
  16. package/src/editor/editor-snapshot.ts +2 -1
  17. package/src/editor/mutation-machine.ts +1 -1
  18. package/src/editor/plugins/createWithEditableAPI.ts +3 -4
  19. package/src/editor/plugins/createWithHotKeys.ts +1 -1
  20. package/src/editor/plugins/createWithObjectKeys.ts +1 -1
  21. package/src/editor/plugins/createWithPatches.ts +5 -3
  22. package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -1
  23. package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
  24. package/src/editor/plugins/slate-plugin.update-selection.ts +1 -1
  25. package/src/editor/plugins/slate-plugin.update-value.ts +1 -1
  26. package/src/editor/plugins/with-plugins.ts +1 -1
  27. package/src/editor/range-decorations-machine.ts +2 -1
  28. package/src/editor/sync-machine.ts +10 -7
  29. package/src/editor/validate-selection-machine.ts +1 -1
  30. package/src/history/slate-plugin.history.ts +1 -1
  31. package/src/history/transform-operation.ts +1 -1
  32. package/src/internal-utils/apply-operation-to-portable-text.ts +10 -1
  33. package/src/internal-utils/applyPatch.ts +1 -1
  34. package/src/internal-utils/event-position.ts +45 -5
  35. package/src/internal-utils/global-scope.ts +12 -4
  36. package/src/internal-utils/sibling-utils.ts +1 -1
  37. package/src/internal-utils/slate-utils.test.tsx +1 -1
  38. package/src/internal-utils/slate-utils.ts +2 -1
  39. package/src/operations/behavior.operation.delete.ts +1 -1
  40. package/src/operations/behavior.operation.insert.block.ts +2 -1
  41. package/src/operations/behavior.operations.ts +1 -1
  42. package/src/plugins/plugin.internal.slate-editor-ref.tsx +1 -1
  43. package/src/priority/priority.sort.ts +3 -1
  44. package/src/types/editor.ts +1 -51
  45. package/src/types/slate-editor.ts +50 -0
  46. package/src/types/slate.ts +1 -1
@@ -8,9 +8,7 @@ import type {
8
8
  Path,
9
9
  PortableTextBlock,
10
10
  PortableTextChild,
11
- PortableTextListBlock,
12
11
  PortableTextObject,
13
- PortableTextSpan,
14
12
  PortableTextTextBlock,
15
13
  TypedObject,
16
14
  } from '@sanity/types'
@@ -18,18 +16,13 @@ import type {
18
16
  ClipboardEvent,
19
17
  FocusEvent,
20
18
  JSX,
21
- KeyboardEvent,
22
19
  PropsWithChildren,
23
20
  ReactElement,
24
21
  RefObject,
25
22
  } from 'react'
26
23
  import type {Observable, Subject} from 'rxjs'
27
- import type {Descendant, Operation as SlateOperation} from 'slate'
28
- import type {DOMNode} from 'slate-dom'
29
- import type {ReactEditor} from 'slate-react'
30
24
  import type {PortableTextEditableProps} from '../editor/Editable'
31
25
  import type {PortableTextEditor} from '../editor/PortableTextEditor'
32
- import type {DecoratedRange} from '../editor/range-decorations-machine'
33
26
  import type {BlockPath} from './paths'
34
27
 
35
28
  /** @beta */
@@ -73,7 +66,7 @@ export interface EditableAPI {
73
66
  ) => [PortableTextBlock | PortableTextChild | undefined, Path | undefined]
74
67
  findDOMNode: (
75
68
  element: PortableTextBlock | PortableTextChild,
76
- ) => DOMNode | undefined
69
+ ) => Node | undefined
77
70
  focus: () => void
78
71
  focusBlock: () => PortableTextBlock | undefined
79
72
  focusChild: () => PortableTextChild | undefined
@@ -111,16 +104,6 @@ export interface EditableAPI {
111
104
  undo: () => void
112
105
  }
113
106
 
114
- type HistoryItem = {
115
- operations: SlateOperation[]
116
- timestamp: Date
117
- }
118
-
119
- interface History {
120
- redos: HistoryItem[]
121
- undos: HistoryItem[]
122
- }
123
-
124
107
  /** @public */
125
108
  export type EditorSelectionPoint = {path: Path; offset: number}
126
109
  /** @public */
@@ -130,39 +113,6 @@ export type EditorSelection = {
130
113
  backward?: boolean
131
114
  } | null
132
115
 
133
- export interface PortableTextSlateEditor extends ReactEditor {
134
- _key: 'editor'
135
- _type: 'editor'
136
- createPlaceholderBlock: () => Descendant
137
- editable: EditableAPI
138
- history: History
139
- insertPortableTextData: (data: DataTransfer) => boolean
140
- insertTextOrHTMLData: (data: DataTransfer) => boolean
141
- isTextBlock: (value: unknown) => value is PortableTextTextBlock
142
- isTextSpan: (value: unknown) => value is PortableTextSpan
143
- isListBlock: (value: unknown) => value is PortableTextListBlock
144
- value: Array<PortableTextBlock>
145
- decoratedRanges: Array<DecoratedRange>
146
- decoratorState: Record<string, boolean | undefined>
147
- blockIndexMap: Map<string, number>
148
- listIndexMap: Map<string, number>
149
-
150
- /**
151
- * Use hotkeys
152
- */
153
- pteWithHotKeys: (event: KeyboardEvent<HTMLDivElement>) => void
154
-
155
- /**
156
- * Undo
157
- */
158
- undo: () => void
159
-
160
- /**
161
- * Redo
162
- */
163
- redo: () => void
164
- }
165
-
166
116
  /**
167
117
  * The editor has mutated it's content.
168
118
  * @beta */
@@ -0,0 +1,50 @@
1
+ import type {
2
+ PortableTextBlock,
3
+ PortableTextListBlock,
4
+ PortableTextSpan,
5
+ PortableTextTextBlock,
6
+ } from '@sanity/types'
7
+ import type {KeyboardEvent} from 'react'
8
+ import type {Descendant, Operation as SlateOperation} from 'slate'
9
+ import type {ReactEditor} from 'slate-react'
10
+ import type {DecoratedRange} from '../editor/range-decorations-machine'
11
+
12
+ type HistoryItem = {
13
+ operations: SlateOperation[]
14
+ timestamp: Date
15
+ }
16
+
17
+ interface History {
18
+ redos: HistoryItem[]
19
+ undos: HistoryItem[]
20
+ }
21
+
22
+ export interface PortableTextSlateEditor extends ReactEditor {
23
+ _key: 'editor'
24
+ _type: 'editor'
25
+ createPlaceholderBlock: () => Descendant
26
+ history: History
27
+ isTextBlock: (value: unknown) => value is PortableTextTextBlock
28
+ isTextSpan: (value: unknown) => value is PortableTextSpan
29
+ isListBlock: (value: unknown) => value is PortableTextListBlock
30
+ value: Array<PortableTextBlock>
31
+ decoratedRanges: Array<DecoratedRange>
32
+ decoratorState: Record<string, boolean | undefined>
33
+ blockIndexMap: Map<string, number>
34
+ listIndexMap: Map<string, number>
35
+
36
+ /**
37
+ * Use hotkeys
38
+ */
39
+ pteWithHotKeys: (event: KeyboardEvent<HTMLDivElement>) => void
40
+
41
+ /**
42
+ * Undo
43
+ */
44
+ undo: () => void
45
+
46
+ /**
47
+ * Redo
48
+ */
49
+ redo: () => void
50
+ }
@@ -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 './editor'
4
+ import type {PortableTextSlateEditor} from './slate-editor'
5
5
 
6
6
  export interface VoidElement {
7
7
  _type: string