@flowengage/react-chatbot 1.8.1 → 1.8.3

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,24 +2429,20 @@ 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) {
2411
- let t = e.toLowerCase();
2412
- 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
- }
2414
2446
  let m = new Set(Array.from(document.querySelectorAll("script[src]")).map((e) => {
2415
2447
  try {
2416
2448
  return new URL(e.getAttribute("src") || "", window.location.href).href;
@@ -2420,42 +2452,68 @@ async function $n(e, { skipPushState: t = !1, isBack: n = !1 } = {}) {
2420
2452
  }));
2421
2453
  function h(t, n) {
2422
2454
  let r = t.getAttribute("src") || "";
2423
- if (r.includes("flowengage")) return;
2424
- let i = document.createElement("script");
2425
- if (r) {
2426
- let n;
2427
- try {
2428
- n = new URL(r, e).href;
2429
- } catch {
2430
- return;
2431
- }
2432
- if (m.has(n)) {
2433
- if (p(n)) return;
2434
- j("trySpaNavigate: re-running theme/custom script:", n);
2435
- }
2436
- m.add(n), i.src = n, i.async = t.async, i.defer = t.defer;
2437
- } else if (t.textContent.trim()) {
2438
- let e = t.textContent;
2439
- if (/window\.location\s*[.=]|location\s*\.\s*(href|assign|replace|reload)\s*[=(]/i.test(e)) {
2440
- j("trySpaNavigate: skipping inline script with navigation:", e.slice(0, 120));
2441
- return;
2455
+ if (!r.includes("flowengage")) {
2456
+ if (r) {
2457
+ let i;
2458
+ try {
2459
+ i = new URL(r, e).href;
2460
+ } catch {
2461
+ return;
2462
+ }
2463
+ if (m.has(i)) return;
2464
+ m.add(i);
2465
+ let a = document.createElement("script");
2466
+ a.src = i, a.async = t.async, a.defer = t.defer;
2467
+ let o = t.getAttribute("type");
2468
+ o && o !== "text/javascript" && o !== "" && (a.type = o), n.parentNode.insertBefore(a, n), j("trySpaNavigate: loading NEW external script:", i);
2469
+ } else if (t.textContent.trim()) {
2470
+ let e = t.textContent, r = t.getAttribute("type") || "";
2471
+ if (r && r !== "text/javascript" && r !== "" || /window\.location\s*[.=]|location\s*\.\s*(href|assign|replace|reload)\s*[=(]/i.test(e) || /drupalSettings\s*[,=]/.test(e)) return;
2472
+ let i = document.createElement("script");
2473
+ i.textContent = `(function(){try{${e}}catch(e){if(!(e instanceof SyntaxError))throw e;}})();`, n.parentNode.insertBefore(i, n);
2442
2474
  }
2443
- if (/^\s*\(?\s*(?:window\.)?drupalSettings\s*[,=]/.test(e)) return;
2444
- i.textContent = e;
2445
- } else return;
2446
- let a = t.getAttribute("type");
2447
- a && a !== "text/javascript" && a !== "" && (i.type = a), n.parentNode.insertBefore(i, n);
2448
- }
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);
2475
+ }
2476
+ }
2477
+ for (let e of Array.from(s.body.querySelectorAll(":scope > script"))) h(e, c);
2451
2478
  try {
2452
- typeof window.Drupal?.attachBehaviors == "function" && window.Drupal.attachBehaviors(document.body, window.drupalSettings);
2479
+ if (typeof window.Drupal?.attachBehaviors == "function") {
2480
+ let e = window.Drupal.behaviors || {};
2481
+ for (let [t, n] of Object.entries(e)) if (typeof n.attach == "function") try {
2482
+ n.attach(document.body, window.drupalSettings);
2483
+ } catch (e) {
2484
+ j("trySpaNavigate: behavior", t, "attach error:", e.message);
2485
+ }
2486
+ }
2453
2487
  } catch {}
2454
2488
  try {
2455
2489
  typeof window.jQuery == "function" && (window.jQuery(document).trigger("ready"), window.dispatchEvent(new Event("resize")));
2456
2490
  } catch {}
2491
+ try {
2492
+ let e = document.querySelectorAll("iframe:not([data-fe-skip-reload])");
2493
+ for (let t of e) {
2494
+ if (t.closest("#flowengage-root, .flowengage-shell")) continue;
2495
+ let e = t.getAttribute("src") || t.src;
2496
+ e && e !== "about:blank" && !e.startsWith("javascript:") && (j("trySpaNavigate: reloading iframe:", e), t.src = e);
2497
+ }
2498
+ } catch {}
2499
+ try {
2500
+ let e = document.querySelectorAll(".g-recaptcha, [data-sitekey]");
2501
+ if (e.length > 0) {
2502
+ if (typeof window.grecaptcha?.render == "function") {
2503
+ for (let t of e) if (!t.closest("#flowengage-root")) {
2504
+ t.innerHTML = "";
2505
+ try {
2506
+ window.grecaptcha.render(t, { sitekey: t.getAttribute("data-sitekey") || "" }), j("trySpaNavigate: re-rendered reCAPTCHA");
2507
+ } catch {}
2508
+ }
2509
+ } else if (!document.querySelector("script[src*='recaptcha']")) {
2510
+ let e = document.createElement("script");
2511
+ e.src = "https://www.google.com/recaptcha/api.js?render=explicit", e.async = !0, document.head.appendChild(e), j("trySpaNavigate: injected reCAPTCHA script");
2512
+ }
2513
+ }
2514
+ } catch {}
2457
2515
  if (setTimeout(() => {
2458
- f = !1, window.location.assign = u, window.location.replace = d;
2516
+ p = !1, window.location.assign = d, window.location.replace = f;
2459
2517
  }, 2e3), s.title && (document.title = s.title), !t) try {
2460
2518
  history.pushState({ flowengageSpa: !0 }, "", e);
2461
2519
  } 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.3",
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",