@rxdi/lit-html 0.7.118

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "printWidth": 80
4
+ }
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # lit-html hard fork prepared for bundlers with removed `.js` files from extensions
2
+
3
+ #### Install
4
+ ```bash
5
+ npm i @rxdi/lit-html
6
+ ```
7
+
8
+ Example component
9
+ ```typescript
10
+ import { LitElement, Component, html, css } from '@rxdi/lit-html';
11
+
12
+ /**
13
+ * @customElement rx-description
14
+ */
15
+ @Component({
16
+ selector: 'rx-description',
17
+ style: css`
18
+ .description {
19
+ color: #222;
20
+ font-size: 14px;
21
+ font-weight: normal;
22
+ text-transform: uppercase;
23
+ }
24
+
25
+ .text {
26
+ color: #666;
27
+ font-size: 15px;
28
+ font-weight: normal;
29
+ line-height: 1.5;
30
+ }
31
+
32
+ .border {
33
+ border-top: 1px solid #e5e5e5;
34
+ margin-top: 20px;
35
+ padding-top: 20px;
36
+ }
37
+ `,
38
+ template(this: DescriptionListComponent) {
39
+ return html`
40
+ <div class="container" part="container">
41
+ <slot name="description" class="description" part="description"></slot>
42
+ <slot name="text" class="text" part="text"></slot>
43
+ <div class="border" part="border"></div>
44
+ </div>
45
+ `;
46
+ }
47
+ })
48
+ export class DescriptionListComponent extends LitElement {}
49
+ ```
@@ -0,0 +1,24 @@
1
+ import { noChange } from 'lit';
2
+ import { AsyncDirective } from 'lit/async-directive';
3
+ interface Unsubscribable {
4
+ unsubscribe(): void;
5
+ }
6
+ interface Subscribable<T> {
7
+ /** @deprecated Use an observer instead of a complete callback */
8
+ subscribe(next: null | undefined, error: null | undefined, complete: () => void): Unsubscribable;
9
+ /** @deprecated Use an observer instead of an error callback */
10
+ subscribe(next: null | undefined, error: (error: any) => void, complete?: () => void): Unsubscribable;
11
+ /** @deprecated Use an observer instead of a complete callback */
12
+ subscribe(next: (value: T) => void, error: null | undefined, complete: () => void): Unsubscribable;
13
+ subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Unsubscribable;
14
+ }
15
+ declare class ObserveDirective extends AsyncDirective {
16
+ observable: Subscribable<unknown> | undefined;
17
+ unsubscribe: Unsubscribable;
18
+ render(asyncResult: Subscribable<unknown>): "" | typeof noChange;
19
+ subscribe(observable: Subscribable<unknown>): void;
20
+ disconnected(): void;
21
+ reconnected(): void;
22
+ }
23
+ export declare const async: (asyncResult: Subscribable<unknown>) => import("lit-html/directive").DirectiveResult<typeof ObserveDirective>;
24
+ export {};
package/dist/async.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.async = void 0;
4
+ const lit_1 = require("lit");
5
+ const directive_1 = require("lit/directive");
6
+ const async_directive_1 = require("lit/async-directive");
7
+ class ObserveDirective extends async_directive_1.AsyncDirective {
8
+ // When the observable changes, unsubscribe to the old one and
9
+ // subscribe to the new one
10
+ render(asyncResult) {
11
+ if ('then' in asyncResult) {
12
+ Promise.resolve(asyncResult).then((v) => this.setValue(v));
13
+ return '';
14
+ }
15
+ if (this.observable !== asyncResult) {
16
+ this.unsubscribe.unsubscribe();
17
+ this.observable = asyncResult;
18
+ if (this.isConnected) {
19
+ this.subscribe(asyncResult);
20
+ }
21
+ }
22
+ return lit_1.noChange;
23
+ }
24
+ // Subscribes to the observable, calling the directive's asynchronous
25
+ // setValue API each time the value changes
26
+ subscribe(observable) {
27
+ this.unsubscribe = observable.subscribe((v) => {
28
+ this.setValue(v);
29
+ });
30
+ }
31
+ // When the directive is disconnected from the DOM, unsubscribe to ensure
32
+ // the directive instance can be garbage collected
33
+ disconnected() {
34
+ this.unsubscribe.unsubscribe();
35
+ }
36
+ // If the subtree the directive is in was disconneted and subsequently
37
+ // re-connected, re-subscribe to make the directive operable again
38
+ reconnected() {
39
+ this.subscribe(this.observable);
40
+ }
41
+ }
42
+ exports.async = directive_1.directive(ObserveDirective);
@@ -0,0 +1,37 @@
1
+ import { CSSResult } from 'lit';
2
+ import { TemplateResult } from 'lit';
3
+ import { RXDIElement } from './tokens';
4
+ export interface CustomElementConfig<T> {
5
+ selector: string;
6
+ template?: (self: T) => TemplateResult;
7
+ style?: CSSResult;
8
+ styles?: CSSResult[];
9
+ useShadow?: boolean;
10
+ extends?: string;
11
+ container?: HTMLElement | DocumentFragment;
12
+ providers?: Function[];
13
+ unsubscribeOnDestroy?: boolean;
14
+ /**
15
+ * It will unsubscribe from previous observables subscriptions
16
+ * Defaults to 5000 ms
17
+ * */
18
+ garbageCollectTimeout?: number;
19
+ garbageCollectOnUpdate?: boolean;
20
+ }
21
+ export declare const Component: <T>(config: CustomElementConfig<T>) => <K extends new (...args: any[]) => {}>(Base: K) => {
22
+ new (...args: any[]): {
23
+ getTemplateResult(): any;
24
+ OnInit(): any;
25
+ disconnectedCallback(): void;
26
+ connectedCallback(): void;
27
+ render(): any;
28
+ update(): void;
29
+ firstUpdated(): void;
30
+ };
31
+ styles: CSSResult[];
32
+ subscriptions: Map<any, any>;
33
+ collectGarbage(): void;
34
+ mapToSubscriptions(): void;
35
+ is(): string;
36
+ setElement: (document: RXDIElement) => K;
37
+ } & K;
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Component = void 0;
4
+ const lit_1 = require("lit");
5
+ const legacyCustomElement = (tagName, clazz, options) => {
6
+ window.customElements.define(tagName, clazz, options);
7
+ return clazz;
8
+ };
9
+ const standardCustomElement = (tagName, descriptor, options) => {
10
+ const { kind, elements } = descriptor;
11
+ return {
12
+ kind,
13
+ elements,
14
+ // This callback is called once the class is otherwise fully defined
15
+ finisher(clazz) {
16
+ window.customElements.define(tagName, clazz, options);
17
+ },
18
+ };
19
+ };
20
+ const customElement = (tag, config = {}) => (Base) => {
21
+ var _a;
22
+ if (!tag || (tag && tag.indexOf('-') <= 0)) {
23
+ throw new Error(`You need at least 1 dash in the custom element name! ${Base}`);
24
+ }
25
+ config.styles = config.styles || [];
26
+ if (!('unsubscribeOnDestroy' in config)) {
27
+ config.unsubscribeOnDestroy = true;
28
+ }
29
+ const OnInit = Base.prototype.OnInit || function () { };
30
+ const OnDestroy = Base.prototype.OnDestroy || function () { };
31
+ const OnUpdate = Base.prototype.OnUpdate || function () { };
32
+ const OnUpdateFirst = Base.prototype.OnUpdateFirst || function () { };
33
+ const connectedCallback = Base.prototype.connectedCallback || function () { };
34
+ const disconnectedCallback = Base.prototype.disconnectedCallback || function () { };
35
+ const update = Base.prototype.update || function () { };
36
+ const firstUpdated = Base.prototype.firstUpdated || function () { };
37
+ if (!config.template) {
38
+ config.template = Base.prototype.render;
39
+ }
40
+ if (config.style) {
41
+ config.styles.push(config.style);
42
+ }
43
+ const ModifiedClass = (_a = class NoName extends Base {
44
+ static collectGarbage() {
45
+ ModifiedClass.subscriptions.forEach((sub) => sub.unsubscribe());
46
+ ModifiedClass.subscriptions.clear();
47
+ }
48
+ static mapToSubscriptions() {
49
+ // Override subscribe method so we can set subscription to new Map() later when component is unmounted we can unsubscribe
50
+ Object.keys(this).forEach((observable) => {
51
+ if (this[observable] &&
52
+ typeof this[observable].lift === 'function' &&
53
+ typeof this[observable].subscribe === 'function') {
54
+ const original = this[observable].subscribe.bind(this[observable]);
55
+ this[observable].subscribe = (cb, err) => {
56
+ const subscribe = original(cb, err);
57
+ ModifiedClass.subscriptions.set(subscribe, subscribe);
58
+ return subscribe;
59
+ };
60
+ }
61
+ });
62
+ }
63
+ static is() {
64
+ return tag;
65
+ }
66
+ getTemplateResult() {
67
+ return this;
68
+ }
69
+ OnInit() {
70
+ if (config.container) {
71
+ lit_1.render(config.template.call(this), config.container);
72
+ if (config.style) {
73
+ const style = document.createElement('style');
74
+ style.type = 'text/css';
75
+ if (style['styleSheet']) {
76
+ // This is required for IE8 and below.
77
+ style['styleSheet'].cssText = config.style.toString();
78
+ }
79
+ else {
80
+ style.appendChild(document.createTextNode(config.style.toString()));
81
+ }
82
+ config.container.prepend(style);
83
+ }
84
+ }
85
+ return OnInit.call(this);
86
+ }
87
+ disconnectedCallback() {
88
+ if (config.unsubscribeOnDestroy) {
89
+ ModifiedClass.collectGarbage();
90
+ }
91
+ OnDestroy.call(this);
92
+ disconnectedCallback.call(this);
93
+ }
94
+ connectedCallback() {
95
+ if (config.unsubscribeOnDestroy) {
96
+ ModifiedClass.mapToSubscriptions.call(this);
97
+ }
98
+ if (!config.template) {
99
+ config.template = () => lit_1.html ``;
100
+ }
101
+ // Check if element is pure HTMLElement or LitElement
102
+ // if (!this['performUpdate']) {
103
+ // config.template = config.template.bind(this);
104
+ // const clone = document.importNode(
105
+ // config.template(this as never),
106
+ // true
107
+ // );
108
+ // if (config.style) {
109
+ // const style = document.createElement('style');
110
+ // style.type = 'text/css';
111
+ // if (style['styleSheet']) {
112
+ // // This is required for IE8 and below.
113
+ // style['styleSheet'].cssText = config.style.toString();
114
+ // } else {
115
+ // style.appendChild(document.createTextNode(config.style.toString()));
116
+ // }
117
+ // clone.append(style);
118
+ // }
119
+ // if (config.useShadow) {
120
+ // this['attachShadow']({ mode: 'open' }).append(clone);
121
+ // } else {
122
+ // this['appendChild'](clone);
123
+ // }
124
+ // }
125
+ connectedCallback.call(this);
126
+ OnInit.call(this);
127
+ }
128
+ render() {
129
+ return config.template.call(this);
130
+ }
131
+ update() {
132
+ if (config.garbageCollectOnUpdate) {
133
+ ModifiedClass.collectGarbage();
134
+ }
135
+ update.call(this);
136
+ OnUpdate.call(this);
137
+ if (config.unsubscribeOnDestroy) {
138
+ ModifiedClass.mapToSubscriptions.call(this);
139
+ }
140
+ }
141
+ firstUpdated() {
142
+ firstUpdated.call(this);
143
+ OnUpdateFirst.call(this);
144
+ if (config.unsubscribeOnDestroy) {
145
+ ModifiedClass.mapToSubscriptions.call(this);
146
+ }
147
+ }
148
+ },
149
+ _a.styles = config.styles,
150
+ _a.subscriptions = new Map(),
151
+ _a.setElement = (document) => {
152
+ config.container = document;
153
+ return Base;
154
+ },
155
+ _a);
156
+ if (typeof ModifiedClass === 'function') {
157
+ legacyCustomElement(tag, ModifiedClass, {
158
+ extends: config.extends,
159
+ });
160
+ }
161
+ else {
162
+ standardCustomElement(tag, ModifiedClass, { extends: config.extends });
163
+ }
164
+ return ModifiedClass;
165
+ };
166
+ exports.Component = (config) => customElement(config.selector, config);
@@ -0,0 +1,8 @@
1
+ interface CustomElementConfig {
2
+ selector: string;
3
+ template: string;
4
+ style?: string;
5
+ useShadow?: boolean;
6
+ }
7
+ export declare const CustomElement: (config: CustomElementConfig) => (cls: any) => void;
8
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomElement = void 0;
4
+ const validateSelector = (selector) => {
5
+ if (selector.indexOf('-') <= 0) {
6
+ throw new Error('You need at least 1 dash in the custom element name!');
7
+ }
8
+ };
9
+ exports.CustomElement = (config) => cls => {
10
+ validateSelector(config.selector);
11
+ if (!config.template) {
12
+ throw new Error('You need to pass a template for the element');
13
+ }
14
+ const template = document.createElement('template');
15
+ if (config.style) {
16
+ config.template = `<style>${config.style}</style> ${config.template}`;
17
+ }
18
+ template.innerHTML = config.template;
19
+ const connectedCallback = cls.prototype.connectedCallback || function () { };
20
+ cls.prototype.connectedCallback = function () {
21
+ // Check if element is pure HTMLElement or LitElement
22
+ if (!this.performUpdate) {
23
+ const clone = document.importNode(template.content, true);
24
+ if (config.useShadow) {
25
+ this.attachShadow({ mode: 'open' }).appendChild(clone);
26
+ }
27
+ else {
28
+ this.appendChild(clone);
29
+ }
30
+ }
31
+ connectedCallback.call(this);
32
+ };
33
+ window.customElements.define(config.selector, cls);
34
+ };
@@ -0,0 +1,5 @@
1
+ export * from './on-before';
2
+ export * from './on-destroy';
3
+ export * from './on-init';
4
+ export * from './on-update';
5
+ export * from './on-update-first';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./on-before"), exports);
14
+ __exportStar(require("./on-destroy"), exports);
15
+ __exportStar(require("./on-init"), exports);
16
+ __exportStar(require("./on-update"), exports);
17
+ __exportStar(require("./on-update-first"), exports);
@@ -0,0 +1,3 @@
1
+ export interface OnBefore {
2
+ OnBefore(): void;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export interface OnDestroy {
2
+ OnDestroy(): void;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export interface OnInit {
2
+ OnInit(): void;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export interface OnUpdateFirst {
2
+ OnUpdateFirst(): void;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export interface OnUpdate {
2
+ OnUpdate(): void;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from './component.decorator';
2
+ export * from './hooks/index';
3
+ export * from './tokens';
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./component.decorator"), exports);
14
+ __exportStar(require("./hooks/index"), exports);
15
+ __exportStar(require("./tokens"), exports);
@@ -0,0 +1,20 @@
1
+ import { CSSResult, CSSResultArray, TemplateResult } from 'lit';
2
+ export declare class Subscription {
3
+ static EMPTY: Subscription;
4
+ closed: boolean;
5
+ protected _parentOrParents: Subscription | Subscription[];
6
+ private _subscriptions;
7
+ constructor(unsubscribe?: () => void);
8
+ unsubscribe(): void;
9
+ }
10
+ export declare class RXDIElement extends HTMLElement {
11
+ static setElement?<T>(component: T, document: RXDIElement): T;
12
+ static is?(document: RXDIElement): RXDIElement;
13
+ static styles?: CSSResult | CSSResultArray;
14
+ static subscriptions?: Map<Subscription, Subscription>;
15
+ getTemplateResult?(): TemplateResult;
16
+ OnBefore?(): void;
17
+ OnInit?(): void;
18
+ OnUpdate?(): void;
19
+ OnUpdateFirst?(): void;
20
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RXDIElement = void 0;
4
+ class RXDIElement extends HTMLElement {
5
+ }
6
+ exports.RXDIElement = RXDIElement;
@@ -0,0 +1,18 @@
1
+ export * from './decorators/index';
2
+ export * from './async';
3
+ export * from 'lit';
4
+ export * from 'lit/decorators';
5
+ export * from 'lit/directives/class-map';
6
+ export * from 'lit/directives/async-append';
7
+ export * from 'lit/directives/async-replace';
8
+ export * from 'lit/directives/cache';
9
+ export * from 'lit/directives/guard';
10
+ export * from 'lit/directives/if-defined';
11
+ export * from 'lit/directives/live';
12
+ export * from 'lit/directives/ref';
13
+ export * from 'lit/directives/repeat';
14
+ export * from 'lit/directives/style-map';
15
+ export * from 'lit/directives/template-content';
16
+ export * from 'lit/directives/unsafe-html';
17
+ export * from 'lit/directives/unsafe-svg';
18
+ export * from 'lit/directives/until';
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./decorators/index"), exports);
14
+ __exportStar(require("./async"), exports);
15
+ __exportStar(require("lit"), exports);
16
+ __exportStar(require("lit/decorators"), exports);
17
+ __exportStar(require("lit/directives/class-map"), exports);
18
+ __exportStar(require("lit/directives/async-append"), exports);
19
+ __exportStar(require("lit/directives/async-replace"), exports);
20
+ __exportStar(require("lit/directives/cache"), exports);
21
+ __exportStar(require("lit/directives/guard"), exports);
22
+ __exportStar(require("lit/directives/if-defined"), exports);
23
+ __exportStar(require("lit/directives/live"), exports);
24
+ __exportStar(require("lit/directives/ref"), exports);
25
+ __exportStar(require("lit/directives/repeat"), exports);
26
+ __exportStar(require("lit/directives/style-map"), exports);
27
+ __exportStar(require("lit/directives/template-content"), exports);
28
+ __exportStar(require("lit/directives/unsafe-html"), exports);
29
+ __exportStar(require("lit/directives/unsafe-svg"), exports);
30
+ __exportStar(require("lit/directives/until"), exports);
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@rxdi/lit-html",
3
+ "version": "0.7.118",
4
+ "main": "./dist/index.js",
5
+ "author": "Kristiyan Tachev",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/rxdi/lit-html"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc || true"
13
+ },
14
+ "dependencies": {
15
+ "lit": "^2.0.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^12.0.10",
19
+ "typescript": "^3.9.3"
20
+ },
21
+ "types": "./dist/index.d.ts",
22
+ "module": "./dist/index.js",
23
+ "typings": "./dist/index.d.ts"
24
+ }
package/types/env.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ interface ShadyCSS {
2
+ styleElement(host: Element, overrideProps?: {[key: string]: string}): void;
3
+ getComputedStyleValue(element: Element, property: string): string;
4
+ ScopingShim: {prepareAdoptedCssText(cssText: string[], name: string): void;};
5
+ nativeShadow: boolean;
6
+ }
7
+
8
+ interface ShadyDOM {
9
+ inUse: boolean;
10
+ }
11
+
12
+ interface Window {
13
+ ShadyCSS?: ShadyCSS;
14
+ ShadyDOM?: ShadyDOM;
15
+ ShadowRoot: typeof ShadowRoot;
16
+ }
17
+
18
+ // Augment existing types with styling API
19
+ interface ShadowRoot {
20
+ adoptedStyleSheets: CSSStyleSheet[];
21
+ }
22
+
23
+ declare var ShadowRoot: {prototype: ShadowRoot; new (): ShadowRoot;}
24
+
25
+ interface CSSStyleSheet {
26
+ replaceSync(cssText: string): void;
27
+ replace(cssText: string): Promise<unknown>;
28
+ }