@tiptap/core 3.0.0-next.3 → 3.0.0-next.5
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.
- package/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +2627 -2651
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2423 -2688
- package/dist/index.d.ts +2423 -2688
- package/dist/index.js +2639 -2684
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime/jsx-runtime.cjs +56 -0
- package/dist/jsx-runtime/jsx-runtime.cjs.map +1 -0
- package/dist/jsx-runtime/jsx-runtime.d.cts +22 -0
- package/dist/jsx-runtime/jsx-runtime.d.ts +22 -0
- package/dist/jsx-runtime/jsx-runtime.js +26 -0
- package/dist/jsx-runtime/jsx-runtime.js.map +1 -0
- package/jsx-runtime/index.cjs +1 -0
- package/jsx-runtime/index.d.cts +1 -0
- package/jsx-runtime/index.d.ts +1 -0
- package/jsx-runtime/index.js +1 -0
- package/package.json +27 -6
- package/src/CommandManager.ts +2 -9
- package/src/Editor.ts +191 -94
- package/src/EventEmitter.ts +7 -10
- package/src/Extendable.ts +483 -0
- package/src/Extension.ts +5 -496
- package/src/ExtensionManager.ts +81 -135
- package/src/InputRule.ts +35 -48
- package/src/Mark.ts +135 -623
- package/src/MarkView.ts +66 -0
- package/src/Node.ts +325 -829
- package/src/NodePos.ts +1 -3
- package/src/NodeView.ts +10 -20
- package/src/PasteRule.ts +43 -55
- package/src/Tracker.ts +7 -9
- package/src/commands/blur.ts +14 -12
- package/src/commands/clearContent.ts +12 -5
- package/src/commands/clearNodes.ts +32 -30
- package/src/commands/command.ts +1 -1
- package/src/commands/createParagraphNear.ts +5 -3
- package/src/commands/cut.ts +12 -10
- package/src/commands/deleteCurrentNode.ts +23 -21
- package/src/commands/deleteNode.ts +18 -16
- package/src/commands/deleteRange.ts +10 -8
- package/src/commands/deleteSelection.ts +5 -3
- package/src/commands/enter.ts +6 -4
- package/src/commands/exitCode.ts +5 -3
- package/src/commands/extendMarkRange.ts +14 -12
- package/src/commands/first.ts +2 -4
- package/src/commands/focus.ts +51 -48
- package/src/commands/forEach.ts +2 -2
- package/src/commands/insertContent.ts +12 -14
- package/src/commands/insertContentAt.ts +105 -98
- package/src/commands/join.ts +20 -12
- package/src/commands/joinItemBackward.ts +16 -18
- package/src/commands/joinItemForward.ts +16 -18
- package/src/commands/joinTextblockBackward.ts +5 -3
- package/src/commands/joinTextblockForward.ts +5 -3
- package/src/commands/keyboardShortcut.ts +29 -34
- package/src/commands/lift.ts +10 -8
- package/src/commands/liftEmptyBlock.ts +6 -4
- package/src/commands/liftListItem.ts +6 -4
- package/src/commands/newlineInCode.ts +5 -3
- package/src/commands/resetAttributes.ts +36 -41
- package/src/commands/scrollIntoView.ts +9 -7
- package/src/commands/selectAll.ts +10 -8
- package/src/commands/selectNodeBackward.ts +5 -3
- package/src/commands/selectNodeForward.ts +5 -3
- package/src/commands/selectParentNode.ts +5 -3
- package/src/commands/selectTextblockEnd.ts +5 -3
- package/src/commands/selectTextblockStart.ts +5 -3
- package/src/commands/setContent.ts +37 -36
- package/src/commands/setMark.ts +55 -57
- package/src/commands/setMeta.ts +7 -5
- package/src/commands/setNode.ts +32 -30
- package/src/commands/setNodeSelection.ts +11 -9
- package/src/commands/setTextSelection.ts +15 -13
- package/src/commands/sinkListItem.ts +6 -4
- package/src/commands/splitBlock.ts +67 -76
- package/src/commands/splitListItem.ts +93 -106
- package/src/commands/toggleList.ts +73 -71
- package/src/commands/toggleMark.ts +11 -9
- package/src/commands/toggleNode.ts +18 -16
- package/src/commands/toggleWrap.ts +10 -8
- package/src/commands/undoInputRule.ts +31 -29
- package/src/commands/unsetAllMarks.ts +16 -14
- package/src/commands/unsetMark.ts +27 -25
- package/src/commands/updateAttributes.ts +92 -100
- package/src/commands/wrapIn.ts +6 -4
- package/src/commands/wrapInList.ts +6 -4
- package/src/extensions/clipboardTextSerializer.ts +2 -4
- package/src/extensions/delete.ts +89 -0
- package/src/extensions/focusEvents.ts +2 -6
- package/src/extensions/index.ts +1 -0
- package/src/extensions/keymap.ts +58 -50
- package/src/extensions/paste.ts +0 -1
- package/src/extensions/tabindex.ts +1 -1
- package/src/helpers/combineTransactionSteps.ts +1 -4
- package/src/helpers/createChainableState.ts +1 -4
- package/src/helpers/createDocument.ts +1 -3
- package/src/helpers/createNodeFromContent.ts +4 -10
- package/src/helpers/findChildrenInRange.ts +1 -5
- package/src/helpers/findParentNode.ts +3 -1
- package/src/helpers/flattenExtensions.ts +30 -0
- package/src/helpers/getAttributes.ts +1 -4
- package/src/helpers/getAttributesFromExtensions.ts +28 -37
- package/src/helpers/getChangedRanges.ts +13 -11
- package/src/helpers/getExtensionField.ts +11 -11
- package/src/helpers/getMarkAttributes.ts +1 -4
- package/src/helpers/getMarkRange.ts +5 -15
- package/src/helpers/getMarkType.ts +1 -3
- package/src/helpers/getNodeAttributes.ts +1 -4
- package/src/helpers/getNodeType.ts +1 -3
- package/src/helpers/getRenderedAttributes.ts +1 -3
- package/src/helpers/getSchema.ts +2 -2
- package/src/helpers/getSchemaByResolvedExtensions.ts +45 -77
- package/src/helpers/getSplittedAttributes.ts +4 -4
- package/src/helpers/getTextContentFromNodes.ts +8 -11
- package/src/helpers/index.ts +4 -0
- package/src/helpers/injectExtensionAttributesToParseRule.ts +1 -1
- package/src/helpers/isActive.ts +1 -5
- package/src/helpers/isExtensionRulesEnabled.ts +1 -3
- package/src/helpers/isNodeEmpty.ts +2 -2
- package/src/helpers/resolveExtensions.ts +25 -0
- package/src/helpers/resolveFocusPosition.ts +3 -14
- package/src/helpers/rewriteUnknownContent.ts +149 -0
- package/src/helpers/sortExtensions.ts +26 -0
- package/src/index.ts +3 -7
- package/src/inputRules/markInputRule.ts +1 -5
- package/src/inputRules/nodeInputRule.ts +2 -9
- package/src/inputRules/textInputRule.ts +1 -4
- package/src/inputRules/textblockTypeInputRule.ts +2 -8
- package/src/inputRules/wrappingInputRule.ts +13 -19
- package/src/jsx-runtime.ts +64 -0
- package/src/pasteRules/markPasteRule.ts +1 -3
- package/src/pasteRules/nodePasteRule.ts +2 -8
- package/src/pasteRules/textPasteRule.ts +1 -4
- package/src/types.ts +529 -174
- package/src/utilities/createStyleTag.ts +3 -1
- package/src/utilities/deleteProps.ts +7 -11
- package/src/utilities/elementFromString.ts +3 -0
- package/src/utilities/findDuplicates.ts +4 -1
- package/src/utilities/index.ts +1 -0
- package/src/utilities/isFunction.ts +1 -0
- package/src/utilities/isMacOS.ts +1 -3
- package/src/utilities/isiOS.ts +5 -10
- package/src/utilities/mergeAttributes.ts +17 -7
- package/src/utilities/removeDuplicates.ts +1 -3
package/src/types.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Mark as ProseMirrorMark,
|
|
3
|
-
Node as ProseMirrorNode,
|
|
4
|
-
ParseOptions,
|
|
5
|
-
Slice,
|
|
6
|
-
} from '@tiptap/pm/model'
|
|
1
|
+
import { Mark as ProseMirrorMark, Node as ProseMirrorNode, ParseOptions, Slice } from '@tiptap/pm/model'
|
|
7
2
|
import { EditorState, Transaction } from '@tiptap/pm/state'
|
|
8
|
-
import { Mappable } from '@tiptap/pm/transform'
|
|
3
|
+
import { Mappable, Transform } from '@tiptap/pm/transform'
|
|
9
4
|
import {
|
|
10
5
|
Decoration,
|
|
11
6
|
DecorationAttrs,
|
|
12
7
|
EditorProps,
|
|
13
8
|
EditorView,
|
|
9
|
+
MarkView,
|
|
10
|
+
MarkViewConstructor,
|
|
14
11
|
NodeView,
|
|
15
12
|
NodeViewConstructor,
|
|
16
13
|
ViewMutationRecord,
|
|
@@ -18,76 +15,305 @@ import {
|
|
|
18
15
|
|
|
19
16
|
import { Editor } from './Editor.js'
|
|
20
17
|
import { Extension } from './Extension.js'
|
|
21
|
-
import {
|
|
22
|
-
Commands, ExtensionConfig, MarkConfig, NodeConfig,
|
|
23
|
-
} from './index.js'
|
|
18
|
+
import { Commands, ExtensionConfig, MarkConfig, NodeConfig } from './index.js'
|
|
24
19
|
import { Mark } from './Mark.js'
|
|
25
20
|
import { Node } from './Node.js'
|
|
26
21
|
|
|
27
|
-
export type AnyConfig = ExtensionConfig | NodeConfig | MarkConfig
|
|
28
|
-
export type AnyExtension = Extension | Node | Mark
|
|
29
|
-
export type Extensions = AnyExtension[]
|
|
22
|
+
export type AnyConfig = ExtensionConfig | NodeConfig | MarkConfig
|
|
23
|
+
export type AnyExtension = Extension | Node | Mark
|
|
24
|
+
export type Extensions = AnyExtension[]
|
|
30
25
|
|
|
31
26
|
export type ParentConfig<T> = Partial<{
|
|
32
27
|
[P in keyof T]: Required<T>[P] extends (...args: any) => any
|
|
33
28
|
? (...args: Parameters<Required<T>[P]>) => ReturnType<Required<T>[P]>
|
|
34
|
-
: T[P]
|
|
35
|
-
}
|
|
29
|
+
: T[P]
|
|
30
|
+
}>
|
|
36
31
|
|
|
37
|
-
export type Primitive = null | undefined | string | number | boolean | symbol | bigint
|
|
32
|
+
export type Primitive = null | undefined | string | number | boolean | symbol | bigint
|
|
38
33
|
|
|
39
|
-
export type RemoveThis<T> = T extends (...args: any) => any
|
|
40
|
-
? (...args: Parameters<T>) => ReturnType<T>
|
|
41
|
-
: T;
|
|
34
|
+
export type RemoveThis<T> = T extends (...args: any) => any ? (...args: Parameters<T>) => ReturnType<T> : T
|
|
42
35
|
|
|
43
|
-
export type MaybeReturnType<T> = T extends (...args: any) => any ? ReturnType<T> : T
|
|
36
|
+
export type MaybeReturnType<T> = T extends (...args: any) => any ? ReturnType<T> : T
|
|
44
37
|
|
|
45
|
-
export type MaybeThisParameterType<T> =
|
|
46
|
-
? ThisParameterType<Exclude<T, Primitive>>
|
|
47
|
-
: any;
|
|
38
|
+
export type MaybeThisParameterType<T> =
|
|
39
|
+
Exclude<T, Primitive> extends (...args: any) => any ? ThisParameterType<Exclude<T, Primitive>> : any
|
|
48
40
|
|
|
49
41
|
export interface EditorEvents {
|
|
50
|
-
beforeCreate: {
|
|
51
|
-
|
|
42
|
+
beforeCreate: {
|
|
43
|
+
/**
|
|
44
|
+
* The editor instance
|
|
45
|
+
*/
|
|
46
|
+
editor: Editor
|
|
47
|
+
}
|
|
48
|
+
create: {
|
|
49
|
+
/**
|
|
50
|
+
* The editor instance
|
|
51
|
+
*/
|
|
52
|
+
editor: Editor
|
|
53
|
+
}
|
|
52
54
|
contentError: {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
/**
|
|
56
|
+
* The editor instance
|
|
57
|
+
*/
|
|
58
|
+
editor: Editor
|
|
59
|
+
/**
|
|
60
|
+
* The error that occurred while parsing the content
|
|
61
|
+
*/
|
|
62
|
+
error: Error
|
|
55
63
|
/**
|
|
56
64
|
* If called, will re-initialize the editor with the collaboration extension removed.
|
|
57
65
|
* This will prevent syncing back deletions of content not present in the current schema.
|
|
58
66
|
*/
|
|
59
|
-
disableCollaboration: () => void
|
|
60
|
-
}
|
|
61
|
-
update: {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
disableCollaboration: () => void
|
|
68
|
+
}
|
|
69
|
+
update: {
|
|
70
|
+
/**
|
|
71
|
+
* The editor instance
|
|
72
|
+
*/
|
|
73
|
+
editor: Editor
|
|
74
|
+
/**
|
|
75
|
+
* The transaction that caused the update
|
|
76
|
+
*/
|
|
77
|
+
transaction: Transaction
|
|
78
|
+
/**
|
|
79
|
+
* Appended transactions that were added to the initial transaction by plugins
|
|
80
|
+
*/
|
|
81
|
+
appendedTransactions: Transaction[]
|
|
82
|
+
}
|
|
83
|
+
selectionUpdate: {
|
|
84
|
+
/**
|
|
85
|
+
* The editor instance
|
|
86
|
+
*/
|
|
87
|
+
editor: Editor
|
|
88
|
+
/**
|
|
89
|
+
* The transaction that caused the selection update
|
|
90
|
+
*/
|
|
91
|
+
transaction: Transaction
|
|
92
|
+
}
|
|
93
|
+
beforeTransaction: {
|
|
94
|
+
/**
|
|
95
|
+
* The editor instance
|
|
96
|
+
*/
|
|
97
|
+
editor: Editor
|
|
98
|
+
/**
|
|
99
|
+
* The transaction that will be applied
|
|
100
|
+
*/
|
|
101
|
+
transaction: Transaction
|
|
102
|
+
/**
|
|
103
|
+
* The next state of the editor after the transaction is applied
|
|
104
|
+
*/
|
|
105
|
+
nextState: EditorState
|
|
106
|
+
}
|
|
107
|
+
transaction: {
|
|
108
|
+
/**
|
|
109
|
+
* The editor instance
|
|
110
|
+
*/
|
|
111
|
+
editor: Editor
|
|
112
|
+
/**
|
|
113
|
+
* The initial transaction
|
|
114
|
+
*/
|
|
115
|
+
transaction: Transaction
|
|
116
|
+
/**
|
|
117
|
+
* Appended transactions that were added to the initial transaction by plugins
|
|
118
|
+
*/
|
|
119
|
+
appendedTransactions: Transaction[]
|
|
120
|
+
}
|
|
121
|
+
focus: {
|
|
122
|
+
/**
|
|
123
|
+
* The editor instance
|
|
124
|
+
*/
|
|
125
|
+
editor: Editor
|
|
126
|
+
/**
|
|
127
|
+
* The focus event
|
|
128
|
+
*/
|
|
129
|
+
event: FocusEvent
|
|
130
|
+
/**
|
|
131
|
+
* The transaction that caused the focus
|
|
132
|
+
*/
|
|
133
|
+
transaction: Transaction
|
|
134
|
+
}
|
|
135
|
+
blur: {
|
|
136
|
+
/**
|
|
137
|
+
* The editor instance
|
|
138
|
+
*/
|
|
139
|
+
editor: Editor
|
|
140
|
+
/**
|
|
141
|
+
* The focus event
|
|
142
|
+
*/
|
|
143
|
+
event: FocusEvent
|
|
144
|
+
/**
|
|
145
|
+
* The transaction that caused the blur
|
|
146
|
+
*/
|
|
147
|
+
transaction: Transaction
|
|
148
|
+
}
|
|
149
|
+
destroy: void
|
|
150
|
+
paste: {
|
|
151
|
+
/**
|
|
152
|
+
* The editor instance
|
|
153
|
+
*/
|
|
154
|
+
editor: Editor
|
|
155
|
+
/**
|
|
156
|
+
* The clipboard event
|
|
157
|
+
*/
|
|
158
|
+
event: ClipboardEvent
|
|
159
|
+
/**
|
|
160
|
+
* The slice that was pasted
|
|
161
|
+
*/
|
|
162
|
+
slice: Slice
|
|
163
|
+
}
|
|
164
|
+
drop: {
|
|
165
|
+
/**
|
|
166
|
+
* The editor instance
|
|
167
|
+
*/
|
|
168
|
+
editor: Editor
|
|
169
|
+
/**
|
|
170
|
+
* The drag event
|
|
171
|
+
*/
|
|
172
|
+
event: DragEvent
|
|
173
|
+
/**
|
|
174
|
+
* The slice that was dropped
|
|
175
|
+
*/
|
|
176
|
+
slice: Slice
|
|
177
|
+
/**
|
|
178
|
+
* Whether the content was moved (true) or copied (false)
|
|
179
|
+
*/
|
|
180
|
+
moved: boolean
|
|
181
|
+
}
|
|
182
|
+
delete: {
|
|
183
|
+
/**
|
|
184
|
+
* The editor instance
|
|
185
|
+
*/
|
|
186
|
+
editor: Editor
|
|
187
|
+
/**
|
|
188
|
+
* The range of the deleted content (before the deletion)
|
|
189
|
+
*/
|
|
190
|
+
deletedRange: Range
|
|
191
|
+
/**
|
|
192
|
+
* The new range of positions of where the deleted content was in the new document (after the deletion)
|
|
193
|
+
*/
|
|
194
|
+
newRange: Range
|
|
195
|
+
/**
|
|
196
|
+
* The transaction that caused the deletion
|
|
197
|
+
*/
|
|
198
|
+
transaction: Transaction
|
|
199
|
+
/**
|
|
200
|
+
* The combined transform (including all appended transactions) that caused the deletion
|
|
201
|
+
*/
|
|
202
|
+
combinedTransform: Transform
|
|
203
|
+
/**
|
|
204
|
+
* Whether the deletion was partial (only a part of this content was deleted)
|
|
205
|
+
*/
|
|
206
|
+
partial: boolean
|
|
207
|
+
/**
|
|
208
|
+
* This is the start position of the mark in the document (before the deletion)
|
|
209
|
+
*/
|
|
210
|
+
from: number
|
|
211
|
+
/**
|
|
212
|
+
* This is the end position of the mark in the document (before the deletion)
|
|
213
|
+
*/
|
|
214
|
+
to: number
|
|
215
|
+
} & (
|
|
216
|
+
| {
|
|
217
|
+
/**
|
|
218
|
+
* The content that was deleted
|
|
219
|
+
*/
|
|
220
|
+
type: 'node'
|
|
221
|
+
/**
|
|
222
|
+
* The node which the deletion occurred in
|
|
223
|
+
* @note This can be a parent node of the deleted content
|
|
224
|
+
*/
|
|
225
|
+
node: ProseMirrorNode
|
|
226
|
+
/**
|
|
227
|
+
* The new start position of the node in the document (after the deletion)
|
|
228
|
+
*/
|
|
229
|
+
newFrom: number
|
|
230
|
+
/**
|
|
231
|
+
* The new end position of the node in the document (after the deletion)
|
|
232
|
+
*/
|
|
233
|
+
newTo: number
|
|
234
|
+
}
|
|
235
|
+
| {
|
|
236
|
+
/**
|
|
237
|
+
* The content that was deleted
|
|
238
|
+
*/
|
|
239
|
+
type: 'mark'
|
|
240
|
+
/**
|
|
241
|
+
* The mark that was deleted
|
|
242
|
+
*/
|
|
243
|
+
mark: ProseMirrorMark
|
|
244
|
+
}
|
|
245
|
+
)
|
|
70
246
|
}
|
|
71
247
|
|
|
72
|
-
export type EnableRules = (AnyExtension | string)[] | boolean
|
|
248
|
+
export type EnableRules = (AnyExtension | string)[] | boolean
|
|
73
249
|
|
|
74
250
|
export interface EditorOptions {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
251
|
+
/**
|
|
252
|
+
* The element or selector to bind the editor to
|
|
253
|
+
* If `null` is passed, the editor will not be mounted automatically
|
|
254
|
+
* If a function is passed, it will be called with the editor's root element
|
|
255
|
+
*/
|
|
256
|
+
element: Element | null
|
|
257
|
+
/**
|
|
258
|
+
* The content of the editor (HTML, JSON, or a JSON array)
|
|
259
|
+
*/
|
|
260
|
+
content: Content
|
|
261
|
+
/**
|
|
262
|
+
* The extensions to use
|
|
263
|
+
*/
|
|
264
|
+
extensions: Extensions
|
|
265
|
+
/**
|
|
266
|
+
* Whether to inject base CSS styles
|
|
267
|
+
*/
|
|
268
|
+
injectCSS: boolean
|
|
269
|
+
/**
|
|
270
|
+
* A nonce to use for CSP while injecting styles
|
|
271
|
+
*/
|
|
272
|
+
injectNonce: string | undefined
|
|
273
|
+
/**
|
|
274
|
+
* The editor's initial focus position
|
|
275
|
+
*/
|
|
276
|
+
autofocus: FocusPosition
|
|
277
|
+
/**
|
|
278
|
+
* Whether the editor is editable
|
|
279
|
+
*/
|
|
280
|
+
editable: boolean
|
|
281
|
+
/**
|
|
282
|
+
* The editor's props
|
|
283
|
+
*/
|
|
284
|
+
editorProps: EditorProps
|
|
285
|
+
/**
|
|
286
|
+
* The editor's content parser options
|
|
287
|
+
*/
|
|
288
|
+
parseOptions: ParseOptions
|
|
289
|
+
/**
|
|
290
|
+
* The editor's core extension options
|
|
291
|
+
*/
|
|
84
292
|
coreExtensionOptions?: {
|
|
85
293
|
clipboardTextSerializer?: {
|
|
86
|
-
blockSeparator?: string
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
294
|
+
blockSeparator?: string
|
|
295
|
+
}
|
|
296
|
+
delete?: {
|
|
297
|
+
/**
|
|
298
|
+
* Whether the `delete` extension should be called asynchronously to avoid blocking the editor while processing deletions
|
|
299
|
+
* @default true deletion events are called asynchronously
|
|
300
|
+
*/
|
|
301
|
+
async?: boolean
|
|
302
|
+
/**
|
|
303
|
+
* Allows filtering the transactions that are processed by the `delete` extension.
|
|
304
|
+
* If the function returns `true`, the transaction will be ignored.
|
|
305
|
+
*/
|
|
306
|
+
filterTransaction?: (transaction: Transaction) => boolean
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Whether to enable input rules behavior
|
|
311
|
+
*/
|
|
312
|
+
enableInputRules: EnableRules
|
|
313
|
+
/**
|
|
314
|
+
* Whether to enable paste rules behavior
|
|
315
|
+
*/
|
|
316
|
+
enablePasteRules: EnableRules
|
|
91
317
|
/**
|
|
92
318
|
* Determines whether core extensions are enabled.
|
|
93
319
|
*
|
|
@@ -116,115 +342,208 @@ export interface EditorOptions {
|
|
|
116
342
|
| 'keymap'
|
|
117
343
|
| 'tabindex'
|
|
118
344
|
| 'drop'
|
|
119
|
-
| 'paste'
|
|
345
|
+
| 'paste'
|
|
346
|
+
| 'delete',
|
|
120
347
|
false
|
|
121
348
|
>
|
|
122
|
-
|
|
349
|
+
>
|
|
123
350
|
/**
|
|
124
351
|
* If `true`, the editor will check the content for errors on initialization.
|
|
125
352
|
* Emitting the `contentError` event if the content is invalid.
|
|
126
353
|
* Which can be used to show a warning or error message to the user.
|
|
127
354
|
* @default false
|
|
128
355
|
*/
|
|
129
|
-
enableContentCheck: boolean
|
|
130
|
-
|
|
131
|
-
|
|
356
|
+
enableContentCheck: boolean
|
|
357
|
+
/**
|
|
358
|
+
* Called before the editor is constructed.
|
|
359
|
+
*/
|
|
360
|
+
onBeforeCreate: (props: EditorEvents['beforeCreate']) => void
|
|
361
|
+
/**
|
|
362
|
+
* Called after the editor is constructed.
|
|
363
|
+
*/
|
|
364
|
+
onCreate: (props: EditorEvents['create']) => void
|
|
132
365
|
/**
|
|
133
366
|
* Called when the editor encounters an error while parsing the content.
|
|
134
367
|
* Only enabled if `enableContentCheck` is `true`.
|
|
135
368
|
*/
|
|
136
|
-
onContentError: (props: EditorEvents['contentError']) => void
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
369
|
+
onContentError: (props: EditorEvents['contentError']) => void
|
|
370
|
+
/**
|
|
371
|
+
* Called when the editor's content is updated.
|
|
372
|
+
*/
|
|
373
|
+
onUpdate: (props: EditorEvents['update']) => void
|
|
374
|
+
/**
|
|
375
|
+
* Called when the editor's selection is updated.
|
|
376
|
+
*/
|
|
377
|
+
onSelectionUpdate: (props: EditorEvents['selectionUpdate']) => void
|
|
378
|
+
/**
|
|
379
|
+
* Called after a transaction is applied to the editor.
|
|
380
|
+
*/
|
|
381
|
+
onTransaction: (props: EditorEvents['transaction']) => void
|
|
382
|
+
/**
|
|
383
|
+
* Called on focus events.
|
|
384
|
+
*/
|
|
385
|
+
onFocus: (props: EditorEvents['focus']) => void
|
|
386
|
+
/**
|
|
387
|
+
* Called on blur events.
|
|
388
|
+
*/
|
|
389
|
+
onBlur: (props: EditorEvents['blur']) => void
|
|
390
|
+
/**
|
|
391
|
+
* Called when the editor is destroyed.
|
|
392
|
+
*/
|
|
393
|
+
onDestroy: (props: EditorEvents['destroy']) => void
|
|
394
|
+
/**
|
|
395
|
+
* Called when content is pasted into the editor.
|
|
396
|
+
*/
|
|
397
|
+
onPaste: (e: ClipboardEvent, slice: Slice) => void
|
|
398
|
+
/**
|
|
399
|
+
* Called when content is dropped into the editor.
|
|
400
|
+
*/
|
|
401
|
+
onDrop: (e: DragEvent, slice: Slice, moved: boolean) => void
|
|
402
|
+
/**
|
|
403
|
+
* Called when content is deleted from the editor.
|
|
404
|
+
*/
|
|
405
|
+
onDelete: (props: EditorEvents['delete']) => void
|
|
145
406
|
}
|
|
146
407
|
|
|
147
|
-
|
|
408
|
+
/**
|
|
409
|
+
* The editor's content as HTML
|
|
410
|
+
*/
|
|
411
|
+
export type HTMLContent = string
|
|
148
412
|
|
|
413
|
+
/**
|
|
414
|
+
* Loosely describes a JSON representation of a Prosemirror document or node
|
|
415
|
+
*/
|
|
149
416
|
export type JSONContent = {
|
|
150
|
-
type?: string
|
|
151
|
-
attrs?: Record<string, any
|
|
152
|
-
content?: JSONContent[]
|
|
417
|
+
type?: string
|
|
418
|
+
attrs?: Record<string, any>
|
|
419
|
+
content?: JSONContent[]
|
|
153
420
|
marks?: {
|
|
154
|
-
type: string
|
|
155
|
-
attrs?: Record<string, any
|
|
156
|
-
[key: string]: any
|
|
157
|
-
}[]
|
|
158
|
-
text?: string
|
|
159
|
-
[key: string]: any
|
|
160
|
-
}
|
|
421
|
+
type: string
|
|
422
|
+
attrs?: Record<string, any>
|
|
423
|
+
[key: string]: any
|
|
424
|
+
}[]
|
|
425
|
+
text?: string
|
|
426
|
+
[key: string]: any
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* A mark type is either a JSON representation of a mark or a Prosemirror mark instance
|
|
431
|
+
*/
|
|
432
|
+
export type MarkType<
|
|
433
|
+
Type extends string | { name: string } = any,
|
|
434
|
+
TAttributes extends undefined | Record<string, any> = any,
|
|
435
|
+
> = {
|
|
436
|
+
type: Type
|
|
437
|
+
attrs: TAttributes
|
|
438
|
+
}
|
|
161
439
|
|
|
162
|
-
|
|
440
|
+
/**
|
|
441
|
+
* A node type is either a JSON representation of a node or a Prosemirror node instance
|
|
442
|
+
*/
|
|
443
|
+
export type NodeType<
|
|
444
|
+
Type extends string | { name: string } = any,
|
|
445
|
+
TAttributes extends undefined | Record<string, any> = any,
|
|
446
|
+
NodeMarkType extends MarkType = any,
|
|
447
|
+
TContent extends (NodeType | TextType)[] = any,
|
|
448
|
+
> = {
|
|
449
|
+
type: Type
|
|
450
|
+
attrs: TAttributes
|
|
451
|
+
content?: TContent
|
|
452
|
+
marks?: NodeMarkType[]
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* A node type is either a JSON representation of a doc node or a Prosemirror doc node instance
|
|
457
|
+
*/
|
|
458
|
+
export type DocumentType<
|
|
459
|
+
TDocAttributes extends Record<string, any> | undefined = Record<string, any>,
|
|
460
|
+
TContentType extends NodeType[] = NodeType[],
|
|
461
|
+
> = Omit<NodeType<'doc', TDocAttributes, never, TContentType>, 'marks' | 'content'> & { content: TContentType }
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* A node type is either a JSON representation of a text node or a Prosemirror text node instance
|
|
465
|
+
*/
|
|
466
|
+
export type TextType<TMarkType extends MarkType = MarkType> = {
|
|
467
|
+
type: 'text'
|
|
468
|
+
text: string
|
|
469
|
+
marks: TMarkType[]
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Describes the output of a `renderHTML` function in prosemirror
|
|
474
|
+
* @see https://prosemirror.net/docs/ref/#model.DOMOutputSpec
|
|
475
|
+
*/
|
|
476
|
+
export type DOMOutputSpecArray =
|
|
477
|
+
| [string]
|
|
478
|
+
| [string, Record<string, any>]
|
|
479
|
+
| [string, 0]
|
|
480
|
+
| [string, Record<string, any>, 0]
|
|
481
|
+
| [string, Record<string, any>, DOMOutputSpecArray | 0]
|
|
482
|
+
| [string, DOMOutputSpecArray]
|
|
483
|
+
|
|
484
|
+
export type Content = HTMLContent | JSONContent | JSONContent[] | null
|
|
163
485
|
|
|
164
486
|
export type CommandProps = {
|
|
165
|
-
editor: Editor
|
|
166
|
-
tr: Transaction
|
|
167
|
-
commands: SingleCommands
|
|
168
|
-
can: () => CanCommands
|
|
169
|
-
chain: () => ChainedCommands
|
|
170
|
-
state: EditorState
|
|
171
|
-
view: EditorView
|
|
172
|
-
dispatch: ((args?: any) => any) | undefined
|
|
173
|
-
}
|
|
487
|
+
editor: Editor
|
|
488
|
+
tr: Transaction
|
|
489
|
+
commands: SingleCommands
|
|
490
|
+
can: () => CanCommands
|
|
491
|
+
chain: () => ChainedCommands
|
|
492
|
+
state: EditorState
|
|
493
|
+
view: EditorView
|
|
494
|
+
dispatch: ((args?: any) => any) | undefined
|
|
495
|
+
}
|
|
174
496
|
|
|
175
|
-
export type Command = (props: CommandProps) => boolean
|
|
497
|
+
export type Command = (props: CommandProps) => boolean
|
|
176
498
|
|
|
177
|
-
export type CommandSpec = (...args: any[]) => Command
|
|
499
|
+
export type CommandSpec = (...args: any[]) => Command
|
|
178
500
|
|
|
179
|
-
export type KeyboardShortcutCommand = (props: { editor: Editor }) => boolean
|
|
501
|
+
export type KeyboardShortcutCommand = (props: { editor: Editor }) => boolean
|
|
180
502
|
|
|
181
503
|
export type Attribute = {
|
|
182
|
-
default?: any
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
504
|
+
default?: any
|
|
505
|
+
validate?: string | ((value: any) => void)
|
|
506
|
+
rendered?: boolean
|
|
507
|
+
renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null
|
|
508
|
+
parseHTML?: ((element: HTMLElement) => any | null) | null
|
|
509
|
+
keepOnSplit?: boolean
|
|
510
|
+
isRequired?: boolean
|
|
511
|
+
}
|
|
189
512
|
|
|
190
513
|
export type Attributes = {
|
|
191
|
-
[key: string]: Attribute
|
|
192
|
-
}
|
|
514
|
+
[key: string]: Attribute
|
|
515
|
+
}
|
|
193
516
|
|
|
194
517
|
export type ExtensionAttribute = {
|
|
195
|
-
type: string
|
|
196
|
-
name: string
|
|
197
|
-
attribute: Required<Attribute
|
|
198
|
-
}
|
|
518
|
+
type: string
|
|
519
|
+
name: string
|
|
520
|
+
attribute: Required<Omit<Attribute, 'validate'>> & Pick<Attribute, 'validate'>
|
|
521
|
+
}
|
|
199
522
|
|
|
200
523
|
export type GlobalAttributes = {
|
|
201
524
|
/**
|
|
202
525
|
* The node & mark types this attribute should be applied to.
|
|
203
526
|
*/
|
|
204
|
-
types: string[]
|
|
527
|
+
types: string[]
|
|
205
528
|
/**
|
|
206
529
|
* The attributes to add to the node or mark types.
|
|
207
530
|
*/
|
|
208
|
-
attributes: Record<string, Attribute | undefined
|
|
209
|
-
}[]
|
|
531
|
+
attributes: Record<string, Attribute | undefined>
|
|
532
|
+
}[]
|
|
210
533
|
|
|
211
|
-
export type PickValue<T, K extends keyof T> = T[K]
|
|
534
|
+
export type PickValue<T, K extends keyof T> = T[K]
|
|
212
535
|
|
|
213
|
-
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
214
|
-
k: infer I
|
|
215
|
-
) => void
|
|
216
|
-
? I
|
|
217
|
-
: never;
|
|
536
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
|
|
218
537
|
|
|
219
538
|
export type Diff<T extends keyof any, U extends keyof any> = ({ [P in T]: P } & {
|
|
220
|
-
[P in U]: never
|
|
221
|
-
} & { [x: string]: never })[T]
|
|
539
|
+
[P in U]: never
|
|
540
|
+
} & { [x: string]: never })[T]
|
|
222
541
|
|
|
223
|
-
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U
|
|
542
|
+
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U
|
|
224
543
|
|
|
225
|
-
export type ValuesOf<T> = T[keyof T]
|
|
544
|
+
export type ValuesOf<T> = T[keyof T]
|
|
226
545
|
|
|
227
|
-
export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T]
|
|
546
|
+
export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T]
|
|
228
547
|
|
|
229
548
|
export type DOMNode = InstanceType<typeof window.Node>
|
|
230
549
|
|
|
@@ -246,23 +565,21 @@ export interface DecorationType {
|
|
|
246
565
|
* This adds the `type` property to the `Decoration` type.
|
|
247
566
|
*/
|
|
248
567
|
export type DecorationWithType = Decoration & {
|
|
249
|
-
type: DecorationType
|
|
250
|
-
}
|
|
568
|
+
type: DecorationType
|
|
569
|
+
}
|
|
251
570
|
|
|
252
571
|
export interface NodeViewProps extends NodeViewRendererProps {
|
|
253
572
|
// TODO this type is not technically correct, but it's the best we can do for now since prosemirror doesn't expose the type of decorations
|
|
254
|
-
decorations: readonly DecorationWithType[]
|
|
255
|
-
selected: boolean
|
|
256
|
-
updateAttributes: (attributes: Record<string, any>) => void
|
|
257
|
-
deleteNode: () => void
|
|
573
|
+
decorations: readonly DecorationWithType[]
|
|
574
|
+
selected: boolean
|
|
575
|
+
updateAttributes: (attributes: Record<string, any>) => void
|
|
576
|
+
deleteNode: () => void
|
|
258
577
|
}
|
|
259
578
|
|
|
260
579
|
export interface NodeViewRendererOptions {
|
|
261
|
-
stopEvent: ((props: { event: Event }) => boolean) | null
|
|
262
|
-
ignoreMutation:
|
|
263
|
-
|
|
264
|
-
| null;
|
|
265
|
-
contentDOMElementTag: string;
|
|
580
|
+
stopEvent: ((props: { event: Event }) => boolean) | null
|
|
581
|
+
ignoreMutation: ((props: { mutation: ViewMutationRecord }) => boolean) | null
|
|
582
|
+
contentDOMElementTag: string
|
|
266
583
|
}
|
|
267
584
|
|
|
268
585
|
export interface NodeViewRendererProps {
|
|
@@ -270,100 +587,138 @@ export interface NodeViewRendererProps {
|
|
|
270
587
|
/**
|
|
271
588
|
* The node that is being rendered.
|
|
272
589
|
*/
|
|
273
|
-
node: Parameters<NodeViewConstructor>[0]
|
|
590
|
+
node: Parameters<NodeViewConstructor>[0]
|
|
274
591
|
/**
|
|
275
592
|
* The editor's view.
|
|
276
593
|
*/
|
|
277
|
-
view: Parameters<NodeViewConstructor>[1]
|
|
594
|
+
view: Parameters<NodeViewConstructor>[1]
|
|
278
595
|
/**
|
|
279
596
|
* A function that can be called to get the node's current position in the document.
|
|
280
597
|
*/
|
|
281
|
-
getPos: Parameters<NodeViewConstructor>[2]
|
|
598
|
+
getPos: Parameters<NodeViewConstructor>[2]
|
|
282
599
|
/**
|
|
283
600
|
* is an array of node or inline decorations that are active around the node.
|
|
284
601
|
* They are automatically drawn in the normal way, and you will usually just want to ignore this, but they can also be used as a way to provide context information to the node view without adding it to the document itself.
|
|
285
602
|
*/
|
|
286
|
-
decorations: Parameters<NodeViewConstructor>[3]
|
|
603
|
+
decorations: Parameters<NodeViewConstructor>[3]
|
|
287
604
|
/**
|
|
288
605
|
* holds the decorations for the node's content. You can safely ignore this if your view has no content or a contentDOM property, since the editor will draw the decorations on the content.
|
|
289
606
|
* But if you, for example, want to create a nested editor with the content, it may make sense to provide it with the inner decorations.
|
|
290
607
|
*/
|
|
291
|
-
innerDecorations: Parameters<NodeViewConstructor>[4]
|
|
608
|
+
innerDecorations: Parameters<NodeViewConstructor>[4]
|
|
292
609
|
// tiptap-specific
|
|
293
610
|
/**
|
|
294
611
|
* The editor instance.
|
|
295
612
|
*/
|
|
296
|
-
editor: Editor
|
|
613
|
+
editor: Editor
|
|
297
614
|
/**
|
|
298
615
|
* The extension that is responsible for the node.
|
|
299
616
|
*/
|
|
300
|
-
extension: Node
|
|
617
|
+
extension: Node
|
|
301
618
|
/**
|
|
302
619
|
* The HTML attributes that should be added to the node's DOM element.
|
|
303
620
|
*/
|
|
304
|
-
HTMLAttributes: Record<string, any
|
|
621
|
+
HTMLAttributes: Record<string, any>
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView
|
|
625
|
+
|
|
626
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
627
|
+
export interface MarkViewProps extends MarkViewRendererProps {}
|
|
628
|
+
|
|
629
|
+
export interface MarkViewRendererProps {
|
|
630
|
+
// pass-through from prosemirror
|
|
631
|
+
/**
|
|
632
|
+
* The node that is being rendered.
|
|
633
|
+
*/
|
|
634
|
+
mark: Parameters<MarkViewConstructor>[0]
|
|
635
|
+
/**
|
|
636
|
+
* The editor's view.
|
|
637
|
+
*/
|
|
638
|
+
view: Parameters<MarkViewConstructor>[1]
|
|
639
|
+
/**
|
|
640
|
+
* indicates whether the mark's content is inline
|
|
641
|
+
*/
|
|
642
|
+
inline: Parameters<MarkViewConstructor>[2]
|
|
643
|
+
// tiptap-specific
|
|
644
|
+
/**
|
|
645
|
+
* The editor instance.
|
|
646
|
+
*/
|
|
647
|
+
editor: Editor
|
|
648
|
+
/**
|
|
649
|
+
* The extension that is responsible for the mark.
|
|
650
|
+
*/
|
|
651
|
+
extension: Mark
|
|
652
|
+
/**
|
|
653
|
+
* The HTML attributes that should be added to the mark's DOM element.
|
|
654
|
+
*/
|
|
655
|
+
HTMLAttributes: Record<string, any>
|
|
305
656
|
}
|
|
306
657
|
|
|
307
|
-
export type
|
|
658
|
+
export type MarkViewRenderer = (props: MarkViewRendererProps) => MarkView
|
|
659
|
+
|
|
660
|
+
export interface MarkViewRendererOptions {
|
|
661
|
+
ignoreMutation: ((props: { mutation: ViewMutationRecord }) => boolean) | null
|
|
662
|
+
}
|
|
308
663
|
|
|
309
|
-
export type AnyCommands = Record<string, (...args: any[]) => Command
|
|
664
|
+
export type AnyCommands = Record<string, (...args: any[]) => Command>
|
|
310
665
|
|
|
311
666
|
export type UnionCommands<T = Command> = UnionToIntersection<
|
|
312
|
-
ValuesOf<Pick<Commands<T>, KeysWithTypeOf<Commands<T>,
|
|
313
|
-
|
|
667
|
+
ValuesOf<Pick<Commands<T>, KeysWithTypeOf<Commands<T>, object>>>
|
|
668
|
+
>
|
|
314
669
|
|
|
315
670
|
export type RawCommands = {
|
|
316
|
-
[Item in keyof UnionCommands]: UnionCommands<Command>[Item]
|
|
317
|
-
}
|
|
671
|
+
[Item in keyof UnionCommands]: UnionCommands<Command>[Item]
|
|
672
|
+
}
|
|
318
673
|
|
|
319
674
|
export type SingleCommands = {
|
|
320
|
-
[Item in keyof UnionCommands]: UnionCommands<boolean>[Item]
|
|
321
|
-
}
|
|
675
|
+
[Item in keyof UnionCommands]: UnionCommands<boolean>[Item]
|
|
676
|
+
}
|
|
322
677
|
|
|
323
678
|
export type ChainedCommands = {
|
|
324
|
-
[Item in keyof UnionCommands]: UnionCommands<ChainedCommands>[Item]
|
|
679
|
+
[Item in keyof UnionCommands]: UnionCommands<ChainedCommands>[Item]
|
|
325
680
|
} & {
|
|
326
|
-
run: () => boolean
|
|
327
|
-
}
|
|
681
|
+
run: () => boolean
|
|
682
|
+
}
|
|
328
683
|
|
|
329
|
-
export type CanCommands = SingleCommands & { chain: () => ChainedCommands }
|
|
684
|
+
export type CanCommands = SingleCommands & { chain: () => ChainedCommands }
|
|
330
685
|
|
|
331
|
-
export type FocusPosition = 'start' | 'end' | 'all' | number | boolean | null
|
|
686
|
+
export type FocusPosition = 'start' | 'end' | 'all' | number | boolean | null
|
|
332
687
|
|
|
333
688
|
export type Range = {
|
|
334
|
-
from: number
|
|
335
|
-
to: number
|
|
336
|
-
}
|
|
689
|
+
from: number
|
|
690
|
+
to: number
|
|
691
|
+
}
|
|
337
692
|
|
|
338
693
|
export type NodeRange = {
|
|
339
|
-
node: ProseMirrorNode
|
|
340
|
-
from: number
|
|
341
|
-
to: number
|
|
342
|
-
}
|
|
694
|
+
node: ProseMirrorNode
|
|
695
|
+
from: number
|
|
696
|
+
to: number
|
|
697
|
+
}
|
|
343
698
|
|
|
344
699
|
export type MarkRange = {
|
|
345
|
-
mark: ProseMirrorMark
|
|
346
|
-
from: number
|
|
347
|
-
to: number
|
|
348
|
-
}
|
|
700
|
+
mark: ProseMirrorMark
|
|
701
|
+
from: number
|
|
702
|
+
to: number
|
|
703
|
+
}
|
|
349
704
|
|
|
350
|
-
export type Predicate = (node: ProseMirrorNode) => boolean
|
|
705
|
+
export type Predicate = (node: ProseMirrorNode) => boolean
|
|
351
706
|
|
|
352
707
|
export type NodeWithPos = {
|
|
353
|
-
node: ProseMirrorNode
|
|
354
|
-
pos: number
|
|
355
|
-
}
|
|
708
|
+
node: ProseMirrorNode
|
|
709
|
+
pos: number
|
|
710
|
+
}
|
|
356
711
|
|
|
357
712
|
export type TextSerializer = (props: {
|
|
358
|
-
node: ProseMirrorNode
|
|
359
|
-
pos: number
|
|
360
|
-
parent: ProseMirrorNode
|
|
361
|
-
index: number
|
|
362
|
-
range: Range
|
|
363
|
-
}) => string
|
|
713
|
+
node: ProseMirrorNode
|
|
714
|
+
pos: number
|
|
715
|
+
parent: ProseMirrorNode
|
|
716
|
+
index: number
|
|
717
|
+
range: Range
|
|
718
|
+
}) => string
|
|
364
719
|
|
|
365
720
|
export type ExtendedRegExpMatchArray = RegExpMatchArray & {
|
|
366
|
-
data?: Record<string, any
|
|
367
|
-
}
|
|
721
|
+
data?: Record<string, any>
|
|
722
|
+
}
|
|
368
723
|
|
|
369
|
-
export type Dispatch = ((args?: any) => any) | undefined
|
|
724
|
+
export type Dispatch = ((args?: any) => any) | undefined
|