@mschop/alpine-web-components 1.0.4 → 1.0.5
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/AlpineWebComponent.ts +7 -7
- package/package.json +1 -1
package/AlpineWebComponent.ts
CHANGED
|
@@ -24,7 +24,7 @@ abstract class AlpineWebComponent extends HTMLElement {
|
|
|
24
24
|
protected abstract template: string
|
|
25
25
|
protected styles: () => string = () => ``
|
|
26
26
|
protected attributeCasts: AttributeCasts = {};
|
|
27
|
-
|
|
27
|
+
protected alpineInitHandler = () => this.init()
|
|
28
28
|
|
|
29
29
|
constructor() {
|
|
30
30
|
super()
|
|
@@ -74,11 +74,11 @@ abstract class AlpineWebComponent extends HTMLElement {
|
|
|
74
74
|
this.state.attributes[name] = castedNewValue;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
protected loadTemplate() {
|
|
78
78
|
this.getRoot().innerHTML = this.template;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
protected bootState() {
|
|
82
82
|
let state = this.state;
|
|
83
83
|
|
|
84
84
|
// @ts-ignore
|
|
@@ -93,14 +93,14 @@ abstract class AlpineWebComponent extends HTMLElement {
|
|
|
93
93
|
this.state = Alpine.reactive(state);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
protected bootAlpine() {
|
|
97
97
|
// @ts-ignore
|
|
98
98
|
Alpine.addScopeToNode(this.getRoot(), this.state)
|
|
99
99
|
// @ts-ignore
|
|
100
100
|
Alpine.initTree(this.getRoot())
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
protected bootAttributes(): void {
|
|
104
104
|
// @ts-ignore
|
|
105
105
|
this.constructor.observedAttributes?.forEach((key: string) => {
|
|
106
106
|
const value = this.getAttribute(key);
|
|
@@ -119,11 +119,11 @@ abstract class AlpineWebComponent extends HTMLElement {
|
|
|
119
119
|
})
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
protected castToAttribute(name: string, value: any): null|string {
|
|
123
123
|
return this.attributeCasts[name] === undefined ? value : this.attributeCasts[name].toAttribute(value);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
protected castFromAttribute(name: string, value: null|string): any {
|
|
127
127
|
return this.attributeCasts[name] === undefined ? value : this.attributeCasts[name].fromAttribute(value);
|
|
128
128
|
}
|
|
129
129
|
|