frontend-plugin-api: remove deprecations from createComponentExtension

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-08-19 14:49:35 +02:00
parent 9727678a7b
commit 613e199390
@@ -15,41 +15,20 @@
*/
import { lazy, ComponentType } from 'react';
import {
AnyExtensionInputMap,
ResolvedExtensionInputs,
createExtension,
createExtensionDataRef,
} from '../wiring';
import { Expand } from '../types';
import { PortableSchema } from '../schema';
import { createExtension, createExtensionDataRef } from '../wiring';
import { ComponentRef } from '../components';
/** @public */
export function createComponentExtension<
TProps extends {},
TConfig extends {},
TInputs extends AnyExtensionInputMap,
>(options: {
export function createComponentExtension<TProps extends {}>(options: {
ref: ComponentRef<TProps>;
name?: string;
disabled?: boolean;
/** @deprecated these will be removed in the future */
inputs?: TInputs;
/** @deprecated these will be removed in the future */
configSchema?: PortableSchema<TConfig>;
loader:
| {
lazy: (values: {
config: TConfig;
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
}) => Promise<ComponentType<TProps>>;
lazy: () => Promise<ComponentType<TProps>>;
}
| {
sync: (values: {
config: TConfig;
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
}) => ComponentType<TProps>;
sync: () => ComponentType<TProps>;
};
}) {
return createExtension({
@@ -57,34 +36,30 @@ export function createComponentExtension<
namespace: options.ref.id,
name: options.name,
attachTo: { id: 'app', input: 'components' },
inputs: options.inputs,
disabled: options.disabled,
configSchema: options.configSchema,
output: {
component: createComponentExtension.componentDataRef,
},
factory({ config, inputs }) {
output: [createComponentExtension.componentDataRef],
factory() {
if ('sync' in options.loader) {
return {
component: {
return [
createComponentExtension.componentDataRef({
ref: options.ref,
impl: options.loader.sync({ config, inputs }) as ComponentType,
},
};
impl: options.loader.sync() as ComponentType,
}),
];
}
const lazyLoader = options.loader.lazy;
const ExtensionComponent = lazy(() =>
lazyLoader({ config, inputs }).then(Component => ({
lazyLoader().then(Component => ({
default: Component,
})),
) as unknown as ComponentType;
return {
component: {
return [
createComponentExtension.componentDataRef({
ref: options.ref,
impl: ExtensionComponent,
},
};
}),
];
},
});
}