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