@rebasepro/types 0.0.1-canary.0
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/LICENSE +21 -0
- package/README.md +174 -0
- package/dist/components/EntityFormActionsProps.d.ts +17 -0
- package/dist/components/EntityFormProps.d.ts +46 -0
- package/dist/components/PropertyPreviewProps.d.ts +50 -0
- package/dist/components/formex.d.ts +40 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/controllers/analytics_controller.d.ts +7 -0
- package/dist/controllers/auth.d.ts +73 -0
- package/dist/controllers/customization_controller.d.ts +50 -0
- package/dist/controllers/datasource.d.ts +179 -0
- package/dist/controllers/dialogs_controller.d.ts +36 -0
- package/dist/controllers/index.d.ts +11 -0
- package/dist/controllers/local_config_persistence.d.ts +20 -0
- package/dist/controllers/navigation.d.ts +262 -0
- package/dist/controllers/side_dialogs_controller.d.ts +67 -0
- package/dist/controllers/side_entity_controller.d.ts +90 -0
- package/dist/controllers/snackbar.d.ts +24 -0
- package/dist/controllers/storage.d.ts +173 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.es.js +113 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +117 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/rebase_context.d.ts +91 -0
- package/dist/types/backend.d.ts +254 -0
- package/dist/types/chips.d.ts +5 -0
- package/dist/types/collections.d.ts +887 -0
- package/dist/types/entities.d.ts +140 -0
- package/dist/types/entity_actions.d.ts +98 -0
- package/dist/types/entity_callbacks.d.ts +173 -0
- package/dist/types/entity_link_builder.d.ts +7 -0
- package/dist/types/entity_overrides.d.ts +5 -0
- package/dist/types/export_import.d.ts +21 -0
- package/dist/types/fields.d.ts +221 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/locales.d.ts +4 -0
- package/dist/types/modify_collections.d.ts +5 -0
- package/dist/types/plugins.d.ts +276 -0
- package/dist/types/properties.d.ts +1103 -0
- package/dist/types/property_config.d.ts +68 -0
- package/dist/types/rebase.d.ts +180 -0
- package/dist/types/relations.d.ts +336 -0
- package/dist/types/user_management_delegate.d.ts +78 -0
- package/dist/types/websockets.d.ts +33 -0
- package/dist/users/index.d.ts +2 -0
- package/dist/users/roles.d.ts +22 -0
- package/dist/users/user.d.ts +42 -0
- package/package.json +137 -0
- package/src/components/EntityFormActionsProps.tsx +18 -0
- package/src/components/EntityFormProps.tsx +52 -0
- package/src/components/PropertyPreviewProps.tsx +61 -0
- package/src/components/formex.tsx +46 -0
- package/src/components/index.ts +3 -0
- package/src/controllers/analytics_controller.tsx +57 -0
- package/src/controllers/auth.tsx +94 -0
- package/src/controllers/customization_controller.tsx +61 -0
- package/src/controllers/datasource.ts +218 -0
- package/src/controllers/dialogs_controller.tsx +37 -0
- package/src/controllers/index.ts +11 -0
- package/src/controllers/local_config_persistence.tsx +22 -0
- package/src/controllers/navigation.ts +317 -0
- package/src/controllers/side_dialogs_controller.tsx +82 -0
- package/src/controllers/side_entity_controller.tsx +104 -0
- package/src/controllers/snackbar.ts +29 -0
- package/src/controllers/storage.ts +196 -0
- package/src/index.ts +5 -0
- package/src/rebase_context.tsx +122 -0
- package/src/types/backend.ts +385 -0
- package/src/types/chips.ts +46 -0
- package/src/types/collections.ts +1013 -0
- package/src/types/entities.ts +207 -0
- package/src/types/entity_actions.tsx +118 -0
- package/src/types/entity_callbacks.ts +217 -0
- package/src/types/entity_link_builder.ts +8 -0
- package/src/types/entity_overrides.tsx +6 -0
- package/src/types/export_import.ts +26 -0
- package/src/types/fields.tsx +298 -0
- package/src/types/index.ts +20 -0
- package/src/types/locales.ts +81 -0
- package/src/types/modify_collections.tsx +6 -0
- package/src/types/plugins.tsx +328 -0
- package/src/types/properties.ts +1270 -0
- package/src/types/property_config.tsx +93 -0
- package/src/types/rebase.tsx +211 -0
- package/src/types/relations.ts +351 -0
- package/src/types/user_management_delegate.ts +98 -0
- package/src/types/websockets.ts +37 -0
- package/src/users/index.ts +2 -0
- package/src/users/roles.ts +33 -0
- package/src/users/user.ts +46 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* New or existing status
|
|
3
|
+
* @group Models
|
|
4
|
+
*/
|
|
5
|
+
export type EntityStatus = "new" | "existing" | "copy";
|
|
6
|
+
/**
|
|
7
|
+
* Representation of an entity fetched from the datasource
|
|
8
|
+
* @group Models
|
|
9
|
+
*/
|
|
10
|
+
export interface Entity<M extends object = object> {
|
|
11
|
+
/**
|
|
12
|
+
* ID of the entity
|
|
13
|
+
*/
|
|
14
|
+
id: string | number;
|
|
15
|
+
/**
|
|
16
|
+
* A string representing the path of the referenced document (relative
|
|
17
|
+
* to the root of the database).
|
|
18
|
+
*/
|
|
19
|
+
path: string;
|
|
20
|
+
/**
|
|
21
|
+
* Current values
|
|
22
|
+
*/
|
|
23
|
+
values: EntityValues<M>;
|
|
24
|
+
/**
|
|
25
|
+
* Which datasource this entity belongs to (e.g., 'postgres', 'firestore').
|
|
26
|
+
* If not specified, the default datasource is assumed.
|
|
27
|
+
*/
|
|
28
|
+
datasource?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Which database within the datasource (e.g., for Firestore multi-database).
|
|
31
|
+
* If not specified, the default database of the datasource is used.
|
|
32
|
+
*/
|
|
33
|
+
databaseId?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* This type represents a record of key value pairs as described in an
|
|
37
|
+
* entity collection.
|
|
38
|
+
* @group Models
|
|
39
|
+
*/
|
|
40
|
+
export type EntityValues<M extends object> = M;
|
|
41
|
+
/**
|
|
42
|
+
* Props for creating an EntityReference
|
|
43
|
+
*/
|
|
44
|
+
export interface EntityReferenceProps {
|
|
45
|
+
/** ID of the entity */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Path of the collection (relative to the root of the database) */
|
|
48
|
+
path: string;
|
|
49
|
+
/** Which datasource (e.g., 'postgres', 'firestore'). Defaults to "(default)" */
|
|
50
|
+
datasource?: string;
|
|
51
|
+
/** Which database within the datasource. Defaults to "(default)" */
|
|
52
|
+
databaseId?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Class used to create a reference to an entity in a different path.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Simple reference (most common case - single datasource, single db)
|
|
59
|
+
* new EntityReference({ id: "123", path: "users" })
|
|
60
|
+
*
|
|
61
|
+
* // Reference to a different datasource (e.g., Firestore)
|
|
62
|
+
* new EntityReference({ id: "123", path: "analytics", datasource: "firestore" })
|
|
63
|
+
*
|
|
64
|
+
* // Reference to a specific database within a datasource
|
|
65
|
+
* new EntityReference({ id: "123", path: "orders", datasource: "postgres", databaseId: "orders_db" })
|
|
66
|
+
*/
|
|
67
|
+
export declare class EntityReference {
|
|
68
|
+
readonly __type = "reference";
|
|
69
|
+
/**
|
|
70
|
+
* ID of the entity
|
|
71
|
+
*/
|
|
72
|
+
readonly id: string;
|
|
73
|
+
/**
|
|
74
|
+
* A string representing the path of the referenced document (relative
|
|
75
|
+
* to the root of the database).
|
|
76
|
+
*/
|
|
77
|
+
readonly path: string;
|
|
78
|
+
/**
|
|
79
|
+
* Which datasource (e.g., 'postgres', 'firestore').
|
|
80
|
+
* Defaults to "(default)" if not specified.
|
|
81
|
+
*/
|
|
82
|
+
readonly datasource?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Which database within the datasource.
|
|
85
|
+
* Defaults to "(default)" if not specified.
|
|
86
|
+
*/
|
|
87
|
+
readonly databaseId?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Create a reference to an entity.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* // Simple reference (most common case)
|
|
93
|
+
* new EntityReference({ id: "123", path: "users" })
|
|
94
|
+
*
|
|
95
|
+
* // With datasource
|
|
96
|
+
* new EntityReference({ id: "123", path: "analytics", datasource: "firestore" })
|
|
97
|
+
*/
|
|
98
|
+
constructor(props: EntityReferenceProps);
|
|
99
|
+
get pathWithId(): string;
|
|
100
|
+
/**
|
|
101
|
+
* Get the full path including datasource and database prefixes if specified.
|
|
102
|
+
* For the common case (single datasource, single db), this just returns pathWithId.
|
|
103
|
+
*/
|
|
104
|
+
get fullPath(): string;
|
|
105
|
+
isEntityReference(): boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Class used to create a reference to an entity in a different path
|
|
109
|
+
*/
|
|
110
|
+
export declare class EntityRelation {
|
|
111
|
+
readonly __type = "relation";
|
|
112
|
+
/**
|
|
113
|
+
* ID of the entity
|
|
114
|
+
*/
|
|
115
|
+
readonly id: string | number;
|
|
116
|
+
/**
|
|
117
|
+
* A string representing the path of the referenced document (relative
|
|
118
|
+
* to the root of the database).
|
|
119
|
+
*/
|
|
120
|
+
readonly path: string;
|
|
121
|
+
constructor(id: string | number, path: string);
|
|
122
|
+
get pathWithId(): string;
|
|
123
|
+
isEntityReference(): boolean;
|
|
124
|
+
isEntityRelation(): boolean;
|
|
125
|
+
}
|
|
126
|
+
export declare class GeoPoint {
|
|
127
|
+
/**
|
|
128
|
+
* The latitude of this GeoPoint instance.
|
|
129
|
+
*/
|
|
130
|
+
readonly latitude: number;
|
|
131
|
+
/**
|
|
132
|
+
* The longitude of this GeoPoint instance.
|
|
133
|
+
*/
|
|
134
|
+
readonly longitude: number;
|
|
135
|
+
constructor(latitude: number, longitude: number);
|
|
136
|
+
}
|
|
137
|
+
export declare class Vector {
|
|
138
|
+
readonly value: number[];
|
|
139
|
+
constructor(value: number[]);
|
|
140
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Entity } from "./entities";
|
|
3
|
+
import { EntityCollection, SelectionController } from "./collections";
|
|
4
|
+
import { FormContext } from "./fields";
|
|
5
|
+
import { User } from "../users";
|
|
6
|
+
import { RebaseContext } from "../rebase_context";
|
|
7
|
+
import { SideEntityController } from "../controllers";
|
|
8
|
+
/**
|
|
9
|
+
* An entity action is a custom action that can be performed on an entity.
|
|
10
|
+
* They are displayed in the entity view and in the collection view.
|
|
11
|
+
*/
|
|
12
|
+
export type EntityAction<M extends object = any, USER extends User = User> = {
|
|
13
|
+
/**
|
|
14
|
+
* Title of the action
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* Key of the action. You only need to provide this if you want to
|
|
19
|
+
* override the default actions, or if you are not passing the action
|
|
20
|
+
* directly to the `entityActions` prop of a collection.
|
|
21
|
+
* You can define your actions at the app level, in which case you
|
|
22
|
+
* must provide a key.
|
|
23
|
+
* The default actions are:
|
|
24
|
+
* - edit
|
|
25
|
+
* - delete
|
|
26
|
+
* - copy
|
|
27
|
+
*/
|
|
28
|
+
key?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Icon of the action
|
|
31
|
+
*/
|
|
32
|
+
icon?: React.ReactElement;
|
|
33
|
+
/**
|
|
34
|
+
* Callback when the action is clicked
|
|
35
|
+
* @param props
|
|
36
|
+
*/
|
|
37
|
+
onClick: (props: EntityActionClickProps<M, USER>) => Promise<void> | void;
|
|
38
|
+
/**
|
|
39
|
+
* Optional callback in case you want to disable the action
|
|
40
|
+
* @param props
|
|
41
|
+
*/
|
|
42
|
+
isEnabled?: (props: EntityActionClickProps<M, USER>) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Show this action collapsed in the menu of the collection view.
|
|
45
|
+
* Defaults to true
|
|
46
|
+
* If false, the action will be shown in the menu
|
|
47
|
+
*/
|
|
48
|
+
collapsed?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Show this action in the form, defaults to true
|
|
51
|
+
*/
|
|
52
|
+
includeInForm?: boolean;
|
|
53
|
+
};
|
|
54
|
+
export type EntityActionClickProps<M extends object, USER extends User = User> = {
|
|
55
|
+
entity?: Entity<M>;
|
|
56
|
+
context: RebaseContext<USER>;
|
|
57
|
+
path?: string;
|
|
58
|
+
collection?: EntityCollection<M>;
|
|
59
|
+
/**
|
|
60
|
+
* Optional form context, present if the action is being called from a form.
|
|
61
|
+
* This allows you to access the form state and methods, including modifying the form values.
|
|
62
|
+
*/
|
|
63
|
+
formContext?: FormContext;
|
|
64
|
+
/**
|
|
65
|
+
* Present if this actions is being called from a side dialog only
|
|
66
|
+
*/
|
|
67
|
+
sideEntityController?: SideEntityController;
|
|
68
|
+
/**
|
|
69
|
+
* Is the action being called from the collection view or from the entity form view?
|
|
70
|
+
*/
|
|
71
|
+
view: "collection" | "form";
|
|
72
|
+
/**
|
|
73
|
+
* If the action is rendered in the form, is it open in a side panel or full screen?
|
|
74
|
+
*/
|
|
75
|
+
openEntityMode: "side_panel" | "full_screen";
|
|
76
|
+
/**
|
|
77
|
+
* Optional selection controller, present if the action is being called from a collection view
|
|
78
|
+
*/
|
|
79
|
+
selectionController?: SelectionController;
|
|
80
|
+
/**
|
|
81
|
+
* Optional highlight function to highlight the entity in the collection view
|
|
82
|
+
* @param entity
|
|
83
|
+
*/
|
|
84
|
+
highlightEntity?: (entity: Entity<Record<string, unknown>>) => void;
|
|
85
|
+
/**
|
|
86
|
+
* Optional unhighlight function to remove the highlight from the entity in the collection view
|
|
87
|
+
* @param entity
|
|
88
|
+
*/
|
|
89
|
+
unhighlightEntity?: (entity: Entity<Record<string, unknown>>) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Optional function to navigate back (e.g. when deleting an entity or navigating from a form)
|
|
92
|
+
*/
|
|
93
|
+
navigateBack?: () => void;
|
|
94
|
+
/**
|
|
95
|
+
* Callback to be called when the collection changes, e.g. after an entity is deleted or created.
|
|
96
|
+
*/
|
|
97
|
+
onCollectionChange?: () => void;
|
|
98
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { EntityCollection } from "./collections";
|
|
2
|
+
import { Entity, EntityStatus, EntityValues } from "./entities";
|
|
3
|
+
import { User } from "../users";
|
|
4
|
+
import { RebaseCallContext } from "../rebase_context";
|
|
5
|
+
/**
|
|
6
|
+
* This interface defines all the callbacks that can be used when an entity
|
|
7
|
+
* is being created, updated or deleted.
|
|
8
|
+
* Useful for adding your own logic or blocking the execution of the operation.
|
|
9
|
+
* @group Models
|
|
10
|
+
*/
|
|
11
|
+
export type EntityCallbacks<M extends Record<string, any> = any, USER extends User = User> = {
|
|
12
|
+
/**
|
|
13
|
+
* Callback used after fetching data
|
|
14
|
+
* @param props
|
|
15
|
+
*/
|
|
16
|
+
afterRead?(props: EntityAfterReadProps<M, USER>): Promise<Entity<M>> | Entity<M>;
|
|
17
|
+
/**
|
|
18
|
+
* Callback used before saving, you need to return the values that will get
|
|
19
|
+
* saved. If you throw an error in this method the process stops, and an
|
|
20
|
+
* error snackbar gets displayed.
|
|
21
|
+
* This runs after schema validation.
|
|
22
|
+
* @param props
|
|
23
|
+
*/
|
|
24
|
+
beforeSave?(props: EntityBeforeSaveProps<M, USER>): Promise<Partial<EntityValues<M>>> | Partial<EntityValues<M>>;
|
|
25
|
+
/**
|
|
26
|
+
* Callback used when save is successful
|
|
27
|
+
* @param props
|
|
28
|
+
*/
|
|
29
|
+
afterSave?(props: EntityAfterSaveProps<M, USER>): Promise<void> | void;
|
|
30
|
+
/**
|
|
31
|
+
* Callback used when saving fails
|
|
32
|
+
* @param props
|
|
33
|
+
*/
|
|
34
|
+
afterSaveError?(props: EntityAfterSaveErrorProps<M, USER>): Promise<void> | void;
|
|
35
|
+
/**
|
|
36
|
+
* Callback used before the entity is deleted.
|
|
37
|
+
* If you throw an error in this method the process stops, and an
|
|
38
|
+
* error snackbar gets displayed.
|
|
39
|
+
*
|
|
40
|
+
* @param props
|
|
41
|
+
*/
|
|
42
|
+
beforeDelete?(props: EntityBeforeDeleteProps<M, USER>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Callback used after the entity is deleted.
|
|
45
|
+
*
|
|
46
|
+
* @param props
|
|
47
|
+
*/
|
|
48
|
+
afterDelete?(props: EntityAfterDeleteProps<M, USER>): void;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Parameters passed to hooks when an entity is fetched
|
|
52
|
+
* @group Models
|
|
53
|
+
*/
|
|
54
|
+
export interface EntityAfterReadProps<M extends Record<string, any> = any, USER extends User = User> {
|
|
55
|
+
/**
|
|
56
|
+
* Collection of the entity
|
|
57
|
+
*/
|
|
58
|
+
collection: EntityCollection<M, USER>;
|
|
59
|
+
/**
|
|
60
|
+
* Full path of the CMS where this collection is being fetched.
|
|
61
|
+
* Might contain unresolved aliases.
|
|
62
|
+
*/
|
|
63
|
+
path: string;
|
|
64
|
+
/**
|
|
65
|
+
* Fetched entity
|
|
66
|
+
*/
|
|
67
|
+
entity: Entity<M>;
|
|
68
|
+
/**
|
|
69
|
+
* Context of the app status
|
|
70
|
+
*/
|
|
71
|
+
context: RebaseCallContext<USER>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Parameters passed to hooks before an entity is saved
|
|
75
|
+
* @group Models
|
|
76
|
+
*/
|
|
77
|
+
export type EntityBeforeSaveProps<M extends Record<string, any> = any, USER extends User = User> = Omit<EntityAfterSaveProps<M, USER>, "entityId"> & {
|
|
78
|
+
entityId?: string | number;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Parameters passed to hooks before an entity is saved
|
|
82
|
+
* @group Models
|
|
83
|
+
*/
|
|
84
|
+
export type EntityAfterSaveErrorProps<M extends Record<string, any> = any, USER extends User = User> = Omit<EntityAfterSaveProps<M, USER>, "entityId"> & {
|
|
85
|
+
entityId?: string | number;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Parameters passed to hooks when an entity is saved
|
|
89
|
+
* @group Models
|
|
90
|
+
*/
|
|
91
|
+
export interface EntityAfterSaveProps<M extends Record<string, any> = any, USER extends User = User> {
|
|
92
|
+
/**
|
|
93
|
+
* Resolved collection of the entity
|
|
94
|
+
*/
|
|
95
|
+
collection: EntityCollection<M>;
|
|
96
|
+
/**
|
|
97
|
+
* Full path of the CMS where this entity is being saved.
|
|
98
|
+
* Might contain unresolved aliases.
|
|
99
|
+
*/
|
|
100
|
+
path: string;
|
|
101
|
+
/**
|
|
102
|
+
* ID of the entity
|
|
103
|
+
*/
|
|
104
|
+
entityId: string | number;
|
|
105
|
+
/**
|
|
106
|
+
* Values being saved
|
|
107
|
+
*/
|
|
108
|
+
values: Partial<EntityValues<M>>;
|
|
109
|
+
/**
|
|
110
|
+
* Previous values
|
|
111
|
+
*/
|
|
112
|
+
previousValues?: Partial<EntityValues<M>>;
|
|
113
|
+
/**
|
|
114
|
+
* New or existing entity
|
|
115
|
+
*/
|
|
116
|
+
status: EntityStatus;
|
|
117
|
+
/**
|
|
118
|
+
* Context of the app status
|
|
119
|
+
*/
|
|
120
|
+
context: RebaseCallContext<USER>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Parameters passed to hooks when an entity is deleted
|
|
124
|
+
* @group Models
|
|
125
|
+
*/
|
|
126
|
+
export interface EntityBeforeDeleteProps<M extends Record<string, any> = any, USER extends User = User> {
|
|
127
|
+
/**
|
|
128
|
+
* collection of the entity being deleted
|
|
129
|
+
*/
|
|
130
|
+
collection: EntityCollection<M>;
|
|
131
|
+
/**
|
|
132
|
+
* Path of the parent collection
|
|
133
|
+
*/
|
|
134
|
+
path: string;
|
|
135
|
+
/**
|
|
136
|
+
* Deleted entity id
|
|
137
|
+
*/
|
|
138
|
+
entityId: string | number;
|
|
139
|
+
/**
|
|
140
|
+
* Deleted entity
|
|
141
|
+
*/
|
|
142
|
+
entity: Entity<M>;
|
|
143
|
+
/**
|
|
144
|
+
* Context of the app status
|
|
145
|
+
*/
|
|
146
|
+
context: RebaseCallContext<USER>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Parameters passed to hooks after an entity is deleted
|
|
150
|
+
* @group Models
|
|
151
|
+
*/
|
|
152
|
+
export interface EntityAfterDeleteProps<M extends Record<string, any> = any, USER extends User = User> {
|
|
153
|
+
/**
|
|
154
|
+
* collection of the entity being deleted
|
|
155
|
+
*/
|
|
156
|
+
collection: EntityCollection<M>;
|
|
157
|
+
/**
|
|
158
|
+
* Path of the parent collection
|
|
159
|
+
*/
|
|
160
|
+
path: string;
|
|
161
|
+
/**
|
|
162
|
+
* Deleted entity id
|
|
163
|
+
*/
|
|
164
|
+
entityId: string | number;
|
|
165
|
+
/**
|
|
166
|
+
* Deleted entity
|
|
167
|
+
*/
|
|
168
|
+
entity: Entity<M>;
|
|
169
|
+
/**
|
|
170
|
+
* Context of the app status
|
|
171
|
+
*/
|
|
172
|
+
context: RebaseCallContext<USER>;
|
|
173
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Entity } from "./entities";
|
|
2
|
+
import { User } from "../users";
|
|
3
|
+
import { RebaseContext } from "../rebase_context";
|
|
4
|
+
/**
|
|
5
|
+
* You can use this configuration to add additional fields to the data
|
|
6
|
+
* exports
|
|
7
|
+
* @group Models
|
|
8
|
+
*/
|
|
9
|
+
export interface ExportConfig<USER extends User = User> {
|
|
10
|
+
additionalFields: ExportMappingFunction<USER>[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @group Models
|
|
14
|
+
*/
|
|
15
|
+
export interface ExportMappingFunction<USER extends User = User> {
|
|
16
|
+
key: string;
|
|
17
|
+
builder: ({ entity, context }: {
|
|
18
|
+
entity: Entity<any>;
|
|
19
|
+
context: RebaseContext<USER>;
|
|
20
|
+
}) => Promise<string> | string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { InferPropertyType, Property } from "./properties";
|
|
2
|
+
import { Entity } from "./entities";
|
|
3
|
+
import { FormexController } from "../components/formex";
|
|
4
|
+
import { EntityCollection } from "./collections";
|
|
5
|
+
export type DefaultFieldConfig = "text_field" | "multiline" | "markdown" | "url" | "email" | "switch" | "select" | "multi_select" | "user_select" | "number_input" | "number_select" | "multi_number_select" | "file_upload" | "multi_file_upload" | "reference_as_string" | "reference" | "multi_references" | "relation" | "date_time" | "group" | "key_value" | "repeat" | "custom_array" | "block";
|
|
6
|
+
/**
|
|
7
|
+
* When building a custom field you need to create a React component that takes
|
|
8
|
+
* this interface as props.
|
|
9
|
+
*
|
|
10
|
+
* @group Form custom fields
|
|
11
|
+
*/
|
|
12
|
+
export interface FieldProps<P extends Property = Property, CustomProps = any, M extends Record<string, any> = any> {
|
|
13
|
+
/**
|
|
14
|
+
* Key of the property
|
|
15
|
+
* E.g. "user.name" for a property with path "user.name"
|
|
16
|
+
*/
|
|
17
|
+
propertyKey: string;
|
|
18
|
+
/**
|
|
19
|
+
* Current value of this field, inferred from the property type P
|
|
20
|
+
*/
|
|
21
|
+
value: InferPropertyType<P>;
|
|
22
|
+
/**
|
|
23
|
+
* Set value of field directly
|
|
24
|
+
*/
|
|
25
|
+
setValue: (value: InferPropertyType<P> | null, shouldValidate?: boolean) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Set value of a different field directly
|
|
28
|
+
* @param propertyKey
|
|
29
|
+
* @param value
|
|
30
|
+
* @param shouldValidate
|
|
31
|
+
*/
|
|
32
|
+
setFieldValue: (propertyKey: string, value: unknown, shouldValidate?: boolean) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Is the form currently submitting
|
|
35
|
+
*/
|
|
36
|
+
isSubmitting?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Should this field show the error indicator.
|
|
39
|
+
* Note that there might be an error (like an empty field that should be
|
|
40
|
+
* filled) but we don't want to show the error until the user has tried
|
|
41
|
+
* saving.
|
|
42
|
+
*/
|
|
43
|
+
showError?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Is there an error in this field. The error field has the same shape as
|
|
46
|
+
* the field, replacing values with a string containing the error.
|
|
47
|
+
* It takes the value `null` if there is no error
|
|
48
|
+
*/
|
|
49
|
+
error?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Has this field been touched
|
|
52
|
+
*/
|
|
53
|
+
touched?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Property related to this field, now strongly typed to P
|
|
56
|
+
*/
|
|
57
|
+
property: P;
|
|
58
|
+
/**
|
|
59
|
+
* Should this field include a description
|
|
60
|
+
*/
|
|
61
|
+
includeDescription?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Flag to indicate that the underlying value has been updated in the
|
|
64
|
+
* datasource
|
|
65
|
+
*/
|
|
66
|
+
underlyingValueHasChanged?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Is this field part of an array
|
|
69
|
+
*/
|
|
70
|
+
partOfArray?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Is this field part of a block
|
|
73
|
+
*/
|
|
74
|
+
partOfBlock?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Display the child properties directly, without being wrapped in an
|
|
77
|
+
* extendable panel. Note that this will also hide the title of this property.
|
|
78
|
+
*/
|
|
79
|
+
minimalistView?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Should this field autofocus on mount
|
|
82
|
+
*/
|
|
83
|
+
autoFocus?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Additional properties set by the developer
|
|
86
|
+
*/
|
|
87
|
+
customProps: CustomProps;
|
|
88
|
+
/**
|
|
89
|
+
* Additional values related to the state of the form or the entity
|
|
90
|
+
*/
|
|
91
|
+
context: FormContext<M>;
|
|
92
|
+
/**
|
|
93
|
+
* Flag to indicate if this field should be disabled
|
|
94
|
+
*/
|
|
95
|
+
disabled?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Size of the field
|
|
98
|
+
*/
|
|
99
|
+
size?: "small" | "medium" | "large";
|
|
100
|
+
/**
|
|
101
|
+
* Some properties might change internal state (like expanding a panel).
|
|
102
|
+
* This function should be called when the internal state changes.
|
|
103
|
+
* This is used to preserve state in array containers.
|
|
104
|
+
*
|
|
105
|
+
* @param property
|
|
106
|
+
*/
|
|
107
|
+
onPropertyChange?: (property: Partial<Property>) => void;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Context passed to custom fields
|
|
111
|
+
* @group Form custom fields
|
|
112
|
+
*/
|
|
113
|
+
export interface FormContext<M extends Record<string, any> = any> {
|
|
114
|
+
/**
|
|
115
|
+
* Current values of the entity
|
|
116
|
+
*/
|
|
117
|
+
values: M;
|
|
118
|
+
/**
|
|
119
|
+
* Update the value of a field
|
|
120
|
+
* @param key
|
|
121
|
+
* @param value
|
|
122
|
+
* @param shouldValidate
|
|
123
|
+
*/
|
|
124
|
+
setFieldValue: (key: string, value: unknown, shouldValidate?: boolean) => void;
|
|
125
|
+
/**
|
|
126
|
+
* Save the entity.
|
|
127
|
+
*/
|
|
128
|
+
save: (values: M) => void;
|
|
129
|
+
/**
|
|
130
|
+
* Collection of the entity being modified
|
|
131
|
+
*/
|
|
132
|
+
collection?: EntityCollection<M>;
|
|
133
|
+
/**
|
|
134
|
+
* Entity id, it can be undefined if it's a new entity
|
|
135
|
+
*/
|
|
136
|
+
entityId?: string | number;
|
|
137
|
+
/**
|
|
138
|
+
* Path this entity is located at
|
|
139
|
+
*/
|
|
140
|
+
path?: string;
|
|
141
|
+
status: "new" | "existing" | "copy";
|
|
142
|
+
entity?: Entity<M>;
|
|
143
|
+
savingError?: Error;
|
|
144
|
+
openEntityMode: "side_panel" | "full_screen";
|
|
145
|
+
/**
|
|
146
|
+
* This is the underlying formex controller that powers the form.
|
|
147
|
+
* If you are in a red only mode, the formex controller is there, but you can't
|
|
148
|
+
* operate with it
|
|
149
|
+
*/
|
|
150
|
+
formex: FormexController<M>;
|
|
151
|
+
disabled: boolean;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* In case you need to render a field bound to a Property inside your
|
|
155
|
+
* custom field you can use {@link PropertyFieldBinding} with these props.
|
|
156
|
+
* @group Form custom fields
|
|
157
|
+
*/
|
|
158
|
+
export interface PropertyFieldBindingProps<M extends Record<string, any> = any> {
|
|
159
|
+
/**
|
|
160
|
+
* The key/path of the property, such as `age`. You can use nested and array
|
|
161
|
+
* indexed such as `address.street` or `people[3]`
|
|
162
|
+
*/
|
|
163
|
+
propertyKey: string;
|
|
164
|
+
/**
|
|
165
|
+
* The CMS property you are binding this field to
|
|
166
|
+
*/
|
|
167
|
+
property: Property;
|
|
168
|
+
/**
|
|
169
|
+
* The context where this field is being rendered. You get a context as a
|
|
170
|
+
* prop when creating a custom field.
|
|
171
|
+
*/
|
|
172
|
+
context: FormContext<M>;
|
|
173
|
+
/**
|
|
174
|
+
* Should the description be included in this field
|
|
175
|
+
*/
|
|
176
|
+
includeDescription?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Has the value of this property been updated in the database while this
|
|
179
|
+
* field is being edited
|
|
180
|
+
*/
|
|
181
|
+
underlyingValueHasChanged?: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Is this field part of an array
|
|
184
|
+
*/
|
|
185
|
+
partOfArray?: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Is this field part of a block
|
|
188
|
+
*/
|
|
189
|
+
partOfBlock?: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Display the child properties directly, without being wrapped in an
|
|
192
|
+
* extendable panel. Note that this will also hide the title of this property.
|
|
193
|
+
*/
|
|
194
|
+
minimalistView?: boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Should the field take focus when rendered. When opening the popup view
|
|
197
|
+
* in table mode, it makes sense to put the focus on the only field rendered.
|
|
198
|
+
*/
|
|
199
|
+
autoFocus?: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Should this field be disabled
|
|
202
|
+
*/
|
|
203
|
+
disabled?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Index of the field in the array.
|
|
206
|
+
* Only used when the field is part of an array.
|
|
207
|
+
*/
|
|
208
|
+
index?: number;
|
|
209
|
+
/**
|
|
210
|
+
* The size of the field
|
|
211
|
+
*/
|
|
212
|
+
size?: "small" | "medium" | "large";
|
|
213
|
+
/**
|
|
214
|
+
* Some properties might change internal state (like expanding a panel).
|
|
215
|
+
* This function should be called when the internal state changes.
|
|
216
|
+
* This is used to preserve state in array containers.
|
|
217
|
+
*
|
|
218
|
+
* @param property
|
|
219
|
+
*/
|
|
220
|
+
onPropertyChange?: (property: Partial<Property>) => void;
|
|
221
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from "./entities";
|
|
2
|
+
export * from "./chips";
|
|
3
|
+
export * from "./entity_actions";
|
|
4
|
+
export * from "./properties";
|
|
5
|
+
export * from "./collections";
|
|
6
|
+
export * from "./relations";
|
|
7
|
+
export * from "./locales";
|
|
8
|
+
export * from "./fields";
|
|
9
|
+
export * from "./property_config";
|
|
10
|
+
export * from "./entity_link_builder";
|
|
11
|
+
export * from "./user_management_delegate";
|
|
12
|
+
export * from "./entity_callbacks";
|
|
13
|
+
export * from "./entity_overrides";
|
|
14
|
+
export * from "./plugins";
|
|
15
|
+
export * from "./rebase";
|
|
16
|
+
export * from "./export_import";
|
|
17
|
+
export * from "./modify_collections";
|
|
18
|
+
export * from "./websockets";
|
|
19
|
+
export * from "./backend";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @group Models
|
|
3
|
+
*/
|
|
4
|
+
export type Locale = "af" | "ar" | "arDZ" | "arMA" | "arSA" | "az" | "be" | "bg" | "bn" | "ca" | "cs" | "cy" | "da" | "de" | "el" | "enAU" | "enCA" | "enGB" | "enIN" | "enNZ" | "enUS" | "eo" | "es" | "et" | "eu" | "faIR" | "fi" | "fil" | "fr" | "frCA" | "frCH" | "gd" | "gl" | "gu" | "he" | "hi" | "hr" | "hu" | "hy" | "id" | "is" | "it" | "ja" | "ka" | "kk" | "kn" | "ko" | "lb" | "lt" | "lv" | "mk" | "ms" | "mt" | "nb" | "nl" | "nlBE" | "nn" | "pl" | "pt" | "ptBR" | "ro" | "ru" | "sk" | "sl" | "sr" | "srLatn" | "sv" | "ta" | "te" | "th" | "tr" | "ug" | "uk" | "uz" | "vi" | "zhCN" | "zhTW";
|