@sanity/code-input
Version:
Sanity input component for code, powered by CodeMirror
122 lines (104 loc) • 2.4 kB
text/typescript
import type {Extension} from '@codemirror/state'
import {JSX as JSX_2} from 'react'
import {ObjectDefinition} from 'sanity'
import {ObjectInputProps} from 'sanity'
import {ObjectSchemaType} from 'sanity'
import {Plugin as Plugin_2} from 'sanity'
import {PreviewConfig} from 'sanity'
import {PreviewProps} from 'sanity'
/**
* @public
*/
export declare interface CodeDefinition
extends Omit<ObjectDefinition, 'type' | 'fields' | 'options'> {
type: typeof codeTypeName
options?: CodeOptions
}
/** @public */
export declare function CodeInput(props: CodeInputProps): JSX_2.Element
/**
* @public
*/
export declare const codeInput: Plugin_2<void | CodeInputConfig>
declare interface CodeInputConfig {
codeModes?: CodeMode[]
}
export declare interface CodeInputLanguage {
title: string
value: string
mode?: string
}
/**
* @public
*/
export declare interface CodeInputProps extends ObjectInputProps<CodeInputValue, CodeSchemaType> {}
/**
* @public
*/
export declare interface CodeInputValue {
_type?: 'code'
code?: string
filename?: string
language?: string
highlightedLines?: number[]
}
declare interface CodeMode {
name: string
loader: ModeLoader
}
/**
* @public
*/
export declare interface CodeOptions {
theme?: string
darkTheme?: string
languageAlternatives?: CodeInputLanguage[]
language?: string
withFilename?: boolean
}
/**
* @public
*/
export declare const codeSchema: {
type: 'object'
name: 'code'
} & Omit<ObjectDefinition, 'preview'> & {
preview?:
| PreviewConfig<
{
language: string
code: string
filename: string
highlightedLines: string
},
Record<'code' | 'language' | 'filename' | 'highlightedLines', any>
>
| undefined
}
/**
* @public
*/
export declare interface CodeSchemaType extends Omit<ObjectSchemaType, 'options'> {
options?: CodeOptions
}
/**
* @public
*/
export declare const codeTypeName: 'code'
declare type ModeLoader = () => Promise<Extension | undefined> | Extension | undefined
/**
* @public
*/
export declare function PreviewCode(props: PreviewCodeProps): JSX_2.Element
/**
* @public
*/
export declare interface PreviewCodeProps extends PreviewProps {
selection?: CodeInputValue
}
export {}
declare module '@sanity/types' {
interface IntrinsicDefinitions {
code: CodeDefinition
}
}