@marketrix.ai/widget 1.0.16 → 1.0.18
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.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAYjD,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AACtF,OAAO,EAIL,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAYjD,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AACtF,OAAO,EAIL,gBAAgB,EAUjB,MAAM,mBAAmB,CAAC;AAoF3B,eAAO,MAAM,UAAU,GACrB,QAAQ,eAAe,EACvB,YAAY,WAAW,KACtB,OAAO,CAAC,IAAI,CAuHd,CAAC;AAKF,eAAO,MAAM,aAAa,QAAO,IAwBhC,CAAC;AAGF,eAAO,MAAM,qBAAqB,GAAU,WAAW,OAAO,CAAC,eAAe,CAAC,KAAG,OAAO,CAAC,IAAI,CAW7F,CAAC;AAGF,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CA0E1D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAU,QAAQ,eAAe,KAAG,OAAO,CAAC,IAAI,CAkDvE,CAAC;AAcF,YAAY,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAC7C,YAAY,EACV,eAAe,EACf,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,WAAW,GACZ,MAAM,SAAS,CAAC;;;0BAvEyB,eAAe,KAAG,OAAO,CAAC,IAAI,CAAC;yBA7P/D,eAAe,cACX,WAAW,KACtB,OAAO,CAAC,IAAI,CAAC;yBA4HiB,IAAI;uCA2BkB,OAAO,CAAC,eAAe,CAAC,KAAG,OAAO,CAAC,IAAI,CAAC;;;AA8K/F,wBAOE"}
|
package/dist/index.mjs
CHANGED
|
@@ -19582,6 +19582,9 @@ class SessionManager {
|
|
|
19582
19582
|
tabId = null;
|
|
19583
19583
|
initializationPromise = null;
|
|
19584
19584
|
constructor() {
|
|
19585
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
19586
|
+
return;
|
|
19587
|
+
}
|
|
19585
19588
|
this.tabId = this.getOrCreateTabId();
|
|
19586
19589
|
log$1.debug("Tab ID:", this.tabId);
|
|
19587
19590
|
this.chatId = this.getStoredChatId();
|
|
@@ -19595,6 +19598,9 @@ class SessionManager {
|
|
|
19595
19598
|
* This ensures the same tab_id is preserved when navigating to external domains.
|
|
19596
19599
|
*/
|
|
19597
19600
|
setupLinkInterceptor() {
|
|
19601
|
+
if (typeof document === "undefined") {
|
|
19602
|
+
return;
|
|
19603
|
+
}
|
|
19598
19604
|
document.addEventListener(
|
|
19599
19605
|
"click",
|
|
19600
19606
|
(event) => {
|
|
@@ -19626,6 +19632,9 @@ class SessionManager {
|
|
|
19626
19632
|
* 3. Generate new - for new tabs
|
|
19627
19633
|
*/
|
|
19628
19634
|
getOrCreateTabId() {
|
|
19635
|
+
if (typeof window === "undefined" || typeof sessionStorage === "undefined") {
|
|
19636
|
+
return this.generateTabId();
|
|
19637
|
+
}
|
|
19629
19638
|
const urlParams = new URLSearchParams(window.location.search);
|
|
19630
19639
|
const urlTabId = urlParams.get("_mktx_tab");
|
|
19631
19640
|
if (urlTabId) {
|
|
@@ -19646,6 +19655,9 @@ class SessionManager {
|
|
|
19646
19655
|
* Remove _mktx_tab parameter from URL without page reload
|
|
19647
19656
|
*/
|
|
19648
19657
|
cleanupTabIdFromUrl() {
|
|
19658
|
+
if (typeof window === "undefined") {
|
|
19659
|
+
return;
|
|
19660
|
+
}
|
|
19649
19661
|
const url = new URL(window.location.href);
|
|
19650
19662
|
if (url.searchParams.has("_mktx_tab")) {
|
|
19651
19663
|
url.searchParams.delete("_mktx_tab");
|
|
@@ -19668,6 +19680,15 @@ class SessionManager {
|
|
|
19668
19680
|
* Get singleton instance
|
|
19669
19681
|
*/
|
|
19670
19682
|
static getInstance() {
|
|
19683
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
19684
|
+
if (!SessionManager.instance) {
|
|
19685
|
+
SessionManager.instance = Object.create(SessionManager.prototype);
|
|
19686
|
+
SessionManager.instance.chatId = null;
|
|
19687
|
+
SessionManager.instance.tabId = null;
|
|
19688
|
+
SessionManager.instance.initializationPromise = null;
|
|
19689
|
+
}
|
|
19690
|
+
return SessionManager.instance;
|
|
19691
|
+
}
|
|
19671
19692
|
if (!SessionManager.instance) {
|
|
19672
19693
|
SessionManager.instance = new SessionManager();
|
|
19673
19694
|
}
|
|
@@ -19744,9 +19765,15 @@ class SessionManager {
|
|
|
19744
19765
|
SessionManager.instance = null;
|
|
19745
19766
|
}
|
|
19746
19767
|
getStoredChatId() {
|
|
19768
|
+
if (typeof localStorage === "undefined") {
|
|
19769
|
+
return null;
|
|
19770
|
+
}
|
|
19747
19771
|
return localStorage.getItem(CHAT_ID_STORAGE_KEY);
|
|
19748
19772
|
}
|
|
19749
19773
|
storeChatId(id) {
|
|
19774
|
+
if (typeof localStorage === "undefined") {
|
|
19775
|
+
return;
|
|
19776
|
+
}
|
|
19750
19777
|
localStorage.setItem(CHAT_ID_STORAGE_KEY, id);
|
|
19751
19778
|
}
|
|
19752
19779
|
}
|
|
@@ -38552,6 +38579,7 @@ const shadowStyles = "/*! tailwindcss v4.1.18 | MIT License | https://tailwindcs
|
|
|
38552
38579
|
let widgetInstance = null;
|
|
38553
38580
|
let currentConfig = null;
|
|
38554
38581
|
let loaderInstance = null;
|
|
38582
|
+
let programmaticInitInProgress = false;
|
|
38555
38583
|
let widgetInstanceCounter = 0;
|
|
38556
38584
|
const generateContainerId = () => {
|
|
38557
38585
|
return `marketrix-widget-container-${++widgetInstanceCounter}`;
|
|
@@ -38638,6 +38666,12 @@ const clearWidgetState = () => {
|
|
|
38638
38666
|
widgetInstance = null;
|
|
38639
38667
|
currentConfig = null;
|
|
38640
38668
|
};
|
|
38669
|
+
const setProgrammaticInitInProgress = (inProgress) => {
|
|
38670
|
+
programmaticInitInProgress = inProgress;
|
|
38671
|
+
};
|
|
38672
|
+
const isProgrammaticInitInProgress = () => {
|
|
38673
|
+
return programmaticInitInProgress;
|
|
38674
|
+
};
|
|
38641
38675
|
const showWidgetSettingsLoader = (message) => {
|
|
38642
38676
|
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
38643
38677
|
return;
|
|
@@ -38703,6 +38737,12 @@ const autoInitializeWidget = (retryCount = 0) => {
|
|
|
38703
38737
|
setTimeout(() => autoInitializeWidget(retryCount + 1), delay);
|
|
38704
38738
|
return;
|
|
38705
38739
|
}
|
|
38740
|
+
if (isWidgetInitialized() || isProgrammaticInitInProgress()) {
|
|
38741
|
+
console.log(
|
|
38742
|
+
"[AutoInit] Script tag not found, but widget is initialized or programmatic init is in progress. Skipping error message."
|
|
38743
|
+
);
|
|
38744
|
+
return;
|
|
38745
|
+
}
|
|
38706
38746
|
console.error("[AutoInit] Script tag not found after all retries");
|
|
38707
38747
|
console.error(
|
|
38708
38748
|
"[AutoInit] Available scripts:",
|
|
@@ -38775,6 +38815,12 @@ const autoInitializeWidget = (retryCount = 0) => {
|
|
|
38775
38815
|
console.error("[AutoInit] Failed to initialize widget:", error);
|
|
38776
38816
|
});
|
|
38777
38817
|
} else {
|
|
38818
|
+
if (isWidgetInitialized() || isProgrammaticInitInProgress()) {
|
|
38819
|
+
console.log(
|
|
38820
|
+
"[AutoInit] Missing required attributes, but widget is initialized or programmatic init is in progress. Skipping error message."
|
|
38821
|
+
);
|
|
38822
|
+
return;
|
|
38823
|
+
}
|
|
38778
38824
|
console.error("[AutoInit] Missing required attributes:", {
|
|
38779
38825
|
hasMtxId: !!mtxId,
|
|
38780
38826
|
hasMtxKey: !!mtxKey,
|
|
@@ -38852,8 +38898,10 @@ async function initializeWidgetWithConfig(config, validationResult) {
|
|
|
38852
38898
|
}
|
|
38853
38899
|
}
|
|
38854
38900
|
const initWidget = async (config, container) => {
|
|
38901
|
+
setProgrammaticInitInProgress(true);
|
|
38855
38902
|
if (isWidgetInitialized()) {
|
|
38856
38903
|
console.warn("Marketrix Widget: already initialized");
|
|
38904
|
+
setProgrammaticInitInProgress(false);
|
|
38857
38905
|
return;
|
|
38858
38906
|
}
|
|
38859
38907
|
if (config.mtxApiHost) {
|
|
@@ -38867,6 +38915,7 @@ const initWidget = async (config, container) => {
|
|
|
38867
38915
|
showWidgetSettingsLoader(
|
|
38868
38916
|
validationResult.error || "Widget validation failed. Please check your configuration."
|
|
38869
38917
|
);
|
|
38918
|
+
setProgrammaticInitInProgress(false);
|
|
38870
38919
|
return;
|
|
38871
38920
|
}
|
|
38872
38921
|
let finalConfig;
|
|
@@ -38875,6 +38924,7 @@ const initWidget = async (config, container) => {
|
|
|
38875
38924
|
} catch (error) {
|
|
38876
38925
|
const errorMessage = error instanceof Error ? error.message : "Failed to initialize widget";
|
|
38877
38926
|
showWidgetSettingsLoader(errorMessage);
|
|
38927
|
+
setProgrammaticInitInProgress(false);
|
|
38878
38928
|
return;
|
|
38879
38929
|
}
|
|
38880
38930
|
setCurrentConfig(finalConfig);
|
|
@@ -38882,6 +38932,7 @@ const initWidget = async (config, container) => {
|
|
|
38882
38932
|
const { mountEl } = createWidgetContainer(container, containerId);
|
|
38883
38933
|
const instance = mountWidgetToContainer(mountEl, finalConfig);
|
|
38884
38934
|
setWidgetInstance(instance);
|
|
38935
|
+
setProgrammaticInitInProgress(false);
|
|
38885
38936
|
try {
|
|
38886
38937
|
if (sessionRecorder && isRecordingInitialized) {
|
|
38887
38938
|
console.warn(
|
|
@@ -39013,6 +39064,7 @@ const MarketrixWidget = ({ settings, container }) => {
|
|
|
39013
39064
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: containerRef, style: { width: "100%", height: "100%", position: "relative" } });
|
|
39014
39065
|
};
|
|
39015
39066
|
const mountWidget = async (config) => {
|
|
39067
|
+
setProgrammaticInitInProgress(true);
|
|
39016
39068
|
const container = config.container;
|
|
39017
39069
|
if ("settings" in config && config.settings !== void 0) {
|
|
39018
39070
|
const previewConfig = config;
|
|
@@ -39023,6 +39075,7 @@ const mountWidget = async (config) => {
|
|
|
39023
39075
|
const { mountEl } = createWidgetContainer(container, containerId);
|
|
39024
39076
|
const instance = mountWidgetToContainer(mountEl, finalConfig);
|
|
39025
39077
|
setWidgetInstance(instance);
|
|
39078
|
+
setProgrammaticInitInProgress(false);
|
|
39026
39079
|
} else if ("mtxId" in config && config.mtxId !== void 0 && config.mtxKey !== void 0) {
|
|
39027
39080
|
const prodConfig = config;
|
|
39028
39081
|
const { mtxId, mtxKey, container: _container, ...restConfig } = prodConfig;
|
|
@@ -39046,6 +39099,7 @@ const mountWidget = async (config) => {
|
|
|
39046
39099
|
container
|
|
39047
39100
|
);
|
|
39048
39101
|
} else {
|
|
39102
|
+
setProgrammaticInitInProgress(false);
|
|
39049
39103
|
throw new Error(
|
|
39050
39104
|
"Invalid configuration: provide either settings (preview), mtxId+mtxKey (production), or mtxApp+mtxAgent (dev)"
|
|
39051
39105
|
);
|