mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-15 18:58:11 +00:00
fix: findDOMNodes error
This commit is contained in:
parent
995785dbc9
commit
6f5342db20
@ -4,7 +4,6 @@ import { Asset, cursor, isElement, isESModule, isReactComponent, setNativeSelect
|
|||||||
import { computed, obx } from '@recore/obx';
|
import { computed, obx } from '@recore/obx';
|
||||||
import DriverUniversal from 'driver-universal';
|
import DriverUniversal from 'driver-universal';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
// @ts-ignore
|
|
||||||
import { createMemoryHistory, MemoryHistory } from 'history';
|
import { createMemoryHistory, MemoryHistory } from 'history';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { ComponentType, createElement, render as raxRender, shared } from 'rax';
|
import { ComponentType, createElement, render as raxRender, shared } from 'rax';
|
||||||
@ -404,8 +403,23 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
findDOMNodes(instance: any): Array<Element | Text> | null {
|
findDOMNodes(instance: any, selector?: string): Array<Element | Text> | null {
|
||||||
return raxFindDOMNodes(instance);
|
let el = instance;
|
||||||
|
if (selector) {
|
||||||
|
el = document.querySelector(selector);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return raxFindDOMNodes(el);
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
if (el && el.type && el.props && el.props.componentId) {
|
||||||
|
el = document.querySelector(`${el.type}[componentid=${el.props.componentId}]`);
|
||||||
|
} else {
|
||||||
|
console.error(instance);
|
||||||
|
throw new Error('This instance may not a valid element');
|
||||||
|
}
|
||||||
|
return raxFindDOMNodes(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
getClientRects(element: Element | Text) {
|
getClientRects(element: Element | Text) {
|
||||||
@ -428,7 +442,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
|
|||||||
onDocumentChange(cb: () => void) {
|
onDocumentChange(cb: () => void) {
|
||||||
this.emitter.on('documentChange', cb);
|
this.emitter.on('documentChange', cb);
|
||||||
return () => {
|
return () => {
|
||||||
this.emitter.removeListener('renderer', fn);
|
this.emitter.removeListener('documentChange', cb);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user