Files
firefly-iii/public/build/assets/create-8d2b7efc.js

4 lines
26 KiB
JavaScript
Raw Normal View History

2023-12-26 08:42:38 +01:00
var q=Object.defineProperty;var H=(n,e,t)=>e in n?q(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var C=(n,e,t)=>(H(n,typeof e!="symbol"?e+"":e,t),t);import{x as B,w as D,J as P,z as j,I as R,A as z,y as $}from"./load-translations-36a0ce82.js";function T(){return{id:"",name:"",alpine_name:""}}function V(){let e=B(new Date,"yyyy-MM-dd HH:mm");return{description:"",amount:"",currency_code:"EUR",source_account:T(),destination_account:T(),date:e,errors:{amount:[]}}}function W(n,e){let t=[];for(let s in n)if(n.hasOwnProperty(s)){const i=n[s];let r={};r.description=i.description,r.source_name=i.source_account.name,r.destination_name=i.destination_account.name,r.amount=i.amount,r.date=i.date,r.currency_code=i.currency_code,typeof i.source_account.id<"u"&&i.source_account.id.toString()!==""&&(r.source_id=i.source_account.id),typeof i.destination_account.id<"u"&&i.destination_account.id.toString()!==""&&(r.destination_id=i.destination_account.id),r.type=e,t.push(r)}return t}const k={showAllSuggestions:!1,suggestionsThreshold:1,maximumItems:0,autoselectFirst:!0,ignoreEnter:!1,updateOnSelect:!1,highlightTyped:!1,highlightClass:"",fullWidth:!1,fixed:!1,fuzzy:!1,startsWith:!1,fillIn:!1,preventBrowserAutocomplete:!1,itemClass:"",activeClasses:["bg-primary","text-white"],labelField:"label",valueField:"value",searchFields:["label"],queryParam:"query",items:[],source:null,hiddenInput:!1,hiddenValue:"",clearControl:"",datalist:"",server:"",serverMethod:"GET",serverParams:{},serverDataKey:"data",fetchOptions:{},liveServer:!1,noCache:!0,debounceTime:300,notFoundMessage:"",onRenderItem:(n,e,t)=>e,onSelectItem:(n,e)=>{},onServerResponse:(n,e)=>n.json(),onChange:(n,e)=>{},onBeforeFetch:n=>{},onAfterFetch:n=>{}},x="is-loading",A="is-active",p="show",_="next",y="prev",g=new WeakMap;let L=0,b=0;function U(n,e=300){let t;return(...s)=>{clearTimeout(t),t=setTimeout(()=>{n.apply(this,s)},e)}}function G(n){return n.normalize("NFD").replace(/[\u0300-\u036f]/g,"")}function v(n){return n?G(n.toString()).toLowerCase():""}function K(n,e){if(n.indexOf(e)>=0)return!0;let t=0;for(let s=0;s<e.length;s++){const i=e[s];if(i!=" "&&(t=n.indexOf(i,t)+1,t<=0))return!1}return!0}function M(n,e){return n.parentNode.insertBefore(e,n.nextSibling)}function J(n){var e=document.createElement("textarea");return e.innerHTML=n,e.value}function w(n,e){for(const[t,s]of Object.entries(e))n.setAttribute(t,s)}function X(n){n.ariaLabel=n.innerText,n.innerHTML=n.innerText.split("").map(e=>e+"&zwj;").join("")}function Y(n,e="window"){return n.split(".").reduce((t,s)=>t[s],e)}class S{constructor(e,t={}){C(this,"handleEvent",e=>{["scroll","resize"].includes(e.type)?(this._timer&&window.cancelAnimationFrame(this._timer),this._timer=window.requestAnimationFrame(()=>{this[`on${e.type}`](e)})):this[`on${e.type}`](e)});if(!(e instanceof HTMLElement)){console.error("Invalid element",e);return}g.set(e,this),L++,b++,this._searchInput=e,this._configure(t),this._preventInput=!1,this._keyboardNavigation=!1,this._searchFunc=U(()=>{this._loadFromServer(!0)},this._config.debounceTime),this._configureSearchInput(),this._configureDropElement(),this._config.fixed&&(document.addEventListener("scroll",this,!0),window.addEventListener("resize",this));const s=this._getClearControl();s&&s.addEventListener("click",this),["focus","change","blur","input","keydown"].forEach(i=>{this._searchInput.addEventListener(i,this)}),["mousemove","mouseleave"].forEach(i=>{this._dropElement.addEventListener(i,this)}),this._fetchData()}static init(e="input.autocomplete",t={}){document.querySelectorAll(e).forEach(i=>{this.getOrCreateInstance(i,t)})}static getInstance(e){return g.has(e)?g.get(e):null}static getOrCreateInstance(e,t={}){return this.getInstance(e)||new this(e,t)}dispose(){b--,["focus","change","blur","input","keydown"].forEach(t=>{this._searchInput.removeEventListener(t,this)}),["mousemove","mouseleave"].forEach(t=>{this._dropElement.removeEventListener(t,this)});const e=this._getClearControl();e&&e.removeEventListener("click",this),this._config.fixed&&b<=0&&(document.removeEventListener("scrol
2023-12-23 16:15:13 +01:00
<path fill-rule="evenodd" d="M2 2.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1H3.707l10.147 10.146a.5.5 0 0 1-.708.708L3 3.707V8.5a.5.5 0 0 1-1 0z"/>
</svg>`,i.append(o),i.classList.add("d-flex","justify-content-between"),o.addEventListener("click",a=>{this._searchInput.value=t.label,this._searchInput.focus()})}return r.addEventListener("mouseenter",o=>{this._keyboardNavigation||(this.removeSelection(),i.querySelector("a").classList.add(...this._activeClasses()))}),r.addEventListener("mousedown",o=>{o.preventDefault()}),r.addEventListener("click",o=>{o.preventDefault(),this._preventInput=!0,this._searchInput.value=J(t.label),this._hiddenInput&&(this._hiddenInput.value=t.value),this._config.onSelectItem(t,this),this.hideSuggestions(),this._preventInput=!1}),i}_showSuggestions(){if(document.activeElement!=this._searchInput)return;const e=v(this._searchInput.value);this._dropElement.innerHTML="";const t=Object.keys(this._items);let s=0,i=null;const r=[];for(let o=0;o<t.length;o++){const a=t[o],c=this._items[a],h=this._config.showAllSuggestions||e.length===0;let u=e.length==0&&this._config.suggestionsThreshold===0;!h&&e.length>0&&this._config.searchFields.forEach(d=>{const f=v(c[d]);let m=!1;if(this._config.fuzzy)m=K(f,e);else{const E=f.indexOf(e);m=this._config.startsWith?E===0:E>=0}m&&(u=!0)});const N=u||e.length===0;if(h||u){if(s++,c.group&&!r.includes(c.group)){const f=this._createGroup(c.group);this._dropElement.appendChild(f),r.push(c.group)}const d=this._createItem(e,c);if(!i&&N&&(i=d),this._dropElement.appendChild(d),this._config.maximumItems>0&&s>=this._config.maximumItems)break}}if(i&&this._config.autoselectFirst&&(this.removeSelection(),this._moveSelection(_,i)),s===0)if(this._config.notFoundMessage){const o=this._createLi();o.innerHTML=`<span class="dropdown-item">${this._config.notFoundMessage}</span>`,this._dropElement.appendChild(o),this._showDropdown()}else this.hideSuggestions();else this._showDropdown()}_createLi(){const e=document.createElement("li");return e.setAttribute("role","presentation"),e}_showDropdown(){this._dropElement.classList.add(p),this._dropElement.setAttribute("role","menu"),w(this._searchInput,{"aria-expanded":"true"}),this._positionMenu()}toggleSuggestions(e=!0){this._dropElement.classList.contains(p)?this.hideSuggestions():this.showOrSearch(e)}hideSuggestions(){this._dropElement.classList.remove(p),w(this._searchInput,{"aria-expanded":"false"}),this.removeSelection()}getInput(){return this._searchInput}getDropMenu(){return this._dropElement}_positionMenu(){const e=window.getComputedStyle(this._searchInput),t=this._searchInput.getBoundingClientRect(),s=e.direction==="rtl",i=this._config.fullWidth,r=this._config.fixed;let o=null,a=null;r&&(o=t.x,a=t.y+t.height,s&&!i&&(o-=this._dropElement.offsetWidth-t.width)),this._dropElement.style.transform="unset",i&&(this._dropElement.style.width=this._searchInput.offsetWidth+"px"),o!==null&&(this._dropElement.style.left=o+"px"),a!==null&&(this._dropElement.style.top=a+"px");const c=this._dropElement.getBoundingClientRect(),h=window.innerHeight;if(c.y+c.height>h){const u=i?t.height+4:t.height;this._dropElement.style.transform="translateY(calc(-100.1% - "+u+"px))"}}_fetchData(){this._items={},this._addItems(this._config.items);const e=this._config.datalist;if(e){const t=document.querySelector(`#${e}`);if(t){const s=Array.from(t.children).map(i=>{const r=i.getAttribute("value")??i.innerHTML.toLowerCase(),o=i.innerHTML;return{value:r,label:o}});this._addItems(s)}else console.error(`Datalist not found ${e}`)}this._setHiddenVal(),this._config.server&&!this._config.liveServer&&this._loadFromServer()}_setHiddenVal(){if(this._config.hiddenInput&&!this._config.hiddenValue)for(const[e,t]of Object.entries(this._items))t.label==this._searchInput.value&&(this._hiddenInput.value=e)}_addItems(e){const t=Object.keys(e);for(let s=0;s<t.length;s++){const i=t[s],r=e[i];if(r.group&&r.items){r.items.forEach(c=>c.group=r.group),this._addItems(r.items);continue}const o=typeof r=="string"?r:r.label,a=typeof r!="object"?{}:r;a.label=r[this._config.labelField]??o,a.value=r[this._config.valueField]??i,a.label&&(this._items[a.value]=a)}}_loadFromServer(e=!1){this._abortController&&this._abortController.abort(),this._a