CustomElement
A base class for HTML5 custom controls.
import { CustomElement } from "@schukai/monster/source/dom/customelement.mjs";Exported
CustomElement, initMethodSymbol, assembleMethodSymbol, attributeObserverSymbol, registerCustomElement, getSlottedElements, updaterTransformerMethodsSymbolDerived from
HTMLElementOptions
The Options listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the HTMLElement.
Properties
The Properties listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Properties from these parent classes. If you cannot find a specific Properties in this list, we recommend consulting the documentation of the HTMLElement.
Methods
The methods listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the HTMLElement.
Constructor
constructor(){Error}the option attribute does not contain a valid JSON definition.
initOptions method is called. Here the options can be defined in derived classes. Subsequently, the shadowRoot is initialized. IMPORTANT: CustomControls instances are not created via the constructor, but either via a tag in the HTML or via document.createElement().Behavioral methods
addAttributeObserver(attribute,callback)attribute: attributecallback: callback
- {CustomElement}
removeAttributeObserver(attribute)attribute: attribute
- {CustomElement}
updateI18n()- {CustomElement}
{Error}Cannot find an element with translations. Add a translation object to the document.
State query methods
hasNode(node)1.19.0node{node}: - The node to check for within this component's child nodes.
- {boolean}: true if the given node is found, otherwise false.
{TypeError}value is not an instance of
Structural methods
getInternalUpdateCloneData()- {*}
getOption(path,)1.10.0path{string}: pathundefined{*}: defaultValue
- {*}
a.b.csetOption(path,value)1.14.0path{string}: pathvalue{*}: value
- {CustomElement}
setOptions(options)1.15.0options{string|object}: options
- {CustomElement}
Static methods
[instanceSymbol]()2.1.0- {symbol}
instanceof operator.getCSSStyleSheet()- {cssstylesheet|cssstylesheet[]|string|undefined}: `CSSStyleSheet` object or an array of such objects that define the styles for the custom element, or `undefined` if no stylesheet should be applied.
getCSSStyleSheet() method returns a CSSStyleSheet object that defines the styles for the custom element. If the environment does not support the CSSStyleSheet constructor, then an object can be built using the provided detour. If undefined is returned, then the shadow root does not receive a stylesheet. Example usage:class MyElement extends CustomElement {
static getCSSStyleSheet() {
const sheet = new CSSStyleSheet();
sheet.replaceSync("p { color: red; }");
return sheet;
}
}
If the environment does not support the CSSStyleSheet constructor, you can use the following workaround to create the stylesheet:const doc = document.implementation.createHTMLDocument("title");
let style = doc.createElement("style");
style.innerHTML = "p { color: red; }";
style.appendChild(document.createTextNode(""));
doc.head.appendChild(style);
return doc.styleSheets[0];
getTag()1.7.0- {string}: tag name associated with the custom element.
{Error}This method must be overridden by the derived class.
getTag() method returns the tag name associated with the custom element. This method should be overwritten by the derived class. Note that there is no check on the name of the tag in this class. It is the responsibility of the developer to assign an appropriate tag name. If the name is not valid, the registerCustomElement() method will issue an error.observedAttributes()1.15.0- {string[]}
attributeChangedCallback(). Unfortunately, this method is static. Therefore, the observedAttributes property cannot be changed during runtime.Lifecycle methods
Lifecycle methods are called by the environment and are usually not intended to be called directly.
adoptedCallback()1.7.0- {void}
attributeChangedCallback(attrName,oldVal,newVal)1.15.0attrName{string}: attrNameoldVal{string}: oldValnewVal{string}: newVal
- {void}
connectedCallback()1.7.0- {void}
disconnectedCallback()1.7.0- {void}
Other methods
[assembleMethodSymbol]()1.8.0- {customelement}: The updated custom element.
- Extracts the options from the attributes and the script tag of the element and sets them.
- Initializes the shadow root and its CSS stylesheet (if specified).
- Initializes the HTML content of the element.
- Initializes the custom elements inside the shadow root and the slotted elements.
- Attaches a mutation observer to observe changes to the attributes of the element.
[initMethodSymbol]()1.8.0- {CustomElement}
[updaterTransformerMethodsSymbol]()2.43.0- {object}
my-transformer is defined. In the template, you can use it as follows:<my-element
data-monster-option-transformer="path:my-value | call:my-transformer"
>
</my-element>
The function my-transformer is called with the value of my-value as a parameter.class MyElement extends CustomElement {
[updaterTransformerMethodsSymbol]() {
return {
"my-transformer": (value) => {
switch (typeof Wert) {
case "string":
return value + "!";
case "Zahl":
return value + 1;
default:
return value;
}
},
};
}
}
attachObserver(observer)observer{observer}: observer
- {CustomElement}
callCallback(name,args)name{string}: - The name of the callback to be executed.args{array}: - An array of arguments to be passed to the callback function.
- {*}: result of the callback function execution.
containsObserver(observer)observer{observer}: observer
- {ProxyObserver}
customization()customization property allows overwriting the defaults. Unlike the defaults that expect an object, the customization is a Map. This also allows overwriting individual values in a deeper structure without having to redefine the entire structure and thus changing the defaults.detachObserver(observer)observer{observer}: observer
- {CustomElement}
Events
This component does not fire any public events. It may fire events that are inherited from its parent classes.