@tiptap/core 2.3.1 → 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/dist/index.js
CHANGED
|
@@ -3546,28 +3546,30 @@ class NodePos {
|
|
|
3546
3546
|
}
|
|
3547
3547
|
querySelectorAll(selector, attributes = {}, firstItemOnly = false) {
|
|
3548
3548
|
let nodes = [];
|
|
3549
|
-
// iterate through children recursively finding all nodes which match the selector with the node name
|
|
3550
3549
|
if (!this.children || this.children.length === 0) {
|
|
3551
3550
|
return nodes;
|
|
3552
3551
|
}
|
|
3552
|
+
const attrKeys = Object.keys(attributes);
|
|
3553
|
+
/**
|
|
3554
|
+
* Finds all children recursively that match the selector and attributes
|
|
3555
|
+
* If firstItemOnly is true, it will return the first item found
|
|
3556
|
+
*/
|
|
3553
3557
|
this.children.forEach(childPos => {
|
|
3558
|
+
// If we already found a node and we only want the first item, we dont need to keep going
|
|
3559
|
+
if (firstItemOnly && nodes.length > 0) {
|
|
3560
|
+
return;
|
|
3561
|
+
}
|
|
3554
3562
|
if (childPos.node.type.name === selector) {
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
for (let index = 0; index < attrKeys.length; index += 1) {
|
|
3559
|
-
const key = attrKeys[index];
|
|
3560
|
-
if (nodeAttributes[key] !== attributes[key]) {
|
|
3561
|
-
return;
|
|
3562
|
-
}
|
|
3563
|
-
}
|
|
3564
|
-
}
|
|
3565
|
-
nodes.push(childPos);
|
|
3566
|
-
if (firstItemOnly) {
|
|
3567
|
-
return;
|
|
3563
|
+
const doesAllAttributesMatch = attrKeys.every(key => attributes[key] === childPos.node.attrs[key]);
|
|
3564
|
+
if (doesAllAttributesMatch) {
|
|
3565
|
+
nodes.push(childPos);
|
|
3568
3566
|
}
|
|
3569
3567
|
}
|
|
3570
|
-
|
|
3568
|
+
// If we already found a node and we only want the first item, we can stop here and skip the recursion
|
|
3569
|
+
if (firstItemOnly && nodes.length > 0) {
|
|
3570
|
+
return;
|
|
3571
|
+
}
|
|
3572
|
+
nodes = nodes.concat(childPos.querySelectorAll(selector, attributes, firstItemOnly));
|
|
3571
3573
|
});
|
|
3572
3574
|
return nodes;
|
|
3573
3575
|
}
|