@luzmo/embed 6.1.2-beta.5 → 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 -23
- 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 -23
- 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,27 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
describe('dashboard-component', () => {
|
|
3
|
+
const DASHBOARD_COMPONENT_TAG = 'dashboard-component';
|
|
4
|
+
|
|
5
|
+
const getShadowRoot = (tagName: string): ShadowRoot => document.body.getElementsByTagName(tagName)[0].shadowRoot;
|
|
6
|
+
|
|
7
|
+
it('dashboard-component tag', async () => {
|
|
8
|
+
const dashboardElement: LitElement = window.document.createElement(
|
|
9
|
+
DASHBOARD_COMPONENT_TAG
|
|
10
|
+
) as LitElement;
|
|
11
|
+
|
|
12
|
+
console.log(dashboardElement);
|
|
13
|
+
window.document.body.append(dashboardElement);
|
|
14
|
+
console.log(dashboardElement.updateComplete);
|
|
15
|
+
await dashboardElement.updateComplete;
|
|
16
|
+
console.log(
|
|
17
|
+
window.document.body.getElementsByTagName(DASHBOARD_COMPONENT_TAG)[0]
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const renderedText = window.document.body.getElementsByTagName(
|
|
21
|
+
DASHBOARD_COMPONENT_TAG
|
|
22
|
+
)[0].textContent;
|
|
23
|
+
|
|
24
|
+
console.log(getShadowRoot(DASHBOARD_COMPONENT_TAG));
|
|
25
|
+
expect(1).toBe(1);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LuzmoDashboard } from './dashboard-base';
|
|
2
|
+
|
|
3
|
+
/**!
|
|
4
|
+
* @element luzmo-embed-dashboard
|
|
5
|
+
* @description Exposed by @luzmo/embed lib to everyone.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export class LuzmoEmbedDashboard extends LuzmoDashboard {}
|
|
9
|
+
|
|
10
|
+
if (!customElements.get('luzmo-embed-dashboard')) {
|
|
11
|
+
customElements.define('luzmo-embed-dashboard', LuzmoEmbedDashboard);
|
|
12
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
|
|
3
|
+
// Styles for dashboard and loader
|
|
4
|
+
export const dashboardStyles = css`
|
|
5
|
+
:host {
|
|
6
|
+
display: block;
|
|
7
|
+
height: 100%;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@-webkit-keyframes spin {
|
|
11
|
+
0% {
|
|
12
|
+
-webkit-transform: rotate(0deg);
|
|
13
|
+
transform: rotate(0deg);
|
|
14
|
+
}
|
|
15
|
+
100% {
|
|
16
|
+
-webkit-transform: rotate(360deg);
|
|
17
|
+
transform: rotate(360deg);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@keyframes spin {
|
|
22
|
+
0% {
|
|
23
|
+
-webkit-transform: rotate(0deg);
|
|
24
|
+
transform: rotate(0deg);
|
|
25
|
+
}
|
|
26
|
+
100% {
|
|
27
|
+
-webkit-transform: rotate(360deg);
|
|
28
|
+
transform: rotate(360deg);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
:host {
|
|
32
|
+
position: relative;
|
|
33
|
+
width: 100%;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.luzmo-embed-dashboard {
|
|
37
|
+
background: transparent;
|
|
38
|
+
padding: 0;
|
|
39
|
+
border: 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.luzmo-embed-dashboard-ede {
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.luzmo-embed-container-ede {
|
|
46
|
+
width: 100%;
|
|
47
|
+
height: 100%;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.luzmo-container-loader {
|
|
51
|
+
width: 100%;
|
|
52
|
+
position: relative;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.luzmo-lc {
|
|
56
|
+
margin: 0 auto;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.luzmo-loading-message {
|
|
60
|
+
width: 100%;
|
|
61
|
+
height: 20px;
|
|
62
|
+
text-align: center;
|
|
63
|
+
margin-bottom: 16px;
|
|
64
|
+
font-family: Helvetica, Arial, sans-serif;
|
|
65
|
+
font-size: 14px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.luzmo-loading-circle {
|
|
69
|
+
box-sizing: border-box;
|
|
70
|
+
margin: 16px auto;
|
|
71
|
+
position: relative;
|
|
72
|
+
text-indent: -9999em;
|
|
73
|
+
animation: spin 0.6s infinite linear;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.luzmo-loading-circle,
|
|
77
|
+
.luzmo-loading-circle:after {
|
|
78
|
+
border-radius: 50%;
|
|
79
|
+
width: 32px;
|
|
80
|
+
height: 32px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.itemEmbedding:after {
|
|
84
|
+
width: 24px;
|
|
85
|
+
height: 24px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.luzmo-error {
|
|
89
|
+
background: transparent;
|
|
90
|
+
padding: 48px 0;
|
|
91
|
+
margin: 0 auto;
|
|
92
|
+
width: 80%;
|
|
93
|
+
border: 0;
|
|
94
|
+
text-align: center;
|
|
95
|
+
min-height: 192px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.dashboard-error {
|
|
99
|
+
font-size: 30px;
|
|
100
|
+
background: transparent;
|
|
101
|
+
padding: 48px 0;
|
|
102
|
+
margin: 0 auto;
|
|
103
|
+
width: 80%;
|
|
104
|
+
border: 0;
|
|
105
|
+
text-align: center;
|
|
106
|
+
min-height: 192px;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.luzmo-loader {
|
|
110
|
+
top: 0;
|
|
111
|
+
left: 0;
|
|
112
|
+
width: 100%;
|
|
113
|
+
min-height: 400px;
|
|
114
|
+
position: absolute;
|
|
115
|
+
transition-duration: 0.3s;
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import * as SharedLib from '@luzmo/shared-embed';
|
|
2
|
+
import LuzmoService from '../luzmo-service';
|
|
3
|
+
|
|
4
|
+
interface AppWindow extends Window {
|
|
5
|
+
__luzmoMessageHandler(event: MessageEvent): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare const window: AppWindow;
|
|
9
|
+
|
|
10
|
+
// create the Luzmo event listener
|
|
11
|
+
export const _setEventHandler = (): void => {
|
|
12
|
+
if (typeof window.__luzmoMessageHandler === 'function') {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
window.__luzmoMessageHandler = (event: MessageEvent) => {
|
|
17
|
+
const dashboardComponent = LuzmoService._components.find(
|
|
18
|
+
(c) => event.data.name === c._iframeId
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (!dashboardComponent) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
switch (event.data?.type) {
|
|
26
|
+
case 'load': {
|
|
27
|
+
dashboardComponent.dispatchEvent(
|
|
28
|
+
new CustomEvent('load', { detail: { data: event.data } })
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (dashboardComponent._loadTimeoutHandle) {
|
|
32
|
+
clearTimeout(dashboardComponent._loadTimeoutHandle);
|
|
33
|
+
dashboardComponent._loadTimeoutHandle = undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
dashboardComponent.iframeLoaded = true;
|
|
37
|
+
dashboardComponent.dimensions = event.data.dimensions;
|
|
38
|
+
dashboardComponent._calculateDimAfterDashboardLoaded();
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case 'error': {
|
|
42
|
+
dashboardComponent.dashboardError = true;
|
|
43
|
+
|
|
44
|
+
if (dashboardComponent._loadTimeoutHandle) {
|
|
45
|
+
clearTimeout(dashboardComponent._loadTimeoutHandle);
|
|
46
|
+
dashboardComponent._loadTimeoutHandle = undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
dashboardComponent.iframeLoaded = true;
|
|
50
|
+
dashboardComponent._displayError();
|
|
51
|
+
console.error('Dashboard error: ', event.data.errorMsg ?? event.data.error?.msg);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'data': {
|
|
55
|
+
SharedLib.resolvePromise(
|
|
56
|
+
dashboardComponent,
|
|
57
|
+
event.data.requestId,
|
|
58
|
+
event.data.data
|
|
59
|
+
);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case 'filters': {
|
|
63
|
+
SharedLib.resolvePromise(
|
|
64
|
+
dashboardComponent,
|
|
65
|
+
event.data.requestId,
|
|
66
|
+
event.data.filters
|
|
67
|
+
);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case 'getAccessibleDashboards': {
|
|
71
|
+
SharedLib.resolvePromise(
|
|
72
|
+
dashboardComponent,
|
|
73
|
+
event.data.requestId,
|
|
74
|
+
event.data.accessibleDashboards
|
|
75
|
+
);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case 'dashboardAction': {
|
|
79
|
+
dashboardComponent.dispatchEvent(
|
|
80
|
+
new CustomEvent('dashboardAction', { detail: { data: event.data } })
|
|
81
|
+
);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case 'export': {
|
|
85
|
+
if (event.data.error) {
|
|
86
|
+
SharedLib.rejectPromise(
|
|
87
|
+
dashboardComponent,
|
|
88
|
+
event.data.requestId,
|
|
89
|
+
event.data
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
dashboardComponent.dispatchEvent(
|
|
94
|
+
new CustomEvent('exported', { detail: { data: event.data } })
|
|
95
|
+
);
|
|
96
|
+
SharedLib.resolvePromise(
|
|
97
|
+
dashboardComponent,
|
|
98
|
+
event.data.requestId,
|
|
99
|
+
event.data
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case 'changedFilters': {
|
|
106
|
+
dashboardComponent.dispatchEvent(
|
|
107
|
+
new CustomEvent('changedFilters', { detail: { data: event.data } })
|
|
108
|
+
);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case 'customEvent': {
|
|
112
|
+
dashboardComponent.dispatchEvent(
|
|
113
|
+
new CustomEvent('customEvent', { detail: { data: event.data } })
|
|
114
|
+
);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'chartsRendered': // TODO remove once chartsRendered is changed to itemsRendered in FE app
|
|
118
|
+
case 'itemsRendered': {
|
|
119
|
+
event.data.type = 'itemsRendered';
|
|
120
|
+
dashboardComponent.dispatchEvent(
|
|
121
|
+
new CustomEvent('itemsRendered', { detail: { data: event.data } })
|
|
122
|
+
);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case 'setEditMode': {
|
|
126
|
+
if (event.data.error) {
|
|
127
|
+
SharedLib.rejectPromise(
|
|
128
|
+
dashboardComponent,
|
|
129
|
+
event.data.requestId,
|
|
130
|
+
event.data
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
SharedLib.resolvePromise(
|
|
135
|
+
dashboardComponent,
|
|
136
|
+
event.data.requestId,
|
|
137
|
+
event.data
|
|
138
|
+
);
|
|
139
|
+
dashboardComponent.params.editMode = event.data.editMode;
|
|
140
|
+
// Update iframe + container dimensions.
|
|
141
|
+
dashboardComponent._containerStyle
|
|
142
|
+
= SharedLib.containerStyles(dashboardComponent);
|
|
143
|
+
|
|
144
|
+
if (dashboardComponent.dimensions) {
|
|
145
|
+
SharedLib._setCalculatedDimensions(dashboardComponent);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
case 'setSelectedData':
|
|
152
|
+
case 'setFilters': {
|
|
153
|
+
event.data.error
|
|
154
|
+
? SharedLib.rejectPromise(
|
|
155
|
+
dashboardComponent,
|
|
156
|
+
event.data.requestId,
|
|
157
|
+
event.data
|
|
158
|
+
)
|
|
159
|
+
: SharedLib.resolvePromise(
|
|
160
|
+
dashboardComponent,
|
|
161
|
+
event.data.requestId,
|
|
162
|
+
event.data
|
|
163
|
+
);
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case 'setPreview': {
|
|
167
|
+
event.data.error
|
|
168
|
+
? SharedLib.rejectPromise(
|
|
169
|
+
dashboardComponent,
|
|
170
|
+
event.data.requestId,
|
|
171
|
+
event.data
|
|
172
|
+
)
|
|
173
|
+
: SharedLib.resolvePromise(
|
|
174
|
+
dashboardComponent,
|
|
175
|
+
event.data.requestId,
|
|
176
|
+
event.data
|
|
177
|
+
);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
window.addEventListener('message', window.__luzmoMessageHandler, false);
|
|
184
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
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 * as pkg from '../../../package.json';
|
|
5
|
+
|
|
6
|
+
const inputMap = {
|
|
7
|
+
aiEndPoint: 'ai-end-point',
|
|
8
|
+
appServer: 'app-server',
|
|
9
|
+
apiHost: 'api-host',
|
|
10
|
+
options: 'options',
|
|
11
|
+
authKey: 'auth-key',
|
|
12
|
+
authToken: 'auth-token',
|
|
13
|
+
version: 'version',
|
|
14
|
+
libVersion: 'lib-version',
|
|
15
|
+
messages: 'messages'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class LuzmoIQEmbedAnswerComponent
|
|
19
|
+
extends LitElement {
|
|
20
|
+
@property() appServer? = 'https://app.luzmo.com';
|
|
21
|
+
@property() apiHost? = 'https://api.luzmo.com';
|
|
22
|
+
@property({ type: Object }) options?: SharedLib.IQAnswerOptions;
|
|
23
|
+
@property() aiEndPoint?: string;
|
|
24
|
+
@property() authKey?: string;
|
|
25
|
+
@property() authToken?: string;
|
|
26
|
+
@property() messages: SharedLib.IQMessage[];
|
|
27
|
+
@property() version?: string = pkg.version + '-wc-luzmo';
|
|
28
|
+
@property() libVersion?: string = pkg.version + '-wc-luzmo';
|
|
29
|
+
@property() remoteEntryServer = 'http://localhost:4202';
|
|
30
|
+
|
|
31
|
+
chartElement: HTMLElement;
|
|
32
|
+
// Static styles to set host display to block, else it is not shown at all for some reason.
|
|
33
|
+
static styles = css`
|
|
34
|
+
:host {
|
|
35
|
+
display: block;
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: 100%;
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment {
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
protected async firstUpdated(_changedProperties: PropertyValues) {
|
|
46
|
+
super.firstUpdated(_changedProperties);
|
|
47
|
+
await SharedLib.loadLibrary(this.appServer.startsWith('http://localhost') ? this.remoteEntryServer : this.appServer, 'Component');
|
|
48
|
+
// if type is available early, create and append element
|
|
49
|
+
this.createAndAppendElement();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private createAndAppendElement() {
|
|
53
|
+
if (!this.chartElement) {
|
|
54
|
+
this.chartElement = document.createElement('luzmo-iq-answer-component');
|
|
55
|
+
|
|
56
|
+
this.chartElement.addEventListener('addQuestion', payload => this.dispatchEvent(new CustomEvent('addQuestion', payload)));
|
|
57
|
+
this.chartElement.addEventListener('addAnswer', payload => this.dispatchEvent(new CustomEvent('addAnswer', payload)));
|
|
58
|
+
|
|
59
|
+
this.updateVizItemProperties();
|
|
60
|
+
|
|
61
|
+
this.renderRoot.append(this.chartElement);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private updateVizItemProperties() {
|
|
66
|
+
if (this.chartElement) {
|
|
67
|
+
// eslint-disable-next-line guard-for-in
|
|
68
|
+
for (const key in inputMap) {
|
|
69
|
+
const value = this[key];
|
|
70
|
+
if (value) {
|
|
71
|
+
const attributeValue = ['appServer', 'apiHost'].includes(key) ? SharedLib.removeTrailingSlash(value) : value;
|
|
72
|
+
this.chartElement.setAttribute(
|
|
73
|
+
inputMap[key],
|
|
74
|
+
typeof attributeValue === 'object' ? JSON.stringify(attributeValue) : attributeValue
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async updated(changedProperties: PropertyValues) {
|
|
82
|
+
if (this.chartElement) {
|
|
83
|
+
for (const [propertyName] of changedProperties.entries()) {
|
|
84
|
+
const mappedAttributeName = inputMap[propertyName as string] ?? (propertyName as string);
|
|
85
|
+
const attributeValue = typeof this[propertyName] === 'object' ? JSON.stringify(this[propertyName]) : (this[propertyName]?.toString() ?? this[propertyName]);
|
|
86
|
+
|
|
87
|
+
this.chartElement.setAttribute(mappedAttributeName, attributeValue);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// make sure type or itemId and dashboardId are available before creating the element
|
|
92
|
+
await SharedLib.loadLibrary(this.appServer.startsWith('http://localhost') ? this.remoteEntryServer : this.appServer, 'Component');
|
|
93
|
+
// When type is available, create and append element
|
|
94
|
+
this.createAndAppendElement();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protected render(): unknown {
|
|
99
|
+
return html` `;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!customElements.get('luzmo-iq-embed-answer')) {
|
|
104
|
+
customElements.define('luzmo-iq-embed-answer', LuzmoIQEmbedAnswerComponent);
|
|
105
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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 * as pkg from '../../../package.json';
|
|
5
|
+
|
|
6
|
+
const inputMap = {
|
|
7
|
+
aiEndpoint: 'ai-endpoint',
|
|
8
|
+
appServer: 'app-server',
|
|
9
|
+
apiHost: 'api-host',
|
|
10
|
+
options: 'options',
|
|
11
|
+
initialSuggestionsDatasetId: 'initialSuggestionsDatasetId',
|
|
12
|
+
authKey: 'auth-key',
|
|
13
|
+
authToken: 'auth-token',
|
|
14
|
+
version: 'version',
|
|
15
|
+
libVersion: 'lib-version',
|
|
16
|
+
aydHost: 'ayd-host'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class LuzmoIQEmbedChatComponent
|
|
20
|
+
extends LitElement {
|
|
21
|
+
@property() appServer? = 'https://app.luzmo.com';
|
|
22
|
+
@property() apiHost? = 'https://api.luzmo.com';
|
|
23
|
+
@property({ type: Object }) options?: SharedLib.IQChatOptions;
|
|
24
|
+
@property({ type: String }) initialSuggestionsDatasetId?: string;
|
|
25
|
+
@property() aiEndpoint?: string;
|
|
26
|
+
@property() authKey?: string;
|
|
27
|
+
@property() authToken?: string;
|
|
28
|
+
@property() version?: string = pkg.version + '-wc-luzmo';
|
|
29
|
+
@property() libVersion?: string = pkg.version + '-wc-luzmo';
|
|
30
|
+
@property() remoteEntryServer = 'http://localhost:4202/';
|
|
31
|
+
@property() aydHost = "https://ayd.luzmo.com/"
|
|
32
|
+
|
|
33
|
+
chartElement!: HTMLElement;
|
|
34
|
+
// Static styles to set host display to block, else it is not shown at all for some reason.
|
|
35
|
+
static styles = css`
|
|
36
|
+
:host {
|
|
37
|
+
display: block;
|
|
38
|
+
width: 100%;
|
|
39
|
+
height: 100%;
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment {
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected async firstUpdated(_changedProperties: PropertyValues) {
|
|
48
|
+
super.firstUpdated(_changedProperties);
|
|
49
|
+
await SharedLib.loadLibrary(this.appServer.startsWith('http://localhost') ? this.remoteEntryServer : this.appServer, 'Component');
|
|
50
|
+
// if type is available early, create and append element
|
|
51
|
+
this.createAndAppendElement();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private createAndAppendElement() {
|
|
55
|
+
if (!this.chartElement) {
|
|
56
|
+
this.chartElement = document.createElement('luzmo-iq-chat-component');
|
|
57
|
+
|
|
58
|
+
this.chartElement.addEventListener('load', payload => this.dispatchEvent(new CustomEvent('load', payload)));
|
|
59
|
+
this.updateVizItemProperties();
|
|
60
|
+
|
|
61
|
+
this.renderRoot.append(this.chartElement);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private updateVizItemProperties() {
|
|
66
|
+
if (this.chartElement) {
|
|
67
|
+
// eslint-disable-next-line guard-for-in
|
|
68
|
+
for (const key in inputMap) {
|
|
69
|
+
const value = this[key];
|
|
70
|
+
if (value) {
|
|
71
|
+
const attributeValue = ['appServer', 'apiHost', 'aydHost'].includes(key) ? SharedLib.removeTrailingSlash(value) : value;
|
|
72
|
+
this.chartElement.setAttribute(
|
|
73
|
+
inputMap[key],
|
|
74
|
+
typeof attributeValue === 'object' ? JSON.stringify(attributeValue) : attributeValue
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async updated(changedProperties: PropertyValues) {
|
|
82
|
+
if (this.chartElement) {
|
|
83
|
+
for (const [propertyName] of changedProperties.entries()) {
|
|
84
|
+
const mappedAttributeName = inputMap[propertyName as string] ?? (propertyName as string);
|
|
85
|
+
const attributeValue = typeof this[propertyName] === 'object' ? JSON.stringify(this[propertyName]) : (this[propertyName]?.toString() ?? this[propertyName]);
|
|
86
|
+
|
|
87
|
+
this.chartElement.setAttribute(mappedAttributeName, attributeValue);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// make sure type or itemId and dashboardId are available before creating the element
|
|
92
|
+
await SharedLib.loadLibrary(this.appServer.startsWith('http://localhost') ? this.remoteEntryServer : this.appServer, 'Component');
|
|
93
|
+
// When type is available, create and append element
|
|
94
|
+
this.createAndAppendElement();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protected render(): unknown {
|
|
99
|
+
return html` `;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!customElements.get('luzmo-iq-embed-chat')) {
|
|
104
|
+
customElements.define('luzmo-iq-embed-chat', LuzmoIQEmbedChatComponent);
|
|
105
|
+
}
|
|
@@ -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
|
+
}
|