@tiptap/core 2.3.2 → 2.5.0-beta.0
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/dist/index.cjs +277 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +277 -67
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +277 -67
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/EventEmitter.d.ts +2 -2
- package/dist/packages/core/src/Extension.d.ts +129 -14
- package/dist/packages/core/src/ExtensionManager.d.ts +37 -0
- package/dist/packages/core/src/Mark.d.ts +129 -14
- package/dist/packages/core/src/Node.d.ts +226 -30
- package/dist/packages/core/src/NodeView.d.ts +4 -0
- package/dist/packages/core/src/PasteRule.d.ts +4 -0
- package/dist/packages/core/src/commands/blur.d.ts +1 -0
- package/dist/packages/core/src/commands/clearContent.d.ts +2 -0
- package/dist/packages/core/src/commands/clearNodes.d.ts +1 -0
- package/dist/packages/core/src/commands/command.d.ts +6 -0
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +1 -0
- package/dist/packages/core/src/commands/cut.d.ts +5 -0
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +1 -0
- package/dist/packages/core/src/commands/deleteNode.d.ts +3 -1
- package/dist/packages/core/src/commands/deleteRange.d.ts +2 -0
- package/dist/packages/core/src/commands/deleteSelection.d.ts +1 -0
- package/dist/packages/core/src/commands/enter.d.ts +1 -0
- package/dist/packages/core/src/commands/exitCode.d.ts +1 -0
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +14 -2
- package/dist/packages/core/src/commands/first.d.ts +2 -0
- package/dist/packages/core/src/commands/focus.d.ts +14 -1
- package/dist/packages/core/src/commands/insertContent.d.ts +17 -1
- package/dist/packages/core/src/commands/insertContentAt.d.ts +20 -1
- package/dist/packages/core/src/commands/join.d.ts +12 -4
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +2 -1
- package/dist/packages/core/src/commands/joinItemForward.d.ts +2 -1
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +2 -0
- package/dist/packages/core/src/commands/lift.d.ts +5 -1
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +2 -1
- package/dist/packages/core/src/commands/liftListItem.d.ts +3 -1
- package/dist/packages/core/src/commands/newlineInCode.d.ts +1 -0
- package/dist/packages/core/src/commands/resetAttributes.d.ts +3 -0
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +1 -0
- package/dist/packages/core/src/commands/selectAll.d.ts +1 -0
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +1 -0
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +1 -0
- package/dist/packages/core/src/commands/selectParentNode.d.ts +1 -0
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +1 -0
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +1 -0
- package/dist/packages/core/src/commands/setContent.d.ts +19 -1
- package/dist/packages/core/src/commands/setMark.d.ts +2 -0
- package/dist/packages/core/src/commands/setMeta.d.ts +3 -0
- package/dist/packages/core/src/commands/setNode.d.ts +3 -0
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +2 -0
- package/dist/packages/core/src/commands/setTextSelection.d.ts +2 -0
- package/dist/packages/core/src/commands/sinkListItem.d.ts +2 -0
- package/dist/packages/core/src/commands/splitBlock.d.ts +3 -0
- package/dist/packages/core/src/commands/splitListItem.d.ts +2 -0
- package/dist/packages/core/src/commands/toggleList.d.ts +5 -0
- package/dist/packages/core/src/commands/toggleMark.d.ts +13 -1
- package/dist/packages/core/src/commands/toggleNode.d.ts +4 -0
- package/dist/packages/core/src/commands/toggleWrap.d.ts +3 -0
- package/dist/packages/core/src/commands/undoInputRule.d.ts +1 -0
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +1 -0
- package/dist/packages/core/src/commands/unsetMark.d.ts +8 -1
- package/dist/packages/core/src/commands/updateAttributes.d.ts +12 -1
- package/dist/packages/core/src/commands/wrapIn.d.ts +3 -0
- package/dist/packages/core/src/commands/wrapInList.d.ts +3 -0
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +3 -0
- package/dist/packages/core/src/helpers/createChainableState.d.ts +5 -0
- package/dist/packages/core/src/helpers/createDocument.d.ts +7 -0
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +7 -0
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +5 -0
- package/dist/packages/core/src/helpers/findChildren.d.ts +6 -0
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +4 -0
- package/dist/packages/core/src/helpers/findParentNode.d.ts +8 -0
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +9 -0
- package/dist/packages/core/src/helpers/generateHTML.d.ts +6 -0
- package/dist/packages/core/src/helpers/generateJSON.d.ts +6 -0
- package/dist/packages/core/src/helpers/generateText.d.ts +7 -0
- package/dist/packages/core/src/helpers/getAttributes.d.ts +6 -0
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +7 -0
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +6 -0
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +6 -0
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +6 -0
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +7 -0
- package/dist/packages/core/src/helpers/getText.d.ts +9 -0
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +8 -0
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +6 -0
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +5 -0
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +1 -0
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +1 -0
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +1 -0
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +1 -0
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +1 -0
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +1 -0
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +1 -0
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +1 -0
- package/package.json +2 -2
- package/src/EventEmitter.ts +2 -2
- package/src/Extension.ts +130 -14
- package/src/ExtensionManager.ts +117 -85
- package/src/Mark.ts +129 -14
- package/src/Node.ts +226 -30
- package/src/NodeView.ts +4 -0
- package/src/PasteRule.ts +4 -0
- package/src/commands/blur.ts +1 -0
- package/src/commands/clearContent.ts +2 -0
- package/src/commands/clearNodes.ts +1 -0
- package/src/commands/command.ts +6 -0
- package/src/commands/createParagraphNear.ts +1 -0
- package/src/commands/cut.ts +5 -0
- package/src/commands/deleteCurrentNode.ts +1 -0
- package/src/commands/deleteNode.ts +3 -1
- package/src/commands/deleteRange.ts +2 -0
- package/src/commands/deleteSelection.ts +1 -0
- package/src/commands/enter.ts +1 -0
- package/src/commands/exitCode.ts +1 -0
- package/src/commands/extendMarkRange.ts +12 -1
- package/src/commands/first.ts +2 -0
- package/src/commands/focus.ts +12 -0
- package/src/commands/insertContent.ts +16 -0
- package/src/commands/insertContentAt.ts +19 -0
- package/src/commands/join.ts +12 -4
- package/src/commands/joinItemBackward.ts +6 -3
- package/src/commands/joinItemForward.ts +2 -1
- package/src/commands/keyboardShortcut.ts +2 -0
- package/src/commands/lift.ts +5 -1
- package/src/commands/liftEmptyBlock.ts +2 -1
- package/src/commands/liftListItem.ts +3 -1
- package/src/commands/newlineInCode.ts +1 -0
- package/src/commands/resetAttributes.ts +3 -0
- package/src/commands/scrollIntoView.ts +1 -0
- package/src/commands/selectAll.ts +1 -0
- package/src/commands/selectNodeBackward.ts +1 -0
- package/src/commands/selectNodeForward.ts +1 -0
- package/src/commands/selectParentNode.ts +1 -0
- package/src/commands/selectTextblockEnd.ts +1 -0
- package/src/commands/selectTextblockStart.ts +1 -0
- package/src/commands/setContent.ts +17 -0
- package/src/commands/setMark.ts +2 -0
- package/src/commands/setMeta.ts +3 -0
- package/src/commands/setNode.ts +3 -0
- package/src/commands/setNodeSelection.ts +2 -0
- package/src/commands/setTextSelection.ts +2 -0
- package/src/commands/sinkListItem.ts +2 -0
- package/src/commands/splitBlock.ts +3 -0
- package/src/commands/splitListItem.ts +2 -0
- package/src/commands/toggleList.ts +5 -0
- package/src/commands/toggleMark.ts +12 -0
- package/src/commands/toggleNode.ts +4 -0
- package/src/commands/toggleWrap.ts +3 -0
- package/src/commands/undoInputRule.ts +1 -0
- package/src/commands/unsetAllMarks.ts +1 -0
- package/src/commands/unsetMark.ts +7 -0
- package/src/commands/updateAttributes.ts +10 -0
- package/src/commands/wrapIn.ts +3 -0
- package/src/commands/wrapInList.ts +3 -0
- package/src/extensions/keymap.ts +7 -1
- package/src/helpers/combineTransactionSteps.ts +3 -0
- package/src/helpers/createChainableState.ts +5 -0
- package/src/helpers/createDocument.ts +7 -0
- package/src/helpers/createNodeFromContent.ts +16 -3
- package/src/helpers/defaultBlockAt.ts +5 -0
- package/src/helpers/findChildren.ts +6 -0
- package/src/helpers/findChildrenInRange.ts +4 -0
- package/src/helpers/findParentNode.ts +8 -0
- package/src/helpers/findParentNodeClosestToPos.ts +9 -0
- package/src/helpers/generateHTML.ts +6 -0
- package/src/helpers/generateJSON.ts +6 -0
- package/src/helpers/generateText.ts +7 -0
- package/src/helpers/getAttributes.ts +6 -0
- package/src/helpers/getExtensionField.ts +7 -0
- package/src/helpers/getSchemaByResolvedExtensions.ts +6 -0
- package/src/helpers/getSchemaTypeByName.ts +6 -0
- package/src/helpers/getSchemaTypeNameByName.ts +6 -0
- package/src/helpers/getSplittedAttributes.ts +7 -0
- package/src/helpers/getText.ts +9 -0
- package/src/helpers/getTextBetween.ts +12 -10
- package/src/helpers/getTextContentFromNodes.ts +6 -0
- package/src/helpers/getTextSerializersFromSchema.ts +5 -0
- package/src/inputRules/markInputRule.ts +1 -0
- package/src/inputRules/nodeInputRule.ts +4 -1
- package/src/inputRules/textInputRule.ts +1 -0
- package/src/inputRules/textblockTypeInputRule.ts +1 -0
- package/src/inputRules/wrappingInputRule.ts +1 -0
- package/src/pasteRules/markPasteRule.ts +1 -0
- package/src/pasteRules/nodePasteRule.ts +1 -0
- package/src/pasteRules/textPasteRule.ts +1 -0
package/src/ExtensionManager.ts
CHANGED
|
@@ -13,8 +13,8 @@ import { getSchemaTypeByName } from './helpers/getSchemaTypeByName.js'
|
|
|
13
13
|
import { isExtensionRulesEnabled } from './helpers/isExtensionRulesEnabled.js'
|
|
14
14
|
import { splitExtensions } from './helpers/splitExtensions.js'
|
|
15
15
|
import { Mark, NodeConfig } from './index.js'
|
|
16
|
-
import { inputRulesPlugin } from './InputRule.js'
|
|
17
|
-
import { pasteRulesPlugin } from './PasteRule.js'
|
|
16
|
+
import { InputRule, inputRulesPlugin } from './InputRule.js'
|
|
17
|
+
import { PasteRule, pasteRulesPlugin } from './PasteRule.js'
|
|
18
18
|
import { AnyConfig, Extensions, RawCommands } from './types.js'
|
|
19
19
|
import { callOrReturn } from './utilities/callOrReturn.js'
|
|
20
20
|
import { findDuplicates } from './utilities/findDuplicates.js'
|
|
@@ -32,89 +32,15 @@ export class ExtensionManager {
|
|
|
32
32
|
this.editor = editor
|
|
33
33
|
this.extensions = ExtensionManager.resolve(extensions)
|
|
34
34
|
this.schema = getSchemaByResolvedExtensions(this.extensions, editor)
|
|
35
|
-
|
|
36
|
-
this.extensions.forEach(extension => {
|
|
37
|
-
// store extension storage in editor
|
|
38
|
-
this.editor.extensionStorage[extension.name] = extension.storage
|
|
39
|
-
|
|
40
|
-
const context = {
|
|
41
|
-
name: extension.name,
|
|
42
|
-
options: extension.options,
|
|
43
|
-
storage: extension.storage,
|
|
44
|
-
editor: this.editor,
|
|
45
|
-
type: getSchemaTypeByName(extension.name, this.schema),
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (extension.type === 'mark') {
|
|
49
|
-
const keepOnSplit = callOrReturn(getExtensionField(extension, 'keepOnSplit', context)) ?? true
|
|
50
|
-
|
|
51
|
-
if (keepOnSplit) {
|
|
52
|
-
this.splittableMarks.push(extension.name)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const onBeforeCreate = getExtensionField<AnyConfig['onBeforeCreate']>(
|
|
57
|
-
extension,
|
|
58
|
-
'onBeforeCreate',
|
|
59
|
-
context,
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
if (onBeforeCreate) {
|
|
63
|
-
this.editor.on('beforeCreate', onBeforeCreate)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const onCreate = getExtensionField<AnyConfig['onCreate']>(extension, 'onCreate', context)
|
|
67
|
-
|
|
68
|
-
if (onCreate) {
|
|
69
|
-
this.editor.on('create', onCreate)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const onUpdate = getExtensionField<AnyConfig['onUpdate']>(extension, 'onUpdate', context)
|
|
73
|
-
|
|
74
|
-
if (onUpdate) {
|
|
75
|
-
this.editor.on('update', onUpdate)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const onSelectionUpdate = getExtensionField<AnyConfig['onSelectionUpdate']>(
|
|
79
|
-
extension,
|
|
80
|
-
'onSelectionUpdate',
|
|
81
|
-
context,
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
if (onSelectionUpdate) {
|
|
85
|
-
this.editor.on('selectionUpdate', onSelectionUpdate)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const onTransaction = getExtensionField<AnyConfig['onTransaction']>(
|
|
89
|
-
extension,
|
|
90
|
-
'onTransaction',
|
|
91
|
-
context,
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
if (onTransaction) {
|
|
95
|
-
this.editor.on('transaction', onTransaction)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const onFocus = getExtensionField<AnyConfig['onFocus']>(extension, 'onFocus', context)
|
|
99
|
-
|
|
100
|
-
if (onFocus) {
|
|
101
|
-
this.editor.on('focus', onFocus)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const onBlur = getExtensionField<AnyConfig['onBlur']>(extension, 'onBlur', context)
|
|
105
|
-
|
|
106
|
-
if (onBlur) {
|
|
107
|
-
this.editor.on('blur', onBlur)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const onDestroy = getExtensionField<AnyConfig['onDestroy']>(extension, 'onDestroy', context)
|
|
111
|
-
|
|
112
|
-
if (onDestroy) {
|
|
113
|
-
this.editor.on('destroy', onDestroy)
|
|
114
|
-
}
|
|
115
|
-
})
|
|
35
|
+
this.setupExtensions()
|
|
116
36
|
}
|
|
117
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Returns a flattened and sorted extension list while
|
|
40
|
+
* also checking for duplicated extensions and warns the user.
|
|
41
|
+
* @param extensions An array of Tiptap extensions
|
|
42
|
+
* @returns An flattened and sorted array of Tiptap extensions
|
|
43
|
+
*/
|
|
118
44
|
static resolve(extensions: Extensions): Extensions {
|
|
119
45
|
const resolvedExtensions = ExtensionManager.sort(ExtensionManager.flatten(extensions))
|
|
120
46
|
const duplicatedNames = findDuplicates(resolvedExtensions.map(extension => extension.name))
|
|
@@ -130,6 +56,11 @@ export class ExtensionManager {
|
|
|
130
56
|
return resolvedExtensions
|
|
131
57
|
}
|
|
132
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Create a flattened array of extensions by traversing the `addExtensions` field.
|
|
61
|
+
* @param extensions An array of Tiptap extensions
|
|
62
|
+
* @returns A flattened array of Tiptap extensions
|
|
63
|
+
*/
|
|
133
64
|
static flatten(extensions: Extensions): Extensions {
|
|
134
65
|
return (
|
|
135
66
|
extensions
|
|
@@ -157,6 +88,11 @@ export class ExtensionManager {
|
|
|
157
88
|
)
|
|
158
89
|
}
|
|
159
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Sort extensions by priority.
|
|
93
|
+
* @param extensions An array of Tiptap extensions
|
|
94
|
+
* @returns A sorted array of Tiptap extensions by priority
|
|
95
|
+
*/
|
|
160
96
|
static sort(extensions: Extensions): Extensions {
|
|
161
97
|
const defaultPriority = 100
|
|
162
98
|
|
|
@@ -176,6 +112,10 @@ export class ExtensionManager {
|
|
|
176
112
|
})
|
|
177
113
|
}
|
|
178
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Get all commands from the extensions.
|
|
117
|
+
* @returns An object with all commands where the key is the command name and the value is the command function
|
|
118
|
+
*/
|
|
179
119
|
get commands(): RawCommands {
|
|
180
120
|
return this.extensions.reduce((commands, extension) => {
|
|
181
121
|
const context = {
|
|
@@ -203,6 +143,10 @@ export class ExtensionManager {
|
|
|
203
143
|
}, {} as RawCommands)
|
|
204
144
|
}
|
|
205
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Get all registered Prosemirror plugins from the extensions.
|
|
148
|
+
* @returns An array of Prosemirror plugins
|
|
149
|
+
*/
|
|
206
150
|
get plugins(): Plugin[] {
|
|
207
151
|
const { editor } = this
|
|
208
152
|
|
|
@@ -213,8 +157,8 @@ export class ExtensionManager {
|
|
|
213
157
|
// based on the `priority` option.
|
|
214
158
|
const extensions = ExtensionManager.sort([...this.extensions].reverse())
|
|
215
159
|
|
|
216
|
-
const inputRules:
|
|
217
|
-
const pasteRules:
|
|
160
|
+
const inputRules: InputRule[] = []
|
|
161
|
+
const pasteRules: PasteRule[] = []
|
|
218
162
|
|
|
219
163
|
const allPlugins = extensions
|
|
220
164
|
.map(extension => {
|
|
@@ -304,10 +248,18 @@ export class ExtensionManager {
|
|
|
304
248
|
]
|
|
305
249
|
}
|
|
306
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Get all attributes from the extensions.
|
|
253
|
+
* @returns An array of attributes
|
|
254
|
+
*/
|
|
307
255
|
get attributes() {
|
|
308
256
|
return getAttributesFromExtensions(this.extensions)
|
|
309
257
|
}
|
|
310
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Get all node views from the extensions.
|
|
261
|
+
* @returns An object with all node views where the key is the node name and the value is the node view function
|
|
262
|
+
*/
|
|
311
263
|
get nodeViews() {
|
|
312
264
|
const { editor } = this
|
|
313
265
|
const { nodeExtensions } = splitExtensions(this.extensions)
|
|
@@ -358,4 +310,84 @@ export class ExtensionManager {
|
|
|
358
310
|
}),
|
|
359
311
|
)
|
|
360
312
|
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Go through all extensions, create extension storages & setup marks
|
|
316
|
+
* & bind editor event listener.
|
|
317
|
+
*/
|
|
318
|
+
private setupExtensions() {
|
|
319
|
+
this.extensions.forEach(extension => {
|
|
320
|
+
// store extension storage in editor
|
|
321
|
+
this.editor.extensionStorage[extension.name] = extension.storage
|
|
322
|
+
|
|
323
|
+
const context = {
|
|
324
|
+
name: extension.name,
|
|
325
|
+
options: extension.options,
|
|
326
|
+
storage: extension.storage,
|
|
327
|
+
editor: this.editor,
|
|
328
|
+
type: getSchemaTypeByName(extension.name, this.schema),
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (extension.type === 'mark') {
|
|
332
|
+
const keepOnSplit = callOrReturn(getExtensionField(extension, 'keepOnSplit', context)) ?? true
|
|
333
|
+
|
|
334
|
+
if (keepOnSplit) {
|
|
335
|
+
this.splittableMarks.push(extension.name)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const onBeforeCreate = getExtensionField<AnyConfig['onBeforeCreate']>(
|
|
340
|
+
extension,
|
|
341
|
+
'onBeforeCreate',
|
|
342
|
+
context,
|
|
343
|
+
)
|
|
344
|
+
const onCreate = getExtensionField<AnyConfig['onCreate']>(extension, 'onCreate', context)
|
|
345
|
+
const onUpdate = getExtensionField<AnyConfig['onUpdate']>(extension, 'onUpdate', context)
|
|
346
|
+
const onSelectionUpdate = getExtensionField<AnyConfig['onSelectionUpdate']>(
|
|
347
|
+
extension,
|
|
348
|
+
'onSelectionUpdate',
|
|
349
|
+
context,
|
|
350
|
+
)
|
|
351
|
+
const onTransaction = getExtensionField<AnyConfig['onTransaction']>(
|
|
352
|
+
extension,
|
|
353
|
+
'onTransaction',
|
|
354
|
+
context,
|
|
355
|
+
)
|
|
356
|
+
const onFocus = getExtensionField<AnyConfig['onFocus']>(extension, 'onFocus', context)
|
|
357
|
+
const onBlur = getExtensionField<AnyConfig['onBlur']>(extension, 'onBlur', context)
|
|
358
|
+
const onDestroy = getExtensionField<AnyConfig['onDestroy']>(extension, 'onDestroy', context)
|
|
359
|
+
|
|
360
|
+
if (onBeforeCreate) {
|
|
361
|
+
this.editor.on('beforeCreate', onBeforeCreate)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (onCreate) {
|
|
365
|
+
this.editor.on('create', onCreate)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (onUpdate) {
|
|
369
|
+
this.editor.on('update', onUpdate)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (onSelectionUpdate) {
|
|
373
|
+
this.editor.on('selectionUpdate', onSelectionUpdate)
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (onTransaction) {
|
|
377
|
+
this.editor.on('transaction', onTransaction)
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (onFocus) {
|
|
381
|
+
this.editor.on('focus', onFocus)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (onBlur) {
|
|
385
|
+
this.editor.on('blur', onBlur)
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (onDestroy) {
|
|
389
|
+
this.editor.on('destroy', onDestroy)
|
|
390
|
+
}
|
|
391
|
+
})
|
|
392
|
+
}
|
|
361
393
|
}
|
package/src/Mark.ts
CHANGED
|
@@ -26,22 +26,40 @@ declare module '@tiptap/core' {
|
|
|
26
26
|
[key: string]: any
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* The extension name - this must be unique.
|
|
30
|
+
* It will be used to identify the extension.
|
|
31
|
+
*
|
|
32
|
+
* @example 'myExtension'
|
|
30
33
|
*/
|
|
31
34
|
name: string
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
|
-
*
|
|
37
|
+
* The priority of your extension. The higher, the later it will be called
|
|
38
|
+
* and will take precedence over other extensions with a lower priority.
|
|
39
|
+
* @default 1000
|
|
40
|
+
* @example 1001
|
|
35
41
|
*/
|
|
36
42
|
priority?: number
|
|
37
43
|
|
|
38
44
|
/**
|
|
39
|
-
*
|
|
45
|
+
* The default options for this extension.
|
|
46
|
+
* @example
|
|
47
|
+
* defaultOptions: {
|
|
48
|
+
* myOption: 'foo',
|
|
49
|
+
* myOtherOption: 10,
|
|
50
|
+
* }
|
|
40
51
|
*/
|
|
41
52
|
defaultOptions?: Options
|
|
42
53
|
|
|
43
54
|
/**
|
|
44
|
-
*
|
|
55
|
+
* This method will add options to this extension
|
|
56
|
+
* @see https://tiptap.dev/guide/custom-extensions#settings
|
|
57
|
+
* @example
|
|
58
|
+
* addOptions() {
|
|
59
|
+
* return {
|
|
60
|
+
* myOption: 'foo',
|
|
61
|
+
* myOtherOption: 10,
|
|
62
|
+
* }
|
|
45
63
|
*/
|
|
46
64
|
addOptions?: (this: {
|
|
47
65
|
name: string
|
|
@@ -49,7 +67,13 @@ declare module '@tiptap/core' {
|
|
|
49
67
|
}) => Options
|
|
50
68
|
|
|
51
69
|
/**
|
|
52
|
-
*
|
|
70
|
+
* The default storage this extension can save data to.
|
|
71
|
+
* @see https://tiptap.dev/guide/custom-extensions#storage
|
|
72
|
+
* @example
|
|
73
|
+
* defaultStorage: {
|
|
74
|
+
* prefetchedUsers: [],
|
|
75
|
+
* loading: false,
|
|
76
|
+
* }
|
|
53
77
|
*/
|
|
54
78
|
addStorage?: (this: {
|
|
55
79
|
name: string
|
|
@@ -58,7 +82,30 @@ declare module '@tiptap/core' {
|
|
|
58
82
|
}) => Storage
|
|
59
83
|
|
|
60
84
|
/**
|
|
61
|
-
*
|
|
85
|
+
* This function adds globalAttributes to specific nodes.
|
|
86
|
+
* @see https://tiptap.dev/guide/custom-extensions#global-attributes
|
|
87
|
+
* @example
|
|
88
|
+
* addGlobalAttributes() {
|
|
89
|
+
* return [
|
|
90
|
+
* {
|
|
91
|
+
// Extend the following extensions
|
|
92
|
+
* types: [
|
|
93
|
+
* 'heading',
|
|
94
|
+
* 'paragraph',
|
|
95
|
+
* ],
|
|
96
|
+
* // … with those attributes
|
|
97
|
+
* attributes: {
|
|
98
|
+
* textAlign: {
|
|
99
|
+
* default: 'left',
|
|
100
|
+
* renderHTML: attributes => ({
|
|
101
|
+
* style: `text-align: ${attributes.textAlign}`,
|
|
102
|
+
* }),
|
|
103
|
+
* parseHTML: element => element.style.textAlign || 'left',
|
|
104
|
+
* },
|
|
105
|
+
* },
|
|
106
|
+
* },
|
|
107
|
+
* ]
|
|
108
|
+
* }
|
|
62
109
|
*/
|
|
63
110
|
addGlobalAttributes?: (this: {
|
|
64
111
|
name: string
|
|
@@ -68,7 +115,14 @@ declare module '@tiptap/core' {
|
|
|
68
115
|
}) => GlobalAttributes | {}
|
|
69
116
|
|
|
70
117
|
/**
|
|
71
|
-
*
|
|
118
|
+
* This function adds commands to the editor
|
|
119
|
+
* @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
|
|
120
|
+
* @example
|
|
121
|
+
* addCommands() {
|
|
122
|
+
* return {
|
|
123
|
+
* myCommand: () => ({ chain }) => chain().setMark('type', 'foo').run(),
|
|
124
|
+
* }
|
|
125
|
+
* }
|
|
72
126
|
*/
|
|
73
127
|
addCommands?: (this: {
|
|
74
128
|
name: string
|
|
@@ -80,7 +134,14 @@ declare module '@tiptap/core' {
|
|
|
80
134
|
}) => Partial<RawCommands>
|
|
81
135
|
|
|
82
136
|
/**
|
|
83
|
-
*
|
|
137
|
+
* This function registers keyboard shortcuts.
|
|
138
|
+
* @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
|
|
139
|
+
* @example
|
|
140
|
+
* addKeyboardShortcuts() {
|
|
141
|
+
* return {
|
|
142
|
+
* 'Mod-l': () => this.editor.commands.toggleBulletList(),
|
|
143
|
+
* }
|
|
144
|
+
* },
|
|
84
145
|
*/
|
|
85
146
|
addKeyboardShortcuts?: (this: {
|
|
86
147
|
name: string
|
|
@@ -94,7 +155,17 @@ declare module '@tiptap/core' {
|
|
|
94
155
|
}
|
|
95
156
|
|
|
96
157
|
/**
|
|
97
|
-
*
|
|
158
|
+
* This function adds input rules to the editor.
|
|
159
|
+
* @see https://tiptap.dev/guide/custom-extensions#input-rules
|
|
160
|
+
* @example
|
|
161
|
+
* addInputRules() {
|
|
162
|
+
* return [
|
|
163
|
+
* markInputRule({
|
|
164
|
+
* find: inputRegex,
|
|
165
|
+
* type: this.type,
|
|
166
|
+
* }),
|
|
167
|
+
* ]
|
|
168
|
+
* },
|
|
98
169
|
*/
|
|
99
170
|
addInputRules?: (this: {
|
|
100
171
|
name: string
|
|
@@ -106,7 +177,17 @@ declare module '@tiptap/core' {
|
|
|
106
177
|
}) => InputRule[]
|
|
107
178
|
|
|
108
179
|
/**
|
|
109
|
-
*
|
|
180
|
+
* This function adds paste rules to the editor.
|
|
181
|
+
* @see https://tiptap.dev/guide/custom-extensions#paste-rules
|
|
182
|
+
* @example
|
|
183
|
+
* addPasteRules() {
|
|
184
|
+
* return [
|
|
185
|
+
* markPasteRule({
|
|
186
|
+
* find: pasteRegex,
|
|
187
|
+
* type: this.type,
|
|
188
|
+
* }),
|
|
189
|
+
* ]
|
|
190
|
+
* },
|
|
110
191
|
*/
|
|
111
192
|
addPasteRules?: (this: {
|
|
112
193
|
name: string
|
|
@@ -118,7 +199,14 @@ declare module '@tiptap/core' {
|
|
|
118
199
|
}) => PasteRule[]
|
|
119
200
|
|
|
120
201
|
/**
|
|
121
|
-
*
|
|
202
|
+
* This function adds Prosemirror plugins to the editor
|
|
203
|
+
* @see https://tiptap.dev/guide/custom-extensions#prosemirror-plugins
|
|
204
|
+
* @example
|
|
205
|
+
* addProseMirrorPlugins() {
|
|
206
|
+
* return [
|
|
207
|
+
* customPlugin(),
|
|
208
|
+
* ]
|
|
209
|
+
* }
|
|
122
210
|
*/
|
|
123
211
|
addProseMirrorPlugins?: (this: {
|
|
124
212
|
name: string
|
|
@@ -130,7 +218,16 @@ declare module '@tiptap/core' {
|
|
|
130
218
|
}) => Plugin[]
|
|
131
219
|
|
|
132
220
|
/**
|
|
133
|
-
*
|
|
221
|
+
* This function adds additional extensions to the editor. This is useful for
|
|
222
|
+
* building extension kits.
|
|
223
|
+
* @example
|
|
224
|
+
* addExtensions() {
|
|
225
|
+
* return [
|
|
226
|
+
* BulletList,
|
|
227
|
+
* OrderedList,
|
|
228
|
+
* ListItem
|
|
229
|
+
* ]
|
|
230
|
+
* }
|
|
134
231
|
*/
|
|
135
232
|
addExtensions?: (this: {
|
|
136
233
|
name: string
|
|
@@ -140,7 +237,14 @@ declare module '@tiptap/core' {
|
|
|
140
237
|
}) => Extensions
|
|
141
238
|
|
|
142
239
|
/**
|
|
143
|
-
*
|
|
240
|
+
* This function extends the schema of the node.
|
|
241
|
+
* @example
|
|
242
|
+
* extendNodeSchema() {
|
|
243
|
+
* return {
|
|
244
|
+
* group: 'inline',
|
|
245
|
+
* selectable: false,
|
|
246
|
+
* }
|
|
247
|
+
* }
|
|
144
248
|
*/
|
|
145
249
|
extendNodeSchema?:
|
|
146
250
|
| ((
|
|
@@ -155,7 +259,14 @@ declare module '@tiptap/core' {
|
|
|
155
259
|
| null
|
|
156
260
|
|
|
157
261
|
/**
|
|
158
|
-
*
|
|
262
|
+
* This function extends the schema of the mark.
|
|
263
|
+
* @example
|
|
264
|
+
* extendMarkSchema() {
|
|
265
|
+
* return {
|
|
266
|
+
* group: 'inline',
|
|
267
|
+
* selectable: false,
|
|
268
|
+
* }
|
|
269
|
+
* }
|
|
159
270
|
*/
|
|
160
271
|
extendMarkSchema?:
|
|
161
272
|
| ((
|
|
@@ -414,6 +525,10 @@ declare module '@tiptap/core' {
|
|
|
414
525
|
}
|
|
415
526
|
}
|
|
416
527
|
|
|
528
|
+
/**
|
|
529
|
+
* The Mark class is used to create custom mark extensions.
|
|
530
|
+
* @see https://tiptap.dev/api/extensions#create-a-new-extension
|
|
531
|
+
*/
|
|
417
532
|
export class Mark<Options = any, Storage = any> {
|
|
418
533
|
type = 'mark'
|
|
419
534
|
|