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