parent
7bba979de8
commit
f96447c8d1
@ -0,0 +1,16 @@ |
|||||||
|
import { ProgressiveForm } from "./progressive-form.ts"; |
||||||
|
import { ReactiveButton } from "./reactive-button.ts"; |
||||||
|
import { ReactiveSpan } from "./reactive-span.ts"; |
||||||
|
|
||||||
|
export const initializeWebComponents = () => { |
||||||
|
if ((window as Partial<typeof window>).customElements?.define) { |
||||||
|
// We need to define customized built-in elements first,
|
||||||
|
// because WebKit (Safari) is not standard-compliant[1] and doesn't support them,
|
||||||
|
// so hopefully these calls will throw, leaving us with all custom elements or none,
|
||||||
|
// instead of defining autonomous custom elements and skipping customized built-in elements.
|
||||||
|
// [1]: https://github.com/WebKit/standards-positions/issues/97
|
||||||
|
customElements.define("progressive-form", ProgressiveForm, { extends: "form" }); |
||||||
|
customElements.define("reactive-button", ReactiveButton, { extends: "button" }); |
||||||
|
customElements.define("reactive-span", ReactiveSpan, { extends: "span" }); |
||||||
|
} |
||||||
|
}; |
@ -0,0 +1,22 @@ |
|||||||
|
import { TrackingTools } from "../lib/query-tracking-utils.ts"; |
||||||
|
|
||||||
|
export class ReactiveButton extends HTMLButtonElement { |
||||||
|
private readonly trackingTools = new TrackingTools(this); |
||||||
|
|
||||||
|
handleTrackedValueUpdate(newValue: string | null) { |
||||||
|
const delta = parseInt(this.getAttribute("delta") ?? "0", 10); |
||||||
|
this.value = (parseInt(newValue ?? "0", 10) + delta).toString(); |
||||||
|
} |
||||||
|
|
||||||
|
connectedCallback() { |
||||||
|
this.trackingTools.connectedCallback(); |
||||||
|
} |
||||||
|
|
||||||
|
attributeChangedCallback() { |
||||||
|
this.trackingTools.attributeChangedCallback(); |
||||||
|
} |
||||||
|
|
||||||
|
disconnectedCallback() { |
||||||
|
this.trackingTools.disconnectedCallback(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
import { TrackingTools } from "../lib/query-tracking-utils.ts"; |
||||||
|
|
||||||
|
export class ReactiveSpan extends HTMLSpanElement { |
||||||
|
private readonly trackingTools = new TrackingTools(this); |
||||||
|
|
||||||
|
handleTrackedValueUpdate(newValue: string | null) { |
||||||
|
this.innerText = newValue ?? "[null]"; |
||||||
|
} |
||||||
|
|
||||||
|
connectedCallback() { |
||||||
|
this.trackingTools.connectedCallback(); |
||||||
|
} |
||||||
|
|
||||||
|
attributeChangedCallback() { |
||||||
|
this.trackingTools.attributeChangedCallback(); |
||||||
|
} |
||||||
|
|
||||||
|
disconnectedCallback() { |
||||||
|
this.trackingTools.disconnectedCallback(); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue