smart-lifecycle 0.2.0 → 0.2.1
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,4 +1,12 @@
|
|
|
1
1
|
import { Services } from "../providers/service-provider.js";
|
|
2
|
+
function getRequiredDecoratorService(token) {
|
|
3
|
+
if (!Services.has(token)) {
|
|
4
|
+
throw new Error(`[SmartRender] Framework services are not available. ` +
|
|
5
|
+
`Call bootstrapFramework(Services) before importing or defining components ` +
|
|
6
|
+
`that use @SmartRender. Missing service: '${token}'.`);
|
|
7
|
+
}
|
|
8
|
+
return Services.get(token);
|
|
9
|
+
}
|
|
2
10
|
/**
|
|
3
11
|
* @SmartRender decorator - Marks a class as a SmartComponent with declarative configuration.
|
|
4
12
|
*
|
|
@@ -28,12 +36,12 @@ export function SmartRender(config) {
|
|
|
28
36
|
selector: config.selector,
|
|
29
37
|
template: config.template || "",
|
|
30
38
|
};
|
|
31
|
-
|
|
39
|
+
getRequiredDecoratorService("IComponentMetadataRegistry").register(config.selector, metadata);
|
|
32
40
|
const options = {
|
|
33
41
|
initializer: config.initializer,
|
|
34
42
|
lifecycle: config.lifecycle,
|
|
35
43
|
};
|
|
36
|
-
|
|
44
|
+
getRequiredDecoratorService("ISmartElementRegistrar").register(config.selector, target, options);
|
|
37
45
|
}
|
|
38
46
|
return target;
|
|
39
47
|
};
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { SmartRender as SmartComponentDecorator } from "./smart-render.decorator.js";
|
|
2
2
|
import { Services } from "../providers/service-provider.js";
|
|
3
|
+
function getRequiredDecoratorService(token) {
|
|
4
|
+
if (!Services.has(token)) {
|
|
5
|
+
throw new Error(`[Smart] Framework services are not available. ` +
|
|
6
|
+
`Call bootstrapFramework(Services) before importing or defining components ` +
|
|
7
|
+
`that use @Smart. Missing service: '${token}'.`);
|
|
8
|
+
}
|
|
9
|
+
return Services.get(token);
|
|
10
|
+
}
|
|
3
11
|
/**
|
|
4
12
|
* Implements the responsibility of providing a functional decorator for SmartComponents.
|
|
5
13
|
*
|
|
@@ -23,7 +31,7 @@ export function Smart(selector, setup) {
|
|
|
23
31
|
if (!setup)
|
|
24
32
|
throw new Error("setup is required");
|
|
25
33
|
const decorator = ((target) => {
|
|
26
|
-
const factory =
|
|
34
|
+
const factory = getRequiredDecoratorService("ISmartComponentFactory");
|
|
27
35
|
const config = factory.captureConfig(setup);
|
|
28
36
|
const EnhancedClass = factory.createEnhancedClass(target, config);
|
|
29
37
|
const InitializerClass = factory.createInitializerClass(config);
|
|
@@ -101,7 +101,7 @@ export class SmartElementFactory {
|
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
103
|
const componentId = this.tagName.toLowerCase();
|
|
104
|
-
const targetRoot = this.attachShadow({ mode: "open" });
|
|
104
|
+
const targetRoot = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
105
105
|
// Inherit the document-level data-theme so that Shadow DOM CSS rules
|
|
106
106
|
// (e.g. Pico CSS :host(:not([data-theme=dark]))) respect the current theme.
|
|
107
107
|
const docTheme = document.documentElement.getAttribute("data-theme");
|