@firecms/collection_editor 3.0.0-alpha.16 → 3.0.0-alpha.18

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 (90) hide show
  1. package/dist/ConfigControllerProvider.d.ts +1 -1
  2. package/dist/components/RootCollectionSuggestions.d.ts +1 -0
  3. package/dist/components/collection_editor/CollectionEditorDialog.d.ts +7 -3
  4. package/dist/components/collection_editor/CollectionPropertiesEditorForm.d.ts +5 -3
  5. package/dist/components/collection_editor/EntityCustomViewsSelectDialog.d.ts +4 -0
  6. package/dist/components/collection_editor/PropertyEditView.d.ts +5 -4
  7. package/dist/components/collection_editor/PropertyFieldPreview.d.ts +4 -3
  8. package/dist/components/collection_editor/PropertySelectItem.d.ts +2 -2
  9. package/dist/components/collection_editor/PropertyTree.d.ts +6 -5
  10. package/dist/components/collection_editor/import/CollectionEditorImportMapping.d.ts +3 -1
  11. package/dist/components/collection_editor/properties/BlockPropertyField.d.ts +3 -1
  12. package/dist/components/collection_editor/properties/MapPropertyField.d.ts +3 -1
  13. package/dist/components/collection_editor/properties/RepeatPropertyField.d.ts +3 -1
  14. package/dist/components/collection_editor/utils/update_property_for_widget.d.ts +2 -3
  15. package/dist/index.d.ts +0 -1
  16. package/dist/index.es.js +2221 -1889
  17. package/dist/index.es.js.map +1 -1
  18. package/dist/index.umd.js +1 -1
  19. package/dist/index.umd.js.map +1 -1
  20. package/dist/types/collection_editor_controller.d.ts +6 -1
  21. package/dist/types/config_controller.d.ts +2 -2
  22. package/dist/types/persisted_collection.d.ts +3 -2
  23. package/dist/utils/entities.d.ts +3 -4
  24. package/dist/utils/icons.d.ts +1 -2
  25. package/dist/utils/join_collections.d.ts +14 -0
  26. package/package.json +10 -5
  27. package/src/ConfigControllerProvider.tsx +177 -0
  28. package/src/components/EditorCollectionAction.tsx +95 -0
  29. package/src/components/HomePageEditorCollectionAction.tsx +81 -0
  30. package/src/components/NewCollectionCard.tsx +45 -0
  31. package/src/components/RootCollectionSuggestions.tsx +53 -0
  32. package/src/components/collection_editor/CollectionDetailsForm.tsx +312 -0
  33. package/src/components/collection_editor/CollectionEditorDialog.tsx +640 -0
  34. package/src/components/collection_editor/CollectionEditorWelcomeView.tsx +212 -0
  35. package/src/components/collection_editor/CollectionPropertiesEditorForm.tsx +450 -0
  36. package/src/components/collection_editor/CollectionYupValidation.tsx +6 -0
  37. package/src/components/collection_editor/EntityCustomViewsSelectDialog.tsx +29 -0
  38. package/src/components/collection_editor/EnumForm.tsx +354 -0
  39. package/src/components/collection_editor/PropertyEditView.tsx +535 -0
  40. package/src/components/collection_editor/PropertyFieldPreview.tsx +205 -0
  41. package/src/components/collection_editor/PropertySelectItem.tsx +31 -0
  42. package/src/components/collection_editor/PropertyTree.tsx +228 -0
  43. package/src/components/collection_editor/SelectIcons.tsx +72 -0
  44. package/src/components/collection_editor/SubcollectionsEditTab.tsx +239 -0
  45. package/src/components/collection_editor/UnsavedChangesDialog.tsx +47 -0
  46. package/src/components/collection_editor/import/CollectionEditorImportDataPreview.tsx +37 -0
  47. package/src/components/collection_editor/import/CollectionEditorImportMapping.tsx +236 -0
  48. package/src/components/collection_editor/import/clean_import_data.ts +53 -0
  49. package/src/components/collection_editor/properties/BlockPropertyField.tsx +131 -0
  50. package/src/components/collection_editor/properties/BooleanPropertyField.tsx +36 -0
  51. package/src/components/collection_editor/properties/CommonPropertyFields.tsx +112 -0
  52. package/src/components/collection_editor/properties/DateTimePropertyField.tsx +86 -0
  53. package/src/components/collection_editor/properties/EnumPropertyField.tsx +116 -0
  54. package/src/components/collection_editor/properties/FieldHelperView.tsx +13 -0
  55. package/src/components/collection_editor/properties/KeyValuePropertyField.tsx +20 -0
  56. package/src/components/collection_editor/properties/MapPropertyField.tsx +154 -0
  57. package/src/components/collection_editor/properties/NumberPropertyField.tsx +38 -0
  58. package/src/components/collection_editor/properties/ReferencePropertyField.tsx +184 -0
  59. package/src/components/collection_editor/properties/RepeatPropertyField.tsx +115 -0
  60. package/src/components/collection_editor/properties/StoragePropertyField.tsx +194 -0
  61. package/src/components/collection_editor/properties/StringPropertyField.tsx +85 -0
  62. package/src/components/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +36 -0
  63. package/src/components/collection_editor/properties/validation/ArrayPropertyValidation.tsx +50 -0
  64. package/src/components/collection_editor/properties/validation/GeneralPropertyValidation.tsx +49 -0
  65. package/src/components/collection_editor/properties/validation/NumberPropertyValidation.tsx +99 -0
  66. package/src/components/collection_editor/properties/validation/StringPropertyValidation.tsx +131 -0
  67. package/src/components/collection_editor/properties/validation/ValidationPanel.tsx +28 -0
  68. package/src/components/collection_editor/templates/blog_template.ts +115 -0
  69. package/src/components/collection_editor/templates/products_template.ts +89 -0
  70. package/src/components/collection_editor/templates/users_template.ts +34 -0
  71. package/src/components/collection_editor/util.ts +21 -0
  72. package/src/components/collection_editor/utils/supported_fields.tsx +28 -0
  73. package/src/components/collection_editor/utils/update_property_for_widget.ts +258 -0
  74. package/src/components/collection_editor/utils/useTraceUpdate.tsx +23 -0
  75. package/src/index.ts +31 -0
  76. package/src/types/collection_editor_controller.tsx +31 -0
  77. package/src/types/collection_inference.ts +3 -0
  78. package/src/types/config_controller.tsx +30 -0
  79. package/src/types/config_permissions.ts +20 -0
  80. package/src/types/persisted_collection.ts +7 -0
  81. package/src/useCollectionEditorController.tsx +9 -0
  82. package/src/useCollectionEditorPlugin.tsx +103 -0
  83. package/src/useCollectionsConfigController.tsx +9 -0
  84. package/src/utils/arrays.ts +3 -0
  85. package/src/utils/entities.ts +38 -0
  86. package/src/utils/icons.ts +17 -0
  87. package/src/utils/join_collections.ts +144 -0
  88. package/src/utils/synonyms.ts +1952 -0
  89. package/src/vite-env.d.ts +1 -0
  90. package/dist/types/editable_properties.d.ts +0 -10
@@ -0,0 +1,144 @@
1
+ import {
2
+ EntityCollection,
3
+ isPropertyBuilder, MapProperty,
4
+ mergeDeep,
5
+ PropertiesOrBuilders,
6
+ Property, PropertyOrBuilder,
7
+ sortProperties
8
+ } from "@firecms/core";
9
+ import { PersistedCollection } from "../types/persisted_collection";
10
+
11
+ /**
12
+ *
13
+ * @param storedCollections
14
+ * @param codedCollections
15
+ */
16
+ export function joinCollectionLists(storedCollections: PersistedCollection[], codedCollections: EntityCollection[] | undefined): EntityCollection[] {
17
+ const resolvedFetchedCollections: PersistedCollection[] = storedCollections.map(c => ({
18
+ ...c,
19
+ editable: true,
20
+ deletable: true
21
+ }));
22
+
23
+ // merge collections that are in both lists
24
+ const updatedCollections = (codedCollections ?? [])
25
+ .map((codedCollection) => {
26
+ const storedCollection = resolvedFetchedCollections?.find((collection) => {
27
+ return collection.path === codedCollection.path || (collection.alias && codedCollection.alias && collection.alias === codedCollection.alias);
28
+ });
29
+ if (!storedCollection) {
30
+ return {
31
+ ...codedCollection,
32
+ properties: markPropertiesAsNonEditable(codedCollection.properties as PropertiesOrBuilders),
33
+ deletable: false
34
+ };
35
+ } else {
36
+ Object.values(storedCollection.properties).forEach((property) => {
37
+ property.editable = true
38
+ });
39
+ const mergedCollection = mergeCollections(storedCollection, codedCollection);
40
+ return { ...mergedCollection, deletable: false };
41
+ }
42
+ });
43
+
44
+ // fetched collections that are not in the base collections
45
+ const resultStoredCollections = resolvedFetchedCollections
46
+ .filter((col) => !updatedCollections.map(c => c.path).includes(col.path) || !updatedCollections.map(c => c.alias).includes(col.alias));
47
+
48
+ console.log("Updated collections", { updatedCollections, resultStoredCollections });
49
+
50
+ return [...updatedCollections, ...resultStoredCollections];
51
+ }
52
+
53
+ function markPropertiesAsNonEditable(properties: PropertiesOrBuilders): PropertiesOrBuilders {
54
+ return Object.entries(properties).reduce((acc, [key, property]) => {
55
+ if (!isPropertyBuilder(property) && property.dataType === "map" && property.properties) {
56
+ const updated = { ...property, properties: markPropertiesAsNonEditable(property.properties as PropertiesOrBuilders) };
57
+ acc[key] = updated;
58
+ }
59
+ if (isPropertyBuilder(property)) {
60
+ acc[key] = property;
61
+ } else {
62
+ acc[key] = { ...property, editable: false };
63
+ }
64
+ return acc;
65
+ }, {} as PropertiesOrBuilders);
66
+
67
+ }
68
+
69
+ /**
70
+ *
71
+ * @param target
72
+ * @param source
73
+ */
74
+ export function mergeCollections(target: EntityCollection, source: EntityCollection): EntityCollection {
75
+ const subcollectionsMerged = target.subcollections?.map((targetSubcollection) => {
76
+ const modifiedCollection =
77
+ source.subcollections?.find((sourceSubcollection) => sourceSubcollection.path === targetSubcollection.path) ??
78
+ source.subcollections?.find((sourceSubcollection) => sourceSubcollection.alias === targetSubcollection.alias);
79
+
80
+ if (!modifiedCollection) {
81
+ return targetSubcollection;
82
+ } else {
83
+ return mergeCollections(targetSubcollection, modifiedCollection);
84
+ }
85
+ });
86
+
87
+ const propertiesMerged: PropertiesOrBuilders = { ...target.properties } as PropertiesOrBuilders;
88
+ Object.keys(source.properties).forEach((key) => {
89
+ const property = target.properties[key] as Property;
90
+ if (property)
91
+ propertiesMerged[key] = mergePropertyOrBuilder(property, source.properties[key] as PropertyOrBuilder);
92
+ else
93
+ propertiesMerged[key] = source.properties[key] as PropertyOrBuilder;
94
+ });
95
+
96
+ const mergedCollection = mergeDeep(target, source);
97
+ const targetPropertiesOrder = getCollectionKeys(target);
98
+ const sourcePropertiesOrder = getCollectionKeys(source);
99
+ const mergedPropertiesOrder = [...new Set([...targetPropertiesOrder, ...sourcePropertiesOrder])];
100
+ const mergedEntityViews = [...new Set([...(target.entityViews ?? []), ...(source.entityViews ?? [])])];
101
+
102
+ return {
103
+ ...mergedCollection,
104
+ subcollections: subcollectionsMerged,
105
+ properties: sortProperties(propertiesMerged, mergedPropertiesOrder),
106
+ propertiesOrder: mergedPropertiesOrder,
107
+ entityViews: mergedEntityViews
108
+ }
109
+ }
110
+
111
+ function mergePropertyOrBuilder(target: Property, source: PropertyOrBuilder): PropertyOrBuilder {
112
+ if (isPropertyBuilder(source)) {
113
+ return source;
114
+ } else {
115
+ const mergedProperty = mergeDeep(target, source);
116
+ const targetEditable = Boolean(target.editable);
117
+ const sourceEditable = Boolean(source.editable);
118
+ if (source.dataType === "map" && source.properties) {
119
+ const targetProperties = ("properties" in target ? target.properties : {}) as PropertiesOrBuilders;
120
+ const sourceProperties = ("properties" in source ? source.properties : {}) as PropertiesOrBuilders;
121
+ const targetPropertiesOrder = "propertiesOrder" in target && target.propertiesOrder ? target.propertiesOrder : Object.keys(targetProperties);
122
+ const sourcePropertiesOrder = "propertiesOrder" in source && source.propertiesOrder ? source.propertiesOrder : ("properties" in source ? Object.keys(source.properties) : []);
123
+ const mergedPropertiesOrder = [...new Set([...targetPropertiesOrder, ...sourcePropertiesOrder])];
124
+ const mergedProperties: PropertiesOrBuilders = { ...targetProperties } as PropertiesOrBuilders;
125
+ Object.keys(source.properties).forEach((key) => {
126
+ const property = targetProperties[key] as Property;
127
+ if (property)
128
+ mergedProperties[key] = mergePropertyOrBuilder(property, sourceProperties[key] as PropertyOrBuilder);
129
+ });
130
+ return { ...mergedProperty, editable: targetEditable && sourceEditable, properties: mergedProperties, propertiesOrder: mergedPropertiesOrder } as MapProperty;
131
+ }
132
+ return { ...mergedProperty, editable: targetEditable && sourceEditable };
133
+ }
134
+ }
135
+
136
+ function getCollectionKeys(collection: EntityCollection) {
137
+ if (collection.propertiesOrder && collection.propertiesOrder.length > 0) {
138
+ return collection.propertiesOrder;
139
+ }
140
+ return [
141
+ ...Object.keys(collection.properties),
142
+ ...(collection.additionalFields ?? [])?.map(f => f.id)
143
+ ];
144
+ }