@@ -23,8 +23,6 @@ import {
|
||||
ResolvedExtensionInputs,
|
||||
AnyExtensionInputMap,
|
||||
createExtensionBlueprint,
|
||||
ExtensionInput,
|
||||
AnyExtensionDataRef,
|
||||
} from '../wiring';
|
||||
import { RouteRef } from '../routing';
|
||||
import { Expand } from '../types';
|
||||
@@ -99,79 +97,6 @@ export function createPageExtension<
|
||||
});
|
||||
}
|
||||
|
||||
export function createNewPageExtension<
|
||||
TConfig extends { path: string },
|
||||
TInputs extends {
|
||||
[inputName in string]: ExtensionInput<
|
||||
AnyExtensionDataRef,
|
||||
{ optional: boolean; singleton: boolean }
|
||||
>;
|
||||
},
|
||||
>(
|
||||
options: (
|
||||
| {
|
||||
defaultPath: string;
|
||||
}
|
||||
| {
|
||||
configSchema: PortableSchema<TConfig>;
|
||||
}
|
||||
) & {
|
||||
namespace?: string;
|
||||
name?: string;
|
||||
attachTo?: { id: string; input: string };
|
||||
disabled?: boolean;
|
||||
inputs?: TInputs;
|
||||
routeRef?: RouteRef;
|
||||
loader: (options: {
|
||||
config: TConfig;
|
||||
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
||||
}) => Promise<JSX.Element>;
|
||||
},
|
||||
) {
|
||||
const configSchema =
|
||||
'configSchema' in options
|
||||
? options.configSchema
|
||||
: (createSchemaFromZod(z =>
|
||||
z.object({ path: z.string().default(options.defaultPath) }),
|
||||
) as PortableSchema<TConfig>);
|
||||
|
||||
return createExtension({
|
||||
kind: 'page',
|
||||
namespace: options.namespace,
|
||||
name: options.name,
|
||||
attachTo: options.attachTo ?? { id: 'app/routes', input: 'routes' },
|
||||
configSchema,
|
||||
inputs: options.inputs,
|
||||
disabled: options.disabled,
|
||||
output: [
|
||||
coreExtensionData.routePath,
|
||||
coreExtensionData.reactElement,
|
||||
coreExtensionData.routeRef.optional(),
|
||||
],
|
||||
factory({ config, inputs, node }) {
|
||||
const ExtensionComponent = lazy(() =>
|
||||
options
|
||||
.loader({ config, inputs })
|
||||
.then(element => ({ default: () => element })),
|
||||
);
|
||||
|
||||
const outputs = [
|
||||
coreExtensionData.routePath(config.path),
|
||||
coreExtensionData.reactElement(
|
||||
<ExtensionBoundary node={node}>
|
||||
<ExtensionComponent />
|
||||
</ExtensionBoundary>,
|
||||
),
|
||||
];
|
||||
|
||||
if (options.routeRef) {
|
||||
return [...outputs, coreExtensionData.routeRef(options.routeRef)];
|
||||
}
|
||||
|
||||
return outputs;
|
||||
},
|
||||
});
|
||||
}
|
||||
/**
|
||||
* A blueprint for creating extensions for routable React page components.
|
||||
* @public
|
||||
@@ -208,7 +133,8 @@ export const PageExtensionBlueprint = createExtensionBlueprint({
|
||||
loader({ config, inputs }).then(element => ({ default: () => element })),
|
||||
);
|
||||
|
||||
// TODO(blam): this is a little awkward for optional returns. I wonder if we should be using generators or yield instead
|
||||
// TODO(blam): this is a little awkward for optional returns.
|
||||
// I wonder if we should be using generators or yield instead
|
||||
// for a better API here.
|
||||
const outputs = [
|
||||
coreExtensionData.routePath(config.path ?? defaultPath!),
|
||||
|
||||
Reference in New Issue
Block a user