Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@open-wc/scoped-elements

Package Overview
Dependencies
Maintainers
2
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@open-wc/scoped-elements - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

src/types.d.ts

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [1.1.1](https://github.com/open-wc/open-wc/compare/@open-wc/scoped-elements@1.1.0...@open-wc/scoped-elements@1.1.1) (2020-04-26)
### Bug Fixes
* **scoped-elements:** duplicate definition ([9aecafb](https://github.com/open-wc/open-wc/commit/9aecafbd68b8eb6a77f9d6fd8420e7693c3e8eef))
# [1.1.0](https://github.com/open-wc/open-wc/compare/@open-wc/scoped-elements@1.0.9...@open-wc/scoped-elements@1.1.0) (2020-04-25)

@@ -8,0 +19,0 @@

export { ScopedElementsMixin } from "./src/ScopedElementsMixin.js";
export type ScopedElementsMap = {
[key: string]: {
new (): HTMLElement;
prototype: HTMLElement;
};
};

2

index.js

@@ -0,1 +1,3 @@

/** @typedef {import('./src/types').ScopedElementsMap} ScopedElementsMap */
export { ScopedElementsMixin } from './src/ScopedElementsMixin.js';

4

package.json
{
"name": "@open-wc/scoped-elements",
"version": "1.1.0",
"version": "1.1.1",
"publishConfig": {

@@ -46,3 +46,3 @@ "access": "public"

"sideEffects": false,
"gitHead": "11bf8b67039d0a8768f009236c0b55426c8449a1"
"gitHead": "11053d638d9d6882d647550f7e1e5999b62552fb"
}

@@ -20,4 +20,4 @@ import { createUniqueTag } from './createUniqueTag.js';

const defineElement = (tagName, klass, registry = customElements) => {
addToGlobalTagsCache(tagName, klass);
registry.define(tagName, class extends klass {});
addToGlobalTagsCache(tagName, klass);
};

@@ -103,3 +103,5 @@

if (tag) {
defineElement(tag, klass, customElements);
if (customElements.get(tag) === undefined) {
defineElement(tag, klass, customElements);
}
} else {

@@ -106,0 +108,0 @@ tagsCache.set(tagName, registerElement(tagName, klass, tagsCache));

@@ -1,29 +0,12 @@

export function ScopedElementsMixin(superclass: import("@open-wc/dedupe-mixin").Constructor<{}>): {
new (...args: any[]): {
/**
* Defines a scoped element
*
* @param {string} tagName
* @param {typeof HTMLElement} klass
*/
defineScopedElement(tagName: string, klass: {
new (): HTMLElement;
prototype: HTMLElement;
}): void;
export type ScopedElementsMixin = typeof import("./types.js").ScopedElementsMixinImplementation;
export const ScopedElementsMixin: typeof import("./types.js").ScopedElementsMixinImplementation;
export type ScopedElementsMap = {
[key: string]: {
new (): HTMLElement;
prototype: HTMLElement;
};
readonly scopedElements: {};
/**
* @override
*/
render(template: any, container: any, options: any): any;
/**
* Returns a scoped tag name
*
* @param {string} tagName
* @returns {string|undefined}
*/
getScopedTagName(tagName: string): string;
};
export type LitElement = import("lit-element").LitElement;
export type ShadyRenderOptions = import("lit-html/lib/shady-render").ShadyRenderOptions;
export type RenderFunction = (arg0: TemplateResult, arg1: Element | DocumentFragment | ShadowRoot, arg2: import("lit-html/lib/shady-render").ShadyRenderOptions) => void;
import { TemplateResult } from "lit-html";

@@ -9,2 +9,5 @@ /* eslint-disable no-use-before-define */

/**
* @typedef {import('./types').ScopedElementsMixin} ScopedElementsMixin
* @typedef {import('./types').ScopedElementsMap} ScopedElementsMap
* @typedef {import("lit-element").LitElement} LitElement
* @typedef {import('lit-html/lib/shady-render').ShadyRenderOptions} ShadyRenderOptions

@@ -23,2 +26,3 @@ * @typedef {function(TemplateResult, Element|DocumentFragment|ShadowRoot, ShadyRenderOptions): void} RenderFunction

* Retrieves or creates a templateCache for a specific key
*
* @param {Function} key

@@ -59,3 +63,3 @@ * @returns {Map<TemplateStringsArray, TemplateStringsArray>}

* @param {ReadonlyArray} items
* @param {Object.<string, typeof HTMLElement>} scopedElements
* @param {ScopedElementsMap} scopedElements
* @param {Map<TemplateStringsArray, TemplateStringsArray>} templateCache

@@ -82,3 +86,3 @@ * @param {Map<string, string>} tagsCache

* @param {TemplateResult} template
* @param {Object.<string, typeof HTMLElement>} scopedElements
* @param {ScopedElementsMap} scopedElements
* @param {Map<TemplateStringsArray, TemplateStringsArray>} templateCache

@@ -96,2 +100,11 @@ * @param {Map<string, string>} tagsCache

/**
* Gets an instance of the ScopedElementsTemplateFactory
*
* @param {string} scopeName
* @param {ScopedElementsMap} scopedElements
* @param {Map<TemplateStringsArray, TemplateStringsArray>} templateCache
* @param {Map<string, string>} tagsCache
* @returns {function(any): any}
*/
const scopedElementsTemplateFactory = (

@@ -108,59 +121,61 @@ scopeName,

export const ScopedElementsMixin = dedupeMixin(
superclass =>
// eslint-disable-next-line no-shadow
class ScopedElementsMixin extends superclass {
static get scopedElements() {
return {};
/** @type {ScopedElementsMixin} */
const ScopedElementsMixinImplementation = superclass =>
class ScopedElementsHost extends superclass {
/**
* Obtains the scoped elements definitions map
*
* @returns {ScopedElementsMap}
*/
static get scopedElements() {
return {};
}
/** @override */
static render(template, container, options) {
if (!options || typeof options !== 'object' || !options.scopeName) {
throw new Error('The `scopeName` option is required.');
}
const { scopeName } = options;
/**
* @override
*/
static render(template, container, options) {
if (!options || typeof options !== 'object' || !options.scopeName) {
throw new Error('The `scopeName` option is required.');
}
const { scopeName } = options;
const templateCache = getTemplateCache(this);
const tagsCache = getTagsCache(this);
const { scopedElements } = this;
const templateCache = getTemplateCache(this);
const tagsCache = getTagsCache(this);
const { scopedElements } = this;
return super.render(template, container, {
...options,
templateFactory: scopedElementsTemplateFactory(
scopeName,
scopedElements,
templateCache,
tagsCache,
),
});
}
// @ts-ignore
return super.render(template, container, {
...options,
templateFactory: scopedElementsTemplateFactory(
scopeName,
scopedElements,
templateCache,
tagsCache,
),
});
}
/**
* Defines a scoped element
*
* @param {string} tagName
* @param {typeof HTMLElement} klass
*/
defineScopedElement(tagName, klass) {
return defineScopedElement(tagName, klass, getTagsCache(this.constructor));
}
/**
* Defines a scoped element
*
* @param {string} tagName
* @param {typeof HTMLElement} klass
*/
defineScopedElement(tagName, klass) {
return defineScopedElement(tagName, klass, getTagsCache(this.constructor));
}
/**
* Returns a scoped tag name
*
* @param {string} tagName
* @returns {string|undefined}
*/
static getScopedTagName(tagName) {
const klass = this.scopedElements[tagName];
/**
* Returns a scoped tag name
*
* @param {string} tagName
* @returns {string|undefined}
*/
static getScopedTagName(tagName) {
const klass = this.scopedElements[tagName];
return klass
? registerElement(tagName, klass, getTagsCache(this))
: getTagsCache(this).get(tagName);
}
};
return klass
? registerElement(tagName, klass, getTagsCache(this))
: getTagsCache(this).get(tagName);
}
},
);
export const ScopedElementsMixin = dedupeMixin(ScopedElementsMixinImplementation);

@@ -6,3 +6,3 @@ /**

* @param {TemplateStringsArray} strings
* @param {Object.<string, typeof HTMLElement>} tags
* @param {ScopedElementsMap} scopedElements
* @param {Map<TemplateStringsArray, TemplateStringsArray>} templateCache

@@ -12,7 +12,8 @@ * @param {Map<string, string>} tagsCache

*/
export function transform(strings: TemplateStringsArray, tags: {
[x: string]: {
export function transform(strings: TemplateStringsArray, scopedElements: import("./types.js").ScopedElementsMap, templateCache: Map<TemplateStringsArray, TemplateStringsArray>, tagsCache: Map<string, string>): TemplateStringsArray;
export type ScopedElementsMap = {
[key: string]: {
new (): HTMLElement;
prototype: HTMLElement;
};
}, templateCache: Map<TemplateStringsArray, TemplateStringsArray>, tagsCache: Map<string, string>): TemplateStringsArray;
};
import { registerElement } from './registerElement.js';
/**
* allowed tag name chars
* @typedef {import('./types').ScopedElementsMap} ScopedElementsMap
*/
/**
* Allowed tag name chars
*

@@ -45,3 +49,3 @@ * @type {string}

* @param {TemplateStringsArray} strings
* @param {Object.<string, typeof HTMLElement>} tags
* @param {ScopedElementsMap} scopedElements
* @param {Map<TemplateStringsArray, TemplateStringsArray>} templateCache

@@ -51,3 +55,3 @@ * @param {Map<string, string>} tagsCache

*/
const transformTemplate = (strings, tags, templateCache, tagsCache) => {
const transformTemplate = (strings, scopedElements, templateCache, tagsCache) => {
const transformedStrings = strings.map(str => {

@@ -59,3 +63,3 @@ let acc = str;

const item = matches[i];
const klass = tags[item[1]];
const klass = scopedElements[item[1]];
const tag = registerElement(item[1], klass, tagsCache);

@@ -85,3 +89,3 @@ const start = item.index + item[0].length - item[1].length;

* @param {TemplateStringsArray} strings
* @param {Object.<string, typeof HTMLElement>} tags
* @param {ScopedElementsMap} scopedElements
* @param {Map<TemplateStringsArray, TemplateStringsArray>} templateCache

@@ -91,4 +95,7 @@ * @param {Map<string, string>} tagsCache

*/
export function transform(strings, tags, templateCache = globalCache, tagsCache) {
return templateCache.get(strings) || transformTemplate(strings, tags, templateCache, tagsCache);
export function transform(strings, scopedElements, templateCache = globalCache, tagsCache) {
return (
templateCache.get(strings) ||
transformTemplate(strings, scopedElements, templateCache, tagsCache)
);
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc