@tb-dev/prototype-dom 6.1.14 → 6.2.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 CHANGED
@@ -36,6 +36,15 @@ declare global {
36
36
  * @param valueFn Function that returns the value for each element.
37
37
  */
38
38
  queryAsMap: <T extends Element, K, V = T>(selector: string, keyFn: (element: T) => K, valueFn?: (element: T) => V) => Map<K, V>;
39
+ /**
40
+ * Wait for the first descendant element that matches the given selector to exist.
41
+ * Once found, scroll the element into view.
42
+ * @param selector CSS selector to match.
43
+ * @param options Options to customize the scrolling behavior.
44
+ */
45
+ scrollAsync: (selector: string, options?: {
46
+ timeout?: number;
47
+ } & ScrollIntoViewOptions) => Promise<void>;
39
48
  /**
40
49
  * Wait for the first descendant element that matches the given selector to exist.
41
50
  * @param selector CSS selector to match.
@@ -125,6 +134,15 @@ declare global {
125
134
  * @param valueFn Function that returns the value for each element.
126
135
  */
127
136
  queryAsMap: <T extends Element, K, V = T>(selector: string, keyFn: (element: T) => K, valueFn?: (element: T) => V) => Map<K, V>;
137
+ /**
138
+ * Wait for the first descendant element that matches the given selector to exist.
139
+ * Once found, scroll the element into view.
140
+ * @param selector CSS selector to match.
141
+ * @param options Options to customize the scrolling behavior.
142
+ */
143
+ scrollAsync: (selector: string, options?: {
144
+ timeout?: number;
145
+ } & ScrollIntoViewOptions) => Promise<void>;
128
146
  /**
129
147
  * Wait for the first descendant element that matches the given selector to exist.
130
148
  * @param selector CSS selector to match.
@@ -113,6 +113,18 @@
113
113
  return promise;
114
114
  };
115
115
  }
116
+ function scrollAsync() {
117
+ return async function(selector, options = {}) {
118
+ const { timeout, ...scrollOptions } = options;
119
+ const element2 = await this.waitChild(selector, timeout);
120
+ element2.scrollIntoView({
121
+ behavior: "smooth",
122
+ block: "center",
123
+ inline: "nearest",
124
+ ...scrollOptions
125
+ });
126
+ };
127
+ }
116
128
  const element = {
117
129
  getAttributeStrict,
118
130
  getAttributeAsFloatStrict,
@@ -124,6 +136,7 @@
124
136
  queryAsArray,
125
137
  queryAsSet,
126
138
  queryAsMap,
139
+ scrollAsync,
127
140
  waitChild
128
141
  };
129
142
 
@@ -164,6 +177,7 @@
164
177
  Document.prototype.queryAsArray = element.queryAsArray();
165
178
  Document.prototype.queryAsSet = element.queryAsSet();
166
179
  Document.prototype.queryAsMap = element.queryAsMap();
180
+ Document.prototype.scrollAsync = element.scrollAsync();
167
181
  Document.prototype.waitChild = element.waitChild();
168
182
  Element.prototype.getAttributeStrict = element.getAttributeStrict();
169
183
  Element.prototype.getAttributeAsFloatStrict = element.getAttributeAsFloatStrict();
@@ -175,6 +189,7 @@
175
189
  Element.prototype.queryAsArray = element.queryAsArray();
176
190
  Element.prototype.queryAsSet = element.queryAsSet();
177
191
  Element.prototype.queryAsMap = element.queryAsMap();
192
+ Element.prototype.scrollAsync = element.scrollAsync();
178
193
  Element.prototype.waitChild = element.waitChild();
179
194
  URLSearchParams.prototype.getStrict = urlSearchParams.getStrict();
180
195
  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.1.14",
3
+ "version": "6.2.0",
4
4
  "description": "Adds prototype methods to DOM objects",
5
5
  "license": "MIT",
6
6
  "type": "module",