@@ -11,6 +11,8 @@ export interface DirectionControlInfo {
11
11
classNames : string [ ] ;
12
12
dir : string ;
13
13
}
14
+
15
+
14
16
export function renderDirectionControlsByInfos (
15
17
moveable : MoveableManagerInterface < Partial < RenderDirections > > ,
16
18
ableName : string ,
@@ -74,61 +76,29 @@ export function renderDirectionControls(
74
76
) : any [ ] {
75
77
const {
76
78
renderDirections : directions = defaultDirections ,
79
+ displayAroundControls,
77
80
} = getProps ( moveable . props , ableName as any ) ;
78
81
79
82
if ( ! directions ) {
80
83
return [ ] ;
81
84
}
82
85
const renderDirections = directions === true ? DIRECTIONS : directions ;
83
86
84
- return renderDirectionControlsByInfos (
85
- moveable ,
86
- ableName ,
87
- renderDirections . map ( dir => {
88
- return {
89
- data : { } ,
90
- classNames : [ ] ,
91
- dir,
92
- } ;
93
- } ) ,
94
- React ,
95
- ) ;
96
- }
97
- export function renderAroundControls (
98
- moveable : MoveableManagerInterface < Partial < RenderDirections > > ,
99
- React : Renderer ,
100
- ) : any [ ] {
101
- const renderState = moveable . renderState ;
102
- if ( ! renderState . renderDirectionMap ) {
103
- renderState . renderDirectionMap = { } ;
104
- }
105
- const {
106
- renderPoses,
107
- rotation : rotationRad ,
108
- direction,
109
- } = moveable . getState ( ) ;
110
-
111
- const renderDirectionMap = renderState . renderDirectionMap ;
112
-
113
- const {
114
- zoom,
115
- } = moveable . props ;
116
- const sign = ( direction > 0 ? 1 : - 1 ) ;
117
- const degRotation = rotationRad / Math . PI * 180 ;
118
-
119
- return getKeys ( renderDirectionMap ) . map ( dir => {
120
- const indexes = DIRECTION_INDEXES [ dir ] ;
121
-
122
- if ( ! indexes ) {
123
- return null ;
124
- }
125
- const directionRotation = ( throttle ( degRotation , 15 ) + sign * DIRECTION_ROTATIONS [ dir ] + 720 ) % 180 ;
126
-
127
- return (
128
- < div className = { prefix ( "around-control" ) } data-rotation = { directionRotation } data-direction = { dir } key = { `direction-around-${ dir } ` }
129
- style = { getControlTransform ( rotationRad , zoom ! , ...indexes . map ( index => renderPoses [ index ] ) ) } > </ div >
130
- ) ;
131
- } ) ;
87
+ return [
88
+ ...( displayAroundControls ? renderAroundControls ( moveable , React , ableName , renderDirections ) : [ ] ) ,
89
+ ...renderDirectionControlsByInfos (
90
+ moveable ,
91
+ ableName ,
92
+ renderDirections . map ( dir => {
93
+ return {
94
+ data : { } ,
95
+ classNames : [ ] ,
96
+ dir,
97
+ } ;
98
+ } ) ,
99
+ React ,
100
+ ) ,
101
+ ] ;
132
102
}
133
103
134
104
export function renderLine (
@@ -168,6 +138,7 @@ export function renderEdgeLines(
168
138
return renderLine ( React , direction , poses [ index1 ] , poses [ index2 ] , zoom , `${ ableName } Edge${ i } ` , ableName ) ;
169
139
} ) . filter ( Boolean ) ;
170
140
}
141
+
171
142
export function getRenderDirections ( ableName : string ) {
172
143
return (
173
144
moveable : MoveableManagerInterface < Partial < RenderDirections > > ,
@@ -190,17 +161,65 @@ export function getRenderDirections(ableName: string) {
190
161
return renderAllDirections ( moveable , ableName , React ) ;
191
162
} ;
192
163
}
164
+
193
165
export function renderAllDirections (
194
166
moveable : MoveableManagerInterface < Partial < RenderDirections > > ,
195
167
ableName : string ,
196
168
React : Renderer ,
197
169
) {
198
170
return renderDirectionControls ( moveable , DIRECTIONS , ableName , React ) ;
199
171
}
172
+
200
173
export function renderDiagonalDirections (
201
174
moveable : MoveableManagerInterface < Partial < RenderDirections > > ,
202
175
ableName : string ,
203
176
React : Renderer ,
204
177
) : any [ ] {
205
178
return renderDirectionControls ( moveable , [ "nw" , "ne" , "sw" , "se" ] , ableName , React ) ;
206
179
}
180
+
181
+ export function renderAroundControls (
182
+ moveable : MoveableManagerInterface < Partial < RenderDirections > > ,
183
+ React : Renderer ,
184
+ ableName ?: string ,
185
+ renderDirections ?: string [ ] ,
186
+ ) : any [ ] {
187
+ const renderState = moveable . renderState ;
188
+ if ( ! renderState . renderDirectionMap ) {
189
+ renderState . renderDirectionMap = { } ;
190
+ }
191
+ const {
192
+ renderPoses,
193
+ rotation : rotationRad ,
194
+ direction,
195
+ } = moveable . getState ( ) ;
196
+
197
+ const renderDirectionMap = renderState . renderDirectionMap ;
198
+
199
+ const {
200
+ zoom,
201
+ } = moveable . props ;
202
+ const sign = ( direction > 0 ? 1 : - 1 ) ;
203
+ const degRotation = rotationRad / Math . PI * 180 ;
204
+
205
+ return ( renderDirections || getKeys ( renderDirectionMap ) ) . map ( dir => {
206
+ const indexes = DIRECTION_INDEXES [ dir ] ;
207
+
208
+ if ( ! indexes ) {
209
+ return null ;
210
+ }
211
+ const directionRotation = ( throttle ( degRotation , 15 ) + sign * DIRECTION_ROTATIONS [ dir ] + 720 ) % 180 ;
212
+
213
+ const classNames : string [ ] = [ "around-control" ] ;
214
+
215
+ if ( ableName ) {
216
+ classNames . push ( "direction" , ableName ) ;
217
+ }
218
+ return (
219
+ < div
220
+ className = { prefix ( ...classNames ) }
221
+ data-rotation = { directionRotation } data-direction = { dir } key = { `direction-around-${ dir } ` }
222
+ style = { getControlTransform ( rotationRad , zoom ! , ...indexes . map ( index => renderPoses [ index ] ) ) } > </ div >
223
+ ) ;
224
+ } ) ;
225
+ }
0 commit comments