@tiptap/core 3.3.1 → 3.4.1
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 +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/Editor.ts +6 -0
- package/src/commands/setMark.ts +6 -2
- package/src/types.ts +20 -0
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
|
+
"version": "3.4.1",
|
|
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.
|
|
55
|
+
"@tiptap/pm": "^3.4.1"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@tiptap/pm": "^3.
|
|
58
|
+
"@tiptap/pm": "^3.4.1"
|
|
59
59
|
},
|
|
60
60
|
"repository": {
|
|
61
61
|
"type": "git",
|
package/src/Editor.ts
CHANGED
|
@@ -95,6 +95,8 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
95
95
|
emitContentError: false,
|
|
96
96
|
onBeforeCreate: () => null,
|
|
97
97
|
onCreate: () => null,
|
|
98
|
+
onMount: () => null,
|
|
99
|
+
onUnmount: () => null,
|
|
98
100
|
onUpdate: () => null,
|
|
99
101
|
onSelectionUpdate: () => null,
|
|
100
102
|
onTransaction: () => null,
|
|
@@ -117,6 +119,8 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
117
119
|
this.createSchema()
|
|
118
120
|
this.on('beforeCreate', this.options.onBeforeCreate)
|
|
119
121
|
this.emit('beforeCreate', { editor: this })
|
|
122
|
+
this.on('mount', this.options.onMount)
|
|
123
|
+
this.on('unmount', this.options.onUnmount)
|
|
120
124
|
this.on('contentError', this.options.onContentError)
|
|
121
125
|
this.on('create', this.options.onCreate)
|
|
122
126
|
this.on('update', this.options.onUpdate)
|
|
@@ -154,6 +158,7 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
154
158
|
)
|
|
155
159
|
}
|
|
156
160
|
this.createView(el)
|
|
161
|
+
this.emit('mount', { editor: this })
|
|
157
162
|
|
|
158
163
|
window.setTimeout(() => {
|
|
159
164
|
if (this.isDestroyed) {
|
|
@@ -197,6 +202,7 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
204
|
this.css = null
|
|
205
|
+
this.emit('unmount', { editor: this })
|
|
200
206
|
}
|
|
201
207
|
|
|
202
208
|
/**
|
package/src/commands/setMark.ts
CHANGED
|
@@ -29,9 +29,13 @@ function canSetMark(state: EditorState, tr: Transaction, newMarkType: MarkType)
|
|
|
29
29
|
|
|
30
30
|
if (cursor) {
|
|
31
31
|
const currentMarks = state.storedMarks ?? cursor.marks()
|
|
32
|
+
const parentAllowsMarkType = cursor.parent.type.allowsMarkType(newMarkType)
|
|
32
33
|
|
|
33
|
-
// There can be no current marks that exclude the new mark
|
|
34
|
-
return
|
|
34
|
+
// There can be no current marks that exclude the new mark, and the parent must allow this mark type
|
|
35
|
+
return (
|
|
36
|
+
parentAllowsMarkType &&
|
|
37
|
+
(!!newMarkType.isInSet(currentMarks) || !currentMarks.some(mark => mark.type.excludes(newMarkType)))
|
|
38
|
+
)
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
const { ranges } = selection
|
package/src/types.ts
CHANGED
|
@@ -39,6 +39,18 @@ export type MaybeThisParameterType<T> =
|
|
|
39
39
|
Exclude<T, Primitive> extends (...args: any) => any ? ThisParameterType<Exclude<T, Primitive>> : any
|
|
40
40
|
|
|
41
41
|
export interface EditorEvents {
|
|
42
|
+
mount: {
|
|
43
|
+
/**
|
|
44
|
+
* The editor instance
|
|
45
|
+
*/
|
|
46
|
+
editor: Editor
|
|
47
|
+
}
|
|
48
|
+
unmount: {
|
|
49
|
+
/**
|
|
50
|
+
* The editor instance
|
|
51
|
+
*/
|
|
52
|
+
editor: Editor
|
|
53
|
+
}
|
|
42
54
|
beforeCreate: {
|
|
43
55
|
/**
|
|
44
56
|
* The editor instance
|
|
@@ -371,6 +383,14 @@ export interface EditorOptions {
|
|
|
371
383
|
* Called after the editor is constructed.
|
|
372
384
|
*/
|
|
373
385
|
onCreate: (props: EditorEvents['create']) => void
|
|
386
|
+
/**
|
|
387
|
+
* Called when the editor is mounted.
|
|
388
|
+
*/
|
|
389
|
+
onMount: (props: EditorEvents['mount']) => void
|
|
390
|
+
/**
|
|
391
|
+
* Called when the editor is unmounted.
|
|
392
|
+
*/
|
|
393
|
+
onUnmount: (props: EditorEvents['unmount']) => void
|
|
374
394
|
/**
|
|
375
395
|
* Called when the editor encounters an error while parsing the content.
|
|
376
396
|
* Only enabled if `enableContentCheck` is `true`.
|