@htmlplus/element 1.0.0 → 1.1.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/README.md +616 -534
- package/bundlers/rollup.d.ts +2 -2
- package/bundlers/rollup.js +5 -5
- package/bundlers/vite.d.ts +2 -2
- package/bundlers/vite.js +5 -5
- package/client/decorators/bind.d.ts +4 -0
- package/client/decorators/bind.js +4 -0
- package/client/decorators/direction.d.ts +5 -0
- package/client/decorators/direction.js +8 -0
- package/client/decorators/element.d.ts +5 -0
- package/client/decorators/element.js +7 -2
- package/client/decorators/event.d.ts +21 -7
- package/client/decorators/event.js +7 -2
- package/client/decorators/host.d.ts +4 -2
- package/client/decorators/host.js +5 -8
- package/client/decorators/index.d.ts +3 -0
- package/client/decorators/index.js +3 -0
- package/client/decorators/isRTL.d.ts +4 -0
- package/client/decorators/isRTL.js +7 -0
- package/client/decorators/listen.d.ts +38 -8
- package/client/decorators/listen.js +9 -12
- package/client/decorators/method.d.ts +4 -0
- package/client/decorators/method.js +4 -0
- package/client/decorators/property.d.ts +8 -1
- package/client/decorators/property.js +4 -0
- package/client/decorators/query.d.ts +9 -2
- package/client/decorators/query.js +10 -9
- package/client/decorators/queryAll.d.ts +12 -2
- package/client/decorators/queryAll.js +13 -9
- package/client/decorators/slots.d.ts +4 -0
- package/client/decorators/slots.js +7 -0
- package/client/decorators/state.d.ts +4 -0
- package/client/decorators/state.js +4 -0
- package/client/decorators/watch.d.ts +5 -4
- package/client/decorators/watch.js +5 -4
- package/client/index.d.ts +1 -3
- package/client/index.js +1 -3
- package/client/utils/classes.d.ts +3 -0
- package/client/utils/classes.js +11 -28
- package/client/utils/config.d.ts +25 -3
- package/client/utils/config.js +18 -10
- package/client/utils/direction.d.ts +5 -2
- package/client/utils/direction.js +5 -1
- package/client/utils/event.d.ts +6 -0
- package/client/utils/event.js +6 -0
- package/client/utils/host.d.ts +3 -0
- package/client/utils/host.js +3 -0
- package/client/utils/index.d.ts +4 -1
- package/client/utils/index.js +4 -1
- package/client/utils/isCSSColor.d.ts +5 -0
- package/client/utils/isCSSColor.js +9 -0
- package/client/utils/isRTL.d.ts +3 -0
- package/client/utils/isRTL.js +3 -0
- package/client/utils/isServer.d.ts +3 -0
- package/client/utils/isServer.js +3 -0
- package/client/utils/query.d.ts +5 -0
- package/client/utils/query.js +8 -0
- package/client/utils/queryAll.d.ts +5 -0
- package/client/utils/queryAll.js +8 -0
- package/client/utils/request.d.ts +1 -1
- package/client/utils/request.js +1 -1
- package/client/utils/slots.d.ts +3 -0
- package/client/utils/slots.js +6 -1
- package/client/utils/styles.d.ts +3 -0
- package/client/utils/styles.js +3 -0
- package/client/utils/toDecorator.d.ts +2 -0
- package/client/utils/toDecorator.js +10 -0
- package/client/utils/toUnit.d.ts +4 -1
- package/client/utils/toUnit.js +6 -3
- package/constants/index.d.ts +1 -0
- package/constants/index.js +2 -0
- package/package.json +3 -3
- package/transformer/index.d.ts +3 -0
- package/transformer/index.js +3 -0
- package/transformer/plugins/assets.d.ts +8 -0
- package/transformer/plugins/assets.js +29 -0
- package/{compiler → transformer}/plugins/copy.d.ts +2 -2
- package/{compiler → transformer}/plugins/customElement.d.ts +2 -2
- package/{compiler → transformer}/plugins/customElement.js +13 -12
- package/{compiler → transformer}/plugins/customElementReact/customElementReact.d.ts +4 -4
- package/{compiler → transformer}/plugins/customElementReact/customElementReact.js +18 -18
- package/{compiler → transformer}/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +1 -1
- package/{compiler → transformer}/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +3 -3
- package/transformer/plugins/customElementReact/templates/src/index.ts.hbs +1 -0
- package/transformer/plugins/document.d.ts +7 -0
- package/{compiler → transformer}/plugins/document.js +18 -18
- package/transformer/plugins/extract.d.ts +2 -0
- package/{compiler → transformer}/plugins/extract.js +1 -18
- package/transformer/plugins/parse.d.ts +6 -0
- package/{compiler → transformer}/plugins/parse.js +1 -1
- package/transformer/plugins/read.d.ts +8 -0
- package/transformer/plugins/read.js +20 -0
- package/transformer/plugins/readme.d.ts +6 -0
- package/{compiler → transformer}/plugins/readme.js +3 -2
- package/transformer/plugins/style.d.ts +6 -0
- package/{compiler → transformer}/plugins/style.js +4 -2
- package/transformer/plugins/validate.d.ts +2 -0
- package/transformer/plugins/validate.js +41 -0
- package/transformer/plugins/visualStudioCode.d.ts +8 -0
- package/{compiler → transformer}/plugins/visualStudioCode.js +10 -8
- package/transformer/plugins/webTypes.d.ts +10 -0
- package/{compiler → transformer}/plugins/webTypes.js +11 -7
- package/transformer/transformer.d.ts +6 -0
- package/{compiler/compiler.js → transformer/transformer.js} +17 -17
- package/transformer/transformer.types.d.ts +50 -0
- package/{compiler → transformer}/utils/printType.js +2 -2
- package/{compiler → transformer}/utils/renderTemplate.js +2 -0
- package/types/index.d.ts +2 -4
- package/types/index.js +1 -4
- package/CHANGELOG.md +0 -7
- package/bundlers/index.d.ts +0 -2
- package/bundlers/index.js +0 -2
- package/client/helpers/index.d.ts +0 -1
- package/client/helpers/index.js +0 -1
- package/client/services/index.d.ts +0 -1
- package/client/services/index.js +0 -1
- package/client/services/link.d.ts +0 -4
- package/client/services/link.js +0 -196
- package/client/utils/getNamespace.d.ts +0 -2
- package/client/utils/getNamespace.js +0 -4
- package/client/vendors/uhtml.d.ts +0 -29
- package/client/vendors/uhtml.js +0 -700
- package/compiler/compiler.d.ts +0 -6
- package/compiler/index.d.ts +0 -2
- package/compiler/index.js +0 -2
- package/compiler/plugins/assets.d.ts +0 -8
- package/compiler/plugins/assets.js +0 -33
- package/compiler/plugins/customElementReact/templates/src/index.ts.hbs +0 -1
- package/compiler/plugins/document.d.ts +0 -7
- package/compiler/plugins/extract.d.ts +0 -2
- package/compiler/plugins/parse.d.ts +0 -5
- package/compiler/plugins/read.d.ts +0 -8
- package/compiler/plugins/read.js +0 -13
- package/compiler/plugins/readme.d.ts +0 -6
- package/compiler/plugins/style.d.ts +0 -6
- package/compiler/plugins/validate.d.ts +0 -2
- package/compiler/plugins/validate.js +0 -37
- package/compiler/plugins/visualStudioCode.d.ts +0 -8
- package/compiler/plugins/webTypes.d.ts +0 -10
- package/types/context.d.ts +0 -31
- package/types/global.d.ts +0 -4
- package/types/global.js +0 -1
- package/types/plugin.d.ts +0 -10
- package/types/plugin.js +0 -1
- package/types/plusElement.d.ts +0 -2
- package/types/plusElement.js +0 -1
- /package/{compiler → transformer}/plugins/copy.js +0 -0
- /package/{compiler → transformer}/plugins/customElementReact/index.d.ts +0 -0
- /package/{compiler → transformer}/plugins/customElementReact/index.js +0 -0
- /package/{compiler → transformer}/plugins/customElementReact/templates/README.md.hbs +0 -0
- /package/{compiler → transformer}/plugins/customElementReact/templates/_.gitignore.hbs +0 -0
- /package/{compiler → transformer}/plugins/customElementReact/templates/package.json.hbs +0 -0
- /package/{compiler → transformer}/plugins/customElementReact/templates/rollup.config.js.hbs +0 -0
- /package/{compiler → transformer}/plugins/customElementReact/templates/src/components/index.ts.hbs +0 -0
- /package/{compiler → transformer}/plugins/customElementReact/templates/src/proxy.ts.hbs +0 -0
- /package/{compiler → transformer}/plugins/customElementReact/templates/tsconfig.json.hbs +0 -0
- /package/{compiler → transformer}/plugins/index.d.ts +0 -0
- /package/{compiler → transformer}/plugins/index.js +0 -0
- /package/{types/context.js → transformer/transformer.types.js} +0 -0
- /package/{compiler → transformer}/utils/__dirname.d.ts +0 -0
- /package/{compiler → transformer}/utils/__dirname.js +0 -0
- /package/{compiler → transformer}/utils/addDependency.d.ts +0 -0
- /package/{compiler → transformer}/utils/addDependency.js +0 -0
- /package/{compiler → transformer}/utils/getInitializer.d.ts +0 -0
- /package/{compiler → transformer}/utils/getInitializer.js +0 -0
- /package/{compiler → transformer}/utils/getType.d.ts +0 -0
- /package/{compiler → transformer}/utils/getType.js +0 -0
- /package/{compiler → transformer}/utils/getTypeReference.d.ts +0 -0
- /package/{compiler → transformer}/utils/getTypeReference.js +0 -0
- /package/{compiler → transformer}/utils/hasDecorator.d.ts +0 -0
- /package/{compiler → transformer}/utils/hasDecorator.js +0 -0
- /package/{compiler → transformer}/utils/index.d.ts +0 -0
- /package/{compiler → transformer}/utils/index.js +0 -0
- /package/{compiler → transformer}/utils/isDirectoryEmpty.d.ts +0 -0
- /package/{compiler → transformer}/utils/isDirectoryEmpty.js +0 -0
- /package/{compiler → transformer}/utils/print.d.ts +0 -0
- /package/{compiler → transformer}/utils/print.js +0 -0
- /package/{compiler → transformer}/utils/printType.d.ts +0 -0
- /package/{compiler → transformer}/utils/removeUnusedImport.d.ts +0 -0
- /package/{compiler → transformer}/utils/removeUnusedImport.js +0 -0
- /package/{compiler → transformer}/utils/renderTemplate.d.ts +0 -0
- /package/{compiler → transformer}/utils/tags.d.ts +0 -0
- /package/{compiler → transformer}/utils/tags.js +0 -0
- /package/{compiler → transformer}/utils/visitor.d.ts +0 -0
- /package/{compiler → transformer}/utils/visitor.js +0 -0
package/README.md
CHANGED
|
@@ -1,197 +1,254 @@
|
|
|
1
1
|
# Create Custom HTML Element
|
|
2
2
|
|
|
3
|
-
A powerful
|
|
3
|
+
A powerful tool for building a scalable, reusable, fast, and lightweight `UI Component Library` for any web technologies, powered by [Custom Elements](https://mdn.io/using-custom-elements).
|
|
4
4
|
|
|
5
|
-
## Table
|
|
5
|
+
## Table Of Content
|
|
6
6
|
|
|
7
|
-
- [
|
|
8
|
-
- [Start](#start)
|
|
9
|
-
- [First Element](#
|
|
10
|
-
- [Styles](#Styles)
|
|
11
|
-
- [Development Environment](#DevelopmentEnvironment)
|
|
7
|
+
- [Features](#features)
|
|
8
|
+
- [Quick Start](#quick-start)
|
|
9
|
+
- [First Element](#first-element)
|
|
12
10
|
- [Decorators](#decorators)
|
|
13
|
-
- [
|
|
11
|
+
- [Utilities](#utilities)
|
|
12
|
+
- [JSX](#jsx)
|
|
14
13
|
- [Lifecycles](#lifecycles)
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [Compiler](#compiler)
|
|
14
|
+
- [Bundlers](#bundlers)
|
|
15
|
+
- [Transformer](#transformer)
|
|
18
16
|
|
|
19
|
-
##
|
|
17
|
+
## Features
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
- **Plugin-Based**: Facilitates the seamless development of diverse plugins and the customization of outputs to meet specific requirements
|
|
20
|
+
- **Built-In Plugins**: Provides a variety of plugins that cater to different requirements.
|
|
21
|
+
- **Global Config**: Provides the ability to define global configs for all elements.
|
|
22
|
+
- **Typings**: Creates TypeScript types for seamless element usage across different environments.
|
|
23
|
+
- **TypeScript + JSX**: Using two powerful tools, TypeScript and JSX, to create elements.
|
|
24
|
+
- **Built-In Utilities**: Provides a set of JavaScript utility functions used across multiple elements.
|
|
25
|
+
- **Secure**: Restricts unwanted access to internal properties and methods.
|
|
26
|
+
- **Style File Recognition**: Identifies and links the relevant style file to the element.
|
|
27
|
+
- **Tag Name Recognition**: Generates tag name from the class name.
|
|
28
|
+
- **Clean Syntax**: Uses a minimal amount of code to achieve the same functionality, making the code easier to read, understand, and maintain.
|
|
29
|
+
- **Attribute Over Class**: Uses HTML attributes instead of HTML class names to keep the size of the start tag short, making it more readable and preventing the DOM from getting dirty.
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
# with npm
|
|
25
|
-
npm init @htmlplus/element@latest
|
|
31
|
+
## Quick Start
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
yarn create @htmlplus/element
|
|
33
|
+
Before proceeding, ensure you have the latest LTS version of [Node.js](https://nodejs.org/en/download) installed on your system.
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
1- Create a new project
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm init @htmlplus/element@latest
|
|
32
39
|
```
|
|
33
40
|
|
|
34
|
-
|
|
41
|
+
2- Navigate to the project directory
|
|
35
42
|
|
|
36
43
|
```bash
|
|
37
44
|
cd htmlplus-project
|
|
38
45
|
```
|
|
39
46
|
|
|
40
|
-
|
|
47
|
+
3- Install the dependencies
|
|
41
48
|
|
|
42
49
|
```bash
|
|
43
|
-
# with npm
|
|
44
50
|
npm i
|
|
45
|
-
|
|
51
|
+
```
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
yarn install
|
|
49
|
-
yarn start
|
|
53
|
+
4- Start the project
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
pnpm start
|
|
55
|
+
```bash
|
|
56
|
+
npm start
|
|
54
57
|
```
|
|
55
58
|
|
|
56
59
|
## First Element
|
|
57
60
|
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
An example demonstrating the implementation and usage of an element.
|
|
62
|
+
|
|
63
|
+
Each element is stored in a file such as `my-counter.tsx`.
|
|
60
64
|
|
|
61
65
|
```tsx
|
|
62
|
-
|
|
66
|
+
import { Element, State } from '@htmlplus/element';
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
@Element()
|
|
69
|
+
export class MyCounter {
|
|
70
|
+
@State()
|
|
71
|
+
value: number = 0;
|
|
65
72
|
|
|
66
|
-
@Element('my-element')
|
|
67
|
-
export class MyElement {
|
|
68
73
|
render() {
|
|
69
|
-
return
|
|
74
|
+
return (
|
|
75
|
+
<host onClick={() => this.value++}>
|
|
76
|
+
Count is {this.value}
|
|
77
|
+
</host>
|
|
78
|
+
)
|
|
70
79
|
}
|
|
71
80
|
}
|
|
72
81
|
```
|
|
73
82
|
|
|
74
|
-
The
|
|
75
|
-
|
|
76
|
-
```html
|
|
77
|
-
<my-element></my-element>
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## Styles
|
|
81
|
-
|
|
82
|
-
The element automatically adds a same name style file to this component. Create `my-element.scss` file for style.
|
|
83
|
-
|
|
84
|
-
```scss
|
|
85
|
-
// my-element.scss
|
|
83
|
+
The element's style is stored in a file such as `my-counter.css`, which shares the same name as the element file `my-counter.tsx`.
|
|
86
84
|
|
|
85
|
+
```css
|
|
87
86
|
:host {
|
|
88
|
-
display: block;
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
display: inline-block;
|
|
88
|
+
border: 1px solid black;
|
|
89
|
+
color: black;
|
|
90
|
+
padding: 1em;
|
|
91
|
+
cursor: pointer;
|
|
91
92
|
}
|
|
92
93
|
```
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
For run any of the component, you must write element name tag into the `index.html`
|
|
95
|
+
To execute the element, include it in the `index.html` file.
|
|
97
96
|
|
|
98
97
|
```html
|
|
99
|
-
<!-- index.html -->
|
|
100
|
-
|
|
101
98
|
<body>
|
|
102
|
-
<my-
|
|
99
|
+
<my-counter></my-counter>
|
|
103
100
|
</body>
|
|
104
101
|
```
|
|
105
102
|
|
|
106
103
|
## Decorators
|
|
107
104
|
|
|
108
|
-
|
|
105
|
+
Decorators can greatly enhance code maintainability, improving efficiency, readability, and reusability.
|
|
109
106
|
|
|
110
107
|
<details>
|
|
111
|
-
<summary>
|
|
108
|
+
<summary>Bind</summary>
|
|
109
|
+
|
|
110
|
+
Used to bind a method of a class to the current context, making it easier to reference `this` within the method.
|
|
111
|
+
|
|
112
|
+
In the `my-counter.tsx` file.
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import { Bind, Element, State } from '@htmlplus/element';
|
|
116
|
+
|
|
117
|
+
@Element()
|
|
118
|
+
export class MyCounter {
|
|
119
|
+
@State()
|
|
120
|
+
value: number = 0;
|
|
121
|
+
|
|
122
|
+
@Bind()
|
|
123
|
+
onClick() {
|
|
124
|
+
this.value++;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
render() {
|
|
128
|
+
return (
|
|
129
|
+
<host onClick={this.onClick}>
|
|
130
|
+
Count is {this.value}
|
|
131
|
+
</host>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
112
136
|
|
|
113
|
-
|
|
137
|
+
In the `index.html` file.
|
|
114
138
|
|
|
115
|
-
|
|
139
|
+
```html
|
|
140
|
+
<my-counter></my-counter>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
</details>
|
|
116
144
|
|
|
117
|
-
|
|
145
|
+
<details>
|
|
146
|
+
<summary>Direction</summary>
|
|
147
|
+
|
|
148
|
+
Indicates whether the [Direction](https://mdn.io/css-direction) of the element is `Right-To-Left` or `Left-To-Right`.
|
|
149
|
+
|
|
150
|
+
In the `my-element.tsx` file.
|
|
118
151
|
|
|
119
152
|
```tsx
|
|
120
|
-
import { Element } from '@htmlplus/element';
|
|
153
|
+
import { Direction, Element } from '@htmlplus/element';
|
|
121
154
|
|
|
122
|
-
@Element(
|
|
155
|
+
@Element()
|
|
123
156
|
export class MyElement {
|
|
124
|
-
|
|
125
|
-
|
|
157
|
+
@Direction()
|
|
158
|
+
direction!: 'ltr' | 'rtl';
|
|
159
|
+
|
|
160
|
+
render() {
|
|
161
|
+
return (
|
|
162
|
+
<div>
|
|
163
|
+
The direction of the element is
|
|
164
|
+
<u>
|
|
165
|
+
{this.direction}
|
|
166
|
+
</u>
|
|
167
|
+
</div>
|
|
168
|
+
)
|
|
126
169
|
}
|
|
127
170
|
}
|
|
128
171
|
```
|
|
129
172
|
|
|
173
|
+
In the `index.html` file.
|
|
174
|
+
|
|
130
175
|
```html
|
|
131
|
-
<
|
|
176
|
+
<body dir="rtl">
|
|
177
|
+
<my-element></my-element>
|
|
178
|
+
</body>
|
|
132
179
|
```
|
|
133
180
|
|
|
134
181
|
</details>
|
|
135
182
|
|
|
136
183
|
<details>
|
|
137
|
-
<summary>
|
|
184
|
+
<summary>Element</summary>
|
|
138
185
|
|
|
139
|
-
|
|
186
|
+
The class marked with this decorator is considered a [Custom Element](https://mdn.io/using-custom-elements), and its name, in kebab-case, serves as the element name.
|
|
140
187
|
|
|
141
|
-
|
|
188
|
+
> It is important to note that each file can only contain one class with this condition.
|
|
142
189
|
|
|
143
|
-
-
|
|
144
|
-
- **reflect**: `Boolean` For watch mode, when you want to be notified of the attribute change.
|
|
190
|
+
In the `say-hello.tsx` file.
|
|
145
191
|
|
|
146
192
|
```tsx
|
|
147
|
-
import { Element
|
|
193
|
+
import { Element } from '@htmlplus/element';
|
|
148
194
|
|
|
149
195
|
@Element()
|
|
150
|
-
export class
|
|
151
|
-
|
|
152
|
-
@Property()
|
|
153
|
-
name?: string = 'Simon';
|
|
154
|
-
|
|
196
|
+
export class SayHello {
|
|
155
197
|
render() {
|
|
156
|
-
return <
|
|
198
|
+
return <div>Hello World</div>
|
|
157
199
|
}
|
|
158
200
|
}
|
|
159
201
|
```
|
|
160
202
|
|
|
161
|
-
|
|
162
|
-
<say-greeting name="Jan" id="greeting"></say-greeting>
|
|
203
|
+
In the `index.html` file.
|
|
163
204
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
</script>
|
|
205
|
+
```html
|
|
206
|
+
<say-hello></say-hello>
|
|
167
207
|
```
|
|
168
208
|
|
|
169
209
|
</details>
|
|
170
210
|
|
|
171
211
|
<details>
|
|
172
212
|
<summary>Event</summary>
|
|
213
|
+
|
|
214
|
+
Provides the capability to dispatch a [CustomEvent](https://mdn.io/custom-event) from an element.
|
|
173
215
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
Options:
|
|
216
|
+
Parameters:
|
|
177
217
|
|
|
178
|
-
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
218
|
+
- `options` (Optional)
|
|
219
|
+
<br />
|
|
220
|
+
An object that configures [options](https://developer.mozilla.org/docs/Web/API/Event/EventEvent#options) for the event dispatcher.
|
|
221
|
+
<br />
|
|
222
|
+
<br />
|
|
223
|
+
- `bubbles` (Optional)
|
|
224
|
+
<br />
|
|
225
|
+
A boolean value indicating whether the event bubbles. The default is `false`.
|
|
226
|
+
<br />
|
|
227
|
+
<br />
|
|
228
|
+
- `cancelable` (Optional)
|
|
229
|
+
<br />
|
|
230
|
+
A boolean value indicating whether the event can be cancelled. The default is `false`.
|
|
231
|
+
<br />
|
|
232
|
+
<br />
|
|
233
|
+
- `composed` (Optional)
|
|
234
|
+
<br />
|
|
235
|
+
A boolean value indicating whether the event will trigger listeners outside of a shadow root (see [Event.composed](https://mdn.io/event-composed) for more details). The default is `false`.
|
|
236
|
+
<br />
|
|
237
|
+
<br />
|
|
238
|
+
|
|
239
|
+
In the `my-button.tsx` file.
|
|
182
240
|
|
|
183
241
|
```tsx
|
|
184
242
|
import { Element, Event, EventEmitter } from '@htmlplus/element';
|
|
185
243
|
|
|
186
244
|
@Element()
|
|
187
245
|
export class MyButton {
|
|
188
|
-
|
|
189
246
|
@Event()
|
|
190
|
-
|
|
247
|
+
myClick!: EventEmitter<string>;
|
|
191
248
|
|
|
192
249
|
render() {
|
|
193
250
|
return (
|
|
194
|
-
<button onClick={() => this.
|
|
251
|
+
<button onClick={() => this.myClick("It's a message form MyButton!")}>
|
|
195
252
|
<slot />
|
|
196
253
|
</button>
|
|
197
254
|
)
|
|
@@ -199,164 +256,283 @@ export class MyButton {
|
|
|
199
256
|
}
|
|
200
257
|
```
|
|
201
258
|
|
|
259
|
+
In the `index.html` file.
|
|
260
|
+
|
|
202
261
|
```html
|
|
203
262
|
<my-button id="button">Button</my-button>
|
|
204
263
|
|
|
205
264
|
<script>
|
|
206
|
-
document
|
|
265
|
+
document
|
|
266
|
+
.getElementById('button')
|
|
267
|
+
.addEventListener('my-click', (event) => {
|
|
268
|
+
alert(event.detail);
|
|
269
|
+
});
|
|
207
270
|
</script>
|
|
208
271
|
```
|
|
209
272
|
|
|
210
273
|
</details>
|
|
211
274
|
|
|
212
275
|
<details>
|
|
213
|
-
<summary>
|
|
276
|
+
<summary>Host</summary>
|
|
214
277
|
|
|
215
|
-
|
|
278
|
+
Indicates the host of the element.
|
|
279
|
+
|
|
280
|
+
In the `my-element.tsx` file.
|
|
216
281
|
|
|
217
282
|
```tsx
|
|
218
|
-
import { Element,
|
|
283
|
+
import { Element, Host } from '@htmlplus/element';
|
|
219
284
|
|
|
220
285
|
@Element()
|
|
221
|
-
export class
|
|
286
|
+
export class MyElement {
|
|
287
|
+
@Host()
|
|
288
|
+
host!: HTMLElement;
|
|
222
289
|
|
|
223
|
-
|
|
224
|
-
|
|
290
|
+
get isSame() {
|
|
291
|
+
return this.host == document.querySelector('my-element');
|
|
292
|
+
}
|
|
225
293
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
this.counter++;
|
|
294
|
+
connectedCallback() {
|
|
295
|
+
console.log('Is Same: ' + this.isSame);
|
|
229
296
|
}
|
|
297
|
+
}
|
|
298
|
+
```
|
|
230
299
|
|
|
231
|
-
|
|
300
|
+
In the `index.html` file.
|
|
301
|
+
|
|
302
|
+
```html
|
|
303
|
+
<my-element></my-element>
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
</details>
|
|
307
|
+
|
|
308
|
+
<details>
|
|
309
|
+
<summary>IsRTL</summary>
|
|
310
|
+
|
|
311
|
+
Indicates whether the direction of the element is `Right-To-Left` or not.
|
|
312
|
+
|
|
313
|
+
In the `my-element.tsx` file.
|
|
314
|
+
|
|
315
|
+
```tsx
|
|
316
|
+
import { Element, IsRTL } from '@htmlplus/element';
|
|
317
|
+
|
|
318
|
+
@Element()
|
|
319
|
+
export class MyElement {
|
|
320
|
+
@IsRTL()
|
|
321
|
+
isRTL!: boolean;
|
|
322
|
+
|
|
323
|
+
render() {
|
|
232
324
|
return (
|
|
233
|
-
<
|
|
234
|
-
|
|
235
|
-
|
|
325
|
+
<div>
|
|
326
|
+
The direction of the element is
|
|
327
|
+
<u>
|
|
328
|
+
{this.isRTL ? 'rtl' : 'ltr'}
|
|
329
|
+
</u>
|
|
330
|
+
</div>
|
|
236
331
|
)
|
|
237
332
|
}
|
|
238
333
|
}
|
|
239
334
|
```
|
|
240
335
|
|
|
241
|
-
|
|
242
|
-
<my-counter id="counter"></my-counter>
|
|
336
|
+
In the `index.html` file.
|
|
243
337
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
338
|
+
```html
|
|
339
|
+
<body dir="rtl">
|
|
340
|
+
<my-element></my-element>
|
|
341
|
+
</body>
|
|
247
342
|
```
|
|
248
343
|
|
|
249
344
|
</details>
|
|
250
345
|
|
|
251
346
|
<details>
|
|
252
|
-
<summary>
|
|
347
|
+
<summary>Listen</summary>
|
|
253
348
|
|
|
254
|
-
|
|
349
|
+
Will be called whenever the specified event is delivered to the target [More](https://mdn.io/add-event-listener).
|
|
350
|
+
|
|
351
|
+
Parameters:
|
|
352
|
+
|
|
353
|
+
- `type` (Required)
|
|
354
|
+
<br />
|
|
355
|
+
A case-sensitive string representing the [Event Type](https://mdn.io/events) to listen for.
|
|
356
|
+
<br />
|
|
357
|
+
<br />
|
|
358
|
+
- `options` (Optional)
|
|
359
|
+
<br />
|
|
360
|
+
An object that configures [options](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener#options) for the event listener.
|
|
361
|
+
<br />
|
|
362
|
+
<br />
|
|
363
|
+
- `capture` (Optional)
|
|
364
|
+
<br />
|
|
365
|
+
A boolean value indicating that events of this type will be dispatched to the registered `listener` before being dispatched to any `EventTarget` beneath it in the DOM tree. If not specified, defaults to `false`.
|
|
366
|
+
<br />
|
|
367
|
+
<br />
|
|
368
|
+
- `once` (Optional)
|
|
369
|
+
<br />
|
|
370
|
+
A boolean value indicating that the `listener` should be invoked at most once after being added. If `true`, the `listener` would be automatically removed when invoked. If not specified, defaults to `false`.
|
|
371
|
+
<br />
|
|
372
|
+
<br />
|
|
373
|
+
- `passive` (Optional)
|
|
374
|
+
<br />
|
|
375
|
+
A boolean value that, if `true`, indicates that the function specified by `listener` will never call [preventDefault()](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault). If a passive listener does call `preventDefault()`, the user agent will do nothing other than generate a console warning.
|
|
376
|
+
<br />
|
|
377
|
+
<br />
|
|
378
|
+
- `signal` (Optional)
|
|
379
|
+
<br />
|
|
380
|
+
An [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). The listener will be removed when the given `AbortSignal` object's [abort()](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort) method is called. If not specified, no `AbortSignal` is associated with the listener.
|
|
381
|
+
<br />
|
|
382
|
+
<br />
|
|
383
|
+
- `target` (Optional)
|
|
384
|
+
<br />
|
|
385
|
+
The target element, defaults to `host`.
|
|
386
|
+
<br />
|
|
387
|
+
<br />
|
|
388
|
+
|
|
389
|
+
In the `my-button.tsx` file.
|
|
255
390
|
|
|
256
391
|
```tsx
|
|
257
|
-
import {
|
|
392
|
+
import { Element, Listen } from '@htmlplus/element';
|
|
258
393
|
|
|
259
|
-
@Element(
|
|
394
|
+
@Element()
|
|
260
395
|
export class MyButton {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return {
|
|
265
|
-
role: 'button'
|
|
266
|
-
}
|
|
396
|
+
@Listen('click')
|
|
397
|
+
onClick(event) {
|
|
398
|
+
alert('The my-button was clicked!');
|
|
267
399
|
}
|
|
268
400
|
|
|
269
401
|
render() {
|
|
270
|
-
return <
|
|
402
|
+
return <slot />
|
|
271
403
|
}
|
|
272
404
|
}
|
|
273
405
|
```
|
|
274
406
|
|
|
407
|
+
In the `index.html` file.
|
|
408
|
+
|
|
275
409
|
```html
|
|
276
|
-
<my-button
|
|
410
|
+
<my-button>Click Me</my-button>
|
|
277
411
|
```
|
|
278
412
|
|
|
279
413
|
</details>
|
|
280
414
|
|
|
281
415
|
<details>
|
|
282
|
-
<summary>
|
|
283
|
-
|
|
284
|
-
Monitors `@Property` and `@State` to catch changes.
|
|
285
|
-
The decorated method will be invoked after any
|
|
286
|
-
changes with the `key`, `newValue`, and `oldValue` as parameters.
|
|
287
|
-
If the arguments aren't defined, all of the `@Property` and `@State` are considered.
|
|
416
|
+
<summary>Method</summary>
|
|
288
417
|
|
|
289
|
-
|
|
418
|
+
Provides a way to encapsulate functionality within an element and invoke it as needed, both internally and externally.
|
|
290
419
|
|
|
291
|
-
|
|
292
|
-
- **type**: string | string[]
|
|
293
|
-
- **default**: undefined
|
|
294
|
-
- **immediate**: Triggers the callback immediately after initialization.
|
|
295
|
-
- **type**: boolean
|
|
296
|
-
- **default**: undefined
|
|
420
|
+
In the `my-counter.tsx` file.
|
|
297
421
|
|
|
298
422
|
```tsx
|
|
299
|
-
import { Element,
|
|
423
|
+
import { Element, Method, State } from '@htmlplus/element';
|
|
300
424
|
|
|
301
425
|
@Element()
|
|
302
|
-
export class
|
|
426
|
+
export class MyCounter {
|
|
427
|
+
@State()
|
|
428
|
+
value: number = 0;
|
|
303
429
|
|
|
304
|
-
@
|
|
305
|
-
|
|
430
|
+
@Method()
|
|
431
|
+
increase() {
|
|
432
|
+
this.value++;
|
|
433
|
+
}
|
|
306
434
|
|
|
307
|
-
|
|
308
|
-
|
|
435
|
+
render() {
|
|
436
|
+
return (
|
|
437
|
+
<host>
|
|
438
|
+
Count is {this.value}
|
|
439
|
+
</host>
|
|
440
|
+
)
|
|
441
|
+
}
|
|
309
442
|
}
|
|
310
443
|
```
|
|
311
444
|
|
|
445
|
+
In the `index.html` file.
|
|
446
|
+
|
|
447
|
+
```html
|
|
448
|
+
<my-counter id="counter"></my-counter>
|
|
449
|
+
|
|
450
|
+
<script>
|
|
451
|
+
setInterval(() => {
|
|
452
|
+
document.getElementById('counter').increase();
|
|
453
|
+
}, 1000);
|
|
454
|
+
</script>
|
|
455
|
+
```
|
|
456
|
+
|
|
312
457
|
</details>
|
|
313
458
|
|
|
314
459
|
<details>
|
|
315
|
-
<summary>
|
|
460
|
+
<summary>Property</summary>
|
|
316
461
|
|
|
317
|
-
|
|
318
|
-
It takes two parameter, event name and event config.
|
|
462
|
+
Creates a reactive property, reflecting a corresponding attribute value, and updates the element when the property is set.
|
|
319
463
|
|
|
320
|
-
|
|
464
|
+
Parameters:
|
|
321
465
|
|
|
322
|
-
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
466
|
+
- `options` (Optional)
|
|
467
|
+
<br />
|
|
468
|
+
The configuration for property decorator.
|
|
469
|
+
<br />
|
|
470
|
+
<br />
|
|
471
|
+
- `reflect` (Optional)
|
|
472
|
+
<br />
|
|
473
|
+
Whether property value is reflected back to the associated attribute. default is `false`.
|
|
474
|
+
<br />
|
|
475
|
+
<br />
|
|
476
|
+
- `type` (Optional)
|
|
477
|
+
<br />
|
|
478
|
+
Do not set the value to this property. This value is automatically set during transpiling.
|
|
479
|
+
<br />
|
|
480
|
+
<br />
|
|
481
|
+
|
|
482
|
+
In the `say-greeting.tsx` file.
|
|
327
483
|
|
|
328
484
|
```tsx
|
|
329
|
-
import { Element,
|
|
485
|
+
import { Element, Property } from '@htmlplus/element';
|
|
330
486
|
|
|
331
487
|
@Element()
|
|
332
|
-
export class
|
|
333
|
-
@
|
|
334
|
-
|
|
488
|
+
export class SayGreeting {
|
|
489
|
+
@Property()
|
|
490
|
+
name?: string = 'Simon';
|
|
491
|
+
|
|
492
|
+
render() {
|
|
493
|
+
return <div>Hi {this.name}</div>
|
|
494
|
+
}
|
|
335
495
|
}
|
|
336
496
|
```
|
|
337
497
|
|
|
338
|
-
|
|
339
|
-
import { Element, Listen } from '@htmlplus/element';
|
|
498
|
+
In the `index.html` file.
|
|
340
499
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
@Listen('scroll', { target: 'window' })
|
|
344
|
-
onScroll(event) {}
|
|
345
|
-
}
|
|
500
|
+
```html
|
|
501
|
+
<say-greeting name="Jan"></say-greeting>
|
|
346
502
|
```
|
|
347
503
|
|
|
504
|
+
</details>
|
|
505
|
+
|
|
506
|
+
<details>
|
|
507
|
+
<summary>Query</summary>
|
|
508
|
+
|
|
509
|
+
Selects the first element in the shadow dom that matches a specified CSS selector.
|
|
510
|
+
|
|
511
|
+
Parameters:
|
|
512
|
+
|
|
513
|
+
- `selectors` (Required)
|
|
514
|
+
<br />
|
|
515
|
+
A string containing one or more selectors to match. This string must be a valid CSS selector string; if it isn't, a `SyntaxError` exception is thrown. See [Locating DOM elements using selectors](https://developer.mozilla.org/en-US/docs/Web/API/Document_object_model/Locating_DOM_elements_using_selectors) for more about selectors and how to manage them.
|
|
516
|
+
<br />
|
|
517
|
+
<br />
|
|
518
|
+
|
|
519
|
+
In the `my-button.tsx` file.
|
|
520
|
+
|
|
348
521
|
```tsx
|
|
349
|
-
import { Element,
|
|
522
|
+
import { Element, Query } from '@htmlplus/element';
|
|
350
523
|
|
|
351
524
|
@Element()
|
|
352
525
|
export class MyButton {
|
|
526
|
+
@Query('.btn')
|
|
527
|
+
buttonRef!: HTMLButtonElement;
|
|
353
528
|
|
|
354
|
-
|
|
355
|
-
|
|
529
|
+
loadedCallback() {
|
|
530
|
+
console.log(this.buttonRef); // <button class="btn"></button>
|
|
531
|
+
}
|
|
356
532
|
|
|
357
533
|
render() {
|
|
358
534
|
return (
|
|
359
|
-
<button
|
|
535
|
+
<button class="btn">
|
|
360
536
|
<slot />
|
|
361
537
|
</button>
|
|
362
538
|
)
|
|
@@ -364,403 +540,367 @@ export class MyButton {
|
|
|
364
540
|
}
|
|
365
541
|
```
|
|
366
542
|
|
|
543
|
+
In the `index.html` file.
|
|
544
|
+
|
|
545
|
+
```html
|
|
546
|
+
<my-button>
|
|
547
|
+
Button
|
|
548
|
+
</my-button>
|
|
549
|
+
```
|
|
550
|
+
|
|
367
551
|
</details>
|
|
368
552
|
|
|
369
553
|
<details>
|
|
370
|
-
<summary>
|
|
554
|
+
<summary>QueryAll</summary>
|
|
371
555
|
|
|
372
|
-
|
|
373
|
-
|
|
556
|
+
Selects all elements in the shadow dom that match a specified CSS selector.
|
|
557
|
+
|
|
558
|
+
Parameters:
|
|
559
|
+
|
|
560
|
+
- `selectors` (Required)
|
|
561
|
+
<br />
|
|
562
|
+
A string containing one or more selectors to match against. This string must be a valid [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors) string; if it's not, a `SyntaxError` exception is thrown. See [Locating DOM elements using selectors](https://developer.mozilla.org/en-US/docs/Web/API/Document_object_model/Locating_DOM_elements_using_selectors) for more information about using selectors to identify elements. Multiple selectors may be specified by separating them using commas.
|
|
563
|
+
<br />
|
|
564
|
+
<br />
|
|
565
|
+
|
|
566
|
+
In the `my-button.tsx` file.
|
|
374
567
|
|
|
375
568
|
```tsx
|
|
376
|
-
import { Element,
|
|
569
|
+
import { Element, QueryAll } from '@htmlplus/element';
|
|
377
570
|
|
|
378
571
|
@Element()
|
|
379
|
-
export class
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
active?: boolean;
|
|
572
|
+
export class MyButton {
|
|
573
|
+
@QueryAll('span')
|
|
574
|
+
spanRefs!: NodeList;
|
|
383
575
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
this.active = !this.active;
|
|
576
|
+
loadedCallback() {
|
|
577
|
+
console.log(this.spanRefs); // [span, span]
|
|
387
578
|
}
|
|
388
579
|
|
|
389
580
|
render() {
|
|
390
581
|
return (
|
|
391
582
|
<button>
|
|
392
|
-
|
|
583
|
+
<span> Suffix </span>
|
|
584
|
+
<b>
|
|
585
|
+
<slot />
|
|
586
|
+
</b>
|
|
587
|
+
<span> Prefix </span>
|
|
393
588
|
</button>
|
|
394
589
|
)
|
|
395
590
|
}
|
|
396
591
|
}
|
|
397
592
|
```
|
|
398
593
|
|
|
594
|
+
In the `index.html` file.
|
|
595
|
+
|
|
596
|
+
```html
|
|
597
|
+
<my-button>
|
|
598
|
+
Button
|
|
599
|
+
</my-button>
|
|
600
|
+
```
|
|
601
|
+
|
|
399
602
|
</details>
|
|
400
603
|
|
|
401
604
|
<details>
|
|
402
|
-
<summary>
|
|
605
|
+
<summary>Slots</summary>
|
|
606
|
+
|
|
607
|
+
Returns the slots name.
|
|
403
608
|
|
|
404
|
-
|
|
609
|
+
In the `my-element.tsx` file.
|
|
405
610
|
|
|
406
611
|
```tsx
|
|
407
|
-
import {
|
|
612
|
+
import { Element, Slots } from '@htmlplus/element';
|
|
408
613
|
|
|
409
614
|
@Element()
|
|
410
|
-
export class
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
onScroll(event) {
|
|
414
|
-
console.log(event);
|
|
415
|
-
}
|
|
615
|
+
export class MyElement {
|
|
616
|
+
@Slots()
|
|
617
|
+
slots;
|
|
416
618
|
|
|
417
619
|
connectedCallback() {
|
|
418
|
-
|
|
620
|
+
console.log(this.slots); // {header: true, default: true, footer: true}
|
|
419
621
|
}
|
|
420
622
|
|
|
421
|
-
|
|
422
|
-
|
|
623
|
+
render() {
|
|
624
|
+
return (
|
|
625
|
+
<host>
|
|
626
|
+
<slot name="header"></slot>
|
|
627
|
+
<slot></slot>
|
|
628
|
+
<slot name="footer"></slot>
|
|
629
|
+
</host>
|
|
630
|
+
)
|
|
423
631
|
}
|
|
424
632
|
}
|
|
425
633
|
```
|
|
426
634
|
|
|
635
|
+
In the `index.html` file.
|
|
636
|
+
|
|
637
|
+
```html
|
|
638
|
+
<my-element>
|
|
639
|
+
<div slot="header">HEADER</div>
|
|
640
|
+
<div>BODY</div>
|
|
641
|
+
<div slot="footer">FOOTER</div>
|
|
642
|
+
</my-element>
|
|
643
|
+
```
|
|
644
|
+
|
|
427
645
|
</details>
|
|
428
646
|
|
|
429
|
-
|
|
647
|
+
<details>
|
|
648
|
+
<summary>State</summary>
|
|
430
649
|
|
|
431
|
-
|
|
650
|
+
Applying this decorator to any `class property` will trigger the element to re-render upon the desired property changes.
|
|
432
651
|
|
|
433
|
-
|
|
652
|
+
In the `my-button.tsx` file.
|
|
434
653
|
|
|
435
|
-
|
|
654
|
+
```tsx
|
|
655
|
+
import { Element, State } from '@htmlplus/element';
|
|
436
656
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
657
|
+
@Element()
|
|
658
|
+
export class MyButton {
|
|
659
|
+
@State()
|
|
660
|
+
active?: boolean;
|
|
440
661
|
|
|
441
|
-
|
|
662
|
+
toggle() {
|
|
663
|
+
this.active = !this.active;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
render() {
|
|
667
|
+
return (
|
|
668
|
+
<button onClick={() => this.toggle()}>
|
|
669
|
+
Click To Change The Status ({this.active ? 'On' : 'Off'})
|
|
670
|
+
</button>
|
|
671
|
+
)
|
|
672
|
+
}
|
|
673
|
+
}
|
|
442
674
|
```
|
|
443
675
|
|
|
444
|
-
|
|
445
|
-
<summary>classes</summary>
|
|
676
|
+
In the `index.html` file.
|
|
446
677
|
|
|
447
|
-
|
|
448
|
-
|
|
678
|
+
```html
|
|
679
|
+
<my-button></my-button>
|
|
680
|
+
```
|
|
449
681
|
|
|
450
682
|
</details>
|
|
451
683
|
|
|
452
684
|
<details>
|
|
453
|
-
<summary>
|
|
685
|
+
<summary>Watch</summary>
|
|
686
|
+
|
|
687
|
+
Monitors `@Property()` and `@State()` to detect changes. The decorated method will be called after any changes, with the `key`, `newValue`, and `oldValue` as parameters. If the `key` is not defined, all `@Property()` and `@State()` are considered.
|
|
688
|
+
|
|
689
|
+
Parameters:
|
|
454
690
|
|
|
455
|
-
|
|
691
|
+
- `keys` (Optional)
|
|
692
|
+
<br />
|
|
693
|
+
Collection of `@Property()` and `@State()` names.
|
|
694
|
+
<br />
|
|
695
|
+
<br />
|
|
696
|
+
- `immediate` (Optional)
|
|
697
|
+
<br />
|
|
698
|
+
Triggers the callback immediately after initialization.
|
|
699
|
+
<br />
|
|
700
|
+
<br />
|
|
456
701
|
|
|
457
|
-
|
|
458
|
-
|
|
702
|
+
In the `my-element.tsx` file.
|
|
703
|
+
|
|
704
|
+
```tsx
|
|
705
|
+
import { Element, Property, Watch } from '@htmlplus/element';
|
|
459
706
|
|
|
460
707
|
@Element()
|
|
461
708
|
export class MyElement {
|
|
462
|
-
|
|
463
|
-
|
|
709
|
+
@Property()
|
|
710
|
+
value?: string;
|
|
711
|
+
|
|
712
|
+
@Watch('value')
|
|
713
|
+
watcher(key, newValue, oldValue) {
|
|
714
|
+
console.log(key, newValue, oldValue);
|
|
464
715
|
}
|
|
465
716
|
}
|
|
466
717
|
```
|
|
467
718
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
<details>
|
|
471
|
-
<summary>event</summary>
|
|
472
|
-
|
|
473
|
-
`Event` is a wrapper of event listener, in JavaScript. `on` is like a `addEventListener` and `off` is like `removeEventListener` and used when you want to add or remove event on `window | documnet | Element`.
|
|
474
|
-
|
|
475
|
-
Options:
|
|
719
|
+
In the `index.html` file.
|
|
476
720
|
|
|
477
|
-
|
|
478
|
-
-
|
|
479
|
-
- handler: `EventListenerOrEventListenerObject`
|
|
480
|
-
- options: `boolean | AddEventListenerOptions`
|
|
721
|
+
```html
|
|
722
|
+
<my-element id="element"></my-element>
|
|
481
723
|
|
|
482
|
-
|
|
483
|
-
|
|
724
|
+
<script>
|
|
725
|
+
setInterval(() => {
|
|
726
|
+
document.getElementById('element').value = new Date();
|
|
727
|
+
}, 1000);
|
|
728
|
+
</script>
|
|
729
|
+
```
|
|
484
730
|
|
|
485
|
-
|
|
486
|
-
export class MyElement {
|
|
731
|
+
</details>
|
|
487
732
|
|
|
488
|
-
|
|
489
|
-
onClick(event) {
|
|
490
|
-
console.log(event);
|
|
491
|
-
}
|
|
733
|
+
## Utilities
|
|
492
734
|
|
|
493
|
-
|
|
494
|
-
on(window, 'click', this.onClick /*, options*/);
|
|
495
|
-
}
|
|
735
|
+
Utilities are a versatile tool in element building projects, eliminating the need for rewriting.
|
|
496
736
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
```
|
|
737
|
+
<details>
|
|
738
|
+
<summary>classes</summary>
|
|
739
|
+
TODO
|
|
740
|
+
</details>
|
|
502
741
|
|
|
742
|
+
<details>
|
|
743
|
+
<summary>getConfig</summary>
|
|
744
|
+
TODO
|
|
503
745
|
</details>
|
|
504
746
|
|
|
505
747
|
<details>
|
|
506
|
-
<summary>
|
|
748
|
+
<summary>setConfig</summary>
|
|
749
|
+
TODO
|
|
750
|
+
</details>
|
|
507
751
|
|
|
508
|
-
|
|
752
|
+
<details>
|
|
753
|
+
<summary>direction</summary>
|
|
509
754
|
|
|
510
|
-
|
|
511
|
-
import { Element, host } from '@htmlplus/element';
|
|
755
|
+
Indicates whether the [Direction](https://mdn.io/css-direction) of the element is `Right-To-Left` or `Left-To-Right`.
|
|
512
756
|
|
|
513
|
-
|
|
514
|
-
export class MyElement {
|
|
515
|
-
connectedCallback() {
|
|
516
|
-
host(this); // <my-element></my-element>
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
```
|
|
757
|
+
TODO
|
|
520
758
|
|
|
521
759
|
</details>
|
|
522
760
|
|
|
523
761
|
<details>
|
|
524
|
-
<summary>
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
```js
|
|
529
|
-
import { Element, isRTL } from '@htmlplus/element';
|
|
762
|
+
<summary>host</summary>
|
|
763
|
+
|
|
764
|
+
Indicates the host of the element.
|
|
530
765
|
|
|
531
|
-
|
|
532
|
-
export class MyElement {
|
|
533
|
-
connectedCallback() {
|
|
534
|
-
isRTL(this); // false | true
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
```
|
|
766
|
+
TODO
|
|
538
767
|
|
|
539
768
|
</details>
|
|
540
769
|
|
|
541
770
|
<details>
|
|
542
|
-
<summary>
|
|
771
|
+
<summary>isCSSColor</summary>
|
|
543
772
|
|
|
544
|
-
|
|
773
|
+
Determines whether the given input string is a valid
|
|
774
|
+
[CSS Color](https://developer.mozilla.org/docs/Web/CSS/color_value)
|
|
775
|
+
or not.
|
|
545
776
|
|
|
546
|
-
|
|
547
|
-
import { Element, isServer } from '@htmlplus/element';
|
|
777
|
+
TODO
|
|
548
778
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
779
|
+
```js
|
|
780
|
+
isCSSColor('red') // true
|
|
781
|
+
isCSSColor('#ff0000') // true
|
|
782
|
+
isCSSColor('#ff000080') // true
|
|
783
|
+
isCSSColor('rgb(255, 0, 0)') // true
|
|
784
|
+
isCSSColor('rgba(255, 0, 0, 0.3)') // true
|
|
785
|
+
isCSSColor('hsl(120, 100%, 50%)') // true
|
|
786
|
+
isCSSColor('hsla(120, 100%, 50%, 0.3)') // true
|
|
787
|
+
isCSSColor('invalid color') // false
|
|
555
788
|
```
|
|
556
789
|
|
|
557
790
|
</details>
|
|
558
791
|
|
|
559
792
|
<details>
|
|
560
|
-
<summary>
|
|
561
|
-
|
|
562
|
-
Is a wrapper of `querySelector` Is a way to find an element with a specific features.
|
|
563
|
-
|
|
564
|
-
Options:
|
|
565
|
-
|
|
566
|
-
- target: `HTML Element` or `Element Component(this)`
|
|
567
|
-
- selectors: `string` any specific features such as `id`, `class`, `element name`, ...
|
|
568
|
-
|
|
569
|
-
```js
|
|
570
|
-
import { Element, query } from '@htmlplus/element';
|
|
571
|
-
|
|
572
|
-
@Element()
|
|
573
|
-
export class MyElement {
|
|
793
|
+
<summary>isRTL</summary>
|
|
574
794
|
|
|
575
|
-
|
|
576
|
-
query(this, 'h1'); // <h1></h1>
|
|
577
|
-
query(this, '#first'); // <h2></h2>
|
|
578
|
-
query(this, '.second'); // <h3></h3>
|
|
579
|
-
}
|
|
795
|
+
Indicates whether the direction of the element is `Right-To-Left` or not.
|
|
580
796
|
|
|
581
|
-
|
|
582
|
-
return (
|
|
583
|
-
<div>
|
|
584
|
-
<h1></h1>
|
|
585
|
-
<h2 id="first"></h2>
|
|
586
|
-
<h3 class="second"></h3>
|
|
587
|
-
</div>
|
|
588
|
-
)
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
```
|
|
797
|
+
TODO
|
|
592
798
|
|
|
593
799
|
</details>
|
|
594
800
|
|
|
595
801
|
<details>
|
|
596
|
-
<summary>
|
|
802
|
+
<summary>on</summary>
|
|
803
|
+
TODO
|
|
804
|
+
</details>
|
|
597
805
|
|
|
598
|
-
|
|
806
|
+
<details>
|
|
807
|
+
<summary>off</summary>
|
|
808
|
+
TODO
|
|
809
|
+
</details>
|
|
599
810
|
|
|
600
|
-
|
|
811
|
+
<details>
|
|
812
|
+
<summary>query</summary>
|
|
601
813
|
|
|
602
|
-
|
|
603
|
-
- selectors: `string` any specific features such as `id`, `class`, `element name`, ...
|
|
814
|
+
Selects the first element in the shadow dom that matches a specified CSS selector.
|
|
604
815
|
|
|
605
|
-
|
|
606
|
-
import { Element, queryAll } from '@htmlplus/element';
|
|
816
|
+
TODO
|
|
607
817
|
|
|
608
|
-
|
|
609
|
-
export class MyElement {
|
|
818
|
+
</details>
|
|
610
819
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
820
|
+
<details>
|
|
821
|
+
<summary>queryAll</summary>
|
|
822
|
+
|
|
823
|
+
Selects all elements in the shadow dom that match a specified CSS selector.
|
|
614
824
|
|
|
615
|
-
|
|
616
|
-
return (
|
|
617
|
-
<div>
|
|
618
|
-
<h1></h1>
|
|
619
|
-
<h2 id="first"></h2>
|
|
620
|
-
<h3 class="second"></h3>
|
|
621
|
-
</div>
|
|
622
|
-
)
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
```
|
|
825
|
+
TODO
|
|
626
826
|
|
|
627
827
|
</details>
|
|
628
828
|
|
|
629
829
|
<details>
|
|
630
830
|
<summary>slots</summary>
|
|
631
831
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
`slots` return the state of the slots of a component (is empty or not).
|
|
635
|
-
|
|
636
|
-
```js
|
|
637
|
-
import { Element, Property, slots } from '@htmlplus/element';
|
|
832
|
+
Returns the slots name.
|
|
638
833
|
|
|
639
|
-
|
|
640
|
-
export class MyElement {
|
|
834
|
+
TODO
|
|
641
835
|
|
|
642
|
-
|
|
643
|
-
slots(this) // { default: true, main: true, empty: false }
|
|
644
|
-
}
|
|
836
|
+
</details>
|
|
645
837
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
<slot name="main" />
|
|
651
|
-
<slot name="empty" />
|
|
652
|
-
</div>
|
|
653
|
-
)
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
```
|
|
838
|
+
<details>
|
|
839
|
+
<summary>styles</summary>
|
|
840
|
+
|
|
841
|
+
Converts a JavaScript object containing CSS styles to a CSS string.
|
|
657
842
|
|
|
658
|
-
|
|
659
|
-
<my-element>
|
|
660
|
-
<h1></h1>
|
|
661
|
-
<h2 slot="main"></h2>
|
|
662
|
-
<h3 slot="extra"></h3>
|
|
663
|
-
</my-element>
|
|
664
|
-
```
|
|
843
|
+
TODO
|
|
665
844
|
|
|
666
845
|
</details>
|
|
667
846
|
|
|
668
847
|
<details>
|
|
669
|
-
<summary>
|
|
670
|
-
|
|
671
|
-
Returns css style of your `array` or `object` style.
|
|
848
|
+
<summary>toUnit</summary>
|
|
672
849
|
|
|
673
|
-
|
|
850
|
+
Converts a value to a unit.
|
|
674
851
|
|
|
675
|
-
|
|
852
|
+
TODO
|
|
676
853
|
|
|
677
|
-
|
|
678
|
-
import { Element, Property, styles } from '@htmlplus/element';
|
|
854
|
+
</details>
|
|
679
855
|
|
|
680
|
-
|
|
681
|
-
export class MyElement {
|
|
856
|
+
## JSX
|
|
682
857
|
|
|
683
|
-
|
|
684
|
-
top?: number = 0;
|
|
858
|
+
TODO
|
|
685
859
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
top: this.top + 'px',
|
|
689
|
-
position: 'absolute',
|
|
690
|
-
})
|
|
691
|
-
}
|
|
860
|
+
<details>
|
|
861
|
+
<summary>host</summary>
|
|
692
862
|
|
|
693
|
-
|
|
694
|
-
return (
|
|
695
|
-
<div style={this.styles}>
|
|
696
|
-
<slot />
|
|
697
|
-
</div>
|
|
698
|
-
)
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
```
|
|
863
|
+
TODO
|
|
702
864
|
|
|
703
865
|
</details>
|
|
704
866
|
|
|
705
867
|
<details>
|
|
706
|
-
<summary>
|
|
707
|
-
|
|
708
|
-
Transformer to `number` type or make unit based on unit input.
|
|
709
|
-
|
|
710
|
-
Options:
|
|
868
|
+
<summary>part</summary>
|
|
711
869
|
|
|
712
|
-
|
|
713
|
-
- unit: `string`
|
|
870
|
+
TODO
|
|
714
871
|
|
|
715
|
-
|
|
716
|
-
import { Element, Property, toUnit } from '@htmlplus/element';
|
|
872
|
+
</details>
|
|
717
873
|
|
|
718
|
-
|
|
719
|
-
export class MyElement {
|
|
874
|
+
## Lifecycles
|
|
720
875
|
|
|
721
|
-
|
|
722
|
-
width?: string | number;
|
|
876
|
+
Elements encompass several lifecycle methods, each triggered at different stages in the element's life cycle, enabling developers to control the element's behavior and perform customized actions.
|
|
723
877
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
<div style={`width: ${toUnit(this.width)}`}>
|
|
727
|
-
<slot />
|
|
728
|
-
</div>
|
|
729
|
-
)
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
```
|
|
878
|
+
<details>
|
|
879
|
+
<summary>adoptedCallback</summary>
|
|
733
880
|
|
|
734
|
-
|
|
735
|
-
<my-element width="150"></my-element> <!-- 150px -->
|
|
736
|
-
<my-element width="150px"></my-element> <!-- 150px -->
|
|
737
|
-
```
|
|
881
|
+
TODO
|
|
738
882
|
|
|
739
883
|
</details>
|
|
740
884
|
|
|
741
|
-
|
|
885
|
+
<details>
|
|
886
|
+
<summary>connectCallback</summary>
|
|
742
887
|
|
|
743
|
-
|
|
888
|
+
TODO
|
|
889
|
+
|
|
890
|
+
</details>
|
|
744
891
|
|
|
745
892
|
<details>
|
|
746
893
|
<summary>connectedCallback</summary>
|
|
747
894
|
|
|
748
|
-
|
|
895
|
+
A lifecycle callback method that is called each time the element is added to the document.
|
|
749
896
|
|
|
750
897
|
```js
|
|
751
898
|
import { Element } from '@htmlplus/element';
|
|
752
899
|
|
|
753
900
|
@Element()
|
|
754
901
|
export class MyElement {
|
|
755
|
-
|
|
756
902
|
connectedCallback() {
|
|
757
|
-
console.log(
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
render() {
|
|
761
|
-
return (
|
|
762
|
-
<slot />
|
|
763
|
-
)
|
|
903
|
+
console.log('Element is connected!');
|
|
764
904
|
}
|
|
765
905
|
}
|
|
766
906
|
```
|
|
@@ -770,22 +910,15 @@ export class MyElement {
|
|
|
770
910
|
<details>
|
|
771
911
|
<summary>disconnectedCallback</summary>
|
|
772
912
|
|
|
773
|
-
|
|
913
|
+
TODO
|
|
774
914
|
|
|
775
915
|
```js
|
|
776
916
|
import { Element } from '@htmlplus/element';
|
|
777
917
|
|
|
778
918
|
@Element()
|
|
779
919
|
export class MyElement {
|
|
780
|
-
|
|
781
920
|
disconnectedCallback() {
|
|
782
|
-
console.log(
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
render() {
|
|
786
|
-
return (
|
|
787
|
-
<slot />
|
|
788
|
-
)
|
|
921
|
+
console.log('Element is disconnected!');
|
|
789
922
|
}
|
|
790
923
|
}
|
|
791
924
|
```
|
|
@@ -795,22 +928,15 @@ export class MyElement {
|
|
|
795
928
|
<details>
|
|
796
929
|
<summary>loadedCallback</summary>
|
|
797
930
|
|
|
798
|
-
|
|
931
|
+
TODO
|
|
799
932
|
|
|
800
933
|
```js
|
|
801
934
|
import { Element } from '@htmlplus/element';
|
|
802
935
|
|
|
803
936
|
@Element()
|
|
804
937
|
export class MyElement {
|
|
805
|
-
|
|
806
938
|
loadedCallback() {
|
|
807
|
-
console.log(
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
render() {
|
|
811
|
-
return (
|
|
812
|
-
<slot />
|
|
813
|
-
)
|
|
939
|
+
console.log('Element is loaded!');
|
|
814
940
|
}
|
|
815
941
|
}
|
|
816
942
|
```
|
|
@@ -818,143 +944,99 @@ export class MyElement {
|
|
|
818
944
|
</details>
|
|
819
945
|
|
|
820
946
|
<details>
|
|
821
|
-
<summary>
|
|
822
|
-
|
|
823
|
-
Called everytime when `states` or `props` changed.It's never called during the first `render()`.
|
|
824
|
-
|
|
825
|
-
```js
|
|
826
|
-
import { Element } from '@htmlplus/element';
|
|
827
|
-
|
|
828
|
-
@Element()
|
|
829
|
-
export class MyElement {
|
|
947
|
+
<summary>updateCallback</summary>
|
|
830
948
|
|
|
831
|
-
|
|
832
|
-
console.log("Component is updated!")
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
render() {
|
|
836
|
-
return (
|
|
837
|
-
<slot />
|
|
838
|
-
)
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
```
|
|
949
|
+
TODO
|
|
842
950
|
|
|
843
951
|
</details>
|
|
844
952
|
|
|
845
953
|
<details>
|
|
846
|
-
<summary>
|
|
954
|
+
<summary>updatedCallback</summary>
|
|
847
955
|
|
|
848
956
|
TODO
|
|
849
957
|
|
|
850
958
|
</details>
|
|
851
959
|
|
|
852
|
-
##
|
|
960
|
+
## Bundlers
|
|
853
961
|
|
|
854
962
|
TODO
|
|
855
963
|
|
|
856
964
|
<details>
|
|
857
|
-
<summary>
|
|
965
|
+
<summary>Rollup</summary>
|
|
858
966
|
|
|
859
967
|
TODO
|
|
860
968
|
|
|
861
969
|
</details>
|
|
862
970
|
|
|
863
|
-
## Tag Name Configuration
|
|
864
|
-
|
|
865
|
-
All examples below produce output `<plus-button></plus-button>`
|
|
866
|
-
|
|
867
971
|
<details>
|
|
868
|
-
<summary>
|
|
869
|
-
|
|
870
|
-
You can give the final name of your component as an input to the `@Element`.
|
|
871
|
-
|
|
872
|
-
```js
|
|
873
|
-
import { Element } from '@htmlplus/element';
|
|
874
|
-
|
|
875
|
-
@Element('plus-button')
|
|
876
|
-
export class Button {}
|
|
877
|
-
```
|
|
878
|
-
|
|
879
|
-
</details>
|
|
880
|
-
|
|
881
|
-
<details>
|
|
882
|
-
<summary>Class name with at least 2 syllables</summary>
|
|
883
|
-
|
|
884
|
-
The name of your element should eventually be `two` syllables.
|
|
885
|
-
|
|
886
|
-
```js
|
|
887
|
-
import { Element } from '@htmlplus/element';
|
|
888
|
-
|
|
889
|
-
@Element()
|
|
890
|
-
export class PlusButton {} // <plus-button></plus-button>
|
|
891
|
-
```
|
|
892
|
-
|
|
893
|
-
</details>
|
|
894
|
-
|
|
895
|
-
<details>
|
|
896
|
-
<summary>With global prefix (recommended)</summary>
|
|
897
|
-
|
|
898
|
-
You can set a prefix for all elements and this prefix attached to all elements.
|
|
899
|
-
|
|
900
|
-
```js
|
|
901
|
-
import { Element } from '@htmlplus/element';
|
|
902
|
-
|
|
903
|
-
@Element()
|
|
904
|
-
export class Button {}
|
|
905
|
-
```
|
|
906
|
-
|
|
907
|
-
Use `prefix` key in `plus.config.js` file.
|
|
908
|
-
|
|
909
|
-
```js
|
|
910
|
-
export default [
|
|
911
|
-
...
|
|
912
|
-
extract({
|
|
913
|
-
prefix: 'plus',
|
|
914
|
-
})
|
|
915
|
-
...
|
|
916
|
-
]
|
|
917
|
-
```
|
|
918
|
-
|
|
919
|
-
</details>
|
|
920
|
-
|
|
921
|
-
<details>
|
|
922
|
-
<summary>Conditional</summary>
|
|
972
|
+
<summary>Vite</summary>
|
|
923
973
|
|
|
924
974
|
TODO
|
|
925
975
|
|
|
926
976
|
</details>
|
|
927
977
|
|
|
928
|
-
##
|
|
978
|
+
## Transformer
|
|
929
979
|
|
|
930
980
|
TODO
|
|
931
981
|
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
const { start, next, finish } = compiler(...plugins);
|
|
936
|
-
```
|
|
937
|
-
|
|
938
|
-
## Compiler plugins
|
|
982
|
+
<details>
|
|
983
|
+
<summary>Getting Started</summary>
|
|
939
984
|
|
|
940
985
|
TODO
|
|
941
986
|
|
|
942
|
-
```
|
|
943
|
-
import {
|
|
944
|
-
import {
|
|
945
|
-
|
|
946
|
-
|
|
987
|
+
```ts
|
|
988
|
+
import { TransformerPlugin, transformer } from '@htmlplus/element';
|
|
989
|
+
import {
|
|
990
|
+
customElement,
|
|
991
|
+
extract,
|
|
992
|
+
parse,
|
|
993
|
+
read,
|
|
994
|
+
style,
|
|
995
|
+
validate,
|
|
996
|
+
} from '@htmlplus/element/transformer/index.js';
|
|
997
|
+
|
|
998
|
+
const plugins = [
|
|
947
999
|
read(),
|
|
948
1000
|
parse(),
|
|
949
1001
|
validate(),
|
|
950
1002
|
extract(),
|
|
951
1003
|
style(),
|
|
952
|
-
customElement()
|
|
953
|
-
|
|
1004
|
+
customElement()
|
|
1005
|
+
];
|
|
1006
|
+
|
|
1007
|
+
const { start, run, finish } = transformer(...plugins);
|
|
954
1008
|
|
|
955
1009
|
await start();
|
|
956
1010
|
|
|
957
|
-
const
|
|
1011
|
+
const context1 = await run('/my-avatar.tsx');
|
|
1012
|
+
const context2 = await run('/my-button.tsx');
|
|
1013
|
+
const context3 = await run('/my-switch.tsx');
|
|
958
1014
|
|
|
959
1015
|
await finish();
|
|
960
1016
|
```
|
|
1017
|
+
|
|
1018
|
+
</details>
|
|
1019
|
+
|
|
1020
|
+
<details>
|
|
1021
|
+
<summary>Plugins</summary>
|
|
1022
|
+
|
|
1023
|
+
TODO
|
|
1024
|
+
|
|
1025
|
+
```ts
|
|
1026
|
+
import {
|
|
1027
|
+
assets,
|
|
1028
|
+
copy,
|
|
1029
|
+
customElement,
|
|
1030
|
+
document,
|
|
1031
|
+
extract,
|
|
1032
|
+
parse,
|
|
1033
|
+
read,
|
|
1034
|
+
readme,
|
|
1035
|
+
style,
|
|
1036
|
+
validate,
|
|
1037
|
+
visualStudioCode,
|
|
1038
|
+
webTypes
|
|
1039
|
+
} from '@htmlplus/element/transformer/index.js';
|
|
1040
|
+
```
|
|
1041
|
+
|
|
1042
|
+
</details>
|