Dan Brown fcf0bf79a9
Some checks failed
analyse-php / build (push) Waiting to run
lint-php / build (push) Waiting to run
test-migrations / build (8.1) (push) Waiting to run
test-migrations / build (8.2) (push) Waiting to run
test-migrations / build (8.3) (push) Waiting to run
test-migrations / build (8.4) (push) Waiting to run
test-php / build (8.1) (push) Waiting to run
test-php / build (8.2) (push) Waiting to run
test-php / build (8.3) (push) Waiting to run
test-php / build (8.4) (push) Waiting to run
lint-js / build (push) Has been cancelled
test-js / build (push) Has been cancelled
Attachments: Hid edit/delete controls where lacking permission
Added test to cover.
Also migrated related ajax-delete-row component to ts.

For #5323
2024-12-11 20:38:30 +00:00

60 lines
1.4 KiB
JavaScript

export class Component {
/**
* The registered name of the component.
* @type {string}
*/
$name = '';
/**
* The element that the component is registered upon.
* @type {HTMLElement}
*/
$el = null;
/**
* Mapping of referenced elements within the component.
* @type {Object<string, HTMLElement>}
*/
$refs = {};
/**
* Mapping of arrays of referenced elements within the component so multiple
* references, sharing the same name, can be fetched.
* @type {Object<string, HTMLElement[]>}
*/
$manyRefs = {};
/**
* Options passed into this component.
* @type {Object<String, String>}
*/
$opts = {};
/**
* Component-specific setup methods.
* Use this to assign local variables and run any initial setup or actions.
*/
setup() {
//
}
/**
* Emit an event from this component.
* Will be bubbled up from the dom element this is registered on, as a custom event
* with the name `<elementName>-<eventName>`, with the provided data in the event detail.
* @param {String} eventName
* @param {Object} data
*/
$emit(eventName, data = {}) {
data.from = this;
const componentName = this.$name;
const event = new CustomEvent(`${componentName}-${eventName}`, {
bubbles: true,
detail: data,
});
this.$el.dispatchEvent(event);
}
}