ronds-metadata 1.2.10 → 1.2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. package/es/api/index.js +249 -0
  2. package/es/comps/DynamicPorts/comps/ContextMenu.js +44 -0
  3. package/es/comps/DynamicPorts/comps/DragNode.js +55 -0
  4. package/es/comps/DynamicPorts/comps/GraphHandler/index.js +51 -0
  5. package/es/comps/DynamicPorts/comps/NodeElement.js +30 -0
  6. package/es/comps/DynamicPorts/comps/contextMenu/EdgeContextMenu/index.js +42 -0
  7. package/es/comps/DynamicPorts/comps/contextMenu/GraphContextMenu/index.js +40 -0
  8. package/es/comps/DynamicPorts/comps/contextMenu/NodeContextMenu/index.js +55 -0
  9. package/es/comps/DynamicPorts/comps/shape/connector.js +19 -0
  10. package/es/comps/DynamicPorts/comps/shape/edge.js +91 -0
  11. package/es/comps/DynamicPorts/comps/shape/node.js +190 -0
  12. package/es/comps/DynamicPorts/constant/index.js +19 -0
  13. package/es/comps/DynamicPorts/graph.js +697 -0
  14. package/es/comps/DynamicPorts/index.js +143 -0
  15. package/es/comps/DynamicPorts/interface.js +6 -0
  16. package/es/comps/DynamicPorts/utils.js +127 -0
  17. package/es/comps/Editable/DataCell/ButtonCell.js +45 -0
  18. package/es/comps/Editable/DataCell/ColorPicker.js +33 -0
  19. package/es/comps/Editable/DataCell/Input.js +54 -0
  20. package/es/comps/Editable/DataCell/Number.js +44 -0
  21. package/es/comps/Editable/DataCell/Select.js +48 -0
  22. package/es/comps/Editable/DataCell/Switch.js +33 -0
  23. package/es/comps/Editable/comps/EditableAction.js +110 -0
  24. package/es/comps/Editable/comps/EditableCell.js +108 -0
  25. package/es/comps/Editable/comps/EditableHeardCell.js +172 -0
  26. package/es/comps/Editable/comps/EditableRow.js +118 -0
  27. package/es/comps/Editable/comps/Texty.js +277 -0
  28. package/es/comps/Editable/index.js +386 -0
  29. package/es/comps/Editable/interface.js +8 -0
  30. package/es/comps/Editable/utils.js +46 -0
  31. package/es/comps/FileView/index.js +198 -0
  32. package/es/comps/FormGenerator/Provider.js +8 -0
  33. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Checkbox.js +69 -0
  34. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Color.js +17 -0
  35. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Date.js +16 -0
  36. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Input.js +17 -0
  37. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/List.js +50 -0
  38. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/MutiSelect.js +55 -0
  39. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Number.js +14 -0
  40. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Obj.js +50 -0
  41. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Password.js +17 -0
  42. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Radio.js +69 -0
  43. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Select.js +55 -0
  44. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Switch.js +13 -0
  45. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Table.js +50 -0
  46. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/TextArea.js +14 -0
  47. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Upload.js +27 -0
  48. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/HOC/index.js +261 -0
  49. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/index.js +62 -0
  50. package/es/comps/FormGenerator/comps/Canvas/core/index.js +315 -0
  51. package/es/comps/FormGenerator/comps/Canvas/index.js +120 -0
  52. package/es/comps/FormGenerator/comps/Settings/index.js +150 -0
  53. package/es/comps/FormGenerator/comps/Sidebar/Elements.js +48 -0
  54. package/es/comps/FormGenerator/comps/Sidebar/index.js +37 -0
  55. package/es/comps/FormGenerator/index.js +68 -0
  56. package/es/comps/FormGenerator/settings/index.js +367 -0
  57. package/es/comps/FormGenerator/settings/ruleConfig.js +557 -0
  58. package/es/comps/FormGenerator/transformer.js +300 -0
  59. package/es/comps/Icons/index.js +23 -0
  60. package/es/comps/JsonEdit/constant/index.js +87 -0
  61. package/es/comps/JsonEdit/index.js +221 -0
  62. package/es/comps/JsonView/index.js +109 -0
  63. package/es/comps/MdEdit/index.js +41 -0
  64. package/es/comps/MdNavbar/index.js +180 -0
  65. package/es/comps/MdNavbar/utils.js +34 -0
  66. package/es/comps/MdView/index.js +70 -0
  67. package/es/comps/MetadataEdit/components/MetaFieldsEdit.js +419 -0
  68. package/es/comps/MetadataEdit/components/MetaPropsEdit.js +368 -0
  69. package/es/comps/MetadataEdit/constant/index.js +69 -0
  70. package/es/comps/MetadataEdit/hooks/index.js +43 -0
  71. package/es/comps/MetadataEdit/index.js +255 -0
  72. package/es/comps/MetadataEditV2/components/MetaFieldsEdit.js +237 -0
  73. package/es/comps/MetadataEditV2/components/MetaPropsEdit.js +367 -0
  74. package/es/comps/MetadataEditV2/constant/index.js +69 -0
  75. package/es/comps/MetadataEditV2/hooks/index.js +43 -0
  76. package/es/comps/MetadataEditV2/index.js +298 -0
  77. package/es/comps/MetadataForm/DataCell/Array.js +148 -0
  78. package/es/comps/MetadataForm/DataCell/Input.js +198 -0
  79. package/es/comps/MetadataForm/DataCell/Number.js +130 -0
  80. package/es/comps/MetadataForm/DataCell/Ref.js +326 -0
  81. package/es/comps/MetadataForm/DataCell/Select.js +557 -0
  82. package/es/comps/MetadataForm/DataCell/Switch.js +115 -0
  83. package/es/comps/MetadataForm/DataCell/layout/TableArray.js +359 -0
  84. package/es/comps/MetadataForm/HOC/index.js +125 -0
  85. package/es/comps/MetadataForm/constants.js +11 -0
  86. package/es/comps/MetadataForm/hooks/index.js +128 -0
  87. package/es/comps/MetadataForm/index.js +268 -0
  88. package/es/comps/MetadataForm/interface.js +8 -0
  89. package/es/comps/MetadataForm/utils.js +112 -0
  90. package/es/comps/locales/en-US.js +24 -0
  91. package/es/comps/locales/index.js +8 -0
  92. package/es/comps/locales/zh-CN.js +24 -0
  93. package/es/config.js +50 -0
  94. package/es/framework/graph/index.js +515 -0
  95. package/es/framework/hooks/use-async-memo.js +32 -0
  96. package/es/framework/hooks/use-sync-scroll.js +106 -0
  97. package/es/framework/http/cache.js +137 -0
  98. package/es/framework/http/cancel.js +44 -0
  99. package/es/framework/http/index.js +392 -0
  100. package/es/framework/http/msgpack.js +34 -0
  101. package/es/framework/http/msgpack5/index.js +84 -0
  102. package/es/framework/http/msgpack5/lib/codecs/DateCodec.js +71 -0
  103. package/es/framework/http/msgpack5/lib/decoder.js +287 -0
  104. package/es/framework/http/msgpack5/lib/encoder.js +252 -0
  105. package/es/framework/http/msgpack5/lib/helpers.js +23 -0
  106. package/es/framework/http/msgpack5/lib/streams.js +93 -0
  107. package/es/framework/http/types.js +1 -0
  108. package/es/framework/libs/jquery.min.js +4022 -0
  109. package/es/framework/locale/dil8/di18n.js +132 -0
  110. package/es/framework/locale/dil8/index.js +3 -0
  111. package/es/framework/locale/dil8/translate.js +76 -0
  112. package/es/framework/locale/dil8/util.js +17 -0
  113. package/es/framework/locale/index.js +26 -0
  114. package/es/framework/metadata/MetadataService.js +169 -0
  115. package/es/framework/metadata/index.js +384 -0
  116. package/es/framework/rxjs-hooks/useMemoSubject.js +16 -0
  117. package/es/framework/rxjs-hooks/useObservable.js +22 -0
  118. package/es/framework/rxjs-hooks/useObservableState.js +45 -0
  119. package/es/index.js +27 -0
  120. package/es/utils.js +138 -0
  121. package/package.json +1 -1
@@ -0,0 +1,359 @@
1
+ import "antd/es/form/style";
2
+ import _Form from "antd/es/form";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
7
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
8
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
9
+ import React, { useRef } from 'react';
10
+ import { MetadataService } from '../../../../framework/metadata/MetadataService';
11
+ import { JsonMetadataProvider } from '../../../../framework/metadata';
12
+ import Editable from '../../../../comps/Editable';
13
+ import useObservable from '../../../../framework/rxjs-hooks/useObservable';
14
+ import { MetadataFormContext } from '../../interface';
15
+ import { assign, getLabelByProps } from '../../utils';
16
+ import { deepClone } from '../../../../utils';
17
+ import { STREAM_EVENT_TYPE } from '../../constants';
18
+
19
+ var TableArray = function TableArray(props) {
20
+ var initValue = props.initValue,
21
+ readonly = props.readonly,
22
+ rowNumber = props.rowNumber,
23
+ initEnumValue = props.initEnumValue,
24
+ addButtonHidden = props.addButtonHidden,
25
+ name = props.name,
26
+ form = props.form,
27
+ refId = props.refId;
28
+ var formContext = React.useContext(MetadataFormContext) || {};
29
+
30
+ var _React$useState = React.useState([]),
31
+ _React$useState2 = _slicedToArray(_React$useState, 2),
32
+ schema = _React$useState2[0],
33
+ setSchema = _React$useState2[1];
34
+
35
+ var _React$useState3 = React.useState({}),
36
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
37
+ defaultValue = _React$useState4[0],
38
+ setDefaultValue = _React$useState4[1];
39
+
40
+ var _React$useState5 = React.useState({}),
41
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
42
+ refFields = _React$useState6[0],
43
+ setRefFields = _React$useState6[1];
44
+
45
+ var refFieldsRef = React.useRef(refFields);
46
+ var firstLoadRef = useRef(true);
47
+
48
+ var _React$useState7 = React.useState(),
49
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
50
+ tblStream = _React$useState8[0],
51
+ setTblStream = _React$useState8[1];
52
+
53
+ var _React$useState9 = React.useState([]),
54
+ _React$useState10 = _slicedToArray(_React$useState9, 2),
55
+ list = _React$useState10[0],
56
+ setList = _React$useState10[1];
57
+
58
+ var listRef = React.useRef([]);
59
+ useObservable(function (p) {
60
+ if ((p === null || p === void 0 ? void 0 : p.type) === 'setFieldsValue') {
61
+ if (typeof name === 'string' && p.payload[name]) {
62
+ setList(_toConsumableArray(p.payload[name]));
63
+ listRef.current = p.payload[name];
64
+ } else if (p.payload[name[0]]) {
65
+ var evalString = 'p.payload';
66
+
67
+ for (var i = 0; i < name.length; i++) {
68
+ evalString = "".concat(evalString, "[name[").concat(i, "]]");
69
+ }
70
+
71
+ var _list = eval(evalString) || [];
72
+
73
+ setList(_toConsumableArray(_list));
74
+ listRef.current = _list;
75
+ }
76
+ }
77
+ }, [formContext.stream$, name]);
78
+ useObservable(function (p) {
79
+ if ((p === null || p === void 0 ? void 0 : p.type) === 'onValuesChange') {
80
+ if (typeof name === 'string') {
81
+ var _p$payload;
82
+
83
+ var val = _defineProperty({}, "".concat(name), _objectSpread({
84
+ rowIdx: p === null || p === void 0 ? void 0 : (_p$payload = p.payload) === null || _p$payload === void 0 ? void 0 : _p$payload.rowIdx
85
+ }, p.payload.values));
86
+
87
+ var allVals = form.getFieldsValue();
88
+ allVals[name] = listRef.current;
89
+ formContext.stream$.next({
90
+ type: STREAM_EVENT_TYPE.ON_VALUES_CHANGE,
91
+ payload: {
92
+ val: val,
93
+ allVals: allVals
94
+ }
95
+ });
96
+ } else {
97
+ var _p$payload2;
98
+
99
+ var _val2 = {};
100
+
101
+ var _allVals = form.getFieldsValue();
102
+
103
+ assign(name, _objectSpread({
104
+ rowIdx: p === null || p === void 0 ? void 0 : (_p$payload2 = p.payload) === null || _p$payload2 === void 0 ? void 0 : _p$payload2.rowIdx
105
+ }, p.payload.values), _val2);
106
+ assign(name, _toConsumableArray(listRef.current), _allVals);
107
+ formContext.stream$.next({
108
+ type: STREAM_EVENT_TYPE.ON_VALUES_CHANGE,
109
+ payload: {
110
+ val: _val2,
111
+ allVals: _allVals
112
+ }
113
+ });
114
+ }
115
+ }
116
+ }, [tblStream]);
117
+ var getSchemaByRefId = React.useCallback( /*#__PURE__*/function () {
118
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(server, __TYPE__) {
119
+ var _schema, res, provider, FormCls, formCls, _fields;
120
+
121
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
122
+ while (1) {
123
+ switch (_context.prev = _context.next) {
124
+ case 0:
125
+ _schema = []; // 如果有内部类,优先在内部类里面找
126
+
127
+ if (__TYPE__.length > 0) {
128
+ _schema = __TYPE__.filter(function (it) {
129
+ return it.id === refId;
130
+ });
131
+ } // 内部类找不到 从接口里面拿
132
+
133
+
134
+ if (!(_schema.length === 0)) {
135
+ _context.next = 7;
136
+ break;
137
+ }
138
+
139
+ _context.next = 5;
140
+ return server.GetMetadataDetailById(refId);
141
+
142
+ case 5:
143
+ res = _context.sent;
144
+
145
+ if (res === null || res === void 0 ? void 0 : res.schema) {
146
+ _schema = JSON.parse(res === null || res === void 0 ? void 0 : res.schema);
147
+ }
148
+
149
+ case 7:
150
+ provider = new JsonMetadataProvider();
151
+
152
+ if (_schema.length > 0) {
153
+ provider.add_types(_schema);
154
+ FormCls = provider.get_type(_schema[0].id);
155
+ formCls = new FormCls();
156
+ _fields = formCls.__type__.__fields__;
157
+ refFieldsRef.current = _fields;
158
+ setRefFields(_objectSpread({}, _fields));
159
+ setSchema(_toConsumableArray(_schema));
160
+ setDefaultValue(_objectSpread({}, JSON.parse(JSON.stringify(formCls))));
161
+ }
162
+
163
+ case 9:
164
+ case "end":
165
+ return _context.stop();
166
+ }
167
+ }
168
+ }, _callee);
169
+ }));
170
+
171
+ return function (_x, _x2) {
172
+ return _ref.apply(this, arguments);
173
+ };
174
+ }(), [refId]);
175
+ React.useEffect(function () {
176
+ if (refId) {
177
+ var server = new MetadataService();
178
+ getSchemaByRefId(server, formContext.__TYPE__);
179
+ return function () {
180
+ server = null;
181
+ };
182
+ }
183
+
184
+ return function () {};
185
+ }, [refId]);
186
+ React.useEffect(function () {
187
+ if (initValue && firstLoadRef.current) {
188
+ if (typeof name === 'string' && initValue[name]) {
189
+ setList(_toConsumableArray(initValue[name]));
190
+ listRef.current = initValue[name];
191
+ } else if (initValue[name[0]]) {
192
+ var evalString = 'initValue';
193
+
194
+ for (var i = 0; i < name.length; i++) {
195
+ evalString = "".concat(evalString, "[name[").concat(i, "]]");
196
+ }
197
+
198
+ var _list = eval(evalString);
199
+
200
+ setList(_toConsumableArray(_list));
201
+ listRef.current = _list;
202
+ }
203
+
204
+ firstLoadRef.current = false;
205
+ }
206
+ }, [initValue, form]);
207
+ var processEnumData = React.useCallback(function (data, _extraInfo) {
208
+ var _extraInfo$enum;
209
+
210
+ var _options = [];
211
+
212
+ var _enum = deepClone(data.enum || []); // 扩展规则的value
213
+
214
+
215
+ if (_extraInfo === null || _extraInfo === void 0 ? void 0 : (_extraInfo$enum = _extraInfo.enum) === null || _extraInfo$enum === void 0 ? void 0 : _extraInfo$enum.value) {
216
+ var _extraInfo$enum2;
217
+
218
+ _enum = deepClone(_extraInfo === null || _extraInfo === void 0 ? void 0 : (_extraInfo$enum2 = _extraInfo.enum) === null || _extraInfo$enum2 === void 0 ? void 0 : _extraInfo$enum2.value);
219
+ } // 目前是更具那么的id判断的,暂未考虑重名问题
220
+
221
+
222
+ if (initEnumValue && initEnumValue[data.id]) {
223
+ _enum = deepClone(initEnumValue[data.id]);
224
+ }
225
+
226
+ _enum.forEach(function (it) {
227
+ var obj = {
228
+ label: it.value,
229
+ value: (it === null || it === void 0 ? void 0 : it.key) || (it === null || it === void 0 ? void 0 : it.value)
230
+ };
231
+
232
+ _options.push(obj);
233
+ });
234
+
235
+ return _options;
236
+ }, []);
237
+ var processColumnType = React.useCallback(function (data, _extraInfo) {
238
+ var _extraInfo$text, _extraInfo$text2;
239
+
240
+ if ((data === null || data === void 0 ? void 0 : data.type) === 'text' && (_extraInfo === null || _extraInfo === void 0 ? void 0 : (_extraInfo$text = _extraInfo.text) === null || _extraInfo$text === void 0 ? void 0 : _extraInfo$text.type) && (_extraInfo === null || _extraInfo === void 0 ? void 0 : (_extraInfo$text2 = _extraInfo.text) === null || _extraInfo$text2 === void 0 ? void 0 : _extraInfo$text2.type) !== 'textarea') {
241
+ var _extraInfo$text3;
242
+
243
+ return (_extraInfo$text3 = _extraInfo.text) === null || _extraInfo$text3 === void 0 ? void 0 : _extraInfo$text3.type;
244
+ }
245
+
246
+ return data.type;
247
+ }, []);
248
+ var processSchemaToColumns = React.useCallback(function (_properties) {
249
+ var _columns = [];
250
+
251
+ for (var i = 0; i < _properties.length; i++) {
252
+ var _extraInfo$common;
253
+
254
+ var it = _properties[i];
255
+ var extraInfo = refFieldsRef.current.get(it.id);
256
+ var obj = {
257
+ title: getLabelByProps(it),
258
+ key: it.id,
259
+ dataIndex: it.id,
260
+ width: processColumnType(it, extraInfo) === 'buttonCell' ? 25 : 50,
261
+ editable: !(extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$common = extraInfo.common) === null || _extraInfo$common === void 0 ? void 0 : _extraInfo$common.disabled),
262
+ type: processColumnType(it, extraInfo),
263
+ enum: it.type === 'enum' ? processEnumData(it, extraInfo) : undefined
264
+ };
265
+
266
+ _columns.push(obj);
267
+ }
268
+
269
+ return _columns;
270
+ }, []);
271
+ var columns = React.useMemo(function () {
272
+ var _columns = [];
273
+
274
+ if (schema.length > 0) {
275
+ _columns = processSchemaToColumns(schema[0].properties);
276
+ }
277
+
278
+ return _columns;
279
+ }, [schema, processSchemaToColumns]);
280
+
281
+ var onTableChange = function onTableChange(values) {
282
+ if (typeof name === 'string') {
283
+ var allVals = form.getFieldsValue();
284
+ allVals[name] = values;
285
+ formContext.stream$.next({
286
+ type: STREAM_EVENT_TYPE.ON_VALUES_CHANGE,
287
+ payload: {
288
+ val: _defineProperty({}, name, values),
289
+ allVals: allVals
290
+ }
291
+ });
292
+ form.setFieldsValue(_objectSpread({}, _defineProperty({}, "".concat(name), values)));
293
+ } else {
294
+ var val = {};
295
+ assign(name, _toConsumableArray(values), val);
296
+
297
+ var _allVals2 = form.getFieldsValue();
298
+
299
+ assign(name, _toConsumableArray(values), _allVals2);
300
+ formContext.stream$.next({
301
+ type: STREAM_EVENT_TYPE.ON_VALUES_CHANGE,
302
+ payload: {
303
+ val: val,
304
+ allVals: _allVals2
305
+ }
306
+ });
307
+ form.setFieldsValue(_objectSpread({}, val));
308
+ }
309
+
310
+ listRef.current = values;
311
+ };
312
+
313
+ var onButtonCellClick = function onButtonCellClick(record) {
314
+ formContext.stream$.next({
315
+ type: 'onButtonCellClick',
316
+ payload: record
317
+ });
318
+ };
319
+
320
+ var getCellHeight = React.useCallback(function (_readonly) {
321
+ return _readonly ? 30 : 33;
322
+ }, []);
323
+ return /*#__PURE__*/React.createElement("div", {
324
+ style: {
325
+ width: '100%',
326
+ padding: '0 0 8px',
327
+ height: addButtonHidden || readonly ? "".concat(rowNumber * getCellHeight(readonly) + 45, "px") : "".concat(rowNumber * getCellHeight(readonly) + 45 + 40, "px")
328
+ }
329
+ }, /*#__PURE__*/React.createElement(_Form.Item, {
330
+ name: name,
331
+ noStyle: true,
332
+ style: {
333
+ margin: 0,
334
+ height: '100%'
335
+ }
336
+ }, /*#__PURE__*/React.createElement(Editable, {
337
+ type: "multiple",
338
+ readonly: readonly,
339
+ defaultValue: defaultValue,
340
+ addPosition: "bottom",
341
+ isAddRow: !addButtonHidden,
342
+ isAction: !addButtonHidden,
343
+ columns: columns,
344
+ dataSource: list,
345
+ onMulChange: onTableChange,
346
+ onButtonCellClick: onButtonCellClick,
347
+ getStreamInstance: function getStreamInstance(_tblStream) {
348
+ setTblStream(_tblStream);
349
+ },
350
+ tableProps: {
351
+ scroll: {
352
+ x: '100%',
353
+ y: addButtonHidden || readonly ? "".concat(rowNumber * getCellHeight(readonly) + 45, "px ") : "".concat(rowNumber * getCellHeight(readonly), "px ")
354
+ }
355
+ }
356
+ })));
357
+ };
358
+
359
+ export default TableArray;
@@ -0,0 +1,125 @@
1
+ import "antd/es/col/style";
2
+ import _Col from "antd/es/col";
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ import React from 'react';
6
+ import { deepClone } from '../../../utils';
7
+ import { useWatchDepend } from '../hooks';
8
+ import { MetadataFormContext } from '../interface';
9
+ import './index.less';
10
+ export function withAddOnAfter(WrappedComponent) {
11
+ return function (props) {
12
+ var _fields$, _fields$$value, _fields$$value$common, _fields$4, _fields$4$value, _fields$4$value$commo, _fields$4$value$commo2;
13
+
14
+ var type = props.type,
15
+ refId = props.refId,
16
+ isShowTypeInfo = props.isShowTypeInfo,
17
+ fields = props.fields,
18
+ colSpan = props.colSpan,
19
+ field = props.field,
20
+ id = props.id,
21
+ _props$name = props.name,
22
+ name = _props$name === void 0 ? [] : _props$name,
23
+ isObj = props.isObj;
24
+ var formContext = React.useContext(MetadataFormContext) || {};
25
+ var depend = useWatchDepend(fields && ((_fields$ = fields[0]) === null || _fields$ === void 0 ? void 0 : (_fields$$value = _fields$.value) === null || _fields$$value === void 0 ? void 0 : (_fields$$value$common = _fields$$value.common) === null || _fields$$value$common === void 0 ? void 0 : _fields$$value$common.depend), formContext === null || formContext === void 0 ? void 0 : formContext.stream$);
26
+
27
+ var _React$useState = React.useState(),
28
+ _React$useState2 = _slicedToArray(_React$useState, 2),
29
+ help = _React$useState2[0],
30
+ setHelp = _React$useState2[1];
31
+
32
+ var _React$useState3 = React.useState(),
33
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
34
+ cellColSpan = _React$useState4[0],
35
+ setCellColSpan = _React$useState4[1];
36
+
37
+ if (id === 'p' || id === 'user') {}
38
+
39
+ var labelSpan = React.useMemo(function () {
40
+ var _fields$0$value, _fields$0$value$commo;
41
+
42
+ var _labelSpan = formContext === null || formContext === void 0 ? void 0 : formContext.labelSpan;
43
+
44
+ var _colSpan = fields && ((_fields$0$value = fields[0].value) === null || _fields$0$value === void 0 ? void 0 : (_fields$0$value$commo = _fields$0$value.common) === null || _fields$0$value$commo === void 0 ? void 0 : _fields$0$value$commo.colSpan);
45
+
46
+ var _formLabelSpan = formContext === null || formContext === void 0 ? void 0 : formContext.labelSpan;
47
+
48
+ if (_colSpan && _formLabelSpan) {
49
+ _labelSpan = _formLabelSpan / _colSpan;
50
+ }
51
+
52
+ return _labelSpan;
53
+ }, [fields, formContext === null || formContext === void 0 ? void 0 : formContext.colSpan, formContext === null || formContext === void 0 ? void 0 : formContext.labelSpan]);
54
+ React.useEffect(function () {
55
+ if (refId) {
56
+ var arr = refId.split(':');
57
+ setHelp(arr[arr.length - 1]);
58
+ }
59
+
60
+ return function () {};
61
+ }, [refId]);
62
+ React.useEffect(function () {
63
+ var _fields$2, _fields$2$value, _fields$2$value$commo, _fields$3, _fields$3$value;
64
+
65
+ var _colSpan = colSpan;
66
+ var compColSpan = fields && (((_fields$2 = fields[0]) === null || _fields$2 === void 0 ? void 0 : (_fields$2$value = _fields$2.value) === null || _fields$2$value === void 0 ? void 0 : (_fields$2$value$commo = _fields$2$value.common) === null || _fields$2$value$commo === void 0 ? void 0 : _fields$2$value$commo.colSpan) || ((_fields$3 = fields[0]) === null || _fields$3 === void 0 ? void 0 : (_fields$3$value = _fields$3.value) === null || _fields$3$value === void 0 ? void 0 : _fields$3$value.colSpan));
67
+
68
+ if (compColSpan) {
69
+ _colSpan = compColSpan * colSpan <= 24 ? compColSpan * colSpan : 24;
70
+ }
71
+
72
+ setCellColSpan(_colSpan);
73
+ }, [fields, colSpan]);
74
+
75
+ var _name = React.useMemo(function () {
76
+ if (id && name.length > 0 && !field) {
77
+ var res = deepClone(name);
78
+ res.push(id);
79
+ return res;
80
+ }
81
+
82
+ if (id && name.length > 0 && field) {
83
+ var _res = deepClone(name);
84
+
85
+ _res.push(id);
86
+
87
+ if (type !== 'ref') {
88
+ _res.shift();
89
+ }
90
+
91
+ return _res;
92
+ }
93
+
94
+ return [id];
95
+ }, [id, name]);
96
+
97
+ if (depend === null || depend === void 0 ? void 0 : depend.hidden) {
98
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
99
+ }
100
+
101
+ if (fields && ((_fields$4 = fields[0]) === null || _fields$4 === void 0 ? void 0 : (_fields$4$value = _fields$4.value) === null || _fields$4$value === void 0 ? void 0 : (_fields$4$value$commo = _fields$4$value.common) === null || _fields$4$value$commo === void 0 ? void 0 : (_fields$4$value$commo2 = _fields$4$value$commo.depend) === null || _fields$4$value$commo2 === void 0 ? void 0 : _fields$4$value$commo2.show) && !(depend === null || depend === void 0 ? void 0 : depend.show)) {
102
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
103
+ }
104
+
105
+ return /*#__PURE__*/React.createElement(_Col, {
106
+ key: id,
107
+ span: cellColSpan
108
+ }, /*#__PURE__*/React.createElement("div", {
109
+ key: "".concat(_name.toString(), "_div"),
110
+ className: "with-add-on-after"
111
+ }, /*#__PURE__*/React.createElement(WrappedComponent, _extends({
112
+ key: "".concat(_name.toString(), "_Wrapped}")
113
+ }, props, {
114
+ style: {
115
+ padding: '0px',
116
+ display: 'flex !important'
117
+ },
118
+ name: _name,
119
+ labelSpan: labelSpan,
120
+ isObj: isObj
121
+ })), isShowTypeInfo && !field && type !== 'number' && type !== 'bool' && /*#__PURE__*/React.createElement("div", {
122
+ className: "with-add-on-after-extra"
123
+ }, help !== null && help !== void 0 ? help : type)));
124
+ };
125
+ }
@@ -0,0 +1,11 @@
1
+ /*
2
+ * @Author: wangxian
3
+ * @Date: 2023-02-03 09:08:06
4
+ * @LastEditTime: 2023-02-03 09:10:19
5
+ */
6
+ export var STREAM_EVENT_TYPE = {
7
+ ON_SELECT_CHANGE: 'onSelectChange',
8
+ ON_BUTTON_CELL_CLICK: 'onButtonCellClick',
9
+ ON_VALUES_CHANGE: 'onValuesChange',
10
+ ON_WATCH_DEPEND: 'onWatchDepend'
11
+ };
@@ -0,0 +1,128 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+
5
+ /*
6
+ * @Author: your name
7
+ * @Date: 2021-09-18 14:15:04
8
+ * @LastEditTime: 2023-02-23 14:53:08
9
+ */
10
+ import { getLocale } from '../../../framework/locale';
11
+ import moment from 'moment';
12
+ import React from 'react';
13
+ import { STREAM_EVENT_TYPE } from '../constants'; // 主题样式名映射
14
+
15
+ var languageMap = {
16
+ 'zh-CN': 'common',
17
+ 'en-US': 'common-en-US'
18
+ };
19
+ export var useGetExtraInfo = function useGetExtraInfo(fields, id, form, type) {
20
+ var _React$useState = React.useState({}),
21
+ _React$useState2 = _slicedToArray(_React$useState, 2),
22
+ extra = _React$useState2[0],
23
+ setExtra = _React$useState2[1];
24
+
25
+ React.useEffect(function () {
26
+ if (fields) {
27
+ var extraInfo = fields.get(id);
28
+
29
+ if (extraInfo) {
30
+ // 将map转化为对象
31
+ var _extraInfo = {};
32
+
33
+ for (var k in extraInfo) {
34
+ _extraInfo[k] = extraInfo[k];
35
+ }
36
+
37
+ // 兼容 common公共的属性
38
+ if (_extraInfo['common-en-US']) {
39
+ _extraInfo = _objectSpread(_objectSpread(_objectSpread({}, _extraInfo), _extraInfo[languageMap[getLocale()]]), _extraInfo[type]);
40
+ } else {
41
+ _extraInfo = _objectSpread(_objectSpread(_objectSpread({}, _extraInfo), _extraInfo.common), _extraInfo[type]);
42
+ }
43
+
44
+ delete _extraInfo.common;
45
+ delete _extraInfo['common-en-US'];
46
+ delete _extraInfo[type];
47
+
48
+ // 时间格式转化
49
+ if (_extraInfo.type === 'datePicker' && form.getFieldValue(id)) {
50
+ form.setFieldsValue(_defineProperty({}, id, moment(form.getFieldValue(id), 'YYYY-MM-DD HH:mm:ss')));
51
+ }
52
+
53
+ setExtra(_objectSpread({}, _extraInfo));
54
+ }
55
+ }
56
+ }, [fields, form, id]);
57
+ return extra;
58
+ }; // 处理depend联动
59
+
60
+ export var useWatchDepend = function useWatchDepend(_depends, stream$) {
61
+ var _React$useState3 = React.useState({}),
62
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
63
+ depends = _React$useState4[0],
64
+ setDepends = _React$useState4[1];
65
+
66
+ var dependsRef = React.useRef({});
67
+ React.useEffect(function () {
68
+ if (_depends && stream$) {
69
+ stream$.subscribe(function (p) {
70
+ if ((p === null || p === void 0 ? void 0 : p.type) === STREAM_EVENT_TYPE.ON_VALUES_CHANGE) {
71
+ if (_depends === null || _depends === void 0 ? void 0 : _depends.hidden) {
72
+ var _p$payload;
73
+
74
+ var _hidden = processDependHiddenOrShow(_depends === null || _depends === void 0 ? void 0 : _depends.hidden, p === null || p === void 0 ? void 0 : (_p$payload = p.payload) === null || _p$payload === void 0 ? void 0 : _p$payload.allVals, stream$);
75
+
76
+ var _dr = dependsRef.current;
77
+ _dr.hidden = _hidden;
78
+ setDepends(_objectSpread({}, _dr));
79
+ dependsRef.current = _dr;
80
+ }
81
+
82
+ if (_depends === null || _depends === void 0 ? void 0 : _depends.show) {
83
+ var _p$payload2;
84
+
85
+ var _show = processDependHiddenOrShow(_depends === null || _depends === void 0 ? void 0 : _depends.show, p === null || p === void 0 ? void 0 : (_p$payload2 = p.payload) === null || _p$payload2 === void 0 ? void 0 : _p$payload2.allVals, stream$);
86
+
87
+ var _dr2 = dependsRef.current;
88
+ _dr2.show = _show;
89
+ setDepends(_objectSpread({}, _dr2));
90
+ dependsRef.current = _dr2;
91
+ }
92
+ }
93
+ });
94
+ }
95
+ }, [_depends, stream$]);
96
+ return depends;
97
+ };
98
+
99
+ var processDependHiddenOrShow = function processDependHiddenOrShow(depend, changeData, stream$) {
100
+ try {
101
+ // const regex = /\w+(\.\w+)?[=<>!]{1}/g;
102
+ var regex = /\w+(\.\w+)?[=<>!]{1}|\w+(\.\w+)?(\.indexOf\('\w+'\)[=<>!]{1})/g;
103
+ var keys = depend.trim().match(regex);
104
+
105
+ if (!keys) {
106
+ return false;
107
+ }
108
+
109
+ var expression = depend;
110
+
111
+ for (var i = 0; i < keys.length; i++) {
112
+ var key = keys[i].substring(0, keys[i].length - 1); // 处理.length 之类的状况
113
+
114
+ var _key = key.split('.');
115
+
116
+ if (changeData[_key[0]] || changeData[_key[0]] === 0) {
117
+ var r = key === _key[0] ? "'".concat(changeData[_key[0]], "'") : eval("changeData[_key[0]].".concat(_key[1]));
118
+ expression = expression.replace(key, r);
119
+ } else {
120
+ expression = expression.replace(key, undefined);
121
+ }
122
+ }
123
+
124
+ return eval(expression);
125
+ } catch (error) {
126
+ console.error("useWatchDepend.expression is error", error);
127
+ }
128
+ };