@botonic/plugin-flow-builder 0.27.7 → 0.27.8-alpha.1
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/lib/cjs/webview/contents-context.d.ts +1 -1
- package/lib/cjs/webview/contents-context.js +3 -2
- package/lib/cjs/webview/contents-context.js.map +1 -1
- package/lib/cjs/webview/types.d.ts +8 -6
- package/lib/cjs/webview/use-webview-contents.d.ts +1 -1
- package/lib/cjs/webview/use-webview-contents.js +23 -11
- package/lib/cjs/webview/use-webview-contents.js.map +1 -1
- package/lib/esm/webview/contents-context.d.ts +1 -1
- package/lib/esm/webview/contents-context.js +3 -2
- package/lib/esm/webview/contents-context.js.map +1 -1
- package/lib/esm/webview/types.d.ts +8 -6
- package/lib/esm/webview/use-webview-contents.d.ts +1 -1
- package/lib/esm/webview/use-webview-contents.js +23 -11
- package/lib/esm/webview/use-webview-contents.js.map +1 -1
- package/package.json +1 -1
- package/src/webview/contents-context.ts +8 -7
- package/src/webview/types.ts +8 -6
- package/src/webview/use-webview-contents.ts +36 -16
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { WebviewContentsContextType } from './types';
|
|
3
|
-
export declare const WebviewContentsContext: import("react").Context<WebviewContentsContextType
|
|
3
|
+
export declare const WebviewContentsContext: import("react").Context<WebviewContentsContextType<unknown>>;
|
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WebviewContentsContext = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
exports.WebviewContentsContext = (0, react_1.createContext)({
|
|
6
|
-
getTextContent: () =>
|
|
7
|
-
getImageSrc: () =>
|
|
6
|
+
getTextContent: () => '',
|
|
7
|
+
getImageSrc: () => '',
|
|
8
8
|
setCurrentLocale: () => undefined,
|
|
9
|
+
contents: {},
|
|
9
10
|
});
|
|
10
11
|
//# sourceMappingURL=contents-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contents-context.js","sourceRoot":"","sources":["../../../src/webview/contents-context.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAIxB,QAAA,sBAAsB,GAAG,IAAA,qBAAa,
|
|
1
|
+
{"version":3,"file":"contents-context.js","sourceRoot":"","sources":["../../../src/webview/contents-context.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAIxB,QAAA,sBAAsB,GAAG,IAAA,qBAAa,EAEjD;IACA,cAAc,EAAE,GAAG,EAAE,CAAC,EAAE;IACxB,WAAW,EAAE,GAAG,EAAE,CAAC,EAAE;IACrB,gBAAgB,EAAE,GAAG,EAAE,CAAC,SAAS;IACjC,QAAQ,EAAE,EAAE;CACb,CAAC,CAAA"}
|
|
@@ -26,21 +26,23 @@ export interface WebviewImageContent {
|
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
export interface UseWebviewContentsProps {
|
|
29
|
+
export interface UseWebviewContentsProps<T> {
|
|
30
30
|
apiUrl?: string;
|
|
31
31
|
version?: FlowBuilderJSONVersion;
|
|
32
32
|
orgId: string;
|
|
33
33
|
botId: string;
|
|
34
34
|
webviewId: string;
|
|
35
35
|
locale: string;
|
|
36
|
+
mapContents: Record<keyof T, string>;
|
|
36
37
|
}
|
|
37
|
-
export interface UseWebviewContents {
|
|
38
|
+
export interface UseWebviewContents<T> {
|
|
38
39
|
isLoading: boolean;
|
|
39
40
|
error: boolean;
|
|
40
|
-
webviewContentsContext: WebviewContentsContextType
|
|
41
|
+
webviewContentsContext: WebviewContentsContextType<T>;
|
|
41
42
|
}
|
|
42
|
-
export interface WebviewContentsContextType {
|
|
43
|
-
getTextContent: (code: string) => string
|
|
44
|
-
getImageSrc: (code: string) => string
|
|
43
|
+
export interface WebviewContentsContextType<T> {
|
|
44
|
+
getTextContent: (code: string) => string;
|
|
45
|
+
getImageSrc: (code: string) => string;
|
|
45
46
|
setCurrentLocale: (locale: string) => void;
|
|
47
|
+
contents: Record<keyof T, string>;
|
|
46
48
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { UseWebviewContents, UseWebviewContentsProps } from './types';
|
|
2
|
-
export declare function useWebviewContents({ apiUrl, version, orgId, botId, webviewId, locale, }: UseWebviewContentsProps): UseWebviewContents
|
|
2
|
+
export declare function useWebviewContents<T>({ apiUrl, version, orgId, botId, webviewId, locale, mapContents, }: UseWebviewContentsProps<T>): UseWebviewContents<T>;
|
|
@@ -7,15 +7,34 @@ const react_1 = require("react");
|
|
|
7
7
|
const constants_1 = require("../constants");
|
|
8
8
|
const types_1 = require("../types");
|
|
9
9
|
const types_2 = require("./types");
|
|
10
|
-
function useWebviewContents({ apiUrl = constants_1.FLOW_BUILDER_API_URL_PROD, version = types_1.FlowBuilderJSONVersion.LATEST, orgId, botId, webviewId, locale, }) {
|
|
10
|
+
function useWebviewContents({ apiUrl = constants_1.FLOW_BUILDER_API_URL_PROD, version = types_1.FlowBuilderJSONVersion.LATEST, orgId, botId, webviewId, locale, mapContents, }) {
|
|
11
11
|
const [textContents, setTextContents] = (0, react_1.useState)();
|
|
12
12
|
const [imageContents, setImageContents] = (0, react_1.useState)();
|
|
13
|
+
const [contents, setContents] = (0, react_1.useState)({});
|
|
13
14
|
const [currentLocale, setCurrentLocale] = (0, react_1.useState)(locale);
|
|
14
|
-
const [isLoading, setLoading] = (0, react_1.useState)(
|
|
15
|
+
const [isLoading, setLoading] = (0, react_1.useState)(true);
|
|
15
16
|
const [error, setError] = (0, react_1.useState)(false);
|
|
17
|
+
const getTextContent = (contentID) => {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
return (((_b = (_a = textContents === null || textContents === void 0 ? void 0 : textContents.find(textContent => textContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.text.find(text => text.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.message) ||
|
|
20
|
+
'');
|
|
21
|
+
};
|
|
22
|
+
const getImageSrc = (contentID) => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
return (((_b = (_a = imageContents === null || imageContents === void 0 ? void 0 : imageContents.find(imageContent => imageContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.image.find(image => image.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.file) ||
|
|
25
|
+
'');
|
|
26
|
+
};
|
|
27
|
+
(0, react_1.useEffect)(() => {
|
|
28
|
+
if (textContents || imageContents) {
|
|
29
|
+
const contentsObject = {};
|
|
30
|
+
for (const [key, value] of Object.entries(mapContents)) {
|
|
31
|
+
contentsObject[key] = getTextContent(value) || getImageSrc(value);
|
|
32
|
+
}
|
|
33
|
+
setContents(contentsObject);
|
|
34
|
+
}
|
|
35
|
+
}, [textContents, imageContents, currentLocale]);
|
|
16
36
|
(0, react_1.useEffect)(() => {
|
|
17
37
|
const getResponseContents = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
setLoading(true);
|
|
19
38
|
const url = `${apiUrl}/webview/${version}`;
|
|
20
39
|
try {
|
|
21
40
|
const response = yield axios_1.default.get(url, {
|
|
@@ -36,14 +55,6 @@ function useWebviewContents({ apiUrl = constants_1.FLOW_BUILDER_API_URL_PROD, ve
|
|
|
36
55
|
});
|
|
37
56
|
getResponseContents();
|
|
38
57
|
}, []);
|
|
39
|
-
const getTextContent = (contentID) => {
|
|
40
|
-
var _a, _b;
|
|
41
|
-
return (_b = (_a = textContents === null || textContents === void 0 ? void 0 : textContents.find(textContent => textContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.text.find(text => text.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.message;
|
|
42
|
-
};
|
|
43
|
-
const getImageSrc = (contentID) => {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
return (_b = (_a = imageContents === null || imageContents === void 0 ? void 0 : imageContents.find(imageContent => imageContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.image.find(image => image.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.file;
|
|
46
|
-
};
|
|
47
58
|
return {
|
|
48
59
|
isLoading,
|
|
49
60
|
error,
|
|
@@ -51,6 +62,7 @@ function useWebviewContents({ apiUrl = constants_1.FLOW_BUILDER_API_URL_PROD, ve
|
|
|
51
62
|
getTextContent,
|
|
52
63
|
getImageSrc,
|
|
53
64
|
setCurrentLocale,
|
|
65
|
+
contents,
|
|
54
66
|
},
|
|
55
67
|
};
|
|
56
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-webview-contents.js","sourceRoot":"","sources":["../../../src/webview/use-webview-contents.ts"],"names":[],"mappings":";;;;AAAA,0DAAyB;AACzB,iCAA2C;AAE3C,4CAAwD;AACxD,oCAAiD;AACjD,mCAOgB;AAEhB,SAAgB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"use-webview-contents.js","sourceRoot":"","sources":["../../../src/webview/use-webview-contents.ts"],"names":[],"mappings":";;;;AAAA,0DAAyB;AACzB,iCAA2C;AAE3C,4CAAwD;AACxD,oCAAiD;AACjD,mCAOgB;AAEhB,SAAgB,kBAAkB,CAAI,EACpC,MAAM,GAAG,qCAAyB,EAClC,OAAO,GAAG,8BAAsB,CAAC,MAAM,EACvC,KAAK,EACL,KAAK,EACL,SAAS,EACT,MAAM,EACN,WAAW,GACgB;IAC3B,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,GAAwB,CAAA;IACxE,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAAA,gBAAQ,GAAyB,CAAA;IAC3E,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EACtC,EAA6B,CAC9B,CAAA;IACD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAAA,gBAAQ,EAAC,MAAM,CAAC,CAAA;IAC1D,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAA;IAC9C,MAAM,CAAC,KAAK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,MAAM,mBAAmB,GAAG,GAAS,EAAE;YACrC,MAAM,GAAG,GAAG,GAAG,MAAM,YAAY,OAAO,EAAE,CAAA;YAC1C,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAA0B,GAAG,EAAE;oBAC7D,MAAM,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE;iBACvD,CAAC,CAAA;gBAEF,MAAM,oBAAoB,GAAG,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAChE,cAAc,CAAC,EAAE,CAAC,cAAc,CAAC,IAAI,KAAK,0BAAkB,CAAC,IAAI,CAC1C,CAAA;gBACzB,eAAe,CAAC,oBAAoB,CAAC,CAAA;gBAErC,MAAM,qBAAqB,GAAG,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CACjE,cAAc,CAAC,EAAE,CAAC,cAAc,CAAC,IAAI,KAAK,0BAAkB,CAAC,KAAK,CAC1C,CAAA;gBAC1B,gBAAgB,CAAC,qBAAqB,CAAC,CAAA;aACxC;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAA;gBACxD,QAAQ,CAAC,IAAI,CAAC,CAAA;aACf;oBAAS;gBACR,UAAU,CAAC,KAAK,CAAC,CAAA;aAClB;QACH,CAAC,CAAA,CAAA;QACD,mBAAmB,EAAE,CAAA;IACvB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,SAAS;QACT,KAAK;QACL,sBAAsB,EAAE;YACtB,cAAc;YACd,WAAW;YACX,gBAAgB;YAChB,QAAQ;SACT;KACF,CAAA;AACH,CAAC;AAnFD,gDAmFC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { WebviewContentsContextType } from './types';
|
|
3
|
-
export declare const WebviewContentsContext: import("react").Context<WebviewContentsContextType
|
|
3
|
+
export declare const WebviewContentsContext: import("react").Context<WebviewContentsContextType<unknown>>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
2
|
export const WebviewContentsContext = createContext({
|
|
3
|
-
getTextContent: () =>
|
|
4
|
-
getImageSrc: () =>
|
|
3
|
+
getTextContent: () => '',
|
|
4
|
+
getImageSrc: () => '',
|
|
5
5
|
setCurrentLocale: () => undefined,
|
|
6
|
+
contents: {},
|
|
6
7
|
});
|
|
7
8
|
//# sourceMappingURL=contents-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contents-context.js","sourceRoot":"","sources":["../../../src/webview/contents-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAIrC,MAAM,CAAC,MAAM,sBAAsB,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"contents-context.js","sourceRoot":"","sources":["../../../src/webview/contents-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAIrC,MAAM,CAAC,MAAM,sBAAsB,GAAG,aAAa,CAEjD;IACA,cAAc,EAAE,GAAG,EAAE,CAAC,EAAE;IACxB,WAAW,EAAE,GAAG,EAAE,CAAC,EAAE;IACrB,gBAAgB,EAAE,GAAG,EAAE,CAAC,SAAS;IACjC,QAAQ,EAAE,EAAE;CACb,CAAC,CAAA"}
|
|
@@ -26,21 +26,23 @@ export interface WebviewImageContent {
|
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
export interface UseWebviewContentsProps {
|
|
29
|
+
export interface UseWebviewContentsProps<T> {
|
|
30
30
|
apiUrl?: string;
|
|
31
31
|
version?: FlowBuilderJSONVersion;
|
|
32
32
|
orgId: string;
|
|
33
33
|
botId: string;
|
|
34
34
|
webviewId: string;
|
|
35
35
|
locale: string;
|
|
36
|
+
mapContents: Record<keyof T, string>;
|
|
36
37
|
}
|
|
37
|
-
export interface UseWebviewContents {
|
|
38
|
+
export interface UseWebviewContents<T> {
|
|
38
39
|
isLoading: boolean;
|
|
39
40
|
error: boolean;
|
|
40
|
-
webviewContentsContext: WebviewContentsContextType
|
|
41
|
+
webviewContentsContext: WebviewContentsContextType<T>;
|
|
41
42
|
}
|
|
42
|
-
export interface WebviewContentsContextType {
|
|
43
|
-
getTextContent: (code: string) => string
|
|
44
|
-
getImageSrc: (code: string) => string
|
|
43
|
+
export interface WebviewContentsContextType<T> {
|
|
44
|
+
getTextContent: (code: string) => string;
|
|
45
|
+
getImageSrc: (code: string) => string;
|
|
45
46
|
setCurrentLocale: (locale: string) => void;
|
|
47
|
+
contents: Record<keyof T, string>;
|
|
46
48
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { UseWebviewContents, UseWebviewContentsProps } from './types';
|
|
2
|
-
export declare function useWebviewContents({ apiUrl, version, orgId, botId, webviewId, locale, }: UseWebviewContentsProps): UseWebviewContents
|
|
2
|
+
export declare function useWebviewContents<T>({ apiUrl, version, orgId, botId, webviewId, locale, mapContents, }: UseWebviewContentsProps<T>): UseWebviewContents<T>;
|
|
@@ -4,15 +4,34 @@ import { useEffect, useState } from 'react';
|
|
|
4
4
|
import { FLOW_BUILDER_API_URL_PROD } from '../constants';
|
|
5
5
|
import { FlowBuilderJSONVersion } from '../types';
|
|
6
6
|
import { WebviewContentType, } from './types';
|
|
7
|
-
export function useWebviewContents({ apiUrl = FLOW_BUILDER_API_URL_PROD, version = FlowBuilderJSONVersion.LATEST, orgId, botId, webviewId, locale, }) {
|
|
7
|
+
export function useWebviewContents({ apiUrl = FLOW_BUILDER_API_URL_PROD, version = FlowBuilderJSONVersion.LATEST, orgId, botId, webviewId, locale, mapContents, }) {
|
|
8
8
|
const [textContents, setTextContents] = useState();
|
|
9
9
|
const [imageContents, setImageContents] = useState();
|
|
10
|
+
const [contents, setContents] = useState({});
|
|
10
11
|
const [currentLocale, setCurrentLocale] = useState(locale);
|
|
11
|
-
const [isLoading, setLoading] = useState(
|
|
12
|
+
const [isLoading, setLoading] = useState(true);
|
|
12
13
|
const [error, setError] = useState(false);
|
|
14
|
+
const getTextContent = (contentID) => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
return (((_b = (_a = textContents === null || textContents === void 0 ? void 0 : textContents.find(textContent => textContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.text.find(text => text.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.message) ||
|
|
17
|
+
'');
|
|
18
|
+
};
|
|
19
|
+
const getImageSrc = (contentID) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
return (((_b = (_a = imageContents === null || imageContents === void 0 ? void 0 : imageContents.find(imageContent => imageContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.image.find(image => image.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.file) ||
|
|
22
|
+
'');
|
|
23
|
+
};
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (textContents || imageContents) {
|
|
26
|
+
const contentsObject = {};
|
|
27
|
+
for (const [key, value] of Object.entries(mapContents)) {
|
|
28
|
+
contentsObject[key] = getTextContent(value) || getImageSrc(value);
|
|
29
|
+
}
|
|
30
|
+
setContents(contentsObject);
|
|
31
|
+
}
|
|
32
|
+
}, [textContents, imageContents, currentLocale]);
|
|
13
33
|
useEffect(() => {
|
|
14
34
|
const getResponseContents = () => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
setLoading(true);
|
|
16
35
|
const url = `${apiUrl}/webview/${version}`;
|
|
17
36
|
try {
|
|
18
37
|
const response = yield axios.get(url, {
|
|
@@ -33,14 +52,6 @@ export function useWebviewContents({ apiUrl = FLOW_BUILDER_API_URL_PROD, version
|
|
|
33
52
|
});
|
|
34
53
|
getResponseContents();
|
|
35
54
|
}, []);
|
|
36
|
-
const getTextContent = (contentID) => {
|
|
37
|
-
var _a, _b;
|
|
38
|
-
return (_b = (_a = textContents === null || textContents === void 0 ? void 0 : textContents.find(textContent => textContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.text.find(text => text.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.message;
|
|
39
|
-
};
|
|
40
|
-
const getImageSrc = (contentID) => {
|
|
41
|
-
var _a, _b;
|
|
42
|
-
return (_b = (_a = imageContents === null || imageContents === void 0 ? void 0 : imageContents.find(imageContent => imageContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.image.find(image => image.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.file;
|
|
43
|
-
};
|
|
44
55
|
return {
|
|
45
56
|
isLoading,
|
|
46
57
|
error,
|
|
@@ -48,6 +59,7 @@ export function useWebviewContents({ apiUrl = FLOW_BUILDER_API_URL_PROD, version
|
|
|
48
59
|
getTextContent,
|
|
49
60
|
getImageSrc,
|
|
50
61
|
setCurrentLocale,
|
|
62
|
+
contents,
|
|
51
63
|
},
|
|
52
64
|
};
|
|
53
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-webview-contents.js","sourceRoot":"","sources":["../../../src/webview/use-webview-contents.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,EAIL,kBAAkB,GAGnB,MAAM,SAAS,CAAA;AAEhB,MAAM,UAAU,kBAAkB,
|
|
1
|
+
{"version":3,"file":"use-webview-contents.js","sourceRoot":"","sources":["../../../src/webview/use-webview-contents.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,C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Ac,CAAC,EAAE,CAAC,cAAc,CAAC,IAAI,KAAK,kBAAkB,CAAC,KAAK,CAC1C,CAAA;gBAC1B,gBAAgB,CAAC,qBAAqB,CAAC,CAAA;aACxC;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAA;gBACxD,QAAQ,CAAC,IAAI,CAAC,CAAA;aACf;oBAAS;gBACR,UAAU,CAAC,KAAK,CAAC,CAAA;aAClB;QACH,CAAC,CAAA,CAAA;QACD,mBAAmB,EAAE,CAAA;IACvB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,SAAS;QACT,KAAK;QACL,sBAAsB,EAAE;YACtB,cAAc;YACd,WAAW;YACX,gBAAgB;YAChB,QAAQ;SACT;KACF,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,10 +2,11 @@ import { createContext } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import { WebviewContentsContextType } from './types'
|
|
4
4
|
|
|
5
|
-
export const WebviewContentsContext = createContext<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
export const WebviewContentsContext = createContext<
|
|
6
|
+
WebviewContentsContextType<unknown>
|
|
7
|
+
>({
|
|
8
|
+
getTextContent: () => '',
|
|
9
|
+
getImageSrc: () => '',
|
|
10
|
+
setCurrentLocale: () => undefined,
|
|
11
|
+
contents: {},
|
|
12
|
+
})
|
package/src/webview/types.ts
CHANGED
|
@@ -25,23 +25,25 @@ export interface WebviewImageContent {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export interface UseWebviewContentsProps {
|
|
28
|
+
export interface UseWebviewContentsProps<T> {
|
|
29
29
|
apiUrl?: string
|
|
30
30
|
version?: FlowBuilderJSONVersion
|
|
31
31
|
orgId: string
|
|
32
32
|
botId: string
|
|
33
33
|
webviewId: string
|
|
34
34
|
locale: string
|
|
35
|
+
mapContents: Record<keyof T, string>
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export interface UseWebviewContents {
|
|
38
|
+
export interface UseWebviewContents<T> {
|
|
38
39
|
isLoading: boolean
|
|
39
40
|
error: boolean
|
|
40
|
-
webviewContentsContext: WebviewContentsContextType
|
|
41
|
+
webviewContentsContext: WebviewContentsContextType<T>
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
export interface WebviewContentsContextType {
|
|
44
|
-
getTextContent: (code: string) => string
|
|
45
|
-
getImageSrc: (code: string) => string
|
|
44
|
+
export interface WebviewContentsContextType<T> {
|
|
45
|
+
getTextContent: (code: string) => string
|
|
46
|
+
getImageSrc: (code: string) => string
|
|
46
47
|
setCurrentLocale: (locale: string) => void
|
|
48
|
+
contents: Record<keyof T, string>
|
|
47
49
|
}
|
|
@@ -12,23 +12,54 @@ import {
|
|
|
12
12
|
WebviewTextContent,
|
|
13
13
|
} from './types'
|
|
14
14
|
|
|
15
|
-
export function useWebviewContents({
|
|
15
|
+
export function useWebviewContents<T>({
|
|
16
16
|
apiUrl = FLOW_BUILDER_API_URL_PROD,
|
|
17
17
|
version = FlowBuilderJSONVersion.LATEST,
|
|
18
18
|
orgId,
|
|
19
19
|
botId,
|
|
20
20
|
webviewId,
|
|
21
21
|
locale,
|
|
22
|
-
|
|
22
|
+
mapContents,
|
|
23
|
+
}: UseWebviewContentsProps<T>): UseWebviewContents<T> {
|
|
23
24
|
const [textContents, setTextContents] = useState<WebviewTextContent[]>()
|
|
24
25
|
const [imageContents, setImageContents] = useState<WebviewImageContent[]>()
|
|
26
|
+
const [contents, setContents] = useState<Record<keyof T, string>>(
|
|
27
|
+
{} as Record<keyof T, string>
|
|
28
|
+
)
|
|
25
29
|
const [currentLocale, setCurrentLocale] = useState(locale)
|
|
26
|
-
const [isLoading, setLoading] = useState(
|
|
30
|
+
const [isLoading, setLoading] = useState(true)
|
|
27
31
|
const [error, setError] = useState(false)
|
|
28
32
|
|
|
33
|
+
const getTextContent = (contentID: string): string => {
|
|
34
|
+
return (
|
|
35
|
+
textContents
|
|
36
|
+
?.find(textContent => textContent.code === contentID)
|
|
37
|
+
?.content.text.find(text => text.locale === currentLocale)?.message ||
|
|
38
|
+
''
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getImageSrc = (contentID: string): string => {
|
|
43
|
+
return (
|
|
44
|
+
imageContents
|
|
45
|
+
?.find(imageContent => imageContent.code === contentID)
|
|
46
|
+
?.content.image.find(image => image.locale === currentLocale)?.file ||
|
|
47
|
+
''
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (textContents || imageContents) {
|
|
53
|
+
const contentsObject = {} as Record<keyof T, string>
|
|
54
|
+
for (const [key, value] of Object.entries<string>(mapContents)) {
|
|
55
|
+
contentsObject[key] = getTextContent(value) || getImageSrc(value)
|
|
56
|
+
}
|
|
57
|
+
setContents(contentsObject)
|
|
58
|
+
}
|
|
59
|
+
}, [textContents, imageContents, currentLocale])
|
|
60
|
+
|
|
29
61
|
useEffect(() => {
|
|
30
62
|
const getResponseContents = async () => {
|
|
31
|
-
setLoading(true)
|
|
32
63
|
const url = `${apiUrl}/webview/${version}`
|
|
33
64
|
try {
|
|
34
65
|
const response = await axios.get<WebviewContentsResponse>(url, {
|
|
@@ -54,18 +85,6 @@ export function useWebviewContents({
|
|
|
54
85
|
getResponseContents()
|
|
55
86
|
}, [])
|
|
56
87
|
|
|
57
|
-
const getTextContent = (contentID: string): string | undefined => {
|
|
58
|
-
return textContents
|
|
59
|
-
?.find(textContent => textContent.code === contentID)
|
|
60
|
-
?.content.text.find(text => text.locale === currentLocale)?.message
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const getImageSrc = (contentID: string): string | undefined => {
|
|
64
|
-
return imageContents
|
|
65
|
-
?.find(imageContent => imageContent.code === contentID)
|
|
66
|
-
?.content.image.find(image => image.locale === currentLocale)?.file
|
|
67
|
-
}
|
|
68
|
-
|
|
69
88
|
return {
|
|
70
89
|
isLoading,
|
|
71
90
|
error,
|
|
@@ -73,6 +92,7 @@ export function useWebviewContents({
|
|
|
73
92
|
getTextContent,
|
|
74
93
|
getImageSrc,
|
|
75
94
|
setCurrentLocale,
|
|
95
|
+
contents,
|
|
76
96
|
},
|
|
77
97
|
}
|
|
78
98
|
}
|