@rxdi/lit-html 0.7.140 → 0.7.141

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