@tb-dev/prototype-dom 6.1.2 → 6.1.3
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.js +7 -27
- package/package.json +2 -4
package/dist/index.js
CHANGED
|
@@ -94,51 +94,31 @@
|
|
|
94
94
|
}
|
|
95
95
|
function waitChild() {
|
|
96
96
|
return function (selector, timeoutMillis = 300_000) {
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
return Promise.resolve(
|
|
97
|
+
let element = this.querySelector(selector);
|
|
98
|
+
if (element)
|
|
99
|
+
return Promise.resolve(element);
|
|
100
100
|
return new Promise((resolve, reject) => {
|
|
101
101
|
let timeout = null;
|
|
102
102
|
let interval = null;
|
|
103
|
-
|
|
104
|
-
const element = this.querySelector(selector);
|
|
105
|
-
if (element) {
|
|
106
|
-
onElementFound(element);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
for (const mutation of mutations) {
|
|
110
|
-
if (mutation.type !== 'childList')
|
|
111
|
-
continue;
|
|
112
|
-
for (const node of Array.from(mutation.addedNodes)) {
|
|
113
|
-
if (node instanceof Element && node.matches(`:has(${selector})`)) {
|
|
114
|
-
onElementFound(node);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
function onElementFound(element) {
|
|
103
|
+
function onElementFound(el) {
|
|
121
104
|
if (typeof timeout === 'number')
|
|
122
105
|
clearTimeout(timeout);
|
|
123
106
|
if (typeof interval === 'number')
|
|
124
107
|
clearInterval(interval);
|
|
125
|
-
|
|
126
|
-
resolve(element);
|
|
108
|
+
resolve(el);
|
|
127
109
|
}
|
|
128
110
|
function onInterval() {
|
|
129
|
-
|
|
111
|
+
element = this.querySelector(selector);
|
|
130
112
|
if (element)
|
|
131
113
|
onElementFound(element);
|
|
132
114
|
}
|
|
133
115
|
function onTimeout() {
|
|
134
116
|
if (typeof interval === 'number')
|
|
135
117
|
clearInterval(interval);
|
|
136
|
-
observer.disconnect();
|
|
137
118
|
reject(new Error(`timeout waiting for element: ${selector}`));
|
|
138
119
|
}
|
|
139
|
-
interval = setInterval(onInterval.bind(this),
|
|
120
|
+
interval = setInterval(onInterval.bind(this), 50);
|
|
140
121
|
timeout = setTimeout(onTimeout, timeoutMillis);
|
|
141
|
-
observer.observe(this, { childList: true, subtree: true });
|
|
142
122
|
});
|
|
143
123
|
};
|
|
144
124
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/prototype-dom",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.3",
|
|
4
4
|
"description": "Adds prototype methods to DOM objects",
|
|
5
5
|
"packageManager": "pnpm@8.15.4",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
27
27
|
"@tb-dev/eslint-config": "^2.1.1",
|
|
28
|
-
"@vitest/ui": "^1.3.1",
|
|
29
28
|
"eslint": "^8.57.0",
|
|
30
29
|
"husky": "^9.0.11",
|
|
31
30
|
"lint-staged": "^15.2.2",
|
|
@@ -34,8 +33,7 @@
|
|
|
34
33
|
"tslib": "^2.6.2",
|
|
35
34
|
"typedoc": "^0.25.9",
|
|
36
35
|
"typedoc-plugin-mdn-links": "^3.1.17",
|
|
37
|
-
"typescript": "5.3.3"
|
|
38
|
-
"vitest": "^1.3.1"
|
|
36
|
+
"typescript": "5.3.3"
|
|
39
37
|
},
|
|
40
38
|
"files": [
|
|
41
39
|
"dist/**/*"
|