@signalplus/params-about 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +59 -3
  2. package/lib/es/index.js +293 -13
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -49,9 +49,12 @@ declare class ParamRenderer extends PureComponent<ParamRendererProps> {
49
49
  }
50
50
 
51
51
  interface ParentSelectorOption {
52
- label: string;
53
- value: string;
52
+ $paramId: string | number;
53
+ name: string;
54
+ disabled?: boolean;
55
+ valueType?: ParamType;
54
56
  children?: ParentSelectorOption[];
57
+ [key: string]: any;
55
58
  }
56
59
  interface ParentSelectorProps extends BaseInputProps {
57
60
  parentOptions?: ParentSelectorOption[];
@@ -212,6 +215,59 @@ declare class ParamGroupEditorModal {
212
215
  static hide(): Promise<void>;
213
216
  }
214
217
 
218
+ interface ParamMoverData {
219
+ parentId: string;
220
+ }
221
+ interface ParamMoverProps {
222
+ targetParams: string[];
223
+ allParams: NonNullable<ParentSelectorProps['parentOptions']>;
224
+ onSubmit?(params: NonNullable<ParentSelectorProps['parentOptions']>): Promise<any>;
225
+ }
226
+ declare function initState(props: ParamMoverProps): {
227
+ preProps: ParamMoverProps;
228
+ options: any[];
229
+ paramsMap: Record<string, ParentSelectorOption>;
230
+ };
231
+ declare type ParamMoverState = ReturnType<typeof initState>;
232
+ declare class ParamMover extends PureComponent<ParamMoverProps, ParamMoverState> {
233
+ static getDerivedStateFromProps(props: ParamMoverProps, state: ParamMoverState): {
234
+ preProps: ParamMoverProps;
235
+ options: any[];
236
+ paramsMap: Record<string, ParentSelectorOption>;
237
+ };
238
+ get newParams(): ParentSelectorOption[];
239
+ state: {
240
+ preProps: ParamMoverProps;
241
+ options: any[];
242
+ paramsMap: Record<string, ParentSelectorOption>;
243
+ };
244
+ ref: React.RefObject<any>;
245
+ get formItems(): {
246
+ label: string;
247
+ name: string;
248
+ Comp: React.ComponentType<BaseInputProps>;
249
+ required?: boolean | undefined;
250
+ validator?(_: any, val: any): Promise<any>;
251
+ }[];
252
+ render(): JSX.Element;
253
+ }
254
+ declare class ParamMoverModalEl extends PureComponent<ParamMoverProps & Required<Pick<ParamMoverProps, 'onSubmit'>>> {
255
+ ref: React.RefObject<ParamMover>;
256
+ state: {
257
+ visible: boolean;
258
+ pending: boolean;
259
+ };
260
+ onShow: () => void;
261
+ onHide: () => void;
262
+ onSubmit: () => any;
263
+ render(): JSX.Element;
264
+ }
265
+ declare class ParamMoverModal {
266
+ static el: ReactGlobalComp<ParamMoverProps & Required<Pick<ParamMoverProps, "onSubmit">>>;
267
+ static show(props: Omit<ComponentProps<typeof ParamMoverModalEl>, 'visible'>): Promise<void>;
268
+ static hide(): Promise<void>;
269
+ }
270
+
215
271
  declare const ParamTypeConfig: Record<ParamType, {
216
272
  name: string;
217
273
  key?: string;
@@ -245,4 +301,4 @@ declare function keyValidator(val: string): "Should not be empty" | "" | "Out of
245
301
  declare function isExpired(val?: string): boolean;
246
302
  declare function validatorCvt(validator: (val: any, values: any) => ValidateInfo['string'], form?: () => any): (_: any, val: any) => Promise<any>;
247
303
 
248
- export { BaseInputProps, ParamForm, ParamFormData, ParamFormModal, ParamFormProps, ParamGroupEditor, ParamGroupEditorData, ParamGroupEditorModal, ParamGroupEditorModalEl, ParamGroupEditorProps, ParamRenderer, ParamRendererProps, ParamType, ParamTypeConfig, ParamTypeOptions, ParamValueEditor, ParamValueEditorData, ParamValueEditorModal, ParamValueEditorModalEl, ParamValueEditorProps, ParamValueStruct, ValidateInfo, emptyValidator, expiriesValidator, expiryValidator, formatNum, isExpired, isNullLike, keyValidator, numRangeValidator, paramValidator, validatorCvt };
304
+ export { BaseInputProps, ParamForm, ParamFormData, ParamFormModal, ParamFormProps, ParamGroupEditor, ParamGroupEditorData, ParamGroupEditorModal, ParamGroupEditorModalEl, ParamGroupEditorProps, ParamMover, ParamMoverData, ParamMoverModal, ParamMoverModalEl, ParamMoverProps, ParamMoverState, ParamRenderer, ParamRendererProps, ParamType, ParamTypeConfig, ParamTypeOptions, ParamValueEditor, ParamValueEditorData, ParamValueEditorModal, ParamValueEditorModalEl, ParamValueEditorProps, ParamValueStruct, ValidateInfo, emptyValidator, expiriesValidator, expiryValidator, formatNum, isExpired, isNullLike, keyValidator, numRangeValidator, paramValidator, validatorCvt };
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Bundle of @signalplus/params-about
3
3
  * Generated: 2022-04-08
4
- * Version: 0.1.4
4
+ * Version: 0.1.5
5
5
  * License: MIT
6
6
  * Author: 2631541504@qq.com
7
7
  */
@@ -566,7 +566,7 @@ var NumCvt = /*#__PURE__*/function () {
566
566
  return NumCvt;
567
567
  }();
568
568
 
569
- function initState(props) {
569
+ function initState$1(props) {
570
570
  return {
571
571
  preProps: props,
572
572
  tempValue: NumCvt.show(props.value, props.isPercentage)
@@ -589,7 +589,7 @@ var Num = /*#__PURE__*/function (_PureComponent) {
589
589
 
590
590
  _this = _super.call.apply(_super, [this].concat(args));
591
591
 
592
- _defineProperty(_assertThisInitialized(_this), "state", initState(_this.props));
592
+ _defineProperty(_assertThisInitialized(_this), "state", initState$1(_this.props));
593
593
 
594
594
  _defineProperty(_assertThisInitialized(_this), "onChange", function (e) {
595
595
  var $value = e.target.value;
@@ -1264,11 +1264,23 @@ var ParamRenderer = /*#__PURE__*/function (_PureComponent) {
1264
1264
  }(PureComponent);
1265
1265
 
1266
1266
  function ParentSelector(props) {
1267
- var value = useMemo(function () {
1267
+ var _useMemo = useMemo(function () {
1268
1268
  var _props$parentOptions;
1269
1269
 
1270
1270
  var $value = [];
1271
1271
 
1272
+ var cvt = function cvt(it) {
1273
+ var _it$children;
1274
+
1275
+ return _objectSpread2(_objectSpread2({}, it), {}, {
1276
+ label: it.name,
1277
+ value: String(it.$paramId),
1278
+ children: (_it$children = it.children) === null || _it$children === void 0 ? void 0 : _it$children.map(cvt)
1279
+ });
1280
+ };
1281
+
1282
+ var $options = ((_props$parentOptions = props.parentOptions) === null || _props$parentOptions === void 0 ? void 0 : _props$parentOptions.map(cvt)) || [];
1283
+
1272
1284
  var find = function find(item) {
1273
1285
  var _item$children;
1274
1286
 
@@ -1281,17 +1293,26 @@ function ParentSelector(props) {
1281
1293
  }));
1282
1294
  };
1283
1295
 
1284
- var matched = props.value && ((_props$parentOptions = props.parentOptions) === null || _props$parentOptions === void 0 ? void 0 : _props$parentOptions.some(function (it) {
1296
+ var matched = props.value && $options.some(function (it) {
1285
1297
  return find(it);
1286
- }));
1287
- if (!matched) return [];
1288
- return $value;
1289
- }, [props.parentOptions, props.value]);
1298
+ });
1299
+ if (!matched) return {
1300
+ value: [],
1301
+ options: $options
1302
+ };
1303
+ return {
1304
+ value: $value,
1305
+ options: $options
1306
+ };
1307
+ }, [props.parentOptions, props.value]),
1308
+ value = _useMemo.value,
1309
+ options = _useMemo.options;
1310
+
1290
1311
  return /*#__PURE__*/React$1.createElement(Cascader, {
1291
1312
  style: props.style,
1292
1313
  disabled: props.readonly,
1293
1314
  placeholder: '请选择',
1294
- options: props.parentOptions,
1315
+ options: options,
1295
1316
  className: classNames('param-parent-selector', {
1296
1317
  readonly: props.readonly
1297
1318
  }, props.className),
@@ -2018,11 +2039,11 @@ var ParamGroupEditorModalEl = /*#__PURE__*/function (_PureComponent2) {
2018
2039
  visible: this.state.visible,
2019
2040
  footer: /*#__PURE__*/React$1.createElement(React$1.Fragment, null, /*#__PURE__*/React$1.createElement(Button, {
2020
2041
  onClick: this.onHide
2021
- }, "Cancel"), /*#__PURE__*/React$1.createElement(Button, {
2042
+ }, "\u53D6\u6D88"), /*#__PURE__*/React$1.createElement(Button, {
2022
2043
  type: "primary",
2023
2044
  onClick: this.onSubmit,
2024
2045
  loading: this.state.pending
2025
- }, "Submit"))
2046
+ }, "\u786E\u5B9A"))
2026
2047
  }, /*#__PURE__*/React$1.createElement(ParamGroupEditor, Object.assign({}, this.props, {
2027
2048
  ref: this.ref,
2028
2049
  onSubmit: undefined
@@ -2058,4 +2079,263 @@ var ParamGroupEditorModal = /*#__PURE__*/function () {
2058
2079
 
2059
2080
  _defineProperty(ParamGroupEditorModal, "el", new ReactGlobalComp('param-group-editor-modal', ParamGroupEditorModalEl));
2060
2081
 
2061
- export { ParamForm, ParamFormModal, ParamGroupEditor, ParamGroupEditorModal, ParamGroupEditorModalEl, ParamRenderer, ParamType, ParamTypeConfig, ParamTypeOptions, ParamValueEditor, ParamValueEditorModal, ParamValueEditorModalEl, emptyValidator, expiriesValidator, expiryValidator, formatNum, isExpired, isNullLike, keyValidator, numRangeValidator, paramValidator, validatorCvt };
2082
+ function genOptions(props) {
2083
+ var filter = function filter(it) {
2084
+ return it.valueType !== ParamType.ParamGroup;
2085
+ };
2086
+
2087
+ var cvt = function cvt(it) {
2088
+ var _it$children;
2089
+
2090
+ return _objectSpread2(_objectSpread2({}, it), {}, {
2091
+ disabled: props.targetParams.includes(String(it.$paramId)),
2092
+ children: (_it$children = it.children) === null || _it$children === void 0 ? void 0 : _it$children.filter(filter).map(cvt)
2093
+ });
2094
+ };
2095
+
2096
+ return props.allParams.map(cvt) || [];
2097
+ }
2098
+
2099
+ function genParamsMap(props) {
2100
+ var map = {};
2101
+
2102
+ var append = function append(it) {
2103
+ var _it$children2;
2104
+
2105
+ map[it.$paramId] = _objectSpread2(_objectSpread2({}, it), {}, {
2106
+ disabled: props.targetParams.includes(String(it.$paramId))
2107
+ });
2108
+ (_it$children2 = it.children) === null || _it$children2 === void 0 ? void 0 : _it$children2.forEach(append);
2109
+ };
2110
+
2111
+ props.allParams.forEach(append);
2112
+ return map;
2113
+ }
2114
+
2115
+ function initState(props) {
2116
+ return {
2117
+ preProps: props,
2118
+ options: genOptions(props),
2119
+ paramsMap: genParamsMap(props)
2120
+ };
2121
+ }
2122
+
2123
+ var ParamMover = /*#__PURE__*/function (_PureComponent) {
2124
+ _inherits(ParamMover, _PureComponent);
2125
+
2126
+ var _super = _createSuper(ParamMover);
2127
+
2128
+ function ParamMover() {
2129
+ var _this;
2130
+
2131
+ _classCallCheck(this, ParamMover);
2132
+
2133
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2134
+ args[_key] = arguments[_key];
2135
+ }
2136
+
2137
+ _this = _super.call.apply(_super, [this].concat(args));
2138
+
2139
+ _defineProperty(_assertThisInitialized(_this), "state", initState(_this.props));
2140
+
2141
+ _defineProperty(_assertThisInitialized(_this), "ref", React$1.createRef());
2142
+
2143
+ return _this;
2144
+ }
2145
+
2146
+ _createClass(ParamMover, [{
2147
+ key: "newParams",
2148
+ get: function get() {
2149
+ var _this2 = this;
2150
+
2151
+ var _getFieldsValue = this.ref.current.getFieldsValue(),
2152
+ parentId = _getFieldsValue.parentId;
2153
+
2154
+ var filter = function filter(it) {
2155
+ return !_this2.props.targetParams.includes(String(it.$paramId));
2156
+ };
2157
+
2158
+ var map = function map(it) {
2159
+ var _it$children3;
2160
+
2161
+ if (it.$paramId === parentId) {
2162
+ return _objectSpread2(_objectSpread2({}, it), {}, {
2163
+ children: (it.children || []).concat(_this2.props.targetParams.map(function ($paramId) {
2164
+ return _this2.state.paramsMap[$paramId];
2165
+ }))
2166
+ });
2167
+ }
2168
+
2169
+ return _objectSpread2(_objectSpread2({}, it), {}, {
2170
+ children: (_it$children3 = it.children) === null || _it$children3 === void 0 ? void 0 : _it$children3.filter(filter).map(map)
2171
+ });
2172
+ };
2173
+
2174
+ return this.props.allParams.filter(filter).map(map);
2175
+ }
2176
+ }, {
2177
+ key: "formItems",
2178
+ get: function get() {
2179
+ var _this3 = this;
2180
+
2181
+ var items = [{
2182
+ label: '选择分组',
2183
+ name: 'parentId',
2184
+ Comp: function Comp(props) {
2185
+ return /*#__PURE__*/React$1.createElement(ParentSelector, Object.assign({}, props, {
2186
+ parentOptions: _this3.state.options
2187
+ }));
2188
+ }
2189
+ }];
2190
+ return items;
2191
+ }
2192
+ }, {
2193
+ key: "render",
2194
+ value: function render() {
2195
+ return /*#__PURE__*/React$1.createElement(Form, {
2196
+ className: "param-value-editor",
2197
+ ref: this.ref,
2198
+ onFinish: this.props.onSubmit
2199
+ }, this.formItems.map(function (it) {
2200
+ return /*#__PURE__*/React$1.createElement(Form.Item, {
2201
+ key: it.name,
2202
+ label: it.label,
2203
+ name: it.name,
2204
+ required: it.required,
2205
+ requiredMark: true,
2206
+ rules: [{
2207
+ validator: it.validator || function () {
2208
+ return Promise.resolve();
2209
+ }
2210
+ }],
2211
+ validateTrigger: 'onBlur'
2212
+ }, /*#__PURE__*/React$1.createElement(it.Comp, null));
2213
+ }), this.props.onSubmit && /*#__PURE__*/React$1.createElement(Button, {
2214
+ type: "primary",
2215
+ htmlType: "submit"
2216
+ }, "\u63D0\u4EA4"));
2217
+ }
2218
+ }], [{
2219
+ key: "getDerivedStateFromProps",
2220
+ value: function getDerivedStateFromProps(props, state) {
2221
+ if (props.allParams !== state.preProps.allParams) {
2222
+ state.paramsMap = genParamsMap(props);
2223
+
2224
+ if (props.targetParams !== state.preProps.targetParams) {
2225
+ state.options = genOptions(props);
2226
+ }
2227
+ }
2228
+
2229
+ return _objectSpread2(_objectSpread2({}, state), {}, {
2230
+ preProps: props
2231
+ });
2232
+ }
2233
+ }]);
2234
+
2235
+ return ParamMover;
2236
+ }(PureComponent);
2237
+ var ParamMoverModalEl = /*#__PURE__*/function (_PureComponent2) {
2238
+ _inherits(ParamMoverModalEl, _PureComponent2);
2239
+
2240
+ var _super2 = _createSuper(ParamMoverModalEl);
2241
+
2242
+ function ParamMoverModalEl() {
2243
+ var _this4;
2244
+
2245
+ _classCallCheck(this, ParamMoverModalEl);
2246
+
2247
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2248
+ args[_key2] = arguments[_key2];
2249
+ }
2250
+
2251
+ _this4 = _super2.call.apply(_super2, [this].concat(args));
2252
+
2253
+ _defineProperty(_assertThisInitialized(_this4), "ref", React$1.createRef());
2254
+
2255
+ _defineProperty(_assertThisInitialized(_this4), "state", {
2256
+ visible: false,
2257
+ pending: false
2258
+ });
2259
+
2260
+ _defineProperty(_assertThisInitialized(_this4), "onShow", function () {
2261
+ return _this4.setState({
2262
+ visible: true
2263
+ });
2264
+ });
2265
+
2266
+ _defineProperty(_assertThisInitialized(_this4), "onHide", function () {
2267
+ return _this4.setState({
2268
+ visible: false
2269
+ });
2270
+ });
2271
+
2272
+ _defineProperty(_assertThisInitialized(_this4), "onSubmit", function () {
2273
+ var form = _this4.ref.current.ref.current;
2274
+ return form.validateFields().then(function () {
2275
+ return _this4.setState({
2276
+ pending: true
2277
+ });
2278
+ }).then(function () {
2279
+ return _this4.props.onSubmit(_this4.ref.current.newParams);
2280
+ }).then(_this4.onHide).finally(function () {
2281
+ return _this4.setState({
2282
+ pending: false
2283
+ });
2284
+ });
2285
+ });
2286
+
2287
+ return _this4;
2288
+ }
2289
+
2290
+ _createClass(ParamMoverModalEl, [{
2291
+ key: "render",
2292
+ value: function render() {
2293
+ return /*#__PURE__*/React$1.createElement(Modal, {
2294
+ key: String(this.state.visible),
2295
+ width: 640,
2296
+ title: '移动参数',
2297
+ closable: false,
2298
+ visible: this.state.visible,
2299
+ footer: /*#__PURE__*/React$1.createElement(React$1.Fragment, null, /*#__PURE__*/React$1.createElement(Button, {
2300
+ onClick: this.onHide
2301
+ }, "\u53D6\u6D88"), /*#__PURE__*/React$1.createElement(Button, {
2302
+ type: "primary",
2303
+ onClick: this.onSubmit,
2304
+ loading: this.state.pending
2305
+ }, "\u786E\u5B9A"))
2306
+ }, /*#__PURE__*/React$1.createElement(ParamMover, Object.assign({}, this.props, {
2307
+ ref: this.ref,
2308
+ onSubmit: undefined
2309
+ })));
2310
+ }
2311
+ }]);
2312
+
2313
+ return ParamMoverModalEl;
2314
+ }(PureComponent);
2315
+ var ParamMoverModal = /*#__PURE__*/function () {
2316
+ function ParamMoverModal() {
2317
+ _classCallCheck(this, ParamMoverModal);
2318
+ }
2319
+
2320
+ _createClass(ParamMoverModal, null, [{
2321
+ key: "show",
2322
+ value: function show(props) {
2323
+ return ParamMoverModal.el.render(props).then(function () {
2324
+ ParamMoverModal.el.ref.onShow();
2325
+ });
2326
+ }
2327
+ }, {
2328
+ key: "hide",
2329
+ value: function hide() {
2330
+ return ParamMoverModal.el.render().then(function () {
2331
+ ParamMoverModal.el.ref.onHide();
2332
+ });
2333
+ }
2334
+ }]);
2335
+
2336
+ return ParamMoverModal;
2337
+ }();
2338
+
2339
+ _defineProperty(ParamMoverModal, "el", new ReactGlobalComp('param-mover-modal', ParamMoverModalEl));
2340
+
2341
+ export { ParamForm, ParamFormModal, ParamGroupEditor, ParamGroupEditorModal, ParamGroupEditorModalEl, ParamMover, ParamMoverModal, ParamMoverModalEl, ParamRenderer, ParamType, ParamTypeConfig, ParamTypeOptions, ParamValueEditor, ParamValueEditorModal, ParamValueEditorModalEl, emptyValidator, expiriesValidator, expiryValidator, formatNum, isExpired, isNullLike, keyValidator, numRangeValidator, paramValidator, validatorCvt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalplus/params-about",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "A description for the module",
5
5
  "main": "./lib/umd/index.js",
6
6
  "module": "./lib/es/index.js",