lightning_ui_kit 0.1.2 → 0.1.4
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.
- checksums.yaml +4 -4
- data/app/assets/builds/lightning_ui_kit.css +1813 -65
- data/app/assets/builds/lightning_ui_kit.js +2 -2
- data/app/assets/builds/lightning_ui_kit.js.map +4 -4
- data/app/assets/vendor/lightning_ui_kit.css +2883 -0
- data/app/assets/vendor/lightning_ui_kit.js +5 -0
- data/app/components/lightning_ui_kit/badge_component.rb +30 -5
- data/app/components/lightning_ui_kit/banner_component.rb +1 -1
- data/app/components/lightning_ui_kit/checkbox_component.html.erb +1 -1
- data/app/components/lightning_ui_kit/dropzone_component.html.erb +82 -0
- data/app/components/lightning_ui_kit/dropzone_component.rb +61 -0
- data/app/components/lightning_ui_kit/errors.rb +34 -0
- data/app/components/lightning_ui_kit/file_input_component.html.erb +50 -0
- data/app/components/lightning_ui_kit/file_input_component.rb +62 -0
- data/app/components/lightning_ui_kit/input_component.html.erb +40 -23
- data/app/components/lightning_ui_kit/input_component.rb +17 -2
- data/app/components/lightning_ui_kit/select_component.html.erb +23 -3
- data/app/components/lightning_ui_kit/select_component.rb +31 -1
- data/app/components/lightning_ui_kit/switch_component.html.erb +9 -2
- data/app/components/lightning_ui_kit/switch_component.rb +12 -1
- data/app/components/lightning_ui_kit/textarea_component.html.erb +17 -10
- data/app/components/lightning_ui_kit/textarea_component.rb +17 -2
- data/app/javascript/lightning_ui_kit/controllers/accordion_controller.js +11 -6
- data/app/javascript/lightning_ui_kit/controllers/dropzone_controller.js +79 -0
- data/app/javascript/lightning_ui_kit/index.js +5 -0
- data/config/locales/en.yml +3 -0
- data/lib/lightning_ui_kit/engine.rb +0 -1
- data/lib/lightning_ui_kit/version.rb +1 -1
- metadata +11 -2
@@ -0,0 +1,5 @@
|
|
1
|
+
(()=>{var ht=Object.defineProperty;var ut=(r,e,t)=>e in r?ht(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var E=(r,e,t)=>(ut(r,typeof e!="symbol"?e+"":e,t),t);var M=(r,e,t)=>new Promise((s,o)=>{var h=g=>{try{f(t.next(g))}catch(v){o(v)}},d=g=>{try{f(t.throw(g))}catch(v){o(v)}},f=g=>g.done?s(g.value):Promise.resolve(g.value).then(h,d);f((t=t.apply(r,e)).next())});var ae=class{constructor(e,t,s){this.eventTarget=e,this.eventName=t,this.eventOptions=s,this.unorderedBindings=new Set}connect(){this.eventTarget.addEventListener(this.eventName,this,this.eventOptions)}disconnect(){this.eventTarget.removeEventListener(this.eventName,this,this.eventOptions)}bindingConnected(e){this.unorderedBindings.add(e)}bindingDisconnected(e){this.unorderedBindings.delete(e)}handleEvent(e){let t=dt(e);for(let s of this.bindings){if(t.immediatePropagationStopped)break;s.handleEvent(t)}}hasBindings(){return this.unorderedBindings.size>0}get bindings(){return Array.from(this.unorderedBindings).sort((e,t)=>{let s=e.index,o=t.index;return s<o?-1:s>o?1:0})}};function dt(r){if("immediatePropagationStopped"in r)return r;{let{stopImmediatePropagation:e}=r;return Object.assign(r,{immediatePropagationStopped:!1,stopImmediatePropagation(){this.immediatePropagationStopped=!0,e.call(this)}})}}var ce=class{constructor(e){this.application=e,this.eventListenerMaps=new Map,this.started=!1}start(){this.started||(this.started=!0,this.eventListeners.forEach(e=>e.connect()))}stop(){this.started&&(this.started=!1,this.eventListeners.forEach(e=>e.disconnect()))}get eventListeners(){return Array.from(this.eventListenerMaps.values()).reduce((e,t)=>e.concat(Array.from(t.values())),[])}bindingConnected(e){this.fetchEventListenerForBinding(e).bindingConnected(e)}bindingDisconnected(e,t=!1){this.fetchEventListenerForBinding(e).bindingDisconnected(e),t&&this.clearEventListenersForBinding(e)}handleError(e,t,s={}){this.application.handleError(e,`Error ${t}`,s)}clearEventListenersForBinding(e){let t=this.fetchEventListenerForBinding(e);t.hasBindings()||(t.disconnect(),this.removeMappedEventListenerFor(e))}removeMappedEventListenerFor(e){let{eventTarget:t,eventName:s,eventOptions:o}=e,h=this.fetchEventListenerMapForEventTarget(t),d=this.cacheKey(s,o);h.delete(d),h.size==0&&this.eventListenerMaps.delete(t)}fetchEventListenerForBinding(e){let{eventTarget:t,eventName:s,eventOptions:o}=e;return this.fetchEventListener(t,s,o)}fetchEventListener(e,t,s){let o=this.fetchEventListenerMapForEventTarget(e),h=this.cacheKey(t,s),d=o.get(h);return d||(d=this.createEventListener(e,t,s),o.set(h,d)),d}createEventListener(e,t,s){let o=new ae(e,t,s);return this.started&&o.connect(),o}fetchEventListenerMapForEventTarget(e){let t=this.eventListenerMaps.get(e);return t||(t=new Map,this.eventListenerMaps.set(e,t)),t}cacheKey(e,t){let s=[e];return Object.keys(t).sort().forEach(o=>{s.push(`${t[o]?"":"!"}${o}`)}),s.join(":")}},ft={stop({event:r,value:e}){return e&&r.stopPropagation(),!0},prevent({event:r,value:e}){return e&&r.preventDefault(),!0},self({event:r,value:e,element:t}){return e?t===r.target:!0}},gt=/^(?:(?:([^.]+?)\+)?(.+?)(?:\.(.+?))?(?:@(window|document))?->)?(.+?)(?:#([^:]+?))(?::(.+))?$/;function pt(r){let t=r.trim().match(gt)||[],s=t[2],o=t[3];return o&&!["keydown","keyup","keypress"].includes(s)&&(s+=`.${o}`,o=""),{eventTarget:mt(t[4]),eventName:s,eventOptions:t[7]?bt(t[7]):{},identifier:t[5],methodName:t[6],keyFilter:t[1]||o}}function mt(r){if(r=="window")return window;if(r=="document")return document}function bt(r){return r.split(":").reduce((e,t)=>Object.assign(e,{[t.replace(/^!/,"")]:!/^!/.test(t)}),{})}function vt(r){if(r==window)return"window";if(r==document)return"document"}function Se(r){return r.replace(/(?:[_-])([a-z0-9])/g,(e,t)=>t.toUpperCase())}function le(r){return Se(r.replace(/--/g,"-").replace(/__/g,"_"))}function R(r){return r.charAt(0).toUpperCase()+r.slice(1)}function Xe(r){return r.replace(/([A-Z])/g,(e,t)=>`-${t.toLowerCase()}`)}function yt(r){return r.match(/[^\s]+/g)||[]}function Pe(r){return r!=null}function he(r,e){return Object.prototype.hasOwnProperty.call(r,e)}var Ue=["meta","ctrl","alt","shift"],ue=class{constructor(e,t,s,o){this.element=e,this.index=t,this.eventTarget=s.eventTarget||e,this.eventName=s.eventName||Et(e)||Y("missing event name"),this.eventOptions=s.eventOptions||{},this.identifier=s.identifier||Y("missing identifier"),this.methodName=s.methodName||Y("missing method name"),this.keyFilter=s.keyFilter||"",this.schema=o}static forToken(e,t){return new this(e.element,e.index,pt(e.content),t)}toString(){let e=this.keyFilter?`.${this.keyFilter}`:"",t=this.eventTargetName?`@${this.eventTargetName}`:"";return`${this.eventName}${e}${t}->${this.identifier}#${this.methodName}`}shouldIgnoreKeyboardEvent(e){if(!this.keyFilter)return!1;let t=this.keyFilter.split("+");if(this.keyFilterDissatisfied(e,t))return!0;let s=t.filter(o=>!Ue.includes(o))[0];return s?(he(this.keyMappings,s)||Y(`contains unknown key filter: ${this.keyFilter}`),this.keyMappings[s].toLowerCase()!==e.key.toLowerCase()):!1}shouldIgnoreMouseEvent(e){if(!this.keyFilter)return!1;let t=[this.keyFilter];return!!this.keyFilterDissatisfied(e,t)}get params(){let e={},t=new RegExp(`^data-${this.identifier}-(.+)-param$`,"i");for(let{name:s,value:o}of Array.from(this.element.attributes)){let h=s.match(t),d=h&&h[1];d&&(e[Se(d)]=At(o))}return e}get eventTargetName(){return vt(this.eventTarget)}get keyMappings(){return this.schema.keyMappings}keyFilterDissatisfied(e,t){let[s,o,h,d]=Ue.map(f=>t.includes(f));return e.metaKey!==s||e.ctrlKey!==o||e.altKey!==h||e.shiftKey!==d}},qe={a:()=>"click",button:()=>"click",form:()=>"submit",details:()=>"toggle",input:r=>r.getAttribute("type")=="submit"?"click":"input",select:()=>"change",textarea:()=>"input"};function Et(r){let e=r.tagName.toLowerCase();if(e in qe)return qe[e](r)}function Y(r){throw new Error(r)}function At(r){try{return JSON.parse(r)}catch(e){return r}}var de=class{constructor(e,t){this.context=e,this.action=t}get index(){return this.action.index}get eventTarget(){return this.action.eventTarget}get eventOptions(){return this.action.eventOptions}get identifier(){return this.context.identifier}handleEvent(e){let t=this.prepareActionEvent(e);this.willBeInvokedByEvent(e)&&this.applyEventModifiers(t)&&this.invokeWithEvent(t)}get eventName(){return this.action.eventName}get method(){let e=this.controller[this.methodName];if(typeof e=="function")return e;throw new Error(`Action "${this.action}" references undefined method "${this.methodName}"`)}applyEventModifiers(e){let{element:t}=this.action,{actionDescriptorFilters:s}=this.context.application,{controller:o}=this.context,h=!0;for(let[d,f]of Object.entries(this.eventOptions))if(d in s){let g=s[d];h=h&&g({name:d,value:f,event:e,element:t,controller:o})}else continue;return h}prepareActionEvent(e){return Object.assign(e,{params:this.action.params})}invokeWithEvent(e){let{target:t,currentTarget:s}=e;try{this.method.call(this.controller,e),this.context.logDebugActivity(this.methodName,{event:e,target:t,currentTarget:s,action:this.methodName})}catch(o){let{identifier:h,controller:d,element:f,index:g}=this,v={identifier:h,controller:d,element:f,index:g,event:e};this.context.handleError(o,`invoking action "${this.action}"`,v)}}willBeInvokedByEvent(e){let t=e.target;return e instanceof KeyboardEvent&&this.action.shouldIgnoreKeyboardEvent(e)||e instanceof MouseEvent&&this.action.shouldIgnoreMouseEvent(e)?!1:this.element===t?!0:t instanceof Element&&this.element.contains(t)?this.scope.containsElement(t):this.scope.containsElement(this.action.element)}get controller(){return this.context.controller}get methodName(){return this.action.methodName}get element(){return this.scope.element}get scope(){return this.context.scope}},Z=class{constructor(e,t){this.mutationObserverInit={attributes:!0,childList:!0,subtree:!0},this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(s=>this.processMutations(s))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,this.mutationObserverInit),this.refresh())}pause(e){this.started&&(this.mutationObserver.disconnect(),this.started=!1),e(),this.started||(this.mutationObserver.observe(this.element,this.mutationObserverInit),this.started=!0)}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started){let e=new Set(this.matchElementsInTree());for(let t of Array.from(this.elements))e.has(t)||this.removeElement(t);for(let t of Array.from(e))this.addElement(t)}}processMutations(e){if(this.started)for(let t of e)this.processMutation(t)}processMutation(e){e.type=="attributes"?this.processAttributeChange(e.target,e.attributeName):e.type=="childList"&&(this.processRemovedNodes(e.removedNodes),this.processAddedNodes(e.addedNodes))}processAttributeChange(e,t){this.elements.has(e)?this.delegate.elementAttributeChanged&&this.matchElement(e)?this.delegate.elementAttributeChanged(e,t):this.removeElement(e):this.matchElement(e)&&this.addElement(e)}processRemovedNodes(e){for(let t of Array.from(e)){let s=this.elementFromNode(t);s&&this.processTree(s,this.removeElement)}}processAddedNodes(e){for(let t of Array.from(e)){let s=this.elementFromNode(t);s&&this.elementIsActive(s)&&this.processTree(s,this.addElement)}}matchElement(e){return this.delegate.matchElement(e)}matchElementsInTree(e=this.element){return this.delegate.matchElementsInTree(e)}processTree(e,t){for(let s of this.matchElementsInTree(e))t.call(this,s)}elementFromNode(e){if(e.nodeType==Node.ELEMENT_NODE)return e}elementIsActive(e){return e.isConnected!=this.element.isConnected?!1:this.element.contains(e)}addElement(e){this.elements.has(e)||this.elementIsActive(e)&&(this.elements.add(e),this.delegate.elementMatched&&this.delegate.elementMatched(e))}removeElement(e){this.elements.has(e)&&(this.elements.delete(e),this.delegate.elementUnmatched&&this.delegate.elementUnmatched(e))}},ee=class{constructor(e,t,s){this.attributeName=t,this.delegate=s,this.elementObserver=new Z(e,this)}get element(){return this.elementObserver.element}get selector(){return`[${this.attributeName}]`}start(){this.elementObserver.start()}pause(e){this.elementObserver.pause(e)}stop(){this.elementObserver.stop()}refresh(){this.elementObserver.refresh()}get started(){return this.elementObserver.started}matchElement(e){return e.hasAttribute(this.attributeName)}matchElementsInTree(e){let t=this.matchElement(e)?[e]:[],s=Array.from(e.querySelectorAll(this.selector));return t.concat(s)}elementMatched(e){this.delegate.elementMatchedAttribute&&this.delegate.elementMatchedAttribute(e,this.attributeName)}elementUnmatched(e){this.delegate.elementUnmatchedAttribute&&this.delegate.elementUnmatchedAttribute(e,this.attributeName)}elementAttributeChanged(e,t){this.delegate.elementAttributeValueChanged&&this.attributeName==t&&this.delegate.elementAttributeValueChanged(e,t)}};function Ot(r,e,t){Qe(r,e).add(t)}function wt(r,e,t){Qe(r,e).delete(t),xt(r,e)}function Qe(r,e){let t=r.get(e);return t||(t=new Set,r.set(e,t)),t}function xt(r,e){let t=r.get(e);t!=null&&t.size==0&&r.delete(e)}var C=class{constructor(){this.valuesByKey=new Map}get keys(){return Array.from(this.valuesByKey.keys())}get values(){return Array.from(this.valuesByKey.values()).reduce((t,s)=>t.concat(Array.from(s)),[])}get size(){return Array.from(this.valuesByKey.values()).reduce((t,s)=>t+s.size,0)}add(e,t){Ot(this.valuesByKey,e,t)}delete(e,t){wt(this.valuesByKey,e,t)}has(e,t){let s=this.valuesByKey.get(e);return s!=null&&s.has(t)}hasKey(e){return this.valuesByKey.has(e)}hasValue(e){return Array.from(this.valuesByKey.values()).some(s=>s.has(e))}getValuesForKey(e){let t=this.valuesByKey.get(e);return t?Array.from(t):[]}getKeysForValue(e){return Array.from(this.valuesByKey).filter(([t,s])=>s.has(e)).map(([t,s])=>t)}};var fe=class{constructor(e,t,s,o){this._selector=t,this.details=o,this.elementObserver=new Z(e,this),this.delegate=s,this.matchesByElement=new C}get started(){return this.elementObserver.started}get selector(){return this._selector}set selector(e){this._selector=e,this.refresh()}start(){this.elementObserver.start()}pause(e){this.elementObserver.pause(e)}stop(){this.elementObserver.stop()}refresh(){this.elementObserver.refresh()}get element(){return this.elementObserver.element}matchElement(e){let{selector:t}=this;if(t){let s=e.matches(t);return this.delegate.selectorMatchElement?s&&this.delegate.selectorMatchElement(e,this.details):s}else return!1}matchElementsInTree(e){let{selector:t}=this;if(t){let s=this.matchElement(e)?[e]:[],o=Array.from(e.querySelectorAll(t)).filter(h=>this.matchElement(h));return s.concat(o)}else return[]}elementMatched(e){let{selector:t}=this;t&&this.selectorMatched(e,t)}elementUnmatched(e){let t=this.matchesByElement.getKeysForValue(e);for(let s of t)this.selectorUnmatched(e,s)}elementAttributeChanged(e,t){let{selector:s}=this;if(s){let o=this.matchElement(e),h=this.matchesByElement.has(s,e);o&&!h?this.selectorMatched(e,s):!o&&h&&this.selectorUnmatched(e,s)}}selectorMatched(e,t){this.delegate.selectorMatched(e,t,this.details),this.matchesByElement.add(t,e)}selectorUnmatched(e,t){this.delegate.selectorUnmatched(e,t,this.details),this.matchesByElement.delete(t,e)}},ge=class{constructor(e,t){this.element=e,this.delegate=t,this.started=!1,this.stringMap=new Map,this.mutationObserver=new MutationObserver(s=>this.processMutations(s))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,attributeOldValue:!0}),this.refresh())}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started)for(let e of this.knownAttributeNames)this.refreshAttribute(e,null)}processMutations(e){if(this.started)for(let t of e)this.processMutation(t)}processMutation(e){let t=e.attributeName;t&&this.refreshAttribute(t,e.oldValue)}refreshAttribute(e,t){let s=this.delegate.getStringMapKeyForAttribute(e);if(s!=null){this.stringMap.has(e)||this.stringMapKeyAdded(s,e);let o=this.element.getAttribute(e);if(this.stringMap.get(e)!=o&&this.stringMapValueChanged(o,s,t),o==null){let h=this.stringMap.get(e);this.stringMap.delete(e),h&&this.stringMapKeyRemoved(s,e,h)}else this.stringMap.set(e,o)}}stringMapKeyAdded(e,t){this.delegate.stringMapKeyAdded&&this.delegate.stringMapKeyAdded(e,t)}stringMapValueChanged(e,t,s){this.delegate.stringMapValueChanged&&this.delegate.stringMapValueChanged(e,t,s)}stringMapKeyRemoved(e,t,s){this.delegate.stringMapKeyRemoved&&this.delegate.stringMapKeyRemoved(e,t,s)}get knownAttributeNames(){return Array.from(new Set(this.currentAttributeNames.concat(this.recordedAttributeNames)))}get currentAttributeNames(){return Array.from(this.element.attributes).map(e=>e.name)}get recordedAttributeNames(){return Array.from(this.stringMap.keys())}},te=class{constructor(e,t,s){this.attributeObserver=new ee(e,t,this),this.delegate=s,this.tokensByElement=new C}get started(){return this.attributeObserver.started}start(){this.attributeObserver.start()}pause(e){this.attributeObserver.pause(e)}stop(){this.attributeObserver.stop()}refresh(){this.attributeObserver.refresh()}get element(){return this.attributeObserver.element}get attributeName(){return this.attributeObserver.attributeName}elementMatchedAttribute(e){this.tokensMatched(this.readTokensForElement(e))}elementAttributeValueChanged(e){let[t,s]=this.refreshTokensForElement(e);this.tokensUnmatched(t),this.tokensMatched(s)}elementUnmatchedAttribute(e){this.tokensUnmatched(this.tokensByElement.getValuesForKey(e))}tokensMatched(e){e.forEach(t=>this.tokenMatched(t))}tokensUnmatched(e){e.forEach(t=>this.tokenUnmatched(t))}tokenMatched(e){this.delegate.tokenMatched(e),this.tokensByElement.add(e.element,e)}tokenUnmatched(e){this.delegate.tokenUnmatched(e),this.tokensByElement.delete(e.element,e)}refreshTokensForElement(e){let t=this.tokensByElement.getValuesForKey(e),s=this.readTokensForElement(e),o=Ft(t,s).findIndex(([h,d])=>!Ct(h,d));return o==-1?[[],[]]:[t.slice(o),s.slice(o)]}readTokensForElement(e){let t=this.attributeName,s=e.getAttribute(t)||"";return Tt(s,e,t)}};function Tt(r,e,t){return r.trim().split(/\s+/).filter(s=>s.length).map((s,o)=>({element:e,attributeName:t,content:s,index:o}))}function Ft(r,e){let t=Math.max(r.length,e.length);return Array.from({length:t},(s,o)=>[r[o],e[o]])}function Ct(r,e){return r&&e&&r.index==e.index&&r.content==e.content}var se=class{constructor(e,t,s){this.tokenListObserver=new te(e,t,this),this.delegate=s,this.parseResultsByToken=new WeakMap,this.valuesByTokenByElement=new WeakMap}get started(){return this.tokenListObserver.started}start(){this.tokenListObserver.start()}stop(){this.tokenListObserver.stop()}refresh(){this.tokenListObserver.refresh()}get element(){return this.tokenListObserver.element}get attributeName(){return this.tokenListObserver.attributeName}tokenMatched(e){let{element:t}=e,{value:s}=this.fetchParseResultForToken(e);s&&(this.fetchValuesByTokenForElement(t).set(e,s),this.delegate.elementMatchedValue(t,s))}tokenUnmatched(e){let{element:t}=e,{value:s}=this.fetchParseResultForToken(e);s&&(this.fetchValuesByTokenForElement(t).delete(e),this.delegate.elementUnmatchedValue(t,s))}fetchParseResultForToken(e){let t=this.parseResultsByToken.get(e);return t||(t=this.parseToken(e),this.parseResultsByToken.set(e,t)),t}fetchValuesByTokenForElement(e){let t=this.valuesByTokenByElement.get(e);return t||(t=new Map,this.valuesByTokenByElement.set(e,t)),t}parseToken(e){try{return{value:this.delegate.parseValueForToken(e)}}catch(t){return{error:t}}}},pe=class{constructor(e,t){this.context=e,this.delegate=t,this.bindingsByAction=new Map}start(){this.valueListObserver||(this.valueListObserver=new se(this.element,this.actionAttribute,this),this.valueListObserver.start())}stop(){this.valueListObserver&&(this.valueListObserver.stop(),delete this.valueListObserver,this.disconnectAllActions())}get element(){return this.context.element}get identifier(){return this.context.identifier}get actionAttribute(){return this.schema.actionAttribute}get schema(){return this.context.schema}get bindings(){return Array.from(this.bindingsByAction.values())}connectAction(e){let t=new de(this.context,e);this.bindingsByAction.set(e,t),this.delegate.bindingConnected(t)}disconnectAction(e){let t=this.bindingsByAction.get(e);t&&(this.bindingsByAction.delete(e),this.delegate.bindingDisconnected(t))}disconnectAllActions(){this.bindings.forEach(e=>this.delegate.bindingDisconnected(e,!0)),this.bindingsByAction.clear()}parseValueForToken(e){let t=ue.forToken(e,this.schema);if(t.identifier==this.identifier)return t}elementMatchedValue(e,t){this.connectAction(t)}elementUnmatchedValue(e,t){this.disconnectAction(t)}},me=class{constructor(e,t){this.context=e,this.receiver=t,this.stringMapObserver=new ge(this.element,this),this.valueDescriptorMap=this.controller.valueDescriptorMap}start(){this.stringMapObserver.start(),this.invokeChangedCallbacksForDefaultValues()}stop(){this.stringMapObserver.stop()}get element(){return this.context.element}get controller(){return this.context.controller}getStringMapKeyForAttribute(e){if(e in this.valueDescriptorMap)return this.valueDescriptorMap[e].name}stringMapKeyAdded(e,t){let s=this.valueDescriptorMap[t];this.hasValue(e)||this.invokeChangedCallback(e,s.writer(this.receiver[e]),s.writer(s.defaultValue))}stringMapValueChanged(e,t,s){let o=this.valueDescriptorNameMap[t];e!==null&&(s===null&&(s=o.writer(o.defaultValue)),this.invokeChangedCallback(t,e,s))}stringMapKeyRemoved(e,t,s){let o=this.valueDescriptorNameMap[e];this.hasValue(e)?this.invokeChangedCallback(e,o.writer(this.receiver[e]),s):this.invokeChangedCallback(e,o.writer(o.defaultValue),s)}invokeChangedCallbacksForDefaultValues(){for(let{key:e,name:t,defaultValue:s,writer:o}of this.valueDescriptors)s!=null&&!this.controller.data.has(e)&&this.invokeChangedCallback(t,o(s),void 0)}invokeChangedCallback(e,t,s){let o=`${e}Changed`,h=this.receiver[o];if(typeof h=="function"){let d=this.valueDescriptorNameMap[e];try{let f=d.reader(t),g=s;s&&(g=d.reader(s)),h.call(this.receiver,f,g)}catch(f){throw f instanceof TypeError&&(f.message=`Stimulus Value "${this.context.identifier}.${d.name}" - ${f.message}`),f}}}get valueDescriptors(){let{valueDescriptorMap:e}=this;return Object.keys(e).map(t=>e[t])}get valueDescriptorNameMap(){let e={};return Object.keys(this.valueDescriptorMap).forEach(t=>{let s=this.valueDescriptorMap[t];e[s.name]=s}),e}hasValue(e){let t=this.valueDescriptorNameMap[e],s=`has${R(t.name)}`;return this.receiver[s]}},be=class{constructor(e,t){this.context=e,this.delegate=t,this.targetsByName=new C}start(){this.tokenListObserver||(this.tokenListObserver=new te(this.element,this.attributeName,this),this.tokenListObserver.start())}stop(){this.tokenListObserver&&(this.disconnectAllTargets(),this.tokenListObserver.stop(),delete this.tokenListObserver)}tokenMatched({element:e,content:t}){this.scope.containsElement(e)&&this.connectTarget(e,t)}tokenUnmatched({element:e,content:t}){this.disconnectTarget(e,t)}connectTarget(e,t){var s;this.targetsByName.has(t,e)||(this.targetsByName.add(t,e),(s=this.tokenListObserver)===null||s===void 0||s.pause(()=>this.delegate.targetConnected(e,t)))}disconnectTarget(e,t){var s;this.targetsByName.has(t,e)&&(this.targetsByName.delete(t,e),(s=this.tokenListObserver)===null||s===void 0||s.pause(()=>this.delegate.targetDisconnected(e,t)))}disconnectAllTargets(){for(let e of this.targetsByName.keys)for(let t of this.targetsByName.getValuesForKey(e))this.disconnectTarget(t,e)}get attributeName(){return`data-${this.context.identifier}-target`}get element(){return this.context.element}get scope(){return this.context.scope}};function K(r,e){let t=Ge(r);return Array.from(t.reduce((s,o)=>(St(o,e).forEach(h=>s.add(h)),s),new Set))}function Mt(r,e){return Ge(r).reduce((s,o)=>(s.push(...Bt(o,e)),s),[])}function Ge(r){let e=[];for(;r;)e.push(r),r=Object.getPrototypeOf(r);return e.reverse()}function St(r,e){let t=r[e];return Array.isArray(t)?t:[]}function Bt(r,e){let t=r[e];return t?Object.keys(t).map(s=>[s,t[s]]):[]}var ve=class{constructor(e,t){this.started=!1,this.context=e,this.delegate=t,this.outletsByName=new C,this.outletElementsByName=new C,this.selectorObserverMap=new Map,this.attributeObserverMap=new Map}start(){this.started||(this.outletDefinitions.forEach(e=>{this.setupSelectorObserverForOutlet(e),this.setupAttributeObserverForOutlet(e)}),this.started=!0,this.dependentContexts.forEach(e=>e.refresh()))}refresh(){this.selectorObserverMap.forEach(e=>e.refresh()),this.attributeObserverMap.forEach(e=>e.refresh())}stop(){this.started&&(this.started=!1,this.disconnectAllOutlets(),this.stopSelectorObservers(),this.stopAttributeObservers())}stopSelectorObservers(){this.selectorObserverMap.size>0&&(this.selectorObserverMap.forEach(e=>e.stop()),this.selectorObserverMap.clear())}stopAttributeObservers(){this.attributeObserverMap.size>0&&(this.attributeObserverMap.forEach(e=>e.stop()),this.attributeObserverMap.clear())}selectorMatched(e,t,{outletName:s}){let o=this.getOutlet(e,s);o&&this.connectOutlet(o,e,s)}selectorUnmatched(e,t,{outletName:s}){let o=this.getOutletFromMap(e,s);o&&this.disconnectOutlet(o,e,s)}selectorMatchElement(e,{outletName:t}){let s=this.selector(t),o=this.hasOutlet(e,t),h=e.matches(`[${this.schema.controllerAttribute}~=${t}]`);return s?o&&h&&e.matches(s):!1}elementMatchedAttribute(e,t){let s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}elementAttributeValueChanged(e,t){let s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}elementUnmatchedAttribute(e,t){let s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}connectOutlet(e,t,s){var o;this.outletElementsByName.has(s,t)||(this.outletsByName.add(s,e),this.outletElementsByName.add(s,t),(o=this.selectorObserverMap.get(s))===null||o===void 0||o.pause(()=>this.delegate.outletConnected(e,t,s)))}disconnectOutlet(e,t,s){var o;this.outletElementsByName.has(s,t)&&(this.outletsByName.delete(s,e),this.outletElementsByName.delete(s,t),(o=this.selectorObserverMap.get(s))===null||o===void 0||o.pause(()=>this.delegate.outletDisconnected(e,t,s)))}disconnectAllOutlets(){for(let e of this.outletElementsByName.keys)for(let t of this.outletElementsByName.getValuesForKey(e))for(let s of this.outletsByName.getValuesForKey(e))this.disconnectOutlet(s,t,e)}updateSelectorObserverForOutlet(e){let t=this.selectorObserverMap.get(e);t&&(t.selector=this.selector(e))}setupSelectorObserverForOutlet(e){let t=this.selector(e),s=new fe(document.body,t,this,{outletName:e});this.selectorObserverMap.set(e,s),s.start()}setupAttributeObserverForOutlet(e){let t=this.attributeNameForOutletName(e),s=new ee(this.scope.element,t,this);this.attributeObserverMap.set(e,s),s.start()}selector(e){return this.scope.outlets.getSelectorForOutletName(e)}attributeNameForOutletName(e){return this.scope.schema.outletAttributeForScope(this.identifier,e)}getOutletNameFromOutletAttributeName(e){return this.outletDefinitions.find(t=>this.attributeNameForOutletName(t)===e)}get outletDependencies(){let e=new C;return this.router.modules.forEach(t=>{let s=t.definition.controllerConstructor;K(s,"outlets").forEach(h=>e.add(h,t.identifier))}),e}get outletDefinitions(){return this.outletDependencies.getKeysForValue(this.identifier)}get dependentControllerIdentifiers(){return this.outletDependencies.getValuesForKey(this.identifier)}get dependentContexts(){let e=this.dependentControllerIdentifiers;return this.router.contexts.filter(t=>e.includes(t.identifier))}hasOutlet(e,t){return!!this.getOutlet(e,t)||!!this.getOutletFromMap(e,t)}getOutlet(e,t){return this.application.getControllerForElementAndIdentifier(e,t)}getOutletFromMap(e,t){return this.outletsByName.getValuesForKey(t).find(s=>s.element===e)}get scope(){return this.context.scope}get schema(){return this.context.schema}get identifier(){return this.context.identifier}get application(){return this.context.application}get router(){return this.application.router}},ye=class{constructor(e,t){this.logDebugActivity=(s,o={})=>{let{identifier:h,controller:d,element:f}=this;o=Object.assign({identifier:h,controller:d,element:f},o),this.application.logDebugActivity(this.identifier,s,o)},this.module=e,this.scope=t,this.controller=new e.controllerConstructor(this),this.bindingObserver=new pe(this,this.dispatcher),this.valueObserver=new me(this,this.controller),this.targetObserver=new be(this,this),this.outletObserver=new ve(this,this);try{this.controller.initialize(),this.logDebugActivity("initialize")}catch(s){this.handleError(s,"initializing controller")}}connect(){this.bindingObserver.start(),this.valueObserver.start(),this.targetObserver.start(),this.outletObserver.start();try{this.controller.connect(),this.logDebugActivity("connect")}catch(e){this.handleError(e,"connecting controller")}}refresh(){this.outletObserver.refresh()}disconnect(){try{this.controller.disconnect(),this.logDebugActivity("disconnect")}catch(e){this.handleError(e,"disconnecting controller")}this.outletObserver.stop(),this.targetObserver.stop(),this.valueObserver.stop(),this.bindingObserver.stop()}get application(){return this.module.application}get identifier(){return this.module.identifier}get schema(){return this.application.schema}get dispatcher(){return this.application.dispatcher}get element(){return this.scope.element}get parentElement(){return this.element.parentElement}handleError(e,t,s={}){let{identifier:o,controller:h,element:d}=this;s=Object.assign({identifier:o,controller:h,element:d},s),this.application.handleError(e,`Error ${t}`,s)}targetConnected(e,t){this.invokeControllerMethod(`${t}TargetConnected`,e)}targetDisconnected(e,t){this.invokeControllerMethod(`${t}TargetDisconnected`,e)}outletConnected(e,t,s){this.invokeControllerMethod(`${le(s)}OutletConnected`,e,t)}outletDisconnected(e,t,s){this.invokeControllerMethod(`${le(s)}OutletDisconnected`,e,t)}invokeControllerMethod(e,...t){let s=this.controller;typeof s[e]=="function"&&s[e](...t)}};function Nt(r){return Lt(r,$t(r))}function Lt(r,e){let t=It(r),s=Dt(r.prototype,e);return Object.defineProperties(t.prototype,s),t}function $t(r){return K(r,"blessings").reduce((t,s)=>{let o=s(r);for(let h in o){let d=t[h]||{};t[h]=Object.assign(d,o[h])}return t},{})}function Dt(r,e){return jt(e).reduce((t,s)=>{let o=kt(r,e,s);return o&&Object.assign(t,{[s]:o}),t},{})}function kt(r,e,t){let s=Object.getOwnPropertyDescriptor(r,t);if(!(s&&"value"in s)){let h=Object.getOwnPropertyDescriptor(e,t).value;return s&&(h.get=s.get||h.get,h.set=s.set||h.set),h}}var jt=(()=>typeof Object.getOwnPropertySymbols=="function"?r=>[...Object.getOwnPropertyNames(r),...Object.getOwnPropertySymbols(r)]:Object.getOwnPropertyNames)(),It=(()=>{function r(t){function s(){return Reflect.construct(t,arguments,new.target)}return s.prototype=Object.create(t.prototype,{constructor:{value:s}}),Reflect.setPrototypeOf(s,t),s}function e(){let s=r(function(){this.a.call(this)});return s.prototype.a=function(){},new s}try{return e(),r}catch(t){return s=>class extends s{}}})();function Vt(r){return{identifier:r.identifier,controllerConstructor:Nt(r.controllerConstructor)}}var Ee=class{constructor(e,t){this.application=e,this.definition=Vt(t),this.contextsByScope=new WeakMap,this.connectedContexts=new Set}get identifier(){return this.definition.identifier}get controllerConstructor(){return this.definition.controllerConstructor}get contexts(){return Array.from(this.connectedContexts)}connectContextForScope(e){let t=this.fetchContextForScope(e);this.connectedContexts.add(t),t.connect()}disconnectContextForScope(e){let t=this.contextsByScope.get(e);t&&(this.connectedContexts.delete(t),t.disconnect())}fetchContextForScope(e){let t=this.contextsByScope.get(e);return t||(t=new ye(this,e),this.contextsByScope.set(e,t)),t}},Ae=class{constructor(e){this.scope=e}has(e){return this.data.has(this.getDataKey(e))}get(e){return this.getAll(e)[0]}getAll(e){let t=this.data.get(this.getDataKey(e))||"";return yt(t)}getAttributeName(e){return this.data.getAttributeNameForKey(this.getDataKey(e))}getDataKey(e){return`${e}-class`}get data(){return this.scope.data}},Oe=class{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get(e){let t=this.getAttributeNameForKey(e);return this.element.getAttribute(t)}set(e,t){let s=this.getAttributeNameForKey(e);return this.element.setAttribute(s,t),this.get(e)}has(e){let t=this.getAttributeNameForKey(e);return this.element.hasAttribute(t)}delete(e){if(this.has(e)){let t=this.getAttributeNameForKey(e);return this.element.removeAttribute(t),!0}else return!1}getAttributeNameForKey(e){return`data-${this.identifier}-${Xe(e)}`}},we=class{constructor(e){this.warnedKeysByObject=new WeakMap,this.logger=e}warn(e,t,s){let o=this.warnedKeysByObject.get(e);o||(o=new Set,this.warnedKeysByObject.set(e,o)),o.has(t)||(o.add(t),this.logger.warn(s,e))}};function xe(r,e){return`[${r}~="${e}"]`}var Te=class{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get schema(){return this.scope.schema}has(e){return this.find(e)!=null}find(...e){return e.reduce((t,s)=>t||this.findTarget(s)||this.findLegacyTarget(s),void 0)}findAll(...e){return e.reduce((t,s)=>[...t,...this.findAllTargets(s),...this.findAllLegacyTargets(s)],[])}findTarget(e){let t=this.getSelectorForTargetName(e);return this.scope.findElement(t)}findAllTargets(e){let t=this.getSelectorForTargetName(e);return this.scope.findAllElements(t)}getSelectorForTargetName(e){let t=this.schema.targetAttributeForScope(this.identifier);return xe(t,e)}findLegacyTarget(e){let t=this.getLegacySelectorForTargetName(e);return this.deprecate(this.scope.findElement(t),e)}findAllLegacyTargets(e){let t=this.getLegacySelectorForTargetName(e);return this.scope.findAllElements(t).map(s=>this.deprecate(s,e))}getLegacySelectorForTargetName(e){let t=`${this.identifier}.${e}`;return xe(this.schema.targetAttribute,t)}deprecate(e,t){if(e){let{identifier:s}=this,o=this.schema.targetAttribute,h=this.schema.targetAttributeForScope(s);this.guide.warn(e,`target:${t}`,`Please replace ${o}="${s}.${t}" with ${h}="${t}". The ${o} attribute is deprecated and will be removed in a future version of Stimulus.`)}return e}get guide(){return this.scope.guide}},Fe=class{constructor(e,t){this.scope=e,this.controllerElement=t}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get schema(){return this.scope.schema}has(e){return this.find(e)!=null}find(...e){return e.reduce((t,s)=>t||this.findOutlet(s),void 0)}findAll(...e){return e.reduce((t,s)=>[...t,...this.findAllOutlets(s)],[])}getSelectorForOutletName(e){let t=this.schema.outletAttributeForScope(this.identifier,e);return this.controllerElement.getAttribute(t)}findOutlet(e){let t=this.getSelectorForOutletName(e);if(t)return this.findElement(t,e)}findAllOutlets(e){let t=this.getSelectorForOutletName(e);return t?this.findAllElements(t,e):[]}findElement(e,t){return this.scope.queryElements(e).filter(o=>this.matchesElement(o,e,t))[0]}findAllElements(e,t){return this.scope.queryElements(e).filter(o=>this.matchesElement(o,e,t))}matchesElement(e,t,s){let o=e.getAttribute(this.scope.schema.controllerAttribute)||"";return e.matches(t)&&o.split(" ").includes(s)}},U=class{constructor(e,t,s,o){this.targets=new Te(this),this.classes=new Ae(this),this.data=new Oe(this),this.containsElement=h=>h.closest(this.controllerSelector)===this.element,this.schema=e,this.element=t,this.identifier=s,this.guide=new we(o),this.outlets=new Fe(this.documentScope,t)}findElement(e){return this.element.matches(e)?this.element:this.queryElements(e).find(this.containsElement)}findAllElements(e){return[...this.element.matches(e)?[this.element]:[],...this.queryElements(e).filter(this.containsElement)]}queryElements(e){return Array.from(this.element.querySelectorAll(e))}get controllerSelector(){return xe(this.schema.controllerAttribute,this.identifier)}get isDocumentScope(){return this.element===document.documentElement}get documentScope(){return this.isDocumentScope?this:new U(this.schema,document.documentElement,this.identifier,this.guide.logger)}},Ce=class{constructor(e,t,s){this.element=e,this.schema=t,this.delegate=s,this.valueListObserver=new se(this.element,this.controllerAttribute,this),this.scopesByIdentifierByElement=new WeakMap,this.scopeReferenceCounts=new WeakMap}start(){this.valueListObserver.start()}stop(){this.valueListObserver.stop()}get controllerAttribute(){return this.schema.controllerAttribute}parseValueForToken(e){let{element:t,content:s}=e;return this.parseValueForElementAndIdentifier(t,s)}parseValueForElementAndIdentifier(e,t){let s=this.fetchScopesByIdentifierForElement(e),o=s.get(t);return o||(o=this.delegate.createScopeForElementAndIdentifier(e,t),s.set(t,o)),o}elementMatchedValue(e,t){let s=(this.scopeReferenceCounts.get(t)||0)+1;this.scopeReferenceCounts.set(t,s),s==1&&this.delegate.scopeConnected(t)}elementUnmatchedValue(e,t){let s=this.scopeReferenceCounts.get(t);s&&(this.scopeReferenceCounts.set(t,s-1),s==1&&this.delegate.scopeDisconnected(t))}fetchScopesByIdentifierForElement(e){let t=this.scopesByIdentifierByElement.get(e);return t||(t=new Map,this.scopesByIdentifierByElement.set(e,t)),t}},Me=class{constructor(e){this.application=e,this.scopeObserver=new Ce(this.element,this.schema,this),this.scopesByIdentifier=new C,this.modulesByIdentifier=new Map}get element(){return this.application.element}get schema(){return this.application.schema}get logger(){return this.application.logger}get controllerAttribute(){return this.schema.controllerAttribute}get modules(){return Array.from(this.modulesByIdentifier.values())}get contexts(){return this.modules.reduce((e,t)=>e.concat(t.contexts),[])}start(){this.scopeObserver.start()}stop(){this.scopeObserver.stop()}loadDefinition(e){this.unloadIdentifier(e.identifier);let t=new Ee(this.application,e);this.connectModule(t);let s=e.controllerConstructor.afterLoad;s&&s.call(e.controllerConstructor,e.identifier,this.application)}unloadIdentifier(e){let t=this.modulesByIdentifier.get(e);t&&this.disconnectModule(t)}getContextForElementAndIdentifier(e,t){let s=this.modulesByIdentifier.get(t);if(s)return s.contexts.find(o=>o.element==e)}proposeToConnectScopeForElementAndIdentifier(e,t){let s=this.scopeObserver.parseValueForElementAndIdentifier(e,t);s?this.scopeObserver.elementMatchedValue(s.element,s):console.error(`Couldn't find or create scope for identifier: "${t}" and element:`,e)}handleError(e,t,s){this.application.handleError(e,t,s)}createScopeForElementAndIdentifier(e,t){return new U(this.schema,e,t,this.logger)}scopeConnected(e){this.scopesByIdentifier.add(e.identifier,e);let t=this.modulesByIdentifier.get(e.identifier);t&&t.connectContextForScope(e)}scopeDisconnected(e){this.scopesByIdentifier.delete(e.identifier,e);let t=this.modulesByIdentifier.get(e.identifier);t&&t.disconnectContextForScope(e)}connectModule(e){this.modulesByIdentifier.set(e.identifier,e),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(s=>e.connectContextForScope(s))}disconnectModule(e){this.modulesByIdentifier.delete(e.identifier),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(s=>e.disconnectContextForScope(s))}},_t={controllerAttribute:"data-controller",actionAttribute:"data-action",targetAttribute:"data-target",targetAttributeForScope:r=>`data-${r}-target`,outletAttributeForScope:(r,e)=>`data-${r}-${e}-outlet`,keyMappings:Object.assign(Object.assign({enter:"Enter",tab:"Tab",esc:"Escape",space:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",home:"Home",end:"End",page_up:"PageUp",page_down:"PageDown"},Re("abcdefghijklmnopqrstuvwxyz".split("").map(r=>[r,r]))),Re("0123456789".split("").map(r=>[r,r])))};function Re(r){return r.reduce((e,[t,s])=>Object.assign(Object.assign({},e),{[t]:s}),{})}var re=class{constructor(e=document.documentElement,t=_t){this.logger=console,this.debug=!1,this.logDebugActivity=(s,o,h={})=>{this.debug&&this.logFormattedMessage(s,o,h)},this.element=e,this.schema=t,this.dispatcher=new ce(this),this.router=new Me(this),this.actionDescriptorFilters=Object.assign({},ft)}static start(e,t){let s=new this(e,t);return s.start(),s}start(){return M(this,null,function*(){yield Pt(),this.logDebugActivity("application","starting"),this.dispatcher.start(),this.router.start(),this.logDebugActivity("application","start")})}stop(){this.logDebugActivity("application","stopping"),this.dispatcher.stop(),this.router.stop(),this.logDebugActivity("application","stop")}register(e,t){this.load({identifier:e,controllerConstructor:t})}registerActionOption(e,t){this.actionDescriptorFilters[e]=t}load(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(o=>{o.controllerConstructor.shouldLoad&&this.router.loadDefinition(o)})}unload(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(o=>this.router.unloadIdentifier(o))}get controllers(){return this.router.contexts.map(e=>e.controller)}getControllerForElementAndIdentifier(e,t){let s=this.router.getContextForElementAndIdentifier(e,t);return s?s.controller:null}handleError(e,t,s){var o;this.logger.error(`%s
|
2
|
+
|
3
|
+
%o
|
4
|
+
|
5
|
+
%o`,t,e,s),(o=window.onerror)===null||o===void 0||o.call(window,t,"",0,0,e)}logFormattedMessage(e,t,s={}){s=Object.assign({application:this},s),this.logger.groupCollapsed(`${e} #${t}`),this.logger.log("details:",Object.assign({},s)),this.logger.groupEnd()}};function Pt(){return new Promise(r=>{document.readyState=="loading"?document.addEventListener("DOMContentLoaded",()=>r()):r()})}function Ut(r){return K(r,"classes").reduce((t,s)=>Object.assign(t,qt(s)),{})}function qt(r){return{[`${r}Class`]:{get(){let{classes:e}=this;if(e.has(r))return e.get(r);{let t=e.getAttributeName(r);throw new Error(`Missing attribute "${t}"`)}}},[`${r}Classes`]:{get(){return this.classes.getAll(r)}},[`has${R(r)}Class`]:{get(){return this.classes.has(r)}}}}function Rt(r){return K(r,"outlets").reduce((t,s)=>Object.assign(t,Kt(s)),{})}function Ke(r,e,t){return r.application.getControllerForElementAndIdentifier(e,t)}function ze(r,e,t){let s=Ke(r,e,t);if(s||(r.application.router.proposeToConnectScopeForElementAndIdentifier(e,t),s=Ke(r,e,t),s))return s}function Kt(r){let e=le(r);return{[`${e}Outlet`]:{get(){let t=this.outlets.find(r),s=this.outlets.getSelectorForOutletName(r);if(t){let o=ze(this,t,r);if(o)return o;throw new Error(`The provided outlet element is missing an outlet controller "${r}" instance for host controller "${this.identifier}"`)}throw new Error(`Missing outlet element "${r}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${s}".`)}},[`${e}Outlets`]:{get(){let t=this.outlets.findAll(r);return t.length>0?t.map(s=>{let o=ze(this,s,r);if(o)return o;console.warn(`The provided outlet element is missing an outlet controller "${r}" instance for host controller "${this.identifier}"`,s)}).filter(s=>s):[]}},[`${e}OutletElement`]:{get(){let t=this.outlets.find(r),s=this.outlets.getSelectorForOutletName(r);if(t)return t;throw new Error(`Missing outlet element "${r}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${s}".`)}},[`${e}OutletElements`]:{get(){return this.outlets.findAll(r)}},[`has${R(e)}Outlet`]:{get(){return this.outlets.has(r)}}}}function zt(r){return K(r,"targets").reduce((t,s)=>Object.assign(t,Wt(s)),{})}function Wt(r){return{[`${r}Target`]:{get(){let e=this.targets.find(r);if(e)return e;throw new Error(`Missing target element "${r}" for "${this.identifier}" controller`)}},[`${r}Targets`]:{get(){return this.targets.findAll(r)}},[`has${R(r)}Target`]:{get(){return this.targets.has(r)}}}}function Ht(r){let e=Mt(r,"values"),t={valueDescriptorMap:{get(){return e.reduce((s,o)=>{let h=Ye(o,this.identifier),d=this.data.getAttributeNameForKey(h.key);return Object.assign(s,{[d]:h})},{})}}};return e.reduce((s,o)=>Object.assign(s,Jt(o)),t)}function Jt(r,e){let t=Ye(r,e),{key:s,name:o,reader:h,writer:d}=t;return{[o]:{get(){let f=this.data.get(s);return f!==null?h(f):t.defaultValue},set(f){f===void 0?this.data.delete(s):this.data.set(s,d(f))}},[`has${R(o)}`]:{get(){return this.data.has(s)||t.hasCustomDefaultValue}}}}function Ye([r,e],t){return Yt({controller:t,token:r,typeDefinition:e})}function ne(r){switch(r){case Array:return"array";case Boolean:return"boolean";case Number:return"number";case Object:return"object";case String:return"string"}}function q(r){switch(typeof r){case"boolean":return"boolean";case"number":return"number";case"string":return"string"}if(Array.isArray(r))return"array";if(Object.prototype.toString.call(r)==="[object Object]")return"object"}function Xt(r){let{controller:e,token:t,typeObject:s}=r,o=Pe(s.type),h=Pe(s.default),d=o&&h,f=o&&!h,g=!o&&h,v=ne(s.type),w=q(r.typeObject.default);if(f)return v;if(g)return w;if(v!==w){let B=e?`${e}.${t}`:t;throw new Error(`The specified default value for the Stimulus Value "${B}" must match the defined type "${v}". The provided default value of "${s.default}" is of type "${w}".`)}if(d)return v}function Qt(r){let{controller:e,token:t,typeDefinition:s}=r,h=Xt({controller:e,token:t,typeObject:s}),d=q(s),f=ne(s),g=h||d||f;if(g)return g;let v=e?`${e}.${s}`:t;throw new Error(`Unknown value type "${v}" for "${t}" value`)}function Gt(r){let e=ne(r);if(e)return We[e];let t=he(r,"default"),s=he(r,"type"),o=r;if(t)return o.default;if(s){let{type:h}=o,d=ne(h);if(d)return We[d]}return r}function Yt(r){let{token:e,typeDefinition:t}=r,s=`${Xe(e)}-value`,o=Qt(r);return{type:o,key:s,name:Se(s),get defaultValue(){return Gt(t)},get hasCustomDefaultValue(){return q(t)!==void 0},reader:Zt[o],writer:He[o]||He.default}}var We={get array(){return[]},boolean:!1,number:0,get object(){return{}},string:""},Zt={array(r){let e=JSON.parse(r);if(!Array.isArray(e))throw new TypeError(`expected value of type "array" but instead got value "${r}" of type "${q(e)}"`);return e},boolean(r){return!(r=="0"||String(r).toLowerCase()=="false")},number(r){return Number(r.replace(/_/g,""))},object(r){let e=JSON.parse(r);if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(`expected value of type "object" but instead got value "${r}" of type "${q(e)}"`);return e},string(r){return r}},He={default:es,array:Je,object:Je};function Je(r){return JSON.stringify(r)}function es(r){return`${r}`}var m=class{constructor(e){this.context=e}static get shouldLoad(){return!0}static afterLoad(e,t){}get application(){return this.context.application}get scope(){return this.context.scope}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get targets(){return this.scope.targets}get outlets(){return this.scope.outlets}get classes(){return this.scope.classes}get data(){return this.scope.data}initialize(){}connect(){}disconnect(){}dispatch(e,{target:t=this.element,detail:s={},prefix:o=this.identifier,bubbles:h=!0,cancelable:d=!0}={}){let f=o?`${o}:${e}`:e,g=new CustomEvent(f,{detail:s,bubbles:h,cancelable:d});return t.dispatchEvent(g),g}};m.blessings=[Ut,zt,Ht,Rt];m.targets=[];m.outlets=[];m.values={};var tt={exports:{}};(function(r,e){(function(t){r.exports=t()})(function(t){var s=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function o(u,l){var i=u[0],n=u[1],c=u[2],a=u[3];i+=(n&c|~n&a)+l[0]-680876936|0,i=(i<<7|i>>>25)+n|0,a+=(i&n|~i&c)+l[1]-389564586|0,a=(a<<12|a>>>20)+i|0,c+=(a&i|~a&n)+l[2]+606105819|0,c=(c<<17|c>>>15)+a|0,n+=(c&a|~c&i)+l[3]-1044525330|0,n=(n<<22|n>>>10)+c|0,i+=(n&c|~n&a)+l[4]-176418897|0,i=(i<<7|i>>>25)+n|0,a+=(i&n|~i&c)+l[5]+1200080426|0,a=(a<<12|a>>>20)+i|0,c+=(a&i|~a&n)+l[6]-1473231341|0,c=(c<<17|c>>>15)+a|0,n+=(c&a|~c&i)+l[7]-45705983|0,n=(n<<22|n>>>10)+c|0,i+=(n&c|~n&a)+l[8]+1770035416|0,i=(i<<7|i>>>25)+n|0,a+=(i&n|~i&c)+l[9]-1958414417|0,a=(a<<12|a>>>20)+i|0,c+=(a&i|~a&n)+l[10]-42063|0,c=(c<<17|c>>>15)+a|0,n+=(c&a|~c&i)+l[11]-1990404162|0,n=(n<<22|n>>>10)+c|0,i+=(n&c|~n&a)+l[12]+1804603682|0,i=(i<<7|i>>>25)+n|0,a+=(i&n|~i&c)+l[13]-40341101|0,a=(a<<12|a>>>20)+i|0,c+=(a&i|~a&n)+l[14]-1502002290|0,c=(c<<17|c>>>15)+a|0,n+=(c&a|~c&i)+l[15]+1236535329|0,n=(n<<22|n>>>10)+c|0,i+=(n&a|c&~a)+l[1]-165796510|0,i=(i<<5|i>>>27)+n|0,a+=(i&c|n&~c)+l[6]-1069501632|0,a=(a<<9|a>>>23)+i|0,c+=(a&n|i&~n)+l[11]+643717713|0,c=(c<<14|c>>>18)+a|0,n+=(c&i|a&~i)+l[0]-373897302|0,n=(n<<20|n>>>12)+c|0,i+=(n&a|c&~a)+l[5]-701558691|0,i=(i<<5|i>>>27)+n|0,a+=(i&c|n&~c)+l[10]+38016083|0,a=(a<<9|a>>>23)+i|0,c+=(a&n|i&~n)+l[15]-660478335|0,c=(c<<14|c>>>18)+a|0,n+=(c&i|a&~i)+l[4]-405537848|0,n=(n<<20|n>>>12)+c|0,i+=(n&a|c&~a)+l[9]+568446438|0,i=(i<<5|i>>>27)+n|0,a+=(i&c|n&~c)+l[14]-1019803690|0,a=(a<<9|a>>>23)+i|0,c+=(a&n|i&~n)+l[3]-187363961|0,c=(c<<14|c>>>18)+a|0,n+=(c&i|a&~i)+l[8]+1163531501|0,n=(n<<20|n>>>12)+c|0,i+=(n&a|c&~a)+l[13]-1444681467|0,i=(i<<5|i>>>27)+n|0,a+=(i&c|n&~c)+l[2]-51403784|0,a=(a<<9|a>>>23)+i|0,c+=(a&n|i&~n)+l[7]+1735328473|0,c=(c<<14|c>>>18)+a|0,n+=(c&i|a&~i)+l[12]-1926607734|0,n=(n<<20|n>>>12)+c|0,i+=(n^c^a)+l[5]-378558|0,i=(i<<4|i>>>28)+n|0,a+=(i^n^c)+l[8]-2022574463|0,a=(a<<11|a>>>21)+i|0,c+=(a^i^n)+l[11]+1839030562|0,c=(c<<16|c>>>16)+a|0,n+=(c^a^i)+l[14]-35309556|0,n=(n<<23|n>>>9)+c|0,i+=(n^c^a)+l[1]-1530992060|0,i=(i<<4|i>>>28)+n|0,a+=(i^n^c)+l[4]+1272893353|0,a=(a<<11|a>>>21)+i|0,c+=(a^i^n)+l[7]-155497632|0,c=(c<<16|c>>>16)+a|0,n+=(c^a^i)+l[10]-1094730640|0,n=(n<<23|n>>>9)+c|0,i+=(n^c^a)+l[13]+681279174|0,i=(i<<4|i>>>28)+n|0,a+=(i^n^c)+l[0]-358537222|0,a=(a<<11|a>>>21)+i|0,c+=(a^i^n)+l[3]-722521979|0,c=(c<<16|c>>>16)+a|0,n+=(c^a^i)+l[6]+76029189|0,n=(n<<23|n>>>9)+c|0,i+=(n^c^a)+l[9]-640364487|0,i=(i<<4|i>>>28)+n|0,a+=(i^n^c)+l[12]-421815835|0,a=(a<<11|a>>>21)+i|0,c+=(a^i^n)+l[15]+530742520|0,c=(c<<16|c>>>16)+a|0,n+=(c^a^i)+l[2]-995338651|0,n=(n<<23|n>>>9)+c|0,i+=(c^(n|~a))+l[0]-198630844|0,i=(i<<6|i>>>26)+n|0,a+=(n^(i|~c))+l[7]+1126891415|0,a=(a<<10|a>>>22)+i|0,c+=(i^(a|~n))+l[14]-1416354905|0,c=(c<<15|c>>>17)+a|0,n+=(a^(c|~i))+l[5]-57434055|0,n=(n<<21|n>>>11)+c|0,i+=(c^(n|~a))+l[12]+1700485571|0,i=(i<<6|i>>>26)+n|0,a+=(n^(i|~c))+l[3]-1894986606|0,a=(a<<10|a>>>22)+i|0,c+=(i^(a|~n))+l[10]-1051523|0,c=(c<<15|c>>>17)+a|0,n+=(a^(c|~i))+l[1]-2054922799|0,n=(n<<21|n>>>11)+c|0,i+=(c^(n|~a))+l[8]+1873313359|0,i=(i<<6|i>>>26)+n|0,a+=(n^(i|~c))+l[15]-30611744|0,a=(a<<10|a>>>22)+i|0,c+=(i^(a|~n))+l[6]-1560198380|0,c=(c<<15|c>>>17)+a|0,n+=(a^(c|~i))+l[13]+1309151649|0,n=(n<<21|n>>>11)+c|0,i+=(c^(n|~a))+l[4]-145523070|0,i=(i<<6|i>>>26)+n|0,a+=(n^(i|~c))+l[11]-1120210379|0,a=(a<<10|a>>>22)+i|0,c+=(i^(a|~n))+l[2]+718787259|0,c=(c<<15|c>>>17)+a|0,n+=(a^(c|~i))+l[9]-343485551|0,n=(n<<21|n>>>11)+c|0,u[0]=i+u[0]|0,u[1]=n+u[1]|0,u[2]=c+u[2]|0,u[3]=a+u[3]|0}function h(u){var l=[],i;for(i=0;i<64;i+=4)l[i>>2]=u.charCodeAt(i)+(u.charCodeAt(i+1)<<8)+(u.charCodeAt(i+2)<<16)+(u.charCodeAt(i+3)<<24);return l}function d(u){var l=[],i;for(i=0;i<64;i+=4)l[i>>2]=u[i]+(u[i+1]<<8)+(u[i+2]<<16)+(u[i+3]<<24);return l}function f(u){var l=u.length,i=[1732584193,-271733879,-1732584194,271733878],n,c,a,y,A,p;for(n=64;n<=l;n+=64)o(i,h(u.substring(n-64,n)));for(u=u.substring(n-64),c=u.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<c;n+=1)a[n>>2]|=u.charCodeAt(n)<<(n%4<<3);if(a[n>>2]|=128<<(n%4<<3),n>55)for(o(i,a),n=0;n<16;n+=1)a[n]=0;return y=l*8,y=y.toString(16).match(/(.*?)(.{0,8})$/),A=parseInt(y[2],16),p=parseInt(y[1],16)||0,a[14]=A,a[15]=p,o(i,a),i}function g(u){var l=u.length,i=[1732584193,-271733879,-1732584194,271733878],n,c,a,y,A,p;for(n=64;n<=l;n+=64)o(i,d(u.subarray(n-64,n)));for(u=n-64<l?u.subarray(n-64):new Uint8Array(0),c=u.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<c;n+=1)a[n>>2]|=u[n]<<(n%4<<3);if(a[n>>2]|=128<<(n%4<<3),n>55)for(o(i,a),n=0;n<16;n+=1)a[n]=0;return y=l*8,y=y.toString(16).match(/(.*?)(.{0,8})$/),A=parseInt(y[2],16),p=parseInt(y[1],16)||0,a[14]=A,a[15]=p,o(i,a),i}function v(u){var l="",i;for(i=0;i<4;i+=1)l+=s[u>>i*8+4&15]+s[u>>i*8&15];return l}function w(u){var l;for(l=0;l<u.length;l+=1)u[l]=v(u[l]);return u.join("")}w(f("hello")),typeof ArrayBuffer!="undefined"&&!ArrayBuffer.prototype.slice&&function(){function u(l,i){return l=l|0||0,l<0?Math.max(l+i,0):Math.min(l,i)}ArrayBuffer.prototype.slice=function(l,i){var n=this.byteLength,c=u(l,n),a=n,y,A,p,O;return i!==t&&(a=u(i,n)),c>a?new ArrayBuffer(0):(y=a-c,A=new ArrayBuffer(y),p=new Uint8Array(A),O=new Uint8Array(this,c,y),p.set(O),A)}}();function B(u){return/[\u0080-\uFFFF]/.test(u)&&(u=unescape(encodeURIComponent(u))),u}function x(u,l){var i=u.length,n=new ArrayBuffer(i),c=new Uint8Array(n),a;for(a=0;a<i;a+=1)c[a]=u.charCodeAt(a);return l?c:n}function G(u){return String.fromCharCode.apply(null,new Uint8Array(u))}function k(u,l,i){var n=new Uint8Array(u.byteLength+l.byteLength);return n.set(new Uint8Array(u)),n.set(new Uint8Array(l),u.byteLength),i?n:n.buffer}function N(u){var l=[],i=u.length,n;for(n=0;n<i-1;n+=2)l.push(parseInt(u.substr(n,2),16));return String.fromCharCode.apply(String,l)}function b(){this.reset()}return b.prototype.append=function(u){return this.appendBinary(B(u)),this},b.prototype.appendBinary=function(u){this._buff+=u,this._length+=u.length;var l=this._buff.length,i;for(i=64;i<=l;i+=64)o(this._hash,h(this._buff.substring(i-64,i)));return this._buff=this._buff.substring(i-64),this},b.prototype.end=function(u){var l=this._buff,i=l.length,n,c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a;for(n=0;n<i;n+=1)c[n>>2]|=l.charCodeAt(n)<<(n%4<<3);return this._finish(c,i),a=w(this._hash),u&&(a=N(a)),this.reset(),a},b.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},b.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},b.prototype.setState=function(u){return this._buff=u.buff,this._length=u.length,this._hash=u.hash,this},b.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},b.prototype._finish=function(u,l){var i=l,n,c,a;if(u[i>>2]|=128<<(i%4<<3),i>55)for(o(this._hash,u),i=0;i<16;i+=1)u[i]=0;n=this._length*8,n=n.toString(16).match(/(.*?)(.{0,8})$/),c=parseInt(n[2],16),a=parseInt(n[1],16)||0,u[14]=c,u[15]=a,o(this._hash,u)},b.hash=function(u,l){return b.hashBinary(B(u),l)},b.hashBinary=function(u,l){var i=f(u),n=w(i);return l?N(n):n},b.ArrayBuffer=function(){this.reset()},b.ArrayBuffer.prototype.append=function(u){var l=k(this._buff.buffer,u,!0),i=l.length,n;for(this._length+=u.byteLength,n=64;n<=i;n+=64)o(this._hash,d(l.subarray(n-64,n)));return this._buff=n-64<i?new Uint8Array(l.buffer.slice(n-64)):new Uint8Array(0),this},b.ArrayBuffer.prototype.end=function(u){var l=this._buff,i=l.length,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],c,a;for(c=0;c<i;c+=1)n[c>>2]|=l[c]<<(c%4<<3);return this._finish(n,i),a=w(this._hash),u&&(a=N(a)),this.reset(),a},b.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},b.ArrayBuffer.prototype.getState=function(){var u=b.prototype.getState.call(this);return u.buff=G(u.buff),u},b.ArrayBuffer.prototype.setState=function(u){return u.buff=x(u.buff,!0),b.prototype.setState.call(this,u)},b.ArrayBuffer.prototype.destroy=b.prototype.destroy,b.ArrayBuffer.prototype._finish=b.prototype._finish,b.ArrayBuffer.hash=function(u,l){var i=g(new Uint8Array(u)),n=w(i);return l?N(n):n},b})})(tt);var ts=tt.exports,ss=File.prototype.slice||File.prototype.mozSlice||File.prototype.webkitSlice,z=class{static create(e,t){new z(e).create(t)}constructor(e){this.file=e,this.chunkSize=2097152,this.chunkCount=Math.ceil(this.file.size/this.chunkSize),this.chunkIndex=0}create(e){this.callback=e,this.md5Buffer=new ts.ArrayBuffer,this.fileReader=new FileReader,this.fileReader.addEventListener("load",t=>this.fileReaderDidLoad(t)),this.fileReader.addEventListener("error",t=>this.fileReaderDidError(t)),this.readNextChunk()}fileReaderDidLoad(e){if(this.md5Buffer.append(e.target.result),!this.readNextChunk()){let t=this.md5Buffer.end(!0),s=btoa(t);this.callback(null,s)}}fileReaderDidError(e){this.callback(`Error reading ${this.file.name}`)}readNextChunk(){if(this.chunkIndex<this.chunkCount||this.chunkIndex==0&&this.chunkCount==0){let e=this.chunkIndex*this.chunkSize,t=Math.min(e+this.chunkSize,this.file.size),s=ss.call(this.file,e,t);return this.fileReader.readAsArrayBuffer(s),this.chunkIndex++,!0}else return!1}};function rs(r){let e=st(document.head,`meta[name="${r}"]`);if(e)return e.getAttribute("content")}function ns(r,e){typeof r=="string"&&(e=r,r=document);let t=r.querySelectorAll(e);return nt(t)}function st(r,e){return typeof r=="string"&&(e=r,r=document),r.querySelector(e)}function rt(r,e,t={}){let{disabled:s}=r,{bubbles:o,cancelable:h,detail:d}=t,f=document.createEvent("Event");f.initEvent(e,o||!0,h||!0),f.detail=d||{};try{r.disabled=!1,r.dispatchEvent(f)}finally{r.disabled=s}return f}function nt(r){return Array.isArray(r)?r:Array.from?Array.from(r):[].slice.call(r)}var Ne=class{constructor(e,t,s,o={}){this.file=e,this.attributes={filename:e.name,content_type:e.type||"application/octet-stream",byte_size:e.size,checksum:t},this.xhr=new XMLHttpRequest,this.xhr.open("POST",s,!0),this.xhr.responseType="json",this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.setRequestHeader("Accept","application/json"),this.xhr.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(o).forEach(d=>{this.xhr.setRequestHeader(d,o[d])});let h=rs("csrf-token");h!=null&&this.xhr.setRequestHeader("X-CSRF-Token",h),this.xhr.addEventListener("load",d=>this.requestDidLoad(d)),this.xhr.addEventListener("error",d=>this.requestDidError(d))}get status(){return this.xhr.status}get response(){let{responseType:e,response:t}=this.xhr;return e=="json"?t:JSON.parse(t)}create(e){this.callback=e,this.xhr.send(JSON.stringify({blob:this.attributes}))}requestDidLoad(e){if(this.status>=200&&this.status<300){let{response:t}=this,{direct_upload:s}=t;delete t.direct_upload,this.attributes=t,this.directUploadData=s,this.callback(null,this.toJSON())}else this.requestDidError(e)}requestDidError(e){this.callback(`Error creating Blob for "${this.file.name}". Status: ${this.status}`)}toJSON(){let e={};for(let t in this.attributes)e[t]=this.attributes[t];return e}},Le=class{constructor(e){this.blob=e,this.file=e.file;let{url:t,headers:s}=e.directUploadData;this.xhr=new XMLHttpRequest,this.xhr.open("PUT",t,!0),this.xhr.responseType="text";for(let o in s)this.xhr.setRequestHeader(o,s[o]);this.xhr.addEventListener("load",o=>this.requestDidLoad(o)),this.xhr.addEventListener("error",o=>this.requestDidError(o))}create(e){this.callback=e,this.xhr.send(this.file.slice())}requestDidLoad(e){let{status:t,response:s}=this.xhr;t>=200&&t<300?this.callback(null,s):this.requestDidError(e)}requestDidError(e){this.callback(`Error storing "${this.file.name}". Status: ${this.xhr.status}`)}},is=0,W=class{constructor(e,t,s,o={}){this.id=++is,this.file=e,this.url=t,this.delegate=s,this.customHeaders=o}create(e){z.create(this.file,(t,s)=>{if(t){e(t);return}let o=new Ne(this.file,s,this.url,this.customHeaders);Ze(this.delegate,"directUploadWillCreateBlobWithXHR",o.xhr),o.create(h=>{if(h)e(h);else{let d=new Le(o);Ze(this.delegate,"directUploadWillStoreFileWithXHR",d.xhr),d.create(f=>{f?e(f):e(null,o.toJSON())})}})})}};function Ze(r,e,...t){if(r&&typeof r[e]=="function")return r[e](...t)}var $e=class{constructor(e,t){this.input=e,this.file=t,this.directUpload=new W(this.file,this.url,this),this.dispatch("initialize")}start(e){let t=document.createElement("input");t.type="hidden",t.name=this.input.name,this.input.insertAdjacentElement("beforebegin",t),this.dispatch("start"),this.directUpload.create((s,o)=>{s?(t.parentNode.removeChild(t),this.dispatchError(s)):t.value=o.signed_id,this.dispatch("end"),e(s)})}uploadRequestDidProgress(e){let t=e.loaded/e.total*100;t&&this.dispatch("progress",{progress:t})}get url(){return this.input.getAttribute("data-direct-upload-url")}dispatch(e,t={}){return t.file=this.file,t.id=this.directUpload.id,rt(this.input,`direct-upload:${e}`,{detail:t})}dispatchError(e){this.dispatch("error",{error:e}).defaultPrevented||alert(e)}directUploadWillCreateBlobWithXHR(e){this.dispatch("before-blob-request",{xhr:e})}directUploadWillStoreFileWithXHR(e){this.dispatch("before-storage-request",{xhr:e}),e.upload.addEventListener("progress",t=>this.uploadRequestDidProgress(t))}},os="input[type=file][data-direct-upload-url]:not([disabled])",De=class{constructor(e){this.form=e,this.inputs=ns(e,os).filter(t=>t.files.length)}start(e){let t=this.createDirectUploadControllers(),s=()=>{let o=t.shift();o?o.start(h=>{h?(e(h),this.dispatch("end")):s()}):(e(),this.dispatch("end"))};this.dispatch("start"),s()}createDirectUploadControllers(){let e=[];return this.inputs.forEach(t=>{nt(t.files).forEach(s=>{let o=new $e(t,s);e.push(o)})}),e}dispatch(e,t={}){return rt(this.form,`direct-uploads:${e}`,{detail:t})}},Be="data-direct-uploads-processing",ke=new WeakMap,et=!1;function je(){et||(et=!0,document.addEventListener("click",as,!0),document.addEventListener("submit",cs,!0),document.addEventListener("ajax:before",ls))}function as(r){let e=r.target.closest("button, input");e&&e.type==="submit"&&e.form&&ke.set(e.form,e)}function cs(r){it(r)}function ls(r){r.target.tagName=="FORM"&&it(r)}function it(r){let e=r.target;if(e.hasAttribute(Be)){r.preventDefault();return}let t=new De(e),{inputs:s}=t;s.length&&(r.preventDefault(),e.setAttribute(Be,""),s.forEach(us),t.start(o=>{e.removeAttribute(Be),o?s.forEach(ds):hs(e)}))}function hs(r){let e=ke.get(r)||st(r,"input[type=submit], button[type=submit]");if(e){let{disabled:t}=e;e.disabled=!1,e.focus(),e.click(),e.disabled=t}else e=document.createElement("input"),e.type="submit",e.style.display="none",r.appendChild(e),e.click(),r.removeChild(e);ke.delete(r)}function us(r){r.disabled=!0}function ds(r){r.disabled=!1}function fs(){window.ActiveStorage&&je()}setTimeout(fs,1);var H=class extends m{connect(){this.hasInputTarget&&(this.inputTarget.disabled=!0)}copy(r){if(r.preventDefault(),!this.hasInputTarget)return;let e=this.inputTarget.innerHTML||this.inputTarget.value;navigator.clipboard.writeText(e)}};E(H,"targets",["input"]);var J=class extends m{toggle(r){r.preventDefault();let e=this.controlTarget;e.dataset.checked?(this.fieldTarget.value=!1,delete e.dataset.checked):(this.fieldTarget.value=!0,e.dataset.checked=!0)}};E(J,"targets",["field","control"]);var ie=class extends m{close(){this.element.classList.remove("opacity-100"),this.element.classList.add("opacity-0"),setTimeout(()=>{this.element.classList.add("hidden")},300)}};var oe=class extends m{openModal(){this.findElement("lui-modal").open()}closeModal(){this.findElement("lui-modal").close()}findElement(r){let e=this.element.dataset.target.replace("#",""),t=document.getElementById(e);return this.application.getControllerForElementAndIdentifier(t,r)}};var j=class extends m{connect(){this.openFirstValue&&this.openItem(this.itemTargets[0])}toggle(r){r.preventDefault(),this.itemTargets.forEach(e=>{e.contains(r.target)?this.isOpen(e)?this.closeItem(e):this.openItem(e):this.closeItem(e)})}openItem(r){let e=r.querySelector("[data-lui-accordion-target=content]");e.classList.remove("grid-rows-[0fr]"),e.classList.add("grid-rows-[1fr]"),e.classList.remove("opacity-0"),e.classList.add("opacity-100"),r.querySelector("[data-lui-accordion-target=arrow]").classList.add("rotate-180")}closeItem(r){let e=r.querySelector("[data-lui-accordion-target=content]");e.classList.remove("grid-rows-[1fr]"),e.classList.add("grid-rows-[0fr]"),e.classList.remove("opacity-100"),e.classList.add("opacity-0"),r.querySelector("[data-lui-accordion-target=arrow]").classList.remove("rotate-180")}isOpen(r){return r.querySelector("[data-lui-accordion-target=content]").classList.contains("grid-rows-[1fr]")}};E(j,"targets",["content","item"]),E(j,"values",{openFirst:{type:Boolean,default:!0}});var I=class extends m{connect(){this.dialogTarget.addEventListener("click",this.onClick.bind(this)),this.openValue&&this.open()}disconnect(){this.dialogTarget.removeEventListener("click",this.onClick.bind(this))}open(){this.dialogTarget.showModal()}close(){this.dialogTarget.setAttribute("closing",""),Promise.all(this.dialogTarget.getAnimations().map(r=>r.finished)).then(()=>{this.dialogTarget.removeAttribute("closing"),this.dialogTarget.close()})}onClick(r){r.target===this.dialogTarget&&this.dialogTarget.close()}submitForm(){this.dialogTarget.querySelector("form").requestSubmit()}};E(I,"targets",["dialog"]),E(I,"values",{open:Boolean});var V=class extends m{connect(){this.initialShowValue||this.itemTargets.forEach(r=>{r.classList.add("hidden")})}toggle(r){r.preventDefault(),this.itemTargets.forEach(e=>{e.classList.toggle("hidden")})}};E(V,"targets",["item"]),E(V,"values",{initialShow:Boolean});var X=class extends m{toggle(r){r.preventDefault();let e=r.target;e.dataset.checked?(this.fieldTarget.value=!1,delete e.dataset.checked):(this.fieldTarget.value=!0,e.dataset.checked=!0)}};E(X,"targets",["field"]);var Ie=class extends m{};Ie.debounces=[];var Ve=class extends m{};Ve.throttles=[];var ps={enterFromClass:"enter",enterActiveClass:"enterStart",enterToClass:"enterEnd",leaveFromClass:"leave",leaveActiveClass:"leaveStart",leaveToClass:"leaveEnd"},ms={transitioned:!1,hiddenClass:"hidden",preserveOriginalClass:!0,removeToClasses:!0},ot=(r,e={})=>{var t,s,o;let h=r,d=h.element.dataset.transitionTarget,f;d&&(f=h[`${d}Target`]);let g=(e==null?void 0:e.element)||f||h.element;if(!(g instanceof HTMLElement||g instanceof SVGElement))return;let v=g.dataset,w=parseInt(v.leaveAfter||"")||e.leaveAfter||0,{transitioned:B,hiddenClass:x,preserveOriginalClass:G,removeToClasses:k}=Object.assign({},ms,e),N=(t=h.enter)===null||t===void 0?void 0:t.bind(h),b=(s=h.leave)===null||s===void 0?void 0:s.bind(h),u=(o=h.toggleTransition)===null||o===void 0?void 0:o.bind(h);function l(p){return M(this,null,function*(){if(h.transitioned)return;h.transitioned=!0,N&&N(p);let O=S("enterFrom",e,v),L=S("enterActive",e,v),$=S("enterTo",e,v),D=S("leaveTo",e,v);x&&g.classList.remove(x),k||A(g,D),yield c(g,O,L,$,x,G,k),w>0&&setTimeout(()=>{i(p)},w)})}function i(p){return M(this,null,function*(){if(!h.transitioned)return;h.transitioned=!1,b&&b(p);let O=S("leaveFrom",e,v),L=S("leaveActive",e,v),$=S("leaveTo",e,v),D=S("enterTo",e,v);k||A(g,D),yield c(g,O,L,$,x,G,k),x&&g.classList.add(x)})}function n(p){u&&u(p),h.transitioned?i():l()}function c(p,O,L,$,D,ct,lt){return M(this,null,function*(){let P=[];ct&&(O.forEach(T=>p.classList.contains(T)&&T!==D&&P.push(T)),L.forEach(T=>p.classList.contains(T)&&T!==D&&P.push(T)),$.forEach(T=>p.classList.contains(T)&&T!==D&&P.push(T))),y(p,O),A(p,P),y(p,L),yield vs(),A(p,O),y(p,$),yield bs(p),A(p,L),lt&&A(p,$),y(p,P)})}function a(){h.transitioned=B,B?(x&&g.classList.remove(x),l()):(x&&g.classList.add(x),i())}function y(p,O){O.length>0&&p.classList.add(...O)}function A(p,O){O.length>0&&p.classList.remove(...O)}return a(),Object.assign(h,{enter:l,leave:i,toggleTransition:n}),[l,i,n]};function S(r,e,t){let s=`transition${r[0].toUpperCase()}${r.substr(1)}`,o=ps[r],h=e[r]||t[s]||t[o]||" ";return ys(h)?[]:h.split(" ")}function bs(r){return M(this,null,function*(){return new Promise(e=>{let t=Number(getComputedStyle(r).transitionDuration.split(",")[0].replace("s",""))*1e3;setTimeout(()=>{e(t)},t)})})}function vs(){return M(this,null,function*(){return new Promise(r=>{requestAnimationFrame(()=>{requestAnimationFrame(r)})})})}function ys(r){return r.length===0||!r.trim()}var _=class extends m{connect(){ot(this,{element:this.menuTarget})}toggle(){this.toggleTransition()}hide(e){!this.element.contains(e.target)&&!this.menuTarget.classList.contains("hidden")&&this.leave()}};E(_,"targets",["menu"]);var _e=class{constructor(e,t){this.controller=t,this.file=e,this.directUpload=new W(e,this.controller.inputTarget.dataset.directUploadUrl,this)}process(){this.insertUpload(),this.directUpload.create((e,t)=>{if(e){let o=this.controller.filesTarget.querySelector(`#upload_${this.directUpload.id}`).querySelector("[data-lui-dropzone-target='status']");o.textContent="Failed. "+e,o.classList.add("text-red-500")}else{let s=document.createElement("input");s.setAttribute("type","hidden"),s.setAttribute("value",t.signed_id),s.name=this.controller.inputTarget.name,this.controller.filesTarget.querySelector(`#upload_${this.directUpload.id}`).appendChild(s),this.controller.inputTarget.value=""}})}insertUpload(){let e=this.controller.templateTarget.content.cloneNode(!0);e.querySelector("#\\#NEW_FILE").id=`upload_${this.directUpload.id}`,e.querySelector("[data-lui-dropzone-target='filename']").textContent=this.file.name,e.querySelector("[data-lui-dropzone-target='status']").textContent="Uploading...",this.controller.filesTarget.appendChild(e)}directUploadWillStoreFileWithXHR(e){e.upload.addEventListener("progress",t=>this.updateProgress(t))}updateProgress(e){let t=(e.loaded/e.total*100).toFixed(0),s=t==100?"Uploaded":"Uploading...",o=this.controller.filesTarget.querySelector(`#upload_${this.directUpload.id}`);o.querySelector("[data-lui-dropzone-target='status']").textContent=s,o.querySelector("[data-lui-dropzone-target='progressbar']").style.width=`${t}%`,o.querySelector("[data-lui-dropzone-target='percentage-progress']").textContent=`${t}%`}},Q=class extends m{selectFiles(r){this.inputTarget.click()}uploadFiles(r){r.preventDefault(),[...r.dataTransfer?r.dataTransfer.files:r.target.files].forEach(t=>new _e(t,this).process())}activate(r){r.preventDefault()}removeFile(r){r.preventDefault(),r.target.closest("[data-lui-dropzone-target='file']").remove()}};E(Q,"targets",["input","template","files"]);var F="lui";je();var at=re.start();window.Stimulus=at;function Es(r){r.register(`${F}-clipboard`,H),r.register(`${F}-checkbox`,J),r.register(`${F}-banner`,ie),r.register(`${F}-main`,oe),r.register(`${F}-accordion`,j),r.register(`${F}-modal`,I),r.register(`${F}-reveal`,V),r.register(`${F}-switch`,X),r.register(`${F}-dropdown`,_),r.register(`${F}-dropzone`,Q)}Es(at);})();
|
@@ -13,7 +13,7 @@ class LightningUiKit::BadgeComponent < LightningUiKit::BaseComponent
|
|
13
13
|
when :warning
|
14
14
|
"bg-yellow-200 text-zinc-500"
|
15
15
|
when :error
|
16
|
-
"bg-red-600 text-white"
|
16
|
+
"bg-red-600/80 text-white"
|
17
17
|
else
|
18
18
|
"bg-zinc-400/20 text-zinc-500"
|
19
19
|
end
|
@@ -23,11 +23,37 @@ class LightningUiKit::BadgeComponent < LightningUiKit::BaseComponent
|
|
23
23
|
def progress_classes
|
24
24
|
progress_classes = case @progress
|
25
25
|
when :complete
|
26
|
-
|
26
|
+
case @status
|
27
|
+
when :success
|
28
|
+
"bg-green-600 border-green-600"
|
29
|
+
when :warning
|
30
|
+
"bg-yellow-400 border-yellow-400"
|
31
|
+
when :error
|
32
|
+
"bg-red-700 border-red-700"
|
33
|
+
else
|
34
|
+
"bg-zinc-400 border-zinc-400"
|
35
|
+
end
|
27
36
|
when :incomplete
|
28
|
-
|
37
|
+
case @status
|
38
|
+
when :error
|
39
|
+
"bg-transparent border-white"
|
40
|
+
else
|
41
|
+
"bg-transparent border-zinc-400"
|
42
|
+
end
|
29
43
|
when :partialy_complete
|
30
|
-
"relative
|
44
|
+
partialy_complete_classes = "relative after:w-[3.75px] after:h-[8.2px]\
|
45
|
+
after:border-transparent after:border-[1px] after:-rotate-45 after:absolute after:-top-[1px]\
|
46
|
+
after:left-[1px] after:margin-0 after-margin-y-[1px]"
|
47
|
+
case @status
|
48
|
+
when :success
|
49
|
+
"#{partialy_complete_classes} border-green-600 after:border-l-green-600 after:border-r-green-600"
|
50
|
+
when :warning
|
51
|
+
"#{partialy_complete_classes} border-yellow-400 after:border-l-yellow-400 after:border-r-yellow-400"
|
52
|
+
when :error
|
53
|
+
"#{partialy_complete_classes} border-white after:border-l-white after:border-r-white"
|
54
|
+
else
|
55
|
+
"#{partialy_complete_classes} border-zinc-400 after:border-l-zinc-400 after:border-r-zinc-400"
|
56
|
+
end
|
31
57
|
end
|
32
58
|
[default_progress_classes, progress_classes].join(" ")
|
33
59
|
end
|
@@ -36,7 +62,6 @@ class LightningUiKit::BadgeComponent < LightningUiKit::BaseComponent
|
|
36
62
|
"h-2 w-2 rounded-[3px] border-[1px]"
|
37
63
|
end
|
38
64
|
|
39
|
-
# hover:bg-zinc-400/30
|
40
65
|
def defalt_classes
|
41
66
|
"relative inline-flex items-center relative gap-x-1.5 rounded-[10px] px-2.5 py-1 text-sm font-medium sm:text-xs forced-colors:outline"
|
42
67
|
end
|
@@ -12,7 +12,7 @@ class LightningUiKit::BannerComponent < LightningUiKit::BaseComponent
|
|
12
12
|
def classes
|
13
13
|
type_classes = case @type
|
14
14
|
when :error
|
15
|
-
"*:data-[slot=header]:bg-red-600/
|
15
|
+
"*:data-[slot=header]:bg-red-600/80 *:data-[slot=header]:text-white"
|
16
16
|
else
|
17
17
|
"*:data-[slot=header]:bg-gray-50"
|
18
18
|
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
class="group inline-flex focus:outline-hidden" id="headlessui-control-:r2m:" role="checkbox" aria-checked="false" tabindex="0" data-headlessui-state="" aria-labelledby="headlessui-label-:r2o:" aria-describedby="headlessui-description-:r2p:"
|
6
6
|
data-action="click->lui-checkbox#toggle"
|
7
7
|
>
|
8
|
-
<span class="relative isolate flex size-[1.125rem] items-center justify-center rounded-[0.3125rem] sm:size-4 before:absolute before:inset-0 before:-z-10 before:rounded-[calc(0.3125rem-1px)] before:bg-white before:shadow-sm group-data-checked:before:bg-(--checkbox-checked-bg) border border-zinc-950/15 group-data-checked:border-transparent group-
|
8
|
+
<span class="relative isolate flex size-[1.125rem] items-center justify-center rounded-[0.3125rem] sm:size-4 before:absolute before:inset-0 before:-z-10 before:rounded-[calc(0.3125rem-1px)] before:bg-white before:shadow-sm group-data-checked:before:bg-(--checkbox-checked-bg) border border-zinc-950/15 group-data-checked:border-transparent group-hover:group-data-checked:border-transparent group-hover:border-zinc-950/30 group-data-checked:bg-(--checkbox-checked-border) after:absolute after:inset-0 after:rounded-[calc(0.3125rem-1px)] after:shadow-[inset_0_1px_--theme(--color-white/15%)] group-data-focus:outline group-data-focus:outline-2 group-data-focus:outline-offset-2 group-data-focus:outline-blue-500 group-data-disabled:opacity-50 group-data-disabled:border-zinc-950/25 group-data-disabled:bg-zinc-950/5 group-data-disabled:[--checkbox-check:var(--color-zinc-950)]/50 group-data-disabled:before:bg-transparent forced-colors:[--checkbox-check:HighlightText] forced-colors:[--checkbox-checked-bg:Highlight] forced-colors:group-data-disabled:[--checkbox-check:Highlight] [--checkbox-check:var(--color-white)] [--checkbox-checked-bg:var(--color-zinc-900)] [--checkbox-checked-border:var(--color-zinc-950)]/90">
|
9
9
|
<svg class="size-4 stroke-(--checkbox-check) opacity-0 group-data-checked:opacity-100 sm:h-3.5 sm:w-3.5" viewBox="0 0 14 14" fill="none">
|
10
10
|
<path class="opacity-100 group-data-indeterminate:opacity-0" d="M3 8L6 11L11 3.5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
|
11
11
|
<path class="opacity-0 group-data-indeterminate:opacity-100" d="M3 7H11" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
|
@@ -0,0 +1,82 @@
|
|
1
|
+
<%= tag.div(class: classes, data:) do %>
|
2
|
+
<template data-lui-dropzone-target="template">
|
3
|
+
<div class="w-full grid gap-1 my-4" id="#NEW_FILE" data-lui-dropzone-target="file">
|
4
|
+
<div class="flex items-center justify-between gap-2">
|
5
|
+
<div class="flex items-center gap-2">
|
6
|
+
<%= heroicon("document", variant: :outline, options: {class: "w-10 h-10 text-indigo-500"}) %>
|
7
|
+
<div class="grid gap-1">
|
8
|
+
<h4 class="text-gray-900 text-sm font-normal leading-snug" data-lui-dropzone-target="filename"></h4>
|
9
|
+
<h5 class="text-gray-400 text-xs font-normal leading-[18px]" data-lui-dropzone-target="status"></h5>
|
10
|
+
</div>
|
11
|
+
</div>
|
12
|
+
<%= heroicon(
|
13
|
+
"x-circle",
|
14
|
+
variant: :outline,
|
15
|
+
options: {
|
16
|
+
class: "w-6 h-6 text-zinc-300 hover:text-indigo-500 hover:cursor-pointer",
|
17
|
+
data_action: "click->lui-dropzone#removeFile"
|
18
|
+
}) %>
|
19
|
+
</div>
|
20
|
+
<div class="relative flex items-center gap-2.5 py-1.5">
|
21
|
+
<div class="relative w-full h-2.5 overflow-hidden rounded-3xl bg-gray-100">
|
22
|
+
<div data-lui-dropzone-target="progressbar" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 0%" class="flex h-full items-center justify-center bg-indigo-600 text-white rounded-3xl"></div>
|
23
|
+
</div>
|
24
|
+
<span data-lui-dropzone-target="percentage-progress" class="ml-2 bg-white rounded-full text-gray-800 text-xs font-medium flex justify-center items-center">0%</span>
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
</template>
|
28
|
+
|
29
|
+
<% if @label %>
|
30
|
+
<%= tag.label(
|
31
|
+
@label,
|
32
|
+
class: "text-base/6 text-zinc-950 select-none data-disabled:opacity-50 sm:text-sm/6",
|
33
|
+
data: label_data
|
34
|
+
) %>
|
35
|
+
<% end %>
|
36
|
+
<% if @description %>
|
37
|
+
<%= tag.p(
|
38
|
+
@description,
|
39
|
+
class: "text-base/6 text-zinc-500 data-disabled:opacity-50 sm:text-sm/6",
|
40
|
+
data: description_data
|
41
|
+
) %>
|
42
|
+
<% end %>
|
43
|
+
|
44
|
+
<div class="py-9 bg-zinc-50 rounded-2xl border border-gray-300 border-dotted hover:cursor-pointer hover:bg-zinc-100" data-action="click->lui-dropzone#selectFiles">
|
45
|
+
<div class="mb-3 flex items-center justify-center">
|
46
|
+
<%= heroicon("cloud-arrow-up", variant: :outline, options: {class: "w-10 h-10 text-indigo-500"}) %>
|
47
|
+
</div>
|
48
|
+
<p class="text-center text-gray-900 text-base font-medium leading-snug"><%= t("dropzone.default_message") %></p>
|
49
|
+
<% if @placeholder %>
|
50
|
+
<p class="text-center text-gray-400 text-base sm:text-sm/6 font-normal leading-4 mt-1.5"><%= @placeholder %></p>
|
51
|
+
<% end %>
|
52
|
+
<% if @form %>
|
53
|
+
<%= @form.file_field(
|
54
|
+
@name,
|
55
|
+
multiple: @multiple,
|
56
|
+
class: "hidden",
|
57
|
+
direct_upload: true,
|
58
|
+
data: input_data,
|
59
|
+
accept: @accept
|
60
|
+
) %>
|
61
|
+
<% else %>
|
62
|
+
<%= file_field_tag(
|
63
|
+
@name,
|
64
|
+
value: @value,
|
65
|
+
multiple: @multiple,
|
66
|
+
class: "hidden",
|
67
|
+
direct_upload: true,
|
68
|
+
data: input_data,
|
69
|
+
accept: @accept
|
70
|
+
) %>
|
71
|
+
<% end %>
|
72
|
+
</div>
|
73
|
+
|
74
|
+
<% if has_errors? %>
|
75
|
+
<%= tag.p(
|
76
|
+
error_messages,
|
77
|
+
class: "text-base/6 text-red-600 data-disabled:opacity-50 sm:text-sm/6",
|
78
|
+
data: error_data
|
79
|
+
) %>
|
80
|
+
<% end %>
|
81
|
+
<div data-lui-dropzone-target="files"></div>
|
82
|
+
<% end %>
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class LightningUiKit::DropzoneComponent < LightningUiKit::BaseComponent
|
4
|
+
include LightningUiKit::Errors
|
5
|
+
|
6
|
+
def initialize(name:, value: nil, label: nil, form: nil, description: nil, multiple: false, accept: nil, disabled: false, placeholder: nil, error: nil, **options)
|
7
|
+
@name = name
|
8
|
+
@value = value
|
9
|
+
@disabled = disabled
|
10
|
+
@accept = accept
|
11
|
+
@multiple = multiple
|
12
|
+
@error = error
|
13
|
+
@label = label
|
14
|
+
@form = form
|
15
|
+
@description = description
|
16
|
+
@placeholder = placeholder
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
def classes
|
21
|
+
merge_classes(["space-y-4 [&>[data-slot=label]+[data-slot=control]]:mt-3 [&>[data-slot=label]+[data-slot=description]]:mt-1 [&>[data-slot=description]+[data-slot=control]]:mt-3 [&>[data-slot=control]+[data-slot=description]]:mt-3 [&>[data-slot=control]+[data-slot=error]]:mt-3 *:data-[slot=label]:font-medium", @options[:class]].compact.join(" "))
|
22
|
+
end
|
23
|
+
|
24
|
+
def data
|
25
|
+
{controller: "lui-dropzone"}.merge(@options[:data] || {})
|
26
|
+
end
|
27
|
+
|
28
|
+
def input_data
|
29
|
+
(@options[:input_data] || {}).tap do |data|
|
30
|
+
data[:lui_dropzone_target] = "input"
|
31
|
+
data[:action] = "dragover->lui-dropzone#activate drop->lui-dropzone#uploadFiles change->lui-dropzone#uploadFiles"
|
32
|
+
if has_errors?
|
33
|
+
data[:invalid] = "true"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def label_data
|
39
|
+
{slot: "label"}.merge(@options[:label_data] || {}).tap do |data|
|
40
|
+
if @disabled
|
41
|
+
data[:disabled] = "true"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def description_data
|
47
|
+
{slot: "description"}.merge(@options[:description_data] || {}).tap do |data|
|
48
|
+
if @disabled
|
49
|
+
data[:disabled] = "true"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def error_data
|
55
|
+
{slot: "error"}.merge(@options[:error_data] || {}).tap do |data|
|
56
|
+
if @disabled
|
57
|
+
data[:disabled] = "true"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module LightningUiKit
|
2
|
+
module Errors
|
3
|
+
def has_errors?
|
4
|
+
error_messages.present?
|
5
|
+
end
|
6
|
+
|
7
|
+
# TODO: simplify this code
|
8
|
+
def error_messages
|
9
|
+
return @error if @error.present?
|
10
|
+
return @error_messages if @error_messages.present?
|
11
|
+
|
12
|
+
if @form.present?
|
13
|
+
@error_messages = @form.object.errors.full_messages_for(@name.to_sym)
|
14
|
+
if @error_messages.blank?
|
15
|
+
@error_messages = infer_errors_from_association
|
16
|
+
end
|
17
|
+
end
|
18
|
+
@error_messages = @error_messages&.to_a&.join(". ")
|
19
|
+
end
|
20
|
+
|
21
|
+
def infer_errors_from_association
|
22
|
+
association = if @name.to_s.end_with?("_ids")
|
23
|
+
return unless @form.object.respond_to?(:reflect_on_association)
|
24
|
+
@form.object.class.reflect_on_association(@name.to_s.chomp("_ids").pluralize.to_sym)
|
25
|
+
else
|
26
|
+
return unless @form.object.respond_to?(:reflect_on_all_associations)
|
27
|
+
@form.object.class.reflect_on_all_associations.find do |a|
|
28
|
+
a.macro == :belongs_to && a.foreign_key.to_s == @name.to_s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
@form.object.errors.full_messages_for(association&.name&.to_sym) if association
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
<%= tag.div(class: classes, data:) do %>
|
2
|
+
<% if @label %>
|
3
|
+
<%= label_tag(
|
4
|
+
@name,
|
5
|
+
@label.is_a?(String) ? @label : nil,
|
6
|
+
class: "text-base/6 text-zinc-950 select-none data-disabled:opacity-50 sm:text-sm/6",
|
7
|
+
data: label_data
|
8
|
+
) %>
|
9
|
+
<% end %>
|
10
|
+
<% if @description %>
|
11
|
+
<%= tag.p(
|
12
|
+
@description,
|
13
|
+
class: "text-base/6 text-zinc-500 data-disabled:opacity-50 sm:text-sm/6",
|
14
|
+
data: description_data
|
15
|
+
) %>
|
16
|
+
<% end %>
|
17
|
+
<span data-slot="control" class="relative block w-full before:absolute before:inset-px before:rounded-[calc(var(--radius-lg)-1px)] before:bg-white before:shadow-sm after:pointer-events-none after:absolute after:inset-0 after:rounded-lg after:ring-transparent after:ring-inset sm:focus-within:after:ring-2 sm:focus-within:after:ring-blue-500 has-data-disabled:opacity-50 has-data-disabled:before:bg-zinc-950/5 has-data-disabled:before:shadow-none has-data-invalid:before:shadow-red-500/10">
|
18
|
+
<% if @form %>
|
19
|
+
<%= @form.file_field(
|
20
|
+
@name,
|
21
|
+
data: input_data,
|
22
|
+
class: "relative block w-full appearance-none rounded-lg px-[calc(--spacing(3.5)-1px)] py-[calc(--spacing(2.5)-1px)] sm:px-[calc(--spacing(3)-1px)] sm:py-[calc(--spacing(1.5)-1px)] text-base/6 text-zinc-950 placeholder:text-zinc-500 sm:text-sm/6 border border-zinc-950/10 hover:border-zinc-950/20 data-disabled:hover:none data-disabled:cursor-not-allowed bg-transparent focus:outline-hidden data-invalid:border-red-500 data-invalid:hover:border-red-500 data-disabled:border-zinc-950/20",
|
23
|
+
disabled: @disabled,
|
24
|
+
autofocus: @autofocus,
|
25
|
+
multiple: @multiple,
|
26
|
+
accept: @accept,
|
27
|
+
placeholder: @placeholder
|
28
|
+
) %>
|
29
|
+
<% else %>
|
30
|
+
<%= file_field_tag(
|
31
|
+
@name,
|
32
|
+
value: @value,
|
33
|
+
data: input_data,
|
34
|
+
class: "relative block w-full appearance-none rounded-lg text-base/6 text-zinc-950 placeholder:text-zinc-500 sm:text-sm/6 border border-zinc-950/10 hover:border-zinc-950/20 bg-transparent focus:outline-hidden data-invalid:border-red-500 data-invalid:hover:border-red-500 data-disabled:hover:none data-disabled:cursor-not-allowed data-disabled:border-zinc-950/20 data-disabled:file:cursor-not-allowed data-disabled:file:cursor-not-allowed file:cursor-pointer cursor-pointer file:border-0 file:px-[calc(--spacing(3.5)-1px)] file:py-[calc(--spacing(2.5)-1px)] file:sm:px-[calc(--spacing(3)-1px)] file:sm:py-[calc(--spacing(1.5)-1px)] file:mr-4 file:bg-zinc-100",
|
35
|
+
disabled: @disabled,
|
36
|
+
autofocus: @autofocus,
|
37
|
+
multiple: @multiple,
|
38
|
+
accept: @accept,
|
39
|
+
placeholder: @placeholder
|
40
|
+
) %>
|
41
|
+
<% end %>
|
42
|
+
</span>
|
43
|
+
<% if has_errors? %>
|
44
|
+
<%= tag.p(
|
45
|
+
error_messages,
|
46
|
+
class: "text-base/6 text-red-600 data-disabled:opacity-50 sm:text-sm/6",
|
47
|
+
data: error_data
|
48
|
+
) %>
|
49
|
+
<% end %>
|
50
|
+
<% end %>
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class LightningUiKit::FileInputComponent < LightningUiKit::BaseComponent
|
4
|
+
include LightningUiKit::Errors
|
5
|
+
|
6
|
+
def initialize(name:, value: nil, autofocus: false, label: nil, form: nil, description: nil, multiple: false, accept: nil, disabled: false, error: nil, **options)
|
7
|
+
@name = name
|
8
|
+
@value = value
|
9
|
+
@disabled = disabled
|
10
|
+
@autofocus = autofocus
|
11
|
+
@accept = accept
|
12
|
+
@multiple = multiple
|
13
|
+
@error = error
|
14
|
+
@label = label
|
15
|
+
@form = form
|
16
|
+
@description = description
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
def classes
|
21
|
+
merge_classes(["[&>[data-slot=label]+[data-slot=control]]:mt-3 [&>[data-slot=label]+[data-slot=description]]:mt-1 [&>[data-slot=description]+[data-slot=control]]:mt-3 [&>[data-slot=control]+[data-slot=description]]:mt-3 [&>[data-slot=control]+[data-slot=error]]:mt-3 *:data-[slot=label]:font-medium", @options[:class]].compact.join(" "))
|
22
|
+
end
|
23
|
+
|
24
|
+
def data
|
25
|
+
@options[:data] || {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def input_data
|
29
|
+
(@options[:input_data] || {}).tap do |data|
|
30
|
+
if @disabled
|
31
|
+
data[:disabled] = "true"
|
32
|
+
end
|
33
|
+
if has_errors?
|
34
|
+
data[:invalid] = "true"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def label_data
|
40
|
+
{slot: "label"}.merge(@options[:label_data] || {}).tap do |data|
|
41
|
+
if @disabled
|
42
|
+
data[:disabled] = "true"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def description_data
|
48
|
+
{slot: "description"}.merge(@options[:description_data] || {}).tap do |data|
|
49
|
+
if @disabled
|
50
|
+
data[:disabled] = "true"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def error_data
|
56
|
+
{slot: "error"}.merge(@options[:error_data] || {}).tap do |data|
|
57
|
+
if @disabled
|
58
|
+
data[:disabled] = "true"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|