@nuralyui/form 0.1.0

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/bundle.js ADDED
@@ -0,0 +1,154 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2019 Google LLC
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+ const t=window,i=t.ShadowRoot&&(void 0===t.ShadyCSS||t.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),e=new WeakMap;class n{constructor(t,i,e){if(this._$cssResult$=!0,e!==s)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=i}get styleSheet(){let t=this.o;const s=this.t;if(i&&void 0===t){const i=void 0!==s&&1===s.length;i&&(t=e.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&e.set(s,t))}return t}toString(){return this.cssText}}const o=i?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let i="";for(const s of t.cssRules)i+=s.cssText;return(t=>new n("string"==typeof t?t:t+"",void 0,s))(i)})(t):t
7
+ /**
8
+ * @license
9
+ * Copyright 2017 Google LLC
10
+ * SPDX-License-Identifier: BSD-3-Clause
11
+ */;var r;const h=window,l=h.trustedTypes,a=l?l.emptyScript:"",d=h.reactiveElementPolyfillSupport,u={toAttribute(t,i){switch(i){case Boolean:t=t?a:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,i){let s=t;switch(i){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t)}catch(t){s=null}}return s}},c=(t,i)=>i!==t&&(i==i||t==t),v={attribute:!0,type:String,converter:u,reflect:!1,hasChanged:c},f="finalized";class p extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this._$Eu()}static addInitializer(t){var i;this.finalize(),(null!==(i=this.h)&&void 0!==i?i:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((i,s)=>{const e=this._$Ep(s,i);void 0!==e&&(this._$Ev.set(e,s),t.push(e))})),t}static createProperty(t,i=v){if(i.state&&(i.attribute=!1),this.finalize(),this.elementProperties.set(t,i),!i.noAccessor&&!this.prototype.hasOwnProperty(t)){const s="symbol"==typeof t?Symbol():"__"+t,e=this.getPropertyDescriptor(t,s,i);void 0!==e&&Object.defineProperty(this.prototype,t,e)}}static getPropertyDescriptor(t,i,s){return{get(){return this[i]},set(e){const n=this[t];this[i]=e,this.requestUpdate(t,n,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||v}static finalize(){if(this.hasOwnProperty(f))return!1;this[f]=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,i=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const s of i)this.createProperty(s,t[s])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const i=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const t of s)i.unshift(o(t))}else void 0!==t&&i.push(o(t));return i}static _$Ep(t,i){const s=i.attribute;return!1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}_$Eu(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var i,s;(null!==(i=this._$ES)&&void 0!==i?i:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(s=t.hostConnected)||void 0===s||s.call(t))}removeController(t){var i;null===(i=this._$ES)||void 0===i||i.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,i)=>{this.hasOwnProperty(i)&&(this._$Ei.set(i,this[i]),delete this[i])}))}createRenderRoot(){var s;const e=null!==(s=this.shadowRoot)&&void 0!==s?s:this.attachShadow(this.constructor.shadowRootOptions);return((s,e)=>{i?s.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((i=>{const e=document.createElement("style"),n=t.litNonce;void 0!==n&&e.setAttribute("nonce",n),e.textContent=i.cssText,s.appendChild(e)}))})(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostConnected)||void 0===i?void 0:i.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostDisconnected)||void 0===i?void 0:i.call(t)}))}attributeChangedCallback(t,i,s){this._$AK(t,s)}_$EO(t,i,s=v){var e;const n=this.constructor._$Ep(t,s);if(void 0!==n&&!0===s.reflect){const o=(void 0!==(null===(e=s.converter)||void 0===e?void 0:e.toAttribute)?s.converter:u).toAttribute(i,s.type);this._$El=t,null==o?this.removeAttribute(n):this.setAttribute(n,o),this._$El=null}}_$AK(t,i){var s;const e=this.constructor,n=e._$Ev.get(t);if(void 0!==n&&this._$El!==n){const t=e.getPropertyOptions(n),o="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(s=t.converter)||void 0===s?void 0:s.fromAttribute)?t.converter:u;this._$El=n,this[n]=o.fromAttribute(i,t.type),this._$El=null}}requestUpdate(t,i,s){let e=!0;void 0!==t&&(((s=s||this.constructor.getPropertyOptions(t)).hasChanged||c)(this[t],i)?(this._$AL.has(t)||this._$AL.set(t,i),!0===s.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,s))):e=!1),!this.isUpdatePending&&e&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,i)=>this[i]=t)),this._$Ei=void 0);let i=!1;const s=this._$AL;try{i=this.shouldUpdate(s),i?(this.willUpdate(s),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostUpdate)||void 0===i?void 0:i.call(t)})),this.update(s)):this._$Ek()}catch(t){throw i=!1,this._$Ek(),t}i&&this._$AE(s)}willUpdate(t){}_$AE(t){var i;null===(i=this._$ES)||void 0===i||i.forEach((t=>{var i;return null===(i=t.hostUpdated)||void 0===i?void 0:i.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,i)=>this._$EO(i,this[i],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}}
12
+ /**
13
+ * @license
14
+ * Copyright 2017 Google LLC
15
+ * SPDX-License-Identifier: BSD-3-Clause
16
+ */
17
+ var m;p[f]=!0,p.elementProperties=new Map,p.elementStyles=[],p.shadowRootOptions={mode:"open"},null==d||d({ReactiveElement:p}),(null!==(r=h.reactiveElementVersions)&&void 0!==r?r:h.reactiveElementVersions=[]).push("1.6.3");const g=window,b=g.trustedTypes,y=b?b.createPolicy("lit-html",{createHTML:t=>t}):void 0,w="$lit$",S=`lit$${(Math.random()+"").slice(9)}$`,$="?"+S,E=`<${$}>`,A=document,F=()=>A.createComment(""),x=t=>null===t||"object"!=typeof t&&"function"!=typeof t,O=Array.isArray,C="[ \t\n\f\r]",_=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,k=/-->/g,T=/>/g,j=RegExp(`>|${C}(?:([^\\s"'>=/]+)(${C}*=${C}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),R=/'/g,D=/"/g,I=/^(?:script|style|textarea|title)$/i,M=Symbol.for("lit-noChange"),U=Symbol.for("lit-nothing"),V=new WeakMap,N=A.createTreeWalker(A,129,null,!1);function P(t,i){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==y?y.createHTML(i):i}class B{constructor({strings:t,_$litType$:i},s){let e;this.parts=[];let n=0,o=0;const r=t.length-1,h=this.parts,[l,a]=((t,i)=>{const s=t.length-1,e=[];let n,o=2===i?"<svg>":"",r=_;for(let i=0;i<s;i++){const s=t[i];let h,l,a=-1,d=0;for(;d<s.length&&(r.lastIndex=d,l=r.exec(s),null!==l);)d=r.lastIndex,r===_?"!--"===l[1]?r=k:void 0!==l[1]?r=T:void 0!==l[2]?(I.test(l[2])&&(n=RegExp("</"+l[2],"g")),r=j):void 0!==l[3]&&(r=j):r===j?">"===l[0]?(r=null!=n?n:_,a=-1):void 0===l[1]?a=-2:(a=r.lastIndex-l[2].length,h=l[1],r=void 0===l[3]?j:'"'===l[3]?D:R):r===D||r===R?r=j:r===k||r===T?r=_:(r=j,n=void 0);const u=r===j&&t[i+1].startsWith("/>")?" ":"";o+=r===_?s+E:a>=0?(e.push(h),s.slice(0,a)+w+s.slice(a)+S+u):s+S+(-2===a?(e.push(void 0),i):u)}return[P(t,o+(t[s]||"<?>")+(2===i?"</svg>":"")),e]})(t,i);if(this.el=B.createElement(l,s),N.currentNode=this.el.content,2===i){const t=this.el.content,i=t.firstChild;i.remove(),t.append(...i.childNodes)}for(;null!==(e=N.nextNode())&&h.length<r;){if(1===e.nodeType){if(e.hasAttributes()){const t=[];for(const i of e.getAttributeNames())if(i.endsWith(w)||i.startsWith(S)){const s=a[o++];if(t.push(i),void 0!==s){const t=e.getAttribute(s.toLowerCase()+w).split(S),i=/([.?@])?(.*)/.exec(s);h.push({type:1,index:n,name:i[2],strings:t,ctor:"."===i[1]?K:"?"===i[1]?J:"@"===i[1]?Z:H})}else h.push({type:6,index:n})}for(const i of t)e.removeAttribute(i)}if(I.test(e.tagName)){const t=e.textContent.split(S),i=t.length-1;if(i>0){e.textContent=b?b.emptyScript:"";for(let s=0;s<i;s++)e.append(t[s],F()),N.nextNode(),h.push({type:2,index:++n});e.append(t[i],F())}}}else if(8===e.nodeType)if(e.data===$)h.push({type:2,index:n});else{let t=-1;for(;-1!==(t=e.data.indexOf(S,t+1));)h.push({type:7,index:n}),t+=S.length-1}n++}}static createElement(t,i){const s=A.createElement("template");return s.innerHTML=t,s}}function L(t,i,s=t,e){var n,o,r,h;if(i===M)return i;let l=void 0!==e?null===(n=s._$Co)||void 0===n?void 0:n[e]:s._$Cl;const a=x(i)?void 0:i._$litDirective$;return(null==l?void 0:l.constructor)!==a&&(null===(o=null==l?void 0:l._$AO)||void 0===o||o.call(l,!1),void 0===a?l=void 0:(l=new a(t),l._$AT(t,s,e)),void 0!==e?(null!==(r=(h=s)._$Co)&&void 0!==r?r:h._$Co=[])[e]=l:s._$Cl=l),void 0!==l&&(i=L(t,l._$AS(t,i.values),l,e)),i}class z{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){var i;const{el:{content:s},parts:e}=this._$AD,n=(null!==(i=null==t?void 0:t.creationScope)&&void 0!==i?i:A).importNode(s,!0);N.currentNode=n;let o=N.nextNode(),r=0,h=0,l=e[0];for(;void 0!==l;){if(r===l.index){let i;2===l.type?i=new q(o,o.nextSibling,this,t):1===l.type?i=new l.ctor(o,l.name,l.strings,this,t):6===l.type&&(i=new G(o,this,t)),this._$AV.push(i),l=e[++h]}r!==(null==l?void 0:l.index)&&(o=N.nextNode(),r++)}return N.currentNode=A,n}v(t){let i=0;for(const s of this._$AV)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++}}class q{constructor(t,i,s,e){var n;this.type=2,this._$AH=U,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cp=null===(n=null==e?void 0:e.isConnected)||void 0===n||n}get _$AU(){var t,i;return null!==(i=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==i?i:this._$Cp}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===(null==t?void 0:t.nodeType)&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=L(this,t,i),x(t)?t===U||null==t||""===t?(this._$AH!==U&&this._$AR(),this._$AH=U):t!==this._$AH&&t!==M&&this._(t):void 0!==t._$litType$?this.g(t):void 0!==t.nodeType?this.$(t):(t=>O(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]))(t)?this.T(t):this._(t)}k(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}$(t){this._$AH!==t&&(this._$AR(),this._$AH=this.k(t))}_(t){this._$AH!==U&&x(this._$AH)?this._$AA.nextSibling.data=t:this.$(A.createTextNode(t)),this._$AH=t}g(t){var i;const{values:s,_$litType$:e}=t,n="number"==typeof e?this._$AC(t):(void 0===e.el&&(e.el=B.createElement(P(e.h,e.h[0]),this.options)),e);if((null===(i=this._$AH)||void 0===i?void 0:i._$AD)===n)this._$AH.v(s);else{const t=new z(n,this),i=t.u(this.options);t.v(s),this.$(i),this._$AH=t}}_$AC(t){let i=V.get(t.strings);return void 0===i&&V.set(t.strings,i=new B(t)),i}T(t){O(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,e=0;for(const n of t)e===i.length?i.push(s=new q(this.k(F()),this.k(F()),this,this.options)):s=i[e],s._$AI(n),e++;e<i.length&&(this._$AR(s&&s._$AB.nextSibling,e),i.length=e)}_$AR(t=this._$AA.nextSibling,i){var s;for(null===(s=this._$AP)||void 0===s||s.call(this,!1,!0,i);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i}}setConnected(t){var i;void 0===this._$AM&&(this._$Cp=t,null===(i=this._$AP)||void 0===i||i.call(this,t))}}class H{constructor(t,i,s,e,n){this.type=1,this._$AH=U,this._$AN=void 0,this.element=t,this.name=i,this._$AM=e,this.options=n,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=U}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,i=this,s,e){const n=this.strings;let o=!1;if(void 0===n)t=L(this,t,i,0),o=!x(t)||t!==this._$AH&&t!==M,o&&(this._$AH=t);else{const e=t;let r,h;for(t=n[0],r=0;r<n.length-1;r++)h=L(this,e[s+r],i,r),h===M&&(h=this._$AH[r]),o||(o=!x(h)||h!==this._$AH[r]),h===U?t=U:t!==U&&(t+=(null!=h?h:"")+n[r+1]),this._$AH[r]=h}o&&!e&&this.j(t)}j(t){t===U?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class K extends H{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===U?void 0:t}}const W=b?b.emptyScript:"";class J extends H{constructor(){super(...arguments),this.type=4}j(t){t&&t!==U?this.element.setAttribute(this.name,W):this.element.removeAttribute(this.name)}}class Z extends H{constructor(t,i,s,e,n){super(t,i,s,e,n),this.type=5}_$AI(t,i=this){var s;if((t=null!==(s=L(this,t,i,0))&&void 0!==s?s:U)===M)return;const e=this._$AH,n=t===U&&e!==U||t.capture!==e.capture||t.once!==e.once||t.passive!==e.passive,o=t!==U&&(e===U||n);n&&this.element.removeEventListener(this.name,this,e),o&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var i,s;"function"==typeof this._$AH?this._$AH.call(null!==(s=null===(i=this.options)||void 0===i?void 0:i.host)&&void 0!==s?s:this.element,t):this._$AH.handleEvent(t)}}class G{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){L(this,t)}}const Q=g.litHtmlPolyfillSupport;
18
+ /**
19
+ * @license
20
+ * Copyright 2017 Google LLC
21
+ * SPDX-License-Identifier: BSD-3-Clause
22
+ */
23
+ var X;null==Q||Q(B,q),(null!==(m=g.litHtmlVersions)&&void 0!==m?m:g.litHtmlVersions=[]).push("2.8.0");const Y=window,tt=Y.trustedTypes,it=tt?tt.createPolicy("lit-html",{createHTML:t=>t}):void 0,st="$lit$",et=`lit$${(Math.random()+"").slice(9)}$`,nt="?"+et,ot=`<${nt}>`,rt=document,ht=()=>rt.createComment(""),lt=t=>null===t||"object"!=typeof t&&"function"!=typeof t,at=Array.isArray,dt="[ \t\n\f\r]",ut=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,ct=/-->/g,vt=/>/g,ft=RegExp(`>|${dt}(?:([^\\s"'>=/]+)(${dt}*=${dt}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),pt=/'/g,mt=/"/g,gt=/^(?:script|style|textarea|title)$/i,bt=(t=>(i,...s)=>({_$litType$:t,strings:i,values:s}))(1),yt=Symbol.for("lit-noChange"),wt=Symbol.for("lit-nothing"),St=new WeakMap,$t=rt.createTreeWalker(rt,129,null,!1);function Et(t,i){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==it?it.createHTML(i):i}const At=(t,i)=>{const s=t.length-1,e=[];let n,o=2===i?"<svg>":"",r=ut;for(let i=0;i<s;i++){const s=t[i];let h,l,a=-1,d=0;for(;d<s.length&&(r.lastIndex=d,l=r.exec(s),null!==l);)d=r.lastIndex,r===ut?"!--"===l[1]?r=ct:void 0!==l[1]?r=vt:void 0!==l[2]?(gt.test(l[2])&&(n=RegExp("</"+l[2],"g")),r=ft):void 0!==l[3]&&(r=ft):r===ft?">"===l[0]?(r=null!=n?n:ut,a=-1):void 0===l[1]?a=-2:(a=r.lastIndex-l[2].length,h=l[1],r=void 0===l[3]?ft:'"'===l[3]?mt:pt):r===mt||r===pt?r=ft:r===ct||r===vt?r=ut:(r=ft,n=void 0);const u=r===ft&&t[i+1].startsWith("/>")?" ":"";o+=r===ut?s+ot:a>=0?(e.push(h),s.slice(0,a)+st+s.slice(a)+et+u):s+et+(-2===a?(e.push(void 0),i):u)}return[Et(t,o+(t[s]||"<?>")+(2===i?"</svg>":"")),e]};class Ft{constructor({strings:t,_$litType$:i},s){let e;this.parts=[];let n=0,o=0;const r=t.length-1,h=this.parts,[l,a]=At(t,i);if(this.el=Ft.createElement(l,s),$t.currentNode=this.el.content,2===i){const t=this.el.content,i=t.firstChild;i.remove(),t.append(...i.childNodes)}for(;null!==(e=$t.nextNode())&&h.length<r;){if(1===e.nodeType){if(e.hasAttributes()){const t=[];for(const i of e.getAttributeNames())if(i.endsWith(st)||i.startsWith(et)){const s=a[o++];if(t.push(i),void 0!==s){const t=e.getAttribute(s.toLowerCase()+st).split(et),i=/([.?@])?(.*)/.exec(s);h.push({type:1,index:n,name:i[2],strings:t,ctor:"."===i[1]?kt:"?"===i[1]?jt:"@"===i[1]?Rt:_t})}else h.push({type:6,index:n})}for(const i of t)e.removeAttribute(i)}if(gt.test(e.tagName)){const t=e.textContent.split(et),i=t.length-1;if(i>0){e.textContent=tt?tt.emptyScript:"";for(let s=0;s<i;s++)e.append(t[s],ht()),$t.nextNode(),h.push({type:2,index:++n});e.append(t[i],ht())}}}else if(8===e.nodeType)if(e.data===nt)h.push({type:2,index:n});else{let t=-1;for(;-1!==(t=e.data.indexOf(et,t+1));)h.push({type:7,index:n}),t+=et.length-1}n++}}static createElement(t,i){const s=rt.createElement("template");return s.innerHTML=t,s}}function xt(t,i,s=t,e){var n,o,r,h;if(i===yt)return i;let l=void 0!==e?null===(n=s._$Co)||void 0===n?void 0:n[e]:s._$Cl;const a=lt(i)?void 0:i._$litDirective$;return(null==l?void 0:l.constructor)!==a&&(null===(o=null==l?void 0:l._$AO)||void 0===o||o.call(l,!1),void 0===a?l=void 0:(l=new a(t),l._$AT(t,s,e)),void 0!==e?(null!==(r=(h=s)._$Co)&&void 0!==r?r:h._$Co=[])[e]=l:s._$Cl=l),void 0!==l&&(i=xt(t,l._$AS(t,i.values),l,e)),i}class Ot{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){var i;const{el:{content:s},parts:e}=this._$AD,n=(null!==(i=null==t?void 0:t.creationScope)&&void 0!==i?i:rt).importNode(s,!0);$t.currentNode=n;let o=$t.nextNode(),r=0,h=0,l=e[0];for(;void 0!==l;){if(r===l.index){let i;2===l.type?i=new Ct(o,o.nextSibling,this,t):1===l.type?i=new l.ctor(o,l.name,l.strings,this,t):6===l.type&&(i=new Dt(o,this,t)),this._$AV.push(i),l=e[++h]}r!==(null==l?void 0:l.index)&&(o=$t.nextNode(),r++)}return $t.currentNode=rt,n}v(t){let i=0;for(const s of this._$AV)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++}}class Ct{constructor(t,i,s,e){var n;this.type=2,this._$AH=wt,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cp=null===(n=null==e?void 0:e.isConnected)||void 0===n||n}get _$AU(){var t,i;return null!==(i=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==i?i:this._$Cp}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===(null==t?void 0:t.nodeType)&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=xt(this,t,i),lt(t)?t===wt||null==t||""===t?(this._$AH!==wt&&this._$AR(),this._$AH=wt):t!==this._$AH&&t!==yt&&this._(t):void 0!==t._$litType$?this.g(t):void 0!==t.nodeType?this.$(t):(t=>at(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]))(t)?this.T(t):this._(t)}k(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}$(t){this._$AH!==t&&(this._$AR(),this._$AH=this.k(t))}_(t){this._$AH!==wt&&lt(this._$AH)?this._$AA.nextSibling.data=t:this.$(rt.createTextNode(t)),this._$AH=t}g(t){var i;const{values:s,_$litType$:e}=t,n="number"==typeof e?this._$AC(t):(void 0===e.el&&(e.el=Ft.createElement(Et(e.h,e.h[0]),this.options)),e);if((null===(i=this._$AH)||void 0===i?void 0:i._$AD)===n)this._$AH.v(s);else{const t=new Ot(n,this),i=t.u(this.options);t.v(s),this.$(i),this._$AH=t}}_$AC(t){let i=St.get(t.strings);return void 0===i&&St.set(t.strings,i=new Ft(t)),i}T(t){at(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,e=0;for(const n of t)e===i.length?i.push(s=new Ct(this.k(ht()),this.k(ht()),this,this.options)):s=i[e],s._$AI(n),e++;e<i.length&&(this._$AR(s&&s._$AB.nextSibling,e),i.length=e)}_$AR(t=this._$AA.nextSibling,i){var s;for(null===(s=this._$AP)||void 0===s||s.call(this,!1,!0,i);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i}}setConnected(t){var i;void 0===this._$AM&&(this._$Cp=t,null===(i=this._$AP)||void 0===i||i.call(this,t))}}class _t{constructor(t,i,s,e,n){this.type=1,this._$AH=wt,this._$AN=void 0,this.element=t,this.name=i,this._$AM=e,this.options=n,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=wt}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,i=this,s,e){const n=this.strings;let o=!1;if(void 0===n)t=xt(this,t,i,0),o=!lt(t)||t!==this._$AH&&t!==yt,o&&(this._$AH=t);else{const e=t;let r,h;for(t=n[0],r=0;r<n.length-1;r++)h=xt(this,e[s+r],i,r),h===yt&&(h=this._$AH[r]),o||(o=!lt(h)||h!==this._$AH[r]),h===wt?t=wt:t!==wt&&(t+=(null!=h?h:"")+n[r+1]),this._$AH[r]=h}o&&!e&&this.j(t)}j(t){t===wt?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class kt extends _t{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===wt?void 0:t}}const Tt=tt?tt.emptyScript:"";class jt extends _t{constructor(){super(...arguments),this.type=4}j(t){t&&t!==wt?this.element.setAttribute(this.name,Tt):this.element.removeAttribute(this.name)}}class Rt extends _t{constructor(t,i,s,e,n){super(t,i,s,e,n),this.type=5}_$AI(t,i=this){var s;if((t=null!==(s=xt(this,t,i,0))&&void 0!==s?s:wt)===yt)return;const e=this._$AH,n=t===wt&&e!==wt||t.capture!==e.capture||t.once!==e.once||t.passive!==e.passive,o=t!==wt&&(e===wt||n);n&&this.element.removeEventListener(this.name,this,e),o&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var i,s;"function"==typeof this._$AH?this._$AH.call(null!==(s=null===(i=this.options)||void 0===i?void 0:i.host)&&void 0!==s?s:this.element,t):this._$AH.handleEvent(t)}}class Dt{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){xt(this,t)}}const It=Y.litHtmlPolyfillSupport;null==It||It(Ft,Ct),(null!==(X=Y.litHtmlVersions)&&void 0!==X?X:Y.litHtmlVersions=[]).push("2.8.0");
24
+ /**
25
+ * @license
26
+ * Copyright 2017 Google LLC
27
+ * SPDX-License-Identifier: BSD-3-Clause
28
+ */
29
+ var Mt,Ut;class Vt extends p{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var t,i;const s=super.createRenderRoot();return null!==(t=(i=this.renderOptions).renderBefore)&&void 0!==t||(i.renderBefore=s.firstChild),s}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=((t,i,s)=>{var e,n;const o=null!==(e=null==s?void 0:s.renderBefore)&&void 0!==e?e:i;let r=o._$litPart$;if(void 0===r){const t=null!==(n=null==s?void 0:s.renderBefore)&&void 0!==n?n:null;o._$litPart$=r=new Ct(i.insertBefore(ht(),t),t,void 0,null!=s?s:{})}return r._$AI(t),r})(i,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!1)}render(){return yt}}Vt.finalized=!0,Vt._$litElement$=!0,null===(Mt=globalThis.litElementHydrateSupport)||void 0===Mt||Mt.call(globalThis,{LitElement:Vt});const Nt=globalThis.litElementPolyfillSupport;null==Nt||Nt({LitElement:Vt}),(null!==(Ut=globalThis.litElementVersions)&&void 0!==Ut?Ut:globalThis.litElementVersions=[]).push("3.3.3");
30
+ /**
31
+ * @license
32
+ * Copyright 2017 Google LLC
33
+ * SPDX-License-Identifier: BSD-3-Clause
34
+ */
35
+ const Pt=(t,i)=>"method"===i.kind&&i.descriptor&&!("value"in i.descriptor)?{...i,finisher(s){s.createProperty(i.key,t)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:i.key,initializer(){"function"==typeof i.initializer&&(this[i.key]=i.initializer.call(this))},finisher(s){s.createProperty(i.key,t)}},Bt=(t,i,s)=>{i.constructor.createProperty(s,t)};
36
+ /**
37
+ * @license
38
+ * Copyright 2017 Google LLC
39
+ * SPDX-License-Identifier: BSD-3-Clause
40
+ */function Lt(t){return(i,s)=>void 0!==s?Bt(t,i,s):Pt(t,i)
41
+ /**
42
+ * @license
43
+ * Copyright 2017 Google LLC
44
+ * SPDX-License-Identifier: BSD-3-Clause
45
+ */}function zt(t){return Lt({...t,state:!0})}
46
+ /**
47
+ * @license
48
+ * Copyright 2021 Google LLC
49
+ * SPDX-License-Identifier: BSD-3-Clause
50
+ */var qt;null===(qt=window.HTMLSlotElement)||void 0===qt||qt.prototype.assignedElements;
51
+ /**
52
+ * @license
53
+ * Copyright 2023 Nuraly, Laabidi Aymen
54
+ * SPDX-License-Identifier: MIT
55
+ */
56
+ const Ht=((t,...i)=>{const e=1===t.length?t[0]:i.reduce(((i,s,e)=>i+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+t[e+1]),t[0]);return new n(e,t,s)})`
57
+ :host {
58
+ display: block;
59
+ width: 100%;
60
+ }
61
+
62
+ :host([disabled]) {
63
+ opacity: 0.6;
64
+ pointer-events: none;
65
+ }
66
+
67
+ .form-wrapper {
68
+ width: 100%;
69
+ display: flex;
70
+ flex-direction: column;
71
+ gap: var(--nuraly-form-gap, 16px);
72
+ }
73
+
74
+ .form-wrapper[disabled] {
75
+ opacity: 0.6;
76
+ pointer-events: none;
77
+ }
78
+
79
+ /* Form validation states */
80
+ :host([data-validation-state="pristine"]) {
81
+ border-left: 3px solid transparent;
82
+ }
83
+
84
+ :host([data-validation-state="valid"]) {
85
+ border-left: 3px solid #52c41a;
86
+ }
87
+
88
+ :host([data-validation-state="invalid"]) {
89
+ border-left: 3px solid #ff4d4f;
90
+ }
91
+
92
+ :host([data-validation-state="pending"]) {
93
+ border-left: 3px solid #1890ff;
94
+ }
95
+
96
+ /* Form submission states */
97
+ :host([data-submission-state="submitting"]) {
98
+ opacity: 0.8;
99
+ pointer-events: none;
100
+ }
101
+
102
+ :host([data-submission-state="success"]) {
103
+ border-left: 3px solid #52c41a;
104
+ }
105
+
106
+ :host([data-submission-state="error"]) {
107
+ border-left: 3px solid #ff4d4f;
108
+ }
109
+
110
+ /* Responsive design */
111
+ @media (max-width: 768px) {
112
+ .form-wrapper {
113
+ gap: var(--nuraly-form-gap-mobile, 12px);
114
+ }
115
+ }
116
+ `
117
+ /**
118
+ * @license
119
+ * Copyright 2023 Nuraly, Laabidi Aymen
120
+ * SPDX-License-Identifier: MIT
121
+ */;var Kt,Wt;!function(t){t.Pristine="pristine",t.Pending="pending",t.Valid="valid",t.Invalid="invalid",t.Submitted="submitted"}(Kt||(Kt={})),function(t){t.Idle="idle",t.Submitting="submitting",t.Success="success",t.Error="error"}(Wt||(Wt={}));const Jt={VALIDATION_CHANGED:"nr-form-validation-changed",FIELD_CHANGED:"nr-form-field-changed",SUBMIT_ATTEMPT:"nr-form-submit-attempt",SUBMIT_SUCCESS:"nr-form-submit-success",SUBMIT_ERROR:"nr-form-submit-error",RESET:"nr-form-reset"},Zt=t=>class extends t{constructor(){super(...arguments),this.handleSystemThemeChange=()=>{this.closest("[data-theme]")||document.documentElement.hasAttribute("data-theme")||this.requestUpdate()}}connectedCallback(){super.connectedCallback(),this.setupThemeObserver(),this.setupDesignSystemObserver(),this.setupSystemThemeListener()}disconnectedCallback(){var t,i,s;super.disconnectedCallback(),null===(t=this.themeObserver)||void 0===t||t.disconnect(),null===(i=this.designSystemObserver)||void 0===i||i.disconnect(),null===(s=this.mediaQuery)||void 0===s||s.removeEventListener("change",this.handleSystemThemeChange)}get currentTheme(){var t,i;const s=(null===(t=this.closest("[data-theme]"))||void 0===t?void 0:t.getAttribute("data-theme"))||document.documentElement.getAttribute("data-theme");return s||((null===(i=window.matchMedia)||void 0===i?void 0:i.call(window,"(prefers-color-scheme: dark)").matches)?"dark":"light")}get currentDesignSystem(){var t;const i=(null===(t=this.closest("[design-system]"))||void 0===t?void 0:t.getAttribute("design-system"))||document.documentElement.getAttribute("design-system");return"carbon"===i?i:"default"}setupThemeObserver(){this.themeObserver=new MutationObserver((()=>{this.requestUpdate()})),this.themeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]})}setupDesignSystemObserver(){this.designSystemObserver=new MutationObserver((()=>{this.requestUpdate()})),this.designSystemObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["design-system"]})}setupSystemThemeListener(){window.matchMedia&&(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),this.mediaQuery.addEventListener("change",this.handleSystemThemeChange))}},Gt=()=>{var t;return void 0!==globalThis.litElementVersions||"undefined"!=typeof process&&"development"===(null===(t=process.env)||void 0===t?void 0:t.NODE_ENV)||"undefined"!=typeof window&&("localhost"===window.location.hostname||"127.0.0.1"===window.location.hostname)},Qt=t=>class extends t{constructor(){super(...arguments),this.requiredComponents=[]}validateDependencies(){if(Gt())for(const t of this.requiredComponents)if(!this.isComponentAvailable(t))throw new Error(`Required component "${t}" is not registered. Please import and register the component before using ${this.tagName.toLowerCase()}. Example: import '@nuralyui/${t}';`)}validateDependenciesWithHandler(t){if(!Gt())return!0;let i=!0;for(const s of this.requiredComponents)if(!this.isComponentAvailable(s)){i=!1;const e=new Error(`Required component "${s}" is not registered. Please import and register the component before using ${this.tagName.toLowerCase()}.`);t?t(s,e):console.error(e.message)}return i}isComponentAvailable(t){return!!customElements.get(t)}getMissingDependencies(){return this.requiredComponents.filter((t=>!this.isComponentAvailable(t)))}areDependenciesAvailable(){return this.requiredComponents.every((t=>this.isComponentAvailable(t)))}addRequiredComponent(t){this.requiredComponents.includes(t)||this.requiredComponents.push(t)}removeRequiredComponent(t){const i=this.requiredComponents.indexOf(t);i>-1&&this.requiredComponents.splice(i,1)}},Xt=t=>class extends t{dispatchCustomEvent(t,i){this.dispatchEvent(new CustomEvent(t,{detail:i,bubbles:!0,composed:!0}))}dispatchEventWithMetadata(t,i){var s;const e=Object.assign(Object.assign({},i),{timestamp:Date.now(),componentName:(null===(s=this.tagName)||void 0===s?void 0:s.toLowerCase())||"unknown"});this.dispatchCustomEvent(t,e)}dispatchInputEvent(t,i){const s=Object.assign({target:i.target||this,value:i.value,originalEvent:i.originalEvent},i);this.dispatchCustomEvent(t,s)}dispatchFocusEvent(t,i){const s=Object.assign({target:i.target||this,value:i.value,focused:i.focused,cursorPosition:i.cursorPosition,selectedText:i.selectedText},i);this.dispatchCustomEvent(t,s)}dispatchValidationEvent(t,i){var s;const e=Object.assign({target:i.target||this,value:i.value,isValid:null!==(s=i.isValid)&&void 0!==s&&s,error:i.error},i);this.dispatchCustomEvent(t,e)}dispatchActionEvent(t,i){const s=Object.assign({target:i.target||this,action:i.action,previousValue:i.previousValue,newValue:i.newValue},i);this.dispatchCustomEvent(t,s)}isReadonlyKeyAllowed(t){if(t.ctrlKey||t.metaKey){return["KeyA","KeyC"].includes(t.code)}return["Tab","Escape","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(t.key)}isActivationKey(t){return"Enter"===t.key||" "===t.key}};
122
+ /**
123
+ * @license
124
+ * Copyright 2023 Nuraly, Laabidi Aymen
125
+ * SPDX-License-Identifier: MIT
126
+ */
127
+ /**
128
+ * @license
129
+ * Copyright 2023 Nuraly, Laabidi Aymen
130
+ * SPDX-License-Identifier: MIT
131
+ */
132
+ var Yt=function(t,i,s,e){return new(s||(s=Promise))((function(n,o){function r(t){try{l(e.next(t))}catch(t){o(t)}}function h(t){try{l(e.throw(t))}catch(t){o(t)}}function l(t){var i;t.done?n(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(r,h)}l((e=e.apply(t,i||[])).next())}))};class ti{constructor(t){this.host=t,this.fields=new Map,this.validationState=Kt.Pristine,this.validationPromise=null}registerField(t){var i;const s=t.name||t.getAttribute("name")||`field-${Date.now()}`,e={element:t,name:s,value:t.value,isValid:t.getValidationStatus().isValid,validationMessage:t.validationMessage||"",required:null!==(i=t.required)&&void 0!==i&&i,touched:!1,dirty:!1};this.fields.set(s,e),this.addFieldListeners(t,s)}unregisterField(t){const i=this.fields.get(t);i&&(this.removeFieldListeners(i.element),this.fields.delete(t))}addFieldListeners(t,i){t.addEventListener("nr-validation",(t=>this.handleFieldValidation(i,t)))}removeFieldListeners(t){}handleFieldValidation(t,i){const s=this.fields.get(t);if(s){if(i&&i.detail)s.isValid=i.detail.isValid||!1,s.validationMessage=i.detail.validationMessage||"";else{const t=s.element.getValidationStatus();s.isValid=t.isValid,s.validationMessage=s.element.validationMessage||""}this.updateFormValidationState()}}updateFormValidationState(){const t=this.getInvalidFields(),i=0===t.length;this.validationState=i?Kt.Valid:Kt.Invalid;const s={isValid:i,invalidFields:t,validationErrors:this.buildValidationErrors(),summary:i?"Form is valid":`${t.length} field(s) have errors`};this.dispatchValidationEvent(s)}buildValidationErrors(){const t={};for(const[i,s]of this.fields)!s.isValid&&s.validationMessage&&(t[i]=s.validationMessage);return t}validateForm(){return this.validationPromise||(this.validationState=Kt.Pending,this.validationPromise=this.performValidation()),this.validationPromise}performValidation(){return Yt(this,void 0,void 0,(function*(){const t=[],i={};for(const[s,e]of this.fields){const n=e.element.getValidationStatus().isValid;e.isValid=n,e.validationMessage=e.element.validationMessage||"",n||(t.push(e),i[s]=e.validationMessage)}const s=0===t.length;this.validationState=s?Kt.Valid:Kt.Invalid;const e={isValid:s,invalidFields:t,validationErrors:i,summary:s?"Form is valid":`${t.length} field(s) have errors`};return this.dispatchValidationEvent(e),this.validationPromise=null,e}))}getValidationState(){return this.validationState}getFields(){return Array.from(this.fields.values())}getInvalidFields(){return Array.from(this.fields.values()).filter((t=>!t.isValid))}isValid(){return this.validationState===Kt.Valid&&Array.from(this.fields.values()).every((t=>t.isValid))}focusFirstInvalidField(){const t=Array.from(this.fields.values()).find((t=>!t.isValid));return!(!t||"function"!=typeof t.element.focus)&&(t.element.focus(),!0)}reset(){for(const t of this.fields.values())"clearValidation"in t.element&&"function"==typeof t.element.clearValidation&&t.element.clearValidation(),"value"in t.element&&(t.element.value=""),t.touched=!1,t.dirty=!1,t.isValid=!0,t.validationMessage="";this.validationState=Kt.Pristine,this.dispatchResetEvent()}dispatchValidationEvent(t){var i,s;null===(s=(i=this.host).dispatchCustomEvent)||void 0===s||s.call(i,Jt.VALIDATION_CHANGED,{validationResult:t})}dispatchResetEvent(){var t,i;null===(i=(t=this.host).dispatchCustomEvent)||void 0===i||i.call(t,Jt.RESET,{})}}
133
+ /**
134
+ * @license
135
+ * Copyright 2023 Nuraly, Laabidi Aymen
136
+ * SPDX-License-Identifier: MIT
137
+ */var ii=function(t,i,s,e){return new(s||(s=Promise))((function(n,o){function r(t){try{l(e.next(t))}catch(t){o(t)}}function h(t){try{l(e.throw(t))}catch(t){o(t)}}function l(t){var i;t.done?n(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(r,h)}l((e=e.apply(t,i||[])).next())}))};class si{constructor(t){this.host=t,this.submissionState=Wt.Idle,this.lastSubmissionData=null}getSubmissionState(){return this.submissionState}isSubmitting(){return this.submissionState===Wt.Submitting}collectFormData(){const t=new FormData,i={},s={};return this.getFormFields().forEach((e=>{const n=e.name||e.getAttribute("name");if(!n)return;const o=e.value;null!=o&&t.append(n,String(o)),i[n]=o,s[n]={element:e,value:o,name:n,type:e.tagName.toLowerCase(),required:e.required||!1,disabled:e.disabled||!1}})),{formData:t,jsonData:i,fields:s}}submitForm(t){return ii(this,void 0,void 0,(function*(){if(this.isSubmitting())throw new Error("Form is already submitting");try{this.setSubmissionState(Wt.Submitting);const i=this.host.validationController;if(i){const t=yield i.validateForm();if(!t.isValid)throw i.focusFirstInvalidField(),this.dispatchSubmitAttemptEvent(t),new Error(`Form validation failed: ${t.summary}`)}const s=this.collectFormData();return t&&(Object.assign(s.jsonData,t),Object.entries(t).forEach((([t,i])=>{s.formData.append(t,String(i))}))),this.lastSubmissionData=s,this.dispatchSubmitSuccessEvent(s),this.setSubmissionState(Wt.Success),s}catch(t){throw this.setSubmissionState(Wt.Error),this.dispatchSubmitErrorEvent(t),t}}))}resetSubmission(){this.submissionState=Wt.Idle,this.lastSubmissionData=null}getLastSubmissionData(){return this.lastSubmissionData}getFormFields(){var t;const i=this.host,s=[],e=["nr-input","nr-select","nr-radio","nr-checkbox","nr-textarea","nr-timepicker","nr-datepicker","input","select","textarea"];e.forEach((t=>{i.querySelectorAll(t).forEach((t=>{(t.name||t.getAttribute("name"))&&s.push(t)}))}));return((null===(t=i.shadowRoot)||void 0===t?void 0:t.querySelectorAll("slot"))||[]).forEach((t=>{t.assignedElements({flatten:!0}).forEach((t=>{e.forEach((i=>{if(t.matches&&t.matches(i)){const i=t;(i.name||i.getAttribute("name"))&&s.push(i)}t.querySelectorAll(i).forEach((t=>{const i=t;(i.name||i.getAttribute("name"))&&s.push(i)}))}))}))})),s}setSubmissionState(t){var i,s;this.submissionState=t,null===(s=(i=this.host).requestUpdate)||void 0===s||s.call(i)}dispatchSubmitAttemptEvent(t){var i,s;null===(s=(i=this.host).dispatchCustomEvent)||void 0===s||s.call(i,Jt.SUBMIT_ATTEMPT,{validationResult:t})}dispatchSubmitSuccessEvent(t){var i,s;null===(s=(i=this.host).dispatchCustomEvent)||void 0===s||s.call(i,Jt.SUBMIT_SUCCESS,{formData:t})}dispatchSubmitErrorEvent(t){var i,s;null===(s=(i=this.host).dispatchCustomEvent)||void 0===s||s.call(i,Jt.SUBMIT_ERROR,{error:t})}}
138
+ /**
139
+ * @license
140
+ * Copyright 2023 Nuraly, Laabidi Aymen
141
+ * SPDX-License-Identifier: MIT
142
+ */var ei=function(t,i,s,e){for(var n,o=arguments.length,r=o<3?i:null===e?e=Object.getOwnPropertyDescriptor(i,s):e,h=t.length-1;h>=0;h--)(n=t[h])&&(r=(o<3?n(r):o>3?n(i,s,r):n(i,s))||r);return o>3&&r&&Object.defineProperty(i,s,r),r},ni=function(t,i,s,e){return new(s||(s=Promise))((function(n,o){function r(t){try{l(e.next(t))}catch(t){o(t)}}function h(t){try{l(e.throw(t))}catch(t){o(t)}}function l(t){var i;t.done?n(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(r,h)}l((e=e.apply(t,i||[])).next())}))};let oi=class extends((t=>Qt(Zt(Xt(t))))(Vt)){constructor(){super(...arguments),this.config={validateOnChange:!1,validateOnBlur:!0,showErrorsImmediately:!1,preventInvalidSubmission:!0,resetOnSuccess:!1,validationDelay:300},this.validateOnChange=!1,this.validateOnBlur=!0,this.preventInvalidSubmission=!0,this.resetOnSuccess=!1,this.method="POST",this.enctype="multipart/form-data",this.disabled=!1,this._validationState=Kt.Pristine,this._submissionState=Wt.Idle,this.validationController=new ti(this),this.submissionController=new si(this),this.handleValidationChanged=t=>{const i=t.detail.validationResult;i&&(this._validationState=i.isValid?Kt.Valid:Kt.Invalid)}}get validationState(){return this._validationState}get submissionState(){return this._submissionState}connectedCallback(){super.connectedCallback(),this.setupFormObserver()}disconnectedCallback(){super.disconnectedCallback(),this.cleanupFormObserver()}willUpdate(t){super.willUpdate(t),(t.has("validateOnChange")||t.has("validateOnBlur")||t.has("preventInvalidSubmission")||t.has("resetOnSuccess"))&&(this.config=Object.assign(Object.assign({},this.config),{validateOnChange:this.validateOnChange,validateOnBlur:this.validateOnBlur,preventInvalidSubmission:this.preventInvalidSubmission,resetOnSuccess:this.resetOnSuccess}))}firstUpdated(){this.registerExistingFields(),this.setupFormEvents()}setupFormObserver(){const t=new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&this.registerFieldsInElement(t)}))}))}));t.observe(this,{childList:!0,subtree:!0}),this._formObserver=t}cleanupFormObserver(){const t=this._formObserver;t&&t.disconnect()}registerExistingFields(){this.registerFieldsInElement(this)}registerFieldsInElement(t){["nr-input","nr-select","nr-radio","nr-checkbox","nr-textarea","nr-timepicker","nr-datepicker"].forEach((i=>{t.querySelectorAll(i).forEach((t=>{t.getAttribute("name")&&this.validationController.registerField(t)}))}))}setupFormEvents(){this.addEventListener("submit",this.handleFormSubmit),this.addEventListener("reset",this.handleFormReset),this.addEventListener(Jt.VALIDATION_CHANGED,this.handleValidationChanged)}handleFormSubmit(t){return ni(this,void 0,void 0,(function*(){if(t.preventDefault(),!this.disabled)try{const t=yield this.submissionController.submitForm();this.resetOnSuccess&&this.reset(),this.action&&this.performNativeSubmission(t.formData)}catch(t){console.error("Form submission failed:",t)}}))}handleFormReset(t){t.preventDefault(),this.reset()}performNativeSubmission(t){const i=document.createElement("form");i.action=this.action,i.method=this.method,i.enctype=this.enctype,this.target&&(i.target=this.target);for(const[s,e]of t.entries()){const t=document.createElement("input");t.type="hidden",t.name=s,t.value=e,i.appendChild(t)}document.body.appendChild(i),i.submit(),document.body.removeChild(i)}validate(){return ni(this,void 0,void 0,(function*(){return(yield this.validationController.validateForm()).isValid}))}submit(t){return ni(this,void 0,void 0,(function*(){yield this.submissionController.submitForm(t)}))}reset(){this.validationController.reset(),this.submissionController.resetSubmission(),this._validationState=Kt.Pristine,this._submissionState=Wt.Idle}get isValid(){return this.validationController.isValid()}get isSubmitting(){return this.submissionController.isSubmitting()}getFormData(){return this.submissionController.collectFormData()}getInvalidFields(){return this.validationController.getInvalidFields()}getFieldsValue(t){const i=this.getFormData().jsonData;if(t&&t.length>0){const s={};return t.forEach((t=>{t in i&&(s[t]=i[t])})),s}return i}getFieldValue(t){return this.getFieldsValue()[t]}setFieldsValue(t){Object.entries(t).forEach((([t,i])=>{this.setFieldValue(t,i)}))}setFieldValue(t,i){const s=this.validationController.getFields().find((i=>i.name===t));s&&s.element&&(s.element.value=i,s.value=i,s.element.dispatchEvent(new Event("change",{bubbles:!0})))}validateFields(t){return ni(this,void 0,void 0,(function*(){const i=yield this.validationController.validateForm();if(t&&t.length>0){const s={};if(t.forEach((t=>{i.validationErrors[t]&&(s[t]=i.validationErrors[t])})),Object.keys(s).length>0)throw new Error(JSON.stringify(s));return this.getFieldsValue(t)}if(!i.isValid)throw new Error(JSON.stringify(i.validationErrors));return this.getFieldsValue()}))}resetFields(t){if(!t||0===t.length)return void this.reset();const i=this.validationController.getFields();t.forEach((t=>{const s=i.find((i=>i.name===t));s&&s.element&&(s.element.value="",s.value="",s.touched=!1,s.dirty=!1,s.isValid=!0,s.validationMessage="",s.element.dispatchEvent(new Event("change",{bubbles:!0})))}))}getFieldError(t){const i=this.validationController.getFields().find((i=>i.name===t));return i&&!i.isValid?i.validationMessage:null}getFieldsError(t){const i=this.validationController.getFields(),s={},e=t?i.filter((i=>t.includes(i.name))):i;return e.forEach((t=>{s[t.name]=t.isValid?null:t.validationMessage})),s}isFieldTouched(t){const i=this.validationController.getFields().find((i=>i.name===t));return!!i&&i.touched}isFieldsTouched(t){const i=this.validationController.getFields(),s=t?i.filter((i=>t.includes(i.name))):i;return s.some((t=>t.touched))}isFieldDirty(t){const i=this.validationController.getFields().find((i=>i.name===t));return!!i&&i.dirty}isFieldsDirty(t){const i=this.validationController.getFields(),s=t?i.filter((i=>t.includes(i.name))):i;return s.some((t=>t.dirty))}getFieldInstance(t){const i=this.validationController.getFields().find((i=>i.name===t));return i?i.element:null}scrollToField(t){if(t){const i=this.getFieldInstance(t);return!!i&&(i.scrollIntoView({behavior:"smooth",block:"center"}),"function"==typeof i.focus&&i.focus(),!0)}return this.validationController.focusFirstInvalidField()}finish(){return ni(this,void 0,void 0,(function*(){try{const t=yield this.validateFields();return yield this.submit(),t}catch(t){throw this.scrollToField(),t}}))}getFieldsWithErrors(){return this.validationController.getFields().filter((t=>!t.isValid)).map((t=>t.name))}hasErrors(){return this.getFieldsWithErrors().length>0}getFormState(){const t=this.validationController.getFields();return{isValid:this.isValid,isSubmitting:this.isSubmitting,hasErrors:this.hasErrors(),errorCount:this.getFieldsWithErrors().length,fieldCount:t.length,touchedFields:t.filter((t=>t.touched)).map((t=>t.name)),dirtyFields:t.filter((t=>t.dirty)).map((t=>t.name)),invalidFields:this.getFieldsWithErrors()}}setLoading(t){this.disabled=t,this.requestUpdate()}render(){return bt`
143
+ <form
144
+ action="${this.action||""}"
145
+ method="${this.method.toLowerCase()}"
146
+ enctype="${this.enctype}"
147
+ target="${this.target||""}"
148
+ class="form-wrapper"
149
+ data-disabled="${this.disabled}"
150
+ novalidate
151
+ >
152
+ <slot></slot>
153
+ </form>
154
+ `}};oi.styles=Ht,ei([Lt({type:Object})],oi.prototype,"config",void 0),ei([Lt({type:Boolean,attribute:"validate-on-change"})],oi.prototype,"validateOnChange",void 0),ei([Lt({type:Boolean,attribute:"validate-on-blur"})],oi.prototype,"validateOnBlur",void 0),ei([Lt({type:Boolean,attribute:"prevent-invalid-submission"})],oi.prototype,"preventInvalidSubmission",void 0),ei([Lt({type:Boolean,attribute:"reset-on-success"})],oi.prototype,"resetOnSuccess",void 0),ei([Lt({type:String})],oi.prototype,"action",void 0),ei([Lt({type:String})],oi.prototype,"method",void 0),ei([Lt({type:String,attribute:"enctype"})],oi.prototype,"enctype",void 0),ei([Lt({type:String})],oi.prototype,"target",void 0),ei([Lt({type:Boolean,reflect:!0})],oi.prototype,"disabled",void 0),ei([zt()],oi.prototype,"_validationState",void 0),ei([zt()],oi.prototype,"_submissionState",void 0),oi=ei([(t=>i=>"function"==typeof i?((t,i)=>(customElements.define(t,i),i))(t,i):((t,i)=>{const{kind:s,elements:e}=i;return{kind:s,elements:e,finisher(i){customElements.define(t,i)}}})(t,i))("nr-form")],oi);export{Jt as FORM_EVENTS,si as FormSubmissionController,Wt as FormSubmissionState,ti as FormValidationController,Kt as FormValidationState,oi as NrFormElement};
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Nuraly, Laabidi Aymen
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import { FormSubmissionData, FormSubmissionState } from '../form.types.js';
7
+ /**
8
+ * Controller that handles form submission logic
9
+ */
10
+ export declare class FormSubmissionController {
11
+ private host;
12
+ private submissionState;
13
+ private lastSubmissionData;
14
+ constructor(host: any);
15
+ /**
16
+ * Get current submission state
17
+ */
18
+ getSubmissionState(): FormSubmissionState;
19
+ /**
20
+ * Check if form is currently submitting
21
+ */
22
+ isSubmitting(): boolean;
23
+ /**
24
+ * Collect form data from all registered fields
25
+ */
26
+ collectFormData(): FormSubmissionData;
27
+ /**
28
+ * Submit form with validation
29
+ */
30
+ submitForm(customData?: Record<string, any>): Promise<FormSubmissionData>;
31
+ /**
32
+ * Reset submission state
33
+ */
34
+ resetSubmission(): void;
35
+ /**
36
+ * Get last submission data
37
+ */
38
+ getLastSubmissionData(): FormSubmissionData | null;
39
+ /**
40
+ * Get all form field elements from the host
41
+ */
42
+ private getFormFields;
43
+ /**
44
+ * Set submission state and update host
45
+ */
46
+ private setSubmissionState;
47
+ /**
48
+ * Dispatch submit attempt event
49
+ */
50
+ private dispatchSubmitAttemptEvent;
51
+ /**
52
+ * Dispatch submit success event
53
+ */
54
+ private dispatchSubmitSuccessEvent;
55
+ /**
56
+ * Dispatch submit error event
57
+ */
58
+ private dispatchSubmitErrorEvent;
59
+ }
60
+ //# sourceMappingURL=submission.controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submission.controller.d.ts","sourceRoot":"","sources":["../../../../src/components/form/controllers/submission.controller.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EAGpB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,qBAAa,wBAAwB;IAIvB,OAAO,CAAC,IAAI;IAHxB,OAAO,CAAC,eAAe,CAAiD;IACxE,OAAO,CAAC,kBAAkB,CAAmC;gBAEzC,IAAI,EAAE,GAAG;IAE7B;;OAEG;IACH,kBAAkB,IAAI,mBAAmB;IAIzC;;OAEG;IACH,YAAY,IAAI,OAAO;IAIvB;;OAEG;IACH,eAAe,IAAI,kBAAkB;IAsCrC;;OAEG;IACG,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAsD/E;;OAEG;IACH,eAAe,IAAI,IAAI;IAKvB;;OAEG;IACH,qBAAqB,IAAI,kBAAkB,GAAG,IAAI;IAIlD;;OAEG;IACH,OAAO,CAAC,aAAa;IAwDrB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAK1B;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAMlC;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAMlC;;OAEG;IACH,OAAO,CAAC,wBAAwB;CAKjC"}
@@ -0,0 +1,220 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Nuraly, Laabidi Aymen
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ import { FormSubmissionState, FORM_EVENTS } from '../form.types.js';
16
+ /**
17
+ * Controller that handles form submission logic
18
+ */
19
+ export class FormSubmissionController {
20
+ constructor(host) {
21
+ this.host = host;
22
+ this.submissionState = FormSubmissionState.Idle;
23
+ this.lastSubmissionData = null;
24
+ }
25
+ /**
26
+ * Get current submission state
27
+ */
28
+ getSubmissionState() {
29
+ return this.submissionState;
30
+ }
31
+ /**
32
+ * Check if form is currently submitting
33
+ */
34
+ isSubmitting() {
35
+ return this.submissionState === FormSubmissionState.Submitting;
36
+ }
37
+ /**
38
+ * Collect form data from all registered fields
39
+ */
40
+ collectFormData() {
41
+ const formData = new FormData();
42
+ const jsonData = {};
43
+ const fields = {};
44
+ // Get all form field elements
45
+ const formFields = this.getFormFields();
46
+ formFields.forEach(element => {
47
+ const name = element.name || element.getAttribute('name');
48
+ if (!name)
49
+ return;
50
+ const value = element.value;
51
+ // Add to FormData
52
+ if (value !== null && value !== undefined) {
53
+ formData.append(name, String(value));
54
+ }
55
+ // Add to JSON data
56
+ jsonData[name] = value;
57
+ fields[name] = {
58
+ element,
59
+ value,
60
+ name,
61
+ type: element.tagName.toLowerCase(),
62
+ required: element.required || false,
63
+ disabled: element.disabled || false
64
+ };
65
+ });
66
+ return {
67
+ formData,
68
+ jsonData,
69
+ fields
70
+ };
71
+ }
72
+ /**
73
+ * Submit form with validation
74
+ */
75
+ submitForm(customData) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ if (this.isSubmitting()) {
78
+ throw new Error('Form is already submitting');
79
+ }
80
+ try {
81
+ this.setSubmissionState(FormSubmissionState.Submitting);
82
+ // Validate form first
83
+ const validationController = this.host.validationController;
84
+ if (validationController) {
85
+ const validationResult = yield validationController.validateForm();
86
+ if (!validationResult.isValid) {
87
+ // Focus first invalid field
88
+ validationController.focusFirstInvalidField();
89
+ // Dispatch submit attempt event
90
+ this.dispatchSubmitAttemptEvent(validationResult);
91
+ throw new Error(`Form validation failed: ${validationResult.summary}`);
92
+ }
93
+ }
94
+ // Collect form data
95
+ const submissionData = this.collectFormData();
96
+ // Merge custom data if provided
97
+ if (customData) {
98
+ Object.assign(submissionData.jsonData, customData);
99
+ Object.entries(customData).forEach(([key, value]) => {
100
+ submissionData.formData.append(key, String(value));
101
+ });
102
+ }
103
+ this.lastSubmissionData = submissionData;
104
+ // Dispatch submit success event
105
+ this.dispatchSubmitSuccessEvent(submissionData);
106
+ this.setSubmissionState(FormSubmissionState.Success);
107
+ return submissionData;
108
+ }
109
+ catch (error) {
110
+ this.setSubmissionState(FormSubmissionState.Error);
111
+ // Dispatch submit error event
112
+ this.dispatchSubmitErrorEvent(error);
113
+ throw error;
114
+ }
115
+ });
116
+ }
117
+ /**
118
+ * Reset submission state
119
+ */
120
+ resetSubmission() {
121
+ this.submissionState = FormSubmissionState.Idle;
122
+ this.lastSubmissionData = null;
123
+ }
124
+ /**
125
+ * Get last submission data
126
+ */
127
+ getLastSubmissionData() {
128
+ return this.lastSubmissionData;
129
+ }
130
+ /**
131
+ * Get all form field elements from the host
132
+ */
133
+ getFormFields() {
134
+ var _a;
135
+ const host = this.host;
136
+ const fields = [];
137
+ // Query for all potential form field elements
138
+ const selectors = [
139
+ 'nr-input',
140
+ 'nr-select',
141
+ 'nr-radio',
142
+ 'nr-checkbox',
143
+ 'nr-textarea',
144
+ 'nr-timepicker',
145
+ 'nr-datepicker',
146
+ 'input',
147
+ 'select',
148
+ 'textarea'
149
+ ];
150
+ // Search in light DOM
151
+ selectors.forEach(selector => {
152
+ const elements = host.querySelectorAll(selector);
153
+ elements.forEach((element) => {
154
+ if (element.name || element.getAttribute('name')) {
155
+ fields.push(element);
156
+ }
157
+ });
158
+ });
159
+ // Search in slotted content
160
+ const slots = ((_a = host.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('slot')) || [];
161
+ slots.forEach((slot) => {
162
+ const assignedElements = slot.assignedElements({ flatten: true });
163
+ assignedElements.forEach(element => {
164
+ selectors.forEach(selector => {
165
+ if (element.matches && element.matches(selector)) {
166
+ const fieldElement = element;
167
+ if (fieldElement.name || fieldElement.getAttribute('name')) {
168
+ fields.push(fieldElement);
169
+ }
170
+ }
171
+ // Also search within the element
172
+ const nestedFields = element.querySelectorAll(selector);
173
+ nestedFields.forEach((nested) => {
174
+ const fieldElement = nested;
175
+ if (fieldElement.name || fieldElement.getAttribute('name')) {
176
+ fields.push(fieldElement);
177
+ }
178
+ });
179
+ });
180
+ });
181
+ });
182
+ return fields;
183
+ }
184
+ /**
185
+ * Set submission state and update host
186
+ */
187
+ setSubmissionState(state) {
188
+ var _a, _b;
189
+ this.submissionState = state;
190
+ (_b = (_a = this.host).requestUpdate) === null || _b === void 0 ? void 0 : _b.call(_a);
191
+ }
192
+ /**
193
+ * Dispatch submit attempt event
194
+ */
195
+ dispatchSubmitAttemptEvent(validationResult) {
196
+ var _a, _b;
197
+ (_b = (_a = this.host).dispatchCustomEvent) === null || _b === void 0 ? void 0 : _b.call(_a, FORM_EVENTS.SUBMIT_ATTEMPT, {
198
+ validationResult
199
+ });
200
+ }
201
+ /**
202
+ * Dispatch submit success event
203
+ */
204
+ dispatchSubmitSuccessEvent(data) {
205
+ var _a, _b;
206
+ (_b = (_a = this.host).dispatchCustomEvent) === null || _b === void 0 ? void 0 : _b.call(_a, FORM_EVENTS.SUBMIT_SUCCESS, {
207
+ formData: data
208
+ });
209
+ }
210
+ /**
211
+ * Dispatch submit error event
212
+ */
213
+ dispatchSubmitErrorEvent(error) {
214
+ var _a, _b;
215
+ (_b = (_a = this.host).dispatchCustomEvent) === null || _b === void 0 ? void 0 : _b.call(_a, FORM_EVENTS.SUBMIT_ERROR, {
216
+ error
217
+ });
218
+ }
219
+ }
220
+ //# sourceMappingURL=submission.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submission.controller.js","sourceRoot":"","sources":["../../../../src/components/form/controllers/submission.controller.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * @license\n * Copyright 2023 Nuraly, Laabidi Aymen\n * SPDX-License-Identifier: MIT\n */\n\nimport { \n FormSubmissionData, \n FormSubmissionState, \n FormFieldCapable,\n FORM_EVENTS \n} from '../form.types.js';\n\n/**\n * Controller that handles form submission logic\n */\nexport class FormSubmissionController {\n private submissionState: FormSubmissionState = FormSubmissionState.Idle;\n private lastSubmissionData: FormSubmissionData | null = null;\n\n constructor(private host: any) {}\n\n /**\n * Get current submission state\n */\n getSubmissionState(): FormSubmissionState {\n return this.submissionState;\n }\n\n /**\n * Check if form is currently submitting\n */\n isSubmitting(): boolean {\n return this.submissionState === FormSubmissionState.Submitting;\n }\n\n /**\n * Collect form data from all registered fields\n */\n collectFormData(): FormSubmissionData {\n const formData = new FormData();\n const jsonData: Record<string, any> = {};\n const fields: Record<string, any> = {};\n\n // Get all form field elements\n const formFields = this.getFormFields();\n\n formFields.forEach(element => {\n const name = element.name || element.getAttribute('name');\n if (!name) return;\n\n const value = element.value;\n \n // Add to FormData\n if (value !== null && value !== undefined) {\n formData.append(name, String(value));\n }\n\n // Add to JSON data\n jsonData[name] = value;\n fields[name] = {\n element,\n value,\n name,\n type: element.tagName.toLowerCase(),\n required: element.required || false,\n disabled: element.disabled || false\n };\n });\n\n return {\n formData,\n jsonData,\n fields\n };\n }\n\n /**\n * Submit form with validation\n */\n async submitForm(customData?: Record<string, any>): Promise<FormSubmissionData> {\n if (this.isSubmitting()) {\n throw new Error('Form is already submitting');\n }\n\n try {\n this.setSubmissionState(FormSubmissionState.Submitting);\n\n // Validate form first\n const validationController = (this.host as any).validationController;\n if (validationController) {\n const validationResult = await validationController.validateForm();\n \n if (!validationResult.isValid) {\n // Focus first invalid field\n validationController.focusFirstInvalidField();\n \n // Dispatch submit attempt event\n this.dispatchSubmitAttemptEvent(validationResult);\n \n throw new Error(`Form validation failed: ${validationResult.summary}`);\n }\n }\n\n // Collect form data\n const submissionData = this.collectFormData();\n \n // Merge custom data if provided\n if (customData) {\n Object.assign(submissionData.jsonData, customData);\n Object.entries(customData).forEach(([key, value]) => {\n submissionData.formData.append(key, String(value));\n });\n }\n\n this.lastSubmissionData = submissionData;\n\n // Dispatch submit success event\n this.dispatchSubmitSuccessEvent(submissionData);\n \n this.setSubmissionState(FormSubmissionState.Success);\n \n return submissionData;\n\n } catch (error) {\n this.setSubmissionState(FormSubmissionState.Error);\n \n // Dispatch submit error event\n this.dispatchSubmitErrorEvent(error as Error);\n \n throw error;\n }\n }\n\n /**\n * Reset submission state\n */\n resetSubmission(): void {\n this.submissionState = FormSubmissionState.Idle;\n this.lastSubmissionData = null;\n }\n\n /**\n * Get last submission data\n */\n getLastSubmissionData(): FormSubmissionData | null {\n return this.lastSubmissionData;\n }\n\n /**\n * Get all form field elements from the host\n */\n private getFormFields(): (HTMLElement & FormFieldCapable)[] {\n const host = this.host;\n const fields: (HTMLElement & FormFieldCapable)[] = [];\n\n // Query for all potential form field elements\n const selectors = [\n 'nr-input',\n 'nr-select', \n 'nr-radio',\n 'nr-checkbox',\n 'nr-textarea',\n 'nr-timepicker',\n 'nr-datepicker',\n 'input',\n 'select',\n 'textarea'\n ];\n\n // Search in light DOM\n selectors.forEach(selector => {\n const elements = host.querySelectorAll(selector);\n elements.forEach((element: HTMLElement & FormFieldCapable) => {\n if (element.name || element.getAttribute('name')) {\n fields.push(element);\n }\n });\n });\n\n // Search in slotted content\n const slots = host.shadowRoot?.querySelectorAll('slot') || [];\n slots.forEach((slot: HTMLSlotElement) => {\n const assignedElements = slot.assignedElements({ flatten: true });\n assignedElements.forEach(element => {\n selectors.forEach(selector => {\n if (element.matches && element.matches(selector)) {\n const fieldElement = element as HTMLElement & FormFieldCapable;\n if (fieldElement.name || fieldElement.getAttribute('name')) {\n fields.push(fieldElement);\n }\n }\n \n // Also search within the element\n const nestedFields = element.querySelectorAll(selector);\n nestedFields.forEach((nested) => {\n const fieldElement = nested as HTMLElement & FormFieldCapable;\n if (fieldElement.name || fieldElement.getAttribute('name')) {\n fields.push(fieldElement);\n }\n });\n });\n });\n });\n\n return fields;\n }\n\n /**\n * Set submission state and update host\n */\n private setSubmissionState(state: FormSubmissionState): void {\n this.submissionState = state;\n (this.host as any).requestUpdate?.();\n }\n\n /**\n * Dispatch submit attempt event\n */\n private dispatchSubmitAttemptEvent(validationResult: any): void {\n (this.host as any).dispatchCustomEvent?.(FORM_EVENTS.SUBMIT_ATTEMPT, {\n validationResult\n });\n }\n\n /**\n * Dispatch submit success event\n */\n private dispatchSubmitSuccessEvent(data: FormSubmissionData): void {\n (this.host as any).dispatchCustomEvent?.(FORM_EVENTS.SUBMIT_SUCCESS, {\n formData: data\n });\n }\n\n /**\n * Dispatch submit error event\n */\n private dispatchSubmitErrorEvent(error: Error): void {\n (this.host as any).dispatchCustomEvent?.(FORM_EVENTS.SUBMIT_ERROR, {\n error\n });\n }\n}\n"]}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Nuraly, Laabidi Aymen
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import { FormField, FormValidationResult, FormValidationState } from '../form.types.js';
7
+ import { ValidatableComponent } from '../../../shared/validation.types.js';
8
+ /**
9
+ * Controller that coordinates validation across all form fields
10
+ * This does NOT perform validation - it coordinates existing component validations
11
+ */
12
+ export declare class FormValidationController {
13
+ private host;
14
+ private fields;
15
+ private validationState;
16
+ private validationPromise;
17
+ constructor(host: any);
18
+ /**
19
+ * Register a form field for validation coordination
20
+ */
21
+ registerField(element: HTMLElement & ValidatableComponent): void;
22
+ /**
23
+ * Unregister a form field
24
+ */
25
+ unregisterField(name: string): void;
26
+ /**
27
+ * Add event listeners to a form field
28
+ */
29
+ private addFieldListeners;
30
+ /**
31
+ * Remove event listeners from a form field
32
+ */
33
+ private removeFieldListeners;
34
+ /**
35
+ * Handle field validation event
36
+ */
37
+ private handleFieldValidation;
38
+ /**
39
+ * Update form validation state based on current field states
40
+ */
41
+ private updateFormValidationState;
42
+ /**
43
+ * Build validation errors object from current field states
44
+ */
45
+ private buildValidationErrors;
46
+ /**
47
+ * Validate all form fields (coordinates existing validations)
48
+ */
49
+ validateForm(): Promise<FormValidationResult>;
50
+ /**
51
+ * Perform the actual validation coordination
52
+ */
53
+ private performValidation;
54
+ /**
55
+ * Get current validation state
56
+ */
57
+ getValidationState(): FormValidationState;
58
+ /**
59
+ * Get all registered fields
60
+ */
61
+ getFields(): FormField[];
62
+ /**
63
+ * Get invalid fields
64
+ */
65
+ getInvalidFields(): FormField[];
66
+ /**
67
+ * Check if form is valid
68
+ */
69
+ isValid(): boolean;
70
+ /**
71
+ * Focus first invalid field
72
+ */
73
+ focusFirstInvalidField(): boolean;
74
+ /**
75
+ * Reset all fields
76
+ */
77
+ reset(): void;
78
+ /**
79
+ * Dispatch validation event
80
+ */
81
+ private dispatchValidationEvent;
82
+ /**
83
+ * Dispatch reset event
84
+ */
85
+ private dispatchResetEvent;
86
+ }
87
+ //# sourceMappingURL=validation.controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.controller.d.ts","sourceRoot":"","sources":["../../../../src/components/form/controllers/validation.controller.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACH,SAAS,EACT,oBAAoB,EACpB,mBAAmB,EAEtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E;;;GAGG;AACH,qBAAa,wBAAwB;IAKvB,OAAO,CAAC,IAAI;IAJxB,OAAO,CAAC,MAAM,CAAqC;IACnD,OAAO,CAAC,eAAe,CAAqD;IAC5E,OAAO,CAAC,iBAAiB,CAA8C;gBAEnD,IAAI,EAAE,GAAG;IAE7B;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,oBAAoB,GAAG,IAAI;IAoBhE;;OAEG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQnC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAM5B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAmB7B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAgBjC;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAY7B;;OAEG;IACH,YAAY,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAa7C;;OAEG;YACW,iBAAiB;IAoC/B;;OAEG;IACH,kBAAkB,IAAI,mBAAmB;IAIzC;;OAEG;IACH,SAAS,IAAI,SAAS,EAAE;IAIxB;;OAEG;IACH,gBAAgB,IAAI,SAAS,EAAE;IAI/B;;OAEG;IACH,OAAO,IAAI,OAAO;IAKlB;;OAEG;IACH,sBAAsB,IAAI,OAAO;IASjC;;OAEG;IACH,KAAK,IAAI,IAAI;IAsBb;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAM/B;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAG3B"}