powerpagestoolkit 2.6.3101 → 2.6.3212
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/README.md +66 -9
- package/dist/bundle.js +4 -3
- package/dist/createDOMNodeReferences.d.ts +6 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,31 +27,88 @@ A powerful class for managing DOM elements with automatic value synchronization
|
|
|
27
27
|
|
|
28
28
|
#### Basic Usage
|
|
29
29
|
|
|
30
|
-
DOMNodeReferences are instantiated with the help of the following factory function
|
|
30
|
+
DOMNodeReferences are instantiated with the help of the following factory function: `createRef`
|
|
31
31
|
|
|
32
32
|
```typescript
|
|
33
33
|
createRef(
|
|
34
|
-
target: HTMLElement | string,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
target: HTMLElement | string,
|
|
35
|
+
options: {
|
|
36
|
+
multiple: (() => boolean) | boolean = false,
|
|
37
|
+
root: HTMLElement,
|
|
38
|
+
timeout: number
|
|
39
|
+
}
|
|
38
40
|
): Promise<DOMNodeReference | DOMNodeReferenceArray>;
|
|
39
41
|
```
|
|
40
42
|
|
|
43
|
+
createRef takes two main arguments:
|
|
44
|
+
|
|
45
|
+
<table style="width: 100%; border-collapse: collapse;">
|
|
46
|
+
<thead>
|
|
47
|
+
<tr>
|
|
48
|
+
<th style="border: 1px solid #ddd; padding: 8px; text-align: left;">Property</th>
|
|
49
|
+
<th style="border: 1px solid #ddd; padding: 8px; text-align: left;">Type</th>
|
|
50
|
+
<th style="border: 1px solid #ddd; padding: 8px; text-align: left;">Details</th>
|
|
51
|
+
</tr>
|
|
52
|
+
</thead>
|
|
53
|
+
<tbody>
|
|
54
|
+
<tr>
|
|
55
|
+
<td style="border: 1px solid #ddd; padding: 8px;">target</td>
|
|
56
|
+
<td style="border: 1px solid #ddd; padding: 8px;">
|
|
57
|
+
<pre><code class="language-javascript">string | HTMLElement</code></pre>
|
|
58
|
+
</td>
|
|
59
|
+
<td style="border: 1px solid #ddd; padding: 8px;">
|
|
60
|
+
Use standard <code>querySelector</code> syntax to target an element, or elements in the DOM, or pass in an instance of the element itself to create a reference.
|
|
61
|
+
</td>
|
|
62
|
+
</tr>
|
|
63
|
+
<tr>
|
|
64
|
+
<td style="border: 1px solid #ddd; padding: 8px;">options</td>
|
|
65
|
+
<td style="border: 1px solid #ddd; padding: 8px;">
|
|
66
|
+
<pre><code class="language-javascript">{
|
|
67
|
+
multiple: () => boolean | boolean,
|
|
68
|
+
root: HTMLElement,
|
|
69
|
+
timeout: number
|
|
70
|
+
}</code></pre>
|
|
71
|
+
</td>
|
|
72
|
+
<td style="border: 1px solid #ddd; padding: 8px;">
|
|
73
|
+
Provides advanced configurations for niche scenarios, such as async DOM element loading, returning arrays of elements, or specifying the parent to search within for the target node.
|
|
74
|
+
</td>
|
|
75
|
+
</tr>
|
|
76
|
+
</tbody>
|
|
77
|
+
</table>
|
|
78
|
+
|
|
41
79
|
Import the utility function for creating DOMNodeReference(s)
|
|
42
80
|
|
|
43
81
|
```typescript
|
|
44
82
|
import { createRef } from "powerpagestoolkit";
|
|
45
83
|
```
|
|
46
84
|
|
|
47
|
-
Instantiate one, or multiple instances of a DOMNodeReference
|
|
85
|
+
Instantiate one, or multiple instances of a DOMNodeReference, and optionally configure advanced options
|
|
48
86
|
|
|
49
|
-
```
|
|
87
|
+
```javascript
|
|
50
88
|
// Create a single reference
|
|
51
|
-
const node = await createRef("#myElement"
|
|
89
|
+
const node = await createRef("#myElement");
|
|
52
90
|
|
|
53
91
|
// Create multiple references
|
|
54
|
-
const nodes = await createRef(".my-class", true);
|
|
92
|
+
const nodes = await createRef(".my-class", { multiple: true });
|
|
93
|
+
|
|
94
|
+
/******************/
|
|
95
|
+
// ADVANCED OPTIONS
|
|
96
|
+
// in the event that you need to be more granular with how you are targeting
|
|
97
|
+
// and retrieving elements, there are additional options
|
|
98
|
+
// If the node you are targeted is not available at the initial execution
|
|
99
|
+
// of the script, set a timeout for 2 seconds
|
|
100
|
+
const node2 = await createRef("#target", { timeout: 2000 });
|
|
101
|
+
|
|
102
|
+
// need to target a node within a specific node? use that node as the root
|
|
103
|
+
const otherElement = document.getElementById("id");
|
|
104
|
+
const node3 = await createRef("#target", { root: otherElement });
|
|
105
|
+
|
|
106
|
+
// implement all options:
|
|
107
|
+
const nodes2 = await createRef("#target", {
|
|
108
|
+
multiple: true,
|
|
109
|
+
timeout: 4000,
|
|
110
|
+
root: otherElement,
|
|
111
|
+
});
|
|
55
112
|
```
|
|
56
113
|
|
|
57
114
|
#### Properties
|
package/dist/bundle.js
CHANGED
|
@@ -649,7 +649,7 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
649
649
|
);
|
|
650
650
|
if (childInputs.length > 0) {
|
|
651
651
|
const promises = childInputs.map(async (input) => {
|
|
652
|
-
const inputRef = await createDOMNodeReference(input, false);
|
|
652
|
+
const inputRef = await createDOMNodeReference(input, { multiple: false });
|
|
653
653
|
return inputRef.clearValue();
|
|
654
654
|
});
|
|
655
655
|
await Promise.all(promises);
|
|
@@ -1022,11 +1022,12 @@ var DOMNodeReference = class _DOMNodeReference {
|
|
|
1022
1022
|
};
|
|
1023
1023
|
|
|
1024
1024
|
// src/createDOMNodeReferences.ts
|
|
1025
|
-
async function createDOMNodeReference(target,
|
|
1025
|
+
async function createDOMNodeReference(target, options = {
|
|
1026
|
+
multiple: false,
|
|
1026
1027
|
root: document.body,
|
|
1027
1028
|
timeout: 0
|
|
1028
1029
|
}) {
|
|
1029
|
-
const { root = document.body, timeout = 0 } = options;
|
|
1030
|
+
const { multiple = false, root = document.body, timeout = 0 } = options;
|
|
1030
1031
|
try {
|
|
1031
1032
|
const isMultiple = typeof multiple === "function" ? multiple() : multiple;
|
|
1032
1033
|
if (isMultiple) {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import DOMNodeReference from "./DOMNodeReference.js";
|
|
2
|
-
export default function createDOMNodeReference(target: HTMLElement | string,
|
|
2
|
+
export default function createDOMNodeReference(target: HTMLElement | string, options?: {
|
|
3
|
+
multiple?: (() => boolean) | false;
|
|
3
4
|
root?: HTMLElement;
|
|
4
5
|
timeout?: number;
|
|
5
|
-
}): Promise<DOMNodeReference
|
|
6
|
-
export default function createDOMNodeReference(target: HTMLElement | string,
|
|
6
|
+
}): Promise<DOMNodeReference>;
|
|
7
|
+
export default function createDOMNodeReference(target: HTMLElement | string, options?: {
|
|
8
|
+
multiple?: (() => true) | true;
|
|
7
9
|
root?: HTMLElement;
|
|
8
10
|
timeout?: number;
|
|
9
|
-
}): Promise<DOMNodeReference>;
|
|
11
|
+
}): Promise<DOMNodeReference[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "powerpagestoolkit",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.3212",
|
|
4
4
|
"description": "Reference, manipulate, and engage with Power Pages sites through the nodes in the DOM; use a variety of custom methods that allow customizing your power pages site quicker and easier. ",
|
|
5
5
|
"main": "./dist/bundle.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|