synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
97 lines (96 loc) • 2.95 kB
JavaScript
import { jsxs as S, jsx as o } from "react/jsx-runtime";
import x from "../../../assets/icons/AddToList.js";
import { Tooltip as _, Button as $ } from "@mui/material";
import { getUiOptions as w, getTemplate as u, ADDITIONAL_PROPERTY_FLAG as C, canExpand as D } from "@rjsf/utils";
import { useRef as k } from "react";
import { useDeepCompareEffectNoCheck as v } from "use-deep-compare-effect";
import { displayToast as L } from "../../ToastMessage/ToastMessage.js";
function G(h) {
const {
description: a,
disabled: T,
formData: i,
idSchema: p,
onAddClick: y,
properties: b,
readonly: A,
registry: n,
required: g,
schema: e,
title: m,
uiSchema: l
} = h, t = w(l), j = u(
"TitleFieldTemplate",
n,
t
), F = u("DescriptionFieldTemplate", n, t), c = k(/* @__PURE__ */ new Set());
return v(() => {
if ("properties" in e && e.properties) {
const d = Object.keys(e.properties), f = new Set(
d.filter((s) => !e.properties[s][C])
);
if (c.current != null) {
const s = Array.from(
c.current
).filter((r) => (
// Property is no longer in schema
!f.has(r) && // Form data exists
!!i && // Property still exists in form data and is not null
// if the data is null, then we don't need to worry about it; user data wasn't lost
i[r] != null && // Property matches `additionalProperties` requirements: is an array and contains non-null values
Array.isArray(i[r]) && i[r].filter(
(O) => O != null
).length > 0
));
s.length > 0 && L(
`The following annotations are no longer specified by the schema and have been converted to custom fields: ${s.join(
", "
)}.`,
"warning",
{
title: "Fields No Longer Specified By Schema"
}
);
}
c.current = f;
}
}, [e.properties]), /* @__PURE__ */ S("fieldset", { id: p.$id, children: [
(t.title || m) && /* @__PURE__ */ o(
j,
{
id: `${p.$id}__title`,
schema: e,
title: t.title || m,
required: g,
uiSchema: l,
registry: n
}
),
(t.description || a) && /* @__PURE__ */ o(
F,
{
id: `${p.$id}__description`,
description: t.description || a,
registry: n,
schema: e
}
),
b.map((d) => d.content),
D(e, l, i) && /* @__PURE__ */ o(_, { title: "Add a new custom field", placement: "top", children: /* @__PURE__ */ o(
$,
{
sx: { my: 2 },
variant: "contained",
className: "rjsf-object-property-expand",
onClick: y(e),
disabled: T || A,
"aria-label": "Add Custom Field",
children: /* @__PURE__ */ o(x, {})
}
) })
] });
}
export {
G as ObjectFieldTemplate
};
//# sourceMappingURL=ObjectFieldTemplate.js.map