@ramstack/alpinegear-destroy 1.0.0-preview.1

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 ADDED
@@ -0,0 +1,66 @@
1
+ # @ramstack/alpinegear-destroy
2
+
3
+ `@ramstack/alpinegear-destroy` is a plugin for [Alpine.js](https://alpinejs.dev/) that provides the `x-destroy` directive.
4
+
5
+ This directive is the opposite of `x-init` and allows you to execute code when an element is removed from the DOM.
6
+
7
+ ## Installation
8
+
9
+ ### Using CDN
10
+ To include the CDN version of this plugin, add the following `<script>` tag before the core `alpine.js` file:
11
+
12
+ ```html
13
+ <!-- alpine.js plugin -->
14
+ <script src="https://cdn.jsdelivr.net/npm/@ramstack/alpinegear-destroy@1/alpinegear-destroy.min.js" defer></script>
15
+
16
+ <!-- alpine.js -->
17
+ <script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
18
+ ```
19
+
20
+ ### Using NPM
21
+ Alternatively, you can install the plugin via `npm`:
22
+
23
+ ```bash
24
+ npm install --save @ramstack/alpinegear-destroy
25
+ ```
26
+
27
+ Then initialize it in your bundle:
28
+
29
+ ```js
30
+ import Alpine from "alpinejs";
31
+ import destroy from "@ramstack/alpinegear-destroy";
32
+
33
+ Alpine.plugin(destroy);
34
+ Alpine.start();
35
+ ```
36
+
37
+ ## Usage
38
+ In this example, when the `<div>` is removed, the message `Element destroyed` will appear.
39
+
40
+ ```html
41
+ <div x-data="{ show: true, destroyed: false }">
42
+ <button @click="show = false">Hide message</button>
43
+
44
+ <p x-show="destroyed">
45
+ <u>Element destroyed</u>
46
+ </p>
47
+
48
+ <template x-if="show">
49
+ <div x-destroy="destroyed = true">
50
+ <p>Hello, World!</p>
51
+ </div>
52
+ </template>
53
+ </div>
54
+ ```
55
+
56
+ ## Source code
57
+ You can find the source code for this plugin on GitHub:
58
+
59
+ https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/destroy
60
+
61
+ ## Contributions
62
+ Bug reports and contributions are welcome.
63
+
64
+ ## License
65
+ This package is released as open source under the **MIT License**.
66
+ See the [LICENSE](https://github.com/rameel/ramstack.alpinegear.js/blob/main/LICENSE) file for more details.
@@ -0,0 +1,7 @@
1
+ function plugin(alpine) {
2
+ alpine.directive("destroy", (_, { expression }, { cleanup, evaluate }) => {
3
+ cleanup(() => evaluate(expression));
4
+ });
5
+ }
6
+
7
+ export { plugin as destroy };
@@ -0,0 +1 @@
1
+ function e(e){e.directive("destroy",((e,{expression:t},{cleanup:o,evaluate:r})=>{o((()=>r(t)))}))}export{e as destroy};
@@ -0,0 +1,12 @@
1
+ (function () {
2
+ 'use strict';
3
+
4
+ function plugin(alpine) {
5
+ alpine.directive("destroy", (_, { expression }, { cleanup, evaluate }) => {
6
+ cleanup(() => evaluate(expression));
7
+ });
8
+ }
9
+
10
+ document.addEventListener("alpine:init", () => { Alpine.plugin(plugin); });
11
+
12
+ })();
@@ -0,0 +1 @@
1
+ !function(){"use strict";function e(e){e.directive("destroy",((e,{expression:n},{cleanup:i,evaluate:t})=>{i((()=>t(n)))}))}document.addEventListener("alpine:init",(()=>{Alpine.plugin(e)}))}();
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@ramstack/alpinegear-destroy",
3
+ "version": "1.0.0-preview.1",
4
+ "description": "@ramstack/alpinegear-destroy provides 'x-destroy' Alpine.js directive, which is the opposite of 'x-init' and allows you to execute code when an element is removed from the DOM.",
5
+ "author": "Rameel Burhan",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/rameel/ramstack.alpinegear.js.git",
10
+ "directory": "src/plugins/destroy"
11
+ },
12
+ "keywords": [
13
+ "alpine.js",
14
+ "alpinejs"
15
+ ],
16
+ "main": "alpinegear-destroy.js",
17
+ "module": "alpinegear-destroy.esm.js"
18
+ }