@optionfactory/ful 0.99.0 → 0.101.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/dist/ful.iife.js +19 -3
- package/dist/ful.iife.js.map +1 -1
- package/dist/ful.iife.min.js +1 -1
- package/dist/ful.iife.min.js.map +1 -1
- package/dist/ful.min.mjs +1 -1
- package/dist/ful.min.mjs.map +1 -1
- package/dist/ful.mjs +19 -3
- package/dist/ful.mjs.map +1 -1
- package/package.json +1 -1
package/dist/ful.min.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class t{static encode(e,s){const r=s||t.URL_SAFE,i=e.byteLength,n=new Uint8Array(e);let a="";for(let t=0;t<i;t+=3){a+=r[n[t]>>2]+r[(3&n[t])<<4|n[t+1]>>4]+r[(15&n[t+1])<<2|n[t+2]>>6]+r[63&n[t+2]]}return i%3==2?a=a.substring(0,a.length-1):i%3==1&&(a=a.substring(0,a.length-2)),a}static decode(e,s){const r=s||t.URL_SAFE;let i=Math.floor(.75*e.length);for(let t=0;t!==e.length&&"="===e[e.length-t-1];++t)--i;const n=new Uint8Array(i);let a=0,o=0;for(;a<.75*e.length;){const t=r.indexOf(e.charAt(o++)),s=r.indexOf(e.charAt(o++)),i=r.indexOf(e.charAt(o++)),l=r.indexOf(e.charAt(o++));n[a++]=t<<2|s>>4,n[a++]=(15&s)<<4|i>>2,n[a++]=(3&i)<<6|l}return n.buffer}}t.STANDARD="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t.URL_SAFE="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";class e{static decode(t){if(t.length%2!=0)throw new Error("invalid length");const e=t.length/2;return new Uint8Array(e).map(((e,s)=>{const r=2*s,i=t.substring(r,r+2);return parseInt(i,16)}))}static encode(t,e){return Array.from(t).map((t=>t.toString(16))).map((t=>e?t.toUpperCase():t)).map((t=>t.padStart(2,0))).join("")}}class s extends Error{constructor(t,e,s){super(t,{cause:s}),this.name="Failure",this.problems=e}}class r{#t;#e;constructor(t,e){this.#t=t,this.#e=e}get normalized(){return`${this.#t}/${this.#e}`}get type(){return this.#t}get subtype(){return this.#e}static parse(t){if(!t)return new r("unknown","unknown");const[e,s]=t.split(";"),[i,n]=e.trim().split("/");return new r(i.toLowerCase(),n?.toLowerCase())}}class i extends s{constructor(t,e,s,r){super(t,s,r),this.name="HttpClientError",this.status=e}static of(t,e){return new i(e.message,0,[{type:t,context:null,reason:e.message,details:null}],e)}static async fromResponse(t){switch(r.parse(t.headers.get("Content-Type")).normalized){case"application/failures+json":{const e=await t.json(),s=`${t.status} ${t.statusText}: ${e.length} failures`;return new i(s,t.status,e)}case"application/problem+json":{const e=await t.json(),s=`${t.status} ${t.statusText}: ${e.title} ${e.detail}`;return new i(s,t.status,e.problems||[{type:"GENERIC_PROBLEM",context:null,reason:s,details:null}])}default:{const e=await t.text(),s=`${t.status} ${t.statusText}: ${e}`;return new i(s,t.status,[{type:"GENERIC_PROBLEM",context:null,reason:s,details:null}])}}}}class n{#s;#r;constructor(){this.#s=document.querySelector("meta[name='_csrf_header']")?.getAttribute("content"),this.#r=document.querySelector("meta[name='_csrf']")?.getAttribute("content")}async intercept(t,e){return this.#s&&this.#r&&t.headers.set(this.#s,this.#r),await e.proceed(t)}}class a{#i;constructor(t){this.#i=t}async intercept(t,e){const s=await e.proceed(t);return 401===s.status&&(window.location.href=this.#i),s}}class o{#n;constructor(){this.#n=[]}withCsrfToken(){return this.#n.push(new n),this}withRedirectOnUnauthorized(t){return this.#n.push(new a(t)),this}withInterceptors(...t){return this.#n.push(...t),this}build(){return new u(this.#n)}}class l{async intercept(t,e){return await fetch(t)}}class c{#n;#a;constructor(t,e){this.#n=t,this.#a=e}async proceed(t){const e=this.#n[this.#a];return await e.intercept(t,new c(this.#n,this.#a+1))}}class u{#n;static builder(){return new o}constructor(t){this.#n=t||[]}async exchange(t,e,s){const r=[...this.#n,...s||[],new l],i=new c(r,0);return await i.proceed(new Request(t,e))}request(t,e){return d.create(this,t,e)}get(t){return d.create(this,"GET",t)}head(t){return d.create(this,"HEAD",t)}post(t){return d.create(this,"POST",t)}put(t){return d.create(this,"PUT",t)}patch(t){return d.create(this,"PATCH",t)}delete(t){return d.create(this,"DELETE",t)}}const h=async(t,e)=>{try{return await t[e]()}catch(t){throw i.of("UNMARSHALING_PROBLEM",t)}};class d{#o;#l;#c;#u;#h;#d;#p;#n;static create(t,e,s){return new d(t,e,s,new URLSearchParams,new Headers,void 0,{},[])}constructor(t,e,s,r,i,n,a,o){this.#o=t,this.#l=e,this.#c=s,this.#u=r,this.#d=n,this.#h=i,this.#p=a,this.#n=o}headers(t){for(const[e,s]of new Headers(t).entries())null==s?this.#h.delete(e):this.#h.set(e,s);return this}header(t,e){return null==e?this.#h.delete(t):this.#h.set(t,e),this}params(t){for(const[e,s]of new URLSearchParams(t).entries())null==s?this.#u.delete(e):this.#u.set(e,s);return this}param(t,e){return null==e?this.#u.delete(t):this.#u.set(t,e),this}body(t){return this.#d=t,this}json(t){return this.#h.set("Content-Type","application/json"),this.#d=JSON.stringify(t),this}multipart(t){const e=new FormData;return t(new p(e)),this.#d=e,this}options(t){for(const[e,s]of Object.entries(t))this.#p[e]=s;return this}option(t,e){return this.#p[t]=e,this}interceptors(t){for(const e of t)this.#n.push(e);return this}interceptor(t){return this.#n.push(t),this}async exchange(){const t=this.#u.size?`${this.#c}?${this.#u}`:this.#c,e={...this.#p,headers:this.#h,method:this.#l,body:this.#d};return await this.#o.exchange(t,e,this.#n)}async fetch(){const t=this.#u.size?`${this.#c}?${this.#u}`:this.#c,e={...this.#p,headers:this.#h,method:this.#l,body:this.#d};try{const s=await this.#o.exchange(t,e,this.#n);if(!s.ok)throw await i.fromResponse(s);return s}catch(t){if(t instanceof s)throw t;throw i.of("CONNECTION_PROBLEM",t)}}async fetchText(){const t=await this.fetch();return await h(t,"text")}async fetchJson(){const t=await this.fetch();return await h(t,"json")}async fetchBlob(){const t=await this.fetch();return await h(t,"blob")}async fetchArrayBuffer(){const t=await this.fetch();return await h(t,"arrayBuffer")}}class p{#f;constructor(t){this.#f=t}field(t,e){return this.#f.append(t,e),this}blob(t,e,s){return this.#f.append(t,e,s),this}blobs(t,e){for(let s of e)this.#f.append(t,s);return this}json(t,e,s){const r=new Blob([JSON.stringify(e)],{type:"application/json"});return this.#f.append(t,r,s),this}}class f{constructor(t,e){this.prefix=t,this.storage=e}save(t,e){this.storage.setItem(`${this.prefix}-${t}`,JSON.stringify(e))}load(t){const e=this.storage.getItem(`${this.prefix}-${t}`);return void 0===e?void 0:JSON.parse(e)}remove(t){this.storage.removeItem(`${this.prefix}-${t}`)}pop(t){const e=this.load(t);return this.remove(t),e}}class m extends f{constructor(t){super(t,localStorage)}}class g extends f{constructor(t){super(t,sessionStorage)}}class b{constructor(t,e,s){this.storage=t,this.key=e,this.dataSupplier=s,this.cache=null}async load(t){const e=this.storage.load(this.key);if(e&&e.revision===t)return void(this.cache=e.value);const s=await this.dataSupplier(t,this.key);this.storage.save(this.key,{revision:t,value:s}),this.cache=s}data(){return this.cache}}class w{static forKeycloak(t,e,s){return new w(t,"openid profile",{auth:new URL("protocol/openid-connect/auth",e),token:new URL("protocol/openid-connect/token",e),logout:new URL("protocol/openid-connect/logout",e),registration:new URL("protocol/openid-connect/registrations",e),redirect:s})}constructor(t,e,{auth:s,token:r,registration:i,logout:n,redirect:a}){this.storage=new g(t),this.clientId=t,this.scope=e,this.uri={auth:s,token:r,registration:i,logout:n,redirect:a}}async action(e,s){const r=t.encode(crypto.getRandomValues(new Uint8Array(32)).buffer),i=t.encode(await crypto.subtle.digest("SHA-256",(new TextEncoder).encode(r))),n=this.clientId+t.encode(crypto.getRandomValues(new Uint8Array(16)).buffer);this.storage.save(w.PKCE_AND_STATE_KEY,{state:n,verifier:r});const a=new URL(e);a.searchParams.set("client_id",this.clientId),a.searchParams.set("redirect_uri",this.uri.redirect),a.searchParams.set("response_type","code"),a.searchParams.set("scope",this.scope),a.searchParams.set("state",n),a.searchParams.set("code_challenge",i),a.searchParams.set("code_challenge_method","S256"),Object.entries(s||{}).forEach((t=>{a.searchParams.set(t[0],t[1])})),window.location.href=a.toString()}async registration(t){await this.action(this.uri.registration,t)}async applicationInitiatedAction(t,e){await this.action(this.uri.auth,{...e,kc_action:t})}async#m(t,e){window.history.replaceState("","",this.uri.redirect);const s=this.storage.pop(w.PKCE_AND_STATE_KEY);if(s.state!==e)throw new Error("State mismatch");const r=await fetch(this.uri.token,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams([["client_id",this.clientId],["code",t],["grant_type","authorization_code"],["code_verifier",s.verifier],["state",s.state],["redirect_uri",this.uri.redirect]])});if(!r.ok){const t=await r.text();throw new Error("Error:"+r.status+": "+t)}const i=await r.json();return new y(this.clientId,i,this.uri)}async ensureLoggedIn(){const t=new URL(window.location.href),e=t.searchParams.get("code");if(e&&this.storage.load(w.PKCE_AND_STATE_KEY)){const s=t.searchParams.get("state");return await this.#m(e,s)}return await this.action(this.uri.auth,{}),null}}w.PKCE_AND_STATE_KEY="state-and-verifier";class y{static parseToken(e){const[s,r,i]=e.split("."),n=new TextDecoder("utf-8");return{header:JSON.parse(n.decode(t.decode(s,t.STANDARD))),payload:JSON.parse(n.decode(t.decode(r,t.STANDARD))),signature:i}}constructor(t,e,{token:s,logout:r,redirect:i}){this.clientId=t,this.token=e,this.idToken=y.parseToken(e.id_token),this.accessToken=y.parseToken(e.access_token),this.refreshToken=y.parseToken(e.refresh_token),this.uri={token:s,logout:r,redirect:i},this.refreshCallback=null}onRefresh(t){this.refreshCallback=t}async refresh(){const t=await fetch(this.uri.token,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams([["client_id",this.clientId],["grant_type","refresh_token"],["refresh_token",this.token.refresh_token]])});if(!t.ok){const e=await t.text();throw new Error("Error:"+t.status+": "+e)}const e=await t.json();this.token=e,this.idToken=y.parseToken(e.id_token),this.accessToken=y.parseToken(e.access_token),this.refreshToken=y.parseToken(e.refresh_token),this.refreshCallback&&this.refreshCallback(this.token,this.accessToken,this.refreshToken)}shouldBeRefreshed(t){const e=(new Date).getTime(),s=1e3*this.refreshToken.payload.exp;return!(e>s)&&e-t>s}async refreshIf(t){this.shouldBeRefreshed(t)&&await this.refresh()}logout(){const t=new URL(this.uri.logout);t.searchParams.set("post_logout_redirect_uri",this.uri.redirect),t.searchParams.set("id_token_hint",this.token.id_token),window.location.href=t.toString()}bearerToken(){return`Bearer ${this.token.access_token}`}interceptor(t,e){return new v(this,t,e)}}class v{#g;#b;#w;constructor(t,e,s){this.#g=t,this.#b=e||2e3,this.#w=s||3e4}async intercept(t,e){await this.#g.refreshIf(this.#b),t.headers.set("Authorization",this.#g.bearerToken());const s=await e.proceed(t);return await this.#g.refreshIf(this.#w),s}}const A={sleep:t=>new Promise((e=>setTimeout(e,t))),DEBOUNCE_DEFAULT:0,DEBOUNCE_IMMEDIATE:1,debounce(t,e,s){let r=null,i=[],n=0,a=s||A.DEBOUNCE_DEFAULT;const o=()=>{const s=(new Date).getTime()-n;t>s?r=setTimeout(o,t-s):(r=null,a!==A.DEBOUNCE_IMMEDIATE&&e(...i),null===r&&(i=[]))};return function(){i=[...arguments],n=(new Date).getTime(),null===r&&(r=setTimeout(o,t),a===A.DEBOUNCE_IMMEDIATE&&e(...i))}},THROTTLE_DEFAULT:0,THROTTLE_NO_LEADING:1,THROTTLE_NO_TRAILING:2,throttle(t,e,s){let r=null,i=[],n=0,a=s||A.THROTTLE_DEFAULT;const o=()=>{n=a&A.THROTTLE_NO_LEADING?0:(new Date).getTime(),r=null,e(...i),null===r&&(i=[])};return function(){const s=(new Date).getTime();!n&&a&A.THROTTLE_NO_LEADING&&(n=s);const l=t-(s-n);i=[...arguments],l<=0||l>t?(null!==r&&(clearTimeout(r),r=null),n=s,e(...i),null===r&&(i=[])):null!==r||a&A.THROTTLE_NO_TRAILING||(r=setTimeout(o,l))}}};class E{constructor(){this.promise=new Promise(((t,e)=>{this.reject=e,this.resolve=t}))}}class T{static fromHtml(...t){const e=document.createElement("template");return e.innerHTML=t.join(""),e.content}static toHtml(t){var e=document.createElement("template");return e.content.appendChild(t),e.innerHTML}static from(...t){const e=new DocumentFragment;return e.append(...t),e}static fromChildNodes(t){const e=new DocumentFragment;return e.append(...t.childNodes),e}}class L{static id=0;static uid(t){return`${t}-${++L.id}`}static defaultValue(t,e,s){return t.hasAttribute(e)||t.setAttribute(e,s),t.getAttribute(e)}static forward(t,e,s){e.getAttributeNames().filter((e=>e.startsWith(t))).forEach((r=>{const i=r.substring(t.length);if("class"!==i)s.setAttribute(i,e.getAttribute(r));else{const r=e.getAttribute(t+"class")?.split(" ").filter((t=>t.length))??[];s.classList.add(...r)}}))}static toggle(t,e,s){s?t.setAttribute(e,""):t.removeAttribute(e)}static flip(t,e){t.hasAttribute(e)?t.removeAttribute(e):t.setAttribute(e,"")}}class S{static from(t){const e=Array.from(t.childNodes).filter((t=>t instanceof Element)).filter((t=>t.matches("[slot]"))).map((t=>{t.remove();const e=t.getAttribute("slot");return t.removeAttribute("slot"),[e??"unnamed",t]})),s={};s.default=new DocumentFragment,s.default.append(...t.childNodes);for(const[t,r]of e)t in s||(s[t]=new DocumentFragment),s[t].append(r);return s}}class _{static isParsed(t){for(var e=t;e;e=e.parentNode)if(e.nextSibling)return!0;return!1}}class k{#y={};#v={};#A;put(t,e){this.#A?this.#v[t]=ftl.Template.fromFragment(e,this.#A):this.#y[t]=e}get(t){if(!this.#A)throw new Error("TemplatesRegistry is not configured");const e=this.#v[t];if(!e)throw new Error(`missing template: '${t}'`);return e}configure(t,...e){this.#A=t;for(const[s,r]of Object.entries(this.#y))delete this.#y[s],this.#v[s]=ftl.Template.fromFragment(r,t,...e)}}class C{#E;#T;#L;#S=0;constructor(){this.#E=new k,this.#T={}}defineTemplate(t){if(null==t)return;const e="unnamed-"+ ++this.#S;return this.#E.put(e,T.fromHtml(t)),e}define(t,e){return this.#L?(customElements.define(t,e),this):(this.#T[t]=e,this)}configure(t,...e){this.#E.configure(t,...e);for(const[t,e]of Object.entries(this.#T))customElements.define(t,e),delete this.#T[t];this.#L=!0}template(t){if(null!=t)return this.#E.get(t)}}const I=new C;const O=new class{#_=[];constructor(){document.addEventListener("DOMContentLoaded",this.dequeue.bind(this))}enqueue(t){this.#_.length||requestAnimationFrame(this.dequeue.bind(this)),this.#_.push(t)}dequeue(){this.#_.splice(0).forEach((t=>t.upgrade()))}},R={string:t=>t,number:t=>null===t?null:Number(t),presence:t=>null!==t,state:t=>null!==t,bool:t=>"true"===t,json:t=>JSON.parse(t)},D=t=>{const{observed:e,template:s,slots:r}=t??{},i=(e??[]).map((t=>{const[e,s]=t.split(":"),r=s?.trim()??"string";if(!(r in R))throw new Error(`unsupported attribute type: ${r}`);return[e.trim(),r]})),n=i.map((([t,e])=>[t,R[e]])),a=Object.fromEntries(n),o=I.defineTemplate(s),l=class extends HTMLElement{static get observedAttributes(){return Object.keys(a)}#k;#C;#I;#O;constructor(){super(),this.#O=this.attachInternals()}get initialized(){return this.#C}get internals(){return this.#O}connectedCallback(){if(this.#k)return;if("complete"===this.ownerDocument.readyState||_.isParsed(this))return void O.enqueue(this);this.ownerDocument.addEventListener("DOMContentLoaded",(()=>{t.disconnect(),O.enqueue(this)}));const t=new MutationObserver((()=>{_.isParsed(this)&&(t.disconnect(),O.enqueue(this))}));t.observe(this.parentNode,{childList:!0,subtree:!0})}attributeChangedCallback(t,e,s){if(!this.#k||e===s)return;if(this.#I)return;const r=a[t];this[t]=r(s)}reflect(t){this.#I=!0;try{t()}finally{this.#I=!1}}async upgrade(){if(!this.#k){this.#k=!0,await this.render(I.template(o),r?S.from(this):void 0);for(const[t,e]of n)this.hasAttribute(t)&&(this[t]=e(this.getAttribute(t)));this.#C=!0}}};for(const[t,e]of i.filter((([t,e])=>"state"===e)))Object.defineProperty(l.prototype,t,{enumerable:!0,configurable:!0,get(){return this.internals.states?this.internals.states.has(`--${t}`):this.hasAttribute(t)},set(e){this.internals.states?.[e?"add":"delete"](`--${t}`),this.reflect((()=>L.toggle(this,t,e)))}});return l};function N(t,e){return Object.keys(t).reduce(((s,r)=>{const i=e.length?e+".":"";return"object"==typeof t[r]&&null!==t[r]?Object.assign(s,N(t[r],i+r)):s[i+r]=t[r],s}),{})}function x(t,e){"radio"!==t.getAttribute("type")?"checkbox"!==t.getAttribute("type")?t.value=e:t.checked=e:t.checked=t.getAttribute("value")===e}class P extends(D()){static IGNORED_CHILDREN_SELECTOR=".d-none, [hidden]";static SCROLL_OFFSET=50;static INVALID_CLASS="is-invalid";submitter;render(){const t=document.createElement("form");L.forward("form-",this,t),t.replaceChildren(...this.childNodes),t.addEventListener("submit",(async t=>{t.preventDefault(),this.spinning((async()=>{await(this.submitter?.(this.values,this))}))})),this.hasAttribute("clear-invalid-on-change")&&this.addEventListener("change",(t=>{const e=t.target;e?.querySelectorAll(`.${CSS.escape(P.INVALID_CLASS)}`).forEach((t=>{t.classList.remove(P.INVALID_CLASS)}))})),this.replaceChildren(t)}spinner(t){this.querySelectorAll("ful-spinner").forEach((e=>{e.hidden=!t})),this.querySelectorAll("[type=submit],[type=reset]").forEach((e=>{e.disabled=t}))}async remoting(t){try{await t()}catch(t){throw t instanceof s&&(this.errors=t.problems),t}}async spinningUntilError(t){this.spinner(!0);try{await this.remoting(t)}catch(t){throw this.spinner(!1),t}}async spinning(t){this.spinner(!0);try{await this.remoting(t)}finally{this.spinner(!1)}}set values(t){for(const[e,s]of Object.entries(N(t,"")))this.querySelectorAll(`[name='${CSS.escape(e)}']`).forEach((t=>x(t,s)))}get values(){return Array.from(this.querySelectorAll("[name]")).filter((t=>"never"!==t.dataset.fulBindInclude&&("always"===t.dataset.fulBindInclude||null===t.closest(P.IGNORED_CHILDREN_SELECTOR)))).reduce(((t,e)=>function(t,e,s){const r=e.split(".").map((t=>t.match(/^[0-9]+$/)?+t:t));let i=t,n=null;for(let e=0;;++e){const a=r[e],o=r[e-1];if(Number.isInteger(a)&&!Array.isArray(i)&&(null!==n?n[o]=i=[]:t=i=[]),e===r.length-1)return i[a]=void 0!==s?s:a in i?i[a]:null,t;void 0===i[a]&&(i[a]={}),n=i,i=i[a]}}(t,e.getAttribute("name"),function(t){if("radio"===t.getAttribute("type")){if(!t.checked)return;return"boolean"===t.dataset.fulBindType?"true"===t.value:t.value}return"checkbox"===t.getAttribute("type")?t.checked:"boolean"===t.dataset.fulBindType?t.value?"true"===t.value:null:"INPUT"!==t.tagName&&"SELECT"!==t.tagName||""!==t.value&&void 0!==t.value?t.value:null}(e))),{})}set errors(t){const e=t.filter((t=>"FIELD_ERROR"===t.type||"INVALID_FORMAT"===t.type)),s=t.filter((t=>"FIELD_ERROR"!==t.type&&"INVALID_FORMAT"!==t.type));if(this.querySelectorAll(`.${P.INVALID_CLASS}`).forEach((t=>t.classList.remove(P.INVALID_CLASS))),this.querySelectorAll("ful-errors").forEach((t=>{t.replaceChildren(),t.setAttribute("hidden","")})),e.forEach((t=>{const e=t.context.replace("[",".").replace("].","."),s=`[name='${CSS.escape(e)}'] [ful-validation-target],[name='${CSS.escape(e)}']:not(:has([ful-validation-target]))`;this.querySelectorAll(s).forEach((t=>t.classList.add(P.INVALID_CLASS)));const r=`ful-field-error[field='${CSS.escape(e)}']`;this.querySelectorAll(r).forEach((e=>{e.innerText=t.reason}))})),this.querySelectorAll("ful-errors").forEach((t=>{t.innerText=s.map((t=>t.reason)).join("\n"),0!==s.length&&t.removeAttribute("hidden")})),!this.hasAttribute("scroll-on-error"))return;const r=Array.from(this.querySelectorAll(`ful-errors:not([hidden]), [ful-validated-field]:has(.${P.INVALID_CLASS}) ful-field-error`)).map((t=>t.parentElement?t.parentElement:t)).map((t=>t.getBoundingClientRect().y+window.scrollY)),i=Math.min(...r);i!==1/0&&window.scroll(window.scrollX,i>P.SCROLL_OFFSET?i-P.SCROLL_OFFSET:0)}}const $='\n<div ful-validated-field>\n <label data-tpl-for="id" class="form-label">{{{{ slots.default }}}}</label>\n <div class="input-group">\n <span data-tpl-if="slots.ibefore" class="input-group-text">{{{{ slots.ibefore }}}}</span>\n <div data-tpl-if="slots.before" data-tpl-remove="tag">{{{{ slots.before }}}}</div>\n {{{{ slots.input }}}} \n <div data-tpl-if="slots.after" data-tpl-remove="tag">{{{{ slots.after }}}}</div>\n <span data-tpl-if="slots.iafter" class="input-group-text">{{{{ slots.iafter }}}}</span>\n </div>\n <ful-field-error data-tpl-if="name" data-tpl-field="name"></ful-field-error>\n</div>\n',U=(t,e,s)=>{const r=t.input=s.input=s.input?.firstElementChild??(()=>{const t=document.createElement("input");return t.classList.add("form-control"),t})();r.setAttribute("ful-validation-target",""),r.addEventListener("change",(e=>{e.stopPropagation(),t.dispatchEvent(new CustomEvent("change",{bubbles:!0,cancelable:!1,detail:{value:t.value}}))}));const i=r.getAttribute("id")??t.getAttribute("input-id")??L.uid("ful-input");L.forward("input-",t,s.input),L.defaultValue(s.input,"id",i),L.defaultValue(s.input,"type","text"),L.defaultValue(s.input,"placeholder"," ");const n=t.getAttribute("name");return e.render(t,{id:i,name:n,slots:s})};class q extends(D({observed:["value"],slots:!0,template:$})){input;render(t,e){const s=U(this,t,e);this.replaceChildren(s)}get value(){return this.input.value}set value(t){this.input.value=t}}class F extends(D({observed:["value"],slots:!0,template:'\n <div ful-validated-field>\n <label data-tpl-for="tsId" class="form-label">{{{{ slots.default }}}}</label>\n {{{{ input }}}}\n <div class="input-group">\n <span data-tpl-if="slots.ibefore" class="input-group-text">{{{{ slots.ibefore }}}}</span>\n <div data-tpl-if="slots.before" data-tpl-remove="tag">{{{{ slots.before }}}}</div>\n {{{{ slots.input }}}} \n <div data-tpl-if="slots.after" data-tpl-remove="tag">{{{{ slots.after }}}}</div>\n <span data-tpl-if="slots.iafter" class="input-group-text">{{{{ slots.iafter }}}}</span>\n </div>\n <ful-field-error data-tpl-if="name" data-tpl-field="name"></ful-field-error>\n </div>\n '})){shouldLoad;_unwrappedRemoteLoad;constructor(t){super(),this.tsConfig=t}render(t,e){const s="local"!=(this.getAttribute("type")??"local"),r="always"!=this.getAttribute("load"),i=this.getAttribute("name"),n=e.input=e.input?.firstElementChild??document.createElement("select");n.setAttribute("ful-validation-target","");const a=n.getAttribute("id")??this.getAttribute("input-id")??L.uid("ful-select"),o=`${a}-ts-control`;L.forward("input-",this,n),L.defaultValue(n,"id",a),L.defaultValue(n,"placeholder"," "),e.input=T.from(n),this.loaded=!s;this._remote=s,this._unwrappedRemoteLoad=async(t,e)=>{if(!s||s&&r&&this.loaded)return void e();const i=t&&t.hasOwnProperty("byId")?"id":"query",n="id"===i?t.byId:t,a=await(this.#R?this.#R(n,i):[]);"id"!==i&&(this.loaded=!0),e(a)},this.ts=new TomSelect(n,Object.assign(s?{preload:"focus",load:this._unwrappedRemoteLoad,shouldLoad:t=>!this.shouldLoad||this.shouldLoad(t)}:{},{render:{loading:()=>'<ful-spinner class="centered p-2"></ful-spinner>'}},this.tsConfig)),this.ts.on("change",(t=>{this.dispatchEvent(new CustomEvent("change",{bubbles:!0,cancelable:!1,detail:{value:this.value}}))})),n.addEventListener("change",(t=>{t.stopPropagation()})),n.remove(),t.renderTo(this,{id:a,tsId:o,name:i,input:n,slots:e})}#R;set loader(t){this.#R=t,this.hasAttribute("value")&&(this.value=this.getAttribute("value"))}get value(){const t=this.ts.getValue();return""===t?null:t}set value(t){(async()=>{this._remote&&await this._unwrappedRemoteLoad({byId:t},this.ts.loadCallback.bind(this.ts));this.ts.setValue(t,!0)})()}}class j extends(D({observed:["value","disabled:state"],slots:!0,template:'\n <fieldset ful-validated-field>\n <legend class="form-label">\n {{{{ slots.default }}}}\n </legend>\n <header data-tpl-if="slots.header">\n {{{{ slots.header }}}}\n </header>\n <section>\n <div class="label-wrapper" data-tpl-each="inputsAndLabels" data-tpl-var="ial">\n <label>\n {{{{ ial[0] }}}}\n {{{{ ial[1] }}}}\n </label>\n </div>\n </section>\n <ful-field-error data-tpl-if="name" data-tpl-field="name"></ful-field-error>\n <footer data-tpl-if="slots.footer">\n {{{{ slots.footer }}}}\n </footer>\n </fieldset>\n '})){render(t,e){const s=this.getAttribute("name")??L.uid("ful-radiogroup"),r=Array.from(e.default.querySelectorAll("ful-radio")),i=r.map((t=>{const e=document.createElement("input");e.setAttribute("type","radio"),L.forward("input-",this,e),L.forward("",t,e),e.setAttribute("name",`${s}-ignore`),e.setAttribute("ful-validation-target",""),e.dataset.fulBindInclude="never",e.addEventListener("change",(t=>{t.stopPropagation(),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,cancelable:!1,detail:{value:this.value}}))}));return[e,T.fromChildNodes(t)]}));r.forEach((t=>t.remove())),t.renderTo(this,{name:s,slots:e,inputsAndLabels:i})}get value(){const t=this.querySelector("input[type=radio]:checked");return t?t.value:null}set value(t){if(null===t)return void this.querySelectorAll("input[type=radio]").forEach((t=>{t.checked=!1}));const e=this.querySelector(`input[type=radio][value=${CSS.escape(t)}]`);e&&(e.checked=!0)}}class B extends(D({slots:!0,template:'\n <div class="ful-spinner-wrapper">\n <div class="ful-spinner-text">{{{{ slots.default }}}}</div>\n <div class="ful-spinner-icon"></div>\n </div>\n '})){render(t,e){t.renderTo(this,{slots:e})}}export{L as Attributes,w as AuthorizationCodeFlow,v as AuthorizationCodeFlowInterceptor,y as AuthorizationCodeFlowSession,t as Base64,E as Deferred,C as ElementsRegistry,s as Failure,P as Form,T as Fragments,e as Hex,u as HttpClient,i as HttpClientError,$ as INPUT_TEMPLATE,q as Input,S as LightSlots,m as LocalStorage,r as MediaType,_ as Nodes,D as ParsedElement,j as RadioGroup,F as Select,g as SessionStorage,B as Spinner,k as TemplatesRegistry,b as VersionedStorage,I as elements,U as makeInputFragment,A as timing};
|
|
1
|
+
class t{static encode(e,s){const r=s||t.URL_SAFE,i=e.byteLength,n=new Uint8Array(e);let a="";for(let t=0;t<i;t+=3){a+=r[n[t]>>2]+r[(3&n[t])<<4|n[t+1]>>4]+r[(15&n[t+1])<<2|n[t+2]>>6]+r[63&n[t+2]]}return i%3==2?a=a.substring(0,a.length-1):i%3==1&&(a=a.substring(0,a.length-2)),a}static decode(e,s){const r=s||t.URL_SAFE;let i=Math.floor(.75*e.length);for(let t=0;t!==e.length&&"="===e[e.length-t-1];++t)--i;const n=new Uint8Array(i);let a=0,o=0;for(;a<.75*e.length;){const t=r.indexOf(e.charAt(o++)),s=r.indexOf(e.charAt(o++)),i=r.indexOf(e.charAt(o++)),l=r.indexOf(e.charAt(o++));n[a++]=t<<2|s>>4,n[a++]=(15&s)<<4|i>>2,n[a++]=(3&i)<<6|l}return n.buffer}}t.STANDARD="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t.URL_SAFE="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";class e{static decode(t){if(t.length%2!=0)throw new Error("invalid length");const e=t.length/2;return new Uint8Array(e).map(((e,s)=>{const r=2*s,i=t.substring(r,r+2);return parseInt(i,16)}))}static encode(t,e){return Array.from(t).map((t=>t.toString(16))).map((t=>e?t.toUpperCase():t)).map((t=>t.padStart(2,0))).join("")}}class s extends Error{constructor(t,e,s){super(t,{cause:s}),this.name="Failure",this.problems=e}}class r{#t;#e;constructor(t,e){this.#t=t,this.#e=e}get normalized(){return`${this.#t}/${this.#e}`}get type(){return this.#t}get subtype(){return this.#e}static parse(t){if(!t)return new r("unknown","unknown");const[e,s]=t.split(";"),[i,n]=e.trim().split("/");return new r(i.toLowerCase(),n?.toLowerCase())}}class i extends s{constructor(t,e,s,r){super(t,s,r),this.name="HttpClientError",this.status=e}static of(t,e){return new i(e.message,0,[{type:t,context:null,reason:e.message,details:null}],e)}static async fromResponse(t){switch(r.parse(t.headers.get("Content-Type")).normalized){case"application/failures+json":{const e=await t.json(),s=`${t.status} ${t.statusText}: ${e.length} failures`;return new i(s,t.status,e)}case"application/problem+json":{const e=await t.json(),s=`${t.status} ${t.statusText}: ${e.title} ${e.detail}`;return new i(s,t.status,e.problems||[{type:"GENERIC_PROBLEM",context:null,reason:s,details:null}])}default:{const e=await t.text(),s=`${t.status} ${t.statusText}: ${e}`;return new i(s,t.status,[{type:"GENERIC_PROBLEM",context:null,reason:s,details:null}])}}}}class n{#s;#r;constructor(){this.#s=document.querySelector("meta[name='_csrf_header']")?.getAttribute("content"),this.#r=document.querySelector("meta[name='_csrf']")?.getAttribute("content")}async intercept(t,e){return this.#s&&this.#r&&t.headers.set(this.#s,this.#r),await e.proceed(t)}}class a{#i;constructor(t){this.#i=t}async intercept(t,e){const s=await e.proceed(t);return 401===s.status&&(window.location.href=this.#i),s}}class o{#n;constructor(){this.#n=[]}withCsrfToken(){return this.#n.push(new n),this}withRedirectOnUnauthorized(t){return this.#n.push(new a(t)),this}withInterceptors(...t){return this.#n.push(...t),this}build(){return new u(this.#n)}}class l{async intercept(t,e){return await fetch(t)}}class c{#n;#a;constructor(t,e){this.#n=t,this.#a=e}async proceed(t){const e=this.#n[this.#a];return await e.intercept(t,new c(this.#n,this.#a+1))}}class u{#n;static builder(){return new o}constructor(t){this.#n=t||[]}async exchange(t,e,s){const r=[...this.#n,...s||[],new l],i=new c(r,0);return await i.proceed(new Request(t,e))}request(t,e){return d.create(this,t,e)}get(t){return d.create(this,"GET",t)}head(t){return d.create(this,"HEAD",t)}post(t){return d.create(this,"POST",t)}put(t){return d.create(this,"PUT",t)}patch(t){return d.create(this,"PATCH",t)}delete(t){return d.create(this,"DELETE",t)}}const h=async(t,e)=>{try{return await t[e]()}catch(t){throw i.of("UNMARSHALING_PROBLEM",t)}};class d{#o;#l;#c;#u;#h;#d;#p;#n;static create(t,e,s){return new d(t,e,s,new URLSearchParams,new Headers,void 0,{},[])}constructor(t,e,s,r,i,n,a,o){this.#o=t,this.#l=e,this.#c=s,this.#u=r,this.#d=n,this.#h=i,this.#p=a,this.#n=o}headers(t){for(const[e,s]of new Headers(t).entries())null==s?this.#h.delete(e):this.#h.set(e,s);return this}header(t,e){return null==e?this.#h.delete(t):this.#h.set(t,e),this}params(t){for(const[e,s]of new URLSearchParams(t).entries())null==s?this.#u.delete(e):this.#u.set(e,s);return this}param(t,e){return null==e?this.#u.delete(t):this.#u.set(t,e),this}body(t){return this.#d=t,this}json(t){return this.#h.set("Content-Type","application/json"),this.#d=JSON.stringify(t),this}multipart(t){const e=new FormData;return t(new p(e)),this.#d=e,this}options(t){for(const[e,s]of Object.entries(t))this.#p[e]=s;return this}option(t,e){return this.#p[t]=e,this}interceptors(t){for(const e of t)this.#n.push(e);return this}interceptor(t){return this.#n.push(t),this}async exchange(){const t=this.#u.size?`${this.#c}?${this.#u}`:this.#c,e={...this.#p,headers:this.#h,method:this.#l,body:this.#d};return await this.#o.exchange(t,e,this.#n)}async fetch(){const t=this.#u.size?`${this.#c}?${this.#u}`:this.#c,e={...this.#p,headers:this.#h,method:this.#l,body:this.#d};try{const s=await this.#o.exchange(t,e,this.#n);if(!s.ok)throw await i.fromResponse(s);return s}catch(t){if(t instanceof s)throw t;throw i.of("CONNECTION_PROBLEM",t)}}async fetchText(){const t=await this.fetch();return await h(t,"text")}async fetchJson(){const t=await this.fetch();return await h(t,"json")}async fetchBlob(){const t=await this.fetch();return await h(t,"blob")}async fetchArrayBuffer(){const t=await this.fetch();return await h(t,"arrayBuffer")}}class p{#f;constructor(t){this.#f=t}field(t,e){return this.#f.append(t,e),this}blob(t,e,s){return this.#f.append(t,e,s),this}blobs(t,e){for(let s of e)this.#f.append(t,s);return this}json(t,e,s){const r=new Blob([JSON.stringify(e)],{type:"application/json"});return this.#f.append(t,r,s),this}}class f{constructor(t,e){this.prefix=t,this.storage=e}save(t,e){this.storage.setItem(`${this.prefix}-${t}`,JSON.stringify(e))}load(t){const e=this.storage.getItem(`${this.prefix}-${t}`);return void 0===e?void 0:JSON.parse(e)}remove(t){this.storage.removeItem(`${this.prefix}-${t}`)}pop(t){const e=this.load(t);return this.remove(t),e}}class m extends f{constructor(t){super(t,localStorage)}}class g extends f{constructor(t){super(t,sessionStorage)}}class b{constructor(t,e,s){this.storage=t,this.key=e,this.dataSupplier=s,this.cache=null}async load(t){const e=this.storage.load(this.key);if(e&&e.revision===t)return void(this.cache=e.value);const s=await this.dataSupplier(t,this.key);this.storage.save(this.key,{revision:t,value:s}),this.cache=s}data(){return this.cache}}class w{static forKeycloak(t,e,s){return new w(t,"openid profile",{auth:new URL("protocol/openid-connect/auth",e),token:new URL("protocol/openid-connect/token",e),logout:new URL("protocol/openid-connect/logout",e),registration:new URL("protocol/openid-connect/registrations",e),redirect:s})}constructor(t,e,{auth:s,token:r,registration:i,logout:n,redirect:a}){this.storage=new g(t),this.clientId=t,this.scope=e,this.uri={auth:s,token:r,registration:i,logout:n,redirect:a}}async action(e,s){const r=t.encode(crypto.getRandomValues(new Uint8Array(32)).buffer),i=t.encode(await crypto.subtle.digest("SHA-256",(new TextEncoder).encode(r))),n=this.clientId+t.encode(crypto.getRandomValues(new Uint8Array(16)).buffer);this.storage.save(w.PKCE_AND_STATE_KEY,{state:n,verifier:r});const a=new URL(e);a.searchParams.set("client_id",this.clientId),a.searchParams.set("redirect_uri",this.uri.redirect),a.searchParams.set("response_type","code"),a.searchParams.set("scope",this.scope),a.searchParams.set("state",n),a.searchParams.set("code_challenge",i),a.searchParams.set("code_challenge_method","S256"),Object.entries(s||{}).forEach((t=>{a.searchParams.set(t[0],t[1])})),window.location.href=a.toString()}async registration(t){await this.action(this.uri.registration,t)}async applicationInitiatedAction(t,e){await this.action(this.uri.auth,{...e,kc_action:t})}async#m(t,e){window.history.replaceState("","",this.uri.redirect);const s=this.storage.pop(w.PKCE_AND_STATE_KEY);if(s.state!==e)throw new Error("State mismatch");const r=await fetch(this.uri.token,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams([["client_id",this.clientId],["code",t],["grant_type","authorization_code"],["code_verifier",s.verifier],["state",s.state],["redirect_uri",this.uri.redirect]])});if(!r.ok){const t=await r.text();throw new Error("Error:"+r.status+": "+t)}const i=await r.json();return new y(this.clientId,i,this.uri)}async ensureLoggedIn(){const t=new URL(window.location.href),e=t.searchParams.get("code");if(e&&this.storage.load(w.PKCE_AND_STATE_KEY)){const s=t.searchParams.get("state");return await this.#m(e,s)}return await this.action(this.uri.auth,{}),null}}w.PKCE_AND_STATE_KEY="state-and-verifier";class y{static parseToken(e){const[s,r,i]=e.split("."),n=new TextDecoder("utf-8");return{header:JSON.parse(n.decode(t.decode(s,t.STANDARD))),payload:JSON.parse(n.decode(t.decode(r,t.STANDARD))),signature:i}}constructor(t,e,{token:s,logout:r,redirect:i}){this.clientId=t,this.token=e,this.idToken=y.parseToken(e.id_token),this.accessToken=y.parseToken(e.access_token),this.refreshToken=y.parseToken(e.refresh_token),this.uri={token:s,logout:r,redirect:i},this.refreshCallback=null}onRefresh(t){this.refreshCallback=t}async refresh(){const t=await fetch(this.uri.token,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams([["client_id",this.clientId],["grant_type","refresh_token"],["refresh_token",this.token.refresh_token]])});if(!t.ok){const e=await t.text();throw new Error("Error:"+t.status+": "+e)}const e=await t.json();this.token=e,this.idToken=y.parseToken(e.id_token),this.accessToken=y.parseToken(e.access_token),this.refreshToken=y.parseToken(e.refresh_token),this.refreshCallback&&this.refreshCallback(this.token,this.accessToken,this.refreshToken)}shouldBeRefreshed(t){const e=(new Date).getTime(),s=1e3*this.refreshToken.payload.exp;return!(e>s)&&e-t>s}async refreshIf(t){this.shouldBeRefreshed(t)&&await this.refresh()}logout(){const t=new URL(this.uri.logout);t.searchParams.set("post_logout_redirect_uri",this.uri.redirect),t.searchParams.set("id_token_hint",this.token.id_token),window.location.href=t.toString()}bearerToken(){return`Bearer ${this.token.access_token}`}interceptor(t,e){return new v(this,t,e)}}class v{#g;#b;#w;constructor(t,e,s){this.#g=t,this.#b=e||2e3,this.#w=s||3e4}async intercept(t,e){await this.#g.refreshIf(this.#b),t.headers.set("Authorization",this.#g.bearerToken());const s=await e.proceed(t);return await this.#g.refreshIf(this.#w),s}}const A={sleep:t=>new Promise((e=>setTimeout(e,t))),DEBOUNCE_DEFAULT:0,DEBOUNCE_IMMEDIATE:1,debounce(t,e,s){let r=null,i=[],n=0,a=s||A.DEBOUNCE_DEFAULT;const o=()=>{const s=(new Date).getTime()-n;t>s?r=setTimeout(o,t-s):(r=null,a!==A.DEBOUNCE_IMMEDIATE&&e(...i),null===r&&(i=[]))};return function(){i=[...arguments],n=(new Date).getTime(),null===r&&(r=setTimeout(o,t),a===A.DEBOUNCE_IMMEDIATE&&e(...i))}},THROTTLE_DEFAULT:0,THROTTLE_NO_LEADING:1,THROTTLE_NO_TRAILING:2,throttle(t,e,s){let r=null,i=[],n=0,a=s||A.THROTTLE_DEFAULT;const o=()=>{n=a&A.THROTTLE_NO_LEADING?0:(new Date).getTime(),r=null,e(...i),null===r&&(i=[])};return function(){const s=(new Date).getTime();!n&&a&A.THROTTLE_NO_LEADING&&(n=s);const l=t-(s-n);i=[...arguments],l<=0||l>t?(null!==r&&(clearTimeout(r),r=null),n=s,e(...i),null===r&&(i=[])):null!==r||a&A.THROTTLE_NO_TRAILING||(r=setTimeout(o,l))}}};class E{constructor(){this.promise=new Promise(((t,e)=>{this.reject=e,this.resolve=t}))}}class T{static fromHtml(...t){const e=document.createElement("template");return e.innerHTML=t.join(""),e.content}static toHtml(t){var e=document.createElement("template");return e.content.appendChild(t),e.innerHTML}static from(...t){const e=new DocumentFragment;return e.append(...t),e}static fromChildNodes(t){const e=new DocumentFragment;return e.append(...t.childNodes),e}}class L{static id=0;static uid(t){return`${t}-${++L.id}`}static defaultValue(t,e,s){return t.hasAttribute(e)||t.setAttribute(e,s),t.getAttribute(e)}static forward(t,e,s){e.getAttributeNames().filter((e=>e.startsWith(t))).forEach((r=>{const i=r.substring(t.length);if("class"!==i)s.setAttribute(i,e.getAttribute(r));else{const r=e.getAttribute(t+"class")?.split(" ").filter((t=>t.length))??[];s.classList.add(...r)}}))}static toggle(t,e,s){s?t.setAttribute(e,""):t.removeAttribute(e)}static flip(t,e){t.hasAttribute(e)?t.removeAttribute(e):t.setAttribute(e,"")}}class S{static from(t){const e=Array.from(t.children).filter((t=>t.matches("[slot]"))).map((t=>{t.remove();const e=t.getAttribute("slot");return t.removeAttribute("slot"),[e??"unnamed",t]})),s={};s.default=new DocumentFragment,s.default.append(...t.childNodes);for(const[t,r]of e)t in s||(s[t]=new DocumentFragment),s[t].append(r);return s}}class _{static isParsed(t){for(let e=t;e;e=e.parentNode)if(e.nextSibling)return!0;return!1}static queryChildren(t,e){for(const s of t.children)if(s.matches(e))return s;return null}static queryChildrenAll(t,e){const s=[];for(const r of t.children)r.matches(e)&&s.push(r);return s}}class k{#y={};#v={};#A;put(t,e){this.#A?this.#v[t]=ftl.Template.fromFragment(e,this.#A):this.#y[t]=e}get(t){if(!this.#A)throw new Error("TemplatesRegistry is not configured");const e=this.#v[t];if(!e)throw new Error(`missing template: '${t}'`);return e}configure(t,...e){this.#A=t;for(const[s,r]of Object.entries(this.#y))delete this.#y[s],this.#v[s]=ftl.Template.fromFragment(r,t,...e)}}class C{#E;#T;#L;#S=0;constructor(){this.#E=new k,this.#T={}}defineTemplate(t){if(null==t)return;const e="unnamed-"+ ++this.#S;return this.#E.put(e,T.fromHtml(t)),e}define(t,e){return this.#L?(customElements.define(t,e),this):(this.#T[t]=e,this)}configure(t,...e){this.#E.configure(t,...e);for(const[t,e]of Object.entries(this.#T))customElements.define(t,e),delete this.#T[t];this.#L=!0}template(t){if(null!=t)return this.#E.get(t)}}const I=new C;const O=new class{#_=[];constructor(){document.addEventListener("DOMContentLoaded",this.dequeue.bind(this))}enqueue(t){this.#_.length||requestAnimationFrame(this.dequeue.bind(this)),this.#_.push(t)}dequeue(){this.#_.splice(0).forEach((t=>t.upgrade()))}},R={string:t=>t,number:t=>null===t?null:Number(t),presence:t=>null!==t,state:t=>null!==t,bool:t=>"true"===t,json:t=>JSON.parse(t)},D=t=>{const{observed:e,template:s,slots:r}=t??{},i=(e??[]).map((t=>{const[e,s]=t.split(":"),r=s?.trim()??"string";if(!(r in R))throw new Error(`unsupported attribute type: ${r}`);return[e.trim(),r]})),n=i.map((([t,e])=>[t,R[e]])),a=Object.fromEntries(n),o=I.defineTemplate(s),l=class extends HTMLElement{static get observedAttributes(){return Object.keys(a)}#k;#C;#I;#O;constructor(){super(),this.#O=this.attachInternals()}get initialized(){return this.#C}get internals(){return this.#O}connectedCallback(){if(this.#k)return;if("complete"===this.ownerDocument.readyState||_.isParsed(this))return void O.enqueue(this);this.ownerDocument.addEventListener("DOMContentLoaded",(()=>{t.disconnect(),O.enqueue(this)}));const t=new MutationObserver((()=>{_.isParsed(this)&&(t.disconnect(),O.enqueue(this))}));t.observe(this.parentNode,{childList:!0,subtree:!0})}attributeChangedCallback(t,e,s){if(!this.#k||e===s)return;if(this.#I)return;const r=a[t];this[t]=r(s)}reflect(t){this.#I=!0;try{t()}finally{this.#I=!1}}async upgrade(){if(!this.#k){this.#k=!0,await this.render(I.template(o),r?S.from(this):void 0);for(const[t,e]of n)this.hasAttribute(t)&&(this[t]=e(this.getAttribute(t)));this.#C=!0}}};for(const[t,e]of i.filter((([t,e])=>"state"===e)))Object.defineProperty(l.prototype,t,{enumerable:!0,configurable:!0,get(){return this.internals.states?this.internals.states.has(`--${t}`):this.hasAttribute(t)},set(e){this.internals.states?.[e?"add":"delete"](`--${t}`),this.reflect((()=>L.toggle(this,t,e)))}});return l};function N(t,e){return Object.keys(t).reduce(((s,r)=>{const i=e.length?e+".":"";return"object"==typeof t[r]&&null!==t[r]?Object.assign(s,N(t[r],i+r)):s[i+r]=t[r],s}),{})}function x(t,e){"radio"!==t.getAttribute("type")?"checkbox"!==t.getAttribute("type")?t.value=e:t.checked=e:t.checked=t.getAttribute("value")===e}class P extends(D()){static IGNORED_CHILDREN_SELECTOR=".d-none, [hidden]";static SCROLL_OFFSET=50;static INVALID_CLASS="is-invalid";submitter;render(){const t=document.createElement("form");L.forward("form-",this,t),t.replaceChildren(...this.childNodes),t.addEventListener("submit",(async t=>{t.preventDefault(),this.spinning((async()=>{await(this.submitter?.(this.values,this))}))})),this.hasAttribute("clear-invalid-on-change")&&this.addEventListener("change",(t=>{const e=t.target;e?.querySelectorAll(`.${CSS.escape(P.INVALID_CLASS)}`).forEach((t=>{t.classList.remove(P.INVALID_CLASS)}))})),this.replaceChildren(t)}spinner(t){this.querySelectorAll("ful-spinner").forEach((e=>{e.hidden=!t})),this.querySelectorAll("[type=submit],[type=reset]").forEach((e=>{e.disabled=t}))}async remoting(t){try{await t()}catch(t){throw t instanceof s&&(this.errors=t.problems),t}}async spinningUntilError(t){this.spinner(!0);try{await this.remoting(t)}catch(t){throw this.spinner(!1),t}}async spinning(t){this.spinner(!0);try{await this.remoting(t)}finally{this.spinner(!1)}}set values(t){for(const[e,s]of Object.entries(N(t,"")))this.querySelectorAll(`[name='${CSS.escape(e)}']`).forEach((t=>x(t,s)))}get values(){return Array.from(this.querySelectorAll("[name]")).filter((t=>"never"!==t.dataset.fulBindInclude&&("always"===t.dataset.fulBindInclude||null===t.closest(P.IGNORED_CHILDREN_SELECTOR)))).reduce(((t,e)=>function(t,e,s){const r=e.split(".").map((t=>t.match(/^[0-9]+$/)?+t:t));let i=t,n=null;for(let e=0;;++e){const a=r[e],o=r[e-1];if(Number.isInteger(a)&&!Array.isArray(i)&&(null!==n?n[o]=i=[]:t=i=[]),e===r.length-1)return i[a]=void 0!==s?s:a in i?i[a]:null,t;void 0===i[a]&&(i[a]={}),n=i,i=i[a]}}(t,e.getAttribute("name"),function(t){if("radio"===t.getAttribute("type")){if(!t.checked)return;return"boolean"===t.dataset.fulBindType?"true"===t.value:t.value}return"checkbox"===t.getAttribute("type")?t.checked:"boolean"===t.dataset.fulBindType?t.value?"true"===t.value:null:"INPUT"!==t.tagName&&"SELECT"!==t.tagName||""!==t.value&&void 0!==t.value?t.value:null}(e))),{})}set errors(t){const e=t.filter((t=>"FIELD_ERROR"===t.type||"INVALID_FORMAT"===t.type)),s=t.filter((t=>"FIELD_ERROR"!==t.type&&"INVALID_FORMAT"!==t.type));if(this.querySelectorAll(`.${P.INVALID_CLASS}`).forEach((t=>t.classList.remove(P.INVALID_CLASS))),this.querySelectorAll("ful-errors").forEach((t=>{t.replaceChildren(),t.setAttribute("hidden","")})),e.forEach((t=>{const e=t.context.replace("[",".").replace("].","."),s=`[name='${CSS.escape(e)}'] [ful-validation-target],[name='${CSS.escape(e)}']:not(:has([ful-validation-target]))`;this.querySelectorAll(s).forEach((t=>t.classList.add(P.INVALID_CLASS)));const r=`ful-field-error[field='${CSS.escape(e)}']`;this.querySelectorAll(r).forEach((e=>{e.innerText=t.reason}))})),this.querySelectorAll("ful-errors").forEach((t=>{t.innerText=s.map((t=>t.reason)).join("\n"),0!==s.length&&t.removeAttribute("hidden")})),!this.hasAttribute("scroll-on-error"))return;const r=Array.from(this.querySelectorAll(`ful-errors:not([hidden]), [ful-validated-field]:has(.${P.INVALID_CLASS}) ful-field-error`)).map((t=>t.parentElement?t.parentElement:t)).map((t=>t.getBoundingClientRect().y+window.scrollY)),i=Math.min(...r);i!==1/0&&window.scroll(window.scrollX,i>P.SCROLL_OFFSET?i-P.SCROLL_OFFSET:0)}}const $='\n<div ful-validated-field>\n <label data-tpl-for="id" class="form-label">{{{{ slots.default }}}}</label>\n <div class="input-group">\n <span data-tpl-if="slots.ibefore" class="input-group-text">{{{{ slots.ibefore }}}}</span>\n <div data-tpl-if="slots.before" data-tpl-remove="tag">{{{{ slots.before }}}}</div>\n {{{{ slots.input }}}} \n <div data-tpl-if="slots.after" data-tpl-remove="tag">{{{{ slots.after }}}}</div>\n <span data-tpl-if="slots.iafter" class="input-group-text">{{{{ slots.iafter }}}}</span>\n </div>\n <ful-field-error data-tpl-if="name" data-tpl-field="name"></ful-field-error>\n</div>\n',U=(t,e,s)=>{const r=t.input=s.input=s.input?.firstElementChild??(()=>{const t=document.createElement("input");return t.classList.add("form-control"),t})();r.setAttribute("ful-validation-target",""),r.addEventListener("change",(e=>{e.stopPropagation(),t.dispatchEvent(new CustomEvent("change",{bubbles:!0,cancelable:!1,detail:{value:t.value}}))}));const i=r.getAttribute("id")??t.getAttribute("input-id")??L.uid("ful-input");L.forward("input-",t,s.input),L.defaultValue(s.input,"id",i),L.defaultValue(s.input,"type","text"),L.defaultValue(s.input,"placeholder"," ");const n=t.getAttribute("name");return e.render(t,{id:i,name:n,slots:s})};class q extends(D({observed:["value"],slots:!0,template:$})){input;render(t,e){const s=U(this,t,e);this.replaceChildren(s)}get value(){return this.input.value}set value(t){this.input.value=t}}class F extends(D({observed:["value"],slots:!0,template:'\n <div ful-validated-field>\n <label data-tpl-for="tsId" class="form-label">{{{{ slots.default }}}}</label>\n {{{{ input }}}}\n <div class="input-group">\n <span data-tpl-if="slots.ibefore" class="input-group-text">{{{{ slots.ibefore }}}}</span>\n <div data-tpl-if="slots.before" data-tpl-remove="tag">{{{{ slots.before }}}}</div>\n {{{{ slots.input }}}} \n <div data-tpl-if="slots.after" data-tpl-remove="tag">{{{{ slots.after }}}}</div>\n <span data-tpl-if="slots.iafter" class="input-group-text">{{{{ slots.iafter }}}}</span>\n </div>\n <ful-field-error data-tpl-if="name" data-tpl-field="name"></ful-field-error>\n </div>\n '})){shouldLoad;_unwrappedRemoteLoad;constructor(t){super(),this.tsConfig=t}render(t,e){const s="local"!=(this.getAttribute("type")??"local"),r="always"!=this.getAttribute("load"),i=this.getAttribute("name"),n=e.input=e.input?.firstElementChild??document.createElement("select");n.setAttribute("ful-validation-target","");const a=n.getAttribute("id")??this.getAttribute("input-id")??L.uid("ful-select"),o=`${a}-ts-control`;L.forward("input-",this,n),L.defaultValue(n,"id",a),L.defaultValue(n,"placeholder"," "),e.input=T.from(n),this.loaded=!s;this._remote=s,this._unwrappedRemoteLoad=async(t,e)=>{if(!s||s&&r&&this.loaded)return void e();const i=t&&t.hasOwnProperty("byId")?"id":"query",n="id"===i?t.byId:t,a=await(this.#R?this.#R(n,i):[]);"id"!==i&&(this.loaded=!0),e(a)},this.ts=new TomSelect(n,Object.assign(s?{preload:"focus",load:this._unwrappedRemoteLoad,shouldLoad:t=>!this.shouldLoad||this.shouldLoad(t)}:{},{render:{loading:()=>'<ful-spinner class="centered p-2"></ful-spinner>'}},this.tsConfig)),this.ts.on("change",(t=>{this.dispatchEvent(new CustomEvent("change",{bubbles:!0,cancelable:!1,detail:{value:this.value}}))})),n.addEventListener("change",(t=>{t.stopPropagation()})),n.remove(),t.renderTo(this,{id:a,tsId:o,name:i,input:n,slots:e})}#R;set loader(t){this.#R=t,this.hasAttribute("value")&&(this.value=this.getAttribute("value"))}get value(){const t=this.ts.getValue();return""===t?null:t}set value(t){(async()=>{this._remote&&await this._unwrappedRemoteLoad({byId:t},this.ts.loadCallback.bind(this.ts));this.ts.setValue(t,!0)})()}}class j extends(D({observed:["value","disabled:state"],slots:!0,template:'\n <fieldset ful-validated-field>\n <legend class="form-label">\n {{{{ slots.default }}}}\n </legend>\n <header data-tpl-if="slots.header">\n {{{{ slots.header }}}}\n </header>\n <section>\n <div class="label-wrapper" data-tpl-each="inputsAndLabels" data-tpl-var="ial">\n <label>\n {{{{ ial[0] }}}}\n {{{{ ial[1] }}}}\n </label>\n </div>\n </section>\n <ful-field-error data-tpl-if="name" data-tpl-field="name"></ful-field-error>\n <footer data-tpl-if="slots.footer">\n {{{{ slots.footer }}}}\n </footer>\n </fieldset>\n '})){render(t,e){const s=this.getAttribute("name")??L.uid("ful-radiogroup"),r=Array.from(e.default.querySelectorAll("ful-radio")),i=r.map((t=>{const e=document.createElement("input");e.setAttribute("type","radio"),L.forward("input-",this,e),L.forward("",t,e),e.setAttribute("name",`${s}-ignore`),e.setAttribute("ful-validation-target",""),e.dataset.fulBindInclude="never",e.addEventListener("change",(t=>{t.stopPropagation(),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,cancelable:!1,detail:{value:this.value}}))}));return[e,T.fromChildNodes(t)]}));r.forEach((t=>t.remove())),t.renderTo(this,{name:s,slots:e,inputsAndLabels:i})}get value(){const t=this.querySelector("input[type=radio]:checked");return t?t.value:null}set value(t){if(null===t)return void this.querySelectorAll("input[type=radio]").forEach((t=>{t.checked=!1}));const e=this.querySelector(`input[type=radio][value=${CSS.escape(t)}]`);e&&(e.checked=!0)}}class B extends(D({slots:!0,template:'\n <div class="ful-spinner-wrapper">\n <div class="ful-spinner-text">{{{{ slots.default }}}}</div>\n <div class="ful-spinner-icon"></div>\n </div>\n '})){render(t,e){t.renderTo(this,{slots:e})}}export{L as Attributes,w as AuthorizationCodeFlow,v as AuthorizationCodeFlowInterceptor,y as AuthorizationCodeFlowSession,t as Base64,E as Deferred,C as ElementsRegistry,s as Failure,P as Form,T as Fragments,e as Hex,u as HttpClient,i as HttpClientError,$ as INPUT_TEMPLATE,q as Input,S as LightSlots,m as LocalStorage,r as MediaType,_ as Nodes,D as ParsedElement,j as RadioGroup,F as Select,g as SessionStorage,B as Spinner,k as TemplatesRegistry,b as VersionedStorage,I as elements,U as makeInputFragment,A as timing};
|
|
2
2
|
//# sourceMappingURL=ful.min.mjs.map
|