shopify-chatbot-widget 0.3.3 → 0.3.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shopify-chatbot-widget",
3
3
  "private": false,
4
- "version": "0.3.3",
4
+ "version": "0.3.4",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
package/dist/iframe.html DELETED
@@ -1,81 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width,initial-scale=1" />
6
- <title>Jaweb Chatbot Iframe</title>
7
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/shopify-chatbot-widget@0.3.0/dist/jaweb-chatbot.css">
8
- <style>
9
- html, body { height: 100%; margin: 0; background: transparent; }
10
- #jaweb-chatbot-root { height: 100%; }
11
- </style>
12
- </head>
13
- <body>
14
- <div id="jaweb-chatbot-root"></div>
15
-
16
- <script defer src="https://cdn.jsdelivr.net/npm/shopify-chatbot-widget@0.3.0/dist/jaweb-chatbot.iife.js"></script>
17
- <script>
18
- // Wait for your IIFE global to exist
19
- function whenReady(fn){
20
- (function check(){
21
- if (window.JawebChatbotWidget?.mount || window.JawebChatbotWidget?.init ||
22
- window.JawebChatbot?.init || typeof window.createJawebChatbot === 'function') return fn();
23
- setTimeout(check, 20);
24
- })();
25
- }
26
-
27
- function ensureRoot(){
28
- var el = document.getElementById('jaweb-chatbot-root');
29
- if (!el) { el = document.createElement('div'); el.id='jaweb-chatbot-root'; document.body.appendChild(el); }
30
- return el;
31
- }
32
-
33
- // Helper to notify parent about open/close
34
- function notifyState(open){ parent.postMessage({ type: 'jaweb:state', open: !!open }, '*'); }
35
-
36
- // Try to hook into your widget's events. If no official API, fallback to DOM observing.
37
- function attachStateObservers(){
38
- // Example 1: if your API exposes callbacks
39
- if (window.JawebChatbotWidget?.on) {
40
- window.JawebChatbotWidget.on('open', () => notifyState(true));
41
- window.JawebChatbotWidget.on('close', () => notifyState(false));
42
- return;
43
- }
44
- // Example 2: observe a class toggle in the DOM
45
- var root = document.body;
46
- var mo = new MutationObserver(() => {
47
- // Adjust selector/flag to your implementation:
48
- var isOpen = !!document.querySelector('.jaweb-chat-open, .jaweb-chatbox-open');
49
- notifyState(isOpen);
50
- });
51
- mo.observe(root, { attributes: true, subtree: true, attributeFilter: ['class','style'] });
52
- }
53
-
54
- // Receive config from parent and boot
55
- window.addEventListener('message', function (e) {
56
- if (e?.data?.type !== 'jaweb:init') return;
57
- var cfg = e.data.payload || {};
58
- whenReady(function () {
59
- var root = ensureRoot();
60
- try {
61
- if (window.JawebChatbotWidget?.mount) {
62
- window.JawebChatbotWidget.mount('#jaweb-chatbot-root', cfg);
63
- } else if (window.JawebChatbotWidget?.init) {
64
- window.JawebChatbotWidget.init(cfg);
65
- } else if (window.JawebChatbot?.init) {
66
- window.JawebChatbot.init(cfg);
67
- } else if (typeof window.createJawebChatbot === 'function') {
68
- window.createJawebChatbot({ target: '#jaweb-chatbot-root', ...cfg });
69
- }
70
- attachStateObservers();
71
- parent.postMessage({ type: 'jaweb:ready' }, '*');
72
- // Optional: auto-open on first load
73
- // parent.postMessage({ type: 'jaweb:state', open: true }, '*');
74
- } catch (err) {
75
- console.error('[Jaweb] init failed', err);
76
- }
77
- });
78
- });
79
- </script>
80
- </body>
81
- </html>