@nuralyui/form 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bundle.js +6 -134
  2. package/package.json +1 -1
package/bundle.js CHANGED
@@ -1,154 +1,26 @@
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
- `
1
+ import{css as t,LitElement as i,html as e}from"lit";import{property as s,state as n,customElement as r}from"lit/decorators.js";import{NuralyUIBaseMixin as o}from"@nuralyui/common/mixins";
117
2
  /**
118
3
  * @license
119
4
  * Copyright 2023 Nuraly, Laabidi Aymen
120
5
  * 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}};
6
+ */const a=t`:host{display:block;width:100%}:host([disabled]){opacity:.6;pointer-events:none}.form-wrapper{width:100%;display:flex;flex-direction:column;gap:var(--nuraly-form-gap,16px)}.form-wrapper[disabled]{opacity:.6;pointer-events:none}:host([data-validation-state=pristine]){border-left:3px solid transparent}:host([data-validation-state=valid]){border-left:3px solid #52c41a}:host([data-validation-state=invalid]){border-left:3px solid #ff4d4f}:host([data-validation-state=pending]){border-left:3px solid #1890ff}:host([data-submission-state=submitting]){opacity:.8;pointer-events:none}:host([data-submission-state=success]){border-left:3px solid #52c41a}:host([data-submission-state=error]){border-left:3px solid #ff4d4f}@media (max-width:768px){.form-wrapper{gap:var(--nuraly-form-gap-mobile,12px)}}`
122
7
  /**
123
8
  * @license
124
9
  * Copyright 2023 Nuraly, Laabidi Aymen
125
10
  * SPDX-License-Identifier: MIT
126
- */
11
+ */;var d,h;!function(t){t.Pristine="pristine",t.Pending="pending",t.Valid="valid",t.Invalid="invalid",t.Submitted="submitted"}(d||(d={})),function(t){t.Idle="idle",t.Submitting="submitting",t.Success="success",t.Error="error"}(h||(h={}));const l={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"};
127
12
  /**
128
13
  * @license
129
14
  * Copyright 2023 Nuraly, Laabidi Aymen
130
15
  * 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,{})}}
16
+ */var u=function(t,i,e,s){return new(e||(e=Promise))((function(n,r){function o(t){try{d(s.next(t))}catch(t){r(t)}}function a(t){try{d(s.throw(t))}catch(t){r(t)}}function d(t){var i;t.done?n(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(o,a)}d((s=s.apply(t,i||[])).next())}))};class c{constructor(t){this.host=t,this.fields=new Map,this.validationState=d.Pristine,this.validationPromise=null}registerField(t){var i;const e=t.name||t.getAttribute("name")||`field-${Date.now()}`,s={element:t,name:e,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(e,s),this.addFieldListeners(t,e)}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 e=this.fields.get(t);if(e){if(i&&i.detail)e.isValid=i.detail.isValid||!1,e.validationMessage=i.detail.validationMessage||"";else{const t=e.element.getValidationStatus();e.isValid=t.isValid,e.validationMessage=e.element.validationMessage||""}this.updateFormValidationState()}}updateFormValidationState(){const t=this.getInvalidFields(),i=0===t.length;this.validationState=i?d.Valid:d.Invalid;const e={isValid:i,invalidFields:t,validationErrors:this.buildValidationErrors(),summary:i?"Form is valid":`${t.length} field(s) have errors`};this.dispatchValidationEvent(e)}buildValidationErrors(){const t={};for(const[i,e]of this.fields)!e.isValid&&e.validationMessage&&(t[i]=e.validationMessage);return t}validateForm(){return this.validationPromise||(this.validationState=d.Pending,this.validationPromise=this.performValidation()),this.validationPromise}performValidation(){return u(this,void 0,void 0,(function*(){const t=[],i={};for(const[e,s]of this.fields){const n=s.element.getValidationStatus().isValid;s.isValid=n,s.validationMessage=s.element.validationMessage||"",n||(t.push(s),i[e]=s.validationMessage)}const e=0===t.length;this.validationState=e?d.Valid:d.Invalid;const s={isValid:e,invalidFields:t,validationErrors:i,summary:e?"Form is valid":`${t.length} field(s) have errors`};return this.dispatchValidationEvent(s),this.validationPromise=null,s}))}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===d.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=d.Pristine,this.dispatchResetEvent()}dispatchValidationEvent(t){var i,e;null===(e=(i=this.host).dispatchCustomEvent)||void 0===e||e.call(i,l.VALIDATION_CHANGED,{validationResult:t})}dispatchResetEvent(){var t,i;null===(i=(t=this.host).dispatchCustomEvent)||void 0===i||i.call(t,l.RESET,{})}}
133
17
  /**
134
18
  * @license
135
19
  * Copyright 2023 Nuraly, Laabidi Aymen
136
20
  * 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})}}
21
+ */var v=function(t,i,e,s){return new(e||(e=Promise))((function(n,r){function o(t){try{d(s.next(t))}catch(t){r(t)}}function a(t){try{d(s.throw(t))}catch(t){r(t)}}function d(t){var i;t.done?n(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(o,a)}d((s=s.apply(t,i||[])).next())}))};class m{constructor(t){this.host=t,this.submissionState=h.Idle,this.lastSubmissionData=null}getSubmissionState(){return this.submissionState}isSubmitting(){return this.submissionState===h.Submitting}collectFormData(){const t=new FormData,i={},e={};return this.getFormFields().forEach((s=>{const n=s.name||s.getAttribute("name");if(!n)return;const r=s.value;null!=r&&t.append(n,String(r)),i[n]=r,e[n]={element:s,value:r,name:n,type:s.tagName.toLowerCase(),required:s.required||!1,disabled:s.disabled||!1}})),{formData:t,jsonData:i,fields:e}}submitForm(t){return v(this,void 0,void 0,(function*(){if(this.isSubmitting())throw new Error("Form is already submitting");try{this.setSubmissionState(h.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 e=this.collectFormData();return t&&(Object.assign(e.jsonData,t),Object.entries(t).forEach((([t,i])=>{e.formData.append(t,String(i))}))),this.lastSubmissionData=e,this.dispatchSubmitSuccessEvent(e),this.setSubmissionState(h.Success),e}catch(t){throw this.setSubmissionState(h.Error),this.dispatchSubmitErrorEvent(t),t}}))}resetSubmission(){this.submissionState=h.Idle,this.lastSubmissionData=null}getLastSubmissionData(){return this.lastSubmissionData}getFormFields(){var t;const i=this.host,e=[],s=["nr-input","nr-select","nr-radio","nr-checkbox","nr-textarea","nr-timepicker","nr-datepicker","input","select","textarea"];s.forEach((t=>{i.querySelectorAll(t).forEach((t=>{(t.name||t.getAttribute("name"))&&e.push(t)}))}));return((null===(t=i.shadowRoot)||void 0===t?void 0:t.querySelectorAll("slot"))||[]).forEach((t=>{t.assignedElements({flatten:!0}).forEach((t=>{s.forEach((i=>{if(t.matches&&t.matches(i)){const i=t;(i.name||i.getAttribute("name"))&&e.push(i)}t.querySelectorAll(i).forEach((t=>{const i=t;(i.name||i.getAttribute("name"))&&e.push(i)}))}))}))})),e}setSubmissionState(t){var i,e;this.submissionState=t,null===(e=(i=this.host).requestUpdate)||void 0===e||e.call(i)}dispatchSubmitAttemptEvent(t){var i,e;null===(e=(i=this.host).dispatchCustomEvent)||void 0===e||e.call(i,l.SUBMIT_ATTEMPT,{validationResult:t})}dispatchSubmitSuccessEvent(t){var i,e;null===(e=(i=this.host).dispatchCustomEvent)||void 0===e||e.call(i,l.SUBMIT_SUCCESS,{formData:t})}dispatchSubmitErrorEvent(t){var i,e;null===(e=(i=this.host).dispatchCustomEvent)||void 0===e||e.call(i,l.SUBMIT_ERROR,{error:t})}}
138
22
  /**
139
23
  * @license
140
24
  * Copyright 2023 Nuraly, Laabidi Aymen
141
25
  * 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};
26
+ */var f=function(t,i,e,s){for(var n,r=arguments.length,o=r<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,e):s,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(i,e,o):n(i,e))||o);return r>3&&o&&Object.defineProperty(i,e,o),o},p=function(t,i,e,s){return new(e||(e=Promise))((function(n,r){function o(t){try{d(s.next(t))}catch(t){r(t)}}function a(t){try{d(s.throw(t))}catch(t){r(t)}}function d(t){var i;t.done?n(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(o,a)}d((s=s.apply(t,i||[])).next())}))};let b=class extends(o(i)){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=d.Pristine,this._submissionState=h.Idle,this.validationController=new c(this),this.submissionController=new m(this),this.handleValidationChanged=t=>{const i=t.detail.validationResult;i&&(this._validationState=i.isValid?d.Valid:d.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(l.VALIDATION_CHANGED,this.handleValidationChanged)}handleFormSubmit(t){return p(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[e,s]of t.entries()){const t=document.createElement("input");t.type="hidden",t.name=e,t.value=s,i.appendChild(t)}document.body.appendChild(i),i.submit(),document.body.removeChild(i)}validate(){return p(this,void 0,void 0,(function*(){return(yield this.validationController.validateForm()).isValid}))}submit(t){return p(this,void 0,void 0,(function*(){yield this.submissionController.submitForm(t)}))}reset(){this.validationController.reset(),this.submissionController.resetSubmission(),this._validationState=d.Pristine,this._submissionState=h.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 e={};return t.forEach((t=>{t in i&&(e[t]=i[t])})),e}return i}getFieldValue(t){return this.getFieldsValue()[t]}setFieldsValue(t){Object.entries(t).forEach((([t,i])=>{this.setFieldValue(t,i)}))}setFieldValue(t,i){const e=this.validationController.getFields().find((i=>i.name===t));e&&e.element&&(e.element.value=i,e.value=i,e.element.dispatchEvent(new Event("change",{bubbles:!0})))}validateFields(t){return p(this,void 0,void 0,(function*(){const i=yield this.validationController.validateForm();if(t&&t.length>0){const e={};if(t.forEach((t=>{i.validationErrors[t]&&(e[t]=i.validationErrors[t])})),Object.keys(e).length>0)throw new Error(JSON.stringify(e));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 e=i.find((i=>i.name===t));e&&e.element&&(e.element.value="",e.value="",e.touched=!1,e.dirty=!1,e.isValid=!0,e.validationMessage="",e.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(),e={};return(t?i.filter((i=>t.includes(i.name))):i).forEach((t=>{e[t.name]=t.isValid?null:t.validationMessage})),e}isFieldTouched(t){const i=this.validationController.getFields().find((i=>i.name===t));return!!i&&i.touched}isFieldsTouched(t){const i=this.validationController.getFields();return(t?i.filter((i=>t.includes(i.name))):i).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();return(t?i.filter((i=>t.includes(i.name))):i).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 p(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 e`<form action="${this.action||""}" method="${this.method.toLowerCase()}" enctype="${this.enctype}" target="${this.target||""}" class="form-wrapper" data-disabled="${this.disabled}" novalidate><slot></slot></form>`}};b.styles=a,f([s({type:Object})],b.prototype,"config",void 0),f([s({type:Boolean,attribute:"validate-on-change"})],b.prototype,"validateOnChange",void 0),f([s({type:Boolean,attribute:"validate-on-blur"})],b.prototype,"validateOnBlur",void 0),f([s({type:Boolean,attribute:"prevent-invalid-submission"})],b.prototype,"preventInvalidSubmission",void 0),f([s({type:Boolean,attribute:"reset-on-success"})],b.prototype,"resetOnSuccess",void 0),f([s({type:String})],b.prototype,"action",void 0),f([s({type:String})],b.prototype,"method",void 0),f([s({type:String,attribute:"enctype"})],b.prototype,"enctype",void 0),f([s({type:String})],b.prototype,"target",void 0),f([s({type:Boolean,reflect:!0})],b.prototype,"disabled",void 0),f([n()],b.prototype,"_validationState",void 0),f([n()],b.prototype,"_submissionState",void 0),b=f([r("nr-form")],b);export{l as FORM_EVENTS,m as FormSubmissionController,h as FormSubmissionState,c as FormValidationController,d as FormValidationState,b as NrFormElement};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuralyui/form",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "NuralyUI Form - A comprehensive form component with validation coordination, submission handling, and state management",
5
5
  "type": "module",
6
6
  "main": "./index.js",