@firecms/core 3.0.0-canary.68 → 3.0.0-canary.69

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@firecms/core",
3
3
  "type": "module",
4
- "version": "3.0.0-canary.68",
4
+ "version": "3.0.0-canary.69",
5
5
  "description": "Awesome Firebase/Firestore-based headless open-source CMS",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/firecmsco"
@@ -46,8 +46,8 @@
46
46
  "./package.json": "./package.json"
47
47
  },
48
48
  "dependencies": {
49
- "@firecms/formex": "^3.0.0-canary.68",
50
- "@firecms/ui": "^3.0.0-canary.68",
49
+ "@firecms/formex": "^3.0.0-canary.69",
50
+ "@firecms/ui": "^3.0.0-canary.69",
51
51
  "@fontsource/jetbrains-mono": "^5.0.20",
52
52
  "@hello-pangea/dnd": "^16.6.0",
53
53
  "@radix-ui/react-portal": "^1.0.4",
@@ -111,7 +111,7 @@
111
111
  "dist",
112
112
  "src"
113
113
  ],
114
- "gitHead": "bfabbd17ea406b898443e03febe4a353c8af5eb4",
114
+ "gitHead": "2864af43a74e4b1ecfc8d382a5ecba3c70569fbe",
115
115
  "publishConfig": {
116
116
  "access": "public"
117
117
  },
@@ -201,15 +201,15 @@ export function EntityEditViewInner<M extends Record<string, any>>({
201
201
 
202
202
  const [entityId, setEntityId] = React.useState<string | undefined>(initialEntityId);
203
203
 
204
- const doOnValuesChanges = (values?: EntityValues<M>) => {
205
- const initialValues = formex.initialValues;
206
- setInternalValues(values);
207
- if (onValuesChanged)
208
- onValuesChanged(values);
209
- if (autoSave && values && !equal(values, initialValues)) {
210
- save(values);
211
- }
212
- };
204
+ // const doOnValuesChanges = (values?: EntityValues<M>) => {
205
+ // const initialValues = formex.initialValues;
206
+ // setInternalValues(values);
207
+ // if (onValuesChanged)
208
+ // onValuesChanged(values);
209
+ // if (autoSave && values && !equal(values, initialValues)) {
210
+ // save(values);
211
+ // }
212
+ // };
213
213
 
214
214
  const [entityIdError, setEntityIdError] = React.useState<boolean>(false);
215
215
  const [savingError, setSavingError] = React.useState<Error | undefined>();
@@ -230,10 +230,10 @@ export function EntityEditViewInner<M extends Record<string, any>>({
230
230
  const mainViewVisible = selectedTabRef.current === MAIN_TAB_VALUE;
231
231
 
232
232
  // const initialValuesRef = useRef<EntityValues<M>>(entity?.values ?? baseDataSourceValues as EntityValues<M>);
233
- const [internalValues, setInternalValues] = useState<EntityValues<M> | undefined>(entity?.values ?? baseDataSourceValuesRef.current as EntityValues<M>);
233
+ // const [internalValues, setInternalValues] = useState<EntityValues<M> | undefined>(entity?.values ?? baseDataSourceValuesRef.current as EntityValues<M>);
234
234
 
235
- const modifiedValuesRef = useRef<EntityValues<M> | undefined>(undefined);
236
- const modifiedValues = modifiedValuesRef.current;
235
+ // const modifiedValuesRef = useRef<EntityValues<M> | undefined>(undefined);
236
+ // const modifiedValues = modifiedValuesRef.current;
237
237
 
238
238
  const subcollections = (collection.subcollections ?? []).filter(c => !c.hideFromNavigation);
239
239
  const subcollectionsCount = subcollections?.length ?? 0;
@@ -443,12 +443,15 @@ export function EntityEditViewInner<M extends Record<string, any>>({
443
443
  collection: inputCollection,
444
444
  path,
445
445
  entityId,
446
- values: internalValues,
446
+ values: formex.values,
447
447
  previousValues: formex.initialValues,
448
448
  fields: customizationController.propertyConfigs
449
449
  });
450
450
 
451
+ const lastSavedValues = useRef<EntityValues<M> | undefined>(entity?.values);
452
+
451
453
  const save = (values: EntityValues<M>): Promise<void> => {
454
+ lastSavedValues.current = values;
452
455
  return onSaveEntityRequest({
453
456
  collection: resolvedCollection,
454
457
  path,
@@ -510,7 +513,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
510
513
  {formContext && <Builder
511
514
  collection={collection}
512
515
  entity={usedEntity}
513
- modifiedValues={modifiedValues ?? usedEntity?.values}
516
+ modifiedValues={formex.values ?? usedEntity?.values}
514
517
  formContext={formContext}
515
518
  />}
516
519
  </ErrorBoundary>
@@ -573,9 +576,9 @@ export function EntityEditViewInner<M extends Record<string, any>>({
573
576
  });
574
577
  };
575
578
 
576
- const onValuesChanged = useCallback((values?: EntityValues<M>) => {
577
- modifiedValuesRef.current = values;
578
- }, []);
579
+ // const onValuesChanged = useCallback((values?: EntityValues<M>) => {
580
+ // modifiedValuesRef.current = values;
581
+ // }, []);
579
582
 
580
583
  // eslint-disable-next-line n/handle-callback-err
581
584
  const onIdUpdateError = useCallback((error: any) => {
@@ -594,11 +597,6 @@ export function EntityEditViewInner<M extends Record<string, any>>({
594
597
  : undefined);
595
598
  }, []);
596
599
 
597
- const onModified = (dirty: boolean) => {
598
- if (!autoSave)
599
- onValuesAreModified(dirty);
600
- }
601
-
602
600
  // useEffect(() => {
603
601
  // baseDataSourceValuesRef.current = getDataSourceEntityValues(initialResolvedCollection, status, entity);
604
602
  // const initialValues = formex.initialValues;
@@ -646,19 +644,19 @@ export function EntityEditViewInner<M extends Record<string, any>>({
646
644
  }
647
645
 
648
646
  const titlePropertyKey = getEntityTitlePropertyKey(resolvedCollection, customizationController.propertyConfigs);
649
- const title = internalValues && titlePropertyKey ? getValueInPath(internalValues, titlePropertyKey) : undefined;
647
+ const title = formex.values && titlePropertyKey ? getValueInPath(formex.values, titlePropertyKey) : undefined;
650
648
 
651
649
  const onIdUpdate = inputCollection.callbacks?.onIdUpdate;
652
650
 
653
651
  const doOnIdUpdate = useCallback(async () => {
654
- if (onIdUpdate && internalValues && (status === "new" || status === "copy")) {
652
+ if (onIdUpdate && formex.values && (status === "new" || status === "copy")) {
655
653
  setCustomIdLoading(true);
656
654
  try {
657
655
  const updatedId = await onIdUpdate({
658
656
  collection: resolvedCollection,
659
657
  path,
660
658
  entityId,
661
- values: internalValues,
659
+ values: formex.values,
662
660
  context
663
661
  });
664
662
  setEntityId(updatedId);
@@ -668,7 +666,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
668
666
  }
669
667
  setCustomIdLoading(false);
670
668
  }
671
- }, [entityId, internalValues, status]);
669
+ }, [entityId, formex.values, status]);
672
670
 
673
671
  useEffect(() => {
674
672
  doOnIdUpdate();
@@ -712,10 +710,13 @@ export function EntityEditViewInner<M extends Record<string, any>>({
712
710
 
713
711
  const modified = formex.dirty;
714
712
  useEffect(() => {
715
- if (onModified)
716
- onModified(modified);
717
- if (onValuesChanged)
718
- onValuesChanged(formex.values);
713
+ if (!autoSave) {
714
+ onValuesAreModified(modified);
715
+ } else {
716
+ if (formex.values && !equal(formex.values, lastSavedValues.current)) {
717
+ save(formex.values);
718
+ }
719
+ }
719
720
  }, [modified, formex.values]);
720
721
 
721
722
  useEffect(() => {
@@ -915,8 +916,6 @@ export function EntityEditViewInner<M extends Record<string, any>>({
915
916
  path={path}
916
917
  collection={collection}
917
918
  onDiscard={onDiscard}
918
- onValuesChanged={onValuesChanged}
919
- onModified={onModified}
920
919
  entity={usedEntity}
921
920
  context={context}
922
921
  formContext={formContext}
@@ -1,13 +1,6 @@
1
1
  import React, { useCallback } from "react";
2
2
 
3
- import {
4
- ArrayProperty,
5
- Entity,
6
- FieldProps,
7
- ResolvedArrayProperty,
8
- ResolvedStringProperty,
9
- StorageConfig
10
- } from "../../types";
3
+ import { ArrayProperty, FieldProps, ResolvedArrayProperty, ResolvedStringProperty, StorageConfig } from "../../types";
11
4
  import { useDropzone } from "react-dropzone";
12
5
  import { PreviewSize } from "../../preview";
13
6
  import { FieldHelperText, LabelWithIcon } from "../components";
@@ -30,7 +23,7 @@ import { useClearRestoreValue } from "../useClearRestoreValue";
30
23
 
31
24
  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";
32
25
  const disabledClasses = "border-dotted-gray"
33
- const nonActiveDropClasses = "hover:bg-field-hover dark:hover:bg-field-hover-dark"
26
+ const nonActiveDropClasses = fieldBackgroundHoverMixin
34
27
  const activeDropClasses = "pt-0 border-2 border-solid"
35
28
  const acceptDropClasses = "transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500"
36
29
  const rejectDropClasses = "transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500"