yy-forms 1.0.44 → 1.0.46

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 (59) hide show
  1. package/dist/index.esm.js +5 -4
  2. package/dist/index.js +5 -4
  3. package/package.json +2 -1
  4. package/.fatherrc.js +0 -37
  5. package/CHANGELOG.md +0 -254
  6. package/es/Provider.js +0 -248
  7. package/es/index.d.ts +0 -145
  8. package/es/index.js +0 -44
  9. package/es/settings/index.js +0 -975
  10. package/es/styles/atom.less +0 -1134
  11. package/es/styles/index.less +0 -358
  12. package/es/transformer/form-render.js +0 -75
  13. package/es/utils/context.js +0 -3
  14. package/es/utils/hooks.js +0 -48
  15. package/es/utils/index.js +0 -706
  16. package/es/utils/mapping.js +0 -31
  17. package/es/utils/serialize.js +0 -276
  18. package/es/widgets/htmlInput.js +0 -20
  19. package/es/widgets/idInput.js +0 -23
  20. package/es/widgets/index.js +0 -5
  21. package/es/widgets/jsonInput.js +0 -24
  22. package/es/widgets/list.js +0 -24
  23. package/es/widgets/percentSlider.js +0 -89
  24. package/src/Provider.jsx +0 -239
  25. package/src/components/Canvas/core/RenderChildren.jsx +0 -18
  26. package/src/components/Canvas/core/RenderField.jsx +0 -131
  27. package/src/components/Canvas/core/Wrapper.jsx +0 -298
  28. package/src/components/Canvas/core/Wrapper.less +0 -57
  29. package/src/components/Canvas/core/index.jsx +0 -171
  30. package/src/components/Canvas/index.jsx +0 -178
  31. package/src/components/Settings/GlobalSettings.jsx +0 -50
  32. package/src/components/Settings/ItemSettings.jsx +0 -154
  33. package/src/components/Settings/index.jsx +0 -75
  34. package/src/components/Settings/index.less +0 -25
  35. package/src/components/Sidebar/Element.jsx +0 -80
  36. package/src/components/Sidebar/Element.less +0 -18
  37. package/src/components/Sidebar/index.jsx +0 -47
  38. package/src/components/Sidebar/index.less +0 -23
  39. package/src/i18next/index.ts +0 -14
  40. package/src/i18next/locales/enUS.json +0 -51
  41. package/src/i18next/locales/resources.ts +0 -7
  42. package/src/i18next/locales/zhCN.json +0 -3
  43. package/src/index.d.ts +0 -145
  44. package/src/index.js +0 -45
  45. package/src/settings/index.js +0 -2030
  46. package/src/styles/atom.less +0 -1134
  47. package/src/styles/index.less +0 -358
  48. package/src/transformer/form-render.js +0 -65
  49. package/src/utils/context.js +0 -4
  50. package/src/utils/hooks.js +0 -35
  51. package/src/utils/index.js +0 -678
  52. package/src/utils/mapping.js +0 -29
  53. package/src/utils/serialize.js +0 -368
  54. package/src/widgets/htmlInput.jsx +0 -24
  55. package/src/widgets/idInput.jsx +0 -27
  56. package/src/widgets/index.js +0 -6
  57. package/src/widgets/jsonInput.jsx +0 -29
  58. package/src/widgets/list.jsx +0 -28
  59. package/src/widgets/percentSlider.jsx +0 -74
@@ -1,358 +0,0 @@
1
- @import './atom.less';
2
-
3
- /*
4
- 用于原有样式的覆盖
5
- */
6
- .fr-generator-container {
7
- display: flex;
8
- overflow: hidden;
9
- height: 100%;
10
- min-height: 30vh;
11
- position: relative;
12
- .mid-layout {
13
- padding: 0 8px;
14
- display: flex;
15
- flex-direction: column;
16
- flex-grow: 1;
17
- flex-shrink: 1;
18
- /* height: 100%; */
19
- overflow: hidden;
20
- border-left: 1px solid #e0e0e0;
21
- border-right: 1px solid #e0e0e0;
22
- }
23
-
24
- .flex-center {
25
- display: flex;
26
- justify-content: center;
27
- align-items: center;
28
- }
29
-
30
- .dnd-container {
31
- flex-grow: 1;
32
- overflow-y: auto;
33
- }
34
-
35
- .ant-tabs.ant-tabs-top {
36
- display: flex;
37
- flex-direction: column;
38
- height: 100%;
39
- }
40
-
41
- .ant-tabs-content-holder {
42
- flex-grow: 1;
43
- }
44
-
45
- .ant-tabs-content.ant-tabs-content-top {
46
- height: 100%;
47
- }
48
-
49
- .ant-tabs-tabpane.ant-tabs-tabpane-active {
50
- height: 100%;
51
- overflow-y: auto;
52
- }
53
- }
54
-
55
- .fr-generator-container .dnd-container.edit {
56
- .top-upper {
57
- top: -12px;
58
- }
59
-
60
- .fr-set {
61
- padding: 12px 14px 12px 12px;
62
- margin-bottom: 12px;
63
- border-radius: 4px;
64
- }
65
-
66
- .fr-field {
67
- margin-bottom: 24px;
68
- }
69
-
70
- .fr-label {
71
- display: block;
72
- }
73
-
74
- .fr-label-title {
75
- display: inline-flex;
76
- color: #333;
77
- font-size: 14px;
78
- min-height: 22px; /* ""的标签页占位 */
79
- line-height: 22px;
80
- }
81
-
82
- .fr-label-required {
83
- margin: 1px 4px 0 0;
84
- color: #f5222d;
85
- font-size: 14px;
86
- font-family: SimSun, sans-serif;
87
- }
88
-
89
- .fr-label-title::after {
90
- content: ':';
91
- position: relative;
92
- top: -0.5px;
93
- margin: 0 10px 0 2px;
94
- }
95
-
96
- .fr-label-title.no-colon::after {
97
- content: '';
98
- margin: 0;
99
- }
100
-
101
- .fr-label-object .fr-label-title {
102
- font-size: 16px;
103
- color: #222;
104
- }
105
-
106
- .fr-desc {
107
- margin-top: 3px;
108
- font-size: 12px;
109
- word-break: break-all;
110
- color: #888;
111
- }
112
-
113
- .fr-validate {
114
- margin-left: 12px;
115
- font-size: 12px;
116
- word-break: break-all;
117
- color: #f5222d;
118
- }
119
-
120
- /* Row */
121
-
122
- .fr-validate-row {
123
- margin: 3px 0 0 0;
124
- }
125
-
126
- .fr-label-row {
127
- text-align: right;
128
- flex-shrink: 0;
129
- }
130
-
131
- .fr-field-row .fr-content {
132
- flex: 1;
133
- position: relative;
134
- }
135
-
136
- .fr-field-row .fr-tooltip-icon {
137
- margin: 3px 2px 0 0;
138
- }
139
-
140
- /* 自定义类 */
141
- .hover-b--black-20:hover {
142
- border-color: rgba(0, 0, 0, 0.3);
143
- }
144
-
145
- .pt44 {
146
- padding-top: 46px;
147
- }
148
-
149
- .pv12 {
150
- padding-top: 12px;
151
- padding-bottom: 12px;
152
- }
153
-
154
- /* 组件内部样式*/
155
- .fr-color-picker {
156
- width: 100%;
157
- display: flex;
158
- flex-direction: row;
159
- align-items: center;
160
- color: #666;
161
- }
162
-
163
- .fr-color-picker .rc-color-picker-trigger {
164
- margin-right: 12px;
165
- height: 30px;
166
- width: 60px;
167
- border: 1px solid #e5e5e5;
168
- }
169
-
170
- .fr-color-picker > p {
171
- margin: 0;
172
- font-size: 14px;
173
- line-height: 28px;
174
- }
175
-
176
- .fr-color-picker .rc-color-picker-wrap {
177
- display: flex;
178
- }
179
-
180
- .next-input,
181
- .next-number-picker {
182
- width: 100%;
183
- }
184
-
185
- .upload-img {
186
- max-width: 200px;
187
- max-height: 200px;
188
- margin-right: 24px;
189
- }
190
-
191
- .fr-preview-image {
192
- width: 160px;
193
- }
194
-
195
- .fr-preview {
196
- position: relative;
197
- cursor: pointer;
198
- }
199
-
200
- .fr-upload-mod,
201
- .fr-upload-file {
202
- display: flex;
203
- }
204
- .fr-upload-mod {
205
- align-items: center;
206
- }
207
- .fr-upload-mod .fr-upload-preview {
208
- margin: 0 12px;
209
- }
210
- .fr-upload-file .ant-upload-list-item {
211
- margin: 5px 0 0 8px;
212
- }
213
- .fr-upload-file .ant-upload-list-item-name {
214
- margin-right: 6px;
215
- }
216
- .fr-upload-file .ant-upload-list-item-info {
217
- cursor: pointer;
218
- }
219
- .fr-upload-file .next-upload-list-text .next-upload-list-item-done,
220
- .fr-upload-file .next-upload-list-text .next-upload-list-item .next-icon {
221
- height: 28px;
222
- line-height: 28px;
223
- margin-left: 12px;
224
- }
225
-
226
- .fr-upload-file .next-upload-list-item-name-wrap {
227
- margin-top: -4px;
228
- }
229
-
230
- .fr-sort-help-class {
231
- background: #fff;
232
- }
233
-
234
- /* 其他样式 */
235
-
236
- .fold-icon.fold-icon-active {
237
- transform: rotate(0deg);
238
- }
239
-
240
- .fold-icon {
241
- transform: rotate(-90deg);
242
- transition: transform 0.24s;
243
- cursor: pointer;
244
- position: relative;
245
- }
246
-
247
- .fold-icon::after {
248
- content: '';
249
- position: absolute;
250
- top: -20px;
251
- right: -10px;
252
- bottom: -5px;
253
- left: -20px;
254
- }
255
-
256
- .fr-tooltip-toggle {
257
- cursor: pointer;
258
- position: relative;
259
- }
260
-
261
- .fr-tooltip-toggle:hover .fr-tooltip-container {
262
- opacity: 1;
263
- visibility: visible;
264
- }
265
-
266
- .fr-tooltip-icon {
267
- height: 14px;
268
- width: 14px;
269
- background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAEnUlEQVR42u1bS0iUURT+zd4Y9KDosSihNhYUaBE9YKpFDKKOOmOLahtJ2SoxA2fUdUoQJK5qU0ib6LlxUYJpkY0LE3tQZkU7y7A0e1jnA4Of8pz//5373/+BF44Oc+/c853v3nOf5xpup0QiMZ9kD8mxeDzeTHKXPveSvKXP3+j/GP1/h++QhzIoW1ZWthu/NYKYysvLN5EhKZJ7ZMQEye8ZyjjJfZIk6vS10YWFhcvI4FoC2wfwLkkf6aiBLt8YHovFNhCoFnRlgNQkY9BJbrLeS9uzqFueYAzXJV9ITgKLVsvBPCnuAAifSIe23kBd7zApHHUI8D3JBfptFUlialbYSJIDweep7+Iog7L4jUMdn4HNzeksmxRcdgColyRZWlq6NQOd21AH6rKrFxiBVanxxcXFS6jSdpsAHtLYUODC1FqAum0S0Q7Mqlp+ESlO2zD8DUmJBhcsgS4bJDwBdhUKb1ko+kll6qLR6AJDU4IuuAZ0W2C7kWnrJy1a/QONvjsNjxLp32VjsEzO1OcOkoJJoeJuGuBWGB4nYCCcD4RGmiSJOm35PIup7kokEplr+CQBCzAJeEeJqC22V3jE2IBQWVd+fv48w2cJmAhbp4C7H7bZaf1KoZJBbET8vCEDRgF/pdXGZim1/ifGl344WtTIJJ//B+ggts+K6t4BrAwBH2GjNKo2CuxVqzJeGLDqFemoFnQ0sq0vDHyP4D+KwI1ILqZqpyqsGmFjznStX8tNIzQlbjYUJasVnCo9wAzsjE1npyPgFQPqJvKDRYC8ioWt/200BFD7FRMwIu0nFBNwgNMFm80Fz0mAFIOqVz4IyoS/ZvQ1mQv1MYBqkO8GCSDXTDRjvAoCznAHrH/X0qu4FqE99Voj2AkErOPsg+3w/wqmwDMjHAkkPGdsPITMBqb7t4SFANjCjTkgoI0ZJY+Hwnp5f9MGdtIMOxF35n1ZXDrG38fYmDa48zWcs4eFANxesUtv+jPMZC4PCwE4NWL0DRvcehkHjyEhACdGCxl9vwBwggEyxw0wXhCAOANG34TsAi4k37kA/RliMnND1ANyGX1DGAMe89Og+uSjaRDSAwKucgeIYSEAcQzc8T4ISDGZrSFygVaml6dAQILJfBEiAl4yy/0KZK6WtsMBJwD+v0bcDk/tlp4yveB0cAmQj8hhs7lQE1NoIAQEPGdsazZ3k+3SoahOAvQfisoDBeR2QAmArjvcsbi2i5FMQ+Ay0Jvn6GIE10VWV2MBIiALmKWrMfFylJsRgkIAsAp1NojX47hCZn74HdfjficAAzp3PY6rf9g4GyBhw3/6Axoi0yW48IDtcQwBRVIUOHaQfguSAiYpvB42Od1Cxiz8s5tkpdfGAwOwSFhhy0xXUnV+DpSEbmCwwFiXKcPXbYTKpnSHykIndFsYf01JsDRJTxCDpUGU7nB5SKcfwuWLiooWK38wQXLJwcOFtIoHE/Bh5v6SE2DMdvNN4BE3nszQ93szfTJDclTbU7lAP5pSGIxY5eWzOdL/lXrkKW6Fp7M3XPTi4SR0zz6dnX087fOEq2k8hTc/nydJm57Pj3v5fP4PSqRR6oYkTaUAAAAASUVORK5CYII=');
270
- background-size: cover;
271
- display: block;
272
- margin: 4px 0 0 4px;
273
- }
274
-
275
- .fr-tooltip-container {
276
- position: absolute;
277
- width: 160px;
278
- left: 50%;
279
- white-space: initial !important;
280
- bottom: 30px;
281
- text-align: center;
282
- background: #2b222a;
283
- padding: 4px;
284
- margin-left: -77px;
285
- border-radius: 4px;
286
- color: #efefef;
287
- font-size: 13px;
288
- cursor: auto;
289
- z-index: 99999;
290
- transition: all 0.5s ease;
291
- opacity: 0;
292
- visibility: hidden;
293
- word-wrap: break-word;
294
- }
295
-
296
- .fr-tooltip-triangle {
297
- position: absolute;
298
- left: 50%;
299
- border-left: 5px solid transparent;
300
- border-right: 5px solid transparent;
301
- border-top: 5px solid #2b222a;
302
- transition: all 0.5s ease;
303
- content: ' ';
304
- font-size: 0;
305
- line-height: 0;
306
- margin-left: -5px;
307
- width: 0;
308
- bottom: -5px;
309
- }
310
-
311
- .fr-tooltip-toggle::before,
312
- .fr-tooltip-toggle::after {
313
- color: #efefef;
314
- font-size: 13px;
315
- opacity: 0;
316
- pointer-events: none;
317
- text-align: center;
318
- }
319
-
320
- .fr-tooltip-toggle:focus::before,
321
- .fr-tooltip-toggle:focus::after,
322
- .fr-tooltip-toggle:hover::before,
323
- .fr-tooltip-toggle:hover::after {
324
- opacity: 1;
325
- transition: all 0.75s ease;
326
- }
327
-
328
- .fr-slider {
329
- display: flex;
330
- width: 100%;
331
- align-items: center;
332
- }
333
-
334
- .fr-map {
335
- display: flex;
336
- flex-wrap: wrap;
337
- }
338
- }
339
-
340
- .frg-options-list {
341
- .fr-list-1 {
342
- .fr-field.fr-field-object {
343
- flex: 1;
344
- }
345
- .fr-field.fr-field-inline > div:first-child {
346
- display: none;
347
- }
348
- }
349
- .frg-options-input {
350
- &:first-child {
351
- margin-right: 6px;
352
- }
353
- .fr-content.fr-content-inline {
354
- max-width: 96px;
355
- min-width: 96px;
356
- }
357
- }
358
- }
@@ -1,75 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- import { getChildren2 } from '../utils';
8
-
9
- // Setting Schema => FR Schema
10
- var transformFrom = function transformFrom(schema) {
11
- var isObj = schema.type === 'object' && schema.properties;
12
- var isList = schema.type === 'array' && schema.items && schema.items.properties;
13
- var hasChildren = isObj || isList;
14
- if (!hasChildren) {
15
- if (Array.isArray(schema.enumList)) {
16
- schema.enum = schema.enumList.filter(function (item) {
17
- return item.value;
18
- }).map(function (item) {
19
- return item.value;
20
- });
21
- schema.enumNames = schema.enumList.filter(function (item) {
22
- return item.value;
23
- }).map(function (item) {
24
- return item.label || item.value;
25
- });
26
- }
27
- delete schema.enumList;
28
- } else {
29
- var childrenList = getChildren2(schema);
30
- childrenList.map(function (item) {
31
- if (isObj) {
32
- schema.properties[item.name] = transformTo(_objectSpread({}, item.schema));
33
- }
34
- if (isList) {
35
- schema.items.properties[item.name] = transformTo(_objectSpread({}, item.schema));
36
- }
37
- });
38
- }
39
- return schema;
40
- };
41
- export var fromSetting = function fromSetting(schema) {
42
- return transformFrom(_objectSpread({}, schema));
43
- };
44
-
45
- // FR Schema => Setting Schema
46
- var transformTo = function transformTo(schema) {
47
- var isObj = schema.type === 'object' && schema.properties;
48
- var isList = schema.type === 'array' && schema.items && schema.items.properties;
49
- var hasChildren = isObj || isList;
50
- if (!hasChildren) {
51
- if (Array.isArray(schema.enum) && Array.isArray(schema.enumNames)) {
52
- var list = schema.enum.map(function (item, idx) {
53
- return {
54
- value: item,
55
- label: schema.enumNames[idx]
56
- };
57
- });
58
- schema.enumList = list;
59
- }
60
- } else {
61
- var childrenList = getChildren2(schema);
62
- childrenList.map(function (item) {
63
- if (isObj) {
64
- schema.properties[item.name] = transformFrom(_objectSpread({}, item.schema));
65
- }
66
- if (isList) {
67
- schema.items.properties[item.name] = transformFrom(_objectSpread({}, item.schema));
68
- }
69
- });
70
- }
71
- return schema;
72
- };
73
- export var toSetting = function toSetting(schema) {
74
- return transformTo(_objectSpread({}, schema));
75
- };
@@ -1,3 +0,0 @@
1
- import { createContext } from 'react';
2
- export var Ctx = /*#__PURE__*/createContext(function () {});
3
- export var StoreCtx = /*#__PURE__*/createContext({});
package/es/utils/hooks.js DELETED
@@ -1,48 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
8
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
10
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
11
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
13
- import { useContext, useReducer } from 'react';
14
- import { Ctx, StoreCtx } from './context';
15
-
16
- // 使用最顶层组件的 setState
17
- export var useGlobal = function useGlobal() {
18
- return useContext(Ctx);
19
- };
20
-
21
- // 组件最顶层传入的所有props
22
- export var useStore = function useStore() {
23
- return useContext(StoreCtx);
24
- };
25
-
26
- // 类似于 class component 的 setState
27
- export var useSet = function useSet(initState) {
28
- var _useReducer = useReducer(function (state, newState) {
29
- var action = newState;
30
- if (typeof newState === 'function') {
31
- action = action(state);
32
- }
33
- if (newState.action && newState.payload) {
34
- action = newState.payload;
35
- if (typeof action === 'function') {
36
- action = action(state);
37
- }
38
- }
39
- return _objectSpread(_objectSpread({}, state), action);
40
- }, initState),
41
- _useReducer2 = _slicedToArray(_useReducer, 2),
42
- state = _useReducer2[0],
43
- setState = _useReducer2[1];
44
- var setStateWithActionName = function setStateWithActionName(state, actionName) {
45
- setState(state);
46
- };
47
- return [state, setStateWithActionName];
48
- };