Comparing version 0.5.0 to 0.6.0
/* | ||
Stimulus 0.5.0 | ||
Stimulus 0.6.0 | ||
Copyright © 2017 Basecamp, LLC | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Stimulus=e():t.Stimulus=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){"use strict";function r(t){return t.replace(/%/g,"%%")}function o(t){return Object.assign({},O,t)}function i(t){return t.toString().replace(/([A-Z])/g,function(t,e){return"-"+e.toLowerCase()})}function s(t){throw new Error(t)}function c(t,e,n){u(t,e).add(n)}function a(t,e,n){u(t,e).delete(n),l(t,e)}function u(t,e){var n=t.get(e);return n||(n=new Set,t.set(e,n)),n}function l(t,e){var n=t.get(e);null!=n&&0==n.size&&t.delete(e)}function h(t){var e=t.target;return e instanceof Element?e:e instanceof Node?e.parentElement:null}function p(t){return!!t&&("undefined"!=typeof EventTarget?t instanceof EventTarget:"function"==typeof t.addEventListener)}function f(t,e){return function(n,r,o){d(n,"initialize",function(){this.addAction(t+"->"+this.identifier+"#"+r,e)})}}function d(t,e,n){var r=t[e];t[e]=function(){n.apply(this,arguments),r.apply(this,arguments)}}Object.defineProperty(e,"__esModule",{value:!0});var m,g=function(){function t(t,e,n,r){this.context=t,this.descriptor=e,this.eventTarget=n,this.delegatedTargetMatcher=r}return Object.defineProperty(t.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"eventName",{get:function(){return this.descriptor.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"methodName",{get:function(){return this.descriptor.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDirect",{get:function(){return!this.isDelegated},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDelegated",{get:function(){return"function"==typeof this.delegatedTargetMatcher},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"method",{get:function(){var t=this.controller[this.methodName];if("function"==typeof t)return t;throw new Error('Action references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),t.prototype.hasSameDescriptorAs=function(t){return null!=t&&t.descriptor.isEqualTo(this.descriptor)},t.prototype.matchDelegatedTarget=function(t){var e=this.delegatedTargetMatcher;return!!e&&e(t)},t.prototype.invokeWithEventAndTarget=function(t,e){this.debug("Invoking action",this,t);try{this.method.call(this.controller,t,e)}catch(e){this.error(e,"while invoking action",this,t)}},t.prototype.debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];(n=this.context).debug.apply(n,[this.descriptor.loggerTag].concat(t));var n},t.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];(n=this.context).error.apply(n,[this.descriptor.loggerTag].concat(t));var n},t}();!function(t){t[t.NONE=0]="NONE",t[t.ERROR=1]="ERROR",t[t.WARN=2]="WARN",t[t.INFO=3]="INFO",t[t.DEBUG=4]="DEBUG"}(m||(m={}));var y="safari"in window,v=/(Trident|Edge)\//.test(navigator.userAgent),b=!v,A=function(){function t(t,e){void 0===t&&(t=m.WARN),void 0===e&&(e=window.console),this.level=t,this.console=e}return t.prototype.debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.level>=m.DEBUG&&this.console.log.apply(this.console,this.formatArgs(t))},t.prototype.info=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.level>=m.INFO&&this.console.log.apply(this.console,this.formatArgs(t))},t.prototype.warn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.level>=m.WARN&&this.console.warn.apply(this.console,this.formatArgs(t))},t.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.level>=m.ERROR&&this.console.error.apply(this.console,this.formatArgs(t))},t.prototype.formatArgs=function(t){if(!b)return t;for(var e=[],n=[],r=0,o=[this.loggerTag].concat(t);r<o.length;r++){var i=o[r],s=typeof i;"string"==s||"number"==s||"boolean"==s?(e.push("%c%s "),n.push("font-family: sans-serif; font-size: small; color: #888",i)):i instanceof Node?(e.push("%o"),n.push(i)):i instanceof E?(e.push(i.formatString," "),n.push.apply(n,i.formatValues)):i instanceof Error?(e.push("\n\n%o\n\n"),n.push(i)):(e.push(y?"%O":"%O "),n.push(i))}return[e.join("")].concat(n)},Object.defineProperty(t.prototype,"loggerTag",{get:function(){return new E("Stimulus")},enumerable:!0,configurable:!0}),t}(),E=function(){function t(t,e,n){void 0===e&&(e="#fff"),void 0===n&&(n="#aaa"),this.name=t,this.foregroundColor=e,this.backgroundColor=n}return Object.defineProperty(t.prototype,"formatString",{get:function(){return"%c"+r(this.name)+"%c"},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"formatValues",{get:function(){return[this.formatValue,""]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"formatValue",{get:function(){return"\n color: "+this.foregroundColor+";\n background-color: "+this.backgroundColor+";\n border: 1px solid rgba(0, 0, 0, 0.25);\n border-radius: 4px;\n padding: 1px 6px;\n font-weight: bold;\n font-family: sans-serif;\n font-size: x-small;\n "},enumerable:!0,configurable:!0}),t}(),O={logLevel:m.WARN,rootElement:document.documentElement,controllerAttribute:"data-controller",actionAttribute:"data-action",targetAttribute:"data-target"},N=function(){function t(t){this.context=t}return Object.defineProperty(t.prototype,"element",{get:function(){return this.context.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),t.prototype.get=function(t){return t=this.getFormattedKey(t),this.element.getAttribute(t)},t.prototype.set=function(t,e){return t=this.getFormattedKey(t),this.element.setAttribute(t,e),this.get(t)},t.prototype.has=function(t){return t=this.getFormattedKey(t),this.element.hasAttribute(t)},t.prototype.delete=function(t){return!!this.has(t)&&(t=this.getFormattedKey(t),this.element.removeAttribute(t),!0)},t.prototype.getFormattedKey=function(t){return"data-"+this.identifier+"-"+i(t)},t}(),x=function(){function t(t,e,n,r){this.identifier=t,this.targetName=e,this.eventName=n,this.methodName=r}return t.forOptions=function(e){return new t(e.identifier||s("Missing identifier in descriptor"),e.targetName||null,e.eventName||s("Missing event name in descriptor"),e.methodName||s("Missing method name in descriptor"))},t.forElementWithInlineDescriptorString=function(e,n){try{var r=this.parseOptionsFromInlineActionDescriptorString(n);return r.eventName=r.eventName||this.getDefaultEventNameForElement(e),t.forOptions(r)}catch(t){throw new Error('Bad descriptor "'+n+'": '+t.message)}},t.parseOptionsFromInlineActionDescriptorString=function(t){var e=t.trim(),n=e.match(/^((.+?)->)?(.+?)#(.+)$/)||s("Invalid descriptor syntax");return{identifier:n[3],eventName:n[2],methodName:n[4]}},t.getDefaultEventNameForElement=function(t){return this.defaultEventNames[t.tagName.toLowerCase()](t)},t.prototype.isEqualTo=function(t){return null!=t&&t.identifier==this.identifier&&t.targetName==this.targetName&&t.eventName==this.eventName&&t.methodName==this.methodName},t.prototype.toString=function(){return this.eventName+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(t.prototype,"loggerTag",{get:function(){return new E(this.toString(),"#000","#fc0")},enumerable:!0,configurable:!0}),t.defaultEventNames={a:function(t){return"click"},button:function(t){return"click"},form:function(t){return"submit"},input:function(t){return"submit"==t.getAttribute("type")?"click":"change"},select:function(t){return"change"},textarea:function(t){return"change"}},t}(),F=function(){function t(){this.valuesByKey=new Map}return Object.defineProperty(t.prototype,"values",{get:function(){return Array.from(this.valuesByKey.values()).reduce(function(t,e){return t.concat(Array.from(e))},[])},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return Array.from(this.valuesByKey.values()).reduce(function(t,e){return t+e.size},0)},enumerable:!0,configurable:!0}),t.prototype.add=function(t,e){c(this.valuesByKey,t,e)},t.prototype.delete=function(t,e){a(this.valuesByKey,t,e)},t.prototype.has=function(t,e){var n=this.valuesByKey.get(t);return null!=n&&n.has(e)},t.prototype.hasKey=function(t){return this.valuesByKey.has(t)},t.prototype.hasValue=function(t){return Array.from(this.valuesByKey.values()).some(function(e){return e.has(t)})},t.prototype.getValuesForKey=function(t){var e=this.valuesByKey.get(t);return e?Array.from(e):[]},t.prototype.getKeysForValue=function(t){return Array.from(this.valuesByKey).filter(function(e){e[0];return e[1].has(t)}).map(function(t){var e=t[0];t[1];return e})},t}(),w=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),T=function(t){function e(){var e=t.call(this)||this;return e.keysByValue=new Map,e}return w(e,t),Object.defineProperty(e.prototype,"values",{get:function(){return Array.from(this.keysByValue.keys())},enumerable:!0,configurable:!0}),e.prototype.add=function(e,n){t.prototype.add.call(this,e,n),c(this.keysByValue,n,e)},e.prototype.delete=function(e,n){t.prototype.delete.call(this,e,n),a(this.keysByValue,n,e)},e.prototype.hasValue=function(t){return this.keysByValue.has(t)},e.prototype.getKeysForValue=function(t){var e=this.keysByValue.get(t);return e?Array.from(e):[]},e}(F),j=function(){function t(){this.actionsByEventName=new F}return Object.defineProperty(t.prototype,"actions",{get:function(){return this.actionsByEventName.values},enumerable:!0,configurable:!0}),t.prototype.add=function(t){this.actionsByEventName.add(t.eventName,t)},t.prototype.delete=function(t){this.actionsByEventName.delete(t.eventName,t)},t.prototype.has=function(t){return this.actionsByEventName.hasValue(t)},t.prototype.getActionsForEventName=function(t){return this.actionsByEventName.getValuesForKey(t)},t}(),S=function(){function t(t,e,n,r){this.name=t,this.target=e,this.listener=n,this.useCapture=r,this.references=0}return t.prototype.isEqualTo=function(t){return t&&t.name===this.name&&t.target==this.target&&t.listener==this.listener&&t.useCapture==this.useCapture},t.prototype.observe=function(){return 0==this.references&&this.target.addEventListener(this.name,this.listener,this.useCapture),1==++this.references},t.prototype.stopObserving=function(){return this.references>0&&(1==this.references&&this.target.removeEventListener(this.name,this.listener,this.useCapture),this.references--),0==this.references},t}(),P=function(){function t(){this.observers=new Set}return t.prototype.add=function(t,e,n,r){var o=new S(t,e,n,r);this.addObserver(o)},t.prototype.delete=function(t,e,n,r){var o=new S(t,e,n,r);this.deleteObserver(o)},t.prototype.addObserver=function(t){var e=this.findMatchingObserver(t);e.observe()&&this.observers.add(e)},t.prototype.deleteObserver=function(t){var e=this.findMatchingObserver(t);e.stopObserving()&&this.observers.delete(e)},t.prototype.findMatchingObserver=function(t){for(var e=0,n=Array.from(this.observers);e<n.length;e++){var r=n[e];if(r.isEqualTo(t))return r}return t},t}(),C=function(){function t(t){this.context=t,this.started=!1,this.directActions=new j,this.delegatedActions=new j,this.events=new P,this.handleDirectEvent=this.handleDirectEvent.bind(this),this.handleDelegatedEvent=this.handleDelegatedEvent.bind(this)}return t.prototype.start=function(){this.started||(this.started=!0,this.addEventListeners())},t.prototype.stop=function(){this.started&&(this.removeEventListeners(),this.started=!1)},t.prototype.addAction=function(t){var e=this.getActionSetForAction(t);e.has(t)||(this.addEventListenerForAction(t),e.add(t))},t.prototype.removeAction=function(t){var e=this.getActionSetForAction(t);e.has(t)&&(this.removeEventListenerForAction(t),e.delete(t))},t.prototype.getActionSetForAction=function(t){return t.isDirect?this.directActions:this.delegatedActions},t.prototype.addEventListeners=function(){this.addEventListenersForActionSet(this.directActions),this.addEventListenersForActionSet(this.delegatedActions)},t.prototype.removeEventListeners=function(){this.removeEventListenersForActionSet(this.delegatedActions),this.removeEventListenersForActionSet(this.directActions)},t.prototype.addEventListenersForActionSet=function(t){for(var e=0,n=t.actions;e<n.length;e++){var r=n[e];this.addEventListenerForAction(r)}},t.prototype.removeEventListenersForActionSet=function(t){for(var e=0,n=t.actions;e<n.length;e++){var r=n[e];this.removeEventListenerForAction(r)}},t.prototype.addEventListenerForAction=function(t){if(this.started){var e=this.getEventListenerForAction(t);this.events.add(t.eventName,t.eventTarget,e,!1)}},t.prototype.removeEventListenerForAction=function(t){if(this.started){var e=this.getEventListenerForAction(t);this.events.delete(t.eventName,t.eventTarget,e,!1)}},t.prototype.getEventListenerForAction=function(t){return t.isDirect?this.handleDirectEvent:this.handleDelegatedEvent},t.prototype.handleDirectEvent=function(t){if(this.canHandleEvent(t)){var e=this.findDirectActionInvocationsForEvent(t);this.performActionInvocations(e)}},t.prototype.handleDelegatedEvent=function(t){if(this.canHandleEvent(t)){var e=this.findDelegatedActionInvocationsForEvent(t);this.performActionInvocations(e)}},t.prototype.canHandleEvent=function(t){var e=h(t);return!e||this.context.canControlElement(e)},t.prototype.findDirectActionInvocationsForEvent=function(t){for(var e=this.directActions.getActionsForEventName(t.type),n=t.currentTarget,r=[],o=0,i=e;o<i.length;o++){var s=i[o];s.eventTarget==n&&r.push([s,t,n])}return r},t.prototype.findDelegatedActionInvocationsForEvent=function(t){for(var e=this.delegatedActions.getActionsForEventName(t.type),n=this.getPathForEvent(t),r=[],o=0,i=n;o<i.length;o++)for(var s=i[o],c=0,a=e;c<a.length;c++){var u=a[c];u.matchDelegatedTarget(s)&&r.push([u,t,s])}return r},t.prototype.performActionInvocations=function(t){for(var e=0,n=t;e<n.length;e++){var r=n[e],o=r[0],i=r[1],s=r[2];o.invokeWithEventAndTarget(i,s)}},t.prototype.getPathForEvent=function(t){for(var e=[],n=h(t);n&&n!=this.parentElement;)e.push(n),n=n.parentElement;return e},Object.defineProperty(t.prototype,"parentElement",{get:function(){return this.context.parentElement},enumerable:!0,configurable:!0}),t}(),k=function(){function t(t,e){var n=this;this.element=t,this.started=!1,this.delegate=e,this.elements=new Set,this.mutationObserver=new MutationObserver(function(t){return n.processMutations(t)})}return t.prototype.start=function(){this.started||(this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.started=!0,this.refresh())},t.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},t.prototype.refresh=function(){if(this.started){for(var t=new Set(this.matchElementsInTree()),e=0,n=Array.from(this.elements);e<n.length;e++){var r=n[e];t.has(r)||this.removeElement(r)}for(var o=0,i=Array.from(t);o<i.length;o++){var r=i[o];this.addElement(r)}}},t.prototype.processMutations=function(t){for(var e=0,n=t;e<n.length;e++){var r=n[e];this.processMutation(r)}},t.prototype.processMutation=function(t){"attributes"==t.type?this.processAttributeChange(t.target,t.attributeName):"childList"==t.type&&(this.processRemovedNodes(t.removedNodes),this.processAddedNodes(t.addedNodes))},t.prototype.processAttributeChange=function(t,e){var n=t;this.elements.has(n)?this.delegate.elementAttributeChanged&&this.matchElement(n)?this.delegate.elementAttributeChanged(n,e):this.removeElement(n):this.matchElement(n)&&this.addElement(n)},t.prototype.processRemovedNodes=function(t){for(var e=0,n=Array.from(t);e<n.length;e++){var r=n[e];this.processNode(r,this.removeElement)}},t.prototype.processAddedNodes=function(t){for(var e=0,n=Array.from(t);e<n.length;e++){var r=n[e];this.processNode(r,this.addElement)}},t.prototype.matchElement=function(t){return this.delegate.matchElement(t)},t.prototype.matchElementsInTree=function(t){return void 0===t&&(t=this.element),this.delegate.matchElementsInTree(t)},t.prototype.processNode=function(t,e){var n=this.elementFromNode(t);if(n)for(var r=0,o=this.matchElementsInTree(n);r<o.length;r++){var i=o[r];e.call(this,i)}},t.prototype.elementFromNode=function(t){if(t.nodeType==Node.ELEMENT_NODE)return t},t.prototype.addElement=function(t){this.elements.has(t)||(this.elements.add(t),this.delegate.elementMatched&&this.delegate.elementMatched(t))},t.prototype.removeElement=function(t){this.elements.has(t)&&(this.elements.delete(t),this.delegate.elementUnmatched&&this.delegate.elementUnmatched(t))},t}(),D=(function(){function t(t,e,n){this.attributeName=e,this.delegate=n,this.elementObserver=new k(t,this)}Object.defineProperty(t.prototype,"element",{get:function(){return this.elementObserver.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"selector",{get:function(){return"["+this.attributeName+"]"},enumerable:!0,configurable:!0}),t.prototype.start=function(){this.elementObserver.start()},t.prototype.stop=function(){this.elementObserver.stop()},t.prototype.matchElement=function(t){return t.hasAttribute(this.attributeName)},t.prototype.matchElementsInTree=function(t){var e=this.matchElement(t)?[t]:[],n=Array.from(t.querySelectorAll(this.selector));return e.concat(n)},t.prototype.elementMatched=function(t){this.delegate.elementMatchedAttribute&&this.delegate.elementMatchedAttribute(t,this.attributeName)},t.prototype.elementUnmatched=function(t){this.delegate.elementUnmatchedAttribute&&this.delegate.elementUnmatchedAttribute(t,this.attributeName)},t.prototype.elementAttributeChanged=function(t,e){this.delegate.elementAttributeValueChanged&&this.attributeName==e&&this.delegate.elementAttributeValueChanged(t,e)}}(),function(){function t(t,e,n){this.attributeName=e,this.delegate=n,this.elementObserver=new k(t,this),this.tokensByElement=new T}return Object.defineProperty(t.prototype,"started",{get:function(){return this.elementObserver.started},enumerable:!0,configurable:!0}),t.prototype.start=function(){this.elementObserver.start()},t.prototype.stop=function(){this.elementObserver.stop()},t.prototype.refresh=function(){this.elementObserver.refresh()},Object.defineProperty(t.prototype,"element",{get:function(){return this.elementObserver.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"selector",{get:function(){return"["+this.attributeName+"]"},enumerable:!0,configurable:!0}),t.prototype.getElementsMatchingToken=function(t){return this.tokensByElement.getKeysForValue(t)},t.prototype.matchElement=function(t){return t.hasAttribute(this.attributeName)},t.prototype.matchElementsInTree=function(t){var e=this.matchElement(t)?[t]:[],n=Array.from(t.querySelectorAll(this.selector));return e.concat(n)},t.prototype.elementMatched=function(t){for(var e=Array.from(this.readTokenSetForElement(t)),n=0,r=e;n<r.length;n++){var o=r[n];this.elementMatchedToken(t,o)}},t.prototype.elementUnmatched=function(t){for(var e=this.getTokensForElement(t),n=0,r=e;n<r.length;n++){var o=r[n];this.elementUnmatchedToken(t,o)}},t.prototype.elementAttributeChanged=function(t){for(var e=this.readTokenSetForElement(t),n=0,r=Array.from(e);n<r.length;n++){var o=r[n];this.elementMatchedToken(t,o)}for(var i=0,s=this.getTokensForElement(t);i<s.length;i++){var o=s[i];e.has(o)||this.elementUnmatchedToken(t,o)}},t.prototype.elementMatchedToken=function(t,e){this.tokensByElement.has(t,e)||(this.tokensByElement.add(t,e),this.delegate.elementMatchedTokenForAttribute&&this.delegate.elementMatchedTokenForAttribute(t,e,this.attributeName))},t.prototype.elementUnmatchedToken=function(t,e){this.tokensByElement.has(t,e)&&(this.tokensByElement.delete(t,e),this.delegate.elementUnmatchedTokenForAttribute&&this.delegate.elementUnmatchedTokenForAttribute(t,e,this.attributeName))},t.prototype.getTokensForElement=function(t){return this.tokensByElement.getValuesForKey(t)},t.prototype.readTokenSetForElement=function(t){for(var e=new Set,n=t.getAttribute(this.attributeName)||"",r=0,o=n.split(/\s+/);r<o.length;r++){var i=o[r];i.length&&e.add(i)}return e},t}()),L=function(){function t(t,e){this.context=t,this.delegate=e,this.tokenListObserver=new D(this.element,this.attributeName,this),this.connectedActions=new F}return Object.defineProperty(t.prototype,"attributeName",{get:function(){return this.context.actionAttribute},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"element",{get:function(){return this.context.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),t.prototype.start=function(){this.tokenListObserver.start()},t.prototype.stop=function(){this.tokenListObserver.stop()},t.prototype.elementMatchedTokenForAttribute=function(t,e,n){if(this.context.canControlElement(t)){var r=this.buildActionForElementWithDescriptorString(t,e);r&&(this.connectedActions.add(t,r),this.delegate.inlineActionConnected(r))}},t.prototype.elementUnmatchedTokenForAttribute=function(t,e,n){var r=this.getConnectedActionForElementWithDescriptorString(t,e);r&&(this.connectedActions.delete(t,r),this.delegate.inlineActionDisconnected(r))},t.prototype.getConnectedActionForElementWithDescriptorString=function(t,e){var n=this.buildActionForElementWithDescriptorString(t,e);if(n)return this.connectedActions.getValuesForKey(t).find(function(t){return t.hasSameDescriptorAs(n)})},t.prototype.buildActionForElementWithDescriptorString=function(t,e){try{var n=x.forElementWithInlineDescriptorString(t,e);if(n.identifier==this.identifier)return new g(this.context,n,this.element,function(e){return e==t})}catch(e){this.context.error(e,"while parsing descriptor string for element",t)}},t}(),B=function(){function t(t){this.context=t}return Object.defineProperty(t.prototype,"attributeName",{get:function(){return this.context.targetAttribute},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"element",{get:function(){return this.context.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),t.prototype.has=function(t){return null!=this.find(t)},t.prototype.find=function(t){var e=this.getSelectorForTargetName(t),n=this.element.querySelector(e);return n&&this.context.canControlElement(n)?n:null},t.prototype.findAll=function(t){var e=this,n=this.getSelectorForTargetName(t);return Array.from(this.element.querySelectorAll(n)).filter(function(t){return e.context.canControlElement(t)})},t.prototype.getSelectorForTargetName=function(t){return"["+this.attributeName+"~='"+this.identifier+"."+t+"']"},t}(),M=function(){function t(t,e){this.contextSet=t,this.element=e,this.targets=new B(this),this.data=new N(this),this.dispatcher=new C(this),this.inlineActionObserver=new L(this,this),this.controller=new t.controllerConstructor(this);try{this.debug("Initializing controller"),this.controller.initialize()}catch(t){this.error(t,"while initializing controller")}}return t.prototype.connect=function(){this.dispatcher.start(),this.inlineActionObserver.start();try{this.debug("Connecting controller"),this.controller.connect()}catch(t){this.error(t,"while connecting controller")}},t.prototype.disconnect=function(){try{this.debug("Disconnecting controller"),this.controller.disconnect()}catch(t){this.error(t,"while disconnecting controller")}this.inlineActionObserver.stop(),this.dispatcher.stop()},t.prototype.canControlElement=function(t){return t.closest(this.selector)==this.element},Object.defineProperty(t.prototype,"application",{get:function(){return this.contextSet.application},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"identifier",{get:function(){return this.contextSet.identifier},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"configuration",{get:function(){return this.application.configuration},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"controllerAttribute",{get:function(){return this.configuration.controllerAttribute},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"actionAttribute",{get:function(){return this.configuration.actionAttribute},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"targetAttribute",{get:function(){return this.configuration.targetAttribute},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parentElement",{get:function(){return this.element.parentElement},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"selector",{get:function(){return"["+this.controllerAttribute+"~='"+this.identifier+"']"},enumerable:!0,configurable:!0}),t.prototype.addAction=function(t,e){var n;if(t instanceof g)n=t;else if("string"==typeof t){var r=t;p(e)||(e=this.element);var o=x.forElementWithInlineDescriptorString(e,r);n=new g(this,o,e)}n&&(this.debug(n.descriptor.loggerTag,"Adding action",n),this.dispatcher.addAction(n))},t.prototype.removeAction=function(t){this.debug(t.descriptor.loggerTag,"Removing action",t),this.dispatcher.removeAction(t)},t.prototype.inlineActionConnected=function(t){this.addAction(t)},t.prototype.inlineActionDisconnected=function(t){this.removeAction(t)},t.prototype.debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(n=this.logger).debug.apply(n,[this.loggerTag].concat(t,[this.controller,this.element]));var n},t.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(n=this.logger).error.apply(n,[this.loggerTag].concat(t,[this.controller,this.element]));var n},Object.defineProperty(t.prototype,"logger",{get:function(){return this.application.logger},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"loggerTag",{get:function(){return new E(this.identifier,"#fff","#38f")},enumerable:!0,configurable:!0}),t}(),I=function(){function t(t,e,n){this.router=t,this.identifier=e,this.controllerConstructor=n,this.contextsByElement=new WeakMap,this.connectedContexts=new Set}return Object.defineProperty(t.prototype,"application",{get:function(){return this.router.application},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"contexts",{get:function(){return Array.from(this.connectedContexts)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return this.connectedContexts.size},enumerable:!0,configurable:!0}),t.prototype.connect=function(t){var e=this.fetchContextForElement(t);e&&!this.connectedContexts.has(e)&&(this.connectedContexts.add(e),e.connect())},t.prototype.disconnect=function(t){var e=this.fetchContextForElement(t);e&&this.connectedContexts.has(e)&&(this.connectedContexts.delete(e),e.disconnect())},t.prototype.getContextForElement=function(t){return this.contextsByElement.get(t)},t.prototype.fetchContextForElement=function(t){var e=this.contextsByElement.get(t);return e||(e=new M(this,t),this.contextsByElement.set(t,e)),e},t}(),K=function(){function t(t){this.application=t,this.tokenListObserver=new D(this.element,this.controllerAttribute,this),this.contextSets=new Map}return Object.defineProperty(t.prototype,"configuration",{get:function(){return this.application.configuration},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"element",{get:function(){return this.configuration.rootElement},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"controllerAttribute",{get:function(){return this.configuration.controllerAttribute},enumerable:!0,configurable:!0}),t.prototype.start=function(){this.tokenListObserver.start()},t.prototype.stop=function(){this.tokenListObserver.stop()},t.prototype.register=function(t,e){if(this.contextSets.has(t))throw new Error("Router already has a controller registered with the identifier '"+t+"'");var n=new I(this,t,e);this.contextSets.set(t,n),this.connectContextSet(n)},t.prototype.unregister=function(t){var e=this.contextSets.get(t);e&&(this.disconnectContextSet(e),this.contextSets.delete(t))},t.prototype.elementMatchedTokenForAttribute=function(t,e,n){this.connectContextForIdentifierToElement(e,t)},t.prototype.elementUnmatchedTokenForAttribute=function(t,e,n){this.disconnectContextForIdentifierFromElement(e,t)},t.prototype.getContextForElementAndIdentifier=function(t,e){var n=this.contextSets.get(e);if(n)return n.getContextForElement(t)},t.prototype.connectContextSet=function(t){for(var e=this.tokenListObserver.getElementsMatchingToken(t.identifier),n=0,r=e;n<r.length;n++){var o=r[n];t.connect(o)}},t.prototype.disconnectContextSet=function(t){for(var e=t.contexts,n=0,r=e;n<r.length;n++){var o=r[n].element;t.disconnect(o)}},t.prototype.connectContextForIdentifierToElement=function(t,e){var n=this.contextSets.get(t);n&&n.connect(e)},t.prototype.disconnectContextForIdentifierFromElement=function(t,e){var n=this.contextSets.get(t);n&&n.disconnect(e)},t}(),V=function(){function t(t){void 0===t&&(t={}),this.configuration=o(t),this.logger=new A(this.configuration.logLevel),this.router=new K(this)}return t.start=function(e){var n=new t(e);return n.start(),n},t.prototype.start=function(){this.router.start()},t.prototype.stop=function(){this.router.stop()},t.prototype.register=function(t,e){this.router.register(t,e)},t.prototype.unregister=function(t){this.router.unregister(t)},t.prototype.getControllerForElementAndIdentifier=function(t,e){var n=this.router.getContextForElementAndIdentifier(t,e);return n?n.controller:null},t}(),R=function(){function t(t){this.context=t}return Object.defineProperty(t.prototype,"application",{get:function(){return this.context.application},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"element",{get:function(){return this.context.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"targets",{get:function(){return this.context.targets},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"data",{get:function(){return this.context.data},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.connect=function(){},t.prototype.disconnect=function(){},t.prototype.addAction=function(t,e){this.context.addAction(t,e)},t.prototype.removeAction=function(t){this.context.removeAction(t)},t}();n.d(e,"Action",function(){return g}),n.d(e,"Application",function(){return V}),n.d(e,"Context",function(){return M}),n.d(e,"Controller",function(){return R}),n.d(e,"Descriptor",function(){return x}),n.d(e,"Logger",function(){return A}),n.d(e,"LogLevel",function(){return m}),n.d(e,"on",function(){return f})}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Stimulus=e():t.Stimulus=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){"use strict";function r(t){throw new Error(t)}function o(t){return"window"==t?window:"document"==t?document:void 0}function i(t){return t==window?"window":t==document?"document":void 0}function s(t){return Object.assign({},E,t)}function c(t,e,n){u(t,e).add(n)}function a(t,e,n){u(t,e).delete(n),h(t,e)}function u(t,e){var n=t.get(e);return n||(n=new Set,t.set(e,n)),n}function h(t,e){var n=t.get(e);null!=n&&0==n.size&&t.delete(e)}function p(t){var e=t.target;return e instanceof Element?e:e instanceof Node?e.parentElement:null}function l(t){return t.toString().replace(/([A-Z])/g,function(t,e){return"-"+e.toLowerCase()})}function f(t,e){return"["+CSS.escape(t)+'~="'+CSS.escape(e)+'"]'}function d(t){return!!t&&("undefined"!=typeof EventTarget?t instanceof EventTarget:"function"==typeof t.addEventListener)}function m(t,e){return function(n,r,o){y(n,"initialize",function(){this.addAction(t+"->"+this.identifier+"#"+r,e)})}}function y(t,e,n){var r=t[e];t[e]=function(){n.apply(this,arguments),r.apply(this,arguments)}}Object.defineProperty(e,"__esModule",{value:!0});var g=function(){function t(t,e,n,r){this.context=t,this.descriptor=e,this.eventTarget=n,this.delegatedTargetMatcher=r}return Object.defineProperty(t.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"eventName",{get:function(){return this.descriptor.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"methodName",{get:function(){return this.descriptor.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDirect",{get:function(){return!this.isDelegated},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDelegated",{get:function(){return"function"==typeof this.delegatedTargetMatcher},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"method",{get:function(){var t=this.controller[this.methodName];if("function"==typeof t)return t;throw new Error('Action "'+this.descriptor+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),t.prototype.hasSameDescriptorAs=function(t){return null!=t&&t.descriptor.isEqualTo(this.descriptor)},t.prototype.matchDelegatedTarget=function(t){var e=this.delegatedTargetMatcher;return!!e&&e(t)},t.prototype.invokeWithEventAndTarget=function(t,e){try{this.method.call(this.controller,t,e)}catch(e){this.context.reportError(e,'invoking action "'+this.descriptor+'"',t,this)}},t}(),v=/^((.+?)(@(window|document))?->)?(.+?)#(.+)$/,b=function(){function t(t,e,n,r){this.identifier=t,this.eventName=e,this.methodName=n,this.eventTarget=r}return t.forOptions=function(e){return new t(e.identifier||r("Missing identifier in action descriptor"),e.eventName||r("Missing event name in action descriptor"),e.methodName||r("Missing method name in action descriptor"),e.eventTarget)},t.forElementWithInlineDescriptorString=function(e,n){try{var r=this.parseOptionsFromInlineActionDescriptorString(n);return r.eventName=r.eventName||this.getDefaultEventNameForElement(e),t.forOptions(r)}catch(t){throw new Error('Bad action descriptor "'+n+'": '+t.message)}},t.parseOptionsFromInlineActionDescriptorString=function(t){var e=t.trim(),n=e.match(v)||r("Invalid action descriptor syntax");return{identifier:n[5],eventName:n[2],methodName:n[6],eventTarget:o(n[4])}},t.getDefaultEventNameForElement=function(t){return this.defaultEventNames[t.tagName.toLowerCase()](t)},Object.defineProperty(t.prototype,"eventTargetName",{get:function(){return i(this.eventTarget)},enumerable:!0,configurable:!0}),t.prototype.isEqualTo=function(t){return null!=t&&t.identifier==this.identifier&&t.eventName==this.eventName&&t.methodName==this.methodName&&t.eventTarget==this.eventTarget},t.prototype.toString=function(){var t=this.eventTarget?"@"+this.eventTargetName:"";return""+this.eventName+t+"->"+this.identifier+"#"+this.methodName},t.defaultEventNames={a:function(t){return"click"},button:function(t){return"click"},form:function(t){return"submit"},input:function(t){return"submit"==t.getAttribute("type")?"click":"change"},select:function(t){return"change"},textarea:function(t){return"change"}},t}(),E={rootElement:document.documentElement,controllerAttribute:"data-controller",actionAttribute:"data-action",targetAttribute:"data-target"},A=function(){function t(){this.valuesByKey=new Map}return Object.defineProperty(t.prototype,"values",{get:function(){return Array.from(this.valuesByKey.values()).reduce(function(t,e){return t.concat(Array.from(e))},[])},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return Array.from(this.valuesByKey.values()).reduce(function(t,e){return t+e.size},0)},enumerable:!0,configurable:!0}),t.prototype.add=function(t,e){c(this.valuesByKey,t,e)},t.prototype.delete=function(t,e){a(this.valuesByKey,t,e)},t.prototype.has=function(t,e){var n=this.valuesByKey.get(t);return null!=n&&n.has(e)},t.prototype.hasKey=function(t){return this.valuesByKey.has(t)},t.prototype.hasValue=function(t){return Array.from(this.valuesByKey.values()).some(function(e){return e.has(t)})},t.prototype.getValuesForKey=function(t){var e=this.valuesByKey.get(t);return e?Array.from(e):[]},t.prototype.getKeysForValue=function(t){return Array.from(this.valuesByKey).filter(function(e){e[0];return e[1].has(t)}).map(function(t){var e=t[0];t[1];return e})},t}(),O=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),F=function(t){function e(){var e=t.call(this)||this;return e.keysByValue=new Map,e}return O(e,t),Object.defineProperty(e.prototype,"values",{get:function(){return Array.from(this.keysByValue.keys())},enumerable:!0,configurable:!0}),e.prototype.add=function(e,n){t.prototype.add.call(this,e,n),c(this.keysByValue,n,e)},e.prototype.delete=function(e,n){t.prototype.delete.call(this,e,n),a(this.keysByValue,n,e)},e.prototype.hasValue=function(t){return this.keysByValue.has(t)},e.prototype.getKeysForValue=function(t){var e=this.keysByValue.get(t);return e?Array.from(e):[]},e}(A),N=function(){function t(){this.actionsByEventName=new A}return Object.defineProperty(t.prototype,"actions",{get:function(){return this.actionsByEventName.values},enumerable:!0,configurable:!0}),t.prototype.add=function(t){this.actionsByEventName.add(t.eventName,t)},t.prototype.delete=function(t){this.actionsByEventName.delete(t.eventName,t)},t.prototype.has=function(t){return this.actionsByEventName.hasValue(t)},t.prototype.getActionsForEventName=function(t){return this.actionsByEventName.getValuesForKey(t)},t}(),x=function(){function t(t,e,n,r){this.name=t,this.target=e,this.listener=n,this.useCapture=r,this.references=0}return t.prototype.isEqualTo=function(t){return t&&t.name===this.name&&t.target==this.target&&t.listener==this.listener&&t.useCapture==this.useCapture},t.prototype.observe=function(){return 0==this.references&&this.target.addEventListener(this.name,this.listener,this.useCapture),1==++this.references},t.prototype.stopObserving=function(){return this.references>0&&(1==this.references&&this.target.removeEventListener(this.name,this.listener,this.useCapture),this.references--),0==this.references},t}(),T=function(){function t(){this.observers=new Set}return t.prototype.add=function(t,e,n,r){var o=new x(t,e,n,r);this.addObserver(o)},t.prototype.delete=function(t,e,n,r){var o=new x(t,e,n,r);this.deleteObserver(o)},t.prototype.addObserver=function(t){var e=this.findMatchingObserver(t);e.observe()&&this.observers.add(e)},t.prototype.deleteObserver=function(t){var e=this.findMatchingObserver(t);e.stopObserving()&&this.observers.delete(e)},t.prototype.findMatchingObserver=function(t){for(var e=0,n=Array.from(this.observers);e<n.length;e++){var r=n[e];if(r.isEqualTo(t))return r}return t},t}(),S=function(){function t(t){this.context=t,this.started=!1,this.directActions=new N,this.delegatedActions=new N,this.events=new T,this.handleDirectEvent=this.handleDirectEvent.bind(this),this.handleDelegatedEvent=this.handleDelegatedEvent.bind(this)}return t.prototype.start=function(){this.started||(this.started=!0,this.addEventListeners())},t.prototype.stop=function(){this.started&&(this.removeEventListeners(),this.started=!1)},t.prototype.addAction=function(t){var e=this.getActionSetForAction(t);e.has(t)||(this.addEventListenerForAction(t),e.add(t))},t.prototype.removeAction=function(t){var e=this.getActionSetForAction(t);e.has(t)&&(this.removeEventListenerForAction(t),e.delete(t))},t.prototype.getActionSetForAction=function(t){return t.isDirect?this.directActions:this.delegatedActions},t.prototype.addEventListeners=function(){this.addEventListenersForActionSet(this.directActions),this.addEventListenersForActionSet(this.delegatedActions)},t.prototype.removeEventListeners=function(){this.removeEventListenersForActionSet(this.delegatedActions),this.removeEventListenersForActionSet(this.directActions)},t.prototype.addEventListenersForActionSet=function(t){for(var e=0,n=t.actions;e<n.length;e++){var r=n[e];this.addEventListenerForAction(r)}},t.prototype.removeEventListenersForActionSet=function(t){for(var e=0,n=t.actions;e<n.length;e++){var r=n[e];this.removeEventListenerForAction(r)}},t.prototype.addEventListenerForAction=function(t){if(this.started){var e=this.getEventListenerForAction(t);this.events.add(t.eventName,t.eventTarget,e,!1)}},t.prototype.removeEventListenerForAction=function(t){if(this.started){var e=this.getEventListenerForAction(t);this.events.delete(t.eventName,t.eventTarget,e,!1)}},t.prototype.getEventListenerForAction=function(t){return t.isDirect?this.handleDirectEvent:this.handleDelegatedEvent},t.prototype.handleDirectEvent=function(t){var e=this.findDirectActionInvocationsForEvent(t);this.performActionInvocations(e)},t.prototype.handleDelegatedEvent=function(t){if(this.canHandleDelegatedEvent(t)){var e=this.findDelegatedActionInvocationsForEvent(t);this.performActionInvocations(e)}},t.prototype.canHandleDelegatedEvent=function(t){var e=p(t);return!e||this.scope.containsElement(e)},t.prototype.findDirectActionInvocationsForEvent=function(t){for(var e=this.directActions.getActionsForEventName(t.type),n=t.currentTarget,r=[],o=0,i=e;o<i.length;o++){var s=i[o];s.eventTarget==n&&r.push([s,t,n])}return r},t.prototype.findDelegatedActionInvocationsForEvent=function(t){for(var e=this.delegatedActions.getActionsForEventName(t.type),n=this.getPathForEvent(t),r=[],o=0,i=n;o<i.length;o++)for(var s=i[o],c=0,a=e;c<a.length;c++){var u=a[c];u.matchDelegatedTarget(s)&&r.push([u,t,s])}return r},t.prototype.performActionInvocations=function(t){for(var e=0,n=t;e<n.length;e++){var r=n[e],o=r[0],i=r[1],s=r[2];o.invokeWithEventAndTarget(i,s)}},t.prototype.getPathForEvent=function(t){for(var e=[],n=p(t);n&&n!=this.parentElement;)e.push(n),n=n.parentElement;return e},Object.defineProperty(t.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parentElement",{get:function(){return this.context.parentElement},enumerable:!0,configurable:!0}),t}(),w=function(){function t(t,e){var n=this;this.element=t,this.started=!1,this.delegate=e,this.elements=new Set,this.mutationObserver=new MutationObserver(function(t){return n.processMutations(t)})}return t.prototype.start=function(){this.started||(this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.started=!0,this.refresh())},t.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},t.prototype.refresh=function(){if(this.started){for(var t=new Set(this.matchElementsInTree()),e=0,n=Array.from(this.elements);e<n.length;e++){var r=n[e];t.has(r)||this.removeElement(r)}for(var o=0,i=Array.from(t);o<i.length;o++){var r=i[o];this.addElement(r)}}},t.prototype.processMutations=function(t){for(var e=0,n=t;e<n.length;e++){var r=n[e];this.processMutation(r)}},t.prototype.processMutation=function(t){"attributes"==t.type?this.processAttributeChange(t.target,t.attributeName):"childList"==t.type&&(this.processRemovedNodes(t.removedNodes),this.processAddedNodes(t.addedNodes))},t.prototype.processAttributeChange=function(t,e){var n=t;this.elements.has(n)?this.delegate.elementAttributeChanged&&this.matchElement(n)?this.delegate.elementAttributeChanged(n,e):this.removeElement(n):this.matchElement(n)&&this.addElement(n)},t.prototype.processRemovedNodes=function(t){for(var e=0,n=Array.from(t);e<n.length;e++){var r=n[e];this.processNode(r,this.removeElement)}},t.prototype.processAddedNodes=function(t){for(var e=0,n=Array.from(t);e<n.length;e++){var r=n[e];this.processNode(r,this.addElement)}},t.prototype.matchElement=function(t){return this.delegate.matchElement(t)},t.prototype.matchElementsInTree=function(t){return void 0===t&&(t=this.element),this.delegate.matchElementsInTree(t)},t.prototype.processNode=function(t,e){var n=this.elementFromNode(t);if(n)for(var r=0,o=this.matchElementsInTree(n);r<o.length;r++){var i=o[r];e.call(this,i)}},t.prototype.elementFromNode=function(t){if(t.nodeType==Node.ELEMENT_NODE)return t},t.prototype.addElement=function(t){this.elements.has(t)||(this.elements.add(t),this.delegate.elementMatched&&this.delegate.elementMatched(t))},t.prototype.removeElement=function(t){this.elements.has(t)&&(this.elements.delete(t),this.delegate.elementUnmatched&&this.delegate.elementUnmatched(t))},t}(),j=(function(){function t(t,e,n){this.attributeName=e,this.delegate=n,this.elementObserver=new w(t,this)}Object.defineProperty(t.prototype,"element",{get:function(){return this.elementObserver.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"selector",{get:function(){return"["+this.attributeName+"]"},enumerable:!0,configurable:!0}),t.prototype.start=function(){this.elementObserver.start()},t.prototype.stop=function(){this.elementObserver.stop()},t.prototype.matchElement=function(t){return t.hasAttribute(this.attributeName)},t.prototype.matchElementsInTree=function(t){var e=this.matchElement(t)?[t]:[],n=Array.from(t.querySelectorAll(this.selector));return e.concat(n)},t.prototype.elementMatched=function(t){this.delegate.elementMatchedAttribute&&this.delegate.elementMatchedAttribute(t,this.attributeName)},t.prototype.elementUnmatched=function(t){this.delegate.elementUnmatchedAttribute&&this.delegate.elementUnmatchedAttribute(t,this.attributeName)},t.prototype.elementAttributeChanged=function(t,e){this.delegate.elementAttributeValueChanged&&this.attributeName==e&&this.delegate.elementAttributeValueChanged(t,e)}}(),function(){function t(t,e,n){this.attributeName=e,this.delegate=n,this.elementObserver=new w(t,this),this.tokensByElement=new F}return Object.defineProperty(t.prototype,"started",{get:function(){return this.elementObserver.started},enumerable:!0,configurable:!0}),t.prototype.start=function(){this.elementObserver.start()},t.prototype.stop=function(){this.elementObserver.stop()},t.prototype.refresh=function(){this.elementObserver.refresh()},Object.defineProperty(t.prototype,"element",{get:function(){return this.elementObserver.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"selector",{get:function(){return"["+this.attributeName+"]"},enumerable:!0,configurable:!0}),t.prototype.getElementsMatchingToken=function(t){return this.tokensByElement.getKeysForValue(t)},t.prototype.matchElement=function(t){return t.hasAttribute(this.attributeName)},t.prototype.matchElementsInTree=function(t){var e=this.matchElement(t)?[t]:[],n=Array.from(t.querySelectorAll(this.selector));return e.concat(n)},t.prototype.elementMatched=function(t){for(var e=Array.from(this.readTokenSetForElement(t)),n=0,r=e;n<r.length;n++){var o=r[n];this.elementMatchedToken(t,o)}},t.prototype.elementUnmatched=function(t){for(var e=this.getTokensForElement(t),n=0,r=e;n<r.length;n++){var o=r[n];this.elementUnmatchedToken(t,o)}},t.prototype.elementAttributeChanged=function(t){for(var e=this.readTokenSetForElement(t),n=0,r=Array.from(e);n<r.length;n++){var o=r[n];this.elementMatchedToken(t,o)}for(var i=0,s=this.getTokensForElement(t);i<s.length;i++){var o=s[i];e.has(o)||this.elementUnmatchedToken(t,o)}},t.prototype.elementMatchedToken=function(t,e){this.tokensByElement.has(t,e)||(this.tokensByElement.add(t,e),this.delegate.elementMatchedTokenForAttribute&&this.delegate.elementMatchedTokenForAttribute(t,e,this.attributeName))},t.prototype.elementUnmatchedToken=function(t,e){this.tokensByElement.has(t,e)&&(this.tokensByElement.delete(t,e),this.delegate.elementUnmatchedTokenForAttribute&&this.delegate.elementUnmatchedTokenForAttribute(t,e,this.attributeName))},t.prototype.getTokensForElement=function(t){return this.tokensByElement.getValuesForKey(t)},t.prototype.readTokenSetForElement=function(t){for(var e=new Set,n=t.getAttribute(this.attributeName)||"",r=0,o=n.split(/\s+/);r<o.length;r++){var i=o[r];i.length&&e.add(i)}return e},t}()),P=function(){function t(t,e){this.context=t,this.delegate=e,this.tokenListObserver=new j(this.element,this.attributeName,this),this.connectedActions=new A}return Object.defineProperty(t.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"configuration",{get:function(){return this.scope.configuration},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"attributeName",{get:function(){return this.configuration.actionAttribute},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"identifier",{get:function(){return this.scope.identifier},enumerable:!0,configurable:!0}),t.prototype.start=function(){this.tokenListObserver.start()},t.prototype.stop=function(){this.tokenListObserver.stop()},t.prototype.elementMatchedTokenForAttribute=function(t,e,n){if(this.scope.containsElement(t)){var r=this.buildActionForElementWithDescriptorString(t,e);r&&(this.connectedActions.add(t,r),this.delegate.inlineActionConnected(r))}},t.prototype.elementUnmatchedTokenForAttribute=function(t,e,n){var r=this.getConnectedActionForElementWithDescriptorString(t,e);r&&(this.connectedActions.delete(t,r),this.delegate.inlineActionDisconnected(r))},t.prototype.getConnectedActionForElementWithDescriptorString=function(t,e){var n=this.buildActionForElementWithDescriptorString(t,e);if(n)return this.connectedActions.getValuesForKey(t).find(function(t){return t.hasSameDescriptorAs(n)})},t.prototype.buildActionForElementWithDescriptorString=function(t,e){try{var n=b.forElementWithInlineDescriptorString(t,e);if(n.identifier==this.identifier)return n.eventTarget?new g(this.context,n,n.eventTarget):new g(this.context,n,this.element,function(e){return e==t})}catch(n){this.context.reportError(n,'parsing descriptor string "'+e+'" for element',t)}},t}(),k=function(){function t(t){this.scope=t}return Object.defineProperty(t.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"identifier",{get:function(){return this.scope.identifier},enumerable:!0,configurable:!0}),t.prototype.get=function(t){return t=this.getFormattedKey(t),this.element.getAttribute(t)},t.prototype.set=function(t,e){return t=this.getFormattedKey(t),this.element.setAttribute(t,e),this.get(t)},t.prototype.has=function(t){return t=this.getFormattedKey(t),this.element.hasAttribute(t)},t.prototype.delete=function(t){return!!this.has(t)&&(t=this.getFormattedKey(t),this.element.removeAttribute(t),!0)},t.prototype.getFormattedKey=function(t){return"data-"+this.identifier+"-"+l(t)},t}(),C=function(){function t(t){this.scope=t}return Object.defineProperty(t.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"identifier",{get:function(){return this.scope.identifier},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"configuration",{get:function(){return this.scope.configuration},enumerable:!0,configurable:!0}),t.prototype.has=function(t){return null!=this.find(t)},t.prototype.find=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=this.getSelectorForTargetNames(t);return this.scope.findElement(n)},t.prototype.findAll=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=this.getSelectorForTargetNames(t);return this.scope.findAllElements(n)},t.prototype.getSelectorForTargetNames=function(t){var e=this;return t.map(function(t){return e.getSelectorForTargetName(t)}).join(", ")},t.prototype.getSelectorForTargetName=function(t){var e=this.identifier+"."+t;return f(this.configuration.targetAttribute,e)},t}(),D=function(){function t(t,e,n){this.configuration=t,this.identifier=e,this.element=n,this.targets=new C(this),this.data=new k(this)}return t.prototype.findElement=function(t){return this.findAllElements(t)[0]},t.prototype.findAllElements=function(t){var e=this.element.matches(t)?[this.element]:[],n=this.filterElements(Array.from(this.element.querySelectorAll(t)));return e.concat(n)},t.prototype.filterElements=function(t){var e=this;return t.filter(function(t){return e.containsElement(t)})},t.prototype.containsElement=function(t){return t.closest(this.controllerSelector)===this.element},Object.defineProperty(t.prototype,"controllerSelector",{get:function(){return f(this.configuration.controllerAttribute,this.identifier)},enumerable:!0,configurable:!0}),t}(),M=function(){function t(t,e){this.contextSet=t,this.scope=new D(this.configuration,this.identifier,e),this.dispatcher=new S(this),this.inlineActionObserver=new P(this,this);try{this.controller=new t.controllerConstructor(this),this.controller.initialize()}catch(t){this.reportError(t,'initializing controller "'+this.identifier+'"')}}return t.prototype.connect=function(){this.dispatcher.start(),this.inlineActionObserver.start();try{this.controller.connect()}catch(t){this.reportError(t,'connecting controller "'+this.identifier+'"')}},t.prototype.disconnect=function(){try{this.controller.disconnect()}catch(t){this.reportError(t,'disconnecting controller "'+this.identifier+'"')}this.inlineActionObserver.stop(),this.dispatcher.stop()},Object.defineProperty(t.prototype,"application",{get:function(){return this.contextSet.application},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"identifier",{get:function(){return this.contextSet.identifier},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"configuration",{get:function(){return this.application.configuration},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parentElement",{get:function(){return this.element.parentElement},enumerable:!0,configurable:!0}),t.prototype.addAction=function(t,e){var n;if(t instanceof g)n=t;else if("string"==typeof t){var r=t;d(e)||(e=this.element);var o=b.forElementWithInlineDescriptorString(e,r);n=new g(this,o,e)}n&&this.dispatcher.addAction(n)},t.prototype.removeAction=function(t){this.dispatcher.removeAction(t)},t.prototype.inlineActionConnected=function(t){this.addAction(t)},t.prototype.inlineActionDisconnected=function(t){this.removeAction(t)},t.prototype.reportError=function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=n.map(function(t){return"%o"}).join("\n"),i="Error %s\n\n%o\n\n"+o+"\n%o\n%o";return console.error.apply(console,[i,e,t].concat(n,[this.controller,this.element]))},t}(),B=function(){function t(t,e,n){this.router=t,this.identifier=e,this.controllerConstructor=n,this.contextsByElement=new WeakMap,this.connectedContexts=new Set}return Object.defineProperty(t.prototype,"application",{get:function(){return this.router.application},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"contexts",{get:function(){return Array.from(this.connectedContexts)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return this.connectedContexts.size},enumerable:!0,configurable:!0}),t.prototype.connect=function(t){var e=this.fetchContextForElement(t);e&&!this.connectedContexts.has(e)&&(this.connectedContexts.add(e),e.connect())},t.prototype.disconnect=function(t){var e=this.fetchContextForElement(t);e&&this.connectedContexts.has(e)&&(this.connectedContexts.delete(e),e.disconnect())},t.prototype.getContextForElement=function(t){return this.contextsByElement.get(t)},t.prototype.fetchContextForElement=function(t){var e=this.contextsByElement.get(t);return e||(e=new M(this,t),this.contextsByElement.set(t,e)),e},t}(),L=function(){function t(t){this.application=t,this.tokenListObserver=new j(this.element,this.controllerAttribute,this),this.contextSets=new Map}return Object.defineProperty(t.prototype,"configuration",{get:function(){return this.application.configuration},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"element",{get:function(){return this.configuration.rootElement},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"controllerAttribute",{get:function(){return this.configuration.controllerAttribute},enumerable:!0,configurable:!0}),t.prototype.start=function(){this.tokenListObserver.start()},t.prototype.stop=function(){this.tokenListObserver.stop()},t.prototype.register=function(t,e){if(this.contextSets.has(t))throw new Error("Router already has a controller registered with the identifier '"+t+"'");var n=new B(this,t,e);this.contextSets.set(t,n),this.connectContextSet(n)},t.prototype.unregister=function(t){var e=this.contextSets.get(t);e&&(this.disconnectContextSet(e),this.contextSets.delete(t))},t.prototype.elementMatchedTokenForAttribute=function(t,e,n){this.connectContextForIdentifierToElement(e,t)},t.prototype.elementUnmatchedTokenForAttribute=function(t,e,n){this.disconnectContextForIdentifierFromElement(e,t)},t.prototype.getContextForElementAndIdentifier=function(t,e){var n=this.contextSets.get(e);if(n)return n.getContextForElement(t)},t.prototype.connectContextSet=function(t){for(var e=this.tokenListObserver.getElementsMatchingToken(t.identifier),n=0,r=e;n<r.length;n++){var o=r[n];t.connect(o)}},t.prototype.disconnectContextSet=function(t){for(var e=t.contexts,n=0,r=e;n<r.length;n++){var o=r[n].element;t.disconnect(o)}},t.prototype.connectContextForIdentifierToElement=function(t,e){var n=this.contextSets.get(t);n&&n.connect(e)},t.prototype.disconnectContextForIdentifierFromElement=function(t,e){var n=this.contextSets.get(t);n&&n.disconnect(e)},t}(),I=function(){function t(t){void 0===t&&(t={}),this.configuration=s(t),this.router=new L(this)}return t.start=function(e){var n=new t(e);return n.start(),n},t.prototype.start=function(){this.router.start()},t.prototype.stop=function(){this.router.stop()},t.prototype.register=function(t,e){this.router.register(t,e)},t.prototype.unregister=function(t){this.router.unregister(t)},t.prototype.getControllerForElementAndIdentifier=function(t,e){var n=this.router.getContextForElementAndIdentifier(t,e);return n?n.controller:null},t}(),K=function(){function t(t){this.context=t}return Object.defineProperty(t.prototype,"application",{get:function(){return this.context.application},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"identifier",{get:function(){return this.scope.identifier},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"targets",{get:function(){return this.scope.targets},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"data",{get:function(){return this.scope.data},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.connect=function(){},t.prototype.disconnect=function(){},t.prototype.addAction=function(t,e){this.context.addAction(t,e)},t.prototype.removeAction=function(t){this.context.removeAction(t)},t}();n.d(e,"Action",function(){return g}),n.d(e,"ActionDescriptor",function(){return b}),n.d(e,"Application",function(){return I}),n.d(e,"Context",function(){return M}),n.d(e,"Controller",function(){return K}),n.d(e,"on",function(){return m})}])}); |
{ | ||
"name": "stimulus", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "👉✨", | ||
@@ -24,11 +24,15 @@ "author": "Basecamp, LLC", | ||
"dependencies": { | ||
"@stimulus/core": "^0.5.0", | ||
"@stimulus/core": "^0.6.0", | ||
"@stimulus/webpack-helpers": "^0.5.0" | ||
}, | ||
"scripts": { | ||
"build": "webpack" | ||
"prepublish": "yarn run build", | ||
"build": "yarn exec webpack" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"webpack": "^3.8.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
30262
1
5
+ Added@stimulus/core@0.6.0(transitive)
- Removed@stimulus/core@0.5.0(transitive)
Updated@stimulus/core@^0.6.0