powerpagestoolkit 2.6.3101 → 2.6.3201

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 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, /* You can target an HTMLElement directly,
35
- or use standard querySelector syntax */
36
- multiple: (() => boolean) | boolean = false /* are you targeting a single
37
- element, or multiple? true = multiple. Default is false (single) */
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
- ```typescript
87
+ ```javascript
50
88
  // Create a single reference
51
- const node = await createRef("#myElement", false);
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, multiple = false, options = {
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,7 @@
1
1
  import DOMNodeReference from "./DOMNodeReference.js";
2
- export default function createDOMNodeReference(target: HTMLElement | string, multiple: true | (() => true), options?: {
3
- root?: HTMLElement;
4
- timeout?: number;
5
- }): Promise<DOMNodeReference[]>;
6
- export default function createDOMNodeReference(target: HTMLElement | string, multiple?: false | (() => false), options?: {
7
- root?: HTMLElement;
8
- timeout?: number;
2
+ export default function createDOMNodeReference(target: HTMLElement | string, options?: {
3
+ multiple?: false | undefined;
9
4
  }): Promise<DOMNodeReference>;
5
+ export default function createDOMNodeReference(target: HTMLElement | string, options?: {
6
+ multiple?: true;
7
+ }): Promise<DOMNodeReference[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powerpagestoolkit",
3
- "version": "2.6.3101",
3
+ "version": "2.6.3201",
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",