@botonic/plugin-flow-builder 0.27.8-alpha.1 → 0.27.8-alpha.3
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/content-fields/flow-handoff.d.ts +1 -1
- package/lib/cjs/content-fields/flow-handoff.js +2 -2
- package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
- package/lib/cjs/webview/contents-context.d.ts +2 -2
- package/lib/cjs/webview/contents-context.js +27 -2
- package/lib/cjs/webview/contents-context.js.map +1 -1
- package/lib/cjs/webview/index.d.ts +1 -1
- package/lib/cjs/webview/index.js +2 -2
- package/lib/cjs/webview/index.js.map +1 -1
- package/lib/cjs/webview/types.d.ts +4 -3
- package/lib/cjs/webview/use-webview-contents.d.ts +2 -2
- package/lib/cjs/webview/use-webview-contents.js.map +1 -1
- package/lib/esm/content-fields/flow-handoff.d.ts +1 -1
- package/lib/esm/content-fields/flow-handoff.js +4 -4
- package/lib/esm/content-fields/flow-handoff.js.map +1 -1
- package/lib/esm/webview/contents-context.d.ts +2 -2
- package/lib/esm/webview/contents-context.js +25 -1
- package/lib/esm/webview/contents-context.js.map +1 -1
- package/lib/esm/webview/index.d.ts +1 -1
- package/lib/esm/webview/index.js +1 -1
- package/lib/esm/webview/index.js.map +1 -1
- package/lib/esm/webview/types.d.ts +4 -3
- package/lib/esm/webview/use-webview-contents.d.ts +2 -2
- package/lib/esm/webview/use-webview-contents.js.map +1 -1
- package/package.json +1 -1
- package/src/content-fields/flow-handoff.tsx +7 -3
- package/src/webview/contents-context.ts +33 -10
- package/src/webview/index.ts +1 -1
- package/src/webview/types.ts +5 -3
- package/src/webview/use-webview-contents.ts +4 -3
|
@@ -10,5 +10,5 @@ export declare class FlowHandoff extends ContentFieldsBase {
|
|
|
10
10
|
static fromHubtypeCMS(cmsHandoff: HtHandoffNode, locale: string, cmsApi: FlowBuilderApi): FlowHandoff;
|
|
11
11
|
private static getOnFinishPayload;
|
|
12
12
|
doHandoff(request: ActionRequest): Promise<void>;
|
|
13
|
-
toBotonic(): JSX.Element;
|
|
13
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element;
|
|
14
14
|
}
|
|
@@ -39,8 +39,8 @@ class FlowHandoff extends content_fields_base_1.ContentFieldsBase {
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
toBotonic() {
|
|
43
|
-
return (0, jsx_runtime_1.jsx)(react_1.WebchatSettings, { enableUserInput: true });
|
|
42
|
+
toBotonic(id, request) {
|
|
43
|
+
return (0, core_1.isDev)(request.session) || (0, core_1.isWebchat)(request.session) ? ((0, jsx_runtime_1.jsx)(react_1.WebchatSettings, { enableUserInput: true }, id)) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}));
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
exports.FlowHandoff = FlowHandoff;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-handoff.js","sourceRoot":"","sources":["../../../src/content-fields/flow-handoff.tsx"],"names":[],"mappings":";;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"flow-handoff.js","sourceRoot":"","sources":["../../../src/content-fields/flow-handoff.tsx"],"names":[],"mappings":";;;;;AAAA,wCAAgE;AAChE,0CAA+D;AAI/D,+DAAyD;AAGzD,MAAa,WAAY,SAAQ,uCAAiB;IAMhD,MAAM,CAAC,cAAc,CACnB,UAAyB,EACzB,MAAc,EACd,MAAsB;QAEtB,MAAM,UAAU,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;QACjD,UAAU,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;QACjC,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC1E,UAAU,CAAC,eAAe,GAAG,IAAI,CAAC,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAA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ACF,kDAAK,CACN,CAAA;IACH,CAAC;CACF;AAxDD,kCAwDC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { WebviewContentsContextType } from './types';
|
|
3
|
-
export declare const
|
|
2
|
+
import { MapContentsType, WebviewContentsContextType } from './types';
|
|
3
|
+
export declare const createWebviewContentsContext: <T extends MapContentsType>() => import("react").Context<WebviewContentsContextType<T>>;
|
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createWebviewContentsContext = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
|
|
5
|
+
/*
|
|
6
|
+
Define a generic type parameter for your context
|
|
7
|
+
WebviewContentsContext is a function that returns a context object with the type parameter T
|
|
8
|
+
It is necessary to create the context outside the component
|
|
9
|
+
e.g.
|
|
10
|
+
|
|
11
|
+
interface WebviewContents {
|
|
12
|
+
textIntro: string
|
|
13
|
+
image2: string
|
|
14
|
+
headerWebview: string
|
|
15
|
+
image: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const MyWebviewContentsContext = WebviewContentsContext<WebviewContents>()
|
|
19
|
+
|
|
20
|
+
Then you can use it in your component like this:
|
|
21
|
+
<MyWebviewContentsContext.Provider value={webviewContentsContext}>
|
|
22
|
+
...// your components
|
|
23
|
+
</MyWebviewContentsContext.Provider>
|
|
24
|
+
|
|
25
|
+
In your components you can use the context to read contents like this:
|
|
26
|
+
|
|
27
|
+
const { contents } = useContext(MyWebviewContentsContext)
|
|
28
|
+
*/
|
|
29
|
+
const createWebviewContentsContext = () => (0, react_1.createContext)({
|
|
6
30
|
getTextContent: () => '',
|
|
7
31
|
getImageSrc: () => '',
|
|
8
32
|
setCurrentLocale: () => undefined,
|
|
9
33
|
contents: {},
|
|
10
34
|
});
|
|
35
|
+
exports.createWebviewContentsContext = createWebviewContentsContext;
|
|
11
36
|
//# 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;
|
|
1
|
+
{"version":3,"file":"contents-context.js","sourceRoot":"","sources":["../../../src/webview/contents-context.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAIrC;;;;;;;;;;;;;;;;;;;;;;;EAuBE;AACK,MAAM,4BAA4B,GAAG,GAA8B,EAAE,CAC1E,IAAA,qBAAa,EAAgC;IAC3C,cAAc,EAAE,GAAG,EAAE,CAAC,EAAE;IACxB,WAAW,EAAE,GAAG,EAAE,CAAC,EAAE;IACrB,gBAAgB,EAAE,GAAG,EAAE,CAAC,SAAS;IACjC,QAAQ,EAAE,EAA6B;CACxC,CAAC,CAAA;AANS,QAAA,4BAA4B,gCAMrC"}
|
package/lib/cjs/webview/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useWebviewContents = exports.
|
|
3
|
+
exports.useWebviewContents = exports.createWebviewContentsContext = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
var contents_context_1 = require("./contents-context");
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "createWebviewContentsContext", { enumerable: true, get: function () { return contents_context_1.createWebviewContentsContext; } });
|
|
7
7
|
tslib_1.__exportStar(require("./types"), exports);
|
|
8
8
|
var use_webview_contents_1 = require("./use-webview-contents");
|
|
9
9
|
Object.defineProperty(exports, "useWebviewContents", { enumerable: true, get: function () { return use_webview_contents_1.useWebviewContents; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/webview/index.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/webview/index.ts"],"names":[],"mappings":";;;;AAAA,uDAAiE;AAAxD,gIAAA,4BAA4B,OAAA;AACrC,kDAAuB;AACvB,+DAA2D;AAAlD,0HAAA,kBAAkB,OAAA"}
|
|
@@ -26,7 +26,8 @@ export interface WebviewImageContent {
|
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
export
|
|
29
|
+
export type MapContentsType = Record<string, string>;
|
|
30
|
+
export interface UseWebviewContentsProps<T extends MapContentsType> {
|
|
30
31
|
apiUrl?: string;
|
|
31
32
|
version?: FlowBuilderJSONVersion;
|
|
32
33
|
orgId: string;
|
|
@@ -35,12 +36,12 @@ export interface UseWebviewContentsProps<T> {
|
|
|
35
36
|
locale: string;
|
|
36
37
|
mapContents: Record<keyof T, string>;
|
|
37
38
|
}
|
|
38
|
-
export interface UseWebviewContents<T> {
|
|
39
|
+
export interface UseWebviewContents<T extends MapContentsType> {
|
|
39
40
|
isLoading: boolean;
|
|
40
41
|
error: boolean;
|
|
41
42
|
webviewContentsContext: WebviewContentsContextType<T>;
|
|
42
43
|
}
|
|
43
|
-
export interface WebviewContentsContextType<T> {
|
|
44
|
+
export interface WebviewContentsContextType<T extends MapContentsType> {
|
|
44
45
|
getTextContent: (code: string) => string;
|
|
45
46
|
getImageSrc: (code: string) => string;
|
|
46
47
|
setCurrentLocale: (locale: string) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { UseWebviewContents, UseWebviewContentsProps } from './types';
|
|
2
|
-
export declare function useWebviewContents<T>({ apiUrl, version, orgId, botId, webviewId, locale, mapContents, }: UseWebviewContentsProps<T>): UseWebviewContents<T>;
|
|
1
|
+
import { MapContentsType, UseWebviewContents, UseWebviewContentsProps } from './types';
|
|
2
|
+
export declare function useWebviewContents<T extends MapContentsType>({ apiUrl, version, orgId, botId, webviewId, locale, mapContents, }: UseWebviewContentsProps<T>): UseWebviewContents<T>;
|
|
@@ -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,
|
|
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,mCAQgB;AAEhB,SAAgB,kBAAkB,CAA4B,EAC5D,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,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAA;IAEzC,MAAM,cAAc,GAAG,CAAC,SAAiB,EAAU,EAAE;;QACnD,OAAO,CACL,CAAA,MAAA,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CACR,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,KAAK,SAAS,CAAC,0CACnD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAA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AoB,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"}
|
|
@@ -10,5 +10,5 @@ export declare class FlowHandoff extends ContentFieldsBase {
|
|
|
10
10
|
static fromHubtypeCMS(cmsHandoff: HtHandoffNode, locale: string, cmsApi: FlowBuilderApi): FlowHandoff;
|
|
11
11
|
private static getOnFinishPayload;
|
|
12
12
|
doHandoff(request: ActionRequest): Promise<void>;
|
|
13
|
-
toBotonic(): JSX.Element;
|
|
13
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element;
|
|
14
14
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { HandOffBuilder } from '@botonic/core';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { HandOffBuilder, isDev, isWebchat } from '@botonic/core';
|
|
4
4
|
import { WebchatSettings } from '@botonic/react';
|
|
5
5
|
import { ContentFieldsBase } from './content-fields-base';
|
|
6
6
|
export class FlowHandoff extends ContentFieldsBase {
|
|
@@ -36,8 +36,8 @@ export class FlowHandoff extends ContentFieldsBase {
|
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
toBotonic() {
|
|
40
|
-
return _jsx(WebchatSettings, { enableUserInput: true });
|
|
39
|
+
toBotonic(id, request) {
|
|
40
|
+
return isDev(request.session) || isWebchat(request.session) ? (_jsx(WebchatSettings, { enableUserInput: true }, id)) : (_jsx(_Fragment, {}));
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
//# sourceMappingURL=flow-handoff.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-handoff.js","sourceRoot":"","sources":["../../../src/content-fields/flow-handoff.tsx"],"names":[],"mappings":";;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"flow-handoff.js","sourceRoot":"","sources":["../../../src/content-fields/flow-handoff.tsx"],"names":[],"mappings":";;AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAiB,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAI/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAGzD,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAMhD,MAAM,CAAC,cAAc,CACnB,UAAyB,EACzB,MAAc,EACd,MAAsB;QAEtB,MAAM,UAAU,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;QACjD,UAAU,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;QACj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O,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAC5D,KAAC,eAAe,IAAU,eAAe,EAAE,IAAI,IAAzB,EAAE,CAA2B,CACpD,CAAC,CAAC,CAAC,CACF,mBAAK,CACN,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { WebviewContentsContextType } from './types';
|
|
3
|
-
export declare const
|
|
2
|
+
import { MapContentsType, WebviewContentsContextType } from './types';
|
|
3
|
+
export declare const createWebviewContentsContext: <T extends MapContentsType>() => import("react").Context<WebviewContentsContextType<T>>;
|
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
|
-
|
|
2
|
+
/*
|
|
3
|
+
Define a generic type parameter for your context
|
|
4
|
+
WebviewContentsContext is a function that returns a context object with the type parameter T
|
|
5
|
+
It is necessary to create the context outside the component
|
|
6
|
+
e.g.
|
|
7
|
+
|
|
8
|
+
interface WebviewContents {
|
|
9
|
+
textIntro: string
|
|
10
|
+
image2: string
|
|
11
|
+
headerWebview: string
|
|
12
|
+
image: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const MyWebviewContentsContext = WebviewContentsContext<WebviewContents>()
|
|
16
|
+
|
|
17
|
+
Then you can use it in your component like this:
|
|
18
|
+
<MyWebviewContentsContext.Provider value={webviewContentsContext}>
|
|
19
|
+
...// your components
|
|
20
|
+
</MyWebviewContentsContext.Provider>
|
|
21
|
+
|
|
22
|
+
In your components you can use the context to read contents like this:
|
|
23
|
+
|
|
24
|
+
const { contents } = useContext(MyWebviewContentsContext)
|
|
25
|
+
*/
|
|
26
|
+
export const createWebviewContentsContext = () => createContext({
|
|
3
27
|
getTextContent: () => '',
|
|
4
28
|
getImageSrc: () => '',
|
|
5
29
|
setCurrentLocale: () => undefined,
|
|
@@ -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,
|
|
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;;;;;;;;;;;;;;;;;;;;;;;EAuBE;AACF,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAA8B,EAAE,CAC1E,aAAa,CAAgC;IAC3C,cAAc,EAAE,GAAG,EAAE,CAAC,EAAE;IACxB,WAAW,EAAE,GAAG,EAAE,CAAC,EAAE;IACrB,gBAAgB,EAAE,GAAG,EAAE,CAAC,SAAS;IACjC,QAAQ,EAAE,EAA6B;CACxC,CAAC,CAAA"}
|
package/lib/esm/webview/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/webview/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/webview/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAA;AACjE,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -26,7 +26,8 @@ export interface WebviewImageContent {
|
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
export
|
|
29
|
+
export type MapContentsType = Record<string, string>;
|
|
30
|
+
export interface UseWebviewContentsProps<T extends MapContentsType> {
|
|
30
31
|
apiUrl?: string;
|
|
31
32
|
version?: FlowBuilderJSONVersion;
|
|
32
33
|
orgId: string;
|
|
@@ -35,12 +36,12 @@ export interface UseWebviewContentsProps<T> {
|
|
|
35
36
|
locale: string;
|
|
36
37
|
mapContents: Record<keyof T, string>;
|
|
37
38
|
}
|
|
38
|
-
export interface UseWebviewContents<T> {
|
|
39
|
+
export interface UseWebviewContents<T extends MapContentsType> {
|
|
39
40
|
isLoading: boolean;
|
|
40
41
|
error: boolean;
|
|
41
42
|
webviewContentsContext: WebviewContentsContextType<T>;
|
|
42
43
|
}
|
|
43
|
-
export interface WebviewContentsContextType<T> {
|
|
44
|
+
export interface WebviewContentsContextType<T extends MapContentsType> {
|
|
44
45
|
getTextContent: (code: string) => string;
|
|
45
46
|
getImageSrc: (code: string) => string;
|
|
46
47
|
setCurrentLocale: (locale: string) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { UseWebviewContents, UseWebviewContentsProps } from './types';
|
|
2
|
-
export declare function useWebviewContents<T>({ apiUrl, version, orgId, botId, webviewId, locale, mapContents, }: UseWebviewContentsProps<T>): UseWebviewContents<T>;
|
|
1
|
+
import { MapContentsType, UseWebviewContents, UseWebviewContentsProps } from './types';
|
|
2
|
+
export declare function useWebviewContents<T extends MapContentsType>({ apiUrl, version, orgId, botId, webviewId, locale, mapContents, }: UseWebviewContentsProps<T>): UseWebviewContents<T>;
|
|
@@ -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,
|
|
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,CAA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Q,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CACjE,cAAc,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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HandOffBuilder } from '@botonic/core'
|
|
1
|
+
import { HandOffBuilder, isDev, isWebchat } from '@botonic/core'
|
|
2
2
|
import { ActionRequest, WebchatSettings } from '@botonic/react'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
|
|
@@ -55,7 +55,11 @@ export class FlowHandoff extends ContentFieldsBase {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
toBotonic(): JSX.Element {
|
|
59
|
-
return
|
|
58
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element {
|
|
59
|
+
return isDev(request.session) || isWebchat(request.session) ? (
|
|
60
|
+
<WebchatSettings key={id} enableUserInput={true} />
|
|
61
|
+
) : (
|
|
62
|
+
<></>
|
|
63
|
+
)
|
|
60
64
|
}
|
|
61
65
|
}
|
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
import { createContext } from 'react'
|
|
2
2
|
|
|
3
|
-
import { WebviewContentsContextType } from './types'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
import { MapContentsType, WebviewContentsContextType } from './types'
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
Define a generic type parameter for your context
|
|
7
|
+
WebviewContentsContext is a function that returns a context object with the type parameter T
|
|
8
|
+
It is necessary to create the context outside the component
|
|
9
|
+
e.g.
|
|
10
|
+
|
|
11
|
+
interface WebviewContents {
|
|
12
|
+
textIntro: string
|
|
13
|
+
image2: string
|
|
14
|
+
headerWebview: string
|
|
15
|
+
image: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const MyWebviewContentsContext = WebviewContentsContext<WebviewContents>()
|
|
19
|
+
|
|
20
|
+
Then you can use it in your component like this:
|
|
21
|
+
<MyWebviewContentsContext.Provider value={webviewContentsContext}>
|
|
22
|
+
...// your components
|
|
23
|
+
</MyWebviewContentsContext.Provider>
|
|
24
|
+
|
|
25
|
+
In your components you can use the context to read contents like this:
|
|
26
|
+
|
|
27
|
+
const { contents } = useContext(MyWebviewContentsContext)
|
|
28
|
+
*/
|
|
29
|
+
export const createWebviewContentsContext = <T extends MapContentsType>() =>
|
|
30
|
+
createContext<WebviewContentsContextType<T>>({
|
|
31
|
+
getTextContent: () => '',
|
|
32
|
+
getImageSrc: () => '',
|
|
33
|
+
setCurrentLocale: () => undefined,
|
|
34
|
+
contents: {} as Record<keyof T, string>,
|
|
35
|
+
})
|
package/src/webview/index.ts
CHANGED
package/src/webview/types.ts
CHANGED
|
@@ -25,7 +25,9 @@ export interface WebviewImageContent {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export
|
|
28
|
+
export type MapContentsType = Record<string, string>
|
|
29
|
+
|
|
30
|
+
export interface UseWebviewContentsProps<T extends MapContentsType> {
|
|
29
31
|
apiUrl?: string
|
|
30
32
|
version?: FlowBuilderJSONVersion
|
|
31
33
|
orgId: string
|
|
@@ -35,13 +37,13 @@ export interface UseWebviewContentsProps<T> {
|
|
|
35
37
|
mapContents: Record<keyof T, string>
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
export interface UseWebviewContents<T> {
|
|
40
|
+
export interface UseWebviewContents<T extends MapContentsType> {
|
|
39
41
|
isLoading: boolean
|
|
40
42
|
error: boolean
|
|
41
43
|
webviewContentsContext: WebviewContentsContextType<T>
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
export interface WebviewContentsContextType<T> {
|
|
46
|
+
export interface WebviewContentsContextType<T extends MapContentsType> {
|
|
45
47
|
getTextContent: (code: string) => string
|
|
46
48
|
getImageSrc: (code: string) => string
|
|
47
49
|
setCurrentLocale: (locale: string) => void
|
|
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'
|
|
|
4
4
|
import { FLOW_BUILDER_API_URL_PROD } from '../constants'
|
|
5
5
|
import { FlowBuilderJSONVersion } from '../types'
|
|
6
6
|
import {
|
|
7
|
+
MapContentsType,
|
|
7
8
|
UseWebviewContents,
|
|
8
9
|
UseWebviewContentsProps,
|
|
9
10
|
WebviewContentsResponse,
|
|
@@ -12,7 +13,7 @@ import {
|
|
|
12
13
|
WebviewTextContent,
|
|
13
14
|
} from './types'
|
|
14
15
|
|
|
15
|
-
export function useWebviewContents<T>({
|
|
16
|
+
export function useWebviewContents<T extends MapContentsType>({
|
|
16
17
|
apiUrl = FLOW_BUILDER_API_URL_PROD,
|
|
17
18
|
version = FlowBuilderJSONVersion.LATEST,
|
|
18
19
|
orgId,
|
|
@@ -50,11 +51,11 @@ export function useWebviewContents<T>({
|
|
|
50
51
|
|
|
51
52
|
useEffect(() => {
|
|
52
53
|
if (textContents || imageContents) {
|
|
53
|
-
const contentsObject = {}
|
|
54
|
+
const contentsObject = {}
|
|
54
55
|
for (const [key, value] of Object.entries<string>(mapContents)) {
|
|
55
56
|
contentsObject[key] = getTextContent(value) || getImageSrc(value)
|
|
56
57
|
}
|
|
57
|
-
setContents(contentsObject)
|
|
58
|
+
setContents(contentsObject as Record<keyof T, string>)
|
|
58
59
|
}
|
|
59
60
|
}, [textContents, imageContents, currentLocale])
|
|
60
61
|
|