powerpagestoolkit 1.3.2 → 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.
package/README.md CHANGED
@@ -59,8 +59,15 @@ target: HTMLElement | string;
59
59
  element: HTMLElement;
60
60
  isLoaded: boolean;
61
61
  value: any;
62
+ /**
63
+ * If the element targeted is the main input for a yes/no radio control,
64
+ * yesRadio and noRadio will be available as properties of 'this'
65
+ */
62
66
  yesRadio: DOMNodeReference;
63
67
  noRadio: DOMNodeReference;
68
+ // and if 'this' is the instance of a yesRadio or noRadio
69
+ // checked will represent wether the radio has been checked or not
70
+ checked: boolean;
64
71
  ```
65
72
 
66
73
  ##### Methods
@@ -85,19 +92,22 @@ show()
85
92
  toggleVisibility(shouldShow: boolean | () => boolean)
86
93
 
87
94
  /**
88
- * Configures conditional rendering for the target element based on a condition
89
- * and the visibility of one or more trigger elements.
95
+ * Configures conditional rendering for the target element
96
+ * based on a condition and the visibility of one or more trigger elements.
90
97
  *
91
- * @param {(this: DOMNodeReference) => boolean} condition - A function that returns a boolean to determine
92
- * the visibility of the target element. If `condition()` returns true, the element is shown;
93
- * otherwise, it is hidden.
94
- * @param {DOMNodeReference[]} triggerNodes - An array of `DOMNodeReference` instances. Event listeners are
95
- * registered on each to toggle the visibility of the target element based on the `condition` and the visibility of
96
- * the target node.
98
+ * @param {(this: DOMNodeReference) => boolean} condition -
99
+ * A function that returns a boolean to determine the visibility
100
+ * of the target element. If `condition()` returns true, the
101
+ * element is shown; otherwise, it is hidden.
102
+ * @param {Array<DOMNodeReference>} dependencies - An array
103
+ * of `DOMNodeReference` instances. Event listeners are
104
+ * registered on each to toggle the visibility of the
105
+ * target element based on the `condition` and the
106
+ * visibility of the target node.
97
107
  */
98
108
  configureConditionalRendering(
99
109
  condition: (this: DOMNodeReference) => boolean,
100
- triggerNodes: DOMNodeReference[]
110
+ dependencies: Array<DOMNodeReference>
101
111
  )
102
112
 
103
113
 
@@ -106,18 +116,36 @@ configureConditionalRendering(
106
116
  const other_node = await createDOMNodeReference(".element_class")
107
117
 
108
118
  your_node.configureConditionalRendering(() =>
109
- other_node.value == "3", // your_node will only be visible when the value of other_node is "3"
110
- [other_node] // and we have to include any DOMNodeReferences used in the evaluation logic, so that changes to them can be watched and the condition evaluated again
119
+ other_node.value == "3",
120
+ /* your_node will only be
121
+ visible when the value of other_node is "3"
122
+ */
123
+ [other_node]
124
+ /* and we have to include any DOMNodeReferences used
125
+ in the evaluation logic, so that changes to them can
126
+ be watched and the condition evaluated again
127
+ */
111
128
  );
112
129
 
113
130
 
114
131
  /**
115
- * 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.
132
+ * Sets up validation and requirement rules for the field.
133
+ * This function dynamically updates the field's required status
134
+ * and validates its input based on the specified conditions.
116
135
  *
117
- * @param {function(this: DOMNodeReference): boolean} isRequired - A function that determines whether the field should be required. Returns `true` if required, `false` otherwise.
118
- * @param {function(this: DOMNodeReference): boolean} isValid - A function that checks if the field's input is valid. Returns `true` if valid, `false` otherwise.
119
- * @param {string} fieldDisplayName - The name of the field, used in error messages if validation fails.
120
- * @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.
136
+ * @param {function(this: DOMNodeReference): boolean} isRequired
137
+ * A function that determines whether the field should be required.
138
+ * Return `true` if required, `false` to not be required.
139
+ * @param {function(this: DOMNodeReference): boolean} isValid
140
+ * A function that checks if the field's input is valid.
141
+ * Return `true` if validation satisfied, `false` if not.
142
+ * @param {string} fieldDisplayName - The name of the field, used
143
+ * in error messages if validation fails.
144
+ * @param {Array<DOMNodeReference>} [dependencies]
145
+ * Other fields that this field’s requirement depends on. When
146
+ * these Nodes or their values change, the required status
147
+ * of this field is re-evaluated. Make sure any DOMNodeReference
148
+ * used in `isRequired` or `isValid` is included in this array.
121
149
  */
122
150
  configureValidationAndRequirements(
123
151
  isRequired: (this: this) => boolean,
@@ -131,18 +159,32 @@ configureValidationAndRequirements(
131
159
  const other_node = await createDOMNodeReference(".element_class")
132
160
 
133
161
  your_node.configureValidationAndRequirements(
134
- () => other_node.yesRadio.checked, // if 'yes' is checked for this other node, this function will evaluate to true, meaning that 'your_node' will be required
135
- function () { // important to use standard 'function' declaration, instead of arrow function when needing to access 'this' (the instance of 'your_node')
136
- if (other_node.yesRadio.checked) { // when other_node radio is checked 'yes'
162
+ () => other_node.yesRadio.checked,
163
+ /* if 'yes' is checked for this other node,
164
+ this function will evaluate to true,
165
+ meaning that 'your_node' will be required */
166
+
167
+ function () {
168
+ /* important to use standard 'function' declaration,
169
+ instead of arrow function when needing to
170
+ access 'this' (the instance of 'your_node') */
171
+
172
+ if (other_node.yesRadio.checked) {
173
+ // when other_node radio is checked 'yes'
137
174
  return this.value; // this is only 'valid' if it has a value
138
175
  } else return true;
139
176
  },
140
177
  "Your Field Name",
141
- [other_node] // since our conditions depend on 'other_node' it must be included in the dependency array so that the requirement conditions can be re-evaluated when the value of 'other_node' changes
178
+ [other_node]
179
+ /* since our conditions depend on
180
+ 'other_node' it must be included in the dependency
181
+ array so that the requirement conditions can be
182
+ re-evaluated when the value of 'other_node' changes */
142
183
  );
143
184
 
144
185
 
145
- // sets the elements 'disabled' to true - useful for inputs that need to be enabled/disabled conditionally
186
+ /* sets the elements 'disabled' to true - useful for inputs
187
+ that need to be enabled/disabled conditionally */
146
188
  disable()
147
189
 
148
190
  // Sets the element 'disabled' to false
@@ -158,6 +200,9 @@ setValue(value: any)
158
200
  // Sets the inner HTML content of the associated HTML element.
159
201
  setTextContent(text: string)
160
202
 
203
+ // set any style attribute for 'this' with standard CSS style declaration
204
+ setStyle(options: Partial<CSSStyleDeclaration>): void;
205
+
161
206
  // Appends child elements to the associated HTML element.
162
207
  append(...elements: HTMLElement[])
163
208
 
@@ -177,9 +222,6 @@ on(eventType: string, eventHandler: (this: DOMNodeReference) => void)
177
222
  // Unchecks both yes and no radio buttons if they exist.
178
223
  uncheckRadios()
179
224
 
180
- //Creates a validation instance for the field.
181
- createValidation(evaluationFunction: () => boolean, fieldDisplayName: string)
182
-
183
225
  // Adds a tooltip to the label associated with the HTML element.
184
226
  addLabelTooltip(text: string)
185
227
 
@@ -815,7 +815,7 @@ var DOMNodeReference = /*#__PURE__*/function () {
815
815
  case 10:
816
816
  this._initValueSync();
817
817
  this._attachVisibilityController();
818
- this.defaultDisplay = this.visibilityController.style.display;
818
+ this.defaultDisplay = this.visibilityController.style.display || "inline-block";
819
819
  this.isLoaded = true;
820
820
  _context.next = 19;
821
821
  break;
@@ -935,16 +935,19 @@ var DOMNodeReference = /*#__PURE__*/function () {
935
935
  key: "on",
936
936
  value: function on(eventType, eventHandler) {
937
937
  this.element.addEventListener(eventType, eventHandler.bind(this));
938
+ return this;
938
939
  }
939
940
  }, {
940
941
  key: "hide",
941
942
  value: function hide() {
942
943
  this.visibilityController.style.display = "none";
944
+ return this;
943
945
  }
944
946
  }, {
945
947
  key: "show",
946
948
  value: function show() {
947
949
  this.visibilityController.style.display = this.defaultDisplay;
950
+ return this;
948
951
  }
949
952
  }, {
950
953
  key: "toggleVisibility",
@@ -954,6 +957,7 @@ var DOMNodeReference = /*#__PURE__*/function () {
954
957
  } else {
955
958
  shouldShow ? this.show() : this.hide();
956
959
  }
960
+ return this;
957
961
  }
958
962
  }, {
959
963
  key: "setValue",
@@ -964,6 +968,7 @@ var DOMNodeReference = /*#__PURE__*/function () {
964
968
  } else {
965
969
  this.element.value = value;
966
970
  }
971
+ return this;
967
972
  }
968
973
  }, {
969
974
  key: "disable",
@@ -973,6 +978,7 @@ var DOMNodeReference = /*#__PURE__*/function () {
973
978
  } catch (e) {
974
979
  throw new Error("There was an error trying to disable the target: ".concat(this.target));
975
980
  }
981
+ return this;
976
982
  }
977
983
  }, {
978
984
  key: "enable",
@@ -982,18 +988,71 @@ var DOMNodeReference = /*#__PURE__*/function () {
982
988
  } catch (e) {
983
989
  throw new Error("There was an error trying to disable the target: ".concat(this.target));
984
990
  }
991
+ return this;
992
+ }
993
+ }, {
994
+ key: "prepend",
995
+ value: function prepend() {
996
+ var _this = this;
997
+ for (var _len = arguments.length, nodes = new Array(_len), _key = 0; _key < _len; _key++) {
998
+ nodes[_key] = arguments[_key];
999
+ }
1000
+ nodes.forEach(function (node) {
1001
+ if (node instanceof DOMNodeReference) {
1002
+ _this.element.prepend(node.element);
1003
+ } else {
1004
+ _this.element.prepend(node);
1005
+ }
1006
+ });
1007
+ return this;
985
1008
  }
986
1009
  }, {
987
1010
  key: "append",
988
1011
  value: function append() {
989
- var _this$element;
990
- (_this$element = this.element).append.apply(_this$element, arguments);
1012
+ var _this2 = this;
1013
+ for (var _len2 = arguments.length, nodes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1014
+ nodes[_key2] = arguments[_key2];
1015
+ }
1016
+ nodes.forEach(function (node) {
1017
+ if (node instanceof DOMNodeReference) {
1018
+ _this2.element.append(node.element);
1019
+ } else {
1020
+ _this2.element.append(node);
1021
+ }
1022
+ });
1023
+ return this;
1024
+ }
1025
+ }, {
1026
+ key: "before",
1027
+ value: function before() {
1028
+ var _this3 = this;
1029
+ for (var _len3 = arguments.length, nodes = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1030
+ nodes[_key3] = arguments[_key3];
1031
+ }
1032
+ nodes.forEach(function (node) {
1033
+ if (node instanceof DOMNodeReference) {
1034
+ _this3.element.before(node.element);
1035
+ } else {
1036
+ _this3.element.before(node);
1037
+ }
1038
+ });
1039
+ return this;
991
1040
  }
992
1041
  }, {
993
1042
  key: "after",
994
1043
  value: function after() {
995
- var _this$element2;
996
- (_this$element2 = this.element).after.apply(_this$element2, arguments);
1044
+ var _this4 = this;
1045
+ for (var _len4 = arguments.length, nodes = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1046
+ nodes[_key4] = arguments[_key4];
1047
+ }
1048
+ nodes.forEach(function (node) {
1049
+ if (node instanceof DOMNodeReference) {
1050
+ _this4.element.after(node.element);
1051
+ } else {
1052
+ _this4.element.after(node);
1053
+ }
1054
+ });
1055
+ return this;
997
1056
  }
998
1057
  }, {
999
1058
  key: "getLabel",
@@ -1005,26 +1064,48 @@ var DOMNodeReference = /*#__PURE__*/function () {
1005
1064
  value: function appendToLabel() {
1006
1065
  var label = this.getLabel();
1007
1066
  if (label) {
1008
- for (var _len = arguments.length, elements = new Array(_len), _key = 0; _key < _len; _key++) {
1009
- elements[_key] = arguments[_key];
1067
+ for (var _len5 = arguments.length, elements = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
1068
+ elements[_key5] = arguments[_key5];
1010
1069
  }
1011
1070
  label.append.apply(label, [" "].concat(elements));
1012
1071
  }
1072
+ return this;
1013
1073
  }
1014
1074
  }, {
1015
1075
  key: "addLabelTooltip",
1016
1076
  value: function addLabelTooltip(text) {
1017
1077
  this.appendToLabel(CreateInfoEl(text));
1078
+ return this;
1018
1079
  }
1019
1080
  }, {
1020
- key: "addToolTip",
1021
- value: function addToolTip(text) {
1081
+ key: "addTooltip",
1082
+ value: function addTooltip(text) {
1022
1083
  this.append(CreateInfoEl(text));
1084
+ return this;
1085
+ }
1086
+ }, {
1087
+ key: "setInnerHTML",
1088
+ value: function setInnerHTML(string) {
1089
+ this.element.innerHTML = string;
1090
+ return this;
1091
+ }
1092
+ }, {
1093
+ key: "remove",
1094
+ value: function remove() {
1095
+ this.element.remove();
1096
+ return this;
1023
1097
  }
1024
1098
  }, {
1025
- key: "setTextContent",
1026
- value: function setTextContent(text) {
1027
- this.element.innerHTML = text;
1099
+ key: "setStyle",
1100
+ value: function setStyle(options) {
1101
+ var _this5 = this;
1102
+ if (Object.prototype.toString.call(options) !== "[object Object]") {
1103
+ throw new Error("powerpagestoolkit: 'DOMNodeReference.setStyle' required options to be in the form of an object. Argument passed was of type: ".concat(DOMNodeReferences_typeof(options)));
1104
+ }
1105
+ Object.keys(options).forEach(function (key) {
1106
+ _this5.element.style[key] = options[key];
1107
+ });
1108
+ return this;
1028
1109
  }
1029
1110
  }, {
1030
1111
  key: "uncheckRadios",
@@ -1035,22 +1116,23 @@ var DOMNodeReference = /*#__PURE__*/function () {
1035
1116
  } else {
1036
1117
  console.error("[SYNACT] Attempted to uncheck radios for an element that has no radios");
1037
1118
  }
1119
+ return this;
1038
1120
  }
1039
1121
  }, {
1040
1122
  key: "configureConditionalRendering",
1041
1123
  value: function configureConditionalRendering(condition, triggerNodes) {
1042
- var _this = this;
1124
+ var _this6 = this;
1043
1125
  try {
1044
1126
  this.toggleVisibility(condition(this));
1045
1127
  if (triggerNodes) {
1046
1128
  var nodes = Array.isArray(triggerNodes) ? triggerNodes : [triggerNodes];
1047
1129
  nodes.forEach(function (node) {
1048
1130
  node.on("change", function () {
1049
- return _this.toggleVisibility(condition(_this));
1131
+ return _this6.toggleVisibility(condition(_this6));
1050
1132
  });
1051
1133
  var observer = new MutationObserver(function () {
1052
1134
  var display = window.getComputedStyle(node.visibilityController).display;
1053
- _this.toggleVisibility(display !== "none" && condition(_this));
1135
+ _this6.toggleVisibility(display !== "none" && condition(_this6));
1054
1136
  });
1055
1137
  observer.observe(node.visibilityController, {
1056
1138
  attributes: true,
@@ -1061,11 +1143,12 @@ var DOMNodeReference = /*#__PURE__*/function () {
1061
1143
  } catch (e) {
1062
1144
  throw new ConditionalRenderingError(this, e);
1063
1145
  }
1146
+ return this;
1064
1147
  }
1065
1148
  }, {
1066
1149
  key: "configureValidationAndRequirements",
1067
1150
  value: function configureValidationAndRequirements(isRequired, isValid, fieldDisplayName) {
1068
- var _this2 = this;
1151
+ var _this7 = this;
1069
1152
  var dependencies = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
1070
1153
  if (typeof Page_Validators !== "undefined") {
1071
1154
  var newValidator = document.createElement("span");
@@ -1080,13 +1163,14 @@ var DOMNodeReference = /*#__PURE__*/function () {
1080
1163
  throw new Error("Attempted to add to Validator where Page_Validators do not exist");
1081
1164
  }
1082
1165
  this.setRequiredLevel(isRequired(this));
1083
- if (!dependencies) return;
1166
+ if (!dependencies) return this;
1084
1167
  dependencies = Array.isArray(dependencies) ? dependencies : [dependencies];
1085
1168
  dependencies.forEach(function (dep) {
1086
1169
  dep.element.addEventListener("change", function () {
1087
- return _this2.setRequiredLevel(isRequired(_this2));
1170
+ return _this7.setRequiredLevel(isRequired(_this7));
1088
1171
  });
1089
1172
  });
1173
+ return this;
1090
1174
  }
1091
1175
  }, {
1092
1176
  key: "setRequiredLevel",
@@ -1096,19 +1180,20 @@ var DOMNodeReference = /*#__PURE__*/function () {
1096
1180
  } else {
1097
1181
  this.getLabel().classList.remove("required-field");
1098
1182
  }
1183
+ return this;
1099
1184
  }
1100
1185
  }, {
1101
1186
  key: "onceLoaded",
1102
1187
  value: function onceLoaded(callback) {
1103
- var _this3 = this;
1188
+ var _this8 = this;
1104
1189
  if (this.isLoaded) {
1105
1190
  callback(this);
1106
1191
  } else {
1107
1192
  var observer = new MutationObserver(function () {
1108
- if (document.querySelector(_this3.target)) {
1193
+ if (document.querySelector(_this8.target)) {
1109
1194
  observer.disconnect(); // Stop observing once loaded
1110
- _this3.isLoaded = true;
1111
- callback(_this3); // Call the provided callback
1195
+ _this8.isLoaded = true;
1196
+ callback(_this8); // Call the provided callback
1112
1197
  }
1113
1198
  });
1114
1199
  observer.observe(document.body, {
@@ -1159,12 +1244,13 @@ function _createDOMNodeReference() {
1159
1244
  var value = target[prop];
1160
1245
  if (typeof value === "function" && prop !== "onceLoaded") {
1161
1246
  return function () {
1162
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1163
- args[_key2] = arguments[_key2];
1247
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
1248
+ args[_key6] = arguments[_key6];
1164
1249
  }
1165
- return target.onceLoaded(function () {
1250
+ target.onceLoaded(function () {
1166
1251
  return value.apply(target, args);
1167
1252
  });
1253
+ return target;
1168
1254
  };
1169
1255
  }
1170
1256
  return value;
package/index.d.ts CHANGED
@@ -8,7 +8,6 @@ class DOMNodeReference {
8
8
  */
9
9
  constructor(target: string): DOMNodeReference;
10
10
 
11
- target: string;
12
11
  /**
13
12
  * The element targeted when instantiating DOMNodeReference.
14
13
  * Made available in order to perform normal DOM traversal,
@@ -17,8 +16,6 @@ class DOMNodeReference {
17
16
  */
18
17
  element: HTMLElement | null;
19
18
  isLoaded: boolean;
20
- visibilityController: HTMLElement | null;
21
- defaultDisplay: string;
22
19
  /**
23
20
  * The value of the element that this node represents
24
21
  * stays in syncs with the live DOM elements via event handler
@@ -50,55 +47,64 @@ class DOMNodeReference {
50
47
 
51
48
  /**
52
49
  * Hides the element by setting its display style to "none".
50
+ * @returns {DOMNodeReference} Returns 'this'
53
51
  */
54
- hide(): void;
52
+ hide(): DOMNodeReference;
55
53
 
56
54
  /**
57
55
  * Shows the element by restoring its default display style.
56
+ * @returns {DOMNodeReference} Returns 'this'
58
57
  */
59
- show(): void;
58
+ show(): DOMNodeReference;
60
59
 
61
60
  /**
62
61
  * Sets the value of the HTML element.
63
62
  * @param {() => any} value - The value to set for the HTML element.
64
63
  * for parents of boolean radios, pass true or false as value, or
65
64
  * an expression returning a boolean
65
+ * @returns {DOMNodeReference} Returns 'this'
66
66
  */
67
- setValue(value: string): void;
67
+ setValue(value: string): DOMNodeReference;
68
68
 
69
69
  /**
70
70
  * Disables the element so that users cannot input any data
71
+ * @returns {DOMNodeReference} Returns 'this'
71
72
  */
72
- disable(): void;
73
+ disable(): DOMNodeReference;
73
74
 
74
75
  /**
75
76
  * Enables the element so that users can input data
77
+ * @returns {DOMNodeReference} Returns 'this'
76
78
  */
77
- enable(): void;
79
+ enable(): DOMNodeReference;
78
80
 
79
81
  /**
80
82
  * Prepends elements to the target
81
- * @param {...HTMLElement} elements - The elements to prepend to the HTML element
83
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to prepend to the HTML element
84
+ * @returns {DOMNodeReference} Returns 'this'
82
85
  */
83
- prepend(...elements: HTMLElement[]): void;
86
+ prepend(...nodes: HTMLElement[] | DOMNodeReference[]): DOMNodeReference;
84
87
 
85
88
  /**
86
89
  * Appends child elements to the HTML element.
87
- * @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'
88
92
  */
89
- append(...elements: HTMLElement[]): void;
93
+ append(...nodes: HTMLElement[] | DOMNodeReference[]): DOMNodeReference;
90
94
 
91
95
  /**
92
96
  * Inserts elements before the HTML element.
93
- * @param {...HTMLElement} elements - The elements to insert before the HTML element.
97
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to insert before the HTML element.
98
+ * @returns {DOMNodeReference} Returns 'this'
94
99
  */
95
- before(...elements: HTMLElement[]): void;
100
+ before(...nodes: HTMLElement[] | DOMNodeReference[]): DOMNodeReference;
96
101
 
97
102
  /**
98
103
  * Inserts elements after the HTML element.
99
- * @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'
100
106
  */
101
- after(...elements: HTMLElement[]): void;
107
+ after(...nodes: HTMLElement[] | DOMNodeReference[]): DOMNodeReference;
102
108
 
103
109
  /**
104
110
  * Retrieves the label associated with the HTML element.
@@ -110,8 +116,9 @@ class DOMNodeReference {
110
116
  /**
111
117
  * Appends child elements to the label associated with the HTML element.
112
118
  * @param {...HTMLElement} elements - The elements to append to the label.
119
+ * @returns {DOMNodeReference} Returns 'this'
113
120
  */
114
- appendToLabel(...elements: HTMLElement[]): void;
121
+ appendToLabel(...elements: HTMLElement[]): DOMNodeReference;
115
122
 
116
123
  /**
117
124
  * Sets up an event listener based on the specified event type, executing the specified
@@ -119,12 +126,15 @@ class DOMNodeReference {
119
126
  * @param {string} eventType - The DOM event to watch for
120
127
  * @param {(this: DOMNodeReference, e: Event) => void} eventHandler - The callback function that runs when the
121
128
  * specified event occurs
129
+ * @returns {DOMNodeReference} Returns 'this'
122
130
  */
123
- on(eventType: string, eventHandler: (event: Event) => void): void;
131
+ on(eventType: string, eventHandler: (event: Event) => void): DOMNodeReference;
132
+
124
133
  /**
125
134
  * Unchecks both the yes and no radio buttons if they exist.
135
+ * @returns {DOMNodeReference} Returns 'this'
126
136
  */
127
- uncheckRadios(): void;
137
+ uncheckRadios(): DOMNodeReference;
128
138
 
129
139
  /**
130
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.
@@ -133,46 +143,66 @@ class DOMNodeReference {
133
143
  * @param {function(this: DOMNodeReference): boolean} isValid - A function that checks if the field's input is valid. Returns `true` if valid, `false` otherwise.
134
144
  * @param {string} fieldDisplayName - The name of the field, used in error messages if validation fails.
135
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'
136
147
  */
137
148
  configureValidationAndRequirements(
138
149
  isRequired: (this: this) => boolean,
139
150
  isValid: (this: this) => boolean,
140
151
  fieldDisplayName: string,
141
152
  dependencies: Array<DOMNodeReference>
142
- ): void;
153
+ ): DOMNodeReference;
143
154
 
144
155
  /**
145
156
  * Sets the required level for the field by adding or removing the "required-field" class on the label.
146
157
  *
147
158
  * @param {boolean} isRequired - Determines whether the field should be marked as required.
148
159
  * If true, the "required-field" class is added to the label; if false, it is removed.
160
+ * @returns {DOMNodeReference} Returns 'this'
149
161
  */
150
- setRequiredLevel(isRequired: boolean): void;
162
+ setRequiredLevel(isRequired: boolean): DOMNodeReference;
151
163
 
152
164
  /**
153
165
  * Adds a tooltip with specified text to the label associated with the HTML element.
154
166
  * @param {string} text - The text to display in the tooltip.
167
+ * @returns {DOMNodeReference} Returns 'this'
155
168
  */
156
- addLabelTooltip(text: string): void;
169
+ addLabelTooltip(text: string): DOMNodeReference;
157
170
 
158
171
  /**
159
172
  * Adds a tooltip with the specified text to the element
160
173
  * @param {string} text - The text to display in the tooltip
174
+ * @returns {DOMNodeReference} Returns 'this'
161
175
  */
162
- addTooltip(text: string): void;
176
+ addTooltip(text: string): DOMNodeReference;
163
177
 
164
178
  /**
165
179
  * Sets the inner HTML content of the HTML element.
166
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'
167
196
  */
168
- setTextContent(text: string): void;
197
+ setStyle(options: Partial<CSSStyleDeclaration>): DOMNodeReference;
169
198
 
170
199
  /**
171
200
  *
172
201
  * @param {boolean} shouldShow shows or hides the target
173
202
  * if = true => show, if = false => hide
203
+ * @returns {DOMNodeReference} Returns 'this'
174
204
  */
175
- toggleVisibility(shouldShow: boolean): void;
205
+ toggleVisibility(shouldShow: boolean): DOMNodeReference;
176
206
 
177
207
  /**
178
208
  * Configures conditional rendering for the target element based on a condition
@@ -181,14 +211,15 @@ class DOMNodeReference {
181
211
  * @param {(this: DOMNodeReference) => boolean} condition - A function that returns a boolean to determine
182
212
  * the visibility of the target element. If `condition()` returns true, the element is shown;
183
213
  * otherwise, it is hidden.
184
- * @param {DOMNodeReference[]} triggerNodes - An array of `DOMNodeReference` instances. Event listeners are
214
+ * @param {Array<DOMNodeReference>} dependencies - An array of `DOMNodeReference` instances. Event listeners are
185
215
  * registered on each to toggle the visibility of the target element based on the `condition` and the visibility of
186
216
  * the target node.
217
+ * @returns {DOMNodeReference} Returns 'this'
187
218
  */
188
219
  configureConditionalRendering(
189
220
  condition: (this: DOMNodeReference) => boolean,
190
- triggerNodes: DOMNodeReference[]
191
- ): void;
221
+ dependencies: DOMNodeReference[]
222
+ ): DOMNodeReference;
192
223
 
193
224
  /**
194
225
  * Executes a callback function once the element is fully loaded.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powerpagestoolkit",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
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/index.bundle.js",
6
6
  "types": "index.d.ts",