@firecms/collection_editor 3.0.0-alpha.9 → 3.0.0-beta.2-pre.1

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 (145) hide show
  1. package/dist/ConfigControllerProvider.d.ts +3 -2
  2. package/dist/index.d.ts +3 -2
  3. package/dist/index.es.js +3128 -4094
  4. package/dist/index.es.js.map +1 -1
  5. package/dist/index.umd.js +3 -1
  6. package/dist/index.umd.js.map +1 -1
  7. package/dist/types/collection_editor_controller.d.ts +22 -7
  8. package/dist/types/collection_inference.d.ts +1 -1
  9. package/dist/types/config_controller.d.ts +32 -5
  10. package/dist/types/persisted_collection.d.ts +3 -1
  11. package/dist/ui/CollectionViewHeaderAction.d.ts +10 -0
  12. package/dist/{components → ui}/EditorCollectionAction.d.ts +1 -1
  13. package/dist/ui/MissingReferenceWidget.d.ts +3 -0
  14. package/dist/ui/NewCollectionButton.d.ts +1 -0
  15. package/dist/ui/PropertyAddColumnComponent.d.ts +6 -0
  16. package/dist/ui/RootCollectionSuggestions.d.ts +1 -0
  17. package/dist/{components → ui}/collection_editor/CollectionDetailsForm.d.ts +3 -2
  18. package/dist/{components → ui}/collection_editor/CollectionEditorDialog.d.ts +11 -6
  19. package/dist/{components → ui}/collection_editor/CollectionPropertiesEditorForm.d.ts +6 -3
  20. package/dist/{components → ui}/collection_editor/CollectionYupValidation.d.ts +3 -0
  21. package/dist/ui/collection_editor/EntityCustomViewsSelectDialog.d.ts +4 -0
  22. package/dist/ui/collection_editor/GetCodeDialog.d.ts +5 -0
  23. package/dist/{components → ui}/collection_editor/PropertyEditView.d.ts +8 -6
  24. package/dist/{components → ui}/collection_editor/PropertyFieldPreview.d.ts +4 -3
  25. package/dist/ui/collection_editor/PropertySelectItem.d.ts +8 -0
  26. package/dist/{components → ui}/collection_editor/PropertyTree.d.ts +8 -5
  27. package/dist/{components → ui}/collection_editor/SubcollectionsEditTab.d.ts +2 -2
  28. package/dist/{components → ui}/collection_editor/import/CollectionEditorImportDataPreview.d.ts +1 -1
  29. package/dist/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +7 -0
  30. package/dist/{components → ui}/collection_editor/import/clean_import_data.d.ts +1 -1
  31. package/dist/{components → ui}/collection_editor/properties/BlockPropertyField.d.ts +4 -1
  32. package/dist/{components → ui}/collection_editor/properties/CommonPropertyFields.d.ts +1 -0
  33. package/dist/{components → ui}/collection_editor/properties/MapPropertyField.d.ts +4 -1
  34. package/dist/{components → ui}/collection_editor/properties/RepeatPropertyField.d.ts +4 -1
  35. package/dist/{components → ui}/collection_editor/properties/StringPropertyField.d.ts +1 -1
  36. package/dist/ui/collection_editor/properties/UrlPropertyField.d.ts +4 -0
  37. package/dist/ui/collection_editor/templates/blog_template.d.ts +2 -0
  38. package/dist/ui/collection_editor/templates/pages_template.d.ts +2 -0
  39. package/dist/ui/collection_editor/templates/products_template.d.ts +2 -0
  40. package/dist/ui/collection_editor/templates/users_template.d.ts +2 -0
  41. package/dist/ui/collection_editor/utils/strings.d.ts +1 -0
  42. package/dist/ui/collection_editor/utils/supported_fields.d.ts +3 -0
  43. package/dist/ui/collection_editor/utils/update_property_for_widget.d.ts +2 -0
  44. package/dist/useCollectionEditorPlugin.d.ts +5 -3
  45. package/dist/utils/entities.d.ts +3 -4
  46. package/package.json +22 -19
  47. package/src/ConfigControllerProvider.tsx +336 -0
  48. package/src/index.ts +35 -0
  49. package/src/types/collection_editor_controller.tsx +42 -0
  50. package/src/types/collection_inference.ts +3 -0
  51. package/src/types/config_controller.tsx +60 -0
  52. package/src/types/config_permissions.ts +20 -0
  53. package/src/types/persisted_collection.ts +9 -0
  54. package/src/ui/CollectionViewHeaderAction.tsx +43 -0
  55. package/src/ui/EditorCollectionAction.tsx +109 -0
  56. package/src/ui/HomePageEditorCollectionAction.tsx +84 -0
  57. package/src/ui/MissingReferenceWidget.tsx +35 -0
  58. package/src/ui/NewCollectionButton.tsx +16 -0
  59. package/src/ui/NewCollectionCard.tsx +47 -0
  60. package/src/ui/PropertyAddColumnComponent.tsx +42 -0
  61. package/src/ui/RootCollectionSuggestions.tsx +55 -0
  62. package/src/ui/collection_editor/CollectionDetailsForm.tsx +366 -0
  63. package/src/ui/collection_editor/CollectionEditorDialog.tsx +754 -0
  64. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +206 -0
  65. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +481 -0
  66. package/src/ui/collection_editor/CollectionYupValidation.tsx +7 -0
  67. package/src/ui/collection_editor/EntityCustomViewsSelectDialog.tsx +37 -0
  68. package/src/ui/collection_editor/EnumForm.tsx +354 -0
  69. package/src/ui/collection_editor/GetCodeDialog.tsx +110 -0
  70. package/src/ui/collection_editor/PropertyEditView.tsx +558 -0
  71. package/src/ui/collection_editor/PropertyFieldPreview.tsx +203 -0
  72. package/src/ui/collection_editor/PropertySelectItem.tsx +32 -0
  73. package/src/ui/collection_editor/PropertyTree.tsx +233 -0
  74. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +253 -0
  75. package/src/ui/collection_editor/UnsavedChangesDialog.tsx +47 -0
  76. package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +37 -0
  77. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +260 -0
  78. package/src/ui/collection_editor/import/clean_import_data.ts +53 -0
  79. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +135 -0
  80. package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +36 -0
  81. package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +137 -0
  82. package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +87 -0
  83. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +117 -0
  84. package/src/ui/collection_editor/properties/FieldHelperView.tsx +13 -0
  85. package/src/ui/collection_editor/properties/KeyValuePropertyField.tsx +20 -0
  86. package/src/ui/collection_editor/properties/MapPropertyField.tsx +149 -0
  87. package/src/ui/collection_editor/properties/NumberPropertyField.tsx +38 -0
  88. package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +165 -0
  89. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +108 -0
  90. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +194 -0
  91. package/src/ui/collection_editor/properties/StringPropertyField.tsx +79 -0
  92. package/src/ui/collection_editor/properties/UrlPropertyField.tsx +89 -0
  93. package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +36 -0
  94. package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +50 -0
  95. package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +50 -0
  96. package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +100 -0
  97. package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +132 -0
  98. package/src/ui/collection_editor/properties/validation/ValidationPanel.tsx +28 -0
  99. package/src/ui/collection_editor/templates/blog_template.ts +115 -0
  100. package/src/ui/collection_editor/templates/pages_template.ts +188 -0
  101. package/src/ui/collection_editor/templates/products_template.ts +88 -0
  102. package/src/ui/collection_editor/templates/users_template.ts +42 -0
  103. package/src/ui/collection_editor/util.ts +21 -0
  104. package/src/ui/collection_editor/utils/strings.ts +8 -0
  105. package/src/ui/collection_editor/utils/supported_fields.tsx +29 -0
  106. package/src/ui/collection_editor/utils/update_property_for_widget.ts +271 -0
  107. package/src/ui/collection_editor/utils/useTraceUpdate.tsx +23 -0
  108. package/src/useCollectionEditorController.tsx +9 -0
  109. package/src/useCollectionEditorPlugin.tsx +137 -0
  110. package/src/useCollectionsConfigController.tsx +9 -0
  111. package/src/utils/arrays.ts +3 -0
  112. package/src/utils/entities.ts +38 -0
  113. package/src/vite-env.d.ts +1 -0
  114. package/dist/components/collection_editor/PropertySelectItem.d.ts +0 -8
  115. package/dist/components/collection_editor/SelectIcons.d.ts +0 -6
  116. package/dist/components/collection_editor/import/CollectionEditorImportMapping.d.ts +0 -4
  117. package/dist/components/collection_editor/templates/blog_template.d.ts +0 -10
  118. package/dist/components/collection_editor/templates/products_template.d.ts +0 -12
  119. package/dist/components/collection_editor/templates/users_template.d.ts +0 -7
  120. package/dist/components/collection_editor/utils/supported_fields.d.ts +0 -3
  121. package/dist/components/collection_editor/utils/update_property_for_widget.d.ts +0 -3
  122. package/dist/types/editable_properties.d.ts +0 -10
  123. package/dist/utils/icons.d.ts +0 -2
  124. package/dist/utils/synonyms.d.ts +0 -1951
  125. /package/dist/{components → ui}/HomePageEditorCollectionAction.d.ts +0 -0
  126. /package/dist/{components → ui}/NewCollectionCard.d.ts +0 -0
  127. /package/dist/{components → ui}/collection_editor/CollectionEditorWelcomeView.d.ts +0 -0
  128. /package/dist/{components → ui}/collection_editor/EnumForm.d.ts +0 -0
  129. /package/dist/{components → ui}/collection_editor/UnsavedChangesDialog.d.ts +0 -0
  130. /package/dist/{components → ui}/collection_editor/properties/BooleanPropertyField.d.ts +0 -0
  131. /package/dist/{components → ui}/collection_editor/properties/DateTimePropertyField.d.ts +0 -0
  132. /package/dist/{components → ui}/collection_editor/properties/EnumPropertyField.d.ts +0 -0
  133. /package/dist/{components → ui}/collection_editor/properties/FieldHelperView.d.ts +0 -0
  134. /package/dist/{components → ui}/collection_editor/properties/KeyValuePropertyField.d.ts +0 -0
  135. /package/dist/{components → ui}/collection_editor/properties/NumberPropertyField.d.ts +0 -0
  136. /package/dist/{components → ui}/collection_editor/properties/ReferencePropertyField.d.ts +0 -0
  137. /package/dist/{components → ui}/collection_editor/properties/StoragePropertyField.d.ts +0 -0
  138. /package/dist/{components → ui}/collection_editor/properties/advanced/AdvancedPropertyValidation.d.ts +0 -0
  139. /package/dist/{components → ui}/collection_editor/properties/validation/ArrayPropertyValidation.d.ts +0 -0
  140. /package/dist/{components → ui}/collection_editor/properties/validation/GeneralPropertyValidation.d.ts +0 -0
  141. /package/dist/{components → ui}/collection_editor/properties/validation/NumberPropertyValidation.d.ts +0 -0
  142. /package/dist/{components → ui}/collection_editor/properties/validation/StringPropertyValidation.d.ts +0 -0
  143. /package/dist/{components → ui}/collection_editor/properties/validation/ValidationPanel.d.ts +0 -0
  144. /package/dist/{components → ui}/collection_editor/util.d.ts +0 -0
  145. /package/dist/{components → ui}/collection_editor/utils/useTraceUpdate.d.ts +0 -0
@@ -0,0 +1,137 @@
1
+ import React from "react";
2
+ import {
3
+ EntityCollection,
4
+ FireCMSPlugin,
5
+ joinCollectionLists,
6
+ makePropertiesEditable,
7
+ ModifyCollectionProps,
8
+ Properties,
9
+ User
10
+ } from "@firecms/core";
11
+ import { ConfigControllerProvider } from "./ConfigControllerProvider";
12
+ import { CollectionEditorPermissionsBuilder } from "./types/config_permissions";
13
+ import { EditorCollectionAction } from "./ui/EditorCollectionAction";
14
+ import { HomePageEditorCollectionAction } from "./ui/HomePageEditorCollectionAction";
15
+ import { NewCollectionCard } from "./ui/NewCollectionCard";
16
+ import { PersistedCollection } from "./types/persisted_collection";
17
+ import { CollectionInference } from "./types/collection_inference";
18
+ import { CollectionsConfigController } from "./types/config_controller";
19
+ import { RootCollectionSuggestions } from "./ui/RootCollectionSuggestions";
20
+ import { CollectionViewHeaderAction } from "./ui/CollectionViewHeaderAction";
21
+ import { PropertyAddColumnComponent } from "./ui/PropertyAddColumnComponent";
22
+ import { NewCollectionButton } from "./ui/NewCollectionButton";
23
+
24
+ export interface CollectionConfigControllerProps<EC extends PersistedCollection = PersistedCollection, UserType extends User = User> {
25
+
26
+ /**
27
+ * Firebase app where the configuration is saved.
28
+ */
29
+ collectionConfigController: CollectionsConfigController;
30
+
31
+ modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void;
32
+
33
+ /**
34
+ * Define what actions can be performed on the configuration.
35
+ */
36
+ configPermissions?: CollectionEditorPermissionsBuilder<UserType, EC>;
37
+
38
+ /**
39
+ * The words you define here will not be allowed to be used as group
40
+ * names when creating collections.
41
+ * e.g. ["admin"]
42
+ */
43
+ reservedGroups: string[];
44
+
45
+ extraView?: {
46
+ View: React.ComponentType<{
47
+ path: string
48
+ }>,
49
+ icon: React.ReactNode
50
+ };
51
+
52
+ pathSuggestions?: (path: string) => Promise<string[]>;
53
+
54
+ collectionInference?: CollectionInference;
55
+
56
+ getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
57
+
58
+ getUser: (uid: string) => UserType | null;
59
+
60
+ onAnalyticsEvent?: (event: string, params?: object) => void;
61
+
62
+ }
63
+
64
+ /**
65
+ * Use this hook to initialise the Collection Editor plugin.
66
+ * This is likely the only hook you will need to use.
67
+ * @param firebaseApp Firebase app where your project data lives.
68
+ * @param configPermissions
69
+ * @param reservedGroups
70
+ * @param extraView
71
+ * @param pathSuggestions
72
+ * @param getUser
73
+ * @param collectionInference
74
+ */
75
+ export function useCollectionEditorPlugin<EC extends PersistedCollection = PersistedCollection, UserType extends User = User>
76
+ ({
77
+ collectionConfigController,
78
+ modifyCollection,
79
+ configPermissions,
80
+ reservedGroups,
81
+ extraView,
82
+ pathSuggestions,
83
+ getUser,
84
+ collectionInference,
85
+ getData,
86
+ onAnalyticsEvent
87
+ }: CollectionConfigControllerProps<EC, UserType>): FireCMSPlugin<any, any, PersistedCollection> {
88
+
89
+ const injectCollections = (baseCollections: EntityCollection[]) => {
90
+
91
+ const markAsEditable = (c: PersistedCollection) => {
92
+ makePropertiesEditable(c.properties as Properties);
93
+ c.subcollections?.forEach(markAsEditable);
94
+ };
95
+ const storedCollections = collectionConfigController.collections ?? [];
96
+ storedCollections.forEach(markAsEditable);
97
+
98
+ console.debug("Collections specified in code:", baseCollections);
99
+ console.debug("Collections stored in the backend", storedCollections);
100
+ const result = joinCollectionLists(baseCollections, storedCollections, [], modifyCollection);
101
+ console.debug("Collections after joining:", result);
102
+ return result;
103
+ };
104
+
105
+ return {
106
+ name: "Collection Editor",
107
+ loading: collectionConfigController.loading,
108
+ collections: {
109
+ injectCollections,
110
+ CollectionActions: EditorCollectionAction
111
+ },
112
+ provider: {
113
+ Component: ConfigControllerProvider,
114
+ props: {
115
+ collectionConfigController,
116
+ configPermissions,
117
+ collectionInference,
118
+ reservedGroups,
119
+ extraView,
120
+ pathSuggestions,
121
+ getUser,
122
+ getData,
123
+ onAnalyticsEvent
124
+ }
125
+ },
126
+ homePage: {
127
+ additionalActions: <NewCollectionButton/>,
128
+ additionalChildrenEnd: <RootCollectionSuggestions/>,
129
+ CollectionActions: HomePageEditorCollectionAction,
130
+ AdditionalCards: NewCollectionCard,
131
+ },
132
+ collectionView: {
133
+ HeaderAction: CollectionViewHeaderAction,
134
+ AddColumnComponent: PropertyAddColumnComponent
135
+ }
136
+ };
137
+ }
@@ -0,0 +1,9 @@
1
+ import { useContext } from "react";
2
+ import { CollectionsConfigController } from "./types/config_controller";
3
+ import { ConfigControllerContext } from "./ConfigControllerProvider";
4
+
5
+ /**
6
+ * Use this hook to access the configuration controller.
7
+ * You can use it to get the list of collections, and to save/delete collections.
8
+ */
9
+ export const useCollectionsConfigController = (): CollectionsConfigController => useContext(ConfigControllerContext);
@@ -0,0 +1,3 @@
1
+ export function toArray<T>(input?: T | T[]):T[] {
2
+ return Array.isArray(input) ? input : (input ? [input] : []);
3
+ }
@@ -0,0 +1,38 @@
1
+ import { isPropertyBuilder, Properties, PropertiesOrBuilders, Property, PropertyOrBuilder } from "@firecms/core";
2
+
3
+ export function editableProperty(property: PropertyOrBuilder | PropertyOrBuilder): boolean {
4
+ if (isPropertyBuilder(property))
5
+ return false;
6
+ if (isPropertyBuilder(property as PropertyOrBuilder))
7
+ return false;
8
+ else {
9
+ const eProperty = property as Property;
10
+ if (eProperty.dataType === "array" && typeof eProperty.of === "function")
11
+ return false;
12
+ else if (eProperty.dataType === "array" && Array.isArray(eProperty.of))
13
+ return false;
14
+ return Boolean(eProperty.editable);
15
+ }
16
+ }
17
+
18
+ export function removeNonEditableProperties(properties: PropertiesOrBuilders<any>): Properties {
19
+ return Object.entries(properties)
20
+ .filter(([_, property]) => editableProperty(property))
21
+ .map(([key, propertyOrBuilder]) => {
22
+ const property = propertyOrBuilder as Property;
23
+ if (!editableProperty(property)) {
24
+ return undefined;
25
+ } else if (property.dataType === "map" && property.properties) {
26
+ return {
27
+ [key]: {
28
+ ...property,
29
+ properties: removeNonEditableProperties(property.properties as PropertiesOrBuilders)
30
+ }
31
+ };
32
+ } else {
33
+ return { [key]: property };
34
+ }
35
+ })
36
+ .filter((e) => Boolean(e))
37
+ .reduce((a, b) => ({ ...a, ...b }), {}) as Properties;
38
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -1,8 +0,0 @@
1
- import { FieldConfig } from "@firecms/core";
2
- export interface PropertySelectItemProps {
3
- value: string;
4
- optionDisabled: boolean;
5
- widget: FieldConfig;
6
- existing: boolean;
7
- }
8
- export declare function PropertySelectItem({ value, optionDisabled, widget, existing }: PropertySelectItemProps): import("react/jsx-runtime").JSX.Element;
@@ -1,6 +0,0 @@
1
- interface SearchIconsProps {
2
- selectedIcon?: string;
3
- onIconSelected: (icon: string) => void;
4
- }
5
- export declare function SearchIcons({ selectedIcon, onIconSelected }: SearchIconsProps): import("react/jsx-runtime").JSX.Element;
6
- export {};
@@ -1,4 +0,0 @@
1
- import { ImportConfig } from "@firecms/data_import";
2
- export declare function CollectionEditorImportMapping({ importConfig }: {
3
- importConfig: ImportConfig;
4
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +0,0 @@
1
- export declare const blogCollectionTemplate: import("@firecms/core").EntityCollection<{
2
- name: string;
3
- header_image: string;
4
- content: any[];
5
- created_on: unknown;
6
- status: unknown;
7
- publish_date: unknown;
8
- reviewed: unknown;
9
- tags: unknown;
10
- }, string, import("@firecms/core").User>;
@@ -1,12 +0,0 @@
1
- export declare const productsCollectionTemplate: import("@firecms/core").EntityCollection<{
2
- name: unknown;
3
- brand: unknown;
4
- description: unknown;
5
- main_image: unknown;
6
- available: unknown;
7
- price: unknown;
8
- images: unknown;
9
- related_products: unknown;
10
- metadata: unknown;
11
- added_on: unknown;
12
- }, string, import("@firecms/core").User>;
@@ -1,7 +0,0 @@
1
- export declare const usersCollectionTemplate: import("@firecms/core").EntityCollection<{
2
- displayName: unknown;
3
- email: unknown;
4
- emailVerified: unknown;
5
- phone: unknown;
6
- photoURL: unknown;
7
- }, string, import("@firecms/core").User>;
@@ -1,3 +0,0 @@
1
- import { FieldConfigId } from "@firecms/core";
2
- export declare const supportedFieldsIds: FieldConfigId[];
3
- export declare const supportedFields: [string, import("@firecms/core").FieldConfig<any>][];
@@ -1,3 +0,0 @@
1
- import { FieldConfigId } from "@firecms/core";
2
- import { EditableProperty } from "../../../types/editable_properties";
3
- export declare function updatePropertyFromWidget(propertyData: any, selectedWidgetId: FieldConfigId | undefined): EditableProperty;
@@ -1,10 +0,0 @@
1
- import { CMSType, Property, PropertyBuilderProps, ResolvedProperty } from "@firecms/core";
2
- export type EditablePropertyOrBuilder = EditableProperty | EditablePropertyBuilder;
3
- export type EditableProperty = Property & {
4
- editable: boolean;
5
- };
6
- export type EditablePropertyBuilder<T extends CMSType = any, M extends Record<string, any> = any> = ({ values, previousValues, propertyValue, path, entityId }: PropertyBuilderProps<M>) => EditableProperty | null;
7
- export type EditablePropertiesOrBuilders<M extends Record<string, any> = Record<string, any>> = {
8
- [k in keyof M]: EditablePropertyOrBuilder;
9
- };
10
- export declare function isEditablePropertyBuilder<T extends CMSType, M extends Record<string, any>>(propertyOrBuilder?: EditablePropertyOrBuilder | ResolvedProperty<T>): propertyOrBuilder is EditablePropertyBuilder;
@@ -1,2 +0,0 @@
1
- import Index from "flexsearch";
2
- export declare const searchIndex: Index;