@firecms/core 3.0.0-beta.10 → 3.0.0-beta.12
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/components/ArrayContainer.d.ts +22 -6
- package/dist/components/EntityCollectionTable/EntityCollectionRowActions.d.ts +2 -1
- package/dist/components/EntityCollectionTable/EntityCollectionTable.d.ts +2 -2
- package/dist/components/EntityCollectionTable/EntityCollectionTableProps.d.ts +17 -3
- package/dist/components/EntityCollectionTable/index.d.ts +1 -1
- package/dist/components/EntityCollectionTable/internal/popup_field/PopupFormField.d.ts +6 -3
- package/dist/components/EntityCollectionView/EntityCollectionView.d.ts +4 -0
- package/dist/components/PropertyIdCopyTooltip.d.ts +1 -1
- package/dist/components/SelectableTable/SelectableTable.d.ts +12 -2
- package/dist/components/SelectableTable/filters/ReferenceFilterField.d.ts +1 -1
- package/dist/components/UnsavedChangesDialog.d.ts +8 -0
- package/dist/components/VirtualTable/VirtualTableProps.d.ts +13 -0
- package/dist/components/common/default_entity_actions.d.ts +0 -2
- package/dist/components/common/index.d.ts +1 -1
- package/dist/components/common/useColumnsIds.d.ts +1 -0
- package/dist/components/common/{useDataSourceEntityCollectionTableController.d.ts → useDataSourceTableController.d.ts} +10 -2
- package/dist/components/common/useDebouncedCallback.d.ts +1 -0
- package/dist/components/common/useScrollRestoration.d.ts +14 -0
- package/dist/contexts/BreacrumbsContext.d.ts +8 -0
- package/dist/core/EntityEditView.d.ts +30 -22
- package/dist/core/EntityEditViewFormActions.d.ts +2 -0
- package/dist/core/FireCMS.d.ts +1 -1
- package/dist/core/FireCMSRouter.d.ts +4 -0
- package/dist/core/NavigationRoutes.d.ts +0 -1
- package/dist/core/SideDialogs.d.ts +4 -2
- package/dist/core/index.d.ts +2 -1
- package/dist/form/EntityForm.d.ts +45 -0
- package/dist/form/EntityFormActions.d.ts +17 -0
- package/dist/form/PropertyFieldBinding.d.ts +1 -1
- package/dist/form/components/FormEntry.d.ts +6 -0
- package/dist/form/components/FormLayout.d.ts +5 -0
- package/dist/form/components/index.d.ts +2 -1
- 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/MapFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.d.ts +2 -2
- package/dist/form/field_bindings/RepeatFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/SwitchFieldBinding.d.ts +1 -2
- package/dist/form/index.d.ts +16 -16
- package/dist/hooks/data/delete.d.ts +4 -4
- package/dist/hooks/data/save.d.ts +3 -3
- package/dist/hooks/data/useCollectionFetch.d.ts +1 -1
- package/dist/hooks/data/useEntityFetch.d.ts +4 -3
- package/dist/hooks/useAuthController.d.ts +1 -1
- package/dist/hooks/useBreadcrumbsController.d.ts +26 -0
- package/dist/hooks/useBuildNavigationController.d.ts +7 -4
- package/dist/hooks/useFireCMSContext.d.ts +1 -1
- package/dist/hooks/useModeController.d.ts +1 -2
- package/dist/hooks/useResolvedNavigationFrom.d.ts +3 -3
- package/dist/hooks/useValidateAuthenticator.d.ts +3 -3
- package/dist/index.es.js +17032 -12909
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +17019 -12898
- package/dist/index.umd.js.map +1 -1
- package/dist/internal/useBuildSideEntityController.d.ts +2 -2
- package/dist/internal/useUnsavedChangesDialog.d.ts +7 -9
- package/dist/preview/PropertyPreviewProps.d.ts +1 -1
- package/dist/preview/components/EnumValuesChip.d.ts +1 -1
- package/dist/preview/util.d.ts +3 -3
- package/dist/routes/CustomCMSRoute.d.ts +4 -0
- package/dist/routes/FireCMSRoute.d.ts +1 -0
- package/dist/routes/HomePageRoute.d.ts +3 -0
- package/dist/types/auth.d.ts +7 -9
- package/dist/types/collections.d.ts +44 -23
- package/dist/types/datasource.d.ts +2 -6
- package/dist/types/dialogs_controller.d.ts +7 -3
- package/dist/types/entities.d.ts +1 -1
- package/dist/types/entity_actions.d.ts +14 -4
- package/dist/types/entity_callbacks.d.ts +16 -16
- package/dist/types/export_import.d.ts +4 -4
- package/dist/types/fields.d.ts +27 -4
- package/dist/types/firecms.d.ts +2 -2
- package/dist/types/firecms_context.d.ts +1 -1
- package/dist/types/navigation.d.ts +29 -12
- package/dist/types/permissions.d.ts +4 -4
- package/dist/types/plugins.d.ts +9 -8
- package/dist/types/properties.d.ts +18 -3
- package/dist/types/property_config.d.ts +0 -2
- package/dist/types/side_entity_controller.d.ts +6 -1
- package/dist/types/user.d.ts +1 -0
- package/dist/util/builders.d.ts +3 -3
- package/dist/util/entities.d.ts +1 -1
- package/dist/util/entity_actions.d.ts +2 -0
- package/dist/util/entity_cache.d.ts +23 -0
- package/dist/util/icon_synonyms.d.ts +0 -1
- package/dist/util/icons.d.ts +3 -1
- package/dist/util/index.d.ts +1 -0
- package/dist/util/navigation_from_path.d.ts +6 -1
- package/dist/util/navigation_utils.d.ts +12 -1
- package/dist/util/objects.d.ts +1 -0
- package/dist/util/permissions.d.ts +4 -4
- package/dist/util/property_utils.d.ts +2 -2
- package/dist/util/resolutions.d.ts +12 -7
- package/package.json +129 -125
- package/src/app/Scaffold.tsx +4 -4
- package/src/components/ArrayContainer.tsx +115 -34
- package/src/components/CircularProgressCenter.tsx +1 -1
- package/src/components/ConfirmationDialog.tsx +2 -2
- package/src/components/DeleteEntityDialog.tsx +10 -19
- package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +44 -20
- package/src/components/EntityCollectionTable/EntityCollectionTable.tsx +23 -17
- package/src/components/EntityCollectionTable/EntityCollectionTableProps.tsx +20 -3
- package/src/components/EntityCollectionTable/PropertyTableCell.tsx +6 -4
- package/src/components/EntityCollectionTable/fields/TableReferenceField.tsx +8 -9
- package/src/components/EntityCollectionTable/fields/TableStorageUpload.tsx +5 -11
- package/src/components/EntityCollectionTable/index.tsx +1 -1
- package/src/components/EntityCollectionTable/internal/CollectionTableToolbar.tsx +3 -3
- package/src/components/EntityCollectionTable/internal/EntityTableCell.tsx +5 -5
- package/src/components/EntityCollectionTable/internal/EntityTableCellActions.tsx +2 -2
- package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +77 -73
- package/src/components/EntityCollectionView/EntityCollectionView.tsx +90 -49
- package/src/components/EntityCollectionView/EntityCollectionViewActions.tsx +4 -2
- package/src/components/EntityCollectionView/useSelectionController.tsx +5 -4
- package/src/components/EntityPreview.tsx +39 -30
- package/src/components/EntityView.tsx +5 -5
- package/src/components/ErrorView.tsx +3 -3
- package/src/components/HomePage/DefaultHomePage.tsx +1 -0
- package/src/components/HomePage/FavouritesView.tsx +6 -11
- package/src/components/HomePage/NavigationCard.tsx +1 -1
- package/src/components/HomePage/NavigationCardBinding.tsx +4 -9
- package/src/components/HomePage/NavigationGroup.tsx +1 -1
- package/src/components/NotFoundPage.tsx +2 -2
- package/src/components/PropertyConfigBadge.tsx +1 -1
- package/src/components/PropertyIdCopyTooltip.tsx +3 -4
- package/src/components/ReferenceTable/ReferenceSelectionTable.tsx +13 -8
- package/src/components/SelectableTable/SelectableTable.tsx +20 -5
- package/src/components/SelectableTable/filters/DateTimeFilterField.tsx +4 -2
- package/src/components/SelectableTable/filters/ReferenceFilterField.tsx +10 -8
- package/src/components/SelectableTable/filters/StringNumberFilterField.tsx +7 -5
- package/src/components/UnsavedChangesDialog.tsx +42 -0
- package/src/components/VirtualTable/VirtualTable.tsx +19 -2
- package/src/components/VirtualTable/VirtualTableHeader.tsx +8 -8
- package/src/components/VirtualTable/VirtualTableHeaderRow.tsx +1 -1
- package/src/components/VirtualTable/VirtualTableProps.tsx +15 -0
- package/src/components/VirtualTable/VirtualTableRow.tsx +1 -1
- package/src/components/VirtualTable/fields/VirtualTableDateField.tsx +1 -1
- package/src/components/VirtualTable/fields/VirtualTableInput.tsx +1 -1
- package/src/components/VirtualTable/fields/VirtualTableSelect.tsx +2 -0
- package/src/components/common/default_entity_actions.tsx +26 -37
- package/src/components/common/index.ts +1 -1
- package/src/components/common/useColumnsIds.tsx +1 -1
- package/src/components/common/useDataSourceTableController.tsx +420 -0
- package/src/components/common/useDebouncedCallback.tsx +20 -0
- package/src/components/common/useScrollRestoration.tsx +68 -0
- package/src/contexts/BreacrumbsContext.tsx +38 -0
- package/src/contexts/DialogsProvider.tsx +3 -2
- package/src/contexts/ModeController.tsx +1 -3
- package/src/contexts/SnackbarProvider.tsx +2 -0
- package/src/core/DefaultAppBar.tsx +56 -25
- package/src/core/DefaultDrawer.tsx +11 -9
- package/src/core/DrawerNavigationItem.tsx +4 -4
- package/src/core/EntityEditView.tsx +282 -1006
- package/src/core/EntityEditViewFormActions.tsx +199 -0
- package/src/core/EntitySidePanel.tsx +85 -15
- package/src/core/FireCMS.tsx +12 -9
- package/src/core/FireCMSRouter.tsx +17 -0
- package/src/core/NavigationRoutes.tsx +23 -32
- package/src/core/SideDialogs.tsx +21 -12
- package/src/core/field_configs.tsx +4 -4
- package/src/core/index.tsx +4 -2
- package/src/form/EntityForm.tsx +774 -0
- package/src/form/EntityFormActions.tsx +169 -0
- package/src/form/PropertyFieldBinding.tsx +39 -30
- package/src/form/components/CustomIdField.tsx +2 -0
- package/src/form/components/FormEntry.tsx +22 -0
- package/src/form/components/FormLayout.tsx +16 -0
- package/src/form/components/LabelWithIcon.tsx +6 -3
- package/src/form/components/StorageItemPreview.tsx +3 -3
- package/src/form/components/StorageUploadProgress.tsx +1 -1
- package/src/form/components/index.tsx +2 -1
- package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +7 -6
- package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +20 -12
- package/src/form/field_bindings/BlockFieldBinding.tsx +45 -25
- package/src/form/field_bindings/DateTimeFieldBinding.tsx +2 -1
- package/src/form/field_bindings/KeyValueFieldBinding.tsx +10 -7
- package/src/form/field_bindings/MapFieldBinding.tsx +69 -52
- package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +9 -6
- package/src/form/field_bindings/MultiSelectFieldBinding.tsx +1 -1
- package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +2 -2
- package/src/form/field_bindings/ReferenceFieldBinding.tsx +5 -5
- package/src/form/field_bindings/RepeatFieldBinding.tsx +30 -22
- package/src/form/field_bindings/SelectFieldBinding.tsx +6 -5
- package/src/form/field_bindings/StorageUploadFieldBinding.tsx +7 -5
- package/src/form/field_bindings/SwitchFieldBinding.tsx +26 -25
- package/src/form/field_bindings/TextFieldBinding.tsx +4 -3
- package/src/form/index.tsx +16 -32
- package/src/form/validation.ts +12 -6
- package/src/hooks/data/delete.ts +4 -4
- package/src/hooks/data/save.ts +8 -9
- package/src/hooks/data/useCollectionFetch.tsx +3 -3
- package/src/hooks/data/useEntityFetch.tsx +10 -6
- package/src/hooks/useAuthController.tsx +1 -1
- package/src/hooks/useBreadcrumbsController.tsx +31 -0
- package/src/hooks/useBuildModeController.tsx +15 -28
- package/src/hooks/useBuildNavigationController.tsx +74 -29
- package/src/hooks/useFireCMSContext.tsx +5 -5
- package/src/hooks/useLargeLayout.tsx +0 -35
- package/src/hooks/useModeController.tsx +1 -2
- package/src/hooks/useResolvedNavigationFrom.tsx +9 -11
- package/src/hooks/useValidateAuthenticator.tsx +3 -3
- package/src/internal/useBuildDataSource.ts +1 -1
- package/src/internal/useBuildSideDialogsController.tsx +3 -2
- package/src/internal/useBuildSideEntityController.tsx +124 -83
- package/src/internal/useUnsavedChangesDialog.tsx +127 -93
- package/src/preview/PropertyPreview.tsx +11 -11
- package/src/preview/PropertyPreviewProps.tsx +1 -1
- package/src/preview/components/BooleanPreview.tsx +1 -1
- package/src/preview/components/EmptyValue.tsx +1 -1
- package/src/preview/components/EnumValuesChip.tsx +1 -1
- package/src/preview/components/ImagePreview.tsx +5 -6
- package/src/preview/components/UrlComponentPreview.tsx +20 -21
- package/src/preview/property_previews/ArrayOfMapsPreview.tsx +1 -1
- package/src/preview/property_previews/ArrayOfReferencesPreview.tsx +2 -2
- package/src/preview/property_previews/ArrayOfStorageComponentsPreview.tsx +2 -2
- package/src/preview/property_previews/ArrayOfStringsPreview.tsx +1 -1
- package/src/preview/property_previews/ArrayOneOfPreview.tsx +2 -2
- package/src/preview/property_previews/ArrayPropertyPreview.tsx +2 -2
- package/src/preview/property_previews/MapPropertyPreview.tsx +7 -6
- package/src/preview/property_previews/SkeletonPropertyComponent.tsx +12 -12
- package/src/preview/property_previews/StringPropertyPreview.tsx +2 -2
- package/src/preview/util.ts +10 -10
- package/src/routes/CustomCMSRoute.tsx +21 -0
- package/src/routes/FireCMSRoute.tsx +235 -0
- package/src/routes/HomePageRoute.tsx +17 -0
- package/src/types/auth.tsx +8 -12
- package/src/types/collections.ts +52 -26
- package/src/types/datasource.ts +2 -6
- package/src/types/dialogs_controller.tsx +7 -3
- package/src/types/entities.ts +1 -1
- package/src/types/entity_actions.tsx +16 -4
- package/src/types/entity_callbacks.ts +18 -18
- package/src/types/export_import.ts +4 -4
- package/src/types/fields.tsx +33 -4
- package/src/types/firecms.tsx +2 -2
- package/src/types/firecms_context.tsx +1 -1
- package/src/types/navigation.ts +36 -16
- package/src/types/permissions.ts +5 -5
- package/src/types/plugins.tsx +9 -8
- package/src/types/properties.ts +21 -3
- package/src/types/property_config.tsx +0 -2
- package/src/types/side_dialogs_controller.tsx +2 -0
- package/src/types/side_entity_controller.tsx +6 -1
- package/src/types/user.ts +2 -0
- package/src/util/builders.ts +10 -8
- package/src/util/entities.ts +3 -1
- package/src/util/entity_actions.ts +28 -0
- package/src/util/entity_cache.ts +204 -0
- package/src/util/icon_list.ts +1 -0
- package/src/util/icon_synonyms.ts +0 -1
- package/src/util/icons.tsx +12 -8
- package/src/util/index.ts +1 -0
- package/src/util/join_collections.ts +3 -0
- package/src/util/navigation_from_path.ts +13 -6
- package/src/util/navigation_utils.ts +53 -1
- package/src/util/objects.ts +24 -1
- package/src/util/parent_references_from_path.ts +3 -3
- package/src/util/permissions.ts +8 -8
- package/src/util/property_utils.tsx +10 -3
- package/src/util/references.ts +8 -2
- package/src/util/resolutions.ts +34 -13
- package/src/util/useStorageUploadController.tsx +40 -22
- package/dist/form/components/FormikArrayContainer.d.ts +0 -19
- package/src/components/common/useDataSourceEntityCollectionTableController.tsx +0 -236
- package/src/form/components/FormikArrayContainer.tsx +0 -47
- /package/src/util/{common.tsx → common.ts} +0 -0
|
@@ -4,7 +4,7 @@ import { EnumType, FieldProps } from "../../types";
|
|
|
4
4
|
import { FieldHelperText, LabelWithIcon } from "../components";
|
|
5
5
|
import { EnumValuesChip } from "../../preview";
|
|
6
6
|
import { getIconForProperty, resolveEnumValues } from "../../util";
|
|
7
|
-
import {
|
|
7
|
+
import { CloseIcon, cls, IconButton, Select, SelectItem } from "@firecms/ui";
|
|
8
8
|
import { useClearRestoreValue } from "../useClearRestoreValue";
|
|
9
9
|
import { PropertyIdCopyTooltip } from "../../components";
|
|
10
10
|
|
|
@@ -29,7 +29,7 @@ export function SelectFieldBinding<T extends EnumType>({
|
|
|
29
29
|
touched,
|
|
30
30
|
property,
|
|
31
31
|
includeDescription,
|
|
32
|
-
size = "
|
|
32
|
+
size = "large"
|
|
33
33
|
}: SelectProps<T>) {
|
|
34
34
|
|
|
35
35
|
const enumValues = resolveEnumValues(property.enumValues ?? []);
|
|
@@ -50,9 +50,10 @@ export function SelectFieldBinding<T extends EnumType>({
|
|
|
50
50
|
<>
|
|
51
51
|
|
|
52
52
|
<Select
|
|
53
|
-
size={size === "medium" ? "medium" : "small"}
|
|
54
53
|
value={value !== undefined && value != null ? value.toString() : ""}
|
|
55
54
|
disabled={disabled}
|
|
55
|
+
size={size}
|
|
56
|
+
fullWidth={true}
|
|
56
57
|
position="item-aligned"
|
|
57
58
|
inputClassName={cls("w-full")}
|
|
58
59
|
label={
|
|
@@ -61,13 +62,13 @@ export function SelectFieldBinding<T extends EnumType>({
|
|
|
61
62
|
icon={getIconForProperty(property, "small")}
|
|
62
63
|
required={property.validation?.required}
|
|
63
64
|
title={property.name}
|
|
64
|
-
className={"text-text-secondary dark:text-text-secondary-dark ml-3.5"}
|
|
65
|
+
className={"h-8 text-text-secondary dark:text-text-secondary-dark ml-3.5 my-0"}
|
|
65
66
|
/>
|
|
66
67
|
</PropertyIdCopyTooltip>}
|
|
67
68
|
endAdornment={
|
|
68
69
|
property.clearable && <IconButton
|
|
69
70
|
onClick={handleClearClick}>
|
|
70
|
-
<
|
|
71
|
+
<CloseIcon/>
|
|
71
72
|
</IconButton>
|
|
72
73
|
}
|
|
73
74
|
onValueChange={(updatedValue: string) => {
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
import { useClearRestoreValue } from "../useClearRestoreValue";
|
|
29
29
|
|
|
30
30
|
const dropZoneClasses = "box-border relative pt-[2px] items-center border border-transparent min-h-[254px] outline-none rounded-md duration-200 ease-[cubic-bezier(0.4,0,0.2,1)] focus:border-primary-solid";
|
|
31
|
-
const disabledClasses =
|
|
31
|
+
const disabledClasses = fieldBackgroundDisabledMixin;
|
|
32
32
|
const nonActiveDropClasses = fieldBackgroundHoverMixin
|
|
33
33
|
const activeDropClasses = "pt-0 border-2 border-solid"
|
|
34
34
|
const acceptDropClasses = "transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500"
|
|
@@ -103,7 +103,7 @@ export function StorageUploadFieldBinding({
|
|
|
103
103
|
icon={getIconForProperty(property, "small")}
|
|
104
104
|
required={property.validation?.required}
|
|
105
105
|
title={property.name}
|
|
106
|
-
className={"
|
|
106
|
+
className={"h-8text-text-secondary dark:text-text-secondary-dark ml-3.5"}/>}
|
|
107
107
|
|
|
108
108
|
<StorageUpload
|
|
109
109
|
value={internalValue}
|
|
@@ -206,6 +206,7 @@ function FileDropComponent({
|
|
|
206
206
|
className={cls(
|
|
207
207
|
fieldBackgroundMixin,
|
|
208
208
|
disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,
|
|
209
|
+
disabled ? "text-surface-accent-600 dark:text-surface-accent-500" : "",
|
|
209
210
|
dropZoneClasses,
|
|
210
211
|
multipleFilesSupported && internalValue.length ? "" : "flex",
|
|
211
212
|
{
|
|
@@ -248,7 +249,7 @@ function FileDropComponent({
|
|
|
248
249
|
metadata={metadata}
|
|
249
250
|
storagePath={storagePathBuilder(entry.file)}
|
|
250
251
|
onFileUploadComplete={onFileUploadComplete}
|
|
251
|
-
imageSize={size === "
|
|
252
|
+
imageSize={size === "large" ? 220 : 118}
|
|
252
253
|
simple={false}
|
|
253
254
|
/>
|
|
254
255
|
);
|
|
@@ -285,7 +286,8 @@ function FileDropComponent({
|
|
|
285
286
|
<div
|
|
286
287
|
className="flex-grow min-h-[38px] box-border m-2 text-center">
|
|
287
288
|
<Typography align={"center"}
|
|
288
|
-
variant={"label"}
|
|
289
|
+
variant={"label"}
|
|
290
|
+
className={disabled ? "text-surface-accent-600 dark:text-surface-accent-500" : ""}>
|
|
289
291
|
{helpText}
|
|
290
292
|
</Typography>
|
|
291
293
|
</div>
|
|
@@ -339,7 +341,7 @@ export function StorageUpload({
|
|
|
339
341
|
}
|
|
340
342
|
|
|
341
343
|
const metadata: Record<string, unknown> | undefined = storage?.metadata;
|
|
342
|
-
const size = multipleFilesSupported ? "
|
|
344
|
+
const size = multipleFilesSupported ? "medium" : "large";
|
|
343
345
|
|
|
344
346
|
const moveItem = useCallback((fromIndex: number, toIndex: number) => {
|
|
345
347
|
if (!multipleFilesSupported) return;
|
|
@@ -16,18 +16,18 @@ type SwitchFieldProps = FieldProps<boolean>;
|
|
|
16
16
|
* and tables to the specified properties.
|
|
17
17
|
* @group Form fields
|
|
18
18
|
*/
|
|
19
|
-
export const SwitchFieldBinding =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
export const SwitchFieldBinding = function SwitchFieldBinding({
|
|
20
|
+
propertyKey,
|
|
21
|
+
value,
|
|
22
|
+
setValue,
|
|
23
|
+
error,
|
|
24
|
+
showError,
|
|
25
|
+
autoFocus,
|
|
26
|
+
disabled,
|
|
27
|
+
size = "large",
|
|
28
|
+
property,
|
|
29
|
+
includeDescription
|
|
30
|
+
}: SwitchFieldProps) {
|
|
31
31
|
|
|
32
32
|
useClearRestoreValue({
|
|
33
33
|
property,
|
|
@@ -39,18 +39,19 @@ export const SwitchFieldBinding = React.forwardRef(function SwitchFieldBinding({
|
|
|
39
39
|
<>
|
|
40
40
|
|
|
41
41
|
<PropertyIdCopyTooltip propertyKey={propertyKey}>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
<BooleanSwitchWithLabel
|
|
43
|
+
value={value}
|
|
44
|
+
onValueChange={(v) => setValue(v)}
|
|
45
|
+
error={showError}
|
|
46
|
+
className={property.widthPercentage !== undefined ? "mt-8" : undefined}
|
|
47
|
+
label={<LabelWithIcon
|
|
48
|
+
icon={getIconForProperty(property, "small")}
|
|
49
|
+
required={property.validation?.required}
|
|
50
|
+
title={property.name}/>}
|
|
51
|
+
disabled={disabled}
|
|
52
|
+
autoFocus={autoFocus}
|
|
53
|
+
size={size}
|
|
54
|
+
/>
|
|
54
55
|
</PropertyIdCopyTooltip>
|
|
55
56
|
|
|
56
57
|
<FieldHelperText includeDescription={includeDescription}
|
|
@@ -61,4 +62,4 @@ export const SwitchFieldBinding = React.forwardRef(function SwitchFieldBinding({
|
|
|
61
62
|
</>
|
|
62
63
|
|
|
63
64
|
);
|
|
64
|
-
}
|
|
65
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useCallback } from "react";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { CloseIcon, Collapse, IconButton, TextField } from "@firecms/ui";
|
|
4
4
|
import { FieldProps, PreviewType } from "../../types";
|
|
5
5
|
import { FieldHelperText, LabelWithIcon } from "../components";
|
|
6
6
|
import { getIconForProperty } from "../../util";
|
|
@@ -28,7 +28,7 @@ export function TextFieldBinding<T extends string | number>({
|
|
|
28
28
|
autoFocus,
|
|
29
29
|
property,
|
|
30
30
|
includeDescription,
|
|
31
|
-
size = "
|
|
31
|
+
size = "large"
|
|
32
32
|
}: TextFieldBindingProps<T>) {
|
|
33
33
|
|
|
34
34
|
let multiline: boolean | undefined;
|
|
@@ -75,6 +75,7 @@ export function TextFieldBinding<T extends string | number>({
|
|
|
75
75
|
value={value}
|
|
76
76
|
onChange={onChange}
|
|
77
77
|
autoFocus={autoFocus}
|
|
78
|
+
className={property.widthPercentage !== undefined ? "mt-8" : undefined}
|
|
78
79
|
label={<LabelWithIcon
|
|
79
80
|
icon={getIconForProperty(property, "small")}
|
|
80
81
|
required={property.validation?.required}
|
|
@@ -85,7 +86,7 @@ export function TextFieldBinding<T extends string | number>({
|
|
|
85
86
|
endAdornment={
|
|
86
87
|
property.clearable && <IconButton
|
|
87
88
|
onClick={handleClearClick}>
|
|
88
|
-
<
|
|
89
|
+
<CloseIcon/>
|
|
89
90
|
</IconButton>
|
|
90
91
|
}
|
|
91
92
|
error={showError ? error : undefined}
|
package/src/form/index.tsx
CHANGED
|
@@ -1,36 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
import { MultiSelectFieldBinding } from "./field_bindings/MultiSelectFieldBinding";
|
|
3
|
-
import { ArrayOfReferencesFieldBinding } from "./field_bindings/ArrayOfReferencesFieldBinding";
|
|
4
|
-
import { StorageUploadFieldBinding } from "./field_bindings/StorageUploadFieldBinding";
|
|
5
|
-
import { TextFieldBinding } from "./field_bindings/TextFieldBinding";
|
|
6
|
-
import { SwitchFieldBinding } from "./field_bindings/SwitchFieldBinding";
|
|
7
|
-
import { DateTimeFieldBinding } from "./field_bindings/DateTimeFieldBinding";
|
|
8
|
-
import { ReferenceFieldBinding } from "./field_bindings/ReferenceFieldBinding";
|
|
9
|
-
import { MapFieldBinding } from "./field_bindings/MapFieldBinding";
|
|
10
|
-
import { KeyValueFieldBinding } from "./field_bindings/KeyValueFieldBinding";
|
|
11
|
-
import { RepeatFieldBinding } from "./field_bindings/RepeatFieldBinding";
|
|
12
|
-
import { BlockFieldBinding } from "./field_bindings/BlockFieldBinding";
|
|
13
|
-
import { ReadOnlyFieldBinding } from "./field_bindings/ReadOnlyFieldBinding";
|
|
14
|
-
import { MarkdownEditorFieldBinding } from "./field_bindings/MarkdownEditorFieldBinding";
|
|
15
|
-
import { ArrayCustomShapedFieldBinding } from "./field_bindings/ArrayCustomShapedFieldBinding";
|
|
1
|
+
export * from "./EntityForm";
|
|
16
2
|
|
|
17
|
-
export {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
TextFieldBinding
|
|
33
|
-
};
|
|
3
|
+
export { SelectFieldBinding } from "./field_bindings/SelectFieldBinding";
|
|
4
|
+
export { MultiSelectFieldBinding } from "./field_bindings/MultiSelectFieldBinding";
|
|
5
|
+
export { ArrayOfReferencesFieldBinding } from "./field_bindings/ArrayOfReferencesFieldBinding";
|
|
6
|
+
export { StorageUploadFieldBinding } from "./field_bindings/StorageUploadFieldBinding";
|
|
7
|
+
export { TextFieldBinding } from "./field_bindings/TextFieldBinding";
|
|
8
|
+
export { SwitchFieldBinding } from "./field_bindings/SwitchFieldBinding";
|
|
9
|
+
export { DateTimeFieldBinding } from "./field_bindings/DateTimeFieldBinding";
|
|
10
|
+
export { ReferenceFieldBinding } from "./field_bindings/ReferenceFieldBinding";
|
|
11
|
+
export { MapFieldBinding } from "./field_bindings/MapFieldBinding";
|
|
12
|
+
export { KeyValueFieldBinding } from "./field_bindings/KeyValueFieldBinding";
|
|
13
|
+
export { RepeatFieldBinding } from "./field_bindings/RepeatFieldBinding";
|
|
14
|
+
export { BlockFieldBinding } from "./field_bindings/BlockFieldBinding";
|
|
15
|
+
export { ReadOnlyFieldBinding } from "./field_bindings/ReadOnlyFieldBinding";
|
|
16
|
+
export { MarkdownEditorFieldBinding } from "./field_bindings/MarkdownEditorFieldBinding";
|
|
17
|
+
export { ArrayCustomShapedFieldBinding } from "./field_bindings/ArrayCustomShapedFieldBinding";
|
|
34
18
|
|
|
35
19
|
export * from "./components";
|
|
36
20
|
|
package/src/form/validation.ts
CHANGED
|
@@ -90,11 +90,11 @@ export function mapPropertyToYup<T extends CMSType>(propertyContext: PropertyCon
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
export function getYupMapObjectSchema({
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
property,
|
|
94
|
+
entityId,
|
|
95
|
+
customFieldValidator,
|
|
96
|
+
name
|
|
97
|
+
}: PropertyContext<Record<string, any>>): ObjectSchema<any> {
|
|
98
98
|
const objectSchema: any = {};
|
|
99
99
|
const validation = property.validation;
|
|
100
100
|
if (property.properties)
|
|
@@ -159,7 +159,13 @@ function getYupStringSchema({
|
|
|
159
159
|
if (validation.lowercase) collection = collection.lowercase();
|
|
160
160
|
if (validation.uppercase) collection = collection.uppercase();
|
|
161
161
|
if (property.email) collection = collection.email(`${property.name} must be an email`);
|
|
162
|
-
if (property.url)
|
|
162
|
+
if (property.url) {
|
|
163
|
+
if (!property.storage || property.storage?.storeUrl) {
|
|
164
|
+
collection = collection.url(`${property.name} must be a url`);
|
|
165
|
+
} else {
|
|
166
|
+
console.warn(`Property ${property.name} has a url validation but its storage configuration is not set to store urls`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
163
169
|
} else {
|
|
164
170
|
collection = collection.notRequired().nullable(true);
|
|
165
171
|
}
|
package/src/hooks/data/delete.ts
CHANGED
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
/**
|
|
13
13
|
* @group Hooks and utilities
|
|
14
14
|
*/
|
|
15
|
-
export type DeleteEntityWithCallbacksProps<M extends Record<string, any>,
|
|
15
|
+
export type DeleteEntityWithCallbacksProps<M extends Record<string, any>, USER extends User = User> =
|
|
16
16
|
DeleteEntityProps<M>
|
|
17
17
|
& {
|
|
18
|
-
callbacks?: EntityCallbacks<M,
|
|
18
|
+
callbacks?: EntityCallbacks<M, USER>;
|
|
19
19
|
onDeleteSuccess?: (entity: Entity<M>) => void;
|
|
20
20
|
onDeleteFailure?: (entity: Entity<M>, e: Error) => void;
|
|
21
21
|
onPreDeleteHookError?: (entity: Entity<M>, e: Error) => void;
|
|
@@ -43,7 +43,7 @@ export type DeleteEntityWithCallbacksProps<M extends Record<string, any>, UserTy
|
|
|
43
43
|
* @param context
|
|
44
44
|
* @group Hooks and utilities
|
|
45
45
|
*/
|
|
46
|
-
export async function deleteEntityWithCallbacks<M extends Record<string, any>,
|
|
46
|
+
export async function deleteEntityWithCallbacks<M extends Record<string, any>, USER extends User>({
|
|
47
47
|
dataSource,
|
|
48
48
|
entity,
|
|
49
49
|
collection,
|
|
@@ -56,7 +56,7 @@ export async function deleteEntityWithCallbacks<M extends Record<string, any>, U
|
|
|
56
56
|
}: DeleteEntityWithCallbacksProps<M> & {
|
|
57
57
|
collection: ResolvedEntityCollection<M>,
|
|
58
58
|
dataSource: DataSource,
|
|
59
|
-
context: FireCMSContext<
|
|
59
|
+
context: FireCMSContext<USER>
|
|
60
60
|
}
|
|
61
61
|
): Promise<boolean> {
|
|
62
62
|
|
package/src/hooks/data/save.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DataSource,
|
|
3
3
|
Entity,
|
|
4
|
-
EntityCallbacks,
|
|
5
4
|
EntityCollection,
|
|
6
5
|
EntityValues,
|
|
7
6
|
FireCMSContext,
|
|
@@ -49,7 +48,7 @@ export type SaveEntityWithCallbacksProps<M extends Record<string, any>> =
|
|
|
49
48
|
* @see useDataSource
|
|
50
49
|
* @group Hooks and utilities
|
|
51
50
|
*/
|
|
52
|
-
export async function saveEntityWithCallbacks<M extends Record<string, any>,
|
|
51
|
+
export async function saveEntityWithCallbacks<M extends Record<string, any>, USER extends User>({
|
|
53
52
|
collection,
|
|
54
53
|
path,
|
|
55
54
|
entityId,
|
|
@@ -63,9 +62,9 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, Use
|
|
|
63
62
|
onPreSaveHookError,
|
|
64
63
|
onSaveSuccessHookError
|
|
65
64
|
}: SaveEntityWithCallbacksProps<M> & {
|
|
66
|
-
collection: EntityCollection<M,
|
|
65
|
+
collection: EntityCollection<M, USER>,
|
|
67
66
|
dataSource: DataSource,
|
|
68
|
-
context: FireCMSContext<
|
|
67
|
+
context: FireCMSContext<USER>,
|
|
69
68
|
}
|
|
70
69
|
): Promise<void> {
|
|
71
70
|
|
|
@@ -76,7 +75,7 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, Use
|
|
|
76
75
|
|
|
77
76
|
const customizationController = context.customizationController;
|
|
78
77
|
|
|
79
|
-
const resolvedPath = context.navigation.
|
|
78
|
+
const resolvedPath = context.navigation.resolveIdsFrom(path);
|
|
80
79
|
|
|
81
80
|
const callbacks = collection.callbacks;
|
|
82
81
|
if (callbacks?.onPreSave) {
|
|
@@ -86,7 +85,7 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, Use
|
|
|
86
85
|
path,
|
|
87
86
|
values: previousValues as EntityValues<M>,
|
|
88
87
|
entityId,
|
|
89
|
-
|
|
88
|
+
propertyConfigs: customizationController.propertyConfigs
|
|
90
89
|
});
|
|
91
90
|
updatedValues = await callbacks.onPreSave({
|
|
92
91
|
collection: resolvedCollection,
|
|
@@ -108,7 +107,7 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, Use
|
|
|
108
107
|
updatedValues = values;
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
console.
|
|
110
|
+
console.debug("Saving entity", {
|
|
112
111
|
entityId,
|
|
113
112
|
updatedValues,
|
|
114
113
|
collection
|
|
@@ -128,7 +127,7 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, Use
|
|
|
128
127
|
path,
|
|
129
128
|
values: updatedValues as EntityValues<M>,
|
|
130
129
|
entityId,
|
|
131
|
-
|
|
130
|
+
propertyConfigs: customizationController.propertyConfigs
|
|
132
131
|
});
|
|
133
132
|
callbacks.onSaveSuccess({
|
|
134
133
|
collection: resolvedCollection,
|
|
@@ -157,7 +156,7 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, Use
|
|
|
157
156
|
path,
|
|
158
157
|
values: updatedValues as EntityValues<M>,
|
|
159
158
|
entityId,
|
|
160
|
-
|
|
159
|
+
propertyConfigs: customizationController.propertyConfigs
|
|
161
160
|
});
|
|
162
161
|
callbacks.onSaveFailure({
|
|
163
162
|
collection: resolvedCollection,
|
|
@@ -60,7 +60,7 @@ export interface CollectionFetchResult<M extends Record<string, any>> {
|
|
|
60
60
|
* @param searchString
|
|
61
61
|
* @group Hooks and utilities
|
|
62
62
|
*/
|
|
63
|
-
export function useCollectionFetch<M extends Record<string, any>,
|
|
63
|
+
export function useCollectionFetch<M extends Record<string, any>, USER extends User>(
|
|
64
64
|
{
|
|
65
65
|
path: inputPath,
|
|
66
66
|
collection,
|
|
@@ -73,12 +73,12 @@ export function useCollectionFetch<M extends Record<string, any>, UserType exten
|
|
|
73
73
|
const dataSource = useDataSource(collection);
|
|
74
74
|
const navigationController = useNavigationController();
|
|
75
75
|
|
|
76
|
-
const path = navigationController.
|
|
76
|
+
const path = navigationController.resolveIdsFrom(inputPath);
|
|
77
77
|
|
|
78
78
|
const sortByProperty = sortBy ? sortBy[0] : undefined;
|
|
79
79
|
const currentSort = sortBy ? sortBy[1] : undefined;
|
|
80
80
|
|
|
81
|
-
const context: FireCMSContext<
|
|
81
|
+
const context: FireCMSContext<USER> = useFireCMSContext();
|
|
82
82
|
|
|
83
83
|
const [data, setData] = useState<Entity<M>[]>([]);
|
|
84
84
|
|
|
@@ -7,10 +7,11 @@ import { useFireCMSContext } from "../useFireCMSContext";
|
|
|
7
7
|
/**
|
|
8
8
|
* @group Hooks and utilities
|
|
9
9
|
*/
|
|
10
|
-
export interface EntityFetchProps<M extends Record<string, any>,
|
|
10
|
+
export interface EntityFetchProps<M extends Record<string, any>, USER extends User = User> {
|
|
11
11
|
path: string;
|
|
12
12
|
entityId?: string;
|
|
13
|
-
|
|
13
|
+
databaseId?: string;
|
|
14
|
+
collection: EntityCollection<M, USER>;
|
|
14
15
|
useCache?: boolean;
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -35,20 +36,21 @@ const CACHE: Record<string, Entity<any> | undefined> = {};
|
|
|
35
36
|
* @group Hooks and utilities
|
|
36
37
|
*/
|
|
37
38
|
|
|
38
|
-
export function useEntityFetch<M extends Record<string, any>,
|
|
39
|
+
export function useEntityFetch<M extends Record<string, any>, USER extends User>(
|
|
39
40
|
{
|
|
40
41
|
path: inputPath,
|
|
41
42
|
entityId,
|
|
42
43
|
collection,
|
|
44
|
+
databaseId,
|
|
43
45
|
useCache = false
|
|
44
|
-
}: EntityFetchProps<M,
|
|
46
|
+
}: EntityFetchProps<M, USER>): EntityFetchResult<M> {
|
|
45
47
|
|
|
46
48
|
const dataSource = useDataSource(collection);
|
|
47
49
|
const navigationController = useNavigationController();
|
|
48
50
|
|
|
49
|
-
const path = navigationController.
|
|
51
|
+
const path = navigationController.resolveIdsFrom(inputPath);
|
|
50
52
|
|
|
51
|
-
const context: FireCMSContext<
|
|
53
|
+
const context: FireCMSContext<USER> = useFireCMSContext();
|
|
52
54
|
|
|
53
55
|
const [entity, setEntity] = useState<Entity<M> | undefined>();
|
|
54
56
|
const [dataLoading, setDataLoading] = useState<boolean>(true);
|
|
@@ -96,6 +98,7 @@ export function useEntityFetch<M extends Record<string, any>, UserType extends U
|
|
|
96
98
|
return dataSource.listenEntity<M>({
|
|
97
99
|
path,
|
|
98
100
|
entityId,
|
|
101
|
+
databaseId,
|
|
99
102
|
collection,
|
|
100
103
|
onUpdate: onEntityUpdate,
|
|
101
104
|
onError
|
|
@@ -104,6 +107,7 @@ export function useEntityFetch<M extends Record<string, any>, UserType extends U
|
|
|
104
107
|
dataSource.fetchEntity<M>({
|
|
105
108
|
path,
|
|
106
109
|
entityId,
|
|
110
|
+
databaseId,
|
|
107
111
|
collection
|
|
108
112
|
})
|
|
109
113
|
.then(onEntityUpdate)
|
|
@@ -11,4 +11,4 @@ import { AuthControllerContext } from "../contexts/AuthControllerContext";
|
|
|
11
11
|
* @see AuthController
|
|
12
12
|
* @group Hooks and utilities
|
|
13
13
|
*/
|
|
14
|
-
export const useAuthController = <
|
|
14
|
+
export const useAuthController = <USER extends User = User, AuthControllerType extends AuthController<USER> = AuthController<USER>>(): AuthControllerType => useContext(AuthControllerContext) as AuthControllerType;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { BreadcrumbContext } from "../contexts/BreacrumbsContext";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @group Hooks and utilities
|
|
6
|
+
*/
|
|
7
|
+
export interface BreadcrumbsController {
|
|
8
|
+
breadcrumbs: BreadcrumbEntry[];
|
|
9
|
+
set: (props: {
|
|
10
|
+
breadcrumbs: BreadcrumbEntry[];
|
|
11
|
+
}) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @group Hooks and utilities
|
|
16
|
+
*/
|
|
17
|
+
export interface BreadcrumbEntry {
|
|
18
|
+
title: string;
|
|
19
|
+
url: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Hook to retrieve the BreadcrumbsController.
|
|
24
|
+
*
|
|
25
|
+
* Consider that in order to use this hook you need to have a parent
|
|
26
|
+
* `FireCMS`
|
|
27
|
+
*
|
|
28
|
+
* @see BreadcrumbsController
|
|
29
|
+
* @group Hooks and utilities
|
|
30
|
+
*/
|
|
31
|
+
export const useBreadcrumbsController = (): BreadcrumbsController => useContext(BreadcrumbContext);
|
|
@@ -16,7 +16,7 @@ export function useBuildModeController(): ModeController {
|
|
|
16
16
|
}, []);
|
|
17
17
|
|
|
18
18
|
const prefersDarkModeStorage: boolean | null = localStorage.getItem("prefers-dark-mode") != null ? localStorage.getItem("prefers-dark-mode") === "true" : null;
|
|
19
|
-
const prefersDarkMode = prefersDarkModeStorage ?? prefersDarkModeQuery;
|
|
19
|
+
const prefersDarkMode = prefersDarkModeStorage ?? prefersDarkModeQuery();
|
|
20
20
|
const [mode, setMode] = useState<"light" | "dark">(prefersDarkMode ? "dark" : "light");
|
|
21
21
|
|
|
22
22
|
useEffect(() => {
|
|
@@ -24,43 +24,30 @@ export function useBuildModeController(): ModeController {
|
|
|
24
24
|
setDocumentMode(prefersDarkMode ? "dark" : "light");
|
|
25
25
|
}, [prefersDarkMode]);
|
|
26
26
|
|
|
27
|
-
// color-scheme: dark;
|
|
28
|
-
const setDarkMode = useCallback(() => {
|
|
29
|
-
setMode("dark");
|
|
30
|
-
setDocumentMode("dark");
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
const setLightMode = useCallback(() => {
|
|
34
|
-
setMode("light");
|
|
35
|
-
setDocumentMode("light");
|
|
36
|
-
}, []);
|
|
37
|
-
|
|
38
27
|
const setDocumentMode = (mode: "light" | "dark") => {
|
|
39
28
|
document.body.style.setProperty("color-scheme", mode);
|
|
40
29
|
document.documentElement.dataset.theme = mode;
|
|
41
30
|
};
|
|
42
31
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const prefersDarkModeQueryResult = prefersDarkModeQuery();
|
|
32
|
+
const setModeInternal = useCallback((mode: "light" | "dark" | "system") => {
|
|
46
33
|
if (mode === "light") {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
setDocumentMode("light");
|
|
35
|
+
localStorage.setItem("prefers-dark-mode", "false");
|
|
36
|
+
setMode("light");
|
|
37
|
+
} else if (mode === "dark") {
|
|
38
|
+
setDocumentMode("dark");
|
|
39
|
+
localStorage.setItem("prefers-dark-mode", "true");
|
|
40
|
+
setMode("dark");
|
|
52
41
|
} else {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
setLightMode();
|
|
42
|
+
const preferredMode = prefersDarkModeQuery() ? "dark" : "light";
|
|
43
|
+
setDocumentMode(preferredMode);
|
|
44
|
+
localStorage.removeItem("prefers-dark-mode");
|
|
45
|
+
setMode(preferredMode);
|
|
58
46
|
}
|
|
59
|
-
}, [
|
|
47
|
+
}, [prefersDarkModeQuery]);
|
|
60
48
|
|
|
61
49
|
return {
|
|
62
50
|
mode,
|
|
63
|
-
setMode
|
|
64
|
-
toggleMode
|
|
51
|
+
setMode: setModeInternal
|
|
65
52
|
};
|
|
66
53
|
}
|