@firecms/core 3.0.0-canary.283 → 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.
- package/dist/core/EntityEditView.d.ts +2 -2
- package/dist/form/EntityForm.d.ts +3 -1
- package/dist/form/index.d.ts +2 -1
- package/dist/index.es.js +123 -120
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +121 -118
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collections.d.ts +7 -0
- package/dist/util/entity_cache.d.ts +2 -1
- package/package.json +5 -5
- package/src/core/EntityEditView.tsx +11 -10
- package/src/core/EntityEditViewFormActions.tsx +33 -18
- package/src/form/EntityForm.tsx +49 -25
- package/src/form/EntityFormActions.tsx +30 -15
- package/src/form/components/ErrorFocus.tsx +22 -29
- package/src/form/index.tsx +5 -1
- package/src/types/collections.ts +8 -0
- package/src/util/entity_cache.ts +22 -34
package/src/form/index.tsx
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export {
|
|
2
|
+
EntityForm,
|
|
3
|
+
yupToFormErrors,
|
|
4
|
+
} from "./EntityForm";
|
|
5
|
+
export type { EntityFormProps } from "./EntityForm";
|
|
2
6
|
|
|
3
7
|
export { SelectFieldBinding } from "./field_bindings/SelectFieldBinding";
|
|
4
8
|
export { MultiSelectFieldBinding } from "./field_bindings/MultiSelectFieldBinding";
|
package/src/types/collections.ts
CHANGED
|
@@ -352,6 +352,14 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
352
352
|
* This prop has no effect if the history plugin is not enabled
|
|
353
353
|
*/
|
|
354
354
|
history?: boolean;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* If set to true, local changes to entities in this collection will be backed up
|
|
358
|
+
* in the browser's local storage. This allows users to recover unsaved changes
|
|
359
|
+
* in case of accidental navigation or browser crashes.
|
|
360
|
+
* Defaults to `true`.
|
|
361
|
+
*/
|
|
362
|
+
enableLocalChangesBackup?: boolean;
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
/**
|
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);
|
|
@@ -157,7 +146,6 @@ export function hasEntityInCache(path: string): boolean {
|
|
|
157
146
|
*/
|
|
158
147
|
export function removeEntityFromCache(path: string): void {
|
|
159
148
|
|
|
160
|
-
|
|
161
149
|
console.debug("Removing entity from cache", path);
|
|
162
150
|
|
|
163
151
|
// Remove from the in-memory cache
|