@dbp-toolkit/language-select
Advanced tools
Comparing version 0.3.4 to 0.3.5
@@ -1,3 +0,204 @@ | ||
import { a as Logger, S as ScopedElementsMixin, A as AdapterLitElement, L as LanguageSelect, k as ke, d as defineCustomElement, c as createInstance, s as setOverrides } from './shared/language-select.CEV4RvHX.es.js'; | ||
import { a as dedupeMixin, S, b as Logger, A as AdapterLitElement, L as LanguageSelect, k as ke, d as defineCustomElement, c as createInstance, s as setOverrides } from './shared/language-select.spN_q76y.es.js'; | ||
/** | ||
* @typedef {import('./types').RenderOptions} RenderOptions | ||
* @typedef {import('./types').ScopedElementsMixin} ScopedElementsMixin | ||
* @typedef {import('./types').ScopedElementsHost} ScopedElementsHost | ||
* @typedef {import('./types').ScopedElementsMap} ScopedElementsMap | ||
* @typedef {import('@lit/reactive-element').CSSResultOrNative} CSSResultOrNative | ||
*/ | ||
const version = '2.2.2'; | ||
// eslint-disable-next-line dot-notation | ||
const versions = window['scopedElementsVersions'] || (window['scopedElementsVersions'] = []); | ||
if (!versions.includes(version)) { | ||
versions.push(version); | ||
} | ||
// @ts-ignore | ||
const supportsScopedRegistry = !!ShadowRoot.prototype.createElement; | ||
/** | ||
* @template {import('./types').Constructor<HTMLElement>} T | ||
* @param {T} superclass | ||
* @return {T & import('./types').Constructor<ScopedElementsHost>} | ||
*/ | ||
const ScopedElementsMixinImplementation = superclass => | ||
/** @type {ScopedElementsHost} */ | ||
class ScopedElementsHost extends superclass { | ||
/** | ||
* Obtains the scoped elements definitions map if specified. | ||
* | ||
* @returns {ScopedElementsMap} | ||
*/ | ||
static get scopedElements() { | ||
return {}; | ||
} | ||
static get scopedElementsVersion() { | ||
return version; | ||
} | ||
/** | ||
* Obtains the ShadowRoot options. | ||
* | ||
* @type {ShadowRootInit} | ||
*/ | ||
static get shadowRootOptions() { | ||
return this.__shadowRootOptions; | ||
} | ||
/** | ||
* Set the shadowRoot options. | ||
* | ||
* @param {ShadowRootInit} value | ||
*/ | ||
static set shadowRootOptions(value) { | ||
this.__shadowRootOptions = value; | ||
} | ||
/** | ||
* Obtains the element styles. | ||
* | ||
* @returns {CSSResultOrNative[]} | ||
*/ | ||
static get elementStyles() { | ||
return this.__elementStyles; | ||
} | ||
static set elementStyles(styles) { | ||
this.__elementStyles = styles; | ||
} | ||
// either TS or ESLint will complain here | ||
// eslint-disable-next-line no-unused-vars | ||
constructor(..._args) { | ||
super(); | ||
/** @type {RenderOptions} */ | ||
this.renderOptions = this.renderOptions || undefined; | ||
} | ||
/** | ||
* Obtains the CustomElementRegistry associated to the ShadowRoot. | ||
* | ||
* @returns {CustomElementRegistry} | ||
*/ | ||
get registry() { | ||
// @ts-ignore | ||
return this.constructor.__registry; | ||
} | ||
/** | ||
* Set the CustomElementRegistry associated to the ShadowRoot | ||
* | ||
* @param {CustomElementRegistry} registry | ||
*/ | ||
set registry(registry) { | ||
// @ts-ignore | ||
this.constructor.__registry = registry; | ||
} | ||
createRenderRoot() { | ||
const { scopedElements, shadowRootOptions, elementStyles } = | ||
/** @type {typeof ScopedElementsHost} */ (this.constructor); | ||
const shouldCreateRegistry = | ||
!this.registry || | ||
// @ts-ignore | ||
(this.registry === this.constructor.__registry && | ||
!Object.prototype.hasOwnProperty.call(this.constructor, '__registry')); | ||
/** | ||
* Create a new registry if: | ||
* - the registry is not defined | ||
* - this class doesn't have its own registry *AND* has no shared registry | ||
*/ | ||
if (shouldCreateRegistry) { | ||
this.registry = supportsScopedRegistry ? new CustomElementRegistry() : customElements; | ||
for (const [tagName, klass] of Object.entries(scopedElements)) { | ||
this.defineScopedElement(tagName, klass); | ||
} | ||
} | ||
/** @type {ShadowRootInit} */ | ||
const options = { | ||
mode: 'open', | ||
...shadowRootOptions, | ||
customElements: this.registry, | ||
registry: this.registry, | ||
}; | ||
const createdRoot = this.attachShadow(options); | ||
if (supportsScopedRegistry) { | ||
this.renderOptions.creationScope = createdRoot; | ||
} | ||
if (createdRoot instanceof ShadowRoot) { | ||
S(createdRoot, elementStyles); | ||
this.renderOptions.renderBefore = this.renderOptions.renderBefore || createdRoot.firstChild; | ||
} | ||
return createdRoot; | ||
} | ||
createScopedElement(tagName) { | ||
const root = supportsScopedRegistry ? this.shadowRoot : document; | ||
// @ts-ignore polyfill to support createElement on shadowRoot is loaded | ||
return root.createElement(tagName); | ||
} | ||
/** | ||
* Defines a scoped element. | ||
* | ||
* @param {string} tagName | ||
* @param {typeof HTMLElement} klass | ||
*/ | ||
defineScopedElement(tagName, klass) { | ||
const registeredClass = this.registry.get(tagName); | ||
if (registeredClass && supportsScopedRegistry === false && registeredClass !== klass) { | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
[ | ||
`You are trying to re-register the "${tagName}" custom element with a different class via ScopedElementsMixin.`, | ||
'This is only possible with a CustomElementRegistry.', | ||
'Your browser does not support this feature so you will need to load a polyfill for it.', | ||
'Load "@webcomponents/scoped-custom-element-registry" before you register ANY web component to the global customElements registry.', | ||
'e.g. add "<script src="/node_modules/@webcomponents/scoped-custom-element-registry/scoped-custom-element-registry.min.js"></script>" as your first script tag.', | ||
'For more details you can visit https://open-wc.org/docs/development/scoped-elements/', | ||
].join('\n'), | ||
); | ||
} | ||
if (!registeredClass) { | ||
return this.registry.define(tagName, klass); | ||
} | ||
return this.registry.get(tagName); | ||
} | ||
/** | ||
* @deprecated use the native el.tagName instead | ||
* | ||
* @param {string} tagName | ||
* @returns {string} the tag name | ||
*/ | ||
// eslint-disable-next-line class-methods-use-this | ||
getScopedTagName(tagName) { | ||
// @ts-ignore | ||
return this.constructor.getScopedTagName(tagName); | ||
} | ||
/** | ||
* @deprecated use the native el.tagName instead | ||
* | ||
* @param {string} tagName | ||
* @returns {string} the tag name | ||
*/ | ||
// eslint-disable-next-line class-methods-use-this | ||
static getScopedTagName(tagName) { | ||
// @ts-ignore | ||
return this.__registry.get(tagName) ? tagName : undefined; | ||
} | ||
}; | ||
const ScopedElementsMixin = dedupeMixin(ScopedElementsMixinImplementation); | ||
class Provider extends HTMLElement { | ||
@@ -4,0 +205,0 @@ constructor() { |
@@ -1,4 +0,4 @@ | ||
import { d as defineCustomElement, L as LanguageSelect } from './shared/language-select.CEV4RvHX.es.js'; | ||
import { d as defineCustomElement, L as LanguageSelect } from './shared/language-select.spN_q76y.es.js'; | ||
defineCustomElement('dbp-language-select', LanguageSelect); | ||
//# sourceMappingURL=dbp-language-select.js.map |
{ | ||
"name": "@dbp-toolkit/language-select", | ||
"homepage": "https://github.com/digital-blueprint/toolkit/tree/main/packages/language-select", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"type": "module", | ||
@@ -43,5 +43,5 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"@dbp-toolkit/common": "^0.3.11", | ||
"@dbp-toolkit/provider": "^0.2.11", | ||
"@open-wc/scoped-elements": "^3.0.5", | ||
"@dbp-toolkit/common": "^0.3.12", | ||
"@dbp-toolkit/provider": "^0.2.12", | ||
"@open-wc/scoped-elements": "^2.1.0", | ||
"lit": "^3.0.0" | ||
@@ -65,3 +65,3 @@ }, | ||
}, | ||
"gitHead": "8b2032fcf77b68f7b0ed81c4da0ae4c4fde66127" | ||
"gitHead": "76d106e21d7e9c4403fabab792b1941d8d70160b" | ||
} |
import {html} from 'lit'; | ||
import {LanguageSelect} from './language-select.js'; | ||
import * as commonUtils from '@dbp-toolkit/common/utils'; | ||
import {AdapterLitElement, ScopedElementsMixin} from '@dbp-toolkit/common'; | ||
import { ScopedElementsMixin } from '@open-wc/scoped-elements'; | ||
import {AdapterLitElement} from '@dbp-toolkit/common'; | ||
import {Provider} from "@dbp-toolkit/provider"; | ||
@@ -6,0 +7,0 @@ import {createInstance, setOverrides} from './i18n.js'; |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
677609
5172
- Removed@open-wc/scoped-elements@3.0.5(transitive)
Updated@dbp-toolkit/common@^0.3.12