@firecms/core 3.0.0-canary.284 → 3.0.0-canary.286
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/index.es.js +5 -25
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +5 -25
- package/dist/index.umd.js.map +1 -1
- package/dist/util/entity_cache.d.ts +2 -1
- package/package.json +5 -5
- package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +3 -1
- package/src/core/EntityEditView.tsx +3 -5
- package/src/util/entity_cache.ts +22 -33
|
@@ -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.
|
|
4
|
+
"version": "3.0.0-canary.286",
|
|
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.
|
|
57
|
-
"@firecms/formex": "^3.0.0-canary.
|
|
58
|
-
"@firecms/ui": "^3.0.0-canary.
|
|
56
|
+
"@firecms/editor": "^3.0.0-canary.286",
|
|
57
|
+
"@firecms/formex": "^3.0.0-canary.286",
|
|
58
|
+
"@firecms/ui": "^3.0.0-canary.286",
|
|
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": "
|
|
111
|
+
"gitHead": "67c7145be1866d52ac71fc6281537c388d074722",
|
|
112
112
|
"publishConfig": {
|
|
113
113
|
"access": "public"
|
|
114
114
|
},
|
|
@@ -79,7 +79,9 @@ export const EntityCollectionRowActions = function EntityCollectionRowActions({
|
|
|
79
79
|
|
|
80
80
|
const collapsedActions = actions.filter(a => a.collapsed || a.collapsed === undefined);
|
|
81
81
|
const uncollapsedActions = actions.filter(a => a.collapsed === false);
|
|
82
|
-
const
|
|
82
|
+
const enableLocalChangesBackup = collection?.enableLocalChangesBackup !== undefined ? collection?.enableLocalChangesBackup : true;
|
|
83
|
+
const hasDraft = enableLocalChangesBackup ? hasEntityInCache(fullPath + "/" + entity.id) : false;
|
|
84
|
+
|
|
83
85
|
return (
|
|
84
86
|
<div
|
|
85
87
|
className={cls(
|
|
@@ -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 =
|
|
103
|
-
? (entityId
|
|
104
|
-
|
|
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
|
|
package/src/util/entity_cache.ts
CHANGED
|
@@ -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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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);
|