@rebasepro/admin-types 0.10.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/dist/admin_collection.d.ts +464 -0
- package/dist/augment.d.ts +66 -0
- package/dist/collections.d.ts +226 -0
- package/dist/controllers/analytics_controller.d.ts +7 -0
- package/dist/controllers/auth.d.ts +110 -0
- package/dist/controllers/customization_controller.d.ts +61 -0
- package/dist/controllers/dialogs_controller.d.ts +36 -0
- package/dist/controllers/index.d.ts +10 -0
- package/dist/controllers/local_config_persistence.d.ts +20 -0
- package/dist/controllers/navigation.d.ts +225 -0
- package/dist/controllers/registry.d.ts +80 -0
- package/dist/controllers/side_dialogs_controller.d.ts +67 -0
- package/dist/controllers/side_panel_controller.d.ts +97 -0
- package/dist/controllers/snackbar.d.ts +24 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.es.js +92 -0
- package/dist/index.es.js.map +1 -0
- package/dist/react_component_ref.d.ts +43 -0
- package/dist/rebase_context.d.ts +68 -0
- package/dist/types/breadcrumbs.d.ts +26 -0
- package/dist/types/builders.d.ts +15 -0
- package/dist/types/component_overrides.d.ts +196 -0
- package/dist/types/entity_actions.d.ts +105 -0
- package/dist/types/entity_link_builder.d.ts +7 -0
- package/dist/types/entity_views.d.ts +95 -0
- package/dist/types/export_import.d.ts +21 -0
- package/dist/types/formex.d.ts +40 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/locales.d.ts +4 -0
- package/dist/types/modify_collections.d.ts +5 -0
- package/dist/types/plugins.d.ts +277 -0
- package/dist/types/property_config.d.ts +74 -0
- package/dist/types/property_options.d.ts +154 -0
- package/dist/types/slots.d.ts +263 -0
- package/dist/types/translations.d.ts +915 -0
- package/dist/types/user_management_delegate.d.ts +22 -0
- package/package.json +103 -0
- package/src/admin_collection.ts +582 -0
- package/src/augment.ts +60 -0
- package/src/collections.ts +256 -0
- package/src/controllers/analytics_controller.tsx +57 -0
- package/src/controllers/auth.ts +121 -0
- package/src/controllers/customization_controller.tsx +72 -0
- package/src/controllers/dialogs_controller.tsx +37 -0
- package/src/controllers/index.ts +10 -0
- package/src/controllers/local_config_persistence.tsx +22 -0
- package/src/controllers/navigation.ts +264 -0
- package/src/controllers/registry.ts +96 -0
- package/src/controllers/side_dialogs_controller.tsx +82 -0
- package/src/controllers/side_panel_controller.tsx +112 -0
- package/src/controllers/snackbar.ts +29 -0
- package/src/index.ts +20 -0
- package/src/react_component_ref.ts +52 -0
- package/src/rebase_context.ts +81 -0
- package/src/types/breadcrumbs.ts +27 -0
- package/src/types/builders.ts +18 -0
- package/src/types/component_overrides.ts +244 -0
- package/src/types/entity_actions.tsx +127 -0
- package/src/types/entity_link_builder.ts +8 -0
- package/src/types/entity_views.tsx +114 -0
- package/src/types/export_import.ts +26 -0
- package/src/types/formex.ts +45 -0
- package/src/types/index.ts +15 -0
- package/src/types/locales.ts +81 -0
- package/src/types/modify_collections.tsx +6 -0
- package/src/types/plugins.tsx +346 -0
- package/src/types/property_config.tsx +95 -0
- package/src/types/property_options.ts +169 -0
- package/src/types/slots.tsx +309 -0
- package/src/types/translations.ts +1026 -0
- package/src/types/user_management_delegate.ts +23 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { EntityReference } from "@rebasepro/types";
|
|
3
|
+
import type { AdminCollection } from "@rebasepro/admin-types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Controller that handles URL path building and resolution.
|
|
7
|
+
* @group Models
|
|
8
|
+
*/
|
|
9
|
+
export type UrlController = {
|
|
10
|
+
/**
|
|
11
|
+
* Default path under the navigation routes of the CMS will be created.
|
|
12
|
+
* Defaults to '/'. You may want to change this `basepath` to 'admin' for example.
|
|
13
|
+
*/
|
|
14
|
+
basePath: string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Default path under the collection routes of the CMS will be created.
|
|
18
|
+
* It defaults to '/c'
|
|
19
|
+
*/
|
|
20
|
+
baseCollectionPath: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Convert a URL path to a collection or entity path
|
|
24
|
+
* `/c/products` => `products`
|
|
25
|
+
* `/my_cms/c/products/B34SAP8Z` => `products/B34SAP8Z`
|
|
26
|
+
* `/my_cms/my_view` => `my_view`
|
|
27
|
+
* @param cmsPath
|
|
28
|
+
*/
|
|
29
|
+
urlPathToDataPath: (cmsPath: string) => string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Base url path for the home screen
|
|
33
|
+
*/
|
|
34
|
+
homeUrl: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Check if a url path belongs to a collection
|
|
38
|
+
* @param path
|
|
39
|
+
*/
|
|
40
|
+
isUrlCollectionPath: (urlPath: string) => boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Build a URL collection path from a data path
|
|
44
|
+
* `products` => `/c/products`
|
|
45
|
+
* `products/B34SAP8Z` => `/c/products/B34SAP8Z`
|
|
46
|
+
* @param path
|
|
47
|
+
*/
|
|
48
|
+
buildUrlCollectionPath: (path: string) => string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Build a URL path for the CMS (e.g. for custom views)
|
|
52
|
+
* @param path
|
|
53
|
+
*/
|
|
54
|
+
buildAppUrlPath: (path: string) => string;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Turn a path with collection ids into a resolved path.
|
|
58
|
+
* The ids (typically used in urls) will be replaced with relative paths (typically used in database paths)
|
|
59
|
+
* @param path
|
|
60
|
+
*/
|
|
61
|
+
resolveDatabasePathsFrom: (path: string) => string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A function to navigate to a specified route or URL.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} to - The target route or URL to navigate to.
|
|
67
|
+
* @param {NavigateOptions} [options] - Optional configuration settings for navigation, such as replace behavior or state data.
|
|
68
|
+
*/
|
|
69
|
+
navigate: (to: string, options?: NavigateOptions) => void;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Controller that manages the state of the navigation menu,
|
|
74
|
+
* including resolved views and top-level grouping.
|
|
75
|
+
* @group Models
|
|
76
|
+
*/
|
|
77
|
+
export type NavigationStateController = {
|
|
78
|
+
/**
|
|
79
|
+
* Custom additional views created by the developer, added to the main
|
|
80
|
+
* navigation
|
|
81
|
+
*/
|
|
82
|
+
views?: AppView[];
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Custom additional views created by the developer, added to the admin
|
|
86
|
+
* navigation
|
|
87
|
+
*/
|
|
88
|
+
adminViews?: AppView[];
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Configuration for the views that should be displayed at the top
|
|
92
|
+
* level of the navigation (e.g. in the home page or the navigation
|
|
93
|
+
* drawer)
|
|
94
|
+
*/
|
|
95
|
+
topLevelNavigation?: NavigationResult;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Is the navigation loading (the configuration persistence has not
|
|
99
|
+
* loaded yet, or a specified navigation builder has not completed)
|
|
100
|
+
*/
|
|
101
|
+
loading: boolean;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Was there an error while loading the navigation data
|
|
105
|
+
*/
|
|
106
|
+
navigationLoadingError?: Error;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Call this method to recalculate the navigation
|
|
110
|
+
*/
|
|
111
|
+
refreshNavigation: () => void;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export interface NavigateOptions {
|
|
115
|
+
replace?: boolean;
|
|
116
|
+
state?: unknown;
|
|
117
|
+
preventScrollReset?: boolean;
|
|
118
|
+
relative?: "route" | "path";
|
|
119
|
+
flushSync?: boolean;
|
|
120
|
+
viewTransition?: boolean;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Custom additional views created by the developer, added to the main
|
|
125
|
+
* navigation.
|
|
126
|
+
* @group Models
|
|
127
|
+
*/
|
|
128
|
+
export interface AppView {
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* CMS Path you can reach this view from.
|
|
132
|
+
*/
|
|
133
|
+
slug: string;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Name of this view
|
|
137
|
+
*/
|
|
138
|
+
name: string;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Optional description of this view. You can use Markdown
|
|
142
|
+
*/
|
|
143
|
+
description?: string;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Icon key to use in this view.
|
|
147
|
+
* You can use any of the icons in the Lucide specs:
|
|
148
|
+
* https://lucide.dev/icons/
|
|
149
|
+
* e.g. 'ShoppingCart' or 'User'
|
|
150
|
+
* Find all the icons in https://rebase.pro/docs/icons
|
|
151
|
+
*/
|
|
152
|
+
icon?: string | React.ReactNode;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Should this view be hidden from the main navigation panel.
|
|
156
|
+
* It will still be accessible if you reach the specified path
|
|
157
|
+
*/
|
|
158
|
+
hideFromNavigation?: boolean;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Navigation group for this view.
|
|
162
|
+
* Views sharing the same group name will be visually grouped
|
|
163
|
+
* together in the drawer and home page. If not set, the view
|
|
164
|
+
* falls into the default "Views" group.
|
|
165
|
+
*/
|
|
166
|
+
group?: string;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Component to be rendered. This can be any React component, and can use
|
|
170
|
+
* any of the provided hooks.
|
|
171
|
+
*
|
|
172
|
+
* Pass a `ComponentType` to enable lazy rendering — the component will
|
|
173
|
+
* only be instantiated when the route is visited. This is recommended
|
|
174
|
+
* for dynamic views generated from database data.
|
|
175
|
+
*/
|
|
176
|
+
view: React.ReactNode | React.ComponentType;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* If true, a wildcard route (slug/*) is automatically registered
|
|
180
|
+
* alongside the base route, enabling nested navigation within this view.
|
|
181
|
+
*/
|
|
182
|
+
nestedRoutes?: boolean;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Restrict this view to users with at least one of the listed roles.
|
|
186
|
+
* When omitted or empty, the view is visible to all authenticated users.
|
|
187
|
+
* Applied during view resolution — the view is filtered out entirely
|
|
188
|
+
* (not just hidden from nav) if the user lacks a matching role.
|
|
189
|
+
*/
|
|
190
|
+
roles?: string[];
|
|
191
|
+
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* A composable section that can be rendered on the home page.
|
|
196
|
+
* Use this to add custom content alongside the auto-generated
|
|
197
|
+
* navigation groups.
|
|
198
|
+
* @group Models
|
|
199
|
+
*/
|
|
200
|
+
export interface HomePageSection {
|
|
201
|
+
/**
|
|
202
|
+
* Unique key for this section.
|
|
203
|
+
*/
|
|
204
|
+
key: string;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Title displayed as the section header.
|
|
208
|
+
*/
|
|
209
|
+
title: string;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Arbitrary React content rendered inside the section.
|
|
213
|
+
*/
|
|
214
|
+
children: React.ReactNode;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Used to group navigation entries in the main navigation.
|
|
219
|
+
*/
|
|
220
|
+
export interface NavigationGroupMapping {
|
|
221
|
+
/**
|
|
222
|
+
* Name of the group, used to display the group header in the UI
|
|
223
|
+
*/
|
|
224
|
+
name: string;
|
|
225
|
+
/**
|
|
226
|
+
* List of collection ids or view paths that belong to this group.
|
|
227
|
+
*/
|
|
228
|
+
entries: string[];
|
|
229
|
+
/**
|
|
230
|
+
* Configure which groups start collapsed.
|
|
231
|
+
* Set to `true` to collapse in both drawer and home page,
|
|
232
|
+
* or use an object to control each independently.
|
|
233
|
+
*
|
|
234
|
+
* @defaultValue false (expanded)
|
|
235
|
+
*/
|
|
236
|
+
collapsedByDefault?: boolean | {
|
|
237
|
+
drawer?: boolean;
|
|
238
|
+
home?: boolean;
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface NavigationEntry {
|
|
243
|
+
id: string;
|
|
244
|
+
url: string;
|
|
245
|
+
name: string;
|
|
246
|
+
slug: string;
|
|
247
|
+
type: "collection" | "view" | "admin";
|
|
248
|
+
collection?: AdminCollection;
|
|
249
|
+
view?: AppView;
|
|
250
|
+
description?: string;
|
|
251
|
+
group: string;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export type NavigationResult = {
|
|
255
|
+
|
|
256
|
+
allowDragAndDrop: boolean;
|
|
257
|
+
|
|
258
|
+
navigationEntries: NavigationEntry[],
|
|
259
|
+
|
|
260
|
+
groups: string[],
|
|
261
|
+
|
|
262
|
+
onNavigationEntriesUpdate: (entries: NavigationGroupMapping[]) => void;
|
|
263
|
+
};
|
|
264
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import type { CollectionConfigsBuilder, AppViewsBuilder } from "../types/builders";
|
|
4
|
+
import type { EntityCustomView } from "../types/entity_views";
|
|
5
|
+
import type { EntityAction } from "../types/entity_actions";
|
|
6
|
+
import type { AppView, NavigationGroupMapping } from "./navigation";
|
|
7
|
+
import type { AdminCollection } from "@rebasepro/admin-types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Options to enable the built-in collection editor.
|
|
11
|
+
* When provided to `<RebaseAdmin>`, the editor is auto-wired as a native feature.
|
|
12
|
+
*/
|
|
13
|
+
export interface CollectionEditorOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Function that returns an auth token for schema-editor API calls.
|
|
16
|
+
* Falls back to `authController.getAuthToken` when omitted.
|
|
17
|
+
*/
|
|
18
|
+
getAuthToken?: () => Promise<string | null>;
|
|
19
|
+
/** Mark the editor as read-only (disable mutations). */
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
/** Suggested base paths shown when creating new collections. */
|
|
22
|
+
pathSuggestions?: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface RebaseAdminConfig<EC extends AdminCollection = AdminCollection> {
|
|
26
|
+
collections?: EC[] | CollectionConfigsBuilder<EC>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Custom top-level views added to the main navigation.
|
|
30
|
+
* Accepts a static array of views or an async builder function
|
|
31
|
+
* that receives the current user/auth context for role-based views.
|
|
32
|
+
*/
|
|
33
|
+
views?: AppView[] | AppViewsBuilder;
|
|
34
|
+
|
|
35
|
+
homePage?: ReactNode;
|
|
36
|
+
entityViews?: EntityCustomView[];
|
|
37
|
+
entityActions?: EntityAction[];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Centralized configuration for how collections and views are grouped
|
|
41
|
+
* in the navigation sidebar and home page.
|
|
42
|
+
* Each mapping defines a named group and the collection/view slugs
|
|
43
|
+
* that belong to it. The array order determines group display order.
|
|
44
|
+
* Entry order within each group determines card order.
|
|
45
|
+
*/
|
|
46
|
+
navigationGroupMappings?: NavigationGroupMapping[];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Enable the built-in visual collection/schema editor.
|
|
50
|
+
* Pass `true` for zero-config, or an options object for fine-grained control.
|
|
51
|
+
* When enabled, the editor slots, provider, and Studio schema view
|
|
52
|
+
* are all auto-wired — no plugin or manual view injection needed.
|
|
53
|
+
*/
|
|
54
|
+
collectionEditor?: boolean | CollectionEditorOptions;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* URL path prefix the admin is mounted under, when it does not live at the
|
|
58
|
+
* site root. Set this when the admin is rendered inside a path-prefixed
|
|
59
|
+
* route (e.g. `<Route path="/admin/*">`) so URL⇄collection resolution
|
|
60
|
+
* accounts for the prefix — otherwise the current path won't be recognized
|
|
61
|
+
* as a collection path and views hang on a spinner with no data fetch.
|
|
62
|
+
*
|
|
63
|
+
* Do NOT set this when mounting via a react-router `basename` — react-router
|
|
64
|
+
* already strips the prefix from the location, so the default (`/`) is correct.
|
|
65
|
+
*
|
|
66
|
+
* @default "/"
|
|
67
|
+
*/
|
|
68
|
+
basePath?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface RebaseStudioConfig {
|
|
72
|
+
tools?: ("sql" | "js" | "rls" | "schema" | "storage" | "cron" | "schema-visualizer" | "branches" | "backups" | "api" | "logs" | "api-keys")[];
|
|
73
|
+
homePage?: ReactNode;
|
|
74
|
+
devViews?: AppView[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface RebaseAuthConfig {
|
|
78
|
+
loginView?: ReactNode;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface RebaseRegistryController {
|
|
82
|
+
// Current state
|
|
83
|
+
cmsConfig: RebaseAdminConfig | null;
|
|
84
|
+
studioConfig: RebaseStudioConfig | null;
|
|
85
|
+
authConfig: RebaseAuthConfig | null;
|
|
86
|
+
|
|
87
|
+
// Registration functions
|
|
88
|
+
registerCMS: (config: RebaseAdminConfig) => void;
|
|
89
|
+
unregisterCMS: () => void;
|
|
90
|
+
|
|
91
|
+
registerStudio: (config: RebaseStudioConfig) => void;
|
|
92
|
+
unregisterStudio: () => void;
|
|
93
|
+
|
|
94
|
+
registerAuth: (config: RebaseAuthConfig) => void;
|
|
95
|
+
unregisterAuth: () => void;
|
|
96
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Controller to open the side dialog
|
|
5
|
+
* @group Hooks and utilities
|
|
6
|
+
*/
|
|
7
|
+
export interface SideDialogsController {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Close the last panel
|
|
11
|
+
*/
|
|
12
|
+
close: () => void;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* List of side panels currently open
|
|
16
|
+
*/
|
|
17
|
+
sidePanels: SideDialogPanelProps[];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Override the current side panels
|
|
21
|
+
* @param panels
|
|
22
|
+
*/
|
|
23
|
+
setSidePanels: (panels: SideDialogPanelProps[]) => void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Open one or multiple side panels
|
|
27
|
+
* @param props
|
|
28
|
+
*/
|
|
29
|
+
open: (panelProps: SideDialogPanelProps | SideDialogPanelProps[]) => void;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Replace the last open panel with the given one
|
|
33
|
+
* @param props
|
|
34
|
+
*/
|
|
35
|
+
replace: (panelProps: SideDialogPanelProps | SideDialogPanelProps[]) => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Props used to open a side dialog
|
|
40
|
+
* @group Hooks and utilities
|
|
41
|
+
*/
|
|
42
|
+
export interface SideDialogPanelProps {
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A key that identifies this panel
|
|
46
|
+
*/
|
|
47
|
+
key: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The component type that will be rendered
|
|
51
|
+
*/
|
|
52
|
+
component: React.ReactNode;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Optional width of the panel
|
|
56
|
+
*/
|
|
57
|
+
width?: string;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* When open, change the URL to this path.
|
|
61
|
+
* Note that if you want to restore state from a URL you need to add the
|
|
62
|
+
* logic yourself by listening to URL updates, and probably call `open`.
|
|
63
|
+
*/
|
|
64
|
+
urlPath?: string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* If the navigation stack is empty (you landed in the `urlPath` url), what
|
|
68
|
+
* url path to change to when the panel gets closed.
|
|
69
|
+
*/
|
|
70
|
+
parentUrlPath?: string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Callback when the panel is closed
|
|
74
|
+
*/
|
|
75
|
+
onClose?: () => void;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Use this prop to store additional data in the panel
|
|
79
|
+
*/
|
|
80
|
+
additional?: unknown;
|
|
81
|
+
|
|
82
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Entity } from "@rebasepro/types";
|
|
2
|
+
import type { AdminCollection } from "@rebasepro/admin-types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Props used to open a side dialog
|
|
6
|
+
* @group Hooks and utilities
|
|
7
|
+
*/
|
|
8
|
+
export interface SidePanelBindingProps<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Absolute path of the entity
|
|
12
|
+
*/
|
|
13
|
+
path: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* ID of the entity, if not set, it means we are creating a new entity
|
|
17
|
+
*/
|
|
18
|
+
entityId?: string | number;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Set this flag to true if you want to make a copy of an existing entity
|
|
22
|
+
*/
|
|
23
|
+
copy?: boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Open the entity with a selected sub-collection view. If the panel for this
|
|
27
|
+
* entity was already open, it is replaced.
|
|
28
|
+
*/
|
|
29
|
+
selectedTab?: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Use this prop to override the width of the form view.
|
|
33
|
+
* e.g. "600px"
|
|
34
|
+
*/
|
|
35
|
+
width?: number | string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Collection representing the entities of this view.
|
|
39
|
+
* If you leave it blank it will be induced by your navigation
|
|
40
|
+
*/
|
|
41
|
+
collection?: AdminCollection<M>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Should update the URL when opening the dialog.
|
|
45
|
+
* Consider that if the collection that you provide is not defined in the base
|
|
46
|
+
* config of your `Rebase` component, you will not be able to recreate
|
|
47
|
+
* the state if copying the URL to a different window.
|
|
48
|
+
*/
|
|
49
|
+
updateUrl?: boolean;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Callback when the entity is updated
|
|
53
|
+
* @param params
|
|
54
|
+
*/
|
|
55
|
+
onUpdate?: (params: { entity: Entity<M> }) => void;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Callback when the dialog is closed
|
|
59
|
+
*/
|
|
60
|
+
onClose?: () => void;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Should this panel close when saving
|
|
64
|
+
*/
|
|
65
|
+
closeOnSave?: boolean;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Override some form properties
|
|
69
|
+
*/
|
|
70
|
+
formProps?: Record<string, unknown>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Allow the user to open the entity fullscreen
|
|
74
|
+
*/
|
|
75
|
+
allowFullScreen?: boolean;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Pre-populate the form with these values when creating a new entity.
|
|
79
|
+
* Only applied when `entityId` is not set (i.e. the form is in "new" mode).
|
|
80
|
+
* Useful for actions that fetch data from an external source (e.g. a URL)
|
|
81
|
+
* and want to pre-fill the document before the user saves.
|
|
82
|
+
*/
|
|
83
|
+
defaultValues?: Partial<M>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Controller to open the side dialog displaying entity forms
|
|
88
|
+
* @group Hooks and utilities
|
|
89
|
+
*/
|
|
90
|
+
export interface SidePanelController {
|
|
91
|
+
/**
|
|
92
|
+
* Close the last panel
|
|
93
|
+
*/
|
|
94
|
+
close: () => void;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Open a new entity sideDialog. By default, the collection and configuration
|
|
98
|
+
* of the view is fetched from the collections you have specified in the
|
|
99
|
+
* navigation.
|
|
100
|
+
* At least you need to pass the path of the entity you would like
|
|
101
|
+
* to edit. You can set a entityId if you would like to edit and existing one
|
|
102
|
+
* (or a new one with that id).
|
|
103
|
+
* @param props
|
|
104
|
+
*/
|
|
105
|
+
open: <M extends Record<string, unknown> = Record<string, unknown>>(props: SidePanelBindingProps<M>) => void;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Replace the last open entity panel with the given one.
|
|
109
|
+
* @param props
|
|
110
|
+
*/
|
|
111
|
+
replace: <M extends Record<string, unknown> = Record<string, unknown>>(props: SidePanelBindingProps<M>) => void;
|
|
112
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Possible snackbar types
|
|
4
|
+
* @group Hooks and utilities
|
|
5
|
+
*/
|
|
6
|
+
export type SnackbarMessageType = "success" | "info" | "warning" | "error";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Controller to display snackbars
|
|
10
|
+
* @group Hooks and utilities
|
|
11
|
+
*/
|
|
12
|
+
export interface SnackbarController {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Close the currently open snackbar
|
|
16
|
+
*/
|
|
17
|
+
close: () => void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Display a new snackbar. You need to specify the type and message.
|
|
21
|
+
* You can optionally specify a title
|
|
22
|
+
*/
|
|
23
|
+
open: (props: {
|
|
24
|
+
type: SnackbarMessageType;
|
|
25
|
+
message: React.ReactNode;
|
|
26
|
+
autoHideDuration?: number;
|
|
27
|
+
}) => void;
|
|
28
|
+
|
|
29
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @rebasepro/admin-types — the React-flavoured half of the Rebase type surface.
|
|
3
|
+
*
|
|
4
|
+
* Everything here describes the admin panel: what a collection looks like on
|
|
5
|
+
* screen, the controllers the panel runs on, the props a custom field or view
|
|
6
|
+
* receives. It depends on @rebasepro/types and nothing in @rebasepro/types
|
|
7
|
+
* depends on it, which is what lets a BaaS install exist without React.
|
|
8
|
+
*
|
|
9
|
+
* If you are building a backend, you want @rebasepro/types.
|
|
10
|
+
*/
|
|
11
|
+
// Side-effect import: this is what adds `admin` back onto the core types.
|
|
12
|
+
import "./augment";
|
|
13
|
+
|
|
14
|
+
export * from "./types/property_options";
|
|
15
|
+
export * from "./react_component_ref";
|
|
16
|
+
export * from "./collections";
|
|
17
|
+
export * from "./admin_collection";
|
|
18
|
+
export * from "./rebase_context";
|
|
19
|
+
export * from "./types";
|
|
20
|
+
export * from "./controllers";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import type { ComponentLike, ComponentRef, LazyComponentRef } from "@rebasepro/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `ComponentRef`, narrowed to real React types.
|
|
6
|
+
*
|
|
7
|
+
* Core's {@link ComponentRef} describes a component structurally
|
|
8
|
+
* ({@link ComponentLike}) so that `properties.ts` — and therefore the whole
|
|
9
|
+
* property model the backend reads — can live without React. The trade is that
|
|
10
|
+
* the return type is `unknown`, so a function returning something React cannot
|
|
11
|
+
* render type-checks there.
|
|
12
|
+
*
|
|
13
|
+
* Use this type wherever React genuinely exists: authoring a collection's admin
|
|
14
|
+
* options, and inside the admin packages. Assignments flow into core unchanged,
|
|
15
|
+
* because every member of this union is a member of that one.
|
|
16
|
+
*/
|
|
17
|
+
export type ReactComponentRef<P = any> =
|
|
18
|
+
| string
|
|
19
|
+
| LazyComponentRef<P>
|
|
20
|
+
| (() => Promise<{ default: React.ComponentType<P> }>)
|
|
21
|
+
| React.ComponentType<P>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The `ComponentLike` contract, as a signature the compiler has to keep true.
|
|
25
|
+
*
|
|
26
|
+
* The split rests on one claim: **every form a React component takes is
|
|
27
|
+
* assignable to `ComponentLike`** — function components, class components,
|
|
28
|
+
* `memo`, `forwardRef`. If that stopped holding, core's `ComponentRef` would
|
|
29
|
+
* quietly begin rejecting real components, and the failure would surface far away
|
|
30
|
+
* in whichever collection file happened to use the broken form.
|
|
31
|
+
*
|
|
32
|
+
* So the claim is not left to a test that someone has to run. This function's
|
|
33
|
+
* parameter and return types state it, and `pnpm typecheck` enforces it on every
|
|
34
|
+
* commit. It is also useful on its own: an explicit widening at the point where
|
|
35
|
+
* an authored component enters a collection config.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* import { MyField } from "./MyField";
|
|
39
|
+
* admin: { Field: asComponentRef(MyField) }
|
|
40
|
+
*/
|
|
41
|
+
export function asComponentRef<P>(component: React.ComponentType<P>): ComponentRef<P> {
|
|
42
|
+
return component;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The same contract in the other direction: a `ComponentLike` is only renderable
|
|
47
|
+
* once narrowed, and this is the single sanctioned place that narrowing is
|
|
48
|
+
* spelled out. `resolveComponentRef` in `@rebasepro/app` does the runtime half.
|
|
49
|
+
*/
|
|
50
|
+
export function asReactComponent<P>(component: ComponentLike<P>): React.ComponentType<P> {
|
|
51
|
+
return component as React.ComponentType<P>;
|
|
52
|
+
}
|