@augment-vir/web 31.73.4 → 32.0.0
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.
|
@@ -13,15 +13,23 @@
|
|
|
13
13
|
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
14
14
|
*/
|
|
15
15
|
export function getNestedChildren(startingElement, depth) {
|
|
16
|
-
return recursivelyGetNestedChildren(
|
|
16
|
+
return recursivelyGetNestedChildren({
|
|
17
|
+
startingElement,
|
|
18
|
+
maxDepth: depth ?? 0,
|
|
19
|
+
currentDepth: 0,
|
|
20
|
+
});
|
|
17
21
|
}
|
|
18
|
-
function recursivelyGetNestedChildren(startingElement, maxDepth, currentDepth) {
|
|
22
|
+
function recursivelyGetNestedChildren({ startingElement, maxDepth, currentDepth, }) {
|
|
19
23
|
const children = getDirectChildren(startingElement);
|
|
20
24
|
return children.flatMap((child) => {
|
|
21
25
|
const nextDepth = currentDepth + 1;
|
|
22
26
|
const nested = maxDepth && nextDepth >= maxDepth
|
|
23
27
|
? []
|
|
24
|
-
: recursivelyGetNestedChildren(
|
|
28
|
+
: recursivelyGetNestedChildren({
|
|
29
|
+
startingElement: child,
|
|
30
|
+
maxDepth,
|
|
31
|
+
currentDepth: nextDepth,
|
|
32
|
+
});
|
|
25
33
|
return [
|
|
26
34
|
child,
|
|
27
35
|
nested,
|
|
@@ -45,15 +53,23 @@ function recursivelyGetNestedChildren(startingElement, maxDepth, currentDepth) {
|
|
|
45
53
|
export function getNestedChildrenTree(startingElement, depth) {
|
|
46
54
|
return {
|
|
47
55
|
element: startingElement,
|
|
48
|
-
children: recursivelyGetNestedChildrenTree(
|
|
56
|
+
children: recursivelyGetNestedChildrenTree({
|
|
57
|
+
startingElement,
|
|
58
|
+
maxDepth: depth ?? 0,
|
|
59
|
+
currentDepth: 0,
|
|
60
|
+
}),
|
|
49
61
|
};
|
|
50
62
|
}
|
|
51
|
-
function recursivelyGetNestedChildrenTree(startingElement, maxDepth, currentDepth) {
|
|
63
|
+
function recursivelyGetNestedChildrenTree({ startingElement, maxDepth, currentDepth, }) {
|
|
52
64
|
return getDirectChildren(startingElement).map((child) => {
|
|
53
65
|
const nextDepth = currentDepth + 1;
|
|
54
66
|
const nested = maxDepth && nextDepth >= Math.abs(maxDepth)
|
|
55
67
|
? []
|
|
56
|
-
: recursivelyGetNestedChildrenTree(
|
|
68
|
+
: recursivelyGetNestedChildrenTree({
|
|
69
|
+
startingElement: child,
|
|
70
|
+
maxDepth,
|
|
71
|
+
currentDepth: nextDepth,
|
|
72
|
+
});
|
|
57
73
|
return {
|
|
58
74
|
element: child,
|
|
59
75
|
children: nested,
|
|
@@ -20,7 +20,12 @@ export function queryThroughShadow(element, rawQuery, options = {}) {
|
|
|
20
20
|
const query = check.isString(rawQuery) ? rawQuery : rawQuery.tagName;
|
|
21
21
|
const splitQuery = query.split(' ').filter(check.isTruthy);
|
|
22
22
|
if (splitQuery.length > 1) {
|
|
23
|
-
return handleNestedQueries(
|
|
23
|
+
return handleNestedQueries({
|
|
24
|
+
element,
|
|
25
|
+
originalQuery: query,
|
|
26
|
+
options,
|
|
27
|
+
queries: splitQuery,
|
|
28
|
+
});
|
|
24
29
|
}
|
|
25
30
|
else if ('shadowRoot' in element && element.shadowRoot) {
|
|
26
31
|
return queryThroughShadow(element.shadowRoot, query, options);
|
|
@@ -57,7 +62,7 @@ function getShadowRootChildren(element) {
|
|
|
57
62
|
.filter((child) => !!child.shadowRoot)
|
|
58
63
|
.map((child) => child.shadowRoot);
|
|
59
64
|
}
|
|
60
|
-
function handleNestedQueries(element, originalQuery, options, queries) {
|
|
65
|
+
function handleNestedQueries({ element, originalQuery, options, queries, }) {
|
|
61
66
|
const firstQuery = queries[0];
|
|
62
67
|
/**
|
|
63
68
|
* No way to intentionally trigger this edge case, we're just catching it here for type
|
|
@@ -74,12 +79,22 @@ function handleNestedQueries(element, originalQuery, options, queries) {
|
|
|
74
79
|
else if (check.isArray(results)) {
|
|
75
80
|
return results
|
|
76
81
|
.flatMap((result) => {
|
|
77
|
-
return handleNestedQueries(
|
|
82
|
+
return handleNestedQueries({
|
|
83
|
+
element: result,
|
|
84
|
+
originalQuery,
|
|
85
|
+
options,
|
|
86
|
+
queries: queries.slice(1),
|
|
87
|
+
});
|
|
78
88
|
})
|
|
79
89
|
.filter(check.isTruthy);
|
|
80
90
|
}
|
|
81
91
|
else if (results) {
|
|
82
|
-
return handleNestedQueries(
|
|
92
|
+
return handleNestedQueries({
|
|
93
|
+
element: results,
|
|
94
|
+
originalQuery,
|
|
95
|
+
options,
|
|
96
|
+
queries: queries.slice(1),
|
|
97
|
+
});
|
|
83
98
|
}
|
|
84
99
|
else {
|
|
85
100
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/web",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "32.0.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes only for web (frontend) JavaScript environments.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"test:update": "npm test"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@augment-vir/assert": "^
|
|
40
|
-
"@augment-vir/common": "^
|
|
41
|
-
"@date-vir/duration": "^8.
|
|
39
|
+
"@augment-vir/assert": "^32.0.0",
|
|
40
|
+
"@augment-vir/common": "^32.0.0",
|
|
41
|
+
"@date-vir/duration": "^8.6.1",
|
|
42
42
|
"html-spec-tags": "^2.2.3",
|
|
43
43
|
"type-fest": "^5.7.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@augment-vir/test": "^
|
|
46
|
+
"@augment-vir/test": "^32.0.0",
|
|
47
47
|
"bowser": "^2.14.1",
|
|
48
48
|
"typescript": "^6.0.3"
|
|
49
49
|
},
|