@@ -35,8 +35,15 @@ function dragStart (d) {
35
35
d . x = 0 ;
36
36
d . y = 0 ;
37
37
}
38
+ // DEACTIVATE ALL textareas AND inputs
39
+ d3 . select ( 'div.canvas' ) . selectAll ( 'textarea, input' )
40
+ . classed ( 'deactivate' , true ) ;
41
+ } else {
42
+ sel . classed ( 'dragging' , false ) ;
43
+ // REACTIVATE ALL textareas AND inputs
44
+ d3 . select ( 'div.canvas' ) . selectAll ( 'textarea, input' )
45
+ . classed ( 'deactivate' , false ) ;
38
46
}
39
- else sel . classed ( 'dragging' , false ) ;
40
47
}
41
48
42
49
let object ;
@@ -110,9 +117,16 @@ async function dragEnd (d) {
110
117
111
118
const sel = d3 . select ( this )
112
119
. classed ( 'dragging' , false ) ;
120
+ // REACTIVATE ALL textareas AND inputs
121
+ d3 . select ( 'div.canvas' ) . selectAll ( 'textarea, input' )
122
+ . classed ( 'deactivate' , false ) ;
123
+
113
124
const parent = d3 . select ( this . parentNode ) ;
125
+ const otree = d . tree ;
114
126
115
127
const hit = d3 . select ( 'div.hit' ) ;
128
+ let pipes = [ ] ;
129
+
116
130
if ( hit . node ( ) ) {
117
131
// 1- CHECK IF THE HIT IS AN EXISTING GROUP
118
132
// OTHERWISE CREATE THE GROUP
@@ -123,13 +137,13 @@ async function dragEnd (d) {
123
137
groupping = hit ;
124
138
d . x = null ;
125
139
d . y = null ;
126
- const { id : gid , tree : gtree } = hit . datum ( ) ;
127
- // d.tree = tree.rebase(d.tree, gid, gtree);
140
+ const { id : gid , tree : gtree , pipe_to } = hit . datum ( ) ;
128
141
d . tree = tree . build ( gtree , gid ) ;
129
-
142
+ if ( Array . isArray ( pipe_to ) && pipe_to ?. length ) pipes = [ ...pipes , ...pipe_to ] ;
143
+
130
144
} else if ( hit . classed ( 'note' ) || hit . classed ( 'card' ) ) {
131
145
// IF THE HIT IS A NOTE OR CARD, CREATE A GROUP
132
- const { x, y, tree : ntree } = hit . datum ( ) ;
146
+ const { x, y, tree : ntree , piped_from } = hit . datum ( ) ;
133
147
134
148
groupping = await Group . add ( {
135
149
parent : d3 . select ( hit . node ( ) . parentNode ) ,
@@ -141,8 +155,26 @@ async function dragEnd (d) {
141
155
d . x = null ;
142
156
d . y = null ;
143
157
const { id : gid , tree : gtree } = groupping . datum ( ) ;
144
- // d.tree = tree.rebase(d.tree, gid, gtree);
145
158
d . tree = tree . build ( gtree , gid ) ;
159
+
160
+ // IF THE hit note IS INSIDE A PIPED GROUP, PIPE THE dragged NOTE
161
+ if ( tree . getDepth ( d . tree ) > 1 ) {
162
+ // CHECK ALL THE PARENT GROUPS FOR PIPING
163
+ const nodes = tree . getNodes ( d . tree ) ;
164
+ let i = nodes . length - 1 ;
165
+
166
+ while ( i >= 0 ) {
167
+ const group = d3 . selectAll ( 'div.group' )
168
+ . filter ( d => d . id === + nodes [ i ] ) ;
169
+
170
+ if ( group . node ( ) ) {
171
+ const { pipe_to } = group . datum ( ) ;
172
+ if ( Array . isArray ( pipe_to ) && pipe_to ?. length ) pipes = [ ...pipes , ...pipe_to ] ;
173
+ }
174
+ i -- ;
175
+ }
176
+
177
+ }
146
178
}
147
179
hit . classed ( 'hit' , false ) ;
148
180
} else { // THE OBJECT IS MOVED OUT OF ALL GROUPS
@@ -155,8 +187,9 @@ async function dragEnd (d) {
155
187
if ( sel . classed ( 'note' ) ) {
156
188
await Note . update ( {
157
189
note : sel ,
158
- datum : d ,
190
+ datum : { ... d , ... { pipe_from : null } } ,
159
191
bcast : true ,
192
+ group_pipes : pipes ,
160
193
} ) ;
161
194
} else if ( sel . classed ( 'card' ) ) {
162
195
await Card . update ( {
0 commit comments