@tiptap/core 3.10.6 → 3.10.8
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 +85 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +85 -71
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/commands/resetAttributes.ts +20 -12
- package/src/commands/updateAttributes.ts +68 -58
- package/src/helpers/getSchemaByResolvedExtensions.ts +2 -2
- package/src/types.ts +55 -1
- package/src/utilities/markdown/parseIndentedBlocks.ts +2 -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.10.
|
|
4
|
+
"version": "3.10.8",
|
|
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.10.
|
|
55
|
+
"@tiptap/pm": "^3.10.8"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@tiptap/pm": "^3.10.
|
|
58
|
+
"@tiptap/pm": "^3.10.8"
|
|
59
59
|
},
|
|
60
60
|
"repository": {
|
|
61
61
|
"type": "git",
|
|
@@ -43,23 +43,31 @@ export const resetAttributes: RawCommands['resetAttributes'] =
|
|
|
43
43
|
markType = getMarkType(typeOrName as MarkType, state.schema)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
let canReset = false
|
|
47
|
+
|
|
48
|
+
tr.selection.ranges.forEach(range => {
|
|
49
|
+
state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
|
|
50
|
+
if (nodeType && nodeType === node.type) {
|
|
51
|
+
canReset = true
|
|
52
|
+
|
|
53
|
+
if (dispatch) {
|
|
50
54
|
tr.setNodeMarkup(pos, undefined, deleteProps(node.attrs, attributes))
|
|
51
55
|
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (markType && node.marks.length) {
|
|
59
|
+
node.marks.forEach(mark => {
|
|
60
|
+
if (markType === mark.type) {
|
|
61
|
+
canReset = true
|
|
52
62
|
|
|
53
|
-
|
|
54
|
-
node.marks.forEach(mark => {
|
|
55
|
-
if (markType === mark.type) {
|
|
63
|
+
if (dispatch) {
|
|
56
64
|
tr.addMark(pos, pos + node.nodeSize, markType.create(deleteProps(mark.attrs, attributes)))
|
|
57
65
|
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
}
|
|
61
69
|
})
|
|
62
|
-
}
|
|
70
|
+
})
|
|
63
71
|
|
|
64
|
-
return
|
|
72
|
+
return canReset
|
|
65
73
|
}
|
|
@@ -53,45 +53,55 @@ export const updateAttributes: RawCommands['updateAttributes'] =
|
|
|
53
53
|
markType = getMarkType(typeOrName as MarkType, state.schema)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
let canUpdate = false
|
|
57
|
+
|
|
58
|
+
tr.selection.ranges.forEach((range: SelectionRange) => {
|
|
59
|
+
const from = range.$from.pos
|
|
60
|
+
const to = range.$to.pos
|
|
61
|
+
|
|
62
|
+
let lastPos: number | undefined
|
|
63
|
+
let lastNode: Node | undefined
|
|
64
|
+
let trimmedFrom: number
|
|
65
|
+
let trimmedTo: number
|
|
66
|
+
|
|
67
|
+
if (tr.selection.empty) {
|
|
68
|
+
state.doc.nodesBetween(from, to, (node: Node, pos: number) => {
|
|
69
|
+
if (nodeType && nodeType === node.type) {
|
|
70
|
+
canUpdate = true
|
|
71
|
+
trimmedFrom = Math.max(pos, from)
|
|
72
|
+
trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
73
|
+
lastPos = pos
|
|
74
|
+
lastNode = node
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
} else {
|
|
78
|
+
state.doc.nodesBetween(from, to, (node: Node, pos: number) => {
|
|
79
|
+
if (pos < from && nodeType && nodeType === node.type) {
|
|
80
|
+
canUpdate = true
|
|
81
|
+
trimmedFrom = Math.max(pos, from)
|
|
82
|
+
trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
83
|
+
lastPos = pos
|
|
84
|
+
lastNode = node
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (pos >= from && pos <= to) {
|
|
68
88
|
if (nodeType && nodeType === node.type) {
|
|
69
|
-
|
|
70
|
-
trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
71
|
-
lastPos = pos
|
|
72
|
-
lastNode = node
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
} else {
|
|
76
|
-
state.doc.nodesBetween(from, to, (node: Node, pos: number) => {
|
|
77
|
-
if (pos < from && nodeType && nodeType === node.type) {
|
|
78
|
-
trimmedFrom = Math.max(pos, from)
|
|
79
|
-
trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
80
|
-
lastPos = pos
|
|
81
|
-
lastNode = node
|
|
82
|
-
}
|
|
89
|
+
canUpdate = true
|
|
83
90
|
|
|
84
|
-
|
|
85
|
-
if (nodeType && nodeType === node.type) {
|
|
91
|
+
if (dispatch) {
|
|
86
92
|
tr.setNodeMarkup(pos, undefined, {
|
|
87
93
|
...node.attrs,
|
|
88
94
|
...attributes,
|
|
89
95
|
})
|
|
90
96
|
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (markType && node.marks.length) {
|
|
100
|
+
node.marks.forEach((mark: Mark) => {
|
|
101
|
+
if (markType === mark.type) {
|
|
102
|
+
canUpdate = true
|
|
91
103
|
|
|
92
|
-
|
|
93
|
-
node.marks.forEach((mark: Mark) => {
|
|
94
|
-
if (markType === mark.type) {
|
|
104
|
+
if (dispatch) {
|
|
95
105
|
const trimmedFrom2 = Math.max(pos, from)
|
|
96
106
|
const trimmedTo2 = Math.min(pos + node.nodeSize, to)
|
|
97
107
|
|
|
@@ -104,37 +114,37 @@ export const updateAttributes: RawCommands['updateAttributes'] =
|
|
|
104
114
|
}),
|
|
105
115
|
)
|
|
106
116
|
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
117
|
+
}
|
|
118
|
+
})
|
|
109
119
|
}
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (lastNode) {
|
|
125
|
+
if (lastPos !== undefined && dispatch) {
|
|
126
|
+
tr.setNodeMarkup(lastPos, undefined, {
|
|
127
|
+
...lastNode.attrs,
|
|
128
|
+
...attributes,
|
|
110
129
|
})
|
|
111
130
|
}
|
|
112
131
|
|
|
113
|
-
if (lastNode) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
trimmedTo,
|
|
127
|
-
markType.create({
|
|
128
|
-
...mark.attrs,
|
|
129
|
-
...attributes,
|
|
130
|
-
}),
|
|
131
|
-
)
|
|
132
|
-
}
|
|
133
|
-
})
|
|
134
|
-
}
|
|
132
|
+
if (markType && lastNode.marks.length) {
|
|
133
|
+
lastNode.marks.forEach((mark: Mark) => {
|
|
134
|
+
if (markType === mark.type && dispatch) {
|
|
135
|
+
tr.addMark(
|
|
136
|
+
trimmedFrom,
|
|
137
|
+
trimmedTo,
|
|
138
|
+
markType.create({
|
|
139
|
+
...mark.attrs,
|
|
140
|
+
...attributes,
|
|
141
|
+
}),
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
})
|
|
135
145
|
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
146
|
+
}
|
|
147
|
+
})
|
|
138
148
|
|
|
139
|
-
return
|
|
149
|
+
return canUpdate
|
|
140
150
|
}
|
|
@@ -34,8 +34,8 @@ function buildAttributeSpec(
|
|
|
34
34
|
): [string, Record<string, any>] {
|
|
35
35
|
const spec: Record<string, any> = {}
|
|
36
36
|
|
|
37
|
-
// Only include 'default' if the attribute is not required and default is
|
|
38
|
-
if (!extensionAttribute?.attribute?.isRequired && extensionAttribute?.attribute
|
|
37
|
+
// Only include 'default' if the attribute is not required and default is set on the attribute
|
|
38
|
+
if (!extensionAttribute?.attribute?.isRequired && 'default' in (extensionAttribute?.attribute || {})) {
|
|
39
39
|
spec.default = extensionAttribute.attribute.default
|
|
40
40
|
}
|
|
41
41
|
|
package/src/types.ts
CHANGED
|
@@ -442,17 +442,71 @@ export interface EditorOptions {
|
|
|
442
442
|
export type HTMLContent = string
|
|
443
443
|
|
|
444
444
|
/**
|
|
445
|
-
*
|
|
445
|
+
* A Tiptap JSON node or document. Tiptap JSON is the standard format for
|
|
446
|
+
* storing and manipulating Tiptap content. It is equivalent to the JSON
|
|
447
|
+
* representation of a Prosemirror node.
|
|
448
|
+
*
|
|
449
|
+
* Tiptap JSON documents are trees of nodes. The root node is usually of type
|
|
450
|
+
* `doc`. Nodes can have other nodes as children. Nodes can also have marks and
|
|
451
|
+
* attributes. Text nodes (nodes with type `text`) have a `text` property and no
|
|
452
|
+
* children.
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```ts
|
|
456
|
+
* const content: JSONContent = {
|
|
457
|
+
* type: 'doc',
|
|
458
|
+
* content: [
|
|
459
|
+
* {
|
|
460
|
+
* type: 'paragraph',
|
|
461
|
+
* content: [
|
|
462
|
+
* {
|
|
463
|
+
* type: 'text',
|
|
464
|
+
* text: 'Hello ',
|
|
465
|
+
* },
|
|
466
|
+
* {
|
|
467
|
+
* type: 'text',
|
|
468
|
+
* text: 'world',
|
|
469
|
+
* marks: [{ type: 'bold' }],
|
|
470
|
+
* },
|
|
471
|
+
* ],
|
|
472
|
+
* },
|
|
473
|
+
* ],
|
|
474
|
+
* }
|
|
475
|
+
* ```
|
|
446
476
|
*/
|
|
447
477
|
export type JSONContent = {
|
|
478
|
+
/**
|
|
479
|
+
* The type of the node
|
|
480
|
+
*/
|
|
448
481
|
type?: string
|
|
482
|
+
/**
|
|
483
|
+
* The attributes of the node. Attributes can have any JSON-serializable value.
|
|
484
|
+
*/
|
|
449
485
|
attrs?: Record<string, any> | undefined
|
|
486
|
+
/**
|
|
487
|
+
* The children of the node. A node can have other nodes as children.
|
|
488
|
+
*/
|
|
450
489
|
content?: JSONContent[]
|
|
490
|
+
/**
|
|
491
|
+
* A list of marks of the node. Inline nodes can have marks.
|
|
492
|
+
*/
|
|
451
493
|
marks?: {
|
|
494
|
+
/**
|
|
495
|
+
* The type of the mark
|
|
496
|
+
*/
|
|
452
497
|
type: string
|
|
498
|
+
/**
|
|
499
|
+
* The attributes of the mark. Attributes can have any JSON-serializable value.
|
|
500
|
+
*/
|
|
453
501
|
attrs?: Record<string, any>
|
|
454
502
|
[key: string]: any
|
|
455
503
|
}[]
|
|
504
|
+
/**
|
|
505
|
+
* The text content of the node. This property is only present on text nodes
|
|
506
|
+
* (i.e. nodes with `type: 'text'`).
|
|
507
|
+
*
|
|
508
|
+
* Text nodes cannot have children, but they can have marks.
|
|
509
|
+
*/
|
|
456
510
|
text?: string
|
|
457
511
|
[key: string]: any
|
|
458
512
|
}
|
|
@@ -103,6 +103,7 @@ export function parseIndentedBlocks(
|
|
|
103
103
|
break
|
|
104
104
|
} else if (currentLine.trim() === '') {
|
|
105
105
|
i += 1
|
|
106
|
+
totalRaw = `${totalRaw}${currentLine}\n`
|
|
106
107
|
continue
|
|
107
108
|
} else {
|
|
108
109
|
return undefined
|
|
@@ -188,6 +189,6 @@ export function parseIndentedBlocks(
|
|
|
188
189
|
|
|
189
190
|
return {
|
|
190
191
|
items,
|
|
191
|
-
raw: totalRaw
|
|
192
|
+
raw: totalRaw,
|
|
192
193
|
}
|
|
193
194
|
}
|