@alifd/meet-react
Version:
Fusion Mobile React UI System Component
74 lines (73 loc) • 3.99 kB
JavaScript
;
exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _form = _interopRequireWildcard(require("../form"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var FieldElement = exports.default = /*#__PURE__*/function (_Component) {
_inheritsLoose(FieldElement, _Component);
function FieldElement(props) {
var _this = _Component.call(this, props) || this;
_this.field = undefined;
_this.renderPreview = _this.renderPreview.bind(_assertThisInitialized(_this));
return _this;
}
var _proto = FieldElement.prototype;
_proto.getValueName = function getValueName() {
return 'value';
};
_proto.getValue = function getValue() {
var _a;
var name = this.getValueName();
if (name in this.props) {
return this.props[name];
}
return (_a = this.field) === null || _a === void 0 ? void 0 : _a.getValue(this.props.name);
};
_proto.setValue = function setValue(value) {
var _a;
return (_a = this.field) === null || _a === void 0 ? void 0 : _a.setValue(this.props.name, value);
};
_proto.renderPreview = function renderPreview(value) {
return value;
};
_proto.renderControl = function renderControl() {
return '请重载 renderControl';
};
_proto.getProps = function getProps() {
return this.props;
};
_proto.componentWillUnmount = function componentWillUnmount() {
this.field = undefined;
};
_proto.render = function render() {
var _this2 = this;
return /*#__PURE__*/(0, _react.createElement)(_form.Context.Consumer, null, function (ctx) {
if (ctx.field && _this2.field !== ctx.field) {
_this2.field = ctx.field;
_this2.forceUpdate();
}
var item = /*#__PURE__*/(0, _react.createElement)(_form.Item, _extends({
valuePropName: _this2.getValueName(),
renderPreview: _this2.renderPreview
}, _this2.getProps()), _this2.renderControl());
if (ctx.form) {
return item;
} else {
return /*#__PURE__*/(0, _react.createElement)(_form.default, {
saveField: function saveField(field) {
_this2.field = field;
_this2.forceUpdate();
}
}, item);
}
});
};
return FieldElement;
}(_react.Component);
FieldElement.displayName = 'Field';