@firecms/core 3.0.0-canary.203 → 3.0.0-canary.204
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/form/EntityForm.d.ts +3 -2
- package/dist/index.es.js +52 -100
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +52 -100
- package/dist/index.umd.js.map +1 -1
- package/package.json +5 -5
- package/src/core/EntityEditView.tsx +7 -23
- package/src/form/EntityForm.tsx +82 -67
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Entity, EntityCollection, EntityStatus, FormContext } from "../types";
|
|
2
|
+
import { Entity, EntityCollection, EntityCustomViewParams, EntityStatus, FormContext } from "../types";
|
|
3
3
|
import { FormexController } from "@firecms/formex";
|
|
4
4
|
import { ValidationError } from "yup";
|
|
5
5
|
import { EntityFormActionsProps } from "./EntityFormActions";
|
|
@@ -38,9 +38,10 @@ export type EntityFormProps<M extends Record<string, any>> = {
|
|
|
38
38
|
*/
|
|
39
39
|
showEntityPath?: boolean;
|
|
40
40
|
EntityFormActionsComponent?: React.FC<EntityFormActionsProps>;
|
|
41
|
+
Builder?: React.ComponentType<EntityCustomViewParams<M>>;
|
|
41
42
|
children?: React.ReactNode;
|
|
42
43
|
};
|
|
43
|
-
export declare function EntityForm<M extends Record<string, any>>({ path, entityId: entityIdProp, collection, onValuesModified, onIdChange, onSaved, entity, initialDirtyValues, onFormContextReady, forceActionsAtTheBottom, initialStatus, className, onStatusChange, onEntityChange, openEntityMode, formex: formexProp, EntityFormActionsComponent, showDefaultActions, showEntityPath, children }: EntityFormProps<M>): import("react/jsx-runtime").JSX.Element;
|
|
44
|
+
export declare function EntityForm<M extends Record<string, any>>({ path, entityId: entityIdProp, collection, onValuesModified, onIdChange, onSaved, entity, initialDirtyValues, onFormContextReady, forceActionsAtTheBottom, initialStatus, className, onStatusChange, onEntityChange, openEntityMode, formex: formexProp, Builder, EntityFormActionsComponent, showDefaultActions, showEntityPath, children }: EntityFormProps<M>): import("react/jsx-runtime").JSX.Element;
|
|
44
45
|
export declare function yupToFormErrors(yupError: ValidationError): Record<string, any>;
|
|
45
46
|
export declare function FormLayoutInner({ id, formContext, children, className, forceActionsAtTheBottom, pluginActions, EntityFormActionsComponent, showDefaultActions, }: {
|
|
46
47
|
id?: string;
|
package/dist/index.es.js
CHANGED
|
@@ -16296,6 +16296,7 @@ function EntityForm({
|
|
|
16296
16296
|
onEntityChange,
|
|
16297
16297
|
openEntityMode = "full_screen",
|
|
16298
16298
|
formex: formexProp,
|
|
16299
|
+
Builder,
|
|
16299
16300
|
EntityFormActionsComponent = EntityFormActions,
|
|
16300
16301
|
showDefaultActions = true,
|
|
16301
16302
|
showEntityPath = true,
|
|
@@ -16610,45 +16611,50 @@ function EntityForm({
|
|
|
16610
16611
|
}
|
|
16611
16612
|
}, [formex.isSubmitting, autoSave, underlyingChanges, entity, formex.values, formex.touched, formex.setFieldValue]);
|
|
16612
16613
|
const formFieldKeys = getFormFieldKeys(resolvedCollection);
|
|
16613
|
-
const formFields = () =>
|
|
16614
|
-
|
|
16615
|
-
|
|
16616
|
-
|
|
16617
|
-
|
|
16618
|
-
const
|
|
16619
|
-
if (
|
|
16620
|
-
|
|
16621
|
-
|
|
16622
|
-
|
|
16623
|
-
|
|
16624
|
-
|
|
16625
|
-
|
|
16626
|
-
|
|
16627
|
-
|
|
16628
|
-
|
|
16629
|
-
|
|
16630
|
-
|
|
16631
|
-
|
|
16632
|
-
|
|
16633
|
-
|
|
16634
|
-
|
|
16635
|
-
|
|
16636
|
-
|
|
16637
|
-
if (!Builder && !additionalField.value) {
|
|
16638
|
-
throw new Error("When using additional fields you need to provide a Builder or a value");
|
|
16614
|
+
const formFields = () => {
|
|
16615
|
+
if (Builder) {
|
|
16616
|
+
return /* @__PURE__ */ jsx(Builder, { collection, entity, modifiedValues: formex.values, formContext });
|
|
16617
|
+
}
|
|
16618
|
+
return /* @__PURE__ */ jsx(FormLayout, { children: formFieldKeys.map((key_1) => {
|
|
16619
|
+
const property_0 = resolvedCollection.properties[key_1];
|
|
16620
|
+
if (property_0) {
|
|
16621
|
+
const underlyingValueHasChanged = !!underlyingChanges && Object.keys(underlyingChanges).includes(key_1) && formex.touched[key_1];
|
|
16622
|
+
const disabled = !autoSave && formex.isSubmitting || isReadOnly(property_0) || Boolean(property_0.disabled);
|
|
16623
|
+
const hidden = isHidden(property_0);
|
|
16624
|
+
if (hidden) return null;
|
|
16625
|
+
const widthPercentage = property_0.widthPercentage ?? 100;
|
|
16626
|
+
const cmsFormFieldProps = {
|
|
16627
|
+
propertyKey: key_1,
|
|
16628
|
+
disabled,
|
|
16629
|
+
property: property_0,
|
|
16630
|
+
includeDescription: property_0.description || property_0.longDescription,
|
|
16631
|
+
underlyingValueHasChanged: underlyingValueHasChanged && !autoSave,
|
|
16632
|
+
context: formContext,
|
|
16633
|
+
partOfArray: false,
|
|
16634
|
+
minimalistView: false,
|
|
16635
|
+
autoFocus: false
|
|
16636
|
+
};
|
|
16637
|
+
return /* @__PURE__ */ jsx(FormEntry, { propertyKey: key_1, widthPercentage, children: /* @__PURE__ */ jsx(PropertyFieldBinding, { ...cmsFormFieldProps }) }, `field_${key_1}`);
|
|
16639
16638
|
}
|
|
16640
|
-
const
|
|
16641
|
-
|
|
16642
|
-
|
|
16643
|
-
|
|
16644
|
-
|
|
16645
|
-
|
|
16646
|
-
/* @__PURE__ */ jsx(
|
|
16647
|
-
|
|
16648
|
-
|
|
16649
|
-
|
|
16650
|
-
|
|
16651
|
-
|
|
16639
|
+
const additionalField = resolvedCollection.additionalFields?.find((f) => f.key === key_1);
|
|
16640
|
+
if (additionalField && entity) {
|
|
16641
|
+
const Builder_0 = additionalField.Builder;
|
|
16642
|
+
if (!Builder_0 && !additionalField.value) {
|
|
16643
|
+
throw new Error("When using additional fields you need to provide a Builder or a value");
|
|
16644
|
+
}
|
|
16645
|
+
const child = Builder_0 ? /* @__PURE__ */ jsx(Builder_0, { entity, context }) : /* @__PURE__ */ jsx("div", { className: "w-full", children: additionalField.value?.({
|
|
16646
|
+
entity,
|
|
16647
|
+
context
|
|
16648
|
+
})?.toString() });
|
|
16649
|
+
return /* @__PURE__ */ jsxs("div", { className: "w-full", children: [
|
|
16650
|
+
/* @__PURE__ */ jsx(LabelWithIconAndTooltip, { propertyKey: key_1, icon: /* @__PURE__ */ jsx(NotesIcon, { size: "small" }), title: additionalField.name, className: "text-text-secondary dark:text-text-secondary-dark ml-3.5" }),
|
|
16651
|
+
/* @__PURE__ */ jsx("div", { className: cls(paperMixin, "w-full min-h-14 p-4 md:p-6 overflow-x-scroll no-scrollbar"), children: /* @__PURE__ */ jsx(ErrorBoundary, { children: child }) })
|
|
16652
|
+
] }, `additional_${key_1}`);
|
|
16653
|
+
}
|
|
16654
|
+
console.warn(`Property ${key_1} not found in collection ${resolvedCollection.name} in properties or additional fields. Skipping.`);
|
|
16655
|
+
return null;
|
|
16656
|
+
}).filter(Boolean) });
|
|
16657
|
+
};
|
|
16652
16658
|
const formRef = useRef(null);
|
|
16653
16659
|
const formView = /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
16654
16660
|
/* @__PURE__ */ jsxs("div", { className: "w-full py-2 flex flex-col items-start my-4 lg:my-6", children: [
|
|
@@ -21749,52 +21755,6 @@ function EntityEditView(t0) {
|
|
|
21749
21755
|
}
|
|
21750
21756
|
return t5;
|
|
21751
21757
|
}
|
|
21752
|
-
function SecondaryForm(t0) {
|
|
21753
|
-
const $ = c(12);
|
|
21754
|
-
const {
|
|
21755
|
-
collection,
|
|
21756
|
-
className,
|
|
21757
|
-
customView,
|
|
21758
|
-
entity,
|
|
21759
|
-
formContext,
|
|
21760
|
-
forceActionsAtTheBottom
|
|
21761
|
-
} = t0;
|
|
21762
|
-
if (!customView.Builder) {
|
|
21763
|
-
console.error("customView.Builder is not defined");
|
|
21764
|
-
return null;
|
|
21765
|
-
}
|
|
21766
|
-
let t1;
|
|
21767
|
-
if ($[0] !== collection || $[1] !== customView.Builder || $[2] !== entity || $[3] !== formContext) {
|
|
21768
|
-
t1 = formContext && /* @__PURE__ */ jsx(customView.Builder, { collection, entity, modifiedValues: formContext.formex.values ?? entity?.values, formContext });
|
|
21769
|
-
$[0] = collection;
|
|
21770
|
-
$[1] = customView.Builder;
|
|
21771
|
-
$[2] = entity;
|
|
21772
|
-
$[3] = formContext;
|
|
21773
|
-
$[4] = t1;
|
|
21774
|
-
} else {
|
|
21775
|
-
t1 = $[4];
|
|
21776
|
-
}
|
|
21777
|
-
let t2;
|
|
21778
|
-
if ($[5] !== t1) {
|
|
21779
|
-
t2 = /* @__PURE__ */ jsx(ErrorBoundary, { children: t1 });
|
|
21780
|
-
$[5] = t1;
|
|
21781
|
-
$[6] = t2;
|
|
21782
|
-
} else {
|
|
21783
|
-
t2 = $[6];
|
|
21784
|
-
}
|
|
21785
|
-
let t3;
|
|
21786
|
-
if ($[7] !== className || $[8] !== forceActionsAtTheBottom || $[9] !== formContext || $[10] !== t2) {
|
|
21787
|
-
t3 = /* @__PURE__ */ jsx(FormLayoutInner, { className, forceActionsAtTheBottom, formContext, EntityFormActionsComponent: EntityEditViewFormActions, children: t2 });
|
|
21788
|
-
$[7] = className;
|
|
21789
|
-
$[8] = forceActionsAtTheBottom;
|
|
21790
|
-
$[9] = formContext;
|
|
21791
|
-
$[10] = t2;
|
|
21792
|
-
$[11] = t3;
|
|
21793
|
-
} else {
|
|
21794
|
-
t3 = $[11];
|
|
21795
|
-
}
|
|
21796
|
-
return t3;
|
|
21797
|
-
}
|
|
21798
21758
|
function EntityEditViewInner({
|
|
21799
21759
|
path,
|
|
21800
21760
|
entityId,
|
|
@@ -21831,7 +21791,6 @@ function EntityEditViewInner({
|
|
|
21831
21791
|
setSelectedTab(selectedTabProp ?? MAIN_TAB_VALUE);
|
|
21832
21792
|
}
|
|
21833
21793
|
}, [selectedTabProp]);
|
|
21834
|
-
const mainViewVisible = selectedTab === MAIN_TAB_VALUE;
|
|
21835
21794
|
const subcollections = (collection.subcollections ?? []).filter((c2) => !c2.hideFromNavigation);
|
|
21836
21795
|
const subcollectionsCount = subcollections?.length ?? 0;
|
|
21837
21796
|
const customViews = collection.entityViews;
|
|
@@ -21839,25 +21798,19 @@ function EntityEditViewInner({
|
|
|
21839
21798
|
const hasAdditionalViews = customViewsCount > 0 || subcollectionsCount > 0;
|
|
21840
21799
|
const resolvedEntityViews = customViews ? customViews.map((e) => resolveEntityView(e, customizationController.entityViews)).filter(Boolean) : [];
|
|
21841
21800
|
const selectedEntityView = resolvedEntityViews.find((e_0) => e_0.key === selectedTab);
|
|
21801
|
+
const selectedSecondaryForm = formContext && customViews && resolvedEntityViews.filter((e_1) => e_1.includeActions).find((e_2) => e_2.key === selectedTab);
|
|
21842
21802
|
const actionsAtTheBottom = !largeLayout || layout === "side_panel" || selectedEntityView?.includeActions === "bottom";
|
|
21843
|
-
const
|
|
21844
|
-
|
|
21845
|
-
if (!customView
|
|
21846
|
-
|
|
21847
|
-
return null;
|
|
21848
|
-
}
|
|
21849
|
-
return /* @__PURE__ */ jsx(SecondaryForm, { className: selectedTab !== customView.key ? "hidden" : "", customView, formContext, collection, forceActionsAtTheBottom: !largeLayout || layout === "side_panel" || customView.includeActions === "bottom", entity: usedEntity }, `custom_view_${customView.key}`);
|
|
21850
|
-
}).filter(Boolean);
|
|
21851
|
-
const customViewsView = customViews && resolvedEntityViews.filter((e_2) => !e_2.includeActions).map((customView_0) => {
|
|
21852
|
-
if (!customView_0) return null;
|
|
21853
|
-
const Builder = customView_0.Builder;
|
|
21803
|
+
const mainViewVisible = selectedTab === MAIN_TAB_VALUE || Boolean(selectedSecondaryForm);
|
|
21804
|
+
const customViewsView = customViews && resolvedEntityViews.filter((e_3) => !e_3.includeActions).map((customView) => {
|
|
21805
|
+
if (!customView) return null;
|
|
21806
|
+
const Builder = customView.Builder;
|
|
21854
21807
|
if (!Builder) {
|
|
21855
21808
|
console.error("customView.Builder is not defined");
|
|
21856
21809
|
return null;
|
|
21857
21810
|
}
|
|
21858
21811
|
return /* @__PURE__ */ jsx("div", { className: cls(defaultBorderMixin, "relative flex-1 w-full h-full overflow-auto", {
|
|
21859
|
-
"hidden": selectedTab !==
|
|
21860
|
-
}), role: "tabpanel", children: /* @__PURE__ */ jsx(ErrorBoundary, { children: formContext && /* @__PURE__ */ jsx(Builder, { collection, entity: usedEntity, modifiedValues: formContext.formex.values ?? usedEntity?.values, formContext }) }) }, `custom_view_${
|
|
21812
|
+
"hidden": selectedTab !== customView.key
|
|
21813
|
+
}), role: "tabpanel", children: /* @__PURE__ */ jsx(ErrorBoundary, { children: formContext && /* @__PURE__ */ jsx(Builder, { collection, entity: usedEntity, modifiedValues: formContext.formex.values ?? usedEntity?.values, formContext }) }) }, `custom_view_${customView.key}`);
|
|
21861
21814
|
}).filter(Boolean);
|
|
21862
21815
|
const globalLoading = dataLoading && !usedEntity;
|
|
21863
21816
|
const subCollectionsViews = subcollections && subcollections.map((subcollection) => {
|
|
@@ -21896,7 +21849,7 @@ function EntityEditViewInner({
|
|
|
21896
21849
|
};
|
|
21897
21850
|
onSaved?.(res);
|
|
21898
21851
|
formProps?.onSaved?.(res);
|
|
21899
|
-
} });
|
|
21852
|
+
}, Builder: selectedSecondaryForm?.Builder });
|
|
21900
21853
|
const subcollectionTabs = subcollections && subcollections.map((subcollection_0) => /* @__PURE__ */ jsx(Tab, { className: "text-sm min-w-[120px]", value: subcollection_0.id, children: subcollection_0.name }, `entity_detail_collection_tab_${subcollection_0.name}`));
|
|
21901
21854
|
const customViewTabs = resolvedEntityViews.map((view) => /* @__PURE__ */ jsx(Tab, { className: "text-sm min-w-[120px]", value: view.key, children: view.name }, `entity_detail_collection_tab_${view.name}`));
|
|
21902
21855
|
const shouldShowTopBar = Boolean(barActions) || hasAdditionalViews;
|
|
@@ -21914,7 +21867,6 @@ function EntityEditViewInner({
|
|
|
21914
21867
|
] })
|
|
21915
21868
|
] }),
|
|
21916
21869
|
globalLoading ? /* @__PURE__ */ jsx("div", { className: "w-full pt-12 pb-16 px-4 sm:px-8 md:px-10", children: /* @__PURE__ */ jsx(CircularProgressCenter, {}) }) : entityView,
|
|
21917
|
-
secondaryForms,
|
|
21918
21870
|
customViewsView,
|
|
21919
21871
|
subCollectionsViews
|
|
21920
21872
|
] });
|