@daeryun/dr_components 0.8.6 → 0.8.8
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/dist/components/Daeryuntalk/ViewportHandler.d.ts +1 -0
- package/dist/components/Daeryuntalk/ViewportHandler.jsx +32 -0
- package/dist/components/Daeryuntalk/ViewportHandler.tsx +39 -0
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.d.ts +4 -3
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.js +6 -4
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.ts +6 -3
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.js +8 -2
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.ts +9 -2
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useFullURL.d.ts +1 -0
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useFullURL.jsx +17 -0
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useFullURL.tsx +22 -0
- package/dist/components/Daeryuntalk/index.jsx +2 -0
- package/dist/components/Daeryuntalk/index.tsx +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ViewportHandler(): null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
export default function ViewportHandler() {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
function updateViewport() {
|
|
6
|
+
let viewportMeta = document.querySelector('meta[name="viewport"]');
|
|
7
|
+
if (!viewportMeta) {
|
|
8
|
+
viewportMeta = document.createElement('meta');
|
|
9
|
+
viewportMeta.name = 'viewport';
|
|
10
|
+
document.head.appendChild(viewportMeta);
|
|
11
|
+
}
|
|
12
|
+
const currentContent = viewportMeta.getAttribute('content');
|
|
13
|
+
let newContent = '';
|
|
14
|
+
if (window.screen.width < 360) {
|
|
15
|
+
const scale = window.screen.width / 360;
|
|
16
|
+
newContent = `width=device-width, initial-scale=${scale.toFixed(2)}, user-scalable=yes, maximum-scale=5, viewport-fit=contain`;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
newContent = `width=device-width, initial-scale=1, user-scalable=yes, maximum-scale=5, viewport-fit=contain`;
|
|
20
|
+
}
|
|
21
|
+
if (currentContent !== newContent) {
|
|
22
|
+
viewportMeta.setAttribute('content', newContent);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
updateViewport();
|
|
26
|
+
window.addEventListener('resize', updateViewport);
|
|
27
|
+
return () => {
|
|
28
|
+
window.removeEventListener('resize', updateViewport);
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
|
|
5
|
+
export default function ViewportHandler() {
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
function updateViewport() {
|
|
8
|
+
let viewportMeta = document.querySelector('meta[name="viewport"]') as HTMLMetaElement | null;
|
|
9
|
+
if (!viewportMeta) {
|
|
10
|
+
viewportMeta = document.createElement('meta');
|
|
11
|
+
viewportMeta.name = 'viewport';
|
|
12
|
+
document.head.appendChild(viewportMeta);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const currentContent = viewportMeta.getAttribute('content');
|
|
16
|
+
|
|
17
|
+
let newContent = '';
|
|
18
|
+
if (window.screen.width < 360) {
|
|
19
|
+
const scale = window.screen.width / 360;
|
|
20
|
+
newContent = `width=device-width, initial-scale=${scale.toFixed(2)}, user-scalable=yes, maximum-scale=5, viewport-fit=contain`;
|
|
21
|
+
} else {
|
|
22
|
+
newContent = `width=device-width, initial-scale=1, user-scalable=yes, maximum-scale=5, viewport-fit=contain`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (currentContent !== newContent) {
|
|
26
|
+
viewportMeta.setAttribute('content', newContent);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
updateViewport();
|
|
31
|
+
window.addEventListener('resize', updateViewport);
|
|
32
|
+
|
|
33
|
+
return () => {
|
|
34
|
+
window.removeEventListener('resize', updateViewport);
|
|
35
|
+
};
|
|
36
|
+
}, []);
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
@@ -48,10 +48,11 @@ export declare function connectWebSocket(wsUrl: string, token: string, onMessage
|
|
|
48
48
|
export declare function getChatInquiryMain(channelNumber: string, version?: string): Promise<IDaeryunTalkResponseWrapper<IChatInquiryMainDataResponse>>;
|
|
49
49
|
/**
|
|
50
50
|
* 새 채팅 문의 생성 (개선된 API)
|
|
51
|
-
* @param
|
|
52
|
-
* @
|
|
51
|
+
* @param channelNumber
|
|
52
|
+
* @param currentUrl
|
|
53
|
+
* @param version
|
|
53
54
|
*/
|
|
54
|
-
export declare function generateChatInquiry(channelNumber: string, version?: string): Promise<IDaeryunTalkResponseWrapper<ChatInquiryCreateDataResponse>>;
|
|
55
|
+
export declare function generateChatInquiry(channelNumber: string, currentUrl: string, version?: string): Promise<IDaeryunTalkResponseWrapper<ChatInquiryCreateDataResponse>>;
|
|
55
56
|
/**
|
|
56
57
|
* 채팅 문의 상세 조회 (개선된 API)
|
|
57
58
|
* @param chatInquiryNumber 채팅 문의 번호
|
|
@@ -290,15 +290,17 @@ export function getChatInquiryMain(channelNumber, version) {
|
|
|
290
290
|
}
|
|
291
291
|
/**
|
|
292
292
|
* 새 채팅 문의 생성 (개선된 API)
|
|
293
|
-
* @param
|
|
294
|
-
* @
|
|
293
|
+
* @param channelNumber
|
|
294
|
+
* @param currentUrl
|
|
295
|
+
* @param version
|
|
295
296
|
*/
|
|
296
|
-
export function generateChatInquiry(channelNumber, version) {
|
|
297
|
+
export function generateChatInquiry(channelNumber, currentUrl, version) {
|
|
297
298
|
return __awaiter(this, void 0, void 0, function* () {
|
|
298
299
|
console.log('[새 채팅 문의 생성 시작 (개선)]', version ? `버전: ${version}` : `기본 버전: ${DEFAULT_API_VERSION}`);
|
|
299
300
|
const body = {
|
|
300
301
|
d: {
|
|
301
|
-
channel_number: channelNumber
|
|
302
|
+
channel_number: channelNumber,
|
|
303
|
+
current_url: currentUrl
|
|
302
304
|
}
|
|
303
305
|
};
|
|
304
306
|
try {
|
|
@@ -359,18 +359,21 @@ export async function getChatInquiryMain(
|
|
|
359
359
|
|
|
360
360
|
/**
|
|
361
361
|
* 새 채팅 문의 생성 (개선된 API)
|
|
362
|
-
* @param
|
|
363
|
-
* @
|
|
362
|
+
* @param channelNumber
|
|
363
|
+
* @param currentUrl
|
|
364
|
+
* @param version
|
|
364
365
|
*/
|
|
365
366
|
export async function generateChatInquiry(
|
|
366
367
|
channelNumber: string,
|
|
368
|
+
currentUrl: string,
|
|
367
369
|
version?: string
|
|
368
370
|
): Promise<IDaeryunTalkResponseWrapper<ChatInquiryCreateDataResponse>> {
|
|
369
371
|
console.log('[새 채팅 문의 생성 시작 (개선)]', version ? `버전: ${version}` : `기본 버전: ${DEFAULT_API_VERSION}`);
|
|
370
372
|
|
|
371
373
|
const body = {
|
|
372
374
|
d: {
|
|
373
|
-
channel_number: channelNumber
|
|
375
|
+
channel_number: channelNumber,
|
|
376
|
+
current_url: currentUrl
|
|
374
377
|
}
|
|
375
378
|
};
|
|
376
379
|
|
|
@@ -11,8 +11,14 @@ import { useCallback } from 'react';
|
|
|
11
11
|
import { attendChatRoomByHistory, chatUserUpdate as apiChatUserUpdate, chatWorkFlow, chatWorkFlowBack, generateChatInquiry, getChatInquiryDetailNew, getChatInquiryMessageList, sendChatMessage } from '../../_api';
|
|
12
12
|
import { convertApiMessageObjectToUiMessageObject, convertApiMessageToUiMessage } from '../../_lib';
|
|
13
13
|
import { useDaeryunTalkToast } from '../../Toast/DaeryuntalkToastProvider';
|
|
14
|
+
import { usePathname, useSearchParams } from 'next/navigation';
|
|
15
|
+
import { useFullURL } from './useFullURL';
|
|
14
16
|
export const useChatHandler = ({ setIsLoading, inquiryMainData, setChatInquiryNumber, setMessages, setInquiryStatus, setMessageObject, chatInquiryNumber, setIsNextPage, setWorkFlowStack, setInquiryMainData }) => {
|
|
15
17
|
const toast = useDaeryunTalkToast();
|
|
18
|
+
const pathname = usePathname(); // => "/daeryuntalk"
|
|
19
|
+
const searchParams = useSearchParams(); // => URLSearchParams 객체
|
|
20
|
+
const fullUrl = useFullURL();
|
|
21
|
+
console.log('fullUrl', fullUrl);
|
|
16
22
|
// 채팅 시작 (문의하기 버튼 클릭 시)
|
|
17
23
|
const startChat = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
24
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
@@ -30,7 +36,7 @@ export const useChatHandler = ({ setIsLoading, inquiryMainData, setChatInquiryNu
|
|
|
30
36
|
else {
|
|
31
37
|
// 새 문의 생성
|
|
32
38
|
console.log('[DaeryuntalkContext] 새 문의 생성 시작');
|
|
33
|
-
const createResponse = yield generateChatInquiry((inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.channel_number) || '');
|
|
39
|
+
const createResponse = yield generateChatInquiry((inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.channel_number) || '', fullUrl);
|
|
34
40
|
if (createResponse && createResponse.data && createResponse.data.chat_inquiry_number) {
|
|
35
41
|
currentChatInquiryNumber = createResponse.data.chat_inquiry_number;
|
|
36
42
|
console.log('[DaeryuntalkContext] 새 문의 생성 완료:', currentChatInquiryNumber);
|
|
@@ -201,7 +207,7 @@ export const useChatHandler = ({ setIsLoading, inquiryMainData, setChatInquiryNu
|
|
|
201
207
|
}
|
|
202
208
|
setIsLoading(true);
|
|
203
209
|
console.log('chatInquiryNumber', chatInquiryNumber);
|
|
204
|
-
const createResponse = yield generateChatInquiry((inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.channel_number) || '');
|
|
210
|
+
const createResponse = yield generateChatInquiry((inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.channel_number) || '', fullUrl);
|
|
205
211
|
console.log('[DaeryuntalkContext] 새 문의 생성 완료:', createResponse);
|
|
206
212
|
if (createResponse.data) {
|
|
207
213
|
const currentChatInquiryNumber = createResponse.data.chat_inquiry_number;
|
|
@@ -15,6 +15,9 @@ import { IChatInquiryMainDataResponse } from '../../_api/daeryuntalk/type/respon
|
|
|
15
15
|
import { Message } from '../../_types/message';
|
|
16
16
|
import { MessageObject } from '../../_types/message_object';
|
|
17
17
|
import { useDaeryunTalkToast } from '../../Toast/DaeryuntalkToastProvider';
|
|
18
|
+
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
|
19
|
+
import { router } from 'next/client';
|
|
20
|
+
import { useFullURL } from './useFullURL';
|
|
18
21
|
interface props {
|
|
19
22
|
setIsLoading: Dispatch<SetStateAction<boolean>>;
|
|
20
23
|
inquiryMainData: IChatInquiryMainDataResponse | null;
|
|
@@ -41,6 +44,10 @@ export const useChatHandler = ({
|
|
|
41
44
|
setInquiryMainData
|
|
42
45
|
}: props) => {
|
|
43
46
|
const toast = useDaeryunTalkToast();
|
|
47
|
+
const pathname = usePathname(); // => "/daeryuntalk"
|
|
48
|
+
const searchParams = useSearchParams(); // => URLSearchParams 객체
|
|
49
|
+
const fullUrl = useFullURL();
|
|
50
|
+
console.log('fullUrl', fullUrl);
|
|
44
51
|
// 채팅 시작 (문의하기 버튼 클릭 시)
|
|
45
52
|
const startChat = useCallback(async () => {
|
|
46
53
|
try {
|
|
@@ -60,7 +67,7 @@ export const useChatHandler = ({
|
|
|
60
67
|
} else {
|
|
61
68
|
// 새 문의 생성
|
|
62
69
|
console.log('[DaeryuntalkContext] 새 문의 생성 시작');
|
|
63
|
-
const createResponse = await generateChatInquiry(inquiryMainData?.channel_number || '');
|
|
70
|
+
const createResponse = await generateChatInquiry(inquiryMainData?.channel_number || '', fullUrl);
|
|
64
71
|
|
|
65
72
|
if (createResponse && createResponse.data && createResponse.data.chat_inquiry_number) {
|
|
66
73
|
currentChatInquiryNumber = createResponse.data.chat_inquiry_number;
|
|
@@ -252,7 +259,7 @@ export const useChatHandler = ({
|
|
|
252
259
|
}
|
|
253
260
|
setIsLoading(true);
|
|
254
261
|
console.log('chatInquiryNumber', chatInquiryNumber);
|
|
255
|
-
const createResponse = await generateChatInquiry(inquiryMainData?.channel_number || '');
|
|
262
|
+
const createResponse = await generateChatInquiry(inquiryMainData?.channel_number || '', fullUrl);
|
|
256
263
|
console.log('[DaeryuntalkContext] 새 문의 생성 완료:', createResponse);
|
|
257
264
|
if (createResponse.data) {
|
|
258
265
|
const currentChatInquiryNumber = createResponse.data.chat_inquiry_number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useFullURL(): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { usePathname, useSearchParams } from 'next/navigation';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
export function useFullURL() {
|
|
4
|
+
const pathname = usePathname();
|
|
5
|
+
const searchParams = useSearchParams();
|
|
6
|
+
const [fullUrl, setFullUrl] = useState('');
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (typeof window !== 'undefined') {
|
|
9
|
+
const origin = window.location.origin; // https://example.com
|
|
10
|
+
const query = searchParams.toString(); // scrollToMsg=true
|
|
11
|
+
const hash = window.location.hash; // #1234 or ''
|
|
12
|
+
const fullPath = origin + pathname + (query ? `?${query}` : '') + hash;
|
|
13
|
+
setFullUrl(fullPath);
|
|
14
|
+
}
|
|
15
|
+
}, [pathname, searchParams]);
|
|
16
|
+
return fullUrl;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { usePathname, useSearchParams } from 'next/navigation';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
export function useFullURL() {
|
|
5
|
+
const pathname = usePathname();
|
|
6
|
+
const searchParams = useSearchParams();
|
|
7
|
+
const [fullUrl, setFullUrl] = useState('');
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (typeof window !== 'undefined') {
|
|
11
|
+
const origin = window.location.origin; // https://example.com
|
|
12
|
+
const query = searchParams.toString(); // scrollToMsg=true
|
|
13
|
+
const hash = window.location.hash; // #1234 or ''
|
|
14
|
+
|
|
15
|
+
const fullPath = origin + pathname + (query ? `?${query}` : '') + hash;
|
|
16
|
+
|
|
17
|
+
setFullUrl(fullPath);
|
|
18
|
+
}
|
|
19
|
+
}, [pathname, searchParams]);
|
|
20
|
+
|
|
21
|
+
return fullUrl;
|
|
22
|
+
}
|
|
@@ -5,6 +5,7 @@ import ChatWidget from './ChatWidget';
|
|
|
5
5
|
import { DaeryuntalkProvider } from './DaeryuntalkContext';
|
|
6
6
|
import { DaeryuntalkToastProvider } from './Toast/DaeryuntalkToastProvider';
|
|
7
7
|
import mobile from 'is-mobile';
|
|
8
|
+
import ViewportHandler from './ViewportHandler';
|
|
8
9
|
const Daeryuntalk = ({ tel = '1800-7905' }) => {
|
|
9
10
|
const [isOpen, setIsOpen] = useState(false);
|
|
10
11
|
const [isMobile, setIsMobile] = useState(false);
|
|
@@ -33,6 +34,7 @@ const Daeryuntalk = ({ tel = '1800-7905' }) => {
|
|
|
33
34
|
}
|
|
34
35
|
}, []);
|
|
35
36
|
return (<DaeryuntalkToastProvider>
|
|
37
|
+
<ViewportHandler />
|
|
36
38
|
<DaeryuntalkProvider propsTel={tel}>
|
|
37
39
|
<ChatButton isOpen={isOpen} isMobile={isMobile} hashValue={hashValue} onClick={toggleChat}/>
|
|
38
40
|
<ChatWidget isOpen={hashValue ? true : isOpen} isMobile={isMobile} onClose={closeChatWidget} hashValue={hashValue} setHashValue={setHashValue}/>
|
|
@@ -6,6 +6,7 @@ import ChatWidget from './ChatWidget';
|
|
|
6
6
|
import { DaeryuntalkProvider, useDaeryuntalk } from './DaeryuntalkContext';
|
|
7
7
|
import { DaeryuntalkToastProvider } from './Toast/DaeryuntalkToastProvider';
|
|
8
8
|
import mobile from 'is-mobile';
|
|
9
|
+
import ViewportHandler from './ViewportHandler';
|
|
9
10
|
|
|
10
11
|
type DaeryuntalkProps = {
|
|
11
12
|
tel: string;
|
|
@@ -48,6 +49,7 @@ const Daeryuntalk: React.FC<DaeryuntalkProps> = ({ tel = '1800-7905' }) => {
|
|
|
48
49
|
|
|
49
50
|
return (
|
|
50
51
|
<DaeryuntalkToastProvider>
|
|
52
|
+
<ViewportHandler />
|
|
51
53
|
<DaeryuntalkProvider propsTel={tel}>
|
|
52
54
|
<ChatButton isOpen={isOpen} isMobile={isMobile} hashValue={hashValue} onClick={toggleChat} />
|
|
53
55
|
<ChatWidget
|