"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getForIndexes = exports.CompRenderer = exports.getComponentRenderList = exports.DataContext = exports.ScopeContext = exports.ForContext = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const mobx_react_lite_1 = require("mobx-react-lite");
const utils_1 = require("../utils");
const lodash_es_1 = require("lodash-es");
const RenderWrapper_1 = require("./RenderWrapper");
const router_1 = require("../router");
const error_1 = require("../utils/error");
const cals_1 = require("@cloudbase/cals");
const mobx_1 = require("mobx");
const constants_1 = require("../utils/constants");
exports.ForContext = React.createContext({});
exports.ScopeContext = React.createContext({});
exports.DataContext = React.createContext({});
const getSafeComponentProps = ({ style, classNameList }) => {
    const componentProps = {};
    if (classNameList.length) {
        componentProps.className = classNameList.join(' ');
    }
    if (style && Object.keys(style).length) {
        componentProps.style = style;
    }
    return componentProps;
};
// TODO: 需要不断移除 dataBinds(style/classList)
function getBindData({ widgetData, forItems, scopeContext, codeContext, commonStyle = {}, classNameList = [], injectContext = {}, }) {
    var _a;
    // bindData
    if (Array.isArray(widgetData)) {
        widgetData =
            forItems.forIndexes === void 0 || widgetData.length === 0
                ? {}
                : (0, lodash_es_1.get)(widgetData, getForIndexes(forItems, widgetData));
    }
    widgetData = widgetData || {};
    const fieldData = Object.assign({}, widgetData);
    const isRootNode = widgetData && !widgetData.parent;
    const isInComposite = !!codeContext.$WEAPPS_COMP;
    // 再次计算 scope value
    for (let key in fieldData) {
        if (Object.prototype.hasOwnProperty.call(fieldData, key)) {
            const value = fieldData[key];
            if (value && value.__type === 'scopedValue') {
                try {
                    fieldData[key] = value.getValue(scopeContext || {});
                }
                catch (e) {
                    console.warn(`Error computing data bind '${key}' error:`, e);
                    fieldData[key] = '';
                }
            }
        }
    }
    // bindStyle
    let bindStyle = fieldData.style || {};
    /**
     * 若指令 hidden
     * 则相当于强制绑定了 display: 'none',
     */
    if (!(injectContext.checkDisplay || utils_1.checkDisplay)(fieldData)) {
        bindStyle = Object.assign(Object.assign({}, bindStyle), { display: 'none' });
    }
    // 复合组件第一层需要将最外层样式 style 挂到节点上
    let cssStyle = commonStyle || {};
    let propStyle = isInComposite && isRootNode ? ((_a = codeContext.$WEAPPS_COMP.props) === null || _a === void 0 ? void 0 : _a.style) || {} : {};
    const finalStyle = getFinalStyle(injectContext.processCssUnit, cssStyle, bindStyle, propStyle);
    // bindClassList
    const bindClassList = fieldData.classList || [];
    const finalClassNameList = getFinalClassNameList(classNameList, bindClassList);
    // 当前在复合组件中，且当前节点为根节点
    if (isInComposite && isRootNode) {
        if (widgetData.ownerWidget) {
            Object.keys(widgetData.ownerWidget).forEach((propName) => {
                if (propName === 'role' || ['aria-', 'data-'].some((prefix) => propName.startsWith(prefix))) {
                    widgetData[propName] = widgetData.ownerWidget[propName];
                }
            });
        }
    }
    // 防止渲染时 data 的 style 与实际的 style 冲突
    delete fieldData.style;
    return {
        fieldData,
        finalStyle,
        finalClassNameList: Array.from(new Set(finalClassNameList)),
    };
}
const _FOR_ERROR_CACHE_MAP = {};
function getForList(compId, dataBinds, parentForItems, dataContext, $w, $scope) {
    /**
     * For循环渲染
     * @important
     * @default undfined // 代表没有进行for循环绑定
     */
    let forList = [];
    try {
        // 绑定了 for 变量，计算值最差应该是空数组
        // 没有绑定，那就是 undefined
        clearTimeout(_FOR_ERROR_CACHE_MAP[compId]);
        let list = (dataBinds === null || dataBinds === void 0 ? void 0 : dataBinds._waFor)
            ? dataBinds._waFor(parentForItems, undefined, dataContext, $w, $scope) || []
            : undefined;
        // 绑定了for 并且计算了值，但是不是数组类型，应该进行兜底
        if (list && !Array.isArray(list)) {
            list = [];
        }
        forList = list;
    }
    catch (e) {
        if ((window === null || window === void 0 ? void 0 : window.__WEDA_LOG_LEVEL__) === 'debug') {
            // 计算值出错则使用空数组兜底
            _FOR_ERROR_CACHE_MAP[compId] = setTimeout(() => {
                console.debug(`${compId}循环绑定错误`, e);
            }, 1000);
        }
        forList = [];
    }
    if (forList && !Array.isArray(forList)) {
        _FOR_ERROR_CACHE_MAP[compId] = setTimeout(() => {
            console.warn(`${compId}循环绑定非数组值：`, forList);
        }, 1000);
        forList = [];
    }
    return forList;
}
// FieldWrapper 依赖 currentWidgets scope 因此需要添加observer
const FieldWrapper = (0, mobx_react_lite_1.observer)(_FieldWrapper);
function useObserverableRef(sourceKey = '') {
    const pureRef = React.useRef();
    const ref = React.useRef();
    const observerRef = React.useMemo(() => {
        return (0, utils_1.checkObserverInstanceRef)(sourceKey) ? (0, mobx_1.observable)(ref) : pureRef;
    }, []);
    return observerRef;
}
function useWidgetInstanceRef(widget) {
    const ref = useObserverableRef(widget === null || widget === void 0 ? void 0 : widget.widgetType);
    const _instanceRef = React.useRef();
    return React.useMemo(() => {
        if (widget) {
            if (widget._instanceRef !== _instanceRef.current) {
                _instanceRef.current = widget._instanceRef;
                widget._instanceRef.current = null;
            }
            return widget._instanceRef;
        }
        return ref;
    }, [widget === null || widget === void 0 ? void 0 : widget._instanceRef, ref]);
}
const emptyObject = {};
function _FieldWrapper({ Field, componentSchema, id, data, style = emptyObject, className = '', events, compositeParent, context, updateContext, renderSlot = false, }) {
    var _a, _b, _c, _d, _e;
    const { forContext, forIndexes, widgetsData, codeContext, 
    //  dataContext,
    virtualFields, } = context;
    // trace(true);
    const injectContext = React.useContext(router_1.InjectContext);
    const scopeContext = React.useContext(exports.ScopeContext);
    const _dataContext = React.useContext(exports.DataContext);
    const indexRef = React.useRef();
    const typeRef = React.useRef();
    const [_, forceUpate] = React.useState(0);
    const isInComposite = !!codeContext.$WEAPPS_COMP;
    const isDataContainer = (_b = (_a = componentSchema === null || componentSchema === void 0 ? void 0 : componentSchema.extra) === null || _a === void 0 ? void 0 : _a.compConfig) === null || _b === void 0 ? void 0 : _b.isDataContainer;
    const currentWidget = Array.isArray(widgetsData) ? (0, lodash_es_1.get)(widgetsData, forIndexes) : widgetsData;
    const instanceRef = useWidgetInstanceRef(currentWidget);
    // context 变化强刷一次children，同时把 currentWidget._scope?.dataContext  添加到 observer 中
    const dispose = React.useMemo(() => {
        return (0, mobx_1.autorun)((r) => {
            var _a;
            // r.trace();
            if (isDataContainer && ((_a = currentWidget === null || currentWidget === void 0 ? void 0 : currentWidget._scope) === null || _a === void 0 ? void 0 : _a.dataContext) && Object.values(currentWidget === null || currentWidget === void 0 ? void 0 : currentWidget._scope.dataContext)) {
                forceUpate((_) => {
                    return _ + 1;
                });
            }
        });
    }, []);
    React.useEffect(() => {
        return () => {
            dispose();
        };
    }, []);
    const totalContext = React.useMemo(() => {
        var _a;
        const res = isDataContainer && ((_a = currentWidget === null || currentWidget === void 0 ? void 0 : currentWidget._scope) === null || _a === void 0 ? void 0 : _a.dataContext)
            ? Object.assign(Object.assign({}, _dataContext), { [id]: currentWidget._scope.dataContext }) : _dataContext;
        return res;
    }, [_dataContext, _]);
    const watchedList = isInComposite
        ? [componentSchema]
        : [componentSchema, scopeContext, codeContext, injectContext, virtualFields];
    let staticResourceAttribute = ((_c = componentSchema.extra) === null || _c === void 0 ? void 0 : _c.staticResourceAttribute) || [];
    // 组件最终用于执行的事件函数
    const emit = React.useCallback((0, utils_1.generateEmit)((_e = (_d = (!isInComposite ? codeContext.$page : codeContext.$WEAPPS_COMP)) === null || _d === void 0 ? void 0 : _d.__internal__) === null || _e === void 0 ? void 0 : _e.$w, currentWidget, injectContext, isDataContainer
        ? [
            {
                key: `wa${Date.now().toString().slice(-8)}`,
                trigger: 'onDataChange',
                isCapturePhase: false,
                data: {},
                dataBinds: {},
                instanceFunction: ({ event }) => {
                    var _a, _b, _c, _d, _e, _f;
                    if (currentWidget === null || currentWidget === void 0 ? void 0 : currentWidget._scope) {
                        if (currentWidget._scope.dataContext) {
                            if (!(0, lodash_es_1.isEqual)(currentWidget._scope.dataContext.data, (_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.data)) {
                                currentWidget._scope.dataContext.data = (_b = event === null || event === void 0 ? void 0 : event.detail) === null || _b === void 0 ? void 0 : _b.data;
                            }
                            if (!(0, lodash_es_1.isEqual)(currentWidget._scope.dataContext.state, (_c = event === null || event === void 0 ? void 0 : event.detail) === null || _c === void 0 ? void 0 : _c.state)) {
                                currentWidget._scope.dataContext.state = (_d = event === null || event === void 0 ? void 0 : event.detail) === null || _d === void 0 ? void 0 : _d.state;
                            }
                        }
                        else {
                            currentWidget._scope.dataContext = { data: (_e = event === null || event === void 0 ? void 0 : event.detail) === null || _e === void 0 ? void 0 : _e.data, state: (_f = event === null || event === void 0 ? void 0 : event.detail) === null || _f === void 0 ? void 0 : _f.state };
                        }
                    }
                    return event.detial;
                },
            },
        ]
        : [], {}), [currentWidget]);
    // 组件最终传给组件props的，要保持引用防rerender
    const emitFn = React.useCallback((trigger, eventData, originalEvent) => {
        var _a;
        return emit(trigger, componentSchema.listenerInstances, eventData, forContext, originalEvent, scopeContext, totalContext, !isInComposite ? (_a = codeContext.$page) === null || _a === void 0 ? void 0 : _a.id : '');
    }, [componentSchema.listenerInstances, forContext, totalContext]);
    React.useLayoutEffect(() => {
        return () => {
            instanceRef.current = null;
        };
    }, []);
    React.useLayoutEffect(() => {
        return () => {
            instanceRef.current = null;
        };
    }, [currentWidget]);
    if (!Array.isArray(staticResourceAttribute)) {
        staticResourceAttribute = [];
    }
    // 判断为容器组件，则增加一个onDataChange事件
    if (isDataContainer && !(events === null || events === void 0 ? void 0 : events.includes('onDataChange'))) {
        events.push('onDataChange');
    }
    // 多个组件的 slot 属性
    const slotMetaMap = React.useMemo(() => {
        return (0, RenderWrapper_1.generateSlotMetaMap)(componentSchema, {
            scopeContext,
            codeContext,
            virtualFields,
            updateContext,
            injectContext,
        }, {
            renderSlot,
        });
    }, watchedList);
    const slotMap = React.useMemo(() => {
        return generateSlotMap(slotMetaMap, {
            forContext,
            dataContext: totalContext,
        });
    }, [slotMetaMap, totalContext, forContext]);
    const _selectableBlockEvents = React.useMemo(() => {
        var _a;
        const r = {
            // 选区的预览的click事件
            onCustomEvent: ({ order: index, blockKey }) => {
                if (index !== undefined) {
                    indexRef.current = index;
                    typeRef.current = blockKey;
                }
            },
            events: ((_a = componentSchema === null || componentSchema === void 0 ? void 0 : componentSchema.selectableBlock) === null || _a === void 0 ? void 0 : _a.events.map((item) => item.name)) || [],
            emit: (trigger, eventData, originalEvent) => {
                var _a, _b, _c;
                return emit(trigger, typeRef.current &&
                    indexRef.current !== undefined &&
                    ((_c = (_b = (_a = data === null || data === void 0 ? void 0 : data[typeRef.current]) === null || _a === void 0 ? void 0 : _a[indexRef.current]) === null || _b === void 0 ? void 0 : _b.selectableBlock) === null || _c === void 0 ? void 0 : _c.listenerInstances), eventData, forContext, originalEvent, scopeContext, totalContext);
            },
        };
        return r;
    }, [componentSchema, totalContext, scopeContext, forContext]);
    return (React.createElement(error_1.ErrorBoundary, { FallbackComponent: ({ error }) => {
            console.error(`组件${id}发生了错误，：${error}`);
            return null;
        } },
        React.createElement(exports.DataContext.Provider, { value: totalContext },
            React.createElement(Field, { ref: instanceRef, data: Object.assign(Object.assign(Object.assign({}, data), slotMap), { _selectableBlockEvents }), id: id, emit: emitFn, events: events, 
                /**
                 * @deprecated
                 * 老的复合组件
                 * 和 Slot 组件依赖
                 * 实际上应废弃
                 */
                compositeParent: compositeParent, forIndexes: forIndexes, "$node": currentWidget, "$widget": currentWidget === null || currentWidget === void 0 ? void 0 : currentWidget._userWidget, domRef: setGetDomApi(currentWidget, { codeContext }), style: style, className: className, staticResourceAttribute: staticResourceAttribute, isInComposite: isInComposite }, (0, RenderWrapper_1.getComponentChildren)(componentSchema, {
                virtualFields,
                codeContext,
                forContext,
                injectContext,
                scopeContext,
                dataContext: totalContext,
                updateContext,
            })))));
}
function SlotElementWrapper({ component, forContext, dataContext, codeContext = undefined }) {
    return component({ forContext, dataContext, codeContext });
}
function generateSlotMap(slots, { forContext, dataContext, codeContext = undefined }) {
    let map = {};
    Object.keys(slots).forEach((slotProp) => {
        let meta = slots[slotProp];
        if (meta.type === 'HOC') {
            (0, lodash_es_1.set)(map, slotProp, meta.node({ forContext, dataContext }));
        }
        else {
            (0, lodash_es_1.set)(map, slotProp, React.createElement(SlotElementWrapper, { component: meta.node, forContext: forContext, dataContext: dataContext, codeContext: codeContext }));
        }
    });
    return map;
}
function SlotWrapper(props) {
    return props.children;
}
function Page(props) {
    return props.children;
}
function getComponentRenderList(props) {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    const { key, virtualFields, renderSlot, codeContext = {}, scopeContext = {}, genericComp = { propName: '' }, emitEvents = [], componentSchema = {}, forContext = {}, injectContext = {}, rootNode = false, dataContext, updateContext, } = props;
    const compId = componentSchema.id;
    const isInComposite = !!codeContext.$WEAPPS_COMP;
    // 判断 widgets 是从 page 来的，还是组件来的
    const widgetsData = !isInComposite ? codeContext.$page.widgets[compId] : codeContext.$WEAPPS_COMP.widgets[compId];
    const classNameList = (((_a = componentSchema === null || componentSchema === void 0 ? void 0 : componentSchema.attributes) === null || _a === void 0 ? void 0 : _a.class) || '').split(/\s/).filter((item) => !!item);
    const dataBinds = ((_b = codeContext._dataBinds) === null || _b === void 0 ? void 0 : _b[compId]) || {};
    const FieldKey = genericComp.propName
        ? codeContext.node[genericComp.propName]
        : `${componentSchema.module}:${componentSchema.component}`;
    const Field = componentSchema.type === 'PAGE' ? Page : virtualFields[FieldKey];
    const context = {
        scopeContext,
        forContext,
        codeContext,
        dataContext,
        virtualFields,
    };
    if ((0, utils_1.isSlot)(componentSchema)) {
        const SlotRender = !compId ? SlotWrapper : injectContext.SlotRender || SlotWrapper;
        const slotId = `${(_d = (_c = componentSchema === null || componentSchema === void 0 ? void 0 : componentSchema.extra) === null || _c === void 0 ? void 0 : _c.__parent) === null || _d === void 0 ? void 0 : _d.id}.${compId}`;
        return (React.createElement(SlotRender, { component: slotId, componentSchema: componentSchema, isComposite: isInComposite }, (0, RenderWrapper_1.getComponentChildren)(componentSchema, Object.assign(Object.assign({}, context), { injectContext,
            updateContext }))));
    }
    /**
     * 这里逻辑的增加是为了支持 Repeater 组件和 $w 作用域
     * 此逻辑作用于 2 层循环组件绑定了 1 层循环项的数组值
     * 1. 补全 forContext.forStack
     * 2. 为 getForList 的 dataBinds._waFor 方法提供正确的 widget 实例
     */
    let currentForParentWidget = Array.isArray(widgetsData) ? (0, lodash_es_1.get)(widgetsData, forContext.forIndexes || []) : widgetsData;
    /**
     * get forIndexes 后仍为数组则说明当前节点是绑定for循环的
     * 会再多一级，此刻仅为了验证
     */
    if (Array.isArray(currentForParentWidget)) {
        /**
         * 提前判断纯属是为了减少 mobx warn
         * 不然访问空数组的[0]总是打一个 warn 出来
         */
        if (currentForParentWidget.length) {
            currentForParentWidget = (_e = currentForParentWidget[0]) === null || _e === void 0 ? void 0 : _e.parent;
        }
        else {
            currentForParentWidget = undefined;
        }
    }
    // For循环渲染
    let forList = getForList(compId, dataBinds, forContext, dataContext, (0, utils_1.generateWidgetAPIContext)((_g = (_f = (!isInComposite ? codeContext.$page : codeContext.$WEAPPS_COMP)) === null || _f === void 0 ? void 0 : _f.__internal__) === null || _g === void 0 ? void 0 : _g.$w, currentForParentWidget, forContext, scopeContext), scopeContext);
    if (forList) {
        return forList
            .map((item, index) => {
            var _a;
            let { forIndexes = [], forStack = [] } = forContext;
            const forItemsIndexes = forIndexes.concat(index);
            const currentWidget = Array.isArray(widgetsData) ? (0, lodash_es_1.get)(widgetsData, forItemsIndexes) : widgetsData;
            let forContextListAlias;
            const listMeta = { currentItem: item, currentIndex: index };
            switch (currentWidget === null || currentWidget === void 0 ? void 0 : currentWidget.widgetType) {
                case `${constants_1.REPEATER.MODULE_NAME}:${constants_1.REPEATER.REPEATER_ITEM_NAME}`:
                case `${constants_1.REPEATER.DEBUG_MODULE_NAME}:${constants_1.REPEATER.REPEATER_ITEM_NAME}`: {
                    const repeaterWidget = currentWidget.parent;
                    forContextListAlias = {
                        [`${repeaterWidget.forIndex}` || 'currentIndex']: listMeta.currentIndex,
                        [`${repeaterWidget.forItem}` || 'currentItem']: listMeta.currentItem,
                    };
                }
            }
            const forItems = Object.assign(Object.assign({}, forContext), { [compId]: item, forIndexes: forItemsIndexes, forStack: [
                    ...forStack,
                    Object.assign(Object.assign({}, listMeta), { alias: forContextListAlias }),
                ] });
            const { fieldData: forItemData, finalStyle: forItemStyle, finalClassNameList: forItemClassNameList, } = getBindData({
                widgetData: widgetsData,
                forItems,
                scopeContext,
                codeContext,
                commonStyle: (_a = componentSchema.extra) === null || _a === void 0 ? void 0 : _a.commonStyle,
                classNameList,
                injectContext: Object.assign(Object.assign({}, injectContext), { processCssUnit: isInComposite ? 'rpx' : injectContext.processCssUnit }),
            });
            const { VisiblePlaceHolder } = injectContext;
            if (!(injectContext.checkVisible || utils_1.checkVisible)(forItemData)) {
                return VisiblePlaceHolder ? React.createElement(VisiblePlaceHolder, { id: compId }) : null;
            }
            const filedElement = (React.createElement(exports.ForContext.Provider, { key: forItemData._key, value: forItems },
                React.createElement(FieldWrapper, Object.assign({ Field: Field, componentSchema: componentSchema, context: Object.assign(Object.assign({}, context), { widgetsData, forContext: forItems, forIndexes: forItemsIndexes }), id: compId, updateContext: updateContext, data: forItemData }, getSafeComponentProps({
                    style: forItemStyle,
                    classNameList: forItemClassNameList,
                }), { events: emitEvents, compositeParent: codeContext, renderSlot: renderSlot }))));
            return !(injectContext.checkDisplay || utils_1.checkDisplay)(forItemData) && VisiblePlaceHolder ? (React.createElement(VisiblePlaceHolder, { id: compId }, filedElement)) : (filedElement);
        })
            .filter((item) => !!item);
    }
    // 修正 forIndexes
    const forIndexes = getForIndexes(forContext, widgetsData);
    // 单节点渲染
    const { fieldData, finalClassNameList, finalStyle } = getBindData({
        widgetData: widgetsData,
        forItems: forContext,
        scopeContext,
        codeContext,
        commonStyle: (_h = componentSchema.extra) === null || _h === void 0 ? void 0 : _h.commonStyle,
        classNameList,
        injectContext: Object.assign(Object.assign({}, injectContext), { processCssUnit: isInComposite ? 'rpx' : injectContext.processCssUnit }),
    });
    // false 或空字符串时
    if (!(injectContext.checkVisible || utils_1.checkVisible)(fieldData)) {
        const { VisiblePlaceHolder } = injectContext;
        return VisiblePlaceHolder ? [React.createElement(VisiblePlaceHolder, { key: key, id: compId })] : [];
    }
    return [
        React.createElement(FieldWrapper, Object.assign({ key: key, Field: Field, componentSchema: componentSchema, context: Object.assign(Object.assign({}, context), { widgetsData,
                forIndexes }), id: compId, updateContext: updateContext, data: fieldData }, getSafeComponentProps({
            style: finalStyle,
            classNameList: finalClassNameList,
        }), { events: emitEvents, compositeParent: codeContext, renderSlot: renderSlot })),
    ];
}
exports.getComponentRenderList = getComponentRenderList;
exports.CompRenderer = (0, mobx_react_lite_1.observer)(function (props) {
    return getComponentRenderList(Object.assign(Object.assign({}, props), { scopeContext: React.createContext(exports.ScopeContext), forContext: React.useContext(exports.ForContext), injectContext: React.useContext(router_1.InjectContext) }));
});
function getFinalStyle(type, commonStyle = {}, bindStyle = {}, propStyle = {}) {
    const processOptions = {
        looseError: true,
        rpxCalcRoot: `var(${utils_1.CALC_RPX_ROOT_VAL_NAME})`,
    };
    const processCssUnit = type || 'rem';
    const remBindStyle = typeof bindStyle === 'object' ? (0, cals_1.processCSSPropertiesUnit)(bindStyle, processCssUnit, processOptions) : {};
    return Object.assign(Object.assign(Object.assign({}, ((0, cals_1.processCSSPropertiesUnit)(commonStyle, processCssUnit, processOptions) || {})), remBindStyle), propStyle);
}
function getFinalClassNameList(classNameList = [], bindClassList = [], widgetClassList = []) {
    return [].concat(classNameList, bindClassList, widgetClassList);
}
// HACK: 从后向前保证循环的深度与 forIndexes 一致
// 后续需要将 For 循环迁移到外层
function getForIndexes(parentForItems, widgetsData) {
    return Array.isArray(widgetsData) && widgetsData.length > 0
        ? (parentForItems.forIndexes || []).slice(0 - getDeepArrLen(widgetsData))
        : undefined;
}
exports.getForIndexes = getForIndexes;
function getDeepArrLen(arr, len = 0) {
    if (Array.isArray(arr)) {
        return getDeepArrLen(arr.length > 0 ? arr[0] : null, len + 1);
    }
    else {
        return len;
    }
}
function setGetDomApi(currentWidget, { codeContext }) {
    if (!currentWidget)
        return React.createRef();
    const isComposite = !currentWidget.widgetType.startsWith('gsd-h5-react');
    const isInComposite = !!(codeContext === null || codeContext === void 0 ? void 0 : codeContext.$WEAPPS_COMP);
    // 如果当前是复合组件，不做 getDom 的挂载
    if (!isComposite) {
        if (!currentWidget.domRef) {
            currentWidget.domRef = React.createRef();
        }
        if (!currentWidget.getDom) {
            currentWidget.getDom = (options) => (0, utils_1.getDom)(currentWidget.domRef.current, options);
        }
        if (isInComposite && // 当前在复合组件内
            !currentWidget.parent && // 当前节点为复合组件的根节点
            codeContext.node && // 复合组件的 node 已经创建
            !codeContext.node.getDom // 复合组件的 node 未挂载 getDom 方法
        ) {
            codeContext.node.domRef = currentWidget.domRef;
            codeContext.node.getDom = currentWidget.getDom;
        }
    }
    return currentWidget.domRef;
}
//# sourceMappingURL=NodeRenderer.js.map