@deltablot/malle 0.1.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/LICENSE +21 -0
- package/README.md +69 -0
- package/package.json +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Nicolas CARPi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# malle
|
|
2
|
+
|
|
3
|
+
Edit in place library with no dependencies and small footprint.
|
|
4
|
+
|
|
5
|
+
# WARNING: ALPHA VERSION!!
|
|
6
|
+
|
|
7
|
+
Api will likely change, do not use!
|
|
8
|
+
|
|
9
|
+
## Description
|
|
10
|
+
|
|
11
|
+
`malle` allows you to listen to a particular event (e.g. click, hover) on an element (e.g. p, span) and transform that element into an input that will be processed by a function.
|
|
12
|
+
|
|
13
|
+
The event can be: click or hover.
|
|
14
|
+
|
|
15
|
+
The element can be a `p`, `div`, `span`, ...
|
|
16
|
+
|
|
17
|
+
The created input can be a normal input or a textarea.
|
|
18
|
+
|
|
19
|
+
The user provided function will typically POST to an endpoint to get some JSON back.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
~~~bash
|
|
24
|
+
npm i malle
|
|
25
|
+
# or
|
|
26
|
+
yarn add malle
|
|
27
|
+
~~~
|
|
28
|
+
|
|
29
|
+
## Quickstart
|
|
30
|
+
|
|
31
|
+
~~~javascript
|
|
32
|
+
import { Malle } from 'malle';
|
|
33
|
+
|
|
34
|
+
const myCustomFunction = (value, event) => {
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// now create the malle
|
|
38
|
+
const malle = new Malle({
|
|
39
|
+
// this is the function that will be called once user has finished entering text (press Enter or click outside)
|
|
40
|
+
// it receives the new value, the original element, the event and the input element
|
|
41
|
+
fun: (value, original, event, input) => {
|
|
42
|
+
console.log(`New text: ${value}`);
|
|
43
|
+
console.log(`Original element:`);
|
|
44
|
+
console.log(original);
|
|
45
|
+
// add here your code for POSTing the new value
|
|
46
|
+
// something along the line of:
|
|
47
|
+
return fetch('/ajax', {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
body: JSON.stringify({ 'name': value, 'id': original.dataset.id }),
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
// and listen for events
|
|
54
|
+
malle.listen();
|
|
55
|
+
~~~
|
|
56
|
+
|
|
57
|
+
In this example, when a user clicks on an element with `data-malleable='true'`, the function in the `fun` option will be called. The element will be replaced by a `form` containing the `input` and optionally action buttons (Submit, Cancel).
|
|
58
|
+
|
|
59
|
+
See the [Documentation](./DOCUMENTATION.md) for usage and available options.
|
|
60
|
+
|
|
61
|
+
See the [demo/](./demo) folder for a full example.
|
|
62
|
+
|
|
63
|
+
## Contributing
|
|
64
|
+
|
|
65
|
+
See [contributing documentation](./CONTRIBUTING.md).
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
This software is open source and licensed under the [MIT License](./LICENSE).
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deltablot/malle",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Make text elements malleable",
|
|
5
|
+
"main": "dist/main.js",
|
|
6
|
+
"repository": "https://github.com/deltablot/malle",
|
|
7
|
+
"author": "Nicolas CARPi @ Deltablot>",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"private": false,
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/*.js",
|
|
12
|
+
"dist/*.js.map"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"lint": "eslint src",
|
|
17
|
+
"serve": "docker run --rm -it --name nginx-malle -p 8088:80 -v $(pwd):/usr/share/nginx/html:ro -d nginx",
|
|
18
|
+
"watch": "tsc --watch"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
22
|
+
"@typescript-eslint/parser": "^5.5.0",
|
|
23
|
+
"eslint": "^8.3.0",
|
|
24
|
+
"eslint-config-standard": "^16.0.3",
|
|
25
|
+
"eslint-plugin-import": "^2.25.3",
|
|
26
|
+
"eslint-plugin-node": "^11.1.0",
|
|
27
|
+
"eslint-plugin-promise": "^5.2.0",
|
|
28
|
+
"typescript": "^4.0.2"
|
|
29
|
+
}
|
|
30
|
+
}
|