UNPKG

@alilc/lowcode-renderer-core

Version:
107 lines 4.24 kB
import _extends from "@babel/runtime/helpers/extends"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _createClass from "@babel/runtime/helpers/createClass"; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import PropTypes from 'prop-types'; import baseRendererFactory from './base'; import { isEmpty } from '../utils'; import logger from '../utils/logger'; export default function addonRendererFactory() { var _AddonRenderer; var BaseRenderer = baseRendererFactory(); return _AddonRenderer = /*#__PURE__*/function (_BaseRenderer) { function AddonRenderer() { var _this; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _BaseRenderer.call.apply(_BaseRenderer, [this].concat(args)) || this; _this.__namespace = 'addon'; _this.addonKey = void 0; _this.appHelper = void 0; _this.open = void 0; _this.close = void 0; return _this; } _inheritsLoose(AddonRenderer, _BaseRenderer); var _proto = AddonRenderer.prototype; _proto.__afterInit = function __afterInit(props) { var _props$config; this.__generateCtx({ component: this }); var schema = props.__schema || {}; this.state = this.__parseData(schema.state || {}); if (isEmpty(props.config) || !((_props$config = props.config) !== null && _props$config !== void 0 && _props$config.addonKey)) { logger.warn('lce addon has wrong config'); this.setState({ __hasError: true }); return; } // 注册插件 this.addonKey = props.config.addonKey; this.appHelper.addons = this.appHelper.addons || {}; this.appHelper.addons[this.addonKey] = this; this.__initDataSource(props); this.open = this.open || function () {}; this.close = this.close || function () {}; this.__executeLifeCycleMethod('constructor', Array.prototype.slice.call(arguments)); }; _proto.componentWillUnmount = /*#__PURE__*/function () { var _componentWillUnmount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var _BaseRenderer$prototy; var config, _args = arguments; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: (_BaseRenderer$prototy = _BaseRenderer.prototype.componentWillUnmount) === null || _BaseRenderer$prototy === void 0 ? void 0 : _BaseRenderer$prototy.apply(this, Array.prototype.slice.call(_args)); // 注销插件 config = this.props.config || {}; if (config && this.appHelper.addons) { delete this.appHelper.addons[config.addonKey]; } case 3: case "end": return _context.stop(); } }, _callee, this); })); function componentWillUnmount() { return _componentWillUnmount.apply(this, arguments); } return componentWillUnmount; }(); _proto.render = function render() { var __schema = this.props.__schema; if (this.__checkSchema(__schema)) { return '插件 schema 结构异常!'; } this.__debug(AddonRenderer.displayName + " render - " + __schema.fileName); this.__generateCtx({ component: this }); this.__render(); return this.__renderContent(this.__renderContextProvider({ compContext: this })); }; return _createClass(AddonRenderer, [{ key: "utils", get: function get() { var _ref = this.context.config || {}, _ref$utils = _ref.utils, utils = _ref$utils === void 0 ? {} : _ref$utils; return _extends({}, this.appHelper.utils, utils); } }]); }(BaseRenderer), _AddonRenderer.displayName = 'AddonRenderer', _AddonRenderer.propTypes = { config: PropTypes.object, __schema: PropTypes.object }, _AddonRenderer.defaultProps = { config: {}, __schema: {} }, _AddonRenderer; }