easy-gestures 2.0.5
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/.swcrc +11 -0
- package/README.md +133 -0
- package/bin/main.js +15 -0
- package/example.js +34433 -0
- package/index.html +52 -0
- package/lib/constants.js +42 -0
- package/lib/customEventTypes.js +74 -0
- package/lib/example/preamble.js +10 -0
- package/lib/example/view.js +233 -0
- package/lib/example.js +19 -0
- package/lib/index.js +18 -0
- package/lib/mixins/touch.js +477 -0
- package/lib/position/relative.js +97 -0
- package/lib/position.js +101 -0
- package/lib/preamble.js +10 -0
- package/lib/selectors.js +26 -0
- package/lib/utilities/positions.js +143 -0
- package/license.txt +48 -0
- package/package.json +38 -0
- package/src/constants.js +10 -0
- package/src/customEventTypes.js +17 -0
- package/src/example/preamble.js +7 -0
- package/src/example/view.js +85 -0
- package/src/example.js +22 -0
- package/src/index.js +3 -0
- package/src/mixins/touch.js +754 -0
- package/src/position/relative.js +63 -0
- package/src/position.js +74 -0
- package/src/preamble.js +7 -0
- package/src/selectors.js +5 -0
- package/src/utilities/positions.js +127 -0
package/.swcrc
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Easy Gestures
|
|
2
|
+
|
|
3
|
+
Touch gestures for web applications.
|
|
4
|
+
|
|
5
|
+
Single tap, double tap, drag, pinch and swipe gestures are all supported.
|
|
6
|
+
|
|
7
|
+
### JSX support
|
|
8
|
+
|
|
9
|
+
There is now support for JSX in the form of [Juxtapose](https://github.com/djalbat/Juxtapose). What this means is that Easy *will* now help you with the architecture of your large application. So although Easy elements will continue to work standalone, their use with Juxtapose is recommended.
|
|
10
|
+
|
|
11
|
+
### Easy projects
|
|
12
|
+
|
|
13
|
+
- [Easy](https://github.com/djalbat/easy) Elements that abstract away from the DOM.
|
|
14
|
+
- [Easy Layout](https://github.com/djalbat/easy-layout) Layout elements that work with CSS flexbox.
|
|
15
|
+
- [Easy Gestures](https://github.com/djalbat/easy-gestures) Touch gestures for web applications.
|
|
16
|
+
- [Easy Navigation](https://github.com/djalbat/easy-navigation) A responsive accordion and associated navigation.
|
|
17
|
+
- [Easy File System](https://github.com/djalbat/easy-file-system) A file system explorer and a rubbish bin.
|
|
18
|
+
- [Easy Rich Textarea](https://github.com/djalbat/easy-richtextarea) A textarea element that handles and hands off events well.
|
|
19
|
+
- [Easy Drag and Drop](https://github.com/djalbat/easy-drag-and-drop) Drag and drop functionality for Easy elements.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
You can install Easy Layout with [npm](https://www.npmjs.com/):
|
|
24
|
+
|
|
25
|
+
npm install easy-gestures
|
|
26
|
+
|
|
27
|
+
You can also clone the repository with [Git](https://git-scm.com/)...
|
|
28
|
+
|
|
29
|
+
git clone https://github.com/djalbat/easy-gestures.git
|
|
30
|
+
|
|
31
|
+
...and then install the dependencies with npm from within the project's root directory:
|
|
32
|
+
|
|
33
|
+
npm install
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
There is a small development server that can be run from within the project's directory with the following command:
|
|
38
|
+
|
|
39
|
+
npm start
|
|
40
|
+
|
|
41
|
+
The example will then be available at the following URL:
|
|
42
|
+
|
|
43
|
+
http://localhost:8888
|
|
44
|
+
|
|
45
|
+
The source for the example can be found in the `src/example.js` file and corresponding`src/example` folder. You are encouraged to try the example whilst reading what follows. You can rebuild it on the fly with the following command:
|
|
46
|
+
|
|
47
|
+
npm run watch-debug
|
|
48
|
+
|
|
49
|
+
The development server will reload the page whenever you make changes.
|
|
50
|
+
|
|
51
|
+
One last thing to bear in mind is that this package is included by way of a relative rather than a package import. If you are importing it into your own application, however, you should use the standard package import.
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
A single mixin is provided for the touch functionality.
|
|
56
|
+
It should be assigned to the class's prototype in the usual manner.
|
|
57
|
+
In order to make use of it, call the associated enable and disable functions.
|
|
58
|
+
|
|
59
|
+
### Touches functionality
|
|
60
|
+
|
|
61
|
+
The following listing gives an example of touch mixin usage:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
import { Element } from "easy";
|
|
65
|
+
import { touchMixins } from "easy-movile";
|
|
66
|
+
|
|
67
|
+
class View extends Element {
|
|
68
|
+
dragUpCustomHandler = (event, element, top, left) => {
|
|
69
|
+
console.log("drag up", top)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
...
|
|
73
|
+
|
|
74
|
+
didMount() {
|
|
75
|
+
this.onCustomDragUp(this.dragUpCustomHandler);
|
|
76
|
+
|
|
77
|
+
...
|
|
78
|
+
|
|
79
|
+
this.enableTouch();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
willUnmount() {
|
|
83
|
+
this.disableTouch();
|
|
84
|
+
|
|
85
|
+
this.offCustomDragUp(this.dragUpCustomHandler);
|
|
86
|
+
|
|
87
|
+
...
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
Object.assign(View.prototype, touchMixins);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Note that only one handler is shown.
|
|
95
|
+
The complete list of custom touch events that can be handled is:
|
|
96
|
+
|
|
97
|
+
* `drag-up`
|
|
98
|
+
* `drag-down`
|
|
99
|
+
* `drag-left`
|
|
100
|
+
* `drag-right`
|
|
101
|
+
* `drag-start`
|
|
102
|
+
* `swipe-up`
|
|
103
|
+
* `swipe-down`
|
|
104
|
+
* `swipe-left`
|
|
105
|
+
* `swipe-right`
|
|
106
|
+
* `pinch-move`
|
|
107
|
+
* `pinch-start`
|
|
108
|
+
* `pinch-stop`
|
|
109
|
+
* `single-tap`
|
|
110
|
+
* `double-tap`
|
|
111
|
+
|
|
112
|
+
As well as the usual `event` and `element` first and second arguments, the handlers can take various other arguments.
|
|
113
|
+
|
|
114
|
+
* The `single-tap` and `double-tap` event handlers as well as the `drag-start` event handler have `top` and `left` additional arguments for the position of the touch.
|
|
115
|
+
|
|
116
|
+
* The `drag-up`, `drag-down`, `drag-left` and `drag-right` event handlers also have `top` and `left` additional arguments but they are relative to the position of the touch at the start of the drag.
|
|
117
|
+
|
|
118
|
+
* The `pinch-start` event handler takes no additional arguments.
|
|
119
|
+
|
|
120
|
+
* The `pinch-move` event handler has a `ratio` additional argument that is the ratio of the distance between the two touch positions divided by the distance between the two starting touch positions.
|
|
121
|
+
|
|
122
|
+
* The `swipe-up`, `swipe-down`, `swipe-left` and `swipe-right` event handlers have `top` and `left` additional arguments for the touch position at the start of the swipe. They also have a `speed` argument which is the speed of the touch position projected in the swipe's direction.
|
|
123
|
+
|
|
124
|
+
## Building
|
|
125
|
+
|
|
126
|
+
Automation is done with [npm scripts](https://docs.npmjs.com/misc/scripts), have a look at the `package.json` file. The pertinent commands are:
|
|
127
|
+
|
|
128
|
+
npm run build-debug
|
|
129
|
+
npm run watch-debug
|
|
130
|
+
|
|
131
|
+
## Contact
|
|
132
|
+
|
|
133
|
+
* james.smith@djalbat.com
|
package/bin/main.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const { createLiveReloadHandler } = require("lively-cli");
|
|
6
|
+
|
|
7
|
+
const server = express(), ///
|
|
8
|
+
staticRouter = express.static("."),
|
|
9
|
+
liveReloadHandler = createLiveReloadHandler("./example.js");
|
|
10
|
+
|
|
11
|
+
server.use(staticRouter);
|
|
12
|
+
|
|
13
|
+
server.get("/live-reload", liveReloadHandler);
|
|
14
|
+
|
|
15
|
+
server.listen(8888);
|