stimulus-use
Advanced tools
Comparing version 0.22.0 to 0.22.1-0
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("stimulus")):"function"==typeof define&&define.amd?define(["exports","stimulus"],n):n((e=e||self).StimulusUse={},e.Stimulus)}(this,function(e,n){var t=function(e,n){var t=e[n];if("function"==typeof t)return t;throw new Error('undefined method "'+n+'"')},i=function(e,n,t){var i=e;return!0===t?i=n.identifier+":"+e:"string"==typeof t&&(i=t+":"+e),i},r=function(e,n,t){var i=n||{bubbles:!0,cancelable:!0,composed:!0},r=i.bubbles,o=i.cancelable,s=i.composed;return n&&Object.assign(t,{originalEvent:n}),new CustomEvent(e,{bubbles:r,cancelable:o,composed:s,detail:t})},o={dispatchEvent:!0,eventPrefix:!0},s=function(e,n){var s;void 0===n&&(n={});var l=Object.assign({},o,n),c=l.dispatchEvent,a=l.eventPrefix,u=(null==(s=n)?void 0:s.element)||e.element,v=e.disconnect.bind(e),d=new IntersectionObserver(function(n){var o=n[0];o.isIntersecting?function(n){if(e.isVisible=!0,e.appear&&t(e,"appear").call(e,n),c){var o=i("appear",e,a),s=r(o,null,{controller:e,entry:n});u.dispatchEvent(s)}}(o):e.isVisible&&function(n){if(e.isVisible=!1,e.disappear&&t(e,"disappear").call(e,n),c){var o=i("disappear",e,a),s=r(o,null,{controller:e,entry:n});u.dispatchEvent(s)}}(o)},n),f=function(){d.observe(u)},b=function(){d.unobserve(u)};return Object.assign(e,{isVisible:!1,disconnect:function(){b(),v()}}),f(),[f,b]};function l(){return(l=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e}).apply(this,arguments)}function c(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var u=function(e){function n(n){var t;return(t=e.call(this,n)||this).isVisible=!1,requestAnimationFrame(function(){var e=s(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return c(n,e),n}(n.Controller),v=function(e,n){var i=e.disconnect.bind(e),r=new IntersectionObserver(function(n){n[0].isIntersecting&&!e.isLoaded&&function(n){var i=e.data.get("src");if(i){var r=e.element;e.isLoading=!0,e.loading&&t(e,"loading").call(e,i),r.onload=function(){!function(n){e.isLoading=!1,e.isLoaded=!0,e.loading&&t(e,"loaded").call(e,n)}(i)},r.src=i}}()},n),o=function(){r.observe(e.element)},s=function(){r.unobserve(e.element)};return Object.assign(e,{isVisible:!1,disconnect:function(){s(),i()}}),o(),[o,s]},d=function(e){function n(n){var t;return(t=e.call(this,n)||this).isLoading=!1,t.isLoaded=!1,t.options={rootMargin:"10%"},requestAnimationFrame(function(){var e=v(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}c(n,e);var t=n.prototype;return t.loading=function(e){},t.loaded=function(e){},n}(n.Controller),f={dispatchEvent:!0,eventPrefix:!0},b=function(e,n){var o;void 0===n&&(n={});var s=Object.assign({},f,n),l=s.dispatchEvent,c=s.eventPrefix,a=(null==(o=n)?void 0:o.element)||e.element,u=e.disconnect.bind(e),v=new ResizeObserver(function(n){var o=n[0];if(e.resize&&t(e,"resize").call(e,o.contentRect),l){var s=i("resize",e,c),u=r(s,null,{controller:e,entry:o});a.dispatchEvent(u)}}),d=function(){v.observe(a)},b=function(){v.unobserve(a)};return Object.assign(e,{disconnect:function(){b(),u()}}),d(),[d,b]},m=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=b(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return c(n,e),n.prototype.resize=function(e){},n}(n.Controller),h={events:["click","touchend"],onlyVisible:!0,dispatchEvent:!0,eventPrefix:!0},p=function(e,n){void 0===n&&(n={});var o=Object.assign({},h,n),s=o.onlyVisible,l=o.dispatchEvent,c=o.events,a=o.eventPrefix,u=function(o){var c,u,v,d,f=(null==(c=n)?void 0:c.element)||e.element;if(!f.contains(o.target)&&(u=f.getBoundingClientRect(),v=window.innerHeight||document.documentElement.clientHeight,d=window.innerWidth||document.documentElement.clientWidth,u.top<=v&&u.top+u.height>=0&&u.left<=d&&u.left+u.width>=0||!s)&&(e.clickOutside&&t(e,"clickOutside").call(e,o),l)){var b=i("click:outside",e,a),m=r(b,o,{controller:e});f.dispatchEvent(m)}},v=function(){null==c||c.forEach(function(e){window.addEventListener(e,u,!1)})},d=function(){null==c||c.forEach(function(e){window.removeEventListener(e,u,!1)})},f=e.disconnect.bind(e);return Object.assign(e,{disconnect:function(){d(),f()}}),v(),[v,d]},g=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=p(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return c(n,e),n.prototype.clickOutside=function(e){},n}(n.Controller),E={debug:!1,logger:console},y=function(e,n){var t,i,r,o,s,c=this;void 0===n&&(n={}),this.log=function(e,n){c.debug&&(c.logger.groupCollapsed("%c"+c.controller.identifier+" %c#"+e,"color: #3B82F6","color: unset"),c.logger.log(l({controllerId:c.controllerId},n)),c.logger.groupEnd())},this.debug=null!=(t=null!=(i=null==(r=n)?void 0:r.debug)?i:e.application.stimulusUseDebug)?t:E.debug,this.logger=null!=(o=null==(s=n)?void 0:s.logger)?o:E.logger,this.controller=e,this.controllerId=e.element.id||e.element.dataset.id,this.controllerInitialize=e.initialize.bind(e),this.controllerConnect=e.connect.bind(e),this.controllerDisconnect=e.disconnect.bind(e)},w=function(e){function n(n,t){var r,o,s,l,c;return void 0===t&&(t={}),(c=e.call(this,n,t)||this).dispatch=function(e,n){void 0===n&&(n={});var t=a(c),r=t.targetElement,o=t.eventPrefix,s=t.bubbles,l=t.cancelable,u=t.log;Object.assign(n,{controller:t.controller});var v=i(e,c.controller,o),d=new CustomEvent(v,{detail:n,bubbles:s,cancelable:l});return r.dispatchEvent(d),u("dispatch",{eventName:v,detail:n,bubbles:s,cancelable:l}),d},c.targetElement=null!=(r=t.element)?r:n.element,c.eventPrefix=null==(o=t.eventPrefix)||o,c.bubbles=null==(s=t.bubbles)||s,c.cancelable=null==(l=t.cancelable)||l,c.enhanceController(),c}return c(n,e),n.prototype.enhanceController=function(){Object.assign(this.controller,{dispatch:this.dispatch})},n}(y),C=function(e,n){return void 0===n&&(n={}),new w(e,n)},O=function(e,n){Object.defineProperty(e,"isPreview",{get:function(){return document.documentElement.hasAttribute("data-turbolinks-preview")}}),Object.defineProperty(e,"csrfToken",{get:function(){return this.metaValue("csrf-token")}}),C(e,n),Object.assign(e,{metaValue:function(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}})},j=function(e){function n(n){var t;return(t=e.call(this,n)||this).isPreview=!1,t.csrfToken="",O(a(t),t.options),t}return c(n,e),n}(n.Controller),L={ms:6e4,initialState:!1,events:["mousemove","mousedown","resize","keydown","touchstart","wheel"],dispatchEvent:!0,eventPrefix:!0},P=function(e,n){void 0===n&&(n={});var o=Object.assign({},L,n),s=o.ms,l=o.events,c=o.dispatchEvent,a=o.eventPrefix,u=o.initialState,v=setTimeout(function(){u=!0,d()},s),d=function(n){var o=i("away",e,a);if(e.isIdle=!0,e.away&&t(e,"away").call(e,n),c){var s=r(o,n||null,{controller:e});e.element.dispatchEvent(s)}},f=function(n){var o=i("back",e,a);if(e.isIdle=!1,e.back&&t(e,"back").call(e,n),c){var s=r(o,n||null,{controller:e});e.element.dispatchEvent(s)}},b=function(e){u&&f(e),u=!1,clearTimeout(v),v=setTimeout(function(){u=!0,d(e)},s)},m=function(e){document.hidden||b(e)};u?d():f();var h=e.disconnect.bind(e),p=function(){l.forEach(function(e){window.addEventListener(e,b)}),document.addEventListener("visibilitychange",m)},g=function(){l.forEach(function(e){window.removeEventListener(e,b)}),document.removeEventListener("visibilitychange",m)};return Object.assign(e,{disconnect:function(){g(),h()}}),p(),[p,g]},V=function(e){function n(n){var t;return(t=e.call(this,n)||this).isIdle=!1,requestAnimationFrame(function(){var e=P(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}c(n,e);var t=n.prototype;return t.away=function(){},t.back=function(){},n}(n.Controller),x={dispatchEvent:!0,eventPrefix:!0},A=function(e){function n(n,o){var s;void 0===o&&(o={}),(s=e.call(this,n,o)||this).observe=function(){s.controller.isVisible=!document.hidden,document.addEventListener("visibilitychange",s.handleVisibilityChange)},s.unobserve=function(){document.removeEventListener("visibilitychange",s.handleVisibilityChange)},s.becomesInvisible=function(e){var n=i("invisible",s.controller,s.eventPrefix);s.controller.isVisible=!1,s.controller.invisible&&t(s.controller,"invisible").call(s.controller,e),s.log("invisible",{isVisible:!1}),s.dispatch(n,e)},s.becomesVisible=function(e){var n=i("visible",s.controller,s.eventPrefix);s.controller.isVisible=!0,s.controller.visible&&t(s.controller,"visible").call(s.controller,e),s.log("visible",{isVisible:!0}),s.dispatch(n,e)},s.dispatch=function(e,n){if(s.dispatchEvent){var t={controller:s.controller,isVisible:s.controller.isVisible},i=r(e,n||null,t);s.controller.element.dispatchEvent(i),s.log("dispatchEvent",l({eventName:e},t))}},s.handleVisibilityChange=function(e){document.hidden?s.becomesInvisible(e):s.becomesVisible(e)};var c=Object.assign({},x,o),u=c.dispatchEvent,v=c.eventPrefix;return Object.assign(a(s),{dispatchEvent:u,eventPrefix:v}),s.controller=n,Object.assign(n,{disconnect:function(){s.unobserve(),s.controllerDisconnect()}}),s.handleVisibilityChange(),s.observe(),s}return c(n,e),n}(y),T=function(e,n){void 0===n&&(n={});var t=new A(e,n);return[t.observe,t.unobserve]},z=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=T(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return c(n,e),n}(n.Controller),I=function(e){function n(n,i){var r,o;return void 0===i&&(i={}),(o=e.call(this,n,i)||this).observe=function(){o.targetElement.addEventListener("mouseenter",o.onEnter),o.targetElement.addEventListener("mouseleave",o.onLeave)},o.unobserve=function(){o.targetElement.removeEventListener("mouseenter",o.onEnter),o.targetElement.removeEventListener("mouseleave",o.onLeave)},o.onEnter=function(){o.controller.mouseEnter&&t(o.controller,"mouseEnter").call(o.controller),o.log("mouseEnter",{hover:!0})},o.onLeave=function(){o.controller.mouseLeave&&t(o.controller,"mouseLeave").call(o.controller),o.log("mouseLeave",{hover:!1})},o.targetElement=(null==(r=i)?void 0:r.element)||n.element,o.controller=n,o.enhanceController(),o.observe(),o}return c(n,e),n.prototype.enhanceController=function(){var e=this,n=this.controller.disconnect.bind(this.controller);Object.assign(this.controller,{disconnect:function(){e.unobserve(),n()}})},n}(y),k=function(e,n){void 0===n&&(n={});var t=new I(e,n);return[t.observe,t.unobserve]},q=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=k(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return c(n,e),n}(n.Controller),F=function(e){function n(n,i){var r,o;return void 0===i&&(i={}),(o=e.call(this,n,i)||this).observe=function(){try{o.observer.observe(o.targetElement,o.options)}catch(e){o.controller.application.handleError(e,"At a minimum, one of childList, attributes, and/or characterData must be true",{})}},o.unobserve=function(){o.observer.disconnect()},o.mutation=function(e){o.controller.mutate&&t(o.controller,"mutate").call(o.controller,e),o.log("mutate",{entries:e})},o.targetElement=(null==(r=i)?void 0:r.element)||n.element,o.controller=n,o.options=i,o.observer=new MutationObserver(o.mutation),o.enhanceController(),o.observe(),o}return c(n,e),n.prototype.enhanceController=function(){var e=this,n=this.controller.disconnect.bind(this.controller);Object.assign(this.controller,{disconnect:function(){e.unobserve(),n()}})},n}(y),R=function(e,n){void 0===n&&(n={});var t=new F(e,n);return[t.observe,t.unobserve]},S=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=R(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return c(n,e),n}(n.Controller),M=function(e){var n=function(n){var i=window,r={height:i.innerHeight||Infinity,width:i.innerWidth||Infinity,event:n};e.windowResize&&t(e,"windowResize").call(e,r)},i=e.disconnect.bind(e),r=function(){window.addEventListener("resize",n),n()},o=function(){window.removeEventListener("resize",n)};return Object.assign(e,{disconnect:function(){o(),i()}}),r(),[r,o]},D=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=M(a(t)),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return c(n,e),n.prototype.windowResize=function(e){},n}(n.Controller),H=function(e,n){void 0===n&&(n=200);var t=null;return function(){var i=arguments,r=this,o=function(){return e.apply(r,i)};clearTimeout(t),t=setTimeout(o,n)}};function U(e,n){var t;return void 0===n&&(n=200),function(){var i=arguments,r=this;t||(t=!0,e.apply(r,i),setTimeout(function(){return t=!1},n))}}function N(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}function W(e){try{return JSON.parse(e)}catch(n){return e}}function _(e){return e.replace(/(?:[_-])([a-z0-9])/g,function(e,n){return n.toUpperCase()})}var B={enterClass:"enter",enterActiveClass:"enterStart",enterToClass:"enterEnd",leaveClass:"leave",leaveActiveClass:"leaveStart",leaveToClass:"leaveEnd"},G={dispatchEvent:!0,eventPrefix:!0,transitioned:!1,hiddenClass:"hidden"},J=function(e,n){var t,i,r,o,s=function(e,n,t,i){try{var r,o;return(r=e.classList).add.apply(r,n),(o=e.classList).add.apply(o,t),Promise.resolve(function(){try{return Promise.resolve(new Promise(function(e){requestAnimationFrame(function(){requestAnimationFrame(e)})}))}catch(e){return Promise.reject(e)}}()).then(function(){var r,o;return(r=e.classList).remove.apply(r,t),(o=e.classList).add.apply(o,i),Promise.resolve(function(e){try{return Promise.resolve(new Promise(function(n){var t=1e3*Number(getComputedStyle(e).transitionDuration.split(",")[0].replace("s",""));setTimeout(function(){n(t)},t)}))}catch(e){return Promise.reject(e)}}(e)).then(function(){var t;(t=e.classList).remove.apply(t,n)})})}catch(e){return Promise.reject(e)}},l=function(t){try{if(!e.transitioned)return Promise.resolve();e.transitioned=!1,p&&p(t);var i=K("leave",n,d),r=K("leaveActive",n,d),o=K("leaveTo",n,d);return Promise.resolve(s(v,i,r,o)).then(function(){m&&v.classList.add(m)})}catch(e){return Promise.reject(e)}},c=function(t){try{if(e.transitioned)return Promise.resolve();e.transitioned=!0,h&&h(t);var i=K("enter",n,d),r=K("enterActive",n,d),o=K("enterTo",n,d);return m&&v.classList.remove(m),Promise.resolve(s(v,i,r,o)).then(function(){})}catch(e){return Promise.reject(e)}};void 0===n&&(n={});var a,u=e.element.dataset.transitionTarget;u&&(a=e[u+"Target"]);var v=(null==(t=n)?void 0:t.element)||a||e.element;if(v instanceof HTMLElement||v instanceof SVGElement){var d=v.dataset,f=Object.assign(G,n),b=f.transitioned,m=f.hiddenClass,h=null==(i=e.enter)?void 0:i.bind(e),p=null==(r=e.leave)?void 0:r.bind(e),g=null==(o=e.toggleTransition)?void 0:o.bind(e);return e.transitioned=b,b?(m&&v.classList.remove(m),c()):(m&&v.classList.add(m),l()),Object.assign(e,{enter:c,leave:l,toggleTransition:E}),[c,l,E]}function E(n){g&&g(n),e.transitioned?l():c()}};function K(e,n,t){var i="transition"+e[0].toUpperCase()+e.substr(1);return(n[e]||t[i]||t[B[e]]||"").split(" ")}var Q=function(e){function n(n){var t;return(t=e.call(this,n)||this).transitioned=!1,requestAnimationFrame(function(){J(a(t),t.options)}),t}return c(n,e),n}(n.Controller);e.ApplicationController=j,e.ClickOutsideController=g,e.HoverController=q,e.IdleController=V,e.IntersectionController=u,e.LazyLoadController=d,e.MutationController=S,e.ResizeController=m,e.TransitionController=Q,e.UseHover=I,e.UseMutation=F,e.UseVisibility=A,e.VisibilityController=z,e.WindowResizeController=D,e.useApplication=O,e.useClickOutside=p,e.useDebounce=function(e,n){var t;null==(t=e.constructor.debounces)||t.forEach(function(t){if("string"==typeof t&&(e[t]=H(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=H(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useDispatch=C,e.useHover=k,e.useIdle=P,e.useIntersection=s,e.useLazyLoad=v,e.useMemo=function(e){var n;null==(n=e.constructor.memos)||n.forEach(function(n){!function(e,n,t){Object.defineProperty(e,n,{value:t})}(e,n,e[n])})},e.useMeta=function(e,n){void 0===n&&(n={suffix:!0});var t=e.constructor.metaNames,i=n.suffix;null==t||t.forEach(function(n){!function(e,n,t){var i=t?_(n)+"Meta":_(n);Object.defineProperty(e,i,{get:function(){return W(N(n))}})}(e,n,i)}),Object.defineProperty(e,"metas",{get:function(){var e={};return null==t||t.forEach(function(n){var t=W(N(n));null!=t&&(e[_(n)]=t)}),e}})},e.useMutation=R,e.useResize=b,e.useThrottle=function(e,n){var t;null==(t=e.constructor.throttles)||t.forEach(function(t){if("string"==typeof t&&(e[t]=U(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=U(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useTransition=J,e.useVisibility=T,e.useWindowResize=M}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("stimulus")):"function"==typeof define&&define.amd?define(["exports","stimulus"],n):n((e=e||self).StimulusUse={},e.Stimulus)}(this,function(e,n){var t=function(e,n){var t=e[n];return"function"==typeof t?t:function(){}},i=function(e,n,t){var i=e;return!0===t?i=n.identifier+":"+e:"string"==typeof t&&(i=t+":"+e),i},r=function(e,n,t){var i=n||{bubbles:!0,cancelable:!0,composed:!0},r=i.bubbles,o=i.cancelable,s=i.composed;return n&&Object.assign(t,{originalEvent:n}),new CustomEvent(e,{bubbles:r,cancelable:o,composed:s,detail:t})},o={dispatchEvent:!0,eventPrefix:!0},s=function(e,n){var s;void 0===n&&(n={});var c=Object.assign({},o,n),l=c.dispatchEvent,a=c.eventPrefix,u=(null==(s=n)?void 0:s.element)||e.element,v=e.disconnect.bind(e),f=new IntersectionObserver(function(n){var o=n[0];o.isIntersecting?function(n){if(e.isVisible=!0,t(e,"appear").call(e,n),l){var o=i("appear",e,a),s=r(o,null,{controller:e,entry:n});u.dispatchEvent(s)}}(o):e.isVisible&&function(n){if(e.isVisible=!1,t(e,"disappear").call(e,n),l){var o=i("disappear",e,a),s=r(o,null,{controller:e,entry:n});u.dispatchEvent(s)}}(o)},n),d=function(){f.observe(u)},b=function(){f.unobserve(u)};return Object.assign(e,{isVisible:!1,disconnect:function(){b(),v()}}),d(),[d,b]};function c(){return(c=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e}).apply(this,arguments)}function l(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var u=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=s(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(function(e){function n(){var n;return(n=e.apply(this,arguments)||this).isVisible=!1,n}return l(n,e),n}(n.Controller)),v=function(e,n){var i=e.disconnect.bind(e),r=new IntersectionObserver(function(n){n[0].isIntersecting&&!e.isLoaded&&function(n){var i=e.data.get("src");if(i){var r=e.element;e.isLoading=!0,t(e,"loading").call(e,i),r.onload=function(){!function(n){e.isLoading=!1,e.isLoaded=!0,t(e,"loaded").call(e,n)}(i)},r.src=i}}()},n),o=function(){r.observe(e.element)},s=function(){r.unobserve(e.element)};return Object.assign(e,{isVisible:!1,disconnect:function(){s(),i()}}),o(),[o,s]},f=function(e){function n(n){var t;return(t=e.call(this,n)||this).options={rootMargin:"10%"},requestAnimationFrame(function(){var e=v(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(function(e){function n(){var n;return(n=e.apply(this,arguments)||this).isLoading=!1,n.isLoaded=!1,n}return l(n,e),n}(n.Controller)),d={dispatchEvent:!0,eventPrefix:!0},b=function(e,n){var o;void 0===n&&(n={});var s=Object.assign({},d,n),c=s.dispatchEvent,l=s.eventPrefix,a=(null==(o=n)?void 0:o.element)||e.element,u=e.disconnect.bind(e),v=new ResizeObserver(function(n){var o=n[0];if(t(e,"resize").call(e,o.contentRect),c){var s=i("resize",e,l),u=r(s,null,{controller:e,entry:o});a.dispatchEvent(u)}}),f=function(){v.observe(a)},b=function(){v.unobserve(a)};return Object.assign(e,{disconnect:function(){b(),u()}}),f(),[f,b]},h=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=b(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(function(e){function n(){return e.apply(this,arguments)||this}return l(n,e),n}(n.Controller)),m={events:["click","touchend"],onlyVisible:!0,dispatchEvent:!0,eventPrefix:!0},p=function(e,n){void 0===n&&(n={});var t=Object.assign({},m,n),o=t.onlyVisible,s=t.dispatchEvent,c=t.events,l=t.eventPrefix,a=function(t){var c,a,u,v,f=(null==(c=n)?void 0:c.element)||e.element;if(!f.contains(t.target)&&(a=f.getBoundingClientRect(),u=window.innerHeight||document.documentElement.clientHeight,v=window.innerWidth||document.documentElement.clientWidth,a.top<=u&&a.top+a.height>=0&&a.left<=v&&a.left+a.width>=0||!o)&&(e.clickOutside&&e.clickOutside(t),s)){var d=i("click:outside",e,l),b=r(d,t,{controller:e});f.dispatchEvent(b)}},u=function(){null==c||c.forEach(function(e){window.addEventListener(e,a,!1)})},v=function(){null==c||c.forEach(function(e){window.removeEventListener(e,a,!1)})},f=e.disconnect.bind(e);return Object.assign(e,{disconnect:function(){v(),f()}}),u(),[u,v]},g=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=p(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(function(e){function n(){return e.apply(this,arguments)||this}return l(n,e),n}(n.Controller)),y={debug:!1,logger:console},E=function(e,n){var t,i,r,o,s,l=this;void 0===n&&(n={}),this.log=function(e,n){l.debug&&(l.logger.groupCollapsed("%c"+l.controller.identifier+" %c#"+e,"color: #3B82F6","color: unset"),l.logger.log(c({controllerId:l.controllerId},n)),l.logger.groupEnd())},this.debug=null!=(t=null!=(i=null==(r=n)?void 0:r.debug)?i:e.application.stimulusUseDebug)?t:y.debug,this.logger=null!=(o=null==(s=n)?void 0:s.logger)?o:y.logger,this.controller=e,this.controllerId=e.element.id||e.element.dataset.id,this.controllerInitialize=e.initialize.bind(e),this.controllerConnect=e.connect.bind(e),this.controllerDisconnect=e.disconnect.bind(e)},w=function(e){function n(n,t){var r,o,s,c,l;return void 0===t&&(t={}),(l=e.call(this,n,t)||this).dispatch=function(e,n){void 0===n&&(n={});var t=a(l),r=t.targetElement,o=t.eventPrefix,s=t.bubbles,c=t.cancelable,u=t.log;Object.assign(n,{controller:t.controller});var v=i(e,l.controller,o),f=new CustomEvent(v,{detail:n,bubbles:s,cancelable:c});return r.dispatchEvent(f),u("dispatch",{eventName:v,detail:n,bubbles:s,cancelable:c}),f},l.targetElement=null!=(r=t.element)?r:n.element,l.eventPrefix=null==(o=t.eventPrefix)||o,l.bubbles=null==(s=t.bubbles)||s,l.cancelable=null==(c=t.cancelable)||c,l.enhanceController(),l}return l(n,e),n.prototype.enhanceController=function(){Object.assign(this.controller,{dispatch:this.dispatch})},n}(E),C=function(e,n){return void 0===n&&(n={}),new w(e,n)},O=function(e,n){void 0===n&&(n={}),Object.defineProperty(e,"isPreview",{get:function(){return document.documentElement.hasAttribute("data-turbolinks-preview")}}),Object.defineProperty(e,"csrfToken",{get:function(){return this.metaValue("csrf-token")}}),C(e,n),Object.assign(e,{metaValue:function(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}})},j=function(e){function n(n){var t;return(t=e.call(this,n)||this).isPreview=!1,t.csrfToken="",O(a(t),t.options),t}return l(n,e),n}(n.Controller),L={ms:6e4,initialState:!1,events:["mousemove","mousedown","resize","keydown","touchstart","wheel"],dispatchEvent:!0,eventPrefix:!0},P=function(e,n){void 0===n&&(n={});var o=Object.assign({},L,n),s=o.ms,c=o.events,l=o.dispatchEvent,a=o.eventPrefix,u=o.initialState,v=setTimeout(function(){u=!0,f()},s),f=function(n){var o=i("away",e,a);if(e.isIdle=!0,t(e,"away").call(e,n),l){var s=r(o,n||null,{controller:e});e.element.dispatchEvent(s)}},d=function(n){var o=i("back",e,a);if(e.isIdle=!1,t(e,"back").call(e,n),l){var s=r(o,n||null,{controller:e});e.element.dispatchEvent(s)}},b=function(e){u&&d(e),u=!1,clearTimeout(v),v=setTimeout(function(){u=!0,f(e)},s)},h=function(e){document.hidden||b(e)};u?f():d();var m=e.disconnect.bind(e),p=function(){c.forEach(function(e){window.addEventListener(e,b)}),document.addEventListener("visibilitychange",h)},g=function(){c.forEach(function(e){window.removeEventListener(e,b)}),document.removeEventListener("visibilitychange",h)};return Object.assign(e,{disconnect:function(){g(),m()}}),p(),[p,g]},V=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=P(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(function(e){function n(){var n;return(n=e.apply(this,arguments)||this).isIdle=!1,n}return l(n,e),n}(n.Controller)),x={dispatchEvent:!0,eventPrefix:!0},A=function(e){function n(n,o){var s;void 0===o&&(o={}),(s=e.call(this,n,o)||this).observe=function(){s.controller.isVisible=!document.hidden,document.addEventListener("visibilitychange",s.handleVisibilityChange)},s.unobserve=function(){document.removeEventListener("visibilitychange",s.handleVisibilityChange)},s.becomesInvisible=function(e){var n=i("invisible",s.controller,s.eventPrefix);s.controller.isVisible=!1,t(s.controller,"invisible").call(s.controller),s.log("invisible",{isVisible:!1}),s.dispatch(n,e)},s.becomesVisible=function(e){var n=i("visible",s.controller,s.eventPrefix);s.controller.isVisible=!0,t(s.controller,"visible").call(s.controller),s.log("visible",{isVisible:!0}),s.dispatch(n,e)},s.dispatch=function(e,n){if(s.dispatchEvent){var t={controller:s.controller,isVisible:s.controller.isVisible},i=r(e,n||null,t);s.controller.element.dispatchEvent(i),s.log("dispatchEvent",c({eventName:e},t))}},s.handleVisibilityChange=function(e){document.hidden?s.becomesInvisible(e):s.becomesVisible(e)};var l=Object.assign({},x,o),u=l.dispatchEvent,v=l.eventPrefix;return Object.assign(a(s),{dispatchEvent:u,eventPrefix:v}),s.controller=n,Object.assign(n,{disconnect:function(){s.unobserve(),s.controllerDisconnect()}}),s.handleVisibilityChange(),s.observe(),s}return l(n,e),n}(E),T=function(e,n){void 0===n&&(n={});var t=new A(e,n);return[t.observe,t.unobserve]},I=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=T(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(function(e){function n(){var n;return(n=e.apply(this,arguments)||this).isVisible=!1,n}return l(n,e),n}(n.Controller)),z=function(e){function n(n,i){var r,o;return void 0===i&&(i={}),(o=e.call(this,n,i)||this).observe=function(){o.targetElement.addEventListener("mouseenter",o.onEnter),o.targetElement.addEventListener("mouseleave",o.onLeave)},o.unobserve=function(){o.targetElement.removeEventListener("mouseenter",o.onEnter),o.targetElement.removeEventListener("mouseleave",o.onLeave)},o.onEnter=function(){t(o.controller,"mouseEnter").call(o.controller),o.log("mouseEnter",{hover:!0})},o.onLeave=function(){t(o.controller,"mouseLeave").call(o.controller),o.log("mouseLeave",{hover:!1})},o.targetElement=(null==(r=i)?void 0:r.element)||n.element,o.controller=n,o.enhanceController(),o.observe(),o}return l(n,e),n.prototype.enhanceController=function(){var e=this,n=this.controller.disconnect.bind(this.controller);Object.assign(this.controller,{disconnect:function(){e.unobserve(),n()}})},n}(E),q=function(e,n){void 0===n&&(n={});var t=new z(e,n);return[t.observe,t.unobserve]},k=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=q(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(function(e){function n(){return e.apply(this,arguments)||this}return l(n,e),n}(n.Controller)),F=function(e){function n(n,i){var r,o;return void 0===i&&(i={}),(o=e.call(this,n,i)||this).observe=function(){try{o.observer.observe(o.targetElement,o.options)}catch(e){o.controller.application.handleError(e,"At a minimum, one of childList, attributes, and/or characterData must be true",{})}},o.unobserve=function(){o.observer.disconnect()},o.mutation=function(e){t(o.controller,"mutate").call(o.controller,e),o.log("mutate",{entries:e})},o.targetElement=(null==(r=i)?void 0:r.element)||n.element,o.controller=n,o.options=i,o.observer=new MutationObserver(o.mutation),o.enhanceController(),o.observe(),o}return l(n,e),n.prototype.enhanceController=function(){var e=this,n=this.controller.disconnect.bind(this.controller);Object.assign(this.controller,{disconnect:function(){e.unobserve(),n()}})},n}(E),S=function(e,n){void 0===n&&(n={});var t=new F(e,n);return[t.observe,t.unobserve]},M=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=S(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(function(e){function n(){return e.apply(this,arguments)||this}return l(n,e),n}(n.Controller)),R=function(e){var n=function(n){var i=window,r={height:i.innerHeight||Infinity,width:i.innerWidth||Infinity,event:n};t(e,"windowResize").call(e,r)},i=e.disconnect.bind(e),r=function(){window.addEventListener("resize",n),n()},o=function(){window.removeEventListener("resize",n)};return Object.assign(e,{disconnect:function(){o(),i()}}),r(),[r,o]},D=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=R(a(t)),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(function(e){function n(){return e.apply(this,arguments)||this}return l(n,e),n}(n.Controller)),H=function(e,n){void 0===n&&(n=200);var t=null;return function(){var i=arguments,r=this,o=function(){return e.apply(r,i)};t&&clearTimeout(t),t=setTimeout(o,n)}};function U(e,n){var t;return void 0===n&&(n=200),function(){var i=arguments,r=this;t||(t=!0,e.apply(r,i),setTimeout(function(){return t=!1},n))}}function N(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}function W(e){try{return JSON.parse(e)}catch(n){return e}}function _(e){return e.replace(/(?:[_-])([a-z0-9])/g,function(e,n){return n.toUpperCase()})}var B={enterClass:"enter",enterActiveClass:"enterStart",enterToClass:"enterEnd",leaveClass:"leave",leaveActiveClass:"leaveStart",leaveToClass:"leaveEnd"},G={dispatchEvent:!0,eventPrefix:!0,transitioned:!1,hiddenClass:"hidden"},J=function(e,n){var t,i,r,o,s=function(e,n,t,i){try{var r,o;return(r=e.classList).add.apply(r,n),(o=e.classList).add.apply(o,t),Promise.resolve(function(){try{return Promise.resolve(new Promise(function(e){requestAnimationFrame(function(){requestAnimationFrame(e)})}))}catch(e){return Promise.reject(e)}}()).then(function(){var r,o;return(r=e.classList).remove.apply(r,t),(o=e.classList).add.apply(o,i),Promise.resolve(function(e){try{return Promise.resolve(new Promise(function(n){var t=1e3*Number(getComputedStyle(e).transitionDuration.split(",")[0].replace("s",""));setTimeout(function(){n(t)},t)}))}catch(e){return Promise.reject(e)}}(e)).then(function(){var t;(t=e.classList).remove.apply(t,n)})})}catch(e){return Promise.reject(e)}},c=function(t){try{if(!e.transitioned)return Promise.resolve();e.transitioned=!1,p&&p(t);var i=K("leave",n,f),r=K("leaveActive",n,f),o=K("leaveTo",n,f);return Promise.resolve(s(v,i,r,o)).then(function(){h&&v.classList.add(h)})}catch(e){return Promise.reject(e)}},l=function(t){try{if(e.transitioned)return Promise.resolve();e.transitioned=!0,m&&m(t);var i=K("enter",n,f),r=K("enterActive",n,f),o=K("enterTo",n,f);return h&&v.classList.remove(h),Promise.resolve(s(v,i,r,o)).then(function(){})}catch(e){return Promise.reject(e)}};void 0===n&&(n={});var a,u=e.element.dataset.transitionTarget;u&&(a=e[u+"Target"]);var v=(null==(t=n)?void 0:t.element)||a||e.element;if(v instanceof HTMLElement||v instanceof SVGElement){var f=v.dataset,d=Object.assign(G,n),b=d.transitioned,h=d.hiddenClass,m=null==(i=e.enter)?void 0:i.bind(e),p=null==(r=e.leave)?void 0:r.bind(e),g=null==(o=e.toggleTransition)?void 0:o.bind(e);return e.transitioned=b,b?(h&&v.classList.remove(h),l()):(h&&v.classList.add(h),c()),Object.assign(e,{enter:l,leave:c,toggleTransition:y}),[l,c,y]}function y(n){g&&g(n),e.transitioned?c():l()}};function K(e,n,t){var i="transition"+e[0].toUpperCase()+e.substr(1);return(n[e]||t[i]||t[B[e]]||"").split(" ")}var Q=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){J(a(t),t.options)}),t}return l(n,e),n}(function(e){function n(){var n;return(n=e.apply(this,arguments)||this).transitioned=!1,n}return l(n,e),n}(n.Controller));e.ApplicationController=j,e.ClickOutsideController=g,e.HoverController=k,e.IdleController=V,e.IntersectionController=u,e.LazyLoadController=f,e.MutationController=M,e.ResizeController=h,e.TransitionController=Q,e.UseHover=z,e.UseMutation=F,e.UseVisibility=A,e.VisibilityController=I,e.WindowResizeController=D,e.useApplication=O,e.useClickOutside=p,e.useDebounce=function(e,n){var t;null==(t=e.constructor.debounces)||t.forEach(function(t){if("string"==typeof t&&(e[t]=H(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=H(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useDispatch=C,e.useHover=q,e.useIdle=P,e.useIntersection=s,e.useLazyLoad=v,e.useMemo=function(e){var n;null==(n=e.constructor.memos)||n.forEach(function(n){!function(e,n,t){Object.defineProperty(e,n,{value:t})}(e,n,e[n])})},e.useMeta=function(e,n){void 0===n&&(n={suffix:!0});var t=e.constructor.metaNames,i=n.suffix;null==t||t.forEach(function(n){!function(e,n,t){var i=t?_(n)+"Meta":_(n);Object.defineProperty(e,i,{get:function(){return W(N(n))}})}(e,n,i)}),Object.defineProperty(e,"metas",{get:function(){var e={};return null==t||t.forEach(function(n){var t=W(N(n));null!=t&&(e[_(n)]=t)}),e}})},e.useMutation=S,e.useResize=b,e.useThrottle=function(e,n){var t;void 0===n&&(n={}),null==(t=e.constructor.throttles)||t.forEach(function(t){var i;if("string"==typeof t&&(e[t]=U(e[t],null==(i=n)?void 0:i.wait)),"object"==typeof t){var r,o=t.name;if(!o)return;e[o]=U(e[o],t.wait||(null==(r=n)?void 0:r.wait))}})},e.useTransition=J,e.useVisibility=T,e.useWindowResize=R}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -6,3 +6,5 @@ export const method = (controller, methodName) => { | ||
} | ||
throw new Error(`undefined method "${methodName}"`); | ||
else { | ||
return (...args) => { }; | ||
} | ||
}; | ||
@@ -9,0 +11,0 @@ export const composeEventName = (name, controller, eventPrefix) => { |
import { Controller, Context } from 'stimulus'; | ||
import { DispatchOptions } from "../use-dispatch"; | ||
export declare class ApplicationController extends Controller { | ||
options: DispatchOptions; | ||
dispatch: (eventName: String, detail: any) => void; | ||
metaValue: (name: string) => string; | ||
options?: DispatchOptions; | ||
readonly isPreview: boolean; | ||
readonly csrfToken: string; | ||
constructor(context: Context); | ||
metaValue: (name: string) => string; | ||
dispatch: (eventName: String, detail: any) => void; | ||
} | ||
//# sourceMappingURL=application-controller.d.ts.map |
import { Controller } from 'stimulus'; | ||
import { DispatchOptions } from '../use-dispatch/index'; | ||
export declare const useApplication: (controller: Controller, options: DispatchOptions) => void; | ||
export declare const useApplication: (controller: Controller, options?: DispatchOptions) => void; | ||
//# sourceMappingURL=use-application.d.ts.map |
import { useDispatch } from '../use-dispatch/index'; | ||
export const useApplication = (controller, options) => { | ||
export const useApplication = (controller, options = {}) => { | ||
// getter to detect Turbolink preview | ||
@@ -4,0 +4,0 @@ Object.defineProperty(controller, 'isPreview', { |
@@ -1,10 +0,12 @@ | ||
import { Controller, Context } from 'stimulus'; | ||
import { Context, Controller } from 'stimulus'; | ||
import { ClickOutsideOptions } from './use-click-outside'; | ||
export declare class ClickOutsideController extends Controller { | ||
options: ClickOutsideOptions; | ||
export declare class ClickOutsideComposableController extends Controller { | ||
clickOutside: (event: Event) => void; | ||
} | ||
export declare class ClickOutsideController extends ClickOutsideComposableController { | ||
options?: ClickOutsideOptions; | ||
constructor(context: Context); | ||
observe: () => void; | ||
unobserve: () => void; | ||
constructor(context: Context); | ||
clickOutside(event: Event): void; | ||
} | ||
//# sourceMappingURL=click-outside-controller.d.ts.map |
import { Controller } from 'stimulus'; | ||
import { useClickOutside } from './use-click-outside'; | ||
export class ClickOutsideController extends Controller { | ||
export class ClickOutsideComposableController extends Controller { | ||
} | ||
export class ClickOutsideController extends ClickOutsideComposableController { | ||
constructor(context) { | ||
@@ -11,4 +13,3 @@ super(context); | ||
} | ||
clickOutside(event) { } | ||
} | ||
//# sourceMappingURL=click-outside-controller.js.map |
@@ -1,5 +0,2 @@ | ||
import { Controller } from 'stimulus'; | ||
interface ClickOutsideController extends Controller { | ||
clickOutside?: (event: Event) => void; | ||
} | ||
import { ClickOutsideComposableController } from './click-outside-controller'; | ||
export interface ClickOutsideOptions { | ||
@@ -12,4 +9,3 @@ element?: Element; | ||
} | ||
export declare const useClickOutside: (controller: ClickOutsideController, options?: ClickOutsideOptions) => readonly [() => void, () => void]; | ||
export {}; | ||
export declare const useClickOutside: (controller: ClickOutsideComposableController, options?: ClickOutsideOptions) => readonly [() => void, () => void]; | ||
//# sourceMappingURL=use-click-outside.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { method, extendedEvent, isElementInViewport, composeEventName } from '../support/index'; | ||
import { composeEventName, extendedEvent, isElementInViewport } from '../support/index'; | ||
const defaultOptions = { | ||
@@ -16,3 +16,5 @@ events: ['click', 'touchend'], | ||
// call the clickOutside method of the Stimulus controller | ||
controller.clickOutside && method(controller, 'clickOutside').call(controller, event); | ||
if (controller.clickOutside) { | ||
controller.clickOutside(event); | ||
} | ||
// emit a custom event | ||
@@ -19,0 +21,0 @@ if (dispatchEvent) { |
@@ -12,3 +12,5 @@ import { Controller } from 'stimulus'; | ||
const callback = () => fn.apply(context, args); | ||
clearTimeout(timeoutId); | ||
if (timeoutId) { | ||
clearTimeout(timeoutId); | ||
} | ||
timeoutId = setTimeout(callback, wait); | ||
@@ -15,0 +17,0 @@ }; |
import { Context, Controller } from 'stimulus'; | ||
import { HoverOptions } from './use-hover'; | ||
export declare class HoverController extends Controller { | ||
options: HoverOptions; | ||
export declare class HoverComposableController extends Controller { | ||
mouseEnter?: () => void; | ||
mouseLeave?: () => void; | ||
} | ||
export declare class HoverController extends HoverComposableController { | ||
options?: HoverOptions; | ||
constructor(context: Context); | ||
observe: () => {}; | ||
unobserve: () => {}; | ||
mouseEnter: () => {}; | ||
mouseLeave: () => {}; | ||
observe: () => void; | ||
unobserve: () => void; | ||
} | ||
//# sourceMappingURL=hover-controller.d.ts.map |
import { Controller } from 'stimulus'; | ||
import { useHover } from './use-hover'; | ||
export class HoverController extends Controller { | ||
export class HoverComposableController extends Controller { | ||
} | ||
export class HoverController extends HoverComposableController { | ||
constructor(context) { | ||
@@ -5,0 +7,0 @@ super(context); |
import { StimulusUse, StimulusUseOptions } from '../stimulus_use'; | ||
import { HoverController } from './hover-controller'; | ||
import { HoverComposableController } from './hover-controller'; | ||
export interface HoverOptions extends StimulusUseOptions { | ||
@@ -7,5 +7,5 @@ element?: Element; | ||
export declare class UseHover extends StimulusUse { | ||
controller: HoverController; | ||
controller: HoverComposableController; | ||
targetElement: Element; | ||
constructor(controller: HoverController, options?: HoverOptions); | ||
constructor(controller: HoverComposableController, options?: HoverOptions); | ||
observe: () => void; | ||
@@ -17,3 +17,3 @@ unobserve: () => void; | ||
} | ||
export declare const useHover: (controller: HoverController, options?: HoverOptions) => readonly [() => void, () => void]; | ||
export declare const useHover: (controller: HoverComposableController, options?: HoverOptions) => readonly [() => void, () => void]; | ||
//# sourceMappingURL=use-hover.d.ts.map |
@@ -15,7 +15,7 @@ import { StimulusUse } from '../stimulus_use'; | ||
this.onEnter = () => { | ||
this.controller.mouseEnter && method(this.controller, 'mouseEnter').call(this.controller); | ||
method(this.controller, 'mouseEnter').call(this.controller); | ||
this.log('mouseEnter', { hover: true }); | ||
}; | ||
this.onLeave = () => { | ||
this.controller.mouseLeave && method(this.controller, 'mouseLeave').call(this.controller); | ||
method(this.controller, 'mouseLeave').call(this.controller); | ||
this.log('mouseLeave', { hover: false }); | ||
@@ -22,0 +22,0 @@ }; |
import { Controller, Context } from 'stimulus'; | ||
import { IdleOptions } from './use-idle'; | ||
export declare class IdleController extends Controller { | ||
export declare class IdleComposableController extends Controller { | ||
isIdle: boolean; | ||
options: IdleOptions; | ||
away: () => void; | ||
back: () => void; | ||
} | ||
export declare class IdleController extends IdleComposableController { | ||
options?: IdleOptions; | ||
constructor(context: Context); | ||
observe: () => void; | ||
unobserve: () => void; | ||
constructor(context: Context); | ||
away(): void; | ||
back(): void; | ||
} | ||
//# sourceMappingURL=idle-controller.d.ts.map |
import { Controller } from 'stimulus'; | ||
import { useIdle } from './use-idle'; | ||
export class IdleController extends Controller { | ||
export class IdleComposableController extends Controller { | ||
constructor() { | ||
super(...arguments); | ||
this.isIdle = false; | ||
} | ||
} | ||
export class IdleController extends IdleComposableController { | ||
constructor(context) { | ||
super(context); | ||
this.isIdle = false; | ||
requestAnimationFrame(() => { | ||
@@ -12,5 +17,3 @@ const [observe, unobserve] = useIdle(this, this.options); | ||
} | ||
away() { } | ||
back() { } | ||
} | ||
//# sourceMappingURL=idle-controller.js.map |
@@ -1,2 +0,2 @@ | ||
import { IdleController } from './idle-controller'; | ||
import { IdleComposableController } from './idle-controller'; | ||
export interface IdleOptions { | ||
@@ -9,3 +9,3 @@ ms?: number; | ||
} | ||
export declare const useIdle: (controller: IdleController, options?: IdleOptions) => readonly [() => void, () => void]; | ||
export declare const useIdle: (controller: IdleComposableController, options?: IdleOptions) => readonly [() => void, () => void]; | ||
//# sourceMappingURL=use-idle.d.ts.map |
@@ -21,3 +21,3 @@ import { extendedEvent, method, composeEventName } from '../support/index'; | ||
controller.isIdle = true; | ||
controller.away && method(controller, 'away').call(controller, event); | ||
method(controller, 'away').call(controller, event); | ||
if (dispatchEvent) { | ||
@@ -31,3 +31,3 @@ const clickOutsideEvent = extendedEvent(eventName, event || null, { controller }); | ||
controller.isIdle = false; | ||
controller.back && method(controller, 'back').call(controller, event); | ||
method(controller, 'back').call(controller, event); | ||
if (dispatchEvent) { | ||
@@ -34,0 +34,0 @@ const clickOutsideEvent = extendedEvent(eventName, event || null, { controller }); |
import { Controller, Context } from 'stimulus'; | ||
import { IntersectionOptions } from './use-intersection'; | ||
export declare class IntersectionController extends Controller { | ||
export declare class IntersectionComposableController extends Controller { | ||
isVisible: boolean; | ||
options: IntersectionOptions; | ||
appear?: (entry: IntersectionObserverEntry) => void; | ||
disappear?: (entry: IntersectionObserverEntry) => void; | ||
} | ||
export declare class IntersectionController extends IntersectionComposableController { | ||
options?: IntersectionOptions; | ||
constructor(context: Context); | ||
observe: () => void; | ||
unobserve: () => void; | ||
appear: (entry: IntersectionObserverEntry) => void; | ||
disappear: (entry: IntersectionObserverEntry) => void; | ||
constructor(context: Context); | ||
} | ||
//# sourceMappingURL=intersection-controller.d.ts.map |
import { Controller } from 'stimulus'; | ||
import { useIntersection } from './use-intersection'; | ||
export class IntersectionController extends Controller { | ||
export class IntersectionComposableController extends Controller { | ||
constructor() { | ||
super(...arguments); | ||
this.isVisible = false; | ||
} | ||
} | ||
export class IntersectionController extends IntersectionComposableController { | ||
constructor(context) { | ||
super(context); | ||
this.isVisible = false; | ||
requestAnimationFrame(() => { | ||
@@ -8,0 +13,0 @@ const [observe, unobserve] = useIntersection(this, this.options); |
@@ -1,2 +0,2 @@ | ||
import { IntersectionController } from './intersection-controller'; | ||
import { IntersectionComposableController } from './intersection-controller'; | ||
export interface IntersectionOptions extends IntersectionObserverInit { | ||
@@ -7,3 +7,3 @@ element?: Element; | ||
} | ||
export declare const useIntersection: (controller: IntersectionController, options?: IntersectionOptions) => readonly [() => void, () => void]; | ||
export declare const useIntersection: (controller: IntersectionComposableController, options?: IntersectionOptions) => readonly [() => void, () => void]; | ||
//# sourceMappingURL=use-intersection.d.ts.map |
@@ -20,3 +20,3 @@ import { method, extendedEvent, composeEventName } from '../support/index'; | ||
controller.isVisible = true; | ||
controller.appear && method(controller, 'appear').call(controller, entry); | ||
method(controller, 'appear').call(controller, entry); | ||
// emit a custom "appear" event | ||
@@ -31,3 +31,3 @@ if (dispatchEvent) { | ||
controller.isVisible = false; | ||
controller.disappear && method(controller, 'disappear').call(controller, entry); | ||
method(controller, 'disappear').call(controller, entry); | ||
// emit a custom "disappear" event | ||
@@ -34,0 +34,0 @@ if (dispatchEvent) { |
import { Controller, Context } from 'stimulus'; | ||
export declare class LazyLoadController extends Controller { | ||
export declare class LazyLoadComposableController extends Controller { | ||
isLoading: boolean; | ||
isLoaded: boolean; | ||
loading: (src: string) => void; | ||
loaded: (src: string) => void; | ||
} | ||
export declare class LazyLoadController extends LazyLoadComposableController { | ||
options: IntersectionObserverInit; | ||
constructor(context: Context); | ||
observe: () => void; | ||
unobserve: () => void; | ||
constructor(context: Context); | ||
loading(src: string): void; | ||
loaded(src: string): void; | ||
} | ||
//# sourceMappingURL=lazy-load-controller.d.ts.map |
import { Controller } from 'stimulus'; | ||
import { useLazyLoad } from './useLazyLoad'; | ||
export class LazyLoadController extends Controller { | ||
export class LazyLoadComposableController extends Controller { | ||
constructor() { | ||
super(...arguments); | ||
this.isLoading = false; | ||
this.isLoaded = false; | ||
} | ||
} | ||
export class LazyLoadController extends LazyLoadComposableController { | ||
constructor(context) { | ||
super(context); | ||
this.isLoading = false; | ||
this.isLoaded = false; | ||
this.options = { rootMargin: '10%' }; | ||
@@ -14,5 +19,3 @@ requestAnimationFrame(() => { | ||
} | ||
loading(src) { } | ||
loaded(src) { } | ||
} | ||
//# sourceMappingURL=lazy-load-controller.js.map |
@@ -1,3 +0,3 @@ | ||
import { LazyLoadController } from './lazy-load-controller'; | ||
export declare const useLazyLoad: (controller: LazyLoadController, options?: IntersectionObserverInit | undefined) => readonly [() => void, () => void]; | ||
import { LazyLoadComposableController } from './lazy-load-controller'; | ||
export declare const useLazyLoad: (controller: LazyLoadComposableController, options?: IntersectionObserverInit | undefined) => readonly [() => void, () => void]; | ||
//# sourceMappingURL=useLazyLoad.d.ts.map |
@@ -15,3 +15,3 @@ import { method } from '../support/index'; | ||
controller.isLoading = true; | ||
controller.loading && method(controller, 'loading').call(controller, src); | ||
method(controller, 'loading').call(controller, src); | ||
imageElement.onload = () => { | ||
@@ -25,3 +25,3 @@ handleLoaded(src); | ||
controller.isLoaded = true; | ||
controller.loading && method(controller, 'loaded').call(controller, src); | ||
method(controller, 'loaded').call(controller, src); | ||
}; | ||
@@ -28,0 +28,0 @@ // keep a copy of the current disconnect() function of the controller to not override it |
import { Context, Controller } from 'stimulus'; | ||
import { MutationOptions } from './use-mutation'; | ||
export declare class MutationController extends Controller { | ||
options: MutationOptions; | ||
export declare class MutationComposableController extends Controller { | ||
mutate: (entries: MutationRecord[]) => void; | ||
} | ||
export declare class MutationController extends MutationComposableController { | ||
options?: MutationOptions; | ||
constructor(context: Context); | ||
observe: () => {}; | ||
unobserve: () => {}; | ||
mutate: (entries: MutationRecord[]) => {}; | ||
observe: () => void; | ||
unobserve: () => void; | ||
} | ||
//# sourceMappingURL=mutation-controller.d.ts.map |
import { Controller } from 'stimulus'; | ||
import { useMutation } from './use-mutation'; | ||
export class MutationController extends Controller { | ||
export class MutationComposableController extends Controller { | ||
} | ||
export class MutationController extends MutationComposableController { | ||
constructor(context) { | ||
@@ -5,0 +7,0 @@ super(context); |
import { StimulusUse, StimulusUseOptions } from '../stimulus_use'; | ||
import { MutationController } from './mutation-controller'; | ||
import { MutationComposableController } from './mutation-controller'; | ||
export interface MutationControllerOptions { | ||
@@ -9,7 +9,7 @@ element?: Element; | ||
export declare class UseMutation extends StimulusUse { | ||
controller: MutationController; | ||
controller: MutationComposableController; | ||
observer: MutationObserver; | ||
targetElement: Element; | ||
options: MutationOptions; | ||
constructor(controller: MutationController, options?: MutationOptions); | ||
constructor(controller: MutationComposableController, options?: MutationOptions); | ||
observe: () => void; | ||
@@ -20,3 +20,3 @@ unobserve: () => void; | ||
} | ||
export declare const useMutation: (controller: MutationController, options?: MutationOptions) => readonly [() => void, () => void]; | ||
export declare const useMutation: (controller: MutationComposableController, options?: MutationOptions) => readonly [() => void, () => void]; | ||
//# sourceMappingURL=use-mutation.d.ts.map |
@@ -18,3 +18,3 @@ import { StimulusUse } from '../stimulus_use'; | ||
this.mutation = (entries) => { | ||
this.controller.mutate && method(this.controller, 'mutate').call(this.controller, entries); | ||
method(this.controller, 'mutate').call(this.controller, entries); | ||
this.log('mutate', { entries }); | ||
@@ -21,0 +21,0 @@ }; |
import { Controller, Context } from 'stimulus'; | ||
import { ResizeOptions } from './use-resize'; | ||
export declare class ResizeController extends Controller { | ||
options: ResizeOptions; | ||
export declare class ResizeComposableController extends Controller { | ||
resize: (contentRect: DOMRectReadOnly) => void; | ||
} | ||
export declare class ResizeController extends ResizeComposableController { | ||
options?: ResizeOptions; | ||
constructor(context: Context); | ||
observe: () => void; | ||
unobserve: () => void; | ||
constructor(context: Context); | ||
resize(contentRect: DOMRectReadOnly): void; | ||
} | ||
//# sourceMappingURL=resize-controller.d.ts.map |
import { Controller } from 'stimulus'; | ||
import { useResize } from './use-resize'; | ||
export class ResizeController extends Controller { | ||
export class ResizeComposableController extends Controller { | ||
} | ||
export class ResizeController extends ResizeComposableController { | ||
constructor(context) { | ||
@@ -11,4 +13,3 @@ super(context); | ||
} | ||
resize(contentRect) { } | ||
} | ||
//# sourceMappingURL=resize-controller.js.map |
@@ -1,2 +0,2 @@ | ||
import { ResizeController } from './resize-controller'; | ||
import { ResizeComposableController } from './resize-controller'; | ||
export interface ResizeOptions { | ||
@@ -7,3 +7,3 @@ element?: Element; | ||
} | ||
export declare const useResize: (controller: ResizeController, options?: ResizeOptions) => readonly [() => void, () => void]; | ||
export declare const useResize: (controller: ResizeComposableController, options?: ResizeOptions) => readonly [() => void, () => void]; | ||
//# sourceMappingURL=use-resize.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { method, extendedEvent, composeEventName } from '../support/index'; | ||
import { composeEventName, extendedEvent, method } from '../support/index'; | ||
const defaultOptions = { | ||
@@ -11,3 +11,3 @@ dispatchEvent: true, | ||
const [entry] = entries; | ||
controller.resize && method(controller, 'resize').call(controller, entry.contentRect); | ||
method(controller, 'resize').call(controller, entry.contentRect); | ||
// emit a custom "controllerIdentifier:resize" event | ||
@@ -14,0 +14,0 @@ if (dispatchEvent) { |
@@ -10,4 +10,4 @@ import { Controller } from 'stimulus'; | ||
export declare function throttle(func: Function, wait?: number): Function; | ||
export declare const useThrottle: (controller: ThrottleController, options: ThrottleOptions) => void; | ||
export declare const useThrottle: (controller: ThrottleController, options?: ThrottleOptions) => void; | ||
export {}; | ||
//# sourceMappingURL=use-throttle.d.ts.map |
@@ -18,3 +18,3 @@ import { Controller } from 'stimulus'; | ||
} | ||
export const useThrottle = (controller, options) => { | ||
export const useThrottle = (controller, options = {}) => { | ||
var _a; | ||
@@ -21,0 +21,0 @@ const constructor = controller.constructor; |
import { Controller, Context } from 'stimulus'; | ||
import { TransitionOptions } from './use-transition'; | ||
export declare class TransitionController extends Controller { | ||
export declare class TransitionComposableController extends Controller { | ||
transitioned: boolean; | ||
options: TransitionOptions; | ||
enter: (event: Event) => void; | ||
leave: (event: Event) => void; | ||
toggleTransition: (event: Event) => void; | ||
} | ||
export declare class TransitionController extends TransitionComposableController { | ||
options?: TransitionOptions; | ||
constructor(context: Context); | ||
} | ||
//# sourceMappingURL=transition-controller.d.ts.map |
import { Controller } from 'stimulus'; | ||
import { useTransition } from './use-transition'; | ||
export class TransitionController extends Controller { | ||
export class TransitionComposableController extends Controller { | ||
constructor() { | ||
super(...arguments); | ||
this.transitioned = false; | ||
} | ||
} | ||
export class TransitionController extends TransitionComposableController { | ||
constructor(context) { | ||
super(context); | ||
this.transitioned = false; | ||
requestAnimationFrame(() => { | ||
@@ -8,0 +13,0 @@ useTransition(this, this.options); |
@@ -1,2 +0,2 @@ | ||
import { TransitionController } from "./transition-controller"; | ||
import { TransitionComposableController } from './transition-controller'; | ||
export interface TransitionOptions { | ||
@@ -15,3 +15,3 @@ element?: Element; | ||
} | ||
export declare const useTransition: (controller: TransitionController, options?: TransitionOptions) => ((event: Event) => void)[] | undefined; | ||
export declare const useTransition: (controller: TransitionComposableController, options?: TransitionOptions) => ((event: Event) => void)[] | undefined; | ||
//# sourceMappingURL=use-transition.d.ts.map |
import { StimulusUse, StimulusUseOptions } from '../stimulus_use'; | ||
import { VisibilityController } from './visibility-controller'; | ||
import { VisibilityComposableController } from './visibility-controller'; | ||
export interface VisibilityOptions extends StimulusUseOptions { | ||
@@ -8,6 +8,6 @@ dispatchEvent?: boolean; | ||
export declare class UseVisibility extends StimulusUse { | ||
controller: VisibilityController; | ||
controller: VisibilityComposableController; | ||
eventPrefix: boolean | string; | ||
dispatchEvent: boolean; | ||
constructor(controller: VisibilityController, options?: VisibilityOptions); | ||
constructor(controller: VisibilityComposableController, options?: VisibilityOptions); | ||
observe: () => void; | ||
@@ -20,3 +20,3 @@ unobserve: () => void; | ||
} | ||
export declare const useVisibility: (controller: VisibilityController, options?: VisibilityOptions) => readonly [() => void, () => void]; | ||
export declare const useVisibility: (controller: VisibilityComposableController, options?: VisibilityOptions) => readonly [() => void, () => void]; | ||
//# sourceMappingURL=use-visibility.d.ts.map |
@@ -1,6 +0,6 @@ | ||
import { extendedEvent, method, composeEventName } from '../support/index'; | ||
import { StimulusUse } from '../stimulus_use'; | ||
import { composeEventName, extendedEvent, method } from '../support/index'; | ||
const defaultOptions = { | ||
dispatchEvent: true, | ||
eventPrefix: true | ||
eventPrefix: true, | ||
}; | ||
@@ -21,4 +21,4 @@ export class UseVisibility extends StimulusUse { | ||
this.controller.isVisible = false; | ||
this.controller.invisible && method(this.controller, 'invisible').call(this.controller, event); | ||
this.log("invisible", { isVisible: false }); | ||
method(this.controller, 'invisible').call(this.controller); | ||
this.log('invisible', { isVisible: false }); | ||
this.dispatch(eventName, event); | ||
@@ -29,4 +29,4 @@ }; | ||
this.controller.isVisible = true; | ||
this.controller.visible && method(this.controller, 'visible').call(this.controller, event); | ||
this.log("visible", { isVisible: true }); | ||
method(this.controller, 'visible').call(this.controller); | ||
this.log('visible', { isVisible: true }); | ||
this.dispatch(eventName, event); | ||
@@ -39,3 +39,3 @@ }; | ||
this.controller.element.dispatchEvent(visibilityEvent); | ||
this.log("dispatchEvent", Object.assign({ eventName }, detail)); | ||
this.log('dispatchEvent', Object.assign({ eventName }, detail)); | ||
} | ||
@@ -42,0 +42,0 @@ }; |
import { Controller, Context } from 'stimulus'; | ||
import { VisibilityOptions } from './use-visibility'; | ||
export declare class VisibilityController extends Controller { | ||
export declare class VisibilityComposableController extends Controller { | ||
isVisible: boolean; | ||
options: VisibilityOptions; | ||
visible?: () => void; | ||
invisible?: () => void; | ||
} | ||
export declare class VisibilityController extends VisibilityComposableController { | ||
options?: VisibilityOptions; | ||
constructor(context: Context); | ||
observe: () => void; | ||
unobserve: () => void; | ||
visible: () => void; | ||
invisible: () => void; | ||
constructor(context: Context); | ||
} | ||
//# sourceMappingURL=visibility-controller.d.ts.map |
import { Controller } from 'stimulus'; | ||
import { useVisibility } from './use-visibility'; | ||
export class VisibilityController extends Controller { | ||
export class VisibilityComposableController extends Controller { | ||
constructor() { | ||
super(...arguments); | ||
this.isVisible = false; | ||
} | ||
} | ||
export class VisibilityController extends VisibilityComposableController { | ||
constructor(context) { | ||
@@ -5,0 +11,0 @@ super(context); |
@@ -1,2 +0,2 @@ | ||
import { WindowResizeController } from './window-resize-controller'; | ||
import { WindowResizeComposableController } from './window-resize-controller'; | ||
export interface WindowResizePayload { | ||
@@ -7,3 +7,3 @@ height: number; | ||
} | ||
export declare const useWindowResize: (controller: WindowResizeController) => readonly [() => void, () => void]; | ||
export declare const useWindowResize: (controller: WindowResizeComposableController) => readonly [() => void, () => void]; | ||
//# sourceMappingURL=use-window-resize.d.ts.map |
@@ -10,3 +10,3 @@ import { method } from '../support/index'; | ||
}; | ||
controller.windowResize && method(controller, 'windowResize').call(controller, payload); | ||
method(controller, 'windowResize').call(controller, payload); | ||
}; | ||
@@ -13,0 +13,0 @@ const controllerDisconnect = controller.disconnect.bind(controller); |
import { Controller, Context } from 'stimulus'; | ||
import { WindowResizePayload } from './use-window-resize'; | ||
export declare class WindowResizeController extends Controller { | ||
export declare class WindowResizeComposableController extends Controller { | ||
windowResize: (payload: WindowResizePayload) => void; | ||
} | ||
export declare class WindowResizeController extends WindowResizeComposableController { | ||
constructor(context: Context); | ||
observe: () => void; | ||
unobserve: () => void; | ||
constructor(context: Context); | ||
windowResize(payload: WindowResizePayload): void; | ||
} | ||
//# sourceMappingURL=window-resize-controller.d.ts.map |
import { Controller } from 'stimulus'; | ||
import { useWindowResize } from './use-window-resize'; | ||
export class WindowResizeController extends Controller { | ||
export class WindowResizeComposableController extends Controller { | ||
} | ||
export class WindowResizeController extends WindowResizeComposableController { | ||
constructor(context) { | ||
@@ -11,4 +13,3 @@ super(context); | ||
} | ||
windowResize(payload) { } | ||
} | ||
//# sourceMappingURL=window-resize-controller.js.map |
{ | ||
"name": "stimulus-use", | ||
"version": "0.22.0", | ||
"version": "0.22.1-0", | ||
"description": "A collection of standard controllers and utilities for Stimulus", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.umd.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
211621
1430