Skip to content

Commit 9c6960b

Browse files
authored
Merge pull request #15 from zsjjs/v1.0.4
V1.0.4
2 parents 635e9c1 + e660288 commit 9c6960b

File tree

13 files changed

+108
-64
lines changed

13 files changed

+108
-64
lines changed

.babelrc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
{
2-
"presets": ["react", "es2015", "stage-3"],
2+
"presets": ["@babel/preset-react", "@babel/preset-env"],
33
"plugins": [
4-
"transform-runtime"
4+
"@babel/plugin-transform-runtime",
5+
["@babel/plugin-proposal-class-properties", { "loose": true }],
6+
// Stage 1
7+
"@babel/plugin-proposal-export-default-from",
8+
"@babel/plugin-proposal-logical-assignment-operators",
9+
["@babel/plugin-proposal-optional-chaining", { "loose": false }],
10+
["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }],
11+
["@babel/plugin-proposal-nullish-coalescing-operator", { "loose": false }],
12+
"@babel/plugin-proposal-do-expressions"
513
]
614
}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@
8181
<td align="center">boolean</td>
8282
<td align="center">true</td>
8383
</tr>
84+
<tr>
85+
<td colspan="2">edit</td>
86+
<td>线条是否可以拖动/删除(如果需要预览态,isSort不能为true)</td>
87+
<td align="center">boolean</td>
88+
<td align="center">true</td>
89+
</tr>
8490
<tr>
8591
<td colspan="2">relation</td>
8692
<td>默认已映射数据</td>

example/test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: yanjun.zsj
33
* @LastEditors: yanjun.zsj
44
* @Date: 2019-03-11 16:43:26
5-
* @LastEditTime: 2019-09-04 11:57:46
5+
* @LastEditTime: 2019-11-21 17:51:13
66
*/
77
/* global React, ReactDOM */
88
const sourceCols = [
@@ -128,7 +128,8 @@ class App extends React.PureComponent {
128128
relation
129129
});
130130
},
131-
isSort: true
131+
isSort: true,
132+
132133
};
133134
return <div>
134135
<div>

package.json

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,39 @@
3131
"LICENSE"
3232
],
3333
"devDependencies": {
34-
"babel-eslint": "^10.0.1",
35-
"eslint": "^5.0.1",
36-
"eslint-loader": "^2.0.0",
37-
"eslint-plugin-react": "^7.10.0",
34+
"@babel/plugin-proposal-class-properties": "^7.7.0",
35+
"@babel/plugin-proposal-do-expressions": "^7.6.0",
36+
"@babel/plugin-proposal-export-default-from": "^7.5.2",
37+
"@babel/plugin-proposal-logical-assignment-operators": "^7.2.0",
38+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
39+
"@babel/plugin-proposal-optional-chaining": "^7.6.0",
40+
"@babel/plugin-proposal-pipeline-operator": "^7.5.0",
41+
"babel-eslint": "^10.0.3",
42+
"eslint": "^6.4.0",
43+
"eslint-loader": "^3.0.0",
44+
"eslint-plugin-react": "^7.14.3",
3845
"jsinspect": "^0.12.7",
39-
"less": "^3.8.1",
40-
"webpack-dev-server": "^3.1.5"
46+
"less": "^3.10.3",
47+
"webpack-dev-server": "^3.8.1"
4148
},
4249
"dependencies": {
43-
"babel-core": "^6.26.3",
44-
"babel-loader": "^7.1.2",
45-
"babel-plugin-transform-runtime": "^6.23.0",
46-
"babel-preset-env": "^1.6.0",
47-
"babel-preset-es2015": "^6.24.1",
48-
"babel-preset-react": "^6.24.1",
49-
"babel-preset-stage-3": "^6.24.1",
50-
"cross-env": "^5.1.1",
51-
"css-loader": "^0.28.7",
52-
"less-loader": "^4.0.5",
50+
"@babel/core": "^7.6.0",
51+
"@babel/plugin-transform-runtime": "^7.6.0",
52+
"@babel/polyfill": "^7.6.0",
53+
"@babel/preset-env": "^7.6.0",
54+
"@babel/preset-react": "^7.0.0",
55+
"@babel/runtime": "^7.6.0",
56+
"babel-loader": "^8.0.6",
57+
"cross-env": "^6.0.0",
58+
"css-loader": "^3.2.0",
59+
"less-loader": "^5.0.0",
60+
"style-loader": "^1.0.0",
61+
"url-loader": "^2.1.0",
62+
"webpack": "^4.40.2",
63+
"webpack-cli": "^3.3.9",
5364
"lodash": "^4.17.11",
5465
"react": "^16.8.4",
5566
"react-dom": "^16.8.4",
56-
"sortablejs": "^1.7.0",
57-
"style-loader": "^0.19.0",
58-
"url-loader": "^0.6.2",
59-
"webpack": "^4.16.5",
60-
"webpack-cli": "^3.1.0"
67+
"sortablejs": "^1.7.0"
6168
}
6269
}

src/Columns.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Columns extends Component {
1616
return result;
1717
}
1818
render() {
19-
const { item, index, columnOpt, sorting, columns, type } = this.props;
19+
const { item, index, columnOpt, sorting, columns, type, edit } = this.props;
2020
return <li {...columnOpt(item, index)} >
2121
{
2222
columns.map((column, idx) => {
@@ -38,7 +38,7 @@ class Columns extends Component {
3838
);
3939
})
4040
}
41-
<div style={{visibility: item.iconShow}} className={`column-icon ${type}-column-icon ${sorting ? "sorting" : ""}`}></div>
41+
<div style={{visibility: edit && item.iconShow}} className={`column-icon ${type}-column-icon ${sorting ? "sorting" : ""} ${edit ? "" : "disabled"}`}></div>
4242
</li>;
4343
}
4444
}

src/drawLines.jsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,30 @@ const defaultState = {
1616
};
1717

1818
class DrawLines extends Component {
19+
baseXY = {
20+
left: 0,
21+
top: 0
22+
}
1923
constructor(props) {
2024
super(props);
2125
this.state = {
22-
baseXY:{
23-
left: 0,
24-
top: 0
25-
},
2626
...defaultState
2727
};
2828
}
2929
componentDidMount() {
3030
const me = this;
31-
const baseXY = getOffset(this.drawEle);
31+
this.baseXY = getOffset(this.drawEle);
3232
const box = document.querySelector('.react-field-mapping-box');
3333
let scrollTop = 0;
3434
let scrollLeft = 0;
35-
this.setState({
36-
baseXY
37-
});
3835
document.documentElement.onmousedown = (event) => {
3936
const eventDom = event.target;
4037
const className = eventDom && eventDom.className;
4138
if (className && typeof className === "string" && className.indexOf("source-column-icon") > -1) {
4239
event.preventDefault();
40+
if(this.baseXY !== getOffset(this.drawEle)) {
41+
this.baseXY = getOffset(this.drawEle);
42+
}
4343
let scrollEle = box;
4444
document.body.classList.add("user-select-none");
4545
const sourceData = _.find(me.props.sourceData, (o) => {
@@ -66,8 +66,8 @@ class DrawLines extends Component {
6666
if (this.state.drawing) {
6767
me.props.onDrawing && me.props.onDrawing(me.state.sourceData, me.props.relation);
6868
me.setState({
69-
endX: event.pageX - baseXY.left + scrollLeft,
70-
endY: event.pageY - baseXY.top + scrollTop
69+
endX: event.pageX - this.baseXY.left + scrollLeft,
70+
endY: event.pageY - this.baseXY.top + scrollTop
7171
});
7272
}
7373
};
@@ -111,8 +111,8 @@ class DrawLines extends Component {
111111
}
112112
domOperate(eventDom) {
113113
return {
114-
left: getOffset(eventDom).left - this.state.baseXY.left + 6,
115-
top: getOffset(eventDom).top - this.state.baseXY.top + 6,
114+
left: getOffset(eventDom).left - this.baseXY.left + 3,
115+
top: getOffset(eventDom).top - this.baseXY.top + 6,
116116
key: eventDom.offsetParent.getAttribute('data-key')
117117
};
118118
}
@@ -133,7 +133,7 @@ class DrawLines extends Component {
133133
}
134134
render() {
135135
const { startX, startY, drawing, endX, endY } = this.state;
136-
const { relation, currentRelation } = this.props;
136+
const { relation, currentRelation, edit } = this.props;
137137
return <div className="lines-area" ref={me => {this.drawEle = me;}}>
138138
<svg width="100%" height="100%" version="1.1"
139139
xmlns="http://www.w3.org/2000/svg">
@@ -159,6 +159,7 @@ class DrawLines extends Component {
159159
endX={item.target.x}
160160
endY={item.target.y}
161161
data={item}
162+
edit={edit}
162163
toTop={this.topLine.bind(this)}
163164
currentRelation={currentRelation}
164165
removeRelation={this.removeRelation.bind(this)}

src/fieldMapping.jsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,14 @@ class FieldMapping extends Component {
108108
target: {
109109
data: targetData,
110110
columns: targetCols
111-
}
112-
} = this.props;
113-
const {
111+
},
114112
className = "",
115113
style = {},
116114
isSort = false,
117115
onDrawStart,
118116
onDrawing,
119-
onDrawEnd
117+
onDrawEnd,
118+
edit
120119
} = this.props;
121120

122121
const sourceOpt = {
@@ -127,6 +126,7 @@ class FieldMapping extends Component {
127126
data: sourceData,
128127
currentRelation,
129128
isSort,
129+
edit,
130130
changeData: this.changeSource.bind(this),
131131
overActive: this.overActive.bind(this)
132132
};
@@ -138,6 +138,7 @@ class FieldMapping extends Component {
138138
data: targetData,
139139
currentRelation,
140140
isSort,
141+
edit,
141142
changeData: this.changeTarget.bind(this),
142143
overActive: this.overActive.bind(this)
143144
};
@@ -148,6 +149,7 @@ class FieldMapping extends Component {
148149
onDrawing,
149150
onDrawEnd,
150151
relation,
152+
edit,
151153
currentRelation,
152154
onChange: this.changeRelation.bind(this),
153155
changeIconStatus: this.changeIconStatus.bind(this)
@@ -198,7 +200,8 @@ FieldMapping.propTypes = {
198200
onChange: PropTypes.func, // function(param= relation)
199201
onDrawStart: PropTypes.func,// function(params=source, relation)
200202
onDrawing: PropTypes.func,// function(params=source, relation)
201-
onDrawEnd: PropTypes.func// function(params=source, relation)
203+
onDrawEnd: PropTypes.func,// function(params=source, relation)
204+
edit: PropTypes.bool // 是否能操作线条编辑 default true
202205
};
203206
FieldMapping.defaultProps = {
204207
relation: [],
@@ -211,6 +214,7 @@ FieldMapping.defaultProps = {
211214
data: [],
212215
onChange: () => {},
213216
columns: []
214-
}
217+
},
218+
edit: true
215219
};
216220
export default FieldMapping;

src/fieldMapping.less

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ body {
9797
&.sorting {
9898
visibility: hidden!important;
9999
}
100+
&.disabled {
101+
visibility: hidden!important;
102+
}
100103
}
101104
}
102105
}
@@ -137,7 +140,8 @@ body {
137140
.icon-remove {
138141
opacity: 0;
139142
}
140-
&.path-end:hover, &.path-end.active {
143+
&.path-end:hover,
144+
&.path-end.active {
141145
fill: #00A2CA;
142146
cursor: pointer;
143147
.line {
@@ -148,6 +152,16 @@ body {
148152
opacity: 1;
149153
}
150154
}
155+
&.path-end.disabled {
156+
cursor: initial;
157+
.line {
158+
stroke: #33B5D4;
159+
stroke-width: 2px;
160+
}
161+
.icon-remove {
162+
opacity: 0;
163+
}
164+
}
151165
}
152166
}
153167
}

src/line.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ class Line extends Component {
1717
endX = 0,
1818
endY = 0,
1919
currentRelation,
20-
data
20+
data,
21+
edit
2122
} = this.props;
22-
return <g className={`path-end ${(currentRelation === data) ? "active" : ""}`} onMouseOver={() => {
23-
this.props.toTop(this.props.data);
24-
}} onClick={this.removeHandle.bind(this)}>
23+
return <g className={`path-end ${(currentRelation === data) ? "active" : ""} ${edit ? '' : 'disabled'}`} onMouseOver={() => {
24+
edit && this.props.toTop(this.props.data);
25+
}} onClick={() => {
26+
edit && this.removeHandle();
27+
}}>
2528
<path
2629
className="line"
2730
d={`M${startX}, ${startY} L${endX}, ${endY}`}

src/sourceData.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class SourceData extends Component {
6868
data,
6969
iconStatus,
7070
overActive,
71-
relation
71+
relation,
72+
edit
7273
} = this.props;
7374
const { sorting } = this.state;
7475
const columnOpt = (item, index) => {
@@ -125,6 +126,7 @@ class SourceData extends Component {
125126
item={item}
126127
index={index}
127128
type="source"
129+
edit={edit}
128130
/>
129131
);
130132
})

0 commit comments

Comments
 (0)