powerpagestoolkit 1.3.203 → 1.3.303

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
@@ -67,7 +67,7 @@ yesRadio: DOMNodeReference;
67
67
  noRadio: DOMNodeReference;
68
68
  // and if 'this' is the instance of a yesRadio or noRadio
69
69
  // checked will represent wether the radio has been checked or not
70
- checked: boolean
70
+ checked: boolean;
71
71
  ```
72
72
 
73
73
  ##### Methods
@@ -107,7 +107,7 @@ toggleVisibility(shouldShow: boolean | () => boolean)
107
107
  */
108
108
  configureConditionalRendering(
109
109
  condition: (this: DOMNodeReference) => boolean,
110
- dependencies: DOMNodeReference[]
110
+ dependencies: Array<DOMNodeReference>
111
111
  )
112
112
 
113
113
 
@@ -200,6 +200,9 @@ setValue(value: any)
200
200
  // Sets the inner HTML content of the associated HTML element.
201
201
  setTextContent(text: string)
202
202
 
203
+ // set any style attribute for 'this' with standard CSS style declaration
204
+ setStyle(options: Partial<CSSStyleDeclaration>): void;
205
+
203
206
  // Appends child elements to the associated HTML element.
204
207
  append(...elements: HTMLElement[])
205
208
 
@@ -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
  }, {
@@ -1026,6 +1074,17 @@ var DOMNodeReference = /*#__PURE__*/function () {
1026
1074
  value: function setTextContent(text) {
1027
1075
  this.element.innerHTML = text;
1028
1076
  }
1077
+ }, {
1078
+ key: "setStyle",
1079
+ value: function setStyle(options) {
1080
+ var _this5 = this;
1081
+ if (Object.prototype.toString.call(options) !== "[object Object]") {
1082
+ 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)));
1083
+ }
1084
+ Object.keys(options).forEach(function (key) {
1085
+ _this5.element.style[key] = options[key];
1086
+ });
1087
+ }
1029
1088
  }, {
1030
1089
  key: "uncheckRadios",
1031
1090
  value: function uncheckRadios() {
@@ -1039,18 +1098,18 @@ var DOMNodeReference = /*#__PURE__*/function () {
1039
1098
  }, {
1040
1099
  key: "configureConditionalRendering",
1041
1100
  value: function configureConditionalRendering(condition, triggerNodes) {
1042
- var _this = this;
1101
+ var _this6 = this;
1043
1102
  try {
1044
1103
  this.toggleVisibility(condition(this));
1045
1104
  if (triggerNodes) {
1046
1105
  var nodes = Array.isArray(triggerNodes) ? triggerNodes : [triggerNodes];
1047
1106
  nodes.forEach(function (node) {
1048
1107
  node.on("change", function () {
1049
- return _this.toggleVisibility(condition(_this));
1108
+ return _this6.toggleVisibility(condition(_this6));
1050
1109
  });
1051
1110
  var observer = new MutationObserver(function () {
1052
1111
  var display = window.getComputedStyle(node.visibilityController).display;
1053
- _this.toggleVisibility(display !== "none" && condition(_this));
1112
+ _this6.toggleVisibility(display !== "none" && condition(_this6));
1054
1113
  });
1055
1114
  observer.observe(node.visibilityController, {
1056
1115
  attributes: true,
@@ -1065,7 +1124,7 @@ var DOMNodeReference = /*#__PURE__*/function () {
1065
1124
  }, {
1066
1125
  key: "configureValidationAndRequirements",
1067
1126
  value: function configureValidationAndRequirements(isRequired, isValid, fieldDisplayName) {
1068
- var _this2 = this;
1127
+ var _this7 = this;
1069
1128
  var dependencies = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
1070
1129
  if (typeof Page_Validators !== "undefined") {
1071
1130
  var newValidator = document.createElement("span");
@@ -1084,7 +1143,7 @@ var DOMNodeReference = /*#__PURE__*/function () {
1084
1143
  dependencies = Array.isArray(dependencies) ? dependencies : [dependencies];
1085
1144
  dependencies.forEach(function (dep) {
1086
1145
  dep.element.addEventListener("change", function () {
1087
- return _this2.setRequiredLevel(isRequired(_this2));
1146
+ return _this7.setRequiredLevel(isRequired(_this7));
1088
1147
  });
1089
1148
  });
1090
1149
  }
@@ -1100,15 +1159,15 @@ var DOMNodeReference = /*#__PURE__*/function () {
1100
1159
  }, {
1101
1160
  key: "onceLoaded",
1102
1161
  value: function onceLoaded(callback) {
1103
- var _this3 = this;
1162
+ var _this8 = this;
1104
1163
  if (this.isLoaded) {
1105
1164
  callback(this);
1106
1165
  } else {
1107
1166
  var observer = new MutationObserver(function () {
1108
- if (document.querySelector(_this3.target)) {
1167
+ if (document.querySelector(_this8.target)) {
1109
1168
  observer.disconnect(); // Stop observing once loaded
1110
- _this3.isLoaded = true;
1111
- callback(_this3); // Call the provided callback
1169
+ _this8.isLoaded = true;
1170
+ callback(_this8); // Call the provided callback
1112
1171
  }
1113
1172
  });
1114
1173
  observer.observe(document.body, {
@@ -1159,8 +1218,8 @@ function _createDOMNodeReference() {
1159
1218
  var value = target[prop];
1160
1219
  if (typeof value === "function" && prop !== "onceLoaded") {
1161
1220
  return function () {
1162
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1163
- args[_key2] = arguments[_key2];
1221
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
1222
+ args[_key6] = arguments[_key6];
1164
1223
  }
1165
1224
  return target.onceLoaded(function () {
1166
1225
  return value.apply(target, args);
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
@@ -78,27 +75,27 @@ class DOMNodeReference {
78
75
 
79
76
  /**
80
77
  * Prepends elements to the target
81
- * @param {...HTMLElement} elements - The elements to prepend to the HTML element
78
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to prepend to the HTML element
82
79
  */
83
- prepend(...elements: HTMLElement[]): void;
80
+ prepend(...nodes: HTMLElement[] | DOMNodeReference[]): void;
84
81
 
85
82
  /**
86
83
  * Appends child elements to the HTML element.
87
- * @param {...HTMLElement} elements - The elements to append to the HTML element.
84
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to append to the HTML element.
88
85
  */
89
- append(...elements: HTMLElement[]): void;
86
+ append(...nodes: HTMLElement[] | DOMNodeReference[]): void;
90
87
 
91
88
  /**
92
89
  * Inserts elements before the HTML element.
93
- * @param {...HTMLElement} elements - The elements to insert before the HTML element.
90
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to insert before the HTML element.
94
91
  */
95
- before(...elements: HTMLElement[]): void;
92
+ before(...nodes: HTMLElement[] | DOMNodeReference[]): void;
96
93
 
97
94
  /**
98
95
  * Inserts elements after the HTML element.
99
- * @param {...HTMLElement} elements - The elements to insert after the HTML element.
96
+ * @param {HTMLElement[] | DOMNodeReference[]} nodes - The elements to insert after the HTML element.
100
97
  */
101
- after(...elements: HTMLElement[]): void;
98
+ after(...nodes: HTMLElement[] | DOMNodeReference[]): void;
102
99
 
103
100
  /**
104
101
  * Retrieves the label associated with the HTML element.
@@ -167,6 +164,13 @@ class DOMNodeReference {
167
164
  */
168
165
  setTextContent(text: string): void;
169
166
 
167
+ /**
168
+ *
169
+ * @param {Partial<CSSStyleDeclaration>} options - An object with the style properties (keys) and updated styles (values)
170
+ * to apply to the this. {"key": "value"}
171
+ */
172
+ setStyle(options: Partial<CSSStyleDeclaration>): void;
173
+
170
174
  /**
171
175
  *
172
176
  * @param {boolean} shouldShow shows or hides the target
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powerpagestoolkit",
3
- "version": "1.3.203",
3
+ "version": "1.3.303",
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",