powerpagestoolkit 1.3.202 → 1.3.204

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: DOMNodeReference[]
101
111
  )
102
112
 
103
113
 
@@ -106,22 +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
118
- * whether the field should be required. Returns `true` if required, `false` otherwise.
119
- * @param {function(this: DOMNodeReference): boolean} isValid - A function that checks if the field's
120
- * input is valid. Returns `true` if valid, `false` otherwise.
121
- * @param {string} fieldDisplayName - The name of the field, used in error messages if validation fails.
122
- * @param {Array<DOMNodeReference>} [dependencies] Other fields that this field’s requirement depends on.
123
- * When these Nodes or their values change, the required status of this field is re-evaluated.
124
- * 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.
125
149
  */
126
150
  configureValidationAndRequirements(
127
151
  isRequired: (this: this) => boolean,
@@ -135,20 +159,27 @@ configureValidationAndRequirements(
135
159
  const other_node = await createDOMNodeReference(".element_class")
136
160
 
137
161
  your_node.configureValidationAndRequirements(
138
- () => other_node.yesRadio.checked, /* if 'yes' is checked for this other node,
139
- this function will evaluate to true, meaning that 'your_node' will be required */
140
-
141
- function () { /* important to use standard 'function' declaration, instead of
142
- arrow function when needing to access 'this' (the instance of 'your_node') */
143
-
144
- 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'
145
174
  return this.value; // this is only 'valid' if it has a value
146
175
  } else return true;
147
176
  },
148
177
  "Your Field Name",
149
- [other_node] /* since our conditions depend on 'other_node' it must be included in the
150
- dependency array so that the requirement conditions can be re-evaluated when
151
- 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 */
152
183
  );
153
184
 
154
185
 
@@ -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;
@@ -983,17 +983,65 @@ var DOMNodeReference = /*#__PURE__*/function () {
983
983
  throw new Error("There was an error trying to disable the target: ".concat(this.target));
984
984
  }
985
985
  }
986
+ }, {
987
+ key: "prepend",
988
+ value: function prepend() {
989
+ var _this = this;
990
+ for (var _len = arguments.length, nodes = new Array(_len), _key = 0; _key < _len; _key++) {
991
+ nodes[_key] = arguments[_key];
992
+ }
993
+ nodes.forEach(function (node) {
994
+ if (node instanceof DOMNodeReference) {
995
+ _this.element.prepend(node.element);
996
+ } else {
997
+ _this.element.prepend(node);
998
+ }
999
+ });
1000
+ }
986
1001
  }, {
987
1002
  key: "append",
988
1003
  value: function append() {
989
- var _this$element;
990
- (_this$element = this.element).append.apply(_this$element, arguments);
1004
+ var _this2 = this;
1005
+ for (var _len2 = arguments.length, nodes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1006
+ nodes[_key2] = arguments[_key2];
1007
+ }
1008
+ nodes.forEach(function (node) {
1009
+ if (node instanceof DOMNodeReference) {
1010
+ _this2.element.append(node.element);
1011
+ } else {
1012
+ _this2.element.append(node);
1013
+ }
1014
+ });
1015
+ }
1016
+ }, {
1017
+ key: "before",
1018
+ value: function before() {
1019
+ var _this3 = this;
1020
+ for (var _len3 = arguments.length, nodes = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1021
+ nodes[_key3] = arguments[_key3];
1022
+ }
1023
+ nodes.forEach(function (node) {
1024
+ if (node instanceof DOMNodeReference) {
1025
+ _this3.element.before(node.element);
1026
+ } else {
1027
+ _this3.element.before(node);
1028
+ }
1029
+ });
991
1030
  }
992
1031
  }, {
993
1032
  key: "after",
994
1033
  value: function after() {
995
- var _this$element2;
996
- (_this$element2 = this.element).after.apply(_this$element2, arguments);
1034
+ var _this4 = this;
1035
+ for (var _len4 = arguments.length, nodes = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1036
+ nodes[_key4] = arguments[_key4];
1037
+ }
1038
+ nodes.forEach(function (node) {
1039
+ if (node instanceof DOMNodeReference) {
1040
+ _this4.element.after(node.element);
1041
+ } else {
1042
+ _this4.element.after(node);
1043
+ }
1044
+ });
997
1045
  }
998
1046
  }, {
999
1047
  key: "getLabel",
@@ -1005,8 +1053,8 @@ var DOMNodeReference = /*#__PURE__*/function () {
1005
1053
  value: function appendToLabel() {
1006
1054
  var label = this.getLabel();
1007
1055
  if (label) {
1008
- for (var _len = arguments.length, elements = new Array(_len), _key = 0; _key < _len; _key++) {
1009
- elements[_key] = arguments[_key];
1056
+ for (var _len5 = arguments.length, elements = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
1057
+ elements[_key5] = arguments[_key5];
1010
1058
  }
1011
1059
  label.append.apply(label, [" "].concat(elements));
1012
1060
  }
@@ -1017,8 +1065,8 @@ var DOMNodeReference = /*#__PURE__*/function () {
1017
1065
  this.appendToLabel(CreateInfoEl(text));
1018
1066
  }
1019
1067
  }, {
1020
- key: "addToolTip",
1021
- value: function addToolTip(text) {
1068
+ key: "addTooltip",
1069
+ value: function addTooltip(text) {
1022
1070
  this.append(CreateInfoEl(text));
1023
1071
  }
1024
1072
  }, {
@@ -1039,18 +1087,18 @@ var DOMNodeReference = /*#__PURE__*/function () {
1039
1087
  }, {
1040
1088
  key: "configureConditionalRendering",
1041
1089
  value: function configureConditionalRendering(condition, triggerNodes) {
1042
- var _this = this;
1090
+ var _this5 = this;
1043
1091
  try {
1044
1092
  this.toggleVisibility(condition(this));
1045
1093
  if (triggerNodes) {
1046
1094
  var nodes = Array.isArray(triggerNodes) ? triggerNodes : [triggerNodes];
1047
1095
  nodes.forEach(function (node) {
1048
1096
  node.on("change", function () {
1049
- return _this.toggleVisibility(condition(_this));
1097
+ return _this5.toggleVisibility(condition(_this5));
1050
1098
  });
1051
1099
  var observer = new MutationObserver(function () {
1052
1100
  var display = window.getComputedStyle(node.visibilityController).display;
1053
- _this.toggleVisibility(display !== "none" && condition(_this));
1101
+ _this5.toggleVisibility(display !== "none" && condition(_this5));
1054
1102
  });
1055
1103
  observer.observe(node.visibilityController, {
1056
1104
  attributes: true,
@@ -1065,7 +1113,7 @@ var DOMNodeReference = /*#__PURE__*/function () {
1065
1113
  }, {
1066
1114
  key: "configureValidationAndRequirements",
1067
1115
  value: function configureValidationAndRequirements(isRequired, isValid, fieldDisplayName) {
1068
- var _this2 = this;
1116
+ var _this6 = this;
1069
1117
  var dependencies = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
1070
1118
  if (typeof Page_Validators !== "undefined") {
1071
1119
  var newValidator = document.createElement("span");
@@ -1084,7 +1132,7 @@ var DOMNodeReference = /*#__PURE__*/function () {
1084
1132
  dependencies = Array.isArray(dependencies) ? dependencies : [dependencies];
1085
1133
  dependencies.forEach(function (dep) {
1086
1134
  dep.element.addEventListener("change", function () {
1087
- return _this2.setRequiredLevel(isRequired(_this2));
1135
+ return _this6.setRequiredLevel(isRequired(_this6));
1088
1136
  });
1089
1137
  });
1090
1138
  }
@@ -1100,15 +1148,15 @@ var DOMNodeReference = /*#__PURE__*/function () {
1100
1148
  }, {
1101
1149
  key: "onceLoaded",
1102
1150
  value: function onceLoaded(callback) {
1103
- var _this3 = this;
1151
+ var _this7 = this;
1104
1152
  if (this.isLoaded) {
1105
1153
  callback(this);
1106
1154
  } else {
1107
1155
  var observer = new MutationObserver(function () {
1108
- if (document.querySelector(_this3.target)) {
1156
+ if (document.querySelector(_this7.target)) {
1109
1157
  observer.disconnect(); // Stop observing once loaded
1110
- _this3.isLoaded = true;
1111
- callback(_this3); // Call the provided callback
1158
+ _this7.isLoaded = true;
1159
+ callback(_this7); // Call the provided callback
1112
1160
  }
1113
1161
  });
1114
1162
  observer.observe(document.body, {
@@ -1159,8 +1207,8 @@ function _createDOMNodeReference() {
1159
1207
  var value = target[prop];
1160
1208
  if (typeof value === "function" && prop !== "onceLoaded") {
1161
1209
  return function () {
1162
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1163
- args[_key2] = arguments[_key2];
1210
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
1211
+ args[_key6] = arguments[_key6];
1164
1212
  }
1165
1213
  return target.onceLoaded(function () {
1166
1214
  return value.apply(target, args);
package/index.d.ts CHANGED
@@ -78,27 +78,27 @@ class DOMNodeReference {
78
78
 
79
79
  /**
80
80
  * Prepends elements to the target
81
- * @param {...HTMLElement} elements - The elements to prepend to the HTML element
81
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to prepend to the HTML element
82
82
  */
83
- prepend(...elements: HTMLElement[]): void;
83
+ prepend(...nodes: HTMLElement[] | DOMNodeReference[]): void;
84
84
 
85
85
  /**
86
86
  * Appends child elements to the HTML element.
87
- * @param {...HTMLElement} elements - The elements to append to the HTML element.
87
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to append to the HTML element.
88
88
  */
89
- append(...elements: HTMLElement[]): void;
89
+ append(...nodes: HTMLElement[] | DOMNodeReference[]): void;
90
90
 
91
91
  /**
92
92
  * Inserts elements before the HTML element.
93
- * @param {...HTMLElement} elements - The elements to insert before the HTML element.
93
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to insert before the HTML element.
94
94
  */
95
- before(...elements: HTMLElement[]): void;
95
+ before(...nodes: HTMLElement[] | DOMNodeReference[]): void;
96
96
 
97
97
  /**
98
98
  * Inserts elements after the HTML element.
99
- * @param {...HTMLElement} elements - The elements to insert after the HTML element.
99
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to insert after the HTML element.
100
100
  */
101
- after(...elements: HTMLElement[]): void;
101
+ after(...nodes: HTMLElement[] | DOMNodeReference[]): void;
102
102
 
103
103
  /**
104
104
  * Retrieves the label associated with the HTML element.
@@ -181,13 +181,13 @@ class DOMNodeReference {
181
181
  * @param {(this: DOMNodeReference) => boolean} condition - A function that returns a boolean to determine
182
182
  * the visibility of the target element. If `condition()` returns true, the element is shown;
183
183
  * otherwise, it is hidden.
184
- * @param {DOMNodeReference[]} triggerNodes - An array of `DOMNodeReference` instances. Event listeners are
184
+ * @param {Array<DOMNodeReference>} dependencies - An array of `DOMNodeReference` instances. Event listeners are
185
185
  * registered on each to toggle the visibility of the target element based on the `condition` and the visibility of
186
186
  * the target node.
187
187
  */
188
188
  configureConditionalRendering(
189
189
  condition: (this: DOMNodeReference) => boolean,
190
- triggerNodes: DOMNodeReference[]
190
+ dependencies: DOMNodeReference[]
191
191
  ): void;
192
192
 
193
193
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powerpagestoolkit",
3
- "version": "1.3.202",
3
+ "version": "1.3.204",
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",