import { type ComponentType, type PropsWithChildren } from 'react'; import { type ClientFactory } from '@remkoj/optimizely-graph-client'; import { type GraphQLClient } from 'graphql-request'; import { type ContentQueryProps } from '@remkoj/optimizely-cms-react/rsc'; export type ContentRequest = (Omit, 'path'> & { path: string | null; token: string; ctx: 'edit' | 'preview'; }); type ServerPageProps = { params: Record>; searchParams: Record; }; export type EditPageComponent = ({ params, searchParams }: T) => Promise; export type EditPageProps = { params: { path?: string[] | string; lang?: string; }; searchParams: { preview_token: string; key?: string; ver?: string; loc?: string; ctx?: 'edit' | 'preview'; path?: string; epieditmode?: string; }; }; export type ValidatedEditPageProps = { params: { path?: string[] | string; lang?: string; }; searchParams: { preview_token: string; } & ({ key: string; ver: string; loc: string; ctx: 'edit' | 'preview'; path?: string; epieditmode: never; } | { key: never; ver: never; loc: never; ctx: never; path: never; epieditmode: 'true' | 'false'; }); }; export type EditViewOptions = { /** * The message to show to the editor when awaiting the data to be updated * in ContentGraph */ refreshNotice: ComponentType<{}>; /** * The layout to use when rendering a page component */ layout: ComponentType>; /** * The fourth step of the handling of a Preview/On-Page-Edit view, * which actually loads the data of content to be shown to the * editor. */ loader: GetContentByIdMethod; /** * The third step of the handling of a Preview/On-Page-Edit view, * which gets the Optimizely Graph client for the token/auth method * inferred by the contentResolver. * * @param token The token to be used * @returns The Optimizely Graph Client */ clientFactory: ClientFactory; /** * If provided, this allows to override the CommunicationInjector * path. */ communicationInjectorPath: string; /** * The second step of the handling of a Preview/On-Page-Edit view, * this actually extracts the requested content identification info * from the path and search params * * @param props The page path props and search params * @returns The requested content information */ contentResolver: (props: ValidatedEditPageProps) => ContentRequest | undefined; /** * This is the first step of the handling of a Preview/On-Page-Edit view, * where the parameters should be validated to ensure this is a correct * preview/on-page-edit request. * * @param props The page path props and search params * @param throwOnInvalid Whether an error must thrown on invalid data * @param isDevelopment Whether this request runs in development mode * @returns If the request is valid */ requestValidator: (props: EditPageProps, throwOnInvalid?: boolean, isDevelopment?: boolean) => props is ValidatedEditPageProps; /** * Enforce a refresh delay in the on page editing / preview, between a signal * has been received from the CMS and the instruction to Next.JS to actually * refresh the page. */ refreshTimeout?: number | false; }; type MayBe = T extends Array ? Array | null : T | null; export type GetContentByIdData = { content?: MayBe<{ items?: MayBe; _type?: MayBe; } & Record> | ({ __typename?: MayBe; _type?: MayBe; } & Record)>; total?: MayBe; }>; }; export type GetContentByIdMethod = (client: GraphQLClient, variables: ContentQueryProps) => Promise; export {};