TComponents. Component_A

new Component_A(parent, props)

Creates an instance of TComponents.Component class. This is the base parent class of all TComponent.

Parameters:
NameTypeDescription
parentHTMLElement

HTMLElement that is going to be the parent of the component.

propsTComponents.ComponentProps

Parameters to create the component.

Example
const component = new TComponents.Component_A(document.body, {
  label: 'My Component',
  labelPos: 'top',
  options: {
    async: true
  }
});

Extends

Members

INPUTVAR_FUNC :object

Enum-like object that defines various input variable handling strategies. These strategies specify how input variables are processed within the component.

Type:
  • object
Properties
NameTypeDescription
CUSTOMstring

A custom processing strategy for input variables.

SYNCstring

A synchronous processing strategy for input variables.

INPUTVAR_TYPE :object

Enum-like object that defines various input variable types. These types are used to categorize the types of input data that can be handled by the component.

Type:
  • object
Properties
NameTypeDescription
NUMstring

Represents a numeric input type.

ANYstring

Represents a generic input type, not limited to a specific data type.

BOOLstring

Represents a boolean input type (true/false).

STRINGstring

Represents a string input type.

enabled

Enables or disables the component and all its child components.

Example
this.enabled = true;

globalEvents :Eventing_A

Global event handler for the Component_A class.

languageAdapter :object

language adapter for the Component_A class.

Type:
  • object

(static) isTComponent

Static method to check if an object is a TComponent.

Methods

(protected) addEventListener(element, eventType, listener, optionsopt) → {void}

Adds an event listener to the specified element and keeps tracking of it.

Parameters:
NameTypeAttributesDescription
elementHTMLElement

The target element to which the event listener will be added.

eventTypestring

The type of the event to listen for (e.g., 'click', 'mouseover').

listenerfunction

The function that will be called when the event is triggered.

optionsboolean | AddEventListenerOptions<optional>

Optional options object or useCapture flag.

Throws:

Throws an error if the specified element is not found.

Type
Error
Returns:
Type: 
void

(protected) addTips() → {void}

Add the tooltip HTML Element for the component.

Returns:
Type: 
void

(protected) afterRenderOnce() → {void}

Lifecycle hook called once after the component is rendered for the first time.

Returns:
Type: 
void

all(selector) → {Array.<Element>}

Returns an Array representing the component's elements that matches the specified selector. If no matches are found, an empty Array is returned.

Parameters:
NameTypeDescription
selectorstring

A string containing one selector to match. This string must be a valid CSS selector string

Returns:

An Array of Elements that matches the specified CSS selector, or an empty array if there are no matches.

Type: 
Array.<Element>

attachToElement(element) → {void}

Changes the DOM element in which this component is to be inserted.

Parameters:
NameTypeDescription
elementHTMLElement | Element

Container DOM element

Returns:
Type: 
void

(protected) convertDataToBool(t) → {boolean}

Converts the provided text to a boolean value. (specific for switch,digitalled)

Parameters:
NameTypeDescription
tstring | boolean | number

The text value to be converted.

Returns:

True if the text is true|TRUE|1, false otherwise.

Type: 
boolean

css(properties) → {string}

Sets or returns the contents of a style declaration as a string.

Parameters:
NameTypeDescription
propertiesstring | Array

Specifies the content of a style declaration. E.g.: "background-color:pink;font-size:55px;border:2px dashed green;color:white;"

Returns:
Type: 
string

cssAddClass(selector, classNames, allopt) → {void}

Adds a class to underlying element(s) containing the input selector

Parameters:
NameTypeAttributesDescription
selectorstring

CSS selector, if class: ".selector", if identifier: "#selector"

classNamesstring | Array.<string>

name of the class to appy (without dot)

allboolean<optional>

if true it will apply the class to all selector found, otherwise it applies to the first one found

Returns:
Type: 
void

cssBox(enable) → {void}

Changes apperance of the component (border and background color) to frame it or not.

Parameters:
NameTypeDescription
enableboolean

if true, the component is framed, if false, not frame is shown

Returns:
Type: 
void

cssRemoveClass(selector, classNames, allopt) → {void}

Removes a class to underlying element(s) containing the input selector

Parameters:
NameTypeAttributesDescription
selectorstring

CSS selector, if class: ".selector", if identifier: "#selector"

classNamesstring

name of the class to appy (without dot)

allboolean<optional>

if true it will apply the class to all selector found, otherwise it applies to the first one found

Returns:
Type: 
void

(protected) defaultProps() → {TComponents.ComponentProps}

Returns the default values of class properties (excluding parent properties).

destroy() → {void}

Clean up before initializing. Relevant from the second time the component is initialized.

  • Call onDestroy method
  • Call return function from onInit method if it exists
  • Detach the component from the parent element
  • Remove all local events, like this.on('event', callback)
  • Remove all event listeners attached with this.addEventListener
Returns:
Type: 
void

(protected) enterTip() → {void}

Shows the tooltip when mouse enters.

Returns:
Type: 
void

find(selector) → {HTMLElement|Element}

Returns the first Element within the component that matches the specified selector. If no matches are found, null is returned.

Parameters:
NameTypeDescription
selectorstring

A string containing one selector to match. This string must be a valid CSS selector string

Returns:

An Element object representing the first element within the component that matches the specified set of CSS selectors, or null if there are no matches.

Type: 
HTMLElement | Element

hide() → {void}

Changes visibility of the component to not show it in the view.

Returns:
Type: 
void

(async) init() → {Promise.<object>}

Initialization of a component. Any asynchronous operation (like access to controller) is done here. The TComponents.Component_A#onInit() method of the component is triggered by this method.

Returns:

The TComponents instance on which this method was called.

Type: 
Promise.<object>

(protected) leaveTip() → {void}

Hides the tooltip when mouse leaves.

Returns:
Type: 
void

(abstract) mapComponents() → {object}

Instantiation of TComponents sub-components that shall be initialized in a synchronous way. All these components are then accessible within onRender method by using this.child.

Returns:

Contains all child TComponents instances used within the component.

Type: 
object

(abstract) markup(self) → {string}

Generates the HTML definition corresponding to the component.

Parameters:
NameTypeDescription
selfobject

The TComponents instance on which this method was called.

Returns:
Type: 
string

(async, protected) onCreated() → {Promise.<void>}

Lifecycle hook called when the component is created.

Returns:
Type: 
Promise.<void>

(async, abstract) onDestroy()

This method is called internally during clean up process orchestrated by destroy.

(async, protected) onDispose() → {Promise.<void>}

Lifecycle hook called when the component is about to be disposed. This hook is triggered when the component is being removed from the renderer and all associated resources should be released.

Returns:
Type: 
Promise.<void>

(async, abstract) onInit()

Contains component specific asynchronous implementation (like access to controller). This method is called internally during initialization process orchestrated by init.

(async, protected) onMounted() → {Promise.<void>}

Lifecycle hook called when the component is mounted.

Returns:
Type: 
Promise.<void>

(abstract) onRender()

Contains all synchronous operations/setups that may be required for any sub-component after its initialization and/or manipulation of the DOM. This method is called internally during rendering process orchestrated by render.

(protected) removeAllEventListeners() → {void}

Removes all the event listeners that were added using addEventListener.

Returns:
Type: 
void

(async) render(dataopt) → {Promise.<object>}

Update the content of the instance into the Document Object Model (DOM). The TComponents.Component_A#onRender() method of this component and eventual initialization of sub-components are managed by this method.

Parameters:
NameTypeAttributesDescription
dataobject<optional>

Data that can be passed to the component, which may be required for the rendering process.

Returns:

The TComponents instance on which this method was called.

Type: 
Promise.<object>

replaceContent(content) → {void}

Replace the content of the component's container.

Parameters:
NameTypeDescription
contentstring | HTMLElement

The new content to replace the current content.

Returns:
Type: 
void
Example
const component = new TComponents.Component_A(document.body, {});
component.replaceContent('New Content');

show() → {void}

Changes visibility of the component to show it in the view.

Returns:
Type: 
void

(async) syncInputData(value) → {Promise.<boolean>}

Synchronizes the input data. This method checks whether the input data is valid and triggers synchronization using an external component. It handles errors gracefully and provides feedback through a popup if synchronization fails.

Parameters:
NameTypeDescription
valueany

The value to be synchronized. This can be of any type depending on the implementation.

Throws:

If binding data is null or synchronization fails unexpectedly.

Type
Error
Returns:

A promise that resolves to true if the synchronization is successful, or false if an error occurs or binding data is null.

Type: 
Promise.<boolean>

syncInputDataWithPopup(value) → {Promise.<void>}

Synchronizes the input data with a popup notification.

Parameters:
NameTypeDescription
valueany

The value to be synchronized.

Throws:

If synchronization fails.

Type
Error
Returns:
Type: 
Promise.<void>

updateProps(_newPropsopt) → {void}

Updates the properties of the component.

Parameters:
NameTypeAttributesDefaultDescription
_newPropsobject<optional>
{}

The new properties to merge with the current properties.

Returns:
Type: 
void

(protected) validateText(t) → {boolean}

Validates if the provided text can be interpreted as a boolean or number. (specific for switch,digitalled)

Parameters:
NameTypeDescription
tstring | boolean | number

The text value to be validated.

Returns:

True if the text is valid, false otherwise.

Type: 
boolean

(static) _hasChildComponent() → {boolean}

Recursively check for instances of type TComponent and FPComponent

Returns:

true if the object has child components, false otherwise

Type: 
boolean

(static) _isFPComponent(o) → {boolean}

Checks if the object is an instance of any FPComponent.

Parameters:
NameTypeDescription
oany
Returns:

true if the object is an FPComponent, false otherwise

Type: 
boolean

(static) _isHTMLElement(o) → {boolean}

Check if an entry is HTML Element

Parameters:
NameTypeDescription
oany
Returns:

true if entry is an HTMLElement, false otherwise

Type: 
boolean

(static) conditionProcessing(self, states) → {void}

Processes conditions and updates the component properties accordingly.

Parameters:
NameTypeDescription
selfobject

The component instance.

statesArray.<any>

The states to process.

Returns:
Type: 
void

(static) disableComponentOn(self, condition) → {void}

Disables the component based on a condition.

Parameters:
NameTypeDescription
selfobject

The component instance.

conditionobject

The condition to evaluate.

Returns:
Type: 
void

(static) dynamicProperty(text, self, propName) → {string|number}

Generates dynamic value based on the input type.

Parameters:
NameTypeDescription
textstring | number

The text to process.

selfobject

The component instance.

propNameString

The property to update.

Deprecated
  • This interface is to be deprecated. If you need to perform multilingual parsing, please use TComponent.tParse.
Returns:

The processed text.

Type: 
string | number

(static) dynamicText(text, self) → {string|number}

Generates dynamic text based on the input type.

Parameters:
NameTypeDescription
textstring | number

The text to process.

selfobject

The component instance.

Returns:

The processed text.

Type: 
string | number

(static) genFuncTemplate(data, self) → {function|null}

Generates a function template from a string.

Parameters:
NameTypeDescription
datastring | function | any

The string containing the function body.

selfobject

The component instance.

Returns:

The generated function or null if the input is not a valid function.

Type: 
function | null

(static) genFuncTemplateWithPopup(data, self)

Generates a function template from a string and pop up dialog if error happens.

Parameters:
NameTypeDescription
dataany
selfany
Deprecated
  • Will remove this

(static) getBindData(strData, self) → {Object|null}

Extracts binding data from a string.

Parameters:
NameTypeDescription
strDatastring

The string to extract data from.

selfobject

The component instance.

Returns:

The binding data or null if not applicable.

Type: 
Object | null

(static) getDataStruct(vs, self) → {object}

Extracts data structure information from the variable string.

Parameters:
NameTypeDescription
vsany

The variable string parts.

selfany

The component instance.

Returns:

The extracted data structure information.

Type: 
object

(static) getInstanceProperty(key) → {Component_A}

Retrieve instance attributes from the global instance table based on the key value

Parameters:
NameTypeDescription
keystring

The key name of the instance.

Returns:

The target instance.

Type: 
Component_A

(static) handleComponentOn(self, options, action) → {void}

Handles component state changes based on resource and action.

Parameters:
NameTypeDescription
selfobject

The component instance.

optionsobject

The options for the handler.

Properties
NameTypeDescription
resourcestring

The resource to monitor.

instanceobject

The instance information.

statestring

The state to monitor.

actionstring

The action to perform.

Returns:
Type: 
void

(static) hideComponentOn(self, condition) → {void}

Hides the component based on a condition.

Parameters:
NameTypeDescription
selfobject

The component instance.

conditionobject

The condition to evaluate.

Returns:
Type: 
void

(static) loadCssClassFromString(css) → {void}

Loads a CSS stylesheet from a string and inserts it into the document. This method uses a hash to avoid injecting the same CSS twice.

Parameters:
NameTypeDescription
cssstring

The CSS string to load.

Throws:

If the provided css argument is not a string.

Type
Error
Returns:
Type: 
void

(static) loadCssClassFromStringUnique(css, selector) → {void}

Loads a unique CSS stylesheet from a string and inserts it into the document. This method uses a hash to avoid injecting the same CSS twice.

Parameters:
NameTypeDescription
cssstring

The CSS string to load.

selectorstring

The CSS selector to apply the styles to.

Throws:

If the provided arguments are not a string.

Type
Error
Returns:
Type: 
void

(static) mFor(array, markup) → {string}

Maps an array to a string of markup.

Parameters:
NameTypeDescription
arrayArray.<any>

The array to map.

markupfunction

The function to generate markup for each item.

Returns:

The concatenated string of markup.

Type: 
string

(static) mIf(condition, markup, elseMarkupopt) → {string}

Returns markup based on a condition.

Parameters:
NameTypeAttributesDefaultDescription
conditionboolean

The condition to evaluate.

markupstring

The markup to return if the condition is true.

elseMarkupstring<optional>
''

The markup to return if the condition is false.

Returns:

The appropriate markup based on the condition.

Type: 
string

(static) resolveBindingExpression(text, self, propName) → {string|number}

Parse the specific value according to the bound text.

Parameters:
NameTypeDescription
textstring | number

The text to process.

selfobject

The component instance.

propNameString

The property to update.

Returns:

The processed text.

Type: 
string | number

(static) setLanguageAdapter(adapter) → {void}

Sets the language adapter for the component.

Parameters:
NameTypeDescription
adapterobject

The language adapter.

Properties
NameTypeDescription
tfunction

The translation function.

Throws:

If adapter.t is not a function.

Type
Error
Returns:
Type: 
void

(async, static) syncData(value, self) → {Promise.<boolean>}

Synchronizes data with a specified value.

Parameters:
NameTypeDescription
valueany

The value to synchronize.

selfobject

The component instance.

Returns:

A promise that resolves to true if synchronization is successful, otherwise false.

Type: 
Promise.<boolean>

(static) t(key) → {string}

Translates a key using the language adapter.

Parameters:
NameTypeDescription
keystring

The key to translate.

Returns:

The translated key.

Type: 
string

(static) tParse(key) → {string}

Parses translation keys and replaces them with their corresponding values.

Parameters:
NameTypeDescription
keystring

The key to translate.

Returns:

The translated value.

Type: 
string