@alpinejs/docs 3.11.1-revision.1 → 3.12.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 +1 -1
- package/src/en/advanced/csp.md +2 -2
- package/src/en/advanced/extending.md +1 -1
- package/src/en/directives/bind.md +5 -5
- package/src/en/directives/data.md +3 -3
- package/src/en/directives/model.md +11 -0
- package/src/en/directives/on.md +15 -2
- package/src/en/essentials/installation.md +6 -6
- package/src/en/essentials/lifecycle.md +1 -1
- package/src/en/plugins/mask.md +14 -1
- package/src/en/ui.md +0 -6
package/package.json
CHANGED
package/src/en/advanced/csp.md
CHANGED
|
@@ -9,12 +9,12 @@ In order for Alpine to be able to execute plain strings from HTML attributes as
|
|
|
9
9
|
|
|
10
10
|
> Under the hood, Alpine doesn't actually use eval() itself because it's slow and problematic. Instead it uses Function declarations, which are much better, but still violate "unsafe-eval".
|
|
11
11
|
|
|
12
|
-
In order to accommodate environments where this CSP is necessary, Alpine
|
|
12
|
+
In order to accommodate environments where this CSP is necessary, Alpine will offer an alternate build that doesn't violate "unsafe-eval", but has a more restrictive syntax.
|
|
13
13
|
|
|
14
14
|
<a name="installation"></a>
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
The CSP build hasn’t been officially released yet. In the meantime, you may [build it from source](https://github.com/alpinejs/alpine/tree/main/packages/csp). Once released, like all Alpine extensions, you will be able to include this either via `<script>` tag or module import:
|
|
18
18
|
|
|
19
19
|
<a name="script-tag"></a>
|
|
20
20
|
### Script tag
|
|
@@ -228,7 +228,7 @@ Now if the directive is removed from this element or the element is removed itse
|
|
|
228
228
|
### Custom order
|
|
229
229
|
|
|
230
230
|
By default, any new directive will run after the majority of the standard ones (with the exception of `x-teleport`). This is usually acceptable but some times you might need to run your custom directive before another specific one.
|
|
231
|
-
This can be achieved by chaining the `.before() function to `Alpine.directive()` and
|
|
231
|
+
This can be achieved by chaining the `.before() function to `Alpine.directive()` and specifying which directive needs to run after your custom one.
|
|
232
232
|
|
|
233
233
|
```js
|
|
234
234
|
Alpine.directive('foo', (el, { value, modifiers, expression }) => {
|
|
@@ -11,7 +11,7 @@ For example, here's a component where we will use `x-bind` to set the placeholde
|
|
|
11
11
|
|
|
12
12
|
```alpine
|
|
13
13
|
<div x-data="{ placeholder: 'Type here...' }">
|
|
14
|
-
|
|
14
|
+
<input type="text" x-bind:placeholder="placeholder">
|
|
15
15
|
</div>
|
|
16
16
|
```
|
|
17
17
|
|
|
@@ -33,11 +33,11 @@ Here's a simple example of a simple dropdown toggle, but instead of using `x-sho
|
|
|
33
33
|
|
|
34
34
|
```alpine
|
|
35
35
|
<div x-data="{ open: false }">
|
|
36
|
-
|
|
36
|
+
<button x-on:click="open = ! open">Toggle Dropdown</button>
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
<div :class="open ? '' : 'hidden'">
|
|
39
|
+
Dropdown Contents...
|
|
40
|
+
</div>
|
|
41
41
|
</div>
|
|
42
42
|
```
|
|
43
43
|
|
|
@@ -86,9 +86,9 @@ Let's refactor our component to use a getter called `isOpen` instead of accessin
|
|
|
86
86
|
|
|
87
87
|
```alpine
|
|
88
88
|
<div x-data="{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
open: false,
|
|
90
|
+
get isOpen() { return this.open },
|
|
91
|
+
toggle() { this.open = ! this.open },
|
|
92
92
|
}">
|
|
93
93
|
<button @click="toggle()">Toggle Content</button>
|
|
94
94
|
|
|
@@ -337,6 +337,17 @@ The default throttle interval is 250 milliseconds, you can easily customize this
|
|
|
337
337
|
<input type="text" x-model.throttle.500ms="search">
|
|
338
338
|
```
|
|
339
339
|
|
|
340
|
+
<a name="fill"></a>
|
|
341
|
+
### `.fill`
|
|
342
|
+
|
|
343
|
+
By default, if an input has a value attribute, it is ignored by Alpine and instead, the value of the input is set to the value of the property bound using `x-model`.
|
|
344
|
+
|
|
345
|
+
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.
|
|
346
|
+
|
|
347
|
+
<div x-data="{ message: null }">
|
|
348
|
+
<input x-model.fill="message" value="This is the default message.">
|
|
349
|
+
</div>
|
|
350
|
+
|
|
340
351
|
<a name="programmatic access"></a>
|
|
341
352
|
## Programmatic access
|
|
342
353
|
|
package/src/en/directives/on.md
CHANGED
|
@@ -100,7 +100,7 @@ Here's an example of a component that dispatches a custom DOM event and listens
|
|
|
100
100
|
|
|
101
101
|
```alpine
|
|
102
102
|
<div x-data @foo="alert('Button Was Clicked!')">
|
|
103
|
-
|
|
103
|
+
<button @click="$event.target.dispatchEvent(new CustomEvent('foo', { bubbles: true }))">...</button>
|
|
104
104
|
</div>
|
|
105
105
|
```
|
|
106
106
|
|
|
@@ -112,7 +112,7 @@ Here's the same component re-written with the `$dispatch` magic property.
|
|
|
112
112
|
|
|
113
113
|
```alpine
|
|
114
114
|
<div x-data @foo="alert('Button Was Clicked!')">
|
|
115
|
-
|
|
115
|
+
<button @click="$dispatch('foo')">...</button>
|
|
116
116
|
</div>
|
|
117
117
|
```
|
|
118
118
|
|
|
@@ -298,3 +298,16 @@ If you are listening for touch events, it's important to add `.passive` to your
|
|
|
298
298
|
```
|
|
299
299
|
|
|
300
300
|
[→ Read more about passive listeners](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners)
|
|
301
|
+
|
|
302
|
+
### .capture
|
|
303
|
+
|
|
304
|
+
Add this modifier if you want to execute this listener in the event's capturing phase, e.g. before the event bubbles from the target element up the DOM.
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
<div @click.capture="console.log('I will log first')">
|
|
308
|
+
<button @click="console.log('I will log second')"></button>
|
|
309
|
+
</div>
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
[→ Read more about the capturing and bubbling phase of events](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#usecapture)
|
|
313
|
+
|
|
@@ -19,12 +19,12 @@ This is by far the simplest way to get started with Alpine. Include the followin
|
|
|
19
19
|
|
|
20
20
|
```alpine
|
|
21
21
|
<html>
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
<head>
|
|
23
|
+
...
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
|
|
26
|
+
</head>
|
|
27
|
+
...
|
|
28
28
|
</html>
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -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.
|
|
36
|
+
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.12.1/dist/cdn.min.js"></script>
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
That's it! Alpine is now available for use inside your page.
|
|
@@ -87,7 +87,7 @@ document.addEventListener('alpine:init', () => {
|
|
|
87
87
|
<a name="alpine-initialized"></a>
|
|
88
88
|
### `alpine:initialized`
|
|
89
89
|
|
|
90
|
-
Alpine also offers a hook that you can use to execute code
|
|
90
|
+
Alpine also offers a hook that you can use to execute code AFTER it's done initializing called `alpine:initialized`:
|
|
91
91
|
|
|
92
92
|
```js
|
|
93
93
|
document.addEventListener('alpine:initialized', () => {
|
package/src/en/plugins/mask.md
CHANGED
|
@@ -58,7 +58,7 @@ Alpine.plugin(mask)
|
|
|
58
58
|
<button :aria-expanded="expanded" @click="expanded = ! expanded" class="text-cyan-600 font-medium underline">
|
|
59
59
|
<span x-text="expanded ? 'Hide' : 'Show more'">Show</span> <span x-text="expanded ? '↑' : '↓'">↓</span>
|
|
60
60
|
</button>
|
|
61
|
-
|
|
61
|
+
</div>
|
|
62
62
|
|
|
63
63
|
<a name="x-mask"></a>
|
|
64
64
|
|
|
@@ -171,3 +171,16 @@ You may also choose to override the thousands separator by supplying a third opt
|
|
|
171
171
|
<input type="text" x-mask:dynamic="$money($input, '.', ' ')" placeholder="3 000.00">
|
|
172
172
|
</div>
|
|
173
173
|
<!-- END_VERBATIM -->
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
You can also override the default precision of 2 digits by using any desired number of digits as the fourth optional argument:
|
|
177
|
+
|
|
178
|
+
```alpine
|
|
179
|
+
<input x-mask:dynamic="$money($input, '.', ',', 4)">
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
<!-- START_VERBATIM -->
|
|
183
|
+
<div class="demo" x-data>
|
|
184
|
+
<input type="text" x-mask:dynamic="$money($input, '.', ',', 4)" placeholder="0.0001">
|
|
185
|
+
</div>
|
|
186
|
+
<!-- END_VERBATIM -->
|