Skip to content

Commit

Permalink
refactor(base): import preview-resolver part from central location
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Sep 10, 2021
1 parent 3696728 commit 5791530
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
22 changes: 0 additions & 22 deletions packages/@sanity/base/src/components/Preview.js

This file was deleted.

21 changes: 21 additions & 0 deletions packages/@sanity/base/src/components/Preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'
import {SchemaType} from '@sanity/types'
import {previewResolver as resolvePreview} from '../legacyParts'

interface PreviewProps {
layout?: string
value?: unknown
type: SchemaType
}

export default function Preview(props: PreviewProps) {
const {type, value, layout} = props

const PreviewComponent = resolvePreview(type)

return PreviewComponent ? (
<PreviewComponent type={type} value={value} layout={layout} />
) : (
<div>No preview for {JSON.stringify(value)}</div>
)
}
6 changes: 6 additions & 0 deletions packages/@sanity/base/src/legacyParts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @todo: remove the following line when part imports has been removed from this file
///<reference types="@sanity/types/parts" />

import previewResolver from 'part:@sanity/base/preview-resolver?'

export {previewResolver}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// @todo: remove the following line when part imports has been removed from this file
///<reference types="@sanity/types/parts" />

import React from 'react'
import customResolver from 'part:@sanity/base/preview-resolver?'
import {isReferenceSchemaType} from '@sanity/types'
import {get} from 'lodash'
import {previewResolver as customResolver} from '../../legacyParts'
import {Type} from '../types'
import SanityDefaultPreview from './SanityDefaultPreview'
import {isReferenceSchemaType} from '@sanity/types'

// Set this to true for debugging preview subscriptions
const DEBUG = false
Expand Down

0 comments on commit 5791530

Please sign in to comment.