1
1
import { Vector } from '../core/vector' ;
2
2
import { Step } from '../definition' ;
3
3
import { DesignerContext } from '../designer-context' ;
4
- import { Placeholder } from '../workspace/component' ;
4
+ import { FoundPlaceholders , Placeholder } from '../workspace/component' ;
5
5
import { Behavior } from './behavior' ;
6
6
import { DragStepView } from './drag-step-behavior-view' ;
7
7
import { PlaceholderFinder } from './placeholder-finder' ;
8
8
import { DesignerState } from '../designer-state' ;
9
9
import { StateModifier } from '../modifier/state-modifier' ;
10
10
import { WorkspaceController } from '../workspace/workspace-controller' ;
11
11
import { StepComponent } from '../workspace/step-component' ;
12
+ import { PlaceholderController } from '../designer-extension' ;
12
13
13
14
export class DragStepBehavior implements Behavior {
14
15
public static create ( designerContext : DesignerContext , step : Step , draggedStepComponent ?: StepComponent ) : DragStepBehavior {
15
16
const view = DragStepView . create ( step , designerContext . theme , designerContext . componentContext ) ;
16
17
return new DragStepBehavior (
17
18
view ,
18
19
designerContext . workspaceController ,
20
+ designerContext . placeholderController ,
19
21
designerContext . state ,
20
22
step ,
21
23
designerContext . stateModifier ,
@@ -27,12 +29,13 @@ export class DragStepBehavior implements Behavior {
27
29
finder : PlaceholderFinder ;
28
30
startPosition : Vector ;
29
31
offset : Vector ;
30
- } ;
32
+ } & FoundPlaceholders ;
31
33
private currentPlaceholder ?: Placeholder ;
32
34
33
35
private constructor (
34
36
private readonly view : DragStepView ,
35
37
private readonly workspaceController : WorkspaceController ,
38
+ private readonly placeholderController : PlaceholderController ,
36
39
private readonly designerState : DesignerState ,
37
40
private readonly step : Step ,
38
41
private readonly stateModifier : StateModifier ,
@@ -44,6 +47,7 @@ export class DragStepBehavior implements Behavior {
44
47
45
48
if ( this . draggedStepComponent ) {
46
49
this . draggedStepComponent . setIsDisabled ( true ) ;
50
+ this . draggedStepComponent . setIsDragging ( true ) ;
47
51
48
52
const hasSameSize =
49
53
this . draggedStepComponent . view . width === this . view . component . width &&
@@ -62,12 +66,17 @@ export class DragStepBehavior implements Behavior {
62
66
this . view . setPosition ( position . subtract ( offset ) ) ;
63
67
this . designerState . setIsDragging ( true ) ;
64
68
65
- const placeholders = this . workspaceController . getPlaceholders ( ) ;
69
+ const { placeholders, components } = this . resolvePlaceholders ( this . draggedStepComponent ) ;
66
70
this . state = {
71
+ placeholders,
72
+ components,
67
73
startPosition : position ,
68
74
finder : PlaceholderFinder . create ( placeholders , this . designerState ) ,
69
75
offset
70
76
} ;
77
+
78
+ placeholders . forEach ( placeholder => placeholder . setIsVisible ( true ) ) ;
79
+ components . forEach ( component => component . setIsDragging ( true ) ) ;
71
80
}
72
81
73
82
public onMove ( delta : Vector ) {
@@ -94,6 +103,8 @@ export class DragStepBehavior implements Behavior {
94
103
throw new Error ( 'Invalid state' ) ;
95
104
}
96
105
106
+ this . state . placeholders . forEach ( placeholder => placeholder . setIsVisible ( false ) ) ;
107
+ this . state . components . forEach ( component => component . setIsDragging ( false ) ) ;
97
108
this . state . finder . destroy ( ) ;
98
109
this . state = undefined ;
99
110
@@ -117,11 +128,23 @@ export class DragStepBehavior implements Behavior {
117
128
if ( ! modified ) {
118
129
if ( this . draggedStepComponent ) {
119
130
this . draggedStepComponent . setIsDisabled ( false ) ;
131
+ this . draggedStepComponent . setIsDragging ( false ) ;
120
132
}
121
133
if ( this . currentPlaceholder ) {
122
134
this . currentPlaceholder . setIsHover ( false ) ;
123
135
}
124
136
}
125
137
this . currentPlaceholder = undefined ;
126
138
}
139
+
140
+ private resolvePlaceholders ( skipComponent : StepComponent | undefined ) : FoundPlaceholders {
141
+ const result = this . workspaceController . resolvePlaceholders ( skipComponent ) ;
142
+ if ( this . placeholderController . canShow ) {
143
+ const canShow = this . placeholderController . canShow ;
144
+ result . placeholders = result . placeholders . filter ( placeholder =>
145
+ canShow ( placeholder . parentSequence , placeholder . index , this . step . componentType , this . step . type )
146
+ ) ;
147
+ }
148
+ return result ;
149
+ }
127
150
}
0 commit comments