@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@firecms/core",
3
3
  "type": "module",
4
- "version": "3.0.0-canary.203",
4
+ "version": "3.0.0-canary.204",
5
5
  "description": "Awesome Firebase/Firestore-based headless open-source CMS",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/firecmsco"
@@ -50,9 +50,9 @@
50
50
  "./package.json": "./package.json"
51
51
  },
52
52
  "dependencies": {
53
- "@firecms/editor": "^3.0.0-canary.203",
54
- "@firecms/formex": "^3.0.0-canary.203",
55
- "@firecms/ui": "^3.0.0-canary.203",
53
+ "@firecms/editor": "^3.0.0-canary.204",
54
+ "@firecms/formex": "^3.0.0-canary.204",
55
+ "@firecms/ui": "^3.0.0-canary.204",
56
56
  "@hello-pangea/dnd": "^17.0.0",
57
57
  "@radix-ui/react-portal": "^1.1.3",
58
58
  "clsx": "^2.1.1",
@@ -104,7 +104,7 @@
104
104
  "dist",
105
105
  "src"
106
106
  ],
107
- "gitHead": "bad3e5f8069d21897795c6d5c42f843e9967b66d",
107
+ "gitHead": "2fb107e78d8fc3ade463adaf00908e3a8c812a0f",
108
108
  "publishConfig": {
109
109
  "access": "public"
110
110
  },
@@ -214,8 +214,6 @@ export function EntityEditViewInner<M extends Record<string, any>>({
214
214
  }
215
215
  }, [selectedTabProp]);
216
216
 
217
- const mainViewVisible = selectedTab === MAIN_TAB_VALUE;
218
-
219
217
  const subcollections = (collection.subcollections ?? []).filter(c => !c.hideFromNavigation);
220
218
  const subcollectionsCount = subcollections?.length ?? 0;
221
219
  const customViews = collection.entityViews;
@@ -228,28 +226,13 @@ export function EntityEditViewInner<M extends Record<string, any>>({
228
226
  : [];
229
227
 
230
228
  const selectedEntityView = resolvedEntityViews.find(e => e.key === selectedTab);
231
- const actionsAtTheBottom = !largeLayout || layout === "side_panel" || selectedEntityView?.includeActions === "bottom";
232
-
233
- const secondaryForms: React.ReactNode[] | undefined = formContext && customViews && resolvedEntityViews
234
- .filter(e => e.includeActions)
235
- .map((customView) => {
236
- if (!customView || !formContext)
237
- return null;
229
+ const selectedSecondaryForm = formContext
230
+ && customViews
231
+ && resolvedEntityViews.filter(e => e.includeActions).find(e => e.key === selectedTab);
238
232
 
239
- if (!customView.Builder) {
240
- console.error("customView.Builder is not defined");
241
- return null;
242
- }
243
-
244
- return <SecondaryForm key={`custom_view_${customView.key}`}
245
- className={selectedTab !== customView.key ? "hidden" : ""}
246
- customView={customView}
247
- formContext={formContext}
248
- collection={collection}
249
- forceActionsAtTheBottom={!largeLayout || layout === "side_panel" || customView.includeActions === "bottom"}
250
- entity={usedEntity}/>;
233
+ const actionsAtTheBottom = !largeLayout || layout === "side_panel" || selectedEntityView?.includeActions === "bottom";
251
234
 
252
- }).filter(Boolean);
235
+ const mainViewVisible = selectedTab === MAIN_TAB_VALUE || Boolean(selectedSecondaryForm);
253
236
 
254
237
  const customViewsView: React.ReactNode[] | undefined = customViews && resolvedEntityViews
255
238
  .filter(e => !e.includeActions)
@@ -361,6 +344,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
361
344
  onSaved?.(res);
362
345
  formProps?.onSaved?.(res);
363
346
  }}
347
+ Builder={selectedSecondaryForm?.Builder}
364
348
  />;
365
349
 
366
350
  const subcollectionTabs = subcollections && subcollections.map((subcollection) =>
@@ -421,7 +405,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
421
405
  </div>
422
406
  : entityView}
423
407
 
424
- {secondaryForms}
408
+ {/*{secondaryForms}*/}
425
409
 
426
410
  {customViewsView}
427
411
 
@@ -3,6 +3,7 @@ import {
3
3
  CMSAnalyticsEvent,
4
4
  Entity,
5
5
  EntityCollection,
6
+ EntityCustomViewParams,
6
7
  EntityStatus,
7
8
  EntityValues,
8
9
  FormContext,
@@ -82,6 +83,8 @@ export type EntityFormProps<M extends Record<string, any>> = {
82
83
 
83
84
  EntityFormActionsComponent?: React.FC<EntityFormActionsProps>;
84
85
 
86
+ Builder?: React.ComponentType<EntityCustomViewParams<M>>;
87
+
85
88
  children?: React.ReactNode;
86
89
  };
87
90
 
@@ -102,6 +105,7 @@ export function EntityForm<M extends Record<string, any>>({
102
105
  onEntityChange,
103
106
  openEntityMode = "full_screen",
104
107
  formex: formexProp,
108
+ Builder,
105
109
  EntityFormActionsComponent = EntityFormActions,
106
110
  showDefaultActions = true,
107
111
  showEntityPath = true,
@@ -498,77 +502,88 @@ export function EntityForm<M extends Record<string, any>>({
498
502
 
499
503
  const formFieldKeys = getFormFieldKeys(resolvedCollection);
500
504
 
501
- const formFields = () => (
502
- <FormLayout>
503
- {formFieldKeys.map((key) => {
504
- const property = resolvedCollection.properties[key];
505
- if (property) {
506
- const underlyingValueHasChanged: boolean =
507
- !!underlyingChanges &&
508
- Object.keys(underlyingChanges).includes(key) &&
509
- formex.touched[key];
510
- const disabled = (!autoSave && formex.isSubmitting) || isReadOnly(property) || Boolean(property.disabled);
511
- const hidden = isHidden(property);
512
- if (hidden) return null;
513
- const widthPercentage = property.widthPercentage ?? 100;
514
- const cmsFormFieldProps: PropertyFieldBindingProps<any, M> = {
515
- propertyKey: key,
516
- disabled,
517
- property,
518
- includeDescription: property.description || property.longDescription,
519
- underlyingValueHasChanged: underlyingValueHasChanged && !autoSave,
520
- context: formContext,
521
- partOfArray: false,
522
- minimalistView: false,
523
- autoFocus: false
524
- };
525
-
526
- return (
527
- <FormEntry propertyKey={key}
528
- widthPercentage={widthPercentage}
529
- key={`field_${key}`}>
530
- <PropertyFieldBinding {...cmsFormFieldProps} />
531
- </FormEntry>
532
- );
533
- }
505
+ const formFields = () => {
534
506
 
535
- const additionalField = resolvedCollection.additionalFields?.find(f => f.key === key);
536
- if (additionalField && entity) {
537
- const Builder = additionalField.Builder;
538
- if (!Builder && !additionalField.value) {
539
- throw new Error("When using additional fields you need to provide a Builder or a value");
507
+ if (Builder) {
508
+ return <Builder
509
+ collection={collection}
510
+ entity={entity}
511
+ modifiedValues={formex.values}
512
+ formContext={formContext}
513
+ />;
514
+ }
515
+ return (
516
+ <FormLayout>
517
+ {formFieldKeys.map((key) => {
518
+ const property = resolvedCollection.properties[key];
519
+ if (property) {
520
+ const underlyingValueHasChanged: boolean =
521
+ !!underlyingChanges &&
522
+ Object.keys(underlyingChanges).includes(key) &&
523
+ formex.touched[key];
524
+ const disabled = (!autoSave && formex.isSubmitting) || isReadOnly(property) || Boolean(property.disabled);
525
+ const hidden = isHidden(property);
526
+ if (hidden) return null;
527
+ const widthPercentage = property.widthPercentage ?? 100;
528
+ const cmsFormFieldProps: PropertyFieldBindingProps<any, M> = {
529
+ propertyKey: key,
530
+ disabled,
531
+ property,
532
+ includeDescription: property.description || property.longDescription,
533
+ underlyingValueHasChanged: underlyingValueHasChanged && !autoSave,
534
+ context: formContext,
535
+ partOfArray: false,
536
+ minimalistView: false,
537
+ autoFocus: false
538
+ };
539
+
540
+ return (
541
+ <FormEntry propertyKey={key}
542
+ widthPercentage={widthPercentage}
543
+ key={`field_${key}`}>
544
+ <PropertyFieldBinding {...cmsFormFieldProps} />
545
+ </FormEntry>
546
+ );
540
547
  }
541
- const child = Builder
542
- ? <Builder entity={entity} context={context}/>
543
- : <div className={"w-full"}>
544
- {additionalField.value?.({
545
- entity,
546
- context
547
- })?.toString()}
548
- </div>;
549
-
550
- return (
551
- <div key={`additional_${key}`} className={"w-full"}>
552
- <LabelWithIconAndTooltip
553
- propertyKey={key}
554
- icon={<NotesIcon size={"small"}/>}
555
- title={additionalField.name}
556
- className={"text-text-secondary dark:text-text-secondary-dark ml-3.5"}/>
557
- <div
558
- className={cls(paperMixin, "w-full min-h-14 p-4 md:p-6 overflow-x-scroll no-scrollbar")}>
559
- <ErrorBoundary>
560
- {child}
561
- </ErrorBoundary>
548
+
549
+ const additionalField = resolvedCollection.additionalFields?.find(f => f.key === key);
550
+ if (additionalField && entity) {
551
+ const Builder = additionalField.Builder;
552
+ if (!Builder && !additionalField.value) {
553
+ throw new Error("When using additional fields you need to provide a Builder or a value");
554
+ }
555
+ const child = Builder
556
+ ? <Builder entity={entity} context={context}/>
557
+ : <div className={"w-full"}>
558
+ {additionalField.value?.({
559
+ entity,
560
+ context
561
+ })?.toString()}
562
+ </div>;
563
+
564
+ return (
565
+ <div key={`additional_${key}`} className={"w-full"}>
566
+ <LabelWithIconAndTooltip
567
+ propertyKey={key}
568
+ icon={<NotesIcon size={"small"}/>}
569
+ title={additionalField.name}
570
+ className={"text-text-secondary dark:text-text-secondary-dark ml-3.5"}/>
571
+ <div
572
+ className={cls(paperMixin, "w-full min-h-14 p-4 md:p-6 overflow-x-scroll no-scrollbar")}>
573
+ <ErrorBoundary>
574
+ {child}
575
+ </ErrorBoundary>
576
+ </div>
562
577
  </div>
563
- </div>
564
- );
565
- }
578
+ );
579
+ }
566
580
 
567
- console.warn(`Property ${key} not found in collection ${resolvedCollection.name} in properties or additional fields. Skipping.`);
568
- return null;
569
- }).filter(Boolean)}
570
- </FormLayout>
571
- );
581
+ console.warn(`Property ${key} not found in collection ${resolvedCollection.name} in properties or additional fields. Skipping.`);
582
+ return null;
583
+ }).filter(Boolean)}
584
+ </FormLayout>
585
+ );
586
+ };
572
587
 
573
588
  const formRef = useRef<HTMLDivElement>(null);
574
589