@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.
Files changed (57) hide show
  1. package/bundle/bundle.umd.js +57 -31
  2. package/bundle/bundle.umd.min.js +1 -1
  3. package/bundle/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
  4. package/bundle/components/Header/useChatBot.d.ts +4 -1
  5. package/dist/components/Header/HeaderChatBotButton.js +2 -2
  6. package/dist/components/Header/HeaderChatBotButton.js.map +1 -1
  7. package/dist/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
  8. package/dist/components/Header/HeaderSecondaryMenuButton.js +3 -3
  9. package/dist/components/Header/HeaderSecondaryMenuButton.js.map +1 -1
  10. package/dist/components/Header/useChatBot.d.ts +4 -1
  11. package/dist/components/Header/useChatBot.js +38 -16
  12. package/dist/components/Header/useChatBot.js.map +1 -1
  13. package/dist/hooks/useExternalNS.js +13 -9
  14. package/dist/hooks/useExternalNS.js.map +1 -1
  15. package/lib/components/Header/HeaderChatBotButton.js +2 -2
  16. package/lib/components/Header/HeaderChatBotButton.js.map +1 -1
  17. package/lib/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
  18. package/lib/components/Header/HeaderSecondaryMenuButton.js +3 -3
  19. package/lib/components/Header/HeaderSecondaryMenuButton.js.map +1 -1
  20. package/lib/components/Header/useChatBot.d.ts +4 -1
  21. package/lib/components/Header/useChatBot.js +39 -17
  22. package/lib/components/Header/useChatBot.js.map +1 -1
  23. package/lib/hooks/useExternalNS.js +13 -9
  24. package/lib/hooks/useExternalNS.js.map +1 -1
  25. package/mobile/bundle/bundle.umd.js +6 -6
  26. package/mobile/bundle/bundle.umd.min.js +1 -1
  27. package/mobile/bundle/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
  28. package/mobile/bundle/components/Header/useChatBot.d.ts +4 -1
  29. package/mobile/dist/components/Header/HeaderChatBotButton.js +2 -2
  30. package/mobile/dist/components/Header/HeaderChatBotButton.js.map +1 -1
  31. package/mobile/dist/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
  32. package/mobile/dist/components/Header/HeaderSecondaryMenuButton.js +3 -3
  33. package/mobile/dist/components/Header/HeaderSecondaryMenuButton.js.map +1 -1
  34. package/mobile/dist/components/Header/useChatBot.d.ts +4 -1
  35. package/mobile/dist/components/Header/useChatBot.js +38 -16
  36. package/mobile/dist/components/Header/useChatBot.js.map +1 -1
  37. package/mobile/dist/hooks/useExternalNS.js +13 -9
  38. package/mobile/dist/hooks/useExternalNS.js.map +1 -1
  39. package/mobile/lib/components/Header/HeaderChatBotButton.js +2 -2
  40. package/mobile/lib/components/Header/HeaderChatBotButton.js.map +1 -1
  41. package/mobile/lib/components/Header/HeaderSecondaryMenuButton.d.ts +1 -0
  42. package/mobile/lib/components/Header/HeaderSecondaryMenuButton.js +3 -3
  43. package/mobile/lib/components/Header/HeaderSecondaryMenuButton.js.map +1 -1
  44. package/mobile/lib/components/Header/useChatBot.d.ts +4 -1
  45. package/mobile/lib/components/Header/useChatBot.js +39 -17
  46. package/mobile/lib/components/Header/useChatBot.js.map +1 -1
  47. package/mobile/lib/hooks/useExternalNS.js +13 -9
  48. package/mobile/lib/hooks/useExternalNS.js.map +1 -1
  49. package/mobile/src/components/Header/HeaderChatBotButton.tsx +2 -1
  50. package/mobile/src/components/Header/HeaderSecondaryMenuButton.tsx +13 -7
  51. package/mobile/src/components/Header/useChatBot.ts +58 -26
  52. package/mobile/src/hooks/useExternalNS.ts +14 -9
  53. package/package.json +1 -1
  54. package/src/components/Header/HeaderChatBotButton.tsx +2 -1
  55. package/src/components/Header/HeaderSecondaryMenuButton.tsx +13 -7
  56. package/src/components/Header/useChatBot.ts +58 -26
  57. 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.createElement('link');
44
- link.href = url;
45
- link.rel = 'stylesheet';
43
+ const link = globalThis.document.getElementById(url);
46
44
 
47
- document.head.appendChild(link);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redneckz/wildless-cms-uni-blocks",
3
- "version": "0.14.774",
3
+ "version": "0.14.776",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "ЦК",
@@ -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
- <Img
62
- image={image}
63
- className={style('h-full', {
64
- 'bg-main-divider/20 rounded-full': isRounded,
65
- })}
66
- imageClassName="group-hover/btn:text-primary-hover group-hover/btn:invert-0"
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
- return async (ev: PreventableEventWithTarget) => {
25
- if (!chatUrl) {
26
- return;
27
- }
27
+ const load = useCallback(
28
+ (ev: PreventableEventWithTarget) => {
29
+ if (!chatUrl) {
30
+ return;
31
+ }
28
32
 
29
- if (chat !== 'personal') {
30
- initializeExternalStylesheet(`${chatUrl}/bundle.css`);
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
- const businessChat = (await initializeExternalNS(
33
- CHAT_NAMESPACE,
34
- `${chatUrl}/bundle.js`,
35
- true,
36
- )) as WebChat;
43
+ return { load, isLoading };
44
+ };
37
45
 
38
- if (businessChat?.render) {
39
- businessChat.render(CHAT_FRAME_ID, true);
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
- if (!target?.classList.contains(CHAT_BUTTON_EXTERNAL_NAME)) {
45
- target?.classList.add(CHAT_BUTTON_EXTERNAL_NAME);
46
- }
49
+ if (!target?.classList.contains(CHAT_BUTTON_EXTERNAL_NAME)) {
50
+ target?.classList.add(CHAT_BUTTON_EXTERNAL_NAME);
51
+ }
47
52
 
48
- const chatFrame = document.getElementById(CHAT_FRAME_ID);
49
- if (!chatFrame) {
50
- initializeExternalNS(CHAT_NAMESPACE, chatUrl);
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.createElement('link');
44
- link.href = url;
45
- link.rel = 'stylesheet';
43
+ const link = globalThis.document.getElementById(url);
46
44
 
47
- document.head.appendChild(link);
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);