Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445// src/plugin/markdown-render-child.ts/** * MarkdownRenderChild — child component bound to a markdown render context. * * Plugins (e.g. Strange New Worlds, Dataview) subclass this to attach widgets * to markdown-rendered DOM. The child's onload()/onunload() are called by the * parent Component (via MarkdownPostProcessorContext.addChild) and the * containerEl is the DOM node the plugin renders into. * * Lives in its own module to avoid the circular import that would otherwise * exist between obsidian-stubs.ts (large barrel) and markdown-renderer-impl.ts. * * See https://docs.obsidian.md/Reference/TypeScript+API/MarkdownRenderChild */
import { Component } from './component'
export class MarkdownRenderChild extends Component { containerEl: HTMLElement
constructor(containerEl: HTMLElement) { super() this.containerEl = containerEl }
/** DOM lifecycle helpers used by Obsidian-compatible live renderers. */ isShown(): boolean { return this.containerEl.isConnected }
onNodeInserted(callback: () => void): () => void { let active = true const invoke = () => { if (!active || !this.containerEl.isConnected) return active = false observer.disconnect() callback() } const observer = new MutationObserver(invoke) if (this.containerEl.isConnected) queueMicrotask(invoke) else if (document.body) observer.observe(document.body, { childList: true, subtree: true }) return () => { active = false; observer.disconnect() } }}