@react-form-builder/core
Version:
React JSON Schema Form Builder to create complex, validated, reusable forms with no deep React knowledge required
51 lines (50 loc) • 2.13 kB
JavaScript
import { jsxs as u, jsx as r } from "react/jsx-runtime";
import { useMemo as m } from "react";
import { useBuilderMode as c } from "../../utils/contexts/BuilderModeContext.js";
import { useComponentData as b } from "../../utils/contexts/ComponentDataContext.js";
import { StoreProvider as F } from "../../utils/contexts/StoreContext.js";
import { createNonNullableContext as p } from "../../utils/createNonNullableContext.js";
import { isUndefined as i } from "../../utils/tools.js";
import { useViewerProps as v } from "../form-viewer/components/ViewerPropsContext.js";
import { useEmbeddedFormViewer as h } from "../form-viewer/EmbeddedFormViewerContext.js";
import { TemplateField as E } from "../validation/utils/TemplateField.js";
import P from "./EmbeddedForm.module.css.js";
const [
/**
* **Internal use only.**
*/
T,
/**
* **Internal use only.**
*/
w
] = p("EmbeddedFormContext"), N = ({ children: e }) => /* @__PURE__ */ r("span", { className: P.embeddedFormLoadError, children: e }), B = (e) => {
const o = v(), d = b(), n = c(), a = h(), t = m(() => {
const f = {
formName: e.formName,
formOptions: e.options,
onFormDataChange: void 0,
formValidators: void 0,
disabled: e.disabled,
readOnly: e.readOnly,
initialState: {}
};
return Object.assign({}, o, f);
}, [o, e]), s = m(() => ({ embeddedFormProps: e, viewerProps: o, data: d }), [e, o, d]);
if (!t.getForm)
return /* @__PURE__ */ u(N, { children: [
"Please define the ",
/* @__PURE__ */ r("code", { children: "getForm" }),
" property!"
] });
if (i(e.formName) && i(e.options))
return n === "builder" ? /* @__PURE__ */ r("span", { children: "The name of the form and options are not specified, set at least one value to display the form" }) : null;
if (!(d.field instanceof E)) return null;
const l = d.field.viewerStore;
return /* @__PURE__ */ r(w, { value: s, children: /* @__PURE__ */ r(F, { value: l, children: /* @__PURE__ */ r(a, { ...t }) }) });
};
export {
B as EmbeddedForm,
T as useEmbeddedForm
};
//# sourceMappingURL=EmbeddedForm.js.map