mongodb-chatbot-ui
Version:
UI React components for the MongoDB Assistant
499 lines (498 loc) • 26.8 kB
JavaScript
import { jsxs as _e, jsx as ge } from "react/jsx-runtime";
import { c as he, a as We } from "./emotion-css.esm.js";
import { m as M, d as re, U as Ve, n as se, w as S, F as g, b as Ue } from "./index2.js";
import * as U from "react";
import O, { useEffect as ae, forwardRef as Ge, useRef as ve, useState as Ye, useCallback as Je, lazy as Ke } from "react";
import { Y as Qe, z as Xe, L as Ze, d as qe, g as er } from "./index10.js";
import { r as rr, v as tr } from "./index4.js";
import { N as ar, y as nr } from "./index9.js";
import { t as or, a as me, i as ir, e as te, r as lr, n as be } from "./glyphCommon-cTThlth0.js";
import { useChatbotContext as sr } from "./useChatbotContext.js";
import "./polished.esm.js";
import "./ChatbotProvider.js";
function ne() {
return ne = Object.assign ? Object.assign.bind() : function(t) {
for (var a = 1; a < arguments.length; a++) {
var o = arguments[a];
for (var i in o)
({}).hasOwnProperty.call(o, i) && (t[i] = o[i]);
}
return t;
}, ne.apply(null, arguments);
}
function ce(t, a) {
return a || (a = t.slice(0)), Object.freeze(Object.defineProperties(t, { raw: { value: Object.freeze(a) } }));
}
var pe, ke, ye, cr = M(pe || (pe = ce([`
display: flex;
flex-direction: column;
gap: `, `px;
align-items: center;
text-align: center;
`])), Qe[200]), ur = function(t) {
return se(cr, t);
}, dr = function(t) {
return M(ke || (ke = ce([`
color: `, `;
`])), Ze[t].text[qe.Secondary][er.Default]);
}, fr = M(ye || (ye = ce([`
> span {
font-size: inherit;
}
`]))), gr = ["children", "className", "darkMode", "title"], ze = function(t) {
var a = t.children, o = t.className, i = t.darkMode, l = t.title, c = function(s, m) {
if (s == null)
return {};
var p, D, P = function($, y) {
if ($ == null)
return {};
var j = {};
for (var L in $)
if ({}.hasOwnProperty.call($, L)) {
if (y.indexOf(L) !== -1)
continue;
j[L] = $[L];
}
return j;
}(s, m);
if (Object.getOwnPropertySymbols) {
var I = Object.getOwnPropertySymbols(s);
for (D = 0; D < I.length; D++)
p = I[D], m.indexOf(p) === -1 && {}.propertyIsEnumerable.call(s, p) && (P[p] = s[p]);
}
return P;
}(t, gr), v = re(i), u = v.darkMode, f = v.theme;
return O.createElement(Ve, { darkMode: u }, O.createElement("div", ne({ className: ur(o) }, c), l && O.createElement(rr, { weight: Xe.SemiBold, className: dr(f) }, l), O.createElement(tr, { className: fr }, a)));
};
ze.displayName = "DisclaimerText";
var oe = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new WeakMap(), xe = 0, hr = void 0;
function vr(t) {
return t ? (q.has(t) || (xe += 1, q.set(t, xe.toString())), q.get(t)) : "0";
}
function mr(t) {
return Object.keys(t).sort().filter(function(a) {
return t[a] !== void 0;
}).map(function(a) {
return a + "_" + (a === "root" ? vr(t.root) : t[a]);
}).toString();
}
function br(t) {
var a = mr(t), o = oe.get(a);
if (!o) {
var i = /* @__PURE__ */ new Map(), l, c = new IntersectionObserver(function(v) {
v.forEach(function(u) {
var f, s = u.isIntersecting && l.some(function(m) {
return u.intersectionRatio >= m;
});
t.trackVisibility && typeof u.isVisible > "u" && (u.isVisible = s), (f = i.get(u.target)) == null || f.forEach(function(m) {
m(s, u);
});
});
}, t);
l = c.thresholds || (Array.isArray(t.threshold) ? t.threshold : [t.threshold || 0]), o = {
id: a,
observer: c,
elements: i
}, oe.set(a, o);
}
return o;
}
function pr(t, a, o, i) {
if (o === void 0 && (o = {}), i === void 0 && (i = hr), typeof window.IntersectionObserver > "u" && i !== void 0) {
var l = t.getBoundingClientRect();
return a(i, {
isIntersecting: i,
target: t,
intersectionRatio: typeof o.threshold == "number" ? o.threshold : 0,
time: 0,
boundingClientRect: l,
intersectionRect: l,
rootBounds: l
}), function() {
};
}
var c = br(o), v = c.id, u = c.observer, f = c.elements, s = f.get(t) || [];
return f.has(t) || f.set(t, s), s.push(a), u.observe(t), function() {
s.splice(s.indexOf(a), 1), s.length === 0 && (f.delete(t), u.unobserve(t)), f.size === 0 && (u.disconnect(), oe.delete(v));
};
}
function De(t) {
var a = t === void 0 ? {} : t, o = a.threshold, i = a.delay, l = a.trackVisibility, c = a.rootMargin, v = a.root, u = a.triggerOnce, f = a.skip, s = a.initialInView, m = a.fallbackInView, p = U.useRef(), D = U.useState({
inView: !!s
}), P = D[0], I = D[1], $ = U.useCallback(
function(j) {
p.current !== void 0 && (p.current(), p.current = void 0), !f && j && (p.current = pr(j, function(L, V) {
I({
inView: L,
entry: V
}), V.isIntersecting && u && p.current && (p.current(), p.current = void 0);
}, {
root: v,
rootMargin: c,
threshold: o,
// @ts-ignore
trackVisibility: l,
// @ts-ignore
delay: i
}, m));
},
// We break the rule here, because we aren't including the actual `threshold` variable
// eslint-disable-next-line react-hooks/exhaustive-deps
[
// If the threshold is an array, convert it to a string so it won't change between renders.
// eslint-disable-next-line react-hooks/exhaustive-deps
Array.isArray(o) ? o.toString() : o,
v,
c,
u,
f,
l,
m,
i
]
);
ae(function() {
!p.current && P.entry && !u && !f && I({
inView: !!s
});
});
var y = [$, P.inView, P.entry];
return y.ref = y[0], y.inView = y[1], y.entry = y[2], y;
}
var kr = { 0: 0, 50: 2, 100: 4, 150: 6, 200: 8, 300: 12, 400: 16, 500: 20, 600: 24 };
function e(t, a, o) {
return (a = function(i) {
var l = function(c, v) {
if (typeof c != "object" || !c)
return c;
var u = c[Symbol.toPrimitive];
if (u !== void 0) {
var f = u.call(c, v);
if (typeof f != "object")
return f;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return String(c);
}(i, "string");
return typeof l == "symbol" ? l : l + "";
}(a)) in t ? Object.defineProperty(t, a, { value: o, enumerable: !0, configurable: !0, writable: !0 }) : t[a] = o, t;
}
function yr(t, a) {
return a || (a = t.slice(0)), Object.freeze(Object.defineProperties(t, { raw: { value: Object.freeze(a) } }));
}
var we, Fe, He, n = { Disabled: "disabled", Placeholder: "placeholder", Primary: "primary", Secondary: "secondary", Tertiary: "tertiary", InversePrimary: "inversePrimary", InverseSecondary: "inverseSecondary", Info: "info", Warning: "warning", Error: "error", Success: "success", Link: "link", OnError: "onError", OnSuccess: "onSuccess", OnSuccessLink: "onSuccessLink" }, r = { Default: "default", Hover: "hover", Focus: "focus" }, Y = g.black, b = g.blue, d = g.gray, w = g.green, H = g.red, xr = g.white, R = g.yellow, Dr = { background: e(e(e(e(e(e(e(e({}, n.Primary, e(e(e({}, r.Default, Y), r.Hover, d.dark2), r.Focus, b.dark3)), n.Secondary, e(e(e({}, r.Default, d.dark4), r.Hover, d.dark2), r.Focus, b.dark3)), n.InversePrimary, e(e(e({}, r.Default, d.light2), r.Hover, d.light3), r.Focus, b.light2)), n.Info, e(e(e({}, r.Default, b.dark3), r.Hover, b.dark3), r.Focus, b.dark3)), n.Warning, e(e(e({}, r.Default, R.dark3), r.Hover, R.dark3), r.Focus, R.dark3)), n.Success, e(e(e({}, r.Default, w.dark3), r.Hover, w.dark3), r.Focus, w.dark3)), n.Error, e(e(e({}, r.Default, H.dark3), r.Hover, H.dark3), r.Focus, H.dark3)), n.Disabled, e(e(e({}, r.Default, d.dark3), r.Hover, d.dark3), r.Focus, d.dark3)), border: e(e(e(e(e(e(e(e({}, n.Primary, e(e(e({}, r.Default, d.base), r.Hover, d.base), r.Focus, b.light1)), n.Secondary, e(e(e({}, r.Default, d.dark2), r.Hover, d.dark2), r.Focus, b.light1)), n.Tertiary, e(e(e({}, r.Default, d.dark1), r.Hover, d.dark1), r.Focus, b.light1)), n.Success, e(e(e({}, r.Default, w.dark1), r.Hover, w.dark1), r.Focus, b.light1)), n.Error, e(e(e({}, r.Default, H.light1), r.Hover, H.light1), r.Focus, b.light1)), n.OnSuccess, e(e(e({}, r.Default, w.dark2), r.Hover, w.dark2), r.Focus, b.light1)), n.OnError, e(e(e({}, r.Default, H.dark2), r.Hover, H.dark2), r.Focus, b.light1)), n.Disabled, e(e(e({}, r.Default, d.dark2), r.Hover, d.dark2), r.Focus, d.dark2)), icon: e(e(e(e(e(e(e(e({}, n.Primary, e(e(e({}, r.Default, d.light1), r.Hover, d.light3), r.Focus, b.light3)), n.Secondary, e(e(e({}, r.Default, d.base), r.Hover, d.light3), r.Focus, b.light3)), n.InversePrimary, e(e(e({}, r.Default, xr), r.Hover, Y), r.Focus, b.dark2)), n.Info, e(e(e({}, r.Default, b.light1), r.Hover, b.light1), r.Focus, b.light1)), n.Warning, e(e(e({}, r.Default, R.base), r.Hover, R.base), r.Focus, R.base)), n.Success, e(e(e({}, r.Default, w.base), r.Hover, w.base), r.Focus, w.base)), n.Error, e(e(e({}, r.Default, H.light1), r.Hover, H.light1), r.Focus, H.light1)), n.Disabled, e(e(e({}, r.Default, d.dark1), r.Hover, d.dark1), r.Focus, d.dark1)), text: (e(e(e(e(e(e(e(e(e(e(we = {}, n.Primary, e(e(e({}, r.Default, d.light2), r.Hover, d.light2), r.Focus, b.light3)), n.Placeholder, e(e(e({}, r.Default, d.dark1), r.Hover, d.dark1), r.Focus, d.dark1)), n.Secondary, e(e(e({}, r.Default, d.light1), r.Hover, d.light2), r.Focus, b.light3)), n.InversePrimary, e(e(e({}, r.Default, Y), r.Hover, Y), r.Focus, b.dark2)), n.InverseSecondary, e(e(e({}, r.Default, d.dark2), r.Hover, Y), r.Focus, b.dark2)), n.Disabled, e(e(e({}, r.Default, d.dark1), r.Hover, d.dark1), r.Focus, d.dark1)), n.Success, e(e(e({}, r.Default, w.light2), r.Hover, w.light2), r.Focus, w.light2)), n.Error, e(e(e({}, r.Default, H.light1), r.Hover, H.light1), r.Focus, H.light1)), n.OnSuccess, e(e(e({}, r.Default, w.light1), r.Hover, w.light1), r.Focus, w.light1)), n.OnSuccessLink, e(e(e({}, r.Default, w.light3), r.Hover, w.light3), r.Focus, w.light3)), e(e(we, n.OnError, e(e(e({}, r.Default, H.light2), r.Hover, H.light2), r.Focus, H.light2)), n.Link, e(e(e({}, r.Default, b.light1), r.Hover, b.light1), r.Focus, b.light1))) }, A = g.black, k = g.blue, h = g.gray, x = g.green, F = g.red, B = g.white, _ = g.yellow, wr = { background: e(e(e(e(e(e(e(e({}, n.Primary, e(e(e({}, r.Default, B), r.Hover, h.light2), r.Focus, k.light3)), n.Secondary, e(e(e({}, r.Default, h.light3), r.Hover, h.light2), r.Focus, k.light3)), n.InversePrimary, e(e(e({}, r.Default, A), r.Hover, h.dark3), r.Focus, k.dark2)), n.Info, e(e(e({}, r.Default, k.light3), r.Hover, k.light3), r.Focus, k.light3)), n.Warning, e(e(e({}, r.Default, _.light3), r.Hover, _.light3), r.Focus, _.light3)), n.Success, e(e(e({}, r.Default, x.light3), r.Hover, x.light3), r.Focus, x.light3)), n.Error, e(e(e({}, r.Default, F.light3), r.Hover, F.light3), r.Focus, F.light3)), n.Disabled, e(e(e({}, r.Default, h.light2), r.Hover, h.light2), r.Focus, h.light2)), border: e(e(e(e(e(e(e(e({}, n.Primary, e(e(e({}, r.Default, h.base), r.Hover, h.base), r.Focus, k.light1)), n.Secondary, e(e(e({}, r.Default, h.light2), r.Hover, h.light2), r.Focus, k.light1)), n.Tertiary, e(e(e({}, r.Default, h.light1), r.Hover, h.light1), r.Focus, k.light1)), n.Success, e(e(e({}, r.Default, x.dark1), r.Hover, x.dark1), r.Focus, k.light1)), n.Error, e(e(e({}, r.Default, F.base), r.Hover, F.base), r.Focus, k.light1)), n.Disabled, e(e(e({}, r.Default, h.light1), r.Hover, h.light1), r.Focus, h.light1)), n.OnSuccess, e(e(e({}, r.Default, x.light2), r.Hover, x.light2), r.Focus, x.light2)), n.OnError, e(e(e({}, r.Default, F.light2), r.Hover, F.light2), r.Focus, F.light2)), icon: e(e(e(e(e(e(e(e({}, n.Primary, e(e(e({}, r.Default, h.dark1), r.Hover, A), r.Focus, k.dark1)), n.Secondary, e(e(e({}, r.Default, h.base), r.Hover, A), r.Focus, k.dark1)), n.InversePrimary, e(e(e({}, r.Default, B), r.Hover, B), r.Focus, k.light2)), n.Info, e(e(e({}, r.Default, k.base), r.Hover, k.base), r.Focus, k.base)), n.Warning, e(e(e({}, r.Default, _.dark2), r.Hover, _.dark2), r.Focus, _.dark2)), n.Success, e(e(e({}, r.Default, x.dark1), r.Hover, x.dark1), r.Focus, x.dark1)), n.Error, e(e(e({}, r.Default, F.base), r.Hover, F.base), r.Focus, F.base)), n.Disabled, e(e(e({}, r.Default, h.base), r.Hover, h.base), r.Focus, h.base)), text: (e(e(e(e(e(e(e(e(e(e(Fe = {}, n.Primary, e(e(e({}, r.Default, A), r.Hover, A), r.Focus, k.dark1)), n.Secondary, e(e(e({}, r.Default, h.dark1), r.Hover, A), r.Focus, k.dark1)), n.InversePrimary, e(e(e({}, r.Default, B), r.Hover, B), r.Focus, k.light2)), n.InverseSecondary, e(e(e({}, r.Default, h.light1), r.Hover, B), r.Focus, k.light2)), n.Disabled, e(e(e({}, r.Default, h.base), r.Hover, h.base), r.Focus, h.base)), n.Success, e(e(e({}, r.Default, x.dark2), r.Hover, x.dark2), r.Focus, x.dark2)), n.Error, e(e(e({}, r.Default, F.base), r.Hover, F.base), r.Focus, F.base)), n.Placeholder, e(e(e({}, r.Default, h.base), r.Hover, h.base), r.Focus, h.base)), n.OnSuccess, e(e(e({}, r.Default, x.dark2), r.Hover, x.dark2), r.Focus, x.dark2)), n.OnSuccessLink, e(e(e({}, r.Default, x.dark3), r.Hover, x.dark3), r.Focus, x.dark3)), e(e(Fe, n.OnError, e(e(e({}, r.Default, F.dark2), r.Hover, F.dark2), r.Focus, F.dark2)), n.Link, e(e(e({}, r.Default, k.base), r.Hover, k.base), r.Focus, k.base))) };
e(e({}, S.Dark, Dr), S.Light, wr);
var ee = { Dark: "dark", Light: "light" };
e(e({}, ee.Light, { default: "0 0 0 2px ".concat(g.white, ", 0 0 0 4px ").concat(g.blue.light1), input: "0 0 0 3px ".concat(g.blue.light1) }), ee.Dark, { default: "0 0 0 2px ".concat(g.black, ", 0 0 0 4px ").concat(g.blue.light1), input: "0 0 0 3px ".concat(g.blue.light1) });
e(e({}, ee.Light, { gray: "0 0 0 3px ".concat(g.gray.light2), green: "0 0 0 3px ".concat(g.green.light2), red: "0 0 0 3px ".concat(g.red.light2) }), ee.Dark, { gray: "0 0 0 3px ".concat(g.gray.dark2), green: "0 0 0 3px ".concat(g.green.dark3), red: "0 0 0 3px ".concat(g.yellow.dark3) });
var Fr = g.black, W = g.gray, Hr = g.white;
e(e({}, n.Primary, e({}, r.Default, W.base)), n.Secondary, e({}, r.Default, W.dark1)), e(e({}, n.Primary, e({}, r.Default, Fr)), n.Secondary, e({}, r.Default, W.dark4)), e(e({}, n.Primary, e({}, r.Default, W.base)), n.Secondary, e({}, r.Default, W.light1)), e(e({}, n.Primary, e({}, r.Default, Hr)), n.Secondary, e({}, r.Default, W.light3));
var T = e(e({}, S.Light, { 1: "color-mix(in srgb, ".concat(g.black, " 15%, transparent)"), 2: "color-mix(in srgb, ".concat(g.black, " 20%, transparent)"), 3: "color-mix(in srgb, ".concat(g.black, " 60%, transparent)"), overflow: "color-mix(in srgb, ".concat(g.gray.dark1, " 30%, transparent)") }), S.Dark, { 1: "transparent", 2: "color-mix(in srgb, #000000 45%, transparent)", 3: "color-mix(in srgb, #000000 60%, transparent)", overflow: "color-mix(in srgb, #000000 30%, transparent)" });
e(e({}, S.Light, { 1: "0px 2px 4px 1px ".concat(T[S.Light][1]), 2: "0px 18px 18px -15px ".concat(T[S.Light][2]), 3: "0px 8px 20px -8px ".concat(T[S.Light][3]), overflow: "0px 2px 4px 1px ".concat(T[S.Light].overflow) }), S.Dark, { 1: "unset", 2: "0 18px 18px -15px ".concat(T[S.Dark][2]), 3: "0 8px 20px -8px ".concat(T[S.Dark][3]), overflow: "0px 2px 4px 1px ".concat(T[S.Dark].overflow) });
var C = { Top: "top", Left: "left", Right: "right", Bottom: "bottom" }, Sr = e(e({}, S.Light, 2), S.Dark, 16), Or = function(t) {
var a = t.isInside, o = t.shadowColor, i = t.shadowOffsetVal, l = t.side, c = a ? "-".concat(36, "px") : "0", v = function(f) {
var s = f.isInside, m = f.side;
return s ? m === C.Top || m === C.Left ? "1" : "initial" : "-1";
}({ isInside: a, side: l }), u = `
content: '';
position: absolute;
border-radius: 40%;
z-index: `.concat(v, `;
`);
switch (l) {
case C.Top:
return `
`.concat(u, `
top: `).concat(c, `;
left: 0;
right: 0;
width: 96%;
height: `).concat(36, `px;
margin: 0 auto;
box-shadow: 0 `).concat(a ? "" : "-").concat(i, "px ").concat(16, "px ").concat(o, `;
`);
case C.Left:
return `
`.concat(u, `
top: 0;
bottom: 0;
left: `).concat(c, `;
width: `).concat(36, `px;
height: 96%;
margin: auto 0;
box-shadow: `).concat(a ? "" : "-").concat(i, "px 0 ").concat(16, "px ").concat(o, `;
`);
case C.Right:
return `
`.concat(u, `
top: 0;
bottom: 0;
right: `).concat(c, `;
width: `).concat(36, `px;
height: 96%;
margin: auto 0;
box-shadow: `).concat(a ? "-" : "").concat(i, "px 0 ").concat(16, "px ").concat(o, `;
`);
case C.Bottom:
return `
`.concat(u, `
bottom: `).concat(c, `;
left: 0;
right: 0;
width: 96%;
height: `).concat(36, `px;
margin: 0 auto;
box-shadow: 0 `).concat(a ? "-" : "").concat(i, "px ").concat(16, "px ").concat(o, `;
`);
default:
return "";
}
}, Se = function(t) {
var a = t.isInside, o = t.side, i = t.theme, l = o === C.Top || o === C.Left ? "::before" : "::after", c = T[i].overflow, v = Sr[i];
return M(He || (He = yr([`
position: relative;
`, ` {
`, `
}
`])), l, Or({ isInside: a, shadowColor: c, shadowOffsetVal: v, side: o }));
}, J = { 0: 0, 25: 1, 50: 2, 100: 4, 150: 6, 200: 8, 300: 12, 400: 16, 500: 20, 600: 24, 800: 32, 900: 36, 1e3: 40, 1200: 48, 1400: 56, 1600: 64, 1800: 72, 1: 4, 2: 8, 3: 16, 4: 24, 5: 32, 6: 64, 7: 88 }, Oe, Pe, Pr = ["className", "size", "title", "aria-label", "aria-labelledby", "fill", "role"], ie = function(t) {
var a = t.className, o = t.size, i = o === void 0 ? 16 : o, l = t.title, c = t["aria-label"], v = t["aria-labelledby"], u = t.fill, f = t.role, s = f === void 0 ? "img" : f, m = or(t, Pr), p = Ue({ prefix: "icon-title" }), D = M(Oe || (Oe = me([`
color: `, `;
`])), u), P = M(Pe || (Pe = me([`
flex-shrink: 0;
`]))), I = ir(s, "ArrowDown", te(te({ title: l, titleId: p }, "aria-label", c), "aria-labelledby", v));
return U.createElement("svg", lr({ className: se(te({}, D, u != null), P, a), height: typeof i == "number" ? i : be[i], width: typeof i == "number" ? i : be[i], role: s }, I, m, { viewBox: "0 0 16 16" }), l && U.createElement("title", { id: p }, l), U.createElement("path", { d: "M9.16788 3L9.16788 9.94442L10.7029 8.40941C11.0934 8.01888 11.7266 8.01889 12.1171 8.40941L12.356 8.64833C12.7465 9.03885 12.7465 9.67201 12.356 10.0625L8.97339 13.4452C8.96483 13.4544 8.95605 13.4635 8.94708 13.4725L8.70816 13.7114C8.31763 14.1019 7.68447 14.1019 7.29395 13.7114L3.64279 10.0602C3.25227 9.66972 3.25227 9.03656 3.64279 8.64603L3.88171 8.40712C4.27223 8.01659 4.9054 8.01659 5.29592 8.40712L6.83 9.9412L6.83 3C6.83 2.44771 7.27772 2 7.83001 2L8.16788 2C8.72017 2 9.16788 2.44772 9.16788 3Z", fill: "currentColor" }));
};
ie.displayName = "ArrowDown", ie.isGlyph = !0;
function Ee(t, a) {
a > t.length && (a = t.length);
for (var o = 0, i = Array(a); o < a; o++)
i[o] = t[o];
return i;
}
function Ie(t, a, o) {
return (a = function(i) {
var l = function(c, v) {
if (typeof c != "object" || !c)
return c;
var u = c[Symbol.toPrimitive];
if (u !== void 0) {
var f = u.call(c, v);
if (typeof f != "object")
return f;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return String(c);
}(i, "string");
return typeof l == "symbol" ? l : l + "";
}(a)) in t ? Object.defineProperty(t, a, { value: o, enumerable: !0, configurable: !0, writable: !0 }) : t[a] = o, t;
}
function le() {
return le = Object.assign ? Object.assign.bind() : function(t) {
for (var a = 1; a < arguments.length; a++) {
var o = arguments[a];
for (var i in o)
({}).hasOwnProperty.call(o, i) && (t[i] = o[i]);
}
return t;
}, le.apply(null, arguments);
}
function Er(t, a) {
return function(o) {
if (Array.isArray(o))
return o;
}(t) || function(o, i) {
var l = o == null ? null : typeof Symbol < "u" && o[Symbol.iterator] || o["@@iterator"];
if (l != null) {
var c, v, u, f, s = [], m = !0, p = !1;
try {
if (u = (l = l.call(o)).next, i !== 0)
for (; !(m = (c = u.call(l)).done) && (s.push(c.value), s.length !== i); m = !0)
;
} catch (D) {
p = !0, v = D;
} finally {
try {
if (!m && l.return != null && (f = l.return(), Object(f) !== f))
return;
} finally {
if (p)
throw v;
}
}
return s;
}
}(t, a) || function(o, i) {
if (o) {
if (typeof o == "string")
return Ee(o, i);
var l = {}.toString.call(o).slice(8, -1);
return l === "Object" && o.constructor && (l = o.constructor.name), l === "Map" || l === "Set" ? Array.from(o) : l === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(l) ? Ee(o, i) : void 0;
}
}(t, a) || function() {
throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
}();
}
function K(t, a) {
return a || (a = t.slice(0)), Object.freeze(Object.defineProperties(t, { raw: { value: Object.freeze(a) } }));
}
var $e, Le, Me, je, Ce, Ir = M($e || ($e = K([`
position: absolute;
bottom: `, `px;
`])), J[400]), $r = M(Le || (Le = K([`
box-shadow: 0 `, "px ", `px rgba(0, 0, 0, 0.2);
border-radius: `, `px;
`])), J[50], J[100], kr[400]), Re = function(t) {
var a = t.darkMode, o = t.onClick, i = t.visible, l = re(a).darkMode;
return i ? O.createElement("div", { className: Ir }, O.createElement(ar, { "aria-label": "Scroll to latest message", className: $r, darkMode: l, onClick: o, rightGlyph: O.createElement(ie, null), size: nr.Small }, "Scroll to latest")) : null;
};
Re.displayName = "ScrollToLatestButton";
var Lr = M(Me || (Me = K([`
max-height: 100%;
width: 100%;
display: flex;
justify-content: center;
position: relative;
overflow: hidden;
`]))), Mr = function(t) {
var a = t.className, o = t.hasBottomShadow, i = t.hasTopShadow, l = t.theme;
return se(Lr, Ie(Ie({}, Se({ side: C.Top, theme: l, isInside: !0 }), i), Se({ side: C.Bottom, theme: l, isInside: !0 }), o), a);
}, jr = M(je || (je = K([`
width: 100%;
height: 100%;
overflow-y: scroll;
scroll-behavior: smooth;
position: relative;
padding: 0 `, `px;
display: flex;
flex-direction: column;
gap: `, `px;
`])), J[400], J[400]), Ne = M(Ce || (Ce = K([`
min-height: 1px;
`]))), Cr = ["children", "darkMode", "className"], Ae = Ge(function(t, a) {
var o = t.children, i = t.darkMode, l = t.className, c = function(E, G) {
if (E == null)
return {};
var N, Q, ue = function(X, Be) {
if (X == null)
return {};
var fe = {};
for (var Z in X)
if ({}.hasOwnProperty.call(X, Z)) {
if (Be.indexOf(Z) !== -1)
continue;
fe[Z] = X[Z];
}
return fe;
}(E, G);
if (Object.getOwnPropertySymbols) {
var de = Object.getOwnPropertySymbols(E);
for (Q = 0; Q < de.length; Q++)
N = de[Q], G.indexOf(N) === -1 && {}.propertyIsEnumerable.call(E, N) && (ue[N] = E[N]);
}
return ue;
}(t, Cr), v = re(i), u = v.darkMode, f = v.theme, s = ve(null), m = ve(null), p = Er(Ye(!1), 2), D = p[0], P = p[1], I = De({ initialInView: !0, root: s.current, threshold: 0 }), $ = I.ref, y = I.inView, j = De({ initialInView: !0, root: s.current, threshold: 0 }), L = j.ref, V = j.inView, z = Je(function() {
s.current && s.current.scrollTo(0, s.current.scrollHeight);
}, []);
return ae(function() {
var E = s.current;
if (E) {
var G = function() {
m.current && clearTimeout(m.current), m.current = setTimeout(function() {
P(!function() {
if (!s.current)
return !0;
var N = s.current;
return N.scrollHeight - N.scrollTop - N.clientHeight <= 2;
}());
}, 100);
};
return E.addEventListener("scroll", G), function() {
E.removeEventListener("scroll", G), m.current && clearTimeout(m.current);
};
}
}, []), ae(function() {
D || z();
}, [o, D, z]), O.createElement(Ve, { darkMode: u }, O.createElement("div", le({}, c, { className: Mr({ className: l, hasBottomShadow: !V, hasTopShadow: !y, theme: f }), ref: a }), O.createElement("div", { className: jr, ref: s }, O.createElement("span", { className: Ne, ref: $ }), o, O.createElement("span", { className: Ne, ref: L })), O.createElement(Re, { darkMode: u, onClick: z, visible: D })));
});
Ae.displayName = "MessageFeed";
const Nr = Ke(async () => ({
default: (await import("./Message.js")).Message
})), Te = {
disclaimer_text: he`
text-align: center;
margin-top: 16px;
margin-bottom: 32px;
`,
message_feed: he`
height: 100%;
max-height: 100%;
& > div {
box-sizing: border-box;
height: unset;
max-height: 100%;
}
`
};
function Jr(t) {
const { darkMode: a } = re(t.darkMode), {
className: o,
disclaimer: i,
disclaimerHeading: l,
initialMessage: c,
messageBottomContent: v
} = t, {
awaitingReply: u,
canSubmit: f,
conversation: s,
handleSubmit: m,
onReferenceClick: p,
onSuggestedPromptClick: D,
onPromotionClick: P
} = sr(), $ = (c ? [c, ...s.messages] : s.messages).filter((y) => y.id !== s.streamingMessageId || y.content !== "");
return $.length === 0 ? null : /* @__PURE__ */ _e(
Ae,
{
darkMode: a,
className: We(Te.message_feed, o, "message-feed"),
children: [
i ? /* @__PURE__ */ ge(
ze,
{
title: l ?? "Terms of Use",
className: Te.disclaimer_text,
children: i
}
) : null,
$.map((y, j) => {
const L = j === 0, V = y.id === s.streamingMessageId, z = y.role === "assistant" && !(V && u) && !L;
return /* @__PURE__ */ ge(
Nr,
{
messageData: y,
showRating: z,
bottomContent: z ? v : null,
conversation: s,
suggestedPrompts: y.suggestedPrompts,
showSuggestedPrompts: (
// For now we'll only show suggested prompts for the initial message and hide them once the user submits anything
L && s.messages.length === 0
),
onReferenceClick: p,
onSuggestedPromptClick: (E) => {
D == null || D(E), m(E);
},
onPromotionClick: P,
canSubmitSuggestedPrompt: f
},
y.id
);
})
]
}
);
}
export {
Jr as ChatMessageFeed
};