@firecms/core 3.0.0-canary.284 → 3.0.0-canary.285

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.
@@ -8,9 +8,10 @@ export declare function saveEntityToCache(path: string, data: object): void;
8
8
  * Retrieves an entity from the in-memory cache or `localStorage`.
9
9
  * If the entity is not in the cache but exists in `localStorage`, it loads it into the cache.
10
10
  * @param path - The unique path/key for the entity.
11
+ * @param useLocalStorage
11
12
  * @returns The cached entity or `undefined` if not found.
12
13
  */
13
- export declare function getEntityFromCache(path: string): object | undefined;
14
+ export declare function getEntityFromCache(path: string, useLocalStorage?: boolean): object | undefined;
14
15
  export declare function hasEntityInCache(path: string): boolean;
15
16
  /**
16
17
  * Removes an entity from both the in-memory cache and `localStorage`.
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.284",
4
+ "version": "3.0.0-canary.285",
5
5
  "description": "Awesome Firebase/Firestore-based headless open-source CMS",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/firecmsco"
@@ -53,9 +53,9 @@
53
53
  "@dnd-kit/core": "^6.3.1",
54
54
  "@dnd-kit/modifiers": "^9.0.0",
55
55
  "@dnd-kit/sortable": "^10.0.0",
56
- "@firecms/editor": "^3.0.0-canary.284",
57
- "@firecms/formex": "^3.0.0-canary.284",
58
- "@firecms/ui": "^3.0.0-canary.284",
56
+ "@firecms/editor": "^3.0.0-canary.285",
57
+ "@firecms/formex": "^3.0.0-canary.285",
58
+ "@firecms/ui": "^3.0.0-canary.285",
59
59
  "@radix-ui/react-portal": "^1.1.9",
60
60
  "clsx": "^2.1.1",
61
61
  "date-fns": "^3.6.0",
@@ -108,7 +108,7 @@
108
108
  "dist",
109
109
  "src"
110
110
  ],
111
- "gitHead": "443c1f2616b08bf03cd00ce2932be53d3aa96110",
111
+ "gitHead": "a442a00b64764b353c977cc9e758953995bd9513",
112
112
  "publishConfig": {
113
113
  "access": "public"
114
114
  },
@@ -99,11 +99,9 @@ export function EntityEditView<M extends Record<string, any>, USER extends User>
99
99
 
100
100
  const enableLocalChangesBackup = props.collection.enableLocalChangesBackup !== undefined ? props.collection.enableLocalChangesBackup : true;
101
101
 
102
- const initialDirtyValues = enableLocalChangesBackup
103
- ? (entityId
104
- ? getEntityFromCache(props.path + "/" + entityId)
105
- : getEntityFromCache(props.path + "#new"))
106
- : undefined;
102
+ const initialDirtyValues = entityId
103
+ ? getEntityFromCache(props.path + "/" + entityId, enableLocalChangesBackup)
104
+ : getEntityFromCache(props.path + "#new", enableLocalChangesBackup);
107
105
 
108
106
  const authController = useAuthController();
109
107
 
@@ -18,25 +18,40 @@ function customReplacer(key: string): any {
18
18
  // Handle Date objects
19
19
  // @ts-ignore
20
20
  if (value instanceof Date) {
21
- return { __type: "Date", value: value.toISOString() };
21
+ return {
22
+ __type: "Date",
23
+ value: value.toISOString()
24
+ };
22
25
  }
23
26
 
24
27
  // Handle EntityReference
25
28
  // @ts-ignore
26
29
  if (value instanceof EntityReference) {
27
- return { __type: "EntityReference", id: value.id, path: value.path, databaseId: value.databaseId };
30
+ return {
31
+ __type: "EntityReference",
32
+ id: value.id,
33
+ path: value.path,
34
+ databaseId: value.databaseId
35
+ };
28
36
  }
29
37
 
30
38
  // Handle GeoPoint
31
39
  // @ts-ignore
32
40
  if (value instanceof GeoPoint) {
33
- return { __type: "GeoPoint", latitude: value.latitude, longitude: value.longitude };
41
+ return {
42
+ __type: "GeoPoint",
43
+ latitude: value.latitude,
44
+ longitude: value.longitude
45
+ };
34
46
  }
35
47
 
36
48
  // Handle Vector
37
49
  // @ts-ignore
38
50
  if (value instanceof Vector) {
39
- return { __type: "Vector", value: value.value };
51
+ return {
52
+ __type: "Vector",
53
+ value: value.value
54
+ };
40
55
  }
41
56
 
42
57
  return value;
@@ -61,33 +76,6 @@ function customReviver(key: string, value: any): any {
61
76
  return value;
62
77
  }
63
78
 
64
- // Initialize the in-memory cache by loading entities from `localStorage`
65
- if (isLocalStorageAvailable) {
66
- try {
67
- // Iterate over all keys in localStorage to find those with the specified prefix
68
- for (let i = 0; i < localStorage.length; i++) {
69
- const fullKey = localStorage.key(i);
70
- if (fullKey && fullKey.startsWith(LOCAL_STORAGE_PREFIX)) {
71
- const path = fullKey.substring(LOCAL_STORAGE_PREFIX.length);
72
- const entityString = localStorage.getItem(fullKey);
73
- if (entityString) {
74
- try {
75
- const entity: object = JSON.parse(entityString, customReviver);
76
- entityCache.set(path, entity);
77
- } catch (parseError) {
78
- console.error(
79
- `Failed to parse entity for path "${path}" from localStorage:`,
80
- parseError
81
- );
82
- }
83
- }
84
- }
85
- }
86
- } catch (error) {
87
- console.error("Error accessing localStorage during initialization:", error);
88
- }
89
- }
90
-
91
79
  /**
92
80
  * Saves data to the in-memory cache and persists it individually in `localStorage`.
93
81
  * @param path - The unique path/key for the data.
@@ -116,9 +104,10 @@ export function saveEntityToCache(path: string, data: object): void {
116
104
  * Retrieves an entity from the in-memory cache or `localStorage`.
117
105
  * If the entity is not in the cache but exists in `localStorage`, it loads it into the cache.
118
106
  * @param path - The unique path/key for the entity.
107
+ * @param useLocalStorage
119
108
  * @returns The cached entity or `undefined` if not found.
120
109
  */
121
- export function getEntityFromCache(path: string): object | undefined {
110
+ export function getEntityFromCache(path: string, useLocalStorage = true): object | undefined {
122
111
 
123
112
  // Attempt to retrieve the entity from the in-memory cache
124
113
  if (entityCache.has(path)) {
@@ -126,7 +115,7 @@ export function getEntityFromCache(path: string): object | undefined {
126
115
  }
127
116
 
128
117
  // If not in the cache, attempt to load it from localStorage
129
- if (isLocalStorageAvailable) {
118
+ if (isLocalStorageAvailable && useLocalStorage) {
130
119
  try {
131
120
  const key = LOCAL_STORAGE_PREFIX + path;
132
121
  const entityString = localStorage.getItem(key);