@firecms/core 3.0.0-alpha.46 → 3.0.0-alpha.47

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 (39) hide show
  1. package/dist/components/EntityCollectionView/EntityCollectionView.d.ts +1 -1
  2. package/dist/components/EntityCollectionView/EntityCollectionViewActions.d.ts +2 -2
  3. package/dist/index.es.js +2087 -2059
  4. package/dist/index.es.js.map +1 -1
  5. package/dist/index.umd.js +12 -12
  6. package/dist/index.umd.js.map +1 -1
  7. package/dist/internal/EntityView.d.ts +2 -1
  8. package/dist/types/collections.d.ts +8 -8
  9. package/dist/types/index.d.ts +1 -0
  10. package/dist/types/modify_collections.d.ts +5 -0
  11. package/dist/types/navigation.d.ts +9 -0
  12. package/dist/types/plugins.d.ts +2 -2
  13. package/dist/ui/ExpandablePanel.d.ts +2 -1
  14. package/dist/util/join_collections.d.ts +3 -7
  15. package/package.json +2 -2
  16. package/src/components/EntityCollectionTable/internal/EntityCollectionRowActions.tsx +1 -1
  17. package/src/components/EntityCollectionTable/internal/common.tsx +1 -1
  18. package/src/components/EntityCollectionView/EntityCollectionView.tsx +7 -7
  19. package/src/components/EntityCollectionView/EntityCollectionViewActions.tsx +3 -3
  20. package/src/core/EntitySidePanel.tsx +5 -0
  21. package/src/core/NavigationRoutes.tsx +5 -5
  22. package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +1 -0
  23. package/src/internal/EntityView.tsx +6 -12
  24. package/src/internal/useBuildNavigationController.tsx +33 -9
  25. package/src/internal/useBuildSideEntityController.tsx +1 -1
  26. package/src/preview/PropertyPreview.tsx +0 -1
  27. package/src/types/collections.ts +9 -9
  28. package/src/types/firecms.tsx +1 -1
  29. package/src/types/index.ts +1 -0
  30. package/src/types/modify_collections.tsx +6 -0
  31. package/src/types/navigation.ts +11 -0
  32. package/src/types/plugins.tsx +2 -2
  33. package/src/ui/ExpandablePanel.tsx +9 -2
  34. package/src/util/builders.ts +2 -1
  35. package/src/util/join_collections.ts +49 -19
  36. package/src/util/navigation_from_path.ts +2 -2
  37. package/src/util/navigation_utils.ts +3 -3
  38. package/src/util/parent_references_from_path.ts +2 -2
  39. package/src/util/property_utils.tsx +1 -7
@@ -10,8 +10,9 @@ export function ExpandablePanel({
10
10
  title,
11
11
  children,
12
12
  invisible = false,
13
- initiallyExpanded: initiallyOpen = true,
13
+ expanded,
14
14
  onExpandedChange,
15
+ initiallyExpanded = true,
15
16
  titleClassName,
16
17
  asField,
17
18
  className
@@ -19,6 +20,7 @@ export function ExpandablePanel({
19
20
  title: React.ReactNode,
20
21
  invisible?: boolean,
21
22
  initiallyExpanded?: boolean;
23
+ expanded?: boolean;
22
24
  onExpandedChange?: (expanded: boolean) => void,
23
25
  titleClassName?: string,
24
26
  asField?: boolean,
@@ -54,7 +56,7 @@ export function ExpandablePanel({
54
56
  }
55
57
  }`);
56
58
 
57
- const [open, setOpen] = useState(initiallyOpen);
59
+ const [open, setOpen] = useState(expanded !== undefined ? expanded : initiallyExpanded);
58
60
  const [allowOverflow, setAllowOverflow] = useState(open);
59
61
 
60
62
  useEffect(() => {
@@ -67,6 +69,11 @@ export function ExpandablePanel({
67
69
  }
68
70
  }, [open]);
69
71
 
72
+ useEffect(() => {
73
+ if (expanded !== undefined)
74
+ setOpen(expanded);
75
+ }, [expanded]);
76
+
70
77
  return (<>
71
78
  <Collapsible.Root
72
79
  className={cn(
@@ -4,7 +4,8 @@ import {
4
4
  BooleanProperty,
5
5
  CMSType,
6
6
  DateProperty,
7
- EntityCallbacks, EntityCollection,
7
+ EntityCallbacks,
8
+ EntityCollection,
8
9
  EnumValueConfig,
9
10
  EnumValues,
10
11
  GeopointProperty,
@@ -1,43 +1,67 @@
1
- import { EntityCollection, MapProperty, PropertiesOrBuilders, Property, PropertyOrBuilder } from "../types";
2
- import { mergeDeep } from "../util/objects";
3
- import { sortProperties } from "../util/collections";
4
- import { isPropertyBuilder } from "../util/entities";
1
+ import {
2
+ EntityCollection,
3
+ MapProperty,
4
+ ModifyCollectionProps,
5
+ PropertiesOrBuilders,
6
+ Property,
7
+ PropertyOrBuilder
8
+ } from "../types";
9
+ import { mergeDeep } from "./objects";
10
+ import { sortProperties } from "./collections";
11
+ import { isPropertyBuilder } from "./entities";
5
12
 
6
13
  /**
7
14
  *
8
- * @param storedCollections
9
- * @param codedCollections
10
15
  */
11
- export function joinCollectionLists(storedCollections: EntityCollection[], codedCollections: EntityCollection[] | undefined): EntityCollection[] {
16
+ export function joinCollectionLists(targetCollections: EntityCollection[],
17
+ sourceCollections: EntityCollection[] | undefined,
18
+ parentPaths: string[] = [],
19
+ modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | undefined): EntityCollection[] {
12
20
 
13
21
  // merge collections that are in both lists
14
- const updatedCollections = (codedCollections ?? [])
22
+ const updatedCollections = (sourceCollections ?? [])
15
23
  .map((codedCollection) => {
16
- const storedCollection = storedCollections?.find((collection) => {
17
- return collection.path === codedCollection.path || (collection.alias && codedCollection.alias && collection.alias === codedCollection.alias);
24
+ const storedCollection = targetCollections?.find((collection) => {
25
+ return collection.id === codedCollection.id;
26
+ // return collection.path === codedCollection.path || collection.id && codedCollection.id;
18
27
  });
19
28
  if (!storedCollection) {
20
29
  return codedCollection;
21
30
  } else {
22
- return mergeCollection(storedCollection, codedCollection);
31
+ return mergeCollection(storedCollection, codedCollection, parentPaths, modifyCollection);
23
32
  }
24
33
  });
25
34
 
26
35
  // fetched collections that are not in the base collections
27
- const resultStoredCollections = storedCollections
28
- .filter((col) => !updatedCollections.map(c => c.path).includes(col.path) || !updatedCollections.map(c => c.alias).includes(col.alias));
36
+ const resultStoredCollections = targetCollections
37
+ .filter((col) => !updatedCollections.map(c => c.id).includes(col.id))
38
+ .map((col) => {
39
+ if (modifyCollection) {
40
+ const modified = modifyCollection({ collection: col, parentPaths });
41
+ return modified ?? col;
42
+ } else {
43
+ return col;
44
+ }
45
+ });
29
46
 
30
47
  return [...updatedCollections, ...resultStoredCollections];
31
48
  }
32
49
 
33
50
  /**
34
51
  *
35
- * @param target
36
- * @param source
37
52
  */
38
- export function mergeCollection(target: EntityCollection, source: EntityCollection): EntityCollection {
53
+ export function mergeCollection(target: EntityCollection,
54
+ source: EntityCollection,
55
+ parentPaths: string[] = [],
56
+ modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | undefined
57
+ ): EntityCollection {
39
58
 
40
- const subcollectionsMerged = joinCollectionLists(target?.subcollections ?? [], source?.subcollections ?? []);
59
+ const subcollectionsMerged = joinCollectionLists(
60
+ target?.subcollections ?? [],
61
+ source?.subcollections ?? [],
62
+ [...parentPaths, target.path],
63
+ modifyCollection
64
+ );
41
65
 
42
66
  const propertiesMerged: PropertiesOrBuilders = { ...target.properties } as PropertiesOrBuilders;
43
67
  Object.keys(source.properties).forEach((key) => {
@@ -51,16 +75,22 @@ export function mergeCollection(target: EntityCollection, source: EntityCollecti
51
75
  const mergedCollection = mergeDeep(target, source);
52
76
  const targetPropertiesOrder = getCollectionKeys(target);
53
77
  const sourcePropertiesOrder = getCollectionKeys(source);
54
- const mergedPropertiesOrder = [...new Set([...targetPropertiesOrder, ...sourcePropertiesOrder])];
78
+ const mergedPropertiesOrder = [...new Set([...sourcePropertiesOrder, ...targetPropertiesOrder])];
55
79
  const mergedEntityViews = [...new Set([...(target.entityViews ?? []), ...(source.entityViews ?? [])])];
56
80
 
57
- return {
81
+ let resultCollection: EntityCollection = {
58
82
  ...mergedCollection,
59
83
  subcollections: subcollectionsMerged,
60
84
  properties: sortProperties(propertiesMerged, mergedPropertiesOrder),
61
85
  propertiesOrder: mergedPropertiesOrder,
62
86
  entityViews: mergedEntityViews
87
+ };
88
+ if (modifyCollection) {
89
+ const modifiedCollection = modifyCollection({ collection: resultCollection, parentPaths });
90
+ if (modifiedCollection)
91
+ resultCollection = modifiedCollection;
63
92
  }
93
+ return resultCollection
64
94
  }
65
95
 
66
96
  function mergePropertyOrBuilder(target: Property, source: PropertyOrBuilder): PropertyOrBuilder {
@@ -46,10 +46,10 @@ export function getNavigationEntriesFromPathInternal(props: {
46
46
  for (let i = 0; i < subpathCombinations.length; i++) {
47
47
  const subpathCombination = subpathCombinations[i];
48
48
 
49
- const collection: EntityCollection<any> | undefined = collections && collections.find((entry) => entry.alias === subpathCombination || entry.path === subpathCombination);
49
+ const collection: EntityCollection<any> | undefined = collections && collections.find((entry) => entry.id === subpathCombination || entry.path === subpathCombination);
50
50
 
51
51
  if (collection) {
52
- const pathOrAlias = collection.alias ?? collection.path;
52
+ const pathOrAlias = collection.id ?? collection.path;
53
53
  const collectionPath = currentFullPath && currentFullPath.length > 0
54
54
  ? (currentFullPath + "/" + pathOrAlias)
55
55
  : pathOrAlias;
@@ -54,7 +54,7 @@ export function resolveCollectionPathAliases(path: string, allCollections: Entit
54
54
  throw Error(`Collection paths must have an odd number of segments: ${path}`);
55
55
  }
56
56
 
57
- const aliasedCollection = allCollections.find((col) => col.alias === subpaths[0]);
57
+ const aliasedCollection = allCollections.find((col) => col.id === subpaths[0]);
58
58
  let resolvedAliased;
59
59
  if (aliasedCollection) {
60
60
  resolvedAliased = aliasedCollection.path;
@@ -90,8 +90,8 @@ export function getCollectionByPathOrAlias(pathOrAlias: string, collections: Ent
90
90
  for (let i = 0; i < subpathCombinations.length; i++) {
91
91
  const subpathCombination = subpathCombinations[i];
92
92
  const navigationEntry = collections && collections
93
- .sort((a, b) => (a.alias ?? "").localeCompare(b.alias ?? ""))
94
- .find((entry) => entry.alias === subpathCombination || entry.path === subpathCombination);
93
+ .sort((a, b) => (a.id ?? "").localeCompare(b.id ?? ""))
94
+ .find((entry) => entry.id === subpathCombination || entry.path === subpathCombination);
95
95
 
96
96
  if (navigationEntry) {
97
97
 
@@ -20,10 +20,10 @@ export function getParentReferencesFromPath(props: {
20
20
  for (let i = 0; i < subpathCombinations.length; i++) {
21
21
  const subpathCombination = subpathCombinations[i];
22
22
 
23
- const collection: EntityCollection<any> | undefined = collections && collections.find((entry) => entry.alias === subpathCombination || entry.path === subpathCombination);
23
+ const collection: EntityCollection<any> | undefined = collections && collections.find((entry) => entry.id === subpathCombination || entry.path === subpathCombination);
24
24
 
25
25
  if (collection) {
26
- const pathOrAlias = collection.alias ?? collection.path;
26
+ const pathOrAlias = collection.id ?? collection.path;
27
27
  const collectionPath = currentFullPath && currentFullPath.length > 0
28
28
  ? (currentFullPath + "/" + pathOrAlias)
29
29
  : pathOrAlias;
@@ -1,12 +1,6 @@
1
1
  import React from "react";
2
2
 
3
- import {
4
- EntityCollection,
5
- PropertiesOrBuilders,
6
- PropertyConfig,
7
- PropertyOrBuilder,
8
- ResolvedProperty
9
- } from "../types";
3
+ import { EntityCollection, PropertiesOrBuilders, PropertyConfig, PropertyOrBuilder, ResolvedProperty } from "../types";
10
4
  import { isPropertyBuilder } from "./entities";
11
5
  import { resolveProperty } from "./resolutions";
12
6
  import { CircleIcon, FunctionsIcon } from "../icons";