UNPKG

@knxcloud/lowcode-hooks

Version:
62 lines (61 loc) 1.52 kB
import { inject, getCurrentInstance } from "vue"; function getCurrentNodeKey() { let key = window.__currentNode; if (!key) { key = Symbol("__currentNode"); window.__currentNode = key; } return key; } function useCurrentNode() { const key = getCurrentNodeKey(); return inject( key, () => { return { mode: "live", node: null, isDesignerEnv: false }; }, true ); } function getRendererContextKey() { let key = window.__rendererContext; if (!key) { key = Symbol("__rendererContext"); window.__rendererContext = key; } return key; } function useRendererContext() { const key = getRendererContextKey(); return inject( key, () => { var _a, _b; const props = (_b = (_a = getCurrentInstance()) == null ? void 0 : _a.props) != null ? _b : {}; return { rerender: () => void 0, thisRequiredInJSE: true, components: getPropValue(props, "components", {}), designMode: getPropValue(props, "designMode", "live"), getNode: getPropValue(props, "getNode", () => null), wrapLeafComp: (_, __, leaf) => leaf, triggerCompGetCtx: getPropValue(props, "triggerCompGetCtx", () => void 0) }; }, true ); } function getPropValue(props, key, defaultValue) { return props[key] || props[`__${key}`] || defaultValue; } export { getCurrentNodeKey, getRendererContextKey, useCurrentNode, useRendererContext }; //# sourceMappingURL=lowcode-hooks.mjs.map