-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathshadowBlock.js
More file actions
229 lines (183 loc) · 8.22 KB
/
shadowBlock.js
File metadata and controls
229 lines (183 loc) · 8.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
define([
'./api.js'
, './constData.js'
], function ( api, constData ) {
const { MapTypeToName } = api;
const { BLOCK_DIRECTION
, BLOCK_CODELINE_TYPE
, NUM_INDENT_DEPTH_PX
, NUM_SHADOWBLOCK_OPACITY
, STR_BLOCK
, STR_DIV
, STR_OPACITY
, STR_WIDTH
, STR_MARGIN_LEFT
, STR_DISPLAY
, VP_CLASS_PREFIX
, VP_CLASS_BLOCK_SHADOWBLOCK_CONTAINER
, VP_CLASS_SELECTED_SHADOWBLOCK } = constData;
var ShadowBlock = function(blockContainerThis, type, realBlock) {
this.type = type;
this.name = MapTypeToName(type);
this.direction = -1;
this.rootBlockUuid = '';
this.blockContainerThis = blockContainerThis;
this.width = blockContainerThis.getBlockMaxWidth();
this.realBlock = realBlock;
this.rootDepth = 0;
this.rootDom = null;
this.containerDom = null;
this.selectBlock = null;
this.childListDom = null;
this.childBlockList = [];
this.init();
}
ShadowBlock.prototype.init = function() {
var blockContainerThis = this.blockContainerThis;
/** root container 생성 */
var shadowContainerDom = document.createElement(STR_DIV);
$(shadowContainerDom).css(STR_DISPLAY,STR_BLOCK);
$(shadowContainerDom).addClass(VP_CLASS_BLOCK_SHADOWBLOCK_CONTAINER);
$(shadowContainerDom).addClass(VP_CLASS_SELECTED_SHADOWBLOCK);
/** 블럭을 이동할 때 */
if (this.realBlock) {
this.childListDom = [];
this.childBlockList = this.realBlock.getBlockList_thisBlockArea();
/* 첫번째 블럭이 node 블럭이고
* toggle 된 상태면 두번째 이후 블럭 생성 안함
*/
if (this.realBlock.getBlockType() == BLOCK_CODELINE_TYPE.NODE
|| this.realBlock.getBlockType() == BLOCK_CODELINE_TYPE.TEXT
|| this.realBlock.isGroupBox) {
var blockMainDom = blockContainerThis.makeShadowBlockDom(this.realBlock);
$(blockMainDom).css(STR_OPACITY, NUM_SHADOWBLOCK_OPACITY);
this.childListDom.push(blockMainDom);
$(shadowContainerDom).append(blockMainDom);
} else {
this.childBlockList.forEach(block => {
var blockMainDom = blockContainerThis.makeShadowBlockDom(block);
$(blockMainDom).css(STR_OPACITY, NUM_SHADOWBLOCK_OPACITY);
this.childListDom.push(blockMainDom);
$(shadowContainerDom).append(blockMainDom);
});
}
/** Logic(Define, Control, Execute) 이동할 때 */
} else {
this.childListDom = [];
var blockMainDom = blockContainerThis.makeShadowBlockDom(this);
$(blockMainDom).css(STR_OPACITY, NUM_SHADOWBLOCK_OPACITY);
this.childListDom.push(blockMainDom);
$(shadowContainerDom).append(blockMainDom);
}
this.setBlockContainerDom(shadowContainerDom);
}
ShadowBlock.prototype.reRender = function() {
var rootDepth = this.getRootDepth();
var blockMaxWidth = this.blockContainerThis.getBlockMaxWidth();
/** 블럭을 이동할 때 */
if (this.realBlock) {
var firstShadowDomDepth = this.childBlockList[0].getDepth();
this.childListDom.forEach( (childDom, index) => {
var childBlockDepth = this.childBlockList[index].getDepth();
var _childBlockDepth = childBlockDepth - firstShadowDomDepth + rootDepth;
var blockwidth = blockMaxWidth - (_childBlockDepth * NUM_INDENT_DEPTH_PX);
$(childDom).css(STR_WIDTH, blockwidth );
$(childDom).css(STR_MARGIN_LEFT, _childBlockDepth * NUM_INDENT_DEPTH_PX);
});
/** Logic(Define, Control, Execute) 이동할 때 */
} else {
this.childListDom.forEach( (childDom) => {
var blockwidth = blockMaxWidth - (rootDepth * NUM_INDENT_DEPTH_PX);
$(childDom).css(STR_WIDTH, blockwidth);
$(childDom).css(STR_MARGIN_LEFT, rootDepth * NUM_INDENT_DEPTH_PX);
});
}
}
/** Logic(Define, Control, Execute)이나 블럭이 이동할 때,
* shadow를 생성하고 그 shadow를 block container dom에 insert하는 메소드
*/
ShadowBlock.prototype.insertShadowDomToBlockDom = function( thisBlock, direction, asGroup=false) {
// var thisBlock = this;
// console.log('depth',depth);
var blockContainerThis = this.getBlockContainerThis();
var depth = thisBlock.getDepth();
var indentPxNum = thisBlock.getIndentNumber();
if (direction == BLOCK_DIRECTION.INDENT) {
indentPxNum += NUM_INDENT_DEPTH_PX;
depth++;
}
var blockMaxWidth = blockContainerThis.getBlockMaxWidth() - indentPxNum;
var shadowContainerDom = this.getBlockContainerDom();
$(shadowContainerDom).css(STR_WIDTH, blockMaxWidth);
$(shadowContainerDom).css(STR_DISPLAY,STR_BLOCK);
// show line number for group block's shadow
// if (asGroup) {
// $(shadowContainerDom).first('.vp-block-num-info').css(STR_OPACITY, 1);
// } else {
// $(shadowContainerDom).first('.vp-block-num-info').css(STR_OPACITY, 0);
// }
this.setSelectBlock(thisBlock);
this.setRootDepth(depth);
this.reRender();
var containerDom = blockContainerThis.getBlockContainerDom();
containerDom.insertBefore(shadowContainerDom, thisBlock.getBlockMainDom().nextSibling);
}
ShadowBlock.prototype.insertShadowDomToBlockDomAsGroup = function(thisBlock, direction) {
var blockContainerThis = this.getBlockContainerThis();
var depth = thisBlock.getDepth();
var indentPxNum = thisBlock.getIndentNumber();
if (direction == BLOCK_DIRECTION.INDENT) {
indentPxNum += NUM_INDENT_DEPTH_PX;
depth++;
}
var blockMaxWidth = blockContainerThis.getBlockMaxWidth() - indentPxNum;
var shadowContainerDom = this.getBlockContainerDom();
$(shadowContainerDom).css(STR_WIDTH, blockMaxWidth);
$(shadowContainerDom).css(STR_DISPLAY, STR_BLOCK);
// show line number for group block's shadow
$(shadowContainerDom).first('.vp-block-num-info').css(STR_OPACITY, 1);
this.setSelectBlock(thisBlock);
this.setRootDepth(depth);
this.reRender();
var containerDom = blockContainerThis.getBlockContainerDom();
containerDom.insertBefore(shadowContainerDom, thisBlock.getBlockMainDom().nextSibling);
}
ShadowBlock.prototype.getBlockContainerThis = function() {
return this.blockContainerThis;
}
ShadowBlock.prototype.setRootDepth = function(rootDepth) {
this.rootDepth = rootDepth;
}
ShadowBlock.prototype.getRootDepth = function() {
return this.rootDepth;
}
ShadowBlock.prototype.getBlockName = function() {
return this.name;
}
ShadowBlock.prototype.setBlockName = function(name) {
this.name = name;
}
ShadowBlock.prototype.getBlockType = function() {
return this.type;
}
ShadowBlock.prototype.getBlockContainerDom = function() {
return this.containerDom;
}
ShadowBlock.prototype.setBlockContainerDom = function(containerDom) {
this.containerDom = containerDom;
}
ShadowBlock.prototype.setSelectBlock = function(selectBlock) {
this.selectBlock = selectBlock;
}
ShadowBlock.prototype.getSelectBlock = function() {
return this.selectBlock;
}
/** insertShadowDomToBlockDom메소드에서
* block container dom에 insert된 Shadow 블럭 dom을 제거하는 메소드 */
ShadowBlock.prototype.deleteShadowBlock = function() {
var blockContainerThis = this.blockContainerThis;
var rootBlockContainerDom = blockContainerThis.getBlockContainerDom();
$(rootBlockContainerDom).find(VP_CLASS_PREFIX + VP_CLASS_BLOCK_SHADOWBLOCK_CONTAINER).remove();
}
return ShadowBlock;
});