scrivito-pisasales-questionnaire-builder
Version:
Scrivito widgets for building PisaSales questionnaires
88 lines (87 loc) • 2.96 kB
JavaScript
import * as h from "react";
import { useEffect as i, useState as c, useCallback as E, useRef as M } from "react";
import * as p from "scrivito";
import { g as F } from "./idGenerator-CnyWSta9.js";
import { E as b, H as C, j as m } from "./scrivitoConfig-WST4rsmc.js";
import { jsxs as f, jsx as a } from "react/jsx-runtime";
import { u as L, b as y } from "./FormContext-CyyAThXO.js";
const j = (o) => {
i(() => {
try {
!o.get(b) && p.isInPlaceEditingActive() && o.update({ externalId: F() });
} catch (n) {
console.error("Error generating externalId:", n);
}
}, []);
}, R = () => {
const [o, n] = h.useState(!1);
return /* @__PURE__ */ f("div", { className: "mandatory-container", children: [
/* @__PURE__ */ a(
"span",
{
className: "text-mandatory",
onMouseEnter: () => {
n(!0);
},
onMouseLeave: () => {
n(!1);
},
children: "*"
}
),
o && /* @__PURE__ */ a("div", { className: "form-popover-container", children: /* @__PURE__ */ a("div", { className: "form-popover-body", children: "mandatory" }) })
] });
}, T = ({ widget: o }) => {
const [n, s] = h.useState(!1);
return /* @__PURE__ */ f("div", { className: "helptext-container", children: [
/* @__PURE__ */ a(
"i",
{
className: "bi bi-question-circle",
onMouseEnter: () => {
s(!0);
},
onMouseLeave: () => {
s(!1);
}
}
),
n && /* @__PURE__ */ a("div", { className: "form-popover-container", children: /* @__PURE__ */ a("div", { className: "form-popover-body", children: /* @__PURE__ */ a(p.ContentTag, { content: o, attribute: C }) }) })
] });
}, V = (o, n, s) => {
const e = L(), [r, l] = c(n), [g, d] = c(s || []), u = E(() => {
const t = e == null ? void 0 : e.getAnswer(o);
t ? (l(t.value), d(t.valueIdentifier)) : m(n) || e == null || e.onChange(o, n, s);
}, [e == null ? void 0 : e.getAnswer, o, n, e == null ? void 0 : e.onChange]);
return i(() => {
m(o) || u();
}, [u, o]), { values: r, idns: g, handleChange: (t, v = [""]) => {
l(t), d(v), e == null || e.onChange(o, t, v);
} };
}, k = (o, n) => {
const s = M(null), e = y(), [r, l] = c(!0);
if (e)
return i(() => {
e.updateValidationState(o, r);
}, [r]), i(() => {
e.registerField(o, n);
}, [o, n]), i(() => {
e.invalidFields[o] !== void 0 && l(!e.invalidFields[o]);
}, [e.invalidFields, o]), i(() => {
e.firstInvalidField === o && s.current && requestAnimationFrame(() => {
s.current.scrollIntoView({
behavior: "smooth",
block: "center",
inline: "nearest"
}), e.setFirstInvalidField(null);
});
}, [e.firstInvalidField]), { isLocallyValid: r, setIsLocallyValid: l, ref: s };
};
export {
T as H,
R as M,
k as a,
j as b,
V as u
};
//# sourceMappingURL=useValidationField-BrRv6UCn.js.map