@redneckz/wildless-cms-uni-blocks 0.14.774 → 0.14.776
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/bundle/bundle.umd.js +57 -31
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
- package/bundle/components/Header/useChatBot.d.ts +4 -1
- package/dist/components/Header/HeaderChatBotButton.js +2 -2
- package/dist/components/Header/HeaderChatBotButton.js.map +1 -1
- package/dist/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
- package/dist/components/Header/HeaderSecondaryMenuButton.js +3 -3
- package/dist/components/Header/HeaderSecondaryMenuButton.js.map +1 -1
- package/dist/components/Header/useChatBot.d.ts +4 -1
- package/dist/components/Header/useChatBot.js +38 -16
- package/dist/components/Header/useChatBot.js.map +1 -1
- package/dist/hooks/useExternalNS.js +13 -9
- package/dist/hooks/useExternalNS.js.map +1 -1
- package/lib/components/Header/HeaderChatBotButton.js +2 -2
- package/lib/components/Header/HeaderChatBotButton.js.map +1 -1
- package/lib/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
- package/lib/components/Header/HeaderSecondaryMenuButton.js +3 -3
- package/lib/components/Header/HeaderSecondaryMenuButton.js.map +1 -1
- package/lib/components/Header/useChatBot.d.ts +4 -1
- package/lib/components/Header/useChatBot.js +39 -17
- package/lib/components/Header/useChatBot.js.map +1 -1
- package/lib/hooks/useExternalNS.js +13 -9
- package/lib/hooks/useExternalNS.js.map +1 -1
- package/mobile/bundle/bundle.umd.js +6 -6
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
- package/mobile/bundle/components/Header/useChatBot.d.ts +4 -1
- package/mobile/dist/components/Header/HeaderChatBotButton.js +2 -2
- package/mobile/dist/components/Header/HeaderChatBotButton.js.map +1 -1
- package/mobile/dist/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
- package/mobile/dist/components/Header/HeaderSecondaryMenuButton.js +3 -3
- package/mobile/dist/components/Header/HeaderSecondaryMenuButton.js.map +1 -1
- package/mobile/dist/components/Header/useChatBot.d.ts +4 -1
- package/mobile/dist/components/Header/useChatBot.js +38 -16
- package/mobile/dist/components/Header/useChatBot.js.map +1 -1
- package/mobile/dist/hooks/useExternalNS.js +13 -9
- package/mobile/dist/hooks/useExternalNS.js.map +1 -1
- package/mobile/lib/components/Header/HeaderChatBotButton.js +2 -2
- package/mobile/lib/components/Header/HeaderChatBotButton.js.map +1 -1
- package/mobile/lib/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
- package/mobile/lib/components/Header/HeaderSecondaryMenuButton.js +3 -3
- package/mobile/lib/components/Header/HeaderSecondaryMenuButton.js.map +1 -1
- package/mobile/lib/components/Header/useChatBot.d.ts +4 -1
- package/mobile/lib/components/Header/useChatBot.js +39 -17
- package/mobile/lib/components/Header/useChatBot.js.map +1 -1
- package/mobile/lib/hooks/useExternalNS.js +13 -9
- package/mobile/lib/hooks/useExternalNS.js.map +1 -1
- package/mobile/src/components/Header/HeaderChatBotButton.tsx +2 -1
- package/mobile/src/components/Header/HeaderSecondaryMenuButton.tsx +13 -7
- package/mobile/src/components/Header/useChatBot.ts +58 -26
- package/mobile/src/hooks/useExternalNS.ts +14 -9
- package/package.json +1 -1
- package/src/components/Header/HeaderChatBotButton.tsx +2 -1
- package/src/components/Header/HeaderSecondaryMenuButton.tsx +13 -7
- package/src/components/Header/useChatBot.ts +58 -26
- package/src/hooks/useExternalNS.ts +14 -9
|
@@ -3,7 +3,7 @@ import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
|
3
3
|
export const getNS = <NS>(_: string): NS | undefined => (globalThis as any)[_];
|
|
4
4
|
|
|
5
5
|
export const initializeExternalNS = <NS>(namespaceName: string, url: string, isModule = false) => {
|
|
6
|
-
const script = document.getElementById(url);
|
|
6
|
+
const script = globalThis.document.getElementById(url);
|
|
7
7
|
|
|
8
8
|
if (script) {
|
|
9
9
|
const ns = getNS<NS>(namespaceName);
|
|
@@ -19,7 +19,7 @@ export const initializeExternalNS = <NS>(namespaceName: string, url: string, isM
|
|
|
19
19
|
}
|
|
20
20
|
} else {
|
|
21
21
|
return new Promise<NS | undefined>((resolve, reject) => {
|
|
22
|
-
const newScript = document.createElement('script');
|
|
22
|
+
const newScript = globalThis.document.createElement('script');
|
|
23
23
|
|
|
24
24
|
newScript.src = url;
|
|
25
25
|
newScript.async = true;
|
|
@@ -34,17 +34,22 @@ export const initializeExternalNS = <NS>(namespaceName: string, url: string, isM
|
|
|
34
34
|
reject(error);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
document.head.appendChild(newScript);
|
|
37
|
+
globalThis.document.head.appendChild(newScript);
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export const initializeExternalStylesheet = (url = '') => {
|
|
43
|
-
const link = document.
|
|
44
|
-
link.href = url;
|
|
45
|
-
link.rel = 'stylesheet';
|
|
43
|
+
const link = globalThis.document.getElementById(url);
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
if (!link) {
|
|
46
|
+
const newLink = globalThis.document.createElement('link');
|
|
47
|
+
newLink.href = url;
|
|
48
|
+
newLink.id = url;
|
|
49
|
+
newLink.rel = 'stylesheet';
|
|
50
|
+
|
|
51
|
+
globalThis.document.head.appendChild(newLink);
|
|
52
|
+
}
|
|
48
53
|
};
|
|
49
54
|
|
|
50
55
|
export function useExternalNS<NS>(
|
|
@@ -71,9 +76,9 @@ export function useExternalNS<NS>(
|
|
|
71
76
|
isMounted = false;
|
|
72
77
|
|
|
73
78
|
if (unmountNS) {
|
|
74
|
-
const script = document.getElementById(url);
|
|
79
|
+
const script = globalThis.document.getElementById(url);
|
|
75
80
|
if (script) {
|
|
76
|
-
document.head.removeChild(script);
|
|
81
|
+
globalThis.document.head.removeChild(script);
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
setExternalNS(undefined);
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@ interface HeaderChatBotButtonProps {
|
|
|
16
16
|
|
|
17
17
|
export const HeaderChatBotButton = JSX<HeaderChatBotButtonProps>(
|
|
18
18
|
({ chat = 'personal', iconVersion, className, ariaLabel = 'Чат', version }) => {
|
|
19
|
-
const load = useChatBot(chat);
|
|
19
|
+
const { load, isLoading } = useChatBot(chat);
|
|
20
20
|
|
|
21
21
|
return (
|
|
22
22
|
<HeaderSecondaryMenuButton
|
|
@@ -27,6 +27,7 @@ export const HeaderChatBotButton = JSX<HeaderChatBotButtonProps>(
|
|
|
27
27
|
buttonSize="large"
|
|
28
28
|
isGrayBg={true}
|
|
29
29
|
version={version}
|
|
30
|
+
isLoading={isLoading}
|
|
30
31
|
/>
|
|
31
32
|
);
|
|
32
33
|
},
|
|
@@ -16,6 +16,7 @@ export interface HeaderSecondaryMenuButtonProps extends ImageContent, AspectsPro
|
|
|
16
16
|
ariaLabel?: string;
|
|
17
17
|
onClick?: (ev: PreventableEventWithTarget) => void;
|
|
18
18
|
version?: BlockVersion;
|
|
19
|
+
isLoading?: boolean;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const BUTTON_SIZE_STYLE = {
|
|
@@ -35,6 +36,7 @@ export const HeaderSecondaryMenuButton = JSX<HeaderSecondaryMenuButtonProps>(
|
|
|
35
36
|
data,
|
|
36
37
|
onClick,
|
|
37
38
|
version,
|
|
39
|
+
isLoading,
|
|
38
40
|
}) => {
|
|
39
41
|
const grayBg = isGrayBg && !isRounded ? 'bg-main-divider' : '';
|
|
40
42
|
const bgColor = version === 'transparent' ? 'backdrop-opacity-30 bg-white/30' : grayBg;
|
|
@@ -58,13 +60,17 @@ export const HeaderSecondaryMenuButton = JSX<HeaderSecondaryMenuButtonProps>(
|
|
|
58
60
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
59
61
|
{...getAspectsAttributes(data)}
|
|
60
62
|
>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
{isLoading ? (
|
|
64
|
+
<div className="w-full h-full rounded-full border-4 border-r-transparent animate-spin text-primary-main" />
|
|
65
|
+
) : (
|
|
66
|
+
<Img
|
|
67
|
+
image={image}
|
|
68
|
+
className={style('h-full', {
|
|
69
|
+
'bg-main-divider/20 rounded-full': isRounded,
|
|
70
|
+
})}
|
|
71
|
+
imageClassName="group-hover/btn:text-primary-hover group-hover/btn:invert-0"
|
|
72
|
+
/>
|
|
73
|
+
)}
|
|
68
74
|
</button>
|
|
69
75
|
);
|
|
70
76
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect } from '@redneckz/uni-jsx/lib/hooks';
|
|
1
|
+
import { useCallback, useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
2
|
import { initializeExternalNS, initializeExternalStylesheet } from '../../hooks/useExternalNS';
|
|
3
3
|
import { type PreventableEventWithTarget } from '../../ui-kit/PreventableEvent';
|
|
4
4
|
|
|
@@ -15,40 +15,72 @@ const CHATBOT_URL: Record<string, string> = {
|
|
|
15
15
|
interface WebChat {
|
|
16
16
|
render?: (id?: string, isOpen?: boolean) => void;
|
|
17
17
|
chatOpen?: () => void;
|
|
18
|
+
chatClose?: () => void;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export const useChatBot = (chat?: string) => {
|
|
22
|
+
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
23
|
+
|
|
21
24
|
useEffect(() => globalThis.localStorage?.setItem(CHAT_STORAGE_NAME, String(Date.now())), []);
|
|
22
25
|
const chatUrl = CHATBOT_URL[chat ?? ''];
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
const load = useCallback(
|
|
28
|
+
(ev: PreventableEventWithTarget) => {
|
|
29
|
+
if (!chatUrl) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
setIsLoading(true);
|
|
34
|
+
if (chat === 'business') {
|
|
35
|
+
renderBusinessChatBot(chatUrl).finally(() => setIsLoading(false));
|
|
36
|
+
} else {
|
|
37
|
+
renderPersonalChatBot(ev, chatUrl).finally(() => setIsLoading(false));
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
[chatUrl, chat],
|
|
41
|
+
);
|
|
31
42
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
`${chatUrl}/bundle.js`,
|
|
35
|
-
true,
|
|
36
|
-
)) as WebChat;
|
|
43
|
+
return { load, isLoading };
|
|
44
|
+
};
|
|
37
45
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
const target = ev.target as HTMLElement;
|
|
46
|
+
const renderPersonalChatBot = async (ev: PreventableEventWithTarget, chatUrl: string) => {
|
|
47
|
+
const target = ev.target as HTMLElement;
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
if (!target?.classList.contains(CHAT_BUTTON_EXTERNAL_NAME)) {
|
|
50
|
+
target?.classList.add(CHAT_BUTTON_EXTERNAL_NAME);
|
|
51
|
+
}
|
|
47
52
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
const chatFrame = globalThis.document.getElementById(CHAT_FRAME_ID);
|
|
54
|
+
if (!chatFrame) {
|
|
55
|
+
await initializeExternalNS(CHAT_NAMESPACE, chatUrl);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const renderBusinessChatBot = async (chatUrl: string) => {
|
|
60
|
+
const businessChat = (await initializeExternalNS(
|
|
61
|
+
CHAT_NAMESPACE,
|
|
62
|
+
`${chatUrl}/bundle.js`,
|
|
63
|
+
true,
|
|
64
|
+
)) as WebChat;
|
|
65
|
+
|
|
66
|
+
initializeExternalStylesheet(`${chatUrl}/bundle.css`);
|
|
67
|
+
|
|
68
|
+
const chatFrame = globalThis.document.getElementById(CHAT_FRAME_ID);
|
|
69
|
+
if (chatFrame) {
|
|
70
|
+
businessChat?.chatOpen?.();
|
|
71
|
+
} else {
|
|
72
|
+
createChatFrame();
|
|
73
|
+
|
|
74
|
+
businessChat?.render?.(CHAT_FRAME_ID, true);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const createChatFrame = () => {
|
|
79
|
+
const chatFrame = globalThis.document.createElement('div');
|
|
80
|
+
chatFrame.id = CHAT_FRAME_ID;
|
|
81
|
+
chatFrame.style.position = 'fixed';
|
|
82
|
+
chatFrame.style.right = '0';
|
|
83
|
+
chatFrame.style.bottom = '0';
|
|
84
|
+
|
|
85
|
+
globalThis.document.body.appendChild(chatFrame);
|
|
54
86
|
};
|
|
@@ -3,7 +3,7 @@ import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
|
3
3
|
export const getNS = <NS>(_: string): NS | undefined => (globalThis as any)[_];
|
|
4
4
|
|
|
5
5
|
export const initializeExternalNS = <NS>(namespaceName: string, url: string, isModule = false) => {
|
|
6
|
-
const script = document.getElementById(url);
|
|
6
|
+
const script = globalThis.document.getElementById(url);
|
|
7
7
|
|
|
8
8
|
if (script) {
|
|
9
9
|
const ns = getNS<NS>(namespaceName);
|
|
@@ -19,7 +19,7 @@ export const initializeExternalNS = <NS>(namespaceName: string, url: string, isM
|
|
|
19
19
|
}
|
|
20
20
|
} else {
|
|
21
21
|
return new Promise<NS | undefined>((resolve, reject) => {
|
|
22
|
-
const newScript = document.createElement('script');
|
|
22
|
+
const newScript = globalThis.document.createElement('script');
|
|
23
23
|
|
|
24
24
|
newScript.src = url;
|
|
25
25
|
newScript.async = true;
|
|
@@ -34,17 +34,22 @@ export const initializeExternalNS = <NS>(namespaceName: string, url: string, isM
|
|
|
34
34
|
reject(error);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
document.head.appendChild(newScript);
|
|
37
|
+
globalThis.document.head.appendChild(newScript);
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export const initializeExternalStylesheet = (url = '') => {
|
|
43
|
-
const link = document.
|
|
44
|
-
link.href = url;
|
|
45
|
-
link.rel = 'stylesheet';
|
|
43
|
+
const link = globalThis.document.getElementById(url);
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
if (!link) {
|
|
46
|
+
const newLink = globalThis.document.createElement('link');
|
|
47
|
+
newLink.href = url;
|
|
48
|
+
newLink.id = url;
|
|
49
|
+
newLink.rel = 'stylesheet';
|
|
50
|
+
|
|
51
|
+
globalThis.document.head.appendChild(newLink);
|
|
52
|
+
}
|
|
48
53
|
};
|
|
49
54
|
|
|
50
55
|
export function useExternalNS<NS>(
|
|
@@ -71,9 +76,9 @@ export function useExternalNS<NS>(
|
|
|
71
76
|
isMounted = false;
|
|
72
77
|
|
|
73
78
|
if (unmountNS) {
|
|
74
|
-
const script = document.getElementById(url);
|
|
79
|
+
const script = globalThis.document.getElementById(url);
|
|
75
80
|
if (script) {
|
|
76
|
-
document.head.removeChild(script);
|
|
81
|
+
globalThis.document.head.removeChild(script);
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
setExternalNS(undefined);
|