mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 21:23:45 +01:00
Remove the Options object from the visual editor extensions GitOrigin-RevId: f06e60b88ef77d3a670d7d956d1a86c116d71873
31 lines
993 B
TypeScript
31 lines
993 B
TypeScript
import {
|
|
Compartment,
|
|
Extension,
|
|
Facet,
|
|
TransactionSpec,
|
|
} from '@codemirror/state'
|
|
import { PreviewPath } from '../../../../../types/preview-path'
|
|
|
|
export type PreviewByPath = (path: string) => PreviewPath | null
|
|
|
|
const previewByPathConf = new Compartment()
|
|
|
|
/**
|
|
* Resolves a path in the project to a preview URL. The value comes from the
|
|
* file tree, so it changes whenever the file tree does. Read it from the state
|
|
* at the point of use rather than capturing it, so decorations and widgets
|
|
* don't hold a resolver for a stale file tree.
|
|
*/
|
|
export const previewByPathFacet = Facet.define<PreviewByPath, PreviewByPath>({
|
|
combine: values => values[0] ?? (() => null),
|
|
})
|
|
|
|
export const filePreview = (previewByPath: PreviewByPath): Extension =>
|
|
previewByPathConf.of(previewByPathFacet.of(previewByPath))
|
|
|
|
export const setFilePreview = (
|
|
previewByPath: PreviewByPath
|
|
): TransactionSpec => ({
|
|
effects: previewByPathConf.reconfigure(previewByPathFacet.of(previewByPath)),
|
|
})
|