powerpagestoolkit 2.5.4111 → 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.
@@ -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
@@ -100,7 +101,8 @@ 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
@@ -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
@@ -479,16 +488,18 @@ 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
@@ -532,11 +543,11 @@ 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
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) {
@@ -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()) {
@@ -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.4111",
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",