@firecms/core 3.0.0-beta.7 → 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/dist/app/AppBar.d.ts +12 -0
- package/dist/app/Drawer.d.ts +17 -0
- package/dist/app/Scaffold.d.ts +30 -0
- package/dist/app/index.d.ts +4 -0
- package/dist/app/useApp.d.ts +16 -0
- package/dist/components/ArrayContainer.d.ts +2 -1
- package/dist/components/CircularProgressCenter.d.ts +1 -1
- package/dist/components/EntityCollectionTable/EntityCollectionRowActions.d.ts +0 -1
- package/dist/components/EntityCollectionTable/fields/TableReferenceField.d.ts +1 -1
- package/dist/components/EntityCollectionTable/internal/popup_field/PopupFormField.d.ts +1 -1
- package/dist/components/EntityCollectionView/EntityCollectionView.d.ts +1 -1
- package/dist/components/EntityPreview.d.ts +1 -1
- package/dist/components/ErrorView.d.ts +1 -1
- package/dist/components/HomePage/DefaultHomePage.d.ts +1 -1
- package/dist/components/HomePage/NavigationCardBinding.d.ts +1 -1
- package/dist/components/PropertyIdCopyTooltip.d.ts +8 -0
- package/dist/components/VirtualTable/VirtualTableProps.d.ts +14 -6
- package/dist/components/common/useColumnsIds.d.ts +2 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/{components/FireCMSAppBar.d.ts → core/DefaultAppBar.d.ts} +3 -8
- package/dist/core/DefaultDrawer.d.ts +19 -0
- package/dist/core/DrawerNavigationItem.d.ts +2 -1
- package/dist/core/EntityEditView.d.ts +18 -4
- package/dist/core/FireCMS.d.ts +1 -1
- package/dist/core/NavigationRoutes.d.ts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/form/PropertyFieldBinding.d.ts +1 -1
- package/dist/form/components/FieldHelperText.d.ts +3 -3
- package/dist/form/components/FormikArrayContainer.d.ts +2 -1
- package/dist/form/components/LabelWithIcon.d.ts +1 -1
- package/dist/form/components/LabelWithIconAndTooltip.d.ts +15 -0
- package/dist/form/components/StorageItemPreview.d.ts +4 -4
- package/dist/form/components/index.d.ts +1 -0
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/KeyValueFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +11 -0
- package/dist/form/field_bindings/{MultiSelectBinding.d.ts → MultiSelectFieldBinding.d.ts} +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/RepeatFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.d.ts +3 -5
- package/dist/form/field_bindings/TextFieldBinding.d.ts +1 -1
- package/dist/form/index.d.ts +3 -5
- package/dist/form/useClearRestoreValue.d.ts +2 -2
- package/dist/hooks/useProjectLog.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +14434 -11300
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +19987 -587
- package/dist/index.umd.js.map +1 -1
- package/dist/preview/PropertyPreviewProps.d.ts +6 -1
- package/dist/preview/components/EnumValuesChip.d.ts +1 -1
- package/dist/preview/components/ReferencePreview.d.ts +1 -1
- package/dist/preview/components/StorageThumbnail.d.ts +2 -1
- package/dist/preview/components/UrlComponentPreview.d.ts +2 -1
- package/dist/types/auth.d.ts +2 -2
- package/dist/types/collections.d.ts +26 -3
- package/dist/types/datasource.d.ts +53 -30
- package/dist/types/entities.d.ts +1 -0
- package/dist/types/entity_overrides.d.ts +2 -2
- package/dist/types/fields.d.ts +47 -41
- package/dist/types/navigation.d.ts +1 -0
- package/dist/types/plugins.d.ts +11 -3
- package/dist/types/properties.d.ts +25 -20
- package/dist/types/side_dialogs_controller.d.ts +10 -0
- package/dist/types/storage.d.ts +75 -0
- package/dist/util/entities.d.ts +1 -1
- package/dist/util/icon_list.d.ts +5 -1
- package/dist/util/icons.d.ts +3 -2
- package/dist/util/index.d.ts +1 -0
- package/dist/util/plurals.d.ts +0 -2
- package/dist/util/property_utils.d.ts +1 -1
- package/dist/util/resolutions.d.ts +15 -1
- package/dist/util/storage.d.ts +23 -2
- package/dist/util/useStorageUploadController.d.ts +3 -3
- package/package.json +18 -29
- package/src/app/AppBar.tsx +18 -0
- package/src/app/Drawer.tsx +25 -0
- package/src/{core → app}/Scaffold.tsx +71 -122
- package/src/app/index.ts +4 -0
- package/src/app/useApp.tsx +32 -0
- package/src/components/ArrayContainer.tsx +15 -10
- package/src/components/CircularProgressCenter.tsx +1 -1
- package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +11 -18
- package/src/components/EntityCollectionTable/EntityCollectionTable.tsx +2 -2
- package/src/components/EntityCollectionTable/PropertyTableCell.tsx +4 -2
- package/src/components/EntityCollectionTable/fields/TableReferenceField.tsx +21 -14
- package/src/components/EntityCollectionTable/fields/TableStorageUpload.tsx +12 -4
- package/src/components/EntityCollectionTable/internal/EntityTableCell.tsx +17 -19
- package/src/components/EntityCollectionTable/internal/EntityTableCellActions.tsx +19 -7
- package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +5 -6
- package/src/components/EntityCollectionView/EntityCollectionView.tsx +33 -29
- package/src/components/EntityCollectionView/useSelectionController.tsx +19 -7
- package/src/components/EntityPreview.tsx +30 -31
- package/src/components/ErrorView.tsx +1 -1
- package/src/components/HomePage/DefaultHomePage.tsx +24 -18
- package/src/components/HomePage/NavigationCardBinding.tsx +1 -1
- package/src/components/HomePage/SmallNavigationCard.tsx +1 -2
- package/src/components/PropertyIdCopyTooltip.tsx +48 -0
- package/src/components/ReferenceTable/ReferenceSelectionTable.tsx +7 -6
- package/src/components/SearchIconsView.tsx +5 -2
- package/src/components/SelectableTable/SelectableTable.tsx +2 -4
- package/src/components/SelectableTable/filters/DateTimeFilterField.tsx +1 -1
- package/src/components/SelectableTable/filters/StringNumberFilterField.tsx +54 -7
- package/src/components/VirtualTable/VirtualTable.tsx +36 -10
- package/src/components/VirtualTable/VirtualTableCell.tsx +1 -9
- package/src/components/VirtualTable/VirtualTableProps.tsx +17 -8
- package/src/components/VirtualTable/fields/VirtualTableDateField.tsx +3 -3
- package/src/components/VirtualTable/fields/VirtualTableInput.tsx +2 -1
- package/src/components/VirtualTable/fields/VirtualTableNumberInput.tsx +2 -1
- package/src/components/VirtualTable/fields/VirtualTableSelect.tsx +14 -28
- package/src/components/common/useColumnsIds.tsx +13 -0
- package/src/components/common/useDataSourceEntityCollectionTableController.tsx +12 -12
- package/src/components/common/useTableSearchHelper.ts +53 -12
- package/src/components/index.tsx +2 -1
- package/src/contexts/DialogsProvider.tsx +2 -2
- package/src/{components/FireCMSAppBar.tsx → core/DefaultAppBar.tsx} +28 -30
- package/src/core/DefaultDrawer.tsx +183 -0
- package/src/core/DrawerNavigationItem.tsx +31 -27
- package/src/core/EntityEditView.tsx +712 -145
- package/src/core/EntitySidePanel.tsx +0 -1
- package/src/core/FireCMS.tsx +2 -2
- package/src/core/NavigationRoutes.tsx +4 -4
- package/src/core/SideDialogs.tsx +1 -0
- package/src/core/field_configs.tsx +5 -5
- package/src/core/index.tsx +2 -2
- package/src/form/PropertyFieldBinding.tsx +53 -19
- package/src/form/components/CustomIdField.tsx +4 -2
- package/src/form/components/FieldHelperText.tsx +4 -4
- package/src/form/components/FormikArrayContainer.tsx +4 -1
- package/src/form/components/LabelWithIcon.tsx +27 -19
- package/src/form/components/LabelWithIconAndTooltip.tsx +28 -0
- package/src/form/components/StorageItemPreview.tsx +20 -10
- package/src/form/components/StorageUploadProgress.tsx +0 -1
- package/src/form/components/index.tsx +1 -0
- package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +26 -15
- package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +28 -25
- package/src/form/field_bindings/BlockFieldBinding.tsx +13 -11
- package/src/form/field_bindings/DateTimeFieldBinding.tsx +17 -14
- package/src/form/field_bindings/KeyValueFieldBinding.tsx +48 -42
- package/src/form/field_bindings/MapFieldBinding.tsx +17 -17
- package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +150 -0
- package/src/form/field_bindings/{MultiSelectBinding.tsx → MultiSelectFieldBinding.tsx} +25 -20
- package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +9 -14
- package/src/form/field_bindings/ReferenceFieldBinding.tsx +27 -18
- package/src/form/field_bindings/RepeatFieldBinding.tsx +32 -19
- package/src/form/field_bindings/SelectFieldBinding.tsx +17 -10
- package/src/form/field_bindings/StorageUploadFieldBinding.tsx +33 -43
- package/src/form/field_bindings/SwitchFieldBinding.tsx +9 -5
- package/src/form/field_bindings/TextFieldBinding.tsx +26 -23
- package/src/form/index.tsx +4 -9
- package/src/form/useClearRestoreValue.tsx +2 -2
- package/src/form/validation.ts +1 -17
- package/src/hooks/data/delete.ts +2 -1
- package/src/hooks/data/save.ts +5 -2
- package/src/hooks/data/useDataSource.tsx +11 -3
- package/src/hooks/useBuildNavigationController.tsx +10 -3
- package/src/hooks/useProjectLog.tsx +18 -7
- package/src/index.ts +1 -0
- package/src/internal/useBuildDataSource.ts +69 -74
- package/src/internal/useBuildSideDialogsController.tsx +1 -0
- package/src/internal/useBuildSideEntityController.tsx +17 -4
- package/src/internal/useUnsavedChangesDialog.tsx +3 -1
- package/src/preview/PropertyPreview.tsx +7 -4
- package/src/preview/PropertyPreviewProps.tsx +7 -1
- package/src/preview/components/BooleanPreview.tsx +1 -1
- package/src/preview/components/EnumValuesChip.tsx +1 -1
- package/src/preview/components/ImagePreview.tsx +24 -34
- package/src/preview/components/ReferencePreview.tsx +2 -12
- package/src/preview/components/StorageThumbnail.tsx +5 -1
- package/src/preview/components/UrlComponentPreview.tsx +44 -11
- package/src/preview/property_previews/ArrayOfMapsPreview.tsx +1 -1
- package/src/preview/property_previews/ArrayOfReferencesPreview.tsx +1 -1
- package/src/preview/property_previews/ArrayOfStorageComponentsPreview.tsx +1 -1
- package/src/preview/property_previews/ArrayOneOfPreview.tsx +2 -2
- package/src/preview/property_previews/ArrayPropertyPreview.tsx +1 -1
- package/src/preview/property_previews/MapPropertyPreview.tsx +1 -1
- package/src/preview/property_previews/SkeletonPropertyComponent.tsx +2 -2
- package/src/preview/property_previews/StringPropertyPreview.tsx +2 -2
- package/src/preview/util.ts +2 -2
- package/src/types/auth.tsx +2 -2
- package/src/types/collections.ts +29 -4
- package/src/types/customization_controller.tsx +0 -1
- package/src/types/datasource.ts +62 -43
- package/src/types/entities.ts +2 -0
- package/src/types/entity_overrides.tsx +2 -2
- package/src/types/fields.tsx +51 -45
- package/src/types/navigation.ts +1 -0
- package/src/types/plugins.tsx +12 -3
- package/src/types/properties.ts +25 -19
- package/src/types/side_dialogs_controller.tsx +13 -0
- package/src/types/storage.ts +82 -0
- package/src/util/entities.ts +5 -4
- package/src/util/icon_list.ts +14 -9
- package/src/util/icons.tsx +8 -2
- package/src/util/index.ts +1 -0
- package/src/util/objects.ts +17 -7
- package/src/util/permissions.ts +1 -0
- package/src/util/plurals.ts +0 -2
- package/src/util/property_utils.tsx +1 -1
- package/src/util/references.ts +3 -0
- package/src/util/resolutions.ts +43 -11
- package/src/util/storage.ts +79 -21
- package/src/util/useStorageUploadController.tsx +33 -7
- package/dist/components/PropertyIdCopyTooltipContent.d.ts +0 -3
- package/dist/core/Drawer.d.ts +0 -16
- package/dist/core/Scaffold.d.ts +0 -51
- package/dist/form/EntityForm.d.ts +0 -77
- package/dist/form/field_bindings/MarkdownFieldBinding.d.ts +0 -9
- package/src/components/PropertyIdCopyTooltipContent.tsx +0 -27
- package/src/core/Drawer.tsx +0 -139
- package/src/form/EntityForm.tsx +0 -736
- package/src/form/field_bindings/MarkdownFieldBinding.tsx +0 -695
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { useCallback, useMemo } from "react";
|
|
2
2
|
import { Entity, EntityCollection, EntityReference, FieldProps, ResolvedProperty } from "../../types";
|
|
3
3
|
import { ReferencePreview } from "../../preview";
|
|
4
|
-
import { FieldHelperText, FormikArrayContainer,
|
|
4
|
+
import { FieldHelperText, FormikArrayContainer, LabelWithIconAndTooltip } from "../components";
|
|
5
5
|
import { ErrorView } from "../../components";
|
|
6
6
|
import { getIconForProperty, getReferenceFrom } from "../../util";
|
|
7
7
|
|
|
8
8
|
import { useNavigationController, useReferenceDialog } from "../../hooks";
|
|
9
|
-
import { Button, cls, ExpandablePanel, fieldBackgroundMixin } from "@firecms/ui";
|
|
9
|
+
import { Button, cls, ExpandablePanel, fieldBackgroundMixin, Typography } from "@firecms/ui";
|
|
10
10
|
import { useClearRestoreValue } from "../useClearRestoreValue";
|
|
11
11
|
|
|
12
12
|
type ArrayOfReferencesFieldProps = FieldProps<EntityReference[]>;
|
|
@@ -25,7 +25,7 @@ export function ArrayOfReferencesFieldBinding({
|
|
|
25
25
|
showError,
|
|
26
26
|
disabled,
|
|
27
27
|
isSubmitting,
|
|
28
|
-
|
|
28
|
+
minimalistView,
|
|
29
29
|
property,
|
|
30
30
|
includeDescription,
|
|
31
31
|
setValue,
|
|
@@ -70,36 +70,39 @@ export function ArrayOfReferencesFieldBinding({
|
|
|
70
70
|
}
|
|
71
71
|
);
|
|
72
72
|
|
|
73
|
-
const onEntryClick =
|
|
73
|
+
const onEntryClick = (e: React.SyntheticEvent) => {
|
|
74
74
|
e.preventDefault();
|
|
75
75
|
referenceDialogController.open();
|
|
76
|
-
}
|
|
76
|
+
};
|
|
77
77
|
|
|
78
78
|
const buildEntry = useCallback((index: number, internalId: number) => {
|
|
79
79
|
const entryValue = value && value.length > index ? value[index] : undefined;
|
|
80
80
|
if (!entryValue)
|
|
81
81
|
return <div>Internal ERROR</div>;
|
|
82
82
|
return (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
<ReferencePreview
|
|
84
|
+
key={internalId}
|
|
85
|
+
disabled={!ofProperty.path}
|
|
86
|
+
previewProperties={ofProperty.previewProperties}
|
|
87
|
+
size={"medium"}
|
|
88
|
+
onClick={onEntryClick}
|
|
89
|
+
hover={!disabled}
|
|
90
|
+
reference={entryValue}
|
|
91
|
+
includeId={ofProperty.includeId}
|
|
92
|
+
includeEntityLink={ofProperty.includeEntityLink}
|
|
93
|
+
/>
|
|
94
94
|
);
|
|
95
95
|
}, [ofProperty.path, ofProperty.previewProperties, value]);
|
|
96
96
|
|
|
97
|
-
const title = (
|
|
98
|
-
<
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
const title = (<>
|
|
98
|
+
<LabelWithIconAndTooltip
|
|
99
|
+
propertyKey={propertyKey}
|
|
100
|
+
icon={getIconForProperty(property, "small")}
|
|
101
|
+
required={property.validation?.required}
|
|
102
|
+
title={property.name}
|
|
103
|
+
className={"flex flex-grow text-text-secondary dark:text-text-secondary-dark"}/>
|
|
104
|
+
{Array.isArray(value) && <Typography variant={"caption"} className={"px-4"}>({value.length})</Typography>}
|
|
105
|
+
</>);
|
|
103
106
|
|
|
104
107
|
const body = <>
|
|
105
108
|
{!collection && <ErrorView
|
|
@@ -117,7 +120,7 @@ export function ArrayOfReferencesFieldBinding({
|
|
|
117
120
|
|
|
118
121
|
<Button
|
|
119
122
|
className="my-4 justify-center text-left"
|
|
120
|
-
variant="
|
|
123
|
+
variant="text"
|
|
121
124
|
color="primary"
|
|
122
125
|
disabled={isSubmitting}
|
|
123
126
|
onClick={onEntryClick}>
|
|
@@ -129,7 +132,7 @@ export function ArrayOfReferencesFieldBinding({
|
|
|
129
132
|
return (
|
|
130
133
|
<>
|
|
131
134
|
|
|
132
|
-
{!
|
|
135
|
+
{!minimalistView &&
|
|
133
136
|
<ExpandablePanel
|
|
134
137
|
titleClassName={fieldBackgroundMixin}
|
|
135
138
|
className={cls("px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2", fieldBackgroundMixin)}
|
|
@@ -138,7 +141,7 @@ export function ArrayOfReferencesFieldBinding({
|
|
|
138
141
|
{body}
|
|
139
142
|
</ExpandablePanel>}
|
|
140
143
|
|
|
141
|
-
{
|
|
144
|
+
{minimalistView && body}
|
|
142
145
|
|
|
143
146
|
<FieldHelperText includeDescription={includeDescription}
|
|
144
147
|
showError={showError}
|
|
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useState } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { Field, useFormex } from "@firecms/formex";
|
|
4
4
|
|
|
5
|
-
import { FieldHelperText, FormikArrayContainer,
|
|
5
|
+
import { FieldHelperText, FormikArrayContainer, LabelWithIconAndTooltip } from "../components";
|
|
6
6
|
import { PropertyFieldBinding } from "../PropertyFieldBinding";
|
|
7
7
|
import { EnumValuesChip } from "../../preview";
|
|
8
8
|
import { FieldProps, FormContext, PropertyFieldBindingProps, PropertyOrBuilder } from "../../types";
|
|
@@ -27,7 +27,7 @@ export function BlockFieldBinding<T extends Array<any>>({
|
|
|
27
27
|
isSubmitting,
|
|
28
28
|
setValue,
|
|
29
29
|
setFieldValue,
|
|
30
|
-
|
|
30
|
+
minimalistView,
|
|
31
31
|
property,
|
|
32
32
|
includeDescription,
|
|
33
33
|
underlyingValueHasChanged,
|
|
@@ -61,14 +61,17 @@ export function BlockFieldBinding<T extends Array<any>>({
|
|
|
61
61
|
}, [context, lastAddedId, property.oneOf, propertyKey, value]);
|
|
62
62
|
|
|
63
63
|
const title = (
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
<LabelWithIconAndTooltip
|
|
65
|
+
propertyKey={propertyKey}
|
|
66
|
+
icon={getIconForProperty(property, "small")}
|
|
67
|
+
required={property.validation?.required}
|
|
68
|
+
title={property.name}
|
|
69
|
+
className={"text-text-secondary dark:text-text-secondary-dark"}/>
|
|
68
70
|
);
|
|
69
71
|
|
|
70
72
|
const firstOneOfKey = Object.keys(property.oneOf.properties)[0];
|
|
71
73
|
const body = <FormikArrayContainer value={value}
|
|
74
|
+
className={"flex flex-col gap-3"}
|
|
72
75
|
name={propertyKey}
|
|
73
76
|
addLabel={property.name ? "Add entry to " + property.name : "Add entry"}
|
|
74
77
|
buildEntry={buildEntry}
|
|
@@ -84,7 +87,7 @@ export function BlockFieldBinding<T extends Array<any>>({
|
|
|
84
87
|
|
|
85
88
|
<>
|
|
86
89
|
|
|
87
|
-
{!
|
|
90
|
+
{!minimalistView &&
|
|
88
91
|
<ExpandablePanel
|
|
89
92
|
className={"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2"}
|
|
90
93
|
initiallyExpanded={expanded}
|
|
@@ -92,7 +95,7 @@ export function BlockFieldBinding<T extends Array<any>>({
|
|
|
92
95
|
{body}
|
|
93
96
|
</ExpandablePanel>}
|
|
94
97
|
|
|
95
|
-
{
|
|
98
|
+
{minimalistView && body}
|
|
96
99
|
|
|
97
100
|
<FieldHelperText includeDescription={includeDescription}
|
|
98
101
|
showError={showError}
|
|
@@ -179,8 +182,7 @@ function BlockEntry({
|
|
|
179
182
|
context,
|
|
180
183
|
autoFocus,
|
|
181
184
|
partOfArray: false,
|
|
182
|
-
|
|
183
|
-
tableMode: false
|
|
185
|
+
minimalistView: true
|
|
184
186
|
}
|
|
185
187
|
: undefined;
|
|
186
188
|
|
|
@@ -193,7 +195,7 @@ function BlockEntry({
|
|
|
193
195
|
};
|
|
194
196
|
|
|
195
197
|
return (
|
|
196
|
-
<div className={cls(paperMixin, "bg-transparent p-
|
|
198
|
+
<div className={cls(paperMixin, "bg-transparent p-2")}>
|
|
197
199
|
|
|
198
200
|
<Field
|
|
199
201
|
name={typeFieldName}
|
|
@@ -7,6 +7,7 @@ import { useCustomizationController } from "../../hooks";
|
|
|
7
7
|
import { getIconForProperty } from "../../util";
|
|
8
8
|
import { DateTimeField } from "@firecms/ui";
|
|
9
9
|
import { useClearRestoreValue } from "../useClearRestoreValue";
|
|
10
|
+
import { PropertyIdCopyTooltip } from "../../components";
|
|
10
11
|
|
|
11
12
|
type DateTimeFieldProps = FieldProps<Date>;
|
|
12
13
|
|
|
@@ -41,20 +42,22 @@ export function DateTimeFieldBinding({
|
|
|
41
42
|
|
|
42
43
|
return (
|
|
43
44
|
<>
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
<PropertyIdCopyTooltip propertyKey={propertyKey}>
|
|
46
|
+
<DateTimeField
|
|
47
|
+
value={internalValue}
|
|
48
|
+
onChange={(dateValue) => setValue(dateValue)}
|
|
49
|
+
size={"medium"}
|
|
50
|
+
mode={property.mode}
|
|
51
|
+
clearable={property.clearable}
|
|
52
|
+
locale={locale}
|
|
53
|
+
error={showError}
|
|
54
|
+
label={<LabelWithIcon
|
|
55
|
+
icon={getIconForProperty(property, "small")}
|
|
56
|
+
required={property.validation?.required}
|
|
57
|
+
className={showError ? "text-red-500 dark:text-red-500" : "text-text-secondary dark:text-text-secondary-dark"}
|
|
58
|
+
title={property.name}/>}
|
|
59
|
+
/>
|
|
60
|
+
</PropertyIdCopyTooltip>
|
|
58
61
|
|
|
59
62
|
<FieldHelperText includeDescription={includeDescription}
|
|
60
63
|
showError={showError}
|
|
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
|
|
|
2
2
|
import { DataType, FieldProps, GeoPoint } from "../../types";
|
|
3
3
|
|
|
4
4
|
import { ArrayContainer } from "../../components";
|
|
5
|
-
import { FieldHelperText,
|
|
5
|
+
import { FieldHelperText, LabelWithIconAndTooltip } from "../components";
|
|
6
6
|
import {
|
|
7
7
|
AddIcon,
|
|
8
8
|
ArrowDropDownIcon,
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
} from "@firecms/ui";
|
|
22
22
|
import { getDefaultValueForDataType, getIconForProperty } from "../../util";
|
|
23
23
|
import { useCustomizationController } from "../../hooks";
|
|
24
|
+
import { getIn } from "@firecms/formex";
|
|
24
25
|
|
|
25
26
|
type MapEditViewRowState = [number, {
|
|
26
27
|
key: string,
|
|
@@ -40,7 +41,7 @@ export function KeyValueFieldBinding({
|
|
|
40
41
|
disabled,
|
|
41
42
|
property,
|
|
42
43
|
setValue,
|
|
43
|
-
|
|
44
|
+
minimalistView,
|
|
44
45
|
includeDescription,
|
|
45
46
|
underlyingValueHasChanged,
|
|
46
47
|
autoFocus,
|
|
@@ -52,12 +53,17 @@ export function KeyValueFieldBinding({
|
|
|
52
53
|
if (!property.keyValue) {
|
|
53
54
|
throw Error(`Your property ${propertyKey} needs to have the 'keyValue' prop in order to use this field binding`);
|
|
54
55
|
}
|
|
56
|
+
|
|
57
|
+
const initialValues = getIn(context.formex.initialValues, propertyKey);
|
|
58
|
+
|
|
55
59
|
const mapFormView = <MapEditView value={value}
|
|
56
60
|
setValue={setValue}
|
|
57
61
|
disabled={disabled}
|
|
62
|
+
initialValue={initialValues}
|
|
58
63
|
fieldName={property.name ?? propertyKey}/>;
|
|
59
64
|
|
|
60
|
-
const title = <
|
|
65
|
+
const title = <LabelWithIconAndTooltip
|
|
66
|
+
propertyKey={propertyKey}
|
|
61
67
|
icon={getIconForProperty(property, "small")}
|
|
62
68
|
required={property.validation?.required}
|
|
63
69
|
title={property.name}
|
|
@@ -66,11 +72,11 @@ export function KeyValueFieldBinding({
|
|
|
66
72
|
return (
|
|
67
73
|
<>
|
|
68
74
|
|
|
69
|
-
{!
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
{!minimalistView && <ExpandablePanel initiallyExpanded={expanded}
|
|
76
|
+
title={title}
|
|
77
|
+
className={"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2"}>{mapFormView}</ExpandablePanel>}
|
|
72
78
|
|
|
73
|
-
{
|
|
79
|
+
{minimalistView && mapFormView}
|
|
74
80
|
|
|
75
81
|
<FieldHelperText includeDescription={includeDescription}
|
|
76
82
|
showError={showError}
|
|
@@ -84,6 +90,7 @@ export function KeyValueFieldBinding({
|
|
|
84
90
|
|
|
85
91
|
interface MapEditViewParams<T extends Record<string, any>> {
|
|
86
92
|
value?: T;
|
|
93
|
+
initialValue?: T;
|
|
87
94
|
setValue: (value: (T | null)) => void;
|
|
88
95
|
fieldName?: string,
|
|
89
96
|
disabled?: boolean
|
|
@@ -91,14 +98,15 @@ interface MapEditViewParams<T extends Record<string, any>> {
|
|
|
91
98
|
|
|
92
99
|
function MapEditView<T extends Record<string, any>>({
|
|
93
100
|
value,
|
|
101
|
+
initialValue,
|
|
94
102
|
setValue,
|
|
95
103
|
fieldName,
|
|
96
104
|
disabled
|
|
97
105
|
}: MapEditViewParams<T>) {
|
|
98
106
|
const [internalState, setInternalState] = React.useState<MapEditViewRowState[]>(
|
|
99
|
-
Object.keys(
|
|
107
|
+
Object.keys(initialValue ?? {}).map((key) => [getRandomId(), {
|
|
100
108
|
key,
|
|
101
|
-
dataType: getDataType(
|
|
109
|
+
dataType: getDataType(initialValue?.[key]) ?? "string"
|
|
102
110
|
}])
|
|
103
111
|
);
|
|
104
112
|
|
|
@@ -121,8 +129,6 @@ function MapEditView<T extends Record<string, any>>({
|
|
|
121
129
|
setInternalState(newRowIds);
|
|
122
130
|
}, [value]);
|
|
123
131
|
|
|
124
|
-
const originalValue = React.useRef<T>(value ?? {} as T);
|
|
125
|
-
|
|
126
132
|
const updateDataType = (rowId: number, dataType: DataType) => {
|
|
127
133
|
if (!rowId) {
|
|
128
134
|
console.warn("No key selected for data type update");
|
|
@@ -168,7 +174,7 @@ function MapEditView<T extends Record<string, any>>({
|
|
|
168
174
|
}
|
|
169
175
|
|
|
170
176
|
const newValue = { ...(value ?? {}) } as T;
|
|
171
|
-
if (typeof
|
|
177
|
+
if (typeof initialValue === "object" && fieldKey in initialValue) {
|
|
172
178
|
// @ts-ignore
|
|
173
179
|
newValue[fieldKey] = undefined; // set to undefined to remove from the object, the datasource will remove it from the backend
|
|
174
180
|
} else {
|
|
@@ -186,7 +192,7 @@ function MapEditView<T extends Record<string, any>>({
|
|
|
186
192
|
value={value ?? {} as T}
|
|
187
193
|
onDeleteClick={() => {
|
|
188
194
|
const newValue = { ...(value ?? {}) as T };
|
|
189
|
-
if (
|
|
195
|
+
if (initialValue && fieldKey in initialValue) {
|
|
190
196
|
// @ts-ignore
|
|
191
197
|
newValue[fieldKey] = undefined;
|
|
192
198
|
} else {
|
|
@@ -305,7 +311,7 @@ function MapKeyValueRow<T extends Record<string, any>>({
|
|
|
305
311
|
}}/>;
|
|
306
312
|
} else if (dataType === "boolean") {
|
|
307
313
|
return <BooleanSwitchWithLabel value={entryValue}
|
|
308
|
-
size={"
|
|
314
|
+
size={"medium"}
|
|
309
315
|
position={"start"}
|
|
310
316
|
disabled={disabled || !fieldKey}
|
|
311
317
|
onValueChange={(newValue) => {
|
|
@@ -375,7 +381,7 @@ function MapKeyValueRow<T extends Record<string, any>>({
|
|
|
375
381
|
<Typography key={rowId.toString()}
|
|
376
382
|
component={"div"}
|
|
377
383
|
className="font-mono flex flex-row gap-1">
|
|
378
|
-
<div className="w-[
|
|
384
|
+
<div className="w-[300px] max-w-[30%]">
|
|
379
385
|
<TextField
|
|
380
386
|
value={fieldKey}
|
|
381
387
|
placeholder={"key"}
|
|
@@ -389,32 +395,32 @@ function MapKeyValueRow<T extends Record<string, any>>({
|
|
|
389
395
|
<div className="flex-grow">
|
|
390
396
|
{(dataType !== "map" && dataType !== "array") && buildInput(entryValue, fieldKey, dataType)}
|
|
391
397
|
</div>
|
|
392
|
-
<
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
</
|
|
398
|
+
<div className={"flex flex-col"}>
|
|
399
|
+
<Menu
|
|
400
|
+
trigger={<IconButton size={"smallest"}>
|
|
401
|
+
<ArrowDropDownIcon size={"small"}/>
|
|
402
|
+
</IconButton>}
|
|
403
|
+
>
|
|
404
|
+
<MenuItem dense
|
|
405
|
+
onClick={() => doUpdateDataType("string")}>string</MenuItem>
|
|
406
|
+
<MenuItem dense
|
|
407
|
+
onClick={() => doUpdateDataType("number")}>number</MenuItem>
|
|
408
|
+
<MenuItem dense
|
|
409
|
+
onClick={() => doUpdateDataType("boolean")}>boolean</MenuItem>
|
|
410
|
+
<MenuItem dense
|
|
411
|
+
onClick={() => doUpdateDataType("date")}>date</MenuItem>
|
|
412
|
+
<MenuItem dense
|
|
413
|
+
onClick={() => doUpdateDataType("map")}>map</MenuItem>
|
|
414
|
+
<MenuItem dense
|
|
415
|
+
onClick={() => doUpdateDataType("array")}>array</MenuItem>
|
|
416
|
+
</Menu>
|
|
417
|
+
|
|
418
|
+
<IconButton aria-label="delete"
|
|
419
|
+
size={"smallest"}
|
|
420
|
+
onClick={onDeleteClick}>
|
|
421
|
+
<RemoveIcon size={"smallest"}/>
|
|
422
|
+
</IconButton>
|
|
423
|
+
</div>
|
|
418
424
|
</Typography>
|
|
419
425
|
|
|
420
426
|
{(dataType === "map" || dataType === "array") && buildInput(entryValue, fieldKey, dataType)}
|
|
@@ -472,7 +478,7 @@ function ArrayKeyValueRow<T>({
|
|
|
472
478
|
}}/>;
|
|
473
479
|
} else if (dataType === "boolean") {
|
|
474
480
|
return <BooleanSwitchWithLabel value={entryValue}
|
|
475
|
-
size={"
|
|
481
|
+
size={"medium"}
|
|
476
482
|
position={"start"}
|
|
477
483
|
onValueChange={(v) => {
|
|
478
484
|
setValue(v as T);
|
|
@@ -3,7 +3,7 @@ import { FieldProps, Properties, ResolvedProperties } from "../../types";
|
|
|
3
3
|
|
|
4
4
|
import { ErrorBoundary } from "../../components";
|
|
5
5
|
import { getIconForProperty, isHidden, pick } from "../../util";
|
|
6
|
-
import { FieldHelperText,
|
|
6
|
+
import { FieldHelperText, LabelWithIconAndTooltip } from "../components";
|
|
7
7
|
import { PropertyFieldBinding } from "../PropertyFieldBinding";
|
|
8
8
|
import { ExpandablePanel, InputLabel, Select, SelectItem } from "@firecms/ui";
|
|
9
9
|
|
|
@@ -21,9 +21,7 @@ export function MapFieldBinding({
|
|
|
21
21
|
error,
|
|
22
22
|
disabled,
|
|
23
23
|
property,
|
|
24
|
-
|
|
25
|
-
partOfBlock,
|
|
26
|
-
tableMode,
|
|
24
|
+
minimalistView,
|
|
27
25
|
includeDescription,
|
|
28
26
|
underlyingValueHasChanged,
|
|
29
27
|
autoFocus,
|
|
@@ -56,23 +54,23 @@ export function MapFieldBinding({
|
|
|
56
54
|
{Object.entries(mapProperties)
|
|
57
55
|
.filter(([_, property]) => !isHidden(property))
|
|
58
56
|
.map(([entryKey, childProperty], index) => {
|
|
59
|
-
const
|
|
57
|
+
const fieldBindingProps = {
|
|
60
58
|
propertyKey: `${propertyKey}.${entryKey}`,
|
|
61
59
|
disabled,
|
|
62
60
|
property: childProperty,
|
|
63
61
|
includeDescription,
|
|
64
62
|
underlyingValueHasChanged,
|
|
65
63
|
context,
|
|
66
|
-
tableMode: false,
|
|
67
64
|
partOfArray: false,
|
|
68
|
-
|
|
65
|
+
minimalistView: false,
|
|
69
66
|
autoFocus: autoFocus && index === 0
|
|
70
67
|
};
|
|
68
|
+
|
|
71
69
|
return (
|
|
72
70
|
<div key={`map-${propertyKey}-${index}`}>
|
|
73
71
|
<ErrorBoundary>
|
|
74
72
|
<PropertyFieldBinding
|
|
75
|
-
{...
|
|
73
|
+
{...fieldBindingProps}/>
|
|
76
74
|
</ErrorBoundary>
|
|
77
75
|
</div>
|
|
78
76
|
);
|
|
@@ -85,23 +83,25 @@ export function MapFieldBinding({
|
|
|
85
83
|
</>;
|
|
86
84
|
|
|
87
85
|
const title = (
|
|
88
|
-
<
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
<LabelWithIconAndTooltip
|
|
87
|
+
propertyKey={propertyKey}
|
|
88
|
+
icon={getIconForProperty(property, "small")}
|
|
89
|
+
required={property.validation?.required}
|
|
90
|
+
title={property.name}
|
|
91
|
+
className={"text-text-secondary dark:text-text-secondary-dark"}/>
|
|
92
92
|
);
|
|
93
93
|
|
|
94
94
|
return (
|
|
95
95
|
<ErrorBoundary>
|
|
96
96
|
|
|
97
|
-
{!
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
{!minimalistView && !minimalistView && <ExpandablePanel initiallyExpanded={expanded}
|
|
98
|
+
className={"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2 bg-slate-50 bg-opacity-50 dark:bg-gray-900"}
|
|
99
|
+
title={title}>{mapFormView}</ExpandablePanel>}
|
|
100
100
|
|
|
101
|
-
{(
|
|
101
|
+
{(minimalistView || minimalistView) && mapFormView}
|
|
102
102
|
|
|
103
103
|
<FieldHelperText includeDescription={includeDescription}
|
|
104
|
-
showError={showError}
|
|
104
|
+
showError={showError ?? false}
|
|
105
105
|
error={error ? (typeof error === "string" ? error : "A property of this map has an error") : undefined}
|
|
106
106
|
disabled={disabled}
|
|
107
107
|
property={property}/>
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
FieldHelperText,
|
|
4
|
+
FieldProps,
|
|
5
|
+
getIconForProperty,
|
|
6
|
+
LabelWithIconAndTooltip, PropertyOrBuilder,
|
|
7
|
+
randomString,
|
|
8
|
+
ResolvedArrayProperty,
|
|
9
|
+
ResolvedStringProperty,
|
|
10
|
+
useStorageSource
|
|
11
|
+
} from "../../index";
|
|
12
|
+
import { cls, fieldBackgroundHoverMixin, fieldBackgroundMixin } from "@firecms/ui";
|
|
13
|
+
import { FireCMSEditor, FireCMSEditorProps } from "@firecms/editor";
|
|
14
|
+
import { resolveProperty, resolveStorageFilenameString, resolveStoragePathString } from "../../util";
|
|
15
|
+
|
|
16
|
+
interface MarkdownEditorFieldProps {
|
|
17
|
+
highlight?: { from: number, to: number };
|
|
18
|
+
editorProps?: Partial<FireCMSEditorProps>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function MarkdownEditorFieldBinding({
|
|
22
|
+
property,
|
|
23
|
+
propertyKey,
|
|
24
|
+
value,
|
|
25
|
+
setValue,
|
|
26
|
+
includeDescription,
|
|
27
|
+
showError,
|
|
28
|
+
error,
|
|
29
|
+
minimalistView,
|
|
30
|
+
isSubmitting,
|
|
31
|
+
context,
|
|
32
|
+
customProps,
|
|
33
|
+
}: FieldProps<string, MarkdownEditorFieldProps>) {
|
|
34
|
+
|
|
35
|
+
const highlight = customProps?.highlight;
|
|
36
|
+
const editorProps = customProps?.editorProps;
|
|
37
|
+
const storageSource = useStorageSource();
|
|
38
|
+
const storage = property.storage;
|
|
39
|
+
|
|
40
|
+
const entityValues = context.values;
|
|
41
|
+
const entityId = context.entityId;
|
|
42
|
+
const path = context.path;
|
|
43
|
+
|
|
44
|
+
// const fieldVersion = useRef(0);
|
|
45
|
+
const [fieldVersion, setFieldVersion] = useState(0);
|
|
46
|
+
const internalValue = useRef(value);
|
|
47
|
+
|
|
48
|
+
const onContentChange = useCallback((content: string) => {
|
|
49
|
+
internalValue.current = content;
|
|
50
|
+
setValue(content);
|
|
51
|
+
}, [setValue]);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (internalValue.current !== value) {
|
|
55
|
+
internalValue.current = value;
|
|
56
|
+
setFieldVersion(fieldVersion + 1);
|
|
57
|
+
// fieldVersion.current = fieldVersion.current + 1;
|
|
58
|
+
}
|
|
59
|
+
}, [value]);
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
const resolvedProperty = resolveProperty({
|
|
63
|
+
propertyOrBuilder: property as PropertyOrBuilder,
|
|
64
|
+
values: entityValues
|
|
65
|
+
}) as ResolvedStringProperty | ResolvedArrayProperty<string[]>;
|
|
66
|
+
|
|
67
|
+
const fileNameBuilder = useCallback(async (file: File) => {
|
|
68
|
+
if (storage?.fileName) {
|
|
69
|
+
const fileName = await resolveStorageFilenameString({
|
|
70
|
+
input: storage.fileName,
|
|
71
|
+
storage,
|
|
72
|
+
values: entityValues,
|
|
73
|
+
entityId,
|
|
74
|
+
path,
|
|
75
|
+
property: resolvedProperty,
|
|
76
|
+
file,
|
|
77
|
+
propertyKey
|
|
78
|
+
});
|
|
79
|
+
if (!fileName || fileName.length === 0) {
|
|
80
|
+
throw Error("You need to return a valid filename");
|
|
81
|
+
}
|
|
82
|
+
return fileName;
|
|
83
|
+
}
|
|
84
|
+
return randomString() + "_" + file.name;
|
|
85
|
+
}, [entityId, entityValues, path, resolvedProperty, propertyKey, storage]);
|
|
86
|
+
|
|
87
|
+
const storagePathBuilder = useCallback((file: File) => {
|
|
88
|
+
if (!storage) return "/";
|
|
89
|
+
const resolvedProperty = resolveProperty({
|
|
90
|
+
propertyOrBuilder: property,
|
|
91
|
+
values: entityValues
|
|
92
|
+
}) as ResolvedStringProperty | ResolvedArrayProperty<string[]>;
|
|
93
|
+
return resolveStoragePathString({
|
|
94
|
+
input: storage.storagePath,
|
|
95
|
+
storage,
|
|
96
|
+
values: entityValues,
|
|
97
|
+
entityId,
|
|
98
|
+
path,
|
|
99
|
+
property: resolvedProperty,
|
|
100
|
+
file,
|
|
101
|
+
propertyKey
|
|
102
|
+
}) ?? "/";
|
|
103
|
+
}, [entityId, entityValues, path, property, propertyKey, storage]);
|
|
104
|
+
|
|
105
|
+
const editor = <FireCMSEditor
|
|
106
|
+
content={value}
|
|
107
|
+
onMarkdownContentChange={onContentChange}
|
|
108
|
+
version={context.formex.version + fieldVersion}
|
|
109
|
+
highlight={highlight}
|
|
110
|
+
handleImageUpload={async (file: File) => {
|
|
111
|
+
const storagePath = storagePathBuilder(file);
|
|
112
|
+
const fileName = await fileNameBuilder(file);
|
|
113
|
+
const result = await storageSource.uploadFile({
|
|
114
|
+
file,
|
|
115
|
+
fileName,
|
|
116
|
+
path: storagePath,
|
|
117
|
+
});
|
|
118
|
+
const downloadConfig = await storageSource.getDownloadURL(result.path);
|
|
119
|
+
const url = downloadConfig.url;
|
|
120
|
+
if (!url) {
|
|
121
|
+
throw new Error("Error uploading image");
|
|
122
|
+
}
|
|
123
|
+
return url;
|
|
124
|
+
}}
|
|
125
|
+
{...editorProps}
|
|
126
|
+
/>;
|
|
127
|
+
|
|
128
|
+
if (minimalistView)
|
|
129
|
+
return editor;
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<>
|
|
133
|
+
<LabelWithIconAndTooltip
|
|
134
|
+
propertyKey={propertyKey}
|
|
135
|
+
icon={getIconForProperty(property, "small")}
|
|
136
|
+
required={property.validation?.required}
|
|
137
|
+
title={property.name}
|
|
138
|
+
className={"text-text-secondary dark:text-text-secondary-dark ml-3.5"}/>
|
|
139
|
+
<div className={cls("rounded-md", fieldBackgroundMixin, fieldBackgroundHoverMixin)}>
|
|
140
|
+
{editor}
|
|
141
|
+
</div>
|
|
142
|
+
<FieldHelperText includeDescription={includeDescription}
|
|
143
|
+
showError={showError}
|
|
144
|
+
error={error}
|
|
145
|
+
property={property}/>
|
|
146
|
+
</>
|
|
147
|
+
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
}
|