@rebasepro/app 0.12.1-canary.gf5f1d39 → 0.13.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.
Files changed (49) hide show
  1. package/README.md +1 -1
  2. package/dist/auth/api.d.ts +3 -8
  3. package/dist/auth/index.d.ts +2 -2
  4. package/dist/auth/types.d.ts +1 -5
  5. package/dist/collections/form-layout.d.ts +107 -0
  6. package/dist/collections/index.d.ts +1 -0
  7. package/dist/collections/title-property.d.ts +22 -0
  8. package/dist/components/Debug/collection-views/sample_data.d.ts +3 -2
  9. package/dist/hooks/ApiConfigContext.d.ts +36 -2
  10. package/dist/hooks/useBackendStorageSource.d.ts +6 -1
  11. package/dist/hooks/useNavigationBlocker.d.ts +1 -1
  12. package/dist/hooks/useSnackbarController.d.ts +2 -1
  13. package/dist/hooks/useStudioBridge.d.ts +27 -0
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.es.js +681 -186
  16. package/dist/index.es.js.map +1 -1
  17. package/dist/internal/common.d.ts +14 -2
  18. package/package.json +29 -25
  19. package/src/auth/api.ts +8 -9
  20. package/src/auth/index.ts +2 -2
  21. package/src/auth/types.ts +5 -6
  22. package/src/collections/form-layout.ts +386 -0
  23. package/src/collections/index.ts +1 -0
  24. package/src/collections/title-property.ts +41 -0
  25. package/src/components/Debug/UIReferenceView.tsx +9 -1
  26. package/src/components/Debug/collection-views/sample_data.ts +4 -2
  27. package/src/components/NotFoundPage.tsx +1 -1
  28. package/src/components/common/useDataTableController.tsx +1 -1
  29. package/src/core/Rebase.tsx +5 -1
  30. package/src/core/RebaseRouter.tsx +2 -1
  31. package/src/core/RebaseRoutes.tsx +1 -1
  32. package/src/hooks/ApiConfigContext.tsx +45 -3
  33. package/src/hooks/useAuthSubscription.ts +29 -3
  34. package/src/hooks/useBackendStorageSource.ts +8 -1
  35. package/src/hooks/useNavigationBlocker.tsx +1 -1
  36. package/src/hooks/useSnackbarController.tsx +34 -6
  37. package/src/hooks/useStudioBridge.tsx +50 -2
  38. package/src/index.ts +1 -1
  39. package/src/internal/common.tsx +15 -3
  40. package/src/internal/useRestoreScroll.tsx +1 -1
  41. package/src/locales/de.ts +23 -2
  42. package/src/locales/en.ts +23 -1
  43. package/src/locales/es.ts +23 -1
  44. package/src/locales/fr.ts +23 -1
  45. package/src/locales/hi.ts +23 -1
  46. package/src/locales/it.ts +23 -1
  47. package/src/locales/pt.ts +23 -1
  48. package/src/util/enums.ts +4 -2
  49. package/src/util/useStorageUploadController.tsx +5 -1
package/README.md CHANGED
@@ -8,7 +8,7 @@ Framework-agnostic runtime for data-driven admin panels — React hooks, provide
8
8
  pnpm add @rebasepro/app
9
9
  ```
10
10
 
11
- **Peer dependencies:** `react >= 19`, `react-dom >= 19`, `react-router ^7`, `react-router-dom ^7`
11
+ **Peer dependencies:** `react >= 19.2.7`, `react-dom >= 19.2.7`, `react-router ^8`
12
12
 
13
13
  ## What This Package Does
14
14
 
@@ -8,13 +8,6 @@
8
8
  * here is the unauthenticated `/api/auth/config` probe used to detect
9
9
  * bootstrap mode and enabled providers before a session exists.
10
10
  */
11
- import { RebaseApiError } from "@rebasepro/types";
12
- /**
13
- * @deprecated Use {@link RebaseApiError} (from `@rebasepro/types`, re-exported by
14
- * `@rebasepro/client`). Kept as an alias so `instanceof` / imports keep working;
15
- * errors thrown here now carry `.code` and `.status` on the unified type.
16
- */
17
- export declare const AuthApiError: typeof RebaseApiError;
18
11
  /**
19
12
  * Auth config response from the backend
20
13
  */
@@ -59,7 +52,9 @@ export declare function createAuthConfigCache(): AuthConfigCache;
59
52
  * Concurrent calls are deduplicated: only one network request is made
60
53
  * and all callers share the same promise.
61
54
  */
62
- export declare function fetchAuthConfig(apiUrl: string, cache: AuthConfigCache): Promise<AuthConfigResponse>;
55
+ export declare function fetchAuthConfig(apiUrl: string, cache: AuthConfigCache,
56
+ /** The backend's `basePath`; only needed if it is not the default. */
57
+ apiPath?: string): Promise<AuthConfigResponse>;
63
58
  /**
64
59
  * Clear the cached auth config (e.g. on logout or for testing).
65
60
  */
@@ -8,7 +8,7 @@
8
8
  * controller are in `../components`. Both are re-exported from the package
9
9
  * root, which is where applications should import them from.
10
10
  */
11
- export type { RebaseAuthController, RebaseAuthControllerProps, AuthTokens, DeviceSession, UserInfo, AuthResponse, RefreshResponse } from "./types";
11
+ export type { RebaseAuthController, RebaseAuthControllerProps, User, AuthTokens, DeviceSession, AuthResponse, RefreshResponse } from "./types";
12
12
  export { useRebaseAuthController } from "./useRebaseAuthController";
13
- export { fetchAuthConfig, clearAuthConfigCache, createAuthConfigCache, AuthApiError } from "./api";
13
+ export { fetchAuthConfig, clearAuthConfigCache, createAuthConfigCache } from "./api";
14
14
  export type { AuthConfigResponse, AuthConfigCache } from "./api";
@@ -1,11 +1,7 @@
1
1
  import { User, AuthTokens, DeviceSession, RebaseSession, AuthChangeEvent } from "@rebasepro/types";
2
2
  import { AuthController } from "@rebasepro/admin-types";
3
3
  import type { AuthConfigResponse } from "./api";
4
- /** @deprecated Use `User` from `@rebasepro/types` instead. */
5
- export type UserInfo = User;
6
- /** @deprecated Use `DeviceSession` from `@rebasepro/types` instead. */
7
- export type Session = DeviceSession;
8
- export type { AuthTokens, DeviceSession };
4
+ export type { User, AuthTokens, DeviceSession };
9
5
  /**
10
6
  * Auth controller that extends the base AuthController
11
7
  * with additional methods for email/password and Google login
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Form layout resolution.
3
+ *
4
+ * Turns a collection into the shape the entity form renders: an ordered list of
5
+ * sections holding grid-spanned fields, plus the metadata rail beside them.
6
+ *
7
+ * The reason this is a pure function rather than logic inside the form is that
8
+ * the *defaults* are the interesting part. A collection that never writes an
9
+ * `admin.form` block still has to get a two-column layout out of this — the flat
10
+ * run of full-width fields it produced before was the single biggest cost in the
11
+ * form, and no amount of config would have fixed it for collections nobody
12
+ * hand-tunes. Deriving it here means it is testable in isolation, which matters
13
+ * because "what span does a date get" is exactly the kind of rule that rots.
14
+ */
15
+ import type { AdminCollection, PropertySpan } from "@rebasepro/admin-types";
16
+ import type { Property } from "@rebasepro/types";
17
+ /** A field placed on the grid. */
18
+ export interface ResolvedFormField {
19
+ key: string;
20
+ /** Columns occupied, out of `GRID_COLUMNS`. Ignored in the rail. */
21
+ span: PropertySpan;
22
+ /** True for an `additionalFields` entry rather than a property. */
23
+ additional: boolean;
24
+ /**
25
+ * The span was written on the property rather than derived from its type.
26
+ * Row filling leaves these alone: an author who wrote a width meant it.
27
+ */
28
+ spanExplicit?: boolean;
29
+ }
30
+ export interface ResolvedFormSection {
31
+ key: string;
32
+ title?: string;
33
+ collapsible: boolean;
34
+ /** Initial state only; the form owns it after first interaction. */
35
+ collapsed: boolean;
36
+ fields: ResolvedFormField[];
37
+ }
38
+ export interface ResolvedFormLayout {
39
+ sections: ResolvedFormSection[];
40
+ /** Fields shown in the rail. Empty means no rail fields. */
41
+ sidebar: ResolvedFormField[];
42
+ /** Show the read-only id/created/updated block at the foot of the rail. */
43
+ showRecordMeta: boolean;
44
+ /** True when there is anything at all to put in the rail. */
45
+ hasRail: boolean;
46
+ }
47
+ export interface ResolveFormLayoutParams<M extends Record<string, unknown>> {
48
+ collection: AdminCollection<M>;
49
+ /**
50
+ * Field keys in render order, already filtered by `propertiesOrder` — i.e.
51
+ * the output of `getFormFieldKeys`. Passed in rather than recomputed so the
52
+ * form and the layout can never disagree about which fields exist.
53
+ */
54
+ fieldKeys: string[];
55
+ /**
56
+ * Which fields the user may edit right now. A manual id is editable while
57
+ * creating and frozen afterwards, and that decides whether it belongs in the
58
+ * form at all or only in the record block.
59
+ */
60
+ status: "new" | "existing" | "copy";
61
+ }
62
+ /**
63
+ * The span a property gets when nothing is declared.
64
+ *
65
+ * Deliberately coarse: three buckets, chosen by how much room the *editor*
66
+ * needs, not by how important the field is. Importance is what `admin.form`
67
+ * sections are for.
68
+ */
69
+ export declare function deriveSpan(property: Property, isTitleProperty: boolean): PropertySpan;
70
+ /**
71
+ * Can the user still type this id?
72
+ *
73
+ * A `manual` id is a real field while creating and frozen once the row exists.
74
+ * Every generated strategy (`uuid`, `cuid`, a raw SQL default) is never typed.
75
+ * Getting this wrong in the "frozen" direction would make manual-id collections
76
+ * uncreatable, so it fails towards showing the field.
77
+ */
78
+ export declare function isIdPropertyEditable(property: Property, status: "new" | "existing" | "copy"): boolean;
79
+ /**
80
+ * An audit timestamp the database maintains — `created_at`, `updated_at`.
81
+ *
82
+ * Not a guess from the name: `autoValue` says the column is written by the
83
+ * system on create or update, so the field is never typed. Rendering it as an
84
+ * input in the middle of the form promised an edit that cannot happen, and the
85
+ * record block already shows both values — the same two dates twice on one
86
+ * screen.
87
+ */
88
+ export declare function isAuditTimestamp(property: Property | undefined): boolean;
89
+ /**
90
+ * Close the trailing gap in each row.
91
+ *
92
+ * Without this a section of half-width fields with an odd count leaves a hole —
93
+ * `name | sku` then `brand | ␣␣` — a field stranded beside half a row of
94
+ * nothing, which reads as a mistake rather than a layout. The remainder is
95
+ * spread across the row's derived fields rather than dumped on the last one, so
96
+ * a lone half-width field becomes full width and a pair grows evenly. Fields
97
+ * with an explicit span are never resized.
98
+ */
99
+ export declare function fillRows(fields: ResolvedFormField[]): ResolvedFormField[];
100
+ /**
101
+ * Resolve the layout for a collection's generated form.
102
+ *
103
+ * Never drops a field: anything not named by a section lands in a trailing
104
+ * group, so adding a column to the database cannot make it silently invisible
105
+ * in the panel.
106
+ */
107
+ export declare function resolveFormLayout<M extends Record<string, unknown>>({ collection, fieldKeys, status }: ResolveFormLayoutParams<M>): ResolvedFormLayout;
@@ -1,6 +1,7 @@
1
1
  export * from "./collection_view_config";
2
2
  export * from "./entity_image_preview";
3
3
  export * from "./filter-operator-resolution";
4
+ export * from "./form-layout";
4
5
  export * from "./navigation_from_path";
5
6
  export * from "./navigation_utils";
6
7
  export * from "./parent_references_from_path";
@@ -14,6 +14,28 @@ import type { AdminCollection } from "@rebasepro/admin-types";
14
14
  * @group Collections
15
15
  */
16
16
  export declare function getTitlePropertyCandidates<M extends Record<string, unknown>>(collection: AdminCollection<M>): string[];
17
+ /**
18
+ * The relation a collection *leads* with, if it leads with one.
19
+ *
20
+ * A junction-shaped collection — a pipeline entry, a membership, a booking —
21
+ * holds no label of its own: it is "this candidate, for that vacancy". The
22
+ * general ranking puts relations last (they only read once the target
23
+ * resolves), so the title slot would otherwise fall to whatever free text
24
+ * happens to follow: a note, a comment. Preview surfaces that render one row
25
+ * per entity (list, cards, board) prefer the leading relation instead.
26
+ *
27
+ * The decision is structural — the first property that could be a title, in the
28
+ * order the developer declared (or ordered) them. Declaration order is a
29
+ * statement about what the collection is about; property *names* are not
30
+ * consulted here.
31
+ *
32
+ * Returns `undefined` when that first property is anything but a
33
+ * single-cardinality relation, or when the collection states its own
34
+ * `titleProperty`.
35
+ *
36
+ * @group Collections
37
+ */
38
+ export declare function getLeadingRelationTitleKey<M extends Record<string, unknown>>(collection: AdminCollection<M>): string | undefined;
17
39
  /**
18
40
  * The property that should fill the title slot for a collection, ignoring any
19
41
  * concrete values. Prefer {@link getTitlePropertyKeyForValues} when an entity
@@ -1,3 +1,4 @@
1
+ import type { ChipColorKey } from "@rebasepro/ui";
1
2
  export type ProjectStatus = "backlog" | "in_progress" | "in_review" | "done";
2
3
  export type ProjectPriority = "low" | "medium" | "high" | "critical";
3
4
  export interface SampleProject {
@@ -14,10 +15,10 @@ export interface SampleProject {
14
15
  }
15
16
  export declare const STATUS_CONFIG: Record<ProjectStatus, {
16
17
  label: string;
17
- color: string;
18
+ color: ChipColorKey;
18
19
  }>;
19
20
  export declare const PRIORITY_CONFIG: Record<ProjectPriority, {
20
21
  label: string;
21
- color: string;
22
+ color: ChipColorKey;
22
23
  }>;
23
24
  export declare const SAMPLE_PROJECTS: SampleProject[];
@@ -8,17 +8,51 @@ import React from "react";
8
8
  */
9
9
  export interface ApiConfig {
10
10
  apiUrl: string;
11
+ /**
12
+ * The path the backend mounts its API under, appended to {@link apiUrl}.
13
+ *
14
+ * `"/api"` by default, which is the server's default `basePath`. It is
15
+ * carried here because a good deal of UI builds request URLs by hand
16
+ * instead of going through the client's typed methods, and every one of
17
+ * those sites used to write `/api` as a literal — so a backend configured
18
+ * with any other `basePath` served an admin panel whose auth-provider
19
+ * discovery, storage browser, history panel, user picker and Studio tools
20
+ * all requested paths that did not exist.
21
+ */
22
+ apiPath: string;
11
23
  getAuthToken?: () => Promise<string | null>;
12
24
  }
25
+ /** What the server uses when `basePath` is not configured. */
26
+ export declare const DEFAULT_API_PATH = "/api";
13
27
  /**
14
28
  * Read the API config from context. Returns `undefined` if no provider is present,
15
29
  * allowing hooks to fall back to their own props.
16
30
  */
17
31
  export declare function useApiConfig(): ApiConfig | undefined;
18
32
  /**
19
- * Provide API configuration (apiUrl, getAuthToken) to the entire subtree.
33
+ * `apiUrl` and `apiPath` joined, with no trailing slash — the prefix to build a
34
+ * request URL from.
35
+ *
36
+ * Returns `undefined` when there is no provider, so a caller can keep its own
37
+ * fallback rather than silently requesting a relative path.
38
+ */
39
+ export declare function useApiBase(): string | undefined;
40
+ /**
41
+ * The same prefix, derived from a client rather than from context.
42
+ *
43
+ * For the code that holds a `RebaseClient` but sits outside (or above) an
44
+ * `ApiConfigProvider`. Returns `undefined` when the client has no base URL,
45
+ * which is the signal every caller already treats as "cannot build a request".
46
+ */
47
+ export declare function apiBaseOf(client?: {
48
+ baseUrl?: string;
49
+ apiPath?: string;
50
+ }): string | undefined;
51
+ /**
52
+ * Provide API configuration (apiUrl, apiPath, getAuthToken) to the entire subtree.
20
53
  * Typically rendered inside `<Rebase>` or at the app root.
21
54
  */
22
- export declare function ApiConfigProvider({ apiUrl, getAuthToken, children }: ApiConfig & {
55
+ export declare function ApiConfigProvider({ apiUrl, apiPath, getAuthToken, children }: Omit<ApiConfig, "apiPath"> & {
56
+ apiPath?: string;
23
57
  children: React.ReactNode;
24
58
  }): React.JSX.Element;
@@ -7,6 +7,11 @@ export interface BackendStorageSourceProps {
7
7
  * Backend API URL (e.g., 'http://localhost:3001')
8
8
  */
9
9
  apiUrl: string;
10
+ /**
11
+ * The path the backend mounts its API under. Defaults to the server's own
12
+ * default; pass the backend's `basePath` if it was configured otherwise.
13
+ */
14
+ apiPath?: string;
10
15
  /**
11
16
  * Function to get the current auth token
12
17
  */
@@ -27,4 +32,4 @@ export interface BackendStorageSourceProps {
27
32
  * <Rebase storageSource={storageSource} ... />
28
33
  * ```
29
34
  */
30
- export declare function useBackendStorageSource({ apiUrl, getAuthToken }: BackendStorageSourceProps): StorageSource;
35
+ export declare function useBackendStorageSource({ apiUrl, apiPath, getAuthToken }: BackendStorageSourceProps): StorageSource;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { Blocker, BlockerFunction } from "react-router-dom";
2
+ import { Blocker, BlockerFunction } from "react-router";
3
3
  /**
4
4
  * Owns the single React Router blocker for the whole app.
5
5
  *
@@ -1,4 +1,4 @@
1
- import type { SnackbarMessageType } from "@rebasepro/admin-types";
1
+ import type { SnackbarAction, SnackbarMessageType } from "@rebasepro/admin-types";
2
2
  import React from "react";
3
3
  /**
4
4
  * Hook to retrieve the SnackbarContext.
@@ -15,6 +15,7 @@ export declare const useSnackbarController: () => {
15
15
  title?: string;
16
16
  message: React.ReactNode;
17
17
  autoHideDuration?: number;
18
+ action?: SnackbarAction;
18
19
  }) => void;
19
20
  close: () => void;
20
21
  };
@@ -13,6 +13,31 @@ export interface StudioBridge {
13
13
  urlController: UrlController;
14
14
  navigationState: NavigationStateController;
15
15
  breadcrumbs: BreadcrumbsController;
16
+ capabilities: StudioCapabilities;
17
+ }
18
+ /**
19
+ * What the *host* of these tools can do, as opposed to what the backend can.
20
+ *
21
+ * Studio is mounted in two very different places. In a project's own admin
22
+ * panel it runs next to the collection source files and can edit them through
23
+ * the schema-editor routes. In the hosted console it runs against somebody
24
+ * else's deployed container: there is no source to edit — the container is
25
+ * rebuilt from the customer's repository on every deploy — and the routes that
26
+ * would edit it are not mounted at all, because the framework switches the
27
+ * schema editor off under `NODE_ENV=production`.
28
+ *
29
+ * Tools that would otherwise offer a write into the codebase read this to
30
+ * decide whether that write is even meaningful.
31
+ */
32
+ export interface StudioCapabilities {
33
+ /**
34
+ * Whether the host has the project's collection source at hand and can
35
+ * write to it.
36
+ *
37
+ * Defaults to `true`, which is what an admin panel running beside its own
38
+ * `collectionsDir` has always assumed.
39
+ */
40
+ codebase: boolean;
16
41
  }
17
42
  export declare const StudioBridgeContext: React.Context<StudioBridge>;
18
43
  /**
@@ -46,6 +71,8 @@ export declare function useStudioUrlController(): UrlController;
46
71
  export declare function useStudioNavigationState(): NavigationStateController;
47
72
  /** Breadcrumbs controller — returns noop if the admin is not present. */
48
73
  export declare function useStudioBreadcrumbs(): BreadcrumbsController;
74
+ /** What the host can do — see {@link StudioCapabilities}. */
75
+ export declare function useStudioCapabilities(): StudioCapabilities;
49
76
  /**
50
77
  * Registry that controllers use to self-register their implementations
51
78
  * into the Studio bridge. Each controller calls `register(key, value)`
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export * from "./auth";
4
4
  export * from "./components";
5
5
  export * from "./util";
6
6
  export * from "./contexts";
7
- export { CONTAINER_FULL_WIDTH, ADDITIONAL_TAB_WIDTH, FORM_CONTAINER_WIDTH } from "./internal/common";
7
+ export { CONTAINER_FULL_WIDTH, FORM_CONTAINER_WIDTH, SIDE_PANEL_DEFAULT_WIDTH } from "./internal/common";
8
8
  export { useRestoreScroll } from "./internal/useRestoreScroll";
9
9
  export { useUnsavedChangesDialog } from "./hooks/useUnsavedChangesDialog";
10
10
  export { NavigationBlockerProvider, useNavigationBlocker } from "./hooks/useNavigationBlocker";