ronds-metadata 1.2.10 → 1.2.12
Sign up to get free protection for your applications and to get access to all the features.
- package/es/api/index.js +249 -0
- package/es/comps/DynamicPorts/comps/ContextMenu.js +44 -0
- package/es/comps/DynamicPorts/comps/DragNode.js +55 -0
- package/es/comps/DynamicPorts/comps/GraphHandler/index.js +51 -0
- package/es/comps/DynamicPorts/comps/NodeElement.js +30 -0
- package/es/comps/DynamicPorts/comps/contextMenu/EdgeContextMenu/index.js +42 -0
- package/es/comps/DynamicPorts/comps/contextMenu/GraphContextMenu/index.js +40 -0
- package/es/comps/DynamicPorts/comps/contextMenu/NodeContextMenu/index.js +55 -0
- package/es/comps/DynamicPorts/comps/shape/connector.js +19 -0
- package/es/comps/DynamicPorts/comps/shape/edge.js +91 -0
- package/es/comps/DynamicPorts/comps/shape/node.js +190 -0
- package/es/comps/DynamicPorts/constant/index.js +19 -0
- package/es/comps/DynamicPorts/graph.js +697 -0
- package/es/comps/DynamicPorts/index.js +143 -0
- package/es/comps/DynamicPorts/interface.js +6 -0
- package/es/comps/DynamicPorts/utils.js +127 -0
- package/es/comps/Editable/DataCell/ButtonCell.js +45 -0
- package/es/comps/Editable/DataCell/ColorPicker.js +33 -0
- package/es/comps/Editable/DataCell/Input.js +54 -0
- package/es/comps/Editable/DataCell/Number.js +44 -0
- package/es/comps/Editable/DataCell/Select.js +48 -0
- package/es/comps/Editable/DataCell/Switch.js +33 -0
- package/es/comps/Editable/comps/EditableAction.js +110 -0
- package/es/comps/Editable/comps/EditableCell.js +108 -0
- package/es/comps/Editable/comps/EditableHeardCell.js +172 -0
- package/es/comps/Editable/comps/EditableRow.js +118 -0
- package/es/comps/Editable/comps/Texty.js +277 -0
- package/es/comps/Editable/index.js +386 -0
- package/es/comps/Editable/interface.js +8 -0
- package/es/comps/Editable/utils.js +46 -0
- package/es/comps/FileView/index.js +198 -0
- package/es/comps/FormGenerator/Provider.js +8 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Checkbox.js +69 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Color.js +17 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Date.js +16 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Input.js +17 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/List.js +50 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/MutiSelect.js +55 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Number.js +14 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Obj.js +50 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Password.js +17 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Radio.js +69 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Select.js +55 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Switch.js +13 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Table.js +50 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/TextArea.js +14 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Upload.js +27 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/HOC/index.js +261 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/index.js +62 -0
- package/es/comps/FormGenerator/comps/Canvas/core/index.js +315 -0
- package/es/comps/FormGenerator/comps/Canvas/index.js +120 -0
- package/es/comps/FormGenerator/comps/Settings/index.js +150 -0
- package/es/comps/FormGenerator/comps/Sidebar/Elements.js +48 -0
- package/es/comps/FormGenerator/comps/Sidebar/index.js +37 -0
- package/es/comps/FormGenerator/index.js +68 -0
- package/es/comps/FormGenerator/settings/index.js +367 -0
- package/es/comps/FormGenerator/settings/ruleConfig.js +557 -0
- package/es/comps/FormGenerator/transformer.js +300 -0
- package/es/comps/Icons/index.js +23 -0
- package/es/comps/JsonEdit/constant/index.js +87 -0
- package/es/comps/JsonEdit/index.js +221 -0
- package/es/comps/JsonView/index.js +109 -0
- package/es/comps/MdEdit/index.js +41 -0
- package/es/comps/MdNavbar/index.js +180 -0
- package/es/comps/MdNavbar/utils.js +34 -0
- package/es/comps/MdView/index.js +70 -0
- package/es/comps/MetadataEdit/components/MetaFieldsEdit.js +419 -0
- package/es/comps/MetadataEdit/components/MetaPropsEdit.js +368 -0
- package/es/comps/MetadataEdit/constant/index.js +69 -0
- package/es/comps/MetadataEdit/hooks/index.js +43 -0
- package/es/comps/MetadataEdit/index.js +255 -0
- package/es/comps/MetadataEditV2/components/MetaFieldsEdit.js +237 -0
- package/es/comps/MetadataEditV2/components/MetaPropsEdit.js +367 -0
- package/es/comps/MetadataEditV2/constant/index.js +69 -0
- package/es/comps/MetadataEditV2/hooks/index.js +43 -0
- package/es/comps/MetadataEditV2/index.js +298 -0
- package/es/comps/MetadataForm/DataCell/Array.js +148 -0
- package/es/comps/MetadataForm/DataCell/Input.js +199 -0
- package/es/comps/MetadataForm/DataCell/Number.js +131 -0
- package/es/comps/MetadataForm/DataCell/Ref.js +326 -0
- package/es/comps/MetadataForm/DataCell/Select.js +558 -0
- package/es/comps/MetadataForm/DataCell/Switch.js +116 -0
- package/es/comps/MetadataForm/DataCell/layout/TableArray.js +359 -0
- package/es/comps/MetadataForm/HOC/index.js +126 -0
- package/es/comps/MetadataForm/constants.js +11 -0
- package/es/comps/MetadataForm/hooks/index.js +139 -0
- package/es/comps/MetadataForm/index.js +268 -0
- package/es/comps/MetadataForm/interface.d.ts +2 -1
- package/es/comps/MetadataForm/interface.js +8 -0
- package/es/comps/MetadataForm/utils.js +112 -0
- package/es/comps/locales/en-US.js +24 -0
- package/es/comps/locales/index.js +8 -0
- package/es/comps/locales/zh-CN.js +24 -0
- package/es/config.js +50 -0
- package/es/framework/graph/index.js +515 -0
- package/es/framework/hooks/use-async-memo.js +32 -0
- package/es/framework/hooks/use-sync-scroll.js +106 -0
- package/es/framework/http/cache.js +137 -0
- package/es/framework/http/cancel.js +44 -0
- package/es/framework/http/index.js +392 -0
- package/es/framework/http/msgpack.js +34 -0
- package/es/framework/http/msgpack5/index.js +84 -0
- package/es/framework/http/msgpack5/lib/codecs/DateCodec.js +71 -0
- package/es/framework/http/msgpack5/lib/decoder.js +287 -0
- package/es/framework/http/msgpack5/lib/encoder.js +252 -0
- package/es/framework/http/msgpack5/lib/helpers.js +23 -0
- package/es/framework/http/msgpack5/lib/streams.js +93 -0
- package/es/framework/http/types.js +1 -0
- package/es/framework/libs/jquery.min.js +4022 -0
- package/es/framework/locale/dil8/di18n.js +132 -0
- package/es/framework/locale/dil8/index.js +3 -0
- package/es/framework/locale/dil8/translate.js +76 -0
- package/es/framework/locale/dil8/util.js +17 -0
- package/es/framework/locale/index.js +26 -0
- package/es/framework/metadata/MetadataService.js +169 -0
- package/es/framework/metadata/index.js +384 -0
- package/es/framework/rxjs-hooks/useMemoSubject.js +16 -0
- package/es/framework/rxjs-hooks/useObservable.js +22 -0
- package/es/framework/rxjs-hooks/useObservableState.js +45 -0
- package/es/index.js +27 -0
- package/es/utils.js +138 -0
- package/package.json +1 -1
@@ -0,0 +1,261 @@
|
|
1
|
+
import "antd/es/button/style";
|
2
|
+
import _Button from "antd/es/button";
|
3
|
+
import "antd/es/form/style";
|
4
|
+
import _Form from "antd/es/form";
|
5
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
6
|
+
import _objectDestructuringEmpty from "@babel/runtime/helpers/esm/objectDestructuringEmpty";
|
7
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
8
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
9
|
+
import React from 'react';
|
10
|
+
import { useDrag, useDrop } from 'react-dnd';
|
11
|
+
import { DragOutlined, SnippetsOutlined, DeleteOutlined } from '@ant-design/icons';
|
12
|
+
import { FGCtx } from '../../../../../Provider';
|
13
|
+
import { dragItemType, streamEventType } from '../../../../../settings';
|
14
|
+
import useObservable from '../../../../../../../framework/rxjs-hooks/useObservable';
|
15
|
+
export function withFieldCellWrapper(WrappedComponent) {
|
16
|
+
return function (props) {
|
17
|
+
var _cellSetting$depend, _cellSetting$depend2, _cellSetting$depend3, _cellSetting$depend4;
|
18
|
+
|
19
|
+
var data = props.data,
|
20
|
+
refId = props.refId,
|
21
|
+
isShowAction = props.isShowAction;
|
22
|
+
var fGCtx = React.useContext(FGCtx) || {};
|
23
|
+
var boxRef = React.useRef(null);
|
24
|
+
|
25
|
+
var _React$useState = React.useState(),
|
26
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
27
|
+
cellSetting = _React$useState2[0],
|
28
|
+
setCellSetting = _React$useState2[1];
|
29
|
+
|
30
|
+
var _React$useState3 = React.useState(),
|
31
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
32
|
+
types = _React$useState4[0],
|
33
|
+
setTypes = _React$useState4[1];
|
34
|
+
|
35
|
+
var _React$useState5 = React.useState(),
|
36
|
+
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
37
|
+
position = _React$useState6[0],
|
38
|
+
setPosition = _React$useState6[1];
|
39
|
+
|
40
|
+
React.useEffect(function () {
|
41
|
+
if ((fGCtx === null || fGCtx === void 0 ? void 0 : fGCtx.types) && (fGCtx === null || fGCtx === void 0 ? void 0 : fGCtx.types[data.id])) {
|
42
|
+
//
|
43
|
+
setTypes(_objectSpread({}, fGCtx === null || fGCtx === void 0 ? void 0 : fGCtx.types[data.id]));
|
44
|
+
}
|
45
|
+
}, [fGCtx === null || fGCtx === void 0 ? void 0 : fGCtx.types]);
|
46
|
+
var processFgStreamData = React.useCallback(function (p) {
|
47
|
+
switch (p === null || p === void 0 ? void 0 : p.type) {
|
48
|
+
case streamEventType.onSettingValueChange:
|
49
|
+
if ((p === null || p === void 0 ? void 0 : p.payload.refId) === refId) {
|
50
|
+
if (p === null || p === void 0 ? void 0 : p.payload[data.id]) {
|
51
|
+
setCellSetting(_objectSpread({}, p === null || p === void 0 ? void 0 : p.payload[data.id]));
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
break;
|
56
|
+
}
|
57
|
+
}, []);
|
58
|
+
useObservable(function (p) {
|
59
|
+
processFgStreamData(p);
|
60
|
+
}, [fGCtx.fgStream]);
|
61
|
+
|
62
|
+
var _useDrag = useDrag({
|
63
|
+
item: {
|
64
|
+
dragItem: data,
|
65
|
+
type: dragItemType
|
66
|
+
},
|
67
|
+
end: function end(item, monitor) {
|
68
|
+
var dropResult = monitor.getDropResult();
|
69
|
+
|
70
|
+
if (item && dropResult) {}
|
71
|
+
},
|
72
|
+
collect: function collect(monitor) {
|
73
|
+
return {
|
74
|
+
isDragging: monitor.isDragging()
|
75
|
+
};
|
76
|
+
}
|
77
|
+
}),
|
78
|
+
_useDrag2 = _slicedToArray(_useDrag, 3);
|
79
|
+
|
80
|
+
_objectDestructuringEmpty(_useDrag2[0]);
|
81
|
+
|
82
|
+
var drag = _useDrag2[1],
|
83
|
+
dragPreview = _useDrag2[2]; // 处理组件拖拽落下事件
|
84
|
+
|
85
|
+
var _useDrop = useDrop({
|
86
|
+
accept: [dragItemType],
|
87
|
+
drop: function drop(item, monitor) {
|
88
|
+
// 如果 children 已经作为了 drop target,不处理
|
89
|
+
var didDrop = monitor.didDrop();
|
90
|
+
|
91
|
+
if (didDrop) {
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
|
95
|
+
(fGCtx === null || fGCtx === void 0 ? void 0 : fGCtx.fgStream) && fGCtx.fgStream.next({
|
96
|
+
type: streamEventType.onDropOver,
|
97
|
+
payload: {
|
98
|
+
dragItem: item.dragItem,
|
99
|
+
dropId: data.id,
|
100
|
+
position: position,
|
101
|
+
refId: refId
|
102
|
+
}
|
103
|
+
});
|
104
|
+
},
|
105
|
+
hover: function hover(item, monitor) {
|
106
|
+
// 只检查被hover的最小元素
|
107
|
+
var didHover = monitor.isOver({
|
108
|
+
shallow: true
|
109
|
+
});
|
110
|
+
|
111
|
+
if (didHover) {
|
112
|
+
if (item.dragItem.id === data.id) return; // Determine rectangle on screen
|
113
|
+
|
114
|
+
// Determine rectangle on screen
|
115
|
+
var hoverBoundingRect = boxRef.current && boxRef.current.getBoundingClientRect(); // Get vertical middle
|
116
|
+
|
117
|
+
// Get vertical middle
|
118
|
+
var hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2; // Determine mouse position
|
119
|
+
// const clientOffset = monitor.getClientOffset();
|
120
|
+
|
121
|
+
// Determine mouse position
|
122
|
+
// const clientOffset = monitor.getClientOffset();
|
123
|
+
var dragOffset = monitor.getSourceClientOffset(); // Get pixels to the top
|
124
|
+
|
125
|
+
// Get pixels to the top
|
126
|
+
var hoverClientY = dragOffset.y - hoverBoundingRect.top;
|
127
|
+
|
128
|
+
if (hoverClientY <= hoverMiddleY) {
|
129
|
+
setPosition('borderTop');
|
130
|
+
} // Dragging upwards
|
131
|
+
|
132
|
+
|
133
|
+
// Dragging upwards
|
134
|
+
if (hoverClientY > hoverMiddleY) {
|
135
|
+
setPosition('borderBottom');
|
136
|
+
}
|
137
|
+
}
|
138
|
+
},
|
139
|
+
collect: function collect(monitor) {
|
140
|
+
return {
|
141
|
+
isOver: monitor.isOver({
|
142
|
+
shallow: true
|
143
|
+
}),
|
144
|
+
canDrop: monitor.canDrop()
|
145
|
+
};
|
146
|
+
}
|
147
|
+
}),
|
148
|
+
_useDrop2 = _slicedToArray(_useDrop, 2),
|
149
|
+
_useDrop2$ = _useDrop2[0],
|
150
|
+
canDrop = _useDrop2$.canDrop,
|
151
|
+
isOver = _useDrop2$.isOver,
|
152
|
+
dropRef = _useDrop2[1];
|
153
|
+
|
154
|
+
var onNodeDelete = function onNodeDelete(e) {
|
155
|
+
e.stopPropagation();
|
156
|
+
fGCtx.fgStream && fGCtx.fgStream.next({
|
157
|
+
type: streamEventType.onNodeDelete,
|
158
|
+
payload: {
|
159
|
+
id: data.id,
|
160
|
+
refId: refId
|
161
|
+
}
|
162
|
+
});
|
163
|
+
};
|
164
|
+
|
165
|
+
var onNodeCopy = function onNodeCopy(e) {
|
166
|
+
e.stopPropagation();
|
167
|
+
fGCtx.fgStream && fGCtx.fgStream.next({
|
168
|
+
type: streamEventType.onNodeCopy,
|
169
|
+
payload: data
|
170
|
+
});
|
171
|
+
};
|
172
|
+
|
173
|
+
var isActive = canDrop && isOver;
|
174
|
+
dragPreview(dropRef(boxRef));
|
175
|
+
|
176
|
+
var getBorder = function getBorder(_position) {
|
177
|
+
var _style = {
|
178
|
+
width: '100%',
|
179
|
+
height: '100%',
|
180
|
+
padding: '4px 10px'
|
181
|
+
};
|
182
|
+
|
183
|
+
if (_position && isActive) {
|
184
|
+
_style[_position] = '2px solid red';
|
185
|
+
}
|
186
|
+
|
187
|
+
return _style;
|
188
|
+
};
|
189
|
+
|
190
|
+
return /*#__PURE__*/React.createElement("div", {
|
191
|
+
ref: boxRef,
|
192
|
+
style: _objectSpread({}, getBorder(position))
|
193
|
+
}, /*#__PURE__*/React.createElement("div", {
|
194
|
+
style: {
|
195
|
+
fontSize: '12px',
|
196
|
+
textAlign: 'right'
|
197
|
+
}
|
198
|
+
}, /*#__PURE__*/React.createElement("span", {
|
199
|
+
style: {
|
200
|
+
color: 'var(--ronds-metadata-color-border-2)'
|
201
|
+
}
|
202
|
+
}, (cellSetting === null || cellSetting === void 0 ? void 0 : cellSetting.id) || data.id), (cellSetting === null || cellSetting === void 0 ? void 0 : cellSetting.hidden) && /*#__PURE__*/React.createElement("span", {
|
203
|
+
style: {
|
204
|
+
color: 'var(--ronds-metadata-color-text-2)'
|
205
|
+
}
|
206
|
+
}, " [ hidden ] "), (cellSetting === null || cellSetting === void 0 ? void 0 : (_cellSetting$depend = cellSetting.depend) === null || _cellSetting$depend === void 0 ? void 0 : _cellSetting$depend.hidden) && /*#__PURE__*/React.createElement("span", {
|
207
|
+
style: {
|
208
|
+
color: 'var(--ronds-metadata-color-text-2)'
|
209
|
+
}
|
210
|
+
}, " [ hidden:", cellSetting === null || cellSetting === void 0 ? void 0 : (_cellSetting$depend2 = cellSetting.depend) === null || _cellSetting$depend2 === void 0 ? void 0 : _cellSetting$depend2.hidden, " ] "), (cellSetting === null || cellSetting === void 0 ? void 0 : (_cellSetting$depend3 = cellSetting.depend) === null || _cellSetting$depend3 === void 0 ? void 0 : _cellSetting$depend3.show) && /*#__PURE__*/React.createElement("span", {
|
211
|
+
style: {
|
212
|
+
color: 'var(--ronds-metadata-color-text-2)'
|
213
|
+
}
|
214
|
+
}, " [ show:", cellSetting === null || cellSetting === void 0 ? void 0 : (_cellSetting$depend4 = cellSetting.depend) === null || _cellSetting$depend4 === void 0 ? void 0 : _cellSetting$depend4.show, " ] ")), /*#__PURE__*/React.createElement(_Form.Item, {
|
215
|
+
key: "".concat(cellSetting === null || cellSetting === void 0 ? void 0 : cellSetting.defaultValue),
|
216
|
+
name: (cellSetting === null || cellSetting === void 0 ? void 0 : cellSetting.id) || data.id,
|
217
|
+
label: /*#__PURE__*/React.createElement("span", {
|
218
|
+
style: (cellSetting === null || cellSetting === void 0 ? void 0 : cellSetting.color) ? {
|
219
|
+
color: cellSetting === null || cellSetting === void 0 ? void 0 : cellSetting.color
|
220
|
+
} : {}
|
221
|
+
}, (cellSetting === null || cellSetting === void 0 ? void 0 : cellSetting.label) || data.name),
|
222
|
+
initialValue: cellSetting === null || cellSetting === void 0 ? void 0 : cellSetting.defaultValue,
|
223
|
+
help: cellSetting === null || cellSetting === void 0 ? void 0 : cellSetting.help,
|
224
|
+
tooltip: cellSetting === null || cellSetting === void 0 ? void 0 : cellSetting.tooltip,
|
225
|
+
rules: [{
|
226
|
+
required: cellSetting === null || cellSetting === void 0 ? void 0 : cellSetting.require
|
227
|
+
}]
|
228
|
+
}, /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, props, {
|
229
|
+
fgStream: fGCtx.fgStream,
|
230
|
+
types: types,
|
231
|
+
setting: cellSetting
|
232
|
+
}))), isShowAction && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
233
|
+
ref: drag,
|
234
|
+
style: {
|
235
|
+
position: 'absolute',
|
236
|
+
top: '-1px',
|
237
|
+
left: '-1px'
|
238
|
+
}
|
239
|
+
}, /*#__PURE__*/React.createElement(_Button, {
|
240
|
+
size: "small",
|
241
|
+
type: "primary",
|
242
|
+
icon: /*#__PURE__*/React.createElement(DragOutlined, null)
|
243
|
+
})), /*#__PURE__*/React.createElement("div", {
|
244
|
+
style: {
|
245
|
+
position: 'absolute',
|
246
|
+
bottom: '-1px',
|
247
|
+
right: '0px'
|
248
|
+
}
|
249
|
+
}, /*#__PURE__*/React.createElement(_Button, {
|
250
|
+
size: "small",
|
251
|
+
type: "primary",
|
252
|
+
onClick: onNodeDelete,
|
253
|
+
icon: /*#__PURE__*/React.createElement(DeleteOutlined, null)
|
254
|
+
}), /*#__PURE__*/React.createElement(_Button, {
|
255
|
+
size: "small",
|
256
|
+
type: "primary",
|
257
|
+
onClick: onNodeCopy,
|
258
|
+
icon: /*#__PURE__*/React.createElement(SnippetsOutlined, null)
|
259
|
+
}))));
|
260
|
+
};
|
261
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: wangxian
|
3
|
+
* @Date: 2023-02-06 11:35:45
|
4
|
+
* @LastEditTime: 2023-02-27 10:13:49
|
5
|
+
*/
|
6
|
+
import React from 'react';
|
7
|
+
import Input from './Cell/Input';
|
8
|
+
import TextArea from './Cell/TextArea';
|
9
|
+
import Date from './Cell/Date';
|
10
|
+
import Number from './Cell/Number';
|
11
|
+
import Switch from './Cell/Switch';
|
12
|
+
import Select from './Cell/Select';
|
13
|
+
import MutiSelect from './Cell/MutiSelect';
|
14
|
+
import Color from './Cell/Color';
|
15
|
+
import Checkbox from './Cell/Checkbox';
|
16
|
+
import Radio from './Cell/Radio';
|
17
|
+
import Password from './Cell/Password';
|
18
|
+
import Upload from './Cell/Upload';
|
19
|
+
import Obj from './Cell/Obj';
|
20
|
+
import List from './Cell/List';
|
21
|
+
import Table from './Cell/Table';
|
22
|
+
|
23
|
+
var RenderField = function RenderField(props) {
|
24
|
+
var data = props.data,
|
25
|
+
refId = props.refId,
|
26
|
+
_props$isShowAction = props.isShowAction,
|
27
|
+
isShowAction = _props$isShowAction === void 0 ? false : _props$isShowAction;
|
28
|
+
var FieldContent = React.useMemo(function () {
|
29
|
+
var _content = /*#__PURE__*/React.createElement(React.Fragment, null);
|
30
|
+
|
31
|
+
if (data.type && DataCellMap[data.type]) {
|
32
|
+
var Comm = DataCellMap[data.type];
|
33
|
+
return /*#__PURE__*/React.createElement(Comm, {
|
34
|
+
data: data,
|
35
|
+
refId: refId,
|
36
|
+
isShowAction: isShowAction
|
37
|
+
});
|
38
|
+
}
|
39
|
+
|
40
|
+
return _content;
|
41
|
+
}, [data, isShowAction]);
|
42
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, FieldContent);
|
43
|
+
};
|
44
|
+
|
45
|
+
export default RenderField;
|
46
|
+
var DataCellMap = {
|
47
|
+
input: Input,
|
48
|
+
textarea: TextArea,
|
49
|
+
date: Date,
|
50
|
+
number: Number,
|
51
|
+
switch: Switch,
|
52
|
+
select: Select,
|
53
|
+
mutiSelect: MutiSelect,
|
54
|
+
color: Color,
|
55
|
+
checkbox: Checkbox,
|
56
|
+
radio: Radio,
|
57
|
+
password: Password,
|
58
|
+
upload: Upload,
|
59
|
+
obj: Obj,
|
60
|
+
list: List,
|
61
|
+
table: Table
|
62
|
+
};
|
@@ -0,0 +1,315 @@
|
|
1
|
+
import "antd/es/form/style";
|
2
|
+
import _Form from "antd/es/form";
|
3
|
+
import "antd/es/row/style";
|
4
|
+
import _Row from "antd/es/row";
|
5
|
+
import "antd/es/col/style";
|
6
|
+
import _Col from "antd/es/col";
|
7
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
8
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
9
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
10
|
+
import React from 'react';
|
11
|
+
import { useDrop } from 'react-dnd';
|
12
|
+
import { FGCtx } from '../../../../../comps/FormGenerator/Provider';
|
13
|
+
import { dragItemType, formSetting as _formSetting, streamEventType } from '../../../settings';
|
14
|
+
import useObservable from '../../../../../framework/rxjs-hooks/useObservable';
|
15
|
+
import { arrayInsert, arrayMoveImmutable, guid } from '../../../../../utils';
|
16
|
+
import RenderField from './RenderField';
|
17
|
+
import './index.less';
|
18
|
+
|
19
|
+
var CanvasCore = function CanvasCore(props) {
|
20
|
+
var _formSetting$layout;
|
21
|
+
|
22
|
+
var refId = props.refId,
|
23
|
+
nodes = props.nodes,
|
24
|
+
onChange = props.onChange;
|
25
|
+
var fGCtx = React.useContext(FGCtx) || {};
|
26
|
+
|
27
|
+
var _React$useState = React.useState([]),
|
28
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
29
|
+
list = _React$useState2[0],
|
30
|
+
setList = _React$useState2[1];
|
31
|
+
|
32
|
+
var listRef = React.useRef([]);
|
33
|
+
|
34
|
+
var _React$useState3 = React.useState(),
|
35
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
36
|
+
curNodeId = _React$useState4[0],
|
37
|
+
setCurNodeId = _React$useState4[1];
|
38
|
+
|
39
|
+
var _React$useState5 = React.useState(_formSetting.param.defaultValue),
|
40
|
+
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
41
|
+
formSetting = _React$useState6[0],
|
42
|
+
setFormSetting = _React$useState6[1];
|
43
|
+
|
44
|
+
var _React$useState7 = React.useState(),
|
45
|
+
_React$useState8 = _slicedToArray(_React$useState7, 2),
|
46
|
+
allSetting = _React$useState8[0],
|
47
|
+
setAllSetting = _React$useState8[1];
|
48
|
+
|
49
|
+
var allSettingRef = React.useRef();
|
50
|
+
React.useEffect(function () {
|
51
|
+
if (refId && nodes.length > 0) {
|
52
|
+
setList(_toConsumableArray(nodes));
|
53
|
+
listRef.current = nodes;
|
54
|
+
}
|
55
|
+
}, [refId, nodes]); // 处理默认数据
|
56
|
+
|
57
|
+
var processDefaultValue = React.useCallback(function (data) {
|
58
|
+
if (!refId) {
|
59
|
+
setList(_toConsumableArray(data.nodes));
|
60
|
+
listRef.current = data.nodes;
|
61
|
+
|
62
|
+
if (data.types) {
|
63
|
+
fGCtx.fgStream && fGCtx.fgStream.next({
|
64
|
+
type: streamEventType.onTypesChange,
|
65
|
+
payload: data.types
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
69
|
+
onChange && onChange(data.nodes);
|
70
|
+
}
|
71
|
+
}, []);
|
72
|
+
var addNewNode = React.useCallback(function (_node, dropId, position) {
|
73
|
+
var _newNode;
|
74
|
+
|
75
|
+
var _list = listRef.current;
|
76
|
+
var newNode = _node;
|
77
|
+
|
78
|
+
var oldIdx = _list.findIndex(function (it) {
|
79
|
+
return it.id === _node.id;
|
80
|
+
});
|
81
|
+
|
82
|
+
if (dropId && position) {
|
83
|
+
//先判断是新增还是改变顺序
|
84
|
+
var newIdx = _list.findIndex(function (it) {
|
85
|
+
return it.id === dropId;
|
86
|
+
});
|
87
|
+
|
88
|
+
newIdx = position === 'borderTop' ? newIdx : newIdx + 1;
|
89
|
+
|
90
|
+
if (oldIdx === -1) {
|
91
|
+
newNode = _objectSpread(_objectSpread({}, _node), {}, {
|
92
|
+
id: "".concat(_node.id.split('-')[0], "-").concat(guid().substring(0, 4))
|
93
|
+
});
|
94
|
+
_list = arrayInsert(_list, newIdx, newNode);
|
95
|
+
} else {
|
96
|
+
newIdx = oldIdx < newIdx ? newIdx - 1 : newIdx;
|
97
|
+
_list = arrayMoveImmutable(_list, oldIdx, newIdx);
|
98
|
+
}
|
99
|
+
} else {
|
100
|
+
if (oldIdx === -1) {
|
101
|
+
newNode = _objectSpread(_objectSpread({}, _node), {}, {
|
102
|
+
id: "".concat(_node.id.split('-')[0], "-").concat(guid().substring(0, 4))
|
103
|
+
});
|
104
|
+
|
105
|
+
_list.push(newNode);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
if ((_newNode = newNode) === null || _newNode === void 0 ? void 0 : _newNode.id) {
|
110
|
+
fGCtx.fgStream && fGCtx.fgStream.next({
|
111
|
+
type: streamEventType.onNodeSelect,
|
112
|
+
payload: {
|
113
|
+
node: newNode,
|
114
|
+
refId: refId
|
115
|
+
}
|
116
|
+
});
|
117
|
+
}
|
118
|
+
|
119
|
+
setList(_toConsumableArray(_list));
|
120
|
+
listRef.current = _list;
|
121
|
+
onChange && onChange(_list);
|
122
|
+
}, []);
|
123
|
+
var processFgStreamData = React.useCallback(function (p) {
|
124
|
+
var _p$payload, _p$payload$node, _p$payload2, _p$payload3, _p$payload4;
|
125
|
+
|
126
|
+
switch (p === null || p === void 0 ? void 0 : p.type) {
|
127
|
+
case streamEventType.onNodeSelect:
|
128
|
+
setCurNodeId(p === null || p === void 0 ? void 0 : (_p$payload = p.payload) === null || _p$payload === void 0 ? void 0 : (_p$payload$node = _p$payload.node) === null || _p$payload$node === void 0 ? void 0 : _p$payload$node.id);
|
129
|
+
break;
|
130
|
+
|
131
|
+
case streamEventType.onClearCanvas:
|
132
|
+
setList([]);
|
133
|
+
listRef.current = [];
|
134
|
+
onChange && onChange([]);
|
135
|
+
break;
|
136
|
+
|
137
|
+
case streamEventType.onDropOver:
|
138
|
+
if (refId === ((_p$payload2 = p.payload) === null || _p$payload2 === void 0 ? void 0 : _p$payload2.refId)) {
|
139
|
+
addNewNode(p.payload.dragItem, p.payload.dropId, p.payload.position);
|
140
|
+
}
|
141
|
+
|
142
|
+
break;
|
143
|
+
|
144
|
+
case streamEventType.onNodeCopy:
|
145
|
+
addNewNode(p.payload);
|
146
|
+
break;
|
147
|
+
|
148
|
+
case streamEventType.onNodeDelete:
|
149
|
+
if (refId === ((_p$payload3 = p.payload) === null || _p$payload3 === void 0 ? void 0 : _p$payload3.refId)) {
|
150
|
+
var _list = listRef.current;
|
151
|
+
_list = _list.filter(function (it) {
|
152
|
+
return it.id !== p.payload.id;
|
153
|
+
});
|
154
|
+
setList(_toConsumableArray(_list));
|
155
|
+
listRef.current = _list;
|
156
|
+
onChange && onChange(_list); // 默认焦点放在第一个
|
157
|
+
|
158
|
+
if (_list.length > 0) {
|
159
|
+
onSelect(_list[0]);
|
160
|
+
} else {
|
161
|
+
fGCtx.fgStream && fGCtx.fgStream.next({
|
162
|
+
type: streamEventType.onClearCanvas
|
163
|
+
});
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
break;
|
168
|
+
|
169
|
+
case streamEventType.onSettingValueChange:
|
170
|
+
if (p === null || p === void 0 ? void 0 : (_p$payload4 = p.payload) === null || _p$payload4 === void 0 ? void 0 : _p$payload4.formSetting) {
|
171
|
+
var _p$payload5;
|
172
|
+
|
173
|
+
setFormSetting(_objectSpread({}, p === null || p === void 0 ? void 0 : (_p$payload5 = p.payload) === null || _p$payload5 === void 0 ? void 0 : _p$payload5.formSetting));
|
174
|
+
}
|
175
|
+
|
176
|
+
if ((p === null || p === void 0 ? void 0 : p.payload.refId) === refId) {
|
177
|
+
if (refId) {
|
178
|
+
var _p$payload6, _p$payload7;
|
179
|
+
|
180
|
+
setAllSetting(_objectSpread({}, p === null || p === void 0 ? void 0 : (_p$payload6 = p.payload) === null || _p$payload6 === void 0 ? void 0 : _p$payload6.allSetting[refId]));
|
181
|
+
allSettingRef.current = _objectSpread({}, p === null || p === void 0 ? void 0 : (_p$payload7 = p.payload) === null || _p$payload7 === void 0 ? void 0 : _p$payload7.allSetting[refId]);
|
182
|
+
} else {
|
183
|
+
var _p$payload8, _p$payload9;
|
184
|
+
|
185
|
+
setAllSetting(_objectSpread({}, p === null || p === void 0 ? void 0 : (_p$payload8 = p.payload) === null || _p$payload8 === void 0 ? void 0 : _p$payload8.allSetting));
|
186
|
+
allSettingRef.current = _objectSpread({}, p === null || p === void 0 ? void 0 : (_p$payload9 = p.payload) === null || _p$payload9 === void 0 ? void 0 : _p$payload9.allSetting);
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
break;
|
191
|
+
|
192
|
+
case streamEventType.onDefaultValue:
|
193
|
+
processDefaultValue(p === null || p === void 0 ? void 0 : p.payload);
|
194
|
+
break;
|
195
|
+
}
|
196
|
+
}, []);
|
197
|
+
useObservable(function (p) {
|
198
|
+
processFgStreamData(p);
|
199
|
+
}, [fGCtx.fgStream]); // 处理组件拖拽落下事件
|
200
|
+
|
201
|
+
var _useDrop = useDrop({
|
202
|
+
accept: [dragItemType],
|
203
|
+
drop: function drop(item, monitor) {
|
204
|
+
// 如果 children 已经作为了 drop target,不处理
|
205
|
+
var didDrop = monitor.didDrop();
|
206
|
+
|
207
|
+
if (didDrop) {
|
208
|
+
return;
|
209
|
+
}
|
210
|
+
|
211
|
+
addNewNode(item.dragItem);
|
212
|
+
},
|
213
|
+
hover: function hover(item, monitor) {
|
214
|
+
// 只检查被hover的最小元素
|
215
|
+
var didHover = monitor.isOver({
|
216
|
+
shallow: true
|
217
|
+
});
|
218
|
+
|
219
|
+
if (didHover) {}
|
220
|
+
},
|
221
|
+
collect: function collect(monitor) {
|
222
|
+
return {
|
223
|
+
isOver: monitor.isOver({
|
224
|
+
shallow: true
|
225
|
+
}),
|
226
|
+
canDrop: monitor.canDrop()
|
227
|
+
};
|
228
|
+
}
|
229
|
+
}),
|
230
|
+
_useDrop2 = _slicedToArray(_useDrop, 2),
|
231
|
+
_useDrop2$ = _useDrop2[0],
|
232
|
+
isOver = _useDrop2$.isOver,
|
233
|
+
canDrop = _useDrop2$.canDrop,
|
234
|
+
dropRef = _useDrop2[1];
|
235
|
+
|
236
|
+
var onSelect = function onSelect(it) {
|
237
|
+
fGCtx.fgStream && fGCtx.fgStream.next({
|
238
|
+
type: streamEventType.onNodeSelect,
|
239
|
+
payload: {
|
240
|
+
node: it,
|
241
|
+
refId: refId
|
242
|
+
}
|
243
|
+
});
|
244
|
+
};
|
245
|
+
|
246
|
+
var processColSpan = function processColSpan(compColSpan, formColSpan) {
|
247
|
+
var _formColSpan = formColSpan !== null && formColSpan !== void 0 ? formColSpan : 24;
|
248
|
+
|
249
|
+
if (compColSpan) {
|
250
|
+
return compColSpan * _formColSpan <= 24 ? compColSpan * _formColSpan : 24;
|
251
|
+
}
|
252
|
+
|
253
|
+
return _formColSpan;
|
254
|
+
};
|
255
|
+
|
256
|
+
var isActive = canDrop && isOver;
|
257
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
258
|
+
className: "canvas-wrapper",
|
259
|
+
ref: dropRef,
|
260
|
+
style: {
|
261
|
+
width: '100%',
|
262
|
+
height: 'calc(100% - 40px)',
|
263
|
+
minHeight: '100px',
|
264
|
+
background: 'var(--ronds-metadata-color-bg-3)',
|
265
|
+
padding: '8px',
|
266
|
+
border: "".concat(isActive ? '2px solid red' : '1px dashed var(--ronds-metadata-color-border-1)'),
|
267
|
+
overflowY: 'auto'
|
268
|
+
}
|
269
|
+
}, /*#__PURE__*/React.createElement(_Form, {
|
270
|
+
layout: (_formSetting$layout = formSetting === null || formSetting === void 0 ? void 0 : formSetting.layout) !== null && _formSetting$layout !== void 0 ? _formSetting$layout : 'horizontal',
|
271
|
+
wrapperCol: (formSetting === null || formSetting === void 0 ? void 0 : formSetting.labelSpan) && (formSetting === null || formSetting === void 0 ? void 0 : formSetting.layout) === 'horizontal' ? {
|
272
|
+
span: 24 - (formSetting === null || formSetting === void 0 ? void 0 : formSetting.labelSpan),
|
273
|
+
offset: 0
|
274
|
+
} : undefined,
|
275
|
+
labelCol: (formSetting === null || formSetting === void 0 ? void 0 : formSetting.labelSpan) && (formSetting === null || formSetting === void 0 ? void 0 : formSetting.layout) === 'horizontal' ? {
|
276
|
+
span: formSetting === null || formSetting === void 0 ? void 0 : formSetting.labelSpan,
|
277
|
+
offset: 0
|
278
|
+
} : undefined,
|
279
|
+
labelWrap: true,
|
280
|
+
autoComplete: "off"
|
281
|
+
}, /*#__PURE__*/React.createElement(_Row, {
|
282
|
+
gutter: 8
|
283
|
+
}, list.length > 0 && list.map(function (it) {
|
284
|
+
var _allSetting$it$id;
|
285
|
+
|
286
|
+
return /*#__PURE__*/React.createElement(_Col, {
|
287
|
+
key: it.id,
|
288
|
+
span: processColSpan(allSetting && ((_allSetting$it$id = allSetting[it.id]) === null || _allSetting$it$id === void 0 ? void 0 : _allSetting$it$id.colSpan), formSetting === null || formSetting === void 0 ? void 0 : formSetting.colSpan),
|
289
|
+
style: {
|
290
|
+
width: '100%'
|
291
|
+
}
|
292
|
+
}, /*#__PURE__*/React.createElement("div", {
|
293
|
+
key: it.id,
|
294
|
+
className: "drag-item ".concat(curNodeId === it.id ? 'drag-item-selected' : ''),
|
295
|
+
onClick: function onClick(e) {
|
296
|
+
e.stopPropagation();
|
297
|
+
onSelect(it);
|
298
|
+
}
|
299
|
+
}, /*#__PURE__*/React.createElement(RenderField, {
|
300
|
+
refId: refId,
|
301
|
+
data: it,
|
302
|
+
isShowAction: curNodeId === it.id
|
303
|
+
})));
|
304
|
+
}), list.length === 0 && /*#__PURE__*/React.createElement("div", {
|
305
|
+
style: {
|
306
|
+
width: '100%',
|
307
|
+
textAlign: 'center',
|
308
|
+
padding: '20px',
|
309
|
+
color: 'var(--ronds-metadata-color-text-2)',
|
310
|
+
opacity: 0.6
|
311
|
+
}
|
312
|
+
}, "\u62D6\u62FD\u5DE6\u4FA7\u680F\u7684\u7EC4\u4EF6\u8FDB\u884C\u6DFB\u52A0")))));
|
313
|
+
};
|
314
|
+
|
315
|
+
export default /*#__PURE__*/React.memo(CanvasCore);
|