feat(dashboard,admin-sdk,admin-shared,admin-vite-plugin): Add support for UI extensions (#7383)
* intial work * update lock * add routes and fix HMR of configs * cleanup * rm imports * rm debug from plugin * address feedback * address feedback
This commit is contained in:
committed by
GitHub
parent
521c252dee
commit
f1176a0673
@@ -0,0 +1,2 @@
|
||||
export * from "./types"
|
||||
export * from "./utils"
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { ComponentType } from "react"
|
||||
|
||||
import { InjectionZone } from "../widgets"
|
||||
|
||||
export type WidgetConfig = {
|
||||
zone: InjectionZone | InjectionZone[]
|
||||
}
|
||||
|
||||
export type RouteConfig = {
|
||||
label?: string
|
||||
icon?: ComponentType
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { RouteConfig, WidgetConfig } from "./types"
|
||||
|
||||
function createConfigHelper<TConfig extends Record<string, unknown>>(
|
||||
config: TConfig
|
||||
): TConfig {
|
||||
return {
|
||||
...config,
|
||||
/**
|
||||
* This property is required to allow the config to be exported,
|
||||
* while still allowing HMR to work correctly.
|
||||
*
|
||||
* It tricks Fast Refresh into thinking that the config is a React component,
|
||||
* which allows it to be updated without a full page reload.
|
||||
*/
|
||||
$$typeof: Symbol.for("react.memo"),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define a widget configuration.
|
||||
*
|
||||
* @param config The widget configuration.
|
||||
* @returns The widget configuration.
|
||||
*/
|
||||
export function defineWidgetConfig(config: WidgetConfig) {
|
||||
return createConfigHelper(config)
|
||||
}
|
||||
|
||||
/**
|
||||
* Define a route configuration.
|
||||
*
|
||||
* @param config The route configuration.
|
||||
* @returns The route configuration.
|
||||
*/
|
||||
export function defineRouteConfig(config: RouteConfig) {
|
||||
return createConfigHelper(config)
|
||||
}
|
||||
Reference in New Issue
Block a user