Files
overleaf-cep/services/web/frontend/js/features/source-editor/extensions/file-preview.ts
T
Eric Mc Sween 2d3474fbdb Merge pull request #36494 from overleaf/em-remove-visual-options
Remove the Options object from the visual editor extensions

GitOrigin-RevId: f06e60b88ef77d3a670d7d956d1a86c116d71873
2026-09-17 11:55:18 +00:00

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)),
})