p-elements-core 1.2.32-rc8 → 1.2.32
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/.editorconfig +17 -17
- package/.gitlab-ci.yml +18 -18
- package/CHANGELOG.md +201 -201
- package/demo/sample.js +1 -1
- package/demo/screen.css +16 -16
- package/dist/p-elements-core-modern.js +1 -1
- package/dist/p-elements-core.js +1 -1
- package/docs/package-lock.json +6897 -6897
- package/docs/package.json +27 -27
- package/docs/src/404.md +8 -8
- package/docs/src/_data/demos/hello-world/hello-world.tsx +35 -35
- package/docs/src/_data/demos/hello-world/index.html +10 -10
- package/docs/src/_data/demos/hello-world/project.json +7 -7
- package/docs/src/_data/demos/timer/demo-timer.tsx +120 -120
- package/docs/src/_data/demos/timer/icons.tsx +62 -62
- package/docs/src/_data/demos/timer/index.html +12 -12
- package/docs/src/_data/demos/timer/project.json +8 -8
- package/docs/src/_data/global.js +13 -13
- package/docs/src/_data/helpers.js +19 -19
- package/docs/src/_includes/layouts/base.njk +30 -30
- package/docs/src/_includes/layouts/playground.njk +40 -40
- package/docs/src/_includes/partials/app-header.njk +8 -8
- package/docs/src/_includes/partials/head.njk +14 -14
- package/docs/src/_includes/partials/nav.njk +19 -19
- package/docs/src/_includes/partials/top-nav.njk +51 -51
- package/docs/src/documentation/custom-element.md +221 -221
- package/docs/src/documentation/decorators/bind.md +71 -71
- package/docs/src/documentation/decorators/custom-element-config.md +63 -63
- package/docs/src/documentation/decorators/property.md +83 -83
- package/docs/src/documentation/decorators/query.md +66 -66
- package/docs/src/documentation/decorators/render-property-on-set.md +60 -60
- package/docs/src/documentation/decorators.md +9 -9
- package/docs/src/documentation/reactive-properties.md +53 -53
- package/docs/src/index.d.ts +25 -25
- package/docs/src/index.md +3 -3
- package/docs/src/scripts/components/app-mode-switch/app-mode-switch.css +78 -78
- package/docs/src/scripts/components/app-mode-switch/app-mode-switch.tsx +166 -166
- package/docs/src/scripts/components/app-playground/app-playground.tsx +189 -189
- package/docs/tsconfig.json +22 -22
- package/index.html +10 -2
- package/package.json +1 -1
- package/readme.md +206 -206
- package/src/custom-element-controller.ts +31 -31
- package/src/custom-element.test.ts +906 -906
- package/src/custom-element.ts +3 -8
- package/src/decorators/bind.test.ts +163 -163
- package/src/decorators/bind.ts +46 -46
- package/src/decorators/custom-element-config.ts +17 -17
- package/src/decorators/property.test.ts +279 -279
- package/src/decorators/query.test.ts +146 -146
- package/src/decorators/query.ts +12 -12
- package/src/decorators/render-property-on-set.ts +3 -3
- package/src/helpers/css.ts +71 -71
- package/src/maquette/cache.ts +35 -35
- package/src/maquette/dom.ts +115 -115
- package/src/maquette/h.ts +100 -100
- package/src/maquette/index.ts +12 -12
- package/src/maquette/interfaces.ts +536 -536
- package/src/maquette/jsx.ts +61 -61
- package/src/maquette/mapping.ts +56 -56
- package/src/maquette/projection.ts +666 -666
- package/src/maquette/projector.ts +205 -205
- package/src/sample/mixin/highlight.tsx +33 -33
- package/src/sample/sample.tsx +98 -0
package/readme.md
CHANGED
|
@@ -1,206 +1,206 @@
|
|
|
1
|
-
# P-Element
|
|
2
|
-
|
|
3
|
-
## CustomElement base class
|
|
4
|
-
|
|
5
|
-
### Static properties
|
|
6
|
-
|
|
7
|
-
#### `projectorMode` "append", "merge" or "replace"
|
|
8
|
-
|
|
9
|
-
The projector mode when using `templateFromString` function
|
|
10
|
-
|
|
11
|
-
#### `style` string
|
|
12
|
-
|
|
13
|
-
The style is adopted to the rootNode.
|
|
14
|
-
if this is set there is no need for calling `templateFromString`. A root node is created and replaced with the result of the `render` function.
|
|
15
|
-
|
|
16
|
-
example
|
|
17
|
-
|
|
18
|
-
``` typescript
|
|
19
|
-
class MyElement extends CustomElement {
|
|
20
|
-
static style = `
|
|
21
|
-
:host {
|
|
22
|
-
color: red;
|
|
23
|
-
}`;
|
|
24
|
-
|
|
25
|
-
render = () :VNode {
|
|
26
|
-
return <div>Hello world</div>;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
#### `isFormAssociated` boolean
|
|
32
|
-
|
|
33
|
-
If true, elementInternals are created using attachInternals in the constructor.
|
|
34
|
-
|
|
35
|
-
example
|
|
36
|
-
|
|
37
|
-
``` typescript
|
|
38
|
-
class MyElement extends CustomElement {
|
|
39
|
-
|
|
40
|
-
static isFormAssociated = true;
|
|
41
|
-
|
|
42
|
-
@Property({type: "string", attribute: "value", reflect: true })
|
|
43
|
-
value: string = "Peter" ;
|
|
44
|
-
|
|
45
|
-
updated(property: string, oldValue: any, newValue: any) {
|
|
46
|
-
if (property === "value"){
|
|
47
|
-
this.internals.setFormValue(this.value);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
render = () :VNode {
|
|
52
|
-
return <div>Hello {this.value}.</div>;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Decorators
|
|
58
|
-
|
|
59
|
-
#### `@CustomElementConfig`
|
|
60
|
-
|
|
61
|
-
Use this decorator to define the custom element
|
|
62
|
-
|
|
63
|
-
example
|
|
64
|
-
|
|
65
|
-
``` typescript
|
|
66
|
-
@CustomElementConfig({
|
|
67
|
-
tagName: "p-foo",
|
|
68
|
-
})
|
|
69
|
-
class PFooElement extends CustomElement {
|
|
70
|
-
...
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
If you want to extend a build in component you need to specify the buildin.
|
|
75
|
-
|
|
76
|
-
example
|
|
77
|
-
|
|
78
|
-
``` typescript
|
|
79
|
-
@CustomElementConfig({
|
|
80
|
-
tagName: "super-a",
|
|
81
|
-
options: {
|
|
82
|
-
extends: "a",
|
|
83
|
-
},
|
|
84
|
-
})
|
|
85
|
-
class SuperAnchorElement extends HTMLAnchorElement {
|
|
86
|
-
...
|
|
87
|
-
}
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
#### `@Property`
|
|
91
|
-
|
|
92
|
-
Use the `@Property` decorator to define reactive properties.
|
|
93
|
-
|
|
94
|
-
example
|
|
95
|
-
|
|
96
|
-
``` typescript
|
|
97
|
-
@CustomElementConfig({
|
|
98
|
-
tagName: "p-foo",
|
|
99
|
-
})
|
|
100
|
-
class PFooElement extends CustomElement {
|
|
101
|
-
...
|
|
102
|
-
|
|
103
|
-
@Property({type: "string", attribute: "nick-name", reflect: true})
|
|
104
|
-
nickName: string;
|
|
105
|
-
|
|
106
|
-
attributeChangedCallback(name: string, oldValue: string, newValue: string): void {
|
|
107
|
-
super.attributeChangedCallback(name, oldValue, newValue);
|
|
108
|
-
...
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
The `type` option could be "string", "number", "boolean" or "object".
|
|
112
|
-
|
|
113
|
-
If `attribute` option is set the property will be set on attribute change. If you implement a `attributeChangeCallback` you need to call the `super.attributeChangedCallback`.
|
|
114
|
-
|
|
115
|
-
If `reflect` is `true` the attribute is set on property change.
|
|
116
|
-
|
|
117
|
-
Use `converter` option to convert attribute to property
|
|
118
|
-
|
|
119
|
-
``` typescript
|
|
120
|
-
const stringArrayConverter: AttributeConverter<string[]> = {
|
|
121
|
-
fromAttribute: (value) => {
|
|
122
|
-
if (!value) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
return value.split(",").map((v) => v.trim());
|
|
126
|
-
},
|
|
127
|
-
toAttribute: (value) => {
|
|
128
|
-
if (!value.join) {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
return value.join(",");
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
class MyElement extend CustomElement {
|
|
136
|
-
@Property({attribute: "items", reflect: true, converter: stringArrayConverter})
|
|
137
|
-
items: string[] = ["foo", "bar"];
|
|
138
|
-
}
|
|
139
|
-
```
|
|
140
|
-
#### `@Query` decorator
|
|
141
|
-
|
|
142
|
-
Use the `@Query` decorator to define a property that returns an element from the shadow dom.
|
|
143
|
-
|
|
144
|
-
example
|
|
145
|
-
|
|
146
|
-
``` typescript
|
|
147
|
-
class PFooElement extends CustomElement {
|
|
148
|
-
...
|
|
149
|
-
@Query("#MyInput")
|
|
150
|
-
nameInput: HTMLInputElement;
|
|
151
|
-
|
|
152
|
-
render = () => {
|
|
153
|
-
return <div>
|
|
154
|
-
<label for="MyInput"></label>
|
|
155
|
-
<input type="text" id="MyInput" />
|
|
156
|
-
</div>;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
#### `@PropertyRenderOnSet` `@RenderOnSet`
|
|
162
|
-
|
|
163
|
-
Properties decorated with `@PropertyRenderOnSet` or `@RenderOnSet` call renderNow when setting a value.
|
|
164
|
-
|
|
165
|
-
example
|
|
166
|
-
|
|
167
|
-
``` typescript
|
|
168
|
-
class PFooElement extends CustomElement {
|
|
169
|
-
...
|
|
170
|
-
@PropertyRenderOnSet
|
|
171
|
-
public foo: string = "foo";
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
#### `@Bind`
|
|
176
|
-
(deprecated, use arrow function `myFn = () => console.log('myFn')`)
|
|
177
|
-
|
|
178
|
-
Functions decorated with `@Bind` will be replaced with the result of bind(this) on the function.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
### Hooks
|
|
182
|
-
|
|
183
|
-
#### `init`
|
|
184
|
-
|
|
185
|
-
The init is the first function called after initialising of the custom element
|
|
186
|
-
|
|
187
|
-
#### `shouldUpdate`
|
|
188
|
-
|
|
189
|
-
Before a property is set to a new value
|
|
190
|
-
|
|
191
|
-
#### `updated`
|
|
192
|
-
|
|
193
|
-
After a property value is set to a new value
|
|
194
|
-
|
|
195
|
-
#### `renderStart`
|
|
196
|
-
|
|
197
|
-
When the custom element start the rendering
|
|
198
|
-
|
|
199
|
-
#### `renderDone`
|
|
200
|
-
|
|
201
|
-
When the custom element is finished rendering
|
|
202
|
-
|
|
203
|
-
#### `attributeChangedCallback`
|
|
204
|
-
|
|
205
|
-
Call `super.attributeChangedCallback()` first.
|
|
206
|
-
|
|
1
|
+
# P-Element
|
|
2
|
+
|
|
3
|
+
## CustomElement base class
|
|
4
|
+
|
|
5
|
+
### Static properties
|
|
6
|
+
|
|
7
|
+
#### `projectorMode` "append", "merge" or "replace"
|
|
8
|
+
|
|
9
|
+
The projector mode when using `templateFromString` function
|
|
10
|
+
|
|
11
|
+
#### `style` string
|
|
12
|
+
|
|
13
|
+
The style is adopted to the rootNode.
|
|
14
|
+
if this is set there is no need for calling `templateFromString`. A root node is created and replaced with the result of the `render` function.
|
|
15
|
+
|
|
16
|
+
example
|
|
17
|
+
|
|
18
|
+
``` typescript
|
|
19
|
+
class MyElement extends CustomElement {
|
|
20
|
+
static style = `
|
|
21
|
+
:host {
|
|
22
|
+
color: red;
|
|
23
|
+
}`;
|
|
24
|
+
|
|
25
|
+
render = () :VNode {
|
|
26
|
+
return <div>Hello world</div>;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### `isFormAssociated` boolean
|
|
32
|
+
|
|
33
|
+
If true, elementInternals are created using attachInternals in the constructor.
|
|
34
|
+
|
|
35
|
+
example
|
|
36
|
+
|
|
37
|
+
``` typescript
|
|
38
|
+
class MyElement extends CustomElement {
|
|
39
|
+
|
|
40
|
+
static isFormAssociated = true;
|
|
41
|
+
|
|
42
|
+
@Property({type: "string", attribute: "value", reflect: true })
|
|
43
|
+
value: string = "Peter" ;
|
|
44
|
+
|
|
45
|
+
updated(property: string, oldValue: any, newValue: any) {
|
|
46
|
+
if (property === "value"){
|
|
47
|
+
this.internals.setFormValue(this.value);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
render = () :VNode {
|
|
52
|
+
return <div>Hello {this.value}.</div>;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Decorators
|
|
58
|
+
|
|
59
|
+
#### `@CustomElementConfig`
|
|
60
|
+
|
|
61
|
+
Use this decorator to define the custom element
|
|
62
|
+
|
|
63
|
+
example
|
|
64
|
+
|
|
65
|
+
``` typescript
|
|
66
|
+
@CustomElementConfig({
|
|
67
|
+
tagName: "p-foo",
|
|
68
|
+
})
|
|
69
|
+
class PFooElement extends CustomElement {
|
|
70
|
+
...
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
If you want to extend a build in component you need to specify the buildin.
|
|
75
|
+
|
|
76
|
+
example
|
|
77
|
+
|
|
78
|
+
``` typescript
|
|
79
|
+
@CustomElementConfig({
|
|
80
|
+
tagName: "super-a",
|
|
81
|
+
options: {
|
|
82
|
+
extends: "a",
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
class SuperAnchorElement extends HTMLAnchorElement {
|
|
86
|
+
...
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### `@Property`
|
|
91
|
+
|
|
92
|
+
Use the `@Property` decorator to define reactive properties.
|
|
93
|
+
|
|
94
|
+
example
|
|
95
|
+
|
|
96
|
+
``` typescript
|
|
97
|
+
@CustomElementConfig({
|
|
98
|
+
tagName: "p-foo",
|
|
99
|
+
})
|
|
100
|
+
class PFooElement extends CustomElement {
|
|
101
|
+
...
|
|
102
|
+
|
|
103
|
+
@Property({type: "string", attribute: "nick-name", reflect: true})
|
|
104
|
+
nickName: string;
|
|
105
|
+
|
|
106
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void {
|
|
107
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
108
|
+
...
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
The `type` option could be "string", "number", "boolean" or "object".
|
|
112
|
+
|
|
113
|
+
If `attribute` option is set the property will be set on attribute change. If you implement a `attributeChangeCallback` you need to call the `super.attributeChangedCallback`.
|
|
114
|
+
|
|
115
|
+
If `reflect` is `true` the attribute is set on property change.
|
|
116
|
+
|
|
117
|
+
Use `converter` option to convert attribute to property
|
|
118
|
+
|
|
119
|
+
``` typescript
|
|
120
|
+
const stringArrayConverter: AttributeConverter<string[]> = {
|
|
121
|
+
fromAttribute: (value) => {
|
|
122
|
+
if (!value) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
return value.split(",").map((v) => v.trim());
|
|
126
|
+
},
|
|
127
|
+
toAttribute: (value) => {
|
|
128
|
+
if (!value.join) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
return value.join(",");
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
class MyElement extend CustomElement {
|
|
136
|
+
@Property({attribute: "items", reflect: true, converter: stringArrayConverter})
|
|
137
|
+
items: string[] = ["foo", "bar"];
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
#### `@Query` decorator
|
|
141
|
+
|
|
142
|
+
Use the `@Query` decorator to define a property that returns an element from the shadow dom.
|
|
143
|
+
|
|
144
|
+
example
|
|
145
|
+
|
|
146
|
+
``` typescript
|
|
147
|
+
class PFooElement extends CustomElement {
|
|
148
|
+
...
|
|
149
|
+
@Query("#MyInput")
|
|
150
|
+
nameInput: HTMLInputElement;
|
|
151
|
+
|
|
152
|
+
render = () => {
|
|
153
|
+
return <div>
|
|
154
|
+
<label for="MyInput"></label>
|
|
155
|
+
<input type="text" id="MyInput" />
|
|
156
|
+
</div>;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### `@PropertyRenderOnSet` `@RenderOnSet`
|
|
162
|
+
|
|
163
|
+
Properties decorated with `@PropertyRenderOnSet` or `@RenderOnSet` call renderNow when setting a value.
|
|
164
|
+
|
|
165
|
+
example
|
|
166
|
+
|
|
167
|
+
``` typescript
|
|
168
|
+
class PFooElement extends CustomElement {
|
|
169
|
+
...
|
|
170
|
+
@PropertyRenderOnSet
|
|
171
|
+
public foo: string = "foo";
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### `@Bind`
|
|
176
|
+
(deprecated, use arrow function `myFn = () => console.log('myFn')`)
|
|
177
|
+
|
|
178
|
+
Functions decorated with `@Bind` will be replaced with the result of bind(this) on the function.
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
### Hooks
|
|
182
|
+
|
|
183
|
+
#### `init`
|
|
184
|
+
|
|
185
|
+
The init is the first function called after initialising of the custom element
|
|
186
|
+
|
|
187
|
+
#### `shouldUpdate`
|
|
188
|
+
|
|
189
|
+
Before a property is set to a new value
|
|
190
|
+
|
|
191
|
+
#### `updated`
|
|
192
|
+
|
|
193
|
+
After a property value is set to a new value
|
|
194
|
+
|
|
195
|
+
#### `renderStart`
|
|
196
|
+
|
|
197
|
+
When the custom element start the rendering
|
|
198
|
+
|
|
199
|
+
#### `renderDone`
|
|
200
|
+
|
|
201
|
+
When the custom element is finished rendering
|
|
202
|
+
|
|
203
|
+
#### `attributeChangedCallback`
|
|
204
|
+
|
|
205
|
+
Call `super.attributeChangedCallback()` first.
|
|
206
|
+
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import type { CustomElement } from './custom-element';
|
|
2
|
-
|
|
3
|
-
export interface ICustomElementController {
|
|
4
|
-
renderNow(): void;
|
|
5
|
-
init?: () => void;
|
|
6
|
-
connected? : () => void;
|
|
7
|
-
disconnected? : () => void;
|
|
8
|
-
hostRenderStart?: () => void;
|
|
9
|
-
hostRenderDone? : () => void;
|
|
10
|
-
hostElement: CustomElement;
|
|
11
|
-
}
|
|
12
|
-
export abstract class CustomElementController implements ICustomElementController {
|
|
13
|
-
constructor(hostElement: CustomElement) {
|
|
14
|
-
this.#hostElement = hostElement;
|
|
15
|
-
this.#hostElement.addController(this);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
#hostElement: CustomElement;
|
|
19
|
-
|
|
20
|
-
get hostElement() {
|
|
21
|
-
return this.#hostElement;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
renderNow() {
|
|
25
|
-
this.hostElement?.renderNow();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
scheduleRender() {
|
|
29
|
-
this.hostElement?.scheduleRender();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
import type { CustomElement } from './custom-element';
|
|
2
|
+
|
|
3
|
+
export interface ICustomElementController {
|
|
4
|
+
renderNow(): void;
|
|
5
|
+
init?: () => void;
|
|
6
|
+
connected? : () => void;
|
|
7
|
+
disconnected? : () => void;
|
|
8
|
+
hostRenderStart?: () => void;
|
|
9
|
+
hostRenderDone? : () => void;
|
|
10
|
+
hostElement: CustomElement;
|
|
11
|
+
}
|
|
12
|
+
export abstract class CustomElementController implements ICustomElementController {
|
|
13
|
+
constructor(hostElement: CustomElement) {
|
|
14
|
+
this.#hostElement = hostElement;
|
|
15
|
+
this.#hostElement.addController(this);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
#hostElement: CustomElement;
|
|
19
|
+
|
|
20
|
+
get hostElement() {
|
|
21
|
+
return this.#hostElement;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
renderNow() {
|
|
25
|
+
this.hostElement?.renderNow();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
scheduleRender() {
|
|
29
|
+
this.hostElement?.scheduleRender();
|
|
30
|
+
}
|
|
31
|
+
}
|