@firecms/core 3.0.0-canary.66 → 3.0.0-canary.67

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 (40) hide show
  1. package/dist/core/EntityEditView.d.ts +17 -3
  2. package/dist/form/PropertiesForm.d.ts +8 -0
  3. package/dist/form/components/FieldHelperText.d.ts +3 -3
  4. package/dist/form/components/StorageItemPreview.d.ts +2 -4
  5. package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
  6. package/dist/form/field_bindings/StorageUploadFieldBinding.d.ts +2 -4
  7. package/dist/form/index.d.ts +0 -2
  8. package/dist/index.es.js +4269 -4322
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/index.umd.js +5 -5
  11. package/dist/index.umd.js.map +1 -1
  12. package/dist/types/collections.d.ts +14 -0
  13. package/dist/types/fields.d.ts +31 -30
  14. package/dist/types/plugins.d.ts +2 -2
  15. package/dist/types/properties.d.ts +1 -1
  16. package/dist/util/storage.d.ts +23 -2
  17. package/dist/util/useStorageUploadController.d.ts +1 -1
  18. package/package.json +4 -4
  19. package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +2 -1
  20. package/src/core/EntityEditView.tsx +662 -120
  21. package/src/core/EntitySidePanel.tsx +0 -1
  22. package/src/form/PropertiesForm.tsx +81 -0
  23. package/src/form/PropertyFieldBinding.tsx +28 -5
  24. package/src/form/components/FieldHelperText.tsx +3 -3
  25. package/src/form/components/StorageItemPreview.tsx +0 -4
  26. package/src/form/field_bindings/MapFieldBinding.tsx +10 -3
  27. package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +0 -7
  28. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +3 -26
  29. package/src/form/index.tsx +4 -4
  30. package/src/form/validation.ts +1 -17
  31. package/src/types/collections.ts +14 -0
  32. package/src/types/customization_controller.tsx +0 -1
  33. package/src/types/fields.tsx +33 -33
  34. package/src/types/plugins.tsx +2 -2
  35. package/src/types/properties.ts +1 -1
  36. package/src/util/permissions.ts +1 -0
  37. package/src/util/storage.ts +75 -21
  38. package/src/util/useStorageUploadController.tsx +21 -3
  39. package/dist/form/EntityForm.d.ts +0 -77
  40. package/src/form/EntityForm.tsx +0 -735
@@ -7,15 +7,28 @@ import {
7
7
  } from "../types";
8
8
  import { randomString } from "./strings";
9
9
 
10
+ interface ResolveFilenameStringParams<M extends object> {
11
+ input: string | ((context: UploadedFileContext) => (Promise<string> | string));
12
+ storage: StorageConfig;
13
+ values: EntityValues<M>;
14
+ entityId: string;
15
+ path?: string;
16
+ property: ResolvedStringProperty | ResolvedArrayProperty<string[]>;
17
+ file: File;
18
+ propertyKey: string;
19
+ }
20
+
10
21
  export async function resolveFilenameString<M extends object>(
11
- input: string | ((context: UploadedFileContext) => Promise<string> | string),
12
- storage: StorageConfig,
13
- values: EntityValues<M>,
14
- entityId: string,
15
- path: string,
16
- property: ResolvedStringProperty | ResolvedArrayProperty<string[]>,
17
- file: File,
18
- propertyKey: string): Promise<string> {
22
+ {
23
+ input,
24
+ storage,
25
+ values,
26
+ entityId,
27
+ path,
28
+ property,
29
+ file,
30
+ propertyKey
31
+ }: ResolveFilenameStringParams<M>): Promise<string> {
19
32
  let result;
20
33
  if (typeof input === "function") {
21
34
  result = await input({
@@ -30,7 +43,13 @@ export async function resolveFilenameString<M extends object>(
30
43
  if (!result)
31
44
  console.warn("Storage callback returned empty result. Using default name value")
32
45
  } else {
33
- result = replacePlaceholders(file, input, entityId, propertyKey, path);
46
+ result = replacePlaceholders({
47
+ file,
48
+ input,
49
+ entityId,
50
+ propertyKey,
51
+ path
52
+ });
34
53
  }
35
54
 
36
55
  if (!result)
@@ -39,15 +58,28 @@ export async function resolveFilenameString<M extends object>(
39
58
  return result;
40
59
  }
41
60
 
61
+ interface ResolveStoragePathStringParams<M extends object> {
62
+ input: string | ((context: UploadedFileContext) => string);
63
+ storage: StorageConfig;
64
+ values: EntityValues<M>;
65
+ entityId: string;
66
+ path?: string;
67
+ property: ResolvedStringProperty | ResolvedArrayProperty<string[]>;
68
+ file: File;
69
+ propertyKey: string;
70
+ }
71
+
42
72
  export function resolveStoragePathString<M extends object>(
43
- input: string | ((context: UploadedFileContext) => string),
44
- storage: StorageConfig,
45
- values: EntityValues<M>,
46
- entityId: string,
47
- path: string,
48
- property: ResolvedStringProperty | ResolvedArrayProperty<string[]>,
49
- file: File,
50
- propertyKey: string): string {
73
+ {
74
+ input,
75
+ storage,
76
+ values,
77
+ entityId,
78
+ path,
79
+ property,
80
+ file,
81
+ propertyKey
82
+ }: ResolveStoragePathStringParams<M>): string {
51
83
  let result;
52
84
  if (typeof input === "function") {
53
85
  result = input({
@@ -62,7 +94,13 @@ export function resolveStoragePathString<M extends object>(
62
94
  if (!result)
63
95
  console.warn("Storage callback returned empty result. Using default name value")
64
96
  } else {
65
- result = replacePlaceholders(file, input, entityId, propertyKey, path);
97
+ result = replacePlaceholders({
98
+ file,
99
+ input,
100
+ entityId,
101
+ propertyKey,
102
+ path
103
+ });
66
104
  }
67
105
 
68
106
  if (!result)
@@ -71,14 +109,30 @@ export function resolveStoragePathString<M extends object>(
71
109
  return result;
72
110
  }
73
111
 
74
- function replacePlaceholders(file: File, input: string, entityId: string, propertyKey: string, path: string) {
112
+ interface Placeholders {
113
+ file: File;
114
+ input: string;
115
+ entityId: string;
116
+ propertyKey: string;
117
+ path?: string;
118
+ }
119
+
120
+ function replacePlaceholders({
121
+ file,
122
+ input,
123
+ entityId,
124
+ propertyKey,
125
+ path
126
+ }: Placeholders) {
75
127
  const ext = file.name.split(".").pop();
76
128
  let result = input.replace("{entityId}", entityId)
77
129
  .replace("{propertyKey}", propertyKey)
78
130
  .replace("{rand}", randomString())
79
131
  .replace("{file}", file.name)
80
- .replace("{file.type}", file.type)
81
- .replace("{path}", path);
132
+ .replace("{file.type}", file.type);
133
+ if (path) {
134
+ result = result.replace("{path}", path);
135
+ }
82
136
  if (ext) {
83
137
  result = result.replace("{file.ext}", ext);
84
138
  const name = file.name.replace(`.${ext}`, "");
@@ -46,7 +46,7 @@ export function useStorageUploadController<M extends object>({
46
46
  entityId: string,
47
47
  entityValues: EntityValues<M>,
48
48
  value: string | string[] | null;
49
- path: string,
49
+ path?: string,
50
50
  propertyKey: string,
51
51
  property: ResolvedStringProperty | ResolvedArrayProperty<string[]>,
52
52
  storageSource: StorageSource,
@@ -95,7 +95,16 @@ export function useStorageUploadController<M extends object>({
95
95
 
96
96
  const fileNameBuilder = useCallback(async (file: File) => {
97
97
  if (storage.fileName) {
98
- const fileName = await resolveFilenameString(storage.fileName, storage, entityValues, entityId, path, property, file, propertyKey);
98
+ const fileName = await resolveFilenameString({
99
+ input: storage.fileName,
100
+ storage,
101
+ values: entityValues,
102
+ entityId,
103
+ path,
104
+ property,
105
+ file,
106
+ propertyKey
107
+ });
99
108
  if (!fileName || fileName.length === 0) {
100
109
  throw Error("You need to return a valid filename");
101
110
  }
@@ -105,7 +114,16 @@ export function useStorageUploadController<M extends object>({
105
114
  }, [entityId, entityValues, path, property, propertyKey, storage]);
106
115
 
107
116
  const storagePathBuilder = useCallback((file: File) => {
108
- return resolveStoragePathString(storage.storagePath, storage, entityValues, entityId, path, property, file, propertyKey) ?? "/";
117
+ return resolveStoragePathString({
118
+ input: storage.storagePath,
119
+ storage,
120
+ values: entityValues,
121
+ entityId,
122
+ path,
123
+ property,
124
+ file,
125
+ propertyKey
126
+ }) ?? "/";
109
127
  }, [entityId, entityValues, path, property, propertyKey, storage]);
110
128
 
111
129
  const onFileUploadComplete = useCallback(async (uploadedPath: string,
@@ -1,77 +0,0 @@
1
- import { Entity, EntityCollection, EntityStatus, EntityValues, FormContext, ResolvedEntityCollection } from "../types";
2
- import { ValidationError } from "yup";
3
- /**
4
- * @group Components
5
- */
6
- export interface EntityFormProps<M extends Record<string, any>> {
7
- /**
8
- * New or existing status
9
- */
10
- status: EntityStatus;
11
- /**
12
- * Path of the collection this entity is located
13
- */
14
- path: string;
15
- /**
16
- * The collection is used to build the fields of the form
17
- */
18
- collection: EntityCollection<M>;
19
- /**
20
- * The updated entity is passed from the parent component when the underlying data
21
- * has changed in the datasource
22
- */
23
- entity?: Entity<M>;
24
- /**
25
- * The callback function called when Save is clicked and validation is correct
26
- */
27
- onEntitySaveRequested: (props: EntityFormSaveParams<M>) => Promise<void>;
28
- /**
29
- * The callback function called when discard is clicked
30
- */
31
- onDiscard?: () => void;
32
- /**
33
- * The callback function when the form is dirty, so the values are different
34
- * from the original ones
35
- */
36
- onModified?: (dirty: boolean) => void;
37
- /**
38
- * The callback function when the form original values have been modified
39
- */
40
- onValuesChanged?: (values?: EntityValues<M>) => void;
41
- /**
42
- *
43
- * @param id
44
- */
45
- onIdChange?: (id: string) => void;
46
- currentEntityId?: string;
47
- onFormContextChange?: (formContext: FormContext<M>) => void;
48
- hideId?: boolean;
49
- autoSave?: boolean;
50
- onIdUpdateError?: (error: any) => void;
51
- }
52
- export type EntityFormSaveParams<M extends Record<string, any>> = {
53
- collection: ResolvedEntityCollection<M>;
54
- path: string;
55
- entityId: string | undefined;
56
- values: EntityValues<M>;
57
- previousValues?: EntityValues<M>;
58
- closeAfterSave: boolean;
59
- autoSave: boolean;
60
- };
61
- /**
62
- * This is the form used internally by the CMS
63
- * @param status
64
- * @param path
65
- * @param collection
66
- * @param entity
67
- * @param onEntitySave
68
- * @param onDiscard
69
- * @param onModified
70
- * @param onValuesChanged
71
- * @constructor
72
- * @group Components
73
- */
74
- export declare const EntityForm: typeof EntityFormInternal;
75
- declare function EntityFormInternal<M extends Record<string, any>>({ status, path, collection: inputCollection, entity, onEntitySaveRequested, onDiscard, onModified, onValuesChanged, onIdChange, onFormContextChange, hideId, autoSave, onIdUpdateError, }: EntityFormProps<M>): import("react/jsx-runtime").JSX.Element;
76
- export declare function yupToFormErrors(yupError: ValidationError): Record<string, any>;
77
- export {};