@flowengage/react-chatbot 1.8.1 → 1.8.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.
@@ -2346,7 +2346,9 @@ async function $n(e, { skipPushState: t = !1, isBack: n = !1 } = {}) {
2346
2346
  try {
2347
2347
  typeof window.Drupal?.detachBehaviors == "function" && window.Drupal.detachBehaviors(document.body, window.drupalSettings);
2348
2348
  } catch {}
2349
- Array.from(document.body.children).forEach((e) => {
2349
+ document.querySelectorAll("script").forEach((e) => {
2350
+ e.setAttribute("data-fe-original", "true");
2351
+ }), Array.from(document.body.children).forEach((e) => {
2350
2352
  if (e === c) return;
2351
2353
  let t = e.tagName?.toUpperCase();
2352
2354
  t === "AUDIO" || t === "VIDEO" || e.remove();
@@ -2381,6 +2383,40 @@ async function $n(e, { skipPushState: t = !1, isBack: n = !1 } = {}) {
2381
2383
  Array.from(s.body.children).forEach((e) => {
2382
2384
  e.tagName?.toUpperCase() !== "SCRIPT" && document.body.insertBefore(document.importNode(e, !0), c);
2383
2385
  });
2386
+ let u = document.querySelectorAll("script:not([data-fe-replayed])");
2387
+ for (let e of u) {
2388
+ if (e.closest("#flowengage-root, .flowengage-shell") || e.hasAttribute("data-fe-original") || e.hasAttribute("data-fe-replayed")) continue;
2389
+ let t = e.getAttribute("src"), n = e.getAttribute("type") || "";
2390
+ if (!(n && n !== "text/javascript" && n !== "" && !n.includes("drupal-ajax"))) {
2391
+ if (n.includes("drupal-ajax")) {
2392
+ e.setAttribute("data-fe-replayed", "true");
2393
+ try {
2394
+ let t = JSON.parse(e.textContent);
2395
+ if (Array.isArray(t)) for (let e of t) {
2396
+ if ((e.command === "insert" || e.command === "insert_new_content") && e.selector && e.data) {
2397
+ let t = document.querySelector(e.selector);
2398
+ t && (e.method === "replaceWith" ? t.outerHTML = e.data : e.method === "html" || e.method === "replace" ? t.innerHTML = e.data : e.method === "append" ? t.insertAdjacentHTML("beforeend", e.data) : e.method === "prepend" ? t.insertAdjacentHTML("afterbegin", e.data) : t.innerHTML = e.data, j("trySpaNavigate: BigPipe replacement →", e.selector));
2399
+ }
2400
+ if (e.command === "settings" && e.settings) try {
2401
+ window.drupalSettings && typeof window.drupalSettings == "object" && Object.assign(window.drupalSettings, e.settings);
2402
+ } catch {}
2403
+ }
2404
+ } catch (e) {
2405
+ j("trySpaNavigate: BigPipe parse error:", e.message);
2406
+ }
2407
+ continue;
2408
+ }
2409
+ if (!t && e.textContent.trim()) {
2410
+ let t = e.textContent;
2411
+ if (/window\.location\s*[.=]|location\s*\.\s*(href|assign|replace|reload)\s*[=(]/i.test(t)) {
2412
+ e.setAttribute("data-fe-replayed", "true");
2413
+ continue;
2414
+ }
2415
+ let n = document.createElement("script");
2416
+ n.textContent = t, n.setAttribute("data-fe-replayed", "true"), e.parentNode.replaceChild(n, e);
2417
+ }
2418
+ }
2419
+ }
2384
2420
  try {
2385
2421
  for (let e of Array.from(s.querySelectorAll("script"))) {
2386
2422
  let t = (e.textContent || "").match(/drupalSettings\s*[,=]\s*(\{[\s\S]*?\})\s*[;)]/);
@@ -2393,32 +2429,32 @@ async function $n(e, { skipPushState: t = !1, isBack: n = !1 } = {}) {
2393
2429
  }
2394
2430
  }
2395
2431
  } catch {}
2396
- let u = window.location.assign.bind(window.location), d = window.location.replace.bind(window.location), f = !0;
2432
+ let d = window.location.assign.bind(window.location), f = window.location.replace.bind(window.location), p = !0;
2397
2433
  window.location.assign = (e) => {
2398
- if (f) {
2434
+ if (p) {
2399
2435
  j("trySpaNavigate: blocked location.assign from replayed script:", e);
2400
2436
  return;
2401
2437
  }
2402
- return u(e);
2438
+ return d(e);
2403
2439
  }, window.location.replace = (e) => {
2404
- if (f) {
2440
+ if (p) {
2405
2441
  j("trySpaNavigate: blocked location.replace from replayed script:", e);
2406
2442
  return;
2407
2443
  }
2408
- return d(e);
2444
+ return f(e);
2409
2445
  };
2410
- function p(e) {
2446
+ function m(e) {
2411
2447
  let t = e.toLowerCase();
2412
2448
  return !!(/\/jquery[.\-\/]/.test(t) || /\/jquery\.min\.js/.test(t) || /\/jquery-once/.test(t) || /\/jquery\.once/.test(t) || /\/jquery\.ui[\./]/.test(t) || /\/jqueryui/.test(t) || /\/core\/misc\//.test(t) || /\/core\/modules\//.test(t) || /\/misc\/drupal\.js/.test(t) || /\/lodash[.\-\/]/.test(t) || /\/underscore[.\-\/]/.test(t) || /\/backbone[.\-\/]/.test(t) || /\/modernizr[.\-\/]/.test(t) || /\/popper[.\-\/]/.test(t) || /\/bootstrap\.min\.js/.test(t) || /\/bootstrap\.bundle/.test(t));
2413
2449
  }
2414
- let m = new Set(Array.from(document.querySelectorAll("script[src]")).map((e) => {
2450
+ let h = new Set(Array.from(document.querySelectorAll("script[src]")).map((e) => {
2415
2451
  try {
2416
2452
  return new URL(e.getAttribute("src") || "", window.location.href).href;
2417
2453
  } catch {
2418
2454
  return "";
2419
2455
  }
2420
2456
  }));
2421
- function h(t, n) {
2457
+ function g(t, n) {
2422
2458
  let r = t.getAttribute("src") || "";
2423
2459
  if (r.includes("flowengage")) return;
2424
2460
  let i = document.createElement("script");
@@ -2429,11 +2465,11 @@ async function $n(e, { skipPushState: t = !1, isBack: n = !1 } = {}) {
2429
2465
  } catch {
2430
2466
  return;
2431
2467
  }
2432
- if (m.has(n)) {
2433
- if (p(n)) return;
2468
+ if (h.has(n)) {
2469
+ if (m(n)) return;
2434
2470
  j("trySpaNavigate: re-running theme/custom script:", n);
2435
2471
  }
2436
- m.add(n), i.src = n, i.async = t.async, i.defer = t.defer;
2472
+ h.add(n), i.src = n, i.async = t.async, i.defer = t.defer;
2437
2473
  } else if (t.textContent.trim()) {
2438
2474
  let e = t.textContent;
2439
2475
  if (/window\.location\s*[.=]|location\s*\.\s*(href|assign|replace|reload)\s*[=(]/i.test(e)) {
@@ -2446,16 +2482,40 @@ async function $n(e, { skipPushState: t = !1, isBack: n = !1 } = {}) {
2446
2482
  let a = t.getAttribute("type");
2447
2483
  a && a !== "text/javascript" && a !== "" && (i.type = a), n.parentNode.insertBefore(i, n);
2448
2484
  }
2449
- for (let e of Array.from(s.head.querySelectorAll("script"))) h(e, c);
2450
- for (let e of Array.from(s.body.querySelectorAll("script"))) h(e, c);
2485
+ for (let e of Array.from(s.head.querySelectorAll("script"))) g(e, c);
2486
+ for (let e of Array.from(s.body.querySelectorAll("script"))) g(e, c);
2451
2487
  try {
2452
2488
  typeof window.Drupal?.attachBehaviors == "function" && window.Drupal.attachBehaviors(document.body, window.drupalSettings);
2453
2489
  } catch {}
2454
2490
  try {
2455
2491
  typeof window.jQuery == "function" && (window.jQuery(document).trigger("ready"), window.dispatchEvent(new Event("resize")));
2456
2492
  } catch {}
2493
+ try {
2494
+ let e = document.querySelectorAll("iframe:not([data-fe-skip-reload])");
2495
+ for (let t of e) {
2496
+ if (t.closest("#flowengage-root, .flowengage-shell")) continue;
2497
+ let e = t.getAttribute("src") || t.src;
2498
+ e && e !== "about:blank" && !e.startsWith("javascript:") && (j("trySpaNavigate: reloading iframe:", e), t.src = e);
2499
+ }
2500
+ } catch {}
2501
+ try {
2502
+ let e = document.querySelectorAll(".g-recaptcha, [data-sitekey]");
2503
+ if (e.length > 0) {
2504
+ if (typeof window.grecaptcha?.render == "function") {
2505
+ for (let t of e) if (!t.closest("#flowengage-root")) {
2506
+ t.innerHTML = "";
2507
+ try {
2508
+ window.grecaptcha.render(t, { sitekey: t.getAttribute("data-sitekey") || "" }), j("trySpaNavigate: re-rendered reCAPTCHA");
2509
+ } catch {}
2510
+ }
2511
+ } else if (!document.querySelector("script[src*='recaptcha']")) {
2512
+ let e = document.createElement("script");
2513
+ e.src = "https://www.google.com/recaptcha/api.js?render=explicit", e.async = !0, document.head.appendChild(e), j("trySpaNavigate: injected reCAPTCHA script");
2514
+ }
2515
+ }
2516
+ } catch {}
2457
2517
  if (setTimeout(() => {
2458
- f = !1, window.location.assign = u, window.location.replace = d;
2518
+ p = !1, window.location.assign = d, window.location.replace = f;
2459
2519
  }, 2e3), s.title && (document.title = s.title), !t) try {
2460
2520
  history.pushState({ flowengageSpa: !0 }, "", e);
2461
2521
  } catch {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowengage/react-chatbot",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "description": "Embeddable AI chat widget for React — powered by FlowEngage. Drop it in with a single siteId.",
5
5
  "keywords": [
6
6
  "chatbot",