Skip to content

Commit

Permalink
fix(sanity): add missing exports
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard committed Oct 4, 2022
1 parent e775bbc commit 96bdc11
Show file tree
Hide file tree
Showing 42 changed files with 164 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './GetHookCollectionState'
export * from './types'
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const RENDER_CALLBACK_NAMES: Record<ComponentNames, RenderComponentCallbackNames
ToolMenu: 'renderToolMenu',
}

interface CreateRenderComponentProps {
export interface CreateRenderComponentProps {
componentName: ComponentNames
config: SourceOptions
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/core/config/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function resolveConfig(config: Config): Observable<Workspace[]> {
)
}

type CreateWorkspaceFromConfigOptions =
export type CreateWorkspaceFromConfigOptions =
| SingleWorkspace
| (SingleWorkspace & {
currentUser: CurrentUser
Expand Down
52 changes: 10 additions & 42 deletions packages/sanity/src/core/form/index.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,19 @@
/* eslint-disable camelcase */

export type {ArrayInputProps} from './inputs/arrays/ArrayOfObjectsInput/ArrayInput'
export * from './inputs/arrays/ArrayOfObjectsInput'

export * from './inputs/PortableText/PortableTextInput'
export {PortableTextInput as BlockEditor} from './inputs/PortableText/PortableTextInput'
/*
* sanity/form
*/

export * from './FormBuilderContext'
export * from './FormInput'
export * from './components/formField'
export * from './inputs'
export * from './members'

export * from './patch/PatchChannel'
export * from './patch/PatchEvent'
export * from './patch/patch'
export * from './patch/types'

export * from './patch'
export * from './store'
export * from './studio'

export * from './types'

export {setAtPath} from './store/stateTreeHelper'
export * from './store/useFormState'
export * from './store/types'
export {getExpandOperations} from './store/utils/getExpandOperations'

export * from './useFormBuilder'
export * from './useFormValue'

export * from './utils/mutationPatch'
export * from './utils/path'

export {FormInput} from './FormInput'

export {type ImageUrlBuilder} from './inputs/files/types'
export {type FileInputProps as BaseFileInputProps} from './inputs/files/FileInput'
export {type ImageInputProps as BaseImageInputProps} from './inputs/files/ImageInput'

export type {CrossDatasetReferenceInputProps} from './inputs/CrossDatasetReferenceInput'

export type {PortableTextEditorElement} from './inputs/PortableText/Compositor'

export type {RenderBlockActionsCallback, RenderBlockActionsProps} from './inputs/PortableText/types'

export * from './inputs/ObjectInput'

export type {FIXME_SanityDocument} from './store/formState' // eslint-disable-line camelcase

export * from './components/formField'

export type {FormInputAbsolutePathArg, FormInputRelativePathArg} from './FormInput'

export type {FormBuilderContextValue} from './FormBuilderContext'
export {useFormBuilder} from './useFormBuilder'
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './CrossDatasetReferenceInput'
export * from './types'
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,3 @@ export interface CrossDatasetSearchHit {
type: string
published: undefined | {_id: string; _type: string}
}

// export interface BaseInputProps {
// type: CrossDatasetReferenceSchemaType
// markers: Marker[]
// id?: string
// focusPath: Path
// readOnly?: boolean
// onSearch: SearchFunction
// onFocus?: (path: Path) => void
// onBlur?: () => void
// getReferenceInfo: (
// doc: {_id: string; _type?: string},
// type: CrossDatasetReferenceSchemaType
// ) => Observable<CrossDatasetReferenceInfo>
// onChange: (event: PatchEvent) => void
// level: number
// presence: FormFieldPresence[]
// }
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,49 @@ import {InvalidFileWarning} from './InvalidFileWarning'
// We alias DOM File type here to distinguish it from the type of the File value
type DOMFile = globalThis.File

export interface File extends Partial<BaseFile> {
export interface BaseFileInputValue extends Partial<BaseFile> {
_upload?: UploadState
}

function passThrough({children}: {children?: React.ReactNode}) {
return children
}

export interface FileInputProps extends ObjectInputProps<File, FileSchemaType> {
export interface BaseFileInputProps extends ObjectInputProps<BaseFileInputValue, FileSchemaType> {
assetSources: AssetSource[]
directUploads?: boolean
observeAsset: (documentId: string) => Observable<FileAsset>
resolveUploader: UploaderResolver
client: SanityClient
}
type FileInputState = {

export interface BaseFileInputState {
isUploading: boolean
selectedAssetSource: AssetSource | null
hoveringFiles: FileInfo[]
isStale: boolean
isMenuOpen: boolean
}

type Focusable = {
export type Focusable = {
focus: () => void
}
const ASSET_FIELD_PATH = ['asset']

export class FileInput extends React.PureComponent<FileInputProps, FileInputState> {
export class BaseFileInput extends React.PureComponent<BaseFileInputProps, BaseFileInputState> {
_focusRef: Focusable | null = null
_assetFieldPath: Path
uploadSubscription: Subscription | null = null

state: FileInputState = {
state: BaseFileInputState = {
isUploading: false,
selectedAssetSource: null,
hoveringFiles: [],
isStale: false,
isMenuOpen: false,
}

constructor(props: FileInputProps) {
constructor(props: BaseFileInputProps) {
super(props)
this._assetFieldPath = props.path.concat(ASSET_FIELD_PATH)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {fireEvent, waitFor} from '@testing-library/react'
import React from 'react'
import {Observable, of} from 'rxjs'
import {renderFileInput} from '../../../../../../../test/form'
import {FileInput} from '../FileInput'
import {BaseFileInput} from '../FileInput'

const observeAssetStub = (): Observable<FileAsset> =>
of({
Expand All @@ -26,7 +26,7 @@ describe('FileInput with empty state', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} />,
render: (inputProps) => <BaseFileInput {...inputProps} />,
})

expect(result.queryByTestId('file-button-input')!.getAttribute('value')).toBe('')
Expand All @@ -47,7 +47,7 @@ describe('FileInput with empty state', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} />,
render: (inputProps) => <BaseFileInput {...inputProps} />,
})

expect(result.queryByTestId('file-input-upload-button')).toBeInTheDocument()
Expand All @@ -62,7 +62,7 @@ describe('FileInput with empty state', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} assetSources={[]} />,
render: (inputProps) => <BaseFileInput {...inputProps} assetSources={[]} />,
})

expect(result.queryByTestId('file-input-upload-button')).toBeInTheDocument()
Expand All @@ -78,7 +78,10 @@ describe('FileInput with empty state', () => {
},
observeAsset: observeAssetStub,
render: (inputProps) => (
<FileInput {...inputProps} assetSources={[{name: 'source1'}, {name: 'source2'}] as any} />
<BaseFileInput
{...inputProps}
assetSources={[{name: 'source1'}, {name: 'source2'}] as any}
/>
),
})

Expand All @@ -105,7 +108,7 @@ describe('FileInput with empty state', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} directUploads={false} />,
render: (inputProps) => <BaseFileInput {...inputProps} directUploads={false} />,
})

expect(result.queryByTestId('file-input-upload-button')!.getAttribute('data-disabled')).toBe(
Expand All @@ -121,7 +124,7 @@ describe('FileInput with empty state', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} directUploads={false} />,
render: (inputProps) => <BaseFileInput {...inputProps} directUploads={false} />,
})

expect(result.queryByText(`Can't upload files here`)).toBeInTheDocument()
Expand All @@ -137,7 +140,7 @@ describe('FileInput with empty state', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} readOnly />,
render: (inputProps) => <BaseFileInput {...inputProps} readOnly />,
})

expect(result.queryByTestId('file-input-upload-button')!.getAttribute('data-disabled')).toBe(
Expand All @@ -153,7 +156,7 @@ describe('FileInput with empty state', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} readOnly />,
render: (inputProps) => <BaseFileInput {...inputProps} readOnly />,
})

expect(result.queryByTestId('file-input-browse-button')!.getAttribute('data-disabled')).toBe(
Expand All @@ -169,7 +172,7 @@ describe('FileInput with empty state', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} readOnly />,
render: (inputProps) => <BaseFileInput {...inputProps} readOnly />,
})

const input = result.queryByTestId('file-button-input')
Expand Down Expand Up @@ -205,7 +208,7 @@ describe('FileInput with asset', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} value={value} />,
render: (inputProps) => <BaseFileInput {...inputProps} value={value} />,
})

expect(result.queryByText('cats.txt')).toBeInTheDocument()
Expand All @@ -230,7 +233,7 @@ describe('FileInput with asset', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} value={value} />,
render: (inputProps) => <BaseFileInput {...inputProps} value={value} />,
})

fireEvent.click(result.queryByTestId('options-menu-button')!)
Expand All @@ -248,7 +251,7 @@ describe('FileInput with asset', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} assetSources={[]} value={value} />,
render: (inputProps) => <BaseFileInput {...inputProps} assetSources={[]} value={value} />,
})

fireEvent.click(result.queryByTestId('options-menu-button')!)
Expand All @@ -268,7 +271,7 @@ describe('FileInput with asset', () => {
},
observeAsset: observeAssetStub,
render: (inputProps) => (
<FileInput
<BaseFileInput
{...inputProps}
assetSources={[{name: 'source1'}, {name: 'source2'}] as any}
value={value}
Expand All @@ -294,7 +297,7 @@ describe('FileInput with asset', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} directUploads={false} value={value} />,
render: (inputProps) => <BaseFileInput {...inputProps} directUploads={false} value={value} />,
})

fireEvent.click(result.queryByTestId('options-menu-button')!)
Expand All @@ -316,7 +319,7 @@ describe('FileInput with asset', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} readOnly value={value} />,
render: (inputProps) => <BaseFileInput {...inputProps} readOnly value={value} />,
})

fireEvent.click(result.queryByTestId('options-menu-button')!)
Expand All @@ -336,7 +339,7 @@ describe('FileInput with asset', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} readOnly value={value} />,
render: (inputProps) => <BaseFileInput {...inputProps} readOnly value={value} />,
})

fireEvent.click(result.queryByTestId('options-menu-button')!)
Expand All @@ -355,7 +358,7 @@ describe('FileInput with asset', () => {
},
observeAsset: observeAssetStub,
render: (inputProps) => (
<FileInput
<BaseFileInput
{...inputProps}
assetSources={[{name: 'source1'}, {name: 'source2'}] as any}
readOnly
Expand Down Expand Up @@ -384,7 +387,7 @@ describe('FileInput with asset', () => {
type: 'file',
},
observeAsset: observeAssetStub,
render: (inputProps) => <FileInput {...inputProps} readOnly value={value} />,
render: (inputProps) => <BaseFileInput {...inputProps} readOnly value={value} />,
})

fireEvent.click(result.queryByTestId('options-menu-button')!)
Expand Down Expand Up @@ -430,7 +433,7 @@ describe('FileInput with asset', () => {
},
observeAsset: observeAssetStub,
render: (inputProps) => (
<FileInput
<BaseFileInput
{...inputProps}
readOnly
schemaType={fileType as any as FileSchemaType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ import {ImageActionsMenu} from './ImageActionsMenu'
import {ImagePreview} from './ImagePreview'
import {InvalidImageWarning} from './InvalidImageWarning'

export interface Image extends Partial<BaseImage> {
export interface BaseImageInputValue extends Partial<BaseImage> {
_upload?: UploadState
}

export interface ImageInputProps extends ObjectInputProps<Image, ImageSchemaType> {
export interface BaseImageInputProps
extends ObjectInputProps<BaseImageInputValue, ImageSchemaType> {
assetSources: AssetSource[]
directUploads?: boolean
imageUrlBuilder: ImageUrlBuilder
Expand All @@ -79,7 +80,7 @@ type FileInfo = {
kind: string // 'file' or 'string'
}

type ImageInputState = {
type BaseImageInputState = {
isUploading: boolean
selectedAssetSource: AssetSource | null
// Metadata about files currently over the drop area
Expand All @@ -101,20 +102,20 @@ const ASSET_FIELD_PATH = ['asset']

const ASSET_IMAGE_MENU_POPOVER: MenuButtonProps['popover'] = {portal: true}

export class ImageInput extends React.PureComponent<ImageInputProps, ImageInputState> {
export class BaseImageInput extends React.PureComponent<BaseImageInputProps, BaseImageInputState> {
_assetElementRef: null | Focusable = null
_assetPath: Path
uploadSubscription: null | Subscription = null

state: ImageInputState = {
state: BaseImageInputState = {
isUploading: false,
selectedAssetSource: null,
hoveringFiles: [],
isStale: false,
isMenuOpen: false,
}

constructor(props: ImageInputProps) {
constructor(props: BaseImageInputProps) {
super(props)
this._assetPath = props.path.concat(ASSET_FIELD_PATH)
}
Expand Down
Loading

0 comments on commit 96bdc11

Please sign in to comment.