@tiptap/core 2.3.0 → 2.3.2
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 +17 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -15
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +17 -15
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/NodePos.ts +19 -18
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/core",
|
|
3
3
|
"description": "headless rich text editor",
|
|
4
|
-
"version": "2.3.
|
|
4
|
+
"version": "2.3.2",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@tiptap/pm": "^2.3.
|
|
35
|
+
"@tiptap/pm": "^2.3.2"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@tiptap/pm": "^2.0.0"
|
package/src/NodePos.ts
CHANGED
|
@@ -64,7 +64,7 @@ export class NodePos {
|
|
|
64
64
|
this.editor.commands.insertContentAt({ from, to }, content)
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
get attributes()
|
|
67
|
+
get attributes(): { [key: string]: any } {
|
|
68
68
|
return this.node.attrs
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -200,34 +200,35 @@ export class NodePos {
|
|
|
200
200
|
querySelectorAll(selector: string, attributes: { [key: string]: any } = {}, firstItemOnly = false): NodePos[] {
|
|
201
201
|
let nodes: NodePos[] = []
|
|
202
202
|
|
|
203
|
-
// iterate through children recursively finding all nodes which match the selector with the node name
|
|
204
203
|
if (!this.children || this.children.length === 0) {
|
|
205
204
|
return nodes
|
|
206
205
|
}
|
|
206
|
+
const attrKeys = Object.keys(attributes)
|
|
207
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Finds all children recursively that match the selector and attributes
|
|
210
|
+
* If firstItemOnly is true, it will return the first item found
|
|
211
|
+
*/
|
|
208
212
|
this.children.forEach(childPos => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
+
// If we already found a node and we only want the first item, we dont need to keep going
|
|
214
|
+
if (firstItemOnly && nodes.length > 0) {
|
|
215
|
+
return
|
|
216
|
+
}
|
|
213
217
|
|
|
214
|
-
|
|
215
|
-
|
|
218
|
+
if (childPos.node.type.name === selector) {
|
|
219
|
+
const doesAllAttributesMatch = attrKeys.every(key => attributes[key] === childPos.node.attrs[key])
|
|
216
220
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
+
if (doesAllAttributesMatch) {
|
|
222
|
+
nodes.push(childPos)
|
|
221
223
|
}
|
|
224
|
+
}
|
|
222
225
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return
|
|
227
|
-
}
|
|
226
|
+
// If we already found a node and we only want the first item, we can stop here and skip the recursion
|
|
227
|
+
if (firstItemOnly && nodes.length > 0) {
|
|
228
|
+
return
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
nodes = nodes.concat(childPos.querySelectorAll(selector))
|
|
231
|
+
nodes = nodes.concat(childPos.querySelectorAll(selector, attributes, firstItemOnly))
|
|
231
232
|
})
|
|
232
233
|
|
|
233
234
|
return nodes
|