@@ -4,7 +4,7 @@ import { select, classNameFromVNode } from 'snabbdom-selector';
4
4
import {
5
5
SortableOptions ,
6
6
MouseOffset ,
7
- ItemDimensions ,
7
+ StartPositionOffset ,
8
8
Intersection
9
9
} from './definitions' ;
10
10
@@ -32,7 +32,8 @@ export function applyDefaults(
32
32
options . parentSelector ||
33
33
'.' + classNameFromVNode ( root ) . split ( ' ' ) . join ( '.' ) ,
34
34
handle : options . handle || itemSelector ,
35
- ghostClass : options . ghostClass || ''
35
+ ghostClass : options . ghostClass || '' ,
36
+ selectionDelay : options . selectionDelay || 0
36
37
} ;
37
38
}
38
39
@@ -124,27 +125,26 @@ export function getIndex(node: any): number {
124
125
125
126
/**
126
127
* Gets the correct style attribute value for the given parameters
127
- * @param {MouseEvent } event the mouse event that was triggered
128
+ * @param {StartPositionOffset } event the mouse event that was triggered, enriched with distance information
128
129
* @param {MouseOffset } mouseOffset the offset of the item
129
130
* @param {ClientRect } itemRect the bounding client rect of the item
130
131
* @return {string } the style value
131
132
*/
132
- export function getGhostStyle (
133
- event : MouseEvent ,
134
- mouseOffset : MouseOffset ,
135
- item : Element
136
- ) : string {
133
+ export function getGhostStyle ( mouseOffset : MouseOffset , item : Element ) : string {
137
134
const itemRect : ClientRect = item . getBoundingClientRect ( ) ;
138
135
return (
139
- 'z-index: 5; margin: 0; pointer-events: none; position: absolute; width: ' +
136
+ 'z-index: 5; margin: 0; pointer-events: none; position: absolute; ' +
137
+ 'width: ' +
140
138
itemRect . width +
141
139
'px; ' +
142
140
'height: ' +
143
141
itemRect . height +
144
- 'px; top: ' +
145
- ( event . clientY + mouseOffset . y + window . screenY ) +
146
- 'px; left: ' +
147
- ( event . clientX + mouseOffset . x + window . scrollX ) +
142
+ 'px; ' +
143
+ 'top: ' +
144
+ ( mouseOffset . itemTop - mouseOffset . parentTop ) +
145
+ 'px; ' +
146
+ 'left: ' +
147
+ ( mouseOffset . itemLeft - mouseOffset . parentLeft ) +
148
148
'px;'
149
149
) ;
150
150
}
@@ -153,7 +153,7 @@ export function getGhostStyle(
153
153
* Returns the updated style for this ghost element
154
154
*/
155
155
export function updateGhostStyle (
156
- event : MouseEvent ,
156
+ event : StartPositionOffset ,
157
157
mouseOffset : MouseOffset ,
158
158
ghost : Element
159
159
) : string {
@@ -162,9 +162,9 @@ export function updateGhostStyle(
162
162
return (
163
163
prevStyle . substring ( 0 , prevStyle . indexOf ( ' top:' ) ) +
164
164
' top: ' +
165
- ( event . clientY + mouseOffset . y + window . scrollY ) +
165
+ ( mouseOffset . itemTop - mouseOffset . parentTop + event . distY ) +
166
166
'px; left: ' +
167
- ( event . clientX + mouseOffset . x + window . scrollX ) +
167
+ ( mouseOffset . itemLeft - mouseOffset . parentLeft + event . distX ) +
168
168
'px;'
169
169
) ;
170
170
}
@@ -197,21 +197,40 @@ export function findParent(node: Element, selector: string): Element {
197
197
}
198
198
199
199
/**
200
- * Adds the given attribute savely to the VNode
200
+ * Adds the given attribute safely to the VNode
201
201
* @param {VNode } node the VNode to add the attributes on
202
202
* @param {any } addition the new attributes
203
203
* @return {VNode } the newly created VNode
204
204
*/
205
205
export function addAttributes (
206
206
e : VNode ,
207
- newAttr : { [ attr : string ] : any }
207
+ newAttr : { [ attr : string ] : any } ,
208
+ ghostClass ?: string
208
209
) : VNode {
209
210
const addition : any = {
210
211
attrs : Object . assign ( { } , e . data ? e . data . attrs : undefined , newAttr )
211
212
} ;
212
213
return addToData ( e , addition ) ;
213
214
}
214
215
216
+ /**
217
+ * Adds the given class safely to the VNode
218
+ * @param {VNode } node the VNode to add the attributes on
219
+ * @param {any } addition the css ghost class
220
+ * @return {VNode } the newly created VNode
221
+ */
222
+ export function addGhostClass ( e : VNode , ghostClass ?: string ) : VNode {
223
+ const className =
224
+ ghostClass && ghostClass . length > 1
225
+ ? ghostClass [ 0 ] === '.' ? ghostClass . substring ( 1 ) : ghostClass
226
+ : undefined ;
227
+ const classVal = className ? { [ className ] : true } : undefined ;
228
+ const addition : any = {
229
+ class : classVal
230
+ } ;
231
+ return addToData ( e , addition ) ;
232
+ }
233
+
215
234
/**
216
235
* Removes the given attribute from the VNode
217
236
* @param {VNode } node the VNode
@@ -233,7 +252,7 @@ export function removeAttribute(node: VNode, attributeName: string): VNode {
233
252
}
234
253
235
254
/**
236
- * Adds the given additions savely to the VNode
255
+ * Adds the given additions safely to the VNode
237
256
* @param {VNode } node the VNode to add the additions on
238
257
* @param {any } addition the new additions
239
258
* @return {VNode } the newly created VNode
0 commit comments