@alpinejs/docs 3.13.8-revision.3 → 3.13.9-revision.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpinejs/docs",
3
- "version": "3.13.8-revision.3",
3
+ "version": "3.13.9-revision.1",
4
4
  "description": "The documentation for Alpine",
5
5
  "author": "Caleb Porzio",
6
6
  "license": "MIT"
@@ -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.8/dist/cdn.min.js"></script>
36
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.13.9/dist/cdn.min.js"></script>
37
37
  ```
38
38
 
39
39
  That's it! Alpine is now available for use inside your page.
@@ -66,7 +66,7 @@ Notice that, because of [event bubbling](https://en.wikipedia.org/wiki/Event_bub
66
66
  </div>
67
67
  ```
68
68
 
69
- > The first example won't work because when `custom-event` is dispatched, it'll propagate to its common ancestor, the `div`, not its sibling, the `<span>`. The second example will work because the sibling is listening for `notify` at the `window` level, which the custom event will eventually bubble up to.
69
+ > The first example won't work because when `notify` is dispatched, it'll propagate to its common ancestor, the `div`, not its sibling, the `<span>`. The second example will work because the sibling is listening for `notify` at the `window` level, which the custom event will eventually bubble up to.
70
70
 
71
71
  <a name="dispatching-to-components"></a>
72
72
  ## Dispatching to other components
@@ -52,22 +52,22 @@ Alpine.plugin(sort)
52
52
  <a name="basic-usage"></a>
53
53
  ## Basic usage
54
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.
55
+ The primary API for using this plugin is the `x-sort` directive. By adding `x-sort` to an element, its children containing `x-sort:item` become sortable—meaning you can drag them around with your mouse, and they will change positions.
56
56
 
57
57
  ```alpine
58
58
  <ul x-sort>
59
- <li>foo</li>
60
- <li>bar</li>
61
- <li>baz</li>
59
+ <li x-sort:item>foo</li>
60
+ <li x-sort:item>bar</li>
61
+ <li x-sort:item>baz</li>
62
62
  </ul>
63
63
  ```
64
64
 
65
65
  <!-- START_VERBATIM -->
66
66
  <div x-data>
67
67
  <ul x-sort>
68
- <li>foo</li>
69
- <li>bar</li>
70
- <li>baz</li>
68
+ <li x-sort:item>foo</li>
69
+ <li x-sort:item>bar</li>
70
+ <li x-sort:item>baz</li>
71
71
  </ul>
72
72
  </div>
73
73
  <!-- END_VERBATIM -->
@@ -75,36 +75,36 @@ The primary API for using this plugin is the `x-sort` directive. By adding `x-so
75
75
  <a name="sort-handlers"></a>
76
76
  ## Sort handlers
77
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:
78
+ You can react to sorting changes by passing a handler function to `x-sort` and adding keys to each item using `x-sort:item`. 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
79
 
80
80
  ```alpine
81
- <ul x-sort="alert($key + ' - ' + $position)">
82
- <li x-sort:key="1">foo</li>
83
- <li x-sort:key="2">bar</li>
84
- <li x-sort:key="3">baz</li>
81
+ <ul x-sort="alert($item + ' - ' + $position)">
82
+ <li x-sort:item="1">foo</li>
83
+ <li x-sort:item="2">bar</li>
84
+ <li x-sort:item="3">baz</li>
85
85
  </ul>
86
86
  ```
87
87
 
88
88
  <!-- START_VERBATIM -->
89
89
  <div x-data>
90
- <ul x-sort="alert($key + ' - ' + $position)">
91
- <li x-sort:key="1">foo</li>
92
- <li x-sort:key="2">bar</li>
93
- <li x-sort:key="3">baz</li>
90
+ <ul x-sort="alert($item + ' - ' + $position)">
91
+ <li x-sort:item="1">foo</li>
92
+ <li x-sort:item="2">bar</li>
93
+ <li x-sort:item="3">baz</li>
94
94
  </ul>
95
95
  </div>
96
96
  <!-- END_VERBATIM -->
97
97
 
98
- The `x-sort` handler will be called every time the sort order of the items change. The `$key` magic will contain the key of the sorted element (derived from `x-sort:key`), and `$position` will contain the new position of the item (staring at index `0`).
98
+ The `x-sort` handler will be called every time the sort order of the items change. The `$item` magic will contain the key of the sorted element (derived from `x-sort:item`), and `$position` will contain the new position of the item (staring at index `0`).
99
99
 
100
- You can also pass a handler function to `x-sort` and that function will receive the `key` and `position` as the first and second parameter:
100
+ You can also pass a handler function to `x-sort` and that function will receive the `item` and `position` as the first and second parameter:
101
101
 
102
102
  ```alpine
103
- <div x-data="{ handle: (key, position) => { ... } }">
103
+ <div x-data="{ handle: (item, position) => { ... } }">
104
104
  <ul x-sort="handle">
105
- <li x-sort:key="1">foo</li>
106
- <li x-sort:key="2">bar</li>
107
- <li x-sort:key="3">baz</li>
105
+ <li x-sort:item="1">foo</li>
106
+ <li x-sort:item="2">bar</li>
107
+ <li x-sort:item="3">baz</li>
108
108
  </ul>
109
109
  </div>
110
110
  ```
@@ -114,44 +114,44 @@ Handler functions are often used to persist the new order of items in the databa
114
114
  <a name="sorting-groups"></a>
115
115
  ## Sorting groups
116
116
 
117
- 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:
117
+ This plugin allows you to drag items from one `x-sort` sortable list into another one by adding a matching `x-sort:group` value to both lists:
118
118
 
119
119
  ```alpine
120
120
  <div>
121
- <ul x-sort.group.todos>
122
- <li x-sort:key="1">foo</li>
123
- <li x-sort:key="2">bar</li>
124
- <li x-sort:key="3">baz</li>
121
+ <ul x-sort x-sort:group="todos">
122
+ <li x-sort:item="1">foo</li>
123
+ <li x-sort:item="2">bar</li>
124
+ <li x-sort:item="3">baz</li>
125
125
  </ul>
126
126
 
127
- <ol x-sort.group.todos>
128
- <li x-sort:key="1">foo</li>
129
- <li x-sort:key="2">bar</li>
130
- <li x-sort:key="3">baz</li>
127
+ <ol x-sort x-sort:group="todos">
128
+ <li x-sort:item="4">foo</li>
129
+ <li x-sort:item="5">bar</li>
130
+ <li x-sort:item="6">baz</li>
131
131
  </ol>
132
132
  </div>
133
133
  ```
134
134
 
135
135
  Because both sortable lists above use the same group name (`todos`), you can drag items from one list onto another.
136
136
 
137
- > 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.
137
+ > When using sort handlers like `x-sort="handle"` and dragging an item from one group to another, only the destination list's handler will be called with the key and new position.
138
138
 
139
139
  <a name="drag-handles"></a>
140
140
  ## Drag handles
141
141
 
142
- 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:
142
+ By default, each `x-sort:item` element 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:
143
143
 
144
144
  ```alpine
145
145
  <ul x-sort>
146
- <li>
146
+ <li x-sort:item>
147
147
  <span x-sort:handle> - </span>foo
148
148
  </li>
149
149
 
150
- <li>
150
+ <li x-sort:item>
151
151
  <span x-sort:handle> - </span>bar
152
152
  </li>
153
153
 
154
- <li>
154
+ <li x-sort:item>
155
155
  <span x-sort:handle> - </span>baz
156
156
  </li>
157
157
  </ul>
@@ -160,13 +160,13 @@ By default, each child element of `x-sort` is draggable by clicking and dragging
160
160
  <!-- START_VERBATIM -->
161
161
  <div x-data>
162
162
  <ul x-sort>
163
- <li>
163
+ <li x-sort:item>
164
164
  <span x-sort:handle> - </span>foo
165
165
  </li>
166
- <li>
166
+ <li x-sort:item>
167
167
  <span x-sort:handle> - </span>bar
168
168
  </li>
169
- <li>
169
+ <li x-sort:item>
170
170
  <span x-sort:handle> - </span>baz
171
171
  </li>
172
172
  </ul>
@@ -186,18 +186,18 @@ If you would like to show a "ghost" of the original element in its place instead
186
186
 
187
187
  ```alpine
188
188
  <ul x-sort.ghost>
189
- <li>foo</li>
190
- <li>bar</li>
191
- <li>baz</li>
189
+ <li x-sort:item>foo</li>
190
+ <li x-sort:item>bar</li>
191
+ <li x-sort:item>baz</li>
192
192
  </ul>
193
193
  ```
194
194
 
195
195
  <!-- START_VERBATIM -->
196
196
  <div x-data>
197
197
  <ul x-sort.ghost>
198
- <li>foo</li>
199
- <li>bar</li>
200
- <li>baz</li>
198
+ <li x-sort:item>foo</li>
199
+ <li x-sort:item>bar</li>
200
+ <li x-sort:item>baz</li>
201
201
  </ul>
202
202
  </div>
203
203
  <!-- END_VERBATIM -->
@@ -217,18 +217,96 @@ This makes it easy to add any custom styling you would like:
217
217
  </style>
218
218
 
219
219
  <ul x-sort.ghost>
220
- <li>foo</li>
221
- <li>bar</li>
222
- <li>baz</li>
220
+ <li x-sort:item>foo</li>
221
+ <li x-sort:item>bar</li>
222
+ <li x-sort:item>baz</li>
223
223
  </ul>
224
224
  ```
225
225
 
226
226
  <!-- START_VERBATIM -->
227
227
  <div x-data>
228
228
  <ul x-sort.ghost x-sort:config="{ ghostClass: 'opacity-50' }">
229
- <li>foo</li>
230
- <li>bar</li>
231
- <li>baz</li>
229
+ <li x-sort:item>foo</li>
230
+ <li x-sort:item>bar</li>
231
+ <li x-sort:item>baz</li>
232
+ </ul>
233
+ </div>
234
+ <!-- END_VERBATIM -->
235
+
236
+ <a name="sorting-class"></a>
237
+ ## Sorting class on body
238
+
239
+ While an element is being dragged around, Alpine will automatically add a `.sorting` class to the `<body>` element of the page.
240
+
241
+ This is useful for styling any element on the page conditionally using only CSS.
242
+
243
+ For example you could have a warning that only displays while a user is sorting items:
244
+
245
+ ```html
246
+ <div id="sort-warning">
247
+ Page functionality is limited while sorting
248
+ </div>
249
+ ```
250
+
251
+ To show this only while sorting, you can use the `body.sorting` CSS selector:
252
+
253
+ ```css
254
+ #sort-warning {
255
+ display: none;
256
+ }
257
+
258
+ body.sorting #sort-warning {
259
+ display: block;
260
+ }
261
+ ```
262
+
263
+ <a name="css-hover-bug"></a>
264
+ ## CSS hover bug
265
+
266
+ Currently, there is a [bug in Chrome and Safari](https://issues.chromium.org/issues/41129937) (not Firefox) that causes issues with hover styles.
267
+
268
+ Consider HTML like the following, where each item in the list is styled differently based on a hover state (here we're using Tailwind's `.hover` class to conditionally add a border):
269
+
270
+ ```html
271
+ <div x-sort>
272
+ <div x-sort:item class="hover:border">foo</div>
273
+ <div x-sort:item class="hover:border">bar</div>
274
+ <div x-sort:item class="hover:border">baz</div>
275
+ </div>
276
+ ```
277
+
278
+ If you drag one of the elements in the list below you will see that the hover effect will be errantly applied to any element in the original element's place:
279
+
280
+ <!-- START_VERBATIM -->
281
+ <div x-data>
282
+ <ul x-sort class="flex flex-col items-start">
283
+ <li x-sort:item class="hover:border border-black">foo</li>
284
+ <li x-sort:item class="hover:border border-black">bar</li>
285
+ <li x-sort:item class="hover:border border-black">baz</li>
286
+ </ul>
287
+ </div>
288
+ <!-- END_VERBATIM -->
289
+
290
+ To fix this, you can leverage the `.sorting` class applied to the body while sorting to limit the hover effect to only be applied while `.sorting` does NOT exist on `body`.
291
+
292
+ Here is how you can do this directly inline using Tailwind arbitrary variants:
293
+
294
+ ```html
295
+ <div x-sort>
296
+ <div x-sort:item class="[body:not(.sorting)_&]:hover:border">foo</div>
297
+ <div x-sort:item class="[body:not(.sorting)_&]:hover:border">bar</div>
298
+ <div x-sort:item class="[body:not(.sorting)_&]:hover:border">baz</div>
299
+ </div>
300
+ ```
301
+
302
+ Now you can see below that the hover effect is only applied to the dragging element and not the others in the list.
303
+
304
+ <!-- START_VERBATIM -->
305
+ <div x-data>
306
+ <ul x-sort class="flex flex-col items-start">
307
+ <li x-sort:item class="[body:not(.sorting)_&]:hover:border border-black">foo</li>
308
+ <li x-sort:item class="[body:not(.sorting)_&]:hover:border border-black">bar</li>
309
+ <li x-sort:item class="[body:not(.sorting)_&]:hover:border border-black">baz</li>
232
310
  </ul>
233
311
  </div>
234
312
  <!-- END_VERBATIM -->
@@ -239,21 +317,23 @@ This makes it easy to add any custom styling you would like:
239
317
  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`:
240
318
 
241
319
  ```alpine
242
- <ul x-sort x-sort:config="{ filter: '.no-drag' }">
243
- <li>foo</li>
244
- <li class="no-drag">bar (not dragable)</li>
245
- <li>baz</li>
320
+ <ul x-sort x-sort:config="{ animation: 0 }">
321
+ <li x-sort:item>foo</li>
322
+ <li x-sort:item>bar</li>
323
+ <li x-sort:item>baz</li>
246
324
  </ul>
247
325
  ```
248
326
 
249
327
  <!-- START_VERBATIM -->
250
328
  <div x-data>
251
- <ul x-sort x-sort:config="{ filter: '.no-drag' }">
252
- <li>foo</li>
253
- <li class="no-drag">bar (not dragable)</li>
254
- <li>baz</li>
329
+ <ul x-sort x-sort:config="{ animation: 0 }">
330
+ <li x-sort:item>foo</li>
331
+ <li x-sort:item>bar</li>
332
+ <li x-sort:item>baz</li>
255
333
  </ul>
256
334
  </div>
257
335
  <!-- END_VERBATIM -->
258
336
 
337
+ > Any config options passed will overwrite Alpine defaults. In this case of `animation`, this is fine, however be aware that overwriting `handle`, `group`, `filter`, `onSort`, `onStart`, or `onEnd` may break functionality.
338
+
259
339
  [View the full list of SortableJS configuration options here →](https://github.com/SortableJS/Sortable?tab=readme-ov-file#options)