@deepfrog/pangents-widget 2.2.0 → 2.2.2

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/README.md CHANGED
@@ -133,6 +133,61 @@ Initialize the widget with configuration.
133
133
 
134
134
  Update widget configuration dynamically.
135
135
 
136
+ #### Example: Fetch config from an API and update at runtime
137
+
138
+ ```html
139
+ <script type="module">
140
+ import Chatbot from 'https://cdn.jsdelivr.net/npm/@deepfrog/pangents-widget/dist/widget.min.js';
141
+
142
+ Chatbot.init({
143
+ pangentsApiKey: '<api_key>',
144
+ tenantId: '<tenant_id>'
145
+ });
146
+
147
+ async function loadWidgetConfig() {
148
+ const res = await fetch('https://api.example.com/widget-config?tenant=<tenant_id>');
149
+ if (!res.ok) throw new Error('Failed to load widget config');
150
+ const remote = await res.json();
151
+
152
+ Chatbot.updateConfig({
153
+ pangentsApiKey: remote.pangentsApiKey ?? '<api_key>',
154
+ tenantId: remote.tenantId ?? '<tenant_id>',
155
+ email: remote.email,
156
+ theme: remote.theme,
157
+ position: remote.position,
158
+ margin: remote.margin,
159
+ zIndex: remote.zIndex
160
+ });
161
+ }
162
+
163
+ loadWidgetConfig();
164
+ </script>
165
+ ```
166
+
167
+ ```ts
168
+ // ESM/bundlers
169
+ import Chatbot from '@deepfrog/pangents-widget/widget';
170
+
171
+ Chatbot.init({
172
+ pangentsApiKey: '<api_key>',
173
+ tenantId: '<tenant_id>'
174
+ });
175
+
176
+ const res = await fetch('/api/widget-config');
177
+ if (!res.ok) throw new Error('Failed to load widget config');
178
+ const cfg = await res.json();
179
+
180
+ Chatbot.updateConfig({
181
+ pangentsApiKey: cfg.pangentsApiKey,
182
+ tenantId: cfg.tenantId,
183
+ email: cfg.email,
184
+ theme: cfg.theme,
185
+ position: cfg.position,
186
+ margin: cfg.margin,
187
+ zIndex: cfg.zIndex
188
+ });
189
+ ```
190
+
136
191
  ### `Chatbot.updateTheme(theme)`
137
192
 
138
193
  Update only the theme configuration.
package/dist/index.cjs.js CHANGED
@@ -6,5 +6,5 @@
6
6
  }
7
7
  } catch (error) {}
8
8
  })();
9
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./widget-embed-BPoilyw_.cjs.js"),t=require("react/jsx-runtime"),n=require("react"),o=e=>Object.freeze(Object.defineProperty({__proto__:null,default:e},Symbol.toStringTag,{value:"Module"}));if("undefined"!=typeof window)try{const e=window.__PANGENTS_WIDGET_CSS;if(e&&!document.getElementById("pangents-widget-styles")){const t=document.createElement("style");t.id="pangents-widget-styles",t.textContent=e,document.head.appendChild(t)}}catch{}exports.Chatbot=e.Chatbot,exports.Widget=e.Widget,exports.ChatbotWidget=({pangentsApiKey:e,email:r,tenantId:i,theme:s,position:d="bottom-right",zIndex:c=9999,onInit:a,onDestroy:l})=>{const u=n.useRef(null),g=n.useRef(null);return n.useEffect(()=>((async()=>{try{const{default:t}=await Promise.resolve().then(()=>o(require("./widget-embed.cjs.js"))),n={pangentsApiKey:e,email:r,tenantId:i,theme:s,position:d,zIndex:c};u.current=t,t.init(n),a&&a()}catch(t){console.error("Failed to initialize chatbot widget:",t)}})(),()=>{if(u.current)try{u.current.destroy(),l&&l()}catch(e){console.error("Error destroying chatbot widget:",e)}}),[e,r,i,s,d,c,a,l]),n.useEffect(()=>{if(u.current){const n={pangentsApiKey:e,email:r,tenantId:i,theme:s,position:d,zIndex:c};try{u.current.updateConfig(n)}catch(t){console.error("Error updating chatbot widget config:",t)}}},[e,r,i,s,d,c]),t.jsx("div",{ref:g,style:{display:"none"}})};
9
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./widget-embed-DCSN_j6Y.cjs.js"),t=require("react/jsx-runtime"),n=require("react"),o=e=>Object.freeze(Object.defineProperty({__proto__:null,default:e},Symbol.toStringTag,{value:"Module"}));if("undefined"!=typeof window)try{const e=window.__PANGENTS_WIDGET_CSS;if(e&&!document.getElementById("pangents-widget-styles")){const t=document.createElement("style");t.id="pangents-widget-styles",t.textContent=e,document.head.appendChild(t)}}catch{}exports.Chatbot=e.Chatbot,exports.Widget=e.Widget,exports.ChatbotWidget=({pangentsApiKey:e,email:r,tenantId:i,theme:s,position:d="bottom-right",zIndex:c=9999,onInit:a,onDestroy:l})=>{const u=n.useRef(null),g=n.useRef(null);return n.useEffect(()=>((async()=>{try{const{default:t}=await Promise.resolve().then(()=>o(require("./widget-embed.cjs.js"))),n={pangentsApiKey:e,email:r,tenantId:i,theme:s,position:d,zIndex:c};u.current=t,t.init(n),a&&a()}catch(t){console.error("Failed to initialize chatbot widget:",t)}})(),()=>{if(u.current)try{u.current.destroy(),l&&l()}catch(e){console.error("Error destroying chatbot widget:",e)}}),[e,r,i,s,d,c,a,l]),n.useEffect(()=>{if(u.current){const n={pangentsApiKey:e,email:r,tenantId:i,theme:s,position:d,zIndex:c};try{u.current.updateConfig(n)}catch(t){console.error("Error updating chatbot widget config:",t)}}},[e,r,i,s,d,c]),t.jsx("div",{ref:g,style:{display:"none"}})};
10
10
  //# sourceMappingURL=index.cjs.js.map
package/dist/index.es.js CHANGED
@@ -6,7 +6,7 @@
6
6
  }
7
7
  } catch (error) {}
8
8
  })();
9
- import { C, W } from "./widget-embed-CtD27t5y.es.js";
9
+ import { C, W } from "./widget-embed-DzLM7DN8.es.js";
10
10
  import { jsx } from "react/jsx-runtime";
11
11
  import { useRef, useEffect } from "react";
12
12
  const ChatbotWidget = ({