sk-react-antd
Version:
React AntD fro ShaneKing
167 lines (135 loc) • 6.98 kB
JavaScript
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
import PropTypes from 'prop-types';
import React from 'react';
import { Proxy0, SK } from 'sk-js';
import { Comp, Model, Reacts, SKDiv } from 'sk-react';
import { SIZE } from './AntdConst';
/**
* 1.The defaultProps and propTypes of AntD just can be use in wrapper Comp or non-Comp
* 2.if origin exist, must be use origin
*/
var AntdComp =
/*#__PURE__*/
function (_Comp) {
_inherits(AntdComp, _Comp);
function AntdComp() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, AntdComp);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(AntdComp)).call.apply(_getPrototypeOf2, [this].concat(args)));
_this.SK_COMP_NAME = AntdComp.SK_COMP_NAME;
return _this;
} // react
_createClass(AntdComp, [{
key: "componentDidMount",
value: function componentDidMount() {
_get(_getPrototypeOf(AntdComp.prototype), "componentDidMount", this).call(this);
this.addAllErroredMonitor();
this.addExtendErroredMonitor();
}
}, {
key: "componentWillUpdate",
value: function componentWillUpdate() {
this.rmvAllErroredMonitor();
this.rmvExtendErroredMonitor();
_get(_getPrototypeOf(AntdComp.prototype), "componentWillUpdate", this).call(this);
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
_get(_getPrototypeOf(AntdComp.prototype), "componentDidUpdate", this).call(this);
this.addAllErroredMonitor();
this.addExtendErroredMonitor();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.rmvAllErroredMonitor();
this.rmvExtendErroredMonitor();
_get(_getPrototypeOf(AntdComp.prototype), "componentWillUnmount", this).call(this);
} // monitor
}, {
key: "addAllErroredMonitor",
value: function addAllErroredMonitor() {
var _this2 = this;
Model.parseSao(this.props.monitor).forEach(function (idOrReg) {
_this2.addErroredMonitor(idOrReg);
}); //Self value monitor
if (this.getModelId()) {
this.addErroredMonitor(this.getModelId());
}
}
}, {
key: "addErroredMonitor",
value: function addErroredMonitor(idOrReg) {
if (this.monitors.indexOf(idOrReg) < 0) {
this.monitors.push(idOrReg);
}
if (Proxy0._.isRegExp(idOrReg)) {
this.skModel().addRegErroredListener(idOrReg, this.updateUI);
} else {
this.skModel().addIdErroredListener(idOrReg, this.updateUI);
}
}
}, {
key: "addExtendErroredMonitor",
value: function addExtendErroredMonitor() {}
}, {
key: "rmvAllErroredMonitor",
value: function rmvAllErroredMonitor() {
var _this3 = this;
this.monitors.forEach(function (idOrReg) {
_this3.rmvErroredMonitor(idOrReg);
});
}
}, {
key: "rmvErroredMonitor",
value: function rmvErroredMonitor(idOrReg) {
if (Proxy0._.isRegExp(idOrReg)) {
this.skModel().rmvRegErroredListener(idOrReg, this.updateUI);
} else {
this.skModel().rmvIdErroredListener(idOrReg, this.updateUI);
}
this.monitors.skRmv(idOrReg);
}
}, {
key: "rmvExtendErroredMonitor",
value: function rmvExtendErroredMonitor() {} //@Deprecated
}, {
key: "hasSpecialChild",
value: function hasSpecialChild(specialChildName) {
return Reacts.some(this.props.children, function ($child) {
return $child.type && $child.type.name === specialChildName;
}, this);
}
}, {
key: "renderAntdCompPreview",
value: function renderAntdCompPreview() {
return React.createElement(SKDiv, null, this.m2v());
}
}]);
return AntdComp;
}(Comp);
AntdComp.SK_COMP_NAME = 'AntdComp';
AntdComp.SK_PROPS = SK.extends(true, {}, Comp.SK_PROPS, {
SIZE: 'size'
});
AntdComp.defaultProps = SK.extends(true, {}, Comp.defaultProps, {});
AntdComp.propTypes = SK.extends(true, {}, Comp.propTypes, {
size: PropTypes.oneOf(Object.values(SIZE)),
skSize: PropTypes.oneOf(Object.values(SIZE))
});
export { AntdComp as default };