llmasaservice-ui 0.7.24 → 0.7.26

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/dist/index.js CHANGED
@@ -241,6 +241,10 @@ var ChatPanel = ({
241
241
  if (Object.keys(initialHistory).length === 0) return;
242
242
  setHistory(initialHistory);
243
243
  }, [initialHistory]);
244
+ (0, import_react3.useEffect)(() => {
245
+ if (!conversation || conversation === "") return;
246
+ setHistory(initialHistory);
247
+ }, [conversation]);
244
248
  (0, import_react3.useEffect)(() => {
245
249
  const handleBeforeUnload = (event) => {
246
250
  if (callToActionMustSendEmail && showCallToAction && callToActionEmailAddress && callToActionEmailAddress !== "" && !hasSentCallToActionEmail) {
@@ -255,13 +259,44 @@ var ChatPanel = ({
255
259
  };
256
260
  }, []);
257
261
  (0, import_react3.useEffect)(() => {
258
- if (cssUrl && cssUrl !== "") {
259
- const link = document.createElement("link");
260
- link.href = cssUrl;
261
- link.rel = "stylesheet";
262
- document.head.appendChild(link);
263
- console.log("Added css link", link);
262
+ const existingLinks = document.querySelectorAll('link[data-source="llmasaservice-ui"]');
263
+ existingLinks.forEach((link) => {
264
+ var _a;
265
+ return (_a = link.parentNode) == null ? void 0 : _a.removeChild(link);
266
+ });
267
+ const existingStyles = document.querySelectorAll('style[data-source="llmasaservice-ui"]');
268
+ existingStyles.forEach((style) => {
269
+ var _a;
270
+ return (_a = style.parentNode) == null ? void 0 : _a.removeChild(style);
271
+ });
272
+ if (cssUrl) {
273
+ if (cssUrl.startsWith("http://") || cssUrl.startsWith("https://") || cssUrl.startsWith("/")) {
274
+ const link = document.createElement("link");
275
+ link.href = cssUrl;
276
+ link.rel = "stylesheet";
277
+ link.setAttribute("data-source", "llmasaservice-ui");
278
+ document.head.appendChild(link);
279
+ console.log("Added CSS link", link);
280
+ } else {
281
+ const style = document.createElement("style");
282
+ style.textContent = cssUrl;
283
+ style.setAttribute("data-source", "llmasaservice-ui");
284
+ document.head.appendChild(style);
285
+ console.log("Added inline CSS", style);
286
+ }
264
287
  }
288
+ return () => {
289
+ const links = document.querySelectorAll('link[data-source="llmasaservice-ui"]');
290
+ links.forEach((link) => {
291
+ var _a;
292
+ return (_a = link.parentNode) == null ? void 0 : _a.removeChild(link);
293
+ });
294
+ const styles = document.querySelectorAll('style[data-source="llmasaservice-ui"]');
295
+ styles.forEach((style) => {
296
+ var _a;
297
+ return (_a = style.parentNode) == null ? void 0 : _a.removeChild(style);
298
+ });
299
+ };
265
300
  }, [cssUrl]);
266
301
  (0, import_react3.useEffect)(() => {
267
302
  if (response && response.length > 0) {
package/dist/index.mjs CHANGED
@@ -207,6 +207,10 @@ var ChatPanel = ({
207
207
  if (Object.keys(initialHistory).length === 0) return;
208
208
  setHistory(initialHistory);
209
209
  }, [initialHistory]);
210
+ useEffect(() => {
211
+ if (!conversation || conversation === "") return;
212
+ setHistory(initialHistory);
213
+ }, [conversation]);
210
214
  useEffect(() => {
211
215
  const handleBeforeUnload = (event) => {
212
216
  if (callToActionMustSendEmail && showCallToAction && callToActionEmailAddress && callToActionEmailAddress !== "" && !hasSentCallToActionEmail) {
@@ -221,13 +225,44 @@ var ChatPanel = ({
221
225
  };
222
226
  }, []);
223
227
  useEffect(() => {
224
- if (cssUrl && cssUrl !== "") {
225
- const link = document.createElement("link");
226
- link.href = cssUrl;
227
- link.rel = "stylesheet";
228
- document.head.appendChild(link);
229
- console.log("Added css link", link);
228
+ const existingLinks = document.querySelectorAll('link[data-source="llmasaservice-ui"]');
229
+ existingLinks.forEach((link) => {
230
+ var _a;
231
+ return (_a = link.parentNode) == null ? void 0 : _a.removeChild(link);
232
+ });
233
+ const existingStyles = document.querySelectorAll('style[data-source="llmasaservice-ui"]');
234
+ existingStyles.forEach((style) => {
235
+ var _a;
236
+ return (_a = style.parentNode) == null ? void 0 : _a.removeChild(style);
237
+ });
238
+ if (cssUrl) {
239
+ if (cssUrl.startsWith("http://") || cssUrl.startsWith("https://") || cssUrl.startsWith("/")) {
240
+ const link = document.createElement("link");
241
+ link.href = cssUrl;
242
+ link.rel = "stylesheet";
243
+ link.setAttribute("data-source", "llmasaservice-ui");
244
+ document.head.appendChild(link);
245
+ console.log("Added CSS link", link);
246
+ } else {
247
+ const style = document.createElement("style");
248
+ style.textContent = cssUrl;
249
+ style.setAttribute("data-source", "llmasaservice-ui");
250
+ document.head.appendChild(style);
251
+ console.log("Added inline CSS", style);
252
+ }
230
253
  }
254
+ return () => {
255
+ const links = document.querySelectorAll('link[data-source="llmasaservice-ui"]');
256
+ links.forEach((link) => {
257
+ var _a;
258
+ return (_a = link.parentNode) == null ? void 0 : _a.removeChild(link);
259
+ });
260
+ const styles = document.querySelectorAll('style[data-source="llmasaservice-ui"]');
261
+ styles.forEach((style) => {
262
+ var _a;
263
+ return (_a = style.parentNode) == null ? void 0 : _a.removeChild(style);
264
+ });
265
+ };
231
266
  }, [cssUrl]);
232
267
  useEffect(() => {
233
268
  if (response && response.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llmasaservice-ui",
3
- "version": "0.7.24",
3
+ "version": "0.7.26",
4
4
  "description": "Prebuilt UI components for LLMAsAService.io",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/ChatPanel.tsx CHANGED
@@ -164,6 +164,11 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
164
164
 
165
165
  }, [initialHistory]);
166
166
 
167
+ useEffect(() => {
168
+ if (!conversation || conversation === "") return;
169
+ setHistory(initialHistory);
170
+ }, [conversation]);
171
+
167
172
  useEffect(() => {
168
173
  const handleBeforeUnload = (event: BeforeUnloadEvent) => {
169
174
  if (
@@ -187,13 +192,42 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
187
192
  }, []);
188
193
 
189
194
  useEffect(() => {
190
- if (cssUrl && cssUrl !== "") {
191
- const link = document.createElement("link");
192
- link.href = cssUrl;
193
- link.rel = "stylesheet";
194
- document.head.appendChild(link);
195
- console.log("Added css link", link);
195
+ // Clean up any previously added CSS from this component
196
+ const existingLinks = document.querySelectorAll('link[data-source="llmasaservice-ui"]');
197
+ existingLinks.forEach(link => link.parentNode?.removeChild(link));
198
+
199
+ const existingStyles = document.querySelectorAll('style[data-source="llmasaservice-ui"]');
200
+ existingStyles.forEach(style => style.parentNode?.removeChild(style));
201
+
202
+ if (cssUrl) {
203
+ if (cssUrl.startsWith('http://') || cssUrl.startsWith('https://') || cssUrl.startsWith('/')) {
204
+ // If it's a URL, create a link element
205
+ const link = document.createElement("link");
206
+ link.href = cssUrl;
207
+ link.rel = "stylesheet";
208
+ // Add a data attribute to identify and remove this link later if needed
209
+ link.setAttribute('data-source', 'llmasaservice-ui');
210
+ document.head.appendChild(link);
211
+ console.log("Added CSS link", link);
212
+ } else {
213
+ // If it's a CSS string, create a style element
214
+ const style = document.createElement("style");
215
+ style.textContent = cssUrl;
216
+ // Add a data attribute to identify and remove this style later if needed
217
+ style.setAttribute('data-source', 'llmasaservice-ui');
218
+ document.head.appendChild(style);
219
+ console.log("Added inline CSS", style);
220
+ }
196
221
  }
222
+
223
+ // Clean up when component unmounts
224
+ return () => {
225
+ const links = document.querySelectorAll('link[data-source="llmasaservice-ui"]');
226
+ links.forEach(link => link.parentNode?.removeChild(link));
227
+
228
+ const styles = document.querySelectorAll('style[data-source="llmasaservice-ui"]');
229
+ styles.forEach(style => style.parentNode?.removeChild(style));
230
+ };
197
231
  }, [cssUrl]);
198
232
 
199
233
  // response change. Update the history