pager-widget 1.0.3 → 1.0.4

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 (71) hide show
  1. package/dist/index.css +1 -1
  2. package/dist/index.js +4 -4
  3. package/dist/react-parcel.9f367d21.css +2 -18
  4. package/dist/react-parcel.9f367d21.css.map +1 -1
  5. package/dist/react-parcel.js +119 -214
  6. package/dist/react-parcel.js.map +1 -1
  7. package/out/AgentFeedbackButtonWrapper.js +15 -0
  8. package/out/App.js +28 -0
  9. package/out/BotMain.js +91 -0
  10. package/out/ButtonsWrapper.js +29 -0
  11. package/out/ChatPage.js +9 -0
  12. package/out/ChatPageContent.js +131 -0
  13. package/out/ChatPageHeader.js +267 -0
  14. package/out/ChatPageInput.js +29 -0
  15. package/out/ChatWidget.js +17 -0
  16. package/out/Consent.js +66 -0
  17. package/out/CountryDropdown.js +31 -0
  18. package/out/Form.js +238 -0
  19. package/out/HomePage.js +11 -0
  20. package/out/HomePageContent.js +32 -0
  21. package/out/HomePageFooter.js +87 -0
  22. package/out/HomePageHeader.js +66 -0
  23. package/out/InputField.js +80 -0
  24. package/out/Markdown.js +126 -0
  25. package/out/Message.js +197 -0
  26. package/out/MessagesT.js +2 -0
  27. package/out/NewRecentMessagePage.js +525 -0
  28. package/out/NewRecentMessageTab.js +23 -0
  29. package/out/ReceivedMessage.js +211 -0
  30. package/out/RecentMessageDetail.js +178 -0
  31. package/out/RecentMessageList.js +112 -0
  32. package/out/RecentMessageListCard.js +20 -0
  33. package/out/RecentMessageListHeader.js +156 -0
  34. package/out/RecentMessagePage.js +183 -0
  35. package/out/RecentMessageTab.js +35 -0
  36. package/out/WidgetMessage.js +14 -0
  37. package/out/WidgetToggleButton.js +191 -0
  38. package/out/WidgetType.js +2 -0
  39. package/out/assets/icons/pikaicons-react.js +17475 -0
  40. package/out/components/ConsentForm.js +7 -0
  41. package/out/components/CustomTooltip.js +34 -0
  42. package/out/hooks/useChatHistoryExists.js +32 -0
  43. package/out/hooks/useChatHistoryListExist.js +81 -0
  44. package/out/hooks/useChatScroll.js +14 -0
  45. package/out/hooks/useCurrentConversationExists.js +88 -0
  46. package/out/hooks/useInitialMessage.js +33 -0
  47. package/out/hooks/useMessage.js +230 -0
  48. package/out/hooks/useMessageReceiver.js +183 -0
  49. package/out/hooks/usePopupAnimation.js +20 -0
  50. package/out/hooks/useSocket.js +19 -0
  51. package/out/hooks/useSocketContext.js +81 -0
  52. package/out/hooks/useWidgetDimension.js +41 -0
  53. package/out/hooks/useWidgetToggle.js +22 -0
  54. package/out/index.js +31 -0
  55. package/out/markdown/CodeCopy.js +22 -0
  56. package/out/markdown/CodeHighlight.js +58 -0
  57. package/out/markdown/PagerMarkdown.js +36 -0
  58. package/out/markdown/pager_md.js +152 -0
  59. package/out/onscreenNotificationPopup.js +23 -0
  60. package/out/socket.js +11 -0
  61. package/out/utils/checkConversationExit.js +24 -0
  62. package/out/utils/convertTime.js +43 -0
  63. package/out/utils/sendInitialMessage.js +82 -0
  64. package/out/widget.js +21 -0
  65. package/out/widgetConfigStore.js +205 -0
  66. package/out/widgetConfigStore2.js +569 -0
  67. package/out/widgetControlstore.js +23 -0
  68. package/out/widgetStateHandler.js +106 -0
  69. package/out/widgetStore.js +171 -0
  70. package/out/widgetUserStore.js +47 -0
  71. package/package.json +1 -1
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMessageReceiver = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ const react_1 = require("react");
6
+ const widgetConfigStore2_1 = require("../widgetConfigStore2");
7
+ const widgetStateHandler_1 = require("../widgetStateHandler");
8
+ const recievedMsg = (msg) => ({
9
+ type: 'received',
10
+ time: new Date(),
11
+ message: {
12
+ ...msg,
13
+ },
14
+ });
15
+ const useMessageReceiver = ({ socket, messages, setMessages, setIsTyping, setAgentStatus, }) => {
16
+ const messagesRef = (0, react_1.useRef)(messages);
17
+ const widget = (0, widgetConfigStore2_1.useWidgetData)();
18
+ console.log('use message receiver message', messages);
19
+ (0, react_1.useEffect)(() => {
20
+ messagesRef.current = messages;
21
+ }, [messages]);
22
+ console.log('messages check', messages);
23
+ const sendMessageToLs = (widget, messages) => {
24
+ const widget_id = widget?.data?.id;
25
+ const bot_id = widget?.data?.bot_id;
26
+ const conversationId = messages.find((msg) => msg.message.system.conversationId)?.message.system.conversationId;
27
+ if (!conversationId)
28
+ return;
29
+ // Parse existing recent list data from localStorage
30
+ const recentListKey = `RecentList::${bot_id}::${widget_id}`;
31
+ const existingData = localStorage.getItem(recentListKey);
32
+ let parsedData = {};
33
+ if (existingData) {
34
+ try {
35
+ parsedData = JSON.parse(existingData);
36
+ }
37
+ catch (error) {
38
+ console.error(`Failed to parse RecentList for widget_id: ${widget_id}`, error);
39
+ }
40
+ }
41
+ // Add or update conversation
42
+ parsedData[conversationId] = messages;
43
+ // Save the updated RecentList
44
+ localStorage.setItem(recentListKey, JSON.stringify(parsedData));
45
+ // Optional: Save a separate payload per widget (if needed elsewhere)
46
+ const payload = { [widget_id]: messages };
47
+ localStorage.setItem(`${bot_id}::${widget_id}`, JSON.stringify(payload));
48
+ console.log('Updated RecentList in localStorage:', recentListKey, parsedData);
49
+ };
50
+ // const sendMessageToLs = (widget: WidgetT, messages: MessagesT[]) => {
51
+ // console.log(
52
+ // 'to local storage',
53
+ // widget.data.bot_id,
54
+ // widget.data.id,
55
+ // messages
56
+ // )
57
+ // const widget_id = widget.data.id // You might be missing this variable declaration
58
+ // const payload = { [widget_id]: messages } // use computed property name
59
+ // const conversationId = messages.find(
60
+ // (messageResponse) => messageResponse.message.system.conversationId
61
+ // )?.message.system.conversationId as string
62
+ // if (!conversationId) return
63
+ // const existingData = localStorage.getItem(widget_id)
64
+ // let parsedData: Record<string, any[]> = {}
65
+ // if (existingData) {
66
+ // try {
67
+ // parsedData = JSON.parse(existingData)
68
+ // } catch (error) {
69
+ // console.error(
70
+ // `Failed to parse data for widget_id: ${widget_id}`,
71
+ // error
72
+ // )
73
+ // }
74
+ // }
75
+ // // Update/add the conversation with new messages
76
+ // parsedData[conversationId] = messages
77
+ // // Save back to localStorage
78
+ // localStorage.setItem(
79
+ // `${widget.data.bot_id}::${widget.data.id}`,
80
+ // JSON.stringify(payload)
81
+ // )
82
+ // localStorage.setItem(
83
+ // `RecentList::${widget?.data?.bot_id}::${widget?.data?.id}`,
84
+ // JSON.stringify(parsedData)
85
+ // )
86
+ // }
87
+ (0, react_1.useEffect)(() => {
88
+ console.log(socket, 'socketss');
89
+ if (!socket)
90
+ return;
91
+ const onMessageReceived = (msg) => {
92
+ console.log('on message received called', msg);
93
+ const recievedMessage = recievedMsg(msg);
94
+ const conversation_id = msg?.system?.conversationId;
95
+ // widgetStore.trigger.setCurrentConversation({
96
+ // conversation_id: conversation_id,
97
+ // })
98
+ localStorage.setItem('CURRENT_CONVERSATION', conversation_id);
99
+ // console.log("msgggg", msg?.system?.conversationId)
100
+ // setMessages((prevMessages) => {
101
+ // const updatedMessages = [...prevMessages, recievedMessage]
102
+ // sendMessageToLs(widget, updatedMessages)
103
+ //
104
+ // setWidgetLocalState({
105
+ // widget_id: widget?.data?.id,
106
+ // user_state: "ALLOW_MESSAGE",
107
+ // events: { ...recievedMessage, time: recievedMessage.time.toString() } as ReceivedEvent,
108
+ // })
109
+ // return updatedMessages
110
+ // })
111
+ const receivedType = recievedMessage.message.output[0].type;
112
+ setAgentStatus(receivedType);
113
+ if (receivedType === 'progress_done' || receivedType == 'text') {
114
+ setAgentStatus(null);
115
+ }
116
+ if (receivedType !== 'thinking' &&
117
+ receivedType !== 'finalizing_output' &&
118
+ receivedType !== 'progress_done' &&
119
+ receivedType !== 'searching_kb' &&
120
+ receivedType !== 'action_detected' &&
121
+ receivedType !== 'validating_input_for_action' &&
122
+ receivedType !== 'executing_action' &&
123
+ receivedType !== 'analysing_response') {
124
+ setMessages((prev) => {
125
+ const updated = [...prev, recievedMessage];
126
+ // Save only REAL messages
127
+ sendMessageToLs(widget, updated);
128
+ // Save local state
129
+ (0, widgetStateHandler_1.setWidgetLocalState)({
130
+ widget_id: widget?.data?.id,
131
+ user_state: 'ALLOW_MESSAGE',
132
+ events: {
133
+ ...recievedMessage,
134
+ time: recievedMessage.time.toString(),
135
+ },
136
+ });
137
+ return updated;
138
+ });
139
+ }
140
+ };
141
+ const onTypingEndReceived = () => {
142
+ setIsTyping(false);
143
+ };
144
+ socket.on('message', onMessageReceived);
145
+ socket.on('typingend', onTypingEndReceived);
146
+ // return () => {
147
+ // socket.off('message', onMessageReceived)
148
+ // socket.off('typingend', onTypingEndReceived)
149
+ // }
150
+ }, [socket]);
151
+ };
152
+ exports.useMessageReceiver = useMessageReceiver;
153
+ // import { useEffect, useRef } from "react"
154
+ // type UseMessageReceiverProps = {
155
+ // widget_id: string
156
+ // socket: any
157
+ // messages: any[]
158
+ // setMessages: React.Dispatch<React.SetStateAction<any[]>>
159
+ // setIsTyping: React.Dispatch<React.SetStateAction<boolean>>
160
+ // }
161
+ // export const useMessageReceiver = ({widget_id,socket,messages,setMessages,setIsTyping}:UseMessageReceiverProps) => {
162
+ // console.log("messages", messages)
163
+ // const onMessageReceived = (messages:any[]) => (msg:any) => {
164
+ // console.log("msg",msg)
165
+ // }
166
+ // const onMessageReceivedCallBack = useRef<(msg: any) => void>(() => {});
167
+ // const onMessageTypingEndReceived = (msg:any) => {
168
+ // setIsTyping(false);
169
+ // };
170
+ // useEffect(()=>{
171
+ // onMessageReceivedCallBack.current = onMessageReceived(messages)
172
+ // },[messages])
173
+ // useEffect(() => {
174
+ // if (socket) {
175
+ // socket.on("message", onMessageReceivedCallBack.current);
176
+ // socket.on("typingend", onMessageTypingEndReceived);
177
+ // }
178
+ // return () => {
179
+ // socket && socket.off("message", onMessageReceivedCallBack.current);
180
+ // socket && socket.off("typingend", onMessageTypingEndReceived);
181
+ // };
182
+ // }, [socket, messages]);
183
+ // }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usePopupAnimation = usePopupAnimation;
4
+ const react_1 = require("react");
5
+ function usePopupAnimation(isOpen) {
6
+ const [isPopUpOpened, setIsPopUpOpened] = (0, react_1.useState)(false);
7
+ const [removeAnimation, setRemoveAnimation] = (0, react_1.useState)(false);
8
+ (0, react_1.useEffect)(() => {
9
+ if (!isOpen) {
10
+ return;
11
+ }
12
+ const openTimer = setTimeout(() => setIsPopUpOpened(true), 10);
13
+ const removeTimer = setTimeout(() => setRemoveAnimation(true), 400);
14
+ return () => {
15
+ clearTimeout(openTimer);
16
+ clearTimeout(removeTimer);
17
+ };
18
+ }, [isOpen]);
19
+ return { isPopUpOpened, removeAnimation };
20
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSocket = void 0;
4
+ const react_1 = require("react");
5
+ const socket_1 = require("../socket");
6
+ const rTrimSlash = (str) => str.replace(/\/$/, '');
7
+ const useSocket = ({ endpoint }) => {
8
+ // const [socket, setSocket] =
9
+ const socket = (0, socket_1.createSocket)(new URL(endpoint).origin, `${rTrimSlash(new URL(endpoint).pathname)}/socket.io`);
10
+ const [connected, setConnected] = (0, react_1.useState)(false);
11
+ // const parsedEndpoint = new URL(endpoint)
12
+ (0, react_1.useEffect)(() => {
13
+ socket.on('connect', () => {
14
+ setConnected(true);
15
+ });
16
+ }, []);
17
+ return { connected, socket };
18
+ };
19
+ exports.useSocket = useSocket;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.useSocketV2 = exports.SocketProvider = exports.SocketContext = void 0;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const react_1 = __importStar(require("react"));
39
+ const socket_1 = require("../socket");
40
+ // Create the context with a default value of null
41
+ // We use 'as SocketContextProps' to override TypeScript's type checking
42
+ // because we ensure the context is provided before being used.
43
+ exports.SocketContext = (0, react_1.createContext)(null);
44
+ const rTrimSlash = (str) => str.replace(/\/$/, '');
45
+ // Create the provider component
46
+ const SocketProvider = ({ children, endpoint, }) => {
47
+ const socketRef = react_1.default.useRef(null);
48
+ const [connected, setConnected] = (0, react_1.useState)(false);
49
+ (0, react_1.useEffect)(() => {
50
+ const socket = (0, socket_1.createSocket)(new URL(endpoint).origin, `${rTrimSlash(new URL(endpoint).pathname)}/socket.io`);
51
+ socketRef.current = socket;
52
+ // Manually connect the socket when the provider mounts
53
+ socket.connect();
54
+ // Optional: Add connection event listeners here if needed globally
55
+ socket.on('connect', () => {
56
+ setConnected(true);
57
+ console.log('Socket connected!', socket.id);
58
+ });
59
+ socket.on('disconnect', () => {
60
+ console.log('Socket disconnected!');
61
+ });
62
+ // Clean up the connection when the provider unmounts
63
+ return () => {
64
+ socket.disconnect();
65
+ };
66
+ }, []); // Empty dependency array ensures this runs only once
67
+ return ((0, jsx_runtime_1.jsx)(exports.SocketContext.Provider, { value: { socket: socketRef.current, connected }, children: children }));
68
+ };
69
+ exports.SocketProvider = SocketProvider;
70
+ // Custom hook to use the socket context
71
+ const useSocketV2 = () => {
72
+ const contextValue = (0, react_1.useContext)(exports.SocketContext);
73
+ console.log('DEBUG:: contextValue', contextValue);
74
+ if (contextValue == null || contextValue?.socket == null) {
75
+ return { socket: null, connected: false };
76
+ }
77
+ const { socket, connected } = contextValue;
78
+ // Type assertion to tell TypeScript that the value is a Socket
79
+ return { socket, connected };
80
+ };
81
+ exports.useSocketV2 = useSocketV2;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useWidgetDimension = useWidgetDimension;
4
+ const react_1 = require("react");
5
+ function useWidgetDimension() {
6
+ const [height, setHeight] = (0, react_1.useState)(0);
7
+ const divRef = (0, react_1.useRef)(null);
8
+ const [viewportHeight, setViewportHeight] = (0, react_1.useState)(() => typeof window !== 'undefined' ? window.innerHeight : 820);
9
+ (0, react_1.useEffect)(() => {
10
+ const element = divRef.current;
11
+ if (!element)
12
+ return;
13
+ const observer = new ResizeObserver((entries) => {
14
+ for (const entry of entries) {
15
+ const newHeight = entry.contentRect.height;
16
+ setHeight(newHeight);
17
+ }
18
+ });
19
+ observer.observe(element);
20
+ return () => observer.disconnect();
21
+ }, []);
22
+ (0, react_1.useEffect)(() => {
23
+ if (typeof window === 'undefined')
24
+ return;
25
+ const update = () => setViewportHeight(window.innerHeight);
26
+ update();
27
+ window.addEventListener('resize', update);
28
+ return () => window.removeEventListener('resize', update);
29
+ }, []);
30
+ const computeDynamicMinHeight = (h) => {
31
+ const raw = 0.9 * h - 40;
32
+ const clamped = Math.round(Math.min(698, Math.max(590, raw)));
33
+ return clamped;
34
+ };
35
+ return {
36
+ divRef,
37
+ height,
38
+ viewportHeight,
39
+ computeDynamicMinHeight
40
+ };
41
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useWidgetToggle = useWidgetToggle;
4
+ const react_1 = require("@xstate/store/react");
5
+ function useWidgetToggle(openByDefault) {
6
+ const store = (0, react_1.useStore)({
7
+ context: {
8
+ chatWindowStatus: openByDefault ? 'OPEN' : 'CLOSE',
9
+ },
10
+ on: {
11
+ toggle: (context) => {
12
+ return {
13
+ chatWindowStatus: context.chatWindowStatus === 'OPEN'
14
+ ? 'CLOSE'
15
+ : 'OPEN',
16
+ };
17
+ },
18
+ },
19
+ });
20
+ const chatWindowStatus = (0, react_1.useSelector)(store, (state) => state.context.chatWindowStatus);
21
+ return [chatWindowStatus, store.trigger.toggle];
22
+ }
package/out/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ // import 'preact/debug'
8
+ const react_1 = __importDefault(require("react"));
9
+ const client_1 = __importDefault(require("react-dom/client"));
10
+ require("./global.css");
11
+ const global_css_1 = __importDefault(require("bundle-text:./global.css"));
12
+ const App_1 = require("./App");
13
+ const init = (config) => {
14
+ const host = document.getElementById(config.id);
15
+ if (!host)
16
+ return;
17
+ const shadowRoot = host.attachShadow({ mode: 'open' });
18
+ const style = document.createElement('style');
19
+ style.setAttribute('data-tailwind', 'true');
20
+ const replaced = global_css_1.default.replace('(((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b))))', '(display: block)');
21
+ console.log('widgetCss', global_css_1.default, replaced);
22
+ style.textContent = replaced;
23
+ shadowRoot.appendChild(style);
24
+ const mountPoint = document.createElement('div');
25
+ mountPoint.className = 'pager-widget';
26
+ shadowRoot.appendChild(mountPoint);
27
+ client_1.default.createRoot(mountPoint).render((0, jsx_runtime_1.jsx)(react_1.default.StrictMode, { children: (0, jsx_runtime_1.jsx)(App_1.App, { ...config }) }));
28
+ };
29
+ window.WAWidget = {
30
+ init,
31
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CopyButton = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const lucide_react_1 = require("lucide-react");
7
+ const pikaicons_react_1 = require("../assets/icons/pikaicons-react");
8
+ const CopyButton = ({ code }) => {
9
+ const [copied, setCopied] = (0, react_1.useState)(false);
10
+ const [pressed, setPressed] = (0, react_1.useState)(false);
11
+ const handleCopy = async () => {
12
+ setPressed(true);
13
+ setTimeout(() => {
14
+ setPressed(false);
15
+ setCopied(true);
16
+ }, 150);
17
+ await navigator.clipboard.writeText(code);
18
+ setTimeout(() => setCopied(false), 1500);
19
+ };
20
+ return ((0, jsx_runtime_1.jsx)("button", { onClick: handleCopy, className: `absolute top-0 right-0 flex items-center text-xss text-slate-500 hover:text-slate-800 gap-1 px-1 py-0 font-medium cursor-pointer transition-all duration-150 ease-out ${pressed ? 'scale-95' : 'scale-100'}`, "aria-label": "Copy code to clipboard", children: copied ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Check, { size: 10, className: "text-green-500" }), "Copied!"] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(pikaicons_react_1.PiCopyDefaultStroke, { className: "w-[10px] h-[10px]" }), "Copy"] })) }));
21
+ };
22
+ exports.CopyButton = CopyButton;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.highlightCodeToElements = highlightCodeToElements;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = __importDefault(require("react"));
9
+ function highlightCodeToElements(code) {
10
+ const lines = code.split('\n');
11
+ return lines.map((line, lineIndex) => {
12
+ const tokens = [];
13
+ let remaining = line;
14
+ let tokenIndex = 0;
15
+ while (remaining.length > 0) {
16
+ const keyBase = `${lineIndex}-${tokenIndex++}`;
17
+ // Match comments (e.g., // something)
18
+ const commentMatch = remaining.match(/^(\/\/.*)/);
19
+ if (commentMatch) {
20
+ tokens.push((0, jsx_runtime_1.jsx)("span", { className: "text-gray-500 italic", children: commentMatch[1] }, `${keyBase}-comment`));
21
+ remaining = remaining.slice(commentMatch[1].length);
22
+ continue;
23
+ }
24
+ // Match strings: single, double, or backtick
25
+ const stringMatch = remaining.match(/^(['"`])(?:\\.|[^\\])*?\1/);
26
+ if (stringMatch) {
27
+ tokens.push((0, jsx_runtime_1.jsx)("span", { className: "text-green-600", children: stringMatch[0] }, `${keyBase}-string`));
28
+ remaining = remaining.slice(stringMatch[0].length);
29
+ continue;
30
+ }
31
+ // Match keywords
32
+ const keywordMatch = remaining.match(/^(const|let|var|function|return|if|else|for|while|import|from|export|new|await|async|class|extends|super|this)\b/);
33
+ if (keywordMatch) {
34
+ tokens.push((0, jsx_runtime_1.jsx)("span", { className: "text-blue-700 font-semibold", children: keywordMatch[0] }, `${keyBase}-keyword`));
35
+ remaining = remaining.slice(keywordMatch[0].length);
36
+ continue;
37
+ }
38
+ // Match booleans or null
39
+ const literalMatch = remaining.match(/^(true|false|null|undefined)\b/);
40
+ if (literalMatch) {
41
+ tokens.push((0, jsx_runtime_1.jsx)("span", { className: "text-amber-700", children: literalMatch[0] }, `${keyBase}-literal`));
42
+ remaining = remaining.slice(literalMatch[0].length);
43
+ continue;
44
+ }
45
+ // Match numbers
46
+ const numberMatch = remaining.match(/^(\d+)/);
47
+ if (numberMatch) {
48
+ tokens.push((0, jsx_runtime_1.jsx)("span", { className: "text-red-500", children: numberMatch[0] }, `${keyBase}-number`));
49
+ remaining = remaining.slice(numberMatch[0].length);
50
+ continue;
51
+ }
52
+ // Match and push 1 character if no patterns match
53
+ tokens.push((0, jsx_runtime_1.jsx)("span", { children: remaining[0] }, `${keyBase}-char`));
54
+ remaining = remaining.slice(1);
55
+ }
56
+ return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [tokens, lineIndex < lines.length - 1 ? (0, jsx_runtime_1.jsx)("br", {}) : null] }, `line-${lineIndex}`));
57
+ });
58
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const react_markdown_1 = __importDefault(require("react-markdown"));
8
+ const remark_gfm_1 = __importDefault(require("remark-gfm"));
9
+ const remark_breaks_1 = __importDefault(require("remark-breaks"));
10
+ const CodeHighlight_1 = require("./CodeHighlight");
11
+ const CodeCopy_1 = require("./CodeCopy");
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ const PagerMarkdown = ({ message }) => {
14
+ return ((0, jsx_runtime_1.jsx)("p", { className: "markdown-parent-container", children: (0, jsx_runtime_1.jsx)(react_markdown_1.default, { remarkPlugins: [remark_gfm_1.default, remark_breaks_1.default], components: {
15
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
+ table: ({ node, ...props }) => ((0, jsx_runtime_1.jsx)("div", { className: "markdown-table-wrapper", children: (0, jsx_runtime_1.jsx)("table", { ...props }) })),
17
+ hr: () => ((0, jsx_runtime_1.jsx)("hr", { style: {
18
+ border: 'none',
19
+ borderTop: '1px solid #D4D4D8',
20
+ width: '100%',
21
+ } })),
22
+ a: ({ href, children, ...props }) => ((0, jsx_runtime_1.jsx)("a", { href: href, target: "_blank", rel: "noopener noreferrer", ...props, children: children })),
23
+ h2: ({ ...props }) => ((0, jsx_runtime_1.jsx)("h2", { className: "text-sm font-semibold", ...props })),
24
+ h3: ({ ...props }) => ((0, jsx_runtime_1.jsx)("h3", { className: "text-sm font-semibold", ...props })),
25
+ h4: ({ ...props }) => ((0, jsx_runtime_1.jsx)("h4", { className: "text-sm font-semibold", ...props })),
26
+ h5: ({ ...props }) => ((0, jsx_runtime_1.jsx)("h5", { className: "text-sm font-semibold", ...props })),
27
+ h6: ({ ...props }) => ((0, jsx_runtime_1.jsx)("h6", { className: "text-sm font-semibold", ...props })),
28
+ code({ inline, children }) {
29
+ const codeContent = String(children);
30
+ return inline ? ((0, jsx_runtime_1.jsx)("code", { className: "text-[12px]", children: codeContent })) : ((0, jsx_runtime_1.jsxs)("div", { className: "relative bg-[#f9fafb] text-[12px] rounded-lg font-mono pt-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "absolute top-0.5 right-1 z-10", children: (0, jsx_runtime_1.jsx)(CodeCopy_1.CopyButton, { code: codeContent }) }), (0, jsx_runtime_1.jsx)("div", { className: "overflow-auto rounded-lg p-4", children: (0, jsx_runtime_1.jsx)("pre", { className: "text-[12px] font-mono leading-relaxed", children: (0, jsx_runtime_1.jsx)("code", { className: "whitespace-pre", children: (0, CodeHighlight_1.highlightCodeToElements)(codeContent) }) }) })] }));
31
+ },
32
+ }, children: typeof message === 'string'
33
+ ? message
34
+ : JSON.stringify(message) }) }));
35
+ };
36
+ exports.default = PagerMarkdown;