@helllo-ai/agent-chat-widget 0.1.8 → 0.1.9
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/agent-chat.latest.js +56 -8
- package/package.json +1 -1
package/agent-chat.latest.js
CHANGED
|
@@ -19,10 +19,18 @@
|
|
|
19
19
|
const safeBg = background || '#ffffff'
|
|
20
20
|
return `
|
|
21
21
|
:host, .acw * { box-sizing: border-box; }
|
|
22
|
-
.acw-container { position: fixed;
|
|
23
|
-
.acw-launcher { background: ${safePrimary}; color: #fff; border: none; border-radius: 999px; padding: 10px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.18); font-size: 14px; }
|
|
22
|
+
.acw-container { position: fixed; z-index: 2147483000; font-family: Inter, system-ui, -apple-system, sans-serif; }
|
|
23
|
+
.acw-launcher { background: ${safePrimary}; color: #fff; border: none; border-radius: 999px; padding: 10px 14px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.18); font-size: 14px; transition: transform 0.2s; }
|
|
24
24
|
.acw-launcher:hover { opacity: 0.95; }
|
|
25
|
-
.acw-
|
|
25
|
+
.acw-launcher.vertical { flex-direction: column; padding: 14px 10px; min-width: 48px; height: auto; }
|
|
26
|
+
.acw-launcher.vertical span { writing-mode: vertical-rl; text-orientation: mixed; letter-spacing: 0.5px; }
|
|
27
|
+
.acw-panel { position: absolute; width: 360px; max-width: 90vw; height: 520px; max-height: 80vh; background: ${safeBg}; border: 1px solid rgba(0,0,0,0.08); border-radius: 12px; box-shadow: 0 16px 40px rgba(0,0,0,0.22); display: none; flex-direction: column; overflow: hidden; }
|
|
28
|
+
.acw-panel.bottom-right { right: 0; bottom: 56px; }
|
|
29
|
+
.acw-panel.middle-right { right: 56px; top: 50%; transform: translateY(-50%); }
|
|
30
|
+
.acw-panel.top-right { right: 0; top: 56px; }
|
|
31
|
+
.acw-panel.bottom-left { left: 0; bottom: 56px; }
|
|
32
|
+
.acw-panel.middle-left { left: 56px; top: 50%; transform: translateY(-50%); }
|
|
33
|
+
.acw-panel.top-left { left: 0; top: 56px; }
|
|
26
34
|
.acw-header { background: ${safePrimary}; color: #fff; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; }
|
|
27
35
|
.acw-title { font-weight: 600; font-size: 14px; }
|
|
28
36
|
.acw-close { background: transparent; border: none; color: #fff; cursor: pointer; font-size: 16px; }
|
|
@@ -57,14 +65,21 @@
|
|
|
57
65
|
wsUrl,
|
|
58
66
|
title = 'Chat with us',
|
|
59
67
|
greeting = null,
|
|
68
|
+
position = 'bottom-right',
|
|
60
69
|
} = config
|
|
61
70
|
|
|
71
|
+
// Valid positions
|
|
72
|
+
const validPositions = ['bottom-right', 'middle-right', 'top-right', 'bottom-left', 'middle-left', 'top-left']
|
|
73
|
+
const finalPosition = validPositions.includes(position) ? position : 'bottom-right'
|
|
74
|
+
const isVertical = finalPosition === 'middle-right' || finalPosition === 'middle-left'
|
|
75
|
+
const isLeft = finalPosition.includes('left')
|
|
76
|
+
|
|
62
77
|
if (!agentId) {
|
|
63
|
-
console.warn('[AgentChatWidget] Missing data-agent-id')
|
|
78
|
+
console.warn('[AgentChatWidget] Missing agentId. Provide it via init({ agentId: "..." }) or data-agent-id attribute')
|
|
64
79
|
return
|
|
65
80
|
}
|
|
66
81
|
if (!embedKey) {
|
|
67
|
-
console.warn('[AgentChatWidget] Missing data-embed-key')
|
|
82
|
+
console.warn('[AgentChatWidget] Missing embedKey. Provide it via init({ embedKey: "..." }) or data-embed-key attribute')
|
|
68
83
|
return
|
|
69
84
|
}
|
|
70
85
|
|
|
@@ -75,17 +90,46 @@
|
|
|
75
90
|
}
|
|
76
91
|
|
|
77
92
|
const container = document.createElement('div')
|
|
78
|
-
container.className =
|
|
93
|
+
container.className = `acw-container ${finalPosition}`
|
|
94
|
+
|
|
95
|
+
// Apply position styles directly to container (since it's in regular DOM, not shadow)
|
|
96
|
+
container.style.position = 'fixed'
|
|
97
|
+
container.style.zIndex = '2147483000'
|
|
98
|
+
container.style.fontFamily = 'Inter, system-ui, -apple-system, sans-serif'
|
|
99
|
+
|
|
100
|
+
// Set container position based on finalPosition
|
|
101
|
+
if (finalPosition === 'bottom-right') {
|
|
102
|
+
container.style.right = '16px'
|
|
103
|
+
container.style.bottom = '16px'
|
|
104
|
+
} else if (finalPosition === 'middle-right') {
|
|
105
|
+
container.style.right = '16px'
|
|
106
|
+
container.style.top = '50%'
|
|
107
|
+
container.style.transform = 'translateY(-50%)'
|
|
108
|
+
} else if (finalPosition === 'top-right') {
|
|
109
|
+
container.style.right = '16px'
|
|
110
|
+
container.style.top = '16px'
|
|
111
|
+
} else if (finalPosition === 'bottom-left') {
|
|
112
|
+
container.style.left = '16px'
|
|
113
|
+
container.style.bottom = '16px'
|
|
114
|
+
} else if (finalPosition === 'middle-left') {
|
|
115
|
+
container.style.left = '16px'
|
|
116
|
+
container.style.top = '50%'
|
|
117
|
+
container.style.transform = 'translateY(-50%)'
|
|
118
|
+
} else if (finalPosition === 'top-left') {
|
|
119
|
+
container.style.left = '16px'
|
|
120
|
+
container.style.top = '16px'
|
|
121
|
+
}
|
|
122
|
+
|
|
79
123
|
const shadow = container.attachShadow({ mode: 'open' })
|
|
80
124
|
const style = document.createElement('style')
|
|
81
125
|
style.textContent = createStyles(primaryColor, backgroundColor)
|
|
82
126
|
shadow.appendChild(style)
|
|
83
127
|
|
|
84
128
|
const panel = document.createElement('div')
|
|
85
|
-
panel.className =
|
|
129
|
+
panel.className = `acw-panel ${finalPosition}`
|
|
86
130
|
|
|
87
131
|
const launcher = document.createElement('button')
|
|
88
|
-
launcher.className = 'acw-launcher'
|
|
132
|
+
launcher.className = isVertical ? 'acw-launcher vertical' : 'acw-launcher'
|
|
89
133
|
launcher.innerHTML = '<span>Chat</span>'
|
|
90
134
|
|
|
91
135
|
const header = document.createElement('div')
|
|
@@ -304,6 +348,9 @@
|
|
|
304
348
|
const scriptEl = document.currentScript || document.querySelector('script[data-agent-id]')
|
|
305
349
|
const ds = (scriptEl && scriptEl.dataset) || {}
|
|
306
350
|
const allowed = (ds.allowedDomains || ds.allowed_domains || '').split(',').map((d) => d.trim()).filter(Boolean)
|
|
351
|
+
const position = userConfig.position || ds.position || ds.launcherPosition || 'bottom-right'
|
|
352
|
+
const validPositions = ['bottom-right', 'middle-right', 'top-right', 'bottom-left', 'middle-left', 'top-left']
|
|
353
|
+
const validPosition = validPositions.includes(position) ? position : 'bottom-right'
|
|
307
354
|
return {
|
|
308
355
|
agentId: userConfig.agentId || ds.agentId,
|
|
309
356
|
embedKey: userConfig.embedKey || ds.embedKey || ds.embed_key,
|
|
@@ -315,6 +362,7 @@
|
|
|
315
362
|
wsUrl: userConfig.wsUrl || ds.wsUrl || ds.ws_url,
|
|
316
363
|
title: userConfig.title || ds.title,
|
|
317
364
|
greeting: userConfig.greeting || ds.greeting,
|
|
365
|
+
position: validPosition,
|
|
318
366
|
}
|
|
319
367
|
}
|
|
320
368
|
|