@alpinejs/docs 3.10.5-revision.1 → 3.11.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.10.5-revision.1",
3
+ "version": "3.11.0-revision.1",
4
4
  "description": "The documentation for Alpine",
5
5
  "author": "Caleb Porzio",
6
6
  "license": "MIT"
@@ -224,6 +224,24 @@ Alpine.directive('...', (el, {}, { cleanup }) => {
224
224
 
225
225
  Now if the directive is removed from this element or the element is removed itself, the event listener will be removed as well.
226
226
 
227
+ <a name="custom-order"></a>
228
+ ### Custom order
229
+
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 specifing which directive needs to run after your custom one.
232
+
233
+ ```js
234
+ Alpine.directive('foo', (el, { value, modifiers, expression }) => {
235
+ Alpine.addScopeToNode(el, {foo: 'bar'})
236
+ }).before('bind')
237
+ ```
238
+ ```alpine
239
+ <div x-data>
240
+ <span x-foo x-bind:foo="foo"></span>
241
+ </div>
242
+ ```
243
+ > Note, the directive name must be written without the `x-` prefix (or any other custom prefix you may use).
244
+
227
245
  <a name="custom-magics"></a>
228
246
  ## Custom magics
229
247
 
@@ -15,7 +15,13 @@ For `x-cloak` to work however, you must add the following CSS to the page.
15
15
  [x-cloak] { display: none !important; }
16
16
  ```
17
17
 
18
- Now, the following example will hide the `<span>` tag until Alpine has set its text content to the `message` property.
18
+ The following example will hide the `<span>` tag until its `x-show` is specifically set to true, preventing any "blip" of the hidden element onto screen as Alpine loads.
19
+
20
+ ```alpine
21
+ <span x-cloak x-show="false">This will not 'blip' onto screen at any point</span>
22
+ ```
23
+
24
+ `x-cloak` doesn't just work on elements hidden by `x-show` or `x-if`: it also ensures that elements containing data are hidden until the data is correctly set. The following example will hide the `<span>` tag until Alpine has set its text content to the `message` property.
19
25
 
20
26
  ```alpine
21
27
  <span x-cloak x-text="message"></span>
@@ -23,6 +29,8 @@ Now, the following example will hide the `<span>` tag until Alpine has set its t
23
29
 
24
30
  When Alpine loads on the page, it removes all `x-cloak` property from the element, which also removes the `display: none;` applied by CSS, therefore showing the element.
25
31
 
32
+ ## Alternative to global syntax
33
+
26
34
  If you'd like to achieve this same behavior, but avoid having to include a global style, you can use the following cool, but admittedly odd trick:
27
35
 
28
36
  ```alpine
@@ -27,8 +27,8 @@ Alpine's `x-for` directive allows you to create DOM elements by iterating throug
27
27
 
28
28
  There are two rules worth noting about `x-for`:
29
29
 
30
- * `x-for` MUST be declared on a `<template>` element
31
- * That `<template>` element MUST have only one root element
30
+ >`x-for` MUST be declared on a `<template>` element
31
+ > That `<template>` element MUST contain only one root element
32
32
 
33
33
  <a name="keys"></a>
34
34
  ## Keys
@@ -85,3 +85,25 @@ If you need to simply loop `n` number of times, rather than iterate through an a
85
85
  ```
86
86
 
87
87
  `i` in this case can be named anything you like.
88
+
89
+ <a name="contents-of-a-template"></a>
90
+ ## Contents of a `<template>`
91
+
92
+ As mentioned above, an `<template>` tag must contain only one root element.
93
+
94
+ For example, the following code will not work:
95
+
96
+ ```alpine
97
+ <template x-for="color in colors">
98
+ <span>The next color is </span><span x-text="color">
99
+ </template>
100
+ ```
101
+
102
+ but this code will work:
103
+ ```alpine
104
+ <template x-for="color in colors">
105
+ <p>
106
+ <span>The next color is </span><span x-text="color">
107
+ </p>
108
+ </template>
109
+ ```
@@ -89,7 +89,7 @@ For easy reference, here is a list of common keys you may want to listen for.
89
89
  | `.caps-lock` | Caps Lock |
90
90
  | `.equal` | Equal, `=` |
91
91
  | `.period` | Period, `.` |
92
- | `.slash` | Foward Slash, `/` |
92
+ | `.slash` | Forward Slash, `/` |
93
93
 
94
94
  <a name="custom-events"></a>
95
95
  ## Custom events
@@ -22,7 +22,7 @@ This is by far the simplest way to get started with Alpine. Include the followin
22
22
  <head>
23
23
  ...
24
24
 
25
- <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
25
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
26
26
  </head>
27
27
  ...
28
28
  </html>
@@ -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://unpkg.com/alpinejs@3.10.5/dist/cdn.min.js"></script>
36
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.11.0/dist/cdn.min.js"></script>
37
37
  ```
38
38
 
39
39
  That's it! Alpine is now available for use inside your page.
@@ -22,10 +22,10 @@ You can include the CDN build of this plugin as a `<script>` tag, just make sure
22
22
 
23
23
  ```alpine
24
24
  <!-- Alpine Plugins -->
25
- <script defer src="https://unpkg.com/@alpinejs/collapse@3.x.x/dist/cdn.min.js"></script>
25
+ <script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/collapse@3.x.x/dist/cdn.min.js"></script>
26
26
 
27
27
  <!-- Alpine Core -->
28
- <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
28
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
29
29
  ```
30
30
 
31
31
  ### Via NPM
@@ -24,10 +24,10 @@ You can include the CDN build of this plugin as a `<script>` tag, just make sure
24
24
 
25
25
  ```alpine
26
26
  <!-- Alpine Plugins -->
27
- <script defer src="https://unpkg.com/@alpinejs/focus@3.x.x/dist/cdn.min.js"></script>
27
+ <script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/focus@3.x.x/dist/cdn.min.js"></script>
28
28
 
29
29
  <!-- Alpine Core -->
30
- <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
30
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
31
31
  ```
32
32
 
33
33
  ### Via NPM
@@ -309,7 +309,7 @@ This plugin offers many smaller utilities for managing focus within a page. Thes
309
309
  | Property | Description |
310
310
  | --- | --- |
311
311
  | `focus(el)` | Focus the passed element (handling annoyances internally: using nextTick, etc.) |
312
- | `focusable(el)` | Detect weather or not an element is focusable |
312
+ | `focusable(el)` | Detect whether or not an element is focusable |
313
313
  | `focusables()` | Get all "focusable" elements within the current element |
314
314
  | `focused()` | Get the currently focused element on the page |
315
315
  | `lastFocused()` | Get the last focused element on the page |
@@ -22,10 +22,10 @@ You can include the CDN build of this plugin as a `<script>` tag, just make sure
22
22
 
23
23
  ```alpine
24
24
  <!-- Alpine Plugins -->
25
- <script defer src="https://unpkg.com/@alpinejs/intersect@3.x.x/dist/cdn.min.js"></script>
25
+ <script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/intersect@3.x.x/dist/cdn.min.js"></script>
26
26
 
27
27
  <!-- Alpine Core -->
28
- <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
28
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
29
29
  ```
30
30
 
31
31
  ### Via NPM
@@ -152,7 +152,7 @@ If you wanted to trigger only when 5% of the element has entered the viewport, y
152
152
  Allows you to control the `rootMargin` property of the underlying `IntersectionObserver`.
153
153
  This effectively tweaks the size of the viewport boundary. Positive values
154
154
  expand the boundary beyond the viewport, and negative values shrink it inward. The values
155
- work like CSS margin: one value for all sides, two values for top/bottom, left/right, or
155
+ work like CSS margin: one value for all sides; two values for top/bottom, left/right; or
156
156
  four values for top, right, bottom, left. You can use `px` and `%` values, or use a bare number to
157
157
  get a pixel value.
158
158
 
@@ -12,6 +12,7 @@ Alpine's Mask plugin allows you to automatically format a text input field as a
12
12
  This is useful for many different types of inputs: phone numbers, credit cards, dollar amounts, account numbers, dates, etc.
13
13
 
14
14
  <a name="installation"></a>
15
+
15
16
  ## Installation
16
17
 
17
18
  <div x-data="{ expanded: false }">
@@ -27,10 +28,10 @@ You can include the CDN build of this plugin as a `<script>` tag, just make sure
27
28
 
28
29
  ```alpine
29
30
  <!-- Alpine Plugins -->
30
- <script defer src="https://unpkg.com/@alpinejs/mask@3.x.x/dist/cdn.min.js"></script>
31
+ <script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/mask@3.x.x/dist/cdn.min.js"></script>
31
32
 
32
33
  <!-- Alpine Core -->
33
- <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
34
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
34
35
  ```
35
36
 
36
37
  ### Via NPM
@@ -60,6 +61,7 @@ Alpine.plugin(mask)
60
61
  </div>
61
62
 
62
63
  <a name="x-mask"></a>
64
+
63
65
  ## x-mask
64
66
 
65
67
  The primary API for using this plugin is the `x-mask` directive.
@@ -80,13 +82,14 @@ Notice how the text you type into the input field must adhere to the format prov
80
82
 
81
83
  The following wildcard characters are supported in masks:
82
84
 
83
- | Wildcard | Description |
84
- | -------------------------- | --------------------------- |
85
- | `*` | Any character |
86
- | `a` | Only alpha characters (a-z, A-Z) |
87
- | `9` | Only numeric characters (0-9) |
85
+ | Wildcard | Description |
86
+ | -------- | -------------------------------- |
87
+ | `*` | Any character |
88
+ | `a` | Only alpha characters (a-z, A-Z) |
89
+ | `9` | Only numeric characters (0-9) |
88
90
 
89
91
  <a name="mask-functions"></a>
92
+
90
93
  ## Dynamic Masks
91
94
 
92
95
  Sometimes simple mask literals (i.e. `(999) 999-9999`) are not sufficient. In these cases, `x-mask:dynamic` allows you to dynamically generate masks on the fly based on user input.
@@ -113,7 +116,7 @@ Try it for yourself by typing a number that starts with "34" and one that doesn'
113
116
  </div>
114
117
  <!-- END_VERBATIM -->
115
118
 
116
- `x-mask:dynamic` also accepts a function as a result of the expression and will automatically pass it the `$input` as the the first paramter. 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 the first parameter. For example:
117
120
 
118
121
  ```alpine
119
122
  <input x-mask:dynamic="creditCardMask">
@@ -128,6 +131,7 @@ function creditCardMask(input) {
128
131
  ```
129
132
 
130
133
  <a name="money-inputs"></a>
134
+
131
135
  ## Money Inputs
132
136
 
133
137
  Because writing your own dynamic mask expression for money inputs is fairly complex, Alpine offers a prebuilt one and makes it available as `$money()`.
@@ -155,3 +159,15 @@ If you wish to swap the periods for commas and vice versa (as is required in cer
155
159
  <input type="text" x-mask:dynamic="$money($input, ',')" placeholder="0,00">
156
160
  </div>
157
161
  <!-- END_VERBATIM -->
162
+
163
+ You may also choose to override the thousands separator by supplying a third optional argument:
164
+
165
+ ```alpine
166
+ <input x-mask:dynamic="$money($input, '.', ' ')">
167
+ ```
168
+
169
+ <!-- START_VERBATIM -->
170
+ <div class="demo" x-data>
171
+ <input type="text" x-mask:dynamic="$money($input, '.', ' ')" placeholder="3 000.00">
172
+ </div>
173
+ <!-- END_VERBATIM -->
@@ -9,7 +9,7 @@ graph_image: https://alpinejs.dev/social_morph.jpg
9
9
 
10
10
  Alpine's Morph plugin allows you to "morph" an element on the page into the provided HTML template, all while preserving any browser or Alpine state within the "morphed" element.
11
11
 
12
- This is useful for updating HTML from a server request without loosing Alpine's on-page state. A utility like this is at the core of full-stack frameworks like [Laravel Livewire](https://laravel-livewire.com/) and [Phoenix LiveView](https://dockyard.com/blog/2018/12/12/phoenix-liveview-interactive-real-time-apps-no-need-to-write-javascript).
12
+ This is useful for updating HTML from a server request without losing Alpine's on-page state. A utility like this is at the core of full-stack frameworks like [Laravel Livewire](https://laravel-livewire.com/) and [Phoenix LiveView](https://dockyard.com/blog/2018/12/12/phoenix-liveview-interactive-real-time-apps-no-need-to-write-javascript).
13
13
 
14
14
  The best way to understand its purpose is with the following interactive visualization. Give it a try!
15
15
 
@@ -41,10 +41,10 @@ You can include the CDN build of this plugin as a `<script>` tag, just make sure
41
41
 
42
42
  ```alpine
43
43
  <!-- Alpine Plugins -->
44
- <script defer src="https://unpkg.com/@alpinejs/morph@3.x.x/dist/cdn.min.js"></script>
44
+ <script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/morph@3.x.x/dist/cdn.min.js"></script>
45
45
 
46
46
  <!-- Alpine Core -->
47
- <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
47
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
48
48
  ```
49
49
 
50
50
  ### Via NPM
@@ -22,10 +22,10 @@ You can include the CDN build of this plugin as a `<script>` tag, just make sure
22
22
 
23
23
  ```alpine
24
24
  <!-- Alpine Plugins -->
25
- <script defer src="https://unpkg.com/@alpinejs/persist@3.x.x/dist/cdn.min.js"></script>
25
+ <script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/persist@3.x.x/dist/cdn.min.js"></script>
26
26
 
27
27
  <!-- Alpine Core -->
28
- <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
28
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
29
29
  ```
30
30
 
31
31
  ### Via NPM
@@ -204,4 +204,4 @@ Alpine.data('dropdown', function () {
204
204
  Alpine.store('darkMode', {
205
205
  on: Alpine.$persist(true).as('darkMode_on')
206
206
  });
207
- ```
207
+ ```
@@ -12,7 +12,7 @@ Using a text editor, fill the file with these contents:
12
12
  ```alpine
13
13
  <html>
14
14
  <head>
15
- <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
15
+ <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
16
16
  </head>
17
17
  <body>
18
18
  <h1 x-data="{ message: 'I ❤️ Alpine' }" x-text="message"></h1>