@nutui/nutui-react 3.0.0 → 3.0.2

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 (207) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/hooks/use-client-rect.js +1 -0
  3. package/dist/cjs/packages/actionsheet/style/style.css +12 -0
  4. package/dist/cjs/packages/address/style/style.css +12 -0
  5. package/dist/cjs/packages/calendar/style/style.css +12 -0
  6. package/dist/cjs/packages/cascader/style/style.css +12 -0
  7. package/dist/cjs/packages/configprovider/types.d.ts +1 -1
  8. package/dist/cjs/packages/datepicker/datepicker.js +8 -6
  9. package/dist/cjs/packages/datepicker/style/style.css +82 -0
  10. package/dist/cjs/packages/datepickerview/datepickerview.d.ts +3 -0
  11. package/dist/cjs/packages/datepickerview/datepickerview.js +118 -0
  12. package/dist/cjs/packages/datepickerview/index.d.ts +3 -0
  13. package/dist/cjs/packages/{subsidenavbar → datepickerview}/index.js +2 -2
  14. package/dist/cjs/packages/datepickerview/style/datepickerview.scss +4 -0
  15. package/dist/cjs/packages/datepickerview/style/index.js +2 -0
  16. package/dist/cjs/packages/datepickerview/style/style.css +78 -0
  17. package/dist/cjs/packages/datepickerview/types.d.ts +15 -0
  18. package/dist/cjs/packages/datepickerview/types.js +4 -0
  19. package/dist/cjs/packages/dialog/dialogwrap.js +3 -0
  20. package/dist/cjs/packages/dialog/style/dialog.scss +0 -1
  21. package/dist/cjs/packages/dialog/style/style.css +0 -1
  22. package/dist/cjs/packages/drag/style/drag.scss +1 -0
  23. package/dist/cjs/packages/drag/style/style.css +1 -0
  24. package/dist/cjs/packages/fixednav/fixednav.js +20 -14
  25. package/dist/cjs/packages/fixednav/style/fixednav.scss +0 -15
  26. package/dist/cjs/packages/fixednav/style/style.css +0 -14
  27. package/dist/cjs/packages/form/__tests__/merge.spec.d.ts +1 -0
  28. package/dist/cjs/packages/form/__tests__/merge.spec.js +545 -0
  29. package/dist/cjs/packages/form/form.d.ts +2 -0
  30. package/dist/cjs/packages/form/form.js +9 -2
  31. package/dist/cjs/packages/form/index.d.ts +2 -1
  32. package/dist/cjs/packages/form/index.js +1 -0
  33. package/dist/cjs/packages/form/style/form.scss +0 -66
  34. package/dist/cjs/packages/form/style/style.css +31 -21
  35. package/dist/cjs/packages/form/types.d.ts +2 -1
  36. package/dist/cjs/packages/form/useform.d.ts +2 -1
  37. package/dist/cjs/packages/form/useform.js +342 -278
  38. package/dist/cjs/packages/formitem/formitem.d.ts +1 -0
  39. package/dist/cjs/packages/formitem/formitem.js +55 -44
  40. package/dist/cjs/packages/formitem/style/formitem.scss +101 -21
  41. package/dist/cjs/packages/formitem/style/style.css +89 -12
  42. package/dist/cjs/packages/imagepreview/style/style.css +12 -0
  43. package/dist/cjs/packages/input/style/input.scss +6 -4
  44. package/dist/cjs/packages/input/style/style.css +4 -0
  45. package/dist/cjs/packages/numberkeyboard/style/style.css +12 -0
  46. package/dist/cjs/packages/nutui.react.build.d.ts +11 -15
  47. package/dist/cjs/packages/nutui.react.build.js +8 -16
  48. package/dist/cjs/packages/nutui.react.d.ts +16 -22
  49. package/dist/cjs/packages/nutui.react.js +13 -23
  50. package/dist/cjs/packages/nutui.react.scss.d.ts +5 -7
  51. package/dist/cjs/packages/nutui.react.scss.js +5 -7
  52. package/dist/cjs/packages/overlay/style/overlay.scss +0 -4
  53. package/dist/cjs/packages/picker/style/index.js +1 -0
  54. package/dist/cjs/packages/picker/style/style.css +82 -0
  55. package/dist/cjs/packages/popover/style/style.css +12 -0
  56. package/dist/cjs/packages/popup/style/popup.scss +12 -4
  57. package/dist/cjs/packages/popup/style/style.css +12 -0
  58. package/dist/cjs/packages/shortpassword/shortpassword.js +5 -7
  59. package/dist/cjs/packages/shortpassword/style/shortpassword.scss +10 -0
  60. package/dist/cjs/packages/shortpassword/style/style.css +21 -0
  61. package/dist/cjs/packages/swipe/style/style.css +3 -3
  62. package/dist/cjs/packages/swipe/style/swipe.scss +7 -3
  63. package/dist/cjs/packages/tabbar/style/style.css +6 -0
  64. package/dist/cjs/packages/tabbaritem/style/style.css +6 -0
  65. package/dist/cjs/packages/tabbaritem/style/tabbaritem.scss +6 -0
  66. package/dist/cjs/packages/timeselect/style/style.css +12 -0
  67. package/dist/cjs/packages/tour/style/style.css +12 -0
  68. package/dist/cjs/utils/get-rect-by-taro.d.ts +1 -1
  69. package/dist/cjs/utils/get-rect-by-taro.js +4 -1
  70. package/dist/cjs/utils/get-system-info.js +4 -5
  71. package/dist/cjs/utils/merge.d.ts +14 -0
  72. package/dist/cjs/utils/merge.js +98 -0
  73. package/dist/cjs/utils/platform-taro.js +4 -5
  74. package/dist/cjs/utils/to-array.d.ts +1 -0
  75. package/dist/cjs/utils/to-array.js +18 -0
  76. package/dist/es/hooks/use-client-rect.js +1 -0
  77. package/dist/es/packages/actionsheet/style/style.css +12 -0
  78. package/dist/es/packages/address/style/style.css +12 -0
  79. package/dist/es/packages/calendar/style/style.css +12 -0
  80. package/dist/es/packages/cascader/style/style.css +12 -0
  81. package/dist/es/packages/configprovider/types.d.ts +1 -1
  82. package/dist/es/packages/datepicker/datepicker.js +8 -6
  83. package/dist/es/packages/datepicker/style/style.css +82 -0
  84. package/dist/es/packages/datepickerview/datepickerview.d.ts +3 -0
  85. package/dist/es/packages/datepickerview/datepickerview.js +106 -0
  86. package/dist/es/packages/datepickerview/index.d.ts +3 -0
  87. package/dist/es/packages/datepickerview/index.js +2 -0
  88. package/dist/es/packages/datepickerview/style/datepickerview.scss +4 -0
  89. package/dist/es/packages/datepickerview/style/index.js +2 -0
  90. package/dist/es/packages/datepickerview/style/style.css +78 -0
  91. package/dist/es/packages/datepickerview/types.d.ts +15 -0
  92. package/dist/es/packages/datepickerview/types.js +1 -0
  93. package/dist/es/packages/dialog/dialogwrap.js +3 -0
  94. package/dist/es/packages/dialog/style/dialog.scss +0 -1
  95. package/dist/es/packages/dialog/style/style.css +0 -1
  96. package/dist/es/packages/drag/style/drag.scss +1 -0
  97. package/dist/es/packages/drag/style/style.css +1 -0
  98. package/dist/es/packages/fixednav/fixednav.js +20 -14
  99. package/dist/es/packages/fixednav/style/fixednav.scss +0 -15
  100. package/dist/es/packages/fixednav/style/style.css +0 -14
  101. package/dist/es/packages/form/__tests__/merge.spec.d.ts +1 -0
  102. package/dist/es/packages/form/__tests__/merge.spec.js +541 -0
  103. package/dist/es/packages/form/form.d.ts +10 -0
  104. package/dist/es/packages/form/form.js +9 -2
  105. package/dist/es/packages/form/index.d.ts +2 -1
  106. package/dist/es/packages/form/index.js +2 -1
  107. package/dist/es/packages/form/style/form.scss +0 -66
  108. package/dist/es/packages/form/style/style.css +31 -21
  109. package/dist/es/packages/form/types.d.ts +2 -1
  110. package/dist/es/packages/form/useform.d.ts +2 -1
  111. package/dist/es/packages/form/useform.js +340 -279
  112. package/dist/es/packages/formitem/formitem.d.ts +1 -0
  113. package/dist/es/packages/formitem/formitem.js +55 -44
  114. package/dist/es/packages/formitem/style/formitem.scss +101 -21
  115. package/dist/es/packages/formitem/style/style.css +89 -12
  116. package/dist/es/packages/imagepreview/style/style.css +12 -0
  117. package/dist/es/packages/input/style/input.scss +6 -4
  118. package/dist/es/packages/input/style/style.css +4 -0
  119. package/dist/es/packages/numberkeyboard/style/style.css +12 -0
  120. package/dist/es/packages/nutui.react.build.d.ts +11 -15
  121. package/dist/es/packages/nutui.react.build.js +11 -15
  122. package/dist/es/packages/overlay/style/overlay.scss +0 -4
  123. package/dist/es/packages/picker/style/index.js +1 -0
  124. package/dist/es/packages/picker/style/style.css +82 -0
  125. package/dist/es/packages/popover/style/style.css +12 -0
  126. package/dist/es/packages/popup/style/popup.scss +12 -4
  127. package/dist/es/packages/popup/style/style.css +12 -0
  128. package/dist/es/packages/shortpassword/shortpassword.js +5 -7
  129. package/dist/es/packages/shortpassword/style/shortpassword.scss +10 -0
  130. package/dist/es/packages/shortpassword/style/style.css +21 -0
  131. package/dist/es/packages/swipe/style/style.css +3 -3
  132. package/dist/es/packages/swipe/style/swipe.scss +7 -3
  133. package/dist/es/packages/tabbar/style/style.css +6 -0
  134. package/dist/es/packages/tabbaritem/style/style.css +6 -0
  135. package/dist/es/packages/tabbaritem/style/tabbaritem.scss +6 -0
  136. package/dist/es/packages/timeselect/style/style.css +12 -0
  137. package/dist/es/packages/tour/style/style.css +12 -0
  138. package/dist/es/utils/get-rect-by-taro.d.ts +1 -1
  139. package/dist/es/utils/get-rect-by-taro.js +4 -1
  140. package/dist/es/utils/get-system-info.js +4 -4
  141. package/dist/es/utils/merge.d.ts +14 -0
  142. package/dist/es/utils/merge.js +68 -0
  143. package/dist/es/utils/platform-taro.js +4 -4
  144. package/dist/es/utils/to-array.d.ts +1 -0
  145. package/dist/es/utils/to-array.js +8 -0
  146. package/dist/nutui.react.umd.js +1483 -1416
  147. package/dist/style.css +1 -1
  148. package/dist/style.scss +33 -35
  149. package/dist/styles/variables-jmapp.scss +0 -50
  150. package/dist/styles/variables-jrkf.scss +0 -50
  151. package/dist/styles/variables.scss +0 -49
  152. package/package.json +1 -1
  153. package/dist/cjs/packages/sidenavbar/context.d.ts +0 -1
  154. package/dist/cjs/packages/sidenavbar/context.js +0 -12
  155. package/dist/cjs/packages/sidenavbar/index.d.ts +0 -3
  156. package/dist/cjs/packages/sidenavbar/index.js +0 -12
  157. package/dist/cjs/packages/sidenavbar/sidenavbar.d.ts +0 -14
  158. package/dist/cjs/packages/sidenavbar/sidenavbar.js +0 -70
  159. package/dist/cjs/packages/sidenavbar/style/index.js +0 -2
  160. package/dist/cjs/packages/sidenavbar/style/sidenavbar.scss +0 -89
  161. package/dist/cjs/packages/sidenavbar/style/style.css +0 -443
  162. package/dist/cjs/packages/sidenavbar/utils.d.ts +0 -3
  163. package/dist/cjs/packages/sidenavbar/utils.js +0 -23
  164. package/dist/cjs/packages/sidenavbaritem/index.d.ts +0 -3
  165. package/dist/cjs/packages/sidenavbaritem/index.js +0 -12
  166. package/dist/cjs/packages/sidenavbaritem/sidenavbaritem.d.ts +0 -11
  167. package/dist/cjs/packages/sidenavbaritem/sidenavbaritem.js +0 -34
  168. package/dist/cjs/packages/sidenavbaritem/style/index.js +0 -1
  169. package/dist/cjs/packages/sidenavbaritem/style/sidenavbaritem.scss +0 -13
  170. package/dist/cjs/packages/sidenavbaritem/style/style.css +0 -14
  171. package/dist/cjs/packages/subsidenavbar/index.d.ts +0 -3
  172. package/dist/cjs/packages/subsidenavbar/style/css.js +0 -1
  173. package/dist/cjs/packages/subsidenavbar/style/index.js +0 -1
  174. package/dist/cjs/packages/subsidenavbar/style/style.css +0 -20
  175. package/dist/cjs/packages/subsidenavbar/style/subsidenavbar.scss +0 -26
  176. package/dist/cjs/packages/subsidenavbar/subsidenavbar.d.ts +0 -13
  177. package/dist/cjs/packages/subsidenavbar/subsidenavbar.js +0 -88
  178. package/dist/es/packages/sidenavbar/context.d.ts +0 -1
  179. package/dist/es/packages/sidenavbar/context.js +0 -2
  180. package/dist/es/packages/sidenavbar/index.d.ts +0 -3
  181. package/dist/es/packages/sidenavbar/index.js +0 -2
  182. package/dist/es/packages/sidenavbar/sidenavbar.d.ts +0 -38
  183. package/dist/es/packages/sidenavbar/sidenavbar.js +0 -58
  184. package/dist/es/packages/sidenavbar/style/css.js +0 -1
  185. package/dist/es/packages/sidenavbar/style/index.js +0 -2
  186. package/dist/es/packages/sidenavbar/style/sidenavbar.scss +0 -89
  187. package/dist/es/packages/sidenavbar/style/style.css +0 -443
  188. package/dist/es/packages/sidenavbar/utils.d.ts +0 -3
  189. package/dist/es/packages/sidenavbar/utils.js +0 -14
  190. package/dist/es/packages/sidenavbaritem/index.d.ts +0 -3
  191. package/dist/es/packages/sidenavbaritem/index.js +0 -2
  192. package/dist/es/packages/sidenavbaritem/sidenavbaritem.d.ts +0 -11
  193. package/dist/es/packages/sidenavbaritem/sidenavbaritem.js +0 -23
  194. package/dist/es/packages/sidenavbaritem/style/css.js +0 -1
  195. package/dist/es/packages/sidenavbaritem/style/index.js +0 -1
  196. package/dist/es/packages/sidenavbaritem/style/sidenavbaritem.scss +0 -13
  197. package/dist/es/packages/sidenavbaritem/style/style.css +0 -14
  198. package/dist/es/packages/subsidenavbar/index.d.ts +0 -3
  199. package/dist/es/packages/subsidenavbar/index.js +0 -2
  200. package/dist/es/packages/subsidenavbar/style/css.js +0 -1
  201. package/dist/es/packages/subsidenavbar/style/index.js +0 -1
  202. package/dist/es/packages/subsidenavbar/style/style.css +0 -20
  203. package/dist/es/packages/subsidenavbar/style/subsidenavbar.scss +0 -26
  204. package/dist/es/packages/subsidenavbar/subsidenavbar.d.ts +0 -13
  205. package/dist/es/packages/subsidenavbar/subsidenavbar.js +0 -77
  206. /package/dist/cjs/packages/{sidenavbar → datepickerview}/style/css.js +0 -0
  207. /package/dist/{cjs/packages/sidenavbaritem → es/packages/datepickerview}/style/css.js +0 -0
@@ -0,0 +1,541 @@
1
+ import { _ as _call_super } from "@swc/helpers/_/_call_super";
2
+ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
3
+ import { _ as _inherits } from "@swc/helpers/_/_inherits";
4
+ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
5
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
6
+ import { _ as _wrap_native_super } from "@swc/helpers/_/_wrap_native_super";
7
+ import { merge, clone, recursive, isPlainObject } from "../../../utils/merge";
8
+ describe('merge', function() {
9
+ it('merges two objects', function() {
10
+ expect(merge({
11
+ a: 1
12
+ }, {
13
+ b: 2
14
+ })).toStrictEqual({
15
+ a: 1,
16
+ b: 2
17
+ });
18
+ });
19
+ it('merges nested levels', function() {
20
+ expect(merge({
21
+ a: 1
22
+ }, {
23
+ b: {
24
+ c: {
25
+ d: 2
26
+ }
27
+ }
28
+ })).toStrictEqual({
29
+ a: 1,
30
+ b: {
31
+ c: {
32
+ d: 2
33
+ }
34
+ }
35
+ });
36
+ });
37
+ it('clones the target', function() {
38
+ var input = {
39
+ a: 1,
40
+ b: {
41
+ c: {
42
+ d: 2,
43
+ e: [
44
+ 'x',
45
+ 'y',
46
+ {
47
+ z: {
48
+ w: [
49
+ 'k'
50
+ ]
51
+ }
52
+ }
53
+ ]
54
+ }
55
+ },
56
+ f: null,
57
+ g: undefined,
58
+ h: true
59
+ };
60
+ var original = {
61
+ a: 1,
62
+ b: {
63
+ c: {
64
+ d: 2,
65
+ e: [
66
+ 'x',
67
+ 'y',
68
+ {
69
+ z: {
70
+ w: [
71
+ 'k'
72
+ ]
73
+ }
74
+ }
75
+ ]
76
+ }
77
+ },
78
+ f: null,
79
+ g: undefined,
80
+ h: true
81
+ };
82
+ var output = merge(true, input);
83
+ input.b.c.d++;
84
+ input.b.c.e[2].z.w = null;
85
+ input.h = null;
86
+ expect(output).toStrictEqual(original);
87
+ input = original;
88
+ output = merge(true, input, {
89
+ a: 2
90
+ });
91
+ expect(output.a).toBe(2);
92
+ expect(input.a).toBe(1);
93
+ });
94
+ it('ignores the sources', function() {
95
+ var values = createNonPlainObjects();
96
+ var $merge = vi.fn().mockImplementation(merge);
97
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
98
+ try {
99
+ for(var _iterator = values[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
100
+ var value = _step.value;
101
+ expect($merge(value)).toStrictEqual({});
102
+ }
103
+ } catch (err) {
104
+ _didIteratorError = true;
105
+ _iteratorError = err;
106
+ } finally{
107
+ try {
108
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
109
+ _iterator.return();
110
+ }
111
+ } finally{
112
+ if (_didIteratorError) {
113
+ throw _iteratorError;
114
+ }
115
+ }
116
+ }
117
+ expect(values.length).toBeGreaterThan(0);
118
+ expect($merge).toBeCalledTimes(values.length);
119
+ expect(merge.apply(void 0, _to_consumable_array(values).concat([
120
+ [
121
+ 0,
122
+ 1,
123
+ 2
124
+ ]
125
+ ], _to_consumable_array(values), [
126
+ {
127
+ a: 1
128
+ }
129
+ ], _to_consumable_array(values), [
130
+ {
131
+ b: 2
132
+ }
133
+ ]))).toStrictEqual({
134
+ a: 1,
135
+ b: 2
136
+ });
137
+ });
138
+ it('does not merge non plain objects', function() {
139
+ var values = createNonPlainObjects();
140
+ expect(values.length).toBeGreaterThan(0);
141
+ var input = {};
142
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
143
+ try {
144
+ for(var _iterator = Object.entries(values)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
145
+ var _step_value = _sliced_to_array(_step.value, 2), index = _step_value[0], value = _step_value[1];
146
+ input["value".concat(index)] = value;
147
+ }
148
+ } catch (err) {
149
+ _didIteratorError = true;
150
+ _iteratorError = err;
151
+ } finally{
152
+ try {
153
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
154
+ _iterator.return();
155
+ }
156
+ } finally{
157
+ if (_didIteratorError) {
158
+ throw _iteratorError;
159
+ }
160
+ }
161
+ }
162
+ var output = merge({}, input);
163
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
164
+ try {
165
+ for(var _iterator1 = Object.entries(values)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
166
+ var _step_value1 = _sliced_to_array(_step1.value, 1), index1 = _step_value1[0];
167
+ var key = "value".concat(index1);
168
+ var inputValue = input[key];
169
+ var outputValue = output[key];
170
+ // eslint-disable-next-line no-restricted-globals
171
+ if (typeof outputValue === 'number' && isNaN(outputValue)) {
172
+ // eslint-disable-next-line no-restricted-globals
173
+ expect(isNaN(inputValue), key).toBeTruthy();
174
+ } else {
175
+ expect(inputValue === outputValue, key).toBeTruthy();
176
+ }
177
+ }
178
+ } catch (err) {
179
+ _didIteratorError1 = true;
180
+ _iteratorError1 = err;
181
+ } finally{
182
+ try {
183
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
184
+ _iterator1.return();
185
+ }
186
+ } finally{
187
+ if (_didIteratorError1) {
188
+ throw _iteratorError1;
189
+ }
190
+ }
191
+ }
192
+ });
193
+ it('is safe', function() {
194
+ expect(merge({}, JSON.parse('{"__proto__": {"evil": true}}'))).toStrictEqual({});
195
+ expect({}.evil).toBeUndefined();
196
+ });
197
+ });
198
+ describe('clone', function() {
199
+ it('clones the input', function() {
200
+ var object1 = {
201
+ a: 1,
202
+ b: {
203
+ c: 2
204
+ }
205
+ };
206
+ var object2 = clone(object1);
207
+ expect(object1).toStrictEqual(object2);
208
+ expect(object1 === object2).toBeFalsy();
209
+ expect(object1.b === object2.b).toBeFalsy();
210
+ });
211
+ it('clones each item of the array', function() {
212
+ var object1 = [
213
+ {
214
+ a: 1,
215
+ b: {
216
+ c: 2
217
+ }
218
+ }
219
+ ];
220
+ var object2 = clone(object1);
221
+ expect(object1).toStrictEqual(object2);
222
+ expect(object1 === object2).toBeFalsy();
223
+ expect(object1[0] === object2[0]).toBeFalsy();
224
+ expect(object1[0].b === object2[0].b).toBeFalsy();
225
+ });
226
+ it('returns the same input', function() {
227
+ var values = createNonPlainObjects();
228
+ var $clone = vi.fn().mockImplementation(clone);
229
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
230
+ try {
231
+ for(var _iterator = values[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
232
+ var value = _step.value;
233
+ var cloned = $clone(value);
234
+ // eslint-disable-next-line no-restricted-globals
235
+ if (typeof cloned === 'number' && isNaN(cloned)) {
236
+ // eslint-disable-next-line no-restricted-globals
237
+ expect(isNaN(value)).toBeTruthy();
238
+ } else if (Array.isArray(cloned)) {
239
+ expect(Array.isArray(value)).toBeTruthy();
240
+ } else {
241
+ expect(cloned === value).toBeTruthy();
242
+ }
243
+ }
244
+ } catch (err) {
245
+ _didIteratorError = true;
246
+ _iteratorError = err;
247
+ } finally{
248
+ try {
249
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
250
+ _iterator.return();
251
+ }
252
+ } finally{
253
+ if (_didIteratorError) {
254
+ throw _iteratorError;
255
+ }
256
+ }
257
+ }
258
+ expect(values.length).toBeGreaterThan(0);
259
+ expect($clone).toBeCalledTimes(values.length);
260
+ });
261
+ });
262
+ describe('recursive', function() {
263
+ it('merges recursively', function() {
264
+ expect(recursive({
265
+ a: {
266
+ b: 1
267
+ }
268
+ }, {
269
+ a: {
270
+ c: 1
271
+ }
272
+ })).toStrictEqual({
273
+ a: {
274
+ b: 1,
275
+ c: 1
276
+ }
277
+ });
278
+ expect(recursive({
279
+ a: {
280
+ b: 1,
281
+ c: 1
282
+ }
283
+ }, {
284
+ a: {
285
+ b: 2
286
+ }
287
+ })).toStrictEqual({
288
+ a: {
289
+ b: 2,
290
+ c: 1
291
+ }
292
+ });
293
+ expect(recursive({
294
+ a: {
295
+ b: [
296
+ 1,
297
+ 2,
298
+ 3
299
+ ],
300
+ c: 1
301
+ }
302
+ }, {
303
+ a: {
304
+ b: [
305
+ 'a'
306
+ ]
307
+ }
308
+ })).toStrictEqual({
309
+ a: {
310
+ b: [
311
+ 'a'
312
+ ],
313
+ c: 1
314
+ }
315
+ });
316
+ expect(recursive({
317
+ a: {
318
+ b: {
319
+ b: 2
320
+ },
321
+ c: 1
322
+ }
323
+ }, {
324
+ a: {
325
+ b: 2
326
+ }
327
+ })).toStrictEqual({
328
+ a: {
329
+ b: 2,
330
+ c: 1
331
+ }
332
+ });
333
+ });
334
+ it('clones recursively', function() {
335
+ var test1 = {
336
+ a: {
337
+ b: 1
338
+ }
339
+ };
340
+ expect(recursive(true, test1, {
341
+ a: {
342
+ c: 1
343
+ }
344
+ })).toStrictEqual({
345
+ a: {
346
+ b: 1,
347
+ c: 1
348
+ }
349
+ });
350
+ expect(test1).toStrictEqual({
351
+ a: {
352
+ b: 1
353
+ }
354
+ });
355
+ var test2 = {
356
+ a: {
357
+ b: 1,
358
+ c: 1
359
+ }
360
+ };
361
+ expect(recursive(true, test2, {
362
+ a: {
363
+ b: 2
364
+ }
365
+ })).toStrictEqual({
366
+ a: {
367
+ b: 2,
368
+ c: 1
369
+ }
370
+ });
371
+ expect(test2).toStrictEqual({
372
+ a: {
373
+ b: 1,
374
+ c: 1
375
+ }
376
+ });
377
+ var test3 = {
378
+ a: {
379
+ b: [
380
+ 1,
381
+ 2,
382
+ 3
383
+ ],
384
+ c: 1
385
+ }
386
+ };
387
+ expect(recursive(true, test3, {
388
+ a: {
389
+ b: [
390
+ 'a'
391
+ ]
392
+ }
393
+ })).toStrictEqual({
394
+ a: {
395
+ b: [
396
+ 'a'
397
+ ],
398
+ c: 1
399
+ }
400
+ });
401
+ expect(test3).toStrictEqual({
402
+ a: {
403
+ b: [
404
+ 1,
405
+ 2,
406
+ 3
407
+ ],
408
+ c: 1
409
+ }
410
+ });
411
+ var test4 = {
412
+ a: {
413
+ b: {
414
+ b: 2
415
+ },
416
+ c: 1
417
+ }
418
+ };
419
+ expect(recursive(true, test4, {
420
+ a: {
421
+ b: 2
422
+ }
423
+ })).toStrictEqual({
424
+ a: {
425
+ b: 2,
426
+ c: 1
427
+ }
428
+ });
429
+ expect(test4).toStrictEqual({
430
+ a: {
431
+ b: {
432
+ b: 2
433
+ },
434
+ c: 1
435
+ }
436
+ });
437
+ });
438
+ it('does not merge non plain objects', function() {
439
+ var object = recursive({
440
+ map: {
441
+ length: 1
442
+ }
443
+ }, {
444
+ map: new Map()
445
+ });
446
+ expect(object.map).toBeInstanceOf(Map);
447
+ });
448
+ it('is safe', function() {
449
+ var payload = '{"__proto__": {"a": true}}';
450
+ expect(recursive({}, JSON.parse(payload))).toStrictEqual({});
451
+ expect({}.a).toBeUndefined();
452
+ expect(recursive({
453
+ deep: {}
454
+ }, JSON.parse(payload))).toStrictEqual({
455
+ deep: {}
456
+ });
457
+ expect({}.b).toBeUndefined();
458
+ });
459
+ });
460
+ describe('isPlainObject', function() {
461
+ it('returns true', function() {
462
+ expect(isPlainObject({})).toBeTruthy();
463
+ expect(isPlainObject({
464
+ v: 1
465
+ })).toBeTruthy();
466
+ expect(isPlainObject(Object.create(null))).toBeTruthy();
467
+ expect(isPlainObject({})).toBeTruthy();
468
+ });
469
+ it('returns false', function() {
470
+ var values = createNonPlainObjects();
471
+ var $isPlainObject = vi.fn().mockImplementation(isPlainObject);
472
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
473
+ try {
474
+ for(var _iterator = values[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
475
+ var value = _step.value;
476
+ expect($isPlainObject(value)).toBeFalsy();
477
+ }
478
+ } catch (err) {
479
+ _didIteratorError = true;
480
+ _iteratorError = err;
481
+ } finally{
482
+ try {
483
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
484
+ _iterator.return();
485
+ }
486
+ } finally{
487
+ if (_didIteratorError) {
488
+ throw _iteratorError;
489
+ }
490
+ }
491
+ }
492
+ expect(values.length).toBeGreaterThan(0);
493
+ expect($isPlainObject).toBeCalledTimes(values.length);
494
+ });
495
+ });
496
+ function createNonPlainObjects() {
497
+ var SubObject = /*#__PURE__*/ function(Object1) {
498
+ "use strict";
499
+ _inherits(SubObject, Object1);
500
+ function SubObject() {
501
+ _class_call_check(this, SubObject);
502
+ return _call_super(this, SubObject, arguments);
503
+ }
504
+ return SubObject;
505
+ }(_wrap_native_super(Object));
506
+ return [
507
+ null,
508
+ undefined,
509
+ 1,
510
+ '',
511
+ 'str',
512
+ [],
513
+ [
514
+ 1
515
+ ],
516
+ function() {},
517
+ function() {},
518
+ true,
519
+ false,
520
+ NaN,
521
+ Infinity,
522
+ function _class() {
523
+ "use strict";
524
+ _class_call_check(this, _class);
525
+ },
526
+ new function _class() {
527
+ "use strict";
528
+ _class_call_check(this, _class);
529
+ }(),
530
+ new Map(),
531
+ new Set(),
532
+ new Date(),
533
+ [],
534
+ new Date(),
535
+ /./,
536
+ /./,
537
+ SubObject,
538
+ new SubObject(),
539
+ Symbol('')
540
+ ];
541
+ }
@@ -22,8 +22,18 @@ export interface FormProps extends BasicComponent {
22
22
  * @default -
23
23
  */
24
24
  form: any
25
+ /**
26
+ * 是否禁用
27
+ * @default false
28
+ */
29
+ disabled: boolean
25
30
  divider: boolean;
26
31
  /**
32
+ * 统一设置字段触发验证的时机
33
+ * @default onChange
34
+ */
35
+ validateTrigger: string | string[] | false
36
+ /**
27
37
  * 表单项 label 的位置
28
38
  * @default right
29
39
  */
@@ -10,7 +10,9 @@ import Cell from "../cell";
10
10
  var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
11
11
  labelPosition: 'right',
12
12
  starPosition: 'left',
13
+ disabled: false,
13
14
  divider: false,
15
+ validateTrigger: 'onChange',
14
16
  onFinish: function(values) {},
15
17
  onFinishFailed: function(values, errorFields) {}
16
18
  });
@@ -21,7 +23,7 @@ var PositionInfo = {
21
23
  };
22
24
  export var Form = /*#__PURE__*/ React.forwardRef(function(props, ref) {
23
25
  var classPrefix = 'nut-form';
24
- var _$_object_spread = _object_spread({}, defaultProps, props), className = _$_object_spread.className, style = _$_object_spread.style, footer = _$_object_spread.footer, children = _$_object_spread.children, initialValues = _$_object_spread.initialValues, divider = _$_object_spread.divider, onFinish = _$_object_spread.onFinish, onFinishFailed = _$_object_spread.onFinishFailed, labelPosition = _$_object_spread.labelPosition, starPosition = _$_object_spread.starPosition, form = _$_object_spread.form;
26
+ var _$_object_spread = _object_spread({}, defaultProps, props), className = _$_object_spread.className, style = _$_object_spread.style, footer = _$_object_spread.footer, children = _$_object_spread.children, initialValues = _$_object_spread.initialValues, divider = _$_object_spread.divider, disabled = _$_object_spread.disabled, onFinish = _$_object_spread.onFinish, onFinishFailed = _$_object_spread.onFinishFailed, validateTrigger = _$_object_spread.validateTrigger, labelPosition = _$_object_spread.labelPosition, starPosition = _$_object_spread.starPosition, form = _$_object_spread.form;
25
27
  var formInstance;
26
28
  if (form !== undefined) {
27
29
  formInstance = form;
@@ -64,7 +66,12 @@ export var Form = /*#__PURE__*/ React.forwardRef(function(props, ref) {
64
66
  }, /*#__PURE__*/ React.createElement(Cell.Group, {
65
67
  divider: divider
66
68
  }, /*#__PURE__*/ React.createElement(Context.Provider, {
67
- value: formInstance
69
+ value: {
70
+ formInstance: formInstance,
71
+ labelPosition: labelPosition,
72
+ disabled: disabled,
73
+ validateTrigger: validateTrigger
74
+ }
68
75
  }, children), footer ? /*#__PURE__*/ React.createElement(Cell, {
69
76
  className: "".concat(classPrefix, "-footer")
70
77
  }, footer) : null));
@@ -2,11 +2,12 @@ import React from 'react';
2
2
  import { FormProps } from './form';
3
3
  import { FormItem } from '../formitem/formitem';
4
4
  import { FormInstance } from './types';
5
- import { useForm } from "./useform";
5
+ import { useForm, useWatch } from "./useform";
6
6
  export type { FormItemRuleWithoutValidator, FormInstance, FormFieldEntity, } from './types';
7
7
  type CompoundedComponent = React.ForwardRefExoticComponent<Partial<FormProps> & Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & React.RefAttributes<FormInstance>> & {
8
8
  Item: typeof FormItem;
9
9
  useForm: typeof useForm;
10
+ useWatch: typeof useWatch;
10
11
  };
11
12
  declare const InnerForm: CompoundedComponent;
12
13
  export default InnerForm;
@@ -1,8 +1,9 @@
1
1
  import React from "react";
2
2
  import { Form } from "./form";
3
3
  import { FormItem } from "../formitem/formitem";
4
- import { useForm } from "./useform";
4
+ import { useForm, useWatch } from "./useform";
5
5
  var InnerForm = Form;
6
6
  InnerForm.Item = FormItem;
7
7
  InnerForm.useForm = useForm;
8
+ InnerForm.useWatch = useWatch;
8
9
  export default InnerForm;
@@ -1,67 +1 @@
1
- .form-layout-right .nut-form-item-label {
2
- text-align: right;
3
- padding-right: 24px;
4
- white-space: nowrap;
5
- }
6
1
 
7
- .form-layout-left .nut-form-item-label {
8
- position: relative;
9
- text-align: left;
10
- padding-left: 12px;
11
- white-space: nowrap;
12
-
13
- .required {
14
- display: block;
15
- line-height: 1.5;
16
- position: absolute;
17
- left: 0.1em;
18
- }
19
- }
20
-
21
- .form-layout-top .nut-form-item {
22
- flex-direction: column;
23
- align-items: flex-start;
24
- white-space: nowrap;
25
- }
26
-
27
- .form-layout-top .nut-form-item-label {
28
- padding-bottom: 4px;
29
- display: block;
30
- padding-right: 24px;
31
- }
32
-
33
- .form-layout-top .nut-form-item-body {
34
- margin-left: 0;
35
- width: 100%;
36
- }
37
-
38
- [dir='rtl'] .form-layout-right .nut-form-item-label,
39
- .nut-rtl .form-layout-right .nut-form-item-label {
40
- text-align: left;
41
- padding-right: 0;
42
- padding-left: 24px;
43
- }
44
-
45
- [dir='rtl'] .form-layout-left .nut-form-item-label,
46
- .nut-rtl .form-layout-left .nut-form-item-label {
47
- text-align: right;
48
- padding-left: 0;
49
- padding-right: 12px;
50
-
51
- .required {
52
- left: auto;
53
- right: 0.1em;
54
- }
55
- }
56
-
57
- [dir='rtl'] .form-layout-top .nut-form-item-label,
58
- .nut-rtl .form-layout-top .nut-form-item-label {
59
- padding-right: 0;
60
- padding-left: 24px;
61
- }
62
-
63
- [dir='rtl'] .form-layout-top .nut-form-item-body,
64
- .nut-rtl .form-layout-top .nut-form-item-body {
65
- margin-left: 0;
66
- margin-right: 0;
67
- }