powerpagestoolkit 1.3.0 → 1.3.2

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/index.d.ts CHANGED
@@ -9,11 +9,37 @@ class DOMNodeReference {
9
9
  constructor(target: string): DOMNodeReference;
10
10
 
11
11
  target: string;
12
+ /**
13
+ * The element targeted when instantiating DOMNodeReference.
14
+ * Made available in order to perform normal DOM traversal,
15
+ * or access properties not available through this class.
16
+ * @type {HTMLElement | null}
17
+ */
12
18
  element: HTMLElement | null;
13
19
  isLoaded: boolean;
14
20
  visibilityController: HTMLElement | null;
15
21
  defaultDisplay: string;
22
+ /**
23
+ * The value of the element that this node represents
24
+ * stays in syncs with the live DOM elements via event handler
25
+ * @type {string | null}
26
+ */
16
27
  value: string | null;
28
+ /**
29
+ * Represents the 'yes' option of a boolean radio field.
30
+ * This property is only available when the parent node
31
+ * is a main field for a boolean radio input.
32
+ * @type {DOMNodeReference | undefined}
33
+ */
34
+ yesRadio?: DOMNodeReference;
35
+
36
+ /**
37
+ * Represents the 'no' option of a boolean radio field.
38
+ * This property is only available when the parent node
39
+ * is a main field for a boolean radio input.
40
+ * @type {DOMNodeReference | undefined}
41
+ */
42
+ noRadio?: DOMNodeReference;
17
43
 
18
44
  /**
19
45
  * Initializes the DOMNodeReference instance by waiting for the element to be available in the DOM.
@@ -34,16 +60,40 @@ class DOMNodeReference {
34
60
 
35
61
  /**
36
62
  * Sets the value of the HTML element.
37
- * @param {string} value - The value to set for the HTML element.
63
+ * @param {() => any} value - The value to set for the HTML element.
64
+ * for parents of boolean radios, pass true or false as value, or
65
+ * an expression returning a boolean
38
66
  */
39
67
  setValue(value: string): void;
40
68
 
69
+ /**
70
+ * Disables the element so that users cannot input any data
71
+ */
72
+ disable(): void;
73
+
74
+ /**
75
+ * Enables the element so that users can input data
76
+ */
77
+ enable(): void;
78
+
79
+ /**
80
+ * Prepends elements to the target
81
+ * @param {...HTMLElement} elements - The elements to prepend to the HTML element
82
+ */
83
+ prepend(...elements: HTMLElement[]): void;
84
+
41
85
  /**
42
86
  * Appends child elements to the HTML element.
43
87
  * @param {...HTMLElement} elements - The elements to append to the HTML element.
44
88
  */
45
89
  append(...elements: HTMLElement[]): void;
46
90
 
91
+ /**
92
+ * Inserts elements before the HTML element.
93
+ * @param {...HTMLElement} elements - The elements to insert before the HTML element.
94
+ */
95
+ before(...elements: HTMLElement[]): void;
96
+
47
97
  /**
48
98
  * Inserts elements after the HTML element.
49
99
  * @param {...HTMLElement} elements - The elements to insert after the HTML element.
@@ -52,9 +102,10 @@ class DOMNodeReference {
52
102
 
53
103
  /**
54
104
  * 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
105
+ * @returns {HTMLElement} The label element associated with this element.
106
+ * @throws {Error} Throws an error if the label cannot be found.
56
107
  */
57
- getLabel(): HTMLElement | null;
108
+ getLabel(): HTMLElement;
58
109
 
59
110
  /**
60
111
  * Appends child elements to the label associated with the HTML element.
@@ -63,39 +114,53 @@ class DOMNodeReference {
63
114
  appendToLabel(...elements: HTMLElement[]): void;
64
115
 
65
116
  /**
66
- * Adds a click event listener to the HTML element.
67
- * @param {Function} eventHandler - The function to execute when the element is clicked.
117
+ * Sets up an event listener based on the specified event type, executing the specified
118
+ * event handler
119
+ * @param {string} eventType - The DOM event to watch for
120
+ * @param {(this: DOMNodeReference, e: Event) => void} eventHandler - The callback function that runs when the
121
+ * specified event occurs
68
122
  */
69
- addClickListener(eventHandler: () => void): void;
70
-
71
- /**
72
- * Adds a change event listener to the HTML element.
73
- * @param {Function} eventHandler - The function to execute when the element's value changes.
74
- */
75
- addChangeListener(eventHandler: () => void): void;
76
-
123
+ on(eventType: string, eventHandler: (event: Event) => void): void;
77
124
  /**
78
125
  * Unchecks both the yes and no radio buttons if they exist.
79
126
  */
80
127
  uncheckRadios(): void;
81
128
 
82
129
  /**
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.
130
+ * 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.
131
+ *
132
+ * @param {function(this: DOMNodeReference): boolean} isRequired - A function that determines whether the field should be required. Returns `true` if required, `false` otherwise.
133
+ * @param {function(this: DOMNodeReference): boolean} isValid - A function that checks if the field's input is valid. Returns `true` if valid, `false` otherwise.
134
+ * @param {string} fieldDisplayName - The name of the field, used in error messages if validation fails.
135
+ * @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.
87
136
  */
88
- createValidation(
89
- evaluationFunction: (value: any) => boolean,
90
- fieldDisplayName: string
137
+ configureValidationAndRequirements(
138
+ isRequired: (this: this) => boolean,
139
+ isValid: (this: this) => boolean,
140
+ fieldDisplayName: string,
141
+ dependencies: Array<DOMNodeReference>
91
142
  ): void;
92
143
 
144
+ /**
145
+ * Sets the required level for the field by adding or removing the "required-field" class on the label.
146
+ *
147
+ * @param {boolean} isRequired - Determines whether the field should be marked as required.
148
+ * If true, the "required-field" class is added to the label; if false, it is removed.
149
+ */
150
+ setRequiredLevel(isRequired: boolean): void;
151
+
93
152
  /**
94
153
  * Adds a tooltip with specified text to the label associated with the HTML element.
95
154
  * @param {string} text - The text to display in the tooltip.
96
155
  */
97
156
  addLabelTooltip(text: string): void;
98
157
 
158
+ /**
159
+ * Adds a tooltip with the specified text to the element
160
+ * @param {string} text - The text to display in the tooltip
161
+ */
162
+ addTooltip(text: string): void;
163
+
99
164
  /**
100
165
  * Sets the inner HTML content of the HTML element.
101
166
  * @param {string} text - The text to set as the inner HTML of the element.
@@ -110,17 +175,19 @@ class DOMNodeReference {
110
175
  toggleVisibility(shouldShow: boolean): void;
111
176
 
112
177
  /**
178
+ * Configures conditional rendering for the target element based on a condition
179
+ * and the visibility of one or more trigger elements.
113
180
  *
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
181
+ * @param {(this: DOMNodeReference) => boolean} condition - A function that returns a boolean to determine
182
+ * the visibility of the target element. If `condition()` returns true, the element is shown;
183
+ * otherwise, it is hidden.
184
+ * @param {DOMNodeReference[]} triggerNodes - An array of `DOMNodeReference` instances. Event listeners are
185
+ * registered on each to toggle the visibility of the target element based on the `condition` and the visibility of
186
+ * the target node.
120
187
  */
121
188
  configureConditionalRendering(
122
- condition: () => boolean,
123
- triggerNode: DOMNodeReference
189
+ condition: (this: DOMNodeReference) => boolean,
190
+ triggerNodes: DOMNodeReference[]
124
191
  ): void;
125
192
 
126
193
  /**
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.2",
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
+ }