@firecms/core 3.0.0-canary.197 → 3.0.0-canary.198

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.
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import { Entity, EntityCollection, EntityStatus, User } from "../types";
3
+ import { EntityFormProps } from "../form";
3
4
  export type OnUpdateParams = {
4
5
  entity: Entity<any>;
5
6
  status: EntityStatus;
@@ -27,13 +28,14 @@ export interface EntityEditViewProps<M extends Record<string, any>> {
27
28
  onTabChange?: (props: OnTabChangeParams<M>) => void;
28
29
  layout?: "side_panel" | "full_screen";
29
30
  barActions?: React.ReactNode;
31
+ formProps?: Partial<EntityFormProps<M>>;
30
32
  }
31
33
  /**
32
34
  * This is the default view that is used as the content of a side panel when
33
35
  * an entity is opened.
34
36
  */
35
37
  export declare function EntityEditView<M extends Record<string, any>, USER extends User>({ entityId, ...props }: EntityEditViewProps<M>): import("react/jsx-runtime").JSX.Element;
36
- export declare function EntityEditViewInner<M extends Record<string, any>>({ path, entityId, selectedTab: selectedTabProp, collection, parentCollectionIds, onValuesModified, onSaved, onTabChange, entity, cachedDirtyValues, dataLoading, layout, barActions, status, setStatus, }: EntityEditViewProps<M> & {
38
+ export declare function EntityEditViewInner<M extends Record<string, any>>({ path, entityId, selectedTab: selectedTabProp, collection, parentCollectionIds, onValuesModified, onSaved, onTabChange, entity, cachedDirtyValues, dataLoading, layout, barActions, status, setStatus, formProps, }: EntityEditViewProps<M> & {
37
39
  entity?: Entity<M>;
38
40
  cachedDirtyValues?: Partial<M>;
39
41
  dataLoading: boolean;
@@ -1,2 +1,2 @@
1
1
  import { EntityFormActionsProps } from "../form/EntityFormActions";
2
- export declare function EntityEditViewFormActions({ collection, path, entity, layout, savingError, formex, disabled, status, pluginActions, openEntityMode }: EntityFormActionsProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function EntityEditViewFormActions({ collection, path, entity, layout, savingError, formex, disabled, status, pluginActions, openEntityMode, showDefaultActions }: EntityFormActionsProps): import("react/jsx-runtime").JSX.Element;
@@ -11,7 +11,7 @@ export type OnUpdateParams = {
11
11
  selectedTab?: string;
12
12
  collection: EntityCollection<any>;
13
13
  };
14
- type EntityFormProps<M extends Record<string, any>> = {
14
+ export type EntityFormProps<M extends Record<string, any>> = {
15
15
  path: string;
16
16
  collection: EntityCollection<M>;
17
17
  entityId?: string;
@@ -20,7 +20,7 @@ type EntityFormProps<M extends Record<string, any>> = {
20
20
  onIdChange?: (id: string) => void;
21
21
  onValuesModified?: (modified: boolean) => void;
22
22
  onSaved?: (params: OnUpdateParams) => void;
23
- cachedDirtyValues?: Partial<M>;
23
+ initialDirtyValues?: Partial<M>;
24
24
  onFormContextReady?: (formContext: FormContext) => void;
25
25
  forceActionsAtTheBottom?: boolean;
26
26
  className?: string;
@@ -29,11 +29,19 @@ type EntityFormProps<M extends Record<string, any>> = {
29
29
  onEntityChange?: (entity: Entity<M>) => void;
30
30
  formex?: FormexController<M>;
31
31
  openEntityMode?: "side_panel" | "full_screen";
32
+ /**
33
+ * Include the copy and delete actions in the form
34
+ */
35
+ showDefaultActions?: boolean;
36
+ /**
37
+ * Display the entity path in the form
38
+ */
39
+ showEntityPath?: boolean;
32
40
  EntityFormActionsComponent?: React.FC<EntityFormActionsProps>;
33
41
  };
34
- export declare function EntityForm<M extends Record<string, any>>({ path, entityId: entityIdProp, collection, onValuesModified, onIdChange, onSaved, entity, cachedDirtyValues, onFormContextReady, forceActionsAtTheBottom, initialStatus, className, onStatusChange, onEntityChange, openEntityMode, formex: formexProp, EntityFormActionsComponent }: EntityFormProps<M>): import("react/jsx-runtime").JSX.Element;
42
+ 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 }: EntityFormProps<M>): import("react/jsx-runtime").JSX.Element;
35
43
  export declare function yupToFormErrors(yupError: ValidationError): Record<string, any>;
36
- export declare function FormLayoutInner({ id, formContext, children, className, forceActionsAtTheBottom, pluginActions, EntityFormActionsComponent }: {
44
+ export declare function FormLayoutInner({ id, formContext, children, className, forceActionsAtTheBottom, pluginActions, EntityFormActionsComponent, showDefaultActions }: {
37
45
  id?: string;
38
46
  formContext: FormContext;
39
47
  children: React.ReactNode;
@@ -41,5 +49,5 @@ export declare function FormLayoutInner({ id, formContext, children, className,
41
49
  forceActionsAtTheBottom?: boolean;
42
50
  pluginActions?: React.ReactNode[];
43
51
  EntityFormActionsComponent: React.FC<EntityFormActionsProps>;
52
+ showDefaultActions?: boolean;
44
53
  }): import("react/jsx-runtime").JSX.Element;
45
- export {};
@@ -12,5 +12,6 @@ export interface EntityFormActionsProps {
12
12
  status: "new" | "existing" | "copy";
13
13
  pluginActions: React.ReactNode[];
14
14
  openEntityMode: "side_panel" | "full_screen";
15
+ showDefaultActions?: boolean;
15
16
  }
16
17
  export declare function EntityFormActions({ collection, entity, layout, savingError, formex, disabled, status, pluginActions, openEntityMode }: EntityFormActionsProps): import("react/jsx-runtime").JSX.Element;
package/dist/index.es.js CHANGED
@@ -16283,7 +16283,7 @@ function EntityForm({
16283
16283
  onIdChange,
16284
16284
  onSaved,
16285
16285
  entity,
16286
- cachedDirtyValues,
16286
+ initialDirtyValues,
16287
16287
  onFormContextReady,
16288
16288
  forceActionsAtTheBottom,
16289
16289
  initialStatus,
@@ -16292,7 +16292,9 @@ function EntityForm({
16292
16292
  onEntityChange,
16293
16293
  openEntityMode = "full_screen",
16294
16294
  formex: formexProp,
16295
- EntityFormActionsComponent = EntityFormActions
16295
+ EntityFormActionsComponent = EntityFormActions,
16296
+ showDefaultActions = true,
16297
+ showEntityPath = true
16296
16298
  }) {
16297
16299
  if (collection.customId && collection.formAutoSave) {
16298
16300
  console.warn(`The collection ${collection.path} has customId and formAutoSave enabled. This is not supported and formAutoSave will be ignored`);
@@ -16366,8 +16368,8 @@ function EntityForm({
16366
16368
  });
16367
16369
  };
16368
16370
  const formex = formexProp ?? useCreateFormex({
16369
- initialValues: cachedDirtyValues ?? getInitialEntityValues(collection, path, status, entity),
16370
- initialDirty: Boolean(cachedDirtyValues),
16371
+ initialValues: initialDirtyValues ?? getInitialEntityValues(collection, path, status, entity),
16372
+ initialDirty: Boolean(initialDirtyValues),
16371
16373
  onSubmit,
16372
16374
  onReset: () => {
16373
16375
  clearDirtyCache();
@@ -16646,7 +16648,7 @@ function EntityForm({
16646
16648
  const formView = /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsxs(Fragment, { children: [
16647
16649
  /* @__PURE__ */ jsxs("div", { className: "w-full py-2 flex flex-col items-start mt-4 lg:mt-8 mb-8", children: [
16648
16650
  /* @__PURE__ */ jsx(Typography, { className: "py-4 flex-grow line-clamp-1 " + (collection.hideIdFromForm ? "mb-2" : "mb-0"), variant: "h4", children: title ?? collection.singularName ?? collection.name }),
16649
- /* @__PURE__ */ jsx(Alert, { color: "base", className: "w-full", size: "small", children: /* @__PURE__ */ jsxs("code", { className: "text-xs select-all text-text-secondary dark:text-text-secondary-dark", children: [
16651
+ showEntityPath && /* @__PURE__ */ jsx(Alert, { color: "base", className: "w-full", size: "small", children: /* @__PURE__ */ jsxs("code", { className: "text-xs select-all text-text-secondary dark:text-text-secondary-dark", children: [
16650
16652
  entity?.path ?? path,
16651
16653
  "/",
16652
16654
  entityId
@@ -16662,7 +16664,7 @@ function EntityForm({
16662
16664
  useEffect(() => {
16663
16665
  if (entityId && onIdChange) onIdChange(entityId);
16664
16666
  }, [entityId, onIdChange]);
16665
- return /* @__PURE__ */ jsx(FormLayoutInner, { className, id: `form_${path}`, pluginActions, forceActionsAtTheBottom, EntityFormActionsComponent, formContext, children: formView });
16667
+ return /* @__PURE__ */ jsx(FormLayoutInner, { className, id: `form_${path}`, pluginActions, forceActionsAtTheBottom, EntityFormActionsComponent, formContext, showDefaultActions, children: formView });
16666
16668
  }
16667
16669
  function getInitialEntityValues(collection, path, status, entity) {
16668
16670
  const resolvedCollection = resolveCollection({
@@ -16698,7 +16700,7 @@ function yupToFormErrors(yupError) {
16698
16700
  return errors;
16699
16701
  }
16700
16702
  function FormLayoutInner(t0) {
16701
- const $ = c(41);
16703
+ const $ = c(42);
16702
16704
  const {
16703
16705
  id,
16704
16706
  formContext,
@@ -16706,7 +16708,8 @@ function FormLayoutInner(t0) {
16706
16708
  className,
16707
16709
  forceActionsAtTheBottom,
16708
16710
  pluginActions,
16709
- EntityFormActionsComponent
16711
+ EntityFormActionsComponent,
16712
+ showDefaultActions
16710
16713
  } = t0;
16711
16714
  const formex = formContext.formex;
16712
16715
  const collection = formContext.collection;
@@ -16729,8 +16732,8 @@ function FormLayoutInner(t0) {
16729
16732
  t2 = $[1];
16730
16733
  }
16731
16734
  let t3;
16732
- if ($[2] !== EntityFormActionsComponent || $[3] !== collection || $[4] !== disabled || $[5] !== entity || $[6] !== formex || $[7] !== openEntityMode || $[8] !== path || $[9] !== savingError || $[10] !== status || $[11] !== t1 || $[12] !== t2) {
16733
- t3 = /* @__PURE__ */ jsx(EntityFormActionsComponent, { collection, path, entity, layout: t1, savingError, formex, disabled, status, pluginActions: t2, openEntityMode });
16735
+ if ($[2] !== EntityFormActionsComponent || $[3] !== collection || $[4] !== disabled || $[5] !== entity || $[6] !== formex || $[7] !== openEntityMode || $[8] !== path || $[9] !== savingError || $[10] !== showDefaultActions || $[11] !== status || $[12] !== t1 || $[13] !== t2) {
16736
+ t3 = /* @__PURE__ */ jsx(EntityFormActionsComponent, { collection, path, entity, layout: t1, savingError, formex, disabled, status, pluginActions: t2, openEntityMode, showDefaultActions });
16734
16737
  $[2] = EntityFormActionsComponent;
16735
16738
  $[3] = collection;
16736
16739
  $[4] = disabled;
@@ -16739,101 +16742,102 @@ function FormLayoutInner(t0) {
16739
16742
  $[7] = openEntityMode;
16740
16743
  $[8] = path;
16741
16744
  $[9] = savingError;
16742
- $[10] = status;
16743
- $[11] = t1;
16744
- $[12] = t2;
16745
- $[13] = t3;
16745
+ $[10] = showDefaultActions;
16746
+ $[11] = status;
16747
+ $[12] = t1;
16748
+ $[13] = t2;
16749
+ $[14] = t3;
16746
16750
  } else {
16747
- t3 = $[13];
16751
+ t3 = $[14];
16748
16752
  }
16749
16753
  const dialogActions = t3;
16750
16754
  const t4 = formContext.formex;
16751
16755
  const t5 = formContext.formex.handleSubmit;
16752
16756
  let t6;
16753
- if ($[14] !== collection || $[15] !== entity || $[16] !== formex || $[17] !== path || $[18] !== status) {
16757
+ if ($[15] !== collection || $[16] !== entity || $[17] !== formex || $[18] !== path || $[19] !== status) {
16754
16758
  t6 = () => formex.resetForm({
16755
16759
  values: getInitialEntityValues(collection, path, status, entity)
16756
16760
  });
16757
- $[14] = collection;
16758
- $[15] = entity;
16759
- $[16] = formex;
16760
- $[17] = path;
16761
- $[18] = status;
16762
- $[19] = t6;
16761
+ $[15] = collection;
16762
+ $[16] = entity;
16763
+ $[17] = formex;
16764
+ $[18] = path;
16765
+ $[19] = status;
16766
+ $[20] = t6;
16763
16767
  } else {
16764
- t6 = $[19];
16768
+ t6 = $[20];
16765
16769
  }
16766
16770
  let t7;
16767
- if ($[20] !== className) {
16771
+ if ($[21] !== className) {
16768
16772
  t7 = cls("flex-1 flex flex-row w-full overflow-y-auto justify-center", className);
16769
- $[20] = className;
16770
- $[21] = t7;
16773
+ $[21] = className;
16774
+ $[22] = t7;
16771
16775
  } else {
16772
- t7 = $[21];
16776
+ t7 = $[22];
16773
16777
  }
16774
16778
  let t8;
16775
16779
  let t9;
16776
- if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
16780
+ if ($[23] === Symbol.for("react.memo_cache_sentinel")) {
16777
16781
  t8 = cls("relative flex flex-row max-w-4xl lg:max-w-3xl xl:max-w-4xl 2xl:max-w-6xl w-full h-fit");
16778
16782
  t9 = cls("flex flex-col w-full pt-12 pb-16 px-4 sm:px-8 md:px-10");
16779
- $[22] = t8;
16780
- $[23] = t9;
16783
+ $[23] = t8;
16784
+ $[24] = t9;
16781
16785
  } else {
16782
- t8 = $[22];
16783
- t9 = $[23];
16786
+ t8 = $[23];
16787
+ t9 = $[24];
16784
16788
  }
16785
16789
  let t10;
16786
- if ($[24] !== formContext.formex.dirty) {
16790
+ if ($[25] !== formContext.formex.dirty) {
16787
16791
  t10 = formContext.formex.dirty ? /* @__PURE__ */ jsx(Tooltip, { title: "Unsaved changes", className: "self-end sticky top-4 z-10", children: /* @__PURE__ */ jsx(Chip, { size: "small", colorScheme: "orangeDarker", children: /* @__PURE__ */ jsx(EditIcon, { size: "smallest" }) }) }) : /* @__PURE__ */ jsx(Tooltip, { title: "In sync with the database", className: "self-end sticky top-4 z-10", children: /* @__PURE__ */ jsx(Chip, { size: "small", children: /* @__PURE__ */ jsx(CheckIcon, { size: "smallest" }) }) });
16788
- $[24] = formContext.formex.dirty;
16789
- $[25] = t10;
16792
+ $[25] = formContext.formex.dirty;
16793
+ $[26] = t10;
16790
16794
  } else {
16791
- t10 = $[25];
16795
+ t10 = $[26];
16792
16796
  }
16793
16797
  let t11;
16794
- if ($[26] !== children || $[27] !== t10) {
16798
+ if ($[27] !== children || $[28] !== t10) {
16795
16799
  t11 = /* @__PURE__ */ jsxs("div", { className: t9, children: [
16796
16800
  t10,
16797
16801
  children
16798
16802
  ] });
16799
- $[26] = children;
16800
- $[27] = t10;
16801
- $[28] = t11;
16803
+ $[27] = children;
16804
+ $[28] = t10;
16805
+ $[29] = t11;
16802
16806
  } else {
16803
- t11 = $[28];
16807
+ t11 = $[29];
16804
16808
  }
16805
16809
  let t12;
16806
- if ($[29] !== id || $[30] !== t11) {
16810
+ if ($[30] !== id || $[31] !== t11) {
16807
16811
  t12 = /* @__PURE__ */ jsx("div", { id, className: t8, children: t11 });
16808
- $[29] = id;
16809
- $[30] = t11;
16810
- $[31] = t12;
16812
+ $[30] = id;
16813
+ $[31] = t11;
16814
+ $[32] = t12;
16811
16815
  } else {
16812
- t12 = $[31];
16816
+ t12 = $[32];
16813
16817
  }
16814
16818
  let t13;
16815
- if ($[32] !== dialogActions || $[33] !== formContext.formex.handleSubmit || $[34] !== t12 || $[35] !== t6 || $[36] !== t7) {
16819
+ if ($[33] !== dialogActions || $[34] !== formContext.formex.handleSubmit || $[35] !== t12 || $[36] !== t6 || $[37] !== t7) {
16816
16820
  t13 = /* @__PURE__ */ jsxs("form", { onSubmit: t5, onReset: t6, noValidate: true, className: t7, children: [
16817
16821
  t12,
16818
16822
  dialogActions
16819
16823
  ] });
16820
- $[32] = dialogActions;
16821
- $[33] = formContext.formex.handleSubmit;
16822
- $[34] = t12;
16823
- $[35] = t6;
16824
- $[36] = t7;
16825
- $[37] = t13;
16824
+ $[33] = dialogActions;
16825
+ $[34] = formContext.formex.handleSubmit;
16826
+ $[35] = t12;
16827
+ $[36] = t6;
16828
+ $[37] = t7;
16829
+ $[38] = t13;
16826
16830
  } else {
16827
- t13 = $[37];
16831
+ t13 = $[38];
16828
16832
  }
16829
16833
  let t14;
16830
- if ($[38] !== formContext.formex || $[39] !== t13) {
16834
+ if ($[39] !== formContext.formex || $[40] !== t13) {
16831
16835
  t14 = /* @__PURE__ */ jsx(Formex, { value: t4, children: t13 });
16832
- $[38] = formContext.formex;
16833
- $[39] = t13;
16834
- $[40] = t14;
16836
+ $[39] = formContext.formex;
16837
+ $[40] = t13;
16838
+ $[41] = t14;
16835
16839
  } else {
16836
- t14 = $[40];
16840
+ t14 = $[41];
16837
16841
  }
16838
16842
  return t14;
16839
16843
  }
@@ -21491,7 +21495,8 @@ function EntityEditViewFormActions({
21491
21495
  disabled,
21492
21496
  status,
21493
21497
  pluginActions,
21494
- openEntityMode
21498
+ openEntityMode,
21499
+ showDefaultActions = true
21495
21500
  }) {
21496
21501
  const authController = useAuthController();
21497
21502
  const context = useFireCMSContext();
@@ -21507,7 +21512,7 @@ function EntityEditViewFormActions({
21507
21512
  if (customEntityActions) return mergeEntityActions(actions, customEntityActions);
21508
21513
  return actions;
21509
21514
  }, [authController, collection, path]);
21510
- const formActions = entityActions.filter((a) => a.includeInForm === void 0 || a.includeInForm);
21515
+ const formActions = showDefaultActions ? entityActions.filter((a) => a.includeInForm === void 0 || a.includeInForm) : [];
21511
21516
  return layout === "bottom" ? buildBottomActions({
21512
21517
  savingError,
21513
21518
  entity,
@@ -21791,7 +21796,8 @@ function EntityEditViewInner({
21791
21796
  layout = "side_panel",
21792
21797
  barActions,
21793
21798
  status,
21794
- setStatus
21799
+ setStatus,
21800
+ formProps
21795
21801
  }) {
21796
21802
  const context = useFireCMSContext();
21797
21803
  const [usedEntity, setUsedEntity] = useState(entity);
@@ -21860,10 +21866,23 @@ function EntityEditViewInner({
21860
21866
  });
21861
21867
  }
21862
21868
  };
21863
- const entityView = /* @__PURE__ */ jsx(EntityForm, { collection, path, entityId: entityId ?? usedEntity?.id, onValuesModified, onSaved: onSaved ? (params) => onSaved({
21864
- ...params,
21865
- selectedTab: MAIN_TAB_VALUE === selectedTab ? void 0 : selectedTab
21866
- }) : void 0, entity, cachedDirtyValues, openEntityMode: layout, onFormContextReady: setFormContext, forceActionsAtTheBottom: actionsAtTheBottom, initialStatus: status, onStatusChange: setStatus, className: !mainViewVisible ? "hidden" : "", EntityFormActionsComponent: EntityEditViewFormActions, onEntityChange: setUsedEntity });
21869
+ const entityView = /* @__PURE__ */ jsx(EntityForm, { collection, path, entityId: entityId ?? usedEntity?.id, onValuesModified, entity, initialDirtyValues: cachedDirtyValues, openEntityMode: layout, forceActionsAtTheBottom: actionsAtTheBottom, initialStatus: status, className: cls(!mainViewVisible ? "hidden" : "", formProps?.className), EntityFormActionsComponent: EntityEditViewFormActions, ...formProps, onEntityChange: (entity_0) => {
21870
+ setUsedEntity(entity_0);
21871
+ formProps?.onEntityChange?.(entity_0);
21872
+ }, onStatusChange: (status_0) => {
21873
+ setStatus(status_0);
21874
+ formProps?.onStatusChange?.(status_0);
21875
+ }, onFormContextReady: (formContext_0) => {
21876
+ setFormContext(formContext_0);
21877
+ formProps?.onFormContextReady?.(formContext_0);
21878
+ }, onSaved: (params) => {
21879
+ const res = {
21880
+ ...params,
21881
+ selectedTab: MAIN_TAB_VALUE === selectedTab ? void 0 : selectedTab
21882
+ };
21883
+ onSaved?.(res);
21884
+ formProps?.onSaved?.(res);
21885
+ } });
21867
21886
  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}`));
21868
21887
  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}`));
21869
21888
  const shouldShowTopBar = Boolean(barActions) || hasAdditionalViews;
@@ -21907,7 +21926,6 @@ function EntitySidePanel(props) {
21907
21926
  const sideEntityController = useSideEntityController();
21908
21927
  const navigationController = useNavigationController();
21909
21928
  const sideDialogsController = useSideDialogContext();
21910
- console.log("sideDialogsController", sideDialogsController);
21911
21929
  const onClose = () => {
21912
21930
  if (props.onClose) {
21913
21931
  props.onClose();
@@ -21989,7 +22007,7 @@ function EntitySidePanel(props) {
21989
22007
  updateUrl: true,
21990
22008
  collection: collection_0
21991
22009
  });
21992
- } }) }) });
22010
+ }, formProps: props.formProps }) }) });
21993
22011
  }
21994
22012
  const NEW_URL_HASH = "new_side";
21995
22013
  const SIDE_URL_HASH = "side";
@@ -22287,7 +22305,8 @@ const propsToSidePanel = (props, buildUrlCollectionPath, resolveIdsFrom, smallLa
22287
22305
  const resolvedPath = resolveIdsFrom(props.path);
22288
22306
  const resolvedPanelProps = {
22289
22307
  ...props,
22290
- path: resolvedPath
22308
+ path: resolvedPath,
22309
+ formProps: props.formProps
22291
22310
  };
22292
22311
  const entityViewWidth = getEntityViewWidth(props, smallLayout);
22293
22312
  return {