synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
76 lines (75 loc) • 2.75 kB
JavaScript
import { jsx as o, jsxs as g, Fragment as T } from "react/jsx-runtime";
import { RJSFInputLabelWrapper as F } from "./RJSFInputLabel.js";
import { Box as x, Button as C } from "@mui/material";
import { getUiOptions as L, getTemplate as s, ADDITIONAL_PROPERTY_FLAG as P } from "@rjsf/utils";
import { isEmpty as R } from "lodash-es";
import { useEffect as D } from "react";
import { useAdditionalPropertyContext as b } from "../../SchemaDrivenAnnotationEditor/template/AdditionalPropertyContext.js";
function S(e) {
const { idSchema: n, uiSchema: l, items: i, registry: r, schema: a, formContext: d } = e, t = L(l), A = s("ArrayFieldTitleTemplate", r, t), u = s("ArrayFieldDescriptionTemplate", r, t), y = s(
"ArrayFieldItemTemplate",
r,
t
), c = !!e.schema[P], p = b();
return D(() => {
// Do not manipulate if the widget is hidden (e.g. 'scopeIds' in an EntityView)
// FIXME: We should probably remove this hook and migrate to a design that accommodates empty arrays.
t.widget !== "hidden" && e.items.length === 0 && !d?.allowRemovingLastItemInArray && e.onAddClick();
}, [e, d?.allowRemovingLastItemInArray, t.widget]), /* @__PURE__ */ o(x, { id: n.$id, className: e.className, children: /* @__PURE__ */ g(
F,
{
fieldLabel: /* @__PURE__ */ o(
A,
{
idSchema: n,
title: t.title || e.title,
schema: a,
uiSchema: l,
required: e.required,
registry: r
}
),
description: /* @__PURE__ */ o(
u,
{
idSchema: n,
schema: a,
description: (t.description || a.description) ?? "",
uiSchema: l,
registry: r
}
),
registry: r,
children: [
(!i || R(i)) && /* @__PURE__ */ o(C, { variant: "outlined", onClick: e.onAddClick, children: "Add item" }),
i && /* @__PURE__ */ o(T, { children: i.map(
({
key: f,
index: h,
...m
}) => /* @__PURE__ */ o(
y,
{
index: h,
...m,
buttonsProps: {
...m.buttonsProps,
// Override hasRemove to prevent removing the last item in an array (except additional properties),
// unless overridden by formContext
hasRemove: c || i.length > 1 || !!d?.allowRemovingLastItemInArray,
onDropIndexClick: c && i.length == 1 && p ? () => (I) => {
p.dropProperty(I);
} : m.buttonsProps.onDropIndexClick
}
},
f
)
) })
]
}
) });
}
export {
S as default
};
//# sourceMappingURL=ArrayFieldTemplate.js.map