/** * Annotation Guide Plugin * * Displays variant-specific annotation guidelines in a left-side drawer. * Fetches markdown documentation from configured URLs and renders it. */ /** * @import { PluginContext } from '../modules/plugin-context.js' * @import { ApplicationState } from '../state.js' * @import MarkdownIt from 'markdown-it' * @import { SlDrawer } from '../ui.js' * @import { annotationGuideDrawerPart } from '../templates/annotation-guide-drawer.types.js' */ import { Plugin } from '../modules/plugin-base.js' import { registerTemplate, createSingleFromTemplate } from '../modules/ui-system.js' import { createMarkdownRenderer, fetchMarkdown, renderMarkdown } from '../modules/markdown-utils.js' /** * Annotation guide information from extractor plugins * @typedef {object} AnnotationGuideInfo * @property {string} variant_id - The variant identifier * @property {"html" | "markdown"} type - The content type * @property {string} url - The URL to fetch the guide from */ // Register template await registerTemplate('annotation-guide-drawer', 'annotation-guide-drawer.html') class AnnotationGuidePlugin extends Plugin { /** @param {PluginContext} context */ constructor(context) { super(context, { name: 'annotation-guide', deps: ['help', 'extraction', 'dialog', 'logger'] }) } get #extraction() { return this.getDependency('extraction') } get #client() { return this.getDependency('client') } /** @type {SlDrawer & annotationGuideDrawerPart} */ #ui = null /** @type {MarkdownIt | null} */ #md = null /** @type {AnnotationGuideInfo[]} */ #annotationGuides = [] /** @type {string | null} */ #currentGuideUrl = null /** * @param {ApplicationState} _state */ async install(_state) { await super.install(_state) this.getDependency('logger').debug(`Installing plugin "annotation-guide"`) this.#ui = this.createUi(createSingleFromTemplate('annotation-guide-drawer', document.body)) this.#ui.closeBtn.addEventListener('click', () => this.#ui.hide()) this.#ui.openInNewWindowBtn.addEventListener('click', () => this.#openInNewWindow()) this.getDependency('help').registerTopic( 'Annotation Guide', 'file-text', () => this.open() ) this.#md = createMarkdownRenderer() // @ts-ignore window.appAnnotationGuide = this } /** * Opens the annotation guide drawer */ async open() { this.#ui.show() if (this.#annotationGuides.length === 0) { let extractors = this.#extraction.extractorInfo() if (!extractors) { extractors = await this.#client.getExtractorList() } if (extractors) { this.#annotationGuides = extractors.flatMap(e => e.annotationGuides || []) } } const variant = this.state?.variant if (variant) { await this.load(variant) } else { this.#ui.openInNewWindowBtn.hidden = true this.#ui.content.innerHTML = `
No document loaded.
Load a document to view its annotation guide.
No annotation guide is available for variant: ${variant}
Check back later or contact your administrator for documentation.
Error loading annotation guide
${errorMessage}