scrivito-pisasales-questionnaire-builder
Version:
Scrivito widgets for building PisaSales questionnaires
112 lines (111 loc) • 3.33 kB
JavaScript
import { J as D, K as p, N as I, R as m, U as w, W as T, X as A, Y as _, Z as E, j as o, _ as d, $ as h, x as y, l as U } from "./scrivitoConfig-WST4rsmc.js";
import { jsx as r, Fragment as O } from "react/jsx-runtime";
import { useState as R, useEffect as v } from "react";
import { provideDataClass as C, connect as f, currentLanguage as x, load as L, createRestApiClient as N, uiContext as b } from "scrivito";
import { c as u, g as P, r as V, a as Q, b as J, s as k } from "./AnswersDataClass-IG1cx70G.js";
import { g as F, r as Y } from "./DocumentDataClass-D1mg6YjJ.js";
const tt = (t) => {
if (typeof t != "string" || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/.test(t))
return !1;
const s = new Date(t);
return !isNaN(s.getTime());
}, et = (t) => {
const e = t.get(D) == "manual" ? t.get(p) : t.get(I), s = t.get(m) == "manual" ? t.get(w) : t.get(T), a = t.get(A) == "manual" ? t.get(_) : t.get(E);
return !o(e) || !o(s) || !o(a);
};
let l;
const j = async () => {
const t = await u("question");
l = C("Question", {
restApi: t,
attributes: {
questionnaireId: "string",
externalId: "string",
type: "string",
help: "string",
position: "number",
identifier: "string",
defaultValue: "string",
mandatory: "boolean",
text: "string"
}
});
}, $ = () => l || null;
let c;
const S = async () => {
const t = await u("question-option");
c = C("AnswerOption", {
restApi: t,
attributes: {
questionId: "string",
text: "string",
externalId: "string",
position: "number",
identifier: "string"
}
});
}, Z = () => c || null, K = f(({ className: t }) => {
const e = X();
return /* @__PURE__ */ r("div", { className: t, children: /* @__PURE__ */ r(
"div",
{
"aria-busy": "true",
"aria-valuetext": e,
className: "loading-placeholder",
role: "progressbar",
title: e
}
) });
});
function X() {
switch (x()) {
case "de":
return "Daten werden geladen…";
case "fr":
return "Chargement des données…";
case "pl":
return "Ładowanie danych…";
default:
return "Loading data…";
}
}
const z = () => L(async () => {
try {
const { url: t, ...e } = await u("whoami", !0);
return !!await N(t, e).get("");
} catch (t) {
return console.error(t), !1;
}
}), st = f(({ children: t }) => {
const [e, s] = R(null), a = b(), g = async () => {
const n = U();
try {
if (n || !d(h())) {
if (!P() && await V(), !Z() && await S(), !$() && await j(), !Q() && await J(), !F() && await Y(), y()) {
const i = await z();
k(i);
}
s(!0);
}
} catch (i) {
console.error("Data class registration failed", i);
}
};
return v(() => {
g();
const n = () => {
s(!1), g();
};
return typeof window < "u" && window.addEventListener("pisaUrlChanged", n), () => {
typeof window < "u" && window.removeEventListener("pisaUrlChanged", n);
};
}, []), d(e) ? /* @__PURE__ */ r(K, { className: a ? `scrivito-${a == null ? void 0 : a.theme}` : "" }) : /* @__PURE__ */ r(O, { children: t });
});
export {
st as P,
Z as a,
$ as g,
et as h,
tt as i
};
//# sourceMappingURL=PisaDataClassContext-B5rbhbtF.js.map