@luzmo/embed 6.1.2-beta.4 → 6.1.2-beta.6
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/.prettierignore +4 -0
- package/esbuild.config.cjs +13 -0
- package/eslint.config.cjs +8 -0
- package/jest.config.ts +11 -0
- package/package.json +2 -2
- package/project.json +50 -0
- package/src/index.ts +46 -0
- package/src/lib/dashboard-component/dashboard-base.ts +827 -0
- package/src/lib/dashboard-component/dashboard-component.spec.ts +27 -0
- package/src/lib/dashboard-component/dashboard-component.ts +12 -0
- package/src/lib/dashboard-component/dashboard-styles.ts +117 -0
- package/src/lib/helper/event-bus-handler.ts +184 -0
- package/src/lib/luzmo-iq-components/luzmo-iq-answer.ts +105 -0
- package/src/lib/luzmo-iq-components/luzmo-iq-chat.ts +105 -0
- package/src/lib/luzmo-service.ts +7 -0
- package/src/lib/viz-item/viz-item-component.ts +9 -0
- package/src/lib/viz-item/viz-item.base.ts +231 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +27 -0
- package/tsconfig.lib.json +10 -0
- package/tsconfig.spec.json +9 -0
- package/tsconfig.typings.json +11 -0
- package/index.cjs +0 -56871
- package/index.d.ts +0 -7
- package/index.js +0 -56841
- package/lib/dashboard-component/dashboard-base.d.ts +0 -98
- package/lib/dashboard-component/dashboard-component.d.ts +0 -8
- package/lib/dashboard-component/dashboard-styles.d.ts +0 -1
- package/lib/helper/event-bus-handler.d.ts +0 -1
- package/lib/luzmo-iq-components/luzmo-iq-answer.d.ts +0 -23
- package/lib/luzmo-iq-components/luzmo-iq-chat.d.ts +0 -24
- package/lib/luzmo-service.d.ts +0 -6
- package/lib/viz-item/viz-item-component.d.ts +0 -4
- package/lib/viz-item/viz-item.base.d.ts +0 -72
- package/luzmo-embed.min.js +0 -58939
- package/src/index.d.ts +0 -7
- package/src/lib/dashboard-component/dashboard-base.d.ts +0 -98
- package/src/lib/dashboard-component/dashboard-component.d.ts +0 -8
- package/src/lib/dashboard-component/dashboard-styles.d.ts +0 -1
- package/src/lib/helper/event-bus-handler.d.ts +0 -1
- package/src/lib/luzmo-iq-components/luzmo-iq-answer.d.ts +0 -23
- package/src/lib/luzmo-iq-components/luzmo-iq-chat.d.ts +0 -24
- package/src/lib/luzmo-service.d.ts +0 -6
- package/src/lib/viz-item/viz-item-component.d.ts +0 -4
- package/src/lib/viz-item/viz-item.base.d.ts +0 -72
|
@@ -0,0 +1,231 @@
|
|
|
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 type { VizItemType, VizItemSlots, FilterGroup, VizItemOptions } 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.89';
|
|
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
|
+
|
|
45
|
+
@property() appServer? = 'https://app.luzmo.com';
|
|
46
|
+
@property() apiHost? = 'https://api.luzmo.com';
|
|
47
|
+
@property({type: Array}) slots?: VizItemSlots = [];
|
|
48
|
+
@property({type: Object}) options?: VizItemOptions;
|
|
49
|
+
@property() type?: VizItemType;
|
|
50
|
+
@property() authKey?: string;
|
|
51
|
+
@property() authToken?: string;
|
|
52
|
+
@property() version?: string = pkg.version + '-wc-luzmo';
|
|
53
|
+
@property() contextId?: string;
|
|
54
|
+
@property({
|
|
55
|
+
converter: value => {
|
|
56
|
+
try {
|
|
57
|
+
return JSON.parse(value);
|
|
58
|
+
} catch (exc) {
|
|
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
|
+
constructor() {
|
|
91
|
+
super();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment {
|
|
95
|
+
if (!this.style.display) {
|
|
96
|
+
this.style.display = 'block';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!this.style.height) {
|
|
100
|
+
this.style.height = '100%';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!this.style.width) {
|
|
104
|
+
this.style.width = '100%';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
canInitializeVizItem(): boolean {
|
|
111
|
+
return !!(this.type || (this.dashboardId && this.itemId));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getFilters(): FilterGroup[] {
|
|
115
|
+
return this.chartElement.getFilters();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export(): void {
|
|
119
|
+
return this.chartElement.export();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getData(): any {
|
|
123
|
+
return this.chartElement.getData();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
refreshData(): void {
|
|
127
|
+
return this.chartElement.refreshData();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
setSelectedData(selectedDataInput: SharedLib.SelectedDataInput): SharedLib.SetSelectedData {
|
|
131
|
+
return this.chartElement.setSelectedData(undefined, selectedDataInput);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
setAuthorization(key: string, token: string): void {
|
|
135
|
+
return this.chartElement.setAuthorization(key, token);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
attributeChangedCallback(name: string, _old: string | null, value: string | null): void {
|
|
139
|
+
super.attributeChangedCallback(name, _old, value);
|
|
140
|
+
|
|
141
|
+
if (name === 'selecteddata') {
|
|
142
|
+
if (this.chartElement) {
|
|
143
|
+
this.setSelectedData(JSON.parse(value ?? '{}'));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this.postInitCallQueue.push([this.setSelectedData, [JSON.parse(value ?? '{}')]]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
protected async firstUpdated(_changedProperties: PropertyValues): Promise<void> {
|
|
152
|
+
super.firstUpdated(_changedProperties);
|
|
153
|
+
if (this.canInitializeVizItem()) {
|
|
154
|
+
await SharedLib.loadLibrary(this.appServer, 'DashboardApp');
|
|
155
|
+
// if type is available early, create and append element
|
|
156
|
+
this.createAndAppendElement();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private createAndAppendElement(): void {
|
|
161
|
+
if (!this.chartElement) {
|
|
162
|
+
this.chartElement = document.createElement('chart-component');
|
|
163
|
+
this.chartElement.setAttribute('embedding-mode', 'chart');
|
|
164
|
+
this.chartElement.style.height = '100%';
|
|
165
|
+
this.chartElement.style.width = '100%';
|
|
166
|
+
this.chartElement.style.display = 'block';
|
|
167
|
+
|
|
168
|
+
this.chartElement.addEventListener('load', payload => this.dispatchEvent(new CustomEvent('load', payload)));
|
|
169
|
+
this.chartElement.addEventListener('rendered', payload => {
|
|
170
|
+
if (this.postInitCallQueue?.length > 0) {
|
|
171
|
+
for (const functionToCall of this.postInitCallQueue) {
|
|
172
|
+
functionToCall[0].bind(this)(...functionToCall[1]);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
if (this.selectedData) {
|
|
177
|
+
this.setSelectedData(this.selectedData);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.dispatchEvent(new CustomEvent('rendered', payload));
|
|
182
|
+
});
|
|
183
|
+
this.chartElement.addEventListener('changedFilters', payload => this.dispatchEvent(new CustomEvent('changedFilters', payload)));
|
|
184
|
+
this.chartElement.addEventListener('exported', payload => this.dispatchEvent(new CustomEvent('exported', payload)));
|
|
185
|
+
this.chartElement.addEventListener('customEvent', payload => this.dispatchEvent(new CustomEvent('customEvent', payload)));
|
|
186
|
+
this.updateVizItemProperties();
|
|
187
|
+
|
|
188
|
+
this.renderRoot.append(this.chartElement);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private updateVizItemProperties(): void {
|
|
193
|
+
if (this.chartElement) {
|
|
194
|
+
// eslint-disable-next-line guard-for-in
|
|
195
|
+
for (const key in SharedLib.libraryTypeToWebComponentTypeMapping) {
|
|
196
|
+
const value = this[key];
|
|
197
|
+
if (value) {
|
|
198
|
+
const attributeValue = ['appServer', 'apiHost'].includes(key) ? SharedLib.removeTrailingSlash(value) : value;
|
|
199
|
+
this.chartElement.setAttribute(
|
|
200
|
+
SharedLib.libraryTypeToWebComponentTypeMapping[key],
|
|
201
|
+
typeof attributeValue === 'object' ? JSON.stringify(attributeValue) : attributeValue
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async updated(changedProperties: PropertyValues): Promise<void> {
|
|
209
|
+
if (this.chartElement) {
|
|
210
|
+
for (const [propertyName] of changedProperties.entries()) {
|
|
211
|
+
const mappedAttributeName = SharedLib.libraryTypeToWebComponentTypeMapping[propertyName as string] ?? (propertyName as string);
|
|
212
|
+
const attributeValue = typeof this[propertyName] === 'object' ? JSON.stringify(this[propertyName]) : (this[propertyName]?.toString() ?? this[propertyName]);
|
|
213
|
+
|
|
214
|
+
this.chartElement.setAttribute(mappedAttributeName, attributeValue);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
// make sure type or itemId and dashboardId are available before creating the element
|
|
219
|
+
if (this.canInitializeVizItem()) {
|
|
220
|
+
await SharedLib.loadLibrary(this.appServer, 'DashboardApp');
|
|
221
|
+
// When type is available, create and append element
|
|
222
|
+
this.createAndAppendElement();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
protected render(): unknown {
|
|
229
|
+
return html` `;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
@@ -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,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../../dist/out-tsc",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"types": ["node"],
|
|
7
|
+
"emitDeclarationOnly": true
|
|
8
|
+
},
|
|
9
|
+
"include": ["src/**/*.ts"],
|
|
10
|
+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
|
|
11
|
+
}
|