powerpagestoolkit 2.6.3325 → 2.6.33311

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.
@@ -11,7 +11,7 @@ declare const _debounceTime: unique symbol;
11
11
  declare const _observers: unique symbol;
12
12
  declare const _boundEventListeners: unique symbol;
13
13
  export default class DOMNodeReference {
14
- target: HTMLElement | QuerySelector;
14
+ target: HTMLElement | string;
15
15
  root: HTMLElement;
16
16
  private [_debounceTime];
17
17
  private isLoaded;
@@ -187,7 +187,7 @@ export default class DOMNodeReference {
187
187
  remove(): this;
188
188
  /**
189
189
  *
190
- * @param {Partial<CSSStyleDeclaration} options and object containing the styles you want to set : {key: value} e.g.: {'display': 'block'}
190
+ * @param options and object containing the styles you want to set : {key: value} e.g.: {'display': 'block'}
191
191
  * @returns - Instance of this [provides option to method chain]
192
192
  */
193
193
  setStyle(options: Partial<CSSStyleDeclaration>): this;
package/dist/bundle.js CHANGED
@@ -481,7 +481,8 @@ var DOMNodeReference = class _DOMNodeReference {
481
481
  this.noRadio = await createDOMNodeReference(`#${this.element.id}_0`);
482
482
  }
483
483
  [_bindMethods]() {
484
- for (const key of Object.getOwnPropertyNames(Object.getPrototypeOf(this))) {
484
+ const prototype = Object.getPrototypeOf(this);
485
+ for (const key of Object.getOwnPropertyNames(prototype)) {
485
486
  const value = this[key];
486
487
  if (key !== "constructor" && typeof value === "function") {
487
488
  this[key] = value.bind(this);
@@ -579,7 +580,7 @@ var DOMNodeReference = class _DOMNodeReference {
579
580
  if (value instanceof Function) {
580
581
  value = value();
581
582
  }
582
- if (this.element.classList.contains("boolean-radio")) {
583
+ if (this.element.classList.contains("boolean-radio") && this.yesRadio instanceof _DOMNodeReference && this.noRadio instanceof _DOMNodeReference) {
583
584
  this.yesRadio.element.checked = value;
584
585
  this.noRadio.element.checked = !value;
585
586
  } else {
@@ -770,7 +771,7 @@ var DOMNodeReference = class _DOMNodeReference {
770
771
  }
771
772
  /**
772
773
  *
773
- * @param {Partial<CSSStyleDeclaration} options and object containing the styles you want to set : {key: value} e.g.: {'display': 'block'}
774
+ * @param options and object containing the styles you want to set : {key: value} e.g.: {'display': 'block'}
774
775
  * @returns - Instance of this [provides option to method chain]
775
776
  */
776
777
  setStyle(options) {
@@ -779,7 +780,8 @@ var DOMNodeReference = class _DOMNodeReference {
779
780
  `powerpagestoolkit: 'DOMNodeReference.setStyle' required options to be in the form of an object. Argument passed was of type: ${typeof options}`
780
781
  );
781
782
  }
782
- for (const key in options) {
783
+ for (const _key in options) {
784
+ const key = _key;
783
785
  this.element.style[key] = options[key];
784
786
  }
785
787
  return this;
@@ -1026,10 +1028,16 @@ var DOMNodeReference = class _DOMNodeReference {
1026
1028
  async function createDOMNodeReference(target, options = {
1027
1029
  multiple: false,
1028
1030
  root: document.body,
1029
- timeout: 1e3
1031
+ timeout: 0
1030
1032
  }) {
1031
- const { multiple = false, root = document.body, timeout = 1e3 } = options;
1032
1033
  try {
1034
+ if (typeof options !== "object") {
1035
+ throw new Error(
1036
+ `'options' must be of type 'object'. Received type: '${typeof options}'`
1037
+ );
1038
+ }
1039
+ validateOptions(options);
1040
+ const { multiple = false, root = document.body, timeout = 0 } = options;
1033
1041
  const isMultiple = typeof multiple === "function" ? multiple() : multiple;
1034
1042
  if (isMultiple) {
1035
1043
  if (typeof target !== "string") {
@@ -1054,6 +1062,33 @@ async function createDOMNodeReference(target, options = {
1054
1062
  throw new Error(e);
1055
1063
  }
1056
1064
  }
1065
+ function validateOptions(options) {
1066
+ const { multiple = false, root = document.body, timeout = 0 } = options;
1067
+ if (typeof multiple !== "boolean" && typeof multiple !== "function") {
1068
+ throw new Error(
1069
+ `'multiple' must be of type 'boolean' or 'function'. Received type: '${typeof multiple}'`
1070
+ );
1071
+ }
1072
+ if (typeof multiple === "function") {
1073
+ const value = multiple();
1074
+ if (typeof value !== "boolean") {
1075
+ throw new Error(
1076
+ `'multiple' function must return a boolean. Received type: '${typeof value}'`
1077
+ );
1078
+ }
1079
+ }
1080
+ if (!(root instanceof HTMLElement)) {
1081
+ throw new Error(
1082
+ `'root' must be of type 'HTMLElement'. Received type: '${typeof root}'`
1083
+ );
1084
+ }
1085
+ if (typeof timeout !== "number") {
1086
+ throw new Error(
1087
+ `'timeout' must be of type 'number'. Received type: '${typeof timeout}'`
1088
+ );
1089
+ }
1090
+ return;
1091
+ }
1057
1092
  function createProxyHandler() {
1058
1093
  return {
1059
1094
  get: (target, prop) => {
@@ -1,10 +1,10 @@
1
1
  import DOMNodeReference from "./DOMNodeReference.js";
2
- export default function createDOMNodeReference(target: HTMLElement | QuerySelector, options?: {
2
+ export default function createDOMNodeReference(target: HTMLElement | string, options?: {
3
3
  multiple?: (() => boolean) | false;
4
4
  root?: HTMLElement;
5
5
  timeout?: number;
6
6
  }): Promise<DOMNodeReference>;
7
- export default function createDOMNodeReference(target: HTMLElement | QuerySelector, options?: {
7
+ export default function createDOMNodeReference(target: string, options?: {
8
8
  multiple?: (() => true) | true;
9
9
  root?: HTMLElement;
10
10
  timeout?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powerpagestoolkit",
3
- "version": "2.6.3325",
3
+ "version": "2.6.33311",
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",