vue-click 2.1.6 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -4
- package/dist/index.js +1 -1
- package/package.json +21 -20
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Vue Click
|
|
2
|
-

|
|
3
3
|
|
|
4
4
|
Vue 3 plugin for advanced click directive.
|
|
5
5
|
|
|
6
|
-
### [🖱️ Demo Page](https://
|
|
6
|
+
### [🖱️ Demo Page](https://nerdoza.github.io/vue-click/)
|
|
7
7
|
|
|
8
8
|
# Installation
|
|
9
9
|
|
|
@@ -58,18 +58,22 @@ Further modify the behavior of the button by adding modifiers:
|
|
|
58
58
|
|
|
59
59
|
Only one behavior and one modifier can be used in a single directive declaration, but multiple directives can be placed on the same element.
|
|
60
60
|
|
|
61
|
+
The bound function can change after the element mounts (ex: `v-click="ready ? openModal : undefined"`), and each directive removes its listeners and cancels its pending timers when its element unmounts.
|
|
62
|
+
|
|
61
63
|
## Behaviors
|
|
62
64
|
|
|
63
65
|
One behavior may be used in a declaration and defines the trigger for the event.
|
|
64
66
|
|
|
65
67
|
### Single Click Behavior _(Default)_
|
|
66
68
|
|
|
67
|
-
The `v-click` event will be fired immediately on a click event similar to `v-on:click`.
|
|
69
|
+
The `v-click` event will be fired immediately on a click event similar to `v-on:click`: a press that is released on the element within `300ms`.
|
|
68
70
|
|
|
69
71
|
```html
|
|
70
72
|
<button v-click="openModal">
|
|
71
73
|
```
|
|
72
74
|
|
|
75
|
+
Keyboard and assistive-technology activation fires it too, once and through the same modifier: <kbd>Enter</kbd> or <kbd>Space</kbd> on a focused `<button>`, or a screen reader's activate command, produce a `click` event with no pointer press before it.
|
|
76
|
+
|
|
73
77
|
### Double Click Behavior
|
|
74
78
|
|
|
75
79
|
The `v-click` event can be bound to fire only on a double click. The event is fired only after 2 clicks within a time period.
|
|
@@ -84,6 +88,8 @@ The default time period is `300ms`, but this can be modify by append the preferr
|
|
|
84
88
|
<button v-click.double.1s="openModal">
|
|
85
89
|
```
|
|
86
90
|
|
|
91
|
+
Double click is a pointer gesture: keyboard and assistive-technology activation doesn't trigger it, so keep its action reachable another way.
|
|
92
|
+
|
|
87
93
|
### Hold Behavior
|
|
88
94
|
|
|
89
95
|
The `v-click` event can be bound to fire after a specified amount of time that the button is held down.
|
|
@@ -98,6 +104,8 @@ The default time period is `300ms`, but this can be modify by append the preferr
|
|
|
98
104
|
<button v-click.hold.1s="openModal">
|
|
99
105
|
```
|
|
100
106
|
|
|
107
|
+
Like double click, hold is a pointer gesture that keyboard and assistive-technology activation doesn't trigger.
|
|
108
|
+
|
|
101
109
|
### Press Behavior
|
|
102
110
|
|
|
103
111
|
The `v-click` event will be fired immediately on the `down` event, regardless of if the `up` event has occurred. This binding can be combined with the `release` behavior for advanced bindings or for scenarios where event latency is very important.
|
|
@@ -114,6 +122,15 @@ The `v-click` event will be fired immediately on the `up` event, which will alwa
|
|
|
114
122
|
<button v-click.release="openModal">
|
|
115
123
|
```
|
|
116
124
|
|
|
125
|
+
## Pointer Input
|
|
126
|
+
|
|
127
|
+
The behaviors listen to touch and mouse events directly, with a few rules that keep stray input from firing them:
|
|
128
|
+
|
|
129
|
+
- **Primary button only:** only the primary mouse button (usually the left) counts; right and middle clicks never fire a behavior or set the active state.
|
|
130
|
+
- **Movement tolerance:** a single, double or hold press is cancelled once the pointer moves more than `10px` from where it went down, so a swipe or drag is not a click and a hold doesn't fire after the finger slides away.
|
|
131
|
+
- **Cancel and release outside:** a press ends when the pointer is released anywhere, on the element or off it, when the browser cancels the touch (`touchcancel`), or when a second finger touches the element. Only a release on the element can complete a click, and every way a press ends clears its pending hold and the `data-vc-state-active` attribute.
|
|
132
|
+
- **Trusted input only:** events dispatched by scripts (ex: `element.click()` or `dispatchEvent()`) are ignored.
|
|
133
|
+
|
|
117
134
|
## Modifiers
|
|
118
135
|
|
|
119
136
|
One modifier may be used in a declaration and changes the behavior of the event trigger to reduce unintended event firing.
|
|
@@ -192,7 +209,7 @@ For the above example, the `buttonPress` function will be called with the string
|
|
|
192
209
|
|
|
193
210
|
## Styling
|
|
194
211
|
|
|
195
|
-
The addition of `TouchEvent` support has resulted in the breaking of normal event propagation which means pseudo selectors like `:active` and `:focus` will no longer active on events. Instead, the `data-vc-state-active` data attribute will be applied during the target elements active state. This works better across both mobile and desktop environments than the `:active` state as it's cleared when the user's finger is removed (where `:active` persists until focus is changed). There is also a `data-vc-state-
|
|
212
|
+
The addition of `TouchEvent` support has resulted in the breaking of normal event propagation which means pseudo selectors like `:active` and `:focus` will no longer active on events. Instead, the `data-vc-state-active` data attribute will be applied during the target elements active state. This works better across both mobile and desktop environments than the `:active` state as it's cleared when the user's finger is removed (where `:active` persists until focus is changed). It's also cleared when the press is cancelled: released off the element, moved past the [movement tolerance](#pointer-input) or interrupted by `touchcancel` or a second finger. There is also a `data-vc-state-deactivated` data attribute which is applied when the binding is removed from an element (ex: `once` modifier).
|
|
196
213
|
|
|
197
214
|
This plugin also provides data attributes for the behavior to allow advanced styling based on the desired user experience.
|
|
198
215
|
|
|
@@ -242,6 +259,12 @@ button[data-vc-bind-press] {
|
|
|
242
259
|
|
|
243
260
|
**Note:** When the `once` modifier is applied, the data-set binding will be removed once the event listener is removed (after the event is fired).
|
|
244
261
|
|
|
262
|
+
# Development
|
|
263
|
+
|
|
264
|
+
`npm run dev` serves the demo page. `npm test` runs the Playwright suite in `tests/`, which drives a test page with real mouse, keyboard and touch input in Chromium; install the browser once with `npx playwright install chromium`.
|
|
265
|
+
|
|
266
|
+
To release, bump `version` in `package.json` and merge to `main`. The Publish workflow publishes any version npm doesn't have yet through npm trusted publishing (no npm token is stored; provenance is attached automatically), then deploys the demo and creates the GitHub release. If a publish fails, re-run the workflow, or run it by hand from the Actions tab.
|
|
267
|
+
|
|
245
268
|
---
|
|
246
269
|
|
|
247
270
|
## Copyright and License
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e
|
|
1
|
+
!function(n,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.VueClick=e():n.VueClick=e()}(self,(()=>(()=>{"use strict";var n={d:(e,t)=>{for(var u in t)n.o(t,u)&&!n.o(e,u)&&Object.defineProperty(e,u,{enumerable:!0,get:t[u]})},o:(n,e)=>Object.prototype.hasOwnProperty.call(n,e),r:n=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})}},e={};n.r(e),n.d(e,{ClickDirective:()=>O,default:()=>D});var t,u,r=/^(\d+)?(m|s|ms)?$/i,o=function(n){var e;void 0===n&&(n="");var t=r.exec(n);if(null!==t&&t.length>=3){var u=parseFloat(t[1]);switch((null!==(e=t[2])&&void 0!==e?e:"ms").toLowerCase()){case"m":return 6e4*u;case"s":return 1e3*u;case"ms":return u}}return null};!function(n){n.Single="single",n.Double="double",n.Hold="hold",n.Press="press",n.Release="release"}(t||(t={})),function(n){n.Once="once",n.Throttle="throttle",n.Debounce="debounce"}(u||(u={}));var i,c,l=function(n,e){return Object.keys(n).filter((function(t){return Object(n)[t]===e})).length>0},a=function(n){var e,i={behavior:t.Single,modifier:null,time:null,argument:null,once:!1,dispatch:function(){}};for(var c in n.modifiers){var a=c.split(":");void 0!==a[1]&&(i.argument=a[1]),void 0===(e=a[0])&&(e=""),r.test(e)?i.time=o(a[0]):l(t,a[0])?i.behavior=a[0]:l(u,a[0])&&(i.modifier=a[0])}return void 0!==n.arg&&(i.argument=n.arg),"function"==typeof n.value&&(i.dispatch=function(){return n.value(i.argument)}),i},f=300,d="vcBind",s=((i={})[t.Single]="Click",i[t.Double]="Double",i[t.Hold]="Hold",i[t.Press]="Press",i[t.Release]="Release",i),v={capture:!0,passive:!1},p={capture:!0,passive:!0},h=function(n,e,t,u){return void 0===u&&(u=v),e.forEach((function(e){return n.addEventListener(e,t,u)})),function(){return e.forEach((function(e){return n.removeEventListener(e,t,u)}))}},m=function(){var n=null,e=function(){null!==n&&(clearTimeout(n),n=null)};return{pending:function(){return null!==n},start:function(t,u){e(),n=window.setTimeout((function(){n=null,null==u||u()}),t)},clear:e}},b=function(n,e,t,u){void 0===u&&(u=!0);var r=null,o=function(){},i=0,c=function(n){return!!n.isTrusted&&(u&&n.cancelable&&n.preventDefault(),i=Date.now(),!0)},l=function(n,t,u){r={x:n,y:t,touchId:u},e()},a=function(n){null!==r&&(r=null,o(),o=function(){},t(n))},f=function(n,e){if(null===r)return!1;var t=n-r.x,u=e-r.y;return t*t+u*u>100},d=function(){return"number"==typeof(null==r?void 0:r.touchId)},s=function(n){for(var e=0;e<n.length;e++)if(null!==r&&n[e].identifier===r.touchId)return n[e];return null},v=function(e){e.isTrusted&&("mouseup"===e.type?0===e.button&&a(e.composedPath().includes(n)):(0==(1&e.buttons)||f(e.clientX,e.clientY))&&a(!1))},m=[h(n,["touchstart"],(function(e){if(c(e)){!d()||null!==s(e.touches)&&null===s(e.changedTouches)||a(!1);for(var t=0,u=0;u<e.touches.length;u++)n.contains(e.touches[u].target)&&t++;if(null!==r||t>1)a(!1);else{var o=e.changedTouches[0];l(o.clientX,o.clientY,o.identifier)}}})),h(n,["touchmove"],(function(n){var e=n.isTrusted?s(n.changedTouches):null;null!==e&&f(e.clientX,e.clientY)&&a(!1)}),p),h(n,["touchend","touchcancel"],(function(n){c(n)&&null!==s(n.changedTouches)&&a("touchend"===n.type)})),h(n,["mousedown"],(function(n){if(c(n)&&0===n.button){var e=d();a(!1),e||(o=h(window,["mousemove","mouseup"],v,p),l(n.clientX,n.clientY,null))}})),h(n,["mouseup"],c)];return{recentlyPressed:function(){return null!==r||Date.now()-i<600},teardown:function(){m.forEach((function(n){return n()})),a(!1)}}},g=function(n){return function(e,t,u){return h(e,n,(function(n){n.isTrusted&&(n.cancelable&&n.preventDefault(),function(n){return!("button"in n)||0===n.button}(n)&&u())}))}},w=((c={})[t.Single]=function(n,e,t){var u=m(),r=b(n,(function(){return u.start(f)}),(function(n){var e=u.pending();u.clear(),n&&e&&t()})),o=h(n,["click"],(function(n){n.isTrusted&&!r.recentlyPressed()&&t()}));return function(){r.teardown(),u.clear(),o()}},c[t.Double]=function(n,e,t){var u,r=null!==(u=e.time)&&void 0!==u?u:f,o=m(),i=0,c=function(){o.clear(),i=0},l=b(n,(function(){return o.start(f,c)}),(function(n){n&&o.pending()?0===i?(i++,o.start(r,c)):(c(),t()):c()}));return function(){l.teardown(),c()}},c[t.Hold]=function(n,e,t){var u=m(),r=b(n,(function(){var n;return u.start(null!==(n=e.time)&&void 0!==n?n:f,t)}),(function(){return u.clear()}));return function(){r.teardown(),u.clear()}},c[t.Press]=g(["touchstart","mousedown"]),c[t.Release]=g(["touchend","mouseup"]),c),y=new WeakMap,T=function(n,e){var t,u;return null!==(u=null===(t=e.dirs)||void 0===t?void 0:t.indexOf(n))&&void 0!==u?u:-1},O={mounted:function(n,e,t){var r,o,i=a(e),c=function(n){switch(n.modifier){case u.Once:return function(n){return{fire:function(e){e(),n.dispatch()},teardown:function(){}}}(n);case u.Throttle:return function(n){var e,t=null!==(e=n.time)&&void 0!==e?e:f,u=m();return{fire:function(){u.pending()||n.dispatch(),u.start(t)},teardown:u.clear}}(n);case u.Debounce:return function(n){var e,t=null!==(e=n.time)&&void 0!==e?e:f,u=m();return{fire:function(){return u.start(t,(function(){return n.dispatch()}))},teardown:u.clear}}(n);default:return{fire:function(){return n.dispatch()},teardown:function(){}}}}(i),l=d+s[i.behavior],v=function(n){if(Object.values(s).some((function(e){return void 0!==n.dataset[d+e]})))return function(){};var e="vcStateActive",t=b(n,(function(){n.dataset[e]=""}),(function(){delete n.dataset[e]}),!1);return function(e){t.teardown(),e&&(n.dataset.vcStateDeactivated="")}}(n),p=function(){h(),v(!0),delete n.dataset[l]},h=w[i.behavior](n,i,(function(){!0!==n.disabled&&c.fire(p)}));n.dataset[l]=null!==(r=i.modifier)&&void 0!==r?r:"";var g=null!==(o=y.get(n))&&void 0!==o?o:new Map;g.set(T(e,t),{bindingOptions:i,teardown:function(){h(),c.teardown(),v(!1)}}),y.set(n,g)},updated:function(n,e,t){var u,r=null===(u=y.get(n))||void 0===u?void 0:u.get(T(e,t));void 0!==r&&(r.bindingOptions.dispatch=a(e).dispatch)},beforeUnmount:function(n,e,t){var u,r=y.get(n),o=T(e,t);null===(u=null==r?void 0:r.get(o))||void 0===u||u.teardown(),null==r||r.delete(o)}};const D={install:function(n){n.directive("click",O)}};return e})()));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-click",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Vue plugin for advanced click directive.",
|
|
6
6
|
"author": "Zachary Cardoza",
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
17
|
"bugs": {
|
|
18
|
-
"url": "https://github.com/
|
|
18
|
+
"url": "https://github.com/nerdoza/vue-click/issues"
|
|
19
19
|
},
|
|
20
|
-
"homepage": "https://github.com/
|
|
20
|
+
"homepage": "https://github.com/nerdoza/vue-click#readme",
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
|
-
"url": "https://github.com/
|
|
23
|
+
"url": "https://github.com/nerdoza/vue-click.git"
|
|
24
24
|
},
|
|
25
25
|
"main": "dist/index.js",
|
|
26
26
|
"types": "dist/index.d.ts",
|
|
@@ -33,27 +33,28 @@
|
|
|
33
33
|
"lint": "eslint .",
|
|
34
34
|
"dev": "webpack serve --config webpack/dev.config.js",
|
|
35
35
|
"start": "npm run dev",
|
|
36
|
-
"demo": "webpack --config webpack/demo.config.js"
|
|
36
|
+
"demo": "webpack --config webpack/demo.config.js",
|
|
37
|
+
"test": "playwright test"
|
|
37
38
|
},
|
|
38
|
-
"dependencies": {},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@typescript-eslint/
|
|
40
|
+
"@playwright/test": "^1.65.1",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^5.43.0",
|
|
42
|
+
"@typescript-eslint/parser": "^5.43.0",
|
|
42
43
|
"clean-webpack-plugin": "^3.0.0",
|
|
43
44
|
"copy-webpack-plugin": "^8.0.0",
|
|
44
45
|
"dts-bundle": "^0.7.3",
|
|
45
|
-
"eslint": "^
|
|
46
|
-
"eslint-config-standard-with-typescript": "^
|
|
47
|
-
"eslint-plugin-import": "^2.
|
|
46
|
+
"eslint": "^8.28.0",
|
|
47
|
+
"eslint-config-standard-with-typescript": "^23.0.0",
|
|
48
|
+
"eslint-plugin-import": "^2.26.0",
|
|
48
49
|
"eslint-plugin-node": "^11.1.0",
|
|
49
|
-
"eslint-plugin-promise": "^
|
|
50
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
50
51
|
"eslint-plugin-standard": "^5.0.0",
|
|
51
|
-
"html-webpack-plugin": "^5.
|
|
52
|
-
"ts-loader": "^
|
|
53
|
-
"typescript": "^4.
|
|
54
|
-
"vue": "^3.
|
|
55
|
-
"webpack": "^5.
|
|
56
|
-
"webpack-cli": "^
|
|
57
|
-
"webpack-dev-server": "^
|
|
52
|
+
"html-webpack-plugin": "^5.5.0",
|
|
53
|
+
"ts-loader": "^9.4.1",
|
|
54
|
+
"typescript": "^4.9.3",
|
|
55
|
+
"vue": "^3.2.45",
|
|
56
|
+
"webpack": "^5.75.0",
|
|
57
|
+
"webpack-cli": "^5.0.0",
|
|
58
|
+
"webpack-dev-server": "^4.11.1"
|
|
58
59
|
}
|
|
59
|
-
}
|
|
60
|
+
}
|