powerpagestoolkit 1.3.0 → 1.3.4

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.
Files changed (4) hide show
  1. package/README.md +146 -32
  2. package/dist/index.bundle.js +467 -354
  3. package/index.d.ts +140 -42
  4. package/package.json +61 -38
package/index.d.ts CHANGED
@@ -8,12 +8,35 @@ class DOMNodeReference {
8
8
  */
9
9
  constructor(target: string): DOMNodeReference;
10
10
 
11
- target: string;
11
+ /**
12
+ * The element targeted when instantiating DOMNodeReference.
13
+ * Made available in order to perform normal DOM traversal,
14
+ * or access properties not available through this class.
15
+ * @type {HTMLElement | null}
16
+ */
12
17
  element: HTMLElement | null;
13
18
  isLoaded: boolean;
14
- visibilityController: HTMLElement | null;
15
- defaultDisplay: string;
19
+ /**
20
+ * The value of the element that this node represents
21
+ * stays in syncs with the live DOM elements via event handler
22
+ * @type {string | null}
23
+ */
16
24
  value: string | null;
25
+ /**
26
+ * Represents the 'yes' option of a boolean radio field.
27
+ * This property is only available when the parent node
28
+ * is a main field for a boolean radio input.
29
+ * @type {DOMNodeReference | undefined}
30
+ */
31
+ yesRadio?: DOMNodeReference;
32
+
33
+ /**
34
+ * Represents the 'no' option of a boolean radio field.
35
+ * This property is only available when the parent node
36
+ * is a main field for a boolean radio input.
37
+ * @type {DOMNodeReference | undefined}
38
+ */
39
+ noRadio?: DOMNodeReference;
17
40
 
18
41
  /**
19
42
  * Initializes the DOMNodeReference instance by waiting for the element to be available in the DOM.
@@ -24,104 +47,179 @@ class DOMNodeReference {
24
47
 
25
48
  /**
26
49
  * Hides the element by setting its display style to "none".
50
+ * @returns {DOMNodeReference} Returns 'this'
27
51
  */
28
- hide(): void;
52
+ hide(): DOMNodeReference;
29
53
 
30
54
  /**
31
55
  * Shows the element by restoring its default display style.
56
+ * @returns {DOMNodeReference} Returns 'this'
32
57
  */
33
- show(): void;
58
+ show(): DOMNodeReference;
34
59
 
35
60
  /**
36
61
  * Sets the value of the HTML element.
37
- * @param {string} value - The value to set for the HTML element.
62
+ * @param {() => any} value - The value to set for the HTML element.
63
+ * for parents of boolean radios, pass true or false as value, or
64
+ * an expression returning a boolean
65
+ * @returns {DOMNodeReference} Returns 'this'
66
+ */
67
+ setValue(value: string): DOMNodeReference;
68
+
69
+ /**
70
+ * Disables the element so that users cannot input any data
71
+ * @returns {DOMNodeReference} Returns 'this'
72
+ */
73
+ disable(): DOMNodeReference;
74
+
75
+ /**
76
+ * Enables the element so that users can input data
77
+ * @returns {DOMNodeReference} Returns 'this'
78
+ */
79
+ enable(): DOMNodeReference;
80
+
81
+ /**
82
+ * Prepends elements to the target
83
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to prepend to the HTML element
84
+ * @returns {DOMNodeReference} Returns 'this'
38
85
  */
39
- setValue(value: string): void;
86
+ prepend(...nodes: HTMLElement[] | DOMNodeReference[]): DOMNodeReference;
40
87
 
41
88
  /**
42
89
  * Appends child elements to the HTML element.
43
- * @param {...HTMLElement} elements - The elements to append to the HTML element.
90
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to append to the HTML element.
91
+ * @returns {DOMNodeReference} Returns 'this'
44
92
  */
45
- append(...elements: HTMLElement[]): void;
93
+ append(...nodes: HTMLElement[] | DOMNodeReference[]): DOMNodeReference;
94
+
95
+ /**
96
+ * Inserts elements before the HTML element.
97
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to insert before the HTML element.
98
+ * @returns {DOMNodeReference} Returns 'this'
99
+ */
100
+ before(...nodes: HTMLElement[] | DOMNodeReference[]): DOMNodeReference;
46
101
 
47
102
  /**
48
103
  * Inserts elements after the HTML element.
49
- * @param {...HTMLElement} elements - The elements to insert after the HTML element.
104
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to insert after the HTML element.
105
+ * @returns {DOMNodeReference} Returns 'this'
50
106
  */
51
- after(...elements: HTMLElement[]): void;
107
+ after(...nodes: HTMLElement[] | DOMNodeReference[]): DOMNodeReference;
52
108
 
53
109
  /**
54
110
  * Retrieves the label associated with the HTML element.
55
- * @returns {HTMLElement} The label element associated with this element, or **null** if no label element is present
111
+ * @returns {HTMLElement} The label element associated with this element.
112
+ * @throws {Error} Throws an error if the label cannot be found.
56
113
  */
57
- getLabel(): HTMLElement | null;
114
+ getLabel(): HTMLElement;
58
115
 
59
116
  /**
60
117
  * Appends child elements to the label associated with the HTML element.
61
118
  * @param {...HTMLElement} elements - The elements to append to the label.
119
+ * @returns {DOMNodeReference} Returns 'this'
62
120
  */
63
- appendToLabel(...elements: HTMLElement[]): void;
121
+ appendToLabel(...elements: HTMLElement[]): DOMNodeReference;
64
122
 
65
123
  /**
66
- * Adds a click event listener to the HTML element.
67
- * @param {Function} eventHandler - The function to execute when the element is clicked.
124
+ * Sets up an event listener based on the specified event type, executing the specified
125
+ * event handler
126
+ * @param {string} eventType - The DOM event to watch for
127
+ * @param {(this: DOMNodeReference, e: Event) => void} eventHandler - The callback function that runs when the
128
+ * specified event occurs
129
+ * @returns {DOMNodeReference} Returns 'this'
68
130
  */
69
- addClickListener(eventHandler: () => void): void;
131
+ on(eventType: string, eventHandler: (event: Event) => void): DOMNodeReference;
70
132
 
71
133
  /**
72
- * Adds a change event listener to the HTML element.
73
- * @param {Function} eventHandler - The function to execute when the element's value changes.
134
+ * Unchecks both the yes and no radio buttons if they exist.
135
+ * @returns {DOMNodeReference} Returns 'this'
74
136
  */
75
- addChangeListener(eventHandler: () => void): void;
137
+ uncheckRadios(): DOMNodeReference;
76
138
 
77
139
  /**
78
- * Unchecks both the yes and no radio buttons if they exist.
140
+ * Sets up validation and requirement rules for the field. This function dynamically updates the field's required status and validates its input based on the specified conditions.
141
+ *
142
+ * @param {function(this: DOMNodeReference): boolean} isRequired - A function that determines whether the field should be required. Returns `true` if required, `false` otherwise.
143
+ * @param {function(this: DOMNodeReference): boolean} isValid - A function that checks if the field's input is valid. Returns `true` if valid, `false` otherwise.
144
+ * @param {string} fieldDisplayName - The name of the field, used in error messages if validation fails.
145
+ * @param {Array<DOMNodeReference>} [dependencies] Other fields that this field’s requirement depends on. When these fields change, the required status of this field is re-evaluated. Make sure any DOMNodeReference used in `isRequired` or `isValid` is included in this array.
146
+ * @returns {DOMNodeReference} Returns 'this'
79
147
  */
80
- uncheckRadios(): void;
148
+ configureValidationAndRequirements(
149
+ isRequired: (this: this) => boolean,
150
+ isValid: (this: this) => boolean,
151
+ fieldDisplayName: string,
152
+ dependencies: Array<DOMNodeReference>
153
+ ): DOMNodeReference;
81
154
 
82
155
  /**
83
- * Creates a validation instance for the field.
84
- * @param {Function} evaluationFunction - The function used to evaluate the field.
85
- * @param {string} fieldDisplayName - The field name to display in error if validation
86
- * fails.
156
+ * Sets the required level for the field by adding or removing the "required-field" class on the label.
157
+ *
158
+ * @param {boolean} isRequired - Determines whether the field should be marked as required.
159
+ * If true, the "required-field" class is added to the label; if false, it is removed.
160
+ * @returns {DOMNodeReference} Returns 'this'
87
161
  */
88
- createValidation(
89
- evaluationFunction: (value: any) => boolean,
90
- fieldDisplayName: string
91
- ): void;
162
+ setRequiredLevel(isRequired: boolean): DOMNodeReference;
92
163
 
93
164
  /**
94
165
  * Adds a tooltip with specified text to the label associated with the HTML element.
95
166
  * @param {string} text - The text to display in the tooltip.
167
+ * @returns {DOMNodeReference} Returns 'this'
96
168
  */
97
- addLabelTooltip(text: string): void;
169
+ addLabelTooltip(text: string): DOMNodeReference;
170
+
171
+ /**
172
+ * Adds a tooltip with the specified text to the element
173
+ * @param {string} text - The text to display in the tooltip
174
+ * @returns {DOMNodeReference} Returns 'this'
175
+ */
176
+ addTooltip(text: string): DOMNodeReference;
98
177
 
99
178
  /**
100
179
  * Sets the inner HTML content of the HTML element.
101
180
  * @param {string} text - The text to set as the inner HTML of the element.
181
+ * @returns {DOMNodeReference} Returns 'this'
182
+ */
183
+ setInnerHTML(text: string): DOMNodeReference;
184
+
185
+ /**
186
+ * Removes the element from the DOM
187
+ * @returns {DOMNodeReference} Returns 'this'
188
+ */
189
+ remove(): DOMNodeReference;
190
+
191
+ /**
192
+ *
193
+ * @param {Partial<CSSStyleDeclaration>} options - An object with the style properties (keys) and updated styles (values)
194
+ * to apply to the this. {"key": "value"}
195
+ * @returns {DOMNodeReference} Returns 'this'
102
196
  */
103
- setTextContent(text: string): void;
197
+ setStyle(options: Partial<CSSStyleDeclaration>): DOMNodeReference;
104
198
 
105
199
  /**
106
200
  *
107
201
  * @param {boolean} shouldShow shows or hides the target
108
202
  * if = true => show, if = false => hide
203
+ * @returns {DOMNodeReference} Returns 'this'
109
204
  */
110
- toggleVisibility(shouldShow: boolean): void;
205
+ toggleVisibility(shouldShow: boolean): DOMNodeReference;
111
206
 
112
207
  /**
208
+ * Configures conditional rendering for the target element based on a condition
209
+ * and the visibility of one or more trigger elements.
113
210
  *
114
- * @param {Function} condition A Function that return a boolean value to set the
115
- * visibility of the targeted element. if condition() returns true, element is shown.
116
- * If false, element is hidden
117
- * @param {DOMNodeReference} triggerNode The DOMNodeReference to which an
118
- * event listener will be registered to change the visibility state of the calling
119
- * DOMNodeReference
211
+ * @param {(this: DOMNodeReference) => boolean} condition - A function that returns a boolean to determine
212
+ * the visibility of the target element. If `condition()` returns true, the element is shown;
213
+ * otherwise, it is hidden.
214
+ * @param {Array<DOMNodeReference>} dependencies - An array of `DOMNodeReference` instances. Event listeners are
215
+ * registered on each to toggle the visibility of the target element based on the `condition` and the visibility of
216
+ * the target node.
217
+ * @returns {DOMNodeReference} Returns 'this'
120
218
  */
121
219
  configureConditionalRendering(
122
- condition: () => boolean,
123
- triggerNode: DOMNodeReference
124
- ): void;
220
+ condition: (this: DOMNodeReference) => boolean,
221
+ dependencies: DOMNodeReference[]
222
+ ): DOMNodeReference;
125
223
 
126
224
  /**
127
225
  * Executes a callback function once the element is fully loaded.
package/package.json CHANGED
@@ -1,38 +1,61 @@
1
- {
2
- "name": "powerpagestoolkit",
3
- "version": "1.3.0",
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
- "main": "./dist/index.bundle.js",
6
- "types": "index.d.ts",
7
- "scripts": {
8
- "build": "webpack",
9
- "lint": "eslint ./src/JS/*"
10
- },
11
- "devDependencies": {
12
- "@babel/core": "^7.25.8",
13
- "@babel/node": "^7.26.0",
14
- "@babel/preset-env": "^7.25.8",
15
- "@types/node": "^22.8.0",
16
- "babel-loader": "^9.2.1",
17
- "clean-webpack-plugin": "^4.0.0",
18
- "css-loader": "^7.1.2",
19
- "eslint": "^8.57.1",
20
- "eslint-plugin-import": "^2.31.0",
21
- "style-loader": "^4.0.0",
22
- "terser-webpack-plugin": "^5.3.4",
23
- "typescript": "^5.6.3",
24
- "webpack": "^5.95.0",
25
- "webpack-cli": "^5.1.4"
26
- },
27
- "author": "KeatonBrewster",
28
- "license": "SSPL-1.0",
29
- "type": "module",
30
- "repository": {
31
- "type": "git",
32
- "url": "https://github.com/Keaton-Brewster/PowerPagesToolKit"
33
- },
34
- "files": [
35
- "dist",
36
- "index.d.ts"
37
- ]
38
- }
1
+ {
2
+ "name": "powerpagestoolkit",
3
+ "version": "1.3.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
+ "main": "./dist/index.bundle.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "build": "webpack",
9
+ "lint": "eslint ./src/JS/*"
10
+ },
11
+ "devDependencies": {
12
+ "@babel/core": "^7.25.8",
13
+ "@babel/node": "^7.26.0",
14
+ "@babel/preset-env": "^7.25.8",
15
+ "@types/node": "^22.8.0",
16
+ "babel-loader": "^9.2.1",
17
+ "clean-webpack-plugin": "^4.0.0",
18
+ "css-loader": "^7.1.2",
19
+ "eslint": "^8.57.1",
20
+ "eslint-plugin-import": "^2.31.0",
21
+ "style-loader": "^4.0.0",
22
+ "terser-webpack-plugin": "^5.3.4",
23
+ "typescript": "^5.6.3",
24
+ "webpack": "^5.95.0",
25
+ "webpack-cli": "^5.1.4"
26
+ },
27
+ "author": "KeatonBrewster",
28
+ "license": "SSPL-1.0",
29
+ "type": "module",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/Keaton-Brewster/PowerPagesToolKit"
33
+ },
34
+ "keywords": [
35
+ "powerpages",
36
+ "power pages",
37
+ "power platform",
38
+ "dynamics 365",
39
+ "power apps portal",
40
+ "dynamics 365 portal",
41
+ "portal",
42
+ "portal management",
43
+ "api",
44
+ "javascript",
45
+ "ajax",
46
+ "dataverse",
47
+ "dom-manipulation",
48
+ "node",
49
+ "http-request",
50
+ "json",
51
+ "rest-api",
52
+ "ajax-wrapper",
53
+ "form-management",
54
+ "frontend",
55
+ "web-development"
56
+ ],
57
+ "files": [
58
+ "dist",
59
+ "index.d.ts"
60
+ ]
61
+ }