UNPKG

@doreamonjs/gate

Version:
89 lines 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const react_1 = tslib_1.__importStar(require("react")); const dva_1 = require("dva"); const doreamon_1 = tslib_1.__importDefault(require("@zodash/doreamon")); const components_1 = require("@doreamonjs/components"); const form = tslib_1.__importStar(require("@doreamonjs/plugin-form")); const NAMESPACE = form.NAMESPACE; const mapState = (states) => { const { visible, attributes, datasets } = states[NAMESPACE]; const { target = {} } = attributes; const nextEffect = `${target.namespace}/${target.effect}`; const loading = states.loading.effects[nextEffect]; return { ...attributes, ...datasets, // visible, loading, values: datasets.values, }; }; const mapActions = (dispatch) => ({ onChange: (key, value, values, context) => dispatch({ type: `${NAMESPACE}/value/change`, payload: { key, value, values, context, }, }), onCancel: () => dispatch({ type: `${NAMESPACE}/cancel` }), onSubmit: (values, lastValues, callback) => dispatch({ type: `${NAMESPACE}/submit`, payload: { values, lastValues, callback, }, }), // onActionTrigger: (namespace, action, data) => dispatch({ type: `${namespace}/dispatcher`, payload: { meta: action, data }, }), }); let ModalForm = class ModalForm extends react_1.PureComponent { get key() { if (this.props.name) { return this.props.name; } if (this.props.alwaysRecreate) { return String(Math.random()); } return this.props.fields.map(e => e.dataIndex || e.key).join('-'); } get fields() { return this.props.fields.map((field) => { return doreamon_1.default.immer.produce(field, (draft) => { var _a; if ((_a = draft.extra) === null || _a === void 0 ? void 0 : _a.action) { const { namespace, key } = draft.extra.action; draft.extra.action.onClick = () => { var _a, _b; (_b = (_a = this.props).onActionTrigger) === null || _b === void 0 ? void 0 : _b.call(_a, namespace, { key }); }; } }); }); } render() { const { type, onActionTrigger, ...props } = this.props; const key = this.key; if (type === 'drawer') { return (react_1.default.createElement(components_1.Form.Drawer, { key: key, ...props, fields: this.fields })); } return (react_1.default.createElement(components_1.Form.Modal, { key: key, ...props, fields: this.fields })); } }; ModalForm.defaultProps = { type: 'modal', }; ModalForm = tslib_1.__decorate([ dva_1.connect(mapState, mapActions) ], ModalForm); exports.default = ModalForm; //# sourceMappingURL=index.js.map