@ramstack/alpinegear-destroy 1.4.2 → 1.4.4
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 +80 -113
- package/alpinegear-destroy.esm.js +5 -5
- package/alpinegear-destroy.esm.min.js +1 -1
- package/alpinegear-destroy.js +10 -5
- package/alpinegear-destroy.min.js +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -1,113 +1,80 @@
|
|
|
1
|
-
# @ramstack/alpinegear-destroy
|
|
2
|
-
[](https://www.npmjs.com/package/@ramstack/alpinegear-destroy)
|
|
3
|
-
[](https://github.com/rameel/ramstack.alpinegear.js/blob/main/LICENSE)
|
|
4
|
-
|
|
5
|
-
`@ramstack/alpinegear-destroy` is a plugin for [Alpine.js](https://alpinejs.dev/) that provides the `x-destroy` directive.
|
|
6
|
-
|
|
7
|
-
This directive is the opposite of `x-init` and allows you to hook into the cleanup phase of any element in Alpine,
|
|
8
|
-
running a callback when the element is removed from the DOM.
|
|
9
|
-
|
|
10
|
-
## Installation
|
|
11
|
-
|
|
12
|
-
### Using CDN
|
|
13
|
-
To include the CDN version of this plugin, add the following `<script>` tag before the core `alpine.js` file:
|
|
14
|
-
|
|
15
|
-
```html
|
|
16
|
-
<!-- alpine.js plugin -->
|
|
17
|
-
<script src="https://cdn.jsdelivr.net/npm/@ramstack/alpinegear-destroy@1/alpinegear-destroy.min.js" defer></script>
|
|
18
|
-
|
|
19
|
-
<!-- alpine.js -->
|
|
20
|
-
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3/dist/cdn.min.js" defer></script>
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### Using NPM
|
|
24
|
-
Alternatively, you can install the plugin via `npm`:
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
npm install --save @ramstack/alpinegear-destroy
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Then initialize it in your bundle:
|
|
31
|
-
|
|
32
|
-
```js
|
|
33
|
-
import Alpine from "alpinejs";
|
|
34
|
-
import destroy from "@ramstack/alpinegear-destroy";
|
|
35
|
-
|
|
36
|
-
Alpine.plugin(destroy);
|
|
37
|
-
Alpine.start();
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Usage
|
|
41
|
-
In this example, when the `<div>` is removed, the message `Element destroyed` will appear.
|
|
42
|
-
|
|
43
|
-
```html
|
|
44
|
-
<div x-data="{ show: true, destroyed: false }">
|
|
45
|
-
<button @click="show = false">Remove element</button>
|
|
46
|
-
<button @click="show = true, destroyed = false">Reset</button>
|
|
47
|
-
|
|
48
|
-
<p x-show="destroyed">
|
|
49
|
-
Element destroyed
|
|
50
|
-
</p>
|
|
51
|
-
|
|
52
|
-
<template x-if="show">
|
|
53
|
-
<p x-destroy="destroyed = true">
|
|
54
|
-
Hello, World!
|
|
55
|
-
</p>
|
|
56
|
-
</template>
|
|
57
|
-
</div>
|
|
58
|
-
```
|
|
59
|
-
🚀 [Live demo | Alpine.js x-destroy: Handle DOM element removal](https://jsfiddle.net/rameel/qcnwm2b0/)
|
|
60
|
-
|
|
61
|
-
## Source code
|
|
62
|
-
You can find the source code for this plugin on GitHub:
|
|
63
|
-
|
|
64
|
-
https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/destroy
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
## Related
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
**[@ramstack/alpinegear-template](https://www.npmjs.com/package/@ramstack/alpinegear-template)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/template))<br>
|
|
83
|
-
Provides the `x-template` directive, which allows you to define a template once anywhere in the DOM and reference it by its ID.
|
|
84
|
-
|
|
85
|
-
**[@ramstack/alpinegear-fragment](https://www.npmjs.com/package/@ramstack/alpinegear-fragment)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/fragment))<br>
|
|
86
|
-
Provides the `x-fragment` directive, which allows for fragment-like behavior similar to what's available in frameworks
|
|
87
|
-
like `Vue.js` or `React`, where multiple root elements can be grouped together.
|
|
88
|
-
|
|
89
|
-
**[@ramstack/alpinegear-match](https://www.npmjs.com/package/@ramstack/alpinegear-match)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/match))<br>
|
|
90
|
-
Provides the `x-match` directive, which functions similarly to the `switch` statement in many programming languages,
|
|
91
|
-
allowing you to conditionally render elements based on matching cases.
|
|
92
|
-
|
|
93
|
-
**[@ramstack/alpinegear-when](https://www.npmjs.com/package/@ramstack/alpinegear-when)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/when))<br>
|
|
94
|
-
Provides the `x-when` directive, which allows for conditional rendering of elements similar to `x-if`, but supports multiple root elements.
|
|
95
|
-
|
|
96
|
-
**[@ramstack/alpinegear-hotkey](https://www.npmjs.com/package/@ramstack/alpinegear-hotkey)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/hotkey))<br>
|
|
97
|
-
Provides the `x-hotkey` directive, which allows you to easily handle keyboard shortcuts within your Alpine.js components or application.
|
|
98
|
-
|
|
99
|
-
**[@ramstack/alpinegear-router](https://www.npmjs.com/package/@ramstack/alpinegear-router)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/router))<br>
|
|
100
|
-
Provides the `x-router` and `x-route` directives, which enable client-side navigation and routing functionality within your Alpine.js application.
|
|
101
|
-
|
|
102
|
-
**[@ramstack/alpinegear-dialog](https://www.npmjs.com/package/@ramstack/alpinegear-dialog)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/dialog))<br>
|
|
103
|
-
Provides a headless dialog directive for Alpine.js based on the native HTML `<dialog>` element.
|
|
104
|
-
It supports declarative composition, value-based close semantics, and both modal and non-modal dialogs,
|
|
105
|
-
with optional Promise-based imperative control.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
## Contributions
|
|
109
|
-
Bug reports and contributions are welcome.
|
|
110
|
-
|
|
111
|
-
## License
|
|
112
|
-
This package is released as open source under the **MIT License**.
|
|
113
|
-
See the [LICENSE](https://github.com/rameel/ramstack.alpinegear.js/blob/main/LICENSE) file for more details.
|
|
1
|
+
# @ramstack/alpinegear-destroy
|
|
2
|
+
[](https://www.npmjs.com/package/@ramstack/alpinegear-destroy)
|
|
3
|
+
[](https://github.com/rameel/ramstack.alpinegear.js/blob/main/LICENSE)
|
|
4
|
+
|
|
5
|
+
`@ramstack/alpinegear-destroy` is a plugin for [Alpine.js](https://alpinejs.dev/) that provides the `x-destroy` directive.
|
|
6
|
+
|
|
7
|
+
This directive is the opposite of `x-init` and allows you to hook into the cleanup phase of any element in Alpine,
|
|
8
|
+
running a callback when the element is removed from the DOM.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
### Using CDN
|
|
13
|
+
To include the CDN version of this plugin, add the following `<script>` tag before the core `alpine.js` file:
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<!-- alpine.js plugin -->
|
|
17
|
+
<script src="https://cdn.jsdelivr.net/npm/@ramstack/alpinegear-destroy@1/alpinegear-destroy.min.js" defer></script>
|
|
18
|
+
|
|
19
|
+
<!-- alpine.js -->
|
|
20
|
+
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3/dist/cdn.min.js" defer></script>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Using NPM
|
|
24
|
+
Alternatively, you can install the plugin via `npm`:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install --save @ramstack/alpinegear-destroy
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then initialize it in your bundle:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import Alpine from "alpinejs";
|
|
34
|
+
import destroy from "@ramstack/alpinegear-destroy";
|
|
35
|
+
|
|
36
|
+
Alpine.plugin(destroy);
|
|
37
|
+
Alpine.start();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
In this example, when the `<div>` is removed, the message `Element destroyed` will appear.
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<div x-data="{ show: true, destroyed: false }">
|
|
45
|
+
<button @click="show = false">Remove element</button>
|
|
46
|
+
<button @click="show = true, destroyed = false">Reset</button>
|
|
47
|
+
|
|
48
|
+
<p x-show="destroyed">
|
|
49
|
+
Element destroyed
|
|
50
|
+
</p>
|
|
51
|
+
|
|
52
|
+
<template x-if="show">
|
|
53
|
+
<p x-destroy="destroyed = true">
|
|
54
|
+
Hello, World!
|
|
55
|
+
</p>
|
|
56
|
+
</template>
|
|
57
|
+
</div>
|
|
58
|
+
```
|
|
59
|
+
🚀 [Live demo | Alpine.js x-destroy: Handle DOM element removal](https://jsfiddle.net/rameel/qcnwm2b0/)
|
|
60
|
+
|
|
61
|
+
## Source code
|
|
62
|
+
You can find the source code for this plugin on GitHub:
|
|
63
|
+
|
|
64
|
+
https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/destroy
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
## Related packages
|
|
68
|
+
This package is part of **[AlpineGear](https://github.com/rameel/ramstack.alpinegear.js)** —
|
|
69
|
+
a collection of utilities and directives for [Alpine.js](https://alpinejs.dev).
|
|
70
|
+
|
|
71
|
+
You can find the full list of related packages and their documentation here:
|
|
72
|
+
https://github.com/rameel/ramstack.alpinegear.js
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
## Contributions
|
|
76
|
+
Bug reports and contributions are welcome.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
This package is released as open source under the **MIT License**.
|
|
80
|
+
See the [LICENSE](https://github.com/rameel/ramstack.alpinegear.js/blob/main/LICENSE) file for more details.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function plugin(alpine) {
|
|
2
|
-
alpine.directive("destroy", (_, { expression }, { cleanup, evaluate }) => {
|
|
3
|
-
cleanup(() => evaluate(expression));
|
|
4
|
-
});
|
|
1
|
+
function plugin(alpine) {
|
|
2
|
+
alpine.directive("destroy", (_, { expression }, { cleanup, evaluate }) => {
|
|
3
|
+
cleanup(() => evaluate(expression));
|
|
4
|
+
});
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export { plugin as destroy };
|
|
7
|
+
export { plugin as default, plugin as destroy };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){e.directive("destroy",(e,{expression:t},{cleanup:
|
|
1
|
+
function e(e){e.directive("destroy",(e,{expression:t},{cleanup:a,evaluate:s})=>{a(()=>s(t))})}export{e as default,e as destroy};
|
package/alpinegear-destroy.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const listen = (target, type, listener, options) => {
|
|
5
|
+
target.addEventListener(type, listener, options);
|
|
6
|
+
return () => target.removeEventListener(type, listener, options);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function plugin(alpine) {
|
|
10
|
+
alpine.directive("destroy", (_, { expression }, { cleanup, evaluate }) => {
|
|
11
|
+
cleanup(() => evaluate(expression));
|
|
12
|
+
});
|
|
8
13
|
}
|
|
9
14
|
|
|
10
|
-
document
|
|
15
|
+
listen(document, "alpine:init", () => Alpine.plugin(plugin));
|
|
11
16
|
|
|
12
17
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";function e(e){e.directive("destroy",(e,{expression:
|
|
1
|
+
!function(){"use strict";function e(e){e.directive("destroy",(e,{expression:i},{cleanup:n,evaluate:t})=>{n(()=>t(i))})}document.addEventListener("alpine:init",()=>Alpine.plugin(e),void 0)}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ramstack/alpinegear-destroy",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
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
5
|
"author": "Rameel Burhan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
"alpinejs-directive",
|
|
16
16
|
"alpinejs-plugin"
|
|
17
17
|
],
|
|
18
|
-
"
|
|
19
|
-
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": {
|
|
21
|
+
"production": "./alpinegear-destroy.esm.min.js",
|
|
22
|
+
"default": "./alpinegear-destroy.esm.js"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
20
26
|
}
|