iglooform 3.7.4 → 3.7.6

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.
@@ -30,7 +30,7 @@ export default function DumiContextWrapper() {
30
30
 
31
31
  return (
32
32
  <SiteContext.Provider value={{
33
- pkg: {"name":"iglooform","version":"3.7.2","license":"MIT"},
33
+ pkg: {"name":"iglooform","version":"3.7.5","license":"MIT"},
34
34
  historyType: "browser",
35
35
  entryExports,
36
36
  demos,
@@ -14,8 +14,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
14
14
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
15
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
16
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
17
- import React, { useReducer, useContext, useCallback } from 'react';
18
- import { Col, Divider, Row, Grid } from 'antd';
17
+ import React, { useReducer, useContext, useCallback, useEffect } from 'react';
18
+ import { Col, Divider, Row, Grid, Form } from 'antd';
19
19
  import Element from "../element";
20
20
  import FormContext from "../../form-context";
21
21
  import { calcNamePath, calcFormItemProps, calcAddableSectionAssertField } from "../../utils/form-utils";
@@ -66,6 +66,21 @@ var AddableSection = function AddableSection(_ref) {
66
66
  if (action.type === 'add') {
67
67
  return [].concat(_toConsumableArray(state), [action.key]);
68
68
  }
69
+ if (action.type === 'sync' && action.count !== undefined) {
70
+ var targetCount = Math.min(max, Math.max(min, action.count, initCount));
71
+ if (targetCount === state.length) {
72
+ return state;
73
+ }
74
+ if (targetCount > state.length) {
75
+ var newKeys = [];
76
+ for (var i = state.length; i < targetCount; i++) {
77
+ newKeys.push(Date.now() + Math.random());
78
+ }
79
+ return [].concat(_toConsumableArray(state), newKeys);
80
+ }
81
+ // targetCount < state.length
82
+ return state.slice(0, targetCount);
83
+ }
69
84
  var found = false;
70
85
  return state.filter(function (key, index) {
71
86
  if (key === action.key) {
@@ -86,7 +101,7 @@ var AddableSection = function AddableSection(_ref) {
86
101
  }
87
102
  return key !== action.key;
88
103
  });
89
- }, []);
104
+ }, [min, max, initCount]);
90
105
  var _useReducer = useReducer(reducer, function () {
91
106
  var init = [];
92
107
  var value = (form === null || form === void 0 ? void 0 : form.getFieldValue(namePath)) || [];
@@ -98,6 +113,18 @@ var AddableSection = function AddableSection(_ref) {
98
113
  _useReducer2 = _slicedToArray(_useReducer, 2),
99
114
  groupKeys = _useReducer2[0],
100
115
  dispath = _useReducer2[1];
116
+
117
+ // 监听外部通过 form.setFieldsValue 设置的值变化
118
+ Form.useWatch(namePath, form);
119
+ var fieldValue = form === null || form === void 0 ? void 0 : form.getFieldValue(namePath);
120
+ useEffect(function () {
121
+ if (Array.isArray(fieldValue)) {
122
+ dispath({
123
+ type: 'sync',
124
+ count: fieldValue.length
125
+ });
126
+ }
127
+ }, [fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.length]);
101
128
  var _calcFormItemProps = calcFormItemProps(config, {
102
129
  requiredMark: requiredMark
103
130
  }, form, parentName, validationCodeExtraParams),
@@ -182,6 +209,23 @@ var AddableSection = function AddableSection(_ref) {
182
209
  return calcAddableSectionAssertField(namePath, path, index, elements);
183
210
  });
184
211
  }
212
+ if (child.copyValue) {
213
+ _child.copyValue = _objectSpread(_objectSpread({}, child.copyValue), {}, {
214
+ assert: _objectSpread(_objectSpread({}, child.copyValue.assert), {}, {
215
+ field: calcAddableSectionAssertField(namePath, child.copyValue.assert.field, index, elements)
216
+ }),
217
+ copyFrom: calcAddableSectionAssertField(namePath, child.copyValue.copyFrom, index, elements)
218
+ });
219
+ }
220
+ if (Array.isArray(child.selectValue)) {
221
+ _child.selectValue = child.selectValue.map(function (sv) {
222
+ return _objectSpread(_objectSpread({}, sv), {}, {
223
+ assert: _objectSpread(_objectSpread({}, sv.assert), {}, {
224
+ field: calcAddableSectionAssertField(namePath, sv.assert.field, index, elements)
225
+ })
226
+ });
227
+ });
228
+ }
185
229
  return /*#__PURE__*/_jsx(Element, {
186
230
  parentName: parentName,
187
231
  config: _child,
@@ -15,7 +15,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
15
15
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
16
16
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
17
  import React, { useReducer, useContext, useEffect, useCallback, cloneElement, isValidElement } from 'react';
18
- import { Col, Row } from 'antd';
18
+ import { Col, Row, Form } from 'antd';
19
19
  import FormContext from "../../form-context";
20
20
  import { calcNamePath, calcFormItemProps, calcAddableSectionAssertField } from "../../utils/form-utils";
21
21
  import Typography from "../../typography";
@@ -68,6 +68,21 @@ var AddableSection = function AddableSection(props) {
68
68
  if (action.type === 'add') {
69
69
  return [].concat(_toConsumableArray(state), [action.key]);
70
70
  }
71
+ if (action.type === 'sync' && action.count !== undefined) {
72
+ var targetCount = Math.min(max, Math.max(min, action.count, initCount));
73
+ if (targetCount === state.length) {
74
+ return state;
75
+ }
76
+ if (targetCount > state.length) {
77
+ var newKeys = [];
78
+ for (var i = state.length; i < targetCount; i++) {
79
+ newKeys.push(Date.now() + Math.random());
80
+ }
81
+ return [].concat(_toConsumableArray(state), newKeys);
82
+ }
83
+ // targetCount < state.length
84
+ return state.slice(0, targetCount);
85
+ }
71
86
  var found = false;
72
87
  return state.filter(function (key, index) {
73
88
  if (key === action.key) {
@@ -88,7 +103,7 @@ var AddableSection = function AddableSection(props) {
88
103
  }
89
104
  return key !== action.key;
90
105
  });
91
- }, []);
106
+ }, [min, max, initCount]);
92
107
  var _useReducer3 = useReducer(reducer, function () {
93
108
  var init = [];
94
109
  var value = (form === null || form === void 0 ? void 0 : form.getFieldValue(namePath)) || [];
@@ -100,6 +115,18 @@ var AddableSection = function AddableSection(props) {
100
115
  _useReducer4 = _slicedToArray(_useReducer3, 2),
101
116
  groupKeys = _useReducer4[0],
102
117
  dispath = _useReducer4[1];
118
+
119
+ // 监听外部通过 form.setFieldsValue 设置的值变化
120
+ Form.useWatch(namePath, form);
121
+ var fieldValue = form === null || form === void 0 ? void 0 : form.getFieldValue(namePath);
122
+ useEffect(function () {
123
+ if (Array.isArray(fieldValue)) {
124
+ dispath({
125
+ type: 'sync',
126
+ count: fieldValue.length
127
+ });
128
+ }
129
+ }, [fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.length]);
103
130
  useEffect(function () {
104
131
  var dependencies = props.dependencies,
105
132
  asserts = props.asserts,
@@ -74,6 +74,21 @@ var AddableSection = function AddableSection(_ref) {
74
74
  if (action.type === 'add') {
75
75
  return [].concat(_toConsumableArray(state), [action.key]);
76
76
  }
77
+ if (action.type === 'sync' && action.count !== undefined) {
78
+ var targetCount = Math.min(max, Math.max(min, action.count, initCount));
79
+ if (targetCount === state.length) {
80
+ return state;
81
+ }
82
+ if (targetCount > state.length) {
83
+ var newKeys = [];
84
+ for (var i = state.length; i < targetCount; i++) {
85
+ newKeys.push(Date.now() + Math.random());
86
+ }
87
+ return [].concat(_toConsumableArray(state), newKeys);
88
+ }
89
+ // targetCount < state.length
90
+ return state.slice(0, targetCount);
91
+ }
77
92
  var found = false;
78
93
  return state.filter(function (key, index) {
79
94
  if (key === action.key) {
@@ -94,7 +109,7 @@ var AddableSection = function AddableSection(_ref) {
94
109
  }
95
110
  return key !== action.key;
96
111
  });
97
- }, []);
112
+ }, [min, max, initCount]);
98
113
  var _useReducer = (0, _react.useReducer)(reducer, function () {
99
114
  var init = [];
100
115
  var value = (form === null || form === void 0 ? void 0 : form.getFieldValue(namePath)) || [];
@@ -106,6 +121,18 @@ var AddableSection = function AddableSection(_ref) {
106
121
  _useReducer2 = _slicedToArray(_useReducer, 2),
107
122
  groupKeys = _useReducer2[0],
108
123
  dispath = _useReducer2[1];
124
+
125
+ // 监听外部通过 form.setFieldsValue 设置的值变化
126
+ _antd.Form.useWatch(namePath, form);
127
+ var fieldValue = form === null || form === void 0 ? void 0 : form.getFieldValue(namePath);
128
+ (0, _react.useEffect)(function () {
129
+ if (Array.isArray(fieldValue)) {
130
+ dispath({
131
+ type: 'sync',
132
+ count: fieldValue.length
133
+ });
134
+ }
135
+ }, [fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.length]);
109
136
  var _calcFormItemProps = (0, _formUtils.calcFormItemProps)(config, {
110
137
  requiredMark: requiredMark
111
138
  }, form, parentName, validationCodeExtraParams),
@@ -190,6 +217,23 @@ var AddableSection = function AddableSection(_ref) {
190
217
  return (0, _formUtils.calcAddableSectionAssertField)(namePath, path, index, elements);
191
218
  });
192
219
  }
220
+ if (child.copyValue) {
221
+ _child.copyValue = _objectSpread(_objectSpread({}, child.copyValue), {}, {
222
+ assert: _objectSpread(_objectSpread({}, child.copyValue.assert), {}, {
223
+ field: (0, _formUtils.calcAddableSectionAssertField)(namePath, child.copyValue.assert.field, index, elements)
224
+ }),
225
+ copyFrom: (0, _formUtils.calcAddableSectionAssertField)(namePath, child.copyValue.copyFrom, index, elements)
226
+ });
227
+ }
228
+ if (Array.isArray(child.selectValue)) {
229
+ _child.selectValue = child.selectValue.map(function (sv) {
230
+ return _objectSpread(_objectSpread({}, sv), {}, {
231
+ assert: _objectSpread(_objectSpread({}, sv.assert), {}, {
232
+ field: (0, _formUtils.calcAddableSectionAssertField)(namePath, sv.assert.field, index, elements)
233
+ })
234
+ });
235
+ });
236
+ }
193
237
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_element.default, {
194
238
  parentName: parentName,
195
239
  config: _child,
@@ -75,6 +75,21 @@ var AddableSection = function AddableSection(props) {
75
75
  if (action.type === 'add') {
76
76
  return [].concat(_toConsumableArray(state), [action.key]);
77
77
  }
78
+ if (action.type === 'sync' && action.count !== undefined) {
79
+ var targetCount = Math.min(max, Math.max(min, action.count, initCount));
80
+ if (targetCount === state.length) {
81
+ return state;
82
+ }
83
+ if (targetCount > state.length) {
84
+ var newKeys = [];
85
+ for (var i = state.length; i < targetCount; i++) {
86
+ newKeys.push(Date.now() + Math.random());
87
+ }
88
+ return [].concat(_toConsumableArray(state), newKeys);
89
+ }
90
+ // targetCount < state.length
91
+ return state.slice(0, targetCount);
92
+ }
78
93
  var found = false;
79
94
  return state.filter(function (key, index) {
80
95
  if (key === action.key) {
@@ -95,7 +110,7 @@ var AddableSection = function AddableSection(props) {
95
110
  }
96
111
  return key !== action.key;
97
112
  });
98
- }, []);
113
+ }, [min, max, initCount]);
99
114
  var _useReducer3 = (0, _react.useReducer)(reducer, function () {
100
115
  var init = [];
101
116
  var value = (form === null || form === void 0 ? void 0 : form.getFieldValue(namePath)) || [];
@@ -107,6 +122,18 @@ var AddableSection = function AddableSection(props) {
107
122
  _useReducer4 = _slicedToArray(_useReducer3, 2),
108
123
  groupKeys = _useReducer4[0],
109
124
  dispath = _useReducer4[1];
125
+
126
+ // 监听外部通过 form.setFieldsValue 设置的值变化
127
+ _antd.Form.useWatch(namePath, form);
128
+ var fieldValue = form === null || form === void 0 ? void 0 : form.getFieldValue(namePath);
129
+ (0, _react.useEffect)(function () {
130
+ if (Array.isArray(fieldValue)) {
131
+ dispath({
132
+ type: 'sync',
133
+ count: fieldValue.length
134
+ });
135
+ }
136
+ }, [fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.length]);
110
137
  (0, _react.useEffect)(function () {
111
138
  var dependencies = props.dependencies,
112
139
  asserts = props.asserts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iglooform",
3
- "version": "3.7.4",
3
+ "version": "3.7.6",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "build-dev": "dumi build",
@@ -1,4 +0,0 @@
1
- import { Form as FormType } from '../types';
2
- import './style';
3
- declare const ExportedForm: FormType;
4
- export default ExportedForm;
@@ -1,11 +0,0 @@
1
- import { FC, PropsWithChildren } from 'react';
2
- import { Form } from 'antd';
3
- import { FormBasicConfig } from '../types';
4
- import './style';
5
- interface FreeFormProps extends Omit<FormBasicConfig, 'config'> {
6
- }
7
- interface FreeFormType extends FC<PropsWithChildren<FreeFormProps>> {
8
- useForm: typeof Form.useForm;
9
- }
10
- declare const FreeForm: FreeFormType;
11
- export default FreeForm;
@@ -1,4 +0,0 @@
1
- import { Form as FormType } from '../types';
2
- import './style';
3
- declare const ExportedForm: FormType;
4
- export default ExportedForm;
@@ -1,11 +0,0 @@
1
- import { FC, PropsWithChildren } from 'react';
2
- import { Form } from 'antd';
3
- import { FormBasicConfig } from '../types';
4
- import './style';
5
- interface FreeFormProps extends Omit<FormBasicConfig, 'config'> {
6
- }
7
- interface FreeFormType extends FC<PropsWithChildren<FreeFormProps>> {
8
- useForm: typeof Form.useForm;
9
- }
10
- declare const FreeForm: FreeFormType;
11
- export default FreeForm;