@firecms/core 3.0.0-canary.3 → 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.
@@ -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<M extends Record<string, any> = any> {
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
  /**
@@ -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<M>;
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.3",
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.3",
50
- "@firecms/ui": "^3.0.0-canary.3",
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": "9d587b683991dfcefd28e1c13b693364b5de72b2",
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 instanceof EntityReference)
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<M> | EntityReference<M>[] | null,
12
+ value: EntityReference | EntityReference[] | null,
13
13
  onReferenceSelected?: (params: {
14
- reference: EntityReference<M> | null,
14
+ reference: EntityReference | null,
15
15
  entity: Entity<M> | null
16
16
  }) => void,
17
17
  onMultipleReferenceSelected?: (params: {
18
- references: EntityReference<M>[] | null,
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 instanceof EntityReference) {
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 instanceof EntityReference)) {
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 instanceof EntityReference ? [newValue] : []) : undefined
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 instanceof EntityReference) {
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 instanceof EntityReference;
52
+ const validValue = value && value.isEntityReference && value.isEntityReference();
53
53
 
54
54
  const navigationController = useNavigationController();
55
55
  const collection: EntityCollection | undefined = useMemo(() => {
@@ -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 instanceof EntityReference) {
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 instanceof EntityReference) {
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 (!((reference as unknown) instanceof EntityReference)) {
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}
@@ -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<M extends Record<string, any> = any> {
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 {
@@ -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<M> {
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