Skip to main content

@barocss/dom-observer

Version in this checkout: 0.1.1. npm · Source

Browser MutationObserver wrapper that reports editor-related text, structure, and attribute changes.

Purpose

Use this package when integrating a custom DOM editing surface. The standard editor views already manage their own observation.

Install

npm install @barocss/dom-observer

The published package provides ES modules and TypeScript declarations. Use a bundler that supports package exports.

Public entry points

ImportRole
@barocss/dom-observerPublic JavaScript and TypeScript API

Import only these public paths. Source paths such as @barocss/dom-observer/src/... are not part of the published API.

Usage

import { MutationObserverManagerImpl } from '@barocss/dom-observer';

export function observeSurface(element: HTMLElement) {
const observer = new MutationObserverManagerImpl();
observer.setEventHandlers({ onTextChange: (change) => console.log(change.newText) });
observer.setup(element);
return () => observer.disconnect();
}

Integration notes

Do not install a second observer as a substitute for the view's input pipeline. Register event handlers before setup and disconnect when the observed surface is removed.

Documentation

License

MIT. The published archive includes the license in dist/LICENSE.