@luzmo/embed 6.2.1 → 6.2.2

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.
Files changed (47) hide show
  1. package/.prettierignore +4 -0
  2. package/esbuild.config.cjs +13 -0
  3. package/eslint.config.cjs +8 -0
  4. package/jest.config.ts +11 -0
  5. package/package.json +4 -2
  6. package/project.json +39 -0
  7. package/src/index.ts +42 -0
  8. package/src/lib/dashboard-component/dashboard-base.ts +828 -0
  9. package/src/lib/dashboard-component/dashboard-component.spec.ts +27 -0
  10. package/src/lib/dashboard-component/dashboard-component.ts +12 -0
  11. package/src/lib/dashboard-component/dashboard-styles.ts +117 -0
  12. package/src/lib/helper/event-bus-handler.ts +195 -0
  13. package/src/lib/helper/json-schema-utils.ts +129 -0
  14. package/src/lib/luzmo-iq-components/luzmo-iq-answer.ts +106 -0
  15. package/src/lib/luzmo-iq-components/luzmo-iq-chat.ts +106 -0
  16. package/src/lib/luzmo-service.ts +7 -0
  17. package/src/lib/viz-item/viz-item-component.ts +9 -0
  18. package/src/lib/viz-item/viz-item.base.ts +227 -0
  19. package/src/vite-env.d.ts +1 -0
  20. package/tsconfig.json +27 -0
  21. package/tsconfig.lib.json +10 -0
  22. package/tsconfig.spec.json +9 -0
  23. package/index.cjs +0 -1579
  24. package/index.d.ts +0 -8
  25. package/index.js +0 -1548
  26. package/lib/dashboard-component/dashboard-base.d.ts +0 -98
  27. package/lib/dashboard-component/dashboard-component.d.ts +0 -8
  28. package/lib/dashboard-component/dashboard-styles.d.ts +0 -1
  29. package/lib/helper/event-bus-handler.d.ts +0 -1
  30. package/lib/helper/json-schema-utils.d.ts +0 -64
  31. package/lib/luzmo-iq-components/luzmo-iq-answer.d.ts +0 -22
  32. package/lib/luzmo-iq-components/luzmo-iq-chat.d.ts +0 -23
  33. package/lib/luzmo-service.d.ts +0 -6
  34. package/lib/viz-item/viz-item-component.d.ts +0 -4
  35. package/lib/viz-item/viz-item.base.d.ts +0 -71
  36. package/luzmo-embed.min.js +0 -3630
  37. package/src/index.d.ts +0 -8
  38. package/src/lib/dashboard-component/dashboard-base.d.ts +0 -98
  39. package/src/lib/dashboard-component/dashboard-component.d.ts +0 -8
  40. package/src/lib/dashboard-component/dashboard-styles.d.ts +0 -1
  41. package/src/lib/helper/event-bus-handler.d.ts +0 -1
  42. package/src/lib/helper/json-schema-utils.d.ts +0 -64
  43. package/src/lib/luzmo-iq-components/luzmo-iq-answer.d.ts +0 -22
  44. package/src/lib/luzmo-iq-components/luzmo-iq-chat.d.ts +0 -23
  45. package/src/lib/luzmo-service.d.ts +0 -6
  46. package/src/lib/viz-item/viz-item-component.d.ts +0 -4
  47. package/src/lib/viz-item/viz-item.base.d.ts +0 -71
@@ -0,0 +1,9 @@
1
+ import { LuzmoBaseVizItem } from './viz-item.base';
2
+
3
+ export type { LuzmoVizItemComponentInterface } from './viz-item.base';
4
+
5
+ export class LuzmoEmbedVizItem extends LuzmoBaseVizItem {}
6
+
7
+ if (!customElements.get('luzmo-embed-viz-item')) {
8
+ customElements.define('luzmo-embed-viz-item', LuzmoEmbedVizItem);
9
+ }
@@ -0,0 +1,227 @@
1
+ import { property } from 'lit/decorators.js';
2
+ import { LitElement, html, PropertyValues, css } from 'lit';
3
+ import * as SharedLib from '@luzmo/shared-embed';
4
+ import { VizItemType, FilterGroup, VizItemOptions, VizItemSlots } from '@luzmo/dashboard-contents-types';
5
+ import * as pkg from '../../../package.json';
6
+
7
+ /**
8
+ * The version of the dashboard contents that is linked to the current library.
9
+ *
10
+ * If custom options/slots/etc. are passed to the component, the library assumes that
11
+ * they are using this dashboard contents version. Then custom options/slots/etc.
12
+ * together with this dashboard contents version are passed to the dashboard app (https://app.luzmo.com/dashboard-app/remoteEntry.mjs)
13
+ * and if needed the migration will be applied on the dashboard app level.
14
+ */
15
+ export const dashboardContentsVersion = '0.1.91';
16
+
17
+ type FunctionCall = [(...args: any) => any, any[]];
18
+
19
+ interface LuzmoVizItemComponentInterface extends HTMLElement {
20
+ options?: VizItemOptions;
21
+ type?: VizItemType;
22
+ appServer?: string;
23
+ apiHost?: string;
24
+ slots?: VizItemSlots;
25
+ canFilter?: string[] | 'all';
26
+ filters?: FilterGroup[];
27
+ contextId?: string;
28
+ authKey?: string;
29
+ authToken?: string;
30
+ dashboardId?: string;
31
+ itemId?: string;
32
+ getFilters: () => FilterGroup[];
33
+ export: () => void;
34
+ refreshData: () => void;
35
+ getData: () => SharedLib.ItemData;
36
+ setSelectedData: (selectedDataInput: SharedLib.SelectedDataInput) => SharedLib.SetSelectedData;
37
+ setAuthorization: (key: string, token: string) => void;
38
+ }
39
+
40
+ export type { LuzmoVizItemComponentInterface };
41
+
42
+ export class LuzmoBaseVizItem
43
+ extends LitElement implements LuzmoVizItemComponentInterface {
44
+ @property() appServer? = 'https://app.luzmo.com';
45
+ @property() apiHost? = 'https://api.luzmo.com';
46
+ @property({ type: Array }) slots?: VizItemSlots = [];
47
+ @property({ type: Object }) options?: VizItemOptions;
48
+ @property() type?: VizItemType;
49
+ @property() authKey?: string;
50
+ @property() authToken?: string;
51
+ @property() version?: string = pkg.version + '-wc-luzmo';
52
+ @property() contextId?: string;
53
+ @property({
54
+ converter: value => {
55
+ try {
56
+ return JSON.parse(value);
57
+ }
58
+ catch {
59
+ return value;
60
+ }
61
+ }
62
+ }) canFilter?: SharedLib.CanFilter;
63
+ @property({ type: Array }) filters?: FilterGroup[];
64
+ @property() dashboardId?: string;
65
+ @property() itemId?: string;
66
+ @property({ type: Object }) selectedData: SharedLib.SelectedDataInput;
67
+ @property() dashboardContentsVersion?: string = dashboardContentsVersion;
68
+ @property() libVersion?: string = pkg.version + '-wc-luzmo';
69
+
70
+ chartElement: HTMLElement & Partial<LuzmoVizItemComponentInterface> & {
71
+ setSelectedData?: (itemId?: string, filters?: SharedLib.SelectedDataInput) => SharedLib.SetSelectedData;
72
+ };
73
+
74
+ postInitCallQueue: FunctionCall[] = [];
75
+
76
+ // Static styles to set host display to block, else it is not shown at all for some reason.
77
+ static styles = css`
78
+ :host {
79
+ display: block;
80
+ width: 100%;
81
+ height: 100%;
82
+ }
83
+
84
+ luzmo-embed-viz-item {
85
+ width: 100%;
86
+ height: 1000%;
87
+ display: block;
88
+ }
89
+ `;
90
+
91
+ protected createRenderRoot(): HTMLElement | DocumentFragment {
92
+ if (!this.style.display) {
93
+ this.style.display = 'block';
94
+ }
95
+
96
+ if (!this.style.height) {
97
+ this.style.height = '100%';
98
+ }
99
+
100
+ if (!this.style.width) {
101
+ this.style.width = '100%';
102
+ }
103
+
104
+ return this;
105
+ }
106
+
107
+ canInitializeVizItem(): boolean {
108
+ return !!(this.type || (this.dashboardId && this.itemId));
109
+ }
110
+
111
+ getFilters(): FilterGroup[] {
112
+ return this.chartElement.getFilters();
113
+ }
114
+
115
+ export(): void {
116
+ return this.chartElement.export();
117
+ }
118
+
119
+ getData(): any {
120
+ return this.chartElement.getData();
121
+ }
122
+
123
+ refreshData(): void {
124
+ return this.chartElement.refreshData();
125
+ }
126
+
127
+ setSelectedData(selectedDataInput: SharedLib.SelectedDataInput): SharedLib.SetSelectedData {
128
+ return this.chartElement.setSelectedData(undefined, selectedDataInput);
129
+ }
130
+
131
+ setAuthorization(key: string, token: string): void {
132
+ return this.chartElement.setAuthorization(key, token);
133
+ }
134
+
135
+ attributeChangedCallback(name: string, _old: string | null, value: string | null): void {
136
+ super.attributeChangedCallback(name, _old, value);
137
+
138
+ if (name === 'selecteddata') {
139
+ if (this.chartElement) {
140
+ this.setSelectedData(JSON.parse(value ?? '{}'));
141
+ }
142
+ else {
143
+ this.postInitCallQueue.push([this.setSelectedData, [JSON.parse(value ?? '{}')]]);
144
+ }
145
+ }
146
+ }
147
+
148
+ protected async firstUpdated(_changedProperties: PropertyValues): Promise<void> {
149
+ super.firstUpdated(_changedProperties);
150
+ if (this.canInitializeVizItem()) {
151
+ await SharedLib.loadLibrary(this.appServer, 'DashboardApp');
152
+ // if type is available early, create and append element
153
+ this.createAndAppendElement();
154
+ }
155
+ }
156
+
157
+ private createAndAppendElement(): void {
158
+ if (!this.chartElement) {
159
+ this.chartElement = document.createElement('chart-component');
160
+ this.chartElement.setAttribute('embedding-mode', 'chart');
161
+ this.chartElement.style.height = '100%';
162
+ this.chartElement.style.width = '100%';
163
+ this.chartElement.style.display = 'block';
164
+
165
+ this.chartElement.addEventListener('load', payload => this.dispatchEvent(new CustomEvent('load', payload)));
166
+ this.chartElement.addEventListener('rendered', payload => {
167
+ if (this.postInitCallQueue?.length > 0) {
168
+ for (const functionToCall of this.postInitCallQueue) {
169
+ functionToCall[0].bind(this)(...functionToCall[1]);
170
+ }
171
+ }
172
+ else {
173
+ if (this.selectedData) {
174
+ this.setSelectedData(this.selectedData);
175
+ }
176
+ }
177
+
178
+ this.dispatchEvent(new CustomEvent('rendered', payload));
179
+ });
180
+ this.chartElement.addEventListener('changedFilters', payload => this.dispatchEvent(new CustomEvent('changedFilters', payload)));
181
+ this.chartElement.addEventListener('exported', payload => this.dispatchEvent(new CustomEvent('exported', payload)));
182
+ this.chartElement.addEventListener('customEvent', payload => this.dispatchEvent(new CustomEvent('customEvent', payload)));
183
+ this.updateVizItemProperties();
184
+
185
+ this.renderRoot.append(this.chartElement);
186
+ }
187
+ }
188
+
189
+ private updateVizItemProperties(): void {
190
+ if (this.chartElement) {
191
+ // eslint-disable-next-line guard-for-in
192
+ for (const key in SharedLib.libraryTypeToWebComponentTypeMapping) {
193
+ const value = this[key];
194
+ if (value) {
195
+ const attributeValue = ['appServer', 'apiHost'].includes(key) ? SharedLib.removeTrailingSlash(value) : value;
196
+ this.chartElement.setAttribute(
197
+ SharedLib.libraryTypeToWebComponentTypeMapping[key],
198
+ typeof attributeValue === 'object' ? JSON.stringify(attributeValue) : attributeValue
199
+ );
200
+ }
201
+ }
202
+ }
203
+ }
204
+
205
+ async updated(changedProperties: PropertyValues): Promise<void> {
206
+ if (this.chartElement) {
207
+ for (const [propertyName] of changedProperties.entries()) {
208
+ const mappedAttributeName = SharedLib.libraryTypeToWebComponentTypeMapping[propertyName as string] ?? (propertyName as string);
209
+ const attributeValue = typeof this[propertyName] === 'object' ? JSON.stringify(this[propertyName]) : (this[propertyName]?.toString() ?? this[propertyName]);
210
+
211
+ this.chartElement.setAttribute(mappedAttributeName, attributeValue);
212
+ }
213
+ }
214
+ else {
215
+ // make sure type or itemId and dashboardId are available before creating the element
216
+ if (this.canInitializeVizItem()) {
217
+ await SharedLib.loadLibrary(this.appServer, 'DashboardApp');
218
+ // When type is available, create and append element
219
+ this.createAndAppendElement();
220
+ }
221
+ }
222
+ }
223
+
224
+ protected render(): unknown {
225
+ return html` `;
226
+ }
227
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "extends": "../../../tsconfig.base-lib.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "forceConsistentCasingInFileNames": true,
6
+ "strict": false,
7
+ "noImplicitOverride": false,
8
+ "noPropertyAccessFromIndexSignature": true,
9
+ "noImplicitReturns": true,
10
+ "noFallthroughCasesInSwitch": true,
11
+ "declaration": true,
12
+ "paths": {
13
+ "@luzmo/dashboard-contents-types": ["libs/dashboard-contents-types/index.ts"],
14
+ "@luzmo/shared-embed": ["libs/embed-libs/shared-embed/src/index.ts"]
15
+ }
16
+ },
17
+ "files": [],
18
+ "include": [],
19
+ "references": [
20
+ {
21
+ "path": "./tsconfig.lib.json"
22
+ },
23
+ {
24
+ "path": "./tsconfig.spec.json"
25
+ }
26
+ ]
27
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../../dist/out-tsc",
5
+ "declaration": true,
6
+ "types": ["node"]
7
+ },
8
+ "include": ["src/**/*.ts"],
9
+ "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
10
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },
8
+ "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
9
+ }