@ramstack/alpinegear-main 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,145 @@
1
+ # @ramstack/alpinegear-main
2
+
3
+ `@ramstack/alpinegear-main` is a combined plugin for [Alpine.js](https://alpinejs.dev/) that includes several useful directives. This plugin aggregates multiple individual plugins, providing a convenient all-in-one package.
4
+
5
+ ## Included Plugins
6
+
7
+ **[@ramstack/alpinegear-bound](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/bound)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/bound))<br>
8
+ Provides the `x-bound` directive, which allows for two-way binding of input elements and their associated data properties. It works similarly to the binding provided by [Svelte](https://svelte.dev/docs/element-directives#bind-property) and also supports synchronizing values between two `Alpine.js` data properties.
9
+
10
+ ```html
11
+ <div x-data="{ width: 0, height: 0, files: [] }">
12
+ <input &files="files" type="file" accept="image/jpeg" />
13
+
14
+ <img &naturalwidth="width" &naturalheight="height" src="..." />
15
+
16
+ ...
17
+
18
+ For other examples, see README
19
+
20
+ </div>
21
+ ```
22
+
23
+
24
+ **[@ramstack/alpinegear-format](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/format)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/format))<br>
25
+ Provides `x-format` directive, which allows you to easily interpolate text using a template syntax similar to what's available in `Vue.js`.
26
+
27
+ ```html
28
+ <div x-data="{ message: 'Hello, World!'}" x-format>
29
+ <span>Message: {{ message }}</span>
30
+ </div>
31
+ ```
32
+
33
+
34
+ **[@ramstack/alpinegear-template](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/template)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/template))<br>
35
+ Provides `x-template` directive, allowing to define a template once anywhere in the DOM and reference it by its ID.
36
+
37
+ This helps avoid duplicating templates, simplifying markup and making it easier to manage.
38
+
39
+ Moreover, it enables recursive templates, allowing you to create components like a **tree view** with ease,
40
+ something that would otherwise be quite complex to implement.
41
+
42
+ ```html
43
+ <template id="treeitem">
44
+ <span x-format>{{ model.name }}</span>
45
+
46
+ <template x-if="model.list">
47
+ <ul>
48
+ <template x-for="item in model.list">
49
+ <li x-template="treeitem" x-data="{ model: item }"></li>
50
+ </template>
51
+ </ul>
52
+ </template>
53
+ </template>
54
+
55
+ <ul x-data="json">
56
+ <li x-template="treeitem"></li>
57
+ </ul>
58
+ ```
59
+
60
+
61
+ **[@ramstack/alpinegear-fragment](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/fragment)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/fragment))<br>
62
+ Provides the `x-fragment` 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.
63
+
64
+ It is particularly useful when you want to avoid wrapping elements in unnecessary container tags.
65
+
66
+ ```html
67
+ <dl>
68
+ <template x-for="item in items" :key="item.id">
69
+ <template x-fragment>
70
+ <dt x-text="item.term"></dt>
71
+ <dd x-text="item.description"></dd>
72
+ </template>
73
+ </template>
74
+ </dl>
75
+ ```
76
+
77
+
78
+ **[@ramstack/alpinegear-match](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/match)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/match))<br>
79
+ Provides the `x-match` directive, which functions similarly to the `switch` statement in many programming languages, allowing to conditionally render elements based on matching cases.
80
+
81
+ ```html
82
+ <template x-for="n in numbers">
83
+ <template x-match>
84
+ <div x-case="n % 3 == 0 && n % 5 == 0">Fizz Buzz</div>
85
+ <div x-case="n % 3 == 0">Fizz</div>
86
+ <div x-case="n % 5 == 0">Buzz</div>
87
+ <div x-default x-text="n"></div>
88
+ </template>
89
+ </template>
90
+ ```
91
+
92
+
93
+ **[@ramstack/alpinegear-when](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/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
+ ```html
97
+ <template x-for="item in items" :key="item.id">
98
+ <template x-when="item.visible">
99
+ <dt x-text="item.term"></dt>
100
+ <dd x-text="item.description"></dd>
101
+ </template>
102
+ </template>
103
+ ```
104
+
105
+ ## Installation
106
+
107
+ ### Using CDN
108
+ To include the CDN version of this plugin, add the following `<script>` tag before the core `alpine.js` file:
109
+
110
+ ```html
111
+ <!-- alpine.js plugin -->
112
+ <script src="https://cdn.jsdelivr.net/npm/@ramstack/alpinegear-main@1/dist/alpinegear-main.min.js" defer></script>
113
+
114
+ <!-- alpine.js -->
115
+ <script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
116
+ ```
117
+
118
+ ### Using NPM
119
+ Alternatively, you can install the plugin via `npm`:
120
+
121
+ ```bash
122
+ npm install --save @ramstack/alpinegear-main
123
+ ```
124
+
125
+ Then initialize it in your bundle:
126
+
127
+ ```js
128
+ import Alpine from "alpinejs";
129
+ import main from "@ramstack/alpinegear-main";
130
+
131
+ Alpine.plugin(main);
132
+ Alpine.start();
133
+ ```
134
+
135
+ ## Source Code
136
+ You can find the source code for this plugin on GitHub:
137
+
138
+ https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/main
139
+
140
+ ## Contributions
141
+ Bug reports and contributions are welcome.
142
+
143
+ ## License
144
+ This package is released as open source under the **MIT License**.
145
+ See the [LICENSE](https://github.com/rameel/ramstack.alpinegear.js/blob/main/LICENSE) file for more details.