@firecms/collection_editor 3.0.0-beta.2-pre.2 → 3.0.0-beta.2-pre.4

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 (59) hide show
  1. package/dist/index.es.js +2532 -2386
  2. package/dist/index.es.js.map +1 -1
  3. package/dist/index.umd.js +2 -2
  4. package/dist/index.umd.js.map +1 -1
  5. package/dist/types/collection_editor_controller.d.ts +3 -2
  6. package/dist/types/config_controller.d.ts +3 -3
  7. package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +3 -5
  8. package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +2 -2
  9. package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -2
  10. package/dist/ui/collection_editor/EnumForm.d.ts +1 -2
  11. package/dist/ui/collection_editor/PropertyEditView.d.ts +5 -5
  12. package/dist/ui/collection_editor/PropertyTree.d.ts +14 -13
  13. package/dist/ui/collection_editor/SwitchControl.d.ts +8 -0
  14. package/dist/ui/collection_editor/properties/CommonPropertyFields.d.ts +0 -1
  15. package/dist/ui/collection_editor/util.d.ts +1 -0
  16. package/package.json +6 -5
  17. package/src/ConfigControllerProvider.tsx +24 -22
  18. package/src/types/collection_editor_controller.tsx +4 -3
  19. package/src/types/config_controller.tsx +3 -3
  20. package/src/ui/CollectionViewHeaderAction.tsx +1 -1
  21. package/src/ui/EditorCollectionAction.tsx +3 -3
  22. package/src/ui/HomePageEditorCollectionAction.tsx +2 -2
  23. package/src/ui/MissingReferenceWidget.tsx +2 -1
  24. package/src/ui/NewCollectionButton.tsx +3 -3
  25. package/src/ui/NewCollectionCard.tsx +2 -1
  26. package/src/ui/PropertyAddColumnComponent.tsx +1 -1
  27. package/src/ui/RootCollectionSuggestions.tsx +3 -2
  28. package/src/ui/collection_editor/CollectionDetailsForm.tsx +2 -2
  29. package/src/ui/collection_editor/CollectionEditorDialog.tsx +420 -374
  30. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +19 -12
  31. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +26 -18
  32. package/src/ui/collection_editor/EnumForm.tsx +118 -114
  33. package/src/ui/collection_editor/GetCodeDialog.tsx +1 -1
  34. package/src/ui/collection_editor/PropertyEditView.tsx +199 -142
  35. package/src/ui/collection_editor/PropertyFieldPreview.tsx +5 -1
  36. package/src/ui/collection_editor/PropertyTree.tsx +132 -113
  37. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +18 -11
  38. package/src/ui/collection_editor/SwitchControl.tsx +39 -0
  39. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +10 -2
  40. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +2 -2
  41. package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +13 -9
  42. package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +11 -37
  43. package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +2 -2
  44. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +3 -6
  45. package/src/ui/collection_editor/properties/MapPropertyField.tsx +2 -2
  46. package/src/ui/collection_editor/properties/NumberPropertyField.tsx +2 -2
  47. package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +11 -14
  48. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +10 -9
  49. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +15 -9
  50. package/src/ui/collection_editor/properties/StringPropertyField.tsx +2 -2
  51. package/src/ui/collection_editor/properties/UrlPropertyField.tsx +2 -2
  52. package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +27 -18
  53. package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +2 -2
  54. package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +27 -16
  55. package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +33 -18
  56. package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +99 -80
  57. package/src/ui/collection_editor/util.ts +7 -0
  58. package/src/ui/collection_editor/utils/strings.ts +2 -1
  59. package/src/useCollectionEditorPlugin.tsx +1 -16
@@ -1,10 +1,11 @@
1
1
  import React from "react";
2
2
 
3
- import { FastField, getIn, useFormikContext } from "formik";
4
- import { isValidRegExp, serializeRegExp, SwitchControl } from "@firecms/core";
3
+ import { Field, FormexFieldProps, getIn, useFormex } from "@firecms/formex";
4
+ import { serializeRegExp } from "@firecms/core";
5
5
  import { DebouncedTextField, } from "@firecms/ui";
6
6
  import { GeneralPropertyValidation } from "./GeneralPropertyValidation";
7
7
  import { FieldHelperView } from "../FieldHelperView";
8
+ import { SwitchControl } from "../../SwitchControl";
8
9
 
9
10
  export function StringPropertyValidation({
10
11
  length,
@@ -32,7 +33,7 @@ export function StringPropertyValidation({
32
33
  values,
33
34
  handleChange,
34
35
  errors
35
- } = useFormikContext();
36
+ } = useFormex();
36
37
 
37
38
  const validationLength = "validation.length";
38
39
  const validationMin = "validation.min";
@@ -47,86 +48,104 @@ export function StringPropertyValidation({
47
48
  const matchesValue = getIn(values, validationMatches);
48
49
  const matchesStringValue = typeof matchesValue === "string" ? matchesValue : serializeRegExp(matchesValue);
49
50
  return (
50
- <div className={"grid grid-cols-12 gap-2"}>
51
-
52
- <GeneralPropertyValidation disabled={disabled}/>
53
-
54
- <div className={"grid grid-cols-12 gap-2 col-span-12"}>
55
- {lowercase && <div className={"col-span-4"}>
56
- <FastField type="checkbox"
57
- name={validationLowercase}
58
- label={"Lowercase"}
59
- disabled={disabled}
60
- component={SwitchControl}/>
61
- </div>}
62
- {uppercase && <div className={"col-span-4"}>
63
- <FastField type="checkbox"
64
- name={validationUppercase}
65
- label={"Uppercase"}
66
- disabled={disabled}
67
- component={SwitchControl}/>
68
- </div>}
69
- {trim && <div className={"col-span-4"}>
70
- <FastField type="checkbox"
71
- name={validationTrim}
72
- label={"Trim"}
73
- disabled={disabled}
74
- component={SwitchControl}/>
75
- </div>}
76
- </div>
77
-
78
- <div className={"grid grid-cols-12 gap-2 col-span-12"}>
79
- {length && <div className={"col-span-4"}>
80
- <DebouncedTextField
81
- value={getIn(values, validationLength)}
82
- label={"Exact length"}
83
- name={validationLength}
84
- type="number"
85
- size="small"
86
-
87
- disabled={disabled}
88
- onChange={handleChange}/>
89
- </div>}
90
-
91
- {min && <div className={"col-span-4"}>
92
- <DebouncedTextField value={getIn(values, validationMin)}
93
- label={"Min length"}
94
- name={validationMin}
95
- type="number"
96
- size="small"
97
-
98
- disabled={disabled}
99
- onChange={handleChange}/>
100
- </div>}
101
-
102
- {max && <div className={"col-span-4"}>
103
- <DebouncedTextField value={getIn(values, validationMax)}
104
- label={"Max length"}
105
- name={validationMax}
106
- type="number"
107
- size="small"
108
-
109
- disabled={disabled}
110
- onChange={handleChange}/>
111
- </div>}
112
-
113
- </div>
114
-
115
- {matches && <div className={"col-span-12"}>
116
- <FastField name={validationMatches}
117
- as={DebouncedTextField}
118
- validate={(value: string) => value && !isValidRegExp(value)}
119
- label={"Matches regex"}
120
- size="small"
121
- disabled={disabled}
122
- value={matchesStringValue}
123
- error={Boolean(matchesError)}/>
124
- <FieldHelperView error={Boolean(matchesError)}>
125
- {matchesError ? "Not a valid regexp" : "e.g. /^\\d+$/ for digits only"}
126
- </FieldHelperView>
51
+ <div className={"grid grid-cols-12 gap-2"}>
52
+
53
+ <GeneralPropertyValidation disabled={disabled}/>
54
+
55
+ <div className={"grid grid-cols-12 gap-2 col-span-12"}>
56
+
57
+ {lowercase && <div className={"col-span-4"}>
58
+ <Field name={validationLowercase}
59
+ type="checkbox">
60
+ {({ field, form }: FormexFieldProps) => {
61
+ return <SwitchControl
62
+ label={"Lowercase"}
63
+ disabled={disabled}
64
+ form={form}
65
+ field={field}/>
66
+ }}
67
+ </Field>
68
+ </div>}
69
+
70
+ {uppercase && <div className={"col-span-4"}>
71
+ <Field name={validationUppercase}
72
+ type="checkbox">
73
+ {({ field, form }: FormexFieldProps) => {
74
+ return <SwitchControl
75
+ label={"Uppercase"}
76
+ disabled={disabled}
77
+ form={form}
78
+ field={field}/>
79
+ }}
80
+ </Field>
81
+ </div>}
82
+
83
+ {trim && <div className={"col-span-4"}>
84
+ <Field name={validationTrim}
85
+ type="checkbox">
86
+ {({ field, form }: FormexFieldProps) => {
87
+ return <SwitchControl
88
+ label={"Trim"}
89
+ disabled={disabled}
90
+ form={form}
91
+ field={field}/>
92
+ }}
93
+ </Field>
127
94
  </div>}
128
95
 
129
96
  </div>
97
+
98
+ <div className={"grid grid-cols-12 gap-2 col-span-12"}>
99
+ {length && <div className={"col-span-4"}>
100
+ <DebouncedTextField
101
+ value={getIn(values, validationLength)}
102
+ label={"Exact length"}
103
+ name={validationLength}
104
+ type="number"
105
+ size="small"
106
+
107
+ disabled={disabled}
108
+ onChange={handleChange}/>
109
+ </div>}
110
+
111
+ {min && <div className={"col-span-4"}>
112
+ <DebouncedTextField value={getIn(values, validationMin)}
113
+ label={"Min length"}
114
+ name={validationMin}
115
+ type="number"
116
+ size="small"
117
+
118
+ disabled={disabled}
119
+ onChange={handleChange}/>
120
+ </div>}
121
+
122
+ {max && <div className={"col-span-4"}>
123
+ <DebouncedTextField value={getIn(values, validationMax)}
124
+ label={"Max length"}
125
+ name={validationMax}
126
+ type="number"
127
+ size="small"
128
+
129
+ disabled={disabled}
130
+ onChange={handleChange}/>
131
+ </div>}
132
+
133
+ </div>
134
+
135
+ {matches && <div className={"col-span-12"}>
136
+ <Field name={validationMatches}
137
+ as={DebouncedTextField}
138
+ label={"Matches regex"}
139
+ size="small"
140
+ disabled={disabled}
141
+ value={matchesStringValue}
142
+ error={Boolean(matchesError)}/>
143
+ <FieldHelperView error={Boolean(matchesError)}>
144
+ {matchesError ? "Not a valid regexp" : "e.g. /^\\d+$/ for digits only"}
145
+ </FieldHelperView>
146
+ </div>}
147
+
148
+ </div>
130
149
  );
131
150
 
132
151
  }
@@ -19,3 +19,10 @@ export function getFullId(propertyKey: string, propertyNamespace?: string): stri
19
19
  ? `${propertyNamespace}.${propertyKey}`
20
20
  : propertyKey;
21
21
  }
22
+
23
+ export function getFullIdPath(propertyKey: string, propertyNamespace?: string): string {
24
+ const keyWithNamespace = propertyNamespace
25
+ ? `${propertyNamespace}.${propertyKey}`
26
+ : propertyKey;
27
+ return idToPropertiesPath(keyWithNamespace);
28
+ }
@@ -1,6 +1,7 @@
1
1
  export function camelCase(str: string): string {
2
+ if (!str) return "";
2
3
  return (str.slice(0, 1).toLowerCase() + str.slice(1))
3
- .replace(/([-_ ]){1,}/g, ' ')
4
+ .replace(/([-_ ]){1,}/g, " ")
4
5
  .split(/[-_ ]/)
5
6
  .reduce((cur, acc) => {
6
7
  return cur + acc[0].toUpperCase() + acc.substring(1);
@@ -86,27 +86,12 @@ export function useCollectionEditorPlugin<EC extends PersistedCollection = Persi
86
86
  onAnalyticsEvent
87
87
  }: CollectionConfigControllerProps<EC, UserType>): FireCMSPlugin<any, any, PersistedCollection> {
88
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
- };
89
+
104
90
 
105
91
  return {
106
92
  name: "Collection Editor",
107
93
  loading: collectionConfigController.loading,
108
94
  collections: {
109
- injectCollections,
110
95
  CollectionActions: EditorCollectionAction
111
96
  },
112
97
  provider: {