@firecms/core 3.0.0-canary.286 → 3.0.0-canary.287
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/core/EntityEditView.d.ts +8 -2
- package/dist/form/EntityForm.d.ts +1 -1
- package/dist/form/components/LocalChangesMenu.d.ts +11 -0
- package/dist/index.es.js +363 -46
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +361 -44
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collections.d.ts +10 -6
- package/dist/util/collections.d.ts +1 -0
- package/dist/util/entity_cache.d.ts +5 -2
- package/package.json +5 -5
- package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +4 -3
- package/src/components/EntityCollectionView/EntityCollectionView.tsx +1 -1
- package/src/core/EntityEditView.tsx +20 -8
- package/src/core/EntitySidePanel.tsx +9 -3
- package/src/form/EntityForm.tsx +77 -22
- package/src/form/components/LocalChangesMenu.tsx +157 -0
- package/src/types/collections.ts +10 -6
- package/src/util/collections.ts +8 -0
- package/src/util/createFormexStub.tsx +4 -0
- package/src/util/entity_cache.ts +18 -22
package/src/util/entity_cache.ts
CHANGED
|
@@ -82,9 +82,6 @@ function customReviver(key: string, value: any): any {
|
|
|
82
82
|
* @param data - The data to cache and persist.
|
|
83
83
|
*/
|
|
84
84
|
export function saveEntityToCache(path: string, data: object): void {
|
|
85
|
-
// Update the in-memory cache
|
|
86
|
-
entityCache.set(path, data);
|
|
87
|
-
|
|
88
85
|
// Persist the data individually in localStorage
|
|
89
86
|
if (isLocalStorageAvailable) {
|
|
90
87
|
try {
|
|
@@ -100,6 +97,22 @@ export function saveEntityToCache(path: string, data: object): void {
|
|
|
100
97
|
}
|
|
101
98
|
}
|
|
102
99
|
|
|
100
|
+
export function removeEntityFromMemoryCache(path: string): void {
|
|
101
|
+
entityCache.delete(path);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function saveEntityToMemoryCache(path: string, data: object): void {
|
|
105
|
+
entityCache.set(path, data);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function getEntityFromMemoryCache(path: string): object | undefined {
|
|
109
|
+
return entityCache.get(path);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function hasEntityInCache(path: string): boolean {
|
|
113
|
+
return entityCache.has(path);
|
|
114
|
+
}
|
|
115
|
+
|
|
103
116
|
/**
|
|
104
117
|
* Retrieves an entity from the in-memory cache or `localStorage`.
|
|
105
118
|
* If the entity is not in the cache but exists in `localStorage`, it loads it into the cache.
|
|
@@ -107,21 +120,15 @@ export function saveEntityToCache(path: string, data: object): void {
|
|
|
107
120
|
* @param useLocalStorage
|
|
108
121
|
* @returns The cached entity or `undefined` if not found.
|
|
109
122
|
*/
|
|
110
|
-
export function getEntityFromCache(path: string
|
|
111
|
-
|
|
112
|
-
// Attempt to retrieve the entity from the in-memory cache
|
|
113
|
-
if (entityCache.has(path)) {
|
|
114
|
-
return entityCache.get(path);
|
|
115
|
-
}
|
|
123
|
+
export function getEntityFromCache(path: string): object | undefined {
|
|
116
124
|
|
|
117
125
|
// If not in the cache, attempt to load it from localStorage
|
|
118
|
-
if (isLocalStorageAvailable
|
|
126
|
+
if (isLocalStorageAvailable) {
|
|
119
127
|
try {
|
|
120
128
|
const key = LOCAL_STORAGE_PREFIX + path;
|
|
121
129
|
const entityString = localStorage.getItem(key);
|
|
122
130
|
if (entityString) {
|
|
123
131
|
const entity: object = JSON.parse(entityString, customReviver);
|
|
124
|
-
entityCache.set(path, entity); // Update the cache
|
|
125
132
|
return entity;
|
|
126
133
|
}
|
|
127
134
|
} catch (error) {
|
|
@@ -136,22 +143,11 @@ export function getEntityFromCache(path: string, useLocalStorage = true): object
|
|
|
136
143
|
return undefined;
|
|
137
144
|
}
|
|
138
145
|
|
|
139
|
-
export function hasEntityInCache(path: string): boolean {
|
|
140
|
-
return entityCache.has(path);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
146
|
/**
|
|
144
147
|
* Removes an entity from both the in-memory cache and `localStorage`.
|
|
145
148
|
* @param path - The unique path/key for the entity to remove.
|
|
146
149
|
*/
|
|
147
150
|
export function removeEntityFromCache(path: string): void {
|
|
148
|
-
|
|
149
|
-
console.debug("Removing entity from cache", path);
|
|
150
|
-
|
|
151
|
-
// Remove from the in-memory cache
|
|
152
|
-
entityCache.delete(path);
|
|
153
|
-
|
|
154
|
-
// Remove from localStorage
|
|
155
151
|
if (isLocalStorageAvailable) {
|
|
156
152
|
try {
|
|
157
153
|
const key = LOCAL_STORAGE_PREFIX + path;
|