stimulus-use
Advanced tools
Comparing version 0.21.1 to 0.21.2
@@ -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},o=function(e,n,t){var i=n||{bubbles:!0,cancelable:!0,composed:!0},o=i.bubbles,r=i.cancelable,c=i.composed;return n&&Object.assign(t,{originalEvent:n}),new CustomEvent(e,{bubbles:o,cancelable:r,composed:c,detail:t})},r={dispatchEvent:!0,eventPrefix:!0},c=function(e,n){var c;void 0===n&&(n={});var s=Object.assign(r,n),l=s.dispatchEvent,u=s.eventPrefix,a=(null==(c=n)?void 0:c.element)||e.element,d=e.disconnect.bind(e),v=new IntersectionObserver(function(n){var r=n[0];r.isIntersecting?function(n){if(e.isVisible=!0,e.appear&&t(e,"appear").call(e,n),l){var r=i("appear",e,u),c=o(r,null,{controller:e,entry:n});a.dispatchEvent(c)}}(r):e.isVisible&&function(n){if(e.isVisible=!1,e.disappear&&t(e,"disappear").call(e,n),l){var r=i("disappear",e,u),c=o(r,null,{controller:e,entry:n});a.dispatchEvent(c)}}(r)},n),f=function(){v.observe(a)},b=function(){v.unobserve(a)};return Object.assign(e,{isVisible:!1,disconnect:function(){b(),d()}}),f(),[f,b]};function s(){return(s=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 u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var a=function(e){function n(n){var t;return(t=e.call(this,n)||this).isVisible=!1,requestAnimationFrame(function(){var e=c(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(n.Controller),d=function(e,n){var i=e.disconnect.bind(e),o=new IntersectionObserver(function(n){n[0].isIntersecting&&!e.isLoaded&&function(n){var i=e.data.get("src");if(i){var o=e.element;e.isLoading=!0,e.loading&&t(e,"loading").call(e,i),o.onload=function(){!function(n){e.isLoading=!1,e.isLoaded=!0,e.loading&&t(e,"loaded").call(e,n)}(i)},o.src=i}}()},n),r=function(){o.observe(e.element)},c=function(){o.unobserve(e.element)};return Object.assign(e,{isVisible:!1,disconnect:function(){c(),i()}}),r(),[r,c]},v=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=d(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}l(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 r;void 0===n&&(n={});var c=Object.assign(f,n),s=c.dispatchEvent,l=c.eventPrefix,u=(null==(r=n)?void 0:r.element)||e.element,a=e.disconnect.bind(e),d=new ResizeObserver(function(n){var r=n[0];if(e.resize&&t(e,"resize").call(e,r.contentRect),s){var c=i("resize",e,l),a=o(c,null,{controller:e,entry:r});u.dispatchEvent(a)}}),v=function(){d.observe(u)},b=function(){d.unobserve(u)};return Object.assign(e,{disconnect:function(){b(),a()}}),v(),[v,b]},h=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=b(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return l(n,e),n.prototype.resize=function(e){},n}(n.Controller),p={events:["click","touchend"],onlyVisible:!0,dispatchEvent:!0,eventPrefix:!0},m=function(e,n){void 0===n&&(n={});var r=Object.assign(p,n),c=r.onlyVisible,s=r.dispatchEvent,l=r.events,u=r.eventPrefix,a=function(r){var l,a,d=(null==(l=n)?void 0:l.element)||e.element;if(!d.contains(r.target)&&((a=d.getBoundingClientRect()).top>=0&&a.left>=0&&a.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&a.right<=(window.innerWidth||document.documentElement.clientWidth)||!c)&&(e.clickOutside&&t(e,"clickOutside").call(e,r),s)){var v=i("click:outside",e,u),f=o(v,r,{controller:e});d.dispatchEvent(f)}},d=function(){null==l||l.forEach(function(e){window.addEventListener(e,a,!1)})},v=function(){null==l||l.forEach(function(e){window.removeEventListener(e,a,!1)})},f=e.disconnect.bind(e);return Object.assign(e,{disconnect:function(){v(),f()}}),d(),[d,v]},g=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=m(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return l(n,e),n.prototype.clickOutside=function(e){},n}(n.Controller),y={debug:!1,logger:console},w=function(e){function n(n,t){var i;return(i=e.call(this,n,t)||this).targetElement=(null==t?void 0:t.element)||n.element,i.eventPrefix=(null==t?void 0:t.eventPrefix)||!0,i.bubbles=(null==t?void 0:t.bubbles)||!0,i.cancelable=(null==t?void 0:t.cancelable)||!0,i.enhanceController(),i}return l(n,e),n.prototype.enhanceController=function(){var e=this.controller,n=this.targetElement,t=this.eventPrefix,o=this.bubbles,r=this.cancelable,c=this.log;Object.assign(this.controller,{dispatch:function(s,l){void 0===l&&(l={}),Object.assign(l,{controller:e});var u=i(s,e,t),a=new CustomEvent(u,{detail:l,bubbles:o,cancelable:r});return n.dispatchEvent(a),c("useDispatch",{eventName:u,detail:l,bubbles:o,cancelable:r}),a}})},n}(function(e,n){var t=this;this.log=function(e,n){if(t.debug){var i=t.id?"id: "+t.id:"";t.logger.group(""+e),t.logger.log("called from controller: "+t.controller.identifier+" "+i,s({},n)),t.logger.groupEnd()}},this.debug=(null==n?void 0:n.debug)||e.application.stimulusUseDebug||y.debug,this.logger=(null==n?void 0:n.logger)||y.logger,this.controller=e,this.id=e.element.id,this.controllerInitialize=e.initialize.bind(e),this.controllerConnect=e.connect.bind(e),this.controllerDisconnect=e.disconnect.bind(e)}),E=function(e,n){return 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")}}),E(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(u(t),t.options),t}return l(n,e),n}(n.Controller),C={ms:6e4,initialState:!1,events:["mousemove","mousedown","resize","keydown","touchstart","wheel"],dispatchEvent:!0,eventPrefix:!0},P=function(e,n){void 0===n&&(n={});var r=Object.assign(C,n),c=r.ms,s=r.events,l=r.dispatchEvent,u=r.eventPrefix,a=r.initialState,d=setTimeout(function(){a=!0,v()},c),v=function(n){var r=i("away",e,u);if(e.isIdle=!0,e.away&&t(e,"away").call(e,n),l){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},f=function(n){var r=i("back",e,u);if(e.isIdle=!1,e.back&&t(e,"back").call(e,n),l){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},b=function(e){a&&f(e),a=!1,clearTimeout(d),d=setTimeout(function(){a=!0,v(e)},c)},h=function(e){document.hidden||b(e)};a?v():f();var p=e.disconnect.bind(e),m=function(){s.forEach(function(e){window.addEventListener(e,b)}),document.addEventListener("visibilitychange",h)},g=function(){s.forEach(function(e){window.removeEventListener(e,b)}),document.removeEventListener("visibilitychange",h)};return Object.assign(e,{disconnect:function(){g(),p()}}),m(),[m,g]},V=function(e){function n(n){var t;return(t=e.call(this,n)||this).isIdle=!1,requestAnimationFrame(function(){var e=P(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}l(n,e);var t=n.prototype;return t.away=function(){},t.back=function(){},n}(n.Controller),x={dispatchEvent:!0,eventPrefix:!0},z=function(e,n){var r=this;void 0===n&&(n={}),this.observe=function(){r.controller.isVisible=!document.hidden,document.addEventListener("visibilitychange",r.handleVisibilityChange)},this.unobserve=function(){document.removeEventListener("visibilitychange",r.handleVisibilityChange)},this.dispatchInvisible=function(e){var n=i("invisible",r.controller,r.eventPrefix);r.controller.isVisible=!1,r.controller.invisible&&t(r.controller,"invisible").call(r.controller,e),r.dispatch(n,e)},this.dispatchVisible=function(e){var n=i("visible",r.controller,r.eventPrefix);r.controller.isVisible=!0,r.controller.visible&&t(r.controller,"visible").call(r.controller,e),r.dispatch(n,e)},this.dispatch=function(e,n){if(r.dispatchEvent){var t=o(e,n||null,{controller:r.controller});r.controller.element.dispatchEvent(t)}},this.handleVisibilityChange=function(e){document.hidden?r.dispatchInvisible(e):r.dispatchVisible(e)};var c=Object.assign(x,n);Object.assign(this,{dispatchEvent:c.dispatchEvent,eventPrefix:c.eventPrefix}),this.controller=e;var s=this.unobserve,l=e.disconnect.bind(e);Object.assign(e,{disconnect:function(){s(),l()}}),this.handleVisibilityChange(),this.observe()},L=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=L(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(n.Controller),I=function(e){var n=function(n){var i=window,o={height:i.innerHeight||Infinity,width:i.innerWidth||Infinity,event:n};e.windowResize&&t(e,"windowResize").call(e,o)},i=e.disconnect.bind(e),o=function(){window.addEventListener("resize",n),n()},r=function(){window.removeEventListener("resize",n)};return Object.assign(e,{disconnect:function(){r(),i()}}),o(),[o,r]},A=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=I(u(t)),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return l(n,e),n.prototype.windowResize=function(e){},n}(n.Controller),R=function(e,n){void 0===n&&(n=200);var t=null;return function(){var i=arguments,o=this,r=function(){return e.apply(o,i)};clearTimeout(t),t=setTimeout(r,n)}};function q(e,n){var t;return void 0===n&&(n=200),function(){var i=arguments,o=this;t||(t=!0,e.apply(o,i),setTimeout(function(){return t=!1},n))}}function T(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}function F(e){try{return JSON.parse(e)}catch(n){return e}}function S(e){return e.replace(/(?:[_-])([a-z0-9])/g,function(e,n){return n.toUpperCase()})}e.ApplicationController=j,e.ClickOutsideController=g,e.IdleController=V,e.IntersectionController=a,e.LazyLoadController=v,e.ResizeController=h,e.UseVisibility=z,e.VisibilityController=k,e.WindowResizeController=A,e.useApplication=O,e.useClickOutside=m,e.useDebounce=function(e,n){var t;null==(t=e.constructor.debounces)||t.forEach(function(t){if("string"==typeof t&&(e[t]=R(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=R(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useDispatch=E,e.useIdle=P,e.useIntersection=c,e.useLazyLoad=d,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?S(n)+"Meta":S(n);Object.defineProperty(e,i,{get:function(){return F(T(n))}})}(e,n,i)}),Object.defineProperty(e,"metas",{get:function(){var e={};return null==t||t.forEach(function(n){var t=F(T(n));null!=t&&(e[S(n)]=t)}),e}})},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]=q(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=q(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useVisibility=L,e.useWindowResize=I}); | ||
!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},o=function(e,n,t){var i=n||{bubbles:!0,cancelable:!0,composed:!0},o=i.bubbles,r=i.cancelable,c=i.composed;return n&&Object.assign(t,{originalEvent:n}),new CustomEvent(e,{bubbles:o,cancelable:r,composed:c,detail:t})},r={dispatchEvent:!0,eventPrefix:!0},c=function(e,n){var c;void 0===n&&(n={});var s=Object.assign({},r,n),l=s.dispatchEvent,u=s.eventPrefix,a=(null==(c=n)?void 0:c.element)||e.element,d=e.disconnect.bind(e),v=new IntersectionObserver(function(n){var r=n[0];r.isIntersecting?function(n){if(e.isVisible=!0,e.appear&&t(e,"appear").call(e,n),l){var r=i("appear",e,u),c=o(r,null,{controller:e,entry:n});a.dispatchEvent(c)}}(r):e.isVisible&&function(n){if(e.isVisible=!1,e.disappear&&t(e,"disappear").call(e,n),l){var r=i("disappear",e,u),c=o(r,null,{controller:e,entry:n});a.dispatchEvent(c)}}(r)},n),f=function(){v.observe(a)},b=function(){v.unobserve(a)};return Object.assign(e,{isVisible:!1,disconnect:function(){b(),d()}}),f(),[f,b]};function s(){return(s=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 u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var a=function(e){function n(n){var t;return(t=e.call(this,n)||this).isVisible=!1,requestAnimationFrame(function(){var e=c(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(n.Controller),d=function(e,n){var i=e.disconnect.bind(e),o=new IntersectionObserver(function(n){n[0].isIntersecting&&!e.isLoaded&&function(n){var i=e.data.get("src");if(i){var o=e.element;e.isLoading=!0,e.loading&&t(e,"loading").call(e,i),o.onload=function(){!function(n){e.isLoading=!1,e.isLoaded=!0,e.loading&&t(e,"loaded").call(e,n)}(i)},o.src=i}}()},n),r=function(){o.observe(e.element)},c=function(){o.unobserve(e.element)};return Object.assign(e,{isVisible:!1,disconnect:function(){c(),i()}}),r(),[r,c]},v=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=d(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}l(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 r;void 0===n&&(n={});var c=Object.assign({},f,n),s=c.dispatchEvent,l=c.eventPrefix,u=(null==(r=n)?void 0:r.element)||e.element,a=e.disconnect.bind(e),d=new ResizeObserver(function(n){var r=n[0];if(e.resize&&t(e,"resize").call(e,r.contentRect),s){var c=i("resize",e,l),a=o(c,null,{controller:e,entry:r});u.dispatchEvent(a)}}),v=function(){d.observe(u)},b=function(){d.unobserve(u)};return Object.assign(e,{disconnect:function(){b(),a()}}),v(),[v,b]},h=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=b(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return l(n,e),n.prototype.resize=function(e){},n}(n.Controller),p={events:["click","touchend"],onlyVisible:!0,dispatchEvent:!0,eventPrefix:!0},m=function(e,n){void 0===n&&(n={});var r=Object.assign({},p,n),c=r.onlyVisible,s=r.dispatchEvent,l=r.events,u=r.eventPrefix,a=function(r){var l,a,d=(null==(l=n)?void 0:l.element)||e.element;if(!d.contains(r.target)&&((a=d.getBoundingClientRect()).top>=0&&a.left>=0&&a.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&a.right<=(window.innerWidth||document.documentElement.clientWidth)||!c)&&(e.clickOutside&&t(e,"clickOutside").call(e,r),s)){var v=i("click:outside",e,u),f=o(v,r,{controller:e});d.dispatchEvent(f)}},d=function(){null==l||l.forEach(function(e){window.addEventListener(e,a,!1)})},v=function(){null==l||l.forEach(function(e){window.removeEventListener(e,a,!1)})},f=e.disconnect.bind(e);return Object.assign(e,{disconnect:function(){v(),f()}}),d(),[d,v]},g=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=m(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return l(n,e),n.prototype.clickOutside=function(e){},n}(n.Controller),y={debug:!1,logger:console},w=function(e){function n(n,t){var i;return(i=e.call(this,n,t)||this).targetElement=(null==t?void 0:t.element)||n.element,i.eventPrefix=(null==t?void 0:t.eventPrefix)||!0,i.bubbles=(null==t?void 0:t.bubbles)||!0,i.cancelable=(null==t?void 0:t.cancelable)||!0,i.enhanceController(),i}return l(n,e),n.prototype.enhanceController=function(){var e=this.controller,n=this.targetElement,t=this.eventPrefix,o=this.bubbles,r=this.cancelable,c=this.log;Object.assign(this.controller,{dispatch:function(s,l){void 0===l&&(l={}),Object.assign(l,{controller:e});var u=i(s,e,t),a=new CustomEvent(u,{detail:l,bubbles:o,cancelable:r});return n.dispatchEvent(a),c("useDispatch",{eventName:u,detail:l,bubbles:o,cancelable:r}),a}})},n}(function(e,n){var t=this;this.log=function(e,n){if(t.debug){var i=t.id?"id: "+t.id:"";t.logger.group(""+e),t.logger.log("called from controller: "+t.controller.identifier+" "+i,s({},n)),t.logger.groupEnd()}},this.debug=(null==n?void 0:n.debug)||e.application.stimulusUseDebug||y.debug,this.logger=(null==n?void 0:n.logger)||y.logger,this.controller=e,this.id=e.element.id,this.controllerInitialize=e.initialize.bind(e),this.controllerConnect=e.connect.bind(e),this.controllerDisconnect=e.disconnect.bind(e)}),E=function(e,n){return 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")}}),E(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(u(t),t.options),t}return l(n,e),n}(n.Controller),C={ms:6e4,initialState:!1,events:["mousemove","mousedown","resize","keydown","touchstart","wheel"],dispatchEvent:!0,eventPrefix:!0},P=function(e,n){void 0===n&&(n={});var r=Object.assign({},C,n),c=r.ms,s=r.events,l=r.dispatchEvent,u=r.eventPrefix,a=r.initialState,d=setTimeout(function(){a=!0,v()},c),v=function(n){var r=i("away",e,u);if(e.isIdle=!0,e.away&&t(e,"away").call(e,n),l){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},f=function(n){var r=i("back",e,u);if(e.isIdle=!1,e.back&&t(e,"back").call(e,n),l){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},b=function(e){a&&f(e),a=!1,clearTimeout(d),d=setTimeout(function(){a=!0,v(e)},c)},h=function(e){document.hidden||b(e)};a?v():f();var p=e.disconnect.bind(e),m=function(){s.forEach(function(e){window.addEventListener(e,b)}),document.addEventListener("visibilitychange",h)},g=function(){s.forEach(function(e){window.removeEventListener(e,b)}),document.removeEventListener("visibilitychange",h)};return Object.assign(e,{disconnect:function(){g(),p()}}),m(),[m,g]},V=function(e){function n(n){var t;return(t=e.call(this,n)||this).isIdle=!1,requestAnimationFrame(function(){var e=P(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}l(n,e);var t=n.prototype;return t.away=function(){},t.back=function(){},n}(n.Controller),x={dispatchEvent:!0,eventPrefix:!0},z=function(e,n){var r=this;void 0===n&&(n={}),this.observe=function(){r.controller.isVisible=!document.hidden,document.addEventListener("visibilitychange",r.handleVisibilityChange)},this.unobserve=function(){document.removeEventListener("visibilitychange",r.handleVisibilityChange)},this.dispatchInvisible=function(e){var n=i("invisible",r.controller,r.eventPrefix);r.controller.isVisible=!1,r.controller.invisible&&t(r.controller,"invisible").call(r.controller,e),r.dispatch(n,e)},this.dispatchVisible=function(e){var n=i("visible",r.controller,r.eventPrefix);r.controller.isVisible=!0,r.controller.visible&&t(r.controller,"visible").call(r.controller,e),r.dispatch(n,e)},this.dispatch=function(e,n){if(r.dispatchEvent){var t=o(e,n||null,{controller:r.controller});r.controller.element.dispatchEvent(t)}},this.handleVisibilityChange=function(e){document.hidden?r.dispatchInvisible(e):r.dispatchVisible(e)};var c=Object.assign({},x,n);Object.assign(this,{dispatchEvent:c.dispatchEvent,eventPrefix:c.eventPrefix}),this.controller=e;var s=this.unobserve,l=e.disconnect.bind(e);Object.assign(e,{disconnect:function(){s(),l()}}),this.handleVisibilityChange(),this.observe()},L=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=L(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(n.Controller),I=function(e){var n=function(n){var i=window,o={height:i.innerHeight||Infinity,width:i.innerWidth||Infinity,event:n};e.windowResize&&t(e,"windowResize").call(e,o)},i=e.disconnect.bind(e),o=function(){window.addEventListener("resize",n),n()},r=function(){window.removeEventListener("resize",n)};return Object.assign(e,{disconnect:function(){r(),i()}}),o(),[o,r]},A=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=I(u(t)),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return l(n,e),n.prototype.windowResize=function(e){},n}(n.Controller),R=function(e,n){void 0===n&&(n=200);var t=null;return function(){var i=arguments,o=this,r=function(){return e.apply(o,i)};clearTimeout(t),t=setTimeout(r,n)}};function q(e,n){var t;return void 0===n&&(n=200),function(){var i=arguments,o=this;t||(t=!0,e.apply(o,i),setTimeout(function(){return t=!1},n))}}function T(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}function F(e){try{return JSON.parse(e)}catch(n){return e}}function S(e){return e.replace(/(?:[_-])([a-z0-9])/g,function(e,n){return n.toUpperCase()})}e.ApplicationController=j,e.ClickOutsideController=g,e.IdleController=V,e.IntersectionController=a,e.LazyLoadController=v,e.ResizeController=h,e.UseVisibility=z,e.VisibilityController=k,e.WindowResizeController=A,e.useApplication=O,e.useClickOutside=m,e.useDebounce=function(e,n){var t;null==(t=e.constructor.debounces)||t.forEach(function(t){if("string"==typeof t&&(e[t]=R(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=R(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useDispatch=E,e.useIdle=P,e.useIntersection=c,e.useLazyLoad=d,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?S(n)+"Meta":S(n);Object.defineProperty(e,i,{get:function(){return F(T(n))}})}(e,n,i)}),Object.defineProperty(e,"metas",{get:function(){var e={};return null==t||t.forEach(function(n){var t=F(T(n));null!=t&&(e[S(n)]=t)}),e}})},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]=q(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=q(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useVisibility=L,e.useWindowResize=I}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -9,3 +9,3 @@ import { method, extendedEvent, isElementInViewport, composeEventName } from '../support/index'; | ||
export const useClickOutside = (controller, options = {}) => { | ||
const { onlyVisible, dispatchEvent, events, eventPrefix } = Object.assign(defaultOptions, options); | ||
const { onlyVisible, dispatchEvent, events, eventPrefix } = Object.assign({}, defaultOptions, options); | ||
const onEvent = (event) => { | ||
@@ -12,0 +12,0 @@ const targetElement = (options === null || options === void 0 ? void 0 : options.element) || controller.element; |
@@ -12,3 +12,3 @@ import { extendedEvent, method, composeEventName } from '../support/index'; | ||
export const useIdle = (controller, options = {}) => { | ||
const { ms, initialState, events, dispatchEvent, eventPrefix } = Object.assign(defaultOptions, options); | ||
const { ms, initialState, events, dispatchEvent, eventPrefix } = Object.assign({}, defaultOptions, options); | ||
let isIdle = initialState; | ||
@@ -15,0 +15,0 @@ let timeout = setTimeout(() => { |
@@ -7,3 +7,3 @@ import { method, extendedEvent, composeEventName } from '../support/index'; | ||
export const useIntersection = (controller, options = {}) => { | ||
const { dispatchEvent, eventPrefix } = Object.assign(defaultOptions, options); | ||
const { dispatchEvent, eventPrefix } = Object.assign({}, defaultOptions, options); | ||
const targetElement = (options === null || options === void 0 ? void 0 : options.element) || controller.element; | ||
@@ -10,0 +10,0 @@ const callback = (entries) => { |
@@ -7,3 +7,3 @@ import { method, extendedEvent, composeEventName } from '../support/index'; | ||
export const useResize = (controller, options = {}) => { | ||
const { dispatchEvent, eventPrefix } = Object.assign(defaultOptions, options); | ||
const { dispatchEvent, eventPrefix } = Object.assign({}, defaultOptions, options); | ||
const targetElement = (options === null || options === void 0 ? void 0 : options.element) || controller.element; | ||
@@ -10,0 +10,0 @@ const callback = (entries) => { |
@@ -42,3 +42,3 @@ import { extendedEvent, method, composeEventName } from '../support/index'; | ||
}; | ||
const { dispatchEvent, eventPrefix } = Object.assign(defaultOptions, options); | ||
const { dispatchEvent, eventPrefix } = Object.assign({}, defaultOptions, options); | ||
Object.assign(this, { dispatchEvent, eventPrefix }); | ||
@@ -45,0 +45,0 @@ this.controller = controller; |
{ | ||
"name": "stimulus-use", | ||
"version": "0.21.1", | ||
"version": "0.21.2", | ||
"description": "A collection of standard controllers and utilities for Stimulus", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.umd.js", |
@@ -150,2 +150,3 @@ <p align="center"> | ||
<td align="center"><a href="https://francisco.io/"><img src="https://avatars2.githubusercontent.com/u/2801252?v=4" width="80px;" alt=""/><br /><sub><b>Francisco Presencia</b></sub></a><br /><a href="https://github.com/stimulus-use/stimulus-use/commits?author=franciscop" title="Documentation">📖</a></td> | ||
<td align="center"><a href="https://github.com/tsmd"><img src="https://avatars3.githubusercontent.com/u/490085?v=4" width="80px;" alt=""/><br /><sub><b>Takayuki Shimada</b></sub></a><br /><a href="https://github.com/stimulus-use/stimulus-use/issues?q=author%3Atsmd" title="Bug reports">🐛</a></td> | ||
</tr> | ||
@@ -152,0 +153,0 @@ </table> |
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
156318
167