2023-11-17 16:15:26 +01:00
import "./global.css.js" ;
import { el } from "deka-dom-el" ;
2023-11-21 14:37:57 +01:00
import { header } from "./layout/head.html.js" ;
2023-11-17 16:15:26 +01:00
import { example } from "./components/example.html.js" ;
2023-11-21 14:37:57 +01:00
import { prevNext } from "./components/prevNext.html.js" ;
2023-11-17 16:15:26 +01:00
/** @param {string} url */
const fileURL = url => new URL ( url , import . meta . url ) ;
2023-11-21 14:37:57 +01:00
2023-11-17 16:15:26 +01:00
/** @param {import("./types.d.ts").PageAttrs} attrs */
export function page ( { pkg , info } ) {
const page _id = info . id ;
return el ( ) . append (
el ( header , { info , pkg } ) ,
el ( "main" ) . append (
2023-11-21 14:37:57 +01:00
el ( "h2" , "Listenning to the native DOM events and other Addons" ) ,
2023-11-17 16:15:26 +01:00
el ( "p" ) . append (
"We quickly introduce helper to listening to the native DOM events." ,
" " ,
2023-11-21 14:37:57 +01:00
"And library syntax/pattern so-called " , el ( "em" , "Addon" ) , " to" ,
2023-11-17 16:15:26 +01:00
" incorporate not only this in UI templates declaratively."
) ,
2023-11-18 14:23:18 +01:00
el ( "h3" , "Events and listenners" ) ,
2023-11-17 16:15:26 +01:00
el ( "p" ) . append (
2023-11-18 14:23:18 +01:00
"In JavaScript you can listen to the native DOM events of the given element by using " ,
el ( "a" , { href : "https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener" , title : "addEventListener on MDN" } ) . append (
el ( "code" , "element.addEventListener(type, listener, options)" )
) , "." ,
" " ,
"The library provides an alternative (" , el ( "code" , "on" ) , ") accepting the differen order" ,
" of the arguments:"
) ,
el ( example , { src : fileURL ( "./components/examples/events/compare.js" ) , page _id } ) ,
el ( "p" ) . append (
"…this is actually one of the two differences. The another one is that" , el ( "code" , "on" ) ,
" accepts only object as the " , el ( "code" , "options" ) , " (but it is still optional)."
) ,
el ( "p" ) . append (
"The other difference is that there is " , el ( "strong" , "no" ) , " " , el ( "code" , "off" ) , " function." ,
" " ,
"You can remove listener declaratively using " , el ( "a" , { textContent : "AbortSignal" , href : "https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#signal" , title : "part of addEventListener on MDN" } ) ,
":"
2023-11-17 16:15:26 +01:00
) ,
2023-11-18 14:23:18 +01:00
el ( example , { src : fileURL ( "./components/examples/events/abortSignal.js" ) , page _id } ) ,
2023-11-21 14:37:57 +01:00
el ( "h3" , "Addons" ) ,
2023-11-18 14:23:18 +01:00
el ( "p" ) . append (
2023-11-21 14:37:57 +01:00
"From practical point of view, " , el ( "em" , "Addons" ) , " are just functions that accept any html element" ,
2023-11-18 14:23:18 +01:00
" as their first parameter. You can see that the " , el ( "code" , "on(…)" ) , " fullfills this requirement."
) ,
el ( "p" ) . append (
2023-11-21 14:37:57 +01:00
"You can use Addons as ≥3rd argument of " , el ( "code" , "el" ) , " function. This way is possible to extends" ,
2023-11-18 14:23:18 +01:00
" you templates by additional (3rd party) functionalities. But for now mainly, you can add events listeners:"
) ,
el ( example , { src : fileURL ( "./components/examples/events/templateWithListeners.js" ) , page _id } ) ,
el ( "p" ) . append (
2023-11-21 14:37:57 +01:00
"As the example shows, you can also provide types in JSDoc+TypeScript by using global type " , el ( "code" , "ddeElementAddon" ) , "." ,
2023-11-18 14:23:18 +01:00
" " ,
2023-11-21 14:37:57 +01:00
"Also notice, you can use Addons to get element reference." ,
2023-11-18 14:23:18 +01:00
) ,
el ( "h3" , "Life cycle events" ) ,
2023-11-21 14:37:57 +01:00
el ( "p" , "Addons are called immediately when the element is created, event it is not connected to live DOM yet." ) ,
2023-11-18 14:23:18 +01:00
// todo
// dispatchEvent
2023-11-17 16:15:26 +01:00
el ( prevNext , info )
)
) ;
}