Sha256: 104c111e5c204d8501efc71494f8482ba78a16cbef3f3f21d73215aa81cdc1d8

Contents?: true

Size: 1.74 KB

Versions: 56

Compression:

Stored size: 1.74 KB

Contents

import { isInitialised, isSupported } from './common/index.mjs';
import { InitError, ElementError, SupportError } from './errors/index.mjs';

class GOVUKFrontendComponent {
  /**
   * Returns the root element of the component
   *
   * @protected
   * @returns {RootElementType} - the root element of component
   */
  get $root() {
    return this._$root;
  }
  constructor($root) {
    this._$root = void 0;
    const childConstructor = this.constructor;
    if (typeof childConstructor.moduleName !== 'string') {
      throw new InitError(`\`moduleName\` not defined in component`);
    }
    if (!($root instanceof childConstructor.elementType)) {
      throw new ElementError({
        element: $root,
        component: childConstructor,
        identifier: 'Root element (`$root`)',
        expectedType: childConstructor.elementType.name
      });
    } else {
      this._$root = $root;
    }
    childConstructor.checkSupport();
    this.checkInitialised();
    const moduleName = childConstructor.moduleName;
    this.$root.setAttribute(`data-${moduleName}-init`, '');
  }
  checkInitialised() {
    const constructor = this.constructor;
    const moduleName = constructor.moduleName;
    if (moduleName && isInitialised(this.$root, moduleName)) {
      throw new InitError(constructor);
    }
  }
  static checkSupport() {
    if (!isSupported()) {
      throw new SupportError();
    }
  }
}

/**
 * @typedef ChildClass
 * @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component
 */

/**
 * @typedef {typeof GOVUKFrontendComponent & ChildClass} ChildClassConstructor
 */
GOVUKFrontendComponent.elementType = HTMLElement;

export { GOVUKFrontendComponent };
//# sourceMappingURL=govuk-frontend-component.mjs.map

Version data entries

56 entries across 56 versions & 2 rubygems

Version Path
govuk_publishing_components-55.0.1 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-55.0.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-54.0.1 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-54.0.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_tech_docs-4.2.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-53.0.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_tech_docs-4.1.2 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-52.1.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-52.0.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-51.2.1 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-51.2.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-51.1.1 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-51.1.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-51.0.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-50.0.1 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-50.0.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-49.1.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-49.0.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-48.0.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
govuk_publishing_components-47.0.0 node_modules/govuk-frontend/dist/govuk/govuk-frontend-component.mjs