@firecms/collection_editor 3.0.0-beta.8 → 3.0.0-beta.9
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/LICENSE +2 -1
- package/dist/ConfigControllerProvider.d.ts +9 -0
- package/dist/index.es.js +4620 -3483
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +6679 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collection_editor_controller.d.ts +10 -0
- package/dist/ui/collection_editor/properties/MarkdownPropertyField.d.ts +4 -0
- package/dist/ui/collection_editor/properties/StringPropertyField.d.ts +1 -1
- package/dist/useCollectionEditorPlugin.d.ts +10 -1
- package/package.json +15 -13
- package/src/ConfigControllerProvider.tsx +11 -2
- package/src/types/collection_editor_controller.tsx +8 -0
- package/src/ui/CollectionViewHeaderAction.tsx +3 -1
- package/src/ui/EditorCollectionAction.tsx +1 -0
- package/src/ui/EditorCollectionActionStart.tsx +1 -0
- package/src/ui/PropertyAddColumnComponent.tsx +3 -1
- package/src/ui/collection_editor/CollectionDetailsForm.tsx +34 -4
- package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +2 -1
- package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +6 -3
- package/src/ui/collection_editor/GetCodeDialog.tsx +1 -1
- package/src/ui/collection_editor/PropertyEditView.tsx +10 -3
- package/src/ui/collection_editor/PropertySelectItem.tsx +1 -1
- package/src/ui/collection_editor/PropertyTree.tsx +4 -2
- package/src/ui/collection_editor/SubcollectionsEditTab.tsx +4 -2
- package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +50 -47
- package/src/ui/collection_editor/properties/MarkdownPropertyField.tsx +139 -0
- package/src/ui/collection_editor/properties/StoragePropertyField.tsx +31 -16
- package/src/ui/collection_editor/properties/StringPropertyField.tsx +1 -10
- package/src/ui/collection_editor/templates/pages_template.ts +0 -5
- package/src/useCollectionEditorPlugin.tsx +12 -3
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { StringPropertyValidation } from "./validation/StringPropertyValidation";
|
|
3
|
+
import { ValidationPanel } from "./validation/ValidationPanel";
|
|
4
|
+
import { Field, getIn, useFormex } from "@firecms/formex";
|
|
5
|
+
|
|
6
|
+
import { DebouncedTextField, ExpandablePanel, FileUploadIcon, TextField, Typography } from "@firecms/ui";
|
|
7
|
+
|
|
8
|
+
export function MarkdownPropertyField({
|
|
9
|
+
disabled,
|
|
10
|
+
showErrors
|
|
11
|
+
}: {
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
showErrors: boolean;
|
|
14
|
+
}) {
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
values,
|
|
18
|
+
setFieldValue
|
|
19
|
+
} = useFormex();
|
|
20
|
+
|
|
21
|
+
const baseStoragePath = "storage";
|
|
22
|
+
|
|
23
|
+
const metadata = `${baseStoragePath}.metadata`;
|
|
24
|
+
const fileName = `${baseStoragePath}.fileName`;
|
|
25
|
+
const maxSize = `${baseStoragePath}.maxSize`;
|
|
26
|
+
const storagePath = `${baseStoragePath}.storagePath`;
|
|
27
|
+
|
|
28
|
+
const fileNameValue = getIn(values, fileName) ?? "{rand}_{file}";
|
|
29
|
+
const storagePathValue = getIn(values, storagePath) ?? "/";
|
|
30
|
+
const maxSizeValue = getIn(values, maxSize);
|
|
31
|
+
|
|
32
|
+
const hasFilenameCallback = typeof fileNameValue === "function";
|
|
33
|
+
const hasStoragePathCallback = typeof storagePathValue === "function";
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
<div className={"col-span-12"}>
|
|
38
|
+
|
|
39
|
+
<ValidationPanel>
|
|
40
|
+
|
|
41
|
+
<StringPropertyValidation disabled={disabled}
|
|
42
|
+
length={true}
|
|
43
|
+
lowercase={true}
|
|
44
|
+
max={true}
|
|
45
|
+
min={true}
|
|
46
|
+
trim={true}
|
|
47
|
+
uppercase={true}
|
|
48
|
+
showErrors={showErrors}/>
|
|
49
|
+
|
|
50
|
+
</ValidationPanel>
|
|
51
|
+
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div className={"col-span-12"}>
|
|
55
|
+
<ExpandablePanel
|
|
56
|
+
title={
|
|
57
|
+
<div className="flex flex-row text-gray-500">
|
|
58
|
+
<FileUploadIcon/>
|
|
59
|
+
<Typography variant={"subtitle2"}
|
|
60
|
+
className="ml-2">
|
|
61
|
+
File upload config
|
|
62
|
+
</Typography>
|
|
63
|
+
</div>
|
|
64
|
+
}>
|
|
65
|
+
|
|
66
|
+
<div className={"grid grid-cols-12 gap-2 p-4"}>
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
<div className={"col-span-12"}>
|
|
70
|
+
<Field name={fileName}
|
|
71
|
+
as={DebouncedTextField}
|
|
72
|
+
label={"File name"}
|
|
73
|
+
size={"small"}
|
|
74
|
+
disabled={hasFilenameCallback || disabled}
|
|
75
|
+
value={hasFilenameCallback ? "-" : fileNameValue}
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
<div className={"col-span-12"}>
|
|
79
|
+
<Field name={storagePath}
|
|
80
|
+
as={DebouncedTextField}
|
|
81
|
+
label={"Storage path"}
|
|
82
|
+
disabled={hasStoragePathCallback || disabled}
|
|
83
|
+
size={"small"}
|
|
84
|
+
value={hasStoragePathCallback ? "-" : storagePathValue}
|
|
85
|
+
/>
|
|
86
|
+
<Typography variant={"caption"} className={"ml-3.5 mt-1 mb-2"}>
|
|
87
|
+
<p>You can use the following placeholders in
|
|
88
|
+
the file name
|
|
89
|
+
and storage path values:</p>
|
|
90
|
+
<ul>
|
|
91
|
+
<li>{"{file} - Full name of the uploaded file"}</li>
|
|
92
|
+
<li>{"{file.name} - Name of the uploaded file without extension"}</li>
|
|
93
|
+
<li>{"{file.ext} - Extension of the uploaded file"}</li>
|
|
94
|
+
<li>{"{entityId} - ID of the entity"}</li>
|
|
95
|
+
<li>{"{propertyKey} - ID of this field"}</li>
|
|
96
|
+
<li>{"{path} - Path of this entity"}</li>
|
|
97
|
+
<li>{"{rand} - Random value used to avoid name collisions"}</li>
|
|
98
|
+
</ul>
|
|
99
|
+
</Typography>
|
|
100
|
+
|
|
101
|
+
<Typography variant={"caption"} className={"ml-3.5 mt-1 mb-2"}>
|
|
102
|
+
When using Markdown, the URL of the uploaded files are always saved in the text value
|
|
103
|
+
(not
|
|
104
|
+
the path).
|
|
105
|
+
</Typography>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<div className={"col-span-12"}>
|
|
109
|
+
<DebouncedTextField name={maxSize}
|
|
110
|
+
type={"number"}
|
|
111
|
+
label={"Max size (in bytes)"}
|
|
112
|
+
size={"small"}
|
|
113
|
+
value={maxSizeValue !== undefined && maxSizeValue !== null ? maxSizeValue.toString() : ""}
|
|
114
|
+
onChange={(e) => {
|
|
115
|
+
const value = e.target.value;
|
|
116
|
+
if (value === "") setFieldValue(maxSize, undefined);
|
|
117
|
+
else setFieldValue(maxSize, parseInt(value));
|
|
118
|
+
}}
|
|
119
|
+
/>
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
</div>
|
|
123
|
+
</ExpandablePanel>
|
|
124
|
+
</div>
|
|
125
|
+
|
|
126
|
+
<div className={"col-span-12"}>
|
|
127
|
+
|
|
128
|
+
<TextField name={"defaultValue"}
|
|
129
|
+
disabled={disabled}
|
|
130
|
+
onChange={(e: any) => {
|
|
131
|
+
setFieldValue("defaultValue", e.target.value === "" ? undefined : e.target.value);
|
|
132
|
+
}}
|
|
133
|
+
label={"Default value"}
|
|
134
|
+
value={getIn(values, "defaultValue") ?? ""}/>
|
|
135
|
+
|
|
136
|
+
</div>
|
|
137
|
+
</>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import {
|
|
3
3
|
Button,
|
|
4
|
-
Checkbox,
|
|
5
4
|
DebouncedTextField,
|
|
6
5
|
ExpandablePanel,
|
|
7
6
|
FileUploadIcon,
|
|
@@ -44,11 +43,13 @@ export function StoragePropertyField({
|
|
|
44
43
|
|
|
45
44
|
const metadata = `${baseStoragePath}.metadata`;
|
|
46
45
|
const fileName = `${baseStoragePath}.fileName`;
|
|
46
|
+
const maxSize = `${baseStoragePath}.maxSize`;
|
|
47
47
|
const storagePath = `${baseStoragePath}.storagePath`;
|
|
48
48
|
const storeUrl = `${baseStoragePath}.storeUrl`;
|
|
49
49
|
|
|
50
50
|
const fileNameValue = getIn(values, fileName) ?? "{rand}_{file}";
|
|
51
51
|
const storagePathValue = getIn(values, storagePath) ?? "/";
|
|
52
|
+
const maxSizeValue = getIn(values, maxSize);
|
|
52
53
|
|
|
53
54
|
const storedValue = getIn(values, acceptedFiles);
|
|
54
55
|
const fileTypesValue: string[] | undefined = Array.isArray(storedValue) ? storedValue : undefined;
|
|
@@ -56,10 +57,10 @@ export function StoragePropertyField({
|
|
|
56
57
|
|
|
57
58
|
const handleTypesChange = (value: string[]) => {
|
|
58
59
|
if (!value) setFieldValue(acceptedFiles, undefined);
|
|
59
|
-
else if (value.includes("all")) setFieldValue(acceptedFiles, undefined);
|
|
60
|
-
else if (value.length >= Object.keys(fileTypes).length) setFieldValue(acceptedFiles, undefined);
|
|
61
|
-
else if (allFileTypesSelected)
|
|
62
|
-
|
|
60
|
+
// else if (value.includes("all")) setFieldValue(acceptedFiles, undefined);
|
|
61
|
+
// else if (value.length >= Object.keys(fileTypes).length) setFieldValue(acceptedFiles, undefined);
|
|
62
|
+
// else if (allFileTypesSelected)
|
|
63
|
+
// setFieldValue(acceptedFiles, Object.keys(fileTypes).filter((v) => !value.includes(v)));
|
|
63
64
|
else setFieldValue(acceptedFiles, value);
|
|
64
65
|
};
|
|
65
66
|
|
|
@@ -87,10 +88,12 @@ export function StoragePropertyField({
|
|
|
87
88
|
<div className={"col-span-12"}>
|
|
88
89
|
|
|
89
90
|
<MultiSelect
|
|
91
|
+
className={"w-full"}
|
|
92
|
+
placeholder={"All file types allowed"}
|
|
90
93
|
disabled={disabled}
|
|
91
94
|
name={acceptedFiles}
|
|
92
95
|
value={fileTypesValue ?? []}
|
|
93
|
-
|
|
96
|
+
onValueChange={handleTypesChange}
|
|
94
97
|
label={allFileTypesSelected ? undefined : "Allowed file types"}
|
|
95
98
|
renderValues={(selected) => {
|
|
96
99
|
if (!selected || selected.length === 0) return "All file types allowed";
|
|
@@ -99,21 +102,15 @@ export function StoragePropertyField({
|
|
|
99
102
|
.join(", ");
|
|
100
103
|
}}>
|
|
101
104
|
|
|
102
|
-
<MultiSelectItem key={"all"} value={"all"} className={"flex items-center gap-2"}>
|
|
103
|
-
<Checkbox
|
|
104
|
-
checked={!fileTypesValue}/>
|
|
105
|
-
All
|
|
106
|
-
</MultiSelectItem>
|
|
107
|
-
|
|
108
105
|
{Object.entries(fileTypes).map(([value, label]) => (
|
|
109
106
|
<MultiSelectItem key={value} value={value} className={"flex items-center gap-2"}>
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
{/*<Checkbox*/}
|
|
108
|
+
{/* checked={allFileTypesSelected || fileTypesValue.indexOf(value) > -1}/>*/}
|
|
112
109
|
<div className={"flex-grow"}>
|
|
113
110
|
{label}
|
|
114
111
|
</div>
|
|
115
112
|
<Button size={"small"}
|
|
116
|
-
variant={"
|
|
113
|
+
variant={"text"}
|
|
117
114
|
onClick={(e) => {
|
|
118
115
|
e.preventDefault();
|
|
119
116
|
e.stopPropagation();
|
|
@@ -161,7 +158,10 @@ export function StoragePropertyField({
|
|
|
161
158
|
|
|
162
159
|
<Field name={storeUrl}
|
|
163
160
|
type="checkbox">
|
|
164
|
-
{({
|
|
161
|
+
{({
|
|
162
|
+
field,
|
|
163
|
+
form
|
|
164
|
+
}: FormexFieldProps) => {
|
|
165
165
|
return <SwitchControl
|
|
166
166
|
label={"Save URL instead of storage path"}
|
|
167
167
|
disabled={existing || disabled}
|
|
@@ -178,6 +178,21 @@ export function StoragePropertyField({
|
|
|
178
178
|
You can only change this prop upon creation.
|
|
179
179
|
</Typography>
|
|
180
180
|
</div>
|
|
181
|
+
|
|
182
|
+
<div className={"col-span-12"}>
|
|
183
|
+
<DebouncedTextField name={maxSize}
|
|
184
|
+
type={"number"}
|
|
185
|
+
label={"Max size (in bytes)"}
|
|
186
|
+
size={"small"}
|
|
187
|
+
value={maxSizeValue !== undefined && maxSizeValue !== null ? maxSizeValue.toString() : ""}
|
|
188
|
+
onChange={(e) => {
|
|
189
|
+
const value = e.target.value;
|
|
190
|
+
if (value === "") setFieldValue(maxSize, undefined);
|
|
191
|
+
else setFieldValue(maxSize, parseInt(value));
|
|
192
|
+
}}
|
|
193
|
+
/>
|
|
194
|
+
</div>
|
|
195
|
+
|
|
181
196
|
</div>
|
|
182
197
|
</ExpandablePanel>
|
|
183
198
|
|
|
@@ -10,7 +10,7 @@ export function StringPropertyField({
|
|
|
10
10
|
disabled,
|
|
11
11
|
showErrors
|
|
12
12
|
}: {
|
|
13
|
-
widgetId: "text_field" | "multiline" | "
|
|
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}
|
|
@@ -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
|
};
|
|
@@ -51,6 +51,13 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
|
|
|
51
51
|
|
|
52
52
|
onAnalyticsEvent?: (event: string, params?: object) => void;
|
|
53
53
|
|
|
54
|
+
components?: {
|
|
55
|
+
/**
|
|
56
|
+
* Custom component to render the database field
|
|
57
|
+
*/
|
|
58
|
+
DatabaseField?: React.ComponentType<{ databaseId?: string, onDatabaseIdUpdate: (databaseId:string) => void }>;
|
|
59
|
+
};
|
|
60
|
+
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
/**
|
|
@@ -74,7 +81,8 @@ export function useCollectionEditorPlugin<EC extends PersistedCollection = Persi
|
|
|
74
81
|
getUser,
|
|
75
82
|
collectionInference,
|
|
76
83
|
getData,
|
|
77
|
-
onAnalyticsEvent
|
|
84
|
+
onAnalyticsEvent,
|
|
85
|
+
components
|
|
78
86
|
}: CollectionConfigControllerProps<EC, UserType>): FireCMSPlugin<any, any, PersistedCollection> {
|
|
79
87
|
|
|
80
88
|
return {
|
|
@@ -91,7 +99,8 @@ export function useCollectionEditorPlugin<EC extends PersistedCollection = Persi
|
|
|
91
99
|
getPathSuggestions,
|
|
92
100
|
getUser,
|
|
93
101
|
getData,
|
|
94
|
-
onAnalyticsEvent
|
|
102
|
+
onAnalyticsEvent,
|
|
103
|
+
components
|
|
95
104
|
}
|
|
96
105
|
},
|
|
97
106
|
homePage: {
|
|
@@ -147,7 +156,7 @@ export function IntroWidget({}: {}) {
|
|
|
147
156
|
: undefined}>
|
|
148
157
|
<AddIcon/>Create your first collection
|
|
149
158
|
</Button>}
|
|
150
|
-
<Typography
|
|
159
|
+
<Typography color={"secondary"}>
|
|
151
160
|
You can also define collections programmatically.
|
|
152
161
|
</Typography>
|
|
153
162
|
</Paper>
|