@prismicio/types-internal
Version:
Prismic types for Custom Types and Prismic Data
84 lines (76 loc) • 1.95 kB
text/typescript
import * as t from "io-ts"
import { Group, GroupFieldType } from "./Group"
import {
BooleanFieldType,
ColorFieldType,
DateFieldType,
EmbedFieldType,
GeoPointFieldType,
ImageFieldType,
IntegrationFieldType,
LinkFieldType,
NumberFieldType,
RangeFieldType,
RichTextFieldType,
SelectFieldType,
SeparatorFieldType,
TableFieldType,
TextFieldType,
TimestampFieldType,
} from "./nestable"
import { NestableWidget } from "./nestable/NestableWidget"
import type { SharedSlice } from "./slices/SharedSlice"
import {
DynamicSlices,
LegacySlicesFieldType,
Slices,
SlicesFieldType,
StaticSlices,
} from "./slices/Slices"
import { UID, UIDFieldType } from "./UID"
export function widgetReader<T extends StaticSlices | DynamicSlices>(
codec: t.Type<T, unknown>,
) {
return t.union([UID, NestableWidget, Group, codec])
}
export const StaticWidget = widgetReader(StaticSlices)
export type StaticWidget = t.TypeOf<typeof StaticWidget>
export const DynamicWidget = widgetReader(DynamicSlices)
export type DynamicWidget = t.TypeOf<typeof DynamicWidget>
export const FieldType = t.keyof({
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
})
export type FieldType = t.TypeOf<typeof FieldType>
export const Widgets = {
toStatic(
widget: DynamicWidget,
sharedSlices: Map<string, SharedSlice>,
): StaticWidget {
switch (widget.type) {
case "Choice":
case "Slices":
return Slices.toStatic(widget, sharedSlices)
default:
return widget
}
},
}