@ramstack/alpinegear-fragment 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 CHANGED
@@ -1,147 +1,115 @@
1
- # @ramstack/alpinegear-fragment
2
- [![NPM](https://img.shields.io/npm/v/@ramstack/alpinegear-fragment)](https://www.npmjs.com/package/@ramstack/alpinegear-fragment)
3
- [![MIT](https://img.shields.io/github/license/rameel/ramstack.alpinegear.js)](https://github.com/rameel/ramstack.alpinegear.js/blob/main/LICENSE)
4
-
5
- `@ramstack/alpinegear-fragment` is a plugin for [Alpine.js](https://alpinejs.dev/) that provides the `x-fragment` directive.
6
-
7
- This directive allows you to use multiple root elements in your templates, similar to the `Fragment` feature found in frameworks like `Vue.js` and `React`. It is particularly useful when you want to avoid wrapping elements in unnecessary container tags.
8
-
9
- > [!Note]
10
- > This package is part of the **[`@ramstack/alpinegear-main`](https://www.npmjs.com/package/@ramstack/alpinegear-main)** bundle.
11
- > If you are using the main bundle, you don't need to install this package separately.
12
-
13
- ## Installation
14
-
15
- ### Using CDN
16
- To include the CDN version of this plugin, add the following `<script>` tag before the core `alpine.js` file:
17
-
18
- ```html
19
- <!-- alpine.js plugin -->
20
- <script src="https://cdn.jsdelivr.net/npm/@ramstack/alpinegear-fragment@1/alpinegear-fragment.min.js" defer></script>
21
-
22
- <!-- alpine.js -->
23
- <script src="https://cdn.jsdelivr.net/npm/alpinejs@3/dist/cdn.min.js" defer></script>
24
- ```
25
-
26
- ### Using NPM
27
- Alternatively, you can install the plugin via `npm`:
28
-
29
- ```bash
30
- npm install --save @ramstack/alpinegear-fragment
31
- ```
32
-
33
- Then initialize it in your bundle:
34
-
35
- ```js
36
- import Alpine from "alpinejs";
37
- import fragment from "@ramstack/alpinegear-fragment";
38
-
39
- Alpine.plugin(fragment);
40
- Alpine.start();
41
- ```
42
-
43
- ## Usage
44
- With the `x-fragment` directive, you can use multiple root elements in your components without needing a wrapper container:
45
-
46
- ```html
47
- <div x-data="{ show: false }">
48
- <button @click="show = !show">Show more</button>
49
-
50
- <ul>
51
- <li>Apple</li>
52
- <li>Banana</li>
53
-
54
- <template x-if="show">
55
- <template x-fragment>
56
- <li>Orange</li>
57
- <li>Grape</li>
58
- <li>Mango</li>
59
- </template>
60
- </template>
61
- </ul>
62
- </div>
63
- ```
64
- 🚀 [Live demo | Alpine.js x-fragment: Multiple root elements](https://jsfiddle.net/rameel/jdwuoatf/)
65
-
66
- In this example, the `x-fragment` directive allows the `<li>` elements (Orange, Grape, and Mango) to be added
67
- to the `<ul>` without a parent container, enabling multiple root elements in the `x-if` template.
68
-
69
- ### Using with `x-for`
70
- The `x-fragment` directive can also be used with the directive `x-for`, giving you the flexibility to render
71
- multiple sibling elements for each iteration without wrapping them:
72
-
73
- ```html
74
- <div x-data="{
75
- items: [
76
- { term: 'Star', description: 'Luminous plasma sphere.' },
77
- { term: 'Planet', description: 'Body orbiting a star.' },
78
- { term: 'Galaxy', description: 'Stars and dust system.' },
79
- { term: 'Nebula', description: 'Cloud of gas in space.' }]
80
- }">
81
- <button @click="items.reverse()">Reverse</button>
82
-
83
- <dl>
84
- <template x-for="item in items" :key="item.term">
85
- <template x-fragment>
86
- <dt x-text="item.term"></dt>
87
- <dd x-text="item.description"></dd>
88
- </template>
89
- </template>
90
- </dl>
91
- </div>
92
- ```
93
- 🚀 [Live demo | Alpine.js x-fragment: Multiple root elements with x-for](https://jsfiddle.net/rameel/201rmntc/)
94
-
95
- ## Source code
96
- You can find the source code for this plugin on GitHub:
97
-
98
- https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/fragment
99
-
100
-
101
- ## Related projects
102
-
103
- **[@ramstack/alpinegear-main](https://www.npmjs.com/package/@ramstack/alpinegear-main)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/main))<br>
104
- Provides a combined plugin that includes several useful directives.
105
- This package aggregates multiple individual plugins, offering a convenient all-in-one bundle.
106
- Included directives: `x-bound`, `x-format`, `x-fragment`, `x-match`, `x-template`, and `x-when`.
107
-
108
- **[@ramstack/alpinegear-bound](https://www.npmjs.com/package/@ramstack/alpinegear-bound)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/bound))<br>
109
- Provides the `x-bound` directive, which allows for two-way binding of input elements and their associated data properties.
110
- It works similarly to the binding provided by [Svelte](https://svelte.dev/docs/element-directives#bind-property)
111
- and also supports synchronizing values between two `Alpine.js` data properties.
112
-
113
- **[@ramstack/alpinegear-format](https://www.npmjs.com/package/@ramstack/alpinegear-format)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/format))<br>
114
- Provides the `x-format` directive, which allows you to easily interpolate text using a template syntax similar to what's available in `Vue.js`.
115
-
116
- **[@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>
117
- Provides the `x-template` directive, which allows you to define a template once anywhere in the DOM and reference it by its ID.
118
-
119
- **[@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>
120
- Provides the `x-match` directive, which functions similarly to the `switch` statement in many programming languages,
121
- allowing you to conditionally render elements based on matching cases.
122
-
123
- **[@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>
124
- Provides the `x-when` directive, which allows for conditional rendering of elements similar to `x-if`, but supports multiple root elements.
125
-
126
- **[@ramstack/alpinegear-destroy](https://www.npmjs.com/package/@ramstack/alpinegear-destroy)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/destroy))<br>
127
- Provides the `x-destroy` directive, which is the opposite of `x-init` and allows you to hook into the cleanup phase
128
- of any element, running a callback when the element is removed from the DOM.
129
-
130
- **[@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>
131
- Provides the `x-hotkey` directive, which allows you to easily handle keyboard shortcuts within your Alpine.js components or application.
132
-
133
- **[@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>
134
- Provides the `x-router` and `x-route` directives, which enable client-side navigation and routing functionality within your Alpine.js application.
135
-
136
- **[@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>
137
- Provides a headless dialog directive for Alpine.js based on the native HTML `<dialog>` element.
138
- It supports declarative composition, value-based close semantics, and both modal and non-modal dialogs,
139
- with optional Promise-based imperative control.
140
-
141
-
142
- ## Contributions
143
- Bug reports and contributions are welcome.
144
-
145
- ## License
146
- This package is released as open source under the **MIT License**.
147
- See the [LICENSE](https://github.com/rameel/ramstack.alpinegear.js/blob/main/LICENSE) file for more details.
1
+ # @ramstack/alpinegear-fragment
2
+ [![NPM](https://img.shields.io/npm/v/@ramstack/alpinegear-fragment)](https://www.npmjs.com/package/@ramstack/alpinegear-fragment)
3
+ [![MIT](https://img.shields.io/github/license/rameel/ramstack.alpinegear.js)](https://github.com/rameel/ramstack.alpinegear.js/blob/main/LICENSE)
4
+
5
+ `@ramstack/alpinegear-fragment` is a plugin for [Alpine.js](https://alpinejs.dev/) that provides the `x-fragment` directive.
6
+
7
+ This directive allows you to use multiple root elements in your templates, similar to the `Fragment` feature found in frameworks
8
+ like `Vue.js` and `React`. It is particularly useful when you want to avoid wrapping elements in unnecessary container tags.
9
+
10
+ > [!Note]
11
+ > This package is part of the **[`@ramstack/alpinegear-main`](https://www.npmjs.com/package/@ramstack/alpinegear-main)** bundle.
12
+ > If you are using the main bundle, you don't need to install this package separately.
13
+
14
+ ## Installation
15
+
16
+ ### Using CDN
17
+ To include the CDN version of this plugin, add the following `<script>` tag before the core `alpine.js` file:
18
+
19
+ ```html
20
+ <!-- alpine.js plugin -->
21
+ <script src="https://cdn.jsdelivr.net/npm/@ramstack/alpinegear-fragment@1/alpinegear-fragment.min.js" defer></script>
22
+
23
+ <!-- alpine.js -->
24
+ <script src="https://cdn.jsdelivr.net/npm/alpinejs@3/dist/cdn.min.js" defer></script>
25
+ ```
26
+
27
+ ### Using NPM
28
+ Alternatively, you can install the plugin via `npm`:
29
+
30
+ ```bash
31
+ npm install --save @ramstack/alpinegear-fragment
32
+ ```
33
+
34
+ Then initialize it in your bundle:
35
+
36
+ ```js
37
+ import Alpine from "alpinejs";
38
+ import fragment from "@ramstack/alpinegear-fragment";
39
+
40
+ Alpine.plugin(fragment);
41
+ Alpine.start();
42
+ ```
43
+
44
+ ## Usage
45
+ With the `x-fragment` directive, you can use multiple root elements in your components without needing a wrapper container:
46
+
47
+ ```html
48
+ <div x-data="{ show: false }">
49
+ <button @click="show = !show">Show more</button>
50
+
51
+ <ul>
52
+ <li>Apple</li>
53
+ <li>Banana</li>
54
+
55
+ <template x-if="show">
56
+ <template x-fragment>
57
+ <li>Orange</li>
58
+ <li>Grape</li>
59
+ <li>Mango</li>
60
+ </template>
61
+ </template>
62
+ </ul>
63
+ </div>
64
+ ```
65
+ 🚀 [Live demo | Alpine.js x-fragment: Multiple root elements](https://jsfiddle.net/rameel/jdwuoatf/)
66
+
67
+ In this example, the `x-fragment` directive allows the `<li>` elements (Orange, Grape, and Mango) to be added
68
+ to the `<ul>` without a parent container, enabling multiple root elements in the `x-if` template.
69
+
70
+ ### Using with `x-for`
71
+ The `x-fragment` directive can also be used with the directive `x-for`, giving you the flexibility to render
72
+ multiple sibling elements for each iteration without wrapping them:
73
+
74
+ ```html
75
+ <div x-data="{
76
+ items: [
77
+ { term: 'Star', description: 'Luminous plasma sphere.' },
78
+ { term: 'Planet', description: 'Body orbiting a star.' },
79
+ { term: 'Galaxy', description: 'Stars and dust system.' },
80
+ { term: 'Nebula', description: 'Cloud of gas in space.' }]
81
+ }">
82
+ <button @click="items.reverse()">Reverse</button>
83
+
84
+ <dl>
85
+ <template x-for="item in items" :key="item.term">
86
+ <template x-fragment>
87
+ <dt x-text="item.term"></dt>
88
+ <dd x-text="item.description"></dd>
89
+ </template>
90
+ </template>
91
+ </dl>
92
+ </div>
93
+ ```
94
+ 🚀 [Live demo | Alpine.js x-fragment: Multiple root elements with x-for](https://jsfiddle.net/rameel/201rmntc/)
95
+
96
+ ## Source code
97
+ You can find the source code for this plugin on GitHub:
98
+
99
+ https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/fragment
100
+
101
+
102
+ ## Related packages
103
+ This package is part of **[AlpineGear](https://github.com/rameel/ramstack.alpinegear.js)** —
104
+ a collection of utilities and directives for [Alpine.js](https://alpinejs.dev).
105
+
106
+ You can find the full list of related packages and their documentation here:
107
+ https://github.com/rameel/ramstack.alpinegear.js
108
+
109
+
110
+ ## Contributions
111
+ Bug reports and contributions are welcome.
112
+
113
+ ## License
114
+ This package is released as open source under the **MIT License**.
115
+ See the [LICENSE](https://github.com/rameel/ramstack.alpinegear.js/blob/main/LICENSE) file for more details.
@@ -1,71 +1,71 @@
1
- const warn = (...args) => console.warn("alpinegear.js:", ...args);
2
- const is_template = el => el.matches("template");
1
+ const warn = (...args) => console.warn("alpinegear.js:", ...args);
2
+ const is_template = el => el.matches("template");
3
3
  const is_element = el => el.nodeType === Node.ELEMENT_NODE;
4
4
 
5
- function anchor_block(el, template, { addScopeToNode, cleanup, initTree, mutateDom, scope = {} }) {
6
- if (el._r_block) {
7
- return;
8
- }
9
-
10
- initialize();
11
-
12
- let nodes = is_template(template)
13
- ? [...template.content.cloneNode(true).childNodes]
14
- : [template.cloneNode(true)];
15
-
16
- mutateDom(() => {
17
- for (let node of nodes) {
18
- is_element(node) && addScopeToNode(node, scope, el);
19
- el.parentElement.insertBefore(node, el);
20
- is_element(node) && initTree(node);
21
- }
22
- });
23
-
24
- el._r_block = {
25
- template,
26
- update() {
27
- mutateDom(() => {
28
- for (let node of nodes ?? []) {
29
- el.parentElement.insertBefore(node, el);
30
- }
31
- });
32
- },
33
- delete() {
34
- el._r_block = null;
35
- for (let node of nodes ?? []) {
36
- node.remove();
37
- }
38
- nodes = null;
39
- }
40
- };
41
-
42
- cleanup(() => el._r_block?.delete());
43
- }
44
-
45
- function initialize() {
46
- document.body._r_block ??= (() => {
47
- const observer = new MutationObserver(mutations => {
48
- for (let mutation of mutations) {
49
- for (let node of mutation.addedNodes) {
50
- node._r_block?.update();
51
- }
52
- }
53
- });
54
-
55
- observer.observe(document.body, { childList: true, subtree: true });
56
- return observer;
57
- })();
5
+ function anchor_block(el, template, { addScopeToNode, cleanup, initTree, mutateDom, scope = {} }) {
6
+ if (el._r_block) {
7
+ return;
8
+ }
9
+
10
+ initialize();
11
+
12
+ let nodes = is_template(template)
13
+ ? [...template.content.cloneNode(true).childNodes]
14
+ : [template.cloneNode(true)];
15
+
16
+ mutateDom(() => {
17
+ for (let node of nodes) {
18
+ is_element(node) && addScopeToNode(node, scope, el);
19
+ el.parentElement.insertBefore(node, el);
20
+ is_element(node) && initTree(node);
21
+ }
22
+ });
23
+
24
+ el._r_block = {
25
+ template,
26
+ update() {
27
+ mutateDom(() => {
28
+ for (let node of nodes ?? []) {
29
+ el.parentElement.insertBefore(node, el);
30
+ }
31
+ });
32
+ },
33
+ delete() {
34
+ el._r_block = null;
35
+ for (let node of nodes ?? []) {
36
+ node.remove();
37
+ }
38
+ nodes = null;
39
+ }
40
+ };
41
+
42
+ cleanup(() => el._r_block?.delete());
58
43
  }
59
44
 
60
- function plugin({ addScopeToNode, directive, initTree, mutateDom }) {
61
- directive("fragment", (el, {}, { cleanup }) => {
62
- if (!is_template(el)) {
63
- warn("x-fragment can only be used on a 'template' tag");
64
- return;
65
- }
66
-
67
- anchor_block(el, el, { addScopeToNode, cleanup, initTree, mutateDom });
68
- });
45
+ function initialize() {
46
+ document.body._r_block ??= (() => {
47
+ const observer = new MutationObserver(mutations => {
48
+ for (let mutation of mutations) {
49
+ for (let node of mutation.addedNodes) {
50
+ node._r_block?.update();
51
+ }
52
+ }
53
+ });
54
+
55
+ observer.observe(document.body, { childList: true, subtree: true });
56
+ return observer;
57
+ })();
58
+ }
59
+
60
+ function plugin({ addScopeToNode, directive, initTree, mutateDom }) {
61
+ directive("fragment", (el, {}, { cleanup }) => {
62
+ if (!is_template(el)) {
63
+ warn("x-fragment can only be used on a 'template' tag");
64
+ return;
65
+ }
66
+
67
+ anchor_block(el, el, { addScopeToNode, cleanup, initTree, mutateDom });
68
+ });
69
69
  }
70
70
 
71
- export { plugin as fragment };
71
+ export { plugin as default, plugin as fragment };
@@ -1 +1 @@
1
- const e=e=>e.matches("template"),o=e=>e.nodeType===Node.ELEMENT_NODE;function t({addScopeToNode:t,directive:n,initTree:r,mutateDom:l}){n("fragment",(n,{},{cleanup:d})=>{e(n)?function(t,n,{addScopeToNode:r,cleanup:l,initTree:d,mutateDom:a,scope:c={}}){if(t._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver(e=>{for(let o of e)for(let e of o.addedNodes)e._r_block?.update()});return e.observe(document.body,{childList:!0,subtree:!0}),e})();let u=e(n)?[...n.content.cloneNode(!0).childNodes]:[n.cloneNode(!0)];a(()=>{for(let e of u)o(e)&&r(e,c,t),t.parentElement.insertBefore(e,t),o(e)&&d(e)}),t._r_block={template:n,update(){a(()=>{for(let e of u??[])t.parentElement.insertBefore(e,t)})},delete(){t._r_block=null;for(let e of u??[])e.remove();u=null}},l(()=>t._r_block?.delete())}(n,n,{addScopeToNode:t,cleanup:d,initTree:r,mutateDom:l}):console.warn("alpinegear.js:","x-fragment can only be used on a 'template' tag")})}export{t as fragment};
1
+ const e=e=>e.matches("template"),o=e=>e.nodeType===Node.ELEMENT_NODE;function t({addScopeToNode:t,directive:n,initTree:r,mutateDom:l}){n("fragment",(n,{},{cleanup:a})=>{e(n)?function(t,n,{addScopeToNode:r,cleanup:l,initTree:a,mutateDom:d,scope:c={}}){if(t._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver(e=>{for(let o of e)for(let e of o.addedNodes)e._r_block?.update()});return e.observe(document.body,{childList:!0,subtree:!0}),e})();let u=e(n)?[...n.content.cloneNode(!0).childNodes]:[n.cloneNode(!0)];d(()=>{for(let e of u)o(e)&&r(e,c,t),t.parentElement.insertBefore(e,t),o(e)&&a(e)}),t._r_block={template:n,update(){d(()=>{for(let e of u??[])t.parentElement.insertBefore(e,t)})},delete(){t._r_block=null;for(let e of u??[])e.remove();u=null}},l(()=>t._r_block?.delete())}(n,n,{addScopeToNode:t,cleanup:a,initTree:r,mutateDom:l}):console.warn("alpinegear.js:","x-fragment can only be used on a 'template' tag")})}export{t as default,t as fragment};
@@ -1,76 +1,81 @@
1
1
  (function () {
2
2
  'use strict';
3
3
 
4
- const warn = (...args) => console.warn("alpinegear.js:", ...args);
5
- const is_template = el => el.matches("template");
4
+ const warn = (...args) => console.warn("alpinegear.js:", ...args);
5
+ const is_template = el => el.matches("template");
6
6
  const is_element = el => el.nodeType === Node.ELEMENT_NODE;
7
7
 
8
- function anchor_block(el, template, { addScopeToNode, cleanup, initTree, mutateDom, scope = {} }) {
9
- if (el._r_block) {
10
- return;
11
- }
12
-
13
- initialize();
14
-
15
- let nodes = is_template(template)
16
- ? [...template.content.cloneNode(true).childNodes]
17
- : [template.cloneNode(true)];
18
-
19
- mutateDom(() => {
20
- for (let node of nodes) {
21
- is_element(node) && addScopeToNode(node, scope, el);
22
- el.parentElement.insertBefore(node, el);
23
- is_element(node) && initTree(node);
24
- }
25
- });
26
-
27
- el._r_block = {
28
- template,
29
- update() {
30
- mutateDom(() => {
31
- for (let node of nodes ?? []) {
32
- el.parentElement.insertBefore(node, el);
33
- }
34
- });
35
- },
36
- delete() {
37
- el._r_block = null;
38
- for (let node of nodes ?? []) {
39
- node.remove();
40
- }
41
- nodes = null;
42
- }
43
- };
44
-
45
- cleanup(() => el._r_block?.delete());
46
- }
47
-
48
- function initialize() {
49
- document.body._r_block ??= (() => {
50
- const observer = new MutationObserver(mutations => {
51
- for (let mutation of mutations) {
52
- for (let node of mutation.addedNodes) {
53
- node._r_block?.update();
54
- }
55
- }
56
- });
57
-
58
- observer.observe(document.body, { childList: true, subtree: true });
59
- return observer;
60
- })();
8
+ const listen = (target, type, listener, options) => {
9
+ target.addEventListener(type, listener, options);
10
+ return () => target.removeEventListener(type, listener, options);
11
+ };
12
+
13
+ function anchor_block(el, template, { addScopeToNode, cleanup, initTree, mutateDom, scope = {} }) {
14
+ if (el._r_block) {
15
+ return;
16
+ }
17
+
18
+ initialize();
19
+
20
+ let nodes = is_template(template)
21
+ ? [...template.content.cloneNode(true).childNodes]
22
+ : [template.cloneNode(true)];
23
+
24
+ mutateDom(() => {
25
+ for (let node of nodes) {
26
+ is_element(node) && addScopeToNode(node, scope, el);
27
+ el.parentElement.insertBefore(node, el);
28
+ is_element(node) && initTree(node);
29
+ }
30
+ });
31
+
32
+ el._r_block = {
33
+ template,
34
+ update() {
35
+ mutateDom(() => {
36
+ for (let node of nodes ?? []) {
37
+ el.parentElement.insertBefore(node, el);
38
+ }
39
+ });
40
+ },
41
+ delete() {
42
+ el._r_block = null;
43
+ for (let node of nodes ?? []) {
44
+ node.remove();
45
+ }
46
+ nodes = null;
47
+ }
48
+ };
49
+
50
+ cleanup(() => el._r_block?.delete());
61
51
  }
62
52
 
63
- function plugin({ addScopeToNode, directive, initTree, mutateDom }) {
64
- directive("fragment", (el, {}, { cleanup }) => {
65
- if (!is_template(el)) {
66
- warn("x-fragment can only be used on a 'template' tag");
67
- return;
68
- }
69
-
70
- anchor_block(el, el, { addScopeToNode, cleanup, initTree, mutateDom });
71
- });
53
+ function initialize() {
54
+ document.body._r_block ??= (() => {
55
+ const observer = new MutationObserver(mutations => {
56
+ for (let mutation of mutations) {
57
+ for (let node of mutation.addedNodes) {
58
+ node._r_block?.update();
59
+ }
60
+ }
61
+ });
62
+
63
+ observer.observe(document.body, { childList: true, subtree: true });
64
+ return observer;
65
+ })();
66
+ }
67
+
68
+ function plugin({ addScopeToNode, directive, initTree, mutateDom }) {
69
+ directive("fragment", (el, {}, { cleanup }) => {
70
+ if (!is_template(el)) {
71
+ warn("x-fragment can only be used on a 'template' tag");
72
+ return;
73
+ }
74
+
75
+ anchor_block(el, el, { addScopeToNode, cleanup, initTree, mutateDom });
76
+ });
72
77
  }
73
78
 
74
- document.addEventListener("alpine:init", () => { Alpine.plugin(plugin); });
79
+ listen(document, "alpine:init", () => Alpine.plugin(plugin));
75
80
 
76
81
  })();
@@ -1 +1 @@
1
- !function(){"use strict";const e=e=>e.matches("template"),o=e=>e.nodeType===Node.ELEMENT_NODE;function t({addScopeToNode:t,directive:n,initTree:l,mutateDom:r}){n("fragment",(n,{},{cleanup:d})=>{e(n)?function(t,n,{addScopeToNode:l,cleanup:r,initTree:d,mutateDom:c,scope:a={}}){if(t._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver(e=>{for(let o of e)for(let e of o.addedNodes)e._r_block?.update()});return e.observe(document.body,{childList:!0,subtree:!0}),e})();let i=e(n)?[...n.content.cloneNode(!0).childNodes]:[n.cloneNode(!0)];c(()=>{for(let e of i)o(e)&&l(e,a,t),t.parentElement.insertBefore(e,t),o(e)&&d(e)}),t._r_block={template:n,update(){c(()=>{for(let e of i??[])t.parentElement.insertBefore(e,t)})},delete(){t._r_block=null;for(let e of i??[])e.remove();i=null}},r(()=>t._r_block?.delete())}(n,n,{addScopeToNode:t,cleanup:d,initTree:l,mutateDom:r}):console.warn("alpinegear.js:","x-fragment can only be used on a 'template' tag")})}document.addEventListener("alpine:init",()=>{Alpine.plugin(t)})}();
1
+ !function(){"use strict";const e=e=>e.matches("template"),o=e=>e.nodeType===Node.ELEMENT_NODE;function t({addScopeToNode:t,directive:n,initTree:l,mutateDom:r}){n("fragment",(n,{},{cleanup:d})=>{e(n)?function(t,n,{addScopeToNode:l,cleanup:r,initTree:d,mutateDom:c,scope:a={}}){if(t._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver(e=>{for(let o of e)for(let e of o.addedNodes)e._r_block?.update()});return e.observe(document.body,{childList:!0,subtree:!0}),e})();let i=e(n)?[...n.content.cloneNode(!0).childNodes]:[n.cloneNode(!0)];c(()=>{for(let e of i)o(e)&&l(e,a,t),t.parentElement.insertBefore(e,t),o(e)&&d(e)}),t._r_block={template:n,update(){c(()=>{for(let e of i??[])t.parentElement.insertBefore(e,t)})},delete(){t._r_block=null;for(let e of i??[])e.remove();i=null}},r(()=>t._r_block?.delete())}(n,n,{addScopeToNode:t,cleanup:d,initTree:l,mutateDom:r}):console.warn("alpinegear.js:","x-fragment can only be used on a 'template' tag")})}document.addEventListener("alpine:init",()=>Alpine.plugin(t),void 0)}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramstack/alpinegear-fragment",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "@ramstack/alpinegear-fragment provides 'x-format' Alpine.js directive, allowing for fragment-like behavior similar to what's available in frameworks like 'Vue.js' or 'React', where multiple root elements can be grouped together.",
5
5
  "author": "Rameel Burhan",
6
6
  "license": "MIT",
@@ -18,6 +18,12 @@
18
18
  "alpinejs-plugin",
19
19
  "template"
20
20
  ],
21
- "main": "alpinegear-fragment.js",
22
- "module": "alpinegear-fragment.esm.js"
21
+ "exports": {
22
+ ".": {
23
+ "import": {
24
+ "production": "./alpinegear-fragment.esm.min.js",
25
+ "default": "./alpinegear-fragment.esm.js"
26
+ }
27
+ }
28
+ }
23
29
  }