@ramstack/alpinegear-template 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 +105 -52
  2. package/package.json +6 -2
package/README.md CHANGED
@@ -11,6 +11,10 @@ This helps avoid duplicating templates, simplifying markup and making it easier
11
11
  Moreover, it enables recursive templates, allowing you to create components like a **tree view** with ease,
12
12
  something that would otherwise be quite complex to implement.
13
13
 
14
+ > [!Note]
15
+ > This package is part of the **[`@ramstack/alpinegear-main`](https://www.npmjs.com/package/@ramstack/alpinegear-main)** bundle.
16
+ > If you are using the main bundle, you don't need to install this package separately.
17
+
14
18
  ## Installation
15
19
 
16
20
  ### Using CDN
@@ -21,7 +25,7 @@ To include the CDN version of this plugin, add the following `<script>` tag befo
21
25
  <script src="https://cdn.jsdelivr.net/npm/@ramstack/alpinegear-template@1/alpinegear-template.min.js" defer></script>
22
26
 
23
27
  <!-- alpine.js -->
24
- <script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
28
+ <script src="https://cdn.jsdelivr.net/npm/alpinejs@3/dist/cdn.min.js" defer></script>
25
29
  ```
26
30
 
27
31
  ### Using NPM
@@ -46,24 +50,25 @@ Here's a simple example where the template definition is separated from the main
46
50
 
47
51
  ```html
48
52
  <template id="columns-template">
49
- <td x-text="item.id"></td>
50
- <td x-text="item.name"></td>
51
- <td x-text="item.description"></td>
53
+ <td x-text="item.name"></td>
54
+ <td x-text="item.description"></td>
52
55
  </template>
53
56
 
54
57
  <div x-data="{
55
- items: [
56
- { id: 1, name: 'Item 1', description: 'Description 1' },
57
- { id: 2, name: 'Item 2', description: 'Description 2' },
58
- { id: 3, name: 'Item 3', description: 'Description 3' } ]
59
- }">
60
- <table>
61
- <template x-for="item in items" :key="item.id">
62
- <tr x-template="columns-template"></tr>
63
- </template>
64
- </table>
58
+ items: [
59
+ { name: 'Star', description: 'Luminous plasma sphere.' },
60
+ { name: 'Planet', description: 'Body orbiting a star.' },
61
+ { name: 'Galaxy', description: 'Stars and dust system.' },
62
+ { name: 'Nebula', description: 'Cloud of gas in space.' }
63
+ ]}">
64
+ <table>
65
+ <template x-for="item in items" :key="item.text">
66
+ <tr x-template="columns-template"></tr>
67
+ </template>
68
+ </table>
65
69
  </div>
66
70
  ```
71
+ 🚀 [Live demo | Alpine.js x-template: External template](https://jsfiddle.net/rameel/20boy7rq/)
67
72
 
68
73
  In this example, the table column template is extracted into a separate template (`columns-template`),
69
74
  which is referenced inside the loop.
@@ -87,49 +92,52 @@ Here's an example of rendering a simple file tree using `<ul>` tags:
87
92
 
88
93
  ```html
89
94
  <template id="treeitem">
90
- <span x-format>{{ model.name }}</span>
91
-
92
- <template x-if="model.list">
93
- <ul>
94
- <template x-for="item in model.list">
95
- <li x-template="treeitem" x-data="{ model: item }"></li>
96
- </template>
97
- </ul>
98
- </template>
95
+ <span x-text="model.name"></span>
96
+
97
+ <template x-if="model.list">
98
+ <ul>
99
+ <template x-for="item in model.list">
100
+ <!-- Recursively apply the current template to render nested items -->
101
+ <li x-template="treeitem" x-data="{ model: item }"></li>
102
+ </template>
103
+ </ul>
104
+ </template>
99
105
  </template>
100
106
 
101
107
  <ul x-data="json">
102
- <li x-template="treeitem"></li>
108
+ <li x-template="treeitem"></li>
103
109
  </ul>
110
+
111
+ <script>
112
+ const json = {
113
+ model: {
114
+ name: 'root',
115
+ list: [
116
+ {
117
+ name: 'Documents',
118
+ list: [
119
+ { name: 'Resume.docx' },
120
+ { name: 'CoverLetter.docx' }
121
+ ]
122
+ },
123
+ {
124
+ name: 'Pictures',
125
+ list: [
126
+ {
127
+ name: 'Nature',
128
+ list: [
129
+ { name: 'Mountains.jpg' },
130
+ { name: 'River.jpg' }
131
+ ]
132
+ }
133
+ ]
134
+ }
135
+ ]
136
+ }
137
+ };
138
+ </script>
104
139
  ```
105
- ```js
106
- const json = {
107
- model: {
108
- name: 'root',
109
- list: [
110
- {
111
- name: 'Documents',
112
- list: [
113
- { name: 'Resume.docx' },
114
- { name: 'CoverLetter.docx' }
115
- ]
116
- },
117
- {
118
- name: 'Pictures',
119
- list: [
120
- {
121
- name: 'Nature',
122
- list: [
123
- { name: 'Mountains.jpg' },
124
- { name: 'River.jpg' }
125
- ]
126
- }
127
- ]
128
- }
129
- ]
130
- }
131
- };
132
- ```
140
+ 🚀 [Live demo | Alpine.js x-template: Recursive template (tree rendering)](https://jsfiddle.net/rameel/8envy4o7/)
133
141
 
134
142
  This will generate the following HTML structure:
135
143
 
@@ -145,11 +153,56 @@ This will generate the following HTML structure:
145
153
  As you can see, we are able to render nested elements by recursively referencing the same template within itself,
146
154
  which opens up a lot of possibilities for complex layouts.
147
155
 
156
+ #### Interactive Tree with Recursive Template
157
+
158
+ Explore another example showcasing a recursive `x-template` to render an interactive tree with expandable folders
159
+ and dynamic child addition.
160
+
161
+ 🚀 [Live demo | Alpine.js x-template: Interactive Tree](https://jsfiddle.net/rameel/xwavq1to/)
162
+
163
+
148
164
  ## Source code
149
165
  You can find the source code for this plugin on GitHub:
150
166
 
151
167
  https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/template
152
168
 
169
+ ## Related projects
170
+
171
+ **[@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>
172
+ Provides a combined plugin that includes several useful directives.
173
+ This package aggregates multiple individual plugins, offering a convenient all-in-one bundle.
174
+ Included directives: `x-bound`, `x-format`, `x-fragment`, `x-match`, `x-template`, and `x-when`.
175
+
176
+ **[@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>
177
+ Provides the `x-bound` directive, which allows for two-way binding of input elements and their associated data properties.
178
+ It works similarly to the binding provided by [Svelte](https://svelte.dev/docs/element-directives#bind-property)
179
+ and also supports synchronizing values between two `Alpine.js` data properties.
180
+
181
+ **[@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>
182
+ Provides the `x-format` directive, which allows you to easily interpolate text using a template syntax similar to what's available in `Vue.js`.
183
+
184
+ **[@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>
185
+ Provides the `x-fragment` directive, which allows for fragment-like behavior similar to what's available in frameworks
186
+ like `Vue.js` or `React`, where multiple root elements can be grouped together.
187
+
188
+ **[@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>
189
+ Provides the `x-match` directive, which functions similarly to the `switch` statement in many programming languages,
190
+ allowing you to conditionally render elements based on matching cases.
191
+
192
+ **[@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>
193
+ Provides the `x-when` directive, which allows for conditional rendering of elements similar to `x-if`, but supports multiple root elements.
194
+
195
+ **[@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>
196
+ Provides the `x-destroy` directive, which is the opposite of `x-init` and allows you to hook into the cleanup phase
197
+ of any element, running a callback when the element is removed from the DOM.
198
+
199
+ **[@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>
200
+ Provides the `x-hotkey` directive, which allows you to easily handle keyboard shortcuts within your Alpine.js components or application.
201
+
202
+ **[@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>
203
+ Provides the `x-router` and `x-route` directives, which enable client-side navigation and routing functionality within your Alpine.js application.
204
+
205
+
153
206
  ## Contributions
154
207
  Bug reports and contributions are welcome.
155
208
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramstack/alpinegear-template",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "@ramstack/alpinegear-template provides 'x-template' Alpine.js directive, that enhances template management, providing better control over reusable template blocks, dynamic and recursive component rendering.",
5
5
  "author": "Rameel Burhan",
6
6
  "license": "MIT",
@@ -11,7 +11,11 @@
11
11
  },
12
12
  "keywords": [
13
13
  "alpine.js",
14
- "alpinejs"
14
+ "alpinejs",
15
+ "template",
16
+ "formatting",
17
+ "alpinejs-directive",
18
+ "alpinejs-plugin"
15
19
  ],
16
20
  "main": "alpinegear-template.js",
17
21
  "module": "alpinegear-template.esm.js"