import { Slice } from "../types/value/slice.js"; //#region src/helpers/mapSliceZone.d.ts /** * Convert a value to a lazyily loaded module. This is useful when using functions like `() => * import("...")`. */ type LazyModule = () => Promise; /** Mark a type as potentially lazy-loaded via a module. */ type MaybeLazyModule = T | LazyModule; type AnyFunction = (...args: any[]) => any; /** * Returns the type of a `SliceLike` type. * * @typeParam Slice - The Slice from which the type will be extracted. */ type ExtractSliceType = TSlice extends SliceLikeRestV2 ? TSlice["slice_type"] : TSlice extends SliceLikeGraphQL ? TSlice["type"] : never; /** * The minimum required properties to represent a Prismic slice from the Prismic Content API for the * `mapSliceZone()` helper. * * @typeParam SliceType - Type name of the slice. */ type SliceLikeRestV2 = Pick, "id" | "slice_type">; /** * The minimum required properties to represent a Prismic slice from the Prismic GraphQL API for the * `mapSliceZone()` helper. * * @typeParam SliceType - Type name of the slice. */ type SliceLikeGraphQL = { type: Slice["slice_type"]; }; /** * The minimum required properties to represent a Prismic slice for the `mapSliceZone()` helper. * * If using Prismic's Content API, use the `Slice` export from `@prismicio/client` for a full * interface. * * @typeParam SliceType - Type name of the slice. */ type SliceLike = SliceLikeRestV2 | SliceLikeGraphQL; /** * A looser version of the `SliceZone` type from `@prismicio/client` using `SliceLike`. * * If using Prismic's Content API, use the `SliceZone` export from `@prismicio/client` for the full * type. * * @typeParam TSlice - The type(s) of a slice in the slice zone. */ type SliceZoneLike = readonly TSlice[]; /** * A set of properties that identify a Slice as having been mapped. Consumers of the mapped Slice * Zone can use these properties to detect and specially handle mapped Slices. */ type MappedSliceLike = { /** * If `true`, this Slice has been modified from its original value using a mapper. * * @internal */ __mapped: true; }; /** * Arguments for a function mapping content from a Prismic Slice using the `mapSliceZone()` helper. * * @typeParam TSlice - The Slice passed as a prop. * @typeParam TContext - Arbitrary data passed to `mapSliceZone()` and made available to all Slice * mappers. */ type SliceMapperArgs = { /** Slice data. */slice: TSlice; /** The index of the Slice in the Slice Zone. */ index: number; /** All Slices from the Slice Zone to which the Slice belongs. */ slices: SliceZoneLike; /** Arbitrary data passed to `mapSliceZone()` and made available to all Slice mappers. */ context: TContext; }; /** A record of mappers. */ type SliceMappers = { [P in ExtractSliceType]?: MaybeLazyModule>, any, TContext>> }; /** * A function that maps a Slice and its metadata to a modified version. The return value will * replace the Slice in the Slice Zone. */ type SliceMapper | undefined | void = Record | undefined | void, TContext = unknown> = (args: SliceMapperArgs) => TMappedSlice | Promise; /** Unwraps a lazily loaded mapper module. */ type ResolveLazySliceMapperModule | LazyModule> = TSliceMapper extends LazyModule ? Awaited> extends { default: unknown; } ? Awaited>["default"] : Awaited> : TSliceMapper; /** Transforms a Slice into its mapped version. */ type MapSliceLike, TSliceMappers extends SliceMappers> = TSliceLike extends Slice ? TSliceLike["slice_type"] extends keyof TSliceMappers ? TSliceMappers[TSliceLike["slice_type"]] extends AnyFunction ? SliceLikeRestV2 & MappedSliceLike & Awaited>> : TSliceLike : TSliceLike : TSliceLike extends SliceLikeGraphQL ? TSliceLike["type"] extends keyof TSliceMappers ? TSliceMappers[TSliceLike["type"]] extends AnyFunction ? SliceLikeGraphQL & MappedSliceLike & Awaited>> : TSliceLike : TSliceLike : never; /** * Transforms a Slice Zone using a set of mapping functions, one for each type of Slice. Mapping * functions can be async. * * Whenever possible, use this function on the server to minimize client-side processing. * * @example * ;```typescript * const mappedSliceZone = await mapSliceZone(page.data.slices, { * code_block: ({ slice }) => ({ * codeHTML: await highlight(slice.primary.code), * }), * }); * ``` */ declare function mapSliceZone, TContext = unknown>(sliceZone: SliceZoneLike, mappers: TSliceMappers, context?: TContext): Promise[]>; //#endregion export { SliceMapper, mapSliceZone }; //# sourceMappingURL=mapSliceZone.d.ts.map