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

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 (71) hide show
  1. package/dist/form/Field.d.ts +53 -0
  2. package/dist/form/Formex.d.ts +4 -0
  3. package/dist/form/index.d.ts +5 -0
  4. package/dist/form/types.d.ts +25 -0
  5. package/dist/form/useCreateFormex.d.ts +9 -0
  6. package/dist/form/utils.d.ts +44 -0
  7. package/dist/index.es.js +2612 -2328
  8. package/dist/index.es.js.map +1 -1
  9. package/dist/index.umd.js +2 -2
  10. package/dist/index.umd.js.map +1 -1
  11. package/dist/types/collection_editor_controller.d.ts +3 -2
  12. package/dist/types/config_controller.d.ts +3 -3
  13. package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +3 -5
  14. package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +2 -2
  15. package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -2
  16. package/dist/ui/collection_editor/EnumForm.d.ts +1 -2
  17. package/dist/ui/collection_editor/PropertyEditView.d.ts +5 -5
  18. package/dist/ui/collection_editor/PropertyTree.d.ts +14 -13
  19. package/dist/ui/collection_editor/SwitchControl.d.ts +8 -0
  20. package/dist/ui/collection_editor/properties/CommonPropertyFields.d.ts +0 -1
  21. package/dist/ui/collection_editor/util.d.ts +1 -0
  22. package/package.json +5 -5
  23. package/src/ConfigControllerProvider.tsx +23 -21
  24. package/src/form/Field.tsx +162 -0
  25. package/src/form/Formex.tsx +8 -0
  26. package/src/form/README.md +165 -0
  27. package/src/form/index.ts +5 -0
  28. package/src/form/types.ts +27 -0
  29. package/src/form/useCreateFormex.tsx +137 -0
  30. package/src/form/utils.ts +169 -0
  31. package/src/types/collection_editor_controller.tsx +4 -3
  32. package/src/types/config_controller.tsx +3 -3
  33. package/src/ui/CollectionViewHeaderAction.tsx +1 -1
  34. package/src/ui/EditorCollectionAction.tsx +3 -3
  35. package/src/ui/HomePageEditorCollectionAction.tsx +2 -2
  36. package/src/ui/MissingReferenceWidget.tsx +2 -1
  37. package/src/ui/NewCollectionButton.tsx +3 -3
  38. package/src/ui/NewCollectionCard.tsx +2 -1
  39. package/src/ui/PropertyAddColumnComponent.tsx +1 -1
  40. package/src/ui/RootCollectionSuggestions.tsx +2 -1
  41. package/src/ui/collection_editor/CollectionDetailsForm.tsx +2 -2
  42. package/src/ui/collection_editor/CollectionEditorDialog.tsx +422 -374
  43. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +19 -12
  44. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +26 -18
  45. package/src/ui/collection_editor/EnumForm.tsx +118 -114
  46. package/src/ui/collection_editor/GetCodeDialog.tsx +1 -1
  47. package/src/ui/collection_editor/PropertyEditView.tsx +198 -142
  48. package/src/ui/collection_editor/PropertyFieldPreview.tsx +5 -1
  49. package/src/ui/collection_editor/PropertyTree.tsx +132 -113
  50. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +18 -11
  51. package/src/ui/collection_editor/SwitchControl.tsx +39 -0
  52. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +10 -2
  53. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +2 -2
  54. package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +13 -9
  55. package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +11 -37
  56. package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +2 -2
  57. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +3 -6
  58. package/src/ui/collection_editor/properties/MapPropertyField.tsx +2 -2
  59. package/src/ui/collection_editor/properties/NumberPropertyField.tsx +2 -2
  60. package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +11 -14
  61. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +10 -9
  62. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +15 -9
  63. package/src/ui/collection_editor/properties/StringPropertyField.tsx +2 -2
  64. package/src/ui/collection_editor/properties/UrlPropertyField.tsx +2 -2
  65. package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +27 -18
  66. package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +2 -2
  67. package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +27 -16
  68. package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +33 -18
  69. package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +99 -80
  70. package/src/ui/collection_editor/util.ts +7 -0
  71. package/src/ui/collection_editor/utils/strings.ts +2 -1
@@ -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 "../../../../form";
4
+ import { isValidRegExp, 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);