@firecms/core 3.0.0-alpha.26 → 3.0.0-alpha.28

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.
Files changed (51) hide show
  1. package/dist/components/Popover.d.ts +3 -1
  2. package/dist/core/builders.d.ts +3 -3
  3. package/dist/core/components/EntityCollectionTable/filters/ReferenceFilterField.d.ts +3 -3
  4. package/dist/core/components/FieldConfigBadge.d.ts +3 -3
  5. package/dist/core/components/VirtualTable/VirtualTableHeader.d.ts +2 -2
  6. package/dist/core/form_field_configs.d.ts +3 -3
  7. package/dist/core/util/property_utils.d.ts +5 -5
  8. package/dist/core/util/references.d.ts +2 -2
  9. package/dist/core/util/resolutions.d.ts +5 -5
  10. package/dist/hooks/index.d.ts +1 -0
  11. package/dist/hooks/useBuildDataSource.d.ts +23 -0
  12. package/dist/index.es.js +6877 -6634
  13. package/dist/index.es.js.map +1 -1
  14. package/dist/index.umd.js +14 -14
  15. package/dist/index.umd.js.map +1 -1
  16. package/dist/types/datasource.d.ts +120 -11
  17. package/dist/types/fields.d.ts +1 -1
  18. package/dist/types/firecms.d.ts +3 -3
  19. package/dist/types/firecms_context.d.ts +3 -3
  20. package/dist/types/index.d.ts +1 -1
  21. package/dist/types/properties.d.ts +1 -1
  22. package/dist/types/{field_config.d.ts → property_config.d.ts} +3 -4
  23. package/package.json +2 -2
  24. package/src/components/Popover.tsx +10 -3
  25. package/src/components/TextareaAutosize.tsx +2 -1
  26. package/src/core/builders.ts +5 -5
  27. package/src/core/components/EntityCollectionTable/EntityCollectionTable.tsx +4 -4
  28. package/src/core/components/EntityCollectionTable/filters/ReferenceFilterField.tsx +11 -6
  29. package/src/core/components/EntityCollectionTable/internal/PropertyTableCell.tsx +2 -2
  30. package/src/core/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +6 -2
  31. package/src/core/components/EntityCollectionView/EntityCollectionView.tsx +1 -1
  32. package/src/core/components/FieldConfigBadge.tsx +4 -4
  33. package/src/core/components/VirtualTable/VirtualTableHeader.tsx +21 -18
  34. package/src/core/form_field_configs.tsx +5 -5
  35. package/src/core/util/property_utils.tsx +5 -5
  36. package/src/core/util/references.ts +2 -2
  37. package/src/core/util/resolutions.ts +16 -11
  38. package/src/form/EntityForm.tsx +1 -1
  39. package/src/form/PropertyFieldBinding.tsx +4 -4
  40. package/src/form/field_bindings/KeyValueFieldBinding.tsx +1 -1
  41. package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +4 -6
  42. package/src/hooks/index.tsx +1 -0
  43. package/src/hooks/useBuildDataSource.ts +351 -0
  44. package/src/preview/property_previews/StringPropertyPreview.tsx +4 -2
  45. package/src/types/datasource.ts +174 -10
  46. package/src/types/fields.tsx +1 -1
  47. package/src/types/firecms.tsx +3 -3
  48. package/src/types/firecms_context.tsx +3 -3
  49. package/src/types/index.ts +1 -1
  50. package/src/types/properties.ts +1 -1
  51. package/src/types/{field_config.tsx → property_config.tsx} +3 -4
@@ -1,6 +1,6 @@
1
- import { Entity, EntityStatus, EntityValues } from "./entities";
1
+ import { Entity, EntityReference, EntityStatus, EntityValues, GeoPoint } from "./entities";
2
2
  import { EntityCollection, FilterValues } from "./collections";
3
- import { ResolvedEntityCollection, ResolvedProperty } from "./resolved_entities";
3
+ import { ResolvedEntityCollection } from "./resolved_entities";
4
4
 
5
5
  /**
6
6
  * @category Datasource
@@ -198,7 +198,6 @@ export interface DataSource {
198
198
  path: string,
199
199
  name: string,
200
200
  value: any,
201
- property: ResolvedProperty,
202
201
  entityId?: string
203
202
  ): Promise<boolean>;
204
203
 
@@ -214,12 +213,177 @@ export interface DataSource {
214
213
 
215
214
  /**
216
215
  * Check if the given filter combination is valid
217
- * @param params
216
+ * @param props
218
217
  */
219
- isFilterCombinationValid?(params: {
220
- path: string,
221
- collection: EntityCollection<any>,
222
- filterValues: FilterValues<any>,
223
- sortBy?: [string, "asc" | "desc"]
224
- }): boolean;
218
+ isFilterCombinationValid?(props: FilterCombinationValidProps): boolean;
219
+ }
220
+
221
+ export type FilterCombinationValidProps = {
222
+ path: string;
223
+ collection: EntityCollection<any>;
224
+ filterValues: FilterValues<any>;
225
+ sortBy?: [string, "asc" | "desc"];
226
+ };
227
+
228
+ export type SaveEntityDelegateProps<M extends Record<string, any> = any> = Omit<SaveEntityProps<M>, "collection">;
229
+
230
+ export type FetchCollectionDelegateProps<M extends Record<string, any> = any> =
231
+ Omit<FetchCollectionProps<M>, "collection">
232
+ & {
233
+ isCollectionGroup?: boolean
234
+ };
235
+
236
+ export type ListenCollectionDelegateProps<M extends Record<string, any> = any> =
237
+ Omit<ListenCollectionProps<M>, "collection">
238
+ & {
239
+ isCollectionGroup?: boolean
240
+ };
241
+
242
+ export interface DataSourceDelegate {
243
+ /**
244
+ * Fetch data from a collection
245
+ * @param path
246
+ * @param filter
247
+ * @param limit
248
+ * @param startAfter
249
+ * @param orderBy
250
+ * @param order
251
+ * @param searchString
252
+ * @return Function to cancel subscription
253
+ * @see useCollectionFetch if you need this functionality implemented as a hook
254
+ */
255
+ fetchCollection<M extends Record<string, any> = any>({
256
+ path,
257
+ filter,
258
+ limit,
259
+ startAfter,
260
+ orderBy,
261
+ order,
262
+ searchString
263
+ }: FetchCollectionDelegateProps<M>): Promise<Entity<M>[]>;
264
+
265
+ /**
266
+ * Listen to a collection in a given path. If you don't implement this method
267
+ * `fetchCollection` will be used instead, with no real time updates.
268
+ * @param path
269
+ * @param onUpdate
270
+ * @param onError
271
+ * @param filter
272
+ * @param limit
273
+ * @param startAfter
274
+ * @param orderBy
275
+ * @param order
276
+ * @param searchString
277
+ * @return Function to cancel subscription
278
+ * @see useCollectionFetch if you need this functionality implemented as a hook
279
+ */
280
+ listenCollection?<M extends Record<string, any> = any>({
281
+ path,
282
+ filter,
283
+ limit,
284
+ startAfter,
285
+ searchString,
286
+ orderBy,
287
+ order,
288
+ onUpdate,
289
+ onError
290
+ }: ListenCollectionDelegateProps<M>): () => void;
291
+
292
+ /**
293
+ * Retrieve an entity given a path and a collection
294
+ * @param path
295
+ * @param entityId
296
+ */
297
+ fetchEntity<M extends Record<string, any> = any>({
298
+ path,
299
+ entityId,
300
+ }: Omit<FetchEntityProps<M>, "collection">): Promise<Entity<M> | undefined>;
301
+
302
+ /**
303
+ * Get realtime updates on one entity.
304
+ * @param path
305
+ * @param entityId
306
+ * @param collection
307
+ * @param onUpdate
308
+ * @param onError
309
+ * @return Function to cancel subscription
310
+ */
311
+ listenEntity?<M extends Record<string, any> = any>({
312
+ path,
313
+ entityId,
314
+ onUpdate,
315
+ onError
316
+ }: Omit<ListenEntityProps<M>, "collection">): () => void;
317
+
318
+ /**
319
+ * Save entity to the specified path
320
+ * @param path
321
+ * @param id
322
+ * @param collection
323
+ * @param status
324
+ */
325
+ saveEntity<M extends Record<string, any> = any>({
326
+ path,
327
+ entityId,
328
+ values,
329
+ status
330
+ }: SaveEntityDelegateProps<M>): Promise<Entity<M>>;
331
+
332
+ /**
333
+ * Delete an entity
334
+ * @param entity
335
+ * @return was the whole deletion flow successful
336
+ */
337
+ deleteEntity<M extends Record<string, any> = any>({ entity }: DeleteEntityProps<M>): Promise<void>;
338
+
339
+ /**
340
+ * Check if the given property is unique in the given collection
341
+ * @param path Collection path
342
+ * @param name of the property
343
+ * @param value
344
+ * @param entityId
345
+ * @return `true` if there are no other fields besides the given entity
346
+ */
347
+ checkUniqueField(path: string, name: string, value: any, entityId?: string): Promise<boolean>;
348
+
349
+ /**
350
+ * Generate an id for a new entity
351
+ */
352
+ generateEntityId(path: string): string;
353
+
354
+ /**
355
+ * Count the number of entities in a collection
356
+ */
357
+ countEntities<M extends Record<string, any> = any>(props: FetchCollectionDelegateProps<M>): Promise<number>;
358
+
359
+ /**
360
+ * Check if the given filter combination is valid
361
+ * @param props
362
+ */
363
+ isFilterCombinationValid?(props: Omit<FilterCombinationValidProps, "collection">): boolean;
364
+
365
+ /**
366
+ * Convert a FireCMS reference to a reference that can be used by the datasource
367
+ * @param reference
368
+ */
369
+ buildReference: (reference: EntityReference) => any,
370
+
371
+ /**
372
+ * Convert a FireCMS GeoPoint to a GeoPoint that can be used by the datasource
373
+ * @param geoPoint
374
+ */
375
+ buildGeoPoint: (geoPoint: GeoPoint) => any,
376
+
377
+ /**
378
+ * Get the object to generate the current time in the datasource
379
+ */
380
+ currentTime(): any;
381
+
382
+ buildDate: (date: Date) => any;
383
+
384
+ buildDeleteFieldValue: () => any;
385
+
386
+ delegateToCMSModel: (data: any) => any;
387
+
388
+ setDateToMidnight: (input?: any) => any;
225
389
  }
@@ -8,7 +8,7 @@ import { ResolvedEntityCollection, ResolvedProperty } from "./resolved_entities"
8
8
  *
9
9
  * @category Form custom fields
10
10
  */
11
- export interface FieldProps<T extends CMSType = CMSType, CustomProps = any, M extends Record<string, any> = any> {
11
+ export interface FieldProps<T extends CMSType = any, CustomProps = any, M extends Record<string, any> = any> {
12
12
 
13
13
  /**
14
14
  * Key of the property
@@ -5,7 +5,7 @@ import { DataSource } from "./datasource";
5
5
  import { EntityCollection, EntityCustomView } from "./collections";
6
6
  import { CMSView } from "./navigation";
7
7
  import { FireCMSContext } from "./firecms_context";
8
- import { FieldConfig } from "./field_config";
8
+ import { PropertyConfig } from "./property_config";
9
9
  import { Locale } from "./locales";
10
10
  import { StorageSource } from "./storage";
11
11
  import { EntityLinkBuilder } from "./entity_link_builder";
@@ -84,9 +84,9 @@ export type FireCMSProps<UserType extends User> = {
84
84
  /**
85
85
  * Record of custom form fields to be used in the CMS.
86
86
  * You can use the key to reference the custom field in
87
- * the `fieldConfig` prop of a property in a collection.
87
+ * the `propertyConfig` prop of a property in a collection.
88
88
  */
89
- fields?: Record<string, FieldConfig>;
89
+ fields?: Record<string, PropertyConfig>;
90
90
 
91
91
  /**
92
92
  * List of additional custom views for entities.
@@ -11,7 +11,7 @@ import { UserConfigurationPersistence } from "./local_config_persistence";
11
11
  import { SideDialogsController } from "./side_dialogs_controller";
12
12
  import { FireCMSPlugin } from "./plugins";
13
13
  import { CMSAnalyticsEvent } from "./analytics";
14
- import { FieldConfig } from "./field_config";
14
+ import { PropertyConfig } from "./property_config";
15
15
  import { EntityCustomView } from "./collections";
16
16
 
17
17
  /**
@@ -96,9 +96,9 @@ export type FireCMSContext<UserType extends User = User, AuthControllerType exte
96
96
  /**
97
97
  * Record of custom form fields to be used in the CMS.
98
98
  * You can use the key to reference the custom field in
99
- * the `fieldConfig` prop of a property in a collection.
99
+ * the `propertyConfig` prop of a property in a collection.
100
100
  */
101
- fields: Record<string, FieldConfig>;
101
+ fields: Record<string, PropertyConfig>;
102
102
 
103
103
  /**
104
104
  * List of additional custom views for entities.
@@ -10,7 +10,7 @@ export * from "./user";
10
10
  export * from "./colors";
11
11
  export * from "./storage";
12
12
  export * from "./fields";
13
- export * from "./field_config";
13
+ export * from "./property_config";
14
14
  export * from "./datasource";
15
15
  export * from "./entity_link_builder";
16
16
  export * from "./side_entity_controller";
@@ -85,7 +85,7 @@ export interface BaseProperty<T extends CMSType, CustomProps = any> {
85
85
  * All the configuration will be taken from the inherited config, and
86
86
  * overwritten by the current property config.
87
87
  */
88
- fieldConfig?: string;
88
+ propertyConfig?: string;
89
89
 
90
90
  /**
91
91
  * Longer description of a field, displayed under a popover
@@ -2,15 +2,14 @@ import React from "react";
2
2
  import { CMSType, PropertyOrBuilder } from "./properties";
3
3
 
4
4
  /**
5
- * This is the configuration object for the field component generated for a
6
- * property.
5
+ * This is the configuration object for a property.
7
6
  * These configs are generated by default for the properties defined in your
8
7
  * collections' configuration, but you can define your own to be used.
9
8
  */
10
- export type FieldConfig<T extends CMSType = any> = {
9
+ export type PropertyConfig<T extends CMSType = any> = {
11
10
 
12
11
  /**
13
- * Key used to identify this field type.
12
+ * Key used to identify this property config.
14
13
  */
15
14
  key: string,
16
15