44 */
55
66import { isTouch , pointerdown , touchend , touchmove , touchstart } from './dd-touch' ;
7- import { GridItemHTMLElement } from './gridstack' ;
7+ import { DDResizableOpt , GridItemHTMLElement } from './gridstack' ;
88
9- export interface DDResizableHandleOpt {
9+ export interface DDResizableHandleOpt extends DDResizableOpt {
1010 start ?: ( event ) => void ;
1111 move ?: ( event ) => void ;
1212 stop ?: ( event ) => void ;
@@ -34,18 +34,34 @@ export class DDResizableHandle {
3434
3535 /** @internal */
3636 protected _init ( ) : DDResizableHandle {
37- const el = this . el = document . createElement ( 'div' ) ;
38- el . classList . add ( 'ui-resizable-handle' ) ;
39- el . classList . add ( `${ DDResizableHandle . prefix } ${ this . dir } ` ) ;
40- el . style . zIndex = '100' ;
41- el . style . userSelect = 'none' ;
42- this . host . appendChild ( this . el ) ;
37+ if ( this . option . element ) {
38+ try {
39+ this . el = this . option . element instanceof HTMLElement
40+ ? this . option . element
41+ : this . host . querySelector ( this . option . element )
42+ } catch ( error ) {
43+ this . option . element = undefined // make sure destroy handles it correctly
44+ console . error ( "Query for resizeable handle failed, falling back" , error )
45+ }
46+ }
47+
48+ if ( ! this . el ) {
49+ this . el = document . createElement ( 'div' ) ;
50+ this . host . appendChild ( this . el ) ;
51+ }
52+
53+ this . el . classList . add ( 'ui-resizable-handle' ) ;
54+ this . el . classList . add ( `${ DDResizableHandle . prefix } ${ this . dir } ` ) ;
55+ this . el . style . zIndex = '100' ;
56+ this . el . style . userSelect = 'none' ;
57+
4358 this . el . addEventListener ( 'mousedown' , this . _mouseDown ) ;
4459 if ( isTouch ) {
4560 this . el . addEventListener ( 'touchstart' , touchstart ) ;
4661 this . el . addEventListener ( 'pointerdown' , pointerdown ) ;
4762 // this.el.style.touchAction = 'none'; // not needed unlike pointerdown doc comment
4863 }
64+
4965 return this ;
5066 }
5167
@@ -57,7 +73,9 @@ export class DDResizableHandle {
5773 this . el . removeEventListener ( 'touchstart' , touchstart ) ;
5874 this . el . removeEventListener ( 'pointerdown' , pointerdown ) ;
5975 }
60- this . host . removeChild ( this . el ) ;
76+ if ( ! this . option . element ) {
77+ this . host . removeChild ( this . el ) ;
78+ }
6179 delete this . el ;
6280 delete this . host ;
6381 return this ;
0 commit comments