(()=>{"use strict";const t=new Map,e=Symbol("riot-component"),n=new Set,s="is",i="mount",r="update",o="unmount",a="shouldUpdate",u="onBeforeMount",l="onMounted",c="onBeforeUpdate",d="onUpdated",h="onBeforeUnmount",p="onUnmounted",m="props",f="state",b="slots",v="root",y=Symbol("pure"),x=Symbol("is_updating"),g=Symbol("parent"),E=Symbol("attributes"),N=Symbol("template"),T=0,A=1,O=2,M=3,_=4,j={ATTRIBUTE:0,EVENT:A,TEXT:2,VALUE:3,REF:_};function w(t){return t.replace(/-(\w)/g,(t,e)=>e.toUpperCase())}function D(t,e){throw new Error(t,{cause:e})}function S(t){const e=new Map,n=n=>(e.has(n)||e.set(n,t.call(this,n)))&&e.get(n);return n.cache=e,n}function I(t){return t.reduce((t,e)=>{const{value:n,type:s}=e;switch(!0){case e.type===_:break;case!e.name&&0===s:return{...t,...n};case 3===s:t.value=e.value;break;default:t[w(e.name)]=e.value}return t},{})}function L(t,e){return typeof t===e}function C(t){const e=t.ownerSVGElement;return!!e||null===e}function k(t){return"template"===t.tagName.toLowerCase()}function U(t){return L(t,"function")}function F(t){return!B(t)&&t.constructor===Object}function B(t){return null==t}function P(){return this}function $(t){return U(t)?t.prototype&&t.prototype.constructor?new t:t():t}function R(t){return Array.from(t.attributes).reduce((t,e)=>(t[w(e.name)]=e.value,t),{})}function z(t){for(;t.firstChild;)t.removeChild(t.firstChild)}const V=t=>t.remove(),H=(t,e)=>e&&e.parentNode&&e.parentNode.insertBefore(t,e),Y=(t,e)=>e&&e.parentNode&&e.parentNode.replaceChild(t,e),K={[i](t){this.el=t},[r]:P,[o](t,e,n=!1){n?V(this.el):n||z(this.el)},clone(){return{...this}},createDOM:P},q=0,X=1,G=2,W=3,Z=4,J={EACH:0,IF:1,SIMPLE:2,TAG:3,SLOT:4};function Q(t,e,n,s={}){return Object.defineProperty(t,e,{value:n,enumerable:!1,writable:!1,configurable:!0,...s}),t}function tt(t,e,n){return Object.entries(e).forEach(([e,s])=>{Q(t,e,s,n)}),t}function et(t,e){return Object.entries(e).forEach(([e,n])=>{t[e]||(t[e]=n)}),t}const nt=Symbol(),st=Symbol();function it(t){const e=t.dom.cloneNode(!0),{head:n,tail:s}=function(){const t=document.createTextNode(""),e=document.createTextNode("");return t[nt]=!0,e[st]=!0,{head:t,tail:e}}();return{avoidDOMInjection:!0,fragment:e,head:n,tail:s,children:[n,...Array.from(e.childNodes),s]}}const rt=Symbol("unmount"),ot={nodes:[],mount(t,e){return this.update(t,e)},update(t,e){const{placeholder:n,nodes:s,childrenMap:i}=this,r=t===rt?null:this.evaluate(t),o=r?Array.from(r):[],{newChildrenMap:a,batches:u,futureNodes:l}=function(t,e,n,s){const{condition:i,template:r,childrenMap:o,itemName:a,getKey:u,indexName:l,root:c,isTemplateTag:d}=s,h=new Map,p=[],m=[];return t.forEach((t,s)=>{const f=function(t,{itemName:e,indexName:n,index:s,item:i}){Q(t,e,i),n&&Q(t,n,s);return t}(Object.create(e),{itemName:a,indexName:l,index:s,item:t}),b=u?u(f):s,v=o.get(b),y=[];if(function(t,e){return!!t&&!t(e)}(i,f))return;const x=!v,g=v?v.template:r.clone(),E=g.el||c.cloneNode(),N=d&&x?it(g):g.meta;x?p.push(()=>g.mount(E,f,n,N)):p.push(()=>g.update(f,n)),d?y.push(...N.children):y.push(E),o.delete(b),m.push(...y),h.set(b,{nodes:y,template:g,context:f,index:s})}),{newChildrenMap:h,batches:p,futureNodes:m}}(o,t,e,this);return((t,e,n,s)=>{const i=e.length;let r=t.length,o=i,a=0,u=0,l=null;for(;as-u){const i=n(t[a],0);for(;u{if(s<0){const n=t[t.length-1];if(n){const{template:s,nodes:i,context:r}=n;i.pop(),i.length||(t.pop(),s.unmount(r,e,null))}}return n}}(Array.from(i.values()),e),n),u.forEach(t=>t()),this.childrenMap=a,this.nodes=l,this},unmount(t,e){return this.update(rt,e),this}};const at={mount(t,e){return this.update(t,e)},update(t,e){const n=!!this.evaluate(t),s=!this.value&&n,i=this.value&&!n,r=()=>{const n=this.node.cloneNode();H(n,this.placeholder),this.template=this.template.clone(),this.template.mount(n,t,e)};switch(!0){case s:r();break;case i:this.unmount(t);break;default:n&&this.template.update(t,e)}return this.value=n,this},unmount(t,e){return this.template.unmount(t,e,!0),this}};const ut="undefined"==typeof Element?{}:Element.prototype,lt=S(t=>ut.hasOwnProperty(t));function ct({node:t,name:e,isBoolean:n,value:s},i){if(!e)return s&&function(t,e,n){const s=e?Object.keys(e):[];Object.keys(n).filter(t=>!s.includes(t)).forEach(e=>t.removeAttribute(e))}(t,i,s),void(i&&function(t,e){Object.keys(e).forEach(n=>ct({node:t,name:n},e[n]))}(t,i));!lt(e)&&(function(t){return L(t,"boolean")}(i)||F(i)||U(i))&&(t[e]=i),!function(t,e){return e?!t&&0!==t:null==t}(i,n)?function(t){return["string","number","boolean"].includes(typeof t)}(i)&&t.setAttribute(e,function(t,e,n){return!0===e&&n?t:e}(e,i,n)):t.removeAttribute(e)}const dt=/^on/,ht={handleEvent(t){this[t.type](t)}},pt=new WeakMap;function mt(t){return B(t)?"":t}const ft=(t,e)=>t.childNodes[e];const bt={[T]:ct,[A]:function({node:t,name:e},n){const s=e.replace(dt,""),i=pt.get(t)||(t=>{const e=Object.create(ht);return pt.set(t,e),e})(t),[r,o]=(t=>Array.isArray(t)?t:[t,!1])(n),a=i[s],u=r&&!a;a&&!r&&t.removeEventListener(s,i),u&&t.addEventListener(s,i,o),i[s]=r},[O]:function({node:t},e){t.data=mt(e)},[M]:function({node:t},e){t.value=mt(e)},[_]:function({node:t,value:e},n){n?n(t):e(null)}},vt={mount(t){return this.value=this.evaluate(t),bt[this.type](this,this.value),this},update(t){const e=this.evaluate(t);return this.value!==e&&(bt[this.type](this,e),this.value=e),this},unmount(){return[A,_].includes(this.type)&&bt[this.type](this,null),this}};function yt(t,e){return{...vt,...e,node:2===e.type?ft(t,e.childNodeIndex):t}}const xt=(t,e)=>e?.find(e=>e.id===t),gt=(t,e)=>t[g]||e,Et={attributes:[],getTemplateScope(t,e){return((t,e,n)=>{if(!t||!t.length)return n;const s=t.map(t=>({...t,value:t.evaluate(e)}));return Object.assign(Object.create(n||null),I(s))})(this.attributes,t,e)},mount(t,e){const n=!!t.slots&&xt(this.name,t.slots),{parentNode:s}=this.node,i=n?gt(t,e):t;return this.templateData=n?.html?n:xt(this.name,i.slots),this.template=this.templateData&&wt(this.templateData.html,this.templateData.bindings).createDOM(s)||this.template?.clone(),this.template&&(z(this.node),this.template.mount(this.node,this.getTemplateScope(t,i),i),this.template.children=Array.from(this.node.childNodes)),Nt(this.node),V(this.node),this},update(t,e){if(this.template){const n=this.templateData?gt(t,e):t;this.template.update(this.getTemplateScope(t,n),n)}return this},unmount(t,e,n){return this.template&&this.template.unmount(this.getTemplateScope(t,e),null,n),this}};function Nt(t){const e=t&&t.firstChild;e&&(H(e,t),Nt(t))}function Tt(t){return t.reduce((t,{bindings:e})=>t.concat(e),[])}const At={mount(t){return this.update(t)},update(t,e){const n=this.evaluate(t);return n&&n===this.name?this.tag.update(t):(this.unmount(t,e,!0),this.name=n,this.tag=function(t,e=[],n=[]){return t?t({slots:e,attributes:n}):wt(function(t){return t.reduce((t,e)=>t+e.html,"")}(e),[...Tt(e),{expressions:n.map(t=>({type:0,...t}))}])}(this.getComponent(n),this.slots,this.attributes),this.tag.mount(this.node,t)),this},unmount(t,e,n){return this.tag&&this.tag.unmount(n),this}};const Ot={[X]:function(t,{evaluate:e,template:n}){const s=document.createTextNode("");return H(s,t),V(t),{...at,node:t,evaluate:e,placeholder:s,template:n.createDOM(t)}},[G]:function(t,{expressions:e}){return n=e.map(e=>yt(t,e)),["mount","update","unmount"].reduce((t,e)=>({...t,[e]:t=>n.map(n=>n[e](t))&&s}),{});var n,s},[q]:function(t,{evaluate:e,condition:n,itemName:s,indexName:i,getKey:r,template:o}){const a=document.createTextNode(""),u=t.cloneNode();return H(a,t),V(t),{...ot,childrenMap:new Map,node:t,root:u,condition:n,evaluate:e,isTemplateTag:k(u),template:o.createDOM(t),getKey:r,indexName:i,itemName:s,placeholder:a}},[W]:function(t,{evaluate:e,getComponent:n,slots:s,attributes:i}){return{...At,node:t,evaluate:e,slots:s,attributes:i,getComponent:n}},[Z]:function(t,{name:e,attributes:n,template:s}){return{...Et,attributes:n,template:s,node:t,name:e}}};function Mt(t,e){return t.map(t=>2===t.type?{...t,childNodeIndex:t.childNodeIndex+e}:t)}function _t(t,e){return C(t)?function(t,e){return e.ownerDocument.importNode((new window.DOMParser).parseFromString(`${t}`,"application/xml").documentElement,!0)}(e,t):function(t,e){const n=k(e)?e:document.createElement("template");return n.innerHTML=t,n.content}(e,t)}const jt={createDOM(t){return this.dom=this.dom||function(t,e){return e&&("string"==typeof e?_t(t,e):e)}(t,this.html)||document.createDocumentFragment(),this},mount(t,e,n,s={}){t||D("Please provide DOM node to mount properly your template"),this.el&&this.unmount(e);const{fragment:i,children:r,avoidDOMInjection:o}=s,{parentNode:a}=r?r[0]:t,u=k(t),l=u?function(t,e,n){const s=Array.from(t.childNodes);return Math.max(s.indexOf(e),s.indexOf(n.head)+1,0)}(a,t,s):null;this.createDOM(t);const c=i||this.dom.cloneNode(!0);return this.el=u?a:t,this.children=u?r||Array.from(c.childNodes):null,!o&&c&&function(t,e){switch(!0){case C(t):!function(t,e){for(;t.firstChild;)e.appendChild(t.firstChild)}(e,t);break;case k(t):t.parentNode.replaceChild(e,t);break;default:t.appendChild(e)}}(t,c),this.bindings=this.bindingsData.map(t=>function(t,e,n){const{selector:s,type:i,redundantAttribute:r,expressions:o}=e,a=s?t.querySelector(s):t;r&&a.removeAttribute(r);const u=o||[];return(Ot[i]||Ot[2])(a,{...e,expressions:n&&!s?Mt(u,n):u})}(this.el,t,l)),this.bindings.forEach(t=>t.mount(e,n)),this.meta=s,this},update(t,e){return this.bindings.forEach(n=>n.update(t,e)),this},unmount(t,e,n=!1){const s=this.el;if(!s)return this;switch(this.bindings.forEach(s=>s.unmount(t,e,n)),!0){case s[y]||null===n:break;case Array.isArray(this.children):!function(t){for(let e=0;et[e]=n;function It(t){return[i,r,o].reduce((e,n)=>(e[n]=t(n),e),{})}function Lt(t){return Array.isArray(t)?t:/^\[object (HTMLCollection|NodeList|Object)\]$/.test(Object.prototype.toString.call(t))&&"number"==typeof t.length?Array.from(t):[t]}function Ct(t,e){return Lt("string"==typeof t?(e||document).querySelectorAll(t):t)}const kt=Object.freeze({$(t){return Ct(t,this.root)[0]},$$(t){return Ct(t,this.root)}}),Ut=Object.freeze({[a]:P,[u]:P,[l]:P,[c]:P,[d]:P,[h]:P,[p]:P}),Ft=t=>1===t.length?t[0]:t;function Bt(t,e,n){const s="object"==typeof e?e:{[e]:n},i=Object.keys(s);return Lt(t).forEach(t=>{i.forEach(e=>t.setAttribute(e,s[e]))}),t}function Pt(t,e){return function(t,e,n){const s="string"==typeof e?[e]:e;return Ft(Lt(t).map(t=>Ft(s.map(e=>t[n](e)))))}(t,e,"getAttribute")}const $t=new Map,Rt=()=>zt||(Bt(zt=Ct("style[riot]")[0]||document.createElement("style"),"type","text/css"),zt.parentNode||document.head.appendChild(zt),zt);var zt;const Vt={CSS_BY_NAME:$t,add(t,e){return $t.has(t)||($t.set(t,e),this.inject()),this},inject(){return Rt().innerHTML=[...$t.values()].join("\n"),this},remove(t){return $t.has(t)&&($t.delete(t),this.inject()),this}};function Ht(t,...e){return(...n)=>(n=[...e,...n]).length{const e=t?.bindingsData?.[0];return e?.selector?[]:e?.expressions?.reduce((t,{name:e,type:n})=>n===j.ATTRIBUTE?t.concat([e]):t,[])??[]});function Gt(t,{slots:e,attributes:i,props:r}){return o=function(t){return[...n].reduce((t,e)=>e(t)||t,t)}(tt(F(t)?Object.create(t):t,{mount(n,o={},a){return Q(n,y,!1),this[g]=a,this[E]=function(t,e=[]){const n=e.map(e=>yt(t,e)),s={};return Object.assign(s,{expressions:n,...It(t=>e=>(n.forEach(n=>n[t](e)),s))})}(n,i).mount(a),Q(this,m,Object.freeze({...qt(n,r),...I(this[E].expressions)})),this[f]=Kt(this[f],o),this[N]=this.template.createDOM(n).clone(),St(n,this),t.name&&function(t,e){Yt(t)!==e&&Bt(t,s,e)}(n,t.name),Q(this,v,n),Q(this,b,e),this[u](this[m],this[f]),this[N].mount(n,this,a),this[l](this[m],this[f]),this},update(t={},e){e&&(this[g]=e,this[E].update(e));const n=Xt(this[N]),i=R({attributes:Array.from(this[v].attributes).filter(({name:t})=>!n.includes(t))}),{[s]:r,...o}={...i,...I(this[E].expressions)};var u,l;if(!1!==this[a](o,this[m]))return Q(this,m,Object.freeze({...e?(u=this[m],l=n,F(u)?Object.fromEntries(l.map(t=>[t,u[t]])):u):this[m],...o})),this[f]=Kt(this[f],t),this[c](this[m],this[f]),this[x]||(this[x]=!0,this[N].update(this,this[g])),this[d](this[m],this[f]),this[x]=!1,this},unmount(t){return this[h](this[m],this[f]),this[E].unmount(),this[N].unmount(this,this[g],null===t?null:!t),this[p](this[m],this[f]),this}})),Object.keys(t).filter(e=>U(t[e])).forEach(t=>{o[t]=o[t].bind(o)}),o;var o}function Wt({css:t,template:e,componentAPI:n,name:s}){return t&&s&&Vt.add(s,t),Ht(Gt)(tt(et(n,{...Ut,[m]:{},[f]:{}}),{[b]:null,[v]:null,...kt,name:s,css:t,template:e}))}const Zt=e=>{const n=function(t={}){return Object.entries($(t)).reduce((t,[e,n])=>{var s;return t[(s=e,s.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase())]=Qt(n),t},{})}(e.exports?e.exports.components:{});return s=>s===e.name?Jt(e):n[s]||t.get(s)},Jt=S(Qt);function Qt(t){const{css:e,template:n,exports:s,name:r}=t,o=n?function(t,e,n){return t(wt,j,J,n)}(n,0,Zt(t)):K;return({slots:t,attributes:a,props:u})=>{if(s&&s[y])return function(t,{slots:e,attributes:n,props:s,css:r,template:o}){o&&D("Pure components can not have html"),r&&D("Pure components do not have css");const a=et(t({slots:e,attributes:n,props:s}),Dt);return It(t=>(...e)=>{if(t===i){const[t]=e;Q(t,y,!0),St(t,a)}return a[t](...e),a})}(s,{slots:t,attributes:a,props:u,css:e,template:n});const l=$(s)||{},c=Wt({css:e,template:o,componentAPI:l,name:r})({slots:t,attributes:a,props:u});return{mount:(t,e,n)=>c.mount(t,n,e),update:(t,e)=>c.update(e,t),unmount:t=>c.unmount(t)}}}const te={css:null,exports:{state:{files:[],field:void 0,disabled:!1,TINY_FIELD_UPLOAD_FIELD:".tiny-field-upload__field",TINY_FIELD_UPLOAD_FILES_ITEM:".tiny-field-upload__files-item"},onMounted(){this.field=this.$(this.state.TINY_FIELD_UPLOAD_FIELD)},onUpdated(){const t=this.$$(this.state.TINY_FIELD_UPLOAD_FILES_ITEM+" input");let e=0;for(const n of t){const t=new DataTransfer;t.items.add(this.state.files[e++]),n.files=t.files}},addSrc:t=>URL.createObjectURL(t),handleOpenFileManager(t){this.field.click()},handleRemoveFile(t,e){const n=this.state.files.indexOf(e);this.state.files.splice(n,1),this.validateMax(),this.update()},handleSelectFile(t){for(const e of t.target.files)(!this.props.max||this.props.max&&this.state.files.length=this.props.max&&(this.state.disabled=!0)}},template:(t,e,n,s)=>t('
',[{redundantAttribute:"expr0",selector:"[expr0]",expressions:[{type:e.ATTRIBUTE,isBoolean:!0,name:"multiple",evaluate:t=>void 0!==t.props.multiple},{type:e.EVENT,name:"onchange",evaluate:t=>e=>{t.handleSelectFile(e)}}]},{redundantAttribute:"expr1",selector:"[expr1]",expressions:[{type:e.TEXT,childNodeIndex:1,evaluate:t=>[t.props.label].join("")},{type:e.EVENT,name:"onclick",evaluate:t=>e=>{t.handleOpenFileManager(e)}},{type:e.ATTRIBUTE,isBoolean:!0,name:"disabled",evaluate:t=>t.state.disabled}]},{type:n.EACH,getKey:null,condition:null,template:t('
',[{redundantAttribute:"expr3",selector:"[expr3]",expressions:[{type:e.TEXT,childNodeIndex:0,evaluate:t=>t.file.name}]},{redundantAttribute:"expr4",selector:"[expr4]",expressions:[{type:e.EVENT,name:"onclick",evaluate:t=>e=>{t.handleRemoveFile(e,t.file)}}]},{redundantAttribute:"expr5",selector:"[expr5]",expressions:[{type:e.ATTRIBUTE,isBoolean:!1,name:"name",evaluate:t=>[t.props.name,"[]"].join("")}]},{redundantAttribute:"expr6",selector:"[expr6]",expressions:[{type:e.ATTRIBUTE,isBoolean:!1,name:"src",evaluate:t=>t.addSrc(t.file)}]}]),redundantAttribute:"expr2",selector:"[expr2]",itemName:"file",indexName:null,evaluate:t=>t.state.files}]),name:"tiny-field-upload"};var ee,ne;!function(e,{css:n,template:s,exports:i}){t.has(e)&&D(`The component "${e}" was already registered`),t.set(e,Qt({name:e,css:n,template:s,exports:i}))}("tiny-field-upload",te),Ct("tiny-field-upload").map(e=>function(e,n,s,i){const r=s||Yt(e);return t.has(r)||D(`The component named "${r}" was never registered`),t.get(r)({props:n,slots:i}).mount(e)}(e,ee,ne));document.querySelector("form").addEventListener("submit",t=>{t.preventDefault(),console.log(t)})})();