@joist/element 4.0.0-next.10 → 4.0.0-next.11
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 +85 -2
- package/package.json +1 -1
- package/target/lib/element.d.ts +6 -3
package/README.md
CHANGED
|
@@ -65,16 +65,99 @@ Joist ships with a very simple template library. It is designed to be very small
|
|
|
65
65
|
]
|
|
66
66
|
})
|
|
67
67
|
export class MyElement extends HTMLElement {
|
|
68
|
-
|
|
69
|
-
accessor greeting = 'Hello World';
|
|
68
|
+
greeting = 'Hello World';
|
|
70
69
|
|
|
71
70
|
items = ['first', 'second', 'third', 'fourth', 'fifth'];
|
|
72
71
|
|
|
72
|
+
// initialize renderer
|
|
73
73
|
#render = template();
|
|
74
74
|
|
|
75
75
|
@ready()
|
|
76
76
|
onReady() {
|
|
77
|
+
// called once element is ready
|
|
78
|
+
|
|
77
79
|
this.#render();
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
```
|
|
83
|
+
|
|
84
|
+
## Styles
|
|
85
|
+
|
|
86
|
+
To apply styles simply pass the result of the `css` tag to the `shadow` array.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
@element({
|
|
90
|
+
tagName: 'my-element',
|
|
91
|
+
shadow: [
|
|
92
|
+
css`
|
|
93
|
+
h1 {
|
|
94
|
+
color: red;
|
|
95
|
+
}
|
|
96
|
+
`,
|
|
97
|
+
html`<h1>Hello World</h1>`
|
|
98
|
+
]
|
|
99
|
+
})
|
|
100
|
+
export class MyElement extends HTMLElement {}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Listeners
|
|
104
|
+
|
|
105
|
+
The `@listen` decorator allows you to easy setup event listeners. By default the listener will be attached to the shadow root if it exists or the host element if it doesn't. This can be customized by pass a selector function to the decorator
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
@element({
|
|
109
|
+
tagName: 'my-element',
|
|
110
|
+
shadow: []
|
|
111
|
+
})
|
|
112
|
+
export class MyElement extends HTMLElement {
|
|
113
|
+
@listen('eventname')
|
|
114
|
+
onEventName1() {
|
|
115
|
+
// all listener to the shadow root
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@listen('eventname', (host) => host)
|
|
119
|
+
onEventName2() {
|
|
120
|
+
// all listener to the host element
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@listen('eventname', (host) => host.querySelector('button'))
|
|
124
|
+
onEventName3() {
|
|
125
|
+
// add listener to a button found in the light dom
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@listen('eventname', '#test')
|
|
129
|
+
onEventName4() {
|
|
130
|
+
// add listener to element with the id of "test" that is found in the shadow dom
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Queries
|
|
136
|
+
|
|
137
|
+
The `query` function will query for a particular element and allow you to easily patch that element with new properties.
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
@element({
|
|
141
|
+
tagName: 'my-element',
|
|
142
|
+
shadow: [
|
|
143
|
+
html`
|
|
144
|
+
<label for="my-input">
|
|
145
|
+
<slot></slot>
|
|
146
|
+
</label>
|
|
147
|
+
|
|
148
|
+
<input id="my-input" />
|
|
149
|
+
`
|
|
150
|
+
]
|
|
151
|
+
})
|
|
152
|
+
export class MyElement extends HTMLElement {
|
|
153
|
+
@observe()
|
|
154
|
+
value: string;
|
|
155
|
+
|
|
156
|
+
#input = query('input');
|
|
157
|
+
|
|
158
|
+
@effect()
|
|
159
|
+
onChange() {
|
|
160
|
+
this.#input({ value: this.value });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
package/package.json
CHANGED
package/target/lib/element.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export declare function element<Target extends CustomElementConstructor, Instanc
|
|
|
43
43
|
readonly clientTop: number;
|
|
44
44
|
readonly clientWidth: number;
|
|
45
45
|
id: string;
|
|
46
|
+
innerHTML: string;
|
|
46
47
|
readonly localName: string;
|
|
47
48
|
readonly namespaceURI: string | null;
|
|
48
49
|
onfullscreenchange: ((this: Element, ev: Event) => any) | null;
|
|
@@ -82,12 +83,13 @@ export declare function element<Target extends CustomElementConstructor, Instanc
|
|
|
82
83
|
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf<SVGElement>;
|
|
83
84
|
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1998/Math/MathML", localName: string): HTMLCollectionOf<MathMLElement>;
|
|
84
85
|
getElementsByTagNameNS(namespace: string | null, localName: string): HTMLCollectionOf<Element>;
|
|
86
|
+
getHTML(options?: GetHTMLOptions): string;
|
|
85
87
|
hasAttribute(qualifiedName: string): boolean;
|
|
86
88
|
hasAttributeNS(namespace: string | null, localName: string): boolean;
|
|
87
89
|
hasAttributes(): boolean;
|
|
88
90
|
hasPointerCapture(pointerId: number): boolean;
|
|
89
91
|
insertAdjacentElement(where: InsertPosition, element: Element): Element | null;
|
|
90
|
-
insertAdjacentHTML(position: InsertPosition,
|
|
92
|
+
insertAdjacentHTML(position: InsertPosition, string: string): void;
|
|
91
93
|
insertAdjacentText(where: InsertPosition, data: string): void;
|
|
92
94
|
matches(selectors: string): boolean;
|
|
93
95
|
releasePointerCapture(pointerId: number): void;
|
|
@@ -95,7 +97,7 @@ export declare function element<Target extends CustomElementConstructor, Instanc
|
|
|
95
97
|
removeAttributeNS(namespace: string | null, localName: string): void;
|
|
96
98
|
removeAttributeNode(attr: Attr): Attr;
|
|
97
99
|
requestFullscreen(options?: FullscreenOptions): Promise<void>;
|
|
98
|
-
requestPointerLock(): void
|
|
100
|
+
requestPointerLock(options?: PointerLockOptions): Promise<void>;
|
|
99
101
|
scroll(options?: ScrollToOptions): void;
|
|
100
102
|
scroll(x: number, y: number): void;
|
|
101
103
|
scrollBy(options?: ScrollToOptions): void;
|
|
@@ -205,7 +207,6 @@ export declare function element<Target extends CustomElementConstructor, Instanc
|
|
|
205
207
|
before(...nodes: (Node | string)[]): void;
|
|
206
208
|
remove(): void;
|
|
207
209
|
replaceWith(...nodes: (Node | string)[]): void;
|
|
208
|
-
innerHTML: string;
|
|
209
210
|
readonly nextElementSibling: Element | null;
|
|
210
211
|
readonly previousElementSibling: Element | null;
|
|
211
212
|
readonly childElementCount: number;
|
|
@@ -247,7 +248,9 @@ export declare function element<Target extends CustomElementConstructor, Instanc
|
|
|
247
248
|
onchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
248
249
|
onclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
249
250
|
onclose: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
251
|
+
oncontextlost: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
250
252
|
oncontextmenu: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
253
|
+
oncontextrestored: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
251
254
|
oncopy: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null;
|
|
252
255
|
oncuechange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
253
256
|
oncut: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null;
|