@memori.ai/memori-react 2.0.11 → 2.1.0
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/CHANGELOG.md +12 -0
- package/README.md +74 -26
- package/dist/components/MediaWidget/MediaItemWidget.js +1 -12
- package/dist/components/MediaWidget/MediaItemWidget.js.map +1 -1
- package/dist/components/MemoriWidget/MemoriWidget.d.ts +17 -1
- package/dist/components/MemoriWidget/MemoriWidget.js +8 -6
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/components/layouts/FullPage.d.ts +2 -15
- package/dist/components/layouts/FullPage.js.map +1 -1
- package/dist/components/layouts/Totem.d.ts +2 -15
- package/dist/components/layouts/Totem.js.map +1 -1
- package/dist/helpers/media.js +25 -19
- package/dist/helpers/media.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/esm/components/MediaWidget/MediaItemWidget.js +1 -12
- package/esm/components/MediaWidget/MediaItemWidget.js.map +1 -1
- package/esm/components/MemoriWidget/MemoriWidget.d.ts +17 -1
- package/esm/components/MemoriWidget/MemoriWidget.js +8 -6
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/components/layouts/FullPage.d.ts +2 -15
- package/esm/components/layouts/FullPage.js.map +1 -1
- package/esm/components/layouts/Totem.d.ts +2 -15
- package/esm/components/layouts/Totem.js.map +1 -1
- package/esm/helpers/media.js +25 -19
- package/esm/helpers/media.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +2 -2
- package/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Chat/__snapshots__/Chat.test.tsx.snap +6 -6
- package/src/components/MediaWidget/MediaItemWidget.tsx +1 -12
- package/src/components/MediaWidget/__snapshots__/MediaItemWidget.test.tsx.snap +6 -6
- package/src/components/MediaWidget/__snapshots__/MediaWidget.test.tsx.snap +1 -1
- package/src/components/MemoriWidget/MemoriWidget.tsx +24 -6
- package/src/components/layouts/FullPage.tsx +2 -16
- package/src/components/layouts/Totem.tsx +2 -16
- package/src/components/layouts/layouts.stories.tsx +41 -1
- package/src/helpers/media.ts +29 -23
- package/src/index.tsx +3 -0
|
@@ -145,12 +145,28 @@ let speechSynthesizer: SpeechSynthesizer | null;
|
|
|
145
145
|
let audioDestination: SpeakerAudioDestination;
|
|
146
146
|
let audioContext: IAudioContext;
|
|
147
147
|
|
|
148
|
+
export interface LayoutProps {
|
|
149
|
+
header?: JSX.Element | null;
|
|
150
|
+
avatar: JSX.Element;
|
|
151
|
+
chat?: JSX.Element | null;
|
|
152
|
+
startPanel: JSX.Element;
|
|
153
|
+
integrationStyle?: JSX.Element | null;
|
|
154
|
+
integrationBackground?: JSX.Element | null;
|
|
155
|
+
changeMode?: JSX.Element | null;
|
|
156
|
+
poweredBy?: JSX.Element | null;
|
|
157
|
+
sessionId?: string;
|
|
158
|
+
hasUserActivatedSpeak?: boolean;
|
|
159
|
+
showInstruct?: boolean;
|
|
160
|
+
loading?: boolean;
|
|
161
|
+
}
|
|
162
|
+
|
|
148
163
|
export interface Props {
|
|
149
164
|
memori: Memori;
|
|
150
165
|
memoriConfigs?: MemoriConfig[];
|
|
151
166
|
memoriLang?: string;
|
|
152
167
|
integration?: Integration;
|
|
153
168
|
layout?: 'DEFAULT' | 'FULLPAGE' | 'TOTEM';
|
|
169
|
+
customLayout?: React.FC<LayoutProps>;
|
|
154
170
|
showShare?: boolean;
|
|
155
171
|
showInstruct?: boolean;
|
|
156
172
|
showInputs?: boolean;
|
|
@@ -184,6 +200,7 @@ const MemoriWidget = ({
|
|
|
184
200
|
memoriLang,
|
|
185
201
|
integration,
|
|
186
202
|
layout = 'DEFAULT',
|
|
203
|
+
customLayout,
|
|
187
204
|
showInstruct = false,
|
|
188
205
|
showShare = true,
|
|
189
206
|
preview = false,
|
|
@@ -2255,12 +2272,13 @@ const MemoriWidget = ({
|
|
|
2255
2272
|
|
|
2256
2273
|
const poweredBy = <PoweredBy tenant={tenant} userLang={userLang} />;
|
|
2257
2274
|
|
|
2258
|
-
const Layout =
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2275
|
+
const Layout = customLayout
|
|
2276
|
+
? customLayout
|
|
2277
|
+
: selectedLayout === 'TOTEM'
|
|
2278
|
+
? TotemLayout
|
|
2279
|
+
: selectedLayout === 'FULLPAGE'
|
|
2280
|
+
? FullPageLayout
|
|
2281
|
+
: FullPageLayout;
|
|
2264
2282
|
|
|
2265
2283
|
return (
|
|
2266
2284
|
<div
|
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import Spin from '../ui/Spin';
|
|
3
|
+
import { LayoutProps } from '../MemoriWidget/MemoriWidget';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
header?: JSX.Element | null;
|
|
6
|
-
avatar: JSX.Element;
|
|
7
|
-
chat?: JSX.Element | null;
|
|
8
|
-
startPanel: JSX.Element;
|
|
9
|
-
integrationStyle?: JSX.Element | null;
|
|
10
|
-
integrationBackground?: JSX.Element | null;
|
|
11
|
-
changeMode?: JSX.Element | null;
|
|
12
|
-
poweredBy?: JSX.Element | null;
|
|
13
|
-
sessionId?: string;
|
|
14
|
-
hasUserActivatedSpeak?: boolean;
|
|
15
|
-
showInstruct?: boolean;
|
|
16
|
-
loading?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const FullPageLayout: React.FC<Props> = ({
|
|
5
|
+
const FullPageLayout: React.FC<LayoutProps> = ({
|
|
20
6
|
header,
|
|
21
7
|
avatar,
|
|
22
8
|
chat,
|
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import Spin from '../ui/Spin';
|
|
3
|
+
import { LayoutProps } from '../MemoriWidget/MemoriWidget';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
header?: JSX.Element | null;
|
|
6
|
-
avatar: JSX.Element;
|
|
7
|
-
chat?: JSX.Element | null;
|
|
8
|
-
startPanel: JSX.Element;
|
|
9
|
-
integrationStyle?: JSX.Element | null;
|
|
10
|
-
integrationBackground?: JSX.Element | null;
|
|
11
|
-
changeMode?: JSX.Element | null;
|
|
12
|
-
poweredBy?: JSX.Element | null;
|
|
13
|
-
sessionId?: string;
|
|
14
|
-
hasUserActivatedSpeak?: boolean;
|
|
15
|
-
showInstruct?: boolean;
|
|
16
|
-
loading?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const TotemLayout: React.FC<Props> = ({
|
|
5
|
+
const TotemLayout: React.FC<LayoutProps> = ({
|
|
20
6
|
header,
|
|
21
7
|
avatar,
|
|
22
8
|
chat,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Meta, Story } from '@storybook/react';
|
|
3
3
|
import { memori, tenant, integration } from '../../mocks/data';
|
|
4
|
-
import Memori, { Props } from '../MemoriWidget/MemoriWidget';
|
|
4
|
+
import Memori, { LayoutProps, Props } from '../MemoriWidget/MemoriWidget';
|
|
5
|
+
import Spin from '../ui/Spin';
|
|
5
6
|
|
|
6
7
|
const meta: Meta = {
|
|
7
8
|
title: 'General/Layouts',
|
|
@@ -21,6 +22,34 @@ const meta: Meta = {
|
|
|
21
22
|
|
|
22
23
|
export default meta;
|
|
23
24
|
|
|
25
|
+
const CustomLayout: React.FC<LayoutProps> = ({
|
|
26
|
+
header,
|
|
27
|
+
avatar,
|
|
28
|
+
chat,
|
|
29
|
+
startPanel,
|
|
30
|
+
integrationStyle,
|
|
31
|
+
integrationBackground,
|
|
32
|
+
changeMode,
|
|
33
|
+
sessionId,
|
|
34
|
+
hasUserActivatedSpeak,
|
|
35
|
+
showInstruct = false,
|
|
36
|
+
loading = false,
|
|
37
|
+
poweredBy,
|
|
38
|
+
}) => (
|
|
39
|
+
<>
|
|
40
|
+
{integrationStyle}
|
|
41
|
+
{integrationBackground}
|
|
42
|
+
|
|
43
|
+
<Spin spinning={loading} className="memori-mycustom-layout">
|
|
44
|
+
{poweredBy}
|
|
45
|
+
|
|
46
|
+
<div className="memori-mycustom-layout--controls">
|
|
47
|
+
{sessionId && hasUserActivatedSpeak ? chat : startPanel}
|
|
48
|
+
</div>
|
|
49
|
+
</Spin>
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
52
|
+
|
|
24
53
|
const Template: Story<Props> = args => <Memori {...args} />;
|
|
25
54
|
|
|
26
55
|
// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test
|
|
@@ -153,3 +182,14 @@ Totem.args = {
|
|
|
153
182
|
tenant,
|
|
154
183
|
layout: 'TOTEM',
|
|
155
184
|
};
|
|
185
|
+
|
|
186
|
+
export const Custom = Template.bind({});
|
|
187
|
+
Custom.args = {
|
|
188
|
+
uiLang: 'it',
|
|
189
|
+
showShare: true,
|
|
190
|
+
showSettings: true,
|
|
191
|
+
memori,
|
|
192
|
+
tenant,
|
|
193
|
+
layout: 'FULLPAGE',
|
|
194
|
+
customLayout: CustomLayout,
|
|
195
|
+
};
|
package/src/helpers/media.ts
CHANGED
|
@@ -17,28 +17,34 @@ export const getResourceUrl = ({
|
|
|
17
17
|
type === 'cover'
|
|
18
18
|
? `${baseURL}/images/memoriCover.png`
|
|
19
19
|
: `${baseURL}/images/memoriAvatar.png`;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
if (!resourceURI || resourceURI.length === 0) {
|
|
23
|
+
return defaultUri;
|
|
24
|
+
} else if (
|
|
25
|
+
resourceURI.includes('memoriai/memory') &&
|
|
26
|
+
!resourceURI.includes('memori-ai-session-id') &&
|
|
27
|
+
sessionID
|
|
28
|
+
) {
|
|
29
|
+
return `${resourceURI}?memori-ai-session-id=${sessionID}`;
|
|
30
|
+
} else if (
|
|
31
|
+
(resourceURI.startsWith('https://') ||
|
|
32
|
+
resourceURI.startsWith('http://')) &&
|
|
33
|
+
new URL(resourceURI).hostname.includes('memori.ai')
|
|
34
|
+
) {
|
|
35
|
+
return `${resourceURI}${sessionID ? `/${sessionID}` : ''}`;
|
|
36
|
+
} else if (resourceURI.startsWith('cloud://')) {
|
|
37
|
+
return `${
|
|
38
|
+
apiURL?.replace(/v2/, 'v1') || ''
|
|
39
|
+
}/CloudAsset/${resourceURI.replace('cloud://', '')}`;
|
|
40
|
+
} else if (resourceURI.startsWith('guid://')) {
|
|
41
|
+
return `${
|
|
42
|
+
apiURL?.replace(/v2/, 'v1') || ''
|
|
43
|
+
}/GuidAsset/${resourceURI.replace('guid://', '')}`;
|
|
44
|
+
} else {
|
|
45
|
+
return resourceURI || defaultUri;
|
|
46
|
+
}
|
|
47
|
+
} catch (e) {
|
|
48
|
+
return resourceURI || defaultUri;
|
|
43
49
|
}
|
|
44
50
|
};
|
package/src/index.tsx
CHANGED
|
@@ -22,6 +22,7 @@ export interface Props {
|
|
|
22
22
|
secretToken?: string;
|
|
23
23
|
sessionID?: string;
|
|
24
24
|
layout?: WidgetProps['layout'];
|
|
25
|
+
customLayout?: WidgetProps['customLayout'];
|
|
25
26
|
showShare?: boolean;
|
|
26
27
|
showSettings?: boolean;
|
|
27
28
|
showInstruct?: boolean;
|
|
@@ -66,6 +67,7 @@ const Memori: React.FC<Props> = ({
|
|
|
66
67
|
secretToken,
|
|
67
68
|
sessionID,
|
|
68
69
|
layout = 'DEFAULT',
|
|
70
|
+
customLayout,
|
|
69
71
|
showShare = true,
|
|
70
72
|
showSettings = true,
|
|
71
73
|
showInstruct = false,
|
|
@@ -147,6 +149,7 @@ const Memori: React.FC<Props> = ({
|
|
|
147
149
|
return memori ? (
|
|
148
150
|
<MemoriWidget
|
|
149
151
|
layout={layout}
|
|
152
|
+
customLayout={customLayout}
|
|
150
153
|
height={height}
|
|
151
154
|
baseUrl={
|
|
152
155
|
baseURL ||
|