@tiptap/core 3.0.0-beta.25 → 3.0.0-beta.26
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 +49 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +48 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/ExtensionManager.ts +4 -1
- package/src/MarkView.ts +56 -0
- package/src/types.ts +3 -1
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.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.26",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
],
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"prosemirror-dev-toolkit": "^1.1.8",
|
|
56
|
-
"@tiptap/pm": "3.0.0-beta.
|
|
56
|
+
"@tiptap/pm": "3.0.0-beta.26"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@tiptap/pm": "3.0.0-beta.
|
|
59
|
+
"@tiptap/pm": "3.0.0-beta.26"
|
|
60
60
|
},
|
|
61
61
|
"repository": {
|
|
62
62
|
"type": "git",
|
package/src/ExtensionManager.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
sortExtensions,
|
|
18
18
|
splitExtensions,
|
|
19
19
|
} from './helpers/index.js'
|
|
20
|
-
import { type MarkConfig, type NodeConfig, type Storage, getMarkType } from './index.js'
|
|
20
|
+
import { type MarkConfig, type NodeConfig, type Storage, getMarkType, updateMarkViewAttributes } from './index.js'
|
|
21
21
|
import type { InputRule } from './InputRule.js'
|
|
22
22
|
import { inputRulesPlugin } from './InputRule.js'
|
|
23
23
|
import { Mark } from './Mark.js'
|
|
@@ -262,6 +262,9 @@ export class ExtensionManager {
|
|
|
262
262
|
editor,
|
|
263
263
|
extension,
|
|
264
264
|
HTMLAttributes,
|
|
265
|
+
updateAttributes: (attrs: Record<string, any>) => {
|
|
266
|
+
updateMarkViewAttributes(mark, editor, attrs)
|
|
267
|
+
},
|
|
265
268
|
})
|
|
266
269
|
}
|
|
267
270
|
|
package/src/MarkView.ts
CHANGED
|
@@ -1,9 +1,57 @@
|
|
|
1
|
+
import type { Mark } from '@tiptap/pm/model'
|
|
1
2
|
import type { ViewMutationRecord } from '@tiptap/pm/view'
|
|
2
3
|
|
|
3
4
|
import type { Editor } from './Editor.js'
|
|
4
5
|
import type { MarkViewProps, MarkViewRendererOptions } from './types.js'
|
|
5
6
|
import { isAndroid, isiOS } from './utilities/index.js'
|
|
6
7
|
|
|
8
|
+
export function updateMarkViewAttributes(checkMark: Mark, editor: Editor, attrs: Record<string, any> = {}): void {
|
|
9
|
+
const { state } = editor
|
|
10
|
+
const { doc, tr } = state
|
|
11
|
+
const thisMark = checkMark
|
|
12
|
+
|
|
13
|
+
doc.descendants((node, pos) => {
|
|
14
|
+
const from = tr.mapping.map(pos)
|
|
15
|
+
const to = tr.mapping.map(pos) + node.nodeSize
|
|
16
|
+
let foundMark: Mark | null = null
|
|
17
|
+
|
|
18
|
+
// find the mark on the current node
|
|
19
|
+
node.marks.forEach(mark => {
|
|
20
|
+
if (mark !== thisMark) {
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
foundMark = mark
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
if (!foundMark) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// check if we need to update given the attributes
|
|
32
|
+
let needsUpdate = false
|
|
33
|
+
Object.keys(attrs).forEach(k => {
|
|
34
|
+
if (attrs[k] !== foundMark!.attrs[k]) {
|
|
35
|
+
needsUpdate = true
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
if (needsUpdate) {
|
|
40
|
+
const updatedMark = checkMark.type.create({
|
|
41
|
+
...checkMark.attrs,
|
|
42
|
+
...attrs,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
tr.removeMark(from, to, checkMark.type)
|
|
46
|
+
tr.addMark(from, to, updatedMark)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
if (tr.docChanged) {
|
|
51
|
+
editor.view.dispatch(tr)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
7
55
|
export class MarkView<Component, Options extends MarkViewRendererOptions = MarkViewRendererOptions> {
|
|
8
56
|
component: Component
|
|
9
57
|
editor: Editor
|
|
@@ -27,6 +75,14 @@ export class MarkView<Component, Options extends MarkViewRendererOptions = MarkV
|
|
|
27
75
|
return null
|
|
28
76
|
}
|
|
29
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Update the attributes of the mark in the document.
|
|
80
|
+
* @param attrs The attributes to update.
|
|
81
|
+
*/
|
|
82
|
+
updateAttributes(attrs: Record<string, any>, checkMark?: Mark): void {
|
|
83
|
+
updateMarkViewAttributes(checkMark || this.mark, this.editor, attrs)
|
|
84
|
+
}
|
|
85
|
+
|
|
30
86
|
ignoreMutation(mutation: ViewMutationRecord): boolean {
|
|
31
87
|
if (!this.dom || !this.contentDOM) {
|
|
32
88
|
return true
|
package/src/types.ts
CHANGED
|
@@ -674,9 +674,11 @@ export interface MarkViewRendererProps {
|
|
|
674
674
|
* The HTML attributes that should be added to the mark's DOM element.
|
|
675
675
|
*/
|
|
676
676
|
HTMLAttributes: Record<string, any>
|
|
677
|
+
|
|
678
|
+
updateAttributes: (attrs: Record<string, any>) => void
|
|
677
679
|
}
|
|
678
680
|
|
|
679
|
-
export type MarkViewRenderer = (props:
|
|
681
|
+
export type MarkViewRenderer<Props = MarkViewRendererProps> = (props: Props) => MarkView
|
|
680
682
|
|
|
681
683
|
export interface MarkViewRendererOptions {
|
|
682
684
|
ignoreMutation: ((props: { mutation: ViewMutationRecord }) => boolean) | null
|