import { ContextTrinity } from "../createTrinity/index.mjs"; import { App } from "vue"; //#region src/composables/createPlugin/index.d.ts interface PluginOptions { namespace: string; provide: (app: App) => void; setup?: (app: App) => void; /** When true, this plugin appears in the Vue DevTools v0 inspector. @default false */ devtools?: boolean; /** Overlay keys onto the inspector snapshot (adapter names, method-backed state). */ inspect?: (context: unknown) => unknown; } interface Plugin { install: (app: App, ...options: unknown[]) => void; } /** * Attach a plugin context to the DevTools inspector record for `namespace`. * * `createPluginContext` calls this after provide. Plugins that wrap * `createPlugin` directly (stack, date) must call it from `provide`. * * @param app The Vue app the plugin was installed on. * @param namespace The plugin namespace, e.g. `'v0:stack'`. * @param context The live plugin context to show in the inspector. * * @example * ```ts * return createPlugin({ * namespace, * provide: app => { * provideStackContext(context, app) * bindPluginContext(app, namespace, context) * }, * }) * ``` */ declare function bindPluginContext(app: App, namespace: string, context: unknown): void; /** * Creates a new Vue plugin. * * @param options The plugin options. * @returns A new Vue plugin. * * @see https://0.vuetifyjs.com/composables/foundation/create-plugin * * @example * ```ts * export const [useContext, provideContext] = createContext('my-plugin') * * const context = {} * * export const MyPlugin = createPlugin({ * namespace: 'my-plugin', * provide: (app) => { * provideContext(context, app) * }, * setup: (app) => { * // Optional setup logic * }, * }) */ declare function createPlugin(options: PluginOptions): Z; interface PluginContextConfig { /** * Optional plugin setup callback, called once per Vue app after context provision. * Use for adapter initialization, Vue app mixins, global side effects, etc. * Receives the plugin options (minus namespace) so adapters and targets are accessible. */ setup?: (context: E, app: App, options: O) => void; /** * Optional fallback factory. When provided, the generated `useX` consumer uses the * defensive pattern: returns the fallback when called outside a component instance or * when the context is not found. Required for composables that may be consumed outside * component setup (e.g. useLogger, useLocale, useHydration). * * Receives the requested namespace so error messages can include it. */ fallback?: (namespace: string) => E; /** Returns the value to persist. Called reactively inside a watch source. */ persist?: (context: E) => unknown; /** Restores previously persisted state into the context. Called before setup. */ restore?: (context: E, saved: unknown) => void; /** Default `devtools` for this plugin. Install-time `devtools` overrides. @default false */ devtools?: boolean; /** Overlay keys onto the inspector snapshot (adapter names, method-backed state). */ inspect?: (context: E) => unknown; } /** * Creates the three standard functions for a plugin composable. * * @param defaultNamespace The default DI namespace string (e.g. `'v0:logger'`). * @param factory Function that creates the composable context instance from options. * @param config Optional setup callback and fallback factory. * @returns A readonly tuple: `[createXContext, createXPlugin, useX]`. * * @example * ```ts * // Simple — no setup or fallback * export const [createStorageContext, createStoragePlugin, useStorage] = * createPluginContext('v0:storage', options => createStorage(options)) * * // With fallback — safe outside component instances * export const [createLoggerContext, createLoggerPlugin, useLogger] = * createPluginContext('v0:logger', options => createLogger(options), { * fallback: ns => createFallbackLogger(ns), * setup: (context) => { * if (__DEV__ && IN_BROWSER) (window as Window & { __v0Logger__?: typeof context }).__v0Logger__ = context * }, * }) * ``` */ type PluginKeys = { namespace?: string; persist?: boolean; devtools?: boolean; }; type PluginMeta = keyof PluginKeys; declare function createPluginContext, E = unknown>(defaultNamespace: string, factory: (options: Omit) => E, config?: PluginContextConfig, E>): readonly [<_E extends E = E>(_options?: O) => ContextTrinity<_E>, (_options?: O & Pick) => Plugin, <_E extends E = E>(namespace?: string) => _E]; //#endregion export { Plugin, PluginContextConfig, PluginOptions, bindPluginContext, createPlugin, createPluginContext };