sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
20 lines (13 loc) • 691 B
text/typescript
import {type SchemaType} from '@sanity/types'
import {type PreviewPath} from '../types'
const DEFAULT_PREVIEW_PATHS: PreviewPath[] = [['_createdAt'], ['_updatedAt']]
/** @internal */
export function getPreviewPaths(preview: SchemaType['preview']): PreviewPath[] | undefined {
const selection = preview?.select
if (!selection) return undefined
// Transform the selection dot-notation paths into array paths.
// Example: ['object.title', 'name'] => [['object', 'title'], ['name']]
const paths = Object.values(selection).map((value) => String(value).split('.')) || []
// Return the paths with the default preview paths appended.
return paths.concat(DEFAULT_PREVIEW_PATHS)
}