prism-react-editor
Version:
Lightweight, extensible code editor component for React apps
68 lines (67 loc) • 3.19 kB
TypeScript
import { PrismEditor } from '../../types';
/**
* Callback used to add extra foldable ranges to an editor.
* @param editor Editor the folding ranges are added to.
* @param currentFolds The ranges that are currently foldable.
* @returns An array of extra foldable ranges.
*/
export type FoldingRangeProvider = (editor: PrismEditor, currentFolds: [number, number][]) => [number, number][] | undefined;
export interface ReadOnlyCodeFolding {
/** The code in the editor with no ranges collapsed. */
readonly fullCode: string;
/**
* Toggles whether a range is folded. Does not cause a rerender so it's possible to
* toggle multiple folds simultaneously.
* @param lineNumber The line number of the fold.
* @param force If set to `true`, the range will only be folded.
* If `false`, the range will only be unfolded.
* If `undefined`, it will be toggled.
* @returns A boolean indicating whether or not a fold was toggled which means
* calling {@link updateFolds} in the near future is necessary.
*/
toggleFold(lineNumber: number, force?: boolean): boolean;
/** Call this after the {@link toggleFold} method to rerender the editor. */
updateFolds(): void;
}
/**
* Hook only supporting read-only editors which adds code folding to the editor.
*
* To fold XML elements, the {@link useTagMatcher} hook needs to be called.
*
* To fold bracket pairs, the {@link useBracketMatcher} hook needs to be added before.
*
* Requires styling from `prism-react-editor/code-folding.css`.
*
* @param providers By default, this extension does not add any foldable ranges and you
* must add folding range providers. This package defines multiple folding range providers
* you can import like {@link bracketFolding}, {@link tagFolding},
* {@link blockCommentFolding}, and {@link markdownFolding}. You can also define your own
* providers.
*/
declare const useReadOnlyCodeFolding: (editor: PrismEditor, ...providers: FoldingRangeProvider[]) => void;
/**
* Folding range provider that adds folding of square, round, and curly brackets.
* Requires the {@link useBracketMatcher} hook to be called before
* {@link readOnlyCodeFolding} for the provider to work.
*/
declare const bracketFolding: FoldingRangeProvider;
/**
* Folding range provider that adds folding of HTML/XML elements.
* Requires the {@link useTagMatcher} hook to be called before
* {@link readOnlyCodeFolding} for the provider to work.
*/
declare const tagFolding: FoldingRangeProvider;
/**
* Folding range provider that allows folding of block comments. For this to work,
* you need to befine block comments in the {@link languageMap} for the language.
*
* Simply pass this function as one of the arguments when calling {@link useReadOnlyCodeFolding}.
*/
declare const blockCommentFolding: FoldingRangeProvider;
/**
* Folding range provider that allows folding of titles and code blocks in markdown.
*
* Simply pass this function as one of the arguments when calling {@link useReadOnlyCodeFolding}.
*/
declare const markdownFolding: FoldingRangeProvider;
export { useReadOnlyCodeFolding, blockCommentFolding, markdownFolding, tagFolding, bracketFolding };