@tiptap/core 3.4.3 → 3.4.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/dist/index.cjs +10 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/Editor.ts +4 -0
- package/src/ExtensionManager.ts +58 -60
- package/src/commands/insertContentAt.ts +5 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/core",
|
|
3
3
|
"description": "headless rich text editor",
|
|
4
|
-
"version": "3.4.
|
|
4
|
+
"version": "3.4.5",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"jsx-dev-runtime"
|
|
53
53
|
],
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@tiptap/pm": "^3.4.
|
|
55
|
+
"@tiptap/pm": "^3.4.5"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@tiptap/pm": "^3.4.
|
|
58
|
+
"@tiptap/pm": "^3.4.5"
|
|
59
59
|
},
|
|
60
60
|
"repository": {
|
|
61
61
|
"type": "git",
|
package/src/Editor.ts
CHANGED
|
@@ -160,6 +160,10 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
160
160
|
this.createView(el)
|
|
161
161
|
this.emit('mount', { editor: this })
|
|
162
162
|
|
|
163
|
+
if (this.css && !document.head.contains(this.css)) {
|
|
164
|
+
document.head.appendChild(this.css)
|
|
165
|
+
}
|
|
166
|
+
|
|
163
167
|
window.setTimeout(() => {
|
|
164
168
|
if (this.isDestroyed) {
|
|
165
169
|
return
|
package/src/ExtensionManager.ts
CHANGED
|
@@ -87,89 +87,87 @@ export class ExtensionManager {
|
|
|
87
87
|
// based on the `priority` option.
|
|
88
88
|
const extensions = sortExtensions([...this.extensions].reverse())
|
|
89
89
|
|
|
90
|
-
const allPlugins = extensions
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
90
|
+
const allPlugins = extensions.flatMap(extension => {
|
|
91
|
+
const context = {
|
|
92
|
+
name: extension.name,
|
|
93
|
+
options: extension.options,
|
|
94
|
+
storage: this.editor.extensionStorage[extension.name as keyof Storage],
|
|
95
|
+
editor,
|
|
96
|
+
type: getSchemaTypeByName(extension.name, this.schema),
|
|
97
|
+
}
|
|
99
98
|
|
|
100
|
-
|
|
99
|
+
const plugins: Plugin[] = []
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
const addKeyboardShortcuts = getExtensionField<AnyConfig['addKeyboardShortcuts']>(
|
|
102
|
+
extension,
|
|
103
|
+
'addKeyboardShortcuts',
|
|
104
|
+
context,
|
|
105
|
+
)
|
|
107
106
|
|
|
108
|
-
|
|
107
|
+
let defaultBindings: Record<string, () => boolean> = {}
|
|
109
108
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
// bind exit handling
|
|
110
|
+
if (extension.type === 'mark' && getExtensionField<MarkConfig['exitable']>(extension, 'exitable', context)) {
|
|
111
|
+
defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark: extension as Mark })
|
|
112
|
+
}
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
if (addKeyboardShortcuts) {
|
|
115
|
+
const bindings = Object.fromEntries(
|
|
116
|
+
Object.entries(addKeyboardShortcuts()).map(([shortcut, method]) => {
|
|
117
|
+
return [shortcut, () => method({ editor })]
|
|
118
|
+
}),
|
|
119
|
+
)
|
|
121
120
|
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
defaultBindings = { ...defaultBindings, ...bindings }
|
|
122
|
+
}
|
|
124
123
|
|
|
125
|
-
|
|
124
|
+
const keyMapPlugin = keymap(defaultBindings)
|
|
126
125
|
|
|
127
|
-
|
|
126
|
+
plugins.push(keyMapPlugin)
|
|
128
127
|
|
|
129
|
-
|
|
128
|
+
const addInputRules = getExtensionField<AnyConfig['addInputRules']>(extension, 'addInputRules', context)
|
|
130
129
|
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) {
|
|
131
|
+
const rules = addInputRules()
|
|
133
132
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
if (rules && rules.length) {
|
|
134
|
+
const inputResult = inputRulesPlugin({
|
|
135
|
+
editor,
|
|
136
|
+
rules,
|
|
137
|
+
})
|
|
139
138
|
|
|
140
|
-
|
|
139
|
+
const inputPlugins = Array.isArray(inputResult) ? inputResult : [inputResult]
|
|
141
140
|
|
|
142
|
-
|
|
143
|
-
}
|
|
141
|
+
plugins.push(...inputPlugins)
|
|
144
142
|
}
|
|
143
|
+
}
|
|
145
144
|
|
|
146
|
-
|
|
145
|
+
const addPasteRules = getExtensionField<AnyConfig['addPasteRules']>(extension, 'addPasteRules', context)
|
|
147
146
|
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
if (isExtensionRulesEnabled(extension, editor.options.enablePasteRules) && addPasteRules) {
|
|
148
|
+
const rules = addPasteRules()
|
|
150
149
|
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
if (rules && rules.length) {
|
|
151
|
+
const pasteRules = pasteRulesPlugin({ editor, rules })
|
|
153
152
|
|
|
154
|
-
|
|
155
|
-
}
|
|
153
|
+
plugins.push(...pasteRules)
|
|
156
154
|
}
|
|
155
|
+
}
|
|
157
156
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
const addProseMirrorPlugins = getExtensionField<AnyConfig['addProseMirrorPlugins']>(
|
|
158
|
+
extension,
|
|
159
|
+
'addProseMirrorPlugins',
|
|
160
|
+
context,
|
|
161
|
+
)
|
|
163
162
|
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
if (addProseMirrorPlugins) {
|
|
164
|
+
const proseMirrorPlugins = addProseMirrorPlugins()
|
|
166
165
|
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
plugins.push(...proseMirrorPlugins)
|
|
167
|
+
}
|
|
169
168
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
.flat()
|
|
169
|
+
return plugins
|
|
170
|
+
})
|
|
173
171
|
|
|
174
172
|
return allPlugins
|
|
175
173
|
}
|
|
@@ -74,7 +74,6 @@ export const insertContentAt: RawCommands['insertContentAt'] =
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
let content: Fragment | ProseMirrorNode
|
|
77
|
-
const { selection } = editor.state
|
|
78
77
|
|
|
79
78
|
const emitContentError = (error: Error) => {
|
|
80
79
|
editor.emit('contentError', {
|
|
@@ -180,9 +179,11 @@ export const insertContentAt: RawCommands['insertContentAt'] =
|
|
|
180
179
|
} else {
|
|
181
180
|
newContent = content
|
|
182
181
|
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
const
|
|
182
|
+
const $from = tr.doc.resolve(from)
|
|
183
|
+
const $fromNode = $from.node()
|
|
184
|
+
const fromSelectionAtStart = $from.parentOffset === 0
|
|
185
|
+
const isTextSelection = $fromNode.isText || $fromNode.isTextblock
|
|
186
|
+
const hasContent = $fromNode.content.size > 0
|
|
186
187
|
|
|
187
188
|
if (fromSelectionAtStart && isTextSelection && hasContent) {
|
|
188
189
|
from = Math.max(0, from - 1)
|