powerpagestoolkit 1.3.102 → 1.3.104

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.
Files changed (3) hide show
  1. package/dist/index.bundle.js +368 -339
  2. package/index.d.ts +91 -27
  3. package/package.json +61 -61
@@ -1,6 +1,6 @@
1
1
  /******/ var __webpack_modules__ = ({
2
2
 
3
- /***/ 693:
3
+ /***/ 672:
4
4
  /***/ ((module, __webpack_exports__, __webpack_require__) => {
5
5
 
6
6
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
@@ -48,6 +48,11 @@ ___CSS_LOADER_EXPORT___.push([module.id, `.info-icon {
48
48
  right: auto;
49
49
  }
50
50
  }
51
+
52
+ .required-field::after {
53
+ content: " *" !important;
54
+ color: #f00 !important;
55
+ }
51
56
  `, ""]);
52
57
  // Exports
53
58
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (___CSS_LOADER_EXPORT___);
@@ -568,113 +573,40 @@ var API = {
568
573
  };
569
574
  /* harmony default export */ const JS_API = (API);
570
575
  ;// ./src/JS/waitFor.js
571
- /**
572
- * @description a function that will wait for a targeted element to appear in the DOM, and then resolve a promise to allow further action to be performed after the targeted elements appears
573
- * @param {String} target a query target expression to target a specific element that you want to appear in the DOM before taking further action
574
- * @returns {Promise} the element targeted by ID *target*
575
- */
576
-
577
576
  function waitFor(target) {
578
- return new Promise(function (resolve) {
579
- if (target instanceof HTMLElement) {
580
- return resolve(target);
581
- }
582
- if (document.querySelector(target)) {
583
- return resolve(document.querySelector(target));
584
- }
577
+ return new Promise(function (resolve, reject) {
578
+ // Create observer to watch for target in DOM
585
579
  var observer = new MutationObserver(function () {
586
- if (document.querySelector(target)) {
580
+ var observedElement = document.querySelector(target);
581
+ if (observedElement) {
582
+ clearTimeout(timeout);
587
583
  observer.disconnect();
588
- resolve(document.querySelector(target));
584
+ resolve(observedElement);
589
585
  }
590
586
  });
587
+ var timeout = setTimeout(function () {
588
+ observer.disconnect();
589
+ reject(new Error("Element not found: ".concat(target, " within 5 seconds")));
590
+ }, 5000);
591
+
592
+ // Check if target is already in DOM
593
+ if (target instanceof HTMLElement) {
594
+ clearTimeout(timeout);
595
+ return resolve(target);
596
+ }
597
+ var element = document.querySelector(target);
598
+ if (element) {
599
+ clearTimeout(timeout);
600
+ return resolve(element);
601
+ }
591
602
  observer.observe(document.body, {
592
603
  subtree: true,
593
- attributes: true
604
+ attributes: true,
605
+ childList: true // Detects added/removed child elements
594
606
  });
595
607
  });
596
608
  }
597
- ;// ./src/JS/FieldValidation.class.js
598
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
599
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
600
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
601
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
602
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
603
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
604
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
605
- var FieldValidation = /*#__PURE__*/_createClass(function FieldValidation(fieldLogicalName, fieldDisplayname, evaluationFunction) {
606
- _classCallCheck(this, FieldValidation);
607
- _defineProperty(this, "createValidator", function () {
608
- if (typeof Page_Validators == "undefined") return;
609
- // Create new validator
610
- var newValidator = document.createElement("span");
611
- newValidator.style.display = "none";
612
- newValidator.id = "".concat(this.fieldLogicalName, "Validator");
613
- newValidator.controltovalidate = "".concat(this.fieldLogicalName);
614
- newValidator.errormessage = "<a href='#".concat(this.fieldDisplayname, "_label'>").concat(this.fieldDisplayname, " is a required field</a>");
615
- newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
616
- newValidator.initialvalue = "";
617
- newValidator.evaluationfunction = this.evaluationFunction;
618
- // Add the new validator to the page validators array:
619
- // eslint-disable-next-line no-undef
620
- Page_Validators.push(newValidator);
621
- });
622
- this.fieldLogicalName = fieldLogicalName;
623
- this.fieldDisplayname = fieldDisplayname;
624
- this.evaluationFunction = evaluationFunction.bind(this);
625
- this.createValidator();
626
- });
627
-
628
- // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js
629
- var injectStylesIntoStyleTag = __webpack_require__(72);
630
- var injectStylesIntoStyleTag_default = /*#__PURE__*/__webpack_require__.n(injectStylesIntoStyleTag);
631
- // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/styleDomAPI.js
632
- var styleDomAPI = __webpack_require__(825);
633
- var styleDomAPI_default = /*#__PURE__*/__webpack_require__.n(styleDomAPI);
634
- // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/insertBySelector.js
635
- var insertBySelector = __webpack_require__(659);
636
- var insertBySelector_default = /*#__PURE__*/__webpack_require__.n(insertBySelector);
637
- // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/setAttributesWithoutAttributes.js
638
- var setAttributesWithoutAttributes = __webpack_require__(56);
639
- var setAttributesWithoutAttributes_default = /*#__PURE__*/__webpack_require__.n(setAttributesWithoutAttributes);
640
- // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/insertStyleElement.js
641
- var insertStyleElement = __webpack_require__(540);
642
- var insertStyleElement_default = /*#__PURE__*/__webpack_require__.n(insertStyleElement);
643
- // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/styleTagTransform.js
644
- var styleTagTransform = __webpack_require__(113);
645
- var styleTagTransform_default = /*#__PURE__*/__webpack_require__.n(styleTagTransform);
646
- // EXTERNAL MODULE: ./node_modules/css-loader/dist/cjs.js!./src/CSS/infoEl.style.css
647
- var infoEl_style = __webpack_require__(693);
648
- ;// ./src/CSS/infoEl.style.css
649
-
650
-
651
-
652
-
653
-
654
-
655
-
656
-
657
-
658
-
659
-
660
- var options = {};
661
-
662
- options.styleTagTransform = (styleTagTransform_default());
663
- options.setAttributes = (setAttributesWithoutAttributes_default());
664
- options.insert = insertBySelector_default().bind(null, "head");
665
- options.domAPI = (styleDomAPI_default());
666
- options.insertStyleElement = (insertStyleElement_default());
667
-
668
- var update = injectStylesIntoStyleTag_default()(infoEl_style/* default */.A, options);
669
-
670
-
671
-
672
-
673
- /* harmony default export */ const CSS_infoEl_style = (infoEl_style/* default */.A && infoEl_style/* default */.A.locals ? infoEl_style/* default */.A.locals : undefined);
674
-
675
609
  ;// ./src/JS/createInfoElement.js
676
- // Import the CSS file
677
-
678
610
  function CreateInfoEl(titleString) {
679
611
  var span = document.createElement("span");
680
612
  span.classList.add("info-icon");
@@ -728,6 +660,97 @@ function CreateInfoEl(titleString) {
728
660
  });
729
661
  return span;
730
662
  }
663
+ ;// ./src/JS/errors.js
664
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
665
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
666
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
667
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
668
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
669
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
670
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
671
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
672
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
673
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
674
+ function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
675
+ function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
676
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
677
+ function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
678
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
679
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
680
+ var DOMNodeInitializationError = /*#__PURE__*/function (_Error) {
681
+ function DOMNodeInitializationError(instance, error) {
682
+ var _this;
683
+ _classCallCheck(this, DOMNodeInitializationError);
684
+ _this = _callSuper(this, DOMNodeInitializationError, ["There was an error initializing a DOMNodeReference for target: ".concat(instance.target, ", :: ").concat(error)]);
685
+ _this.name = "DOMNodeInitializationError";
686
+ return _this;
687
+ }
688
+ _inherits(DOMNodeInitializationError, _Error);
689
+ return _createClass(DOMNodeInitializationError);
690
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
691
+ var DOMNodeNotFoundError = /*#__PURE__*/function (_Error2) {
692
+ function DOMNodeNotFoundError(instance) {
693
+ _classCallCheck(this, DOMNodeNotFoundError);
694
+ return _callSuper(this, DOMNodeNotFoundError, ["The targeted DOM element was not found: ".concat(instance.target)]);
695
+ }
696
+ _inherits(DOMNodeNotFoundError, _Error2);
697
+ return _createClass(DOMNodeNotFoundError);
698
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
699
+ var ConditionalRenderingError = /*#__PURE__*/function (_Error3) {
700
+ function ConditionalRenderingError(instance, error) {
701
+ _classCallCheck(this, ConditionalRenderingError);
702
+ return _callSuper(this, ConditionalRenderingError, ["There was an error condiguring conditional rendering for target: ".concat(instance.target, " :: ").concat(error)]);
703
+ }
704
+ _inherits(ConditionalRenderingError, _Error3);
705
+ return _createClass(ConditionalRenderingError);
706
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
707
+ // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js
708
+ var injectStylesIntoStyleTag = __webpack_require__(72);
709
+ var injectStylesIntoStyleTag_default = /*#__PURE__*/__webpack_require__.n(injectStylesIntoStyleTag);
710
+ // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/styleDomAPI.js
711
+ var styleDomAPI = __webpack_require__(825);
712
+ var styleDomAPI_default = /*#__PURE__*/__webpack_require__.n(styleDomAPI);
713
+ // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/insertBySelector.js
714
+ var insertBySelector = __webpack_require__(659);
715
+ var insertBySelector_default = /*#__PURE__*/__webpack_require__.n(insertBySelector);
716
+ // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/setAttributesWithoutAttributes.js
717
+ var setAttributesWithoutAttributes = __webpack_require__(56);
718
+ var setAttributesWithoutAttributes_default = /*#__PURE__*/__webpack_require__.n(setAttributesWithoutAttributes);
719
+ // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/insertStyleElement.js
720
+ var insertStyleElement = __webpack_require__(540);
721
+ var insertStyleElement_default = /*#__PURE__*/__webpack_require__.n(insertStyleElement);
722
+ // EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/styleTagTransform.js
723
+ var styleTagTransform = __webpack_require__(113);
724
+ var styleTagTransform_default = /*#__PURE__*/__webpack_require__.n(styleTagTransform);
725
+ // EXTERNAL MODULE: ./node_modules/css-loader/dist/cjs.js!./src/CSS/style.css
726
+ var style = __webpack_require__(672);
727
+ ;// ./src/CSS/style.css
728
+
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+ var options = {};
740
+
741
+ options.styleTagTransform = (styleTagTransform_default());
742
+ options.setAttributes = (setAttributesWithoutAttributes_default());
743
+ options.insert = insertBySelector_default().bind(null, "head");
744
+ options.domAPI = (styleDomAPI_default());
745
+ options.insertStyleElement = (insertStyleElement_default());
746
+
747
+ var update = injectStylesIntoStyleTag_default()(style/* default */.A, options);
748
+
749
+
750
+
751
+
752
+ /* harmony default export */ const CSS_style = (style/* default */.A && style/* default */.A.locals ? style/* default */.A.locals : undefined);
753
+
731
754
  ;// ./src/JS/DOMNodeReferences.js
732
755
  function DOMNodeReferences_typeof(o) { "@babel/helpers - typeof"; return DOMNodeReferences_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, DOMNodeReferences_typeof(o); }
733
756
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == DOMNodeReferences_typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(DOMNodeReferences_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
@@ -742,6 +765,7 @@ function DOMNodeReferences_toPrimitive(t, r) { if ("object" != DOMNodeReferences
742
765
 
743
766
 
744
767
 
768
+
745
769
  /**
746
770
  * Class representing a reference to a DOM node.
747
771
  */
@@ -762,16 +786,10 @@ var DOMNodeReference = /*#__PURE__*/function () {
762
786
  this.value = null;
763
787
  // we defer the rest of initialization
764
788
  }
765
-
766
- /**
767
- * Initializes the DOMNodeReference instance by waiting for the element to be available in the DOM.
768
- */
769
- /******/ /******/
770
789
  return DOMNodeReferences_createClass(DOMNodeReference, [{
771
- key: "init",
772
- value: (function () {
773
- var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
774
- var _this = this;
790
+ key: "_init",
791
+ value: function () {
792
+ var _init2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
775
793
  var element;
776
794
  return _regeneratorRuntime().wrap(function _callee$(_context) {
777
795
  while (1) switch (_context.prev = _context.next) {
@@ -786,139 +804,202 @@ var DOMNodeReference = /*#__PURE__*/function () {
786
804
  _context.next = 7;
787
805
  break;
788
806
  }
789
- throw new Error("[SYNACT] No Element could be found with the provided query selector: ".concat(this.target));
807
+ throw new DOMNodeNotFoundError(this);
790
808
  case 7:
791
- this.value = this.element.value;
792
809
  if (!this.element.classList.contains("boolean-radio")) {
793
- _context.next = 15;
810
+ _context.next = 10;
794
811
  break;
795
812
  }
796
- _context.next = 11;
797
- return createDOMNodeReference("#".concat(this.element.id, "_1"));
798
- case 11:
799
- this.yesRadio = _context.sent;
800
- _context.next = 14;
801
- return createDOMNodeReference("#".concat(this.element.id, "_0"));
802
- case 14:
803
- this.noRadio = _context.sent;
804
- case 15:
805
- this.element.addEventListener("change", function () {
806
- _this.value = _this.element.value;
807
- });
808
-
809
- // based on the type of element we have targeted in instantiation
810
- // we now grab the parent element that will be responsible for
811
- // 'showing' and 'hiding' the target element
812
- // this is needed also in order to observe changes to visibility so that
813
- // changes to target can cascade to dependent DOMNodeReferences
814
- _context.t0 = this.element.tagName;
815
- _context.next = _context.t0 === "SPAN" ? 19 : _context.t0 === "INPUT" ? 19 : _context.t0 === "TEXTAREA" ? 19 : _context.t0 === "SELECT" ? 19 : _context.t0 === "FIELDSET" ? 21 : 21;
816
- break;
817
- case 19:
818
- this.visibilityController = this.element.closest("td");
819
- return _context.abrupt("break", 22);
820
- case 21:
821
- this.visibilityController = this.element;
822
- case 22:
813
+ _context.next = 10;
814
+ return this._attachRadioButtons();
815
+ case 10:
816
+ this._initValueSync();
817
+ this._attachVisibilityController();
823
818
  this.defaultDisplay = this.visibilityController.style.display;
824
819
  this.isLoaded = true;
825
- _context.next = 29;
820
+ _context.next = 19;
826
821
  break;
827
- case 26:
828
- _context.prev = 26;
829
- _context.t1 = _context["catch"](0);
830
- throw new Error("powerpagestoolkit: There was an error initializing a DOMNodeReference with the target: ".concat(this.target, " :: ").concat(_context.t1));
831
- case 29:
822
+ case 16:
823
+ _context.prev = 16;
824
+ _context.t0 = _context["catch"](0);
825
+ throw new DOMNodeInitializationError(this, _context.t0);
826
+ case 19:
832
827
  case "end":
833
828
  return _context.stop();
834
829
  }
835
- }, _callee, this, [[0, 26]]);
830
+ }, _callee, this, [[0, 16]]);
836
831
  }));
837
- function init() {
838
- return _init.apply(this, arguments);
832
+ function _init() {
833
+ return _init2.apply(this, arguments);
839
834
  }
840
- return init;
835
+ return _init;
841
836
  }()
842
- /**
843
- * Hides the element by setting its display style to "none".
844
- * @method hide
845
- */
846
- /******/
847
- )
837
+ }, {
838
+ key: "_initValueSync",
839
+ value: function _initValueSync() {
840
+ // Function to update this.value based on element type
841
+
842
+ // Initial sync
843
+ this.updateValue();
844
+
845
+ // Event listeners for real-time changes based on element type
846
+ var elementType = this.element.type;
847
+ if (elementType === "checkbox" || elementType === "radio") {
848
+ this.element.addEventListener("click", this.updateValue.bind(this));
849
+ } else if (elementType === "select-one" || elementType === "select-multiple") {
850
+ this.element.addEventListener("change", this.updateValue.bind(this));
851
+ } else {
852
+ this.element.addEventListener("input", this.updateValue.bind(this));
853
+ }
854
+ }
855
+ }, {
856
+ key: "updateValue",
857
+ value: function updateValue() {
858
+ switch (this.element.type) {
859
+ case "checkbox":
860
+ case "radio":
861
+ this.value = this.element.checked;
862
+ this.checked = this.element.checked;
863
+ break;
864
+ case "select-multiple":
865
+ this.value = Array.from(this.element.selectedOptions).map(function (option) {
866
+ return option.value;
867
+ });
868
+ break;
869
+ case "file":
870
+ this.value = this.element.files.length > 0 ? Array.from(this.element.files) : null;
871
+ break;
872
+ case "number":
873
+ this.value = this.element.value !== "" ? Number(this.element.value) : null;
874
+ break;
875
+ default:
876
+ this.value = this.element.value || null;
877
+ break;
878
+ }
879
+ if (this.element.classList.contains("boolean-radio")) {
880
+ this.yesRadio.updateValue();
881
+ this.noRadio.updateValue();
882
+ }
883
+ }
884
+ }, {
885
+ key: "_attachVisibilityController",
886
+ value: function _attachVisibilityController() {
887
+ // Set the default visibility controller to the element itself
888
+ this.visibilityController = this.element;
889
+
890
+ // If the element is a table, use its closest fieldset as the controller
891
+ if (this.element.tagName === "TABLE") {
892
+ var fieldset = this.element.closest("fieldset");
893
+ if (fieldset) {
894
+ this.visibilityController = fieldset;
895
+ }
896
+ return;
897
+ }
898
+
899
+ // For specific tag types, use the closest 'td' if available as the controller
900
+ var tagsRequiringTdParent = ["SPAN", "INPUT", "TEXTAREA", "SELECT", "TABLE"];
901
+ if (tagsRequiringTdParent.includes(this.element.tagName)) {
902
+ var tdParent = this.element.closest("td");
903
+ if (tdParent) {
904
+ this.visibilityController = tdParent;
905
+ }
906
+ }
907
+ }
908
+ }, {
909
+ key: "_attachRadioButtons",
910
+ value: function () {
911
+ var _attachRadioButtons2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
912
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
913
+ while (1) switch (_context2.prev = _context2.next) {
914
+ case 0:
915
+ _context2.next = 2;
916
+ return createDOMNodeReference("#".concat(this.element.id, "_1"));
917
+ case 2:
918
+ this.yesRadio = _context2.sent;
919
+ _context2.next = 5;
920
+ return createDOMNodeReference("#".concat(this.element.id, "_0"));
921
+ case 5:
922
+ this.noRadio = _context2.sent;
923
+ case 6:
924
+ case "end":
925
+ return _context2.stop();
926
+ }
927
+ }, _callee2, this);
928
+ }));
929
+ function _attachRadioButtons() {
930
+ return _attachRadioButtons2.apply(this, arguments);
931
+ }
932
+ return _attachRadioButtons;
933
+ }()
934
+ }, {
935
+ key: "on",
936
+ value: function on(eventType, eventHandler) {
937
+ this.element.addEventListener(eventType, eventHandler.bind(this));
938
+ }
848
939
  }, {
849
940
  key: "hide",
850
941
  value: function hide() {
851
942
  this.visibilityController.style.display = "none";
852
943
  }
853
-
854
- /**
855
- * Shows the element by restoring its default display style.
856
- * @method show
857
- */
858
- /******/
859
944
  }, {
860
945
  key: "show",
861
946
  value: function show() {
862
947
  this.visibilityController.style.display = this.defaultDisplay;
863
948
  }
864
-
865
- /**
866
- * Sets the value of the HTML element.
867
- * @method setValue
868
- * @param {string} value - The value to set for the HTML element.
869
- */
870
- /******/
949
+ }, {
950
+ key: "toggleVisibility",
951
+ value: function toggleVisibility(shouldShow) {
952
+ if (shouldShow instanceof Function) {
953
+ shouldShow() ? this.show() : this.hide();
954
+ } else {
955
+ shouldShow ? this.show() : this.hide();
956
+ }
957
+ }
871
958
  }, {
872
959
  key: "setValue",
873
960
  value: function setValue(value) {
874
- this.element.value = value;
961
+ if (this.element.classList.contains("boolean-radio")) {
962
+ this.yesRadio.element.checked = value;
963
+ this.noRadio.element.checked = !value;
964
+ } else {
965
+ this.element.value = value;
966
+ }
967
+ }
968
+ }, {
969
+ key: "disable",
970
+ value: function disable() {
971
+ try {
972
+ this.element.disabled = true;
973
+ } catch (e) {
974
+ throw new Error("There was an error trying to disable the target: ".concat(this.target));
975
+ }
976
+ }
977
+ }, {
978
+ key: "enable",
979
+ value: function enable() {
980
+ try {
981
+ this.element.disabled = false;
982
+ } catch (e) {
983
+ throw new Error("There was an error trying to disable the target: ".concat(this.target));
984
+ }
875
985
  }
876
-
877
- /**
878
- * Appends child elements to the HTML element.
879
- * @method append
880
- * @param {...HTMLElement} elements - The elements to append to the HTML element.
881
- */
882
- /******/
883
986
  }, {
884
987
  key: "append",
885
988
  value: function append() {
886
989
  var _this$element;
887
990
  (_this$element = this.element).append.apply(_this$element, arguments);
888
991
  }
889
-
890
- /**
891
- * Inserts elements after the HTML element.
892
- * @method after
893
- * @param {...HTMLElement} elements - The elements to insert after the HTML element.
894
- */
895
- /******/
896
992
  }, {
897
993
  key: "after",
898
994
  value: function after() {
899
995
  var _this$element2;
900
996
  (_this$element2 = this.element).after.apply(_this$element2, arguments);
901
997
  }
902
-
903
- /**
904
- * Retrieves the label associated with the HTML element.
905
- * @method getLabel
906
- * @returns {HTMLElement} The label element associated with this element.
907
- * @throws {Error} Throws an error if the label cannot be found.
908
- */
909
- /******/
910
998
  }, {
911
999
  key: "getLabel",
912
1000
  value: function getLabel() {
913
1001
  return document.querySelector("#".concat(this.element.id, "_label")) || null;
914
1002
  }
915
-
916
- /**
917
- * Appends child elements to the label associated with the HTML element.
918
- * @method appendToLabel
919
- * @param {...HTMLElement} elements - The elements to append to the label.
920
- */
921
- /******/
922
1003
  }, {
923
1004
  key: "appendToLabel",
924
1005
  value: function appendToLabel() {
@@ -930,146 +1011,94 @@ var DOMNodeReference = /*#__PURE__*/function () {
930
1011
  label.append.apply(label, [" "].concat(elements));
931
1012
  }
932
1013
  }
933
-
934
- /**
935
- * Adds a click event listener to the HTML element.
936
- * @method addClickListener
937
- * @param {Function} eventHandler - The function to execute when the element is clicked.
938
- */
939
- /******/
940
- }, {
941
- key: "addClickListener",
942
- value: function addClickListener(eventHandler) {
943
- this.element.addEventListener("click", function (e) {
944
- e.preventDefault();
945
- eventHandler();
946
- });
947
- }
948
-
949
- /**
950
- * Adds a change event listener to the HTML element.
951
- * @method addChangeListener
952
- * @param {Function} eventHandler - The function to execute when the element's value changes.
953
- */
954
- /******/
955
- }, {
956
- key: "addChangeListener",
957
- value: function addChangeListener(eventHandler) {
958
- this.element.addEventListener("change", function (e) {
959
- e.preventDefault();
960
- eventHandler();
961
- });
962
- }
963
-
964
- /**
965
- * Unchecks both the yes and no radio buttons if they exist.
966
- * @method uncheckRadios
967
- */
968
- /******/
969
- }, {
970
- key: "uncheckRadios",
971
- value: function uncheckRadios() {
972
- if (this.yesRadio && this.noRadio) {
973
- this.yesRadio.element.checked = false;
974
- this.noRadio.element.checked = false;
975
- } else {
976
- console.error("[SYNACT] Attempted to uncheck radios for an element that has no radios");
977
- }
978
- }
979
-
980
- /**
981
- * Creates a validation instance for the field.
982
- * @method createValidation
983
- * @param {Function} evaluationFunction - The function used to evaluate the field.
984
- * @param {string} fieldDisplayName - The field name to display in error if validation fails.
985
- */
986
- /******/
987
- }, {
988
- key: "createValidation",
989
- value: function createValidation(evaluationFunction, fieldDisplayName) {
990
- new FieldValidation(this.id, "'".concat(fieldDisplayName, "'"), evaluationFunction);
991
- }
992
-
993
- /**
994
- * Adds a tooltip with specified text to the label associated with the HTML element.
995
- * @method addLabelTooltip
996
- * @param {string} text - The text to display in the tooltip.
997
- */
998
- /******/
999
1014
  }, {
1000
1015
  key: "addLabelTooltip",
1001
1016
  value: function addLabelTooltip(text) {
1002
1017
  this.appendToLabel(CreateInfoEl(text));
1003
1018
  }
1004
-
1005
- /******/
1006
1019
  }, {
1007
1020
  key: "addToolTip",
1008
1021
  value: function addToolTip(text) {
1009
1022
  this.append(CreateInfoEl(text));
1010
1023
  }
1011
-
1012
- /**
1013
- * Sets the inner HTML content of the HTML element.
1014
- * @method setTextContent
1015
- * @param {string} text - The text to set as the inner HTML of the element.
1016
- */
1017
- /******/
1018
1024
  }, {
1019
1025
  key: "setTextContent",
1020
1026
  value: function setTextContent(text) {
1021
1027
  this.element.innerHTML = text;
1022
1028
  }
1023
-
1024
- /**
1025
- *
1026
- * @param {boolean} shouldShow shows or hides the target
1027
- * if = true => show, if = false => hide
1028
- */
1029
1029
  }, {
1030
- key: "toggleVisibility",
1031
- value: function toggleVisibility(shouldShow) {
1032
- shouldShow ? this.show() : this.hide();
1030
+ key: "uncheckRadios",
1031
+ value: function uncheckRadios() {
1032
+ if (this.yesRadio && this.noRadio) {
1033
+ this.yesRadio.element.checked = false;
1034
+ this.noRadio.element.checked = false;
1035
+ } else {
1036
+ console.error("[SYNACT] Attempted to uncheck radios for an element that has no radios");
1037
+ }
1033
1038
  }
1034
-
1035
- /**
1036
- *
1037
- * @param {Function} condition A Function that return a boolean value to set the
1038
- * visibility of the targeted element. if condition() returns true, element is shown.
1039
- * If false, element is hidden
1040
- * @param {DOMNodeReference} triggerNode The DOMNodeReference to which an
1041
- * event listener will be registered to change the visibility state of the calling
1042
- * DOMNodeReference
1043
- */
1044
- /******/
1045
1039
  }, {
1046
1040
  key: "configureConditionalRendering",
1047
- value: function configureConditionalRendering(condition, triggerNode) {
1041
+ value: function configureConditionalRendering(condition, triggerNodes) {
1042
+ var _this = this;
1043
+ try {
1044
+ this.toggleVisibility(condition());
1045
+ if (triggerNodes) {
1046
+ var nodes = Array.isArray(triggerNodes) ? triggerNodes : [triggerNodes];
1047
+ nodes.forEach(function (node) {
1048
+ node.on("change", function () {
1049
+ return _this.toggleVisibility(condition());
1050
+ });
1051
+ var observer = new MutationObserver(function () {
1052
+ var display = window.getComputedStyle(node.visibilityController).display;
1053
+ _this.toggleVisibility(display !== "none" && condition());
1054
+ });
1055
+ observer.observe(node.visibilityController, {
1056
+ attributes: true,
1057
+ attributeFilter: ["style"]
1058
+ });
1059
+ });
1060
+ }
1061
+ } catch (e) {
1062
+ throw new ConditionalRenderingError(this, e);
1063
+ }
1064
+ }
1065
+ }, {
1066
+ key: "configureValidationAndRequirements",
1067
+ value: function configureValidationAndRequirements(_ref, fieldDisplayName) {
1048
1068
  var _this2 = this;
1049
- this.toggleVisibility(condition());
1050
- if (triggerNode) {
1051
- triggerNode.addChangeListener(function () {
1052
- _this2.toggleVisibility(condition());
1053
- });
1054
- var observer = new MutationObserver(function () {
1055
- var display = window.getComputedStyle(triggerNode.visibilityController).display;
1056
- _this2.toggleVisibility(display !== "none" && condition());
1057
- });
1058
- observer.observe(triggerNode.visibilityController, {
1059
- attributes: true,
1060
- attributeFilter: ["style"]
1069
+ var requirementLogic = _ref.requirementLogic,
1070
+ validationLogic = _ref.validationLogic;
1071
+ var dependencies = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
1072
+ if (typeof Page_Validators !== "undefined") {
1073
+ var newValidator = document.createElement("span");
1074
+ newValidator.style.display = "none";
1075
+ newValidator.id = "".concat(this.id, "Validator");
1076
+ newValidator.controltovalidate = this.id;
1077
+ newValidator.errormessage = "<a href='#".concat(this.element.id, "_label'>").concat(fieldDisplayName, " is a required field</a>");
1078
+ newValidator.evaluationfunction = validationLogic.bind(this);
1079
+ //eslint-disable-next-line
1080
+ Page_Validators.push(newValidator);
1081
+ } else {
1082
+ throw new Error("Attempted to add to Validator where Page_Validators do not exist");
1083
+ }
1084
+ this.setRequiredLevel(requirementLogic(this));
1085
+ if (!dependencies) return;
1086
+ dependencies = Array.isArray(dependencies) ? dependencies : [dependencies];
1087
+ dependencies.forEach(function (dep) {
1088
+ dep.element.addEventListener("change", function () {
1089
+ return _this2.setRequiredLevel(requirementLogic(_this2));
1061
1090
  });
1091
+ });
1092
+ }
1093
+ }, {
1094
+ key: "setRequiredLevel",
1095
+ value: function setRequiredLevel(isRequired) {
1096
+ if (isRequired) {
1097
+ this.getLabel().classList.add("required-field");
1098
+ } else {
1099
+ this.getLabel().classList.remove("required-field");
1062
1100
  }
1063
1101
  }
1064
-
1065
- /**
1066
- * Executes a callback function once the element is fully loaded.
1067
- * If the element is already loaded, the callback is called immediately.
1068
- * Otherwise, a MutationObserver is used to detect when the element is added to the DOM.
1069
- * @method onceLoaded
1070
- * @param {Function} callback - A callback function to execute once the element is loaded.
1071
- */
1072
- /******/
1073
1102
  }, {
1074
1103
  key: "onceLoaded",
1075
1104
  value: function onceLoaded(callback) {
@@ -1111,21 +1140,21 @@ function createDOMNodeReference(_x) {
1111
1140
  * @returns {Promise<DOMNodeReference[]>} A promise that resolves to an array of Proxies of initialized DOMNodeReference instances.
1112
1141
  */
1113
1142
  function _createDOMNodeReference() {
1114
- _createDOMNodeReference = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(target) {
1143
+ _createDOMNodeReference = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(target) {
1115
1144
  var instance;
1116
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1117
- while (1) switch (_context2.prev = _context2.next) {
1145
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1146
+ while (1) switch (_context3.prev = _context3.next) {
1118
1147
  case 0:
1119
- _context2.prev = 0;
1148
+ _context3.prev = 0;
1120
1149
  instance = new DOMNodeReference(target);
1121
- _context2.next = 4;
1122
- return instance.init();
1150
+ _context3.next = 4;
1151
+ return instance._init();
1123
1152
  case 4:
1124
- return _context2.abrupt("return", new Proxy(instance, {
1153
+ return _context3.abrupt("return", new Proxy(instance, {
1125
1154
  get: function get(target, prop) {
1126
1155
  // do not proxy the initialization method
1127
1156
  // init() is only needed in this factory function
1128
- if (prop == "init") return undefined;
1157
+ if (prop.toString().startsWith("_")) return undefined;
1129
1158
 
1130
1159
  // proxy the class to wrap all methods in the 'onceLoaded' method, to make sure the
1131
1160
  // element is always available before executing method
@@ -1144,15 +1173,15 @@ function _createDOMNodeReference() {
1144
1173
  }
1145
1174
  }));
1146
1175
  case 7:
1147
- _context2.prev = 7;
1148
- _context2.t0 = _context2["catch"](0);
1149
- console.error("There was an error creating a DOMNodeReference: ".concat(_context2.t0));
1150
- throw new Error(_context2.t0);
1176
+ _context3.prev = 7;
1177
+ _context3.t0 = _context3["catch"](0);
1178
+ console.error("There was an error creating a DOMNodeReference: ".concat(_context3.t0));
1179
+ throw new Error(_context3.t0);
1151
1180
  case 11:
1152
1181
  case "end":
1153
- return _context2.stop();
1182
+ return _context3.stop();
1154
1183
  }
1155
- }, _callee2, null, [[0, 7]]);
1184
+ }, _callee3, null, [[0, 7]]);
1156
1185
  }));
1157
1186
  return _createDOMNodeReference.apply(this, arguments);
1158
1187
  }
@@ -1160,19 +1189,19 @@ function createMultipleDOMNodeReferences(_x2) {
1160
1189
  return _createMultipleDOMNodeReferences.apply(this, arguments);
1161
1190
  }
1162
1191
  function _createMultipleDOMNodeReferences() {
1163
- _createMultipleDOMNodeReferences = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(querySelector) {
1192
+ _createMultipleDOMNodeReferences = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(querySelector) {
1164
1193
  var elements;
1165
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1166
- while (1) switch (_context3.prev = _context3.next) {
1194
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1195
+ while (1) switch (_context4.prev = _context4.next) {
1167
1196
  case 0:
1168
- _context3.prev = 0;
1197
+ _context4.prev = 0;
1169
1198
  elements = Array.from(document.querySelectorAll(querySelector));
1170
- _context3.next = 4;
1199
+ _context4.next = 4;
1171
1200
  return Promise.all(elements.map(function (element) {
1172
1201
  return createDOMNodeReference(element);
1173
1202
  }));
1174
1203
  case 4:
1175
- elements = _context3.sent;
1204
+ elements = _context4.sent;
1176
1205
  elements.hideAll = function () {
1177
1206
  return elements.forEach(function (instance) {
1178
1207
  return instance.hide();
@@ -1183,17 +1212,17 @@ function _createMultipleDOMNodeReferences() {
1183
1212
  return instance.show();
1184
1213
  });
1185
1214
  };
1186
- return _context3.abrupt("return", elements);
1215
+ return _context4.abrupt("return", elements);
1187
1216
  case 10:
1188
- _context3.prev = 10;
1189
- _context3.t0 = _context3["catch"](0);
1190
- console.error("There was an error creating multiple DOMNodeReferences: ".concat(_context3.t0));
1191
- throw new Error(_context3.t0);
1217
+ _context4.prev = 10;
1218
+ _context4.t0 = _context4["catch"](0);
1219
+ console.error("There was an error creating multiple DOMNodeReferences: ".concat(_context4.t0));
1220
+ throw new Error(_context4.t0);
1192
1221
  case 14:
1193
1222
  case "end":
1194
- return _context3.stop();
1223
+ return _context4.stop();
1195
1224
  }
1196
- }, _callee3, null, [[0, 10]]);
1225
+ }, _callee4, null, [[0, 10]]);
1197
1226
  }));
1198
1227
  return _createMultipleDOMNodeReferences.apply(this, arguments);
1199
1228
  }
package/index.d.ts CHANGED
@@ -9,11 +9,37 @@ class DOMNodeReference {
9
9
  constructor(target: string): DOMNodeReference;
10
10
 
11
11
  target: string;
12
+ /**
13
+ * The element targeted when instantiating DOMNodeReference.
14
+ * Made available in order to perform normal DOM traversal,
15
+ * or access properties not available through this class.
16
+ * @type {HTMLElement | null}
17
+ */
12
18
  element: HTMLElement | null;
13
19
  isLoaded: boolean;
14
20
  visibilityController: HTMLElement | null;
15
21
  defaultDisplay: string;
22
+ /**
23
+ * The value of the element that this node represents
24
+ * stays in syncs with the live DOM elements via event handler
25
+ * @type {string | null}
26
+ */
16
27
  value: string | null;
28
+ /**
29
+ * Represents the 'yes' option of a boolean radio field.
30
+ * This property is only available when the parent node
31
+ * is a main field for a boolean radio input.
32
+ * @type {DOMNodeReference | undefined}
33
+ */
34
+ yesRadio?: DOMNodeReference;
35
+
36
+ /**
37
+ * Represents the 'no' option of a boolean radio field.
38
+ * This property is only available when the parent node
39
+ * is a main field for a boolean radio input.
40
+ * @type {DOMNodeReference | undefined}
41
+ */
42
+ noRadio?: DOMNodeReference;
17
43
 
18
44
  /**
19
45
  * Initializes the DOMNodeReference instance by waiting for the element to be available in the DOM.
@@ -34,16 +60,40 @@ class DOMNodeReference {
34
60
 
35
61
  /**
36
62
  * Sets the value of the HTML element.
37
- * @param {string} value - The value to set for the HTML element.
63
+ * @param {() => any} value - The value to set for the HTML element.
64
+ * for parents of boolean radios, pass true or false as value, or
65
+ * an expression returning a boolean
38
66
  */
39
67
  setValue(value: string): void;
40
68
 
69
+ /**
70
+ * Disables the element so that users cannot input any data
71
+ */
72
+ disable(): void;
73
+
74
+ /**
75
+ * Enables the element so that users can input data
76
+ */
77
+ enable(): void;
78
+
79
+ /**
80
+ * Prepends elements to the target
81
+ * @param {...HTMLElement} elements - The elements to prepend to the HTML element
82
+ */
83
+ prepend(...elements: HTMLElement[]): void;
84
+
41
85
  /**
42
86
  * Appends child elements to the HTML element.
43
87
  * @param {...HTMLElement} elements - The elements to append to the HTML element.
44
88
  */
45
89
  append(...elements: HTMLElement[]): void;
46
90
 
91
+ /**
92
+ * Inserts elements before the HTML element.
93
+ * @param {...HTMLElement} elements - The elements to insert before the HTML element.
94
+ */
95
+ before(...elements: HTMLElement[]): void;
96
+
47
97
  /**
48
98
  * Inserts elements after the HTML element.
49
99
  * @param {...HTMLElement} elements - The elements to insert after the HTML element.
@@ -52,9 +102,10 @@ class DOMNodeReference {
52
102
 
53
103
  /**
54
104
  * Retrieves the label associated with the HTML element.
55
- * @returns {HTMLElement} The label element associated with this element, or **null** if no label element is present
105
+ * @returns {HTMLElement} The label element associated with this element.
106
+ * @throws {Error} Throws an error if the label cannot be found.
56
107
  */
57
- getLabel(): HTMLElement | null;
108
+ getLabel(): HTMLElement;
58
109
 
59
110
  /**
60
111
  * Appends child elements to the label associated with the HTML element.
@@ -63,33 +114,44 @@ class DOMNodeReference {
63
114
  appendToLabel(...elements: HTMLElement[]): void;
64
115
 
65
116
  /**
66
- * Adds a click event listener to the HTML element.
67
- * @param {Function} eventHandler - The function to execute when the element is clicked.
68
- */
69
- addClickListener(eventHandler: () => void): void;
70
-
71
- /**
72
- * Adds a change event listener to the HTML element.
73
- * @param {Function} eventHandler - The function to execute when the element's value changes.
117
+ * Sets up an event listener based on the specified event type, executing the specified
118
+ * event handler
119
+ * @param {string} eventType - The DOM event to watch for
120
+ * @param {(this: DOMNodeReference, e: Event) => void} eventHandler - The callback function that runs when the
121
+ * specified event occurs
74
122
  */
75
- addChangeListener(eventHandler: () => void): void;
76
-
123
+ on(eventType: string, eventHandler: (event: Event) => void): void;
77
124
  /**
78
125
  * Unchecks both the yes and no radio buttons if they exist.
79
126
  */
80
127
  uncheckRadios(): void;
81
128
 
82
129
  /**
83
- * Creates a validation instance for the field.
84
- * @param {Function} evaluationFunction - The function used to evaluate the field.
85
- * @param {string} fieldDisplayName - The field name to display in error if validation
86
- * fails.
130
+ * Configures validation and requirement conditions for the field based on the provided logic functions and dependencies.
131
+ * Creates a validator and sets a required level dynamically based on dependency changes.
132
+ * @param {Object} config An object containing the requirement and validation logical functions
133
+ * @param {(this: DOMNodeReference) => boolean} config.requirementLogic - Function to determine if the field is required.
134
+ * @param {(this: DOMNodeReference) => boolean} config.validationLogic - Function to evaluate the field's validity.
135
+ * @param {string} fieldDisplayName - Display name used in error messages if validation fails.
136
+ * @param {Array<DOMNodeReference>} [dependencies] - Optional dependencies for setting requirement conditions dynamically.
87
137
  */
88
- createValidation(
89
- evaluationFunction: (value: any) => boolean,
90
- fieldDisplayName: string
138
+ configureValidationAndRequirements(
139
+ config: {
140
+ requirementLogic: (this: this) => boolean;
141
+ validationLogic: (this: this) => boolean;
142
+ },
143
+ fieldDisplayName: string,
144
+ dependencies?: DOMNodeReference[]
91
145
  ): void;
92
146
 
147
+ /**
148
+ * Sets the required level for the field by adding or removing the "required-field" class on the label.
149
+ *
150
+ * @param {boolean} isRequired - Determines whether the field should be marked as required.
151
+ * If true, the "required-field" class is added to the label; if false, it is removed.
152
+ */
153
+ setRequiredLevel(isRequired: boolean): void;
154
+
93
155
  /**
94
156
  * Adds a tooltip with specified text to the label associated with the HTML element.
95
157
  * @param {string} text - The text to display in the tooltip.
@@ -110,17 +172,19 @@ class DOMNodeReference {
110
172
  toggleVisibility(shouldShow: boolean): void;
111
173
 
112
174
  /**
175
+ * Configures conditional rendering for the target element based on a condition
176
+ * and the visibility of one or more trigger elements.
113
177
  *
114
- * @param {Function} condition A Function that return a boolean value to set the
115
- * visibility of the targeted element. if condition() returns true, element is shown.
116
- * If false, element is hidden
117
- * @param {DOMNodeReference} triggerNode The DOMNodeReference to which an
118
- * event listener will be registered to change the visibility state of the calling
119
- * DOMNodeReference
178
+ * @param {Function} condition - A function that returns a boolean to determine
179
+ * the visibility of the target element. If `condition()` returns true, the element is shown;
180
+ * otherwise, it is hidden.
181
+ * @param {DOMNodeReference | DOMNodeReference[]} triggerNodes - A single `DOMNodeReference`
182
+ * or an array of `DOMNodeReference` instances. Event listeners are registered on each
183
+ * `triggerNode` to toggle the visibility of the target element based on the `condition`.
120
184
  */
121
185
  configureConditionalRendering(
122
186
  condition: () => boolean,
123
- triggerNode: DOMNodeReference
187
+ triggerNodes?: DOMNodeReference | DOMNodeReference[]
124
188
  ): void;
125
189
 
126
190
  /**
package/package.json CHANGED
@@ -1,61 +1,61 @@
1
- {
2
- "name": "powerpagestoolkit",
3
- "version": "1.3.102",
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
- "main": "./dist/index.bundle.js",
6
- "types": "index.d.ts",
7
- "scripts": {
8
- "build": "webpack",
9
- "lint": "eslint ./src/JS/*"
10
- },
11
- "devDependencies": {
12
- "@babel/core": "^7.25.8",
13
- "@babel/node": "^7.26.0",
14
- "@babel/preset-env": "^7.25.8",
15
- "@types/node": "^22.8.0",
16
- "babel-loader": "^9.2.1",
17
- "clean-webpack-plugin": "^4.0.0",
18
- "css-loader": "^7.1.2",
19
- "eslint": "^8.57.1",
20
- "eslint-plugin-import": "^2.31.0",
21
- "style-loader": "^4.0.0",
22
- "terser-webpack-plugin": "^5.3.4",
23
- "typescript": "^5.6.3",
24
- "webpack": "^5.95.0",
25
- "webpack-cli": "^5.1.4"
26
- },
27
- "author": "KeatonBrewster",
28
- "license": "SSPL-1.0",
29
- "type": "module",
30
- "repository": {
31
- "type": "git",
32
- "url": "https://github.com/Keaton-Brewster/PowerPagesToolKit"
33
- },
34
- "keywords": [
35
- "powerpages",
36
- "power pages",
37
- "power platform",
38
- "dynamics 365",
39
- "power apps portal",
40
- "dynamics 365 portal",
41
- "portal",
42
- "portal management",
43
- "api",
44
- "javascript",
45
- "ajax",
46
- "dataverse",
47
- "dom-manipulation",
48
- "node",
49
- "http-request",
50
- "json",
51
- "rest-api",
52
- "ajax-wrapper",
53
- "form-management",
54
- "frontend",
55
- "web-development"
56
- ],
57
- "files": [
58
- "dist",
59
- "index.d.ts"
60
- ]
61
- }
1
+ {
2
+ "name": "powerpagestoolkit",
3
+ "version": "1.3.104",
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
+ "main": "./dist/index.bundle.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "build": "webpack",
9
+ "lint": "eslint ./src/JS/*"
10
+ },
11
+ "devDependencies": {
12
+ "@babel/core": "^7.25.8",
13
+ "@babel/node": "^7.26.0",
14
+ "@babel/preset-env": "^7.25.8",
15
+ "@types/node": "^22.8.0",
16
+ "babel-loader": "^9.2.1",
17
+ "clean-webpack-plugin": "^4.0.0",
18
+ "css-loader": "^7.1.2",
19
+ "eslint": "^8.57.1",
20
+ "eslint-plugin-import": "^2.31.0",
21
+ "style-loader": "^4.0.0",
22
+ "terser-webpack-plugin": "^5.3.4",
23
+ "typescript": "^5.6.3",
24
+ "webpack": "^5.95.0",
25
+ "webpack-cli": "^5.1.4"
26
+ },
27
+ "author": "KeatonBrewster",
28
+ "license": "SSPL-1.0",
29
+ "type": "module",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/Keaton-Brewster/PowerPagesToolKit"
33
+ },
34
+ "keywords": [
35
+ "powerpages",
36
+ "power pages",
37
+ "power platform",
38
+ "dynamics 365",
39
+ "power apps portal",
40
+ "dynamics 365 portal",
41
+ "portal",
42
+ "portal management",
43
+ "api",
44
+ "javascript",
45
+ "ajax",
46
+ "dataverse",
47
+ "dom-manipulation",
48
+ "node",
49
+ "http-request",
50
+ "json",
51
+ "rest-api",
52
+ "ajax-wrapper",
53
+ "form-management",
54
+ "frontend",
55
+ "web-development"
56
+ ],
57
+ "files": [
58
+ "dist",
59
+ "index.d.ts"
60
+ ]
61
+ }