powerpagestoolkit 2.5.411 → 2.5.4211

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
@@ -21,7 +21,7 @@ npm install powerpagestoolkit
21
21
 
22
22
  # Core Modules
23
23
 
24
- - ### DOMNodeReference
24
+ ### DOMNodeReference
25
25
 
26
26
  A powerful class for managing DOM elements with automatic value synchronization and event handling.
27
27
 
@@ -92,11 +92,11 @@ node.hide();
92
92
  node.show();
93
93
  ```
94
94
 
95
- ##### Advanced conditional rendering
95
+ **_Advanced conditional rendering_**
96
96
 
97
97
  Out of the box, Microsoft does not provide PowerPages developers the ability to hide or show fields or form elements based on the value of another field. This method allows such configurations
98
98
 
99
- - Method Signature
99
+ _Method signature:_
100
100
 
101
101
  ```typescript
102
102
  DOMNodeReference.configureConditionalRendering(
@@ -106,7 +106,7 @@ DOMNodeReference.configureConditionalRendering(
106
106
  ): DOMNodeReference
107
107
  ```
108
108
 
109
- - Method Implementation
109
+ _Example implementation:_
110
110
 
111
111
  ```typescript
112
112
  node.configureConditionalRendering(
@@ -125,6 +125,8 @@ node.configureConditionalRendering(
125
125
 
126
126
  This utility enhances PowerPages forms by adding dynamic field validation and conditional requirements based on other field values.
127
127
 
128
+ _Method signature:_
129
+
128
130
  ```typescript
129
131
  // Core method for setting up validation
130
132
  function configureValidationAndRequirements(
@@ -136,7 +138,7 @@ function configureValidationAndRequirements(
136
138
  method chaining */
137
139
  ```
138
140
 
139
- - Here's a practical example showing how to make a field required only when a "Yes" radio button is selected:
141
+ _Example implementation:_
140
142
 
141
143
  ```typescript
142
144
  node.configureValidationAndRequirements(
@@ -172,6 +174,9 @@ node.setValue(() => {
172
174
  // Sync with DOM
173
175
  node.updateValue();
174
176
 
177
+ // Clear the value for both the instance and the target element
178
+ node.clearValue()
179
+
175
180
  /****/ Content manipulation /****/
176
181
 
177
182
  node.setInnerHTML("<span>New content</span>");
@@ -213,11 +218,11 @@ node.addTooltip(
213
218
  );
214
219
  ```
215
220
 
216
- - ### DataVerse API
221
+ ### DataVerse API
217
222
 
218
- Type-safe wrapper for DataVerse API operations.
223
+ Perform secure API calls to DataVerse from your PowerPages site. This method implements the shell deferred token to send requests with `__RequestVerificationToken`
219
224
 
220
- #### Create Record
225
+ #### Create Records
221
226
 
222
227
  ```typescript
223
228
  await API.createRecord("accounts", {
@@ -277,18 +282,10 @@ node.configureConditionalRendering(
277
282
 
278
283
  3. Use TypeScript for better type safety and IntelliSense support.
279
284
 
280
- 4. Handle loading states:
285
+ 4. Use proper error handling with API operations:
281
286
 
282
287
  ```typescript
283
- node.onceLoaded((instance) => {
284
- // Safe to manipulate the element here
285
- });
286
- ```
287
-
288
- 5. Use proper error handling with API operations:
289
-
290
- ```typescript
291
- await API.createRecord(/*...*/)
288
+ /* optionally await */ API.createRecord(/*...*/)
292
289
  .then((recordId) => {})
293
290
  .catch((error) => {
294
291
  // handle your errors appropriately
@@ -306,3 +303,7 @@ Contributions are welcome, feel free to create a pull request with enhancements.
306
303
  ## License
307
304
 
308
305
  This project is licensed under the AGPL-3.0 License - see the [LICENSE](LICENSE) file for details.
306
+
307
+ ## Funding
308
+
309
+ If you like this project, found it useful, or would like to help support the long-term support of this package, please feel free to contribute via GitHub Sponsors: [Keaton-Brewster](https://github.com/sponsors/Keaton-Brewster)
@@ -13,7 +13,7 @@ export default class DOMNodeReference {
13
13
  * Made available in order to perform normal DOM traversal,
14
14
  * or access properties not available through this class.
15
15
  */
16
- element: Element;
16
+ element: HTMLElement;
17
17
  private visibilityController;
18
18
  checked: boolean;
19
19
  /**
@@ -41,11 +41,6 @@ export default class DOMNodeReference {
41
41
  */
42
42
  private _initValueSync;
43
43
  private _initDateSync;
44
- /**
45
- * Updates the value and checked state based on element type
46
- * @public
47
- */
48
- updateValue(): void;
49
44
  /**
50
45
  * Gets the current value of the element based on its type
51
46
  * @private
@@ -59,6 +54,12 @@ export default class DOMNodeReference {
59
54
  private _updateRadioGroup;
60
55
  private _attachVisibilityController;
61
56
  private _attachRadioButtons;
57
+ private _bindMethods;
58
+ /**
59
+ * Updates the value and checked state based on element type
60
+ * @public
61
+ */
62
+ updateValue(): void;
62
63
  /**
63
64
  * Sets up an event listener based on the specified event type, executing the specified
64
65
  * event handler
@@ -80,7 +81,7 @@ export default class DOMNodeReference {
80
81
  show(): DOMNodeReference;
81
82
  /**
82
83
  *
83
- * @param {function(instance: DOMNodeReference): boolean | boolean} shouldShow - Either a function that returns true or false,
84
+ * @param shouldShow - Either a function that returns true or false,
84
85
  * or a natural boolean to determine the visibility of this
85
86
  * @returns - Instance of this [provides option to method chain]
86
87
  */
@@ -100,12 +101,13 @@ export default class DOMNodeReference {
100
101
  disable(): DOMNodeReference;
101
102
  /**
102
103
  * Clears all values and states of the element.
103
- * Handles different input types appropriately.
104
+ * Handles different input types appropriately, and can be called
105
+ * on an element containing N child inputs to clear all
104
106
  *
105
107
  * @returns - Instance of this [provides option to method chain]
106
108
  * @throws If clearing values fails
107
109
  */
108
- clearValues(): Promise<DOMNodeReference>;
110
+ clearValue(): Promise<DOMNodeReference>;
109
111
  /**
110
112
  * Enables the element so that users can input data
111
113
  * @returns - Instance of this [provides option to method chain]
@@ -180,25 +182,25 @@ export default class DOMNodeReference {
180
182
  * Configures conditional rendering for the target element based on a condition
181
183
  * and the visibility of one or more trigger elements.
182
184
  *
183
- * @param {() => boolean} condition - A function that returns a boolean to determine
185
+ * @param condition - A function that returns a boolean to determine
184
186
  * the visibility of the target element. If `condition()` returns true, the element is shown;
185
187
  * otherwise, it is hidden.
186
- * @param {Array<DOMNodeReference>} [dependencies] - An array of `DOMNodeReference` instances. Event listeners are
188
+ * @param dependencies - An array of `DOMNodeReference` instances. Event listeners are
187
189
  * registered on each to toggle the visibility of the target element based on the `condition` and the visibility of
188
190
  * the target node.
189
- * @throws {ConditionalRenderingError} When there's an error in setting up conditional rendering
190
- * @returns {DOMNodeReference} - Instance of this [provides option to method chain]
191
+ * @throws - When there's an error in setting up conditional rendering
192
+ * @returns - Instance of this [provides option to method chain]
191
193
  */
192
194
  configureConditionalRendering(condition: () => boolean, dependencies?: Array<DOMNodeReference>, clearValuesOnHide?: boolean): DOMNodeReference;
193
195
  /**
194
196
  * Sets up validation and requirement rules for the field with enhanced error handling and dynamic updates.
195
197
  *
196
- * @param {() => boolean} isRequired - Function determining if field is required
197
- * @param {() => boolean} isValid - Function validating field input
198
- * @param {string} fieldDisplayName - Display name for error messages
199
- * @param {Array<DOMNodeReference>} dependencies - Fields that trigger requirement/validation updates
200
- * @returns {DOMNodeReference} Instance of this
201
- * @throws {ValidationConfigError} If validation setup fails
198
+ * @param isRequired - Function determining if field is required
199
+ * @param isValid - Function validating field input
200
+ * @param fieldDisplayName - Display name for error messages
201
+ * @param dependencies - Fields that trigger requirement/validation updates
202
+ * @returns - Instance of this
203
+ * @throws - If validation setup fails
202
204
  */
203
205
  configureValidationAndRequirements(isRequired: () => boolean, isValid: () => boolean, fieldDisplayName: string, dependencies: Array<DOMNodeReference>): DOMNodeReference;
204
206
  /**
@@ -212,7 +214,7 @@ export default class DOMNodeReference {
212
214
  /**
213
215
  * Sets the required level for the field by adding or removing the "required-field" class on the label.
214
216
  *
215
- * @param {Function | boolean} isRequired - Determines whether the field should be marked as required.
217
+ * @param isRequired - Determines whether the field should be marked as required.
216
218
  * If true, the "required-field" class is added to the label; if false, it is removed.
217
219
  * @returns - Instance of this [provides option to method chain]
218
220
  */
@@ -221,7 +223,8 @@ export default class DOMNodeReference {
221
223
  * Executes a callback function once the element is fully loaded.
222
224
  * If the element is already loaded, the callback is called immediately.
223
225
  * Otherwise, a MutationObserver is used to detect when the element is added to the DOM.
224
- * @param {Function} callback - A callback function to execute once the element is loaded.
226
+ * @param callback - A callback function to execute once the element is loaded.
227
+ * Receives instance of 'this' as an argument
225
228
  */
226
229
  onceLoaded(callback: (instance: DOMNodeReference) => any): any;
227
230
  }
package/dist/bundle.js CHANGED
@@ -250,7 +250,7 @@ var DOMNodeReference = class _DOMNodeReference {
250
250
  this.isLoaded = false;
251
251
  this.defaultDisplay = "";
252
252
  this.value = null;
253
- this.updateValue = this.updateValue.bind(this);
253
+ this._bindMethods();
254
254
  }
255
255
  async [_init]() {
256
256
  try {
@@ -266,8 +266,9 @@ var DOMNodeReference = class _DOMNodeReference {
266
266
  this._attachVisibilityController();
267
267
  this.defaultDisplay = this.visibilityController.style.display;
268
268
  this.isLoaded = true;
269
- } catch (e) {
270
- throw new DOMNodeInitializationError(this, e);
269
+ } catch (error) {
270
+ const errorMessage = error instanceof Error ? error.message : String(error);
271
+ throw new DOMNodeInitializationError(this, errorMessage);
271
272
  }
272
273
  }
273
274
  /**
@@ -315,18 +316,6 @@ var DOMNodeReference = class _DOMNodeReference {
315
316
  const dateNode = await waitFor("[data-date-format]", parentElement);
316
317
  dateNode.addEventListener("select", this.updateValue);
317
318
  }
318
- /**
319
- * Updates the value and checked state based on element type
320
- * @public
321
- */
322
- updateValue() {
323
- const elementValue = this._getElementValue();
324
- this.value = elementValue.value;
325
- if (elementValue.checked !== void 0) {
326
- this.checked = elementValue.checked;
327
- }
328
- this._updateRadioGroup();
329
- }
330
319
  /**
331
320
  * Gets the current value of the element based on its type
332
321
  * @private
@@ -401,6 +390,26 @@ var DOMNodeReference = class _DOMNodeReference {
401
390
  this.yesRadio = await createDOMNodeReference(`#${this.element.id}_1`);
402
391
  this.noRadio = await createDOMNodeReference(`#${this.element.id}_0`);
403
392
  }
393
+ _bindMethods() {
394
+ for (const key of Object.getOwnPropertyNames(Object.getPrototypeOf(this))) {
395
+ const value = this[key];
396
+ if (key !== "constructor" && typeof value === "function") {
397
+ this[key] = value.bind(this);
398
+ }
399
+ }
400
+ }
401
+ /**
402
+ * Updates the value and checked state based on element type
403
+ * @public
404
+ */
405
+ updateValue() {
406
+ const elementValue = this._getElementValue();
407
+ this.value = elementValue.value;
408
+ if (elementValue.checked !== void 0) {
409
+ this.checked = elementValue.checked;
410
+ }
411
+ this._updateRadioGroup();
412
+ }
404
413
  /**
405
414
  * Sets up an event listener based on the specified event type, executing the specified
406
415
  * event handler
@@ -441,7 +450,7 @@ var DOMNodeReference = class _DOMNodeReference {
441
450
  }
442
451
  /**
443
452
  *
444
- * @param {function(instance: DOMNodeReference): boolean | boolean} shouldShow - Either a function that returns true or false,
453
+ * @param shouldShow - Either a function that returns true or false,
445
454
  * or a natural boolean to determine the visibility of this
446
455
  * @returns - Instance of this [provides option to method chain]
447
456
  */
@@ -479,21 +488,23 @@ var DOMNodeReference = class _DOMNodeReference {
479
488
  disable() {
480
489
  try {
481
490
  this.element.disabled = true;
482
- } catch (e) {
491
+ } catch (error) {
492
+ const errorMessage = error instanceof Error ? error.message : String(error);
483
493
  throw new Error(
484
- `There was an error trying to disable the target: ${this.target}`
494
+ `There was an error trying to disable the target: ${this.target}: "${errorMessage}"`
485
495
  );
486
496
  }
487
497
  return this;
488
498
  }
489
499
  /**
490
500
  * Clears all values and states of the element.
491
- * Handles different input types appropriately.
501
+ * Handles different input types appropriately, and can be called
502
+ * on an element containing N child inputs to clear all
492
503
  *
493
504
  * @returns - Instance of this [provides option to method chain]
494
505
  * @throws If clearing values fails
495
506
  */
496
- async clearValues() {
507
+ async clearValue() {
497
508
  try {
498
509
  const element = this.element;
499
510
  if (element instanceof HTMLInputElement) {
@@ -532,16 +543,16 @@ var DOMNodeReference = class _DOMNodeReference {
532
543
  this.element.querySelectorAll("input, select, textarea")
533
544
  );
534
545
  if (childInputs.length > 0) {
535
- const clearPromises = childInputs.map(async (input) => {
546
+ const promises = childInputs.map(async (input) => {
536
547
  const inputRef = await createDOMNodeReference(input, false);
537
- return inputRef.clearValues();
548
+ return inputRef.clearValue();
538
549
  });
539
- await Promise.all(clearPromises);
550
+ await Promise.all(promises);
540
551
  }
541
552
  }
542
553
  if (this.yesRadio instanceof _DOMNodeReference && this.noRadio instanceof _DOMNodeReference) {
543
- await this.yesRadio.clearValues();
544
- await this.noRadio.clearValues();
554
+ await this.yesRadio.clearValue();
555
+ await this.noRadio.clearValue();
545
556
  }
546
557
  const events = [
547
558
  new Event("input", { bubbles: true }),
@@ -686,14 +697,14 @@ var DOMNodeReference = class _DOMNodeReference {
686
697
  * Configures conditional rendering for the target element based on a condition
687
698
  * and the visibility of one or more trigger elements.
688
699
  *
689
- * @param {() => boolean} condition - A function that returns a boolean to determine
700
+ * @param condition - A function that returns a boolean to determine
690
701
  * the visibility of the target element. If `condition()` returns true, the element is shown;
691
702
  * otherwise, it is hidden.
692
- * @param {Array<DOMNodeReference>} [dependencies] - An array of `DOMNodeReference` instances. Event listeners are
703
+ * @param dependencies - An array of `DOMNodeReference` instances. Event listeners are
693
704
  * registered on each to toggle the visibility of the target element based on the `condition` and the visibility of
694
705
  * the target node.
695
- * @throws {ConditionalRenderingError} When there's an error in setting up conditional rendering
696
- * @returns {DOMNodeReference} - Instance of this [provides option to method chain]
706
+ * @throws - When there's an error in setting up conditional rendering
707
+ * @returns - Instance of this [provides option to method chain]
697
708
  */
698
709
  configureConditionalRendering(condition, dependencies, clearValuesOnHide = true) {
699
710
  try {
@@ -728,12 +739,12 @@ var DOMNodeReference = class _DOMNodeReference {
728
739
  /**
729
740
  * Sets up validation and requirement rules for the field with enhanced error handling and dynamic updates.
730
741
  *
731
- * @param {() => boolean} isRequired - Function determining if field is required
732
- * @param {() => boolean} isValid - Function validating field input
733
- * @param {string} fieldDisplayName - Display name for error messages
734
- * @param {Array<DOMNodeReference>} dependencies - Fields that trigger requirement/validation updates
735
- * @returns {DOMNodeReference} Instance of this
736
- * @throws {ValidationConfigError} If validation setup fails
742
+ * @param isRequired - Function determining if field is required
743
+ * @param isValid - Function validating field input
744
+ * @param fieldDisplayName - Display name for error messages
745
+ * @param dependencies - Fields that trigger requirement/validation updates
746
+ * @returns - Instance of this
747
+ * @throws - If validation setup fails
737
748
  */
738
749
  configureValidationAndRequirements(isRequired, isValid, fieldDisplayName, dependencies) {
739
750
  if (!fieldDisplayName?.trim()) {
@@ -813,7 +824,7 @@ var DOMNodeReference = class _DOMNodeReference {
813
824
  const handleChange = () => {
814
825
  handler();
815
826
  if (clearValuesOnHide && window.getComputedStyle(this.visibilityController).display === "none") {
816
- this.clearValues();
827
+ this.clearValue();
817
828
  }
818
829
  };
819
830
  dep.on("change", handleChange);
@@ -845,7 +856,7 @@ var DOMNodeReference = class _DOMNodeReference {
845
856
  /**
846
857
  * Sets the required level for the field by adding or removing the "required-field" class on the label.
847
858
  *
848
- * @param {Function | boolean} isRequired - Determines whether the field should be marked as required.
859
+ * @param isRequired - Determines whether the field should be marked as required.
849
860
  * If true, the "required-field" class is added to the label; if false, it is removed.
850
861
  * @returns - Instance of this [provides option to method chain]
851
862
  */
@@ -862,7 +873,8 @@ var DOMNodeReference = class _DOMNodeReference {
862
873
  * Executes a callback function once the element is fully loaded.
863
874
  * If the element is already loaded, the callback is called immediately.
864
875
  * Otherwise, a MutationObserver is used to detect when the element is added to the DOM.
865
- * @param {Function} callback - A callback function to execute once the element is loaded.
876
+ * @param callback - A callback function to execute once the element is loaded.
877
+ * Receives instance of 'this' as an argument
866
878
  */
867
879
  onceLoaded(callback) {
868
880
  if (this.isLoaded) {
package/dist/waitFor.d.ts CHANGED
@@ -4,4 +4,4 @@
4
4
  * @param root optional parameter to replace document as the root from which to perform the node search
5
5
  * @returns
6
6
  */
7
- export default function waitFor(target: HTMLElement | string, root?: Element | Document): Promise<Element>;
7
+ export default function waitFor(target: HTMLElement | string, root?: HTMLElement | Document): Promise<HTMLElement>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powerpagestoolkit",
3
- "version": "2.5.411",
3
+ "version": "2.5.4211",
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",