@alpinejs/docs 3.13.10-revision.1 → 3.14.0-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.10-revision.1",
3
+ "version": "3.14.0-revision.1",
4
4
  "description": "The documentation for Alpine",
5
5
  "author": "Caleb Porzio",
6
6
  "license": "MIT"
@@ -13,7 +13,7 @@ Here's an example of simple button that shows an alert when clicked.
13
13
  <button x-on:click="alert('Hello World!')">Say Hi</button>
14
14
  ```
15
15
 
16
- > `x-on` can only listen for events with lower case names, as HTML attributes are case-insensitive. Writing `x-on:CLICK` will listen for an event named `click`. If you need to listen for a custom event with a camelCase name, you can use the [`.camel` helper](#camel) to work around this limitation. Alternatively, you can use [`x-bind`](/directives/bind#bind-directives) to attach an `x-on` directive to an element in javascript code (where case will be preserved).
16
+ > `x-on` can only listen for events with lower case names, as HTML attributes are case-insensitive. Writing `x-on:CLICK` will listen for an event named `click`. If you need to listen for a custom event with a camelCase name, you can use the [`.camel` helper](#camel) to work around this limitation. Alternatively, you can use [`x-bind`](/directives/bind#bind-directives) to attach an `x-on` directive to an element in javascript code (where case will be preserved).
17
17
 
18
18
  <a name="shorthand-syntax"></a>
19
19
  ## Shorthand syntax
@@ -74,23 +74,64 @@ You can directly use any valid key names exposed via [`KeyboardEvent.key`](https
74
74
 
75
75
  For easy reference, here is a list of common keys you may want to listen for.
76
76
 
77
- | Modifier | Keyboard Key |
78
- | -------------------------- | --------------------------- |
79
- | `.shift` | Shift |
80
- | `.enter` | Enter |
81
- | `.space` | Space |
82
- | `.ctrl` | Ctrl |
83
- | `.cmd` | Cmd |
84
- | `.meta` | Cmd on Mac, Windows key on Windows |
85
- | `.alt` | Alt |
86
- | `.up` `.down` `.left` `.right` | Up/Down/Left/Right arrows |
87
- | `.escape` | Escape |
88
- | `.tab` | Tab |
89
- | `.caps-lock` | Caps Lock |
90
- | `.equal` | Equal, `=` |
91
- | `.period` | Period, `.` |
92
- | `.comma` | Comma, `,` |
93
- | `.slash` | Forward Slash, `/` |
77
+ | Modifier | Keyboard Key |
78
+ | ------------------------------ | ---------------------------------- |
79
+ | `.shift` | Shift |
80
+ | `.enter` | Enter |
81
+ | `.space` | Space |
82
+ | `.ctrl` | Ctrl |
83
+ | `.cmd` | Cmd |
84
+ | `.meta` | Cmd on Mac, Windows key on Windows |
85
+ | `.alt` | Alt |
86
+ | `.up` `.down` `.left` `.right` | Up/Down/Left/Right arrows |
87
+ | `.escape` | Escape |
88
+ | `.tab` | Tab |
89
+ | `.caps-lock` | Caps Lock |
90
+ | `.equal` | Equal, `=` |
91
+ | `.period` | Period, `.` |
92
+ | `.comma` | Comma, `,` |
93
+ | `.slash` | Forward Slash, `/` |
94
+
95
+ <a name="mouse-events"></a>
96
+ ## Mouse events
97
+
98
+ Like the above Keyboard Events, Alpine allows the use of some key modifiers for handling `click` events.
99
+
100
+ | Modifier | Event Key |
101
+ | -------- | --------- |
102
+ | `.shift` | shiftKey |
103
+ | `.ctrl` | ctrlKey |
104
+ | `.cmd` | metaKey |
105
+ | `.meta` | metaKey |
106
+ | `.alt` | altKey |
107
+
108
+ These work on `click`, `auxclick`, `context` and `dblclick` events, and even `mouseover`, `mousemove`, `mouseenter`, `mouseleave`, `mouseout`, `mouseup` and `mousedown`.
109
+
110
+ Here's an example of a button that changes behaviour when the `Shift` key is held down.
111
+
112
+ ```alpine
113
+ <button type="button"
114
+ @click="message = 'selected'"
115
+ @click.shift="message = 'added to selection'">
116
+ @mousemove.shift="message = 'add to selection'"
117
+ @mouseout="message = 'select'"
118
+ x-text="message"></button>
119
+ ```
120
+
121
+ <!-- START_VERBATIM -->
122
+ <div class="demo">
123
+ <div x-data="{ message: '' }">
124
+ <button type="button"
125
+ @click="message = 'selected'"
126
+ @click.shift="message = 'added to selection'"
127
+ @mousemove.shift="message = 'add to selection'"
128
+ @mouseout="message = 'select'"
129
+ x-text="message"></button>
130
+ </div>
131
+ </div>
132
+ <!-- END_VERBATIM -->
133
+
134
+ > Note: Normal click events with some modifiers (like `ctrl`) will automatically become `contextmenu` events in most browsers. Similarly, `right-click` events will trigger a `contextmenu` event, but will also trigger an `auxclick` event if the `contextmenu` event is prevented.
94
135
 
95
136
  <a name="custom-events"></a>
96
137
  ## Custom events
@@ -311,4 +352,3 @@ Add this modifier if you want to execute this listener in the event's capturing
311
352
  ```
312
353
 
313
354
  [→ Read more about the capturing and bubbling phase of events](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#usecapture)
314
-
@@ -21,9 +21,9 @@ The simplest way to achieve a transition using Alpine is by adding `x-transition
21
21
  <div x-data="{ open: false }">
22
22
  <button @click="open = ! open">Toggle</button>
23
23
 
24
- <span x-show="open" x-transition>
24
+ <div x-show="open" x-transition>
25
25
  Hello 👋
26
- </span>
26
+ </div>
27
27
  </div>
28
28
  ```
29
29
 
@@ -32,9 +32,9 @@ The simplest way to achieve a transition using Alpine is by adding `x-transition
32
32
  <div x-data="{ open: false }">
33
33
  <button @click="open = ! open">Toggle</button>
34
34
 
35
- <span x-show="open" x-transition>
35
+ <div x-show="open" x-transition>
36
36
  Hello 👋
37
- </span>
37
+ </div>
38
38
  </div>
39
39
  </div>
40
40
  <!-- END_VERBATIM -->
@@ -33,11 +33,13 @@ 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.10/dist/cdn.min.js"></script>
36
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.14.0/dist/cdn.min.js"></script>
37
37
  ```
38
38
 
39
39
  That's it! Alpine is now available for use inside your page.
40
40
 
41
+ Note that you will still need to define a component with `x-data` in order for any Alpine.js attributes to work. See <https://github.com/alpinejs/alpine/discussions/3805> for more information.
42
+
41
43
  <a name="as-a-module"></a>
42
44
  ## As a module
43
45
 
@@ -65,9 +65,9 @@ The primary API for using this plugin is the `x-sort` directive. By adding `x-so
65
65
  <!-- START_VERBATIM -->
66
66
  <div x-data>
67
67
  <ul x-sort>
68
- <li x-sort:item>foo</li>
69
- <li x-sort:item>bar</li>
70
- <li x-sort:item>baz</li>
68
+ <li x-sort:item class="cursor-pointer">foo</li>
69
+ <li x-sort:item class="cursor-pointer">bar</li>
70
+ <li x-sort:item class="cursor-pointer">baz</li>
71
71
  </ul>
72
72
  </div>
73
73
  <!-- END_VERBATIM -->
@@ -88,9 +88,9 @@ You can react to sorting changes by passing a handler function to `x-sort` and a
88
88
  <!-- START_VERBATIM -->
89
89
  <div x-data>
90
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>
91
+ <li x-sort:item="1" class="cursor-pointer">foo</li>
92
+ <li x-sort:item="2" class="cursor-pointer">bar</li>
93
+ <li x-sort:item="3" class="cursor-pointer">baz</li>
94
94
  </ul>
95
95
  </div>
96
96
  <!-- END_VERBATIM -->
@@ -161,13 +161,13 @@ By default, each `x-sort:item` element is draggable by clicking and dragging any
161
161
  <div x-data>
162
162
  <ul x-sort>
163
163
  <li x-sort:item>
164
- <span x-sort:handle> - </span>foo
164
+ <span x-sort:handle class="cursor-pointer"> - </span>foo
165
165
  </li>
166
166
  <li x-sort:item>
167
- <span x-sort:handle> - </span>bar
167
+ <span x-sort:handle class="cursor-pointer"> - </span>bar
168
168
  </li>
169
169
  <li x-sort:item>
170
- <span x-sort:handle> - </span>baz
170
+ <span x-sort:handle class="cursor-pointer"> - </span>baz
171
171
  </li>
172
172
  </ul>
173
173
  </div>
@@ -195,9 +195,9 @@ If you would like to show a "ghost" of the original element in its place instead
195
195
  <!-- START_VERBATIM -->
196
196
  <div x-data>
197
197
  <ul x-sort.ghost>
198
- <li x-sort:item>foo</li>
199
- <li x-sort:item>bar</li>
200
- <li x-sort:item>baz</li>
198
+ <li x-sort:item class="cursor-pointer">foo</li>
199
+ <li x-sort:item class="cursor-pointer">bar</li>
200
+ <li x-sort:item class="cursor-pointer">baz</li>
201
201
  </ul>
202
202
  </div>
203
203
  <!-- END_VERBATIM -->
@@ -226,9 +226,9 @@ This makes it easy to add any custom styling you would like:
226
226
  <!-- START_VERBATIM -->
227
227
  <div x-data>
228
228
  <ul x-sort.ghost x-sort:config="{ ghostClass: 'opacity-50' }">
229
- <li x-sort:item>foo</li>
230
- <li x-sort:item>bar</li>
231
- <li x-sort:item>baz</li>
229
+ <li x-sort:item class="cursor-pointer">foo</li>
230
+ <li x-sort:item class="cursor-pointer">bar</li>
231
+ <li x-sort:item class="cursor-pointer">baz</li>
232
232
  </ul>
233
233
  </div>
234
234
  <!-- END_VERBATIM -->
@@ -280,9 +280,9 @@ If you drag one of the elements in the list below you will see that the hover ef
280
280
  <!-- START_VERBATIM -->
281
281
  <div x-data>
282
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>
283
+ <li x-sort:item class="hover:border border-black cursor-pointer">foo</li>
284
+ <li x-sort:item class="hover:border border-black cursor-pointer">bar</li>
285
+ <li x-sort:item class="hover:border border-black cursor-pointer">baz</li>
286
286
  </ul>
287
287
  </div>
288
288
  <!-- END_VERBATIM -->
@@ -304,9 +304,9 @@ Now you can see below that the hover effect is only applied to the dragging elem
304
304
  <!-- START_VERBATIM -->
305
305
  <div x-data>
306
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>
307
+ <li x-sort:item class="[body:not(.sorting)_&]:hover:border border-black cursor-pointer">foo</li>
308
+ <li x-sort:item class="[body:not(.sorting)_&]:hover:border border-black cursor-pointer">bar</li>
309
+ <li x-sort:item class="[body:not(.sorting)_&]:hover:border border-black cursor-pointer">baz</li>
310
310
  </ul>
311
311
  </div>
312
312
  <!-- END_VERBATIM -->
@@ -327,9 +327,9 @@ Alpine chooses sensible defaults for configuring [SortableJS](https://github.com
327
327
  <!-- START_VERBATIM -->
328
328
  <div x-data>
329
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>
330
+ <li x-sort:item class="cursor-pointer">foo</li>
331
+ <li x-sort:item class="cursor-pointer">bar</li>
332
+ <li x-sort:item class="cursor-pointer">baz</li>
333
333
  </ul>
334
334
  </div>
335
335
  <!-- END_VERBATIM -->
@@ -96,14 +96,14 @@ When a `click` event happens, Alpine will call the associated JavaScript express
96
96
  ### Reacting to changes
97
97
 
98
98
  ```alpine
99
- <h1 x-text="count"></h1>
99
+ <span x-text="count"></span>
100
100
  ```
101
101
 
102
102
  `x-text` is an Alpine directive you can use to set the text content of an element to the result of a JavaScript expression.
103
103
 
104
- In this case, we're telling Alpine to always make sure that the contents of this `h1` tag reflect the value of the `count` property.
104
+ In this case, we're telling Alpine to always make sure that the contents of this `span` tag reflect the value of the `count` property.
105
105
 
106
- In case it's not clear, `x-text`, like most directives accepts a plain JavaScript expression as an argument. So for example, you could instead set its contents to: `x-text="count * 2"` and the text content of the `h1` will now always be 2 times the value of `count`.
106
+ In case it's not clear, `x-text`, like most directives accepts a plain JavaScript expression as an argument. So for example, you could instead set its contents to: `x-text="count * 2"` and the text content of the `span` will now always be 2 times the value of `count`.
107
107
 
108
108
  [→ Read more about `x-text`](/directives/text)
109
109