powerpagestoolkit 3.0.402 → 3.0.404
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/dist/src/ancillary/DOMNodeReference.d.ts +11 -29
- package/dist/src/ancillary/EventManager.d.ts +9 -9
- package/dist/src/ancillary/InfoElement.d.ts +25 -0
- package/dist/src/ancillary/LoadingSpinner.d.ts +16 -0
- package/dist/src/ancillary/Radio.d.ts +3 -0
- package/dist/src/core/PowerPagesElement.d.ts +3 -0
- package/dist/src/core/getPowerPagesElement.d.ts +2 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +4 -4
- package/dist/src/utils/InputMask.d.ts +1 -1
- package/package.json +6 -3
- package/dist/src/globals.d.ts +0 -195
- package/dist/src/utils/createInfoElement.d.ts +0 -8
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference path="../globals.d.ts" />
|
|
2
|
+
import type EventManager from "../ancillary/EventManager.d.ts";
|
|
2
3
|
import type ValueManager from "../ancillary/ValueManager.d.ts";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
export default class DOMNodeReference {
|
|
4
|
+
import type VisibilityManager from "./VisibilityManager.d.ts";
|
|
5
|
+
export default abstract class DOMNodeReference {
|
|
6
6
|
static instances: DOMNodeReference[];
|
|
7
7
|
[key: symbol]: (...arg: any[]) => any;
|
|
8
8
|
target: Element | string;
|
|
@@ -27,16 +27,6 @@ export default class DOMNodeReference {
|
|
|
27
27
|
visibilityManager: VisibilityManager | null;
|
|
28
28
|
valueManager: ValueManager | null;
|
|
29
29
|
eventManager: EventManager | null;
|
|
30
|
-
/**
|
|
31
|
-
* Represents the 'yes' option of a boolean radio field.
|
|
32
|
-
* This property is only available when the parent node
|
|
33
|
-
* is a main field for a boolean radio input.
|
|
34
|
-
*/
|
|
35
|
-
/**
|
|
36
|
-
* Represents the 'no' option of a boolean radio field.
|
|
37
|
-
* This property is only available when the parent node
|
|
38
|
-
* is a main field for a boolean radio input.
|
|
39
|
-
*/
|
|
40
30
|
/**
|
|
41
31
|
* Creates an instance of DOMNodeReference.
|
|
42
32
|
* @param target - The CSS selector to find the desired DOM element.
|
|
@@ -44,11 +34,10 @@ export default class DOMNodeReference {
|
|
|
44
34
|
* Defaults to 'document.body'
|
|
45
35
|
*/
|
|
46
36
|
/******/ /******/ constructor(target: Element | string, root: Element | undefined, timeoutMs: number);
|
|
37
|
+
protected abstract initValueManager(): void;
|
|
38
|
+
protected abstract initVisibilityManager(): void;
|
|
39
|
+
protected abstract initEventManager(): void;
|
|
47
40
|
protected _extractLogicalName(target: Element | string): string;
|
|
48
|
-
/**
|
|
49
|
-
* Initializes value synchronization with appropriate event listeners
|
|
50
|
-
* based on element type.
|
|
51
|
-
*/
|
|
52
41
|
protected _valueSync(): void;
|
|
53
42
|
protected _determineEventType(): keyof GlobalEventHandlersEventMap;
|
|
54
43
|
protected _isDateInput(): boolean;
|
|
@@ -159,7 +148,7 @@ export default class DOMNodeReference {
|
|
|
159
148
|
* @param string - The text to set as the inner HTML of the element.
|
|
160
149
|
* @returns - Instance of this [provides option to method chain]
|
|
161
150
|
*/
|
|
162
|
-
setInnerHTML(string: string):
|
|
151
|
+
setInnerHTML(string: string): DOMNodeReference;
|
|
163
152
|
/**
|
|
164
153
|
* Removes this element from the DOM
|
|
165
154
|
* @returns - Instance of this [provides option to method chain]
|
|
@@ -170,7 +159,7 @@ export default class DOMNodeReference {
|
|
|
170
159
|
* @param options - An object containing CSS property-value pairs, e.g., { display: 'block' }.
|
|
171
160
|
* @returns The instance, enabling method chaining.
|
|
172
161
|
*/
|
|
173
|
-
setStyle(options: Partial<CSSStyleDeclaration>):
|
|
162
|
+
setStyle(options: Partial<CSSStyleDeclaration>): DOMNodeReference;
|
|
174
163
|
/**
|
|
175
164
|
* Applies a business rule to manage visibility, required state, value, and disabled state dynamically.
|
|
176
165
|
* @see {@link BusinessRule}
|
|
@@ -181,15 +170,8 @@ export default class DOMNodeReference {
|
|
|
181
170
|
applyBusinessRule(rule: BusinessRule, dependencies: DependencyArray<DOMNodeReference>): DOMNodeReference;
|
|
182
171
|
private _setupRequirementsValidator;
|
|
183
172
|
private _createBusinessRuleHandler;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
* Sets up tracking for dependencies using both event listeners and mutation observers.
|
|
187
|
-
* @protected
|
|
188
|
-
* @param handler The function to execute when dependencies change
|
|
189
|
-
* @param dependencies Array of dependent DOM nodes to track
|
|
190
|
-
* all other options defaults to true
|
|
191
|
-
*/
|
|
192
|
-
protected _configureDependencyTracking(handler: DependencyHandler, dependencies: DOMNodeReference[]): void;
|
|
173
|
+
private _createValidator;
|
|
174
|
+
private _configureDependencyTracking;
|
|
193
175
|
/**
|
|
194
176
|
* Sets the required level for the field by adding or removing the "required-field" class on the label.
|
|
195
177
|
*
|
|
@@ -205,5 +187,5 @@ export default class DOMNodeReference {
|
|
|
205
187
|
* @param callback A callback function to execute once the element is loaded.
|
|
206
188
|
* Receives instance of 'this' as an argument
|
|
207
189
|
*/
|
|
208
|
-
onceLoaded(callback: (instance: DOMNodeReference) => any):
|
|
190
|
+
onceLoaded(callback: (instance: DOMNodeReference) => any): void;
|
|
209
191
|
}
|
|
@@ -9,17 +9,17 @@ declare type Handler = (this: DOMNodeReference, ...args: any[]) => void;
|
|
|
9
9
|
private observers;
|
|
10
10
|
private boundListeners;
|
|
11
11
|
constructor();
|
|
12
|
-
dispatchDependencyHandlers(): void;
|
|
13
|
-
registerDependent(dependency: DOMNodeReference, handler: Handler):
|
|
14
|
-
registerEvent(event: EventType, handler: Handler):
|
|
15
|
-
registerListener(event: EventType, listener: DOMNodeReference):
|
|
16
|
-
emit(eventType: EventType, ...args: any[]): void;
|
|
17
|
-
stopListening(listener: DOMNodeReference): void;
|
|
18
|
-
registerObserver(observer: MutationObserver | ResizeObserver, observerOptions: {
|
|
12
|
+
/********/ dispatchDependencyHandlers(): void;
|
|
13
|
+
/********/ registerDependent(dependency: DOMNodeReference, handler: Handler): "success" | Error;
|
|
14
|
+
/********/ registerEvent(event: EventType, handler: Handler): "success" | Error;
|
|
15
|
+
/********/ registerListener(event: EventType, listener: DOMNodeReference): "success" | Error;
|
|
16
|
+
/********/ emit(eventType: EventType, ...args: any[]): void;
|
|
17
|
+
/********/ stopListening(listener: DOMNodeReference): void;
|
|
18
|
+
/********/ registerObserver(observer: MutationObserver | ResizeObserver, observerOptions: {
|
|
19
19
|
nodeToObserve: Element;
|
|
20
20
|
options: Partial<ResizeObserverOptions> | Partial<MutationObserverInit>;
|
|
21
21
|
}): void;
|
|
22
|
-
registerDOMEventListener(element: Element, eventType: keyof HTMLElementEventMap, handler: (e: Event) => unknown): void;
|
|
23
|
-
destroy(): void;
|
|
22
|
+
/********/ registerDOMEventListener(element: Element, eventType: keyof HTMLElementEventMap, handler: (e: Event) => unknown): void;
|
|
23
|
+
/********/ destroy(): void;
|
|
24
24
|
}
|
|
25
25
|
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference path="../globals.d.ts" />
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {string} titleString The text to display in the tooltip flyout content
|
|
5
|
+
* @param iconStyle Optional CSS styles to apply to the info icon
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
/********/ /********/ export default class InfoElement extends HTMLElement {
|
|
9
|
+
private flyoutContent;
|
|
10
|
+
private icon;
|
|
11
|
+
private observers;
|
|
12
|
+
/********/ constructor(titleString: string, iconStyle?: Partial<CSSStyleDeclaration>);
|
|
13
|
+
/********/ private attachEventListeners;
|
|
14
|
+
/********/ private setupObservers;
|
|
15
|
+
/********/ private getDesiredWidth;
|
|
16
|
+
/********/ private positionFlyout;
|
|
17
|
+
/********/ private updateFlyoutWidth;
|
|
18
|
+
/********/ private handleClick;
|
|
19
|
+
/********/ private handleResize;
|
|
20
|
+
/********/ private handleTouchStart;
|
|
21
|
+
/********/ private handleMouseEnter;
|
|
22
|
+
/********/ private handleMouseLeave;
|
|
23
|
+
/********/ private handleScroll;
|
|
24
|
+
/********/ private destroy;
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference path="../globals.d.ts" />
|
|
2
|
+
/**
|
|
3
|
+
* @class LoadingSpinner - instantiate a spinner to handle loading state in your powerpages site
|
|
4
|
+
*/
|
|
5
|
+
/********/ /********/ export default class LoadingSpinner extends HTMLElement {
|
|
6
|
+
private element;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* @method hide - Hides the loading spinner
|
|
10
|
+
*/
|
|
11
|
+
hide(): void;
|
|
12
|
+
/**
|
|
13
|
+
* @method show - Shows the loading spinner
|
|
14
|
+
*/
|
|
15
|
+
show(): void;
|
|
16
|
+
}
|
|
@@ -5,4 +5,7 @@ export default class Radio extends DOMNodeReference {
|
|
|
5
5
|
radioType: RadioType | undefined;
|
|
6
6
|
radioParent: DOMNodeReference | undefined;
|
|
7
7
|
constructor(parent: DOMNodeReference, target: Element | string, root: Element | undefined, timeoutMs: number, radioType: RadioType);
|
|
8
|
+
protected initEventManager(): void;
|
|
9
|
+
protected initValueManager(): void;
|
|
10
|
+
protected initVisibilityManager(): void;
|
|
8
11
|
}
|
|
@@ -23,6 +23,9 @@ import Radio from "../ancillary/Radio.d.ts";
|
|
|
23
23
|
* Defaults to 'document.body'
|
|
24
24
|
*/
|
|
25
25
|
/******/ constructor(target: Element | string, root: Element | undefined, timeoutMs: number);
|
|
26
|
+
protected initValueManager(): void;
|
|
27
|
+
protected initVisibilityManager(): void;
|
|
28
|
+
protected initEventManager(): void;
|
|
26
29
|
protected _attachRadioButtons(): Promise<void>;
|
|
27
30
|
clearValue(): void;
|
|
28
31
|
/**
|
|
@@ -16,7 +16,8 @@ import PowerPagesElement from "./PowerPagesElement.d.ts";
|
|
|
16
16
|
* @see {@link enhanceArray}
|
|
17
17
|
*/
|
|
18
18
|
export default function createPowerPagesElement(target: string | Element): Promise<PowerPagesElement>;
|
|
19
|
-
export default function createPowerPagesElement(target: Element
|
|
19
|
+
export default function createPowerPagesElement(target: Element): Promise<PowerPagesElement>;
|
|
20
|
+
export default function createPowerPagesElement(target: string, options?: {
|
|
20
21
|
/**
|
|
21
22
|
* Optionally specify the element within which to search for the element targeted by 'target'.
|
|
22
23
|
* Defaults to 'document.body'.
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import API from "./core/API.d.ts";
|
|
|
2
2
|
import get from "./core/getPowerPagesElement.d.ts";
|
|
3
3
|
import waitFor from "./core/waitFor.d.ts";
|
|
4
4
|
import bindForm from "./core/bindForm.d.ts";
|
|
5
|
-
|
|
5
|
+
import LoadingSpinner from "./ancillary/LoadingSpinner.d.ts";
|
|
6
|
+
export { API, bindForm, get, waitFor, LoadingSpinner };
|
package/dist/src/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* @ts-self-types="./index.d.ts" */
|
|
2
|
-
function E(s){let e=$.Deferred();return shell.getTokenDeferred().done(function(t){s.headers?s.headers.__RequestVerificationToken=t:$.extend(s,{headers:{__RequestVerificationToken:t}}),$.ajax(s).done(function(i,n,r){validateLoginSession(i,n,r,e.resolve)}).fail(e.reject)}).fail(function(){e.rejectWith(this,arguments)}),e.promise()}var S=class{static createRecord(e,t){return new Promise((i,n)=>{E({type:"POST",url:`/_api/${e}`,data:JSON.stringify(t),contentType:"application/json",success:function(r,o,l){i(l.getResponseHeader("entityid"))},error:r=>{n(r)}})})}static getRecord(e,t,i){return new Promise((n,r)=>{let o=`/_api/${e}(${t})${i?`?$${i}`:""}`;E({type:"GET",url:o,success:n,error:r})})}static getMultiple(e,t){return new Promise((i,n)=>{let r=`/_api/${e}${t?`?${t}`:""}`;E({type:"GET",url:r,success:function(o){i(o.value)},error:n})})}static updateRecord(e,t,i){return new Promise((n,r)=>{let o=`/_api/${e}(${t})`;E({type:"PATCH",url:o,data:JSON.stringify(i),success:n,error:r})})}},k=S;var M=class{events=new Map;listeners=new Map;dependencyHandlers=new Set;observers=[];boundListeners=[];constructor(){}dispatchDependencyHandlers(){for(let[e,t]of this.dependencyHandlers)t.call(e)}registerDependent(e,t){try{return this.dependencyHandlers.add([e,t]),!0}catch{return!1}}registerEvent(e,t){return this.events.has(e)?(console.error("Event registration has already been defined for: ",e),!1):(this.listeners.set(e,new Set),this.events.set(e,t),!0)}registerListener(e,t){if(this.events.has(e)){let i=this.listeners.get(e)??new Set;return i.add(t),this.listeners.set(e,i),!0}else return console.error("No event registration found for: ",e),!1}emit(e,...t){if(this.events.has(e)){let i=this.events.get(e),n=this.listeners.get(e);if(!n)return;for(let r of n)i.call(r,...t)}else console.error("Event not found in EventRegistry: ",e)}stopListening(e){for(let[t,i]of this.listeners)i.has(e)&&i.delete(e)}registerObserver(e,t){let{nodeToObserve:i,options:n}=t;e.observe(i,n),this.observers.push(e)}registerDOMEventListener(e,t,i){e.addEventListener(t,i),this.boundListeners.push({element:e,handler:i,event:t})}destroy(){this.boundListeners?.forEach(e=>{e.element?.removeEventListener(e.event,e.handler)}),this.boundListeners=[],this.observers?.forEach(e=>{e.disconnect()}),this.observers=[],this.events.clear(),this.dependencyHandlers.clear(),this.listeners.clear()}};var w=class{defaultVisibility;set defaultDisplay(e){this.defaultVisibility=e}constructor(e){if(this.visibilityController=e,e.tagName==="TABLE"){let i=e.closest("fieldset");i&&(this.visibilityController=i)}if(["SPAN","INPUT","TEXTAREA","SELECT","TABLE"].includes(e.tagName)){let i=e.closest("td");i&&(this.visibilityController=i)}this.defaultVisibility=this.visibilityController.style.display}hide(){this.visibilityController.style.display="none"}show(){this.visibilityController.style.display=this.defaultVisibility}toggleVisibility(e){e?this.show():this.hide()}getVisibility(){return window.getComputedStyle(this.visibilityController).display!=="none"&&window.getComputedStyle(this.visibilityController).visibility!=="hidden"&&this.visibilityController.getBoundingClientRect().height>0&&this.visibilityController.getBoundingClientRect().width>0}destroy(){this.visibilityController=null,this.defaultVisibility=null}};function D(s,e){if(typeof s!="string")throw new Error(`argument "titleString" must be of type "string". Received: "${typeof s}"`);if(e&&typeof e!="object")throw new Error(`argument "iconStyle" must be of type "object". Received: "${typeof e}"`);let t=document.createElement("span");t.classList.add("info-icon");let i=document.createElement("i");i.classList.add("fa","fa-solid","fa-info-circle"),i.setAttribute("aria-label","Info"),i.style.cursor="pointer";let n=document.createElement("div");n.innerHTML=s,n.classList.add("flyout-content"),t.appendChild(i),t.appendChild(n),e&&Object.assign(i.style,e);let r=()=>{n.style.display="block";let o=n.getBoundingClientRect(),l=window.innerWidth;if(o.right>l){let a=o.right-l;n.style.left=`calc(50% - ${a}px)`}if(o.left<0){let a=Math.abs(o.left);n.style.left=`calc(50% + ${a}px)`}};return t.addEventListener("mouseenter",()=>{r()}),t.addEventListener("mouseleave",o=>{let l=o.relatedTarget;t.contains(l)||(n.style.display="none")}),i.addEventListener("touchstart",o=>{o.preventDefault(),n.style.display=n.style.display==="block"?"none":"block",n.style.display==="block"&&r()}),document.body.addEventListener("click",o=>{t.contains(o.target)||(n.style.display="none")}),n.style.display="none",t}function y(s,e=document,t=!1,i){return new Promise((n,r)=>{if(t){let o,l=[],a=new Set;if(i<1)return n(Array.from(e.querySelectorAll(s)));let c=new MutationObserver(()=>{Array.from(e.querySelectorAll(s)).forEach(V=>{a.has(V)||(a.add(V),l.push(V))}),clearTimeout(o),o=setTimeout(()=>{l.length>0?(c.disconnect(),n(l)):r(new Error(`No elements found with target: "${s}" within ${i/1e3} seconds. If the element you are expecting has not loaded yet, consider raising your timeout.`))},i)});c.observe(e,{childList:!0,subtree:!0,attributes:!1})}else{let o=new MutationObserver(()=>{let c=e.querySelector(s);c&&(clearTimeout(l),o.disconnect(),n(c))}),l=setTimeout(()=>{o.disconnect(),r(new Error(`Element not found by target: "${s}" within ${i/1e3} second. If the element you are expecting has not loaded yet, consider raising your timeout.`))},i),a=e.querySelector(s);if(a)return clearTimeout(l),n(a);o.observe(e,{subtree:!0,attributes:!0,childList:!0})}})}var m=class extends Error{node;constructor(e,t){super(t),this.node=e,Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}},H=class extends m{constructor(e,t){super(e,`There was an error initializing a DOMNodeReference for target: ${e.target}, :: ${t}`)}},C=class extends m{constructor(e){super(e,`The targeted DOM element was not found: ${e.target}`)}},I=class extends m{constructor(e){super(e,"Page_Validators could not be found")}},A=class extends m{constructor(e){super(e,`Error applying business rule to target: ${e.target}`)}},F=class extends m{constructor(e){super(e,"Self-referential dependency found. A DOMNodeReference cannot depend on itself")}},_=class extends m{constructor(e){super(e,`No label could be found for the target: ${e.target}`)}},B=class extends m{constructor(e,t,i,n,r){let o=n.join(" or ");super(e,`${t} expects ${i} to be of type ${o}. Received: ${r===null?"null":typeof r}`)}},W={NodeNotFoundError:C,InitializationError:H,Page_ValidatorsNotFoundError:I,BusinessRuleError:A,SelfReferenceError:F,LabelNotFoundError:_,IncorrectParameterError:B},u=W;var h=Symbol("init"),p=Symbol("destroy");var N={CHECKBOX:"click",RADIO:"click",SELECT:"change",TEXT:"keyup",DEFAULT:"input"};var f=class s{static instances=[];target;logicalName;root;timeoutMs;isLoaded;get value(){return this.valueManager.value}set value(e){this.valueManager.setValue(e)}get checked(){return this.valueManager.checked}set defaultDisplay(e){this.visibilityManager.defaultDisplay=e}visibilityManager;valueManager;eventManager;constructor(e,t=document.body,i){this.target=e,this.logicalName=this._extractLogicalName(e),this.root=t,this.timeoutMs=i,this.isLoaded=!1}async[h](){if(this.target instanceof HTMLElement?this.element=this.target:this.element=await y(this.target,this.root,!1,this.timeoutMs),!this.element)throw new u.NodeNotFoundError(this);this.eventManager=new M,this.visibilityManager=new w(this.element)}_extractLogicalName(e){if(typeof e!="string")return"";let t=e.match(/\[([^\]]+)\]/);if(!t)return e.replace(/[#\[\]]/g,"");let i=t[1];return(i.match(/["']([^"']+)["']/)?.[1]||i).replace(/[#\[\]]/g,"")}_valueSync(){if(!this._isValidFormElement(this.element))return;this.updateValue();let e=this._determineEventType();this.eventManager.registerDOMEventListener(this.element,e,this.updateValue.bind(this)),this._isDateInput()&&this._dateSync(this.element)}_determineEventType(){return this.element instanceof HTMLSelectElement?"change":this.element instanceof HTMLTextAreaElement?"keyup":this.element instanceof HTMLInputElement?N[this.element.type.toUpperCase()]||N.DEFAULT:N.DEFAULT}_isDateInput(){return this.element instanceof HTMLInputElement&&this.element.dataset.type==="date"}_isValidFormElement(e){return e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSpanElement||e instanceof HTMLButtonElement||e instanceof HTMLFieldSetElement}async _dateSync(e){let t=e.parentElement;if(!t)throw new DOMException("Date input must have a parent element");let i=await y("[data-date-format]",t,!1,1500);this.valueManager.element=i,this.eventManager.registerDOMEventListener(i,"select",this.updateValue.bind(this))}_bindMethods(){let e=Object.getPrototypeOf(this);for(let t of Object.getOwnPropertyNames(e)){let i=this[t];t!=="constructor"&&typeof i=="function"&&(this[t]=i.bind(this))}}[p](){this.isLoaded=!1,this.value=null,this.eventManager.destroy(),this.eventManager=null,this.visibilityManager.destroy(),this.visibilityManager=null,this.valueManager.destroy(),this.valueManager=null}async updateValue(e){e&&!e.isTrusted||(await this.valueManager.updateValue(e),this.triggerDependentsHandlers())}triggerDependentsHandlers(){this.eventManager.dispatchDependencyHandlers()}on(e,t){if(typeof t!="function")throw new u.IncorrectParameterError(this,"on","eventHandler",["function"],typeof t);let i=t;return this.eventManager.registerDOMEventListener(this.element,e,i.bind(this)),this}hide(){return this.visibilityManager.hide(),this}show(){return this.visibilityManager.show(),this}toggleVisibility(e){let t=e instanceof Function?e.call(this):e;return this.visibilityManager.toggleVisibility(t),this}setValue(e){return e instanceof Function&&(e=e()),this.valueManager.setValue(e),this}disable(){return this.element.disabled=!0,this}clearValue(){this.valueManager.clearValue(),this._getChildren()&&this.callAgainstChildrenInputs(e=>e.clearValue())}_getChildren(){let t=Array.from(this.element.querySelectorAll("input, select, textarea")).map(n=>n.id),i=s.instances.filter(n=>t.includes(n.element.id));return i.length>0?i:null}callAgainstChildrenInputs(e){let t=this._getChildren();if(!t){console.error("No child inputs found for target: ",this);return}for(let i of t)e(i)}enable(){return this.element.disabled=!1,this}prepend(...e){return this.element.prepend(...e),this}append(...e){return this.element.append(...e),this}before(...e){return this.element.before(...e),this}after(...e){return this.element.after(...e),this}getLabel(){let e=document.querySelector(`#${this.element.id}_label`)||null;if(!e)throw new u.LabelNotFoundError(this);return e}addLabelTooltip(e,t){return this.getLabel()?.append(D(e,t||void 0)),this}addTooltip(e,t){return this.append(D(e,t||void 0)),this}setInnerHTML(e){return this.element.innerHTML=e,this}remove(){return this.element.remove(),this}setStyle(e){if(e===null||typeof e!="object")throw new u.IncorrectParameterError(this,"setStyle","options",["Partial<CSSStyleDeclaration>"],typeof e);return Object.entries(e).forEach(([t,i])=>{i!==void 0&&(this.element.style[t]=i)}),this}applyBusinessRule(e,t){try{e.setRequirements&&this._setupRequirementsValidator(e.setRequirements());let i=this._createBusinessRuleHandler(e);return i(),t.length&&this._configureDependencyTracking(i,t),this}catch(i){throw i instanceof Error?i:new u.BusinessRuleError(this)}}_setupRequirementsValidator(e){let{isRequired:t,isValid:i}=e;if(typeof Page_Validators>"u")throw new u.Page_ValidatorsNotFoundError(this);let n=()=>!0;t&&i?n=()=>{let r=t.call(this),o=this.visibilityManager.getVisibility();return!r||o&&i.call(this,r)}:i?n=()=>this.visibilityManager.getVisibility()&&i.call(this):t&&(n=()=>this.visibilityManager.getVisibility()&&t.call(this)),this._createValidator(n)}_createBusinessRuleHandler(e){return()=>{let t=!1;if(e.setVisibility){let n=e.setVisibility.call(this);t=!n,this.toggleVisibility(n)}if(e.setRequirements&&e.setRequirements().isRequired){let{isRequired:i}=e.setRequirements();this.setRequiredLevel(i.call(this))}if(e.setValue){let{condition:i,value:n}=e.setValue();if(i.call(this)){let r=n instanceof Function?n():n;this.setValue.call(this,r)}}e.setDisabled&&(e.setDisabled.call(this)?this.disable():this.enable()),t&&!e.setValue&&this.clearValue(),this.triggerDependentsHandlers()}}_createValidator(e){let t=(()=>{let r=this.getLabel();if(!r)throw new u.LabelNotFoundError(this);return r=r.innerHTML,r.length>50&&(r=r.substring(0,50)+"..."),r})(),i=`${this.element.id}Validator`,n=document.createElement("span");if(n.style.display="none",n.id=i,Object.assign(n,{controltovalidate:this.element.id,errormessage:`<a href='#${this.element.id}_label'>${t} is a required field</a>`,evaluationfunction:e}),Page_Validators==null)throw new u.Page_ValidatorsNotFoundError(this);Page_Validators.push(n)}_configureDependencyTracking(e,t){if(t.length<1){console.error(`powerpagestoolkit: No dependencies specified for ${this.element.id}. Include all required nodes in the dependency array for proper tracking.`);return}t.forEach(i=>{if(!i||!(i instanceof s))throw new TypeError("Each dependency must be a valid DOMNodeReference instance");if(i.logicalName===this.logicalName)throw new u.SelfReferenceError(this);i.eventManager.registerDependent(this,e.bind(this))})}setRequiredLevel(e){return e instanceof Function?(e()?this.getLabel()?.classList.add("required-field"):this.getLabel()?.classList.remove("required-field"),this):(e?this.getLabel()?.classList.add("required-field"):this.getLabel()?.classList.remove("required-field"),this)}onceLoaded(e){if(this.isLoaded){e(this);return}if(this.target instanceof HTMLElement){e(this);return}let t=new MutationObserver(function(){document.querySelector(this.target)&&(t.disconnect(),this.isLoaded=!0,e(this))}.bind(this));this.eventManager.registerObserver(t,{nodeToObserve:document.body,options:{subtree:!0,childList:!0}})}};var b=class{constructor(){}onFocus(){setTimeout(()=>this.input.select(),0)}onBlur(){this.formatInput()}setValue(e){this.input.value=String(e)}destroy(){this.input.removeEventListener("blur",this.onBlur),this.input.removeEventListener("focus",this.onFocus)}};var R=class extends b{input;options;constructor(e,t={}){super(),this.input=e,this.options={format:t.format||"(xxx) xxx-xxxx",countryCode:t.countryCode||"",countryCodeFormat:t.countryCodeFormat||"+"},this.onFocus=this.onFocus.bind(this),this.formatInput=this.formatInput.bind(this),this.onBlur=this.onBlur.bind(this),this.setupEventListeners(),setTimeout(()=>{this.formatInput()},0)}setupEventListeners(){this.input.addEventListener("focus",this.onFocus),this.input.addEventListener("input",this.formatInput),this.input.addEventListener("blur",this.onBlur)}formatInput(){let e=this.input.value,t=this.input.selectionStart||0,i=e.length,n=e.replace(/\D/g,""),r=this.formatPhoneNumber(n);this.input.value=r;let o=Math.min(t+(r.length-i),r.length);this.input.setSelectionRange(o,o)}formatPhoneNumber(e){if(!e)return"";let t=e,i="";if(this.options.countryCode){let a=this.options.countryCode.length;e.length>a?(i=e.substring(0,a),t=e.substring(a)):(i=e,t="")}let n="";if(i)switch(this.options.countryCodeFormat){case"+":n=`+${i} `;break;case"()":n=`(${i}) `;break;case"00":n=`00${i} `;break;default:n=`+${i} `}let r=this.options.format,o=0;for(let a=0;a<r.length&&o<t.length;a++)r[a]==="x"&&(r=r.substring(0,a)+t[o++]+r.substring(a+1));r=r.replace(/x/g,"");let l=r.split("").findIndex((a,c)=>!/\d/.test(a)&&r.substring(c).indexOf("x")===-1&&r.substring(c).replace(/[\s\-()]/g,"").length===0);return l!==-1&&(r=r.substring(0,l)),n+r}onFocus(){setTimeout(()=>this.input.select(),0)}onBlur(){this.formatInput();let e=this.getDigits(),t=this.options.countryCode?7+this.options.countryCode.length:7;e.length<t}getDigits(){return this.input.value.replace(/\D/g,"")}getCountryCode(){if(!this.options.countryCode)return"";let e=this.getDigits(),t=this.options.countryCode.length;return e.length>=t?e.substring(0,t):e}getPhoneDigits(){if(!this.options.countryCode)return this.getDigits();let e=this.getDigits(),t=this.options.countryCode.length;return e.length>t?e.substring(t):""}setValue(e){let t=e.replace(/\D/g,"");this.input.value=this.formatPhoneNumber(t)}isValid(){let e=this.getPhoneDigits(),t=this.getCountryCode();return(!this.options.countryCode||t.length===this.options.countryCode.length)&&e.length>=10}destroy(){this.input.removeEventListener("focus",this.onFocus),this.input.removeEventListener("input",this.formatInput),this.input.removeEventListener("blur",this.onBlur)}};var d=class extends f{radioType;constructor(e,t,i=document.body,n,r){super(t,i,n),this.radioParent=e,this.radioType=r}async[h](){try{await super[h](),this.valueManager=new v(this),this._valueSync(),this._bindMethods();let e=new MutationObserver(t=>{for(let i of t)if(Array.from(i.removedNodes).includes(this.element)){this[p](),e.disconnect();break}});e.observe(document.body,{childList:!0,subtree:!0}),f.instances.push(this),this.isLoaded=!0}catch(e){let t=e instanceof Error?e.message:String(e);throw new u.InitializationError(this,t)}}[p](){super[p](),this.radioParent=void 0,this.radioType=void 0}};var v=class{value;checked=!1;element;noRadio;yesRadio;radioParent;isRadio=!1;radioType;constructor(e){e instanceof g?(this.noRadio=e.noRadio,this.yesRadio=e.yesRadio,this.radioParent=void 0):e instanceof d&&(this.isRadio=!0,this.noRadio=void 0,this.yesRadio=void 0,this.radioParent=e.radioParent,this.radioType=e.radioType),this.element=e.element}setValue(e){let t=this._validateValue(e);this.yesRadio instanceof d&&this.noRadio instanceof d?(this.yesRadio.element.checked=!!e,this.noRadio.element.checked=!e,this.value=e,this.element.checked=!!e,this.element.value=e):this.isRadio||this.element.type==="radio"?(this.element.checked=e,this.checked=e,this.value=e,this.radioParent?.updateValue()):(this.element.value=t,this.value=t)}async updateValue(e){e&&e.stopPropagation();let t=await this.getElementValue();if(this.value=t.value,t.checked!==void 0&&(this.checked=t.checked),this.radioParent instanceof g&&e&&e.type!=="manual-radio-sync"){switch(this.radioType){case"falsy":this.radioParent.yesRadio.setValue(!t),await this.radioParent.yesRadio.updateValue(new Event("manual-radio-sync"));break;case"truthy":this.radioParent.noRadio.setValue(!t),await this.radioParent.noRadio.updateValue(new Event("manual-radio-sync"));break}this.radioParent.updateValue()}}getElementValue(){return new Promise(e=>{let t=this.element,i=this.element;this.yesRadio instanceof d&&this.noRadio instanceof d&&e({value:this.yesRadio.checked,checked:this.yesRadio.checked});let n={value:null};switch(t.type){case"checkbox":case"radio":e({value:t.checked,checked:t.checked});break;case"select-multiple":e({value:Array.from(i.selectedOptions).map(r=>r.value)});break;case"select-one":e({value:i.value});break;case"number":e({value:t.value!==""?Number(t.value):null});break;default:{let r=t.value;this.element.classList.contains("decimal")&&(r=parseFloat(t.value.replace(/[$,]/g,"").trim())),n={value:r}}}n={...n,value:this._validateValue(n.value)},e(n)})}_validateValue(e){return typeof e=="boolean"||e==="true"||e==="false"?e===!0||e==="true":this.element instanceof HTMLSelectElement||this.element.type==="text"&&!this.element.classList.contains("decimal")||e===null||e===""||isNaN(Number(e))?e:Number(e)}clearValue(){try{let e=this.element;if(e.defaultValue="",e instanceof HTMLInputElement)switch(e.type.toLowerCase()){case"checkbox":case"radio":e.checked=!1,this.checked=!1,this.value=!1;break;case"number":e.value="",this.value=null;break;default:e.value="",this.value=null;break}else e instanceof HTMLSelectElement?e.multiple?(Array.from(e.options).forEach(t=>t.selected=!1),this.value=null):(e.selectedIndex=-1,this.value=null):e instanceof HTMLTextAreaElement?(e.value="",this.value=null):this.value=null}catch(e){let t=`Failed to clear values for element with target "${this}": ${e instanceof Error?e.message:String(e)}`;throw new Error(t)}}destroy(){this.value=null,this.checked=!1,this.element=null,this.noRadio=void 0,this.yesRadio=void 0,this.isRadio=!1}};var P=class extends b{input;options;buffer="";charAtSelection="";charBeforeSelection="";lengthOf0FormattedValue;digitRegex=/\d/;nonDigitRegex=/\D/g;thousandsRegex=/\B(?=(\d{3})+(?!\d))/g;separatorRegex;constructor(e,t={}){super(),this.input=e,this.options={prefix:t.prefix||"$",decimalPlaces:t.decimalPlaces??2,thousandsSeparator:t.thousandsSeparator||",",decimalSeparator:t.decimalSeparator||".",allowNegative:t.allowNegative??!0};let i=this.escapeRegExp(this.options.thousandsSeparator),n=this.escapeRegExp(this.options.decimalSeparator);this.separatorRegex=new RegExp(`[${i}${n}]`),this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onSelectionChange=this.onSelectionChange.bind(this),this.onBlur=this.onBlur.bind(this),this.lengthOf0FormattedValue=`0${this.options.decimalPlaces>0?this.options.decimalSeparator+"0".repeat(this.options.decimalPlaces):""}`.length,this.setupEventListeners(),this.input.value&&(this.buffer=this.input.value.replace(this.nonDigitRegex,"")),this.formatAndDisplay()}escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}formatAndDisplay(){let e=Number(this.buffer||"0");this.input.value=this.formatNumber(e)}setupEventListeners(){this.input.addEventListener("focus",this.onFocus),this.input.addEventListener("input",this.onInput),this.input.addEventListener("selectionchange",this.onSelectionChange),this.input.addEventListener("blur",this.onBlur)}formatInput(){let e=this.input.value,t=this.input.selectionStart||0,i=e.length,n=new RegExp(`[^0-9${this.options.decimalSeparator}${this.options.allowNegative?"-":""}]`,"g"),r=e.replace(n,""),o=r.split(this.options.decimalSeparator);o.length>2&&(r=o[0]+this.options.decimalSeparator+o.slice(1).join("")),this.options.allowNegative&&r.indexOf("-")>0&&(r=r.replace(/-/g,""),r.charAt(0)!=="-"&&(r="-"+r));let l;r===""||r==="-"?l=0:l=parseFloat(r.replace(this.options.decimalSeparator,".")),isNaN(l)&&(l=0);let a=this.formatNumber(l);this.input.value=a;let c=t+(a.length-i);this.input.setSelectionRange(c,c)}formatNumber(e){let t=e/10**this.options.decimalPlaces,i=t<0,r=Math.abs(t).toFixed(this.options.decimalPlaces),[o,l]=r.split("."),a=o.replace(this.thousandsRegex,this.options.thousandsSeparator);return(i?"-":"")+this.options.prefix+a+(this.options.decimalPlaces>0?this.options.decimalSeparator+l:"")}onSelectionChange(e){let t=this.input.selectionStart;this.charAtSelection=this.input.value[t],this.charBeforeSelection=this.input.value[t-1]}onInput(e){let t=e,i=this.input.value,n=this.input.selectionStart??0,r=i.slice(0,n).replace(this.nonDigitRegex,"").length,o=r;switch(t.inputType){case"insertText":this.buffer=this.buffer.slice(0,r-1)+(t.data||"").replace(this.nonDigitRegex,"")+this.buffer.slice(r-1),o=r;break;case"deleteContentBackward":r>=0?this.separatorRegex.test(this.charBeforeSelection)?(this.buffer=this.buffer.slice(0,r-1)+this.buffer.slice(r),o=r-1):(this.buffer=this.buffer.slice(0,r)+this.buffer.slice(r+1),o=r):i===""&&(this.buffer="");break;case"deleteContentForward":r<this.buffer.length&&(this.buffer=this.buffer.slice(0,r)+this.buffer.slice(r+1));break;case"deleteWordBackward":case"deleteWordForward":this.buffer="",o=this.lengthOf0FormattedValue;break;default:this.buffer=i.replace(this.nonDigitRegex,""),o=this.buffer.length}let l=Number(this.buffer||"0"),a=this.formatNumber(l);this.input.value=a;let c=this.mapRawIndexToFormattedPosition(o,a);this.input.setSelectionRange(c,c)}mapRawIndexToFormattedPosition(e,t){let i=0;for(let n=0;n<t.length;n++)if(this.digitRegex.test(t[n])&&i++,i===e)return n+1;return t.length}onFocus(){setTimeout(()=>this.input.select(),0)}onBlur(){let e=Number(this.buffer||"0");if(this.input.value=this.formatNumber(e),e===0){this.buffer="";let t="0".repeat(this.options.decimalPlaces);this.input.value=`${this.options.prefix}0${this.options.decimalPlaces>0?this.options.decimalSeparator+t:""}`}}getNumericalValue(){return Number(this.buffer||"0")/10**this.options.decimalPlaces}setValue(e){let t=Math.round(Math.abs(e)*10**this.options.decimalPlaces);this.buffer=t.toString(),this.input.value=this.formatNumber(t)}destroy(){this.input.removeEventListener("focus",this.onFocus),this.input.removeEventListener("input",this.onInput),this.input.removeEventListener("selectionchange",this.onSelectionChange),this.input.removeEventListener("blur",this.onBlur)}};var g=class s extends f{isMasked=!1;yesRadio;noRadio;constructor(e,t=document.body,i){super(e,t,i)}async[h](){try{await super[h](),this.element.id&&this.element.querySelectorAll(`#${this.element.id} > input[type="radio"]`).length>0&&await this._attachRadioButtons(),this.valueManager=new v(this),this._valueSync(),this._bindMethods();let e=new MutationObserver(t=>{for(let i of t)if(Array.from(i.removedNodes).includes(this.element)){typeof this[p]=="function"&&this[p](),e.disconnect();break}});e.observe(document.body,{childList:!0,subtree:!0}),s.instances.push(this),this.isLoaded=!0}catch(e){let t=e instanceof Error?e.message:String(e);throw new u.InitializationError(this,t)}}async _attachRadioButtons(){if(!this.element){console.error("'this.element' not found: cannot attach radio buttons for ",this.target);return}this.yesRadio=new d(this,'input[type="radio"][value="1"]',this.element,0,"truthy"),this.noRadio=new d(this,'input[type="radio"][value="0"]',this.element,0,"falsy"),await this.yesRadio[h](),await this.noRadio[h]()}clearValue(){this.yesRadio instanceof d&&this.noRadio instanceof d&&(this.yesRadio.clearValue(),this.noRadio.clearValue()),super.clearValue()}uncheckRadios(){return this.yesRadio instanceof f&&this.noRadio instanceof f?(this.yesRadio.element.checked=!1,this.noRadio.element.checked=!1):console.error("[SYNACT] Attempted to uncheck radios for an element that has no radios"),this}inputMask(e,t){if(this.isMasked)throw new Error(`You cannot apply multiple input masks to the same element. @${this.target}`);let i;switch(e){case"money":i=new P(this.element,t);break;case"phone":i=new R(this.element,t);break;default:throw new Error(`No type provided for 'inputMask()' at: ${this.target}`)}return this.valueManager.element=i.input,this.isMasked=!0,this}[p](){super[p](),this.yesRadio?.[p](),this.noRadio?.[p](),this.yesRadio=void 0,this.noRadio=void 0}};var L=class extends Array{hideAll(){return this.forEach(e=>e.hide()),this}showAll(){return this.forEach(e=>e.show()),this}};function T(s){let e=new L(...s);return new Proxy(e,{get(t,i,n){if(i in t)return Reflect.get(t,i,n);if(typeof i=="string")return t.find(r=>r.target.toString().replace(/[#\[\]]/g,"")===i||r.logicalName===i)}})}async function x(s,e={multiple:!1,root:document.body,timeoutMs:0}){try{if(typeof e!="object")throw new TypeError(`'options' must be of type 'object'. Received type: '${typeof e}'`);G(e);let{multiple:t=!1,root:i=document.body,timeoutMs:n=0}=e;if(typeof t=="function"?t():t){if(typeof s!="string")throw new TypeError(`'target' must be of type 'string' if 'multiple' is set to 'true'. Received type: '${typeof s}'`);let l=await y(s,i,!0,n),a=await Promise.all(l.map(async c=>{let O=new g(c,i,n);return await O[h](),new Proxy(O,j())}));return T(a)}let o=new g(s,i,n);return await o[h](),new Proxy(o,j())}catch(t){throw t instanceof Error?t:new Error("Failed to get DOM Node by target: "+s)}}function G(s){let{multiple:e=!1,root:t=document.body,timeoutMs:i=0}=s;if(typeof e!="boolean"&&typeof e!="function")throw new TypeError(`'multiple' must be of type 'boolean' or 'function'. Received type: '${typeof e}'`);if(typeof e=="function"){let n=e();if(typeof n!="boolean")throw new TypeError(`'multiple' function must return a boolean. Received type: '${typeof n}'`)}if(!(t instanceof HTMLElement))throw new TypeError(`'root' must be of type 'HTMLElement'. Received type: '${typeof t}'`);if(typeof i!="number")throw new TypeError(`'timeout' must be of type 'number'. Received type: '${typeof i}'`)}function j(){return{get:(s,e)=>{if(e.toString().startsWith("_"))return;let t=s[e];return typeof t=="function"&&e!=="onceLoaded"?(...i)=>(s.onceLoaded(()=>t.apply(s,i)),s):t}}}async function z(s){try{let e=await k.getRecord("systemforms",s),{formxml:t}=e,n=new DOMParser().parseFromString(t,"application/xml"),r=q(n.getElementsByTagName("control")),o=q(n.getElementsByTagName("section")),l=q(n.getElementsByTagName("tab")),a=await Promise.all([...r,...o,...l]);return T(a.filter(c=>c!==null))}catch(e){throw e instanceof Error?(console.error(e.message),e):(console.error(e),new Error(String(e)))}}function q(s){return Array.from(s).map(e=>{let t=J(e.tagName),i=e.getAttribute(t);if(!i)return null;let n=U(e.tagName,i);return n?x(n).catch(r=>(console.warn(`Failed to create a reference to the form field: ${i}`,r),null)):null}).filter(Boolean)}function J(s){return s==="control"?"id":s==="tab"||s==="section"?"name":"id"}function U(s,e){return s==="control"?`#${e}`:s==="tab"||s==="section"?`[data-name="${e}"]`:null}export{k as API,z as bindForm,x as get,y as waitFor};
|
|
2
|
+
function L(r){let e=$.Deferred();return shell.getTokenDeferred().done(function(t){r.headers?r.headers.__RequestVerificationToken=t:$.extend(r,{headers:{__RequestVerificationToken:t}}),$.ajax(r).done(function(i,s,n){validateLoginSession(i,s,n,e.resolve)}).fail(e.reject)}).fail(function(){e.rejectWith(this,arguments)}),e.promise()}var S=class{static createRecord(e,t){return new Promise((i,s)=>{L({type:"POST",url:`/_api/${e}`,data:JSON.stringify(t),contentType:"application/json",success:function(n,o,l){i(l.getResponseHeader("entityid"))},error:n=>{s(n)}})})}static getRecord(e,t,i){return new Promise((s,n)=>{let o=`/_api/${e}(${t})${i?`?$${i}`:""}`;L({type:"GET",url:o,success:s,error:n})})}static getMultiple(e,t){return new Promise((i,s)=>{let n=`/_api/${e}${t?`?${t}`:""}`;L({type:"GET",url:n,success:function(o){i(o.value)},error:s})})}static updateRecord(e,t,i){return new Promise((s,n)=>{let o=`/_api/${e}(${t})`;L({type:"PATCH",url:o,data:JSON.stringify(i),success:s,error:n})})}},H=S;var y=class{defaultVisibility;set defaultDisplay(e){this.defaultVisibility=e}constructor(e){if(this.visibilityController=e,e.tagName==="TABLE"){let i=e.closest("fieldset");i&&(this.visibilityController=i)}if(["SPAN","INPUT","TEXTAREA","SELECT","TABLE"].includes(e.tagName)){let i=e.closest("td");i&&(this.visibilityController=i)}this.defaultVisibility=this.visibilityController.style.display}hide(){this.visibilityController.style.display="none"}show(){this.visibilityController.style.display=this.defaultVisibility}toggleVisibility(e){e?this.show():this.hide()}getVisibility(){return window.getComputedStyle(this.visibilityController).display!=="none"&&window.getComputedStyle(this.visibilityController).visibility!=="hidden"&&this.visibilityController.getBoundingClientRect().height>0&&this.visibilityController.getBoundingClientRect().width>0}destroy(){this.visibilityController=null,this.defaultVisibility=null}};var x={CHECKBOX:"click",RADIO:"click",SELECT:"change",TEXT:"keyup",DEFAULT:"input"};var h=Symbol("init"),p=Symbol("destroy");var b=class extends HTMLElement{flyoutContent;icon;observers=[];constructor(e,t){if(super(),typeof e!="string")throw new Error(`argument "titleString" must be of type "string". Received: "${typeof e}"`);if(t&&typeof t!="object")throw new Error(`argument "iconStyle" must be of type "object". Received: "${typeof t}"`);this.classList.add("info-icon"),this.icon=document.createElement("i"),this.icon.classList.add("fa","fa-solid","fa-info-circle"),this.icon.setAttribute("aria-label","Info"),this.icon.style.cursor="pointer",this.flyoutContent=document.createElement("div"),this.flyoutContent.innerHTML=e,this.flyoutContent.classList.add("flyout-content"),this.appendChild(this.icon),this.appendChild(this.flyoutContent),t&&Object.assign(this.icon.style,t),this.handleClick=this.handleClick.bind(this),this.handleResize=this.handleResize.bind(this),this.handleTouchStart=this.handleTouchStart.bind(this),this.handleMouseEnter=this.handleMouseEnter.bind(this),this.handleMouseLeave=this.handleMouseLeave.bind(this),this.handleScroll=this.handleScroll.bind(this),this.flyoutContent.style.minWidth=this.getDesiredWidth(),this.flyoutContent.style.display="none",this.attachEventListeners(),this.setupObservers()}attachEventListeners(){document.body.addEventListener("click",this.handleClick),self.addEventListener("resize",this.handleResize),this.icon.addEventListener("touchstart",this.handleTouchStart),this.addEventListener("mouseenter",this.handleMouseEnter),this.addEventListener("mouseleave",this.handleMouseLeave),self.addEventListener("scroll",this.handleScroll)}setupObservers(){let e=new MutationObserver(i=>{for(let s of i)for(let n of Array.from(s.removedNodes))if(n===this){this.destroy();return}});e.observe(document,{childList:!0,subtree:!0,attributes:!1});let t=new MutationObserver(()=>this.updateFlyoutWidth);t.observe(document,{childList:!0,subtree:!0,attributes:!1}),this.observers.push(e,t)}getDesiredWidth(){let e=self.innerWidth;return`${Math.min(e-40,600)}px`}positionFlyout(){this.flyoutContent.style.display="block";let e=this.icon.getBoundingClientRect(),t=this.flyoutContent.getBoundingClientRect(),i=self.innerHeight,n=e.bottom-5;n+t.height>i&&(n=e.top-t.height),this.flyoutContent.style.top=`${n}px`}updateFlyoutWidth(){this.flyoutContent.style.minWidth=this.getDesiredWidth()}handleClick(e){this.contains(e.target)||(this.flyoutContent.style.display="none")}handleResize(e){this.flyoutContent.style.minWidth=this.getDesiredWidth()}handleTouchStart(){this.flyoutContent.style.display=this.flyoutContent.style.display==="block"?"none":"block",this.flyoutContent.style.display==="block"&&this.positionFlyout()}handleMouseEnter(e){this.positionFlyout()}handleMouseLeave(e){let t=e.relatedTarget;this.contains(t)||(this.flyoutContent.style.display="none")}handleScroll(){let e=this.flyoutContent.style.display;e!=="none"&&(this.positionFlyout(),this.flyoutContent.style.display=e)}destroy(){document.body.removeEventListener("click",this.handleClick),self.removeEventListener("resize",this.handleResize),this.icon.removeEventListener("touchstart",this.handleTouchStart),this.removeEventListener("mouseenter",this.handleMouseEnter),this.removeEventListener("mouseleave",this.handleMouseLeave),self.removeEventListener("scroll",this.handleScroll),this.observers.forEach(e=>e.disconnect())}};customElements.define("info-element",b);function v(r,e=document,t=!1,i){return new Promise((s,n)=>{if(t){let o,l=[],a=new Set;if(i<1)return s(Array.from(e.querySelectorAll(r)));let c=new MutationObserver(()=>{Array.from(e.querySelectorAll(r)).forEach(C=>{a.has(C)||(a.add(C),l.push(C))}),clearTimeout(o),o=setTimeout(()=>{l.length>0?(c.disconnect(),s(l)):n(new Error(`No elements found with target: "${r}" within ${i/1e3} seconds. If the element you are expecting has not loaded yet, consider raising your timeout.`))},i)});c.observe(e,{childList:!0,subtree:!0,attributes:!1})}else{let o=new MutationObserver(()=>{let c=e.querySelector(r);c&&(clearTimeout(l),o.disconnect(),s(c))}),l=setTimeout(()=>{o.disconnect(),n(new Error(`Element not found by target: "${r}" within ${i/1e3} second. If the element you are expecting has not loaded yet, consider raising your timeout.`))},i),a=e.querySelector(r);if(a)return clearTimeout(l),s(a);o.observe(e,{subtree:!0,attributes:!0,childList:!0})}})}var m=class extends Error{node;constructor(e,t){super(t),this.node=e,Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}},k=class extends m{constructor(e,t){super(e,`There was an error initializing a DOMNodeReference for target: ${e.target}, :: ${t}`)}},I=class extends m{constructor(e){super(e,`The targeted DOM element was not found: ${e.target}`)}},F=class extends m{constructor(e){super(e,"Page_Validators could not be found")}},A=class extends m{constructor(e){super(e,`Error applying business rule to target: ${e.target}`)}},_=class extends m{constructor(e){super(e,"Self-referential dependency found. A DOMNodeReference cannot depend on itself")}},B=class extends m{constructor(e){super(e,`No label could be found for the target: ${e.target}`)}},q=class extends m{constructor(e,t,i,s,n){let o=s.join(" or ");super(e,`${t} expects ${i} to be of type ${o}. Received: ${n===null?"null":typeof n}`)}},G={NodeNotFoundError:I,InitializationError:k,Page_ValidatorsNotFoundError:F,BusinessRuleError:A,SelfReferenceError:_,LabelNotFoundError:B,IncorrectParameterError:q},u=G;var f=class r{static instances=[];target;logicalName;root;timeoutMs;isLoaded;get value(){return this.valueManager.value}set value(e){this.valueManager.setValue(e)}get checked(){return this.valueManager.checked}set defaultDisplay(e){this.visibilityManager.defaultDisplay=e}visibilityManager;valueManager;eventManager;constructor(e,t=document.body,i){this.target=e,this.logicalName=this._extractLogicalName(e),this.root=t,this.timeoutMs=i,this.isLoaded=!1}async[h](){if(this.target instanceof HTMLElement?this.element=this.target:this.element=await v(this.target,this.root,!1,this.timeoutMs),!this.element)throw new u.NodeNotFoundError(this)}_extractLogicalName(e){if(typeof e!="string")return"";let t=e.match(/\[([^\]]+)\]/);if(!t)return e.replace(/[#\[\]]/g,"");let i=t[1];return(i.match(/["']([^"']+)["']/)?.[1]||i).replace(/[#\[\]]/g,"")}_valueSync(){if(!this._isValidFormElement(this.element))return;this.updateValue();let e=this._determineEventType();this.eventManager.registerDOMEventListener(this.element,e,this.updateValue.bind(this)),this._isDateInput()&&this._dateSync(this.element)}_determineEventType(){return this.element instanceof HTMLSelectElement?"change":this.element instanceof HTMLTextAreaElement?"keyup":this.element instanceof HTMLInputElement?x[this.element.type.toUpperCase()]||x.DEFAULT:x.DEFAULT}_isDateInput(){return this.element instanceof HTMLInputElement&&this.element.dataset.type==="date"}_isValidFormElement(e){return e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSpanElement||e instanceof HTMLButtonElement||e instanceof HTMLFieldSetElement}async _dateSync(e){let t=e.parentElement;if(!t)throw new DOMException("Date input must have a parent element");let i=await v("[data-date-format]",t,!1,1500);this.valueManager.element=i,this.eventManager.registerDOMEventListener(i,"select",this.updateValue.bind(this))}_bindMethods(){let e=Object.getPrototypeOf(this);for(let t of Object.getOwnPropertyNames(e)){let i=this[t];t!=="constructor"&&typeof i=="function"&&(this[t]=i.bind(this))}}[p](){this.isLoaded=!1,this.value=null,this.eventManager.destroy(),this.eventManager=null,this.visibilityManager.destroy(),this.visibilityManager=null,this.valueManager.destroy(),this.valueManager=null}async updateValue(e){e&&!e.isTrusted||(await this.valueManager.updateValue(e),this.triggerDependentsHandlers())}triggerDependentsHandlers(){this.eventManager.dispatchDependencyHandlers()}on(e,t){if(typeof t!="function")throw new u.IncorrectParameterError(this,"on","eventHandler",["function"],typeof t);let i=t;return this.eventManager.registerDOMEventListener(this.element,e,i.bind(this)),this}hide(){return this.visibilityManager.hide(),this}show(){return this.visibilityManager.show(),this}toggleVisibility(e){let t=e instanceof Function?e.call(this):e;return this.visibilityManager.toggleVisibility(t),this}setValue(e){return e instanceof Function&&(e=e()),this.valueManager.setValue(e),this}disable(){return this.element.disabled=!0,this}clearValue(){this.valueManager.clearValue(),this._getChildren()&&this.callAgainstChildrenInputs(e=>e.clearValue())}_getChildren(){let t=Array.from(this.element.querySelectorAll("input, select, textarea")).map(s=>s.id),i=r.instances.filter(s=>t.includes(s.element.id));return i.length>0?i:null}callAgainstChildrenInputs(e){let t=this._getChildren();if(!t){console.error("No child inputs found for target: ",this);return}for(let i of t)e(i)}enable(){return this.element.disabled=!1,this}prepend(...e){return this.element.prepend(...e),this}append(...e){return this.element.append(...e),this}before(...e){return this.element.before(...e),this}after(...e){return this.element.after(...e),this}getLabel(){let e=document.querySelector(`#${this.element.id}_label`)||null;if(!e)throw new u.LabelNotFoundError(this);return e}addLabelTooltip(e,t){return this.getLabel()?.append(new b(e,t||void 0)),this}addTooltip(e,t){return this.append(new b(e,t||void 0)),this}setInnerHTML(e){return this.element.innerHTML=e,this}remove(){return this.element.remove(),this}setStyle(e){if(e===null||typeof e!="object")throw new u.IncorrectParameterError(this,"setStyle","options",["Partial<CSSStyleDeclaration>"],typeof e);return Object.entries(e).forEach(([t,i])=>{i!==void 0&&(this.element.style[t]=i)}),this}applyBusinessRule(e,t){try{e.setRequirements&&this._setupRequirementsValidator(e.setRequirements());let i=this._createBusinessRuleHandler(e);return i(),t.length&&this._configureDependencyTracking(i,t),this}catch(i){throw i instanceof Error?i:new u.BusinessRuleError(this)}}_setupRequirementsValidator(e){let{isRequired:t,isValid:i}=e;if(typeof Page_Validators>"u")throw new u.Page_ValidatorsNotFoundError(this);let s=()=>!0;t&&i?s=()=>{let n=t.call(this),o=this.visibilityManager.getVisibility();return!n||o&&i.call(this,n)}:i?s=()=>this.visibilityManager.getVisibility()&&i.call(this):t&&(s=()=>this.visibilityManager.getVisibility()&&t.call(this)),this._createValidator(s)}_createBusinessRuleHandler(e){return()=>{let t=!1;if(e.setVisibility){let s=e.setVisibility.call(this);t=!s,this.toggleVisibility(s)}if(e.setRequirements&&e.setRequirements().isRequired){let{isRequired:i}=e.setRequirements();this.setRequiredLevel(i.call(this))}if(e.setValue){let{condition:i,value:s}=e.setValue();if(i.call(this)){let n=s instanceof Function?s():s;this.setValue.call(this,n)}}e.setDisabled&&(e.setDisabled.call(this)?this.disable():this.enable()),t&&!e.setValue&&this.clearValue(),this.triggerDependentsHandlers()}}_createValidator(e){let t=(()=>{let n=this.getLabel();if(!n)throw new u.LabelNotFoundError(this);return n=n.innerHTML,n.length>50&&(n=n.substring(0,50)+"..."),n})(),i=`${this.element.id}Validator`,s=document.createElement("span");if(s.style.display="none",s.id=i,Object.assign(s,{controltovalidate:this.element.id,errormessage:`<a href='#${this.element.id}_label'>${t} is a required field</a>`,evaluationfunction:e}),Page_Validators==null)throw new u.Page_ValidatorsNotFoundError(this);Page_Validators.push(s)}_configureDependencyTracking(e,t){if(t.length<1){console.error(`powerpagestoolkit: No dependencies specified for ${this.element.id}. Include all required nodes in the dependency array for proper tracking.`);return}t.forEach(i=>{if(!i||!(i instanceof r))throw new TypeError("Each dependency must be a valid DOMNodeReference instance");if(i.logicalName===this.logicalName)throw new u.SelfReferenceError(this);i.eventManager.registerDependent(this,e.bind(this))})}setRequiredLevel(e){return e instanceof Function?(e()?this.getLabel()?.classList.add("required-field"):this.getLabel()?.classList.remove("required-field"),this):(e?this.getLabel()?.classList.add("required-field"):this.getLabel()?.classList.remove("required-field"),this)}onceLoaded(e){if(this.isLoaded){e(this);return}if(this.target instanceof HTMLElement){e(this);return}let t=new MutationObserver(function(){document.querySelector(this.target)&&(t.disconnect(),this.isLoaded=!0,e(this))}.bind(this));this.eventManager.registerObserver(t,{nodeToObserve:document.body,options:{subtree:!0,childList:!0}})}};var E=class{constructor(){}onFocus(){setTimeout(()=>this.input.select(),0)}onBlur(){this.formatInput()}setValue(e){this.input.value=String(e)}};var R=class extends E{input;options;constructor(e,t={}){super(),this.input=e,this.options={format:t.format||"(xxx) xxx-xxxx",countryCode:t.countryCode||"",countryCodeFormat:t.countryCodeFormat||"+"},this.onFocus=this.onFocus.bind(this),this.formatInput=this.formatInput.bind(this),this.onBlur=this.onBlur.bind(this),this.setupEventListeners(),setTimeout(()=>{this.formatInput()},0)}setupEventListeners(){this.input.addEventListener("focus",this.onFocus),this.input.addEventListener("input",this.formatInput),this.input.addEventListener("blur",this.onBlur)}formatInput(){let e=this.input.value,t=this.input.selectionStart||0,i=e.length,s=e.replace(/\D/g,""),n=this.formatPhoneNumber(s);this.input.value=n;let o=Math.min(t+(n.length-i),n.length);this.input.setSelectionRange(o,o)}formatPhoneNumber(e){if(!e)return"";let t=e,i="";if(this.options.countryCode){let a=this.options.countryCode.length;e.length>a?(i=e.substring(0,a),t=e.substring(a)):(i=e,t="")}let s="";if(i)switch(this.options.countryCodeFormat){case"+":s=`+${i} `;break;case"()":s=`(${i}) `;break;case"00":s=`00${i} `;break;default:s=`+${i} `}let n=this.options.format,o=0;for(let a=0;a<n.length&&o<t.length;a++)n[a]==="x"&&(n=n.substring(0,a)+t[o++]+n.substring(a+1));n=n.replace(/x/g,"");let l=n.split("").findIndex((a,c)=>!/\d/.test(a)&&n.substring(c).indexOf("x")===-1&&n.substring(c).replace(/[\s\-()]/g,"").length===0);return l!==-1&&(n=n.substring(0,l)),s+n}onFocus(){setTimeout(()=>this.input.select(),0)}onBlur(){this.formatInput();let e=this.getDigits(),t=this.options.countryCode?7+this.options.countryCode.length:7;e.length<t}getDigits(){return this.input.value.replace(/\D/g,"")}getCountryCode(){if(!this.options.countryCode)return"";let e=this.getDigits(),t=this.options.countryCode.length;return e.length>=t?e.substring(0,t):e}getPhoneDigits(){if(!this.options.countryCode)return this.getDigits();let e=this.getDigits(),t=this.options.countryCode.length;return e.length>t?e.substring(t):""}setValue(e){let t=e.replace(/\D/g,"");this.input.value=this.formatPhoneNumber(t)}isValid(){let e=this.getPhoneDigits(),t=this.getCountryCode();return(!this.options.countryCode||t.length===this.options.countryCode.length)&&e.length>=10}destroy(){this.input.removeEventListener("focus",this.onFocus),this.input.removeEventListener("input",this.formatInput),this.input.removeEventListener("blur",this.onBlur)}};var M=class{events=new Map;listeners=new Map;dependencyHandlers=new Set;observers=[];boundListeners=[];constructor(){}dispatchDependencyHandlers(){for(let[e,t]of this.dependencyHandlers)t.call(e)}registerDependent(e,t){try{return this.dependencyHandlers.add([e,t]),"success"}catch{return new Error(`Failed register dependant: ${e.target}`)}}registerEvent(e,t){return this.events.has(e)?(console.error("Event registration has already been defined for: ",e),new Error(`Event registration has already been defined for: ${e}`)):(this.listeners.set(e,new Set),this.events.set(e,t),"success")}registerListener(e,t){if(this.events.has(e)){let i=this.listeners.get(e)??new Set;return i.add(t),this.listeners.set(e,i),"success"}else return console.error("No event registration found for: ",e),new Error(`No event registration found for: ${e}`)}emit(e,...t){if(this.events.has(e)){let i=this.events.get(e),s=this.listeners.get(e);if(!s)return;for(let n of s)i.call(n,...t)}else console.error("Event not found in EventRegistry: ",e)}stopListening(e){for(let[t,i]of this.listeners)i.has(e)&&i.delete(e)}registerObserver(e,t){let{nodeToObserve:i,options:s}=t;e.observe(i,s),this.observers.push(e)}registerDOMEventListener(e,t,i){e.addEventListener(t,i),this.boundListeners.push({element:e,handler:i,event:t})}destroy(){this.boundListeners?.forEach(e=>{e.element?.removeEventListener(e.event,e.handler)}),this.boundListeners=[],this.observers?.forEach(e=>{e.disconnect()}),this.observers=[],this.events.clear(),this.dependencyHandlers.clear(),this.listeners.clear()}};var d=class extends f{radioType;constructor(e,t,i=document.body,s,n){super(t,i,s),this.radioParent=e,this.radioType=n}async[h](){try{await super[h](),this.initEventManager(),this.initVisibilityManager(),this.initValueManager(),this._bindMethods();let e=new MutationObserver(t=>{for(let i of t)if(Array.from(i.removedNodes).includes(this.element)){this[p](),e.disconnect();break}});e.observe(document.body,{childList:!0,subtree:!0}),f.instances.push(this),this.isLoaded=!0}catch(e){let t=e instanceof Error?e.message:String(e);throw new u.InitializationError(this,t)}}initEventManager(){this.eventManager=new M}initValueManager(){this.valueManager=new w(this),this._valueSync()}initVisibilityManager(){this.visibilityManager=new y(this.element)}[p](){super[p](),this.radioParent=void 0,this.radioType=void 0}};var w=class{value;checked=!1;element;noRadio;yesRadio;radioParent;isRadio=!1;radioType;constructor(e){e instanceof g?(this.noRadio=e.noRadio,this.yesRadio=e.yesRadio,this.radioParent=void 0):e instanceof d&&(this.isRadio=!0,this.noRadio=void 0,this.yesRadio=void 0,this.radioParent=e.radioParent,this.radioType=e.radioType),this.element=e.element}setValue(e){let t=this._validateValue(e);this.yesRadio instanceof d&&this.noRadio instanceof d?(this.yesRadio.element.checked=!!e,this.noRadio.element.checked=!e,this.value=e,this.element.checked=!!e,this.element.value=e):this.isRadio||this.element.type==="radio"?(this.element.checked=e,this.checked=e,this.value=e,this.radioParent?.updateValue()):(this.element.value=t,this.value=t)}async updateValue(e){e&&e.stopPropagation();let t=await this.getElementValue();if(this.value=t.value,t.checked!==void 0&&(this.checked=t.checked),this.radioParent instanceof g&&e&&e.type!=="manual-radio-sync"){switch(this.radioType){case"falsy":this.radioParent.yesRadio.setValue(!t),await this.radioParent.yesRadio.updateValue(new Event("manual-radio-sync"));break;case"truthy":this.radioParent.noRadio.setValue(!t),await this.radioParent.noRadio.updateValue(new Event("manual-radio-sync"));break}this.radioParent.updateValue()}}getElementValue(){return new Promise(e=>{let t=this.element,i=this.element;this.yesRadio instanceof d&&this.noRadio instanceof d&&e({value:this.yesRadio.checked,checked:this.yesRadio.checked});let s={value:null};switch(t.type){case"checkbox":case"radio":e({value:t.checked,checked:t.checked});break;case"select-multiple":e({value:Array.from(i.selectedOptions).map(n=>n.value)});break;case"select-one":e({value:i.value});break;case"number":e({value:t.value!==""?Number(t.value):null});break;default:{let n=t.value;this.element.classList.contains("decimal")&&(n=parseFloat(t.value.replace(/[$,]/g,"").trim())),s={value:n}}}s={...s,value:this._validateValue(s.value)},e(s)})}_validateValue(e){return typeof e=="boolean"||e==="true"||e==="false"?e===!0||e==="true":this.element instanceof HTMLSelectElement||this.element.type==="text"&&!this.element.classList.contains("decimal")||e===null||e===""||isNaN(Number(e))?e:Number(e)}clearValue(){try{let e=this.element;if(e.defaultValue="",e instanceof HTMLInputElement)switch(e.type.toLowerCase()){case"checkbox":case"radio":e.checked=!1,this.checked=!1,this.value=!1;break;case"number":e.value="",this.value=null;break;default:e.value="",this.value=null;break}else e instanceof HTMLSelectElement?e.multiple?(Array.from(e.options).forEach(t=>t.selected=!1),this.value=null):(e.selectedIndex=-1,this.value=null):e instanceof HTMLTextAreaElement?(e.value="",this.value=null):this.value=null}catch(e){let t=`Failed to clear values for element with target "${this}": ${e instanceof Error?e.message:String(e)}`;throw new Error(t)}}destroy(){this.value=null,this.checked=!1,this.element=null,this.noRadio=void 0,this.yesRadio=void 0,this.isRadio=!1}};var P=class extends E{input;options;buffer="";charAtSelection="";charBeforeSelection="";lengthOf0FormattedValue;digitRegex=/\d/;nonDigitRegex=/\D/g;thousandsRegex=/\B(?=(\d{3})+(?!\d))/g;separatorRegex;constructor(e,t={}){super(),this.input=e,this.options={prefix:t.prefix||"$",decimalPlaces:t.decimalPlaces??2,thousandsSeparator:t.thousandsSeparator||",",decimalSeparator:t.decimalSeparator||".",allowNegative:t.allowNegative??!0};let i=this.escapeRegExp(this.options.thousandsSeparator),s=this.escapeRegExp(this.options.decimalSeparator);this.separatorRegex=new RegExp(`[${i}${s}]`),this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onSelectionChange=this.onSelectionChange.bind(this),this.onBlur=this.onBlur.bind(this),this.lengthOf0FormattedValue=`0${this.options.decimalPlaces>0?this.options.decimalSeparator+"0".repeat(this.options.decimalPlaces):""}`.length,this.setupEventListeners(),this.input.value&&(this.buffer=this.input.value.replace(this.nonDigitRegex,"")),this.formatAndDisplay()}escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}formatAndDisplay(){let e=Number(this.buffer||"0");this.input.value=this.formatNumber(e)}setupEventListeners(){this.input.addEventListener("focus",this.onFocus),this.input.addEventListener("input",this.onInput),this.input.addEventListener("selectionchange",this.onSelectionChange),this.input.addEventListener("blur",this.onBlur)}formatInput(){let e=this.input.value,t=this.input.selectionStart||0,i=e.length,s=new RegExp(`[^0-9${this.options.decimalSeparator}${this.options.allowNegative?"-":""}]`,"g"),n=e.replace(s,""),o=n.split(this.options.decimalSeparator);o.length>2&&(n=o[0]+this.options.decimalSeparator+o.slice(1).join("")),this.options.allowNegative&&n.indexOf("-")>0&&(n=n.replace(/-/g,""),n.charAt(0)!=="-"&&(n="-"+n));let l;n===""||n==="-"?l=0:l=parseFloat(n.replace(this.options.decimalSeparator,".")),isNaN(l)&&(l=0);let a=this.formatNumber(l);this.input.value=a;let c=t+(a.length-i);this.input.setSelectionRange(c,c)}formatNumber(e){let t=e/10**this.options.decimalPlaces,i=t<0,n=Math.abs(t).toFixed(this.options.decimalPlaces),[o,l]=n.split("."),a=o.replace(this.thousandsRegex,this.options.thousandsSeparator);return(i?"-":"")+this.options.prefix+a+(this.options.decimalPlaces>0?this.options.decimalSeparator+l:"")}onSelectionChange(e){let t=this.input.selectionStart;this.charAtSelection=this.input.value[t],this.charBeforeSelection=this.input.value[t-1]}onInput(e){let t=e,i=this.input.value,s=this.input.selectionStart??0,n=i.slice(0,s).replace(this.nonDigitRegex,"").length,o=n;switch(t.inputType){case"insertText":this.buffer=this.buffer.slice(0,n-1)+(t.data||"").replace(this.nonDigitRegex,"")+this.buffer.slice(n-1),o=n;break;case"deleteContentBackward":n>=0?this.separatorRegex.test(this.charBeforeSelection)?(this.buffer=this.buffer.slice(0,n-1)+this.buffer.slice(n),o=n-1):(this.buffer=this.buffer.slice(0,n)+this.buffer.slice(n+1),o=n):i===""&&(this.buffer="");break;case"deleteContentForward":n<this.buffer.length&&(this.buffer=this.buffer.slice(0,n)+this.buffer.slice(n+1));break;case"deleteWordBackward":case"deleteWordForward":this.buffer="",o=this.lengthOf0FormattedValue;break;default:this.buffer=i.replace(this.nonDigitRegex,""),o=this.buffer.length}let l=Number(this.buffer||"0"),a=this.formatNumber(l);this.input.value=a;let c=this.mapRawIndexToFormattedPosition(o,a);this.input.setSelectionRange(c,c)}mapRawIndexToFormattedPosition(e,t){let i=0;for(let s=0;s<t.length;s++)if(this.digitRegex.test(t[s])&&i++,i===e)return s+1;return t.length}onFocus(){setTimeout(()=>this.input.select(),0)}onBlur(){let e=Number(this.buffer||"0");if(this.input.value=this.formatNumber(e),e===0){this.buffer="";let t="0".repeat(this.options.decimalPlaces);this.input.value=`${this.options.prefix}0${this.options.decimalPlaces>0?this.options.decimalSeparator+t:""}`}}getNumericalValue(){return Number(this.buffer||"0")/10**this.options.decimalPlaces}setValue(e){let t=Math.round(Math.abs(e)*10**this.options.decimalPlaces);this.buffer=t.toString(),this.input.value=this.formatNumber(t)}destroy(){this.input.removeEventListener("focus",this.onFocus),this.input.removeEventListener("input",this.onInput),this.input.removeEventListener("selectionchange",this.onSelectionChange),this.input.removeEventListener("blur",this.onBlur)}};var g=class r extends f{isMasked=!1;yesRadio;noRadio;constructor(e,t=document.body,i){super(e,t,i)}async[h](){try{await super[h](),this.element.id&&this.element.querySelectorAll(`#${this.element.id} > input[type="radio"]`).length>0&&await this._attachRadioButtons(),this.initEventManager(),this.initVisibilityManager(),this.initValueManager(),this._bindMethods();let e=new MutationObserver(t=>{for(let i of t)if(Array.from(i.removedNodes).includes(this.element)){typeof this[p]=="function"&&this[p](),e.disconnect();break}});e.observe(document.body,{childList:!0,subtree:!0}),r.instances.push(this),this.isLoaded=!0}catch(e){let t=e instanceof Error?e.message:String(e);throw new u.InitializationError(this,t)}}initValueManager(){this.valueManager=new w(this),this._valueSync()}initVisibilityManager(){this.visibilityManager=new y(this.element)}initEventManager(){this.eventManager=new M}async _attachRadioButtons(){if(!this.element){console.error("'this.element' not found: cannot attach radio buttons for ",this.target);return}this.yesRadio=new d(this,'input[type="radio"][value="1"]',this.element,0,"truthy"),this.noRadio=new d(this,'input[type="radio"][value="0"]',this.element,0,"falsy"),await this.yesRadio[h](),await this.noRadio[h]()}clearValue(){this.yesRadio instanceof d&&this.noRadio instanceof d&&(this.yesRadio.clearValue(),this.noRadio.clearValue()),super.clearValue()}uncheckRadios(){return this.yesRadio instanceof f&&this.noRadio instanceof f?(this.yesRadio.element.checked=!1,this.noRadio.element.checked=!1):console.error("[SYNACT] Attempted to uncheck radios for an element that has no radios"),this}inputMask(e,t){if(this.isMasked)throw new Error(`You cannot apply multiple input masks to the same element. @${this.target}`);let i;switch(e){case"money":i=new P(this.element,t);break;case"phone":i=new R(this.element,t);break;default:throw new Error(`No type provided for 'inputMask()' at: ${this.target}`)}return this.valueManager.element=i.input,this.isMasked=!0,this}[p](){super[p](),this.yesRadio?.[p](),this.noRadio?.[p](),this.yesRadio=void 0,this.noRadio=void 0}};var T=class extends Array{hideAll(){return this.forEach(e=>e.hide()),this}showAll(){return this.forEach(e=>e.show()),this}};function D(r){let e=new T(...r);return new Proxy(e,{get(t,i,s){if(i in t)return Reflect.get(t,i,s);if(typeof i=="string")return t.find(n=>n.target.toString().replace(/[#\[\]]/g,"")===i||n.logicalName===i)}})}async function O(r,e={multiple:!1,root:document.body,timeoutMs:0}){try{if(typeof e!="object")throw new TypeError(`'options' must be of type 'object'. Received type: '${typeof e}'`);J(e);let{multiple:t=!1,root:i=document.body,timeoutMs:s=0}=e;if(typeof t=="function"?t():t){if(typeof r!="string")throw new TypeError(`'target' must be of type 'string' if 'multiple' is set to 'true'. Received type: '${typeof r}'`);let l=await v(r,i,!0,s),a=await Promise.all(l.map(async c=>{let V=new g(c,i,s);return await V[h](),new Proxy(V,W())}));return D(a)}let o=new g(r,i,s);return await o[h](),new Proxy(o,W())}catch(t){throw t instanceof Error?t:new Error("Failed to get DOM Node by target: "+r)}}function J(r){let{multiple:e=!1,root:t=document.body,timeoutMs:i=0}=r;if(typeof e!="boolean"&&typeof e!="function")throw new TypeError(`'multiple' must be of type 'boolean' or 'function'. Received type: '${typeof e}'`);if(typeof e=="function"){let s=e();if(typeof s!="boolean")throw new TypeError(`'multiple' function must return a boolean. Received type: '${typeof s}'`)}if(!(t instanceof HTMLElement))throw new TypeError(`'root' must be of type 'HTMLElement'. Received type: '${typeof t}'`);if(typeof i!="number")throw new TypeError(`'timeout' must be of type 'number'. Received type: '${typeof i}'`)}function W(){return{get:(r,e)=>{if(e.toString().startsWith("_"))return;let t=r[e];return typeof t=="function"&&e!=="onceLoaded"?(...i)=>(r.onceLoaded(()=>t.apply(r,i)),r):t}}}async function z(r){try{let e=await H.getRecord("systemforms",r),{formxml:t}=e,s=new DOMParser().parseFromString(t,"application/xml"),n=j(s.getElementsByTagName("control")),o=j(s.getElementsByTagName("section")),l=j(s.getElementsByTagName("tab")),a=await Promise.all([...n,...o,...l]);return D(a.filter(c=>c!==null))}catch(e){throw e instanceof Error?(console.error(e.message),e):(console.error(e),new Error(String(e)))}}function j(r){return Array.from(r).map(e=>{let t=U(e.tagName),i=e.getAttribute(t);if(!i)return null;let s=K(e.tagName,i);return s?O(s).catch(n=>(console.warn(`Failed to create a reference to the form field: ${i}`,n),null)):null}).filter(Boolean)}function U(r){return r==="control"?"id":r==="tab"||r==="section"?"name":"id"}function K(r,e){return r==="control"?`#${e}`:r==="tab"||r==="section"?`[data-name="${e}"]`:null}var N=class extends HTMLElement{element;constructor(){if(!document)throw new Error("Cannot instantiate 'LoadingSpinner': No DOM Found");super(),this.id="loader",this.classList.add("loader-overlay","hidden"),this.element=document.createElement("div"),this.element.classList.add("spinner-border","text-light"),this.element.role="status",this.appendChild(this.element);let e=document.createElement("span");e.classList.add("visually-hidden"),e.textContent="Loading...",this.element.appendChild(e),document.body.appendChild(this)}hide(){this.classList.add("hidden")}show(){this.classList.remove("hidden")}};customElements.define("loading-spinner",N);export{H as API,N as LoadingSpinner,z as bindForm,O as get,v as waitFor};
|
|
3
3
|
/*! For license information please see index.js.LEGAL.txt */
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
if (typeof document !== 'undefined') {
|
|
8
8
|
const style = document.createElement('style');
|
|
9
|
-
style.textContent = ".info-icon {\r\n position: relative;\r\n display: inline-block;\r\n margin: 3px;\r\n}\r\n\r\n.info-icon .fa-info-circle {\r\n cursor: pointer; /* Ensures the icon is recognized as interactive */\r\n}\r\n\r\n.
|
|
9
|
+
style.textContent = ".info-icon {\r\n position: relative;\r\n display: inline-block;\r\n margin: 3px;\r\n}\r\n\r\n.info-icon .fa-info-circle {\r\n cursor: pointer; /* Ensures the icon is recognized as interactive */\r\n}\r\n\r\n.flyout-content {\r\n max-width: 600px; /* Reasonable default max width */\r\n width: calc(\r\n 100vw - 40px\r\n ); /* Responsive width with 20px padding on each side */\r\n display: none; /* Initially hidden */\r\n position: fixed;\r\n left: 50%; /* Center horizontally */\r\n transform: translateX(-50%); /* Center adjustment */\r\n margin-top: 8px; /* Small gap from the icon */\r\n color: #000;\r\n background-color: #f9f9f9;\r\n padding: 10px;\r\n border: 1px solid #ddd;\r\n z-index: 1000; /* Ensure it appears above other content */\r\n box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);\r\n border-radius: 8px; /* Rounded corners */\r\n}\r\n\r\n@media (max-width: 600px) {\r\n .flyout-content {\r\n padding: 12px;\r\n font-size: 0.9em;\r\n }\r\n}\r\n\r\n\r\n.required-field::after {\r\n content: \" *\" !important;\r\n color: #f00 !important;\r\n}\r\n\r\n.loader-overlay {\r\n position: fixed;\r\n top: 0;\r\n left: 0;\r\n width: 100%;\r\n height: 100%;\r\n background-color: rgba(0, 0, 0, 0.5); /* Faded background */\r\n z-index: 9999; /* Ensure it's on top */\r\n display: flex;\r\n justify-content: center;\r\n align-items: center;\r\n}\r\n\r\n.loader-overlay.hidden {\r\n display: none;\r\n}\r\n";
|
|
10
10
|
document.head.appendChild(style);
|
|
11
11
|
}
|
|
12
12
|
|