drill-widgets 2.7.20 → 2.7.22
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/drill-widgets.es.js +347 -299
- package/dist/drill-widgets.umd.js +83 -67
- package/dist/lib.d.ts +1 -0
- package/package.json +1 -1
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* @license
|
|
3
3
|
* Copyright 2019 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
-
*/var Oe;const T=globalThis,ne=T.ShadowRoot&&(T.ShadyCSS===void 0||T.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,
|
|
5
|
+
*/var Oe;const T=globalThis,ne=T.ShadowRoot&&(T.ShadyCSS===void 0||T.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,ae=Symbol(),_e=new WeakMap;let ye=class{constructor(e,t,i){if(this._$cssResult$=!0,i!==ae)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const t=this.t;if(ne&&e===void 0){const i=t!==void 0&&t.length===1;i&&(e=_e.get(t)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),i&&_e.set(t,e))}return e}toString(){return this.cssText}};const Re=s=>new ye(typeof s=="string"?s:s+"",void 0,ae),L=(s,...e)=>{const t=s.length===1?s[0]:e.reduce((i,r,n)=>i+(a=>{if(a._$cssResult$===!0)return a.cssText;if(typeof a=="number")return a;throw Error("Value passed to 'css' function must be a 'css' function result: "+a+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(r)+s[n+1],s[0]);return new ye(t,s,ae)},je=(s,e)=>{if(ne)s.adoptedStyleSheets=e.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const t of e){const i=document.createElement("style"),r=T.litNonce;r!==void 0&&i.setAttribute("nonce",r),i.textContent=t.cssText,s.appendChild(i)}},we=ne?s=>s:s=>s instanceof CSSStyleSheet?(e=>{let t="";for(const i of e.cssRules)t+=i.cssText;return Re(t)})(s):s;/**
|
|
6
6
|
* @license
|
|
7
7
|
* Copyright 2017 Google LLC
|
|
8
8
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
9
|
-
*/const{is:Ve,defineProperty:We,getOwnPropertyDescriptor:He,getOwnPropertyNames:Be,getOwnPropertySymbols:Qe,getPrototypeOf:Ge}=Object,M=globalThis,Se=M.trustedTypes,Ye=Se?Se.emptyScript:"",
|
|
9
|
+
*/const{is:Ve,defineProperty:We,getOwnPropertyDescriptor:He,getOwnPropertyNames:Be,getOwnPropertySymbols:Qe,getPrototypeOf:Ge}=Object,M=globalThis,Se=M.trustedTypes,Ye=Se?Se.emptyScript:"",oe=M.reactiveElementPolyfillSupport,V=(s,e)=>s,K={toAttribute(s,e){switch(e){case Boolean:s=s?Ye:null;break;case Object:case Array:s=s==null?s:JSON.stringify(s)}return s},fromAttribute(s,e){let t=s;switch(e){case Boolean:t=s!==null;break;case Number:t=s===null?null:Number(s);break;case Object:case Array:try{t=JSON.parse(s)}catch{t=null}}return t}},de=(s,e)=>!Ve(s,e),ke={attribute:!0,type:String,converter:K,reflect:!1,useDefault:!1,hasChanged:de};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),M.litPropertyMetadata??(M.litPropertyMetadata=new WeakMap);let O=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??(this.l=[])).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=ke){if(t.state&&(t.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((t=Object.create(t)).wrapped=!0),this.elementProperties.set(e,t),!t.noAccessor){const i=Symbol(),r=this.getPropertyDescriptor(e,i,t);r!==void 0&&We(this.prototype,e,r)}}static getPropertyDescriptor(e,t,i){const{get:r,set:n}=He(this.prototype,e)??{get(){return this[t]},set(a){this[t]=a}};return{get:r,set(a){const o=r==null?void 0:r.call(this);n==null||n.call(this,a),this.requestUpdate(e,o,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??ke}static _$Ei(){if(this.hasOwnProperty(V("elementProperties")))return;const e=Ge(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(V("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(V("properties"))){const t=this.properties,i=[...Be(t),...Qe(t)];for(const r of i)this.createProperty(r,t[r])}const e=this[Symbol.metadata];if(e!==null){const t=litPropertyMetadata.get(e);if(t!==void 0)for(const[i,r]of t)this.elementProperties.set(i,r)}this._$Eh=new Map;for(const[t,i]of this.elementProperties){const r=this._$Eu(t,i);r!==void 0&&this._$Eh.set(r,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const i=new Set(e.flat(1/0).reverse());for(const r of i)t.unshift(we(r))}else e!==void 0&&t.push(we(e));return t}static _$Eu(e,t){const i=t.attribute;return i===!1?void 0:typeof i=="string"?i:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var e;this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),(e=this.constructor.l)==null||e.forEach(t=>t(this))}addController(e){var t;(this._$EO??(this._$EO=new Set)).add(e),this.renderRoot!==void 0&&this.isConnected&&((t=e.hostConnected)==null||t.call(e))}removeController(e){var t;(t=this._$EO)==null||t.delete(e)}_$E_(){const e=new Map,t=this.constructor.elementProperties;for(const i of t.keys())this.hasOwnProperty(i)&&(e.set(i,this[i]),delete this[i]);e.size>0&&(this._$Ep=e)}createRenderRoot(){const e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return je(e,this.constructor.elementStyles),e}connectedCallback(){var e;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(e=this._$EO)==null||e.forEach(t=>{var i;return(i=t.hostConnected)==null?void 0:i.call(t)})}enableUpdating(e){}disconnectedCallback(){var e;(e=this._$EO)==null||e.forEach(t=>{var i;return(i=t.hostDisconnected)==null?void 0:i.call(t)})}attributeChangedCallback(e,t,i){this._$AK(e,i)}_$ET(e,t){var n;const i=this.constructor.elementProperties.get(e),r=this.constructor._$Eu(e,i);if(r!==void 0&&i.reflect===!0){const a=(((n=i.converter)==null?void 0:n.toAttribute)!==void 0?i.converter:K).toAttribute(t,i.type);this._$Em=e,a==null?this.removeAttribute(r):this.setAttribute(r,a),this._$Em=null}}_$AK(e,t){var n,a;const i=this.constructor,r=i._$Eh.get(e);if(r!==void 0&&this._$Em!==r){const o=i.getPropertyOptions(r),d=typeof o.converter=="function"?{fromAttribute:o.converter}:((n=o.converter)==null?void 0:n.fromAttribute)!==void 0?o.converter:K;this._$Em=r,this[r]=d.fromAttribute(t,o.type)??((a=this._$Ej)==null?void 0:a.get(r))??null,this._$Em=null}}requestUpdate(e,t,i){var r;if(e!==void 0){const n=this.constructor,a=this[e];if(i??(i=n.getPropertyOptions(e)),!((i.hasChanged??de)(a,t)||i.useDefault&&i.reflect&&a===((r=this._$Ej)==null?void 0:r.get(e))&&!this.hasAttribute(n._$Eu(e,i))))return;this.C(e,t,i)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(e,t,{useDefault:i,reflect:r,wrapped:n},a){i&&!(this._$Ej??(this._$Ej=new Map)).has(e)&&(this._$Ej.set(e,a??t??this[e]),n!==!0||a!==void 0)||(this._$AL.has(e)||(this.hasUpdated||i||(t=void 0),this._$AL.set(e,t)),r===!0&&this._$Em!==e&&(this._$Eq??(this._$Eq=new Set)).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var i;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[n,a]of this._$Ep)this[n]=a;this._$Ep=void 0}const r=this.constructor.elementProperties;if(r.size>0)for(const[n,a]of r){const{wrapped:o}=a,d=this[n];o!==!0||this._$AL.has(n)||d===void 0||this.C(n,void 0,a,d)}}let e=!1;const t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),(i=this._$EO)==null||i.forEach(r=>{var n;return(n=r.hostUpdate)==null?void 0:n.call(r)}),this.update(t)):this._$EM()}catch(r){throw e=!1,this._$EM(),r}e&&this._$AE(t)}willUpdate(e){}_$AE(e){var t;(t=this._$EO)==null||t.forEach(i=>{var r;return(r=i.hostUpdated)==null?void 0:r.call(i)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&(this._$Eq=this._$Eq.forEach(t=>this._$ET(t,this[t]))),this._$EM()}updated(e){}firstUpdated(e){}};O.elementStyles=[],O.shadowRootOptions={mode:"open"},O[V("elementProperties")]=new Map,O[V("finalized")]=new Map,oe==null||oe({ReactiveElement:O}),(M.reactiveElementVersions??(M.reactiveElementVersions=[])).push("2.1.0");/**
|
|
10
10
|
* @license
|
|
11
11
|
* Copyright 2017 Google LLC
|
|
12
12
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
13
13
|
*/const W=globalThis,J=W.trustedTypes,$e=J?J.createPolicy("lit-html",{createHTML:s=>s}):void 0,De="$lit$",F=`lit$${Math.random().toFixed(9).slice(2)}$`,Ce="?"+F,qe=`<${Ce}>`,I=document,H=()=>I.createComment(""),B=s=>s===null||typeof s!="object"&&typeof s!="function",le=Array.isArray,Ke=s=>le(s)||typeof(s==null?void 0:s[Symbol.iterator])=="function",pe=`[
|
|
14
14
|
\f\r]`,Q=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Ae=/-->/g,Ee=/>/g,z=RegExp(`>|${pe}(?:([^\\s"'>=/]+)(${pe}*=${pe}*(?:[^
|
|
15
|
-
\f\r"'\`<>=]|("|')|))|$)`,"g"),Te=/'/g,Me=/"/g,Fe=/^(?:script|style|textarea|title)$/i,Je=s=>(e,...t)=>({_$litType$:s,strings:e,values:t}),l=Je(1),U=Symbol.for("lit-noChange"),w=Symbol.for("lit-nothing"),Ie=new WeakMap,P=I.createTreeWalker(I,129);function ze(s,e){if(!le(s)||!s.hasOwnProperty("raw"))throw Error("invalid template strings array");return $e!==void 0?$e.createHTML(e):e}const Xe=(s,e)=>{const t=s.length-1,i=[];let r,n=e===2?"<svg>":e===3?"<math>":"",
|
|
15
|
+
\f\r"'\`<>=]|("|')|))|$)`,"g"),Te=/'/g,Me=/"/g,Fe=/^(?:script|style|textarea|title)$/i,Je=s=>(e,...t)=>({_$litType$:s,strings:e,values:t}),l=Je(1),U=Symbol.for("lit-noChange"),w=Symbol.for("lit-nothing"),Ie=new WeakMap,P=I.createTreeWalker(I,129);function ze(s,e){if(!le(s)||!s.hasOwnProperty("raw"))throw Error("invalid template strings array");return $e!==void 0?$e.createHTML(e):e}const Xe=(s,e)=>{const t=s.length-1,i=[];let r,n=e===2?"<svg>":e===3?"<math>":"",a=Q;for(let o=0;o<t;o++){const d=s[o];let p,c,u=-1,h=0;for(;h<d.length&&(a.lastIndex=h,c=a.exec(d),c!==null);)h=a.lastIndex,a===Q?c[1]==="!--"?a=Ae:c[1]!==void 0?a=Ee:c[2]!==void 0?(Fe.test(c[2])&&(r=RegExp("</"+c[2],"g")),a=z):c[3]!==void 0&&(a=z):a===z?c[0]===">"?(a=r??Q,u=-1):c[1]===void 0?u=-2:(u=a.lastIndex-c[2].length,p=c[1],a=c[3]===void 0?z:c[3]==='"'?Me:Te):a===Me||a===Te?a=z:a===Ae||a===Ee?a=Q:(a=z,r=void 0);const m=a===z&&s[o+1].startsWith("/>")?" ":"";n+=a===Q?d+qe:u>=0?(i.push(p),d.slice(0,u)+De+d.slice(u)+F+m):d+F+(u===-2?o:m)}return[ze(s,n+(s[t]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),i]};class G{constructor({strings:e,_$litType$:t},i){let r;this.parts=[];let n=0,a=0;const o=e.length-1,d=this.parts,[p,c]=Xe(e,t);if(this.el=G.createElement(p,i),P.currentNode=this.el.content,t===2||t===3){const u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(r=P.nextNode())!==null&&d.length<o;){if(r.nodeType===1){if(r.hasAttributes())for(const u of r.getAttributeNames())if(u.endsWith(De)){const h=c[a++],m=r.getAttribute(u).split(F),y=/([.?@])?(.*)/.exec(h);d.push({type:1,index:n,name:y[2],strings:m,ctor:y[1]==="."?et:y[1]==="?"?tt:y[1]==="@"?it:X}),r.removeAttribute(u)}else u.startsWith(F)&&(d.push({type:6,index:n}),r.removeAttribute(u));if(Fe.test(r.tagName)){const u=r.textContent.split(F),h=u.length-1;if(h>0){r.textContent=J?J.emptyScript:"";for(let m=0;m<h;m++)r.append(u[m],H()),P.nextNode(),d.push({type:2,index:++n});r.append(u[h],H())}}}else if(r.nodeType===8)if(r.data===Ce)d.push({type:2,index:n});else{let u=-1;for(;(u=r.data.indexOf(F,u+1))!==-1;)d.push({type:7,index:n}),u+=F.length-1}n++}}static createElement(e,t){const i=I.createElement("template");return i.innerHTML=e,i}}function R(s,e,t=s,i){var a,o;if(e===U)return e;let r=i!==void 0?(a=t._$Co)==null?void 0:a[i]:t._$Cl;const n=B(e)?void 0:e._$litDirective$;return(r==null?void 0:r.constructor)!==n&&((o=r==null?void 0:r._$AO)==null||o.call(r,!1),n===void 0?r=void 0:(r=new n(s),r._$AT(s,t,i)),i!==void 0?(t._$Co??(t._$Co=[]))[i]=r:t._$Cl=r),r!==void 0&&(e=R(s,r._$AS(s,e.values),r,i)),e}class Ze{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:t},parts:i}=this._$AD,r=((e==null?void 0:e.creationScope)??I).importNode(t,!0);P.currentNode=r;let n=P.nextNode(),a=0,o=0,d=i[0];for(;d!==void 0;){if(a===d.index){let p;d.type===2?p=new Y(n,n.nextSibling,this,e):d.type===1?p=new d.ctor(n,d.name,d.strings,this,e):d.type===6&&(p=new st(n,this,e)),this._$AV.push(p),d=i[++o]}a!==(d==null?void 0:d.index)&&(n=P.nextNode(),a++)}return P.currentNode=I,r}p(e){let t=0;for(const i of this._$AV)i!==void 0&&(i.strings!==void 0?(i._$AI(e,i,t),t+=i.strings.length-2):i._$AI(e[t])),t++}}class Y{get _$AU(){var e;return((e=this._$AM)==null?void 0:e._$AU)??this._$Cv}constructor(e,t,i,r){this.type=2,this._$AH=w,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=i,this.options=r,this._$Cv=(r==null?void 0:r.isConnected)??!0}get parentNode(){let e=this._$AA.parentNode;const t=this._$AM;return t!==void 0&&(e==null?void 0:e.nodeType)===11&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){e=R(this,e,t),B(e)?e===w||e==null||e===""?(this._$AH!==w&&this._$AR(),this._$AH=w):e!==this._$AH&&e!==U&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):Ke(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==w&&B(this._$AH)?this._$AA.nextSibling.data=e:this.T(I.createTextNode(e)),this._$AH=e}$(e){var n;const{values:t,_$litType$:i}=e,r=typeof i=="number"?this._$AC(e):(i.el===void 0&&(i.el=G.createElement(ze(i.h,i.h[0]),this.options)),i);if(((n=this._$AH)==null?void 0:n._$AD)===r)this._$AH.p(t);else{const a=new Ze(r,this),o=a.u(this.options);a.p(t),this.T(o),this._$AH=a}}_$AC(e){let t=Ie.get(e.strings);return t===void 0&&Ie.set(e.strings,t=new G(e)),t}k(e){le(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let i,r=0;for(const n of e)r===t.length?t.push(i=new Y(this.O(H()),this.O(H()),this,this.options)):i=t[r],i._$AI(n),r++;r<t.length&&(this._$AR(i&&i._$AB.nextSibling,r),t.length=r)}_$AR(e=this._$AA.nextSibling,t){var i;for((i=this._$AP)==null?void 0:i.call(this,!1,!0,t);e&&e!==this._$AB;){const r=e.nextSibling;e.remove(),e=r}}setConnected(e){var t;this._$AM===void 0&&(this._$Cv=e,(t=this._$AP)==null||t.call(this,e))}}class X{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,i,r,n){this.type=1,this._$AH=w,this._$AN=void 0,this.element=e,this.name=t,this._$AM=r,this.options=n,i.length>2||i[0]!==""||i[1]!==""?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=w}_$AI(e,t=this,i,r){const n=this.strings;let a=!1;if(n===void 0)e=R(this,e,t,0),a=!B(e)||e!==this._$AH&&e!==U,a&&(this._$AH=e);else{const o=e;let d,p;for(e=n[0],d=0;d<n.length-1;d++)p=R(this,o[i+d],t,d),p===U&&(p=this._$AH[d]),a||(a=!B(p)||p!==this._$AH[d]),p===w?e=w:e!==w&&(e+=(p??"")+n[d+1]),this._$AH[d]=p}a&&!r&&this.j(e)}j(e){e===w?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class et extends X{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===w?void 0:e}}class tt extends X{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==w)}}class it extends X{constructor(e,t,i,r,n){super(e,t,i,r,n),this.type=5}_$AI(e,t=this){if((e=R(this,e,t,0)??w)===U)return;const i=this._$AH,r=e===w&&i!==w||e.capture!==i.capture||e.once!==i.once||e.passive!==i.passive,n=e!==w&&(i===w||r);r&&this.element.removeEventListener(this.name,this,i),n&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){var t;typeof this._$AH=="function"?this._$AH.call(((t=this.options)==null?void 0:t.host)??this.element,e):this._$AH.handleEvent(e)}}class st{constructor(e,t,i){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(e){R(this,e)}}const ce=W.litHtmlPolyfillSupport;ce==null||ce(G,Y),(W.litHtmlVersions??(W.litHtmlVersions=[])).push("3.3.0");const rt=(s,e,t)=>{const i=(t==null?void 0:t.renderBefore)??e;let r=i._$litPart$;if(r===void 0){const n=(t==null?void 0:t.renderBefore)??null;i._$litPart$=r=new Y(e.insertBefore(H(),n),n,void 0,t??{})}return r._$AI(s),r};/**
|
|
16
16
|
* @license
|
|
17
17
|
* Copyright 2017 Google LLC
|
|
18
18
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
* @license
|
|
25
25
|
* Copyright 2017 Google LLC
|
|
26
26
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
27
|
-
*/const nt={attribute:!0,type:String,converter:K,reflect:!1,hasChanged:de},
|
|
27
|
+
*/const nt={attribute:!0,type:String,converter:K,reflect:!1,hasChanged:de},at=(s=nt,e,t)=>{const{kind:i,metadata:r}=t;let n=globalThis.litPropertyMetadata.get(r);if(n===void 0&&globalThis.litPropertyMetadata.set(r,n=new Map),i==="setter"&&((s=Object.create(s)).wrapped=!0),n.set(t.name,s),i==="accessor"){const{name:a}=t;return{set(o){const d=e.get.call(this);e.set.call(this,o),this.requestUpdate(a,d,s)},init(o){return o!==void 0&&this.C(a,void 0,s,o),o}}}if(i==="setter"){const{name:a}=t;return function(o){const d=this[a];e.call(this,o),this.requestUpdate(a,d,s)}}throw Error("Unsupported decorator location: "+i)};function $(s){return(e,t)=>typeof t=="object"?at(s,e,t):((i,r,n)=>{const a=r.hasOwnProperty(n);return r.constructor.createProperty(n,i),a?Object.getOwnPropertyDescriptor(r,n):void 0})(s,e,t)}/**
|
|
28
28
|
* @license
|
|
29
29
|
* Copyright 2017 Google LLC
|
|
30
30
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
31
|
-
*/function b(s){return $({...s,state:!0,attribute:!1})}const k=[];for(let s=0;s<256;++s)k.push((s+256).toString(16).slice(1));function
|
|
31
|
+
*/function b(s){return $({...s,state:!0,attribute:!1})}const k=[];for(let s=0;s<256;++s)k.push((s+256).toString(16).slice(1));function ot(s,e=0){return(k[s[e+0]]+k[s[e+1]]+k[s[e+2]]+k[s[e+3]]+"-"+k[s[e+4]]+k[s[e+5]]+"-"+k[s[e+6]]+k[s[e+7]]+"-"+k[s[e+8]]+k[s[e+9]]+"-"+k[s[e+10]]+k[s[e+11]]+k[s[e+12]]+k[s[e+13]]+k[s[e+14]]+k[s[e+15]]).toLowerCase()}let he;const dt=new Uint8Array(16);function lt(){if(!he){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");he=crypto.getRandomValues.bind(crypto)}return he(dt)}const Pe={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function E(s,e,t){var r;if(Pe.randomUUID&&!s)return Pe.randomUUID();s=s||{};const i=s.random??((r=s.rng)==null?void 0:r.call(s))??lt();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,ot(i)}const pt=L`
|
|
32
32
|
:host {
|
|
33
33
|
/* Color tokens (defaults) */
|
|
34
34
|
--bg: #f9fafb;
|
|
@@ -3297,11 +3297,11 @@
|
|
|
3297
3297
|
flex-direction: column;
|
|
3298
3298
|
}
|
|
3299
3299
|
}
|
|
3300
|
-
`;var gt=Object.defineProperty,mt=Object.getOwnPropertyDescriptor,x=(s,e,t,i)=>{for(var r=i>1?void 0:i?mt(e,t):e,n=s.length-1,
|
|
3300
|
+
`;var gt=Object.defineProperty,mt=Object.getOwnPropertyDescriptor,x=(s,e,t,i)=>{for(var r=i>1?void 0:i?mt(e,t):e,n=s.length-1,a;n>=0;n--)(a=s[n])&&(r=(i?a(e,t,r):a(r))||r);return i&&r&>(e,t,r),r};let v=class extends j{constructor(){super(...arguments),this.labelForDrill="Drill",this.labelForGroup="Group",this.subjectTypes=[],this.groups=[],this._templateData={name:"",description:"",steps:[]},this._showStepModal=!1,this._stepFormData={title:"",description:""},this._draggedStepId=null,this._dragOverStepId=null,this._selectedStepId=null,this._questions=[],this._editingStepId=null,this._stepAssignmentCategory="individual",this._stepAssignmentType="subject",this._stepAssignmentTarget="",this._stepAssignmentFirstName="",this._stepAssignmentLastName="",this._openMenuStepId=null}connectedCallback(){super.connectedCallback(),this.workflow?(this._templateData={...this.workflow},this.workflow.steps&&this.workflow.steps.length>0&&(this._selectedStepId=this.workflow.steps[0].id),console.log("Builder loaded with existing workflow:",this.workflow.name)):this._templateData=this._getDefaultWorkflowData(),this._clickOutsideHandler=()=>this._closeStepMenu(),document.addEventListener("click",this._clickOutsideHandler)}disconnectedCallback(){super.disconnectedCallback(),this._clickOutsideHandler&&document.removeEventListener("click",this._clickOutsideHandler)}updated(s){s.has("workflow")&&this.workflow&&(this._templateData={...this.workflow},this.workflow.steps&&this.workflow.steps.length>0&&(this._selectedStepId=this.workflow.steps[0].id),console.log("Workflow property changed, reloading template data"))}_getDefaultWorkflowData(){const s={id:E(),title:"Step 1",description:"",order:1,assignment:{category:"individual",type:"subject"},elements:[],status:"pending"};return{id:E(),name:"",description:"",steps:[s]}}_handleTitleChange(s){const e=s.target;this._templateData={...this._templateData,name:e.value}}_handleDescriptionChange(s){const e=s.target;this._templateData={...this._templateData,description:e.value}}_handleCancel(){var s;console.log("🚫 Builder Widget: Cancel button clicked"),(s=this.onCancel)==null||s.call(this)}_handleSave(){var s,e,t;if((s=this._templateData.name)!=null&&s.trim()){const i={id:this._templateData.id||E(),name:this._templateData.name,description:this._templateData.description||"",steps:this._templateData.steps||[],subjectType:this._templateData.subjectType};console.log("💾 Builder Widget: Save button clicked"),console.log("📄 Workflow Template:",JSON.stringify(i,null,2)),this.workflow?(console.log("Calling onWorkflowUpdated callback"),(e=this.onWorkflowUpdated)==null||e.call(this,i)):(console.log("Calling onWorkflowCreated callback"),(t=this.onWorkflowCreated)==null||t.call(this,i))}else console.log("⚠️ Builder Widget: Save attempted but no title provided")}_addStep(){console.log("🔹 Opening step creation modal"),this._stepFormData={title:"",description:""},this._showStepModal=!0}_closeStepModal(){console.log("🔹 Closing step creation modal"),this._showStepModal=!1,this._editingStepId=null,this._stepFormData={title:"",description:""},this._stepAssignmentCategory="individual",this._stepAssignmentType="subject",this._stepAssignmentTarget="",this._stepAssignmentFirstName="",this._stepAssignmentLastName=""}_handleStepFormInput(s){const e=s.target,{name:t,value:i}=e;this._stepFormData={...this._stepFormData,[t]:i}}_toggleStepMenu(s,e){s.stopPropagation(),this._openMenuStepId=this._openMenuStepId===e?null:e}_closeStepMenu(){this._openMenuStepId=null}_editStep(s){var t;const e=(t=this._templateData.steps)==null?void 0:t.find(i=>i.id===s);if(e){if(this._editingStepId=s,this._stepFormData={title:e.title,description:e.description},this._stepAssignmentCategory=e.assignment.category,this._stepAssignmentType=e.assignment.type,this._stepAssignmentTarget=e.assignment.email||e.assignment.targetId||"",this._stepAssignmentType==="specific_user"){const r=(e.assignment.targetName||"").split(" ");this._stepAssignmentFirstName=r[0]||"",this._stepAssignmentLastName=r.slice(1).join(" ")||""}else this._stepAssignmentFirstName="",this._stepAssignmentLastName="";this._showStepModal=!0,this._closeStepMenu(),console.log("Editing step:",s)}}_duplicateStep(s){var r,n;const e=(r=this._templateData.steps)==null?void 0:r.find(a=>a.id===s);if(!e)return;const t=this._templateData.steps||[],i={...e,id:E(),title:`${e.title} (Copy)`,order:t.length+1,elements:((n=e.elements)==null?void 0:n.map(a=>({...a,id:E()})))||[]};this._templateData={...this._templateData,steps:[...t,i]},this._closeStepMenu(),console.log("Step duplicated:",s)}_deleteStep(s){const e=(this._templateData.steps||[]).filter(t=>t.id!==s);e.forEach((t,i)=>{t.order=i+1}),this._templateData={...this._templateData,steps:e},this._selectedStepId===s&&(this._selectedStepId=e.length>0?e[0].id:null),this._closeStepMenu(),console.log("Step deleted:",s)}_createStep(){var t,i;if(!((t=this._stepFormData.title)!=null&&t.trim())){console.log("⚠️ Step title is required");return}const s=this._templateData.steps||[],e={category:this._stepAssignmentCategory,type:this._stepAssignmentType};if(this._stepAssignmentType==="specific_user"&&this._stepAssignmentTarget?(e.email=this._stepAssignmentTarget,this._stepAssignmentFirstName||this._stepAssignmentLastName?e.targetName=`${this._stepAssignmentFirstName} ${this._stepAssignmentLastName}`.trim():e.targetName=this._stepAssignmentTarget):this._stepAssignmentType==="instance_role_assignee_select"&&this._stepAssignmentTarget&&(e.targetId=this._stepAssignmentTarget),this._editingStepId){const r=s.map(n=>{var a;return n.id===this._editingStepId?{...n,title:this._stepFormData.title.trim(),description:((a=this._stepFormData.description)==null?void 0:a.trim())||"",assignment:e}:n});this._templateData={...this._templateData,steps:r},console.log("✅ Step updated:",this._editingStepId)}else{const r={id:E(),title:this._stepFormData.title.trim(),description:((i=this._stepFormData.description)==null?void 0:i.trim())||"",order:s.length+1,assignment:e,elements:[],status:"pending"};this._templateData={...this._templateData,steps:[...s,r]},this._selectedStepId=r.id,console.log("✅ Step created and selected:",r)}this._closeStepModal()}_selectStep(s){this._selectedStepId=s,console.log("🎯 Step selected:",s)}_getSelectedStep(){return!this._selectedStepId||!this._templateData.steps?null:this._templateData.steps.find(s=>s.id===this._selectedStepId)||null}_handleDragStart(s,e){this._draggedStepId=e,s.dataTransfer&&(s.dataTransfer.effectAllowed="move",s.dataTransfer.setData("text/plain",e)),console.log("🔄 Drag started for step:",e)}_handleDragEnd(s){this._draggedStepId=null,this._dragOverStepId=null,console.log("🔄 Drag ended")}_handleDragOver(s,e){s.preventDefault(),s.dataTransfer&&(s.dataTransfer.dropEffect="move"),this._dragOverStepId!==e&&(this._dragOverStepId=e)}_handleDragLeave(s){const e=s.relatedTarget;s.currentTarget.contains(e)||(this._dragOverStepId=null)}_handleDrop(s,e){if(s.preventDefault(),!this._draggedStepId||this._draggedStepId===e){this._draggedStepId=null,this._dragOverStepId=null;return}const t=this._templateData.steps||[],i=t.findIndex(o=>o.id===this._draggedStepId),r=t.findIndex(o=>o.id===e);if(i===-1||r===-1){console.error("Could not find step indices for reordering");return}console.log("🔄 Before reorder:",t.map((o,d)=>`${d+1}: ${o.title}`));const n=[...t],[a]=n.splice(i,1);n.splice(r,0,a),n.forEach((o,d)=>{o.order=d+1}),console.log("🔄 After reorder:",n.map((o,d)=>`${d+1}: ${o.title}`)),this._templateData={...this._templateData,steps:n},console.log("📝 Template updated with new step order"),this._draggedStepId=null,this._dragOverStepId=null}_handleSubjectTypeChange(s){this._templateData={...this._templateData,subjectType:s.target.value}}_addQuestion(s="text_input"){var i,r;if(!this._templateData.steps||this._templateData.steps.length===0||!this._selectedStepId){console.log("⚠️ Cannot add questions without steps or selected step");return}const e=this._getSelectedStep();if(!e){console.log("⚠️ No step selected");return}if(["text","html","divider","markdown"].includes(s)){let n={id:E(),type:s,order:(((i=e.elements)==null?void 0:i.length)||0)+1};switch(s){case"text":n.content="Enter your text content here...";break;case"html":n.content="<p>Enter your HTML content here...</p>";break;case"divider":n.content="",n.caption="Section Divider";break;case"markdown":n.content=`## Enter your markdown content here...
|
|
3301
3301
|
|
|
3302
|
-
Use **bold** and *italic* text.`;break}const
|
|
3302
|
+
Use **bold** and *italic* text.`;break}const a=this._templateData.steps.map(o=>o.id===this._selectedStepId?{...o,elements:[...o.elements||[],n]}:o);this._templateData={...this._templateData,steps:a},console.log("✅ Content element added to step:",this._selectedStepId)}else{const n={id:E(),type:s,label:this._getQuestionTypeDisplayName(s),order:(((r=e.elements)==null?void 0:r.length)||0)+1,required:!1};["select","radio","checkbox"].includes(s)&&(n.options=["Option 1","Option 2"]);const a=this._templateData.steps.map(o=>o.id===this._selectedStepId?{...o,elements:[...o.elements||[],n]}:o);this._templateData={...this._templateData,steps:a},console.log("✅ Question added to step:",this._selectedStepId)}}_addContentElement(s){var r;if(!this._templateData.steps||this._templateData.steps.length===0||!this._selectedStepId){console.log("⚠️ Cannot add content without steps or selected step");return}const e=this._getSelectedStep();if(!e){console.log("⚠️ No step selected");return}let t={id:E(),type:s,order:(((r=e.elements)==null?void 0:r.length)||0)+1};switch(s){case"text":t.content="Enter your text content here...";break;case"html":t.content="<p>Enter your HTML content here...</p>";break;case"image":t.content="",t.url="",t.alt="",t.caption="";break;case"video":t.content="",t.url="",t.caption="";break;case"file":t.content="",t.url="",t.caption="";break;case"divider":t.content="",t.caption="Section Divider";break;case"markdown":t.content=`## Enter your markdown content here...
|
|
3303
3303
|
|
|
3304
|
-
Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n.id===this._selectedStepId?{...n,elements:[...n.elements||[],t]}:n);this._templateData={...this._templateData,steps:i},console.log("✅ Content element added to step:",this._selectedStepId)}_updateQuestion(s,e){var i;if(!this._selectedStepId)return;const t=(i=this._templateData.steps)==null?void 0:i.map(r=>{var n;return r.id===this._selectedStepId?{...r,elements:((n=r.elements)==null?void 0:n.map(
|
|
3304
|
+
Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n.id===this._selectedStepId?{...n,elements:[...n.elements||[],t]}:n);this._templateData={...this._templateData,steps:i},console.log("✅ Content element added to step:",this._selectedStepId)}_updateQuestion(s,e){var i;if(!this._selectedStepId)return;const t=(i=this._templateData.steps)==null?void 0:i.map(r=>{var n;return r.id===this._selectedStepId?{...r,elements:((n=r.elements)==null?void 0:n.map(a=>a.id===s?{...a,...e}:a))||[]}:r});this._templateData={...this._templateData,steps:t}}_updateContentElement(s,e){var i;if(!this._selectedStepId)return;const t=(i=this._templateData.steps)==null?void 0:i.map(r=>{var n;return r.id===this._selectedStepId?{...r,elements:((n=r.elements)==null?void 0:n.map(a=>a.id===s?{...a,...e}:a))||[]}:r});this._templateData={...this._templateData,steps:t}}_deleteQuestion(s){var t;if(!this._selectedStepId)return;const e=(t=this._templateData.steps)==null?void 0:t.map(i=>{var r;return i.id===this._selectedStepId?{...i,elements:((r=i.elements)==null?void 0:r.filter(n=>n.id!==s))||[]}:i});this._templateData={...this._templateData,steps:e},console.log("🗑️ Question deleted:",s)}_renderQuestionTypeSpecificFields(s){switch(s.type){case"select":case"radio":return l`
|
|
3305
3305
|
<div class="question-options-section">
|
|
3306
3306
|
<label class="options-label">Options:</label>
|
|
3307
3307
|
<div class="options-list">
|
|
@@ -3823,7 +3823,7 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
3823
3823
|
<select
|
|
3824
3824
|
class="assignment-select"
|
|
3825
3825
|
.value=${this._stepAssignmentTarget}
|
|
3826
|
-
@change=${t=>{var n,
|
|
3826
|
+
@change=${t=>{var n,a;const i=t.target;this._stepAssignmentTarget=i.value;const r=(n=this._templateData.steps)==null?void 0:n.findIndex(o=>o.id===this._editingStepId);r!==void 0&&r>-1&&(this._templateData.steps[r].assignment.targetName=(a=this.groups.find(o=>o.id===i.value))==null?void 0:a.name,this._templateData.steps[r].assignment.targetId=i.value,this.requestUpdate())}}
|
|
3827
3827
|
>
|
|
3828
3828
|
<!-- Groups -->
|
|
3829
3829
|
<option value="" disabled selected>
|
|
@@ -4022,7 +4022,7 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4022
4022
|
<select
|
|
4023
4023
|
class="question-type-select"
|
|
4024
4024
|
.value=${n.type||"text_input"}
|
|
4025
|
-
@change=${
|
|
4025
|
+
@change=${a=>{const d=a.target.value;if(["text","html","divider","markdown"].includes(d)){this._addQuestion(d),this._deleteQuestion(n.id);return}const c={type:d};["select","radio","checkbox"].includes(d)&&!n.options&&(c.options=["Option 1","Option 2"]);const u=this._getQuestionTypeDisplayName(n.type);(!n.label||n.label===u)&&(c.label=this._getQuestionTypeDisplayName(d)),this._updateQuestion(n.id,c)}}
|
|
4026
4026
|
>
|
|
4027
4027
|
<optgroup label="Questions">
|
|
4028
4028
|
<option value="text_input">Text Input (short)</option>
|
|
@@ -4074,7 +4074,7 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4074
4074
|
class="question-label-input"
|
|
4075
4075
|
placeholder="Question label"
|
|
4076
4076
|
.value=${n.label||""}
|
|
4077
|
-
@input=${
|
|
4077
|
+
@input=${a=>{const o=a.target;this._updateQuestion(n.id,{label:o.value})}}
|
|
4078
4078
|
/>
|
|
4079
4079
|
|
|
4080
4080
|
${this._renderQuestionTypeSpecificFields(n)}
|
|
@@ -4083,7 +4083,7 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4083
4083
|
<input
|
|
4084
4084
|
type="checkbox"
|
|
4085
4085
|
.checked=${n.required||!1}
|
|
4086
|
-
@change=${
|
|
4086
|
+
@change=${a=>{const o=a.target;this._updateQuestion(n.id,{required:o.checked})}}
|
|
4087
4087
|
/>
|
|
4088
4088
|
Required
|
|
4089
4089
|
</label>
|
|
@@ -4098,7 +4098,7 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4098
4098
|
<select
|
|
4099
4099
|
class="question-type-select"
|
|
4100
4100
|
.value=${t.type||"text"}
|
|
4101
|
-
@change=${
|
|
4101
|
+
@change=${a=>{const d=a.target.value;if(!["text","html","divider","markdown"].includes(d)){this._addQuestion(d),this._deleteQuestion(t.id);return}this._addQuestion(d),this._deleteQuestion(t.id)}}
|
|
4102
4102
|
>
|
|
4103
4103
|
<optgroup label="Questions">
|
|
4104
4104
|
<option value="text_input">Text Input (short)</option>
|
|
@@ -4183,10 +4183,10 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4183
4183
|
${ut}
|
|
4184
4184
|
${Ne}
|
|
4185
4185
|
${ht}
|
|
4186
|
-
`,x([$({attribute:!1})],v.prototype,"labelForDrill",2),x([$({attribute:!1})],v.prototype,"labelForGroup",2),x([$({attribute:!1})],v.prototype,"subjectTypes",2),x([$({attribute:!1})],v.prototype,"groups",2),x([b()],v.prototype,"_templateData",2),x([b()],v.prototype,"_showStepModal",2),x([b()],v.prototype,"_stepFormData",2),x([b()],v.prototype,"_draggedStepId",2),x([b()],v.prototype,"_dragOverStepId",2),x([b()],v.prototype,"_selectedStepId",2),x([b()],v.prototype,"_questions",2),x([b()],v.prototype,"_editingStepId",2),x([b()],v.prototype,"_stepAssignmentCategory",2),x([b()],v.prototype,"_stepAssignmentType",2),x([b()],v.prototype,"_stepAssignmentTarget",2),x([b()],v.prototype,"_stepAssignmentFirstName",2),x([b()],v.prototype,"_stepAssignmentLastName",2),x([$({attribute:!1})],v.prototype,"onCancel",2),x([$({attribute:!1})],v.prototype,"workflow",2),x([b()],v.prototype,"_openMenuStepId",2),v=x([Ue("builder-widget")],v);class ft{constructor(e,t){this.signaturePads=e,this.savedSignatures=t}validateStep(e,t,i){if(i==="preview")return{isValid:!0,errors:{}};if(!e)return{isValid:!1,errors:{}};let r=!0;const n={};for(const
|
|
4186
|
+
`,x([$({attribute:!1})],v.prototype,"labelForDrill",2),x([$({attribute:!1})],v.prototype,"labelForGroup",2),x([$({attribute:!1})],v.prototype,"subjectTypes",2),x([$({attribute:!1})],v.prototype,"groups",2),x([b()],v.prototype,"_templateData",2),x([b()],v.prototype,"_showStepModal",2),x([b()],v.prototype,"_stepFormData",2),x([b()],v.prototype,"_draggedStepId",2),x([b()],v.prototype,"_dragOverStepId",2),x([b()],v.prototype,"_selectedStepId",2),x([b()],v.prototype,"_questions",2),x([b()],v.prototype,"_editingStepId",2),x([b()],v.prototype,"_stepAssignmentCategory",2),x([b()],v.prototype,"_stepAssignmentType",2),x([b()],v.prototype,"_stepAssignmentTarget",2),x([b()],v.prototype,"_stepAssignmentFirstName",2),x([b()],v.prototype,"_stepAssignmentLastName",2),x([$({attribute:!1})],v.prototype,"onCancel",2),x([$({attribute:!1})],v.prototype,"workflow",2),x([b()],v.prototype,"_openMenuStepId",2),v=x([Ue("builder-widget")],v);class ft{constructor(e,t){this.signaturePads=e,this.savedSignatures=t}validateStep(e,t,i){if(i==="preview")return{isValid:!0,errors:{}};if(!e)return{isValid:!1,errors:{}};let r=!0;const n={};for(const a of e.elements)if(this.isQuestionElement(a)){const o=a;if(o.required){const d=this.validateQuestion(o,t[o.id],t);d&&(r=!1,n[o.id]=d.message)}}return{isValid:r,errors:n}}validateQuestion(e,t,i){switch(e.type){case"checkbox":return this.validateCheckbox(e,t);case"signature":return this.validateSignature(e,t,i);case"file_upload":return this.validateFileUpload(e,t);default:return this.validateBasicField(e,t)}}validateCheckbox(e,t){if(e.options&&e.options.length>0){if(!Array.isArray(t)||t.length===0)return{questionId:e.id,message:`${e.label} is required.`}}else if(t!==!0)return{questionId:e.id,message:`${e.label} is required.`};return null}validateSignature(e,t,i){if(i&&i[e.id])return null;const r=this.signaturePads.get(e.id);return!r||r.isEmpty()?{questionId:e.id,message:`${e.label} is required.`}:this.savedSignatures.has(e.id)?null:{questionId:e.id,message:`Please save your ${e.label} before continuing.`}}validateFileUpload(e,t){return!t||t===null||t===void 0?{questionId:e.id,message:`${e.label} is required.`}:null}validateBasicField(e,t){return t==null||t===""?{questionId:e.id,message:`${e.label} is required.`}:null}isQuestionElement(e){return["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"].includes(e.type)}}class bt{getStorageKey(e){return`runner-form-data-${e||"default"}`}saveFormData(e,t,i,r,n,a){var c,u,h;const o=this.getStorageKey(e),d=a?{...a,currentStepId:(u=(c=a.steps)==null?void 0:c[i])==null?void 0:u.id,completedSteps:Array.from(n),steps:(h=a.steps)==null?void 0:h.map(m=>({...m,responses:m.responses||[]}))}:null,p={formData:t,timestamp:new Date().toISOString(),stepIndex:i,savedSignatures:Array.from(r),completedSteps:Array.from(n),instance:d};try{localStorage.setItem(o,JSON.stringify(p))}catch(m){console.warn("Failed to save form data to localStorage:",m)}}restoreFormData(e){const t=this.getStorageKey(e);try{const i=localStorage.getItem(t);if(!i)return null;const r=JSON.parse(i);return{formData:r.formData||{},stepIndex:r.stepIndex||0,savedSignatures:new Set(r.savedSignatures||[]),completedSteps:new Set(r.completedSteps||[]),savedInstance:r.instance||null}}catch(i){return console.warn("Failed to restore form data from localStorage:",i),null}}clearFormData(e,t="completed workflow"){const i=this.getStorageKey(e);try{localStorage.removeItem(i),console.log(`Cleared saved form data for ${t}`)}catch(r){console.warn("Failed to clear saved form data:",r)}}shouldRestoreData(e){return e==="default"}}/*!
|
|
4187
4187
|
* Signature Pad v5.0.10 | https://github.com/szimek/signature_pad
|
|
4188
4188
|
* (c) 2025 Szymon Nowak | Released under the MIT license
|
|
4189
|
-
*/class Z{constructor(e,t,i,r){if(isNaN(e)||isNaN(t))throw new Error(`Point is invalid: (${e}, ${t})`);this.x=+e,this.y=+t,this.pressure=i||0,this.time=r||Date.now()}distanceTo(e){return Math.sqrt(Math.pow(this.x-e.x,2)+Math.pow(this.y-e.y,2))}equals(e){return this.x===e.x&&this.y===e.y&&this.pressure===e.pressure&&this.time===e.time}velocityFrom(e){return this.time!==e.time?this.distanceTo(e)/(this.time-e.time):0}}class ge{static fromPoints(e,t){const i=this.calculateControlPoints(e[0],e[1],e[2]).c2,r=this.calculateControlPoints(e[1],e[2],e[3]).c1;return new ge(e[1],i,r,e[2],t.start,t.end)}static calculateControlPoints(e,t,i){const r=e.x-t.x,n=e.y-t.y,o=t.x-i.x,a=t.y-i.y,d={x:(e.x+t.x)/2,y:(e.y+t.y)/2},p={x:(t.x+i.x)/2,y:(t.y+i.y)/2},c=Math.sqrt(r*r+n*n),u=Math.sqrt(o*o+a*a),h=d.x-p.x,m=d.y-p.y,y=c+u==0?0:u/(c+u),S={x:p.x+h*y,y:p.y+m*y},se=t.x-S.x,re=t.y-S.y;return{c1:new Z(d.x+se,d.y+re),c2:new Z(p.x+se,p.y+re)}}constructor(e,t,i,r,n,o){this.startPoint=e,this.control2=t,this.control1=i,this.endPoint=r,this.startWidth=n,this.endWidth=o}length(){let t=0,i,r;for(let n=0;n<=10;n+=1){const o=n/10,a=this.point(o,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),d=this.point(o,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(n>0){const p=a-i,c=d-r;t+=Math.sqrt(p*p+c*c)}i=a,r=d}return t}point(e,t,i,r,n){return t*(1-e)*(1-e)*(1-e)+3*i*(1-e)*(1-e)*e+3*r*(1-e)*e*e+n*e*e*e}}class vt{constructor(){try{this._et=new EventTarget}catch{this._et=document}}addEventListener(e,t,i){this._et.addEventListener(e,t,i)}dispatchEvent(e){return this._et.dispatchEvent(e)}removeEventListener(e,t,i){this._et.removeEventListener(e,t,i)}}function xt(s,e=250){let t=0,i=null,r,n,o;const a=()=>{t=Date.now(),i=null,r=s.apply(n,o),i||(n=null,o=[])};return function(...p){const c=Date.now(),u=e-(c-t);return n=this,o=p,u<=0||u>e?(i&&(clearTimeout(i),i=null),t=c,r=s.apply(n,o),i||(n=null,o=[])):i||(i=window.setTimeout(a,u)),r}}class ee extends vt{constructor(e,t={}){var i,r,n;super(),this.canvas=e,this._drawingStroke=!1,this._isEmpty=!0,this._lastPoints=[],this._data=[],this._lastVelocity=0,this._lastWidth=0,this.velocityFilterWeight=t.velocityFilterWeight||.7,this.minWidth=t.minWidth||.5,this.maxWidth=t.maxWidth||2.5,this.throttle=(i=t.throttle)!==null&&i!==void 0?i:16,this.minDistance=(r=t.minDistance)!==null&&r!==void 0?r:5,this.dotSize=t.dotSize||0,this.penColor=t.penColor||"black",this.backgroundColor=t.backgroundColor||"rgba(0,0,0,0)",this.compositeOperation=t.compositeOperation||"source-over",this.canvasContextOptions=(n=t.canvasContextOptions)!==null&&n!==void 0?n:{},this._strokeMoveUpdate=this.throttle?xt(ee.prototype._strokeUpdate,this.throttle):ee.prototype._strokeUpdate,this._handleMouseDown=this._handleMouseDown.bind(this),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this._handleTouchStart=this._handleTouchStart.bind(this),this._handleTouchMove=this._handleTouchMove.bind(this),this._handleTouchEnd=this._handleTouchEnd.bind(this),this._handlePointerDown=this._handlePointerDown.bind(this),this._handlePointerMove=this._handlePointerMove.bind(this),this._handlePointerUp=this._handlePointerUp.bind(this),this._ctx=e.getContext("2d",this.canvasContextOptions),this.clear(),this.on()}clear(){const{_ctx:e,canvas:t}=this;e.fillStyle=this.backgroundColor,e.clearRect(0,0,t.width,t.height),e.fillRect(0,0,t.width,t.height),this._data=[],this._reset(this._getPointGroupOptions()),this._isEmpty=!0,this._strokePointerId=void 0}fromDataURL(e,t={}){return new Promise((i,r)=>{const n=new Image,o=t.ratio||window.devicePixelRatio||1,a=t.width||this.canvas.width/o,d=t.height||this.canvas.height/o,p=t.xOffset||0,c=t.yOffset||0;this._reset(this._getPointGroupOptions()),n.onload=()=>{this._ctx.drawImage(n,p,c,a,d),i()},n.onerror=u=>{r(u)},n.crossOrigin="anonymous",n.src=e,this._isEmpty=!1})}toDataURL(e="image/png",t){switch(e){case"image/svg+xml":return typeof t!="object"&&(t=void 0),`data:image/svg+xml;base64,${btoa(this.toSVG(t))}`;default:return typeof t!="number"&&(t=void 0),this.canvas.toDataURL(e,t)}}on(){this.canvas.style.touchAction="none",this.canvas.style.msTouchAction="none",this.canvas.style.userSelect="none";const e=/Macintosh/.test(navigator.userAgent)&&"ontouchstart"in document;window.PointerEvent&&!e?this._handlePointerEvents():(this._handleMouseEvents(),"ontouchstart"in window&&this._handleTouchEvents())}off(){this.canvas.style.touchAction="auto",this.canvas.style.msTouchAction="auto",this.canvas.style.userSelect="auto",this.canvas.removeEventListener("pointerdown",this._handlePointerDown),this.canvas.removeEventListener("mousedown",this._handleMouseDown),this.canvas.removeEventListener("touchstart",this._handleTouchStart),this._removeMoveUpEventListeners()}_getListenerFunctions(){var e;const t=window.document===this.canvas.ownerDocument?window:(e=this.canvas.ownerDocument.defaultView)!==null&&e!==void 0?e:this.canvas.ownerDocument;return{addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}_removeMoveUpEventListeners(){const{removeEventListener:e}=this._getListenerFunctions();e("pointermove",this._handlePointerMove),e("pointerup",this._handlePointerUp),e("mousemove",this._handleMouseMove),e("mouseup",this._handleMouseUp),e("touchmove",this._handleTouchMove),e("touchend",this._handleTouchEnd)}isEmpty(){return this._isEmpty}fromData(e,{clear:t=!0}={}){t&&this.clear(),this._fromData(e,this._drawCurve.bind(this),this._drawDot.bind(this)),this._data=this._data.concat(e)}toData(){return this._data}_isLeftButtonPressed(e,t){return t?e.buttons===1:(e.buttons&1)===1}_pointerEventToSignatureEvent(e){return{event:e,type:e.type,x:e.clientX,y:e.clientY,pressure:"pressure"in e?e.pressure:0}}_touchEventToSignatureEvent(e){const t=e.changedTouches[0];return{event:e,type:e.type,x:t.clientX,y:t.clientY,pressure:t.force}}_handleMouseDown(e){!this._isLeftButtonPressed(e,!0)||this._drawingStroke||this._strokeBegin(this._pointerEventToSignatureEvent(e))}_handleMouseMove(e){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}_handleMouseUp(e){this._isLeftButtonPressed(e)||this._strokeEnd(this._pointerEventToSignatureEvent(e))}_handleTouchStart(e){e.targetTouches.length!==1||this._drawingStroke||(e.cancelable&&e.preventDefault(),this._strokeBegin(this._touchEventToSignatureEvent(e)))}_handleTouchMove(e){if(e.targetTouches.length===1){if(e.cancelable&&e.preventDefault(),!this._drawingStroke){this._strokeEnd(this._touchEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._touchEventToSignatureEvent(e))}}_handleTouchEnd(e){e.targetTouches.length===0&&(e.cancelable&&e.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(e)))}_getPointerId(e){return e.persistentDeviceId||e.pointerId}_allowPointerId(e,t=!1){return typeof this._strokePointerId>"u"?t:this._getPointerId(e)===this._strokePointerId}_handlePointerDown(e){this._drawingStroke||!this._isLeftButtonPressed(e)||!this._allowPointerId(e,!0)||(this._strokePointerId=this._getPointerId(e),e.preventDefault(),this._strokeBegin(this._pointerEventToSignatureEvent(e)))}_handlePointerMove(e){if(this._allowPointerId(e)){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}e.preventDefault(),this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}}_handlePointerUp(e){this._isLeftButtonPressed(e)||!this._allowPointerId(e)||(e.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(e)))}_getPointGroupOptions(e){return{penColor:e&&"penColor"in e?e.penColor:this.penColor,dotSize:e&&"dotSize"in e?e.dotSize:this.dotSize,minWidth:e&&"minWidth"in e?e.minWidth:this.minWidth,maxWidth:e&&"maxWidth"in e?e.maxWidth:this.maxWidth,velocityFilterWeight:e&&"velocityFilterWeight"in e?e.velocityFilterWeight:this.velocityFilterWeight,compositeOperation:e&&"compositeOperation"in e?e.compositeOperation:this.compositeOperation}}_strokeBegin(e){if(!this.dispatchEvent(new CustomEvent("beginStroke",{detail:e,cancelable:!0})))return;const{addEventListener:i}=this._getListenerFunctions();switch(e.event.type){case"mousedown":i("mousemove",this._handleMouseMove,{passive:!1}),i("mouseup",this._handleMouseUp,{passive:!1});break;case"touchstart":i("touchmove",this._handleTouchMove,{passive:!1}),i("touchend",this._handleTouchEnd,{passive:!1});break;case"pointerdown":i("pointermove",this._handlePointerMove,{passive:!1}),i("pointerup",this._handlePointerUp,{passive:!1});break}this._drawingStroke=!0;const r=this._getPointGroupOptions(),n=Object.assign(Object.assign({},r),{points:[]});this._data.push(n),this._reset(r),this._strokeUpdate(e)}_strokeUpdate(e){if(!this._drawingStroke)return;if(this._data.length===0){this._strokeBegin(e);return}this.dispatchEvent(new CustomEvent("beforeUpdateStroke",{detail:e}));const t=this._createPoint(e.x,e.y,e.pressure),i=this._data[this._data.length-1],r=i.points,n=r.length>0&&r[r.length-1],o=n?t.distanceTo(n)<=this.minDistance:!1,a=this._getPointGroupOptions(i);if(!n||!(n&&o)){const d=this._addPoint(t,a);n?d&&this._drawCurve(d,a):this._drawDot(t,a),r.push({time:t.time,x:t.x,y:t.y,pressure:t.pressure})}this.dispatchEvent(new CustomEvent("afterUpdateStroke",{detail:e}))}_strokeEnd(e,t=!0){this._removeMoveUpEventListeners(),this._drawingStroke&&(t&&this._strokeUpdate(e),this._drawingStroke=!1,this._strokePointerId=void 0,this.dispatchEvent(new CustomEvent("endStroke",{detail:e})))}_handlePointerEvents(){this._drawingStroke=!1,this.canvas.addEventListener("pointerdown",this._handlePointerDown,{passive:!1})}_handleMouseEvents(){this._drawingStroke=!1,this.canvas.addEventListener("mousedown",this._handleMouseDown,{passive:!1})}_handleTouchEvents(){this.canvas.addEventListener("touchstart",this._handleTouchStart,{passive:!1})}_reset(e){this._lastPoints=[],this._lastVelocity=0,this._lastWidth=(e.minWidth+e.maxWidth)/2,this._ctx.fillStyle=e.penColor,this._ctx.globalCompositeOperation=e.compositeOperation}_createPoint(e,t,i){const r=this.canvas.getBoundingClientRect();return new Z(e-r.left,t-r.top,i,new Date().getTime())}_addPoint(e,t){const{_lastPoints:i}=this;if(i.push(e),i.length>2){i.length===3&&i.unshift(i[0]);const r=this._calculateCurveWidths(i[1],i[2],t),n=ge.fromPoints(i,r);return i.shift(),n}return null}_calculateCurveWidths(e,t,i){const r=i.velocityFilterWeight*t.velocityFrom(e)+(1-i.velocityFilterWeight)*this._lastVelocity,n=this._strokeWidth(r,i),o={end:n,start:this._lastWidth};return this._lastVelocity=r,this._lastWidth=n,o}_strokeWidth(e,t){return Math.max(t.maxWidth/(e+1),t.minWidth)}_drawCurveSegment(e,t,i){const r=this._ctx;r.moveTo(e,t),r.arc(e,t,i,0,2*Math.PI,!1),this._isEmpty=!1}_drawCurve(e,t){const i=this._ctx,r=e.endWidth-e.startWidth,n=Math.ceil(e.length())*2;i.beginPath(),i.fillStyle=t.penColor;for(let o=0;o<n;o+=1){const a=o/n,d=a*a,p=d*a,c=1-a,u=c*c,h=u*c;let m=h*e.startPoint.x;m+=3*u*a*e.control1.x,m+=3*c*d*e.control2.x,m+=p*e.endPoint.x;let y=h*e.startPoint.y;y+=3*u*a*e.control1.y,y+=3*c*d*e.control2.y,y+=p*e.endPoint.y;const S=Math.min(e.startWidth+p*r,t.maxWidth);this._drawCurveSegment(m,y,S)}i.closePath(),i.fill()}_drawDot(e,t){const i=this._ctx,r=t.dotSize>0?t.dotSize:(t.minWidth+t.maxWidth)/2;i.beginPath(),this._drawCurveSegment(e.x,e.y,r),i.closePath(),i.fillStyle=t.penColor,i.fill()}_fromData(e,t,i){for(const r of e){const{points:n}=r,o=this._getPointGroupOptions(r);if(n.length>1)for(let a=0;a<n.length;a+=1){const d=n[a],p=new Z(d.x,d.y,d.pressure,d.time);a===0&&this._reset(o);const c=this._addPoint(p,o);c&&t(c,o)}else this._reset(o),i(n[0],o)}}toSVG({includeBackgroundColor:e=!1}={}){const t=this._data,i=Math.max(window.devicePixelRatio||1,1),r=0,n=0,o=this.canvas.width/i,a=this.canvas.height/i,d=document.createElementNS("http://www.w3.org/2000/svg","svg");if(d.setAttribute("xmlns","http://www.w3.org/2000/svg"),d.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),d.setAttribute("viewBox",`${r} ${n} ${o} ${a}`),d.setAttribute("width",o.toString()),d.setAttribute("height",a.toString()),e&&this.backgroundColor){const p=document.createElement("rect");p.setAttribute("width","100%"),p.setAttribute("height","100%"),p.setAttribute("fill",this.backgroundColor),d.appendChild(p)}return this._fromData(t,(p,{penColor:c})=>{const u=document.createElement("path");if(!isNaN(p.control1.x)&&!isNaN(p.control1.y)&&!isNaN(p.control2.x)&&!isNaN(p.control2.y)){const h=`M ${p.startPoint.x.toFixed(3)},${p.startPoint.y.toFixed(3)} C ${p.control1.x.toFixed(3)},${p.control1.y.toFixed(3)} ${p.control2.x.toFixed(3)},${p.control2.y.toFixed(3)} ${p.endPoint.x.toFixed(3)},${p.endPoint.y.toFixed(3)}`;u.setAttribute("d",h),u.setAttribute("stroke-width",(p.endWidth*2.25).toFixed(3)),u.setAttribute("stroke",c),u.setAttribute("fill","none"),u.setAttribute("stroke-linecap","round"),d.appendChild(u)}},(p,{penColor:c,dotSize:u,minWidth:h,maxWidth:m})=>{const y=document.createElement("circle"),S=u>0?u:(h+m)/2;y.setAttribute("r",S.toString()),y.setAttribute("cx",p.x.toString()),y.setAttribute("cy",p.y.toString()),y.setAttribute("fill",c),d.appendChild(y)}),d.outerHTML}}class _t{constructor(e){this.signaturePads=new Map,this.canvasElements=new Map,this.onSignatureChange=e}initializeSignaturePad(e,t){const i=t==null?void 0:t.getElementById(`signature-${e}`);if(!i)return null;this.clearSignaturePad(e),this.resizeCanvas(i);const r=new ee(i,{backgroundColor:"rgb(255, 255, 255)",penColor:"rgb(0, 0, 0)",minWidth:.5,maxWidth:2.5});return this.signaturePads.set(e,r),this.canvasElements.set(e,i),r.addEventListener("endStroke",()=>{this.handleSignatureChange(e)}),r}handleSignatureChange(e){var n;const t=this.signaturePads.get(e);if(!t)return;const i=!t.isEmpty(),r=i?t.toData():null;(n=this.onSignatureChange)==null||n.call(this,{questionId:e,hasSignature:i,signatureData:r})}clearSignature(e){const t=this.signaturePads.get(e);t&&(t.clear(),this.handleSignatureChange(e))}saveSignature(e){const t=this.signaturePads.get(e);if(!t||t.isEmpty())return null;const i=t.toSVG(),r=t.toDataURL();return{questionId:e,svgData:i,dataURL:r}}restoreSignature(e,t){const i=this.signaturePads.get(e);if(!i||!t)return!1;try{return i.clear(),i.fromData(t),!0}catch(r){return console.warn(`Failed to restore signature for ${e}:`,r),!1}}handleResize(){this.signaturePads.forEach((e,t)=>{const i=this.canvasElements.get(t);if(i){this.resizeCanvas(i);const r=e.toData();e.clear(),e.fromData(r)}})}resizeCanvas(e){const t=Math.max(window.devicePixelRatio||1,1),i=window.getComputedStyle(e),r=parseFloat(i.width),n=parseFloat(i.height);e.width=r*t,e.height=n*t;const o=e.getContext("2d");o&&o.scale(t,t)}clearSignaturePad(e){var t;this.signaturePads.has(e)&&((t=this.signaturePads.get(e))==null||t.off(),this.signaturePads.delete(e),this.canvasElements.delete(e))}getSignaturePad(e){return this.signaturePads.get(e)}hasSignaturePads(){return this.signaturePads.size>0}getAllSignaturePads(){return new Map(this.signaturePads)}destroy(){this.signaturePads.forEach(e=>{e.off()}),this.signaturePads.clear(),this.canvasElements.clear()}}class yt{trackQuestionResponse(e,t,i){if(!e)return;e.responses||(e.responses=[]);const r=e.responses.findIndex(o=>o.elementId===t),n={elementId:t,value:i,answeredAt:new Date};r>=0?e.responses[r]=n:e.responses.push(n)}updateInstanceWithFormData(e,t){e!=null&&e.steps&&e.steps.forEach(i=>{i.responses||(i.responses=[]),i.elements.forEach(r=>{if(this.isQuestionElement(r.type)){const n=t[r.id];if(n!==void 0&&i.responses){let o=i.responses.find(a=>a.elementId===r.id);o?(o.value=n,o.answeredAt=new Date):(o={elementId:r.id,value:n,answeredAt:new Date},i.responses.push(o))}}})})}extractFormDataFromSteps(e){const t={};return e.forEach(i=>{i.responses&&i.responses.forEach(r=>{t[r.elementId]=r.value})}),t}hasChangedFromPrevious(e,t,i){if(!(i!=null&&i.steps))return!0;for(const r of i.steps)if(r.responses){const n=r.responses.find(o=>o.elementId===e);if(n)return n.value!==t}return!0}isQuestionElement(e){return["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"].includes(e)}}class wt{constructor(e,t){this.mode=e,this.currentUser=t}updateMode(e){this.mode=e}updateCurrentUser(e){this.currentUser=e}isStepAssignedToUser(e){if(!this.currentUser)return!1;const t=e.assignment;return!!(this.currentUser.targetId&&t.targetId&&this.currentUser.targetId===t.targetId||this.currentUser.email&&t.email&&this.currentUser.email===t.email)}getAssignedSteps(e){return e!=null&&e.steps?e.steps.filter(t=>this.isStepAssignedToUser(t)):[]}findNextAssignedStep(e,t){if(!(t!=null&&t.steps))return-1;if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print")return e+1<t.steps.length?e+1:-1;for(let i=e+1;i<t.steps.length;i++){const r=t.steps[i];if(this.isStepAssignedToUser(r))return i}return-1}isLastAssignedStep(e,t){if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print"){const i=t==null?void 0:t.steps;return e===((i==null?void 0:i.length)||0)-1}return this.findNextAssignedStep(e,t)===-1}canNavigateToStep(e,t,i,r,n,o){if((n||o)&&this.mode!=="admin"&&this.mode!=="view-only"&&this.mode!=="print")return{canNavigate:!1,newStepIndex:t,reason:"Navigation blocked: workflow submitted"};if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print"){const p=i.steps;return!p||e<0||e>=p.length?{canNavigate:!1,newStepIndex:t,reason:"Invalid step index"}:{canNavigate:!0,newStepIndex:e}}const a=i.steps;if(!a||e<0||e>=a.length)return{canNavigate:!1,newStepIndex:t,reason:"Invalid step index"};const d=a[e];if(this.isStepAssignedToUser(d)){const p=r.has(d.id),c=this.isStepWithinAllowedRange(e,i,r);return p||c?{canNavigate:!0,newStepIndex:e}:{canNavigate:!1,newStepIndex:t,reason:"Step not accessible yet"}}else return{canNavigate:!0,newStepIndex:e}}isStepWithinAllowedRange(e,t,i){if(!(t!=null&&t.steps))return!1;const n=this.getAssignedSteps(t).map(d=>t.steps.findIndex(p=>p.id===d.id)).sort((d,p)=>d-p);let o=-1;for(const d of n){const p=t.steps[d];i.has(p.id)&&(o=d)}let a=-1;for(const d of n)if(d>o){a=d;break}return a!==-1?e<=a&&this.isStepAssignedToUser(t.steps[e]):this.isStepAssignedToUser(t.steps[e])}}const te=class te{constructor(){this.formData={},this.validationErrors={}}updateFormData(e){this.formData={...e}}mergeFormData(e){this.formData={...this.formData,...e}}setFormField(e,t){this.formData={...this.formData,[e]:t}}removeFormField(e){const t={...this.formData};delete t[e],this.formData=t}getFormData(){return{...this.formData}}getFormField(e){return this.formData[e]}hasFormField(e){return e in this.formData}setValidationErrors(e){this.validationErrors={...e}}getValidationErrors(){return{...this.validationErrors}}clearValidationError(e){if(this.validationErrors[e]){const t={...this.validationErrors};delete t[e],this.validationErrors=t}}hasValidationError(e){return!!this.validationErrors[e]}setValidationError(e,t){this.validationErrors={...this.validationErrors,[e]:t}}clearAllValidationErrors(){this.validationErrors={}}initializeFromResponses(e){const t={};e.forEach(i=>{i.responses&&i.responses.forEach(r=>{t[r.elementId]=r.value})}),this.formData=t}reset(){this.formData={},this.validationErrors={}}isQuestionElement(e){return te.QUESTION_ELEMENT_TYPES.includes(e.type)}getStepFormData(e){var i;const t={};return(i=e.elements)==null||i.forEach(r=>{if(this.isQuestionElement(r)){const n=r,o=this.formData[n.id];o!==void 0&&(t[n.id]=o)}}),t}hasFormData(){return Object.keys(this.formData).length>0}getFormFieldIds(){return Object.keys(this.formData)}getValidationErrorCount(){return Object.keys(this.validationErrors).length}};te.QUESTION_ELEMENT_TYPES=["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"];let me=te;const ie=class ie{constructor(e,t){this.formStateManager=e,this.responseTracker=t}handleFileUpload(e,t,i){var p,c,u,h,m;const r=t.target,n=(p=r.files)==null?void 0:p[0];if(!n){this.clearFile(e),(c=i.onRequestUpdate)==null||c.call(i);return}const o=this.validateFileSize(n);if(o){this.handleFileValidationError(e,o,r),(u=i.onRequestUpdate)==null||u.call(i);return}this.formStateManager.clearValidationError(e);const a=this.createFileInfo(n);this.formStateManager.setFormField(e,a);const d=this.hasFileChanged(e,a,i.savedInstance);d&&i.mode!=="preview"?this.executeFileUploadCallback(e,n,a,i):this.logSkippedCallback(e,i.mode,d),(h=i.onRequestUpdate)==null||h.call(i),i.mode!=="admin"&&((m=i.onFormDataSave)==null||m.call(i))}clearFile(e){this.formStateManager.setFormField(e,null),this.formStateManager.clearValidationError(e)}validateFileSize(e){return e.size>ie.MAX_FILE_SIZE?`File size must be less than 5MB. Current size: ${(e.size/1024/1024).toFixed(2)}MB`:null}handleFileValidationError(e,t,i){this.formStateManager.setValidationError(e,t),this.formStateManager.setFormField(e,null),i.value=""}createFileInfo(e){return{name:e.name,size:e.size,type:e.type,lastModified:e.lastModified}}hasFileChanged(e,t,i){if(!(i!=null&&i.steps))return!0;for(const r of i.steps)if(r.responses){const n=r.responses.find(o=>o.elementId===e);if(n&&n.value&&typeof n.value=="object"){const o=n.value;return o.name!==t.name||o.size!==t.size||o.type!==t.type||o.lastModified!==t.lastModified}}return!0}executeFileUploadCallback(e,t,i,r){var n,o;console.log("File changed, calling callback for:",e),console.log("Callback function exists:",!!r.onFileUploaded),r.onFileUploaded&&r.onFileUploaded({instanceId:(n=r.instance)==null?void 0:n.id,stepId:(o=r.currentStep)==null?void 0:o.id,questionId:e,file:t,fileName:i.name,fileSize:i.size,fileType:i.type})}logSkippedCallback(e,t,i){t==="preview"?console.log("Preview mode: skipping file upload callback for:",e):i||console.log("File unchanged, skipping callback for:",e)}};ie.MAX_FILE_SIZE=5*1024*1024;let fe=ie;class D{static _isInputDisabled(e){return(e.isSubmitted||e.userStepsSubmitted)&&e.mode!=="admin"||e.mode==="view-only"||e.mode==="print"||e.mode==="default"&&!e.handlers.isCurrentStepAssigned()}static _formatFileSize(e){if(e===0)return"0 Bytes";const t=1024,i=["Bytes","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,r)).toFixed(2))+" "+i[r]}static _extractFilenameFromUrl(e){try{return new URL(e).pathname.split("/").pop()||""||"Uploaded File"}catch{const t=e.split("/"),i=t[t.length-1];return i&&i.includes(".")?i:"Uploaded File"}}static _guessFileTypeFromUrl(e){var n;const i=(n=D._extractFilenameFromUrl(e).split(".").pop())==null?void 0:n.toLowerCase();return i?{pdf:"PDF Document",doc:"Word Document",docx:"Word Document",xls:"Excel Spreadsheet",xlsx:"Excel Spreadsheet",png:"PNG Image",jpg:"JPEG Image",jpeg:"JPEG Image",gif:"GIF Image",svg:"SVG Image",txt:"Text File",csv:"CSV File",zip:"ZIP Archive",mp4:"MP4 Video",mp3:"MP3 Audio"}[i]||`${i.toUpperCase()} File`:"Unknown"}static renderTextArea(e,t,i){return i.mode==="print"?l`<div class="print-response-value textarea-response">
|
|
4189
|
+
*/class Z{constructor(e,t,i,r){if(isNaN(e)||isNaN(t))throw new Error(`Point is invalid: (${e}, ${t})`);this.x=+e,this.y=+t,this.pressure=i||0,this.time=r||Date.now()}distanceTo(e){return Math.sqrt(Math.pow(this.x-e.x,2)+Math.pow(this.y-e.y,2))}equals(e){return this.x===e.x&&this.y===e.y&&this.pressure===e.pressure&&this.time===e.time}velocityFrom(e){return this.time!==e.time?this.distanceTo(e)/(this.time-e.time):0}}class ge{static fromPoints(e,t){const i=this.calculateControlPoints(e[0],e[1],e[2]).c2,r=this.calculateControlPoints(e[1],e[2],e[3]).c1;return new ge(e[1],i,r,e[2],t.start,t.end)}static calculateControlPoints(e,t,i){const r=e.x-t.x,n=e.y-t.y,a=t.x-i.x,o=t.y-i.y,d={x:(e.x+t.x)/2,y:(e.y+t.y)/2},p={x:(t.x+i.x)/2,y:(t.y+i.y)/2},c=Math.sqrt(r*r+n*n),u=Math.sqrt(a*a+o*o),h=d.x-p.x,m=d.y-p.y,y=c+u==0?0:u/(c+u),S={x:p.x+h*y,y:p.y+m*y},se=t.x-S.x,re=t.y-S.y;return{c1:new Z(d.x+se,d.y+re),c2:new Z(p.x+se,p.y+re)}}constructor(e,t,i,r,n,a){this.startPoint=e,this.control2=t,this.control1=i,this.endPoint=r,this.startWidth=n,this.endWidth=a}length(){let t=0,i,r;for(let n=0;n<=10;n+=1){const a=n/10,o=this.point(a,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),d=this.point(a,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(n>0){const p=o-i,c=d-r;t+=Math.sqrt(p*p+c*c)}i=o,r=d}return t}point(e,t,i,r,n){return t*(1-e)*(1-e)*(1-e)+3*i*(1-e)*(1-e)*e+3*r*(1-e)*e*e+n*e*e*e}}class vt{constructor(){try{this._et=new EventTarget}catch{this._et=document}}addEventListener(e,t,i){this._et.addEventListener(e,t,i)}dispatchEvent(e){return this._et.dispatchEvent(e)}removeEventListener(e,t,i){this._et.removeEventListener(e,t,i)}}function xt(s,e=250){let t=0,i=null,r,n,a;const o=()=>{t=Date.now(),i=null,r=s.apply(n,a),i||(n=null,a=[])};return function(...p){const c=Date.now(),u=e-(c-t);return n=this,a=p,u<=0||u>e?(i&&(clearTimeout(i),i=null),t=c,r=s.apply(n,a),i||(n=null,a=[])):i||(i=window.setTimeout(o,u)),r}}class ee extends vt{constructor(e,t={}){var i,r,n;super(),this.canvas=e,this._drawingStroke=!1,this._isEmpty=!0,this._lastPoints=[],this._data=[],this._lastVelocity=0,this._lastWidth=0,this.velocityFilterWeight=t.velocityFilterWeight||.7,this.minWidth=t.minWidth||.5,this.maxWidth=t.maxWidth||2.5,this.throttle=(i=t.throttle)!==null&&i!==void 0?i:16,this.minDistance=(r=t.minDistance)!==null&&r!==void 0?r:5,this.dotSize=t.dotSize||0,this.penColor=t.penColor||"black",this.backgroundColor=t.backgroundColor||"rgba(0,0,0,0)",this.compositeOperation=t.compositeOperation||"source-over",this.canvasContextOptions=(n=t.canvasContextOptions)!==null&&n!==void 0?n:{},this._strokeMoveUpdate=this.throttle?xt(ee.prototype._strokeUpdate,this.throttle):ee.prototype._strokeUpdate,this._handleMouseDown=this._handleMouseDown.bind(this),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this._handleTouchStart=this._handleTouchStart.bind(this),this._handleTouchMove=this._handleTouchMove.bind(this),this._handleTouchEnd=this._handleTouchEnd.bind(this),this._handlePointerDown=this._handlePointerDown.bind(this),this._handlePointerMove=this._handlePointerMove.bind(this),this._handlePointerUp=this._handlePointerUp.bind(this),this._ctx=e.getContext("2d",this.canvasContextOptions),this.clear(),this.on()}clear(){const{_ctx:e,canvas:t}=this;e.fillStyle=this.backgroundColor,e.clearRect(0,0,t.width,t.height),e.fillRect(0,0,t.width,t.height),this._data=[],this._reset(this._getPointGroupOptions()),this._isEmpty=!0,this._strokePointerId=void 0}fromDataURL(e,t={}){return new Promise((i,r)=>{const n=new Image,a=t.ratio||window.devicePixelRatio||1,o=t.width||this.canvas.width/a,d=t.height||this.canvas.height/a,p=t.xOffset||0,c=t.yOffset||0;this._reset(this._getPointGroupOptions()),n.onload=()=>{this._ctx.drawImage(n,p,c,o,d),i()},n.onerror=u=>{r(u)},n.crossOrigin="anonymous",n.src=e,this._isEmpty=!1})}toDataURL(e="image/png",t){switch(e){case"image/svg+xml":return typeof t!="object"&&(t=void 0),`data:image/svg+xml;base64,${btoa(this.toSVG(t))}`;default:return typeof t!="number"&&(t=void 0),this.canvas.toDataURL(e,t)}}on(){this.canvas.style.touchAction="none",this.canvas.style.msTouchAction="none",this.canvas.style.userSelect="none";const e=/Macintosh/.test(navigator.userAgent)&&"ontouchstart"in document;window.PointerEvent&&!e?this._handlePointerEvents():(this._handleMouseEvents(),"ontouchstart"in window&&this._handleTouchEvents())}off(){this.canvas.style.touchAction="auto",this.canvas.style.msTouchAction="auto",this.canvas.style.userSelect="auto",this.canvas.removeEventListener("pointerdown",this._handlePointerDown),this.canvas.removeEventListener("mousedown",this._handleMouseDown),this.canvas.removeEventListener("touchstart",this._handleTouchStart),this._removeMoveUpEventListeners()}_getListenerFunctions(){var e;const t=window.document===this.canvas.ownerDocument?window:(e=this.canvas.ownerDocument.defaultView)!==null&&e!==void 0?e:this.canvas.ownerDocument;return{addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}_removeMoveUpEventListeners(){const{removeEventListener:e}=this._getListenerFunctions();e("pointermove",this._handlePointerMove),e("pointerup",this._handlePointerUp),e("mousemove",this._handleMouseMove),e("mouseup",this._handleMouseUp),e("touchmove",this._handleTouchMove),e("touchend",this._handleTouchEnd)}isEmpty(){return this._isEmpty}fromData(e,{clear:t=!0}={}){t&&this.clear(),this._fromData(e,this._drawCurve.bind(this),this._drawDot.bind(this)),this._data=this._data.concat(e)}toData(){return this._data}_isLeftButtonPressed(e,t){return t?e.buttons===1:(e.buttons&1)===1}_pointerEventToSignatureEvent(e){return{event:e,type:e.type,x:e.clientX,y:e.clientY,pressure:"pressure"in e?e.pressure:0}}_touchEventToSignatureEvent(e){const t=e.changedTouches[0];return{event:e,type:e.type,x:t.clientX,y:t.clientY,pressure:t.force}}_handleMouseDown(e){!this._isLeftButtonPressed(e,!0)||this._drawingStroke||this._strokeBegin(this._pointerEventToSignatureEvent(e))}_handleMouseMove(e){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}_handleMouseUp(e){this._isLeftButtonPressed(e)||this._strokeEnd(this._pointerEventToSignatureEvent(e))}_handleTouchStart(e){e.targetTouches.length!==1||this._drawingStroke||(e.cancelable&&e.preventDefault(),this._strokeBegin(this._touchEventToSignatureEvent(e)))}_handleTouchMove(e){if(e.targetTouches.length===1){if(e.cancelable&&e.preventDefault(),!this._drawingStroke){this._strokeEnd(this._touchEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._touchEventToSignatureEvent(e))}}_handleTouchEnd(e){e.targetTouches.length===0&&(e.cancelable&&e.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(e)))}_getPointerId(e){return e.persistentDeviceId||e.pointerId}_allowPointerId(e,t=!1){return typeof this._strokePointerId>"u"?t:this._getPointerId(e)===this._strokePointerId}_handlePointerDown(e){this._drawingStroke||!this._isLeftButtonPressed(e)||!this._allowPointerId(e,!0)||(this._strokePointerId=this._getPointerId(e),e.preventDefault(),this._strokeBegin(this._pointerEventToSignatureEvent(e)))}_handlePointerMove(e){if(this._allowPointerId(e)){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}e.preventDefault(),this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}}_handlePointerUp(e){this._isLeftButtonPressed(e)||!this._allowPointerId(e)||(e.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(e)))}_getPointGroupOptions(e){return{penColor:e&&"penColor"in e?e.penColor:this.penColor,dotSize:e&&"dotSize"in e?e.dotSize:this.dotSize,minWidth:e&&"minWidth"in e?e.minWidth:this.minWidth,maxWidth:e&&"maxWidth"in e?e.maxWidth:this.maxWidth,velocityFilterWeight:e&&"velocityFilterWeight"in e?e.velocityFilterWeight:this.velocityFilterWeight,compositeOperation:e&&"compositeOperation"in e?e.compositeOperation:this.compositeOperation}}_strokeBegin(e){if(!this.dispatchEvent(new CustomEvent("beginStroke",{detail:e,cancelable:!0})))return;const{addEventListener:i}=this._getListenerFunctions();switch(e.event.type){case"mousedown":i("mousemove",this._handleMouseMove,{passive:!1}),i("mouseup",this._handleMouseUp,{passive:!1});break;case"touchstart":i("touchmove",this._handleTouchMove,{passive:!1}),i("touchend",this._handleTouchEnd,{passive:!1});break;case"pointerdown":i("pointermove",this._handlePointerMove,{passive:!1}),i("pointerup",this._handlePointerUp,{passive:!1});break}this._drawingStroke=!0;const r=this._getPointGroupOptions(),n=Object.assign(Object.assign({},r),{points:[]});this._data.push(n),this._reset(r),this._strokeUpdate(e)}_strokeUpdate(e){if(!this._drawingStroke)return;if(this._data.length===0){this._strokeBegin(e);return}this.dispatchEvent(new CustomEvent("beforeUpdateStroke",{detail:e}));const t=this._createPoint(e.x,e.y,e.pressure),i=this._data[this._data.length-1],r=i.points,n=r.length>0&&r[r.length-1],a=n?t.distanceTo(n)<=this.minDistance:!1,o=this._getPointGroupOptions(i);if(!n||!(n&&a)){const d=this._addPoint(t,o);n?d&&this._drawCurve(d,o):this._drawDot(t,o),r.push({time:t.time,x:t.x,y:t.y,pressure:t.pressure})}this.dispatchEvent(new CustomEvent("afterUpdateStroke",{detail:e}))}_strokeEnd(e,t=!0){this._removeMoveUpEventListeners(),this._drawingStroke&&(t&&this._strokeUpdate(e),this._drawingStroke=!1,this._strokePointerId=void 0,this.dispatchEvent(new CustomEvent("endStroke",{detail:e})))}_handlePointerEvents(){this._drawingStroke=!1,this.canvas.addEventListener("pointerdown",this._handlePointerDown,{passive:!1})}_handleMouseEvents(){this._drawingStroke=!1,this.canvas.addEventListener("mousedown",this._handleMouseDown,{passive:!1})}_handleTouchEvents(){this.canvas.addEventListener("touchstart",this._handleTouchStart,{passive:!1})}_reset(e){this._lastPoints=[],this._lastVelocity=0,this._lastWidth=(e.minWidth+e.maxWidth)/2,this._ctx.fillStyle=e.penColor,this._ctx.globalCompositeOperation=e.compositeOperation}_createPoint(e,t,i){const r=this.canvas.getBoundingClientRect();return new Z(e-r.left,t-r.top,i,new Date().getTime())}_addPoint(e,t){const{_lastPoints:i}=this;if(i.push(e),i.length>2){i.length===3&&i.unshift(i[0]);const r=this._calculateCurveWidths(i[1],i[2],t),n=ge.fromPoints(i,r);return i.shift(),n}return null}_calculateCurveWidths(e,t,i){const r=i.velocityFilterWeight*t.velocityFrom(e)+(1-i.velocityFilterWeight)*this._lastVelocity,n=this._strokeWidth(r,i),a={end:n,start:this._lastWidth};return this._lastVelocity=r,this._lastWidth=n,a}_strokeWidth(e,t){return Math.max(t.maxWidth/(e+1),t.minWidth)}_drawCurveSegment(e,t,i){const r=this._ctx;r.moveTo(e,t),r.arc(e,t,i,0,2*Math.PI,!1),this._isEmpty=!1}_drawCurve(e,t){const i=this._ctx,r=e.endWidth-e.startWidth,n=Math.ceil(e.length())*2;i.beginPath(),i.fillStyle=t.penColor;for(let a=0;a<n;a+=1){const o=a/n,d=o*o,p=d*o,c=1-o,u=c*c,h=u*c;let m=h*e.startPoint.x;m+=3*u*o*e.control1.x,m+=3*c*d*e.control2.x,m+=p*e.endPoint.x;let y=h*e.startPoint.y;y+=3*u*o*e.control1.y,y+=3*c*d*e.control2.y,y+=p*e.endPoint.y;const S=Math.min(e.startWidth+p*r,t.maxWidth);this._drawCurveSegment(m,y,S)}i.closePath(),i.fill()}_drawDot(e,t){const i=this._ctx,r=t.dotSize>0?t.dotSize:(t.minWidth+t.maxWidth)/2;i.beginPath(),this._drawCurveSegment(e.x,e.y,r),i.closePath(),i.fillStyle=t.penColor,i.fill()}_fromData(e,t,i){for(const r of e){const{points:n}=r,a=this._getPointGroupOptions(r);if(n.length>1)for(let o=0;o<n.length;o+=1){const d=n[o],p=new Z(d.x,d.y,d.pressure,d.time);o===0&&this._reset(a);const c=this._addPoint(p,a);c&&t(c,a)}else this._reset(a),i(n[0],a)}}toSVG({includeBackgroundColor:e=!1}={}){const t=this._data,i=Math.max(window.devicePixelRatio||1,1),r=0,n=0,a=this.canvas.width/i,o=this.canvas.height/i,d=document.createElementNS("http://www.w3.org/2000/svg","svg");if(d.setAttribute("xmlns","http://www.w3.org/2000/svg"),d.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),d.setAttribute("viewBox",`${r} ${n} ${a} ${o}`),d.setAttribute("width",a.toString()),d.setAttribute("height",o.toString()),e&&this.backgroundColor){const p=document.createElement("rect");p.setAttribute("width","100%"),p.setAttribute("height","100%"),p.setAttribute("fill",this.backgroundColor),d.appendChild(p)}return this._fromData(t,(p,{penColor:c})=>{const u=document.createElement("path");if(!isNaN(p.control1.x)&&!isNaN(p.control1.y)&&!isNaN(p.control2.x)&&!isNaN(p.control2.y)){const h=`M ${p.startPoint.x.toFixed(3)},${p.startPoint.y.toFixed(3)} C ${p.control1.x.toFixed(3)},${p.control1.y.toFixed(3)} ${p.control2.x.toFixed(3)},${p.control2.y.toFixed(3)} ${p.endPoint.x.toFixed(3)},${p.endPoint.y.toFixed(3)}`;u.setAttribute("d",h),u.setAttribute("stroke-width",(p.endWidth*2.25).toFixed(3)),u.setAttribute("stroke",c),u.setAttribute("fill","none"),u.setAttribute("stroke-linecap","round"),d.appendChild(u)}},(p,{penColor:c,dotSize:u,minWidth:h,maxWidth:m})=>{const y=document.createElement("circle"),S=u>0?u:(h+m)/2;y.setAttribute("r",S.toString()),y.setAttribute("cx",p.x.toString()),y.setAttribute("cy",p.y.toString()),y.setAttribute("fill",c),d.appendChild(y)}),d.outerHTML}}class _t{constructor(e){this.signaturePads=new Map,this.canvasElements=new Map,this.onSignatureChange=e}initializeSignaturePad(e,t){const i=t==null?void 0:t.getElementById(`signature-${e}`);if(!i)return null;this.clearSignaturePad(e),this.resizeCanvas(i);const r=new ee(i,{backgroundColor:"rgb(255, 255, 255)",penColor:"rgb(0, 0, 0)",minWidth:.5,maxWidth:2.5});return this.signaturePads.set(e,r),this.canvasElements.set(e,i),r.addEventListener("endStroke",()=>{this.handleSignatureChange(e)}),r}handleSignatureChange(e){var n;const t=this.signaturePads.get(e);if(!t)return;const i=!t.isEmpty(),r=i?t.toData():null;(n=this.onSignatureChange)==null||n.call(this,{questionId:e,hasSignature:i,signatureData:r})}clearSignature(e){const t=this.signaturePads.get(e);t&&(t.clear(),this.handleSignatureChange(e))}saveSignature(e){const t=this.signaturePads.get(e);if(!t||t.isEmpty())return null;const i=t.toSVG(),r=t.toDataURL();return{questionId:e,svgData:i,dataURL:r}}restoreSignature(e,t){const i=this.signaturePads.get(e);if(!i||!t)return!1;try{return i.clear(),i.fromData(t),!0}catch(r){return console.warn(`Failed to restore signature for ${e}:`,r),!1}}handleResize(){this.signaturePads.forEach((e,t)=>{const i=this.canvasElements.get(t);if(i){this.resizeCanvas(i);const r=e.toData();e.clear(),e.fromData(r)}})}resizeCanvas(e){const t=Math.max(window.devicePixelRatio||1,1),i=window.getComputedStyle(e),r=parseFloat(i.width),n=parseFloat(i.height);e.width=r*t,e.height=n*t;const a=e.getContext("2d");a&&a.scale(t,t)}clearSignaturePad(e){var t;this.signaturePads.has(e)&&((t=this.signaturePads.get(e))==null||t.off(),this.signaturePads.delete(e),this.canvasElements.delete(e))}getSignaturePad(e){return this.signaturePads.get(e)}hasSignaturePads(){return this.signaturePads.size>0}getAllSignaturePads(){return new Map(this.signaturePads)}destroy(){this.signaturePads.forEach(e=>{e.off()}),this.signaturePads.clear(),this.canvasElements.clear()}}class yt{trackQuestionResponse(e,t,i){if(!e)return;e.responses||(e.responses=[]);const r=e.responses.findIndex(a=>a.elementId===t),n={elementId:t,value:i,answeredAt:new Date};r>=0?e.responses[r]=n:e.responses.push(n)}updateInstanceWithFormData(e,t){e!=null&&e.steps&&e.steps.forEach(i=>{i.responses||(i.responses=[]),i.elements.forEach(r=>{if(this.isQuestionElement(r.type)){const n=t[r.id];if(n!==void 0&&i.responses){let a=i.responses.find(o=>o.elementId===r.id);a?(a.value=n,a.answeredAt=new Date):(a={elementId:r.id,value:n,answeredAt:new Date},i.responses.push(a))}}})})}extractFormDataFromSteps(e){const t={};return e.forEach(i=>{i.responses&&i.responses.forEach(r=>{t[r.elementId]=r.value})}),t}hasChangedFromPrevious(e,t,i){if(!(i!=null&&i.steps))return!0;for(const r of i.steps)if(r.responses){const n=r.responses.find(a=>a.elementId===e);if(n)return n.value!==t}return!0}isQuestionElement(e){return["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"].includes(e)}}class wt{constructor(e,t){this.mode=e,this.currentUser=t}updateMode(e){this.mode=e}updateCurrentUser(e){this.currentUser=e}isStepAssignedToUser(e){if(!this.currentUser)return!1;const t=e.assignment;return!!(this.currentUser.targetId&&t.targetId&&this.currentUser.targetId===t.targetId||this.currentUser.email&&t.email&&this.currentUser.email===t.email)}getAssignedSteps(e){return e!=null&&e.steps?e.steps.filter(t=>this.isStepAssignedToUser(t)):[]}findNextAssignedStep(e,t){if(!(t!=null&&t.steps))return-1;if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print")return e+1<t.steps.length?e+1:-1;for(let i=e+1;i<t.steps.length;i++){const r=t.steps[i];if(this.isStepAssignedToUser(r))return i}return-1}isLastAssignedStep(e,t){if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print"){const i=t==null?void 0:t.steps;return e===((i==null?void 0:i.length)||0)-1}return this.findNextAssignedStep(e,t)===-1}canNavigateToStep(e,t,i,r,n,a){if((n||a)&&this.mode!=="admin"&&this.mode!=="view-only"&&this.mode!=="print")return{canNavigate:!1,newStepIndex:t,reason:"Navigation blocked: workflow submitted"};if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print"){const p=i.steps;return!p||e<0||e>=p.length?{canNavigate:!1,newStepIndex:t,reason:"Invalid step index"}:{canNavigate:!0,newStepIndex:e}}const o=i.steps;if(!o||e<0||e>=o.length)return{canNavigate:!1,newStepIndex:t,reason:"Invalid step index"};const d=o[e];if(this.isStepAssignedToUser(d)){const p=r.has(d.id),c=this.isStepWithinAllowedRange(e,i,r);return p||c?{canNavigate:!0,newStepIndex:e}:{canNavigate:!1,newStepIndex:t,reason:"Step not accessible yet"}}else return{canNavigate:!0,newStepIndex:e}}isStepWithinAllowedRange(e,t,i){if(!(t!=null&&t.steps))return!1;const n=this.getAssignedSteps(t).map(d=>t.steps.findIndex(p=>p.id===d.id)).sort((d,p)=>d-p);let a=-1;for(const d of n){const p=t.steps[d];i.has(p.id)&&(a=d)}let o=-1;for(const d of n)if(d>a){o=d;break}return o!==-1?e<=o&&this.isStepAssignedToUser(t.steps[e]):this.isStepAssignedToUser(t.steps[e])}}const te=class te{constructor(){this.formData={},this.validationErrors={}}updateFormData(e){this.formData={...e}}mergeFormData(e){this.formData={...this.formData,...e}}setFormField(e,t){this.formData={...this.formData,[e]:t}}removeFormField(e){const t={...this.formData};delete t[e],this.formData=t}getFormData(){return{...this.formData}}getFormField(e){return this.formData[e]}hasFormField(e){return e in this.formData}setValidationErrors(e){this.validationErrors={...e}}getValidationErrors(){return{...this.validationErrors}}clearValidationError(e){if(this.validationErrors[e]){const t={...this.validationErrors};delete t[e],this.validationErrors=t}}hasValidationError(e){return!!this.validationErrors[e]}setValidationError(e,t){this.validationErrors={...this.validationErrors,[e]:t}}clearAllValidationErrors(){this.validationErrors={}}initializeFromResponses(e){const t={};e.forEach(i=>{i.responses&&i.responses.forEach(r=>{t[r.elementId]=r.value})}),this.formData=t}reset(){this.formData={},this.validationErrors={}}isQuestionElement(e){return te.QUESTION_ELEMENT_TYPES.includes(e.type)}getStepFormData(e){var i;const t={};return(i=e.elements)==null||i.forEach(r=>{if(this.isQuestionElement(r)){const n=r,a=this.formData[n.id];a!==void 0&&(t[n.id]=a)}}),t}hasFormData(){return Object.keys(this.formData).length>0}getFormFieldIds(){return Object.keys(this.formData)}getValidationErrorCount(){return Object.keys(this.validationErrors).length}};te.QUESTION_ELEMENT_TYPES=["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"];let me=te;const ie=class ie{constructor(e,t){this.formStateManager=e,this.responseTracker=t}handleFileUpload(e,t,i){var p,c,u,h,m;const r=t.target,n=(p=r.files)==null?void 0:p[0];if(!n){this.clearFile(e),(c=i.onRequestUpdate)==null||c.call(i);return}const a=this.validateFileSize(n);if(a){this.handleFileValidationError(e,a,r),(u=i.onRequestUpdate)==null||u.call(i);return}this.formStateManager.clearValidationError(e);const o=this.createFileInfo(n);this.formStateManager.setFormField(e,o);const d=this.hasFileChanged(e,o,i.savedInstance);d&&i.mode!=="preview"?this.executeFileUploadCallback(e,n,o,i):this.logSkippedCallback(e,i.mode,d),(h=i.onRequestUpdate)==null||h.call(i),i.mode!=="admin"&&((m=i.onFormDataSave)==null||m.call(i))}clearFile(e){this.formStateManager.setFormField(e,null),this.formStateManager.clearValidationError(e)}validateFileSize(e){return e.size>ie.MAX_FILE_SIZE?`File size must be less than 5MB. Current size: ${(e.size/1024/1024).toFixed(2)}MB`:null}handleFileValidationError(e,t,i){this.formStateManager.setValidationError(e,t),this.formStateManager.setFormField(e,null),i.value=""}createFileInfo(e){return{name:e.name,size:e.size,type:e.type,lastModified:e.lastModified}}hasFileChanged(e,t,i){if(!(i!=null&&i.steps))return!0;for(const r of i.steps)if(r.responses){const n=r.responses.find(a=>a.elementId===e);if(n&&n.value&&typeof n.value=="object"){const a=n.value;return a.name!==t.name||a.size!==t.size||a.type!==t.type||a.lastModified!==t.lastModified}}return!0}executeFileUploadCallback(e,t,i,r){var n,a;console.log("File changed, calling callback for:",e),console.log("Callback function exists:",!!r.onFileUploaded),r.onFileUploaded&&r.onFileUploaded({instanceId:(n=r.instance)==null?void 0:n.id,stepId:(a=r.currentStep)==null?void 0:a.id,questionId:e,file:t,fileName:i.name,fileSize:i.size,fileType:i.type})}logSkippedCallback(e,t,i){t==="preview"?console.log("Preview mode: skipping file upload callback for:",e):i||console.log("File unchanged, skipping callback for:",e)}};ie.MAX_FILE_SIZE=5*1024*1024;let fe=ie;class D{static _isInputDisabled(e){return(e.isSubmitted||e.userStepsSubmitted)&&e.mode!=="admin"||e.mode==="view-only"||e.mode==="print"||e.mode==="default"&&!e.handlers.isCurrentStepAssigned()}static _formatFileSize(e){if(e===0)return"0 Bytes";const t=1024,i=["Bytes","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,r)).toFixed(2))+" "+i[r]}static _extractFilenameFromUrl(e){try{return new URL(e).pathname.split("/").pop()||""||"Uploaded File"}catch{const t=e.split("/"),i=t[t.length-1];return i&&i.includes(".")?i:"Uploaded File"}}static _guessFileTypeFromUrl(e){var n;const i=(n=D._extractFilenameFromUrl(e).split(".").pop())==null?void 0:n.toLowerCase();return i?{pdf:"PDF Document",doc:"Word Document",docx:"Word Document",xls:"Excel Spreadsheet",xlsx:"Excel Spreadsheet",png:"PNG Image",jpg:"JPEG Image",jpeg:"JPEG Image",gif:"GIF Image",svg:"SVG Image",txt:"Text File",csv:"CSV File",zip:"ZIP Archive",mp4:"MP4 Video",mp3:"MP3 Audio"}[i]||`${i.toUpperCase()} File`:"Unknown"}static renderTextArea(e,t,i){return i.mode==="print"?l`<div class="print-response-value textarea-response">
|
|
4190
4190
|
${t||l`<span class="print-no-response">No response</span>`}
|
|
4191
4191
|
</div>`:l`<textarea
|
|
4192
4192
|
id=${e.id}
|
|
@@ -4207,36 +4207,36 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4207
4207
|
>
|
|
4208
4208
|
<option value="">Choose</option>
|
|
4209
4209
|
${(r=e.options)==null?void 0:r.map(n=>l`<option value=${n}>${n}</option>`)}
|
|
4210
|
-
</select>`}static renderRadio(e,t,i){var
|
|
4210
|
+
</select>`}static renderRadio(e,t,i){var a;const r=this._isInputDisabled(i),n=i.mode==="print";return n?l`<div class="print-response-value radio-response">
|
|
4211
4211
|
${t||l`<span class="print-no-response">No selection made</span>`}
|
|
4212
4212
|
</div>`:l`<div class="radio-group ${n?"print-mode":""}">
|
|
4213
|
-
${(
|
|
4213
|
+
${(a=e.options)==null?void 0:a.map(o=>l`
|
|
4214
4214
|
<label class="radio-option">
|
|
4215
4215
|
<input
|
|
4216
4216
|
type="radio"
|
|
4217
4217
|
name=${e.id}
|
|
4218
|
-
value=${
|
|
4219
|
-
.checked=${t===
|
|
4218
|
+
value=${o}
|
|
4219
|
+
.checked=${t===o}
|
|
4220
4220
|
?disabled=${r}
|
|
4221
4221
|
@change=${n?null:d=>i.handlers.handleInputChange(e.id,d)}
|
|
4222
4222
|
/>
|
|
4223
|
-
<span class="radio-label">${
|
|
4223
|
+
<span class="radio-label">${o}</span>
|
|
4224
4224
|
</label>
|
|
4225
4225
|
`)}
|
|
4226
|
-
</div>`}static renderCheckbox(e,t,i){var
|
|
4227
|
-
${
|
|
4226
|
+
</div>`}static renderCheckbox(e,t,i){var a;const r=this._isInputDisabled(i),n=i.mode==="print";if(e.options&&e.options.length>0){if(n){const o=Array.isArray(t)?t:[];return l`<div class="print-response-value checkbox-response">
|
|
4227
|
+
${o.length>0?o.map(d=>l`<div>• ${d}</div>`):l`<span class="print-no-response">No selections made</span>`}
|
|
4228
4228
|
</div>`}return l`<div class="checkbox-group ${n?"print-mode":""}">
|
|
4229
|
-
${(
|
|
4229
|
+
${(a=e.options)==null?void 0:a.map(o=>l`
|
|
4230
4230
|
<label class="checkbox-option">
|
|
4231
4231
|
<input
|
|
4232
4232
|
type="checkbox"
|
|
4233
4233
|
name=${e.id}
|
|
4234
|
-
value=${
|
|
4235
|
-
.checked=${Array.isArray(t)?t.includes(
|
|
4234
|
+
value=${o}
|
|
4235
|
+
.checked=${Array.isArray(t)?t.includes(o):!1}
|
|
4236
4236
|
?disabled=${r}
|
|
4237
|
-
@change=${n?null:d=>i.handlers.handleCheckboxGroupChange(e.id,
|
|
4237
|
+
@change=${n?null:d=>i.handlers.handleCheckboxGroupChange(e.id,o,d)}
|
|
4238
4238
|
/>
|
|
4239
|
-
<span class="checkbox-label">${
|
|
4239
|
+
<span class="checkbox-label">${o}</span>
|
|
4240
4240
|
</label>
|
|
4241
4241
|
`)}
|
|
4242
4242
|
</div>`}else return n?l`<div class="print-response-value checkbox-response">
|
|
@@ -4247,10 +4247,10 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4247
4247
|
id=${e.id}
|
|
4248
4248
|
.checked=${!!t}
|
|
4249
4249
|
?disabled=${r}
|
|
4250
|
-
@change=${n?null:
|
|
4250
|
+
@change=${n?null:o=>i.handlers.handleCheckboxChange(e.id,o)}
|
|
4251
4251
|
/>
|
|
4252
4252
|
<span class="checkbox-label">${e.label}</span>
|
|
4253
|
-
</label>`}static renderSignature(e,t,i){const r=i.formData[e.id],n=!!i.formData[e.id],
|
|
4253
|
+
</label>`}static renderSignature(e,t,i){const r=i.formData[e.id],n=!!i.formData[e.id],a=i.savedSignatures.has(e.id),o=i.replacingSignatures.has(e.id);if(i.mode==="print")return r&&typeof r=="string"?l`
|
|
4254
4254
|
<div class="print-response-value signature-response">
|
|
4255
4255
|
<img
|
|
4256
4256
|
src="${r}"
|
|
@@ -4280,7 +4280,23 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4280
4280
|
<div class="signature-view-only">
|
|
4281
4281
|
<span class="no-signature">No signature captured</span>
|
|
4282
4282
|
</div>
|
|
4283
|
-
`;if(i.mode==="
|
|
4283
|
+
`;if(i.mode==="default"&&!i.handlers.isCurrentStepAssigned())return r&&typeof r=="string"?l`
|
|
4284
|
+
<div class="signature-view-only">
|
|
4285
|
+
<img
|
|
4286
|
+
src="${r}"
|
|
4287
|
+
alt="Digital Signature"
|
|
4288
|
+
class="signature-image"
|
|
4289
|
+
@error=${d=>{var u;const p=d.target;p.style.display="none";const c=(u=p.parentElement)==null?void 0:u.querySelector(".signature-fallback");c&&c.classList.remove("hidden")}}
|
|
4290
|
+
/>
|
|
4291
|
+
<div class="signature-fallback hidden">
|
|
4292
|
+
<span class="signature-error">Unable to display signature</span>
|
|
4293
|
+
</div>
|
|
4294
|
+
</div>
|
|
4295
|
+
`:l`
|
|
4296
|
+
<div class="signature-view-only">
|
|
4297
|
+
<span class="no-signature">No signature captured</span>
|
|
4298
|
+
</div>
|
|
4299
|
+
`;if(i.mode==="admin"&&r&&typeof r=="string"&&!o){const d=r.trim().startsWith("<svg");return l`
|
|
4284
4300
|
<div class="signature-admin-display">
|
|
4285
4301
|
<div class="signature-existing">
|
|
4286
4302
|
${d?l` <div class="signature-svg-container" .innerHTML=${r}></div> `:l`
|
|
@@ -4317,7 +4333,7 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4317
4333
|
>
|
|
4318
4334
|
Clear
|
|
4319
4335
|
</button>
|
|
4320
|
-
${n&&!
|
|
4336
|
+
${n&&!a?l`
|
|
4321
4337
|
<button
|
|
4322
4338
|
type="button"
|
|
4323
4339
|
class="signature-save-btn"
|
|
@@ -4327,8 +4343,8 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4327
4343
|
Save
|
|
4328
4344
|
</button>
|
|
4329
4345
|
`:""}
|
|
4330
|
-
${
|
|
4331
|
-
${i.mode==="admin"&&
|
|
4346
|
+
${a?l` <span class="signature-saved">✓ Saved</span> `:""}
|
|
4347
|
+
${i.mode==="admin"&&o?l`
|
|
4332
4348
|
<button
|
|
4333
4349
|
type="button"
|
|
4334
4350
|
class="signature-cancel-btn"
|
|
@@ -4339,17 +4355,17 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4339
4355
|
`:""}
|
|
4340
4356
|
</div>
|
|
4341
4357
|
</div>
|
|
4342
|
-
`}static renderFileUpload(e,t,i){const r=i.formData[e.id];if(i.mode==="view-only"||i.mode==="print")if(r){const n=typeof r=="string",
|
|
4358
|
+
`}static renderFileUpload(e,t,i){const r=i.formData[e.id];if(i.mode==="view-only"||i.mode==="print")if(r){const n=typeof r=="string",a=typeof r=="object"&&r.name;if(i.mode==="print"){if(a)return l`
|
|
4343
4359
|
<div class="print-response-value file-response">
|
|
4344
4360
|
📎 ${r.name}
|
|
4345
4361
|
${r.size?l` <span class="file-size"
|
|
4346
4362
|
>(${D._formatFileSize(r.size)})</span
|
|
4347
4363
|
>`:""}
|
|
4348
4364
|
</div>
|
|
4349
|
-
`;if(n){const
|
|
4365
|
+
`;if(n){const o=D._extractFilenameFromUrl(r);return l` <div class="print-response-value file-response">📎 ${o}</div> `}else return l` <div class="print-response-value file-response">📎 ${r}</div> `}else{const o=n?r:"#",d=a?r.name:n?D._extractFilenameFromUrl(r):"View File";return l`
|
|
4350
4366
|
<div class="file-upload-view-only">
|
|
4351
|
-
<a href="${
|
|
4352
|
-
${
|
|
4367
|
+
<a href="${o}" target="_blank" class="file-link"> 📎 ${d} </a>
|
|
4368
|
+
${a&&r.size?l`
|
|
4353
4369
|
<span class="file-size-info"
|
|
4354
4370
|
>(${D._formatFileSize(r.size)})</span
|
|
4355
4371
|
>
|
|
@@ -4396,15 +4412,15 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4396
4412
|
?disabled=${this._isInputDisabled(i)}
|
|
4397
4413
|
placeholder=${e.placeholder?e.placeholder:"Your response"} // custom placeholder when not blank
|
|
4398
4414
|
@input=${n=>i.handlers.handleInputChange(e.id,n)}
|
|
4399
|
-
/>`}static render(e,t){const i=t.formData[e.id]??"",r=t.validationErrors[e.id],n=()=>{switch(e.type){case"textarea":return D.renderTextArea(e,i,t);case"select":return D.renderSelect(e,i,t);case"radio":return D.renderRadio(e,i,t);case"checkbox":return D.renderCheckbox(e,i,t);case"signature":return D.renderSignature(e,i,t);case"file_upload":return D.renderFileUpload(e,i,t);default:return D.renderDefaultInput(e,i,t)}},
|
|
4415
|
+
/>`}static render(e,t){const i=t.formData[e.id]??"",r=t.validationErrors[e.id],n=()=>{switch(e.type){case"textarea":return D.renderTextArea(e,i,t);case"select":return D.renderSelect(e,i,t);case"radio":return D.renderRadio(e,i,t);case"checkbox":return D.renderCheckbox(e,i,t);case"signature":return D.renderSignature(e,i,t);case"file_upload":return D.renderFileUpload(e,i,t);default:return D.renderDefaultInput(e,i,t)}},a=e.type==="checkbox"&&(!e.options||e.options.length===0);return t.mode==="print"?l`
|
|
4400
4416
|
<div class="question-print">
|
|
4401
|
-
${
|
|
4417
|
+
${a?"":l` <div class="print-question-title">${e.label}:</div> `}
|
|
4402
4418
|
${n()}
|
|
4403
4419
|
<hr class="print-question-separator" />
|
|
4404
4420
|
</div>
|
|
4405
4421
|
`:l`
|
|
4406
4422
|
<div class="question ${r?"error":""}">
|
|
4407
|
-
${
|
|
4423
|
+
${a?"":l`
|
|
4408
4424
|
<div class="runner-question-title">
|
|
4409
4425
|
${e.label}${e.required?l`<span class="runner-question-required">*</span>`:""}
|
|
4410
4426
|
</div>
|
|
@@ -4474,14 +4490,14 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4474
4490
|
<div class="runner-mobile-steps">
|
|
4475
4491
|
<nav aria-label="Workflow steps">
|
|
4476
4492
|
<div class="runner-mobile-steps-container">
|
|
4477
|
-
${t==null?void 0:t.map(r=>{const n=e.isStepAssignedToUser(r),
|
|
4493
|
+
${t==null?void 0:t.map(r=>{const n=e.isStepAssignedToUser(r),a=e.completedSteps.has(r.id);return l`
|
|
4478
4494
|
<div
|
|
4479
|
-
class="runner-mobile-step-tab ${
|
|
4495
|
+
class="runner-mobile-step-tab ${a?"completed":""} ${n?"":"unassigned"} ${i?"disabled":""}"
|
|
4480
4496
|
style="cursor: not-allowed; opacity: ${i?"0.6":n?"1":"0.6"};"
|
|
4481
4497
|
>
|
|
4482
4498
|
<span class="runner-mobile-step-title">${r.title}</span>
|
|
4483
4499
|
<span class="runner-mobile-step-badge">
|
|
4484
|
-
${
|
|
4500
|
+
${a?"Completed":n?"Your Step":"Other User"}
|
|
4485
4501
|
</span>
|
|
4486
4502
|
</div>
|
|
4487
4503
|
`})}
|
|
@@ -4511,7 +4527,7 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4511
4527
|
</p>
|
|
4512
4528
|
</div>
|
|
4513
4529
|
</div>
|
|
4514
|
-
`}static renderSubmissionErrorView(e){var r,n,
|
|
4530
|
+
`}static renderSubmissionErrorView(e){var r,n,a;const{submissionError:t,onRetry:i}=e;return l`
|
|
4515
4531
|
<div class="runner-layout">
|
|
4516
4532
|
<!-- Mobile Steps Navigation (visible only on mobile) -->
|
|
4517
4533
|
${this.renderMobileStepsForStatus({steps:(r=e.instance)==null?void 0:r.steps,isStepAssignedToUser:e.isStepAssignedToUser,completedSteps:e.completedSteps,disabled:!0})}
|
|
@@ -4521,12 +4537,12 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4521
4537
|
<div class="runner-sidebar-header">Steps</div>
|
|
4522
4538
|
<nav aria-label="Workflow steps">
|
|
4523
4539
|
<ul class="runner-steps-list">
|
|
4524
|
-
${(
|
|
4540
|
+
${(a=(n=e.instance)==null?void 0:n.steps)==null?void 0:a.map(o=>{const d=e.isStepAssignedToUser(o),p=e.completedSteps.has(o.id);return l`
|
|
4525
4541
|
<li
|
|
4526
4542
|
class="runner-step-item ${p?"completed":""} ${d?"":"unassigned"}"
|
|
4527
4543
|
style="opacity: ${d?"1":"0.6"}; cursor: not-allowed;"
|
|
4528
4544
|
>
|
|
4529
|
-
<span class="runner-step-title">${
|
|
4545
|
+
<span class="runner-step-title">${o.title}</span>
|
|
4530
4546
|
<span class="runner-step-badge ${!p&&d?"error":""}">
|
|
4531
4547
|
${p?"Submitted":d?"Failed":"Other User"}
|
|
4532
4548
|
</span>
|
|
@@ -4573,14 +4589,14 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4573
4589
|
<div class="runner-sidebar-header">Steps</div>
|
|
4574
4590
|
<nav aria-label="Workflow steps">
|
|
4575
4591
|
<ul class="runner-steps-list">
|
|
4576
|
-
${(r=(i=e.instance)==null?void 0:i.steps)==null?void 0:r.map(n=>{const
|
|
4592
|
+
${(r=(i=e.instance)==null?void 0:i.steps)==null?void 0:r.map(n=>{const a=e.isStepAssignedToUser(n),o=e.completedSteps.has(n.id);return l`
|
|
4577
4593
|
<li
|
|
4578
|
-
class="runner-step-item ${
|
|
4579
|
-
style="opacity: ${
|
|
4594
|
+
class="runner-step-item ${o?"completed":""} ${a?"":"unassigned"}"
|
|
4595
|
+
style="opacity: ${a?"1":"0.6"}; cursor: not-allowed;"
|
|
4580
4596
|
>
|
|
4581
4597
|
<span class="runner-step-title">${n.title}</span>
|
|
4582
4598
|
<span class="runner-step-badge">
|
|
4583
|
-
${
|
|
4599
|
+
${o?"Submitted":a?"Your Step":"Other User"}
|
|
4584
4600
|
</span>
|
|
4585
4601
|
</li>
|
|
4586
4602
|
`})}
|
|
@@ -4617,15 +4633,15 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4617
4633
|
<div class="runner-sidebar-header">Steps</div>
|
|
4618
4634
|
<nav aria-label="Workflow steps">
|
|
4619
4635
|
<ul class="runner-steps-list">
|
|
4620
|
-
${t==null?void 0:t.map((i,r)=>{const n=e.mode==="preview"||e.mode==="admin"||e.mode==="view-only"||e.mode==="print"||e.isStepAssignedToUser(i),
|
|
4636
|
+
${t==null?void 0:t.map((i,r)=>{const n=e.mode==="preview"||e.mode==="admin"||e.mode==="view-only"||e.mode==="print"||e.isStepAssignedToUser(i),a=r===e.currentStepIndex,o=this.isStepCompleted(i,e,n),d=(e.isSubmitted||e.userStepsSubmitted)&&e.mode!=="preview"&&e.mode!=="admin"&&e.mode!=="view-only"&&e.mode!=="print",p=e.isLoading;return l`
|
|
4621
4637
|
<li
|
|
4622
|
-
class="runner-step-item ${
|
|
4638
|
+
class="runner-step-item ${a?"active":""} ${o?"completed":""} ${n?"":"unassigned"} ${d?"disabled":""} ${p?"loading-disabled":""}"
|
|
4623
4639
|
@click=${()=>!p&&e.goToStep(r)}
|
|
4624
4640
|
style="${d?"opacity: 0.5; cursor: not-allowed;":""}"
|
|
4625
4641
|
>
|
|
4626
4642
|
<span class="runner-step-title">${i.title}</span>
|
|
4627
4643
|
<span class="runner-step-badge">
|
|
4628
|
-
${e.mode==="preview"?"Preview":e.mode==="admin"?"Admin":e.mode==="view-only"?"View Only":e.mode==="print"?"Print":d?"Submitted":
|
|
4644
|
+
${e.mode==="preview"?"Preview":e.mode==="admin"?"Admin":e.mode==="view-only"?"View Only":e.mode==="print"?"Print":d?"Submitted":o?"Completed":n?"Assigned":"Not Assigned"}
|
|
4629
4645
|
</span>
|
|
4630
4646
|
</li>
|
|
4631
4647
|
`})}
|
|
@@ -4636,16 +4652,16 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4636
4652
|
<div class="runner-mobile-steps">
|
|
4637
4653
|
<nav aria-label="Workflow steps">
|
|
4638
4654
|
<div class="runner-mobile-steps-container">
|
|
4639
|
-
${t==null?void 0:t.map((i,r)=>{const n=e.mode==="preview"||e.mode==="admin"||e.mode==="view-only"||e.mode==="print"||e.isStepAssignedToUser(i),
|
|
4655
|
+
${t==null?void 0:t.map((i,r)=>{const n=e.mode==="preview"||e.mode==="admin"||e.mode==="view-only"||e.mode==="print"||e.isStepAssignedToUser(i),a=r===e.currentStepIndex,o=this.isStepCompleted(i,e,n),d=(e.isSubmitted||e.userStepsSubmitted)&&e.mode!=="preview"&&e.mode!=="admin"&&e.mode!=="view-only"&&e.mode!=="print",p=e.isLoading;return l`
|
|
4640
4656
|
<button
|
|
4641
|
-
class="runner-mobile-step-tab ${
|
|
4657
|
+
class="runner-mobile-step-tab ${a?"active":""} ${o?"completed":""} ${n?"":"unassigned"} ${d?"disabled":""} ${p?"loading-disabled":""}"
|
|
4642
4658
|
@click=${()=>!p&&e.goToStep(r)}
|
|
4643
4659
|
?disabled=${d||p}
|
|
4644
|
-
aria-current=${
|
|
4660
|
+
aria-current=${a?"step":"false"}
|
|
4645
4661
|
>
|
|
4646
4662
|
<span class="runner-mobile-step-title">${i.title}</span>
|
|
4647
4663
|
<span class="runner-mobile-step-badge">
|
|
4648
|
-
${e.mode==="preview"?"Preview":e.mode==="admin"?"Admin":e.mode==="view-only"?"View Only":e.mode==="print"?"Print":d?"Submitted":
|
|
4664
|
+
${e.mode==="preview"?"Preview":e.mode==="admin"?"Admin":e.mode==="view-only"?"View Only":e.mode==="print"?"Print":d?"Submitted":o?"Completed":n?"Assigned":"Not Assigned"}
|
|
4649
4665
|
</span>
|
|
4650
4666
|
</button>
|
|
4651
4667
|
`})}
|
|
@@ -4674,7 +4690,7 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4674
4690
|
${e.mode==="admin"?e.justSaved?"✓ Saved!":"Save":e.isLastStep?"Submit":"Next"}
|
|
4675
4691
|
</button>
|
|
4676
4692
|
</div>
|
|
4677
|
-
`}}class xe{static handleInputChange(e,t,i,r,n,o){const a=t.target;let d;a.type==="radio"?d=a.value:a.type==="checkbox"?d=a.checked:d=a.value;const p={...i,[e]:d};r(p),o!=="preview"&&n(e,d)}static handleCheckboxChange(e,t,i,r,n,o){const d=t.target.checked,p={...i,[e]:d};r(p),o!=="preview"&&n(e,d)}static handleCheckboxGroupChange(e,t,i,r,n,o,a){const d=i.target,p=r[e];let c=Array.isArray(p)?[...p]:[];d.checked?c.includes(t)||c.push(t):c=c.filter(h=>h!==t);const u={...r,[e]:c};n(u),a!=="preview"&&o(e,c)}}var Ct=Object.defineProperty,At=Object.getOwnPropertyDescriptor,_=(s,e,t,i)=>{for(var r=i>1?void 0:i?At(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(i?o(e,t,r):o(r))||r);return i&&r&&Ct(e,t,r),r};let f=class extends j{constructor(){super(...arguments),this.mode="default",this.isLoading=!1,this._currentStepIndex=0,this._formData={},this._validationErrors={},this._internalCompletedSteps=new Set,this._formRestorationComplete=!1,this._savedSignatures=new Set,this._replacingSignatures=new Set,this._isSubmitted=!1,this._userStepsSubmitted=!1,this._justSaved=!1,this._submissionError=null}willUpdate(s){(s.has("mode")||s.has("currentUser"))&&this._updateNavigationService(),(s.has("instance")||s.has("workflow")||s.has("mode"))&&(this._initializeState(),this._updateValidationService())}connectedCallback(){super.connectedCallback(),this._initializeServices(),this._initializeState(),window.addEventListener("resize",this._handleResize.bind(this)),this._restoreFormData()}disconnectedCallback(){var s;super.disconnectedCallback(),window.removeEventListener("resize",this._handleResize.bind(this)),(s=this.signatureManager)==null||s.destroy()}_initializeServices(){this.persistenceManager=new bt,this.responseTracker=new yt,this.formStateManager=new me,this.signatureManager=new _t(s=>this._handleSignatureChange(s)),this.fileUploadManager=new fe(this.formStateManager,this.responseTracker),this._updateNavigationService(),this._updateValidationService()}_updateNavigationService(){this.navigationService=new wt(this.mode||"default",this.currentUser)}_updateValidationService(){var s;this.validationService=new ft(((s=this.signatureManager)==null?void 0:s.getAllSignaturePads())||new Map,this._savedSignatures)}_getRenderContext(){return{formData:this._formData,validationErrors:this._validationErrors,currentStepIndex:this._currentStepIndex,internalCompletedSteps:this._internalCompletedSteps,savedSignatures:this._savedSignatures,replacingSignatures:this._replacingSignatures,isSubmitted:this._isSubmitted,userStepsSubmitted:this._userStepsSubmitted,justSaved:this._justSaved,validationService:this.validationService,persistenceManager:this.persistenceManager,signatureManager:this.signatureManager,responseTracker:this.responseTracker,navigationService:this.navigationService,formStateManager:this.formStateManager,fileUploadManager:this.fileUploadManager,mode:this.mode||"default",instance:this.instance,workflow:this.workflow,currentUser:this.currentUser,isLoading:this.isLoading,handlers:{handleInputChange:this._handleInputChange.bind(this),handleCheckboxChange:this._handleCheckboxChange.bind(this),handleCheckboxGroupChange:this._handleCheckboxGroupChange.bind(this),startReplaceSignature:this._startReplaceSignature.bind(this),cancelReplaceSignature:this._cancelReplaceSignature.bind(this),clearSignature:this._clearSignature.bind(this),saveSignature:this._saveSignature.bind(this),handleFileUpload:this._handleFileUpload.bind(this),trackQuestionResponse:this._trackQuestionResponse.bind(this),isCurrentStepAssigned:this._isCurrentStepAssigned.bind(this)}}}_handleSignatureChange(s){this.formStateManager.setFormField(s.questionId,s.hasSignature),this.formStateManager.setFormField(`${s.questionId}_signatureData`,s.signatureData),this._formData=this.formStateManager.getFormData(),this._savedSignatures.has(s.questionId)&&(this._savedSignatures=new Set([...this._savedSignatures].filter(e=>e!==s.questionId))),this._clearValidationError(s.questionId),this.mode!=="admin"&&this._saveFormDataToHistory()}_clearValidationError(s){this.formStateManager.clearValidationError(s),this._validationErrors=this.formStateManager.getValidationErrors()}_updateFormData(s){this.formStateManager.updateFormData(s),this._formData=this.formStateManager.getFormData(),this.mode!=="admin"&&this._saveFormDataToHistory()}_handleFormDataUpdate(s){this._clearValidationError(s)}_initializeState(){var s,e,t;if((s=this.formStateManager)==null||s.reset(),this._validationErrors={},this._formData={},this._formRestorationComplete=!1,this._savedSignatures=new Set,this._replacingSignatures=new Set,this._savedInstance=void 0,this._justSaved=!1,this._isSubmitted=((e=this.instance)==null?void 0:e.status)==="completed"||!1,this.instance&&this.instance.status!=="completed"){const i=this._getAssignedSteps(),r=i.filter(n=>{var o;return(o=this.instance.completedSteps)==null?void 0:o.includes(n.id)});this._userStepsSubmitted=i.length>0&&r.length===i.length}else this._userStepsSubmitted=((t=this.instance)==null?void 0:t.status)==="completed"||!1;this.mode==="preview"&&this.workflow?this._initializePreviewMode():this.mode==="view-only"&&this.instance?this._initializeViewOnlyMode():this.mode==="print"&&this.instance?this._initializePrintMode():this.instance&&this._initializeDefaultMode()}_initializePreviewMode(){var s;if(console.log("Initializing preview mode..."),!((s=this.workflow)!=null&&s.steps)||this.workflow.steps.length===0){console.warn("Workflow has no steps in preview mode.");return}this.formStateManager.reset(),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=0,this._internalCompletedSteps=new Set,console.log("Preview mode initialized with empty form data.")}_initializeDefaultMode(){var s;!((s=this.instance)!=null&&s.steps)||this.instance.steps.length===0||(this.instance.completedSteps?this._internalCompletedSteps=new Set(this.instance.completedSteps):this._internalCompletedSteps=new Set(this.instance.steps.filter(e=>e.status==="completed").map(e=>e.id)),this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=this.instance.steps.findIndex(e=>{var t;return e.id===((t=this.instance)==null?void 0:t.currentStepId)}),this._currentStepIndex<0&&(this._currentStepIndex=0),this.instance.steps.forEach((e,t)=>{this._internalCompletedSteps.has(e.id)?e.status="completed":t===this._currentStepIndex?e.status="active":e.status="pending"}))}_initializeViewOnlyMode(){var s;!((s=this.instance)!=null&&s.steps)||this.instance.steps.length===0||(this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=0,this.instance.steps.forEach(e=>{e.responses&&e.responses.length>0?(e.status="completed",this._internalCompletedSteps.add(e.id)):e.status="pending"}),console.log("View-only mode initialized with existing responses:",this._formData))}_initializePrintMode(){var s;!((s=this.instance)!=null&&s.steps)||this.instance.steps.length===0||(this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=0,this.instance.steps.forEach(e=>{e.responses&&e.responses.length>0?(e.status="completed",this._internalCompletedSteps.add(e.id)):e.status="pending"}),console.log("Print mode initialized with existing responses:",this._formData))}_isStepAssignedToUser(s){return this.navigationService.isStepAssignedToUser(s)}_getAssignedSteps(){return this.instance?this.navigationService.getAssignedSteps(this.instance):[]}_isCurrentStepAssigned(){const s=this._currentStep;return!s||this.mode!=="default"?!0:this._isStepAssignedToUser(s)}_renderNotAssignedView(){return ve.renderNotAssignedView()}get _currentStep(){var s,e,t;return this.mode==="preview"&&this.workflow?(s=this.workflow.steps)==null?void 0:s[this._currentStepIndex]:(t=(e=this.instance)==null?void 0:e.steps)==null?void 0:t[this._currentStepIndex]}_validateStep(){const s=this._currentStep;if(!s)return!1;const e=this.validationService.validateStep(s,this._formData,this.mode||"default");return this.formStateManager.setValidationErrors(e.errors),this._validationErrors=this.formStateManager.getValidationErrors(),e.isValid}_handleInputChange(s,e){xe.handleInputChange(s,e,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(s)}_handleCheckboxChange(s,e){xe.handleCheckboxChange(s,e,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(s)}_handleCheckboxGroupChange(s,e,t){xe.handleCheckboxGroupChange(s,e,t,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(s)}_initializeSignaturePad(s){this.signatureManager.initializeSignaturePad(s,this.shadowRoot)&&this._updateValidationService()}_handleResize(){this.signatureManager.handleResize()}_clearSignature(s){this.signatureManager.clearSignature(s)}_startReplaceSignature(s){this._replacingSignatures=new Set([...this._replacingSignatures,s]),this.formStateManager.setFormField(s,!1),this.formStateManager.setFormField(`${s}_signatureData`,null),this._formData=this.formStateManager.getFormData(),this._savedSignatures=new Set([...this._savedSignatures].filter(e=>e!==s)),this.requestUpdate()}_cancelReplaceSignature(s){this._replacingSignatures=new Set([...this._replacingSignatures].filter(e=>e!==s))}_saveSignature(s){var i,r,n;const e=this.signatureManager.saveSignature(s);if(!e)return;const t=this._hasSignatureChanged(s,e.svgData);this._savedSignatures=new Set([...this._savedSignatures,s]),this._replacingSignatures.has(s)&&(this._replacingSignatures=new Set([...this._replacingSignatures].filter(o=>o!==s))),this._trackQuestionResponse(s,e.svgData),t&&this.mode!=="preview"?(console.log("Signature changed, calling callback for:",s),console.log("Callback function exists:",!!this.onSignatureCaptured),(n=this.onSignatureCaptured)==null||n.call(this,{instanceId:(i=this.instance)==null?void 0:i.id,stepId:(r=this._currentStep)==null?void 0:r.id,questionId:s,svgData:e.svgData,dataURL:e.dataURL})):this.mode==="preview"?console.log("Preview mode: skipping signature callback for:",s):console.log("Signature unchanged, skipping callback for:",s),this._clearValidationError(s),this.mode!=="admin"&&this._saveFormDataToHistory()}_hasSignatureChanged(s,e){return this.responseTracker.hasChangedFromPrevious(s,e,this._savedInstance)}_restoreInstanceResponses(){var s,e;!((s=this._savedInstance)!=null&&s.steps)||!((e=this.instance)!=null&&e.steps)||this._savedInstance.steps.forEach((t,i)=>{var r;(r=this.instance)!=null&&r.steps&&this.instance.steps[i]&&(this.instance.steps[i].responses=t.responses||[])})}_handleFileUpload(s,e){this.fileUploadManager.handleFileUpload(s,e,{instance:this.instance,currentStep:this._currentStep,mode:this.mode||"default",savedInstance:this._savedInstance,onFileUploaded:this.onFileUploaded,onFormDataSave:()=>this._saveFormDataToHistory(),onRequestUpdate:()=>{this._formData=this.formStateManager.getFormData(),this._validationErrors=this.formStateManager.getValidationErrors();const t=this._formData[s];t&&this._trackQuestionResponse(s,t),this.requestUpdate()}})}_captureSignaturesFromStep(s){console.log("Capturing signatures from step:",s.id)}_trackQuestionResponse(s,e){this.responseTracker.trackQuestionResponse(this._currentStep,s,e)}_renderQuestion(s){return D.render(s,this._getRenderContext())}_renderContentElement(s){return C.render(s,this._getRenderContext())}_isQuestionElement(s){return f.QUESTION_ELEMENT_TYPES.includes(s.type)}_isContentElement(s){return f.CONTENT_ELEMENT_TYPES.includes(s.type)}_renderStepElement(s){return this.mode==="print"?this._isQuestionElement(s)?this._renderQuestion(s):this._isContentElement(s)?this._renderContentElement(s):l`<div class="unknown-element">
|
|
4693
|
+
`}}class xe{static handleInputChange(e,t,i,r,n,a){const o=t.target;let d;o.type==="radio"?d=o.value:o.type==="checkbox"?d=o.checked:d=o.value;const p={...i,[e]:d};r(p),a!=="preview"&&n(e,d)}static handleCheckboxChange(e,t,i,r,n,a){const d=t.target.checked,p={...i,[e]:d};r(p),a!=="preview"&&n(e,d)}static handleCheckboxGroupChange(e,t,i,r,n,a,o){const d=i.target,p=r[e];let c=Array.isArray(p)?[...p]:[];d.checked?c.includes(t)||c.push(t):c=c.filter(h=>h!==t);const u={...r,[e]:c};n(u),o!=="preview"&&a(e,c)}}var Ct=Object.defineProperty,At=Object.getOwnPropertyDescriptor,_=(s,e,t,i)=>{for(var r=i>1?void 0:i?At(e,t):e,n=s.length-1,a;n>=0;n--)(a=s[n])&&(r=(i?a(e,t,r):a(r))||r);return i&&r&&Ct(e,t,r),r};let f=class extends j{constructor(){super(...arguments),this.mode="default",this.isLoading=!1,this._currentStepIndex=0,this._formData={},this._validationErrors={},this._internalCompletedSteps=new Set,this._formRestorationComplete=!1,this._savedSignatures=new Set,this._replacingSignatures=new Set,this._isSubmitted=!1,this._userStepsSubmitted=!1,this._justSaved=!1,this._submissionError=null}willUpdate(s){(s.has("mode")||s.has("currentUser"))&&this._updateNavigationService(),(s.has("instance")||s.has("workflow")||s.has("mode"))&&(this._initializeState(),this._updateValidationService())}connectedCallback(){super.connectedCallback(),this._initializeServices(),this._initializeState(),window.addEventListener("resize",this._handleResize.bind(this)),this._restoreFormData()}disconnectedCallback(){var s;super.disconnectedCallback(),window.removeEventListener("resize",this._handleResize.bind(this)),(s=this.signatureManager)==null||s.destroy()}_initializeServices(){this.persistenceManager=new bt,this.responseTracker=new yt,this.formStateManager=new me,this.signatureManager=new _t(s=>this._handleSignatureChange(s)),this.fileUploadManager=new fe(this.formStateManager,this.responseTracker),this._updateNavigationService(),this._updateValidationService()}_updateNavigationService(){this.navigationService=new wt(this.mode||"default",this.currentUser)}_updateValidationService(){var s;this.validationService=new ft(((s=this.signatureManager)==null?void 0:s.getAllSignaturePads())||new Map,this._savedSignatures)}_getRenderContext(){return{formData:this._formData,validationErrors:this._validationErrors,currentStepIndex:this._currentStepIndex,internalCompletedSteps:this._internalCompletedSteps,savedSignatures:this._savedSignatures,replacingSignatures:this._replacingSignatures,isSubmitted:this._isSubmitted,userStepsSubmitted:this._userStepsSubmitted,justSaved:this._justSaved,validationService:this.validationService,persistenceManager:this.persistenceManager,signatureManager:this.signatureManager,responseTracker:this.responseTracker,navigationService:this.navigationService,formStateManager:this.formStateManager,fileUploadManager:this.fileUploadManager,mode:this.mode||"default",instance:this.instance,workflow:this.workflow,currentUser:this.currentUser,isLoading:this.isLoading,handlers:{handleInputChange:this._handleInputChange.bind(this),handleCheckboxChange:this._handleCheckboxChange.bind(this),handleCheckboxGroupChange:this._handleCheckboxGroupChange.bind(this),startReplaceSignature:this._startReplaceSignature.bind(this),cancelReplaceSignature:this._cancelReplaceSignature.bind(this),clearSignature:this._clearSignature.bind(this),saveSignature:this._saveSignature.bind(this),handleFileUpload:this._handleFileUpload.bind(this),trackQuestionResponse:this._trackQuestionResponse.bind(this),isCurrentStepAssigned:this._isCurrentStepAssigned.bind(this)}}}_handleSignatureChange(s){this.formStateManager.setFormField(s.questionId,s.hasSignature),this.formStateManager.setFormField(`${s.questionId}_signatureData`,s.signatureData),this._formData=this.formStateManager.getFormData(),this._savedSignatures.has(s.questionId)&&(this._savedSignatures=new Set([...this._savedSignatures].filter(e=>e!==s.questionId))),this._clearValidationError(s.questionId),this.mode!=="admin"&&this._saveFormDataToHistory()}_clearValidationError(s){this.formStateManager.clearValidationError(s),this._validationErrors=this.formStateManager.getValidationErrors()}_updateFormData(s){this.formStateManager.updateFormData(s),this._formData=this.formStateManager.getFormData(),this.mode!=="admin"&&this._saveFormDataToHistory()}_handleFormDataUpdate(s){this._clearValidationError(s)}_initializeState(){var s,e,t;if((s=this.formStateManager)==null||s.reset(),this._validationErrors={},this._formData={},this._formRestorationComplete=!1,this._savedSignatures=new Set,this._replacingSignatures=new Set,this._savedInstance=void 0,this._justSaved=!1,this._isSubmitted=((e=this.instance)==null?void 0:e.status)==="completed"||!1,this.instance&&this.instance.status!=="completed"){const i=this._getAssignedSteps(),r=i.filter(n=>{var a;return(a=this.instance.completedSteps)==null?void 0:a.includes(n.id)});this._userStepsSubmitted=i.length>0&&r.length===i.length}else this._userStepsSubmitted=((t=this.instance)==null?void 0:t.status)==="completed"||!1;this.mode==="preview"&&this.workflow?this._initializePreviewMode():this.mode==="view-only"&&this.instance?this._initializeViewOnlyMode():this.mode==="print"&&this.instance?this._initializePrintMode():this.instance&&this._initializeDefaultMode()}_initializePreviewMode(){var s;if(console.log("Initializing preview mode..."),!((s=this.workflow)!=null&&s.steps)||this.workflow.steps.length===0){console.warn("Workflow has no steps in preview mode.");return}this.formStateManager.reset(),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=0,this._internalCompletedSteps=new Set,console.log("Preview mode initialized with empty form data.")}_initializeDefaultMode(){var s;!((s=this.instance)!=null&&s.steps)||this.instance.steps.length===0||(this.instance.completedSteps?this._internalCompletedSteps=new Set(this.instance.completedSteps):this._internalCompletedSteps=new Set(this.instance.steps.filter(e=>e.status==="completed").map(e=>e.id)),this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._markExistingSignaturesAsSaved(),this._currentStepIndex=this.instance.steps.findIndex(e=>{var t;return e.id===((t=this.instance)==null?void 0:t.currentStepId)}),this._currentStepIndex<0&&(this._currentStepIndex=0),this.instance.steps.forEach((e,t)=>{this._internalCompletedSteps.has(e.id)?e.status="completed":t===this._currentStepIndex?e.status="active":e.status="pending"}))}_initializeViewOnlyMode(){var s;!((s=this.instance)!=null&&s.steps)||this.instance.steps.length===0||(this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._markExistingSignaturesAsSaved(),this._currentStepIndex=0,this.instance.steps.forEach(e=>{e.responses&&e.responses.length>0?(e.status="completed",this._internalCompletedSteps.add(e.id)):e.status="pending"}),console.log("View-only mode initialized with existing responses:",this._formData))}_initializePrintMode(){var s;!((s=this.instance)!=null&&s.steps)||this.instance.steps.length===0||(this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._markExistingSignaturesAsSaved(),this._currentStepIndex=0,this.instance.steps.forEach(e=>{e.responses&&e.responses.length>0?(e.status="completed",this._internalCompletedSteps.add(e.id)):e.status="pending"}),console.log("Print mode initialized with existing responses:",this._formData))}_isStepAssignedToUser(s){return this.navigationService.isStepAssignedToUser(s)}_markExistingSignaturesAsSaved(){var s;(s=this.instance)!=null&&s.steps&&this.instance.steps.forEach(e=>{e.elements.forEach(t=>{if(t.type==="signature"){const i=t.id;this._formData[i]&&this._savedSignatures.add(i)}})})}_getAssignedSteps(){return this.instance?this.navigationService.getAssignedSteps(this.instance):[]}_isCurrentStepAssigned(){const s=this._currentStep;return!s||this.mode!=="default"?!0:this._isStepAssignedToUser(s)}_renderNotAssignedView(){return ve.renderNotAssignedView()}get _currentStep(){var s,e,t;return this.mode==="preview"&&this.workflow?(s=this.workflow.steps)==null?void 0:s[this._currentStepIndex]:(t=(e=this.instance)==null?void 0:e.steps)==null?void 0:t[this._currentStepIndex]}_validateStep(){const s=this._currentStep;if(!s)return!1;const e=this.validationService.validateStep(s,this._formData,this.mode||"default");return this.formStateManager.setValidationErrors(e.errors),this._validationErrors=this.formStateManager.getValidationErrors(),e.isValid}_handleInputChange(s,e){xe.handleInputChange(s,e,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(s)}_handleCheckboxChange(s,e){xe.handleCheckboxChange(s,e,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(s)}_handleCheckboxGroupChange(s,e,t){xe.handleCheckboxGroupChange(s,e,t,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(s)}_initializeSignaturePad(s){this.signatureManager.initializeSignaturePad(s,this.shadowRoot)&&this._updateValidationService()}_handleResize(){this.signatureManager.handleResize()}_clearSignature(s){this.signatureManager.clearSignature(s)}_startReplaceSignature(s){this._replacingSignatures=new Set([...this._replacingSignatures,s]),this.formStateManager.setFormField(s,!1),this.formStateManager.setFormField(`${s}_signatureData`,null),this._formData=this.formStateManager.getFormData(),this._savedSignatures=new Set([...this._savedSignatures].filter(e=>e!==s)),this.requestUpdate()}_cancelReplaceSignature(s){this._replacingSignatures=new Set([...this._replacingSignatures].filter(e=>e!==s))}_saveSignature(s){var i,r,n;const e=this.signatureManager.saveSignature(s);if(!e)return;const t=this._hasSignatureChanged(s,e.svgData);this._savedSignatures=new Set([...this._savedSignatures,s]),this._replacingSignatures.has(s)&&(this._replacingSignatures=new Set([...this._replacingSignatures].filter(a=>a!==s))),this._trackQuestionResponse(s,e.svgData),t&&this.mode!=="preview"?(console.log("Signature changed, calling callback for:",s),console.log("Callback function exists:",!!this.onSignatureCaptured),(n=this.onSignatureCaptured)==null||n.call(this,{instanceId:(i=this.instance)==null?void 0:i.id,stepId:(r=this._currentStep)==null?void 0:r.id,questionId:s,svgData:e.svgData,dataURL:e.dataURL})):this.mode==="preview"?console.log("Preview mode: skipping signature callback for:",s):console.log("Signature unchanged, skipping callback for:",s),this._clearValidationError(s),this.mode!=="admin"&&this._saveFormDataToHistory()}_hasSignatureChanged(s,e){return this.responseTracker.hasChangedFromPrevious(s,e,this._savedInstance)}_restoreInstanceResponses(){var s,e;!((s=this._savedInstance)!=null&&s.steps)||!((e=this.instance)!=null&&e.steps)||this._savedInstance.steps.forEach((t,i)=>{var r;(r=this.instance)!=null&&r.steps&&this.instance.steps[i]&&(this.instance.steps[i].responses=t.responses||[])})}_handleFileUpload(s,e){this.fileUploadManager.handleFileUpload(s,e,{instance:this.instance,currentStep:this._currentStep,mode:this.mode||"default",savedInstance:this._savedInstance,onFileUploaded:this.onFileUploaded,onFormDataSave:()=>this._saveFormDataToHistory(),onRequestUpdate:()=>{this._formData=this.formStateManager.getFormData(),this._validationErrors=this.formStateManager.getValidationErrors();const t=this._formData[s];t&&this._trackQuestionResponse(s,t),this.requestUpdate()}})}_captureSignaturesFromStep(s){console.log("Capturing signatures from step:",s.id)}_trackQuestionResponse(s,e){this.responseTracker.trackQuestionResponse(this._currentStep,s,e)}_renderQuestion(s){return D.render(s,this._getRenderContext())}_renderContentElement(s){return C.render(s,this._getRenderContext())}_isQuestionElement(s){return f.QUESTION_ELEMENT_TYPES.includes(s.type)}_isContentElement(s){return f.CONTENT_ELEMENT_TYPES.includes(s.type)}_renderStepElement(s){return this.mode==="print"?this._isQuestionElement(s)?this._renderQuestion(s):this._isContentElement(s)?this._renderContentElement(s):l`<div class="unknown-element">
|
|
4678
4694
|
<p>⚠️ Unknown element type: ${s.type}</p>
|
|
4679
4695
|
</div>`:this._isQuestionElement(s)?l`<div class="runner-card">${this._renderQuestion(s)}</div>`:this._isContentElement(s)?l`<div class="runner-card">${this._renderContentElement(s)}</div>`:l`<div class="runner-card">
|
|
4680
4696
|
<div class="unknown-element">
|
|
@@ -4698,7 +4714,7 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4698
4714
|
|
|
4699
4715
|
${this.instance.steps.map(e=>this._renderStepWithElements(e))}
|
|
4700
4716
|
</div>
|
|
4701
|
-
`}async _nextStep(){var t,i,r,n;if(!this._validateStep())return;const s=this._currentStep;s&&this._captureSignaturesFromStep(s);const e=this._findNextAssignedStep(this._currentStepIndex);if(e!==-1){const o=(t=this._currentStep)==null?void 0:t.id;if(this._currentStepIndex=e,(await this._updateInstanceData(o,"step_navigation",{direction:"next",fromStepIndex:this._currentStepIndex-1,toStepIndex:this._currentStepIndex,completedStepId:o})).success&&o&&(i=this.instance)!=null&&i.steps){const p=this.instance.steps.find(c=>c.id===o);p&&(p.status="completed")}const d=(n=(r=this.instance)==null?void 0:r.steps)==null?void 0:n[this._currentStepIndex];d&&(d.status="active"),this.mode!=="admin"&&this._saveFormDataToHistory(),this._scrollToTop()}}_findNextAssignedStep(s){return this.instance?this.navigationService.findNextAssignedStep(s,this.instance):-1}_isLastAssignedStep(){return this.navigationService.isLastAssignedStep(this._currentStepIndex,this.instance)}_isLastStepInWorkflow(){var e;const s=(e=this.instance)==null?void 0:e.steps;return s?this._currentStepIndex===s.length-1:!1}_goToStep(s){var i;console.log(`🎯 _goToStep called: stepIndex=${s}, mode=${this.mode}, currentStep=${this._currentStepIndex}`);const e=this.mode==="preview"?this.workflow:this.instance;if(console.log("📊 Data source:",e?`${((i=e.steps)==null?void 0:i.length)||0} steps`:"null"),!e){console.log("❌ No data source available");return}const t=this.navigationService.canNavigateToStep(s,this._currentStepIndex,e,this._internalCompletedSteps,this._isSubmitted,this._userStepsSubmitted);console.log("🚦 Navigation result:",t),t.canNavigate?(this._currentStepIndex=t.newStepIndex,console.log(`✅ Navigated to step ${t.newStepIndex}`),this._scrollToTop()):console.log("❌ Navigation blocked:",t.reason)}async _submitUserSteps(){var i;if(!this._validateStep())return;const s=this._currentStep;if(s&&this._captureSignaturesFromStep(s),!this.instance){console.error("Cannot submit, instance data is missing.");return}const e=(i=this._currentStep)==null?void 0:i.id;e&&this._internalCompletedSteps.add(e),(await this._updateInstanceData(e,"user_steps_submission")).success&&e&&this._internalCompletedSteps.add(e),this._userStepsSubmitted=!0,this._clearSavedFormData("user steps submission"),this._scrollToTop()}async _submit(){var i;if(!this._validateStep())return;const s=this._currentStep;if(s&&this._captureSignaturesFromStep(s),!this.instance){console.error("Cannot submit, instance data is missing.");return}const e=(i=this._currentStep)==null?void 0:i.id;console.log("Submitting entire workflow:",this.instance.id),console.log("Final form data:",this._formData),(await this._updateInstanceData(e,"submission")).success&&(e&&this._internalCompletedSteps.add(e),this.instance&&(this.instance.status="completed",this.instance.currentStepId=void 0,this.instance.completedSteps=Array.from(this._internalCompletedSteps)),this._isSubmitted=!0,this._clearSavedFormData("full workflow submission"),this._scrollToTop())}async _saveStep(){var i;if(!this._validateStep())return;const s=this._currentStep;if(s&&this._captureSignaturesFromStep(s),!this.instance){console.error("Cannot save, instance data is missing.");return}const e=(i=this._currentStep)==null?void 0:i.id;if((await this._updateInstanceData(e,"admin_save",{stepId:e,adminMode:!0})).success){if(e&&(this._internalCompletedSteps.add(e),this.instance.steps)){const r=this.instance.steps.find(n=>n.id===e);r&&(r.status="completed")}this._justSaved=!0,this.requestUpdate(),setTimeout(()=>{this._justSaved=!1,this.requestUpdate()},2e3)}}_clearSavedFormData(s){var e;this.persistenceManager.clearFormData((e=this.instance)==null?void 0:e.id,s)}_scrollToTop(){requestAnimationFrame(()=>{var t,i;this.scrollIntoView({behavior:"smooth",block:"start"});const s=(t=this.shadowRoot)==null?void 0:t.querySelector(".runner-layout");s&&s.scrollTo({top:0,behavior:"smooth"});const e=(i=this.shadowRoot)==null?void 0:i.querySelector(".runner-main-content");e&&e.scrollTo({top:0,behavior:"smooth"})})}async _updateInstanceData(s,e,t){var d,p,c,u,h,m,y;s&&this._internalCompletedSteps.add(s);let i=(p=(d=this.instance)==null?void 0:d.steps)==null?void 0:p.find(S=>S.id===s);if(!i&&this._internalCompletedSteps.size>0){const S=Array.from(this._internalCompletedSteps),se=S[S.length-1];i=(u=(c=this.instance)==null?void 0:c.steps)==null?void 0:u.find(re=>re.id===se)}const r=e==="submission",n=((h=this.instance)==null?void 0:h.steps)&&this._internalCompletedSteps.size>=this.instance.steps.length,o=r||n?null:this._currentStep?{id:this._currentStep.id,title:this._currentStep.title}:null,a={instanceId:(m=this.instance)==null?void 0:m.id,workflowId:(y=this.instance)==null?void 0:y.workflowId,completedStepId:s||(i?i.id:void 0),completedStepData:i?{id:i.id,title:i.title,responses:i.responses||[]}:void 0,completedSteps:Array.from(this._internalCompletedSteps),currentStep:o,mode:this.mode};if(this.onInstanceUpdated)try{this._submissionError=null,this.requestUpdate();const S=await this.onInstanceUpdated(a);return S.success?this._submissionError=null:(this._submissionError=S.error||"Unable to save response. Please try again.",s&&this._internalCompletedSteps.delete(s)),this.requestUpdate(),S}catch(S){return this._submissionError=S instanceof Error?S.message:"Unable to save response. Please try again.",s&&this._internalCompletedSteps.delete(s),this.requestUpdate(),{success:!1,error:this._submissionError}}return{success:!0}}_restoreFormData(){var e;if(!this.persistenceManager.shouldRestoreData(this.mode||"default")){console.log("Skipping form data restoration - showing official instance data");return}const s=this.persistenceManager.restoreFormData((e=this.instance)==null?void 0:e.id);s?(this.formStateManager.updateFormData(s.formData),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=s.stepIndex,this._savedSignatures=s.savedSignatures,this._internalCompletedSteps=s.completedSteps,this._savedInstance=s.savedInstance||void 0):this._updateCompletedStepsFromCurrentIndex()}_updateCompletedStepsFromCurrentIndex(){var s;if((s=this.instance)!=null&&s.steps){this._internalCompletedSteps=new Set(this.instance.completedSteps||[]);for(let e=0;e<this._currentStepIndex;e++)this.instance.steps[e]&&this._internalCompletedSteps.add(this.instance.steps[e].id)}}_restoreFormDataFromDOM(){this._restoreFormData(),this._restoreFormValuesToDOM()}_restoreFormValuesToDOM(){this.updateComplete.then(()=>{var e,t;(e=this.shadowRoot)!=null&&e.querySelector(".runner-step-form")&&(Object.entries(this._formData).forEach(([i,r])=>{var o;if(i.endsWith("_signatureData"))return;const n=(o=this.shadowRoot)==null?void 0:o.getElementById(i);if(n){if(n.type==="checkbox"){const a=n;typeof r=="boolean"?a.checked=r:Array.isArray(r)&&(a.checked=r.includes(a.value))}else if(n.type==="radio"){const a=n;a.checked=a.value===r}else if(n.type==="file"){const a=n;a.value=""}else n.value=String(r||"");console.log(`Restored value for ${i}:`,r)}}),this._restoreSignatures(),console.log("Form values restored to DOM elements"),this._updateInstanceWithFormData(!0),(t=this._savedInstance)!=null&&t.steps&&this._restoreInstanceResponses())})}_updateInstanceWithFormData(s=!1){this.instance&&this.instance.steps&&this.instance.steps.forEach(e=>{e.responses||(e.responses=[]),e.elements.forEach(t=>{if(t.type==="text_input"||t.type==="textarea"||t.type==="select"||t.type==="number"||t.type==="radio"||t.type==="checkbox"||t.type==="date"||t.type==="file_upload"||t.type==="signature"){const i=t,r=this._formData[i.id];if(r!==void 0&&e.responses){let n=e.responses.find(o=>o.elementId===i.id);n?(n.value=r,n.answeredAt=new Date):(n={elementId:i.id,value:r,answeredAt:new Date},e.responses.push(n))}}})})}_restoreSignatures(){Object.entries(this._formData).forEach(([s,e])=>{if(s.endsWith("_signatureData")&&e){const t=s.replace("_signatureData",""),i=this.signatureManager.getSignaturePad(t);if(i&&e)try{i.clear(),i.fromData(e)}catch{}}})}_saveFormDataToHistory(){var s;this.persistenceManager.saveFormData((s=this.instance)==null?void 0:s.id,this._formData,this._currentStepIndex,this._savedSignatures,this._internalCompletedSteps,this.instance||null)}_extractFormDataFromDOM(){var i;const s={},e=(i=this.shadowRoot)==null?void 0:i.querySelector(".runner-step-form");if(!e)return s;const t=e.elements;for(let r=0;r<t.length;r++){const n=t[r];if(n.name||n.id){const o=n.id||n.name;if(n.type==="checkbox"){const a=n;a.name&&a.name===o?(s[o]||(s[o]=[]),a.checked&&s[o].push(a.value)):s[o]=a.checked}else if(n.type==="radio"){const a=n;a.checked&&(s[o]=a.value)}else s[o]=n.value}}return s}_updateInstanceFromFormData(s=!1){const e=this._extractFormDataFromDOM();Object.keys(e).length>0?(this.formStateManager.mergeFormData(e),this._formData=this.formStateManager.getFormData(),this.instance&&this.instance.steps&&this.instance.steps.forEach(i=>{i.responses||(i.responses=[]),i.elements.forEach(r=>{if(r.type==="text_input"||r.type==="textarea"||r.type==="select"||r.type==="number"||r.type==="radio"||r.type==="checkbox"||r.type==="date"||r.type==="file_upload"||r.type==="signature"){const n=r,o=this._formData[n.id];if(o!==void 0&&i.responses){let a=i.responses.find(d=>d.elementId===n.id);a?(a.value=o,a.answeredAt=new Date):(a={elementId:n.id,value:o,answeredAt:new Date},i.responses.push(a))}}})}),console.log("Instance updated from form data:",this.instance),s&&this._updateInstanceData(void 0,"form_data_update",{updatedFormDataKeys:Object.keys(this._formData),updatedCompletedSteps:Array.from(this._internalCompletedSteps)})):console.log("No new form data to update instance with")}updateInstanceFromFormData(s=!1){this._updateInstanceFromFormData(s)}getFormData(){return this.formStateManager.getFormData()}restoreFormData(){this._restoreFormDataFromDOM()}clearSavedFormData(s){this._clearSavedFormData(s)}_renderUnifiedSubmissionView(){const s={instance:this.instance,assignedSteps:this._getAssignedSteps(),completedSteps:this._internalCompletedSteps,isStepAssignedToUser:this._isStepAssignedToUser.bind(this)};return ve.renderUnifiedSubmissionView(s)}_isInstanceCompleted(){var s;return((s=this.instance)==null?void 0:s.status)==="completed"}_areUserStepsCompleted(){var e;if(!((e=this.instance)!=null&&e.steps))return!1;const s=this._getAssignedSteps();return s.length===0?!1:s.every(t=>t.status==="completed")}_isCurrentStepCompleted(){const s=this._currentStep;return!s||!this._isCurrentStepAssigned()?!1:this._internalCompletedSteps.has(s.id)}_shouldShowCompletionView(){var s;return this.mode!=="default"?!1:!!(this._isCurrentStepCompleted()||this._isInstanceCompleted()||((s=this.instance)==null?void 0:s.status)==="active"&&this._areUserStepsCompleted())}_renderSubmissionErrorView(){const s={instance:this.instance,assignedSteps:this._getAssignedSteps(),completedSteps:this._internalCompletedSteps,isStepAssignedToUser:this._isStepAssignedToUser.bind(this),submissionError:this._submissionError,onRetry:()=>{this._submissionError=null,this._isSubmitted=!1,this._userStepsSubmitted=!1,this.requestUpdate()}};return ve.renderSubmissionErrorView(s)}_renderModeBasedContent(){var e,t;if(this._submissionError)return this._renderSubmissionErrorView();if(this._shouldShowCompletionView())return this._renderUnifiedSubmissionView();if(this.mode==="print")return this._renderAllStepsForPrint();const s=this.mode==="preview"?(e=this.workflow)==null?void 0:e.steps:(t=this.instance)==null?void 0:t.steps;return!s||s.length===0?l`<div class="runner-content">
|
|
4717
|
+
`}async _nextStep(){var t,i,r,n;if(!this._validateStep())return;const s=this._currentStep;s&&this._captureSignaturesFromStep(s);const e=this._findNextAssignedStep(this._currentStepIndex);if(e===-1){await this._submitUserSteps();return}if(e>this._currentStepIndex+1){console.log(`Next assigned step (${e}) is not consecutive. Steps in between are assigned to other users.`),await this._submitUserSteps();return}if(e!==-1){const a=(t=this._currentStep)==null?void 0:t.id;if(this._currentStepIndex=e,(await this._updateInstanceData(a,"step_navigation",{direction:"next",fromStepIndex:this._currentStepIndex-1,toStepIndex:this._currentStepIndex,completedStepId:a})).success&&a&&(i=this.instance)!=null&&i.steps){const p=this.instance.steps.find(c=>c.id===a);p&&(p.status="completed")}const d=(n=(r=this.instance)==null?void 0:r.steps)==null?void 0:n[this._currentStepIndex];d&&(d.status="active"),this.mode!=="admin"&&this._saveFormDataToHistory(),this._scrollToTop()}}_findNextAssignedStep(s){return this.instance?this.navigationService.findNextAssignedStep(s,this.instance):-1}_isLastAssignedStep(){return this.navigationService.isLastAssignedStep(this._currentStepIndex,this.instance)}_isLastStepInWorkflow(){var e;const s=(e=this.instance)==null?void 0:e.steps;return s?this._currentStepIndex===s.length-1:!1}_goToStep(s){var i;console.log(`🎯 _goToStep called: stepIndex=${s}, mode=${this.mode}, currentStep=${this._currentStepIndex}`);const e=this.mode==="preview"?this.workflow:this.instance;if(console.log("📊 Data source:",e?`${((i=e.steps)==null?void 0:i.length)||0} steps`:"null"),!e){console.log("❌ No data source available");return}const t=this.navigationService.canNavigateToStep(s,this._currentStepIndex,e,this._internalCompletedSteps,this._isSubmitted,this._userStepsSubmitted);console.log("🚦 Navigation result:",t),t.canNavigate?(this._currentStepIndex=t.newStepIndex,console.log(`✅ Navigated to step ${t.newStepIndex}`),this._scrollToTop()):console.log("❌ Navigation blocked:",t.reason)}async _submitUserSteps(){var i;if(!this._validateStep())return;const s=this._currentStep;if(s&&this._captureSignaturesFromStep(s),!this.instance){console.error("Cannot submit, instance data is missing.");return}const e=(i=this._currentStep)==null?void 0:i.id;e&&this._internalCompletedSteps.add(e),(await this._updateInstanceData(e,"user_steps_submission")).success&&e&&this._internalCompletedSteps.add(e),this._userStepsSubmitted=!0,this._clearSavedFormData("user steps submission"),this._scrollToTop()}async _submit(){var i;if(!this._validateStep())return;const s=this._currentStep;if(s&&this._captureSignaturesFromStep(s),!this.instance){console.error("Cannot submit, instance data is missing.");return}const e=(i=this._currentStep)==null?void 0:i.id;console.log("Submitting entire workflow:",this.instance.id),console.log("Final form data:",this._formData),(await this._updateInstanceData(e,"submission")).success&&(e&&this._internalCompletedSteps.add(e),this.instance&&(this.instance.status="completed",this.instance.currentStepId=void 0,this.instance.completedSteps=Array.from(this._internalCompletedSteps)),this._isSubmitted=!0,this._clearSavedFormData("full workflow submission"),this._scrollToTop())}async _saveStep(){var i;if(!this._validateStep())return;const s=this._currentStep;if(s&&this._captureSignaturesFromStep(s),!this.instance){console.error("Cannot save, instance data is missing.");return}const e=(i=this._currentStep)==null?void 0:i.id;if((await this._updateInstanceData(e,"admin_save",{stepId:e,adminMode:!0})).success){if(e&&(this._internalCompletedSteps.add(e),this.instance.steps)){const r=this.instance.steps.find(n=>n.id===e);r&&(r.status="completed")}this._justSaved=!0,this.requestUpdate(),setTimeout(()=>{this._justSaved=!1,this.requestUpdate()},2e3)}}_clearSavedFormData(s){var e;this.persistenceManager.clearFormData((e=this.instance)==null?void 0:e.id,s)}_scrollToTop(){requestAnimationFrame(()=>{var t,i;this.scrollIntoView({behavior:"smooth",block:"start"});const s=(t=this.shadowRoot)==null?void 0:t.querySelector(".runner-layout");s&&s.scrollTo({top:0,behavior:"smooth"});const e=(i=this.shadowRoot)==null?void 0:i.querySelector(".runner-main-content");e&&e.scrollTo({top:0,behavior:"smooth"})})}async _updateInstanceData(s,e,t){var d,p,c,u,h,m,y;s&&this._internalCompletedSteps.add(s);let i=(p=(d=this.instance)==null?void 0:d.steps)==null?void 0:p.find(S=>S.id===s);if(!i&&this._internalCompletedSteps.size>0){const S=Array.from(this._internalCompletedSteps),se=S[S.length-1];i=(u=(c=this.instance)==null?void 0:c.steps)==null?void 0:u.find(re=>re.id===se)}const r=e==="submission",n=((h=this.instance)==null?void 0:h.steps)&&this._internalCompletedSteps.size>=this.instance.steps.length,a=r||n?null:this._currentStep?{id:this._currentStep.id,title:this._currentStep.title}:null,o={instanceId:(m=this.instance)==null?void 0:m.id,workflowId:(y=this.instance)==null?void 0:y.workflowId,completedStepId:s||(i?i.id:void 0),completedStepData:i?{id:i.id,title:i.title,responses:i.responses||[]}:void 0,completedSteps:Array.from(this._internalCompletedSteps),currentStep:a,mode:this.mode};if(this.onInstanceUpdated)try{this._submissionError=null,this.requestUpdate();const S=await this.onInstanceUpdated(o);return S.success?this._submissionError=null:(this._submissionError=S.error||"Unable to save response. Please try again.",s&&this._internalCompletedSteps.delete(s)),this.requestUpdate(),S}catch(S){return this._submissionError=S instanceof Error?S.message:"Unable to save response. Please try again.",s&&this._internalCompletedSteps.delete(s),this.requestUpdate(),{success:!1,error:this._submissionError}}return{success:!0}}_restoreFormData(){var e;if(!this.persistenceManager.shouldRestoreData(this.mode||"default")){console.log("Skipping form data restoration - showing official instance data");return}const s=this.persistenceManager.restoreFormData((e=this.instance)==null?void 0:e.id);s?(this.formStateManager.updateFormData(s.formData),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=s.stepIndex,this._savedSignatures=s.savedSignatures,this._internalCompletedSteps=s.completedSteps,this._savedInstance=s.savedInstance||void 0):this._updateCompletedStepsFromCurrentIndex()}_updateCompletedStepsFromCurrentIndex(){var s;if((s=this.instance)!=null&&s.steps){this._internalCompletedSteps=new Set(this.instance.completedSteps||[]);for(let e=0;e<this._currentStepIndex;e++)this.instance.steps[e]&&this._internalCompletedSteps.add(this.instance.steps[e].id)}}_restoreFormDataFromDOM(){this._restoreFormData(),this._restoreFormValuesToDOM()}_restoreFormValuesToDOM(){this.updateComplete.then(()=>{var e,t;(e=this.shadowRoot)!=null&&e.querySelector(".runner-step-form")&&(Object.entries(this._formData).forEach(([i,r])=>{var a;if(i.endsWith("_signatureData"))return;const n=(a=this.shadowRoot)==null?void 0:a.getElementById(i);if(n){if(n.type==="checkbox"){const o=n;typeof r=="boolean"?o.checked=r:Array.isArray(r)&&(o.checked=r.includes(o.value))}else if(n.type==="radio"){const o=n;o.checked=o.value===r}else if(n.type==="file"){const o=n;o.value=""}else n.value=String(r||"");console.log(`Restored value for ${i}:`,r)}}),this._restoreSignatures(),console.log("Form values restored to DOM elements"),this._updateInstanceWithFormData(!0),(t=this._savedInstance)!=null&&t.steps&&this._restoreInstanceResponses())})}_updateInstanceWithFormData(s=!1){this.instance&&this.instance.steps&&this.instance.steps.forEach(e=>{e.responses||(e.responses=[]),e.elements.forEach(t=>{if(t.type==="text_input"||t.type==="textarea"||t.type==="select"||t.type==="number"||t.type==="radio"||t.type==="checkbox"||t.type==="date"||t.type==="file_upload"||t.type==="signature"){const i=t,r=this._formData[i.id];if(r!==void 0&&e.responses){let n=e.responses.find(a=>a.elementId===i.id);n?(n.value=r,n.answeredAt=new Date):(n={elementId:i.id,value:r,answeredAt:new Date},e.responses.push(n))}}})})}_restoreSignatures(){Object.entries(this._formData).forEach(([s,e])=>{if(s.endsWith("_signatureData")&&e){const t=s.replace("_signatureData",""),i=this.signatureManager.getSignaturePad(t);if(i&&e)try{i.clear(),i.fromData(e)}catch{}}})}_saveFormDataToHistory(){var s;this.persistenceManager.saveFormData((s=this.instance)==null?void 0:s.id,this._formData,this._currentStepIndex,this._savedSignatures,this._internalCompletedSteps,this.instance||null)}_extractFormDataFromDOM(){var i;const s={},e=(i=this.shadowRoot)==null?void 0:i.querySelector(".runner-step-form");if(!e)return s;const t=e.elements;for(let r=0;r<t.length;r++){const n=t[r];if(n.name||n.id){const a=n.id||n.name;if(n.type==="checkbox"){const o=n;o.name&&o.name===a?(s[a]||(s[a]=[]),o.checked&&s[a].push(o.value)):s[a]=o.checked}else if(n.type==="radio"){const o=n;o.checked&&(s[a]=o.value)}else s[a]=n.value}}return s}_updateInstanceFromFormData(s=!1){const e=this._extractFormDataFromDOM();Object.keys(e).length>0?(this.formStateManager.mergeFormData(e),this._formData=this.formStateManager.getFormData(),this.instance&&this.instance.steps&&this.instance.steps.forEach(i=>{i.responses||(i.responses=[]),i.elements.forEach(r=>{if(r.type==="text_input"||r.type==="textarea"||r.type==="select"||r.type==="number"||r.type==="radio"||r.type==="checkbox"||r.type==="date"||r.type==="file_upload"||r.type==="signature"){const n=r,a=this._formData[n.id];if(a!==void 0&&i.responses){let o=i.responses.find(d=>d.elementId===n.id);o?(o.value=a,o.answeredAt=new Date):(o={elementId:n.id,value:a,answeredAt:new Date},i.responses.push(o))}}})}),console.log("Instance updated from form data:",this.instance),s&&this._updateInstanceData(void 0,"form_data_update",{updatedFormDataKeys:Object.keys(this._formData),updatedCompletedSteps:Array.from(this._internalCompletedSteps)})):console.log("No new form data to update instance with")}updateInstanceFromFormData(s=!1){this._updateInstanceFromFormData(s)}getFormData(){return this.formStateManager.getFormData()}restoreFormData(){this._restoreFormDataFromDOM()}clearSavedFormData(s){this._clearSavedFormData(s)}_renderUnifiedSubmissionView(){const s={instance:this.instance,assignedSteps:this._getAssignedSteps(),completedSteps:this._internalCompletedSteps,isStepAssignedToUser:this._isStepAssignedToUser.bind(this)};return ve.renderUnifiedSubmissionView(s)}_isInstanceCompleted(){var s;return((s=this.instance)==null?void 0:s.status)==="completed"}_areUserStepsCompleted(){var e;if(!((e=this.instance)!=null&&e.steps))return!1;const s=this._getAssignedSteps();return s.length===0?!1:s.every(t=>t.status==="completed")}_isCurrentStepCompleted(){const s=this._currentStep;return!s||!this._isCurrentStepAssigned()?!1:this._internalCompletedSteps.has(s.id)}_shouldShowCompletionView(){var s;return this.mode!=="default"?!1:!!(this._isCurrentStepCompleted()||this._isInstanceCompleted()||((s=this.instance)==null?void 0:s.status)==="active"&&this._areUserStepsCompleted())}_renderSubmissionErrorView(){const s={instance:this.instance,assignedSteps:this._getAssignedSteps(),completedSteps:this._internalCompletedSteps,isStepAssignedToUser:this._isStepAssignedToUser.bind(this),submissionError:this._submissionError,onRetry:()=>{this._submissionError=null,this._isSubmitted=!1,this._userStepsSubmitted=!1,this.requestUpdate()}};return ve.renderSubmissionErrorView(s)}_renderModeBasedContent(){var e,t;if(this._submissionError)return this._renderSubmissionErrorView();if(this._shouldShowCompletionView())return this._renderUnifiedSubmissionView();if(this.mode==="print")return this._renderAllStepsForPrint();const s=this.mode==="preview"?(e=this.workflow)==null?void 0:e.steps:(t=this.instance)==null?void 0:t.steps;return!s||s.length===0?l`<div class="runner-content">
|
|
4702
4718
|
${this.mode==="preview"?"No workflow loaded or workflow has no steps.":"No workflow instance loaded or instance has no steps."}
|
|
4703
4719
|
</div>`:this.mode==="default"&&this._getAssignedSteps().length===0?this._renderNotAssignedView():null}_validateCurrentStep(){return this._currentStep}_initializeStepAssets(s){this.updateComplete.then(()=>{s.elements.forEach(e=>{var t;e.type==="signature"&&((t=this.shadowRoot)!=null&&t.getElementById(`signature-${e.id}`))&&this._initializeSignaturePad(e.id)}),this._restoreSignatures(),setTimeout(()=>{this._formRestorationComplete||(this._restoreFormDataFromDOM(),this._formRestorationComplete=!0)},100)})}_renderCurrentStepLayout(s){var r,n;const e=this._isLastAssignedStep(),t=this._isLastStepInWorkflow(),i=this.mode==="preview"?(r=this.workflow)==null?void 0:r.steps:(n=this.instance)==null?void 0:n.steps;return l`
|
|
4704
4720
|
<!-- Mobile Steps Navigation (visible only on mobile) -->
|
|
@@ -4712,8 +4728,8 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4712
4728
|
${this.mode==="print"?q.renderStepHeader({step:s,mode:this.mode}):l`<div class="runner-card">
|
|
4713
4729
|
${q.renderStepHeader({step:s,mode:this.mode})}
|
|
4714
4730
|
</div>`}
|
|
4715
|
-
<form class="runner-step-form" @submit=${
|
|
4716
|
-
${s.elements.map(
|
|
4731
|
+
<form class="runner-step-form" @submit=${a=>a.preventDefault()}>
|
|
4732
|
+
${s.elements.map(a=>this._renderStepElement(a))}
|
|
4717
4733
|
${Dt.renderFormActions({mode:this.mode||"default",isLastStep:e,isLastStepInWorkflow:t,justSaved:this._justSaved,isCurrentStepAssigned:this._isCurrentStepAssigned(),handlers:{saveStep:()=>{this._saveStep()},nextStep:()=>{this._nextStep()},submitUserSteps:()=>{this._submitUserSteps()},submit:()=>{this._submit()}}})}
|
|
4718
4734
|
</form>
|
|
4719
4735
|
</main>
|
|
@@ -4731,7 +4747,7 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4731
4747
|
</div>
|
|
4732
4748
|
`:""}
|
|
4733
4749
|
</div>
|
|
4734
|
-
`}};f.styles=[Ne],f.QUESTION_ELEMENT_TYPES=["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"],f.CONTENT_ELEMENT_TYPES=["text","html","image","video","file","divider","markdown"],_([$({type:Object})],f.prototype,"instance",2),_([$({type:Object})],f.prototype,"workflow",2),_([$({type:String})],f.prototype,"mode",2),_([$({type:Boolean})],f.prototype,"isLoading",2),_([$({type:Object})],f.prototype,"currentUser",2),_([$({type:Function})],f.prototype,"onSignatureCaptured",2),_([$({type:Function})],f.prototype,"onFileUploaded",2),_([$({type:Function})],f.prototype,"onInstanceUpdated",2),_([b()],f.prototype,"_currentStepIndex",2),_([b()],f.prototype,"_formData",2),_([b()],f.prototype,"_validationErrors",2),_([b()],f.prototype,"_internalCompletedSteps",2),_([b()],f.prototype,"_formRestorationComplete",2),_([b()],f.prototype,"_savedSignatures",2),_([b()],f.prototype,"_replacingSignatures",2),_([b()],f.prototype,"_savedInstance",2),_([b()],f.prototype,"_isSubmitted",2),_([b()],f.prototype,"_userStepsSubmitted",2),_([b()],f.prototype,"_justSaved",2),_([b()],f.prototype,"_submissionError",2),f=_([Ue("runner-widget")],f);function Et(s,e={}){const{title:t=s.name||"Workflow Instance",includeStyles:i=!0,customCSS:r="",showTimestamps:n=!1}=e,
|
|
4750
|
+
`}};f.styles=[Ne],f.QUESTION_ELEMENT_TYPES=["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"],f.CONTENT_ELEMENT_TYPES=["text","html","image","video","file","divider","markdown"],_([$({type:Object})],f.prototype,"instance",2),_([$({type:Object})],f.prototype,"workflow",2),_([$({type:String})],f.prototype,"mode",2),_([$({type:Boolean})],f.prototype,"isLoading",2),_([$({type:Object})],f.prototype,"currentUser",2),_([$({type:Function})],f.prototype,"onSignatureCaptured",2),_([$({type:Function})],f.prototype,"onFileUploaded",2),_([$({type:Function})],f.prototype,"onInstanceUpdated",2),_([b()],f.prototype,"_currentStepIndex",2),_([b()],f.prototype,"_formData",2),_([b()],f.prototype,"_validationErrors",2),_([b()],f.prototype,"_internalCompletedSteps",2),_([b()],f.prototype,"_formRestorationComplete",2),_([b()],f.prototype,"_savedSignatures",2),_([b()],f.prototype,"_replacingSignatures",2),_([b()],f.prototype,"_savedInstance",2),_([b()],f.prototype,"_isSubmitted",2),_([b()],f.prototype,"_userStepsSubmitted",2),_([b()],f.prototype,"_justSaved",2),_([b()],f.prototype,"_submissionError",2),f=_([Ue("runner-widget")],f);function Et(s,e={}){const{title:t=s.name||"Workflow Instance",includeStyles:i=!0,customCSS:r="",showTimestamps:n=!1}=e,a=new Date;if(!(s!=null&&s.steps)||s.steps.length===0)throw new Error("Instance must have at least one step to generate HTML");return{html:`<!DOCTYPE html>
|
|
4735
4751
|
<html lang="en">
|
|
4736
4752
|
<head>
|
|
4737
4753
|
<meta charset="UTF-8">
|
|
@@ -4748,12 +4764,12 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4748
4764
|
</div>
|
|
4749
4765
|
<hr class="print-question-separator" />
|
|
4750
4766
|
|
|
4751
|
-
${n?Ht(s,
|
|
4767
|
+
${n?Ht(s,a):""}
|
|
4752
4768
|
${s.steps.map(d=>Tt(d)).join(`
|
|
4753
4769
|
`)}
|
|
4754
4770
|
</div>
|
|
4755
4771
|
</body>
|
|
4756
|
-
</html>`,title:t,generatedAt:
|
|
4772
|
+
</html>`,title:t,generatedAt:a}}function Tt(s){return`
|
|
4757
4773
|
<div class="print-step">
|
|
4758
4774
|
<!-- Step Header -->
|
|
4759
4775
|
${Mt(s)}
|
|
@@ -4772,11 +4788,11 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
4772
4788
|
<div class="print-question-title">
|
|
4773
4789
|
${g(s.label)}:
|
|
4774
4790
|
</div>
|
|
4775
|
-
`,
|
|
4791
|
+
`,a='<hr class="print-question-separator" />';switch(s.type){case"text_input":case"number":case"date":return n+Ut(s,i)+a;case"textarea":return n+Pt(s,i)+a;case"select":return n+Nt(s,i)+a;case"radio":return n+Lt(s,i)+a;case"checkbox":return n+Ot(s,i)+a;case"file_upload":return n+Rt(s,i)+a;case"signature":return n+jt(s,i)+a;default:return n+`
|
|
4776
4792
|
<div class="unknown-element">
|
|
4777
4793
|
<p>⚠️ Unknown question type: ${g(s.type)}</p>
|
|
4778
4794
|
</div>
|
|
4779
|
-
`+
|
|
4795
|
+
`+a}}function zt(s){const e=s.type!=="divider"?'<hr class="print-question-separator" />':"";switch(s.type){case"text":return`
|
|
4780
4796
|
<div class="content-print">
|
|
4781
4797
|
<div class="content-element">
|
|
4782
4798
|
<div class="text-content">
|
|
@@ -5423,4 +5439,4 @@ Use **bold** and *italic* text.`;break}const i=this._templateData.steps.map(n=>n
|
|
|
5423
5439
|
margin: 2px 0;
|
|
5424
5440
|
line-height: 1.4;
|
|
5425
5441
|
}
|
|
5426
|
-
`}function qt(s,e={}){var r;if(!customElements.get("builder-widget"))return console.error("Error: <builder-widget> is not defined. Make sure it was imported."),null;const t=document.getElementById(s);if(!t)return console.error(`Error: Target element with ID '${s}' not found.`),null;t.innerHTML="";const i=document.createElement("builder-widget");return e.workflow&&(i.workflow=e.workflow,e.subjectTypes&&e.subjectTypes.length>0&&((r=e.subjectTypes[0])!=null&&r.name)&&(console.log("Setting default subject type to:",e.subjectTypes[0].name),i.workflow.subjectType=e.subjectTypes[0].name)),e.onWorkflowCreated&&(i.onWorkflowCreated=e.onWorkflowCreated),e.onWorkflowDeleted&&(i.onWorkflowDeleted=e.onWorkflowDeleted),e.onWorkflowUpdated&&(i.onWorkflowUpdated=e.onWorkflowUpdated),i.labelForDrill=e.labelForDrill||"Drill",i.labelForGroup=e.labelForGroup||"Group",i.subjectTypes=e.subjectTypes||[],i.groups=e.groups||[],t.appendChild(i),console.log(`Drill Builder mounted on #${s}`),i}function Kt(s,e){if(!customElements.get("runner-widget"))return console.error("Error: <runner-widget> is not defined. Make sure it was imported."),null;const t=document.getElementById(s);if(!t)return console.error(`Error: Target element with ID '${s}' not found.`),null;if(e.mode==="preview"){if(!e||!e.workflow)return console.error("Error: Workflow data must be provided for preview mode."),t.innerHTML='<p style="color: red;">Error: Workflow data required for preview mode.</p>',null;if(!e.workflow.steps||e.workflow.steps.length===0)return console.error("Error: Workflow provided to runner has no steps defined."),t.innerHTML='<p style="color: red;">Error: Workflow has no steps.</p>',null}else{if(!e||!e.instance)return console.error("Error: Instance data must be provided in runner config."),t.innerHTML='<p style="color: red;">Error: Instance data required.</p>',null;if(!e.instance.steps||e.instance.steps.length===0)return console.error("Error: Instance provided to runner has no steps defined."),t.innerHTML='<p style="color: red;">Error: Instance has no steps.</p>',null}t.innerHTML="";const i=document.createElement("runner-widget");return e.mode==="preview"?(i.workflow=e.workflow,i.mode="preview"):(i.instance=e.instance,i.mode=e.mode||"default"),e.mode&&(i.mode=e.mode),e.isLoading!==void 0&&(i.isLoading=e.isLoading),e.onSignatureCaptured&&(i.onSignatureCaptured=e.onSignatureCaptured),e.onFileUploaded&&(i.onFileUploaded=e.onFileUploaded),e.currentUser&&(i.currentUser=e.currentUser),e.onInstanceUpdated&&(i.onInstanceUpdated=e.onInstanceUpdated),t.appendChild(i),console.log(`Drill Runner mounted on #${s}`),i}function Jt(s,e){const t=s.getFormData(),i=JSON.parse(JSON.stringify(e));return i.steps&&i.steps.forEach(r=>{r.responses||(r.responses=[]),r.elements.forEach(n=>{if(n.type==="text_input"||n.type==="textarea"||n.type==="select"||n.type==="number"||n.type==="radio"||n.type==="checkbox"||n.type==="date"||n.type==="file_upload"||n.type==="signature"){const
|
|
5442
|
+
`}function qt(s,e={}){var r;if(!customElements.get("builder-widget"))return console.error("Error: <builder-widget> is not defined. Make sure it was imported."),null;const t=document.getElementById(s);if(!t)return console.error(`Error: Target element with ID '${s}' not found.`),null;t.innerHTML="";const i=document.createElement("builder-widget");return e.workflow&&(i.workflow=e.workflow,e.subjectTypes&&e.subjectTypes.length>0&&((r=e.subjectTypes[0])!=null&&r.name)&&(console.log("Setting default subject type to:",e.subjectTypes[0].name),i.workflow.subjectType=e.subjectTypes[0].name)),e.onWorkflowCreated&&(i.onWorkflowCreated=e.onWorkflowCreated),e.onWorkflowDeleted&&(i.onWorkflowDeleted=e.onWorkflowDeleted),e.onWorkflowUpdated&&(i.onWorkflowUpdated=e.onWorkflowUpdated),i.labelForDrill=e.labelForDrill||"Drill",i.labelForGroup=e.labelForGroup||"Group",i.subjectTypes=e.subjectTypes||[],i.groups=e.groups||[],t.appendChild(i),console.log(`Drill Builder mounted on #${s}`),i}function Kt(s,e){if(!customElements.get("runner-widget"))return console.error("Error: <runner-widget> is not defined. Make sure it was imported."),null;const t=document.getElementById(s);if(!t)return console.error(`Error: Target element with ID '${s}' not found.`),null;if(e.mode==="preview"){if(!e||!e.workflow)return console.error("Error: Workflow data must be provided for preview mode."),t.innerHTML='<p style="color: red;">Error: Workflow data required for preview mode.</p>',null;if(!e.workflow.steps||e.workflow.steps.length===0)return console.error("Error: Workflow provided to runner has no steps defined."),t.innerHTML='<p style="color: red;">Error: Workflow has no steps.</p>',null}else{if(!e||!e.instance)return console.error("Error: Instance data must be provided in runner config."),t.innerHTML='<p style="color: red;">Error: Instance data required.</p>',null;if(!e.instance.steps||e.instance.steps.length===0)return console.error("Error: Instance provided to runner has no steps defined."),t.innerHTML='<p style="color: red;">Error: Instance has no steps.</p>',null}t.innerHTML="";const i=document.createElement("runner-widget");return e.mode==="preview"?(i.workflow=e.workflow,i.mode="preview"):(i.instance=e.instance,i.mode=e.mode||"default"),e.mode&&(i.mode=e.mode),e.isLoading!==void 0&&(i.isLoading=e.isLoading),e.onSignatureCaptured&&(i.onSignatureCaptured=e.onSignatureCaptured),e.onFileUploaded&&(i.onFileUploaded=e.onFileUploaded),e.currentUser&&(i.currentUser=e.currentUser),e.onInstanceUpdated&&(i.onInstanceUpdated=e.onInstanceUpdated),t.appendChild(i),console.log(`Drill Runner mounted on #${s}`),i}function Jt(s,e){const t=s.getFormData(),i=JSON.parse(JSON.stringify(e));return i.steps&&i.steps.forEach(r=>{r.responses||(r.responses=[]),r.elements.forEach(n=>{if(n.type==="text_input"||n.type==="textarea"||n.type==="select"||n.type==="number"||n.type==="radio"||n.type==="checkbox"||n.type==="date"||n.type==="file_upload"||n.type==="signature"){const a=t[n.id];if(a!==void 0){let o=r.responses.find(d=>d.elementId===n.id);o?(o.value=a,o.answeredAt=new Date):(o={elementId:n.id,value:a,answeredAt:new Date},r.responses.push(o))}}})}),i}function Xt(s,e){const t={};e.steps&&e.steps.forEach(i=>{i.responses&&i.responses.forEach(r=>{t[r.elementId]=r.value})}),s.restoreFormData(),console.log("Form data restored to runner widget:",t)}A.createBuilder=qt,A.createRunner=Kt,A.generateInstanceHTML=Et,A.restoreFormDataToRunner=Xt,A.updateInstanceFromRunnerForm=Jt,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|