UNPKG

@nteract/monaco-editor

Version:

A React component for the monaco editor, tailored for nteract

46 lines 1.66 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.unobserve = exports.observe = void 0; const intersectionObserver_1 = __importDefault(require("./polyfill/intersectionObserver")); const monitoredIntersectables = new Map(); let viewPortObserver; function getObserverSingleton() { if (!viewPortObserver) { const IntersectionObserverImpl = window.IntersectionObserver || intersectionObserver_1.default; viewPortObserver = new IntersectionObserverImpl((entries) => { for (const entry of entries) { const element = entry.target; const editor = monitoredIntersectables.get(element); if (editor) { editor.onIntersecting(entry.isIntersecting); } } }); } return viewPortObserver; } /** * Observe the element for viewport intersection events. * @param editor * @param element * @returns callback to unobserve the element */ function observe(intersectable, element) { monitoredIntersectables.set(element, intersectable); getObserverSingleton().observe(element); return () => unobserve(element); } exports.observe = observe; /** * unobserve the element for viewport intersection events. * @param element the monitored html element */ function unobserve(element) { getObserverSingleton().unobserve(element); monitoredIntersectables.delete(element); } exports.unobserve = unobserve; //# sourceMappingURL=intersectionObserver.js.map