UNPKG

verstak

Version:
117 lines (116 loc) 4.99 kB
import { ReactiveTreeNode, ReactiveSystem, proceedSyncOrAsync } from "reactronic"; import { Constants, ElDriver, ElImpl } from "./ElDriver.js"; export class WebDriver extends ElDriver { setNativeElement(node) { } runPreparation(node) { this.setNativeElement(node); const e = node.element.native; if (ReactiveSystem.isLogging && e !== undefined && !node.driver.isPartition) e.setAttribute(Constants.keyAttrName, node.key); const result = super.runPreparation(node); if (e == undefined && ReactiveSystem.isLogging && !node.driver.isPartition) node.element.native.setAttribute(Constants.keyAttrName, node.key); return result; } runFinalization(node, isLeader) { var _a; const element = node.element; const native = element.native; if (native) { (_a = native.resizeObserver) === null || _a === void 0 ? void 0 : _a.unobserve(native); if (isLeader) native.remove(); } super.runFinalization(node, isLeader); element.native = null; return false; } runMount(node) { const element = node.element; const native = element.native; if (native) { const sequential = node.owner.children.isStrict; const automaticHost = ReactiveTreeNode.findMatchingHost(node, n => n.element.native instanceof HTMLElement || n.element.native instanceof SVGElement); const automaticNativeHost = automaticHost !== node.owner ? automaticHost === null || automaticHost === void 0 ? void 0 : automaticHost.driver.provideHost(automaticHost).element.native : automaticHost === null || automaticHost === void 0 ? void 0 : automaticHost.element.native; if (automaticNativeHost) { if (sequential && !node.driver.isPartition) { const after = ReactiveTreeNode.findMatchingPrevSibling(node, n => n.element.native instanceof HTMLElement || n.element.native instanceof SVGElement); if (after === undefined || after.driver.isPartition) { if (automaticNativeHost !== native.parentNode || !native.previousSibling) automaticNativeHost.prepend(native); } else { const nativeAfter = after.element.native; if (nativeAfter instanceof Element) { if (nativeAfter.nextSibling !== native) automaticNativeHost.insertBefore(native, nativeAfter.nextSibling); } } } else automaticNativeHost.appendChild(native); } } } runScript(node) { const element = node.element; if (element instanceof ElImpl) element.prepareForUpdate(); let result = super.runScript(node); result = proceedSyncOrAsync(result, v => { if (element.place === undefined) { const oel = node.owner.element; if (oel instanceof ElImpl && oel.isTable) element.place = undefined; } if (gBlinkingEffectMarker) blink(element.native, ReactiveTreeNode.currentScriptPriority, node.stamp); }, e => { }); return result; } static findBrotherlyHost(node) { return ReactiveTreeNode.findMatchingHost(node, n => n.element.native instanceof HTMLElement || n.element.native instanceof SVGElement); } static findBrotherlyPrevSibling(node) { return ReactiveTreeNode.findMatchingPrevSibling(node, n => n.element.native instanceof HTMLElement || n.element.native instanceof SVGElement); } static get blinkingEffectMarker() { return gBlinkingEffectMarker; } static set blinkingEffectMarker(value) { gBlinkingEffectMarker = value; } } export class StaticDriver extends WebDriver { constructor(native, name, isRow, initialize) { super(name, isRow, initialize); this.native = native; } setNativeElement(node) { node.element.native = this.native; } } export class HtmlDriver extends WebDriver { setNativeElement(node) { node.element.native = document.createElement(node.driver.name); } } export class SvgDriver extends WebDriver { setNativeElement(node) { node.element.native = document.createElementNS("http://www.w3.org/2000/svg", node.driver.name); } } function blink(element, priority, revision) { if (element !== undefined) { const n1 = revision % 2; const n2 = 1 >> n1; const bem = gBlinkingEffectMarker; element.classList.toggle(`${bem}${priority}${n1}`, true); element.classList.toggle(`${bem}${priority}${n2}`, false); } } let gBlinkingEffectMarker = undefined;