@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.
- 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 +4 -2
- package/project.json +39 -0
- package/src/index.ts +42 -0
- package/src/lib/dashboard-component/dashboard-base.ts +828 -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 +195 -0
- package/src/lib/helper/json-schema-utils.ts +129 -0
- package/src/lib/luzmo-iq-components/luzmo-iq-answer.ts +106 -0
- package/src/lib/luzmo-iq-components/luzmo-iq-chat.ts +106 -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 +227 -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/index.cjs +0 -1579
- package/index.d.ts +0 -8
- package/index.js +0 -1548
- 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/helper/json-schema-utils.d.ts +0 -64
- package/lib/luzmo-iq-components/luzmo-iq-answer.d.ts +0 -22
- 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 -71
- package/luzmo-embed.min.js +0 -3630
- package/src/index.d.ts +0 -8
- 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/helper/json-schema-utils.d.ts +0 -64
- package/src/lib/luzmo-iq-components/luzmo-iq-answer.d.ts +0 -22
- 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 -71
|
@@ -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,195 @@
|
|
|
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 'calculatedDimensions': {
|
|
152
|
+
dashboardComponent.dimensions = event.data.dimensions;
|
|
153
|
+
SharedLib._setCalculatedDimensions(dashboardComponent);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case 'setSelectedData':
|
|
157
|
+
case 'setFilters': {
|
|
158
|
+
if (event.data.error) {
|
|
159
|
+
SharedLib.rejectPromise(
|
|
160
|
+
dashboardComponent,
|
|
161
|
+
event.data.requestId,
|
|
162
|
+
event.data
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
SharedLib.resolvePromise(
|
|
167
|
+
dashboardComponent,
|
|
168
|
+
event.data.requestId,
|
|
169
|
+
event.data
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case 'setPreview': {
|
|
175
|
+
if (event.data.error) {
|
|
176
|
+
SharedLib.rejectPromise(
|
|
177
|
+
dashboardComponent,
|
|
178
|
+
event.data.requestId,
|
|
179
|
+
event.data
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
SharedLib.resolvePromise(
|
|
184
|
+
dashboardComponent,
|
|
185
|
+
event.data.requestId,
|
|
186
|
+
event.data
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
window.addEventListener('message', window.__luzmoMessageHandler, false);
|
|
195
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { dashboardContentsVersion } from '../viz-item/viz-item.base';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cache for JSON schemas. A key is a URL (schema $id), a value is a schema itself.
|
|
5
|
+
*/
|
|
6
|
+
const cachedSchemas: Record<string, any> = {};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Adds JSON schemas to cache.
|
|
10
|
+
*/
|
|
11
|
+
export function addJSONSchemas(schemas: any) {
|
|
12
|
+
if (schemas.some((schema: any) => !schema.$id)) {
|
|
13
|
+
throw new Error('To add schemas they all must have an $id property.');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
schemas.forEach((schema: any) => {
|
|
17
|
+
cachedSchemas[schema.$id] = schema;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns a cached JSON schema by URL/schema $id.
|
|
23
|
+
*/
|
|
24
|
+
export function getCachedJSONSchema(schemaUrl: string) {
|
|
25
|
+
return cachedSchemas[schemaUrl];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns all the cached JSON schemas.
|
|
30
|
+
*/
|
|
31
|
+
export function getCachedJSONSchemas() {
|
|
32
|
+
return cachedSchemas;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns a URL for a Luzmo JSON schema name.
|
|
37
|
+
*/
|
|
38
|
+
export function getJSONSchemaUrl(schemaName: string) {
|
|
39
|
+
return `https://developer.luzmo.com/assets/json-schemas/${dashboardContentsVersion}/${schemaName}.schema.json`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Fetches a Luzmo JSON schema. If a schema is cached it's returned.
|
|
44
|
+
*
|
|
45
|
+
* Example usage:
|
|
46
|
+
* const schema = await fetchJSONSchema('viz-item-type');
|
|
47
|
+
*
|
|
48
|
+
* In the example above, a schema https://developer.luzmo.com/assets/json-schemas/{version}/viz-item-type.schema.json
|
|
49
|
+
* will be fetched and cached.
|
|
50
|
+
*/
|
|
51
|
+
export async function fetchJSONSchema(schemaName: string) {
|
|
52
|
+
const schemaUrl = getJSONSchemaUrl(schemaName);
|
|
53
|
+
|
|
54
|
+
if (getCachedJSONSchema(schemaUrl)) {
|
|
55
|
+
return getCachedJSONSchema(schemaUrl);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const response = await fetch(schemaUrl, { credentials: 'omit' });
|
|
60
|
+
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
throw new Error(`Failed to fetch schema ${schemaUrl}, response status: ${response.status}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const schema = await response.json();
|
|
66
|
+
|
|
67
|
+
addJSONSchemas([schema]);
|
|
68
|
+
|
|
69
|
+
return schema;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Luzmo resolver for the @apidevtools/json-schema-ref-parser library. It is used in the luzmoRefParserOptions and is
|
|
78
|
+
* needed to dereference Luzmo JSON schemas.
|
|
79
|
+
*/
|
|
80
|
+
const luzmoRefParserResolver = {
|
|
81
|
+
order: 101, // 101 would make it run after the file resolver, but before the HTTP resolver
|
|
82
|
+
canRead: (file: any) => {
|
|
83
|
+
const isLuzmoUrl = file.url.startsWith('https://developer.luzmo.com');
|
|
84
|
+
|
|
85
|
+
if (isLuzmoUrl) {
|
|
86
|
+
return !!getCachedJSONSchema(file.url);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return false;
|
|
90
|
+
},
|
|
91
|
+
read: (file: any, callback: any) => {
|
|
92
|
+
callback(null, getCachedJSONSchema(file.url));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* If you need to dereference Luzmo JSON schemas in your application, you can use @apidevtools/json-schema-ref-parser
|
|
98
|
+
* library and provide the following options for the refParser.dereference() method.
|
|
99
|
+
*
|
|
100
|
+
* Example usage:
|
|
101
|
+
*
|
|
102
|
+
* import * as refParser from '@apidevtools/json-schema-ref-parser';
|
|
103
|
+
* import { fetchJSONSchema, luzmoRefParserOptions } from '@luzmo/embed';
|
|
104
|
+
*
|
|
105
|
+
* async function showDereferencedSchema() {
|
|
106
|
+
* const schema = await fetchJSONSchema('text');
|
|
107
|
+
* const dereferencedSchema = await refParser.dereference(schema, luzmoRefParserOptions);
|
|
108
|
+
* console.log(dereferencedSchema);
|
|
109
|
+
* }
|
|
110
|
+
*
|
|
111
|
+
* Another example:
|
|
112
|
+
*
|
|
113
|
+
* import * as refParser from '@apidevtools/json-schema-ref-parser';
|
|
114
|
+
* import { addJSONSchemas, luzmoRefParserOptions } from '@luzmo/embed';
|
|
115
|
+
* import { TextJSONSchema, TextOptionsJSONSchema } from "@luzmo/dashboard-contents-types";
|
|
116
|
+
*
|
|
117
|
+
* async function showDereferencedSchema() {
|
|
118
|
+
* addJSONSchemas([TextJSONSchema, TextOptionsJSONSchema]);
|
|
119
|
+
* const dereferencedSchema = await refParser.dereference(TextJSONSchema, luzmoRefParserOptions);
|
|
120
|
+
* console.log(dereferencedSchema);
|
|
121
|
+
* }
|
|
122
|
+
*/
|
|
123
|
+
export const luzmoRefParserOptions = {
|
|
124
|
+
mutateInputSchema: false,
|
|
125
|
+
resolve: {
|
|
126
|
+
luzmo: luzmoRefParserResolver,
|
|
127
|
+
external: true
|
|
128
|
+
}
|
|
129
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { IQAnswerOptions, IQMessage } from '@luzmo/dashboard-contents-types';
|
|
2
|
+
import { property } from 'lit/decorators.js';
|
|
3
|
+
import { LitElement, html, PropertyValues, css } from 'lit';
|
|
4
|
+
import * as SharedLib from '@luzmo/shared-embed';
|
|
5
|
+
import * as pkg from '../../../package.json';
|
|
6
|
+
|
|
7
|
+
const inputMap = {
|
|
8
|
+
aiEndPoint: 'ai-end-point',
|
|
9
|
+
appServer: 'app-server',
|
|
10
|
+
apiHost: 'api-host',
|
|
11
|
+
options: 'options',
|
|
12
|
+
authKey: 'auth-key',
|
|
13
|
+
authToken: 'auth-token',
|
|
14
|
+
version: 'version',
|
|
15
|
+
libVersion: 'lib-version',
|
|
16
|
+
messages: 'messages'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class LuzmoIQEmbedAnswerComponent
|
|
20
|
+
extends LitElement {
|
|
21
|
+
@property() appServer? = 'https://app.luzmo.com';
|
|
22
|
+
@property() apiHost? = 'https://api.luzmo.com';
|
|
23
|
+
@property({ type: Object }) options?: IQAnswerOptions;
|
|
24
|
+
@property() aiEndPoint?: string;
|
|
25
|
+
@property() authKey?: string;
|
|
26
|
+
@property() authToken?: string;
|
|
27
|
+
@property() messages: IQMessage[];
|
|
28
|
+
@property() version?: string = pkg.version + '-wc-luzmo';
|
|
29
|
+
@property() libVersion?: string = pkg.version + '-wc-luzmo';
|
|
30
|
+
@property() remoteEntryServer = 'http://localhost:4202';
|
|
31
|
+
|
|
32
|
+
chartElement: HTMLElement;
|
|
33
|
+
// Static styles to set host display to block, else it is not shown at all for some reason.
|
|
34
|
+
static styles = css`
|
|
35
|
+
:host {
|
|
36
|
+
display: block;
|
|
37
|
+
width: 100%;
|
|
38
|
+
height: 100%;
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment {
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected async firstUpdated(_changedProperties: PropertyValues) {
|
|
47
|
+
super.firstUpdated(_changedProperties);
|
|
48
|
+
await SharedLib.loadLibrary(this.appServer.startsWith('http://localhost') ? this.remoteEntryServer : this.appServer, 'Component');
|
|
49
|
+
// if type is available early, create and append element
|
|
50
|
+
this.createAndAppendElement();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private createAndAppendElement() {
|
|
54
|
+
if (!this.chartElement) {
|
|
55
|
+
this.chartElement = document.createElement('luzmo-iq-answer-component');
|
|
56
|
+
|
|
57
|
+
this.chartElement.addEventListener('addQuestion', payload => this.dispatchEvent(new CustomEvent('addQuestion', payload)));
|
|
58
|
+
this.chartElement.addEventListener('addAnswer', payload => this.dispatchEvent(new CustomEvent('addAnswer', payload)));
|
|
59
|
+
|
|
60
|
+
this.updateVizItemProperties();
|
|
61
|
+
|
|
62
|
+
this.renderRoot.append(this.chartElement);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private updateVizItemProperties() {
|
|
67
|
+
if (this.chartElement) {
|
|
68
|
+
// eslint-disable-next-line guard-for-in
|
|
69
|
+
for (const key in inputMap) {
|
|
70
|
+
const value = this[key];
|
|
71
|
+
if (value) {
|
|
72
|
+
const attributeValue = ['appServer', 'apiHost'].includes(key) ? SharedLib.removeTrailingSlash(value) : value;
|
|
73
|
+
this.chartElement.setAttribute(
|
|
74
|
+
inputMap[key],
|
|
75
|
+
typeof attributeValue === 'object' ? JSON.stringify(attributeValue) : attributeValue
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async updated(changedProperties: PropertyValues) {
|
|
83
|
+
if (this.chartElement) {
|
|
84
|
+
for (const [propertyName] of changedProperties.entries()) {
|
|
85
|
+
const mappedAttributeName = inputMap[propertyName as string] ?? (propertyName as string);
|
|
86
|
+
const attributeValue = typeof this[propertyName] === 'object' ? JSON.stringify(this[propertyName]) : (this[propertyName]?.toString() ?? this[propertyName]);
|
|
87
|
+
|
|
88
|
+
this.chartElement.setAttribute(mappedAttributeName, attributeValue);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// make sure type or itemId and dashboardId are available before creating the element
|
|
93
|
+
await SharedLib.loadLibrary(this.appServer.startsWith('http://localhost') ? this.remoteEntryServer : this.appServer, 'Component');
|
|
94
|
+
// When type is available, create and append element
|
|
95
|
+
this.createAndAppendElement();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected render(): unknown {
|
|
100
|
+
return html` `;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!customElements.get('luzmo-iq-embed-answer')) {
|
|
105
|
+
customElements.define('luzmo-iq-embed-answer', LuzmoIQEmbedAnswerComponent);
|
|
106
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { IQChatOptions } from '@luzmo/dashboard-contents-types';
|
|
2
|
+
import { property } from 'lit/decorators.js';
|
|
3
|
+
import { LitElement, html, PropertyValues, css } from 'lit';
|
|
4
|
+
import * as SharedLib from '@luzmo/shared-embed';
|
|
5
|
+
import * as pkg from '../../../package.json';
|
|
6
|
+
|
|
7
|
+
const inputMap = {
|
|
8
|
+
aiEndpoint: 'ai-endpoint',
|
|
9
|
+
appServer: 'app-server',
|
|
10
|
+
apiHost: 'api-host',
|
|
11
|
+
options: 'options',
|
|
12
|
+
initialSuggestionsDatasetId: 'initialSuggestionsDatasetId',
|
|
13
|
+
authKey: 'auth-key',
|
|
14
|
+
authToken: 'auth-token',
|
|
15
|
+
version: 'version',
|
|
16
|
+
libVersion: 'lib-version',
|
|
17
|
+
aydHost: 'ayd-host'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class LuzmoIQEmbedChatComponent
|
|
21
|
+
extends LitElement {
|
|
22
|
+
@property() appServer? = 'https://app.luzmo.com';
|
|
23
|
+
@property() apiHost? = 'https://api.luzmo.com';
|
|
24
|
+
@property({ type: Object }) options?: IQChatOptions;
|
|
25
|
+
@property({ type: String }) initialSuggestionsDatasetId?: string;
|
|
26
|
+
@property() aiEndpoint?: string;
|
|
27
|
+
@property() authKey?: string;
|
|
28
|
+
@property() authToken?: string;
|
|
29
|
+
@property() version?: string = pkg.version + '-wc-luzmo';
|
|
30
|
+
@property() libVersion?: string = pkg.version + '-wc-luzmo';
|
|
31
|
+
@property() remoteEntryServer = 'http://localhost:4202/';
|
|
32
|
+
@property() aydHost = "https://ayd.luzmo.com/"
|
|
33
|
+
|
|
34
|
+
chartElement!: HTMLElement;
|
|
35
|
+
// Static styles to set host display to block, else it is not shown at all for some reason.
|
|
36
|
+
static styles = css`
|
|
37
|
+
:host {
|
|
38
|
+
display: block;
|
|
39
|
+
width: 100%;
|
|
40
|
+
height: 100%;
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment {
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
protected async firstUpdated(_changedProperties: PropertyValues) {
|
|
49
|
+
super.firstUpdated(_changedProperties);
|
|
50
|
+
await SharedLib.loadLibrary(this.appServer.startsWith('http://localhost') ? this.remoteEntryServer : this.appServer, 'Component');
|
|
51
|
+
// if type is available early, create and append element
|
|
52
|
+
this.createAndAppendElement();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private createAndAppendElement() {
|
|
56
|
+
if (!this.chartElement) {
|
|
57
|
+
this.chartElement = document.createElement('luzmo-iq-chat-component');
|
|
58
|
+
|
|
59
|
+
this.chartElement.addEventListener('load', payload => this.dispatchEvent(new CustomEvent('load', payload)));
|
|
60
|
+
this.updateVizItemProperties();
|
|
61
|
+
|
|
62
|
+
this.renderRoot.append(this.chartElement);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private updateVizItemProperties() {
|
|
67
|
+
if (this.chartElement) {
|
|
68
|
+
// eslint-disable-next-line guard-for-in
|
|
69
|
+
for (const key in inputMap) {
|
|
70
|
+
const value = this[key];
|
|
71
|
+
if (value) {
|
|
72
|
+
const attributeValue = ['appServer', 'apiHost', 'aydHost'].includes(key) ? SharedLib.removeTrailingSlash(value) : value;
|
|
73
|
+
this.chartElement.setAttribute(
|
|
74
|
+
inputMap[key],
|
|
75
|
+
typeof attributeValue === 'object' ? JSON.stringify(attributeValue) : attributeValue
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async updated(changedProperties: PropertyValues) {
|
|
83
|
+
if (this.chartElement) {
|
|
84
|
+
for (const [propertyName] of changedProperties.entries()) {
|
|
85
|
+
const mappedAttributeName = inputMap[propertyName as string] ?? (propertyName as string);
|
|
86
|
+
const attributeValue = typeof this[propertyName] === 'object' ? JSON.stringify(this[propertyName]) : (this[propertyName]?.toString() ?? this[propertyName]);
|
|
87
|
+
|
|
88
|
+
this.chartElement.setAttribute(mappedAttributeName, attributeValue);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// make sure type or itemId and dashboardId are available before creating the element
|
|
93
|
+
await SharedLib.loadLibrary(this.appServer.startsWith('http://localhost') ? this.remoteEntryServer : this.appServer, 'Component');
|
|
94
|
+
// When type is available, create and append element
|
|
95
|
+
this.createAndAppendElement();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected render(): unknown {
|
|
100
|
+
return html` `;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!customElements.get('luzmo-iq-embed-chat')) {
|
|
105
|
+
customElements.define('luzmo-iq-embed-chat', LuzmoIQEmbedChatComponent);
|
|
106
|
+
}
|