@alpinejs/docs 3.13.10-revision.2 → 3.14.1-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
package/src/en/advanced/csp.md
CHANGED
|
@@ -118,3 +118,26 @@ Alpine.data('counter', () => ({
|
|
|
118
118
|
},
|
|
119
119
|
}))
|
|
120
120
|
```
|
|
121
|
+
|
|
122
|
+
The CSP build supports accessing nested properties (property accessors) using the dot notation.
|
|
123
|
+
|
|
124
|
+
```alpine
|
|
125
|
+
<!-- This works too -->
|
|
126
|
+
<div x-data="counter">
|
|
127
|
+
<button @click="foo.increment">Increment</button>
|
|
128
|
+
|
|
129
|
+
<span x-text="foo.count"></span>
|
|
130
|
+
</div>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
Alpine.data('counter', () => ({
|
|
135
|
+
foo: {
|
|
136
|
+
count: 1,
|
|
137
|
+
|
|
138
|
+
increment() {
|
|
139
|
+
this.count++
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
}))
|
|
143
|
+
```
|
package/src/en/directives/for.md
CHANGED
|
@@ -51,7 +51,7 @@ You may also pass objects to `x-for`.
|
|
|
51
51
|
|
|
52
52
|
There are two rules worth noting about `x-for`:
|
|
53
53
|
|
|
54
|
-
>`x-for` MUST be declared on a `<template>` element
|
|
54
|
+
>`x-for` MUST be declared on a `<template>` element.
|
|
55
55
|
> That `<template>` element MUST contain only one root element
|
|
56
56
|
|
|
57
57
|
<a name="keys"></a>
|
package/src/en/directives/on.md
CHANGED
|
@@ -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
|
|
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
|
|
78
|
-
|
|
|
79
|
-
| `.shift`
|
|
80
|
-
| `.enter`
|
|
81
|
-
| `.space`
|
|
82
|
-
| `.ctrl`
|
|
83
|
-
| `.cmd`
|
|
84
|
-
| `.meta`
|
|
85
|
-
| `.alt`
|
|
86
|
-
| `.up` `.down` `.left` `.right` | Up/Down/Left/Right arrows
|
|
87
|
-
| `.escape`
|
|
88
|
-
| `.tab`
|
|
89
|
-
| `.caps-lock`
|
|
90
|
-
| `.equal`
|
|
91
|
-
| `.period`
|
|
92
|
-
| `.comma`
|
|
93
|
-
| `.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
|
-
<
|
|
24
|
+
<div x-show="open" x-transition>
|
|
25
25
|
Hello 👋
|
|
26
|
-
</
|
|
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
|
-
<
|
|
35
|
+
<div x-show="open" x-transition>
|
|
36
36
|
Hello 👋
|
|
37
|
-
</
|
|
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.
|
|
36
|
+
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.14.1/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
|
|
package/src/en/start-here.md
CHANGED
|
@@ -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
|
-
<
|
|
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 `
|
|
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 `
|
|
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
|
|