@rxdi/lit-html 0.7.141 → 0.7.144
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.
|
@@ -3,13 +3,13 @@ import { CSSResult } from '../reactive-element/css-tag';
|
|
|
3
3
|
export interface CustomAttributeRegistry {
|
|
4
4
|
define(name: string, modifier: Function | Modifier): void;
|
|
5
5
|
get(element: HTMLElement, attrName: string): any;
|
|
6
|
+
unsubscribe(): void;
|
|
6
7
|
}
|
|
7
8
|
export interface ModifierOptions {
|
|
8
|
-
|
|
9
|
+
selector: string;
|
|
9
10
|
registry?: CustomAttributeRegistry;
|
|
10
11
|
}
|
|
11
12
|
export interface Modifier extends Function {
|
|
12
|
-
name: string;
|
|
13
13
|
options(): ModifierOptions;
|
|
14
14
|
}
|
|
15
15
|
export interface CustomElementConfig<T> {
|
|
@@ -32,6 +32,7 @@ const customElement = (tag, config = {}) => (Base) => {
|
|
|
32
32
|
const disconnectedCallback = Base.prototype.disconnectedCallback || function () { };
|
|
33
33
|
const update = Base.prototype.update || function () { };
|
|
34
34
|
const firstUpdated = Base.prototype.firstUpdated || function () { };
|
|
35
|
+
let registry;
|
|
35
36
|
if (!config.template) {
|
|
36
37
|
config.template = Base.prototype.render || (() => (0, lit_html_1.html) ``);
|
|
37
38
|
}
|
|
@@ -66,13 +67,16 @@ const customElement = (tag, config = {}) => (Base) => {
|
|
|
66
67
|
disconnectedCallback() {
|
|
67
68
|
OnDestroy.call(this);
|
|
68
69
|
disconnectedCallback.call(this);
|
|
70
|
+
registry === null || registry === void 0 ? void 0 : registry.unsubscribe();
|
|
71
|
+
registry = null;
|
|
69
72
|
}
|
|
70
73
|
connectedCallback() {
|
|
74
|
+
var _a;
|
|
71
75
|
connectedCallback.call(this);
|
|
72
76
|
OnInit.call(this);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
if (isFunction(config.registry)) {
|
|
78
|
+
registry = config.registry.call(this);
|
|
79
|
+
}
|
|
76
80
|
if ((_a = config.modifiers) === null || _a === void 0 ? void 0 : _a.length) {
|
|
77
81
|
for (const modifier of config.modifiers) {
|
|
78
82
|
if (!modifier) {
|
|
@@ -85,18 +89,20 @@ const customElement = (tag, config = {}) => (Base) => {
|
|
|
85
89
|
throw new Error(`Modifier options is not a function ${modifier.name} and component "${config.selector}"`);
|
|
86
90
|
}
|
|
87
91
|
const options = modifier.options.call(this);
|
|
88
|
-
if (!(options === null || options === void 0 ? void 0 : options.
|
|
92
|
+
if (!(options === null || options === void 0 ? void 0 : options.selector)) {
|
|
89
93
|
throw new Error(`Missing attribute name for ${modifier.name} inside component "${config.selector}"`);
|
|
90
94
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
if (!options.registry) {
|
|
96
|
+
registry = options.registry;
|
|
97
|
+
}
|
|
94
98
|
if (!registry) {
|
|
95
|
-
throw new Error(`Missing attribute registry for attribute "${options.
|
|
99
|
+
throw new Error(`Missing attribute registry for attribute "${options.selector}" and no default registry specified inside component "${config.selector}"`);
|
|
96
100
|
}
|
|
97
|
-
registry.define(options.
|
|
101
|
+
registry.define(options.selector, modifier);
|
|
98
102
|
}
|
|
99
103
|
}
|
|
104
|
+
}
|
|
105
|
+
render() {
|
|
100
106
|
return config.template.call(this);
|
|
101
107
|
}
|
|
102
108
|
update() {
|