shopify-chatbot-widget 0.4.2 → 0.4.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 (2) hide show
  1. package/dist/jawebDirect.js +100 -0
  2. package/package.json +1 -1
@@ -0,0 +1,100 @@
1
+ (() => {
2
+ // ----- Read config from attributes -----
3
+ const currentScript = document.currentScript || document.querySelector('script[data-company][src*="jaweb-chatbot"]');
4
+ if (!currentScript) return console.warn('[Jaweb] install script not found');
5
+ const company = (currentScript.getAttribute('data-company') || '').trim();
6
+ if (!company) return console.error('[Jaweb] data-company is required');
7
+
8
+ const apiBase = currentScript.getAttribute('data-src') || 'https://jawebcrm.onrender.com/api/proxy/iframe';
9
+ const corner = currentScript.getAttribute('data-corner') || 'right'; // 'right' | 'left'
10
+ const openWidth = currentScript.getAttribute('data-open-width') || '400px';
11
+ const openHeight = currentScript.getAttribute('data-open-height') || '560px';
12
+ const mobileSheetVh = currentScript.getAttribute('data-mobile-vh') || '85vh'; // leave some page visible
13
+
14
+ // ----- Make styles -----
15
+ const style = document.createElement('style');
16
+ style.textContent = `
17
+ #jaweb-chatbot-iframe {
18
+ position: fixed;
19
+ ${corner === 'left' ? 'left' : 'right'}: 16px;
20
+ bottom: 16px;
21
+ z-index: 2147483647;
22
+ border: 0;
23
+ transition: width .2s, height .2s, border-radius .2s, inset .2s, box-shadow .2s;
24
+ overflow: hidden;
25
+ background: transparent;
26
+ }
27
+ #jaweb-chatbot-iframe.is-closed {
28
+ width: 64px; height: 64px;
29
+ border-radius: 9999px;
30
+ box-shadow: 0 8px 20px rgba(0,0,0,.2);
31
+ }
32
+ #jaweb-chatbot-iframe.is-open {
33
+ width: ${openWidth}; height: ${openHeight};
34
+ border-radius: 16px;
35
+ box-shadow: 0 10px 30px rgba(0,0,0,.15);
36
+ }
37
+ @media (max-width: 768px) {
38
+ #jaweb-chatbot-iframe.is-open {
39
+ left: 0; right: 0; bottom: 0; top: auto;
40
+ width: 100%; height: ${mobileSheetVh};
41
+ border-radius: 16px 16px 0 0;
42
+ box-shadow: 0 -10px 30px rgba(0,0,0,.15);
43
+ }
44
+ #jaweb-chatbot-iframe.is-closed {
45
+ ${corner === 'left' ? 'left' : 'right'}: 16px;
46
+ bottom: 16px;
47
+ }
48
+ }
49
+ `;
50
+ document.head.appendChild(style);
51
+
52
+ // ----- Build iframe src -----
53
+ const params = new URLSearchParams({ company_username: company });
54
+ try {
55
+ const trackId = localStorage.getItem('track_id');
56
+ if (trackId) params.set('track_id', trackId);
57
+ localStorage.setItem('company_username', company);
58
+ } catch (_) {}
59
+
60
+ // ----- Create iframe -----
61
+ if (document.getElementById('jaweb-chatbot-iframe')) return;
62
+ const iframe = document.createElement('iframe');
63
+ iframe.id = 'jaweb-chatbot-iframe';
64
+ iframe.className = 'is-closed'; // start as bubble
65
+ iframe.src = `${apiBase}?${params.toString()}`;
66
+ iframe.allow = 'microphone; camera; autoplay; clipboard-write';
67
+ document.body.appendChild(iframe);
68
+
69
+ // Optional: ensure outside page stays scrollable
70
+ const unlockScroll = () => {
71
+ document.documentElement.style.overflow = '';
72
+ document.body.style.overflow = '';
73
+ document.body.style.position = '';
74
+ document.body.style.top = '';
75
+ ['modal-open','no-scroll','overflow-hidden','lock-scroll','js-focus-lock'].forEach(c => {
76
+ document.documentElement.classList.remove(c);
77
+ document.body.classList.remove(c);
78
+ });
79
+ };
80
+ requestAnimationFrame(unlockScroll);
81
+
82
+ // ----- Handshake with child -----
83
+ window.addEventListener('message', (e) => {
84
+ const msg = e.data || {};
85
+ if (msg.type !== 'JAWEB_CHAT') return;
86
+
87
+ if (msg.action === 'open') {
88
+ iframe.classList.remove('is-closed');
89
+ iframe.classList.add('is-open');
90
+ unlockScroll();
91
+ iframe.contentWindow?.postMessage({ type: 'JAWEB_CHAT', action: 'open-ready' }, '*');
92
+ } else if (msg.action === 'close') {
93
+ iframe.classList.remove('is-open');
94
+ iframe.classList.add('is-closed');
95
+ unlockScroll();
96
+ iframe.contentWindow?.postMessage({ type: 'JAWEB_CHAT', action: 'closed' }, '*');
97
+ }
98
+ });
99
+ })();
100
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shopify-chatbot-widget",
3
3
  "private": false,
4
- "version": "0.4.2",
4
+ "version": "0.4.4",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",