I have a widget which adds a Google Maps embedding. The problem is that when I scroll below and the map goes out of the viewport, the DOM node gets deleted, and recreated when back in view so the zoom level I set is gone.
Is there any way to prevent widgets of a certain widget type from getting deleted?
No. Content outside of the viewport is removed from the DOM. You may, if the maps widget can handle being detached and reattached, be able to set up something like a caching layer where you reuse the same rendered DOM on a re-render, but the editor itself won’t keep out-of-view content in the DOM.
Do you mean something like doing a removeChild when the Widget’s destroy method is called and returning the node returned by removeChild when toDOM is called?
I tried the following and it doesn’t seem to work:
let elements = [];
for (let i = 0; i < 1000; i++) {
// elements.push(htmlToElement('<input type="checkbox"/>'))
elements.push(htmlToElement(mapHTML))
}
class MapWidget extends WidgetType {
destroy(dom: HTMLElement) {
let child = dom.removeChild(dom.firstChild);
console.log("caching ", child);
elements[this.index] = child;
}
toDOM(view: EditorView) {
const container = document.createElement('div')
container.appendChild(elements[this.index]);
return container;
}