@firecms/collection_editor 3.0.0-canary.240 → 3.0.0-canary.241
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/README.md
CHANGED
|
@@ -1 +1,165 @@
|
|
|
1
|
-
|
|
1
|
+
# FireCMS Collection Editor Plugin
|
|
2
|
+
|
|
3
|
+
This plugin enables creating and managing Firestore collections directly from your FireCMS interface. It adds a visual
|
|
4
|
+
collection editor that allows you to create, edit, and delete collections without writing code.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @firecms/collection_editor
|
|
10
|
+
# or
|
|
11
|
+
yarn add @firecms/collection_editor
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
For Firebase integration, also install:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @firecms/collection_editor_firebase
|
|
18
|
+
# or
|
|
19
|
+
yarn add @firecms/collection_editor_firebase
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- Create and edit collections through a visual interface
|
|
25
|
+
- Define properties, validations, and display options
|
|
26
|
+
- Organize collections with groups and subcollections
|
|
27
|
+
- Merge UI-defined collections with code-defined collections
|
|
28
|
+
- Persist collection configurations in Firestore
|
|
29
|
+
- Control permissions for collection editing operations
|
|
30
|
+
|
|
31
|
+
## Basic Usage
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import React from "react";
|
|
35
|
+
import { FireCMS } from "@firecms/core";
|
|
36
|
+
import { useCollectionEditorPlugin } from "@firecms/collection_editor";
|
|
37
|
+
import { useFirestoreCollectionsConfigController } from "@firecms/collection_editor_firebase";
|
|
38
|
+
|
|
39
|
+
export default function App() {
|
|
40
|
+
// Controller to save collection configs in Firestore
|
|
41
|
+
const collectionConfigController = useFirestoreCollectionsConfigController({
|
|
42
|
+
firebaseApp
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Initialize the collection editor plugin
|
|
46
|
+
const collectionEditorPlugin = useCollectionEditorPlugin({
|
|
47
|
+
collectionConfigController
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const navigationController = useBuildNavigationController({
|
|
51
|
+
// Your other config options
|
|
52
|
+
plugins: [collectionEditorPlugin]
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return <FireCMS
|
|
56
|
+
name={"My CMS"}
|
|
57
|
+
navigationController={navigationController}
|
|
58
|
+
authentication={myAuthenticator}
|
|
59
|
+
firebaseConfig={firebaseConfig}
|
|
60
|
+
/>;
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Advanced Configuration
|
|
65
|
+
|
|
66
|
+
You can customize collection editor behavior with these options:
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
const collectionEditorPlugin = useCollectionEditorPlugin({
|
|
70
|
+
collectionConfigController, // Required: controller that handles persistence
|
|
71
|
+
|
|
72
|
+
// Define permissions for collection operations
|
|
73
|
+
configPermissions: ({ user }) => ({
|
|
74
|
+
createCollections: user.roles?.includes("admin") ?? false,
|
|
75
|
+
editCollections: user.roles?.includes("admin") ?? false,
|
|
76
|
+
deleteCollections: user.roles?.includes("admin") ?? false
|
|
77
|
+
}),
|
|
78
|
+
|
|
79
|
+
// Prevent these group names from being used
|
|
80
|
+
reservedGroups: ["admin", "system"],
|
|
81
|
+
|
|
82
|
+
// Optional custom view to add to the editor
|
|
83
|
+
extraView: {
|
|
84
|
+
View: MyCustomView,
|
|
85
|
+
icon: <CustomIcon />
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
// Function to infer collection structure from existing data
|
|
89
|
+
collectionInference: async ({ path }) => {
|
|
90
|
+
// Return inferred schema based on data at path
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
// Function to get sample data for a collection
|
|
94
|
+
getData: async (path, parentPaths) => {
|
|
95
|
+
// Return sample data for the specified path
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
// Track collection editor events
|
|
99
|
+
onAnalyticsEvent: (event, params) => {
|
|
100
|
+
console.log("Collection editor event:", event, params);
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
// Include introduction widget when no collections exist
|
|
104
|
+
includeIntroView: true
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Integration with Code-Defined Collections
|
|
109
|
+
|
|
110
|
+
You can combine collections defined in code with those created in the UI:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import { mergeCollections } from "@firecms/collection_editor";
|
|
114
|
+
|
|
115
|
+
const collectionsBuilder = useCallback(() => {
|
|
116
|
+
// Collections defined in code
|
|
117
|
+
const codeCollections = [productsCollection, ordersCollection];
|
|
118
|
+
|
|
119
|
+
// Merge with collections from the editor UI
|
|
120
|
+
return mergeCollections(codeCollections, collectionConfigController.collections ?? []);
|
|
121
|
+
}, [collectionConfigController.collections]);
|
|
122
|
+
|
|
123
|
+
const navigationController = useBuildNavigationController({
|
|
124
|
+
collections: collectionsBuilder,
|
|
125
|
+
// Other options
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Firestore Configuration Controller
|
|
130
|
+
|
|
131
|
+
To persist collections in Firestore:
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
const collectionConfigController = useFirestoreCollectionsConfigController({
|
|
135
|
+
firebaseApp,
|
|
136
|
+
|
|
137
|
+
// Optional: specify where to save configs (default: "__FIRECMS/config/collections")
|
|
138
|
+
configPath: "custom/config/path",
|
|
139
|
+
|
|
140
|
+
// Optional: define permissions for collections
|
|
141
|
+
permissions: ({ user }) => ({
|
|
142
|
+
// Your permissions logic
|
|
143
|
+
}),
|
|
144
|
+
|
|
145
|
+
// Optional: custom property configurations
|
|
146
|
+
propertyConfigs: [
|
|
147
|
+
// Custom property types
|
|
148
|
+
]
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Additional Notes
|
|
153
|
+
|
|
154
|
+
- Collections created through the editor are stored in Firestore and loaded dynamically
|
|
155
|
+
- The plugin automatically adds UI elements for creating and managing collections
|
|
156
|
+
- For a complete solution, consider using alongside other plugins like data import/export
|
|
157
|
+
|
|
158
|
+
## Related Plugins
|
|
159
|
+
|
|
160
|
+
FireCMS offers several complementary plugins:
|
|
161
|
+
|
|
162
|
+
- Data Import: Import data from CSV or JSON into Firestore collections
|
|
163
|
+
- Data Export: Export collection data to CSV or JSON formats
|
|
164
|
+
- Data Enhancement: Generate content using AI for your collections
|
|
165
|
+
- Entity History: Track changes to your collection entities
|
package/dist/index.es.js
CHANGED
|
@@ -7014,8 +7014,8 @@ function CollectionPropertiesEditorForm({
|
|
|
7014
7014
|
setSelectedPropertyKey(propertyKey_2);
|
|
7015
7015
|
setSelectedPropertyNamespace(namespace_5);
|
|
7016
7016
|
};
|
|
7017
|
-
const body = /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-12 gap-2 h-full bg-
|
|
7018
|
-
/* @__PURE__ */ jsxs("div", { className: cls("p-4 md:p-8 pb-20 md:pb-20", "col-span-12 lg:col-span-5 h-full overflow-auto", !asDialog && "border-r " + defaultBorderMixin), children: [
|
|
7017
|
+
const body = /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-12 gap-2 h-full bg-white dark:bg-surface-950", children: [
|
|
7018
|
+
/* @__PURE__ */ jsxs("div", { className: cls("bg-surface-50 dark:bg-surface-900", "p-4 md:p-8 pb-20 md:pb-20", "col-span-12 lg:col-span-5 h-full overflow-auto", !asDialog && "border-r " + defaultBorderMixin), children: [
|
|
7019
7019
|
/* @__PURE__ */ jsxs("div", { className: "flex my-2", children: [
|
|
7020
7020
|
/* @__PURE__ */ jsxs("div", { className: "flex-grow mb-4", children: [
|
|
7021
7021
|
/* @__PURE__ */ jsx(Field, { name: "name", as: DebouncedTextField, invisible: true, className: "-ml-1", inputClassName: "text-2xl font-headers", placeholder: "Collection name", size: "small", required: true, error: Boolean(errors?.name) }),
|
|
@@ -7034,7 +7034,7 @@ function CollectionPropertiesEditorForm({
|
|
|
7034
7034
|
/* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(PropertyTree, { className: "pl-8", inferredPropertyKeys, selectedPropertyKey: selectedPropertyKey ? getFullId(selectedPropertyKey, selectedPropertyNamespace) : void 0, properties: values.properties, additionalFields: values.additionalFields, propertiesOrder: usedPropertiesOrder, onPropertyClick, onPropertyMove, onPropertyRemove: isNewCollection ? deleteProperty : void 0, collectionEditable, errors }) }),
|
|
7035
7035
|
/* @__PURE__ */ jsx(Button, { className: "mt-8 w-full", color: "primary", variant: "outlined", size: "large", onClick: () => setNewPropertyDialogOpen(true), startIcon: /* @__PURE__ */ jsx(AddIcon, {}), children: "Add new property" })
|
|
7036
7036
|
] }),
|
|
7037
|
-
!asDialog && /* @__PURE__ */ jsx("div", { className: "col-span-12 lg:col-span-7 p-4 md:py-8 md:px-4 h-full overflow-auto pb-20 md:pb-20", children: /* @__PURE__ */ jsxs(
|
|
7037
|
+
!asDialog && /* @__PURE__ */ jsx("div", { className: "col-span-12 lg:col-span-7 p-4 md:py-8 md:px-4 h-full overflow-auto pb-20 md:pb-20", children: /* @__PURE__ */ jsxs("div", { className: "sticky top-8 min-h-full w-full flex flex-col justify-center", children: [
|
|
7038
7038
|
selectedPropertyFullId && selectedProperty && !isPropertyBuilder(selectedProperty) && /* @__PURE__ */ jsx(PropertyForm, { inArray: false, existingProperty: !isNewCollection, autoUpdateId: false, allowDataInference: !isNewCollection, autoOpenTypeSelect: false, propertyKey: selectedPropertyKey, propertyNamespace: selectedPropertyNamespace, property: selectedProperty, onPropertyChanged, onDelete: deleteProperty, onError: onPropertyErrorInternal, forceShowErrors: showErrors, initialErrors, getData, propertyConfigs, collectionEditable }, `edit_view_${selectedPropertyIndex}`),
|
|
7039
7039
|
!selectedProperty && /* @__PURE__ */ jsxs("div", { className: "w-full flex flex-col items-center justify-center h-full gap-4", children: [
|
|
7040
7040
|
/* @__PURE__ */ jsx(Typography, { variant: "label", className: "", children: emptyCollection ? "Now you can add your first property" : "Select a property to edit it" }),
|