@alpinejs/docs 3.13.7-revision.1 → 3.13.8-revision.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpinejs/docs",
3
- "version": "3.13.7-revision.1",
3
+ "version": "3.13.8-revision.2",
4
4
  "description": "The documentation for Alpine",
5
5
  "author": "Caleb Porzio",
6
6
  "license": "MIT"
@@ -379,7 +379,7 @@ By default, if an input has a value attribute, it is ignored by Alpine and inste
379
379
  But if a bound property is empty, then you can use an input's value attribute to populate the property by adding the `.fill` modifier.
380
380
 
381
381
  <div x-data="{ message: null }">
382
- <input x-model.fill="message" value="This is the default message.">
382
+ <input type="text" x-model.fill="message" value="This is the default message.">
383
383
  </div>
384
384
 
385
385
  <a name="programmatic access"></a>
@@ -33,7 +33,7 @@ This is by far the simplest way to get started with Alpine. Include the followin
33
33
  Notice the `@3.x.x` in the provided CDN link. This will pull the latest version of Alpine version 3. For stability in production, it's recommended that you hardcode the latest version in the CDN link.
34
34
 
35
35
  ```alpine
36
- <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.13.7/dist/cdn.min.js"></script>
36
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.13.8/dist/cdn.min.js"></script>
37
37
  ```
38
38
 
39
39
  That's it! Alpine is now available for use inside your page.
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  order: 5
3
3
  title: Anchor
4
- description: Anchor an element's positioning to another element on the pageg
4
+ description: Anchor an element's positioning to another element on the page
5
5
  graph_image: https://alpinejs.dev/social_anchor.jpg
6
6
  ---
7
7
 
8
8
  # Anchor Plugin
9
9
 
10
- Alpine's Anchor plugin allows you easily anchor an element's positioning to another element on the page.
10
+ Alpine's Anchor plugin allows you to easily anchor an element's positioning to another element on the page.
11
11
 
12
12
  This functionality is useful when creating dropdown menus, popovers, dialogs, and tooltips with Alpine.
13
13
 
@@ -56,7 +56,7 @@ The primary API for using this plugin is the `x-anchor` directive.
56
56
 
57
57
  To use this plugin, add the `x-anchor` directive to any element and pass it a reference to the element you want to anchor it's position to (often a button on the page).
58
58
 
59
- By default, `x-anchor` will set the the element's CSS to `position: absolute` and the appropriate `top` and `left` values. If the anchored element is normally displayed below the reference element but doesn't have room on the page, it's styling will be adjusted to render above the element.
59
+ By default, `x-anchor` will set the element's CSS to `position: absolute` and the appropriate `top` and `left` values. If the anchored element is normally displayed below the reference element but doesn't have room on the page, it's styling will be adjusted to render above the element.
60
60
 
61
61
  For example, here's a simple dropdown anchored to the button that toggles it:
62
62
 
@@ -116,7 +116,7 @@ Try it for yourself by typing a number that starts with "34" and one that doesn'
116
116
  </div>
117
117
  <!-- END_VERBATIM -->
118
118
 
119
- `x-mask:dynamic` also accepts a function as a result of the expression and will automatically pass it the `$input` as the the first parameter. For example:
119
+ `x-mask:dynamic` also accepts a function as a result of the expression and will automatically pass it the `$input` as the first parameter. For example:
120
120
 
121
121
  ```alpine
122
122
  <input x-mask:dynamic="creditCardMask">
@@ -0,0 +1,249 @@
1
+ ---
2
+ order: 6
3
+ title: Sort
4
+ description: Easily re-order elements by dragging them with your mouse
5
+ graph_image: https://alpinejs.dev/social_sort.jpg
6
+ ---
7
+
8
+ # Sort Plugin
9
+
10
+ Alpine's Sort plugin allows you to easily re-order elements by dragging them with your mouse.
11
+
12
+ This functionality is useful for things like Kanban boards, to-do lists, sortable table columns, etc.
13
+
14
+ The drag functionality used in this plugin is provided by the [SortableJS](https://github.com/SortableJS/Sortable) project.
15
+
16
+ <a name="installation"></a>
17
+ ## Installation
18
+
19
+ You can use this plugin by either including it from a `<script>` tag or installing it via NPM:
20
+
21
+ ### Via CDN
22
+
23
+ You can include the CDN build of this plugin as a `<script>` tag; just make sure to include it BEFORE Alpine's core JS file.
24
+
25
+ ```alpine
26
+ <!-- Alpine Plugins -->
27
+ <script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/sort@3.x.x/dist/cdn.min.js"></script>
28
+
29
+ <!-- Alpine Core -->
30
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
31
+ ```
32
+
33
+ ### Via NPM
34
+
35
+ You can install Anchor from NPM for use inside your bundle like so:
36
+
37
+ ```shell
38
+ npm install @alpinejs/sort
39
+ ```
40
+
41
+ Then initialize it from your bundle:
42
+
43
+ ```js
44
+ import Alpine from 'alpinejs'
45
+ import sort from '@alpinejs/sort'
46
+
47
+ Alpine.plugin(sort)
48
+
49
+ ...
50
+ ```
51
+
52
+ <a name="basic-usage"></a>
53
+ ## Basic usage
54
+
55
+ The primary API for using this plugin is the `x-sort` directive. By adding `x-sort` to an element, its children become sortable—meaning you can drag them around with your mouse, and they will change positions.
56
+
57
+ ```alpine
58
+ <ul x-sort>
59
+ <li>foo</li>
60
+ <li>bar</li>
61
+ <li>baz</li>
62
+ </ul>
63
+ ```
64
+
65
+ <!-- START_VERBATIM -->
66
+ <div x-data>
67
+ <ul x-sort>
68
+ <li>foo</li>
69
+ <li>bar</li>
70
+ <li>baz</li>
71
+ </ul>
72
+ </div>
73
+ <!-- END_VERBATIM -->
74
+
75
+ <a name="sort-handlers"></a>
76
+ ## Sort handlers
77
+
78
+ You can react to sorting changes by passing a handler function to `x-sort` and adding keys to each item using `x-sort:key`. Here is an example of a simple handler function that shows an alert dialog with the changed item's key and its new position:
79
+
80
+ ```alpine
81
+ <div x-data="{ handle(key, position) { alert(key + ' - ' + position)} }">
82
+ <ul x-sort="handle">
83
+ <li x-sort:key="1">foo</li>
84
+ <li x-sort:key="2">bar</li>
85
+ <li x-sort:key="3">baz</li>
86
+ </ul>
87
+ </div>
88
+ ```
89
+
90
+ <!-- START_VERBATIM -->
91
+ <div x-data="{ handle(key, position) { alert(key + ' - ' + position)} }">
92
+ <ul x-sort="handle">
93
+ <li x-sort:key="1">foo</li>
94
+ <li x-sort:key="2">bar</li>
95
+ <li x-sort:key="3">baz</li>
96
+ </ul>
97
+ </div>
98
+ <!-- END_VERBATIM -->
99
+
100
+ As you can see, the `key` and `position` parameters are passed into the handler function on every sorting change. The `key` parameter is the value provided to `x-sort:key`, and the `position` parameter is its new position in the list of children (starting at index `0`).
101
+
102
+ Handler functions are often used to persist the new order of items in the database so that the sorting order of a list is preserved between page refreshes.
103
+
104
+ <a name="sorting-groups"></a>
105
+ ## Sorting groups
106
+
107
+ This plugin allows you to drag items from one `x-sort` sortable list into another one by adding a matching `.group` modifier to both lists:
108
+
109
+ ```alpine
110
+ <div>
111
+ <ul x-sort.group.todos>
112
+ <li x-sort:key="1">foo</li>
113
+ <li x-sort:key="2">bar</li>
114
+ <li x-sort:key="3">baz</li>
115
+ </ul>
116
+
117
+ <ol x-sort.group.todos>
118
+ <li x-sort:key="1">foo</li>
119
+ <li x-sort:key="2">bar</li>
120
+ <li x-sort:key="3">baz</li>
121
+ </ol>
122
+ </div>
123
+ ```
124
+
125
+ Because both sortable lists above use the same group name (`todos`), you can drag items from one list onto another.
126
+
127
+ > When using sort handlers like `x-sort="handle"` and dragging an item from one group to another, only the destination lists handler will be called with the key and new position.
128
+
129
+ <a name="drag-handles"></a>
130
+ ## Drag handles
131
+
132
+ By default, each child element of `x-sort` is draggable by clicking and dragging anywhere within it. However, you may want to designate a smaller, more specific element as the "drag handle" so that the rest of the element can be interacted with like normal, and only the handle will respond to mouse dragging:
133
+
134
+ ```alpine
135
+ <ul x-sort>
136
+ <li>
137
+ <span x-sort:handle> - </span>foo
138
+ </li>
139
+
140
+ <li>
141
+ <span x-sort:handle> - </span>bar
142
+ </li>
143
+
144
+ <li>
145
+ <span x-sort:handle> - </span>baz
146
+ </li>
147
+ </ul>
148
+ ```
149
+
150
+ <!-- START_VERBATIM -->
151
+ <div x-data>
152
+ <ul x-sort>
153
+ <li>
154
+ <span x-sort:handle> - </span>foo
155
+ </li>
156
+ <li>
157
+ <span x-sort:handle> - </span>bar
158
+ </li>
159
+ <li>
160
+ <span x-sort:handle> - </span>baz
161
+ </li>
162
+ </ul>
163
+ </div>
164
+ <!-- END_VERBATIM -->
165
+
166
+ As you can see in the above example, the hyphen "-" is draggable, but the item text ("foo") is not.
167
+
168
+ <a name="ghost-elements"></a>
169
+ ## Ghost elements
170
+
171
+ When a user drags an item, the element will follow their mouse to appear as though they are physically dragging the element.
172
+
173
+ By default, a "hole" (empty space) will be left in the original element's place during the drag.
174
+
175
+ If you would like to show a "ghost" of the original element in its place instead of an empty space, you can add the `.ghost` modifier to `x-sort`:
176
+
177
+ ```alpine
178
+ <ul x-sort.ghost>
179
+ <li>foo</li>
180
+ <li>bar</li>
181
+ <li>baz</li>
182
+ </ul>
183
+ ```
184
+
185
+ <!-- START_VERBATIM -->
186
+ <div x-data>
187
+ <ul x-sort.ghost>
188
+ <li>foo</li>
189
+ <li>bar</li>
190
+ <li>baz</li>
191
+ </ul>
192
+ </div>
193
+ <!-- END_VERBATIM -->
194
+
195
+ <a name="ghost-styling"></a>
196
+ ### Styling the ghost element
197
+
198
+ By default, the "ghost" element has a `.sortable-ghost` CSS class attached to it while the original element is being dragged.
199
+
200
+ This makes it easy to add any custom styling you would like:
201
+
202
+ ```alpine
203
+ <style>
204
+ .sortable-ghost {
205
+ opacity: .5 !important;
206
+ }
207
+ </style>
208
+
209
+ <ul x-sort.ghost>
210
+ <li>foo</li>
211
+ <li>bar</li>
212
+ <li>baz</li>
213
+ </ul>
214
+ ```
215
+
216
+ <!-- START_VERBATIM -->
217
+ <div x-data>
218
+ <ul x-sort.ghost x-sort:config="{ ghostClass: 'opacity-50' }">
219
+ <li>foo</li>
220
+ <li>bar</li>
221
+ <li>baz</li>
222
+ </ul>
223
+ </div>
224
+ <!-- END_VERBATIM -->
225
+
226
+ <a name="custom-configuration"></a>
227
+ ## Custom configuration
228
+
229
+ Alpine chooses sensible defaults for configuring [SortableJS](https://github.com/SortableJS/Sortable?tab=readme-ov-file#options) under the hood. However, you can add or override any of these options yourself using `x-sort:config`:
230
+
231
+ ```alpine
232
+ <ul x-sort x-sort:config="{ filter: '.no-drag' }">
233
+ <li>foo</li>
234
+ <li class="no-drag">bar (not dragable)</li>
235
+ <li>baz</li>
236
+ </ul>
237
+ ```
238
+
239
+ <!-- START_VERBATIM -->
240
+ <div x-data>
241
+ <ul x-sort x-sort:config="{ filter: '.no-drag' }">
242
+ <li>foo</li>
243
+ <li class="no-drag">bar (not dragable)</li>
244
+ <li>baz</li>
245
+ </ul>
246
+ </div>
247
+ <!-- END_VERBATIM -->
248
+
249
+ [View the full list of SortableJS configuration options here →](https://github.com/SortableJS/Sortable?tab=readme-ov-file#options)