2023-12-22 16:49:59 +01:00
|
|
|
import { el, on, customElementRender, customElementWithDDE, scope, simulateSlots } from "../../index.js";
|
2024-05-22 21:43:49 +02:00
|
|
|
import { S } from "../../signals.js";
|
2023-09-09 21:15:43 +02:00
|
|
|
|
2023-11-08 18:53:22 +01:00
|
|
|
/**
|
2023-11-22 17:39:46 +01:00
|
|
|
* Compatible with `npx -y web-component-analyzer examples/components/webComponent.js`
|
|
|
|
* @element custom-test
|
2023-09-09 21:15:43 +02:00
|
|
|
* */
|
2023-09-11 18:31:23 +02:00
|
|
|
export class CustomHTMLTestElement extends HTMLElement{
|
2023-11-08 18:53:22 +01:00
|
|
|
static tagName= "custom-test";
|
2023-09-09 21:15:43 +02:00
|
|
|
static get observedAttributes(){
|
2023-09-12 15:26:06 +02:00
|
|
|
return [ "name", "pre-name" ];
|
2023-09-09 21:15:43 +02:00
|
|
|
}
|
|
|
|
connectedCallback(){
|
2023-11-22 17:39:46 +01:00
|
|
|
if(!this.hasAttribute("pre-name")) this.setAttribute("pre-name", "default");
|
2024-01-31 14:37:57 +01:00
|
|
|
customElementRender(this, this.attachShadow({ mode: "open" }), this.render, this.attributes)
|
2023-09-09 21:15:43 +02:00
|
|
|
}
|
|
|
|
|
2024-01-05 16:49:05 +01:00
|
|
|
attributes(element){
|
2024-05-22 21:43:49 +02:00
|
|
|
const observed= S.observedAttributes(element);
|
2024-01-05 16:49:05 +01:00
|
|
|
return Object.assign({ test: element.test }, observed);
|
|
|
|
}
|
|
|
|
render({ name, preName, test }){
|
2023-10-10 10:55:00 +02:00
|
|
|
console.log(scope.state);
|
2023-11-22 21:29:40 +01:00
|
|
|
scope.host(
|
2023-11-17 14:48:11 +01:00
|
|
|
on.connected(()=> console.log(CustomHTMLTestElement)),
|
|
|
|
on.attributeChanged(e=> console.log(e)),
|
|
|
|
on.disconnected(()=> console.log(CustomHTMLTestElement))
|
|
|
|
);
|
2024-01-05 16:49:05 +01:00
|
|
|
const text= text=> el().append(
|
|
|
|
el("#text", text),
|
|
|
|
" | "
|
|
|
|
);
|
2023-09-12 15:26:06 +02:00
|
|
|
return el("p").append(
|
2024-01-05 16:49:05 +01:00
|
|
|
text(test),
|
|
|
|
text(name),
|
|
|
|
text(preName),
|
2023-11-08 18:53:22 +01:00
|
|
|
el("button", { type: "button", textContent: "pre-name", onclick: ()=> preName("Ahoj") })
|
2023-09-12 15:26:06 +02:00
|
|
|
);
|
2023-09-11 18:31:23 +02:00
|
|
|
}
|
2023-11-22 17:39:46 +01:00
|
|
|
test= "A";
|
2024-11-22 16:26:42 +01:00
|
|
|
|
2023-11-08 18:53:22 +01:00
|
|
|
get name(){ return this.getAttribute("name"); }
|
|
|
|
set name(value){ this.setAttribute("name", value); }
|
2023-11-22 17:39:46 +01:00
|
|
|
/** @attr pre-name */
|
2023-11-08 18:53:22 +01:00
|
|
|
get preName(){ return this.getAttribute("pre-name"); }
|
|
|
|
set preName(value){ this.setAttribute("pre-name", value); }
|
2023-09-09 21:15:43 +02:00
|
|
|
}
|
2023-12-22 16:49:59 +01:00
|
|
|
customElementWithDDE(CustomHTMLTestElement);
|
2023-11-08 18:53:22 +01:00
|
|
|
customElements.define(CustomHTMLTestElement.tagName, CustomHTMLTestElement);
|
2023-09-11 18:31:23 +02:00
|
|
|
|
2023-12-22 16:49:59 +01:00
|
|
|
export class CustomSlottingHTMLElement extends HTMLElement{
|
|
|
|
static tagName= "custom-slotting";
|
|
|
|
render(){
|
|
|
|
return simulateSlots(this, el().append(
|
|
|
|
el("p").append(
|
|
|
|
"Ahoj ", el("slot", { name: "name", className: "name", textContent: "World" })
|
|
|
|
),
|
|
|
|
el("p").append(
|
|
|
|
"BTW ", el("slot")
|
|
|
|
)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
connectedCallback(){
|
2024-01-31 14:37:57 +01:00
|
|
|
customElementRender(this, this, this.render);
|
2023-12-22 16:49:59 +01:00
|
|
|
}
|
2023-09-11 18:31:23 +02:00
|
|
|
}
|
2023-12-22 16:49:59 +01:00
|
|
|
customElementWithDDE(CustomSlottingHTMLElement);
|
|
|
|
customElements.define(CustomSlottingHTMLElement.tagName, CustomSlottingHTMLElement);
|