@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 +55 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/{widget-embed-BPoilyw_.cjs.js → widget-embed-DCSN_j6Y.cjs.js} +4 -4
- package/dist/widget-embed-DCSN_j6Y.cjs.js.map +1 -0
- package/dist/{widget-embed-CtD27t5y.es.js → widget-embed-DzLM7DN8.es.js} +26 -24
- package/dist/widget-embed-DzLM7DN8.es.js.map +1 -0
- package/dist/widget-embed.cjs.js +1 -1
- package/dist/widget-embed.es.js +1 -1
- package/dist/widget.js +25 -23
- package/package.json +1 -1
- package/dist/widget-embed-BPoilyw_.cjs.js.map +0 -1
- package/dist/widget-embed-CtD27t5y.es.js.map +0 -1
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-
|
|
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