@getwidgets/live-chat-widget 1.0.4 → 1.0.6
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/live-chat-widget.umd.js +215 -32
- package/package.json +1 -1
|
@@ -19536,6 +19536,180 @@
|
|
|
19536
19536
|
rnds[8] = rnds[8] & 63 | 128;
|
|
19537
19537
|
return unsafeStringify(rnds);
|
|
19538
19538
|
}
|
|
19539
|
+
/**
|
|
19540
|
+
* @license lucide-react v0.456.0 - ISC
|
|
19541
|
+
*
|
|
19542
|
+
* This source code is licensed under the ISC license.
|
|
19543
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
19544
|
+
*/
|
|
19545
|
+
const toKebabCase = (string2) => string2.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
19546
|
+
const mergeClasses = (...classes) => classes.filter((className, index2, array) => {
|
|
19547
|
+
return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index2;
|
|
19548
|
+
}).join(" ").trim();
|
|
19549
|
+
/**
|
|
19550
|
+
* @license lucide-react v0.456.0 - ISC
|
|
19551
|
+
*
|
|
19552
|
+
* This source code is licensed under the ISC license.
|
|
19553
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
19554
|
+
*/
|
|
19555
|
+
var defaultAttributes = {
|
|
19556
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
19557
|
+
width: 24,
|
|
19558
|
+
height: 24,
|
|
19559
|
+
viewBox: "0 0 24 24",
|
|
19560
|
+
fill: "none",
|
|
19561
|
+
stroke: "currentColor",
|
|
19562
|
+
strokeWidth: 2,
|
|
19563
|
+
strokeLinecap: "round",
|
|
19564
|
+
strokeLinejoin: "round"
|
|
19565
|
+
};
|
|
19566
|
+
/**
|
|
19567
|
+
* @license lucide-react v0.456.0 - ISC
|
|
19568
|
+
*
|
|
19569
|
+
* This source code is licensed under the ISC license.
|
|
19570
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
19571
|
+
*/
|
|
19572
|
+
const Icon = reactExports.forwardRef(
|
|
19573
|
+
({
|
|
19574
|
+
color: color2 = "currentColor",
|
|
19575
|
+
size = 24,
|
|
19576
|
+
strokeWidth = 2,
|
|
19577
|
+
absoluteStrokeWidth,
|
|
19578
|
+
className = "",
|
|
19579
|
+
children,
|
|
19580
|
+
iconNode,
|
|
19581
|
+
...rest
|
|
19582
|
+
}, ref) => {
|
|
19583
|
+
return reactExports.createElement(
|
|
19584
|
+
"svg",
|
|
19585
|
+
{
|
|
19586
|
+
ref,
|
|
19587
|
+
...defaultAttributes,
|
|
19588
|
+
width: size,
|
|
19589
|
+
height: size,
|
|
19590
|
+
stroke: color2,
|
|
19591
|
+
strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
|
|
19592
|
+
className: mergeClasses("lucide", className),
|
|
19593
|
+
...rest
|
|
19594
|
+
},
|
|
19595
|
+
[
|
|
19596
|
+
...iconNode.map(([tag, attrs]) => reactExports.createElement(tag, attrs)),
|
|
19597
|
+
...Array.isArray(children) ? children : [children]
|
|
19598
|
+
]
|
|
19599
|
+
);
|
|
19600
|
+
}
|
|
19601
|
+
);
|
|
19602
|
+
/**
|
|
19603
|
+
* @license lucide-react v0.456.0 - ISC
|
|
19604
|
+
*
|
|
19605
|
+
* This source code is licensed under the ISC license.
|
|
19606
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
19607
|
+
*/
|
|
19608
|
+
const createLucideIcon = (iconName, iconNode) => {
|
|
19609
|
+
const Component = reactExports.forwardRef(
|
|
19610
|
+
({ className, ...props }, ref) => reactExports.createElement(Icon, {
|
|
19611
|
+
ref,
|
|
19612
|
+
iconNode,
|
|
19613
|
+
className: mergeClasses(`lucide-${toKebabCase(iconName)}`, className),
|
|
19614
|
+
...props
|
|
19615
|
+
})
|
|
19616
|
+
);
|
|
19617
|
+
Component.displayName = `${iconName}`;
|
|
19618
|
+
return Component;
|
|
19619
|
+
};
|
|
19620
|
+
/**
|
|
19621
|
+
* @license lucide-react v0.456.0 - ISC
|
|
19622
|
+
*
|
|
19623
|
+
* This source code is licensed under the ISC license.
|
|
19624
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
19625
|
+
*/
|
|
19626
|
+
const Send = createLucideIcon("Send", [
|
|
19627
|
+
[
|
|
19628
|
+
"path",
|
|
19629
|
+
{
|
|
19630
|
+
d: "M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",
|
|
19631
|
+
key: "1ffxy3"
|
|
19632
|
+
}
|
|
19633
|
+
],
|
|
19634
|
+
["path", { d: "m21.854 2.147-10.94 10.939", key: "12cjpa" }]
|
|
19635
|
+
]);
|
|
19636
|
+
var DefaultContext = {
|
|
19637
|
+
color: void 0,
|
|
19638
|
+
size: void 0,
|
|
19639
|
+
className: void 0,
|
|
19640
|
+
style: void 0,
|
|
19641
|
+
attr: void 0
|
|
19642
|
+
};
|
|
19643
|
+
var IconContext = React.createContext && React.createContext(DefaultContext);
|
|
19644
|
+
var __assign = function() {
|
|
19645
|
+
__assign = Object.assign || function(t2) {
|
|
19646
|
+
for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
|
|
19647
|
+
s = arguments[i];
|
|
19648
|
+
for (var p2 in s) if (Object.prototype.hasOwnProperty.call(s, p2)) t2[p2] = s[p2];
|
|
19649
|
+
}
|
|
19650
|
+
return t2;
|
|
19651
|
+
};
|
|
19652
|
+
return __assign.apply(this, arguments);
|
|
19653
|
+
};
|
|
19654
|
+
var __rest = function(s, e) {
|
|
19655
|
+
var t2 = {};
|
|
19656
|
+
for (var p2 in s) if (Object.prototype.hasOwnProperty.call(s, p2) && e.indexOf(p2) < 0) t2[p2] = s[p2];
|
|
19657
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p2 = Object.getOwnPropertySymbols(s); i < p2.length; i++) {
|
|
19658
|
+
if (e.indexOf(p2[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p2[i])) t2[p2[i]] = s[p2[i]];
|
|
19659
|
+
}
|
|
19660
|
+
return t2;
|
|
19661
|
+
};
|
|
19662
|
+
function Tree2Element(tree) {
|
|
19663
|
+
return tree && tree.map(function(node2, i) {
|
|
19664
|
+
return React.createElement(node2.tag, __assign({
|
|
19665
|
+
key: i
|
|
19666
|
+
}, node2.attr), Tree2Element(node2.child));
|
|
19667
|
+
});
|
|
19668
|
+
}
|
|
19669
|
+
function GenIcon(data) {
|
|
19670
|
+
return function(props) {
|
|
19671
|
+
return React.createElement(IconBase, __assign({
|
|
19672
|
+
attr: __assign({}, data.attr)
|
|
19673
|
+
}, props), Tree2Element(data.child));
|
|
19674
|
+
};
|
|
19675
|
+
}
|
|
19676
|
+
function IconBase(props) {
|
|
19677
|
+
var elem = function(conf) {
|
|
19678
|
+
var attr = props.attr, size = props.size, title = props.title, svgProps = __rest(props, ["attr", "size", "title"]);
|
|
19679
|
+
var computedSize = size || conf.size || "1em";
|
|
19680
|
+
var className;
|
|
19681
|
+
if (conf.className) className = conf.className;
|
|
19682
|
+
if (props.className) className = (className ? className + " " : "") + props.className;
|
|
19683
|
+
return React.createElement("svg", __assign({
|
|
19684
|
+
stroke: "currentColor",
|
|
19685
|
+
fill: "currentColor",
|
|
19686
|
+
strokeWidth: "0"
|
|
19687
|
+
}, conf.attr, attr, svgProps, {
|
|
19688
|
+
className,
|
|
19689
|
+
style: __assign(__assign({
|
|
19690
|
+
color: props.color || conf.color
|
|
19691
|
+
}, conf.style), props.style),
|
|
19692
|
+
height: computedSize,
|
|
19693
|
+
width: computedSize,
|
|
19694
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
19695
|
+
}), title && React.createElement("title", null, title), props.children);
|
|
19696
|
+
};
|
|
19697
|
+
return IconContext !== void 0 ? React.createElement(IconContext.Consumer, null, function(conf) {
|
|
19698
|
+
return elem(conf);
|
|
19699
|
+
}) : elem(DefaultContext);
|
|
19700
|
+
}
|
|
19701
|
+
function IoIosSend(props) {
|
|
19702
|
+
return GenIcon({ "attr": { "viewBox": "0 0 512 512" }, "child": [{ "tag": "path", "attr": { "d": "M435.9 64.9l-367.1 160c-6.5 3.1-6.3 12.4.3 15.3l99.3 56.1c5.9 3.3 13.2 2.6 18.3-1.8l195.8-168.8c1.3-1.1 4.4-3.2 5.6-2 1.3 1.3-.7 4.3-1.8 5.6L216.9 320.1c-4.7 5.3-5.4 13.1-1.6 19.1l64.9 104.1c3.2 6.3 12.3 6.2 15.2-.2L447.2 76c3.3-7.2-4.2-14.5-11.3-11.1z" } }] })(props);
|
|
19703
|
+
}
|
|
19704
|
+
function IoSendOutline(props) {
|
|
19705
|
+
return GenIcon({ "attr": { "viewBox": "0 0 512 512" }, "child": [{ "tag": "path", "attr": { "fill": "none", "strokeLinecap": "round", "strokeLinejoin": "round", "strokeWidth": "32", "d": "M470.3 271.15L43.16 447.31a7.83 7.83 0 01-11.16-7V327a8 8 0 016.51-7.86l247.62-47c17.36-3.29 17.36-28.15 0-31.44l-247.63-47a8 8 0 01-6.5-7.85V72.59c0-5.74 5.88-10.26 11.16-8L470.3 241.76a16 16 0 010 29.39z" } }] })(props);
|
|
19706
|
+
}
|
|
19707
|
+
function MdOutlineSend(props) {
|
|
19708
|
+
return GenIcon({ "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "fill": "none", "d": "M0 0h24v24H0V0z" } }, { "tag": "path", "attr": { "d": "M4.01 6.03l7.51 3.22-7.52-1 .01-2.22m7.5 8.72L4 17.97v-2.22l7.51-1M2.01 3L2 10l15 2-15 2 .01 7L23 12 2.01 3z" } }] })(props);
|
|
19709
|
+
}
|
|
19710
|
+
function LuSend(props) {
|
|
19711
|
+
return GenIcon({ "attr": { "viewBox": "0 0 24 24", "fill": "none", "stroke": "currentColor", "strokeWidth": "2", "strokeLinecap": "round", "strokeLinejoin": "round" }, "child": [{ "tag": "path", "attr": { "d": "m22 2-7 20-4-9-9-4Z" } }, { "tag": "path", "attr": { "d": "M22 2 11 13" } }] })(props);
|
|
19712
|
+
}
|
|
19539
19713
|
const fetchWidgetConfig = async (widgetId) => {
|
|
19540
19714
|
const res = await fetch(`https://api.getwidgets.app/api/widgets/user-widgets/${widgetId}/config`);
|
|
19541
19715
|
if (!res.ok) throw new Error("Failed to fetch widget config");
|
|
@@ -19598,6 +19772,7 @@
|
|
|
19598
19772
|
const [hasCheckedSession, setHasCheckedSession] = reactExports.useState(false);
|
|
19599
19773
|
const [windowWidth, setWindowWidth] = reactExports.useState(typeof window !== "undefined" ? window.innerWidth : 1024);
|
|
19600
19774
|
const isOpenRef = reactExports.useRef(false);
|
|
19775
|
+
const ICON_MAP = { IoIosSend, IoSendOutline, MdOutlineSend, LuSend };
|
|
19601
19776
|
const normalizeIncomingMessage = (m2) => {
|
|
19602
19777
|
if (!m2) return { id: void 0, role: "agent", content: "", timestamp: (/* @__PURE__ */ new Date()).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }), created_at: Date.now() };
|
|
19603
19778
|
if (m2.sent_by) {
|
|
@@ -19673,12 +19848,10 @@
|
|
|
19673
19848
|
try {
|
|
19674
19849
|
const status = await checkSessionStatus(widgetId, sessionId);
|
|
19675
19850
|
if (status.success && ((_a2 = status.data) == null ? void 0 : _a2.is_active)) {
|
|
19676
|
-
console.log("Session is active, connecting to websocket...");
|
|
19677
19851
|
setIsConnecting(true);
|
|
19678
19852
|
openLiveWebsocket(sessionId);
|
|
19679
19853
|
setIsSessionInitialized(true);
|
|
19680
19854
|
} else {
|
|
19681
|
-
console.log("Session not active, will create new session on first message");
|
|
19682
19855
|
}
|
|
19683
19856
|
} catch (error) {
|
|
19684
19857
|
console.error("Failed to check session status:", error);
|
|
@@ -19735,7 +19908,6 @@
|
|
|
19735
19908
|
const ws = new WebSocket(url);
|
|
19736
19909
|
wsRef.current = ws;
|
|
19737
19910
|
ws.onopen = () => {
|
|
19738
|
-
console.log("LiveChat WS connected", url);
|
|
19739
19911
|
setLocalLoading(false);
|
|
19740
19912
|
setIsConnecting(false);
|
|
19741
19913
|
if (onOpenCallback) {
|
|
@@ -19841,7 +20013,6 @@
|
|
|
19841
20013
|
}
|
|
19842
20014
|
};
|
|
19843
20015
|
ws.onclose = () => {
|
|
19844
|
-
console.log("LiveChat WS closed");
|
|
19845
20016
|
try {
|
|
19846
20017
|
localStorage.removeItem("live-chat-widget/session-id");
|
|
19847
20018
|
} catch (e) {
|
|
@@ -19976,6 +20147,18 @@
|
|
|
19976
20147
|
const appearanceConfig = appearance || {};
|
|
19977
20148
|
const chatAreaConfig = chat_area || {};
|
|
19978
20149
|
const inputAreaConfig = input_area || {};
|
|
20150
|
+
const sendButtonSize = (() => {
|
|
20151
|
+
var _a2;
|
|
20152
|
+
try {
|
|
20153
|
+
const raw = (_a2 = inputAreaConfig == null ? void 0 : inputAreaConfig.send_button) == null ? void 0 : _a2.size;
|
|
20154
|
+
const parsed = raw ? parseInt(String(raw).replace(/[^0-9]/g, ""), 10) : NaN;
|
|
20155
|
+
if (Number.isFinite(parsed) && !Number.isNaN(parsed)) {
|
|
20156
|
+
return Math.max(30, Math.min(50, parsed));
|
|
20157
|
+
}
|
|
20158
|
+
} catch (e) {
|
|
20159
|
+
}
|
|
20160
|
+
return 40;
|
|
20161
|
+
})();
|
|
19979
20162
|
const getResponsiveDimensions = () => {
|
|
19980
20163
|
const isMobile2 = windowWidth < 768;
|
|
19981
20164
|
if (isMobile2) {
|
|
@@ -20029,9 +20212,17 @@
|
|
|
20029
20212
|
};
|
|
20030
20213
|
const isMobile = windowWidth < 768;
|
|
20031
20214
|
return /* @__PURE__ */ React.createElement("div", { style: getPositionStyles() }, !isOpen && showNotificationPreview && /* @__PURE__ */ React.createElement(
|
|
20032
|
-
"
|
|
20215
|
+
"div",
|
|
20033
20216
|
{
|
|
20217
|
+
role: "button",
|
|
20218
|
+
tabIndex: 0,
|
|
20034
20219
|
onClick: toggleWidget,
|
|
20220
|
+
onKeyDown: (e) => {
|
|
20221
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
20222
|
+
e.preventDefault();
|
|
20223
|
+
toggleWidget();
|
|
20224
|
+
}
|
|
20225
|
+
},
|
|
20035
20226
|
className: "rounded-2xl shadow-lg hover:shadow-xl transition-all duration-300 flex flex-col gap-2 p-4 max-w-xs responsive-notification relative",
|
|
20036
20227
|
style: {
|
|
20037
20228
|
backgroundColor: headerConfig.background_color || "#111827",
|
|
@@ -20198,12 +20389,7 @@
|
|
|
20198
20389
|
{
|
|
20199
20390
|
src: headerConfig.logo_url,
|
|
20200
20391
|
alt: "logo",
|
|
20201
|
-
|
|
20202
|
-
width: isMobile ? "28px" : "32px",
|
|
20203
|
-
height: isMobile ? "28px" : "32px",
|
|
20204
|
-
marginBottom: isMobile ? "6px" : "8px",
|
|
20205
|
-
borderRadius: "4px"
|
|
20206
|
-
}
|
|
20392
|
+
className: "w-auto h-8 mx-auto mb-2"
|
|
20207
20393
|
}
|
|
20208
20394
|
), !headerConfig.hide_title && /* @__PURE__ */ React.createElement("h2", { className: "font-semibold leading-tight", style: { fontSize: isMobile ? "14px" : "16px", margin: "0" } }, headerConfig.title || "Live Chat"), /* @__PURE__ */ React.createElement("p", { className: "opacity-80 leading-tight", style: { fontSize: isMobile ? "11px" : "13px", margin: "2px 0 0 0" } }, headerConfig.subtitle || "Connect with visitors"))
|
|
20209
20395
|
),
|
|
@@ -20314,10 +20500,10 @@
|
|
|
20314
20500
|
className: "rounded-full flex items-center justify-center flex-shrink-0 hover:opacity-90 transition-opacity",
|
|
20315
20501
|
style: {
|
|
20316
20502
|
backgroundColor: ((_b = inputAreaConfig.send_button) == null ? void 0 : _b.color) || "#2563EB",
|
|
20317
|
-
width:
|
|
20318
|
-
height:
|
|
20319
|
-
minWidth:
|
|
20320
|
-
minHeight:
|
|
20503
|
+
width: `${sendButtonSize}px`,
|
|
20504
|
+
height: `${sendButtonSize}px`,
|
|
20505
|
+
minWidth: `${sendButtonSize}px`,
|
|
20506
|
+
minHeight: `${sendButtonSize}px`,
|
|
20321
20507
|
opacity: localLoading || !inputMessage.trim() ? 0.5 : 1,
|
|
20322
20508
|
transition: "opacity 0.2s",
|
|
20323
20509
|
border: "none",
|
|
@@ -20329,25 +20515,24 @@
|
|
|
20329
20515
|
{
|
|
20330
20516
|
className: "rounded-full animate-spin",
|
|
20331
20517
|
style: {
|
|
20332
|
-
width:
|
|
20333
|
-
height:
|
|
20518
|
+
width: 16,
|
|
20519
|
+
height: 16,
|
|
20334
20520
|
border: "2px solid #FFFFFF",
|
|
20335
20521
|
borderTop: "2px solid transparent"
|
|
20336
20522
|
}
|
|
20337
20523
|
}
|
|
20338
|
-
) :
|
|
20339
|
-
|
|
20340
|
-
|
|
20341
|
-
|
|
20342
|
-
|
|
20343
|
-
|
|
20344
|
-
|
|
20345
|
-
|
|
20346
|
-
|
|
20347
|
-
|
|
20348
|
-
}
|
|
20349
|
-
|
|
20350
|
-
)
|
|
20524
|
+
) : (() => {
|
|
20525
|
+
var _a2, _b2, _c;
|
|
20526
|
+
const iconComponentKey = (_a2 = inputAreaConfig == null ? void 0 : inputAreaConfig.send_button) == null ? void 0 : _a2.icon_component;
|
|
20527
|
+
const iconUrl = (_b2 = inputAreaConfig == null ? void 0 : inputAreaConfig.send_button) == null ? void 0 : _b2.icon_url;
|
|
20528
|
+
const iconColor = ((_c = inputAreaConfig == null ? void 0 : inputAreaConfig.send_button) == null ? void 0 : _c.icon_color) || "#FFFFFF";
|
|
20529
|
+
if (iconComponentKey && ICON_MAP[iconComponentKey]) {
|
|
20530
|
+
const Icon2 = ICON_MAP[iconComponentKey];
|
|
20531
|
+
return /* @__PURE__ */ React.createElement(Icon2, { className: "w-4 h-4", style: { color: iconColor } });
|
|
20532
|
+
}
|
|
20533
|
+
if (iconUrl) return /* @__PURE__ */ React.createElement("img", { src: iconUrl, alt: "send", style: { width: "60%", height: "60%" } });
|
|
20534
|
+
return /* @__PURE__ */ React.createElement(Send, { className: "w-4 h-4", style: { color: "#FFFFFF" } });
|
|
20535
|
+
})()
|
|
20351
20536
|
)
|
|
20352
20537
|
),
|
|
20353
20538
|
inputAreaConfig.show_branding !== false && /* @__PURE__ */ React.createElement(
|
|
@@ -20463,12 +20648,10 @@
|
|
|
20463
20648
|
shadowRoot.appendChild(styles);
|
|
20464
20649
|
const root2 = client.createRoot(mountPoint);
|
|
20465
20650
|
try {
|
|
20466
|
-
console.log("🚀 Rendering LiveChatWidget with ID:", widgetId, "Mode:", mode);
|
|
20467
20651
|
root2.render(
|
|
20468
20652
|
/* @__PURE__ */ React.createElement(React.StrictMode, null, /* @__PURE__ */ React.createElement(LiveChatWidget, { widgetId, apiKey }))
|
|
20469
20653
|
);
|
|
20470
20654
|
container.__livechat_mounted = true;
|
|
20471
|
-
console.log("✅ LiveChatWidget rendered successfully");
|
|
20472
20655
|
} catch (err) {
|
|
20473
20656
|
console.error("❌ LiveChatWidget render failed:", err);
|
|
20474
20657
|
const errDiv = document.createElement("div");
|