@ramstack/alpinegear-fragment 1.2.3 → 1.2.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.
Files changed (2) hide show
  1. package/README.md +76 -24
  2. package/package.json +7 -2
package/README.md CHANGED
@@ -6,6 +6,9 @@
6
6
 
7
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
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.
9
12
 
10
13
  ## Installation
11
14
 
@@ -17,7 +20,7 @@ To include the CDN version of this plugin, add the following `<script>` tag befo
17
20
  <script src="https://cdn.jsdelivr.net/npm/@ramstack/alpinegear-fragment@1/alpinegear-fragment.min.js" defer></script>
18
21
 
19
22
  <!-- alpine.js -->
20
- <script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
23
+ <script src="https://cdn.jsdelivr.net/npm/alpinejs@3/dist/cdn.min.js" defer></script>
21
24
  ```
22
25
 
23
26
  ### Using NPM
@@ -41,47 +44,96 @@ Alpine.start();
41
44
  With the `x-fragment` directive, you can use multiple root elements in your components without needing a wrapper container:
42
45
 
43
46
  ```html
44
- <div x-data="{ show: true, message: 'Example' }">
45
- <div>
46
- <button @click="show = !show">Edit Message</button>
47
- </div>
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>
48
53
 
49
54
  <template x-if="show">
50
- <template x-fragment>
51
- <label>Message:</label>
52
- <input x-model="message" />
53
- </template>
55
+ <template x-fragment>
56
+ <li>Orange</li>
57
+ <li>Grape</li>
58
+ <li>Mango</li>
59
+ </template>
54
60
  </template>
61
+ </ul>
55
62
  </div>
56
63
  ```
57
- In this example, the `x-fragment` directive allows the `<label>` and `<input>` elements to exist side by side without a parent container.
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.
58
68
 
59
69
  ### Using with `x-for`
60
- The `x-fragment` directive can also be used with the directive `x-for`, giving you the flexibility to render multiple sibling elements for each iteration without wrapping them:
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:
61
72
 
62
73
  ```html
63
74
  <div x-data="{
64
- items: [
65
- { id: 1, term: 'Item 1', description: 'Description 1' },
66
- { id: 2, term: 'Item 2', description: 'Description 2' },
67
- { id: 3, term: 'Item 3', description: 'Description 3' } ]
68
- }">
69
- <dl>
70
- <template x-for="item in items" :key="item.id">
71
- <template x-fragment>
72
- <dt x-text="item.term"></dt>
73
- <dd x-text="item.description"></dd>
74
- </template>
75
- </template>
76
- </dl>
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>
77
91
  </div>
78
92
  ```
93
+ 🚀 [Live demo | Alpine.js x-fragment: Multiple root elements with x-for](https://jsfiddle.net/rameel/201rmntc/)
79
94
 
80
95
  ## Source code
81
96
  You can find the source code for this plugin on GitHub:
82
97
 
83
98
  https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/fragment
84
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
+
85
137
  ## Contributions
86
138
  Bug reports and contributions are welcome.
87
139
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramstack/alpinegear-fragment",
3
- "version": "1.2.3",
3
+ "version": "1.2.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",
@@ -11,7 +11,12 @@
11
11
  },
12
12
  "keywords": [
13
13
  "alpine.js",
14
- "alpinejs"
14
+ "alpinejs",
15
+ "fragment",
16
+ "alpinejs-fragment",
17
+ "alpinejs-directive",
18
+ "alpinejs-plugin",
19
+ "template"
15
20
  ],
16
21
  "main": "alpinegear-fragment.js",
17
22
  "module": "alpinegear-fragment.esm.js"