@webhandle/component-swipe-listener 1.0.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 +52 -0
- package/initialize-webhandle-component.mjs +81 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @webhandle/component-swipe-listener
|
|
2
|
+
|
|
3
|
+
Packages the fantastic swipe-listener module as a webhandle-component. By default,
|
|
4
|
+
this component will provide a resource via the external resource manager.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm i @webhandle/component-swipe-listener
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Server Side Usage
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
import swipeSetup from "@webhandle/component-swipe-listener/initialize-webhandle-component.mjs"
|
|
16
|
+
let swipeManager = await swipeSetup(webhandle)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Client Side Usage
|
|
20
|
+
SwipeListener adds itself to the window scope. If `directions.left` is true, it indicates the
|
|
21
|
+
user is swiping towards the left. Creating a new SwipeListener around an element causes it
|
|
22
|
+
to emit swipe events.
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import 'swipe-listener'
|
|
26
|
+
|
|
27
|
+
let testBox = document.getElementById('test-box')
|
|
28
|
+
let messages = document.getElementById('messages')
|
|
29
|
+
|
|
30
|
+
function addText(txt) {
|
|
31
|
+
messages.innerHTML += `<p>${txt}</p>`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let listener = new SwipeListener(testBox)
|
|
35
|
+
|
|
36
|
+
testBox.addEventListener('swipe', (evt) => {
|
|
37
|
+
let directions = evt.detail.directions
|
|
38
|
+
if(directions.left) {
|
|
39
|
+
addText('left')
|
|
40
|
+
}
|
|
41
|
+
if(directions.right) {
|
|
42
|
+
addText('right')
|
|
43
|
+
}
|
|
44
|
+
if(directions.top) {
|
|
45
|
+
addText('top')
|
|
46
|
+
}
|
|
47
|
+
if(directions.bottom) {
|
|
48
|
+
addText('bottom')
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
```
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import createInitializeWebhandleComponent from "@webhandle/initialize-webhandle-component/create-initialize-webhandle-component.mjs"
|
|
2
|
+
import ComponentManager from "@webhandle/initialize-webhandle-component/component-manager.mjs"
|
|
3
|
+
import path from "node:path"
|
|
4
|
+
import fs from "node:fs/promises"
|
|
5
|
+
|
|
6
|
+
let initializeWebhandleComponent = createInitializeWebhandleComponent()
|
|
7
|
+
|
|
8
|
+
initializeWebhandleComponent.componentName = '@webhandle/component-swipe-listener'
|
|
9
|
+
initializeWebhandleComponent.componentDir = import.meta.dirname
|
|
10
|
+
initializeWebhandleComponent.defaultConfig = {
|
|
11
|
+
provideResources: true
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
initializeWebhandleComponent.setup = async function(webhandle, config) {
|
|
17
|
+
let manager = new ComponentManager()
|
|
18
|
+
manager.config = config
|
|
19
|
+
let dir = 'node_modules/swipe-listener/dist'
|
|
20
|
+
|
|
21
|
+
let resourceLocation
|
|
22
|
+
try {
|
|
23
|
+
let loc = path.join(initializeWebhandleComponent.componentDir, dir)
|
|
24
|
+
let result = fs.stat(loc + '/swipe-listener.min.js')
|
|
25
|
+
if(result) {
|
|
26
|
+
resourceLocation = loc
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch(e) { }
|
|
30
|
+
|
|
31
|
+
if(!resourceLocation) {
|
|
32
|
+
try {
|
|
33
|
+
let loc = path.join(webhandle.projectRoot, dir)
|
|
34
|
+
let result = fs.stat(loc + '/swipe-listener.min.js')
|
|
35
|
+
if(result) {
|
|
36
|
+
resourceLocation = loc
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch(e) { }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
manager.addExternalResources = function(externalResourceManager) {
|
|
43
|
+
let resource = {
|
|
44
|
+
mimeType: 'application/javascript'
|
|
45
|
+
, url: '/@webhandle/component-swipe-listener/files/js/swipe-listener.min.js'
|
|
46
|
+
, name: 'swipe-listener'
|
|
47
|
+
, resourceType: 'module'
|
|
48
|
+
, cachable: webhandle.development ? false : true
|
|
49
|
+
}
|
|
50
|
+
externalResourceManager.provideResource(resource)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
webhandle.routers.preDynamic.use((req, res, next) => {
|
|
54
|
+
if(manager.config.provideResources) {
|
|
55
|
+
manager.addExternalResources(res.locals.externalResourceManager)
|
|
56
|
+
}
|
|
57
|
+
next()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
if(resourceLocation) {
|
|
61
|
+
manager.staticPaths.push(
|
|
62
|
+
webhandle.addStaticDir(
|
|
63
|
+
resourceLocation
|
|
64
|
+
, {
|
|
65
|
+
urlPrefix: '/@webhandle/component-swipe-listener/files/js'
|
|
66
|
+
, fixedSetOfFiles: true
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
let msg = 'Could not find resources for @webhandle/component-swipe-listener: ' + resourceLocation
|
|
73
|
+
console.log(msg)
|
|
74
|
+
console.error(msg)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
return manager
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default initializeWebhandleComponent
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webhandle/component-swipe-listener",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "initialize-webhandle-component.mjs",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "run-webhandle ./initialize-webhandle-component.mjs"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/EmergentIdeas/webhandle-component-swipe-listener.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/EmergentIdeas/webhandle-component-swipe-listener/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/EmergentIdeas/webhandle-component-swipe-listener#readme",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@webhandle/initialize-webhandle-component": "^1.0.2",
|
|
23
|
+
"swipe-listener": "^1.3.0"
|
|
24
|
+
}
|
|
25
|
+
, "files": [
|
|
26
|
+
"*.mjs"
|
|
27
|
+
, "README.md"
|
|
28
|
+
]
|
|
29
|
+
}
|