/** * This module defines a CompelExtension class. */ import { helperFun, builder, Page } from "jpc-like-websites"; /** * Defines an extension that can be added to the jpclw-framework */ export class CompelExtension { /** * @type {string} */ name; /** * @type {string} */ diplayTitle; /** * @type {Array} */ stylings; /** * @type {Array} */ functions; /** * Predefined components. Usually of a higher (constructed) kind. * @type {Object} */ components; /** * Extensions for/to the Page or the framework in general. * @type {Object} */ frameworkControls; /** * Additional elements for the builder (likely referencing components) * @type {Object} */ builderElements; /** * Additional helper functions * @type {{*:Function}} */ helperFun; /** * functions that are supposed to be executed after install, * to extend it that way. * @type {Array} */ funAfterInstall /** * * @param {string} name the working name of the extension * @param {string} displayTitle the name under wich it will be displayed in the framework panel */ constructor(name = "", displayTitle = "") { this.name = name; this.displayTitle = displayTitle; } /** * defines how jpc-like-websites is to be extended and executes that extension */ install() { if (this.helperFun) { helperFun.extensions = Object.assign(helperFun.extensions, this.helperFun); } if (this.builderElements) { builder.extensions = Object.assign(builder.extensions, this.builderElements); } if (this.frameworkControls) { Page.extensions = Object.assign(Page.extensions, this.frameworkControls); } if (this.stylings) { for (const key of Object.keys(this.stylings)) { Page.registerStyling(key, this.stylings[key]); } } if (this.funAfterInstall) { for (const fun of this.funAfterInstall) { fun(); } } } }