@firecms/core 3.0.0-canary.2 → 3.0.0-canary.4
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/components/ReferenceWidget.d.ts +3 -3
- package/dist/index.es.js +1389 -1387
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +5 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/types/entities.d.ts +2 -1
- package/dist/util/entities.d.ts +1 -1
- package/package.json +4 -4
- package/src/components/EntityCollectionTable/fields/TableReferenceField.tsx +1 -1
- package/src/components/ReferenceWidget.tsx +4 -4
- package/src/components/SelectableTable/filters/ReferenceFilterField.tsx +2 -2
- package/src/form/field_bindings/KeyValueFieldBinding.tsx +1 -1
- package/src/form/field_bindings/ReferenceFieldBinding.tsx +1 -1
- package/src/hooks/useBuildNavigationController.tsx +1 -9
- package/src/internal/useBuildDataSource.ts +1 -1
- package/src/preview/PropertyPreview.tsx +1 -1
- package/src/preview/components/ReferencePreview.tsx +1 -1
- package/src/types/entities.ts +5 -1
- package/src/util/entities.ts +1 -1
package/dist/types/entities.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type EntityValues<M extends object> = M;
|
|
|
31
31
|
/**
|
|
32
32
|
* Class used to create a reference to an entity in a different path
|
|
33
33
|
*/
|
|
34
|
-
export declare class EntityReference
|
|
34
|
+
export declare class EntityReference {
|
|
35
35
|
/**
|
|
36
36
|
* ID of the entity
|
|
37
37
|
*/
|
|
@@ -43,6 +43,7 @@ export declare class EntityReference<M extends Record<string, any> = any> {
|
|
|
43
43
|
readonly path: string;
|
|
44
44
|
constructor(id: string, path: string);
|
|
45
45
|
get pathWithId(): string;
|
|
46
|
+
isEntityReference(): boolean;
|
|
46
47
|
}
|
|
47
48
|
export declare class GeoPoint {
|
|
48
49
|
/**
|
package/dist/util/entities.d.ts
CHANGED
|
@@ -23,6 +23,6 @@ export declare function updateDateAutoValues<M extends Record<string, any>>({ in
|
|
|
23
23
|
* @group Datasource
|
|
24
24
|
*/
|
|
25
25
|
export declare function sanitizeData<M extends Record<string, any>>(values: EntityValues<M>, properties: ResolvedProperties<M>): any;
|
|
26
|
-
export declare function getReferenceFrom<M extends Record<string, any>>(entity: Entity<M>): EntityReference
|
|
26
|
+
export declare function getReferenceFrom<M extends Record<string, any>>(entity: Entity<M>): EntityReference;
|
|
27
27
|
export declare function traverseValuesProperties<M extends Record<string, any>>(inputValues: Partial<EntityValues<M>>, properties: ResolvedProperties<M>, operation: (value: any, property: Property) => any): EntityValues<M> | undefined;
|
|
28
28
|
export declare function traverseValueProperty(inputValue: any, property: Property, operation: (value: any, property: Property) => any): any;
|
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.4",
|
|
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.
|
|
50
|
-
"@firecms/ui": "^3.0.0-canary.
|
|
49
|
+
"@firecms/formex": "^3.0.0-canary.4",
|
|
50
|
+
"@firecms/ui": "^3.0.0-canary.4",
|
|
51
51
|
"@fontsource/ibm-plex-mono": "^5.0.8",
|
|
52
52
|
"@fontsource/roboto": "^5.0.8",
|
|
53
53
|
"@hello-pangea/dnd": "^16.5.0",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"dist",
|
|
116
116
|
"src"
|
|
117
117
|
],
|
|
118
|
-
"gitHead": "
|
|
118
|
+
"gitHead": "b821bceb86cfbbcdfe34bb234e5adfd0e740a6cf",
|
|
119
119
|
"publishConfig": {
|
|
120
120
|
"access": "public"
|
|
121
121
|
}
|
|
@@ -96,7 +96,7 @@ export const TableReferenceFieldSuccess = React.memo(
|
|
|
96
96
|
const valueNotSet = !internalValue || (Array.isArray(internalValue) && internalValue.length === 0);
|
|
97
97
|
|
|
98
98
|
const buildSingleReferenceField = () => {
|
|
99
|
-
if (internalValue
|
|
99
|
+
if (internalValue && !Array.isArray(internalValue) && internalValue.isEntityReference && internalValue.isEntityReference())
|
|
100
100
|
return <ReferencePreview
|
|
101
101
|
onClick={disabled ? undefined : handleOpen}
|
|
102
102
|
size={getPreviewSizeFrom(size)}
|
|
@@ -9,13 +9,13 @@ import { Button, cn } from "@firecms/ui";
|
|
|
9
9
|
export type ReferenceWidgetProps<M extends Record<string, any>> = {
|
|
10
10
|
name?: string,
|
|
11
11
|
multiselect?: boolean,
|
|
12
|
-
value: EntityReference
|
|
12
|
+
value: EntityReference | EntityReference[] | null,
|
|
13
13
|
onReferenceSelected?: (params: {
|
|
14
|
-
reference: EntityReference
|
|
14
|
+
reference: EntityReference | null,
|
|
15
15
|
entity: Entity<M> | null
|
|
16
16
|
}) => void,
|
|
17
17
|
onMultipleReferenceSelected?: (params: {
|
|
18
|
-
references: EntityReference
|
|
18
|
+
references: EntityReference[] | null,
|
|
19
19
|
entities: Entity<M>[] | null
|
|
20
20
|
}) => void,
|
|
21
21
|
path: string,
|
|
@@ -113,7 +113,7 @@ export function ReferenceWidget<M extends Record<string, any>>({
|
|
|
113
113
|
size={size}/>
|
|
114
114
|
})}
|
|
115
115
|
</div>
|
|
116
|
-
} else if (value
|
|
116
|
+
} else if (value?.isEntityReference && value?.isEntityReference()) {
|
|
117
117
|
child = <ReferencePreview
|
|
118
118
|
reference={value}
|
|
119
119
|
onClick={onEntryClick}
|
|
@@ -60,7 +60,7 @@ export function ReferenceFilterField({
|
|
|
60
60
|
|
|
61
61
|
const selectedEntityIds = internalValue
|
|
62
62
|
? (Array.isArray(internalValue) ? internalValue.map((ref) => {
|
|
63
|
-
if (!(ref
|
|
63
|
+
if (!(ref.isEntityReference && ref.isEntityReference())) {
|
|
64
64
|
return null;
|
|
65
65
|
}
|
|
66
66
|
return ref.id;
|
|
@@ -74,7 +74,7 @@ export function ReferenceFilterField({
|
|
|
74
74
|
let newValue = val;
|
|
75
75
|
if (prevOpIsArray !== newOpIsArray) {
|
|
76
76
|
// @ts-ignore
|
|
77
|
-
newValue = newOpIsArray ? (newValue
|
|
77
|
+
newValue = newOpIsArray ? (newValue.isEntityReference && newValue.isEntityReference() ? [newValue] : []) : undefined
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
setOperation(op);
|
|
@@ -546,7 +546,7 @@ function getDataType(value: any): DataType | undefined {
|
|
|
546
546
|
return "array";
|
|
547
547
|
} else if (value instanceof Date) {
|
|
548
548
|
return "date";
|
|
549
|
-
} else if (value
|
|
549
|
+
} else if (value.isEntityReference && value.isEntityReference()) {
|
|
550
550
|
return "reference";
|
|
551
551
|
} else if (value instanceof GeoPoint) {
|
|
552
552
|
return "geopoint";
|
|
@@ -49,7 +49,7 @@ function ReferenceFieldBindingInternal<M extends Record<string, any>>({
|
|
|
49
49
|
setValue
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
const validValue = value && value
|
|
52
|
+
const validValue = value && value.isEntityReference && value.isEntityReference();
|
|
53
53
|
|
|
54
54
|
const navigationController = useNavigationController();
|
|
55
55
|
const collection: EntityCollection | undefined = useMemo(() => {
|
|
@@ -279,15 +279,7 @@ export function useBuildNavigationController<EC extends EntityCollection, UserTy
|
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
// for each odd path segment, get the collection
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
getCollectionFromPaths(oddPathSegments);
|
|
285
|
-
|
|
286
|
-
// const allParentCollectionsForPath = getAllParentReferencesForPath(path);
|
|
287
|
-
// console.log("allParentCollectionsForPath", allParentCollectionsForPath);
|
|
288
|
-
// const parentCollectionIds = allParentCollectionsForPath.map(r => r.id);
|
|
289
|
-
console.log("getParentCollectionIds", path, parentCollectionIds);
|
|
290
|
-
return parentCollectionIds;
|
|
282
|
+
return result.map(r => getCollectionFromPaths(r)?.id).filter(Boolean) as string[];
|
|
291
283
|
}, [getAllParentReferencesForPath])
|
|
292
284
|
|
|
293
285
|
const convertIdsToPaths = useCallback((ids: string[]): string[] => {
|
|
@@ -342,7 +342,7 @@ export function cmsToDelegateModel(data: any,
|
|
|
342
342
|
return buildDelete();
|
|
343
343
|
} else if (Array.isArray(data)) {
|
|
344
344
|
return data.map(v => cmsToDelegateModel(v, buildReference, buildGeoPoint, buildDate, buildDelete));
|
|
345
|
-
} else if (data
|
|
345
|
+
} else if (data.isEntityReference && data.isEntityReference()) {
|
|
346
346
|
return buildReference(data);
|
|
347
347
|
} else if (data instanceof GeoPoint) {
|
|
348
348
|
return buildGeoPoint(data);
|
|
@@ -178,7 +178,7 @@ export const PropertyPreview = React.memo(function PropertyPreview<T extends CMS
|
|
|
178
178
|
}
|
|
179
179
|
} else if (property.dataType === "reference") {
|
|
180
180
|
if (typeof property.path === "string") {
|
|
181
|
-
if (value
|
|
181
|
+
if (typeof value === "object" && "isEntityReference" in value && value.isEntityReference()) {
|
|
182
182
|
content = <ReferencePreview
|
|
183
183
|
disabled={!property.path}
|
|
184
184
|
previewProperties={property.previewProperties}
|
|
@@ -32,7 +32,7 @@ export type ReferencePreviewProps = {
|
|
|
32
32
|
*/
|
|
33
33
|
export const ReferencePreview = React.memo<ReferencePreviewProps>(function ReferencePreview(props: ReferencePreviewProps) {
|
|
34
34
|
const reference = props.reference;
|
|
35
|
-
if (!(
|
|
35
|
+
if (!(typeof reference === "object" && "isEntityReference" in reference && reference.isEntityReference())) {
|
|
36
36
|
console.warn("Reference preview received value of type", typeof reference);
|
|
37
37
|
return <ReferencePreviewContainer
|
|
38
38
|
onClick={props.onClick}
|
package/src/types/entities.ts
CHANGED
|
@@ -37,7 +37,7 @@ export type EntityValues<M extends object> = M;
|
|
|
37
37
|
/**
|
|
38
38
|
* Class used to create a reference to an entity in a different path
|
|
39
39
|
*/
|
|
40
|
-
export class EntityReference
|
|
40
|
+
export class EntityReference {
|
|
41
41
|
/**
|
|
42
42
|
* ID of the entity
|
|
43
43
|
*/
|
|
@@ -56,6 +56,10 @@ export class EntityReference<M extends Record<string, any> = any> {
|
|
|
56
56
|
get pathWithId() {
|
|
57
57
|
return `${this.path}/${this.id}`;
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
isEntityReference() {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
export class GeoPoint {
|
package/src/util/entities.ts
CHANGED
|
@@ -139,7 +139,7 @@ export function sanitizeData<M extends Record<string, any>>
|
|
|
139
139
|
return result;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
export function getReferenceFrom<M extends Record<string, any>>(entity: Entity<M>): EntityReference
|
|
142
|
+
export function getReferenceFrom<M extends Record<string, any>>(entity: Entity<M>): EntityReference {
|
|
143
143
|
return new EntityReference(entity.id, entity.path);
|
|
144
144
|
}
|
|
145
145
|
|