diff --git a/packages/custom-elements/CHANGELOG.md b/packages/custom-elements/CHANGELOG.md index 5ab3592d..495e5d66 100644 --- a/packages/custom-elements/CHANGELOG.md +++ b/packages/custom-elements/CHANGELOG.md @@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - +## Unreleased + +- Re implement the CustomElementRegistry interface ([#606](https://github.com/webcomponents/polyfills/pull/606)) ## [1.6.0] - 2023-03-30 diff --git a/packages/custom-elements/ts_src/CustomElementRegistry.ts b/packages/custom-elements/ts_src/CustomElementRegistry.ts index b8e32931..0eb93d35 100644 --- a/packages/custom-elements/ts_src/CustomElementRegistry.ts +++ b/packages/custom-elements/ts_src/CustomElementRegistry.ts @@ -278,6 +278,11 @@ export default class CustomElementRegistry { return undefined; } + getName(constructor: ElementConstructor): string | null { + const definition = this._constructorToDefinition.get(constructor); + return definition ? definition.localName : null; + } + whenDefined(localName: string): Promise { if (!Utilities.isValidCustomElementName(localName)) { return Promise.reject( @@ -363,4 +368,6 @@ CustomElementRegistry.prototype['polyfillDefineLazy'] = CustomElementRegistry.prototype.polyfillDefineLazy; CustomElementRegistry.prototype['polyfillWrapFlushCallback'] = CustomElementRegistry.prototype.polyfillWrapFlushCallback; +CustomElementRegistry.prototype['getName'] = + CustomElementRegistry.prototype.getName; /* eslint-enable no-self-assign */ diff --git a/packages/tests/custom-elements/html/registry.test.html b/packages/tests/custom-elements/html/registry.test.html index 54226516..65722625 100644 --- a/packages/tests/custom-elements/html/registry.test.html +++ b/packages/tests/custom-elements/html/registry.test.html @@ -209,6 +209,23 @@ }); }); + suite('getName', function () { + test('returns the local name for a defined custom element constructor', function () { + class XGetName extends HTMLElement {} + customElements.define('x-get-name', XGetName); + + var name = customElements.getName(XGetName); + assert.equal(name, 'x-get-name'); + }); + + test('returns null for an undefined custom element constructor', function () { + class XUndefinedElement extends HTMLElement {} + + var name = customElements.getName(XUndefinedElement); + assert.isNull(name); + }); + }); + suite('whenDefined', function () { test('resolves when a tag is defined', function () { var promise = customElements