UNPKG

@sprig-technologies/sprig-bundled

Version:

npm package for the sprig web sdk with bundled dependencies

194 lines (193 loc) 12.4 kB
import { a as s, c as C, u as k, F as Z, h as R, p as E, _ as S, d as H, y as Q, b as q, z as _, B as G } from "./view-Cu4weTLz.js"; import { j as J, k as X, l as Y, m as ee, E as j } from "./index-Czvv7meW.js"; const te = (e) => s("button", { ...e, className: C("ul-card-text__button", e.className), id: "ul-card-text__button" }), oe = ({ html: e, ...o }) => { const { enableCspTrustedTypes: i } = k((n) => ({ enableCspTrustedTypes: n.enableCspTrustedTypes })), t = Z(() => J(e, i), [i, e]); return s("div", { ...o, dangerouslySetInnerHTML: { __html: t } }); }, M = () => { const { viewDocument: e } = k((t) => ({ viewDocument: t.viewDocument })), [o, i] = R(!1); return E(() => { const t = e.querySelector(".sprig-question-body"), n = new ResizeObserver(() => { window.requestAnimationFrame(() => { i(!!(t && X(t) && t.scrollHeight > t.offsetHeight)); }); }); return t && n.observe(t), () => { t && n.disconnect(); }; }, [e]), o; }, A = ({ plainText: e, richText: o, id: i, className: t, isHeader: n, showAsterisk: r }) => o ? s(oe, { className: t, html: o, id: i }) : e ? n ? s("h1", { className: t, id: i, children: [e, r && "*"] }) : s("p", { className: t, id: i, children: e }) : null, ue = ({ message: e, properties: o, isRequired: i }) => { const t = S(null), n = o == null ? void 0 : o.captionText, r = M(); return s("div", { className: C("question-header-container", "sprig-header-container", r ? "sprig-border-bottom" : null), ref: t, children: [s("div", { className: "question-header-button-container", children: s(A, { className: "ul-question", id: "ul-question", isHeader: !0, plainText: e, richText: o == null ? void 0 : o.questionHtml, showAsterisk: i }) }), s(A, { className: "ul-caption", id: "ul-caption", plainText: n, richText: o == null ? void 0 : o.captionHtml })] }); }, ne = () => s("svg", { fill: "none", height: "10", viewBox: "0 0 13 10", width: "13", xmlns: "http://www.w3.org/2000/svg", children: s("path", { d: "M11.5 1.5L4.5 8.5L1 5", stroke: "#FFFFFF", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "1.5" }) }), pe = ({ isSubmitDisabled: e, handleSubmit: o }) => s("div", { className: "ul-card-longform__submit-button-container", children: s(te, { className: "ul-card-longform__submit-button", disabled: e, onClick: o, children: ["OK ", s(ne, {})] }) }), he = (e, o) => { const i = S(0); return () => { if (e.current) { const t = e.current; t.style.height = "1px"; const n = t.scrollHeight + (t.offsetHeight - t.clientHeight), r = parseInt(window.getComputedStyle(t).getPropertyValue("max-height")), a = n <= r ? n : r; i.current !== a && requestAnimationFrame(() => { o(); }), i.current = a, t.style.height = `${a}px`; } }; }, be = (e) => { const o = S(), { setAllResponsesRaw: i } = k((t) => ({ setAllResponsesRaw: t.setAllResponsesRaw })); E(() => { const t = o.current; (!t || Object.keys(e).length !== Object.keys(t).length || Object.keys(e).some((n) => e[n] !== t[n])) && (i(e), o.current = e); }, [e, i]); }, F = ({ buttonText: e = "View Prototype", handleClick: o }) => s("button", { className: "prototype-button", onClick: o, children: e }, "prototype-btn"), me = ({ embeddedType: e = "prototype", properties: o, children: i }) => { var y; const { handleClickEmbedButton: t, hasViewedEmbed: n, headers: r, useDesktopPrototype: a } = k((u) => ({ handleClickEmbedButton: u.handleClickEmbedButton, hasViewedEmbed: u.hasViewedEmbed, headers: u.headers, useDesktopPrototype: u.useDesktopPrototype })), h = (o == null ? void 0 : o.conceptUrl) || ((y = o == null ? void 0 : o.consentDocument) == null ? void 0 : y.url), l = window.innerWidth < ee, p = r["userleap-platform"], d = (u, f) => { u.preventDefault(), t(f); }; if ((() => { const { update: u, index: f, isConversationalUI: v, viewDocument: T } = k(({ update: m, index: b, isConversationalUI: w, viewDocument: g }) => ({ update: m, index: b, isConversationalUI: w, viewDocument: g })), c = Y(u, 100); E(() => { if (v) return; const m = new ResizeObserver(c), b = T.querySelector(".ul-card__container"); return b && m.observe(b, { box: "border-box" }), () => { m.disconnect(); }; }, [c, u, f, v, T]); })(), !a && l && !n && h && ["email", "link"].includes(p)) { if (e === "prototype") return s(F, { handleClick: (u) => { d(u, "question.prototype.click"); } }); if (e === "pdf") return s(F, { buttonText: (o == null ? void 0 : o.viewDocumentText) || "View Document", handleClick: (u) => { d(u, "question.agreement.click"); } }); } return s(H, { children: i }); }, V = ({ isSelected: e, id: o, divId: i, themeColor: t, disabled: n = !1 }) => s("div", { "aria-checked": e, "aria-disabled": n, "aria-labelledby": `label-${o}`, className: "select-checkbox", id: i, role: "checkbox", style: { ...e ? { backgroundColor: t, borderColor: t, boxShadow: "none" } : {}, ...n ? { opacity: 0.5 } : {} }, tabIndex: n ? -1 : 0, children: e && s(Q, {}) }), ve = ({ ariaLabel: e, border: o, choiceStyle: i = {}, label: t, isSelected: n, value: r, text: a, id: h, isRadio: l, useMobileStyling: p, error: d, allowTextEntry: y, noneOfTheAbove: u, promptText: f, disabled: v = !1, onUserInputChanged: T }) => { const { styleNonce: c, viewDocument: m } = k((x) => ({ styleNonce: x.styleNonce, viewDocument: x.viewDocument })), [b, w] = R(!1); ie(m, o, c); const g = ({ isSelected: x, userText: I }) => { T && T({ id: h, selected: x, value: r, userText: I, noneOfTheAbove: u }); }, D = (x) => { v || (x.stopPropagation(), g({ isSelected: l || !n, userText: a }), w(!1)); }, z = () => { b || w(!0); }, O = () => { b && w(!1); }, N = { onClick: (x) => D(x), onKeyPress: (x) => ((I) => { v || I.key !== "Enter" && I.key !== " " || D(I); })(x) }; "ontouchstart" in m.documentElement ? (N.onTouchStart = O, N.onTouchCancel = O, N.onTouchEnd = O) : (N.onMouseDown = z, N.onMouseLeave = O); const L = l ? `radio-${h}` : `checkbox-${h}`, P = n || b ? [$] : [], K = [...d ? [B] : [], ...P, ...v ? ["ul-choice-disabled"] : []], W = t ? { "aria-labelledby": `label-${h}` } : { "aria-label": e }; return s("div", { className: C(q("choice", p), ...K), id: `choice-div-${h}`, style: { ...i, ...d ? { borderColor: j } : {}, ...v ? { opacity: 0.5, cursor: "not-allowed" } : {} }, ...v ? {} : N, "aria-disabled": v, children: [s("div", { className: C("choice-label-container"), children: [l ? s("div", { ...W, className: C("select-radio", ...P), id: L, role: "radio", tabIndex: 0 }) : s(V, { disabled: v, divId: L, id: h, isSelected: n, themeColor: o }), t && s("label", { className: C(q("select-label", p)), htmlFor: L, id: `label-${h}`, children: t })] }), y && n && s("div", { className: C("choice-text-entry-container", ...P), children: s(se, { onTextChange: (x) => g({ isSelected: n, userText: x }), promptText: f || "Please specify", textValue: a, useMobileStyling: p }) })] }); }, se = ({ promptText: e, textValue: o, onTextChange: i, useMobileStyling: t }) => { const n = S(null); return E(() => { n.current && n.current.focus(); }, []), s("textarea", { "aria-label": e, "aria-multiline": "true", "aria-placeholder": e, className: C(q("choice-text-input", t)), "data-gramm": "false", maxLength: 5e3, name: "text", onChange: (r) => { r.stopPropagation(), i(r.currentTarget.value); }, onClick: (r) => { r.stopPropagation(); }, onKeyPress: (r) => { r.stopPropagation(); }, placeholder: e, ref: n, role: "textbox", rows: 1, value: o }); }, U = "ul-select-style-element", $ = "ul-select-active-dynamic-style", B = "ul-select-error-dynamic-style", ie = (e, o, i) => { let t = e.getElementById(U), n = !1; t || (t = e.createElement("style"), n = !0), t.tagName.toLowerCase() === "style" && (t.id = U, i && (t.nonce = i), t.textContent = re(o), n && e.head.appendChild(t)); }, re = (e) => ` .${$} { border-color: ${e}; } .${$} .select-radio, .${$}.select-radio { border: 6px solid ${e}; box-shadow: none; } .${B} { border-color: ${j}; } `, we = ({ children: e }) => s("div", { className: "sprig-question-body", children: e }), xe = ({ children: e }) => { const o = M(), { isConversationalUI: i } = k((t) => ({ isConversationalUI: t.isConversationalUI })); return s("div", { className: C("sprig-question-footer-container", o && !i ? "sprig-border-top" : null), children: e }); }, le = ({ options: e, selectItem: o, selectedOptions: i, showCheckbox: t, disabledOptions: n, dropdownFooter: r, panelRef: a }) => { const { themeColor: h } = k((l) => ({ doc: l.viewDocument, themeColor: l.border })); return s("div", { className: "select-list", ref: a, children: [e.map((l) => { return s("div", { "aria-disabled": n == null ? void 0 : n.includes(l), className: C("select-option", n != null && n.includes(l) ? "ul-choice-disabled" : ""), onClick: (d) => { n != null && n.includes(l) || (o(l), d.stopPropagation()); }, role: "option", style: { ...n != null && n.includes(l) ? { opacity: 0.5, cursor: "not-allowed" } : {} }, children: [t && s(V, { divId: (p = l.id, `checkbox-div-${p}`), id: l.id, isSelected: i.includes(l), themeColor: h }), l.label] }, l.id); var p; }), r] }); }, ye = ({ isMultiSelect: e = !1, multiselectText: o = "choices selected", onChange: i, options: t, placeholderText: n, value: r, disabledOptions: a = [], dropdownFooter: h }) => { const [l, p] = R(!1), d = S(null), { viewDocument: y, update: u, isConversationalUI: f } = k((c) => ({ viewDocument: c.viewDocument, update: c.update, isConversationalUI: c.isConversationalUI })), v = () => { p(!l); }; _(() => { f || u(); }, [l, f, u]), _(() => { l && d.current && d.current.scrollIntoView({ behavior: "smooth", block: "nearest" }); }, [l]), E(() => { var m; const c = (b) => { const w = b.target; (w == null ? void 0 : w.closest(".select-option.ul-choice-disabled")) || p(!1); }; y.addEventListener("click", c); try { (m = window.parent) == null || m.addEventListener("click", c); } catch { window.addEventListener("click", c); } return () => { var b; y.removeEventListener("click", c); try { (b = window.parent) == null || b.removeEventListener("click", c); } catch { window.removeEventListener("click", c); } }; }, [y]); const T = r.length === 0 ? ["select-button-placeholder"] : []; return s(H, { children: [s("button", { "aria-label": "choice dropdown button", className: C("select-button", ...T), onClick: (c) => { c.stopPropagation(), v(); }, type: "button", children: [s("span", { children: r.length === 0 ? n : r.length === 1 ? r[0].label : `${r.length} ${o}` }), s(G, {})] }), l && s(le, { disabledOptions: a, dropdownFooter: h, options: t, panelRef: d, selectedOptions: r, selectItem: (c) => { var w; const m = r.some((g) => g.id === c.id), b = r.some((g) => { var D; return (D = g.optionProperties) == null ? void 0 : D.noneOfTheAbove; }); (w = c.optionProperties) != null && w.noneOfTheAbove && !m ? i([c]) : e ? i(m ? r.filter((g) => g.id !== c.id) : b ? [c] : [...r, c]) : m || i([c]), e || v(); }, showCheckbox: e })] }); }, ae = { "{{user_id}}": "externalUserId", "{{email}}": "email" }, ge = (e = void 0, o = {}) => { if (!e) return e; const i = ["http:", "https:", "itms-apps:", "market:"], t = ((a) => /^[a-zA-Z][a-zA-Z0-9+\-.]*:\/\//.test(a) ? a : `http://${a}`)(e); if (!t) return; try { const a = new URL(t); if (!a.protocol || !i.includes(a.protocol)) return; } catch { return; } const n = [], r = ((a, h, l) => { let p = a; for (const [d, y] of Object.entries(ae)) if (p.toLowerCase().includes(d)) if (h[y]) { const u = new RegExp(d, "gi"); p = p.replace(u, h[y]); } else l.push(d); return p; })(t, o, n); return n.length === 0 ? r : ((a, h) => { if (!a.includes("?")) return a; const l = a.slice(0, a.indexOf("?")), p = a.slice(a.indexOf("?") + 1).split("&").map((d) => d.split("=")).filter((d) => !h.includes(d[1])); return p.length === 0 ? l : `${l}?${p.map((d) => d.join("=")).join("&")}`; })(r, n); }; export { te as B, ue as H, pe as L, me as M, ve as O, we as Q, ye as S, oe as a, xe as b, be as c, ge as g, he as u };