2024-06-03 16:20:42 +02:00
|
|
|
|
import { T, t } from "./utils/index.js";
|
2024-05-22 21:43:49 +02:00
|
|
|
|
export const info= {
|
2024-06-04 16:00:37 +02:00
|
|
|
|
title: t`Web Components`,
|
2024-06-03 16:20:42 +02:00
|
|
|
|
description: t`Using custom elements in combinantion with DDE`,
|
2024-05-22 21:43:49 +02:00
|
|
|
|
};
|
2024-01-09 21:18:43 +01:00
|
|
|
|
|
|
|
|
|
import { el } from "deka-dom-el";
|
2024-05-22 21:43:49 +02:00
|
|
|
|
import { simplePage } from "./layout/simplePage.html.js";
|
2024-01-09 21:18:43 +01:00
|
|
|
|
import { example } from "./components/example.html.js";
|
|
|
|
|
import { h3 } from "./components/pageUtils.html.js";
|
|
|
|
|
import { mnemonic } from "./components/mnemonic/customElement-init.js";
|
|
|
|
|
import { code } from "./components/code.html.js";
|
|
|
|
|
/** @param {string} url */
|
|
|
|
|
const fileURL= url=> new URL(url, import.meta.url);
|
2024-05-31 14:14:48 +02:00
|
|
|
|
const references= {
|
2024-06-04 16:00:37 +02:00
|
|
|
|
mdn_web_components: { /** Web Components on MDN */
|
|
|
|
|
title: t`MDN documentation page for Web Components`,
|
|
|
|
|
href: "https://developer.mozilla.org/en-US/docs/Web/API/Web_components",
|
|
|
|
|
},
|
|
|
|
|
mdn_observedAttributes: { /** observedAttributes on MDN */
|
|
|
|
|
title: t`MDN documentation page for observedAttributes`,
|
|
|
|
|
href: "https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes",
|
|
|
|
|
},
|
|
|
|
|
mdn_custom_elements: { /** Custom Elements on MDN */
|
2024-06-03 16:20:42 +02:00
|
|
|
|
title: t`MDN documentation page for Custom Elements`,
|
2024-05-31 14:14:48 +02:00
|
|
|
|
href: "https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements",
|
|
|
|
|
},
|
2024-06-04 16:00:37 +02:00
|
|
|
|
custom_elements_tips: { /** Custom Elements tips from WebReflection */
|
2024-06-03 16:20:42 +02:00
|
|
|
|
title: t`Ideas and tips from WebReflection`,
|
2024-05-31 14:14:48 +02:00
|
|
|
|
href: "https://gist.github.com/WebReflection/ec9f6687842aa385477c4afca625bbf4",
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-01-09 21:18:43 +01:00
|
|
|
|
/** @param {import("./types.d.ts").PageAttrs} attrs */
|
|
|
|
|
export function page({ pkg, info }){
|
|
|
|
|
const page_id= info.id;
|
|
|
|
|
return el(simplePage, { info, pkg }).append(
|
2024-06-04 16:00:37 +02:00
|
|
|
|
el("h2", t`Using web components in combinantion with DDE`),
|
2024-06-03 16:20:42 +02:00
|
|
|
|
el("p").append(...T`
|
2024-06-04 16:00:37 +02:00
|
|
|
|
The DDE library allows for use within ${el("a", references.mdn_web_components).append( el("strong", "Web Components") )}
|
|
|
|
|
for dom-tree generation. However, in order to be able to use signals (possibly mapping to registered
|
|
|
|
|
${el("a", references.mdn_observedAttributes).append( el("code", "observedAttributes") )}) and additional
|
|
|
|
|
functionality is (unfortunately) required to use helpers provided by the library.
|
2024-06-03 16:20:42 +02:00
|
|
|
|
`),
|
2024-01-09 21:18:43 +01:00
|
|
|
|
el(code, { src: fileURL("./components/examples/customElement/intro.js"), page_id }),
|
|
|
|
|
|
2024-06-03 16:20:42 +02:00
|
|
|
|
el(h3, t`Custom Elements Introduction`),
|
|
|
|
|
el("p").append(...T`
|
2024-06-04 16:00:37 +02:00
|
|
|
|
To start with, let’s see how to use native Custom Elements. As starting point please read
|
|
|
|
|
${el("a", references.mdn_custom_elements).append( el("strong", "Using Custom Elements"), " on MDN" )}.
|
|
|
|
|
To sum up and for mnemonic see following code overview:
|
2024-06-03 16:20:42 +02:00
|
|
|
|
`),
|
2024-01-09 21:18:43 +01:00
|
|
|
|
el(code, { src: fileURL("./components/examples/customElement/native-basic.js"), page_id }),
|
2024-06-03 16:20:42 +02:00
|
|
|
|
el("p").append(...T`
|
2024-06-04 16:00:37 +02:00
|
|
|
|
For more advanced use of Custom Elements, the summary ${el("a", references.custom_elements_tips)
|
|
|
|
|
.append( el("strong", t`Handy Custom Elements' Patterns`) )} may be useful. Especially pay attention to
|
|
|
|
|
linking HTML attributes and defining setters/getters, this is very helpful to use in combination with
|
|
|
|
|
the library (${el("code", "el(CustomHTMLElement.tagName, { customAttribute: \"new-value\" });")}).
|
2024-06-03 16:20:42 +02:00
|
|
|
|
`),
|
2024-01-09 21:18:43 +01:00
|
|
|
|
|
|
|
|
|
el(mnemonic)
|
|
|
|
|
);
|
|
|
|
|
}
|