@firecms/collection_editor 3.0.0-alpha.33 → 3.0.0-alpha.35
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.
- package/dist/index.es.js +1586 -1554
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collection_editor_controller.d.ts +1 -1
- package/dist/ui/collection_editor/properties/StringPropertyField.d.ts +1 -1
- package/dist/ui/collection_editor/properties/UrlPropertyField.d.ts +4 -0
- package/dist/ui/collection_editor/templates/blog_template.d.ts +1 -1
- package/package.json +5 -5
- package/src/types/collection_editor_controller.tsx +1 -1
- package/src/ui/collection_editor/CollectionDetailsForm.tsx +52 -1
- package/src/ui/collection_editor/CollectionEditorDialog.tsx +40 -26
- package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +9 -9
- package/src/ui/collection_editor/EntityCustomViewsSelectDialog.tsx +3 -1
- package/src/ui/collection_editor/PropertyEditView.tsx +6 -3
- package/src/ui/collection_editor/SubcollectionsEditTab.tsx +1 -1
- package/src/ui/collection_editor/properties/MapPropertyField.tsx +1 -1
- package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +1 -0
- package/src/ui/collection_editor/properties/StringPropertyField.tsx +1 -7
- package/src/ui/collection_editor/properties/UrlPropertyField.tsx +89 -0
- package/src/ui/collection_editor/templates/blog_template.ts +3 -4
- package/src/ui/collection_editor/templates/products_template.ts +3 -5
- package/src/ui/collection_editor/templates/users_template.ts +3 -4
- package/src/useCollectionEditorPlugin.tsx +1 -2
- package/dist/utils/join_collections.d.ts +0 -13
- package/src/utils/join_collections.ts +0 -113
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EntityCollection,
|
|
3
|
-
isPropertyBuilder,
|
|
4
|
-
MapProperty,
|
|
5
|
-
mergeDeep,
|
|
6
|
-
PropertiesOrBuilders,
|
|
7
|
-
Property,
|
|
8
|
-
PropertyOrBuilder,
|
|
9
|
-
sortProperties
|
|
10
|
-
} from "@firecms/core";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param storedCollections
|
|
15
|
-
* @param codedCollections
|
|
16
|
-
*/
|
|
17
|
-
export function joinCollectionLists(storedCollections: EntityCollection[], codedCollections: EntityCollection[] | undefined): EntityCollection[] {
|
|
18
|
-
|
|
19
|
-
// merge collections that are in both lists
|
|
20
|
-
const updatedCollections = (codedCollections ?? [])
|
|
21
|
-
.map((codedCollection) => {
|
|
22
|
-
const storedCollection = storedCollections?.find((collection) => {
|
|
23
|
-
return collection.path === codedCollection.path || (collection.alias && codedCollection.alias && collection.alias === codedCollection.alias);
|
|
24
|
-
});
|
|
25
|
-
if (!storedCollection) {
|
|
26
|
-
return codedCollection;
|
|
27
|
-
} else {
|
|
28
|
-
return mergeCollection(storedCollection, codedCollection);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// fetched collections that are not in the base collections
|
|
33
|
-
const resultStoredCollections = storedCollections
|
|
34
|
-
.filter((col) => !updatedCollections.map(c => c.path).includes(col.path) || !updatedCollections.map(c => c.alias).includes(col.alias));
|
|
35
|
-
|
|
36
|
-
return [...updatedCollections, ...resultStoredCollections];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* @param target
|
|
42
|
-
* @param source
|
|
43
|
-
*/
|
|
44
|
-
export function mergeCollection(target: EntityCollection, source: EntityCollection): EntityCollection {
|
|
45
|
-
|
|
46
|
-
const subcollectionsMerged = joinCollectionLists(target?.subcollections ?? [], source?.subcollections ?? []);
|
|
47
|
-
|
|
48
|
-
const propertiesMerged: PropertiesOrBuilders = { ...target.properties } as PropertiesOrBuilders;
|
|
49
|
-
Object.keys(source.properties).forEach((key) => {
|
|
50
|
-
const property = target.properties[key] as Property;
|
|
51
|
-
if (property)
|
|
52
|
-
propertiesMerged[key] = mergePropertyOrBuilder(property, source.properties[key] as PropertyOrBuilder);
|
|
53
|
-
else
|
|
54
|
-
propertiesMerged[key] = source.properties[key] as PropertyOrBuilder;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const mergedCollection = mergeDeep(target, source);
|
|
58
|
-
const targetPropertiesOrder = getCollectionKeys(target);
|
|
59
|
-
const sourcePropertiesOrder = getCollectionKeys(source);
|
|
60
|
-
const mergedPropertiesOrder = [...new Set([...targetPropertiesOrder, ...sourcePropertiesOrder])];
|
|
61
|
-
const mergedEntityViews = [...new Set([...(target.entityViews ?? []), ...(source.entityViews ?? [])])];
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
...mergedCollection,
|
|
65
|
-
subcollections: subcollectionsMerged,
|
|
66
|
-
properties: sortProperties(propertiesMerged, mergedPropertiesOrder),
|
|
67
|
-
propertiesOrder: mergedPropertiesOrder,
|
|
68
|
-
entityViews: mergedEntityViews
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function mergePropertyOrBuilder(target: Property, source: PropertyOrBuilder): PropertyOrBuilder {
|
|
73
|
-
if (isPropertyBuilder(source)) {
|
|
74
|
-
return source;
|
|
75
|
-
} else {
|
|
76
|
-
const mergedProperty = mergeDeep(target, source);
|
|
77
|
-
const targetEditable = Boolean(target.editable);
|
|
78
|
-
const sourceEditable = Boolean(source.editable);
|
|
79
|
-
if (source.dataType === "map" && source.properties) {
|
|
80
|
-
const targetProperties = ("properties" in target ? target.properties : {}) as PropertiesOrBuilders;
|
|
81
|
-
const sourceProperties = ("properties" in source ? source.properties : {}) as PropertiesOrBuilders;
|
|
82
|
-
const targetPropertiesOrder = "propertiesOrder" in target && target.propertiesOrder ? target.propertiesOrder : Object.keys(targetProperties);
|
|
83
|
-
const sourcePropertiesOrder = "propertiesOrder" in source && source.propertiesOrder ? source.propertiesOrder : ("properties" in source ? Object.keys(source.properties) : []);
|
|
84
|
-
const mergedPropertiesOrder = [...new Set([...targetPropertiesOrder, ...sourcePropertiesOrder])];
|
|
85
|
-
const mergedProperties: PropertiesOrBuilders = { ...targetProperties } as PropertiesOrBuilders;
|
|
86
|
-
Object.keys(source.properties).forEach((key) => {
|
|
87
|
-
const property = targetProperties[key] as Property;
|
|
88
|
-
if (property)
|
|
89
|
-
mergedProperties[key] = mergePropertyOrBuilder(property, sourceProperties[key] as PropertyOrBuilder);
|
|
90
|
-
});
|
|
91
|
-
return { ...mergedProperty, editable: targetEditable && sourceEditable, properties: mergedProperties, propertiesOrder: mergedPropertiesOrder } as MapProperty;
|
|
92
|
-
}
|
|
93
|
-
return { ...mergedProperty, editable: targetEditable && sourceEditable };
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function getCollectionKeys(collection: EntityCollection) {
|
|
98
|
-
if (collection.propertiesOrder && collection.propertiesOrder.length > 0) {
|
|
99
|
-
const propertiesOrder = collection.propertiesOrder;
|
|
100
|
-
if (collection.additionalFields) {
|
|
101
|
-
collection.additionalFields.forEach((field) => {
|
|
102
|
-
if (!propertiesOrder.includes(field.key)) {
|
|
103
|
-
propertiesOrder.push(field.key);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
return propertiesOrder;
|
|
108
|
-
}
|
|
109
|
-
return [
|
|
110
|
-
...Object.keys(collection.properties),
|
|
111
|
-
...(collection.additionalFields ?? [])?.map(f => f.key)
|
|
112
|
-
];
|
|
113
|
-
}
|