@tb-dev/prototype-dom 6.1.14 → 6.3.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.
- package/dist/index.d.ts +21 -0
- package/dist/index.iife.js +19 -0
- package/package.json +11 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
export declare interface ScrollAsyncOptions extends ScrollIntoViewOptions {
|
|
2
|
+
timeout?: number;
|
|
3
|
+
/** @default true */
|
|
4
|
+
throwOnTimeout?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
1
7
|
export { }
|
|
2
8
|
|
|
9
|
+
|
|
3
10
|
declare global {
|
|
4
11
|
interface Document {
|
|
5
12
|
/**
|
|
@@ -36,6 +43,13 @@ declare global {
|
|
|
36
43
|
* @param valueFn Function that returns the value for each element.
|
|
37
44
|
*/
|
|
38
45
|
queryAsMap: <T extends Element, K, V = T>(selector: string, keyFn: (element: T) => K, valueFn?: (element: T) => V) => Map<K, V>;
|
|
46
|
+
/**
|
|
47
|
+
* Wait for the first descendant element that matches the given selector to exist.
|
|
48
|
+
* Once found, scroll the element into view.
|
|
49
|
+
* @param selector CSS selector to match.
|
|
50
|
+
* @param options Options to customize the scrolling behavior.
|
|
51
|
+
*/
|
|
52
|
+
scrollAsync: (selector: string, options?: ScrollAsyncOptions) => Promise<void>;
|
|
39
53
|
/**
|
|
40
54
|
* Wait for the first descendant element that matches the given selector to exist.
|
|
41
55
|
* @param selector CSS selector to match.
|
|
@@ -125,6 +139,13 @@ declare global {
|
|
|
125
139
|
* @param valueFn Function that returns the value for each element.
|
|
126
140
|
*/
|
|
127
141
|
queryAsMap: <T extends Element, K, V = T>(selector: string, keyFn: (element: T) => K, valueFn?: (element: T) => V) => Map<K, V>;
|
|
142
|
+
/**
|
|
143
|
+
* Wait for the first descendant element that matches the given selector to exist.
|
|
144
|
+
* Once found, scroll the element into view.
|
|
145
|
+
* @param selector CSS selector to match.
|
|
146
|
+
* @param options Options to customize the scrolling behavior.
|
|
147
|
+
*/
|
|
148
|
+
scrollAsync: (selector: string, options?: ScrollAsyncOptions) => Promise<void>;
|
|
128
149
|
/**
|
|
129
150
|
* Wait for the first descendant element that matches the given selector to exist.
|
|
130
151
|
* @param selector CSS selector to match.
|
package/dist/index.iife.js
CHANGED
|
@@ -113,6 +113,22 @@
|
|
|
113
113
|
return promise;
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
+
function scrollAsync() {
|
|
117
|
+
return async function(selector, options = {}) {
|
|
118
|
+
const { timeout, throwOnTimeout = true, ...scrollOptions } = options;
|
|
119
|
+
try {
|
|
120
|
+
const element2 = await this.waitChild(selector, timeout);
|
|
121
|
+
element2.scrollIntoView({
|
|
122
|
+
behavior: "smooth",
|
|
123
|
+
block: "center",
|
|
124
|
+
inline: "nearest",
|
|
125
|
+
...scrollOptions
|
|
126
|
+
});
|
|
127
|
+
} catch (err) {
|
|
128
|
+
if (throwOnTimeout) throw err;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
116
132
|
const element = {
|
|
117
133
|
getAttributeStrict,
|
|
118
134
|
getAttributeAsFloatStrict,
|
|
@@ -124,6 +140,7 @@
|
|
|
124
140
|
queryAsArray,
|
|
125
141
|
queryAsSet,
|
|
126
142
|
queryAsMap,
|
|
143
|
+
scrollAsync,
|
|
127
144
|
waitChild
|
|
128
145
|
};
|
|
129
146
|
|
|
@@ -164,6 +181,7 @@
|
|
|
164
181
|
Document.prototype.queryAsArray = element.queryAsArray();
|
|
165
182
|
Document.prototype.queryAsSet = element.queryAsSet();
|
|
166
183
|
Document.prototype.queryAsMap = element.queryAsMap();
|
|
184
|
+
Document.prototype.scrollAsync = element.scrollAsync();
|
|
167
185
|
Document.prototype.waitChild = element.waitChild();
|
|
168
186
|
Element.prototype.getAttributeStrict = element.getAttributeStrict();
|
|
169
187
|
Element.prototype.getAttributeAsFloatStrict = element.getAttributeAsFloatStrict();
|
|
@@ -175,6 +193,7 @@
|
|
|
175
193
|
Element.prototype.queryAsArray = element.queryAsArray();
|
|
176
194
|
Element.prototype.queryAsSet = element.queryAsSet();
|
|
177
195
|
Element.prototype.queryAsMap = element.queryAsMap();
|
|
196
|
+
Element.prototype.scrollAsync = element.scrollAsync();
|
|
178
197
|
Element.prototype.waitChild = element.waitChild();
|
|
179
198
|
URLSearchParams.prototype.getStrict = urlSearchParams.getStrict();
|
|
180
199
|
URLSearchParams.prototype.getAsInteger = urlSearchParams.getAsInteger();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/prototype-dom",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "Adds prototype methods to DOM objects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
"*.{?(c|m)@(j|t)s,css,vue,md,json}": "prettier --write"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@tb-dev/eslint-config": "^5.2
|
|
26
|
-
"eslint": "^9.
|
|
27
|
-
"husky": "^9.1.
|
|
28
|
-
"lint-staged": "^15.2.
|
|
25
|
+
"@tb-dev/eslint-config": "^5.3.2",
|
|
26
|
+
"eslint": "^9.10.0",
|
|
27
|
+
"husky": "^9.1.6",
|
|
28
|
+
"lint-staged": "^15.2.10",
|
|
29
29
|
"prettier": "^3.3.3",
|
|
30
|
-
"tslib": "^2.
|
|
31
|
-
"typedoc": "^0.26.
|
|
32
|
-
"typedoc-plugin-mdn-links": "^3.2.
|
|
33
|
-
"typescript": "^5.
|
|
34
|
-
"vite": "^5.4.
|
|
35
|
-
"vite-plugin-dts": "^4.
|
|
30
|
+
"tslib": "^2.7.0",
|
|
31
|
+
"typedoc": "^0.26.7",
|
|
32
|
+
"typedoc-plugin-mdn-links": "^3.2.12",
|
|
33
|
+
"typescript": "^5.6.2",
|
|
34
|
+
"vite": "^5.4.5",
|
|
35
|
+
"vite-plugin-dts": "^4.2.1"
|
|
36
36
|
},
|
|
37
37
|
"files": [
|
|
38
38
|
"dist/**/*"
|