stimulus-use
Advanced tools
Comparing version 0.10.0 to 0.11.0
@@ -6,2 +6,3 @@ export { useIntersection, IntersectionController } from './use-intersection'; | ||
export { useApplication, ApplicationController } from './use-application'; | ||
export { useIdle, IdleController } from './use-idle'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,2 +6,3 @@ export { useIntersection, IntersectionController } from './use-intersection'; | ||
export { useApplication, ApplicationController } from './use-application'; | ||
export { useIdle, IdleController } from './use-idle'; | ||
//# sourceMappingURL=index.js.map |
@@ -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,s=i.composed;return n&&Object.assign(t,{originalEvent:n}),new CustomEvent(e,{bubbles:o,cancelable:r,composed:s,detail:t})},r={dispatchEvent:!0,eventPrefix:!0},s=function(e,n){var s;void 0===n&&(n={});var c=Object.assign(r,n),u=c.dispatchEvent,a=c.eventPrefix,l=(null==(s=n)?void 0:s.element)||e.element,v=e.disconnect;Object.assign(e,{isVisible:!1,observer:new IntersectionObserver(function(n){var r=n[0];r.isIntersecting?function(n){if(e.isVisible=!0,e.appear&&t(e,"appear").call(e,n),u){var r=i("appear",e,a),s=o(r,null,{controller:e,entry:n});l.dispatchEvent(s)}}(r):e.isVisible&&function(n){if(e.isVisible=!1,e.disappear&&t(e,"disappear").call(e,n),u){var r=i("disappear",e,a),s=o(r,null,{controller:e,entry:n});l.dispatchEvent(s)}}(r)},n),observe:function(){this.observer.observe(l)},unObserve:function(){this.observer.unobserve(l)},disconnect:function(){e.unObserve(),v()}}),e.observe()};function c(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,t.options={},requestAnimationFrame(function(){s(u(t),t.options)}),t}c(n,e);var t=n.prototype;return t.observe=function(){},t.unObserve=function(){},t.appear=function(e){},t.disappear=function(e){},n}(n.Controller),l=function(e,n){var i=e.disconnect;Object.assign(e,{isVisible:!1,observer: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),observe:function(){this.observer.observe(e.element)},unObserve:function(){this.observer.unobserve(e.element)},disconnect:function(){e.unObserve(),i()}}),e.observe()},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(){l(u(t),t.options)}),t}c(n,e);var t=n.prototype;return t.observe=function(){},t.unObserve=function(){},t.loading=function(e){},t.loaded=function(e){},n}(n.Controller),d={dispatchEvent:!0,eventPrefix:!0},f=function(e,n){var r;void 0===n&&(n={});var s=Object.assign(d,n),c=s.dispatchEvent,u=s.eventPrefix,a=(null==(r=n)?void 0:r.element)||e.element,l=e.disconnect;Object.assign(e,{observer:new ResizeObserver(function(n){var r=n[0];if(e.resize&&t(e,"resize").call(e,r.contentRect),c){var s=i("resize",e,u),l=o(s,null,{controller:e,entry:r});a.dispatchEvent(l)}}),observe:function(){this.observer.observe(a)},unObserve:function(){this.observer.unobserve(a)},disconnect:function(){e.unObserve(),l()}}),e.observe()},b=function(e){function n(n){var t;return(t=e.call(this,n)||this).options={},requestAnimationFrame(function(){f(u(t),t.options)}),t}c(n,e);var t=n.prototype;return t.observe=function(){},t.unObserve=function(){},t.resize=function(e){},n}(n.Controller),p={events:["click","touchend"],onlyVisible:!0,dispatchEvent:!0,eventPrefix:!0},h=function(e,n){void 0===n&&(n={});var r=Object.assign(p,n),s=r.onlyVisible,c=r.dispatchEvent,u=r.events,a=r.eventPrefix,l=function(r){var u,l,v=(null==(u=n)?void 0:u.element)||e.element;if(!v.contains(r.target)&&((l=v.getBoundingClientRect()).top>=0&&l.left>=0&&l.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&l.right<=(window.innerWidth||document.documentElement.clientWidth)||!s)&&(e.clickOutside&&t(e,"clickOutside").call(e,r),c)){var d=i("click:outside",e,a),f=o(d,r,{controller:e});v.dispatchEvent(f)}};null==u||u.forEach(function(e){window.addEventListener(e,l,!1)});var v=e.disconnect;Object.assign(e,{disconnect:function(){null==u||u.forEach(function(e){window.removeEventListener(e,l,!1)}),v()}})},m=function(e){function n(n){var t;return(t=e.call(this,n)||this).options={},requestAnimationFrame(function(){h(u(t),t.options)}),t}return c(n,e),n.prototype.clickOutside=function(e){},n}(n.Controller),g=function(e){Object.defineProperty(e,"isPreview",{get:function(){return document.documentElement.hasAttribute("data-turbolinks-preview")}}),Object.defineProperty(e,"csrfToken",{get:function(){return this.metaValue("csrf-token")}}),Object.assign(e,{dispatch:function(n,t){var i=void 0===t?{}:t,o=i.target,r=void 0===o?e.element:o,s=i.detail,c=void 0===s?{}:s,u=i.bubbles,a=void 0===u||u,l=i.cancelable,v=void 0===l||l;Object.assign(c,{controller:e});var d=new CustomEvent(e.identifier+":"+n,{detail:c,bubbles:a,cancelable:v});return r.dispatchEvent(d),d},metaValue:function(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}})};e.ApplicationController=function(e){function n(n){var t;return(t=e.call(this,n)||this).isPreview=!1,t.csrfToken="",g(u(t)),t}c(n,e);var t=n.prototype;return t.dispatch=function(e,n){},t.metaValue=function(e){return""},n}(n.Controller),e.ClickOutsideController=m,e.IntersectionController=a,e.LazyLoadController=v,e.ResizeController=b,e.useApplication=g,e.useClickOutside=h,e.useIntersection=s,e.useLazyLoad=l,e.useResize=f}); | ||
!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,s=i.composed;return n&&Object.assign(t,{originalEvent:n}),new CustomEvent(e,{bubbles:o,cancelable:r,composed:s,detail:t})},r={dispatchEvent:!0,eventPrefix:!0},s=function(e,n){var s;void 0===n&&(n={});var c=Object.assign(r,n),u=c.dispatchEvent,a=c.eventPrefix,l=(null==(s=n)?void 0:s.element)||e.element,v=e.disconnect;Object.assign(e,{isVisible:!1,observer:new IntersectionObserver(function(n){var r=n[0];r.isIntersecting?function(n){if(e.isVisible=!0,e.appear&&t(e,"appear").call(e,n),u){var r=i("appear",e,a),s=o(r,null,{controller:e,entry:n});l.dispatchEvent(s)}}(r):e.isVisible&&function(n){if(e.isVisible=!1,e.disappear&&t(e,"disappear").call(e,n),u){var r=i("disappear",e,a),s=o(r,null,{controller:e,entry:n});l.dispatchEvent(s)}}(r)},n),observe:function(){this.observer.observe(l)},unObserve:function(){this.observer.unobserve(l)},disconnect:function(){e.unObserve(),v()}}),e.observe()};function c(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,t.options={},requestAnimationFrame(function(){s(u(t),t.options)}),t}c(n,e);var t=n.prototype;return t.observe=function(){},t.unObserve=function(){},t.appear=function(e){},t.disappear=function(e){},n}(n.Controller),l=function(e,n){var i=e.disconnect;Object.assign(e,{isVisible:!1,observer: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),observe:function(){this.observer.observe(e.element)},unObserve:function(){this.observer.unobserve(e.element)},disconnect:function(){e.unObserve(),i()}}),e.observe()},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(){l(u(t),t.options)}),t}c(n,e);var t=n.prototype;return t.observe=function(){},t.unObserve=function(){},t.loading=function(e){},t.loaded=function(e){},n}(n.Controller),d={dispatchEvent:!0,eventPrefix:!0},f=function(e,n){var r;void 0===n&&(n={});var s=Object.assign(d,n),c=s.dispatchEvent,u=s.eventPrefix,a=(null==(r=n)?void 0:r.element)||e.element,l=e.disconnect;Object.assign(e,{observer:new ResizeObserver(function(n){var r=n[0];if(e.resize&&t(e,"resize").call(e,r.contentRect),c){var s=i("resize",e,u),l=o(s,null,{controller:e,entry:r});a.dispatchEvent(l)}}),observe:function(){this.observer.observe(a)},unObserve:function(){this.observer.unobserve(a)},disconnect:function(){e.unObserve(),l()}}),e.observe()},b=function(e){function n(n){var t;return(t=e.call(this,n)||this).options={},requestAnimationFrame(function(){f(u(t),t.options)}),t}c(n,e);var t=n.prototype;return t.observe=function(){},t.unObserve=function(){},t.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),s=r.onlyVisible,c=r.dispatchEvent,u=r.events,a=r.eventPrefix,l=function(r){var u,l,v=(null==(u=n)?void 0:u.element)||e.element;if(!v.contains(r.target)&&((l=v.getBoundingClientRect()).top>=0&&l.left>=0&&l.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&l.right<=(window.innerWidth||document.documentElement.clientWidth)||!s)&&(e.clickOutside&&t(e,"clickOutside").call(e,r),c)){var d=i("click:outside",e,a),f=o(d,r,{controller:e});v.dispatchEvent(f)}};null==u||u.forEach(function(e){window.addEventListener(e,l,!1)});var v=e.disconnect;Object.assign(e,{disconnect:function(){null==u||u.forEach(function(e){window.removeEventListener(e,l,!1)}),v()}})},h=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){m(u(t),t.options)}),t}return c(n,e),n.prototype.clickOutside=function(e){},n}(n.Controller),g=function(e){Object.defineProperty(e,"isPreview",{get:function(){return document.documentElement.hasAttribute("data-turbolinks-preview")}}),Object.defineProperty(e,"csrfToken",{get:function(){return this.metaValue("csrf-token")}}),Object.assign(e,{dispatch:function(n,t){var i=void 0===t?{}:t,o=i.target,r=void 0===o?e.element:o,s=i.detail,c=void 0===s?{}:s,u=i.bubbles,a=void 0===u||u,l=i.cancelable,v=void 0===l||l;Object.assign(c,{controller:e});var d=new CustomEvent(e.identifier+":"+n,{detail:c,bubbles:a,cancelable:v});return r.dispatchEvent(d),d},metaValue:function(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}})},O=function(e){function n(n){var t;return(t=e.call(this,n)||this).isPreview=!1,t.csrfToken="",g(u(t)),t}c(n,e);var t=n.prototype;return t.dispatch=function(e,n){},t.metaValue=function(e){return""},n}(n.Controller),E={ms:6e4,initialState:!1,events:["mousemove","mousedown","resize","keydown","touchstart","wheel"],dispatchEvent:!0,eventPrefix:!0},w=function(e,n){void 0===n&&(n={});var r=Object.assign(E,n),s=r.ms,c=r.events,u=r.dispatchEvent,a=r.eventPrefix,l=r.initialState,v=setTimeout(function(){l=!0,d()},s),d=function(n){var r=i("away",e,a);if(e.isIdle=!0,e.away&&t(e,"away").call(e,n),u){var s=o(r,n||null,{controller:e});e.element.dispatchEvent(s)}},f=function(n){var r=i("back",e,a);if(e.isIdle=!1,e.back&&t(e,"back").call(e,n),u){var s=o(r,n||null,{controller:e});e.element.dispatchEvent(s)}},b=function(e){l&&f(e),l=!1,clearTimeout(v),v=setTimeout(function(){l=!0,d(e)},s)},p=function(e){document.hidden||b(e)};l?d():f();var m=e.disconnect;Object.assign(e,{observe:function(){c.forEach(function(e){window.addEventListener(e,b)}),document.addEventListener("visibilitychange",p)},unObserve:function(){c.forEach(function(e){window.removeEventListener(e,b)}),document.removeEventListener("visibilitychange",p)},disconnect:function(){this.unObserve(),m()}}),e.observe()},y=function(e){function n(n){var t;return(t=e.call(this,n)||this).isIdle=!1,requestAnimationFrame(function(){w(u(t))}),t}c(n,e);var t=n.prototype;return t.observe=function(){},t.unObserve=function(){},t.away=function(){},t.back=function(){},n}(n.Controller);e.ApplicationController=O,e.ClickOutsideController=h,e.IdleController=y,e.IntersectionController=a,e.LazyLoadController=v,e.ResizeController=b,e.useApplication=g,e.useClickOutside=m,e.useIdle=w,e.useIntersection=s,e.useLazyLoad=l,e.useResize=f}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -20,3 +20,2 @@ var __extends = (this && this.__extends) || (function () { | ||
var _this = _super.call(this, context) || this; | ||
_this.options = {}; | ||
requestAnimationFrame(function () { | ||
@@ -23,0 +22,0 @@ useClickOutside(_this, _this.options); |
@@ -1,2 +0,5 @@ | ||
import { ClickOutsideController } from './click-outside-controller'; | ||
import { Controller } from 'stimulus'; | ||
interface ClickOutsideController extends Controller { | ||
clickOutside?: (event: Event) => void; | ||
} | ||
export interface ClickOutsideOptions { | ||
@@ -10,2 +13,3 @@ element?: Element; | ||
export declare const useClickOutside: (controller: ClickOutsideController, options?: ClickOutsideOptions) => void; | ||
export {}; | ||
//# sourceMappingURL=use-click-outside.d.ts.map |
{ | ||
"name": "stimulus-use", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "A collection of standard controllers and utilities for Stimulus", | ||
@@ -19,3 +19,3 @@ "main": "dist/index.umd.js", | ||
"dev": "tsc -b -w", | ||
"clean": "rimraf dist *.tsbuildinfo", | ||
"clean": "rimraf dist *.tsbuildinfo coverage", | ||
"doc": "docsify serve ./docs", | ||
@@ -25,6 +25,6 @@ "release": "np" | ||
"devDependencies": { | ||
"@babel/core": "^7.3.4", | ||
"@babel/plugin-proposal-class-properties": "^7.8.3", | ||
"@babel/plugin-transform-runtime": "^7.10.3", | ||
"@babel/preset-env": "^7.9.6", | ||
"@babel/core": "^7.11.1", | ||
"@babel/plugin-proposal-class-properties": "^7.10.4", | ||
"@babel/plugin-transform-runtime": "^7.11.0", | ||
"@babel/preset-env": "^7.11.0", | ||
"@babel/preset-modules": "^0.1.3", | ||
@@ -35,6 +35,6 @@ "babel-loader": "^8.1.0", | ||
"html2js": "^0.2.0", | ||
"karma": "^5.0.9", | ||
"karma": "^5.1.1", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-coverage": "^2.0.2", | ||
"karma-coverage": "^2.0.3", | ||
"karma-fixture": "^0.2.6", | ||
@@ -46,18 +46,18 @@ "karma-html2js-preprocessor": "^1.1.0", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
"karma-typescript": "^5.0.3", | ||
"karma-typescript": "^5.1.0", | ||
"karma-webpack": "^4.0.2", | ||
"kind-of": "^6.0.3", | ||
"microbundle": "^0.12.2", | ||
"mocha": "^7.2.0", | ||
"np": "^6.2.3", | ||
"microbundle": "^0.12.3", | ||
"mocha": "^8.1.1", | ||
"np": "^6.4.0", | ||
"rimraf": "^3.0.2", | ||
"sinon": "^9.0.2", | ||
"sinon": "^9.0.3", | ||
"sinon-chai": "^3.5.0", | ||
"sourcemap": "^0.1.0", | ||
"stimulus": "^1.1.1", | ||
"ts-loader": "^7.0.5", | ||
"typescript": "^3.9.3", | ||
"webpack": "^4.43.0", | ||
"webpack-cli": "^3.3.11", | ||
"webpack-dev-server": "^3.2.1" | ||
"ts-loader": "^8.0.2", | ||
"typescript": "^3.9.7", | ||
"webpack": "^4.44.1", | ||
"webpack-cli": "^3.3.12", | ||
"webpack-dev-server": "^3.11.0" | ||
}, | ||
@@ -64,0 +64,0 @@ "repository": { |
@@ -19,2 +19,8 @@ <p align="center"> | ||
<p align="center"> | ||
<img src="./docs/assets/stimulus-use example.png" alt="Stimulus Use Example"> | ||
</p> | ||
<br /> | ||
- **New lifecycle behaviors**: adds new standard behaviors to your Stimulus controllers. | ||
@@ -54,2 +60,6 @@ - **Composable**: compose at will different behaviors in a single controller. | ||
- **Idle** | ||
- [`useIdle, IdleController`](./docs/use-idle.md) — Tracks if the user is idle on your page and adds **away** and **back** callbacks to your controller. | ||
## Extend or compose | ||
@@ -137,3 +147,3 @@ | ||
<td align="center"><a href="https://github.com/juancarlosasensio"><img src="https://avatars3.githubusercontent.com/u/37816105?v=4" width="100px;" alt=""/><br /><sub><b>juancarlosasensio</b></sub></a><br /><a href="https://github.com/stimulus-use/stimulus-use/commits?author=juancarlosasensio" title="Documentation">📖</a></td> | ||
<td align="center"><a href="https://marcoroth.dev"><img src="https://avatars2.githubusercontent.com/u/6411752?v=4" width="100px;" alt=""/><br /><sub><b>Marco Roth</b></sub></a><br /><a href="#infra-marcoroth" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td> | ||
<td align="center"><a href="https://marcoroth.dev"><img src="https://avatars2.githubusercontent.com/u/6411752?v=4" width="100px;" alt=""/><br /><sub><b>Marco Roth</b></sub></a><br /><a href="#infra-marcoroth" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/stimulus-use/stimulus-use/commits?author=marcoroth" title="Code">💻</a></td> | ||
<td align="center"><a href="http://philippdaun.net"><img src="https://avatars3.githubusercontent.com/u/22225348?v=4" width="100px;" alt=""/><br /><sub><b>Philipp Daun</b></sub></a><br /><a href="https://github.com/stimulus-use/stimulus-use/issues?q=author%3Adaun" title="Bug reports">🐛</a></td> | ||
@@ -140,0 +150,0 @@ </tr> |
@@ -6,1 +6,2 @@ export { useIntersection, IntersectionController } from './use-intersection' | ||
export { useApplication, ApplicationController } from './use-application' | ||
export { useIdle, IdleController } from './use-idle' |
@@ -6,3 +6,3 @@ import { Controller, Context } from 'stimulus' | ||
observer!: ResizeObserver | ||
options: ClickOutsideOptions = {} | ||
options!: ClickOutsideOptions | ||
@@ -9,0 +9,0 @@ constructor(context: Context) { |
@@ -1,4 +0,8 @@ | ||
import { ClickOutsideController } from './click-outside-controller' | ||
import { Controller } from 'stimulus' | ||
import { method, extendedEvent, isElementInViewport, composeEventName } from '../support' | ||
interface ClickOutsideController extends Controller { | ||
clickOutside?: (event: Event) => void | ||
} | ||
export interface ClickOutsideOptions { | ||
@@ -5,0 +9,0 @@ element?: Element |
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
120762
107
1386
155