@rxdi/lit-html 0.7.139 → 0.7.142

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.
@@ -1,15 +1,26 @@
1
- import { CSSResult } from '../reactive-element/css-tag';
2
1
  import { TemplateResult } from '../lit-html/lit-html';
3
- export declare const pipe: (...fns: Function[]) => (x: TemplateResult) => any;
2
+ import { CSSResult } from '../reactive-element/css-tag';
3
+ export interface CustomAttributeRegistry {
4
+ define(name: string, modifier: Function | Modifier): void;
5
+ get(element: HTMLElement, attrName: string): any;
6
+ unsubscribe(): void;
7
+ }
8
+ export interface ModifierOptions {
9
+ name: string;
10
+ registry?: CustomAttributeRegistry;
11
+ }
12
+ export interface Modifier extends Function {
13
+ name: string;
14
+ options(): ModifierOptions;
15
+ }
4
16
  export interface CustomElementConfig<T> {
5
17
  selector: string;
6
- template?: (self: T) => TemplateResult;
18
+ template?: (this: T) => TemplateResult;
7
19
  style?: CSSResult;
8
20
  styles?: CSSResult[];
9
21
  extends?: string;
10
- modifiers?: (Function | {
11
- html(template: TemplateResult): TemplateResult;
12
- })[];
22
+ registry?: (this: T) => CustomAttributeRegistry;
23
+ modifiers?: Modifier[];
13
24
  /**
14
25
  * Intended only for first render inside the DOM
15
26
  * for example we want app-component to be rendered
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Component = exports.pipe = void 0;
3
+ exports.Component = void 0;
4
4
  const lit_html_1 = require("../lit-html/lit-html");
5
- const pipe = (...fns) => (x) => fns.reduce((v, f) => f.call(this, v), x);
6
- exports.pipe = pipe;
7
5
  const legacyCustomElement = (tagName, clazz, options) => {
8
6
  window.customElements.define(tagName, clazz, options);
9
7
  return clazz;
@@ -16,9 +14,10 @@ const standardCustomElement = (tagName, descriptor, options) => {
16
14
  // This callback is called once the class is otherwise fully defined
17
15
  finisher(clazz) {
18
16
  window.customElements.define(tagName, clazz, options);
19
- },
17
+ }
20
18
  };
21
19
  };
20
+ const isFunction = (v) => typeof v === 'function';
22
21
  const customElement = (tag, config = {}) => (Base) => {
23
22
  var _a;
24
23
  if (!tag || (tag && tag.indexOf('-') <= 0)) {
@@ -33,6 +32,7 @@ const customElement = (tag, config = {}) => (Base) => {
33
32
  const disconnectedCallback = Base.prototype.disconnectedCallback || function () { };
34
33
  const update = Base.prototype.update || function () { };
35
34
  const firstUpdated = Base.prototype.firstUpdated || function () { };
35
+ let registry;
36
36
  if (!config.template) {
37
37
  config.template = Base.prototype.render || (() => (0, lit_html_1.html) ``);
38
38
  }
@@ -67,16 +67,41 @@ const customElement = (tag, config = {}) => (Base) => {
67
67
  disconnectedCallback() {
68
68
  OnDestroy.call(this);
69
69
  disconnectedCallback.call(this);
70
+ registry === null || registry === void 0 ? void 0 : registry.unsubscribe();
71
+ registry = null;
70
72
  }
71
73
  connectedCallback() {
74
+ var _a;
72
75
  connectedCallback.call(this);
73
76
  OnInit.call(this);
74
- }
75
- render() {
76
- var _a;
77
77
  if ((_a = config.modifiers) === null || _a === void 0 ? void 0 : _a.length) {
78
- return (0, exports.pipe)(...(config.modifiers.map(v => v['modifier'])))(config.template.call(this));
78
+ for (const modifier of config.modifiers) {
79
+ if (!modifier) {
80
+ throw new Error(`Provided null value inside modifiers for component "${config.selector}"`);
81
+ }
82
+ if (!modifier.options) {
83
+ throw new Error(`Missing options for attribute inside ${modifier.name}`);
84
+ }
85
+ if (typeof modifier.options !== 'function') {
86
+ throw new Error(`Modifier options is not a function ${modifier.name} and component "${config.selector}"`);
87
+ }
88
+ const options = modifier.options.call(this);
89
+ if (!(options === null || options === void 0 ? void 0 : options.name)) {
90
+ throw new Error(`Missing attribute name for ${modifier.name} inside component "${config.selector}"`);
91
+ }
92
+ if (!registry) {
93
+ registry = (isFunction(config.registry)
94
+ ? config.registry.call(this)
95
+ : options.registry);
96
+ }
97
+ if (!registry) {
98
+ throw new Error(`Missing attribute registry for attribute "${options.name}" and no default registry specified inside component "${config.selector}"`);
99
+ }
100
+ registry.define(options.name, modifier);
101
+ }
79
102
  }
103
+ }
104
+ render() {
80
105
  return config.template.call(this);
81
106
  }
82
107
  update() {
@@ -93,21 +118,21 @@ const customElement = (tag, config = {}) => (Base) => {
93
118
  const registeredElement = window.customElements.get(tag);
94
119
  if (registeredElement) {
95
120
  console.error(`** IMPORTANT!!! **
96
- ------------------------------------------
97
- <${tag}></${tag}> Component re-defined multiple times and it is already registered inside customElements registry
121
+ ------------------------------------------
122
+ < ${tag} > </${tag}> Component re-defined multiple times and it is already registered inside customElements registry
98
123
  Possible Solutions:
99
124
  * Bundle problem where multiple versions of the component are used
100
- * @Component decorator is used twice for the same component
101
- * Defined "selector" with the same name in multiple components
125
+ * @Component decorator is used twice for the same component
126
+ * Defined "selector" with the same name in multiple components
102
127
 
103
- ** If this is Server Side Rendering you can ignore this message **
104
- ------------------------------------------
105
- `);
128
+ ** If this is Server Side Rendering you can ignore this message **
129
+ ------------------------------------------
130
+ `);
106
131
  return registeredElement;
107
132
  }
108
133
  if (typeof ModifiedClass === 'function') {
109
134
  legacyCustomElement(tag, ModifiedClass, {
110
- extends: config.extends,
135
+ extends: config.extends
111
136
  });
112
137
  }
113
138
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdi/lit-html",
3
- "version": "0.7.139",
3
+ "version": "0.7.142",
4
4
  "main": "./dist/index.js",
5
5
  "author": "Kristiyan Tachev",
6
6
  "license": "MIT",