@firecms/collection_editor 3.0.0-canary.14 → 3.0.0-canary.140

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 (62) hide show
  1. package/LICENSE +114 -21
  2. package/dist/ConfigControllerProvider.d.ts +11 -2
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.es.js +4898 -3532
  5. package/dist/index.es.js.map +1 -1
  6. package/dist/index.umd.js +6827 -3
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/types/collection_editor_controller.d.ts +14 -2
  9. package/dist/types/collection_inference.d.ts +1 -1
  10. package/dist/ui/CollectionViewHeaderAction.d.ts +3 -2
  11. package/dist/ui/EditorCollectionActionStart.d.ts +2 -0
  12. package/dist/ui/PropertyAddColumnComponent.d.ts +3 -1
  13. package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +4 -3
  14. package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +1 -1
  15. package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -1
  16. package/dist/ui/collection_editor/PropertyEditView.d.ts +8 -0
  17. package/dist/ui/collection_editor/PropertyTree.d.ts +9 -9
  18. package/dist/ui/collection_editor/SubcollectionsEditTab.d.ts +1 -1
  19. package/dist/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +7 -0
  20. package/dist/ui/collection_editor/properties/MarkdownPropertyField.d.ts +4 -0
  21. package/dist/ui/collection_editor/properties/StringPropertyField.d.ts +1 -1
  22. package/dist/useCollectionEditorPlugin.d.ts +15 -9
  23. package/dist/utils/collections.d.ts +6 -0
  24. package/package.json +21 -35
  25. package/src/ConfigControllerProvider.tsx +75 -63
  26. package/src/index.ts +1 -0
  27. package/src/types/collection_editor_controller.tsx +14 -4
  28. package/src/types/collection_inference.ts +1 -1
  29. package/src/ui/CollectionViewHeaderAction.tsx +9 -4
  30. package/src/ui/EditorCollectionAction.tsx +10 -63
  31. package/src/ui/EditorCollectionActionStart.tsx +88 -0
  32. package/src/ui/HomePageEditorCollectionAction.tsx +18 -13
  33. package/src/ui/NewCollectionButton.tsx +12 -10
  34. package/src/ui/NewCollectionCard.tsx +3 -3
  35. package/src/ui/PropertyAddColumnComponent.tsx +9 -4
  36. package/src/ui/collection_editor/CollectionDetailsForm.tsx +69 -8
  37. package/src/ui/collection_editor/CollectionEditorDialog.tsx +57 -32
  38. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +6 -5
  39. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +34 -27
  40. package/src/ui/collection_editor/GetCodeDialog.tsx +15 -3
  41. package/src/ui/collection_editor/PropertyEditView.tsx +252 -78
  42. package/src/ui/collection_editor/PropertyFieldPreview.tsx +3 -6
  43. package/src/ui/collection_editor/PropertyTree.tsx +7 -5
  44. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +26 -19
  45. package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +25 -9
  46. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +40 -9
  47. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +31 -19
  48. package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +50 -47
  49. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +1 -1
  50. package/src/ui/collection_editor/properties/MapPropertyField.tsx +5 -5
  51. package/src/ui/collection_editor/properties/MarkdownPropertyField.tsx +139 -0
  52. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +0 -1
  53. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +31 -16
  54. package/src/ui/collection_editor/properties/StringPropertyField.tsx +1 -10
  55. package/src/ui/collection_editor/properties/validation/ValidationPanel.tsx +1 -1
  56. package/src/ui/collection_editor/templates/pages_template.ts +1 -6
  57. package/src/useCollectionEditorPlugin.tsx +37 -27
  58. package/src/utils/collections.ts +30 -0
  59. package/dist/ui/RootCollectionSuggestions.d.ts +0 -3
  60. package/dist/ui/collection_editor/PropertySelectItem.d.ts +0 -8
  61. package/src/ui/RootCollectionSuggestions.tsx +0 -63
  62. package/src/ui/collection_editor/PropertySelectItem.tsx +0 -32
@@ -10,7 +10,7 @@ export function StringPropertyField({
10
10
  disabled,
11
11
  showErrors
12
12
  }: {
13
- widgetId: "text_field" | "multiline" | "markdown" | "email";
13
+ widgetId: "text_field" | "multiline" | "email";
14
14
  disabled: boolean;
15
15
  showErrors: boolean;
16
16
  }) {
@@ -42,15 +42,6 @@ export function StringPropertyField({
42
42
  trim={true}
43
43
  uppercase={true}
44
44
  showErrors={showErrors}/>}
45
- {widgetId === "markdown" &&
46
- <StringPropertyValidation disabled={disabled}
47
- length={true}
48
- lowercase={true}
49
- max={true}
50
- min={true}
51
- trim={true}
52
- uppercase={true}
53
- showErrors={showErrors}/>}
54
45
 
55
46
  {widgetId === "email" &&
56
47
  <StringPropertyValidation disabled={disabled}
@@ -10,7 +10,7 @@ export function ValidationPanel({
10
10
  <ExpandablePanel
11
11
  initiallyExpanded={false}
12
12
  asField={true}
13
- className="p-4"
13
+ innerClassName="p-4"
14
14
  title={
15
15
  <div className="flex flex-row text-gray-500">
16
16
  <RuleIcon/>
@@ -19,7 +19,7 @@ export const pagesCollectionTemplate: EntityCollection = {
19
19
  validation: {
20
20
  required: true,
21
21
  unique: true,
22
- matches: /^[a-z0-9]+(?:-[a-z0-9]+)*$/,
22
+ matches: "^[a-z0-9]+(?:-[a-z0-9]+)*$",
23
23
  matchesMessage: "Must be lowercase, alphanumeric, and hyphenated"
24
24
  }
25
25
  },
@@ -178,11 +178,6 @@ export const pagesCollectionTemplate: EntityCollection = {
178
178
  name: "Is Published",
179
179
  columnWidth: 100,
180
180
  description: "Should this page be live on the site?"
181
- },
182
- author_uid: {
183
- dataType: "reference",
184
- name: "Author",
185
- path: "users"
186
181
  }
187
182
  }
188
183
  };
@@ -4,16 +4,16 @@ import { ConfigControllerProvider } from "./ConfigControllerProvider";
4
4
  import { CollectionEditorPermissionsBuilder } from "./types/config_permissions";
5
5
  import { EditorCollectionAction } from "./ui/EditorCollectionAction";
6
6
  import { HomePageEditorCollectionAction } from "./ui/HomePageEditorCollectionAction";
7
- import { NewCollectionCard } from "./ui/NewCollectionCard";
8
7
  import { PersistedCollection } from "./types/persisted_collection";
9
8
  import { CollectionInference } from "./types/collection_inference";
10
9
  import { CollectionsConfigController } from "./types/config_controller";
11
- import { RootCollectionSuggestions } from "./ui/RootCollectionSuggestions";
12
10
  import { CollectionViewHeaderAction } from "./ui/CollectionViewHeaderAction";
13
11
  import { PropertyAddColumnComponent } from "./ui/PropertyAddColumnComponent";
14
12
  import { NewCollectionButton } from "./ui/NewCollectionButton";
15
- import { AddIcon, Button, Typography } from "@firecms/ui";
13
+ import { AddIcon, Button, Paper, Typography } from "@firecms/ui";
16
14
  import { useCollectionEditorController } from "./useCollectionEditorController";
15
+ import { EditorCollectionActionStart } from "./ui/EditorCollectionActionStart";
16
+ import { NewCollectionCard } from "./ui/NewCollectionCard";
17
17
 
18
18
  export interface CollectionConfigControllerProps<EC extends PersistedCollection = PersistedCollection, UserType extends User = User> {
19
19
 
@@ -32,7 +32,7 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
32
32
  * names when creating collections.
33
33
  * e.g. ["admin"]
34
34
  */
35
- reservedGroups: string[];
35
+ reservedGroups?: string[];
36
36
 
37
37
  extraView?: {
38
38
  View: React.ComponentType<{
@@ -41,17 +41,22 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
41
41
  icon: React.ReactNode
42
42
  };
43
43
 
44
- pathSuggestions?: (path: string) => Promise<string[]>;
44
+ getPathSuggestions?: (path?: string) => Promise<string[]>;
45
45
 
46
46
  collectionInference?: CollectionInference;
47
47
 
48
48
  getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
49
49
 
50
- getUser: (uid: string) => UserType | null;
50
+ getUser?: (uid: string) => UserType | null;
51
51
 
52
52
  onAnalyticsEvent?: (event: string, params?: object) => void;
53
53
 
54
- introMode?: "new_project" | "existing_project";
54
+ components?: {
55
+ /**
56
+ * Custom component to render the database field
57
+ */
58
+ DatabaseField?: React.ComponentType<{ databaseId?: string, onDatabaseIdUpdate: (databaseId:string) => void }>;
59
+ };
55
60
 
56
61
  }
57
62
 
@@ -62,22 +67,22 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
62
67
  * @param configPermissions
63
68
  * @param reservedGroups
64
69
  * @param extraView
65
- * @param pathSuggestions
70
+ * @param getData
66
71
  * @param getUser
67
72
  * @param collectionInference
68
73
  */
69
74
  export function useCollectionEditorPlugin<EC extends PersistedCollection = PersistedCollection, UserType extends User = User>
70
75
  ({
71
76
  collectionConfigController,
72
- introMode,
73
77
  configPermissions,
74
78
  reservedGroups,
75
79
  extraView,
76
- pathSuggestions,
80
+ getPathSuggestions,
77
81
  getUser,
78
82
  collectionInference,
79
83
  getData,
80
- onAnalyticsEvent
84
+ onAnalyticsEvent,
85
+ components
81
86
  }: CollectionConfigControllerProps<EC, UserType>): FireCMSPlugin<any, any, PersistedCollection> {
82
87
 
83
88
  return {
@@ -91,20 +96,22 @@ export function useCollectionEditorPlugin<EC extends PersistedCollection = Persi
91
96
  collectionInference,
92
97
  reservedGroups,
93
98
  extraView,
94
- pathSuggestions,
99
+ getPathSuggestions,
95
100
  getUser,
96
101
  getData,
97
- onAnalyticsEvent
102
+ onAnalyticsEvent,
103
+ components
98
104
  }
99
105
  },
100
106
  homePage: {
101
107
  additionalActions: <NewCollectionButton/>,
102
- additionalChildrenStart: introMode ? <IntroWidget introMode={introMode}/> : undefined,
103
- additionalChildrenEnd: <RootCollectionSuggestions introMode={introMode}/>,
108
+ additionalChildrenStart: <IntroWidget/>,
109
+ // additionalChildrenEnd: <RootCollectionSuggestions introMode={introMode}/>,
104
110
  CollectionActions: HomePageEditorCollectionAction,
105
- AdditionalCards: introMode ? undefined : NewCollectionCard,
111
+ AdditionalCards: NewCollectionCard,
106
112
  },
107
113
  collectionView: {
114
+ CollectionActionsStart: EditorCollectionActionStart,
108
115
  CollectionActions: EditorCollectionAction,
109
116
  HeaderAction: CollectionViewHeaderAction,
110
117
  AddColumnComponent: PropertyAddColumnComponent
@@ -112,9 +119,7 @@ export function useCollectionEditorPlugin<EC extends PersistedCollection = Persi
112
119
  };
113
120
  }
114
121
 
115
- export function IntroWidget({ introMode }: {
116
- introMode?: "new_project" | "existing_project";
117
- }) {
122
+ export function IntroWidget({}: {}) {
118
123
 
119
124
  const navigation = useNavigationController();
120
125
  if (!navigation.topLevelNavigation)
@@ -129,17 +134,19 @@ export function IntroWidget({ introMode }: {
129
134
  }).createCollections
130
135
  : true;
131
136
 
137
+ if (!navigation.initialised || (navigation.collections ?? []).length > 0) {
138
+ return null;
139
+ }
140
+
132
141
  return (
133
- <div className={"mt-8 flex flex-col mt-8 p-2"}>
134
- <Typography variant={"h4"} className="mb-4">Welcome</Typography>
135
- <Typography paragraph={true}>Your admin panel is ready ✌️</Typography>
136
- <Typography paragraph={true}>
142
+ <Paper
143
+ className={"my-4 px-4 py-6 flex flex-col bg-white dark:bg-slate-800 gap-2"}>
144
+ <Typography variant={"subtitle2"} className={"uppercase"}>No collections found</Typography>
145
+ <Typography>
137
146
  Start building collections in FireCMS easily. Map them to your existing
138
- database data, import from files, or use our templates. Simplify your data management process
139
- now.
147
+ database data, import from files, or use our templates.
140
148
  </Typography>
141
149
  {canCreateCollections && <Button
142
- className={"mt-4"}
143
150
  onClick={collectionEditorController && canCreateCollections
144
151
  ? () => collectionEditorController.createCollection({
145
152
  parentCollectionIds: [],
@@ -149,6 +156,9 @@ export function IntroWidget({ introMode }: {
149
156
  : undefined}>
150
157
  <AddIcon/>Create your first collection
151
158
  </Button>}
152
- </div>
159
+ <Typography color={"secondary"}>
160
+ You can also define collections programmatically.
161
+ </Typography>
162
+ </Paper>
153
163
  );
154
164
  }
@@ -0,0 +1,30 @@
1
+ import {
2
+ EntityCollection,
3
+ joinCollectionLists,
4
+ makePropertiesEditable,
5
+ ModifyCollectionProps,
6
+ Properties
7
+ } from "@firecms/core";
8
+ import { PersistedCollection } from "../types/persisted_collection";
9
+
10
+ /**
11
+ * Function in charge of merging collections defined in code with those stored in the backend.
12
+ */
13
+ export const mergeCollections = (baseCollections: EntityCollection[],
14
+ backendCollections: PersistedCollection[],
15
+ modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void
16
+ ) => {
17
+
18
+ const markAsEditable = (c: PersistedCollection) => {
19
+ makePropertiesEditable(c.properties as Properties);
20
+ c.subcollections?.forEach(markAsEditable);
21
+ };
22
+ const storedCollections = backendCollections ?? [];
23
+ storedCollections.forEach(markAsEditable);
24
+
25
+ console.debug("Collections specified in code:", baseCollections);
26
+ console.debug("Collections stored in the backend", storedCollections);
27
+ const result = joinCollectionLists(baseCollections, storedCollections, [], modifyCollection);
28
+ console.debug("Collections after joining:", result);
29
+ return result;
30
+ }
@@ -1,3 +0,0 @@
1
- export declare function RootCollectionSuggestions({ introMode }: {
2
- introMode?: "new_project" | "existing_project";
3
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,8 +0,0 @@
1
- import { PropertyConfig } from "@firecms/core";
2
- export interface PropertySelectItemProps {
3
- value: string;
4
- optionDisabled: boolean;
5
- propertyConfig: PropertyConfig;
6
- existing: boolean;
7
- }
8
- export declare function PropertySelectItem({ value, optionDisabled, propertyConfig, existing }: PropertySelectItemProps): import("react/jsx-runtime").JSX.Element;
@@ -1,63 +0,0 @@
1
- import { unslugify, useAuthController, useNavigationController } from "@firecms/core";
2
- import { AddIcon, Chip, CircularProgress, Collapse, Typography, } from "@firecms/ui";
3
- import { useCollectionEditorController } from "../useCollectionEditorController";
4
- import React from "react";
5
-
6
- export function RootCollectionSuggestions({ introMode }: { introMode?: "new_project" | "existing_project" }) {
7
-
8
- const authController = useAuthController();
9
- const navigationController = useNavigationController();
10
-
11
- const collectionEditorController = useCollectionEditorController();
12
- const canCreateCollections = collectionEditorController.configPermissions
13
- ? collectionEditorController.configPermissions({
14
- user: authController.user
15
- }).createCollections
16
- : true;
17
-
18
- const rootPathSuggestions = collectionEditorController.rootPathSuggestions;
19
-
20
- const showSuggestions = (rootPathSuggestions ?? []).length > 3 || ((navigationController.collections ?? []).length === 0 && (rootPathSuggestions ?? []).length > 0);
21
- const forceShowSuggestions = introMode === "existing_project";
22
- return <Collapse
23
- in={forceShowSuggestions || showSuggestions}>
24
-
25
- <div
26
- className={"flex flex-col gap-1 p-2 my-4"}>
27
-
28
- {!introMode && <Typography variant={"body2"} color={"secondary"}>
29
- Create a collection <b>automatically</b> from your data:
30
- </Typography>}
31
-
32
- {introMode === "existing_project" && <Typography>
33
- You will see your <b>database collections</b> here, a few seconds after project creation
34
- </Typography>}
35
-
36
- <div
37
- className={"flex flex-row gap-1 overflow-scroll no-scrollbar "}>
38
- {(rootPathSuggestions ?? []).map((path) => {
39
- return (
40
- <div key={path}>
41
- <Chip
42
- icon={<AddIcon size={"small"}/>}
43
- colorScheme={"cyanLighter"}
44
- onClick={collectionEditorController && canCreateCollections
45
- ? () => collectionEditorController.createCollection({
46
- initialValues: { path, name: unslugify(path) },
47
- parentCollectionIds: [],
48
- redirect: true,
49
- sourceClick: "root_collection_suggestion"
50
- })
51
- : undefined}
52
- size="small">
53
- {path}
54
- </Chip>
55
- </div>
56
- );
57
- })}
58
- {rootPathSuggestions === undefined && <CircularProgress size={"small"}/>}
59
- {rootPathSuggestions?.length === 0 && <Typography variant={"caption"}>No suggestions</Typography>}
60
- </div>
61
- </div>
62
- </Collapse>
63
- }
@@ -1,32 +0,0 @@
1
- import { PropertyConfigBadge, PropertyConfig } from "@firecms/core";
2
- import { cn, SelectItem, Typography } from "@firecms/ui";
3
-
4
- export interface PropertySelectItemProps {
5
- value: string;
6
- optionDisabled: boolean;
7
- propertyConfig: PropertyConfig;
8
- existing: boolean;
9
- }
10
-
11
- export function PropertySelectItem({ value, optionDisabled, propertyConfig, existing }: PropertySelectItemProps) {
12
- return <SelectItem value={value}
13
- disabled={optionDisabled}
14
- className={"flex flex-row items-center"}>
15
- <div
16
- className={cn(
17
- "flex flex-row items-center text-base min-h-[52px]",
18
- optionDisabled ? "w-full" : "")}>
19
- <div className={"mr-8"}>
20
- <PropertyConfigBadge propertyConfig={propertyConfig}/>
21
- </div>
22
- <div>
23
- <div>{propertyConfig.name}</div>
24
- <Typography variant={"caption"}
25
- color={"disabled"}
26
- className={"max-w-sm"}>
27
- {existing && optionDisabled ? "You can only switch to widgets that use the same data type" : propertyConfig.description}
28
- </Typography>
29
- </div>
30
- </div>
31
- </SelectItem>
32
- }