@firecms/core 3.0.0-canary.215 → 3.0.0-canary.216

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.
@@ -653,6 +653,12 @@ export type StorageConfig = {
653
653
  * Define maximal file size in bytes
654
654
  */
655
655
  maxSize?: number;
656
+ /**
657
+ * Use this callback to process the file before uploading it to the storage.
658
+ * If nothing is returned, the file is uploaded as it is.
659
+ * @param file
660
+ */
661
+ processFile?: (file: File) => Promise<File> | undefined;
656
662
  /**
657
663
  * Postprocess the saved value (storage path or URL)
658
664
  * after it has been resolved.
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.215",
4
+ "version": "3.0.0-canary.216",
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.215",
54
- "@firecms/formex": "^3.0.0-canary.215",
55
- "@firecms/ui": "^3.0.0-canary.215",
53
+ "@firecms/editor": "^3.0.0-canary.216",
54
+ "@firecms/formex": "^3.0.0-canary.216",
55
+ "@firecms/ui": "^3.0.0-canary.216",
56
56
  "@hello-pangea/dnd": "^17.0.0",
57
57
  "@radix-ui/react-portal": "^1.1.3",
58
58
  "clsx": "^2.1.1",
@@ -105,7 +105,7 @@
105
105
  "dist",
106
106
  "src"
107
107
  ],
108
- "gitHead": "e04e9ae0e4c6b351f6a77f30295445bededef042",
108
+ "gitHead": "806f397ce4c02424b832311615c8864939a4f4d5",
109
109
  "publishConfig": {
110
110
  "access": "public"
111
111
  },
@@ -165,7 +165,7 @@ export const EntityCollectionRowActions = function EntityCollectionRowActions({
165
165
 
166
166
  {!hideId && size !== "xs" && (
167
167
  <div
168
- className="w-[138px] overflow-hidden truncate font-mono text-xs text-text-secondary dark:text-text-secondary-dark max-w-full text-ellipsis px-2 align-center flex items-center gap-1"
168
+ className="w-[138px] overflow-hidden truncate font-mono text-xs text-text-secondary dark:text-text-secondary-dark max-w-full text-ellipsis px-2 align-center justify-center flex items-center gap-1"
169
169
  onClick={(event) => {
170
170
  event.stopPropagation();
171
171
  }}>
@@ -815,6 +815,13 @@ export type StorageConfig = {
815
815
  */
816
816
  maxSize?: number,
817
817
 
818
+ /**
819
+ * Use this callback to process the file before uploading it to the storage.
820
+ * If nothing is returned, the file is uploaded as it is.
821
+ * @param file
822
+ */
823
+ processFile?: (file: File) => Promise<File> | undefined;
824
+
818
825
  /**
819
826
  * Postprocess the saved value (storage path or URL)
820
827
  * after it has been resolved.
@@ -71,6 +71,8 @@ export function useStorageUploadController<M extends object>({
71
71
  if (!storage)
72
72
  throw Error("Storage meta must be specified");
73
73
 
74
+ const processFile = storage?.processFile;
75
+
74
76
  const metadata: Record<string, any> | undefined = storage?.metadata;
75
77
  const size = multipleFilesSupported ? "medium" : "large";
76
78
 
@@ -172,7 +174,22 @@ export function useStorageUploadController<M extends object>({
172
174
  if (!acceptedFiles.length || disabled)
173
175
  return;
174
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
+
175
191
  let newInternalValue: StorageFieldItem[];
192
+
176
193
  if (multipleFilesSupported) {
177
194
  newInternalValue = [...internalValue,
178
195
  ...(await Promise.all(acceptedFiles.map(async file => {