@firecms/collection_editor 3.0.0-alpha.34 → 3.0.0-alpha.36
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 +1516 -1465
- 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 +3 -3
- package/dist/types/persisted_collection.d.ts +2 -3
- package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +2 -1
- package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +2 -2
- package/dist/ui/collection_editor/PropertyEditView.d.ts +1 -1
- package/dist/ui/collection_editor/PropertyTree.d.ts +2 -2
- package/dist/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +2 -2
- package/dist/ui/collection_editor/properties/BlockPropertyField.d.ts +2 -2
- package/dist/ui/collection_editor/properties/MapPropertyField.d.ts +2 -2
- package/dist/ui/collection_editor/properties/RepeatPropertyField.d.ts +2 -2
- 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/dist/ui/collection_editor/utils/update_property_for_widget.d.ts +1 -1
- package/package.json +5 -5
- package/src/ConfigControllerProvider.tsx +6 -6
- package/src/types/collection_editor_controller.tsx +2 -2
- package/src/types/persisted_collection.ts +2 -2
- package/src/ui/EditorCollectionAction.tsx +1 -1
- package/src/ui/RootCollectionSuggestions.tsx +1 -1
- package/src/ui/collection_editor/CollectionDetailsForm.tsx +52 -1
- package/src/ui/collection_editor/CollectionEditorDialog.tsx +85 -33
- package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +15 -15
- package/src/ui/collection_editor/EntityCustomViewsSelectDialog.tsx +3 -1
- package/src/ui/collection_editor/PropertyEditView.tsx +18 -15
- package/src/ui/collection_editor/PropertyFieldPreview.tsx +4 -4
- package/src/ui/collection_editor/PropertyTree.tsx +3 -2
- package/src/ui/collection_editor/SubcollectionsEditTab.tsx +1 -1
- package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +9 -11
- package/src/ui/collection_editor/properties/BlockPropertyField.tsx +3 -3
- package/src/ui/collection_editor/properties/MapPropertyField.tsx +4 -4
- package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +1 -0
- package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +4 -6
- 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/ui/collection_editor/utils/update_property_for_widget.ts +6 -3
- package/src/useCollectionEditorPlugin.tsx +10 -5
- package/dist/utils/join_collections.d.ts +0 -13
- package/src/utils/join_collections.ts +0 -113
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { EntityCollection } from "@firecms/core";
|
|
1
|
+
import { EntityCollection, makePropertiesEditable } from "@firecms/core";
|
|
2
2
|
|
|
3
3
|
export const usersCollectionTemplate: EntityCollection = {
|
|
4
4
|
path: "users",
|
|
5
5
|
name: "Users",
|
|
6
6
|
singularName: "User",
|
|
7
|
-
group: "Main",
|
|
8
7
|
description: "Registered users in the app/web",
|
|
9
8
|
icon: "person",
|
|
10
|
-
properties: {
|
|
9
|
+
properties: makePropertiesEditable({
|
|
11
10
|
displayName: {
|
|
12
11
|
name: "Display name",
|
|
13
12
|
dataType: "string"
|
|
@@ -30,5 +29,5 @@ export const usersCollectionTemplate: EntityCollection = {
|
|
|
30
29
|
dataType: "string",
|
|
31
30
|
url: "image"
|
|
32
31
|
}
|
|
33
|
-
},
|
|
32
|
+
}),
|
|
34
33
|
};
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
|
|
13
13
|
export function updatePropertyFromWidget(propertyData: any,
|
|
14
14
|
selectedWidgetId: string | undefined,
|
|
15
|
-
|
|
15
|
+
propertyConfigs: Record<string, PropertyConfig>): Property {
|
|
16
16
|
|
|
17
17
|
let updatedProperty;
|
|
18
18
|
if (selectedWidgetId === "text_field") {
|
|
@@ -260,8 +260,11 @@ export function updatePropertyFromWidget(propertyData: any,
|
|
|
260
260
|
}
|
|
261
261
|
} satisfies ArrayProperty
|
|
262
262
|
);
|
|
263
|
-
} else if (selectedWidgetId &&
|
|
264
|
-
updatedProperty = {
|
|
263
|
+
} else if (selectedWidgetId && propertyConfigs[selectedWidgetId]) {
|
|
264
|
+
updatedProperty = {
|
|
265
|
+
...propertyConfigs[selectedWidgetId].property,
|
|
266
|
+
propertyConfig: selectedWidgetId
|
|
267
|
+
};
|
|
265
268
|
}
|
|
266
269
|
|
|
267
270
|
return updatedProperty;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import React, { useCallback } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
EntityCollection,
|
|
4
|
+
FireCMSPlugin,
|
|
5
|
+
joinCollectionLists,
|
|
6
|
+
makePropertiesEditable,
|
|
7
|
+
Properties,
|
|
8
|
+
User
|
|
9
|
+
} from "@firecms/core";
|
|
3
10
|
import { ConfigControllerProvider } from "./ConfigControllerProvider";
|
|
4
11
|
import { CollectionEditorPermissionsBuilder } from "./types/config_permissions";
|
|
5
12
|
import { EditorCollectionAction } from "./ui/EditorCollectionAction";
|
|
@@ -9,7 +16,6 @@ import { PersistedCollection } from "./types/persisted_collection";
|
|
|
9
16
|
import { CollectionInference } from "./types/collection_inference";
|
|
10
17
|
import { CollectionsConfigController } from "./types/config_controller";
|
|
11
18
|
import { RootCollectionSuggestions } from "./ui/RootCollectionSuggestions";
|
|
12
|
-
import { joinCollectionLists } from "./utils/join_collections";
|
|
13
19
|
import { CollectionViewHeaderAction } from "./ui/CollectionViewHeaderAction";
|
|
14
20
|
import { PropertyAddColumnComponent } from "./ui/PropertyAddColumnComponent";
|
|
15
21
|
|
|
@@ -75,12 +81,11 @@ export function useCollectionEditorPlugin<EC extends PersistedCollection = Persi
|
|
|
75
81
|
const injectCollections = useCallback(
|
|
76
82
|
(collections: EntityCollection[]) => {
|
|
77
83
|
const markAsEditable = (c: PersistedCollection) => {
|
|
78
|
-
makePropertiesEditable(c.properties);
|
|
84
|
+
makePropertiesEditable(c.properties as Properties);
|
|
79
85
|
c.subcollections?.forEach(markAsEditable);
|
|
80
86
|
};
|
|
81
87
|
const editableCollections = collectionConfigController.collections ?? [];
|
|
82
88
|
editableCollections.forEach(markAsEditable);
|
|
83
|
-
console.debug("Injecting collections", { editableCollections, collections });
|
|
84
89
|
return joinCollectionLists(editableCollections, collections);
|
|
85
90
|
},
|
|
86
91
|
[collectionConfigController.collections]);
|
|
@@ -106,7 +111,7 @@ export function useCollectionEditorPlugin<EC extends PersistedCollection = Persi
|
|
|
106
111
|
}
|
|
107
112
|
},
|
|
108
113
|
homePage: {
|
|
109
|
-
|
|
114
|
+
additionalChildrenEnd: <RootCollectionSuggestions/>,
|
|
110
115
|
CollectionActions: HomePageEditorCollectionAction,
|
|
111
116
|
AdditionalCards: NewCollectionCard,
|
|
112
117
|
},
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { EntityCollection } from "@firecms/core";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param storedCollections
|
|
5
|
-
* @param codedCollections
|
|
6
|
-
*/
|
|
7
|
-
export declare function joinCollectionLists(storedCollections: EntityCollection[], codedCollections: EntityCollection[] | undefined): EntityCollection[];
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param target
|
|
11
|
-
* @param source
|
|
12
|
-
*/
|
|
13
|
-
export declare function mergeCollection(target: EntityCollection, source: EntityCollection): EntityCollection;
|
|
@@ -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
|
-
}
|