@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.
- package/dist/form/Field.d.ts +53 -0
- package/dist/form/Formex.d.ts +4 -0
- package/dist/form/index.d.ts +5 -0
- package/dist/form/types.d.ts +25 -0
- package/dist/form/useCreateFormex.d.ts +9 -0
- package/dist/form/utils.d.ts +44 -0
- package/dist/index.es.js +2612 -2328
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collection_editor_controller.d.ts +3 -2
- package/dist/types/config_controller.d.ts +3 -3
- package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +3 -5
- package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +2 -2
- package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -2
- package/dist/ui/collection_editor/EnumForm.d.ts +1 -2
- package/dist/ui/collection_editor/PropertyEditView.d.ts +5 -5
- package/dist/ui/collection_editor/PropertyTree.d.ts +14 -13
- package/dist/ui/collection_editor/SwitchControl.d.ts +8 -0
- package/dist/ui/collection_editor/properties/CommonPropertyFields.d.ts +0 -1
- package/dist/ui/collection_editor/util.d.ts +1 -0
- package/package.json +5 -5
- package/src/ConfigControllerProvider.tsx +23 -21
- package/src/form/Field.tsx +162 -0
- package/src/form/Formex.tsx +8 -0
- package/src/form/README.md +165 -0
- package/src/form/index.ts +5 -0
- package/src/form/types.ts +27 -0
- package/src/form/useCreateFormex.tsx +137 -0
- package/src/form/utils.ts +169 -0
- package/src/types/collection_editor_controller.tsx +4 -3
- package/src/types/config_controller.tsx +3 -3
- package/src/ui/CollectionViewHeaderAction.tsx +1 -1
- package/src/ui/EditorCollectionAction.tsx +3 -3
- package/src/ui/HomePageEditorCollectionAction.tsx +2 -2
- package/src/ui/MissingReferenceWidget.tsx +2 -1
- package/src/ui/NewCollectionButton.tsx +3 -3
- package/src/ui/NewCollectionCard.tsx +2 -1
- package/src/ui/PropertyAddColumnComponent.tsx +1 -1
- package/src/ui/RootCollectionSuggestions.tsx +2 -1
- package/src/ui/collection_editor/CollectionDetailsForm.tsx +2 -2
- package/src/ui/collection_editor/CollectionEditorDialog.tsx +422 -374
- package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +19 -12
- package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +26 -18
- package/src/ui/collection_editor/EnumForm.tsx +118 -114
- package/src/ui/collection_editor/GetCodeDialog.tsx +1 -1
- package/src/ui/collection_editor/PropertyEditView.tsx +198 -142
- package/src/ui/collection_editor/PropertyFieldPreview.tsx +5 -1
- package/src/ui/collection_editor/PropertyTree.tsx +132 -113
- package/src/ui/collection_editor/SubcollectionsEditTab.tsx +18 -11
- package/src/ui/collection_editor/SwitchControl.tsx +39 -0
- package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +10 -2
- package/src/ui/collection_editor/properties/BlockPropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +13 -9
- package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +11 -37
- package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/EnumPropertyField.tsx +3 -6
- package/src/ui/collection_editor/properties/MapPropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/NumberPropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +11 -14
- package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +10 -9
- package/src/ui/collection_editor/properties/StoragePropertyField.tsx +15 -9
- package/src/ui/collection_editor/properties/StringPropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/UrlPropertyField.tsx +2 -2
- package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +27 -18
- package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +2 -2
- package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +27 -16
- package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +33 -18
- package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +99 -80
- package/src/ui/collection_editor/util.ts +7 -0
- package/src/ui/collection_editor/utils/strings.ts +2 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { isValidRegExp, serializeRegExp
|
|
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
|
-
} =
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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);
|