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