import React from "react"; import type { CollectionRegistryController } from "@rebasepro/types"; import type { SidePanelController, UrlController, NavigationStateController, BreadcrumbEntry, BreadcrumbsController } from "@rebasepro/cms-types"; export type { BreadcrumbEntry, BreadcrumbsController }; /** * StudioBridge provides optional admin capabilities to Studio components. * When the admin is present, a bridge provider injects real implementations. * When the admin is absent, noop defaults ensure Studio works standalone. */ /** * Editing a collection's source through the admin's plan/apply flow. * * Studio has its own writers — the RLS editor saves a policy, the collection * editor saves a property — and until this existed they did not go to the same * place. Saving a policy on a mapped table POSTed the rules straight to * `/schema-editor/collection/save`: no plan, no dialog, no record of what SQL * the change would produce, while the identical edit made two tabs away in the * collection editor showed all three. * * `available` is false when there is no collection editor above this Studio — * the hosted console against somebody else's container, or a panel that never * enabled it — and the caller falls back to whatever it did before. */ export interface StudioSchemaEditing { available: boolean; /** * Merge `patch` into the collection and take it through plan → confirm → * apply: the same dialog `useLiveSchemaEditing` shows the collection * editor. * * Resolves once the change has been applied, or written source-only if * that is what was chosen. Rejects with `SchemaChangeCancelled` when the * dialog was closed — which is not an error to report, it is an answer. */ updateCollection: (collectionId: string, patch: Record) => Promise; } export interface StudioBridge { collectionRegistry: CollectionRegistryController; schemaEditing: StudioSchemaEditing; sidePanelController: SidePanelController; urlController: UrlController; navigationState: NavigationStateController; breadcrumbs: BreadcrumbsController; capabilities: StudioCapabilities; } /** * What the *host* of these tools can do, as opposed to what the backend can. * * Studio is mounted in two very different places. In a project's own admin * panel it runs next to the collection source files and can edit them through * the schema-editor routes. In the hosted console it runs against somebody * else's deployed container: there is no source to edit — the container is * rebuilt from the customer's repository on every deploy — and the routes that * would edit it are not mounted at all, because the framework switches the * schema editor off under `NODE_ENV=production`. * * Tools that would otherwise offer a write into the codebase read this to * decide whether that write is even meaningful. */ export interface StudioCapabilities { /** * Whether the host has the project's collection source at hand and can * write to it. * * Defaults to `true`, which is what an admin panel running beside its own * `collectionsDir` has always assumed. */ codebase: boolean; } export declare const StudioBridgeContext: React.Context; /** * Provider that injects admin capabilities into Studio. * Accepts partial overrides — any field not provided falls back to noop. * * Usage (in app wiring, when the admin is present): * ```tsx * * * * ``` */ export declare function StudioBridgeProvider({ value, children }: { value: Partial; children: React.ReactNode; }): React.JSX.Element; /** * Source editing through the admin's plan/apply dialog. `available` is false * when no collection editor is mounted. */ export declare function useStudioSchemaEditing(): StudioSchemaEditing; /** Collection registry — returns noop if the admin is not present. */ export declare function useStudioCollectionRegistry(): CollectionRegistryController; /** Side panel controller — returns noop if the admin is not present. */ export declare function useStudioSidePanelController(): SidePanelController; /** URL controller — returns noop if the admin is not present. */ export declare function useStudioUrlController(): UrlController; /** Navigation state — returns noop if the admin is not present. */ export declare function useStudioNavigationState(): NavigationStateController; /** Breadcrumbs controller — returns noop if the admin is not present. */ export declare function useStudioBreadcrumbs(): BreadcrumbsController; /** What the host can do — see {@link StudioCapabilities}. */ export declare function useStudioCapabilities(): StudioCapabilities; /** * Registry that controllers use to self-register their implementations * into the Studio bridge. Each controller calls `register(key, value)` * on mount and `unregister(key)` on unmount. */ export interface StudioBridgeRegistry { register: (key: K, value: StudioBridge[K]) => void; unregister: (key: keyof StudioBridge) => void; } export declare const StudioBridgeRegistryContext: React.Context; /** * Provider that creates a self-assembling bridge. * * Mount this above the controller providers. Each controller calls * `useBridgeRegistration(key, value)` to inject its implementation. * The bridge context value is automatically kept in sync. * * ```tsx * * // auto-registers * // auto-registers * // auto-registers * // consumes bridge * * * * * ``` */ export declare function StudioBridgeRegistryProvider({ children }: { children: React.ReactNode; }): React.JSX.Element;