@markuplint/alpine-spec 5.0.0-alpha.0
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/ARCHITECTURE.md +123 -0
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/SKILL.md +64 -0
- package/docs/maintenance.ja.md +76 -0
- package/docs/maintenance.md +76 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +283 -0
- package/package.json +30 -0
package/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# @markuplint/alpine-spec
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`@markuplint/alpine-spec` is a spec extension package that provides Alpine.js-specific directive definitions for markuplint. It exports a single `ExtendedSpec` object that registers global Alpine.js directives (such as `x-data`, `x-show`, `x-bind`, `x-on`, `x-model`, `x-text`, `x-html`, `x-ref`, `x-if`, `x-for`, `x-transition`, `x-effect`, `x-ignore`, `x-cloak`, etc.) available on every HTML element.
|
|
6
|
+
|
|
7
|
+
This package contains no parsing logic -- it is purely a data definition consumed by `@markuplint/ml-spec` to extend the base HTML specification with Alpine.js-specific attributes.
|
|
8
|
+
|
|
9
|
+
## ExtendedSpec Content
|
|
10
|
+
|
|
11
|
+
### Global Attributes
|
|
12
|
+
|
|
13
|
+
Global attributes are defined under `def['#globalAttrs']['#extends']` and are available on every HTML element:
|
|
14
|
+
|
|
15
|
+
#### Component Initialization
|
|
16
|
+
|
|
17
|
+
| Attribute | Type | Description |
|
|
18
|
+
| --------- | ----- | ---------------------------------------------------------------- |
|
|
19
|
+
| `x-data` | `Any` | Declares an Alpine component and defines its reactive data scope |
|
|
20
|
+
| `x-init` | `Any` | Hooks into the initialization phase |
|
|
21
|
+
|
|
22
|
+
#### Rendering & Visibility
|
|
23
|
+
|
|
24
|
+
| Attribute | Type | Description |
|
|
25
|
+
| --------- | ----- | --------------------------------------------------- |
|
|
26
|
+
| `x-show` | `Any` | Toggles element visibility via CSS display property |
|
|
27
|
+
| `x-if` | `Any` | Conditionally adds/removes elements from the DOM |
|
|
28
|
+
| `x-for` | `Any` | Renders elements by iterating over collections |
|
|
29
|
+
|
|
30
|
+
#### Content Binding
|
|
31
|
+
|
|
32
|
+
| Attribute | Type | Description |
|
|
33
|
+
| --------- | ----- | ----------------------------------- |
|
|
34
|
+
| `x-text` | `Any` | Sets the textContent of the element |
|
|
35
|
+
| `x-html` | `Any` | Sets the innerHTML of the element |
|
|
36
|
+
|
|
37
|
+
#### Data Binding
|
|
38
|
+
|
|
39
|
+
| Attribute | Type | Description |
|
|
40
|
+
| ------------- | ----- | ----------------------------------------------------------- |
|
|
41
|
+
| `x-model` | `Any` | Creates two-way data binding between form elements and data |
|
|
42
|
+
| `x-modelable` | `Any` | Exposes a property as the target of an outer x-model |
|
|
43
|
+
|
|
44
|
+
#### Reactivity
|
|
45
|
+
|
|
46
|
+
| Attribute | Type | Description |
|
|
47
|
+
| ---------- | ----- | -------------------------------------------------------------- |
|
|
48
|
+
| `x-effect` | `Any` | Reactively re-evaluates an expression when dependencies change |
|
|
49
|
+
|
|
50
|
+
#### DOM Manipulation & References
|
|
51
|
+
|
|
52
|
+
| Attribute | Type | Description |
|
|
53
|
+
| ------------ | ----- | ------------------------------------------------- |
|
|
54
|
+
| `x-ref` | `Any` | Marks an element for access via $refs |
|
|
55
|
+
| `x-teleport` | `Any` | Moves DOM content to another location in the page |
|
|
56
|
+
| `x-id` | `Any` | Declares a scope for auto-generated IDs via $id() |
|
|
57
|
+
|
|
58
|
+
#### Transitions
|
|
59
|
+
|
|
60
|
+
| Attribute | Type | Description |
|
|
61
|
+
| -------------------------- | ----- | ------------------------------------- |
|
|
62
|
+
| `x-transition` | `Any` | Applies CSS transition animations |
|
|
63
|
+
| `x-transition:enter` | `Any` | CSS classes for the entering phase |
|
|
64
|
+
| `x-transition:enter-start` | `Any` | CSS classes before element insertion |
|
|
65
|
+
| `x-transition:enter-end` | `Any` | CSS classes after element insertion |
|
|
66
|
+
| `x-transition:leave` | `Any` | CSS classes for the leaving phase |
|
|
67
|
+
| `x-transition:leave-start` | `Any` | CSS classes when leaving is triggered |
|
|
68
|
+
| `x-transition:leave-end` | `Any` | CSS classes after leave starts |
|
|
69
|
+
|
|
70
|
+
#### Processing Control
|
|
71
|
+
|
|
72
|
+
| Attribute | Type | Description |
|
|
73
|
+
| ---------- | --------- | ------------------------------------------------------------------- |
|
|
74
|
+
| `x-ignore` | `Boolean` | Prevents Alpine from initializing the element |
|
|
75
|
+
| `x-cloak` | `Boolean` | Hidden until Alpine initializes; prevents flash of unstyled content |
|
|
76
|
+
|
|
77
|
+
## Directory Structure
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
src/
|
|
81
|
+
└── index.ts — Exports the ExtendedSpec object with Alpine.js-specific attributes
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Key Source Files
|
|
85
|
+
|
|
86
|
+
| File | Purpose |
|
|
87
|
+
| ---------- | ------------------------------------------------------------------- |
|
|
88
|
+
| `index.ts` | Defines and exports the `ExtendedSpec` object as the default export |
|
|
89
|
+
|
|
90
|
+
## Integration Points
|
|
91
|
+
|
|
92
|
+
```mermaid
|
|
93
|
+
flowchart LR
|
|
94
|
+
subgraph upstream ["Upstream"]
|
|
95
|
+
htmlSpec["@markuplint/html-spec\n(Base HTML spec)"]
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
subgraph pkg ["@markuplint/alpine-spec"]
|
|
99
|
+
spec["ExtendedSpec\n(Alpine.js directives)"]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
subgraph downstream ["Downstream"]
|
|
103
|
+
mlSpec["@markuplint/ml-spec\n(Spec resolution)"]
|
|
104
|
+
mlCore["@markuplint/ml-core\n(Linting engine)"]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
htmlSpec -->|"Base spec"| mlSpec
|
|
108
|
+
spec -->|"Extends"| mlSpec
|
|
109
|
+
mlSpec -->|"Resolved spec"| mlCore
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Upstream
|
|
113
|
+
|
|
114
|
+
- **`@markuplint/ml-spec`** -- Provides the `ExtendedSpec` type that this package implements
|
|
115
|
+
|
|
116
|
+
### Downstream
|
|
117
|
+
|
|
118
|
+
- **`@markuplint/ml-spec`** -- Consumes the `ExtendedSpec` object to merge Alpine.js-specific attributes into the resolved specification
|
|
119
|
+
- **`@markuplint/ml-core`** -- Uses the resolved spec (including Alpine.js extensions) during linting
|
|
120
|
+
|
|
121
|
+
## Documentation Map
|
|
122
|
+
|
|
123
|
+
- [Maintenance Guide](docs/maintenance.md) -- Commands, recipes, and ExtendedSpec type reference
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [5.0.0-alpha.0](https://github.com/markuplint/markuplint/compare/v4.14.1...v5.0.0-alpha.0) (2026-02-20)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- add @markuplint/htmx-spec and @markuplint/alpine-spec packages ([75f5cd6](https://github.com/markuplint/markuplint/commit/75f5cd68e33ef3a53483254c2956f8c07ec235b6))
|
|
11
|
+
- delete htmx-parser, simplify alpine-parser, add migration guide and tests ([f8dbb09](https://github.com/markuplint/markuplint/commit/f8dbb090707d8cfbf3d859a9b868b2087064f89b))
|
|
12
|
+
- **ml-spec:** add declarative directivePatterns for parser-less framework support ([ceb9aa6](https://github.com/markuplint/markuplint/commit/ceb9aa67048e3a058b40a9e4d91eb903c8ff1861))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2024 Yusuke Hirao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @markuplint/alpine-spec
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@markuplint/alpine-spec)
|
|
4
|
+
|
|
5
|
+
Use **markuplint** with [**Alpine.js**](https://alpinejs.dev/).
|
|
6
|
+
Add Alpine.js specific directives to the schema.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```shell
|
|
11
|
+
$ npm install -D @markuplint/alpine-spec
|
|
12
|
+
|
|
13
|
+
$ yarn add -D @markuplint/alpine-spec
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Add `specs` option to your [configuration](https://markuplint.dev/configuration/#properties/specs).
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"specs": {
|
|
23
|
+
"\\.html$": "@markuplint/alpine-spec"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Maintenance tasks for @markuplint/alpine-spec
|
|
3
|
+
globs:
|
|
4
|
+
- packages/@markuplint/alpine-spec/src/**/*.ts
|
|
5
|
+
alwaysApply: false
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# alpine-spec-maintenance
|
|
9
|
+
|
|
10
|
+
Perform maintenance tasks for `@markuplint/alpine-spec`: add global attributes
|
|
11
|
+
and modify the ExtendedSpec object.
|
|
12
|
+
|
|
13
|
+
## Input
|
|
14
|
+
|
|
15
|
+
`$ARGUMENTS` specifies the task. Supported tasks:
|
|
16
|
+
|
|
17
|
+
| Task | Description |
|
|
18
|
+
| ---------------------- | ---------------------------------------------- |
|
|
19
|
+
| `add-global-attribute` | Add a new global attribute to the ExtendedSpec |
|
|
20
|
+
|
|
21
|
+
If omitted, defaults to `add-global-attribute`.
|
|
22
|
+
|
|
23
|
+
## Reference
|
|
24
|
+
|
|
25
|
+
Before executing any task, read `docs/maintenance.md` (or `docs/maintenance.ja.md`)
|
|
26
|
+
for the full guide. The recipes there are the source of truth for procedures.
|
|
27
|
+
|
|
28
|
+
Also read:
|
|
29
|
+
|
|
30
|
+
- `ARCHITECTURE.md` -- Package overview, ExtendedSpec content, and integration points
|
|
31
|
+
- `src/index.ts` -- ExtendedSpec object definition (source of truth)
|
|
32
|
+
|
|
33
|
+
## Task: add-global-attribute
|
|
34
|
+
|
|
35
|
+
Add a new global Alpine.js directive available on every HTML element. Follow recipe #1 in `docs/maintenance.md`.
|
|
36
|
+
|
|
37
|
+
### Step 1: Identify the attribute
|
|
38
|
+
|
|
39
|
+
1. Determine the directive name, type (`Any`, `Boolean`, or a specific type), and description
|
|
40
|
+
2. Check the Alpine.js documentation to confirm the directive is valid
|
|
41
|
+
|
|
42
|
+
### Step 2: Add the attribute
|
|
43
|
+
|
|
44
|
+
1. Read `src/index.ts`
|
|
45
|
+
2. Add a new entry under `def['#globalAttrs']['#extends']`:
|
|
46
|
+
```ts
|
|
47
|
+
'x-directiveName': {
|
|
48
|
+
type: 'Any', // or 'Boolean'
|
|
49
|
+
},
|
|
50
|
+
```
|
|
51
|
+
3. Add a JSDoc comment above the entry describing its purpose
|
|
52
|
+
|
|
53
|
+
### Step 3: Verify
|
|
54
|
+
|
|
55
|
+
1. Build: `yarn build --scope @markuplint/alpine-spec`
|
|
56
|
+
2. Confirm the attribute appears in the exported spec object
|
|
57
|
+
|
|
58
|
+
## Rules
|
|
59
|
+
|
|
60
|
+
1. **Only export an ExtendedSpec object** -- this package contains no parsing logic.
|
|
61
|
+
2. **All Alpine.js directives are global** -- they go under `def['#globalAttrs']['#extends']`.
|
|
62
|
+
3. **Alpine.js directives are prefixed with `x-`** -- follow this naming convention.
|
|
63
|
+
4. **Each attribute needs at minimum a `type` field** -- valid types include `Any`, `Boolean`, and specific type strings.
|
|
64
|
+
5. **Add JSDoc comments** to all new attribute entries describing their purpose.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# メンテナンスガイド
|
|
2
|
+
|
|
3
|
+
## コマンド
|
|
4
|
+
|
|
5
|
+
| コマンド | 説明 |
|
|
6
|
+
| -------------------------------------------- | ---------------------- |
|
|
7
|
+
| `yarn build --scope @markuplint/alpine-spec` | このパッケージをビルド |
|
|
8
|
+
| `yarn dev --scope @markuplint/alpine-spec` | ウォッチモードでビルド |
|
|
9
|
+
| `yarn clean --scope @markuplint/alpine-spec` | ビルド成果物を削除 |
|
|
10
|
+
|
|
11
|
+
## テスト
|
|
12
|
+
|
|
13
|
+
このパッケージには専用のテストスイートはありません。`ExtendedSpec` オブジェクトは、`@markuplint/ml-spec` の `ExtendedSpec` 型に対する TypeScript 型チェックにより、ビルド時に検証されます。エクスポートされたオブジェクトが型に適合しない場合、ビルドが失敗します。
|
|
14
|
+
|
|
15
|
+
統合テストは下流で行われます:
|
|
16
|
+
|
|
17
|
+
- `@markuplint/ml-spec` が拡張仕様を解決し、基本 HTML 仕様とマージ
|
|
18
|
+
- `@markuplint/ml-core` がリント時に解決済み仕様を使用し、属性定義を実行
|
|
19
|
+
|
|
20
|
+
変更を検証するには、パッケージをビルドして下流のテストを実行します:
|
|
21
|
+
|
|
22
|
+
```shell
|
|
23
|
+
yarn build --scope @markuplint/alpine-spec
|
|
24
|
+
yarn test --scope @markuplint/ml-spec --scope @markuplint/ml-core
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## レシピ
|
|
28
|
+
|
|
29
|
+
### 1. グローバル属性の追加
|
|
30
|
+
|
|
31
|
+
Alpine.js のディレクティブはすべてグローバルです -- すべての HTML 要素で利用可能です。
|
|
32
|
+
|
|
33
|
+
1. `src/index.ts` を開く
|
|
34
|
+
2. `def['#globalAttrs']['#extends']` の下に新しいエントリを追加:
|
|
35
|
+
```ts
|
|
36
|
+
/** ディレクティブの説明 */
|
|
37
|
+
'x-directiveName': {
|
|
38
|
+
type: 'Any', // または 'Boolean'
|
|
39
|
+
},
|
|
40
|
+
```
|
|
41
|
+
3. 適切な型を選択:
|
|
42
|
+
- `'Any'` -- 任意の値を受け付ける(文字列、式など)
|
|
43
|
+
- `'Boolean'` -- ブール属性(存在が `true` を意味する)
|
|
44
|
+
4. ビルド: `yarn build --scope @markuplint/alpine-spec`
|
|
45
|
+
|
|
46
|
+
## ExtendedSpec 型リファレンス
|
|
47
|
+
|
|
48
|
+
`ExtendedSpec` 型(`@markuplint/ml-spec` から)は、このパッケージに関連する以下の構造を持ちます:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
interface ExtendedSpec {
|
|
52
|
+
cites?: string[];
|
|
53
|
+
def?: {
|
|
54
|
+
'#globalAttrs'?: {
|
|
55
|
+
'#extends': Record<string, AttributeSpec>;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
specs?: Array<{
|
|
59
|
+
name: string;
|
|
60
|
+
attributes: Record<string, AttributeSpec>;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### AttributeSpec のフィールド
|
|
66
|
+
|
|
67
|
+
| フィールド | 型 | 必須 | 説明 |
|
|
68
|
+
| --------------- | ---------- | ------ | --------------------------------------- |
|
|
69
|
+
| `type` | `string` | はい | 属性値の型(`'Any'`、`'Boolean'` など) |
|
|
70
|
+
| `caseSensitive` | `boolean` | いいえ | 属性名の大文字小文字を区別するかどうか |
|
|
71
|
+
| `condition` | `string[]` | いいえ | 属性が適用される CSS セレクタ条件 |
|
|
72
|
+
|
|
73
|
+
### 型の値
|
|
74
|
+
|
|
75
|
+
- `'Any'` -- 属性は任意の値を受け付ける
|
|
76
|
+
- `'Boolean'` -- 属性はブール値(存在が `true` を示す)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Maintenance Guide
|
|
2
|
+
|
|
3
|
+
## Commands
|
|
4
|
+
|
|
5
|
+
| Command | Description |
|
|
6
|
+
| -------------------------------------------- | ---------------------- |
|
|
7
|
+
| `yarn build --scope @markuplint/alpine-spec` | Build this package |
|
|
8
|
+
| `yarn dev --scope @markuplint/alpine-spec` | Watch mode build |
|
|
9
|
+
| `yarn clean --scope @markuplint/alpine-spec` | Remove build artifacts |
|
|
10
|
+
|
|
11
|
+
## Testing
|
|
12
|
+
|
|
13
|
+
This package has no dedicated test suite. The `ExtendedSpec` object is validated at build time through TypeScript type checking against the `ExtendedSpec` type from `@markuplint/ml-spec`. If the exported object does not conform to the type, the build will fail.
|
|
14
|
+
|
|
15
|
+
Integration testing occurs downstream:
|
|
16
|
+
|
|
17
|
+
- `@markuplint/ml-spec` resolves the extended spec and merges it with the base HTML spec
|
|
18
|
+
- `@markuplint/ml-core` uses the resolved spec during linting, which exercises the attribute definitions
|
|
19
|
+
|
|
20
|
+
To verify changes, build the package and run downstream tests:
|
|
21
|
+
|
|
22
|
+
```shell
|
|
23
|
+
yarn build --scope @markuplint/alpine-spec
|
|
24
|
+
yarn test --scope @markuplint/ml-spec --scope @markuplint/ml-core
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Recipes
|
|
28
|
+
|
|
29
|
+
### 1. Adding a Global Attribute
|
|
30
|
+
|
|
31
|
+
All Alpine.js directives are global -- they are available on every HTML element.
|
|
32
|
+
|
|
33
|
+
1. Open `src/index.ts`
|
|
34
|
+
2. Add a new entry under `def['#globalAttrs']['#extends']`:
|
|
35
|
+
```ts
|
|
36
|
+
/** Description of the directive */
|
|
37
|
+
'x-directiveName': {
|
|
38
|
+
type: 'Any', // or 'Boolean'
|
|
39
|
+
},
|
|
40
|
+
```
|
|
41
|
+
3. Choose the appropriate type:
|
|
42
|
+
- `'Any'` -- accepts any value (strings, expressions, etc.)
|
|
43
|
+
- `'Boolean'` -- boolean attribute (presence indicates `true`)
|
|
44
|
+
4. Build: `yarn build --scope @markuplint/alpine-spec`
|
|
45
|
+
|
|
46
|
+
## ExtendedSpec Type Reference
|
|
47
|
+
|
|
48
|
+
The `ExtendedSpec` type (from `@markuplint/ml-spec`) has the following structure relevant to this package:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
interface ExtendedSpec {
|
|
52
|
+
cites?: string[];
|
|
53
|
+
def?: {
|
|
54
|
+
'#globalAttrs'?: {
|
|
55
|
+
'#extends': Record<string, AttributeSpec>;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
specs?: Array<{
|
|
59
|
+
name: string;
|
|
60
|
+
attributes: Record<string, AttributeSpec>;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### AttributeSpec Fields
|
|
66
|
+
|
|
67
|
+
| Field | Type | Required | Description |
|
|
68
|
+
| --------------- | ---------- | -------- | ------------------------------------------------------ |
|
|
69
|
+
| `type` | `string` | Yes | The attribute value type (`'Any'`, `'Boolean'`, etc.) |
|
|
70
|
+
| `caseSensitive` | `boolean` | No | Whether the attribute name is case-sensitive |
|
|
71
|
+
| `condition` | `string[]` | No | CSS selector conditions for when the attribute applies |
|
|
72
|
+
|
|
73
|
+
### Type Values
|
|
74
|
+
|
|
75
|
+
- `'Any'` -- The attribute accepts any value
|
|
76
|
+
- `'Boolean'` -- The attribute is a boolean (presence indicates `true`)
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @markuplint/alpine-spec
|
|
3
|
+
*
|
|
4
|
+
* Provides Alpine.js-specific extended specifications for markuplint.
|
|
5
|
+
* Defines Alpine.js directives (`x-data`, `x-show`, `x-bind`, `x-on`,
|
|
6
|
+
* `x-model`, `x-text`, `x-html`, `x-ref`, `x-if`, `x-for`,
|
|
7
|
+
* `x-transition`, `x-effect`, `x-ignore`, `x-cloak`, etc.)
|
|
8
|
+
* as global attributes available on any HTML element.
|
|
9
|
+
*
|
|
10
|
+
* Alpine.js is a lightweight JavaScript framework that provides
|
|
11
|
+
* reactive and declarative features directly in HTML markup.
|
|
12
|
+
*
|
|
13
|
+
* @see https://alpinejs.dev/
|
|
14
|
+
*/
|
|
15
|
+
import type { ExtendedSpec } from '@markuplint/ml-spec';
|
|
16
|
+
/**
|
|
17
|
+
* The Alpine.js framework extended specification.
|
|
18
|
+
*
|
|
19
|
+
* Registers global Alpine.js directives available on every HTML element.
|
|
20
|
+
* Alpine.js directives are all global and prefixed with `x-`.
|
|
21
|
+
*/
|
|
22
|
+
declare const spec: ExtendedSpec;
|
|
23
|
+
export default spec;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @markuplint/alpine-spec
|
|
3
|
+
*
|
|
4
|
+
* Provides Alpine.js-specific extended specifications for markuplint.
|
|
5
|
+
* Defines Alpine.js directives (`x-data`, `x-show`, `x-bind`, `x-on`,
|
|
6
|
+
* `x-model`, `x-text`, `x-html`, `x-ref`, `x-if`, `x-for`,
|
|
7
|
+
* `x-transition`, `x-effect`, `x-ignore`, `x-cloak`, etc.)
|
|
8
|
+
* as global attributes available on any HTML element.
|
|
9
|
+
*
|
|
10
|
+
* Alpine.js is a lightweight JavaScript framework that provides
|
|
11
|
+
* reactive and declarative features directly in HTML markup.
|
|
12
|
+
*
|
|
13
|
+
* @see https://alpinejs.dev/
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The Alpine.js framework extended specification.
|
|
17
|
+
*
|
|
18
|
+
* Registers global Alpine.js directives available on every HTML element.
|
|
19
|
+
* Alpine.js directives are all global and prefixed with `x-`.
|
|
20
|
+
*/
|
|
21
|
+
const spec = {
|
|
22
|
+
cites: ['https://alpinejs.dev/'],
|
|
23
|
+
directivePatterns: [
|
|
24
|
+
/**
|
|
25
|
+
* Static directives: x-data, x-init, x-show, x-text, x-html,
|
|
26
|
+
* x-modelable, x-effect, x-ref, x-id, x-for, x-if, x-teleport
|
|
27
|
+
*/
|
|
28
|
+
{
|
|
29
|
+
pattern: '^x-(?:data|init|show|text|html|modelable|effect|ref|id|for|if|teleport)$',
|
|
30
|
+
isDirective: true,
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* Boolean directives: x-ignore, x-cloak
|
|
34
|
+
*/
|
|
35
|
+
{
|
|
36
|
+
pattern: '^x-(?:ignore|cloak)$',
|
|
37
|
+
isDirective: true,
|
|
38
|
+
valueType: 'boolean',
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* x-model with optional modifiers (.lazy, .number, .debounce, etc.)
|
|
42
|
+
* @see https://alpinejs.dev/directives/model
|
|
43
|
+
*/
|
|
44
|
+
{
|
|
45
|
+
pattern: '^x-model(?:$|\\.)',
|
|
46
|
+
isDirective: true,
|
|
47
|
+
isDynamicValue: true,
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* x-bind:attr or :attr shorthand => potentialName = attr
|
|
51
|
+
* @see https://alpinejs.dev/directives/bind
|
|
52
|
+
*/
|
|
53
|
+
{
|
|
54
|
+
pattern: '^(?:x-bind:|:)([^.]+)(?:\\.[^.]+)?$',
|
|
55
|
+
potentialName: '$1',
|
|
56
|
+
isDynamicValue: true,
|
|
57
|
+
valueType: 'code',
|
|
58
|
+
isDuplicatable: ['class', 'style'],
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* x-on:event or @event shorthand => potentialName = onevent
|
|
62
|
+
* @see https://alpinejs.dev/directives/on
|
|
63
|
+
*/
|
|
64
|
+
{
|
|
65
|
+
pattern: '^(?:x-on:|@)([^.]+)(?:\\..+)?$',
|
|
66
|
+
potentialName: 'on$1',
|
|
67
|
+
isDirective: true,
|
|
68
|
+
isDynamicValue: true,
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* x-transition (with optional suffix like :enter, :leave, .duration, etc.)
|
|
72
|
+
* @see https://alpinejs.dev/directives/transition
|
|
73
|
+
*/
|
|
74
|
+
{
|
|
75
|
+
pattern: '^x-transition(?:$|:|\\.)',
|
|
76
|
+
isDirective: true,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
specs: [
|
|
80
|
+
{
|
|
81
|
+
name: 'template',
|
|
82
|
+
attributes: {
|
|
83
|
+
'x-for': {
|
|
84
|
+
type: 'NoEmptyAny',
|
|
85
|
+
description: 'Renders elements by iterating over arrays, objects, or numeric ranges',
|
|
86
|
+
},
|
|
87
|
+
key: {
|
|
88
|
+
type: 'NoEmptyAny',
|
|
89
|
+
description: 'A special attribute for list rendering that helps Alpine track changes',
|
|
90
|
+
condition: '[x-for]',
|
|
91
|
+
},
|
|
92
|
+
'x-teleport': {
|
|
93
|
+
type: 'NoEmptyAny',
|
|
94
|
+
description: 'Moves the element DOM content to another location in the page',
|
|
95
|
+
},
|
|
96
|
+
'x-if': {
|
|
97
|
+
type: 'NoEmptyAny',
|
|
98
|
+
description: 'Conditionally adds/removes elements from the DOM entirely',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'input',
|
|
104
|
+
attributes: {
|
|
105
|
+
'x-model': {
|
|
106
|
+
type: 'NoEmptyAny',
|
|
107
|
+
condition: '[type=text i], [type=checkbox i], [type=radio i], [type=range i]',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'select',
|
|
113
|
+
attributes: {
|
|
114
|
+
'x-model': {
|
|
115
|
+
type: 'NoEmptyAny',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: 'textarea',
|
|
121
|
+
attributes: {
|
|
122
|
+
'x-model': {
|
|
123
|
+
type: 'NoEmptyAny',
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
def: {
|
|
129
|
+
'#globalAttrs': {
|
|
130
|
+
'#extends': {
|
|
131
|
+
/**
|
|
132
|
+
* Declares an element as an Alpine component and
|
|
133
|
+
* defines its reactive data scope
|
|
134
|
+
*/
|
|
135
|
+
'x-data': {
|
|
136
|
+
type: 'Any',
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Hooks into the initialization phase;
|
|
140
|
+
* runs code when the element initializes
|
|
141
|
+
*/
|
|
142
|
+
'x-init': {
|
|
143
|
+
type: 'Any',
|
|
144
|
+
},
|
|
145
|
+
/**
|
|
146
|
+
* Toggles element visibility via CSS display property
|
|
147
|
+
*/
|
|
148
|
+
'x-show': {
|
|
149
|
+
type: 'Any',
|
|
150
|
+
},
|
|
151
|
+
/**
|
|
152
|
+
* Sets the textContent of the element to the result
|
|
153
|
+
* of the expression
|
|
154
|
+
*/
|
|
155
|
+
'x-text': {
|
|
156
|
+
type: 'Any',
|
|
157
|
+
},
|
|
158
|
+
/**
|
|
159
|
+
* Sets the innerHTML of the element to the result
|
|
160
|
+
* of the expression
|
|
161
|
+
*/
|
|
162
|
+
'x-html': {
|
|
163
|
+
type: 'Any',
|
|
164
|
+
},
|
|
165
|
+
/**
|
|
166
|
+
* Creates two-way data binding between form elements
|
|
167
|
+
* and Alpine data
|
|
168
|
+
*/
|
|
169
|
+
'x-model': {
|
|
170
|
+
type: 'Any',
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* Exposes an internal component property as the target
|
|
174
|
+
* of an outer x-model directive
|
|
175
|
+
*/
|
|
176
|
+
'x-modelable': {
|
|
177
|
+
type: 'Any',
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* Runs the expression and reactively re-evaluates it
|
|
181
|
+
* whenever any of its referenced reactive data
|
|
182
|
+
* dependencies change
|
|
183
|
+
*/
|
|
184
|
+
'x-effect': {
|
|
185
|
+
type: 'Any',
|
|
186
|
+
},
|
|
187
|
+
/**
|
|
188
|
+
* Marks an element with a name so it can be accessed
|
|
189
|
+
* via $refs in other Alpine expressions
|
|
190
|
+
*/
|
|
191
|
+
'x-ref': {
|
|
192
|
+
type: 'Any',
|
|
193
|
+
},
|
|
194
|
+
/**
|
|
195
|
+
* Conditionally adds/removes elements from the DOM
|
|
196
|
+
* entirely. Must be on a template tag.
|
|
197
|
+
*/
|
|
198
|
+
'x-if': {
|
|
199
|
+
type: 'Any',
|
|
200
|
+
},
|
|
201
|
+
/**
|
|
202
|
+
* Renders elements by iterating over arrays, objects,
|
|
203
|
+
* or numeric ranges. Must be on a template tag.
|
|
204
|
+
*/
|
|
205
|
+
'x-for': {
|
|
206
|
+
type: 'Any',
|
|
207
|
+
},
|
|
208
|
+
/**
|
|
209
|
+
* Applies CSS transition animations to x-show toggles
|
|
210
|
+
*/
|
|
211
|
+
'x-transition': {
|
|
212
|
+
type: 'Any',
|
|
213
|
+
},
|
|
214
|
+
/**
|
|
215
|
+
* CSS class names applied during the entire entering phase
|
|
216
|
+
*/
|
|
217
|
+
'x-transition:enter': {
|
|
218
|
+
type: 'Any',
|
|
219
|
+
},
|
|
220
|
+
/**
|
|
221
|
+
* CSS class names applied before element is inserted
|
|
222
|
+
*/
|
|
223
|
+
'x-transition:enter-start': {
|
|
224
|
+
type: 'Any',
|
|
225
|
+
},
|
|
226
|
+
/**
|
|
227
|
+
* CSS class names applied one frame after insertion
|
|
228
|
+
*/
|
|
229
|
+
'x-transition:enter-end': {
|
|
230
|
+
type: 'Any',
|
|
231
|
+
},
|
|
232
|
+
/**
|
|
233
|
+
* CSS class names applied during the entire leaving phase
|
|
234
|
+
*/
|
|
235
|
+
'x-transition:leave': {
|
|
236
|
+
type: 'Any',
|
|
237
|
+
},
|
|
238
|
+
/**
|
|
239
|
+
* CSS class names applied when leaving is triggered
|
|
240
|
+
*/
|
|
241
|
+
'x-transition:leave-start': {
|
|
242
|
+
type: 'Any',
|
|
243
|
+
},
|
|
244
|
+
/**
|
|
245
|
+
* CSS class names applied one frame after leave starts
|
|
246
|
+
*/
|
|
247
|
+
'x-transition:leave-end': {
|
|
248
|
+
type: 'Any',
|
|
249
|
+
},
|
|
250
|
+
/**
|
|
251
|
+
* Moves the element's DOM content to another location
|
|
252
|
+
* in the page. Must be on a template tag.
|
|
253
|
+
*/
|
|
254
|
+
'x-teleport': {
|
|
255
|
+
type: 'Any',
|
|
256
|
+
},
|
|
257
|
+
/**
|
|
258
|
+
* Declares a new scope for auto-generated IDs
|
|
259
|
+
* via the $id() magic property
|
|
260
|
+
*/
|
|
261
|
+
'x-id': {
|
|
262
|
+
type: 'Any',
|
|
263
|
+
},
|
|
264
|
+
/**
|
|
265
|
+
* Prevents Alpine from initializing the element
|
|
266
|
+
* and its children
|
|
267
|
+
*/
|
|
268
|
+
'x-ignore': {
|
|
269
|
+
type: 'Boolean',
|
|
270
|
+
},
|
|
271
|
+
/**
|
|
272
|
+
* Hidden by Alpine on initialization; used with CSS
|
|
273
|
+
* rule [x-cloak] { display: none !important; }
|
|
274
|
+
* to prevent flash of unstyled content
|
|
275
|
+
*/
|
|
276
|
+
'x-cloak': {
|
|
277
|
+
type: 'Boolean',
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
export default spec;
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@markuplint/alpine-spec",
|
|
3
|
+
"version": "5.0.0-alpha.0",
|
|
4
|
+
"description": "Extended specification for tags and attributes in Alpine.js",
|
|
5
|
+
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
|
+
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./lib/index.js",
|
|
15
|
+
"types": "./lib/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc --project tsconfig.build.json",
|
|
23
|
+
"dev": "tsc --watch --project tsconfig.build.json",
|
|
24
|
+
"clean": "tsc --build --clean tsconfig.build.json"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@markuplint/ml-spec": "5.0.0-alpha.0"
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "13dcfc84ec83d87360c720e253383b60767e1b56"
|
|
30
|
+
}
|