mirror of
https://github.com/dragonish/obsidian-heading-decorator.git
synced 2026-07-22 05:42:05 +00:00
40 lines
964 B
TypeScript
40 lines
964 B
TypeScript
import { Component } from "obsidian";
|
|
|
|
export class OutlineChildComponent extends Component {
|
|
private containerEl: HTMLElement | null;
|
|
private callback: () => void;
|
|
private observer: MutationObserver | null = null;
|
|
private config: MutationObserverInit = {
|
|
childList: true,
|
|
subtree: true,
|
|
};
|
|
|
|
constructor(containerEl: HTMLElement, callback: () => void) {
|
|
super();
|
|
this.containerEl = containerEl;
|
|
this.callback = callback;
|
|
}
|
|
|
|
onload(): void {
|
|
this.callback();
|
|
|
|
this.observer = new MutationObserver(() => {
|
|
this.observer?.disconnect();
|
|
this.callback();
|
|
if (this.containerEl) {
|
|
this.observer?.observe(this.containerEl, this.config);
|
|
}
|
|
});
|
|
|
|
if (this.containerEl) {
|
|
this.observer.observe(this.containerEl, this.config);
|
|
}
|
|
}
|
|
|
|
onunload(): void {
|
|
this.observer?.takeRecords();
|
|
this.observer?.disconnect();
|
|
this.observer = null;
|
|
this.containerEl = null;
|
|
}
|
|
}
|