@firecms/core 3.4.0-canary.8635253 → 3.4.0-canary.d20cc85

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 (87) hide show
  1. package/dist/components/EntityCollectionTable/internal/CollectionTableToolbar.d.ts +6 -1
  2. package/dist/components/EntityCollectionTable/internal/popup_field/PopupFormField.d.ts +3 -1
  3. package/dist/components/EntityCollectionView/EntityCollectionBoardView.d.ts +3 -1
  4. package/dist/components/EntityCollectionView/EntityCollectionView.d.ts +7 -0
  5. package/dist/components/EntityCollectionView/useBoardDataController.d.ts +3 -1
  6. package/dist/components/ReferenceTable/ReferenceSelectionTable.d.ts +10 -1
  7. package/dist/components/SelectableTable/filters/filter_text_input.d.ts +30 -0
  8. package/dist/components/SelectableTable/filters/filter_text_input.test.d.ts +1 -0
  9. package/dist/components/common/table_url_params.d.ts +24 -0
  10. package/dist/components/common/useDataSourceTableController.d.ts +7 -1
  11. package/dist/components/common/useTableSearchHelper.d.ts +7 -1
  12. package/dist/core/EntityEditView.d.ts +7 -1
  13. package/dist/form/EntityForm.d.ts +6 -1
  14. package/dist/hooks/data/save.d.ts +1 -1
  15. package/dist/hooks/data/useCollectionFetch.d.ts +7 -1
  16. package/dist/hooks/data/useEntityFetch.d.ts +6 -1
  17. package/dist/index.es.js +949 -622
  18. package/dist/index.es.js.map +1 -1
  19. package/dist/index.umd.js +948 -621
  20. package/dist/index.umd.js.map +1 -1
  21. package/dist/types/collections.d.ts +7 -0
  22. package/dist/types/datasource.d.ts +59 -4
  23. package/dist/types/entities.d.ts +21 -1
  24. package/dist/types/properties.d.ts +17 -1
  25. package/dist/types/side_entity_controller.d.ts +6 -0
  26. package/dist/types/translations.d.ts +6 -0
  27. package/dist/util/__tests__/collections.test.d.ts +1 -0
  28. package/dist/util/__tests__/urls.test.d.ts +1 -0
  29. package/dist/util/collections.d.ts +1 -1
  30. package/dist/util/index.d.ts +1 -0
  31. package/dist/util/navigation_from_path.d.ts +7 -0
  32. package/dist/util/navigation_utils.d.ts +3 -1
  33. package/dist/util/parent_references_from_path.d.ts +1 -0
  34. package/dist/util/urls.d.ts +22 -0
  35. package/package.json +4 -4
  36. package/src/components/EntityCollectionTable/EntityCollectionTable.tsx +1 -0
  37. package/src/components/EntityCollectionTable/internal/CollectionTableToolbar.tsx +7 -0
  38. package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +5 -1
  39. package/src/components/EntityCollectionView/EntityCollectionBoardView.tsx +4 -0
  40. package/src/components/EntityCollectionView/EntityCollectionView.tsx +29 -3
  41. package/src/components/EntityCollectionView/useBoardDataController.tsx +11 -0
  42. package/src/components/ReferenceTable/ReferenceSelectionTable.tsx +11 -0
  43. package/src/components/SelectableTable/filters/StringNumberFilterField.tsx +33 -7
  44. package/src/components/SelectableTable/filters/filter_text_input.test.ts +184 -0
  45. package/src/components/SelectableTable/filters/filter_text_input.ts +71 -0
  46. package/src/components/common/table_url_params.ts +172 -0
  47. package/src/components/common/useDataSourceTableController.tsx +64 -175
  48. package/src/components/common/useTableSearchHelper.ts +21 -2
  49. package/src/contexts/SnackbarProvider.tsx +14 -1
  50. package/src/core/EntityEditView.tsx +21 -0
  51. package/src/core/EntitySidePanel.tsx +2 -0
  52. package/src/form/EntityForm.tsx +9 -3
  53. package/src/hooks/data/delete.ts +2 -0
  54. package/src/hooks/data/save.ts +2 -0
  55. package/src/hooks/data/useCollectionFetch.tsx +13 -0
  56. package/src/hooks/data/useEntityFetch.tsx +18 -0
  57. package/src/hooks/useResolvedNavigationFrom.tsx +2 -0
  58. package/src/hooks/useValidateAuthenticator.tsx +4 -0
  59. package/src/internal/useBuildDataSource.ts +25 -4
  60. package/src/internal/useBuildSideEntityController.tsx +6 -0
  61. package/src/locales/de.ts +5 -0
  62. package/src/locales/en.ts +5 -0
  63. package/src/locales/es.ts +5 -0
  64. package/src/locales/fr.ts +5 -0
  65. package/src/locales/hi.ts +5 -0
  66. package/src/locales/it.ts +5 -0
  67. package/src/locales/pl.ts +5 -0
  68. package/src/locales/pt.ts +5 -0
  69. package/src/preview/components/StorageThumbnail.tsx +24 -2
  70. package/src/routes/FireCMSRoute.tsx +3 -0
  71. package/src/types/collections.ts +8 -0
  72. package/src/types/datasource.ts +59 -4
  73. package/src/types/entities.ts +24 -1
  74. package/src/types/properties.ts +17 -0
  75. package/src/types/side_entity_controller.tsx +6 -0
  76. package/src/types/translations.ts +6 -0
  77. package/src/util/__tests__/collections.test.ts +32 -0
  78. package/src/util/__tests__/urls.test.ts +131 -0
  79. package/src/util/collections.ts +1 -1
  80. package/src/util/entities.ts +3 -1
  81. package/src/util/index.ts +1 -0
  82. package/src/util/navigation_from_path.ts +19 -1
  83. package/src/util/navigation_utils.ts +4 -0
  84. package/src/util/parent_references_from_path.ts +10 -2
  85. package/src/util/previews.ts +8 -1
  86. package/src/util/resolutions.ts +8 -0
  87. package/src/util/urls.ts +52 -0
@@ -19,6 +19,12 @@ export interface EntitySidePanelProps<M extends Record<string, any> = any> {
19
19
  * Full CMS path of the entity, including the collection and sub-collections.
20
20
  */
21
21
  fullIdPath?: string;
22
+ /**
23
+ * `path` split at its real segment boundaries, e.g. `["nodes", "node/42", "edges"]`.
24
+ * Optional: when omitted the panel falls back to splitting `path`, which is correct for
25
+ * any backend whose entity ids cannot contain "/".
26
+ */
27
+ pathSegments?: string[];
22
28
 
23
29
  /**
24
30
  * ID of the entity, if not set, it means we are creating a new entity
@@ -419,6 +419,8 @@ export interface FireCMSTranslations {
419
419
  download: string;
420
420
  large_number_of_documents: string;
421
421
  include_undefined_values: string;
422
+ /** Toggle in the export dialog, only shown when a filter or sort is active */
423
+ export_apply_filter_sort: string;
422
424
  submit: string;
423
425
 
424
426
  no_filterable_properties: string;
@@ -620,6 +622,10 @@ export interface FireCMSTranslations {
620
622
  order_property_not_found: string;
621
623
  no_number_properties: string;
622
624
  order_property_description: string;
625
+ image_property: string;
626
+ image_property_not_found: string;
627
+ no_image_properties: string;
628
+ image_property_description: string;
623
629
  display_settings: string;
624
630
  default_row_size: string;
625
631
  side_dialog_width: string;
@@ -0,0 +1,32 @@
1
+ import { getLocalChangesBackup } from "../collections";
2
+ import { EntityCollection } from "../../types";
3
+
4
+ function collectionWith(localChangesBackup?: "manual_apply" | "auto_apply" | false): EntityCollection {
5
+ return {
6
+ id: "products",
7
+ name: "Products",
8
+ path: "products",
9
+ properties: {},
10
+ localChangesBackup
11
+ } as EntityCollection;
12
+ }
13
+
14
+ describe("getLocalChangesBackup", () => {
15
+
16
+ it("should default to manual_apply when not set", () => {
17
+ expect(getLocalChangesBackup(collectionWith(undefined))).toEqual("manual_apply");
18
+ });
19
+
20
+ it("should return manual_apply when explicitly set", () => {
21
+ expect(getLocalChangesBackup(collectionWith("manual_apply"))).toEqual("manual_apply");
22
+ });
23
+
24
+ it("should return auto_apply when explicitly set", () => {
25
+ expect(getLocalChangesBackup(collectionWith("auto_apply"))).toEqual("auto_apply");
26
+ });
27
+
28
+ it("should return false when explicitly disabled, and not fall back to the default", () => {
29
+ expect(getLocalChangesBackup(collectionWith(false))).toEqual(false);
30
+ });
31
+
32
+ });
@@ -0,0 +1,131 @@
1
+ import { getFileExtensionFromUrl, getPreviewTypeFromUrl, isAbsoluteHttpUrl } from "../urls";
2
+
3
+ describe("url utilities", () => {
4
+
5
+ describe("isAbsoluteHttpUrl", () => {
6
+
7
+ it("should detect absolute http and https URLs", () => {
8
+ expect(isAbsoluteHttpUrl("https://abc.com/abc.png")).toBe(true);
9
+ expect(isAbsoluteHttpUrl("http://abc.com/abc.png")).toBe(true);
10
+ expect(isAbsoluteHttpUrl("HTTPS://ABC.COM/ABC.PNG")).toBe(true);
11
+ });
12
+
13
+ it("should detect Firebase Storage download URLs as absolute URLs", () => {
14
+ expect(isAbsoluteHttpUrl("https://firebasestorage.googleapis.com/v0/b/demo.appspot.com/o/images%2Fcat.png?alt=media&token=abc")).toBe(true);
15
+ expect(isAbsoluteHttpUrl("https://storage.googleapis.com/demo.appspot.com/images/cat.png")).toBe(true);
16
+ });
17
+
18
+ it("should not consider storage paths absolute URLs", () => {
19
+ expect(isAbsoluteHttpUrl("images/cat.png")).toBe(false);
20
+ expect(isAbsoluteHttpUrl("/images/cat.png")).toBe(false);
21
+ expect(isAbsoluteHttpUrl("cat.png")).toBe(false);
22
+ });
23
+
24
+ it("should not consider other protocols absolute http URLs", () => {
25
+ expect(isAbsoluteHttpUrl("gs://demo.appspot.com/images/cat.png")).toBe(false);
26
+ expect(isAbsoluteHttpUrl("data:image/png;base64,AAAA")).toBe(false);
27
+ expect(isAbsoluteHttpUrl("//abc.com/abc.png")).toBe(false);
28
+ });
29
+
30
+ it("should handle empty values", () => {
31
+ expect(isAbsoluteHttpUrl("")).toBe(false);
32
+ expect(isAbsoluteHttpUrl(undefined)).toBe(false);
33
+ expect(isAbsoluteHttpUrl(null)).toBe(false);
34
+ });
35
+
36
+ it("should not match http appearing later in the value", () => {
37
+ expect(isAbsoluteHttpUrl("images/https://abc.com/abc.png")).toBe(false);
38
+ });
39
+
40
+ });
41
+
42
+ describe("getFileExtensionFromUrl", () => {
43
+
44
+ it("should extract the extension of a plain URL", () => {
45
+ expect(getFileExtensionFromUrl("https://abc.com/abc.png")).toBe("png");
46
+ });
47
+
48
+ it("should lowercase the extension", () => {
49
+ expect(getFileExtensionFromUrl("https://abc.com/ABC.PNG")).toBe("png");
50
+ });
51
+
52
+ it("should ignore query strings and hash fragments", () => {
53
+ expect(getFileExtensionFromUrl("https://abc.com/abc.png?width=200")).toBe("png");
54
+ expect(getFileExtensionFromUrl("https://abc.com/abc.png#anchor")).toBe("png");
55
+ expect(getFileExtensionFromUrl("https://firebasestorage.googleapis.com/v0/b/demo.appspot.com/o/images%2Fcat.jpeg?alt=media&token=abc")).toBe("jpeg");
56
+ });
57
+
58
+ it("should work with storage paths", () => {
59
+ expect(getFileExtensionFromUrl("images/cat.webp")).toBe("webp");
60
+ });
61
+
62
+ it("should use the last dot of the file name", () => {
63
+ expect(getFileExtensionFromUrl("https://abc.com/archive.tar.gz")).toBe("gz");
64
+ });
65
+
66
+ it("should return undefined when there is no extension", () => {
67
+ expect(getFileExtensionFromUrl("https://abc.com/abc")).toBeUndefined();
68
+ expect(getFileExtensionFromUrl("https://abc.com/")).toBeUndefined();
69
+ expect(getFileExtensionFromUrl("images/cat")).toBeUndefined();
70
+ });
71
+
72
+ it("should not take dots of the host or the path as extensions", () => {
73
+ expect(getFileExtensionFromUrl("https://abc.com/images/cat")).toBeUndefined();
74
+ expect(getFileExtensionFromUrl("https://abc.com/abc.png/download")).toBeUndefined();
75
+ });
76
+
77
+ it("should return undefined for dotfiles and trailing dots", () => {
78
+ expect(getFileExtensionFromUrl("https://abc.com/.gitignore")).toBeUndefined();
79
+ expect(getFileExtensionFromUrl("https://abc.com/abc.")).toBeUndefined();
80
+ });
81
+
82
+ it("should handle empty values", () => {
83
+ expect(getFileExtensionFromUrl("")).toBeUndefined();
84
+ expect(getFileExtensionFromUrl(undefined)).toBeUndefined();
85
+ expect(getFileExtensionFromUrl(null)).toBeUndefined();
86
+ });
87
+
88
+ });
89
+
90
+ describe("getPreviewTypeFromUrl", () => {
91
+
92
+ it("should infer image previews", () => {
93
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.png")).toBe("image");
94
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.jpg")).toBe("image");
95
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.jpeg")).toBe("image");
96
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.gif")).toBe("image");
97
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.webp")).toBe("image");
98
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.svg")).toBe("image");
99
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.avif")).toBe("image");
100
+ });
101
+
102
+ it("should infer video previews", () => {
103
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.mp4")).toBe("video");
104
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.webm")).toBe("video");
105
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.mov")).toBe("video");
106
+ });
107
+
108
+ it("should infer audio previews", () => {
109
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.mp3")).toBe("audio");
110
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.wav")).toBe("audio");
111
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.m4a")).toBe("audio");
112
+ });
113
+
114
+ it("should infer the type of Firebase Storage download URLs", () => {
115
+ expect(getPreviewTypeFromUrl("https://firebasestorage.googleapis.com/v0/b/demo.appspot.com/o/images%2Fcat.png?alt=media&token=abc")).toBe("image");
116
+ });
117
+
118
+ it("should be case insensitive", () => {
119
+ expect(getPreviewTypeFromUrl("https://abc.com/ABC.PNG")).toBe("image");
120
+ });
121
+
122
+ it("should return undefined for unknown or missing extensions", () => {
123
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.pdf")).toBeUndefined();
124
+ expect(getPreviewTypeFromUrl("https://abc.com/abc.zip")).toBeUndefined();
125
+ expect(getPreviewTypeFromUrl("https://abc.com/abc")).toBeUndefined();
126
+ expect(getPreviewTypeFromUrl(undefined)).toBeUndefined();
127
+ });
128
+
129
+ });
130
+
131
+ });
@@ -117,7 +117,7 @@ export const applyPermissionsFunctionIfEmpty = (collections: EntityCollection[],
117
117
  }
118
118
 
119
119
  export function getLocalChangesBackup(collection: EntityCollection) {
120
- if (!collection.localChangesBackup) {
120
+ if (collection.localChangesBackup === undefined) {
121
121
  return "manual_apply";
122
122
  }
123
123
 
@@ -142,7 +142,9 @@ export function getReferenceFrom<M extends Record<string, any>>(entity: Entity<M
142
142
  if (!entity) {
143
143
  throw new Error("getReferenceFrom: entity is null or undefined");
144
144
  }
145
- return new EntityReference(entity.id, entity.path, entity.databaseId);
145
+ // Carry the segments the entity was loaded with, so a reference to an entity under a
146
+ // slash-bearing parent stays resolvable. Undefined when the entity does not have them.
147
+ return new EntityReference(entity.id, entity.path, entity.databaseId, entity.pathSegments);
146
148
  }
147
149
 
148
150
  export function traverseValuesProperties<M extends Record<string, any>>(
package/src/util/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./enums";
6
6
  export * from "./objects";
7
7
  export * from "./paths";
8
8
  export * from "./regexp";
9
+ export * from "./urls";
9
10
  export * from "./navigation_utils";
10
11
  export * from "./entity_actions";
11
12
  export * from "./useDebouncedCallback";
@@ -13,6 +13,8 @@ export interface NavigationViewEntityInternal<M extends Record<string, any>> {
13
13
  path: string;
14
14
  fullIdPath: string;
15
15
  fullPath: string;
16
+ /** `path` split at its real boundaries — see `pathSegments` on the datasource props. */
17
+ pathSegments: string[];
16
18
  parentCollection: EntityCollection<M>;
17
19
  }
18
20
 
@@ -22,6 +24,8 @@ export interface NavigationViewCollectionInternal<M extends Record<string, any>>
22
24
  path: string;
23
25
  fullIdPath: string;
24
26
  fullPath: string;
27
+ /** `path` split at its real boundaries — see `pathSegments` on the datasource props. */
28
+ pathSegments: string[];
25
29
  collection: EntityCollection<M>;
26
30
  }
27
31
 
@@ -30,6 +34,8 @@ export interface NavigationViewEntityCustomInternal<M extends Record<string, any
30
34
  path: string;
31
35
  fullIdPath: string;
32
36
  fullPath: string;
37
+ /** `path` split at its real boundaries — see `pathSegments` on the datasource props. */
38
+ pathSegments: string[];
33
39
  entityId: string;
34
40
  view: EntityCustomView<M>;
35
41
  }
@@ -49,6 +55,7 @@ export function getNavigationEntriesFromPath(props: {
49
55
  currentFullPath?: string,
50
56
  currentFullIdPath?: string,
51
57
  currentFullUrlPath?: string,
58
+ currentPathSegments?: string[],
52
59
  contextEntityViews?: EntityCustomView<any>[]
53
60
  }): NavigationViewInternal [] {
54
61
 
@@ -57,7 +64,8 @@ export function getNavigationEntriesFromPath(props: {
57
64
  collections = [],
58
65
  currentFullPath,
59
66
  currentFullIdPath,
60
- currentFullUrlPath
67
+ currentFullUrlPath,
68
+ currentPathSegments = []
61
69
  } = props;
62
70
 
63
71
  const subpaths = removeInitialAndTrailingSlashes(path).split("/");
@@ -83,12 +91,16 @@ export function getNavigationEntriesFromPath(props: {
83
91
  const fullIdPath = currentFullIdPath && currentFullIdPath.length > 0
84
92
  ? (currentFullIdPath + "/" + collection.id)
85
93
  : collection.id;
94
+ // A collection `path` may itself span several segments (e.g. "users/uid/experiences"),
95
+ // and those are unambiguous, so they are spread rather than kept whole.
96
+ const collectionSegments = [...currentPathSegments, ...collection.path.split("/")];
86
97
  result.push({
87
98
  type: "collection",
88
99
  id: collection.id,
89
100
  path: collectionPath,
90
101
  fullPath: collectionUrlPath,
91
102
  fullIdPath,
103
+ pathSegments: collectionSegments,
92
104
  collection
93
105
  });
94
106
  const restOfThePath = removeInitialAndTrailingSlashes(removeInitialAndTrailingSlashes(path).replace(subpathCombination, ""));
@@ -98,12 +110,16 @@ export function getNavigationEntriesFromPath(props: {
98
110
  const entityId = decodeEntityId(encodedEntityId);
99
111
  const fullPath = collectionPath + "/" + entityId;
100
112
  const fullUrlPath = collectionUrlPath + "/" + encodedEntityId;
113
+ // The id is ONE segment however many slashes it contains — that is the
114
+ // whole point of this array.
115
+ const entitySegments = [...collectionSegments, entityId];
101
116
  result.push({
102
117
  type: "entity",
103
118
  entityId,
104
119
  path: collectionPath,
105
120
  fullIdPath,
106
121
  fullPath: fullUrlPath,
122
+ pathSegments: collectionSegments,
107
123
  parentCollection: collection
108
124
  });
109
125
  if (nextSegments.length > 1) {
@@ -123,6 +139,7 @@ export function getNavigationEntriesFromPath(props: {
123
139
  entityId: entityId,
124
140
  fullIdPath,
125
141
  fullPath: fullUrlPath + "/" + customView.key,
142
+ pathSegments: collectionSegments,
126
143
  view: customView
127
144
  });
128
145
  } else if (collection.subcollections) {
@@ -132,6 +149,7 @@ export function getNavigationEntriesFromPath(props: {
132
149
  currentFullPath: fullPath,
133
150
  currentFullIdPath: fullIdPath,
134
151
  currentFullUrlPath: fullUrlPath,
152
+ currentPathSegments: entitySegments,
135
153
  contextEntityViews: props.contextEntityViews
136
154
  }));
137
155
  }
@@ -212,6 +212,7 @@ export function navigateToEntity({
212
212
  copy,
213
213
  path,
214
214
  fullIdPath,
215
+ pathSegments,
215
216
  selectedTab,
216
217
  sideEntityController,
217
218
  onClose,
@@ -226,6 +227,8 @@ export function navigateToEntity({
226
227
  copy?: boolean;
227
228
  path: string;
228
229
  fullIdPath?: string;
230
+ /** `path` split at its real segment boundaries. */
231
+ pathSegments?: string[];
229
232
  sideEntityController: SideEntityController;
230
233
  onClose?: () => void;
231
234
  navigation: NavigationController
@@ -237,6 +240,7 @@ export function navigateToEntity({
237
240
  entityId,
238
241
  path,
239
242
  fullIdPath,
243
+ pathSegments,
240
244
  copy,
241
245
  selectedTab,
242
246
  collection,
@@ -5,12 +5,14 @@ export function getParentReferencesFromPath(props: {
5
5
  path: string,
6
6
  collections: EntityCollection[] | undefined,
7
7
  currentFullPath?: string,
8
+ currentPathSegments?: string[],
8
9
  }): EntityReference [] {
9
10
 
10
11
  const {
11
12
  path,
12
13
  collections = [],
13
14
  currentFullPath,
15
+ currentPathSegments = [],
14
16
  } = props;
15
17
 
16
18
  const subpaths = removeInitialAndTrailingSlashes(path).split("/");
@@ -27,6 +29,9 @@ export function getParentReferencesFromPath(props: {
27
29
  const collectionPath = currentFullPath && currentFullPath.length > 0
28
30
  ? (currentFullPath + "/" + collection.path)
29
31
  : collection.path;
32
+ // A collection's own path may span several segments, and those are
33
+ // unambiguous, so they are spread rather than kept whole.
34
+ const collectionSegments = [...currentPathSegments, ...collection.path.split("/")];
30
35
 
31
36
  const restOfThePath = removeInitialAndTrailingSlashes(removeInitialAndTrailingSlashes(path).replace(subpathCombination, ""));
32
37
  const nextSegments = restOfThePath.length > 0 ? restOfThePath.split("/") : [];
@@ -35,7 +40,9 @@ export function getParentReferencesFromPath(props: {
35
40
  // datasource-facing, so they carry the raw id.
36
41
  const entityId = decodeEntityId(nextSegments[0]);
37
42
  const fullPath = collectionPath + "/" + entityId;
38
- result.push(new EntityReference(entityId, collectionPath));
43
+ // The id is ONE segment however many slashes it contains.
44
+ const entitySegments = [...collectionSegments, entityId];
45
+ result.push(new EntityReference(entityId, collectionPath, undefined, collectionSegments));
39
46
  if (nextSegments.length > 1) {
40
47
  const newPath = nextSegments.slice(1).join("/");
41
48
  if (!collection) {
@@ -45,7 +52,8 @@ export function getParentReferencesFromPath(props: {
45
52
  result.push(...getParentReferencesFromPath({
46
53
  path: newPath,
47
54
  collections: collection.subcollections,
48
- currentFullPath: fullPath
55
+ currentFullPath: fullPath,
56
+ currentPathSegments: entitySegments
49
57
  }));
50
58
  }
51
59
  }
@@ -1,4 +1,4 @@
1
- import { AuthController, EntityCollection, Property, PropertyConfig, ResolvedEntityCollection } from "../types";
1
+ import { AuthController, EntityCollection, Property, PropertyConfig, ResolvedEntityCollection, ResolvedProperties } from "../types";
2
2
  import { isReferenceProperty } from "./property_utils";
3
3
  import { isPropertyBuilder } from "./entities";
4
4
  import { getFieldConfig } from "../core";
@@ -44,6 +44,13 @@ export function getEntityTitlePropertyKey<M extends Record<string, any>>(collect
44
44
 
45
45
  export function getEntityImagePreviewPropertyKey<M extends object>(collection: ResolvedEntityCollection<M>): string | undefined {
46
46
 
47
+ if (collection.imageProperty) {
48
+ const imagePropertyKey = collection.imageProperty as keyof ResolvedProperties<M>;
49
+ if (collection.properties[imagePropertyKey]) {
50
+ return collection.imageProperty as string;
51
+ }
52
+ }
53
+
47
54
  // find first storage property of type image
48
55
  for (const key in collection.properties) {
49
56
  const property = collection.properties[key];
@@ -305,7 +305,15 @@ export function resolveArrayProperty<T extends any[], M>({
305
305
  ignoreMissingFields,
306
306
  ...props
307
307
  });
308
+ // `of` describes the shape of any element of the array, not one
309
+ // specific element, so there is no index to qualify the key with.
310
+ // We pass the array's own key, mirroring what the `oneOf` branch
311
+ // below does for `oneOf.properties`. Without this, a property
312
+ // builder used as `of` (or nested inside it) would be invoked with
313
+ // `propertyKey: undefined`, while the per-index resolutions above
314
+ // receive `${propertyKey}.${index}`.
308
315
  const ofProperty = resolveProperty({
316
+ propertyKey,
309
317
  propertyOrBuilder: of,
310
318
  ignoreMissingFields,
311
319
  ...props
@@ -0,0 +1,52 @@
1
+ import type { PreviewType } from "../types";
2
+
3
+ const ABSOLUTE_HTTP_URL_REGEX = /^https?:\/\//i;
4
+
5
+ const IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "gif", "webp", "avif", "bmp", "svg", "ico", "tif", "tiff", "heic", "heif"];
6
+ const VIDEO_EXTENSIONS = ["mp4", "webm", "ogv", "mov", "m4v", "avi", "mkv", "mpeg", "mpg", "3gp"];
7
+ const AUDIO_EXTENSIONS = ["mp3", "wav", "ogg", "oga", "m4a", "aac", "flac", "weba", "opus", "mid", "midi"];
8
+
9
+ /**
10
+ * Is the given value an absolute `http(s)` URL, as opposed to a relative
11
+ * storage path such as `images/my_image.png`?
12
+ *
13
+ * Values saved in the datasource for storage properties can be either, e.g.
14
+ * when the property is configured with `storeUrl: true`, or when the value was
15
+ * written directly pointing to an externally hosted file.
16
+ */
17
+ export function isAbsoluteHttpUrl(value?: string | null): boolean {
18
+ if (!value) return false;
19
+ return ABSOLUTE_HTTP_URL_REGEX.test(value);
20
+ }
21
+
22
+ /**
23
+ * Extract the lowercase file extension of a URL or path, ignoring any query
24
+ * string or hash fragment. Returns `undefined` when there is no extension.
25
+ */
26
+ export function getFileExtensionFromUrl(urlOrPath?: string | null): string | undefined {
27
+ if (!urlOrPath) return undefined;
28
+ // Query strings and hash fragments are not part of the file name, and they
29
+ // are common in download URLs, e.g. `?alt=media&token=...`
30
+ const withoutQuery = urlOrPath.split(/[?#]/)[0];
31
+ const lastSegment = withoutQuery.split("/").pop();
32
+ if (!lastSegment) return undefined;
33
+ const lastDot = lastSegment.lastIndexOf(".");
34
+ // No dot, a leading dot (a dotfile), or a trailing dot means no extension
35
+ if (lastDot <= 0 || lastDot === lastSegment.length - 1) return undefined;
36
+ return lastSegment.substring(lastDot + 1).toLowerCase();
37
+ }
38
+
39
+ /**
40
+ * Best effort guess of the preview type of a URL or path, based on its file
41
+ * extension. Used when no storage metadata (and therefore no content type) is
42
+ * available, e.g. for externally hosted files.
43
+ * Returns `undefined` when the extension is missing or not recognised.
44
+ */
45
+ export function getPreviewTypeFromUrl(urlOrPath?: string | null): PreviewType | undefined {
46
+ const extension = getFileExtensionFromUrl(urlOrPath);
47
+ if (!extension) return undefined;
48
+ if (IMAGE_EXTENSIONS.includes(extension)) return "image";
49
+ if (VIDEO_EXTENSIONS.includes(extension)) return "video";
50
+ if (AUDIO_EXTENSIONS.includes(extension)) return "audio";
51
+ return undefined;
52
+ }