@firecms/collection_editor 3.0.0-canary.11 → 3.0.0-canary.110

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 (54) 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 +4680 -3442
  5. package/dist/index.es.js.map +1 -1
  6. package/dist/index.umd.js +6699 -3
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/types/collection_editor_controller.d.ts +14 -2
  9. package/dist/ui/CollectionViewHeaderAction.d.ts +3 -2
  10. package/dist/ui/EditorCollectionActionStart.d.ts +2 -0
  11. package/dist/ui/PropertyAddColumnComponent.d.ts +3 -1
  12. package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +4 -3
  13. package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +1 -1
  14. package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -1
  15. package/dist/ui/collection_editor/PropertyTree.d.ts +9 -9
  16. package/dist/ui/collection_editor/SubcollectionsEditTab.d.ts +1 -1
  17. package/dist/ui/collection_editor/properties/MarkdownPropertyField.d.ts +4 -0
  18. package/dist/ui/collection_editor/properties/StringPropertyField.d.ts +1 -1
  19. package/dist/useCollectionEditorPlugin.d.ts +15 -9
  20. package/dist/utils/collections.d.ts +6 -0
  21. package/package.json +21 -35
  22. package/src/ConfigControllerProvider.tsx +75 -63
  23. package/src/index.ts +1 -0
  24. package/src/types/collection_editor_controller.tsx +14 -4
  25. package/src/ui/CollectionViewHeaderAction.tsx +9 -4
  26. package/src/ui/EditorCollectionAction.tsx +10 -63
  27. package/src/ui/EditorCollectionActionStart.tsx +88 -0
  28. package/src/ui/HomePageEditorCollectionAction.tsx +16 -11
  29. package/src/ui/NewCollectionButton.tsx +12 -10
  30. package/src/ui/NewCollectionCard.tsx +3 -3
  31. package/src/ui/PropertyAddColumnComponent.tsx +9 -4
  32. package/src/ui/collection_editor/CollectionDetailsForm.tsx +67 -7
  33. package/src/ui/collection_editor/CollectionEditorDialog.tsx +56 -31
  34. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +6 -5
  35. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +33 -27
  36. package/src/ui/collection_editor/GetCodeDialog.tsx +15 -3
  37. package/src/ui/collection_editor/PropertyEditView.tsx +15 -7
  38. package/src/ui/collection_editor/PropertyFieldPreview.tsx +3 -6
  39. package/src/ui/collection_editor/PropertySelectItem.tsx +3 -3
  40. package/src/ui/collection_editor/PropertyTree.tsx +7 -5
  41. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +6 -4
  42. package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +25 -9
  43. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +9 -7
  44. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +14 -8
  45. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +1 -1
  46. package/src/ui/collection_editor/properties/MapPropertyField.tsx +5 -5
  47. package/src/ui/collection_editor/properties/MarkdownPropertyField.tsx +139 -0
  48. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +0 -1
  49. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +21 -1
  50. package/src/ui/collection_editor/properties/StringPropertyField.tsx +1 -10
  51. package/src/useCollectionEditorPlugin.tsx +37 -27
  52. package/src/utils/collections.ts +30 -0
  53. package/dist/ui/RootCollectionSuggestions.d.ts +0 -3
  54. package/src/ui/RootCollectionSuggestions.tsx +0 -63
@@ -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,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
- }