@quandis/qbo4.configuration 4.0.1-CI-20240513-201149 → 4.0.1-CI-20240519-215631

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quandis/qbo4.configuration",
3
- "version": "4.0.1-CI-20240513-201149",
3
+ "version": "4.0.1-CI-20240519-215631",
4
4
  "type": "module",
5
5
  "types": "./src/Program.d.ts",
6
6
  "exports": {
package/src/Program.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from './Services.js';
8
8
  export * from './IConfiguration.js';
9
9
  export * from './Configuration.js';
10
10
  export * from './qbo-config-editor.js';
11
+ export * from './qbo-template.js';
package/src/Program.js CHANGED
@@ -3,4 +3,5 @@ export * from './Services.js';
3
3
  export * from './IConfiguration.js';
4
4
  export * from './Configuration.js';
5
5
  export * from './qbo-config-editor.js';
6
+ export * from './qbo-template.js';
6
7
  //# sourceMappingURL=Program.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Program.js","sourceRoot":"","sources":["Program.ts"],"names":[],"mappings":"AAOA,OAAO,kBAAkB,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"Program.js","sourceRoot":"","sources":["Program.ts"],"names":[],"mappings":"AAOA,OAAO,kBAAkB,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC"}
package/src/Program.ts CHANGED
@@ -10,4 +10,5 @@ export * from './Services.js';
10
10
  export * from './IConfiguration.js';
11
11
  export * from './Configuration.js';
12
12
  export * from './qbo-config-editor.js';
13
+ export * from './qbo-template.js';
13
14
 
@@ -0,0 +1,21 @@
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ export declare class ITemplate {
3
+ type: string;
4
+ map: Map<string, TemplateFunction> | undefined;
5
+ prefix: string;
6
+ templateEndpoint: string;
7
+ }
8
+ type Constructor<T = {}> = new (...args: any[]) => T;
9
+ export type TemplateFunction = (component: any) => TemplateResult;
10
+ export declare const templates: Map<string, Map<string, TemplateFunction>>;
11
+ export declare const QboTemplateMixin: <T extends Constructor<LitElement>>(superClass: T) => Constructor<ITemplate> & T;
12
+ /**
13
+ * Renders a template defined in configuration.
14
+ *
15
+ * @remarks
16
+ * @param apiEndpoint - The API endpoint to fetch data from.
17
+ * @param method - The HTTP method to use when fetching data.
18
+ * @param error - Indicates whether an error occurred while fetching data.
19
+ */
20
+ export declare const QboTemplate: Constructor<ITemplate> & typeof LitElement;
21
+ export {};
@@ -0,0 +1,94 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { LitElement } from 'lit';
11
+ import { property } from 'lit/decorators.js';
12
+ const scriptCache = {};
13
+ export const templates = new Map();
14
+ export const QboTemplateMixin = (superClass) => {
15
+ class QboTemplateClass extends superClass {
16
+ constructor(...args) {
17
+ super(...args);
18
+ this.type = '';
19
+ this.templateEndpoint = '/configuration/templates';
20
+ this.prefix = null;
21
+ this.map = undefined;
22
+ }
23
+ async connectedCallback() {
24
+ super.connectedCallback();
25
+ this.prefix ??= this.constructor.name;
26
+ // Ensure we have a map for this class
27
+ if (!templates.has(this.prefix)) {
28
+ templates.set(this.prefix, new Map());
29
+ }
30
+ ;
31
+ this.map = templates.get(this.prefix);
32
+ if (this.map === undefined)
33
+ console.error(`The prefix ${this.prefix} is not defined in the templates map.`);
34
+ // Don't bother with the API call if we already have the template.
35
+ if (this.map && !this.map.has(this.type)) {
36
+ await this.loadScript(this.prefix);
37
+ }
38
+ }
39
+ async loadScript(prefix) {
40
+ if (!scriptCache[prefix]) {
41
+ scriptCache[prefix] = this.fetchScript(prefix);
42
+ }
43
+ try {
44
+ const scriptText = await scriptCache[prefix];
45
+ this.appendScriptToHead(scriptText);
46
+ console.log(`Template script for ${this.prefix} loaded and executed.`);
47
+ }
48
+ catch (error) {
49
+ console.error(`Template script for ${this.prefix} failed to load:`, error);
50
+ }
51
+ }
52
+ async fetchScript(prefix) {
53
+ const response = await fetch(`${this.templateEndpoint}/${prefix}`);
54
+ if (!response.ok) {
55
+ throw new Error('Network response was not ok');
56
+ }
57
+ return response.text();
58
+ }
59
+ appendScriptToHead(scriptText) {
60
+ const scriptElement = document.createElement('script');
61
+ scriptElement.type = 'text/javascript';
62
+ scriptElement.text = scriptText;
63
+ document.head.appendChild(scriptElement);
64
+ }
65
+ }
66
+ __decorate([
67
+ property(),
68
+ __metadata("design:type", Object)
69
+ ], QboTemplateClass.prototype, "type", void 0);
70
+ __decorate([
71
+ property(),
72
+ __metadata("design:type", Object)
73
+ ], QboTemplateClass.prototype, "templateEndpoint", void 0);
74
+ __decorate([
75
+ property(),
76
+ __metadata("design:type", Object)
77
+ ], QboTemplateClass.prototype, "prefix", void 0);
78
+ __decorate([
79
+ property({ attribute: false }),
80
+ __metadata("design:type", Object)
81
+ ], QboTemplateClass.prototype, "map", void 0);
82
+ ;
83
+ return QboTemplateClass;
84
+ };
85
+ /**
86
+ * Renders a template defined in configuration.
87
+ *
88
+ * @remarks
89
+ * @param apiEndpoint - The API endpoint to fetch data from.
90
+ * @param method - The HTTP method to use when fetching data.
91
+ * @param error - Indicates whether an error occurred while fetching data.
92
+ */
93
+ export const QboTemplate = QboTemplateMixin(LitElement);
94
+ //# sourceMappingURL=qbo-template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qbo-template.js","sourceRoot":"","sources":["qbo-template.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAa7C,MAAM,WAAW,GAAuC,EAAE,CAAC;AAC3D,MAAM,CAAC,MAAM,SAAS,GAA+C,IAAI,GAAG,EAAE,CAAC;AAE/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAoC,UAAa,EAAE,EAAE;IACjF,MAAM,gBAAiB,SAAQ,UAAU;QAarC,YAAY,GAAG,IAAW;YACtB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAZnB,SAAI,GAAG,EAAE,CAAC;YAGV,qBAAgB,GAAG,0BAA0B,CAAC;YAG9C,WAAM,GAAkB,IAAI,CAAC;YAG7B,QAAG,GAA8C,SAAS,CAAC;QAI3D,CAAC;QAED,KAAK,CAAC,iBAAiB;YACnB,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;YACtC,sCAAsC;YACtC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC9B,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;YAC1C,CAAC;YAAA,CAAC;YACF,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACtC,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS;gBACtB,OAAO,CAAC,KAAK,CAAC,cAAc,IAAI,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B,CAAC;YACvC,aAAa,CAAC,IAAI,GAAG,UAAU,CAAC;YAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;QAC7C,CAAC;KACJ;IA1DG;QADC,QAAQ,EAAE;;kDACD;IAGV;QADC,QAAQ,EAAE;;8DACmC;IAG9C;QADC,QAAQ,EAAE;;oDACkB;IAG7B;QADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;;iDAC4B;IAiD9D,CAAC;IAEF,OAAO,gBAAyD,CAAC;AACrE,CAAC,CAAA;AAED;;;;;;;IAOI;AACJ,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,92 @@
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ import { property } from 'lit/decorators.js';
3
+
4
+ // Define the interface for the mixin
5
+ export declare class ITemplate {
6
+ type: string;
7
+ map: Map<string, TemplateFunction> | undefined;
8
+ prefix: string;
9
+ templateEndpoint: string;
10
+ }
11
+
12
+ type Constructor<T = {}> = new (...args: any[]) => T;
13
+ export type TemplateFunction = (component: any) => TemplateResult;
14
+
15
+ const scriptCache: { [key: string]: Promise<string> } = {};
16
+ export const templates: Map<string, Map<string, TemplateFunction>> = new Map();
17
+
18
+ export const QboTemplateMixin = <T extends Constructor<LitElement>>(superClass: T) => {
19
+ class QboTemplateClass extends superClass {
20
+ @property()
21
+ type = '';
22
+
23
+ @property()
24
+ templateEndpoint = '/configuration/templates';
25
+
26
+ @property()
27
+ prefix: string | null = null;
28
+
29
+ @property({ attribute: false })
30
+ map: Map<string, TemplateFunction> | undefined = undefined;
31
+
32
+ constructor(...args: any[]) {
33
+ super(...args);
34
+ }
35
+
36
+ async connectedCallback() {
37
+ super.connectedCallback();
38
+ this.prefix ??= this.constructor.name;
39
+ // Ensure we have a map for this class
40
+ if (!templates.has(this.prefix)) {
41
+ templates.set(this.prefix, new Map());
42
+ };
43
+ this.map = templates.get(this.prefix);
44
+ if (this.map === undefined)
45
+ console.error(`The prefix ${this.prefix} is not defined in the templates map.`);
46
+ // Don't bother with the API call if we already have the template.
47
+ if (this.map && !this.map.has(this.type)) {
48
+ await this.loadScript(this.prefix);
49
+ }
50
+ }
51
+
52
+ async loadScript(prefix: string): Promise<void> {
53
+ if (!scriptCache[prefix]) {
54
+ scriptCache[prefix] = this.fetchScript(prefix);
55
+ }
56
+ try {
57
+ const scriptText = await scriptCache[prefix];
58
+ this.appendScriptToHead(scriptText);
59
+ console.log(`Template script for ${this.prefix} loaded and executed.`);
60
+ } catch (error) {
61
+ console.error(`Template script for ${this.prefix} failed to load:`, error);
62
+ }
63
+ }
64
+
65
+ async fetchScript(prefix: string): Promise<string> {
66
+ const response = await fetch(`${this.templateEndpoint}/${prefix}`);
67
+ if (!response.ok) {
68
+ throw new Error('Network response was not ok');
69
+ }
70
+ return response.text();
71
+ }
72
+
73
+ appendScriptToHead(scriptText: string): void {
74
+ const scriptElement = document.createElement('script');
75
+ scriptElement.type = 'text/javascript';
76
+ scriptElement.text = scriptText;
77
+ document.head.appendChild(scriptElement);
78
+ }
79
+ };
80
+
81
+ return QboTemplateClass as unknown as Constructor<ITemplate> & T;
82
+ }
83
+
84
+ /**
85
+ * Renders a template defined in configuration.
86
+ *
87
+ * @remarks
88
+ * @param apiEndpoint - The API endpoint to fetch data from.
89
+ * @param method - The HTTP method to use when fetching data.
90
+ * @param error - Indicates whether an error occurred while fetching data.
91
+ */
92
+ export const QboTemplate = QboTemplateMixin(LitElement);