@firecms/core 3.0.0-beta.12 → 3.0.0-beta.13

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.
Files changed (84) hide show
  1. package/dist/app/Scaffold.d.ts +4 -0
  2. package/dist/components/ArrayContainer.d.ts +12 -5
  3. package/dist/components/EntityCollectionView/EntityCollectionView.d.ts +4 -0
  4. package/dist/components/EntityJsonPreview.d.ts +3 -0
  5. package/dist/core/DefaultAppBar.d.ts +8 -2
  6. package/dist/core/EntityEditView.d.ts +8 -1
  7. package/dist/core/FireCMS.d.ts +2 -2
  8. package/dist/form/EntityForm.d.ts +5 -1
  9. package/dist/form/PropertyFieldBinding.d.ts +1 -1
  10. package/dist/hooks/data/save.d.ts +1 -1
  11. package/dist/index.es.js +8630 -8578
  12. package/dist/index.es.js.map +1 -1
  13. package/dist/index.umd.js +8663 -8612
  14. package/dist/index.umd.js.map +1 -1
  15. package/dist/internal/useBuildDataSource.d.ts +3 -2
  16. package/dist/internal/useBuildSideEntityController.d.ts +3 -3
  17. package/dist/types/collections.d.ts +6 -0
  18. package/dist/types/fields.d.ts +4 -1
  19. package/dist/types/firecms.d.ts +1 -1
  20. package/dist/types/navigation.d.ts +4 -0
  21. package/dist/types/plugins.d.ts +1 -0
  22. package/dist/types/properties.d.ts +22 -1
  23. package/dist/util/createFormexStub.d.ts +2 -0
  24. package/dist/util/navigation_utils.d.ts +2 -1
  25. package/dist/util/objects.d.ts +1 -1
  26. package/dist/util/property_utils.d.ts +2 -2
  27. package/dist/util/references.d.ts +2 -2
  28. package/dist/util/resolutions.d.ts +11 -6
  29. package/package.json +6 -5
  30. package/src/app/Scaffold.tsx +13 -3
  31. package/src/components/ArrayContainer.tsx +40 -23
  32. package/src/components/DeleteEntityDialog.tsx +4 -2
  33. package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +8 -6
  34. package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +5 -2
  35. package/src/components/EntityCollectionView/EntityCollectionView.tsx +22 -6
  36. package/src/components/EntityJsonPreview.tsx +66 -0
  37. package/src/components/EntityPreview.tsx +10 -3
  38. package/src/components/EntityView.tsx +4 -1
  39. package/src/components/ReferenceTable/ReferenceSelectionTable.tsx +3 -1
  40. package/src/components/VirtualTable/VirtualTable.tsx +29 -1
  41. package/src/components/common/default_entity_actions.tsx +15 -4
  42. package/src/core/DefaultAppBar.tsx +17 -5
  43. package/src/core/EntityEditView.tsx +111 -35
  44. package/src/core/FireCMS.tsx +13 -12
  45. package/src/form/EntityForm.tsx +31 -23
  46. package/src/form/PropertyFieldBinding.tsx +8 -5
  47. package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +4 -1
  48. package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +1 -0
  49. package/src/form/field_bindings/BlockFieldBinding.tsx +1 -1
  50. package/src/form/field_bindings/KeyValueFieldBinding.tsx +1 -1
  51. package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +6 -2
  52. package/src/form/field_bindings/MultiSelectFieldBinding.tsx +2 -2
  53. package/src/form/field_bindings/RepeatFieldBinding.tsx +8 -2
  54. package/src/form/field_bindings/SelectFieldBinding.tsx +1 -1
  55. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +5 -2
  56. package/src/hooks/data/save.ts +24 -29
  57. package/src/hooks/useBuildNavigationController.tsx +12 -1
  58. package/src/hooks/useFireCMSContext.tsx +0 -30
  59. package/src/internal/useBuildDataSource.ts +9 -5
  60. package/src/internal/useBuildSideEntityController.tsx +26 -20
  61. package/src/preview/PropertyPreview.tsx +4 -2
  62. package/src/preview/property_previews/ArrayOfMapsPreview.tsx +4 -3
  63. package/src/preview/property_previews/ArrayOfReferencesPreview.tsx +4 -3
  64. package/src/preview/property_previews/ArrayOfStorageComponentsPreview.tsx +4 -2
  65. package/src/preview/property_previews/ArrayOfStringsPreview.tsx +4 -3
  66. package/src/preview/property_previews/ArrayOneOfPreview.tsx +4 -2
  67. package/src/preview/property_previews/ArrayPropertyPreview.tsx +4 -2
  68. package/src/routes/FireCMSRoute.tsx +15 -4
  69. package/src/types/collections.ts +7 -0
  70. package/src/types/fields.tsx +5 -1
  71. package/src/types/firecms.tsx +1 -1
  72. package/src/types/navigation.ts +5 -0
  73. package/src/types/plugins.tsx +1 -0
  74. package/src/types/properties.ts +27 -1
  75. package/src/types/side_entity_controller.tsx +5 -0
  76. package/src/util/createFormexStub.tsx +62 -0
  77. package/src/util/join_collections.ts +3 -1
  78. package/src/util/navigation_from_path.ts +5 -1
  79. package/src/util/navigation_utils.ts +64 -15
  80. package/src/util/objects.ts +5 -1
  81. package/src/util/property_utils.tsx +7 -3
  82. package/src/util/references.ts +8 -6
  83. package/src/util/resolutions.ts +17 -9
  84. package/src/util/useStorageUploadController.tsx +21 -2
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  ArrayProperty,
3
+ AuthController,
3
4
  CMSType,
4
5
  CustomizationController,
5
6
  EntityCollection,
@@ -27,9 +28,7 @@ import { getDefaultValuesFor, isPropertyBuilder } from "./entities";
27
28
  import { DEFAULT_ONE_OF_TYPE } from "./common";
28
29
  import { getIn } from "@firecms/formex";
29
30
  import { enumToObjectEntries } from "./enums";
30
- import { isDefaultFieldConfigId } from "../core/field_configs";
31
-
32
- // import util from "util";
31
+ import { isDefaultFieldConfigId } from "../core";
33
32
 
34
33
  export const resolveCollection = <M extends Record<string, any>, >
35
34
  ({
@@ -40,7 +39,8 @@ export const resolveCollection = <M extends Record<string, any>, >
40
39
  previousValues,
41
40
  userConfigPersistence,
42
41
  propertyConfigs,
43
- ignoreMissingFields = false
42
+ ignoreMissingFields = false,
43
+ authController
44
44
  }: {
45
45
  collection: EntityCollection<M> | ResolvedEntityCollection<M>;
46
46
  path: string,
@@ -50,6 +50,7 @@ export const resolveCollection = <M extends Record<string, any>, >
50
50
  userConfigPersistence?: UserConfigurationPersistence;
51
51
  propertyConfigs?: Record<string, PropertyConfig>;
52
52
  ignoreMissingFields?: boolean;
53
+ authController: AuthController;
53
54
  }): ResolvedEntityCollection<M> => {
54
55
 
55
56
  const collectionOverride = userConfigPersistence?.getCollectionConfig<M>(path);
@@ -69,7 +70,8 @@ export const resolveCollection = <M extends Record<string, any>, >
69
70
  path,
70
71
  entityId,
71
72
  propertyConfigs: propertyConfigs,
72
- ignoreMissingFields
73
+ ignoreMissingFields,
74
+ authController
73
75
  });
74
76
  if (!childResolvedProperty) return {};
75
77
  return ({
@@ -114,6 +116,7 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
114
116
  fromBuilder?: boolean;
115
117
  propertyConfigs?: Record<string, PropertyConfig<any>>;
116
118
  ignoreMissingFields?: boolean;
119
+ authController: AuthController;
117
120
  }): ResolvedProperty<T> | null {
118
121
 
119
122
  if (typeof propertyOrBuilder === "object" && "resolved" in propertyOrBuilder) {
@@ -234,7 +237,8 @@ export function getArrayResolvedProperties<M>({
234
237
  entityId?: string;
235
238
  index?: number;
236
239
  fromBuilder?: boolean;
237
- propertyConfigs?: Record<string, PropertyConfig>
240
+ propertyConfigs?: Record<string, PropertyConfig>;
241
+ authController: AuthController;
238
242
  }) {
239
243
 
240
244
  const of = property.of;
@@ -266,6 +270,7 @@ export function resolveArrayProperty<T extends any[], M>({
266
270
  fromBuilder?: boolean;
267
271
  propertyConfigs?: Record<string, PropertyConfig>;
268
272
  ignoreMissingFields?: boolean;
273
+ authController: AuthController;
269
274
  }): ResolvedArrayProperty {
270
275
  const propertyValue = propertyKey ? getIn(props.values, propertyKey) : undefined;
271
276
 
@@ -281,7 +286,7 @@ export function resolveArrayProperty<T extends any[], M>({
281
286
  propertyOrBuilder: p as Property<any>,
282
287
  ignoreMissingFields,
283
288
  ...props,
284
- index
289
+ index,
285
290
  });
286
291
  })
287
292
  } as ResolvedArrayProperty;
@@ -373,6 +378,7 @@ export function resolveProperties<M extends Record<string, any>>({
373
378
  fromBuilder?: boolean;
374
379
  propertyConfigs?: Record<string, PropertyConfig>;
375
380
  ignoreMissingFields?: boolean;
381
+ authController: AuthController;
376
382
  }): ResolvedProperties<M> {
377
383
  return Object.entries<PropertyOrBuilder>(properties as Record<string, PropertyOrBuilder>)
378
384
  .map(([key, property]) => {
@@ -435,11 +441,13 @@ export function resolveEntityView(entityView: string | EntityCustomView<any>, co
435
441
  export function resolvedSelectedEntityView<M extends Record<string, any>>(
436
442
  customViews: (string | EntityCustomView<M>)[] | undefined,
437
443
  customizationController: CustomizationController,
438
- selectedTab?: string
444
+ selectedTab?: string,
445
+ canEdit?: boolean,
439
446
  ) {
440
447
  const resolvedEntityViews = customViews ? customViews
441
448
  .map(e => resolveEntityView(e, customizationController.entityViews))
442
- .filter(Boolean) as EntityCustomView[]
449
+ .filter((e): e is EntityCustomView<M> => Boolean(e))
450
+ // .filter((e) => canEdit || !e.includeActions)
443
451
  : [];
444
452
 
445
453
  const selectedEntityView = resolvedEntityViews.find(e => e.key === selectedTab);
@@ -18,6 +18,7 @@ import { PreviewSize } from "../preview";
18
18
  import { randomString } from "./strings";
19
19
  import { resolveStorageFilenameString, resolveStoragePathString } from "./storage";
20
20
  import { resolveProperty } from "./resolutions";
21
+ import { useAuthController } from "../hooks";
21
22
 
22
23
  /**
23
24
  * Internal representation of an item in the storage
@@ -34,7 +35,6 @@ export interface StorageFieldItem {
34
35
  size: PreviewSize
35
36
  }
36
37
 
37
-
38
38
  export function useStorageUploadController<M extends object>({
39
39
  entityId,
40
40
  entityValues,
@@ -58,6 +58,7 @@ export function useStorageUploadController<M extends object>({
58
58
  onChange: (value: string | string[] | null) => void
59
59
  }) {
60
60
 
61
+ const authController = useAuthController();
61
62
  const storage: StorageConfig | undefined = property.dataType === "string"
62
63
  ? property.storage
63
64
  : property.dataType === "array" &&
@@ -70,6 +71,8 @@ export function useStorageUploadController<M extends object>({
70
71
  if (!storage)
71
72
  throw Error("Storage meta must be specified");
72
73
 
74
+ const processFile = storage?.processFile;
75
+
73
76
  const metadata: Record<string, any> | undefined = storage?.metadata;
74
77
  const size = multipleFilesSupported ? "medium" : "large";
75
78
 
@@ -90,7 +93,8 @@ export function useStorageUploadController<M extends object>({
90
93
 
91
94
  const resolvedProperty = resolveProperty({
92
95
  propertyOrBuilder: property as PropertyOrBuilder,
93
- values: entityValues
96
+ values: entityValues,
97
+ authController
94
98
  }) as ResolvedStringProperty | ResolvedArrayProperty<string[]>;
95
99
 
96
100
  const fileNameBuilder = useCallback(async (file: File) => {
@@ -170,7 +174,22 @@ export function useStorageUploadController<M extends object>({
170
174
  if (!acceptedFiles.length || disabled)
171
175
  return;
172
176
 
177
+ if (processFile) {
178
+ try {
179
+ acceptedFiles = await Promise.all(acceptedFiles.map(async file => {
180
+ const processedFile = await processFile(file);
181
+ if (!processedFile) {
182
+ return file;
183
+ }
184
+ return processedFile;
185
+ }));
186
+ } catch (e) {
187
+ console.error("Error processing file with custom code. Attempting to continue uploading.", e);
188
+ }
189
+ }
190
+
173
191
  let newInternalValue: StorageFieldItem[];
192
+
174
193
  if (multipleFilesSupported) {
175
194
  newInternalValue = [...internalValue,
176
195
  ...(await Promise.all(acceptedFiles.map(async file => {