@@ -8,6 +8,7 @@ import { GridItemHTMLElement, GridStackElement, DDDragOpt } from './types';
8
8
import { Utils } from './utils' ;
9
9
import { DDManager } from './dd-manager' ;
10
10
import { DDElement , DDElementHost } from './dd-element' ;
11
+ import { GridHTMLElement } from './gridstack' ;
8000
11
12
12
13
/** Drag&Drop drop options */
13
14
export type DDDropOpt = {
@@ -32,7 +33,7 @@ export type DDCallback = (event: Event, arg2: GridItemHTMLElement, helper?: Grid
32
33
export class DDGridStack {
33
34
34
35
public resizable ( el : GridItemHTMLElement , opts : DDOpts , key ?: DDKey , value ?: DDValue ) : DDGridStack {
35
- this . _getDDElements ( el ) . forEach ( dEl => {
36
+ this . _getDDElements ( el , opts ) . forEach ( dEl => {
36
37
if ( opts === 'disable' || opts === 'enable' ) {
37
38
dEl . ddResizable && dEl . ddResizable [ opts ] ( ) ; // can't create DD as it requires options for setupResizable()
38
39
} else if ( opts === 'destroy' ) {
@@ -67,7 +68,7 @@ export class DDGridStack {
67
68
}
68
69
69
70
public draggable ( el : GridItemHTMLElement , opts : DDOpts , key ?: DDKey , value ?: DDValue ) : DDGridStack {
70
- this . _getDDElements ( el ) . forEach ( dEl => {
71
+ this . _getDDElements ( el , opts ) . forEach ( dEl => {
71
72
if ( opts === 'disable' || opts === 'enable' ) {
72
73
dEl . ddDraggable && dEl . ddDraggable [ opts ] ( ) ; // can't create DD as it requires options for setupDraggable()
73
74
} else if ( opts === 'destroy' ) {
@@ -100,13 +101,11 @@ export class DDGridStack {
100
101
opts . _accept = opts . accept ;
101
102
opts . accept = ( el ) => opts . _accept ( el ) ;
102
103
}
103
- this . _getDDElements ( el ) . forEach ( dEl => {
104
+ this . _getDDElements ( el , opts ) . forEach ( dEl => {
104
105
if ( opts === 'disable' || opts === 'enable' ) {
105
106
dEl . ddDroppable && dEl . ddDroppable [ opts ] ( ) ;
106
107
} else if ( opts === 'destroy' ) {
107
- if ( dEl . ddDroppable ) { // error to call destroy if not there
108
- dEl . cleanDroppable ( ) ;
109
- }
108
+ dEl . ddDroppable && dEl . cleanDroppable ( ) ;
110
109
} else if ( opts === 'option' ) {
111
110
dEl . setupDroppable ( { [ key ] : value } ) ;
112
111
} else {
@@ -148,12 +147,13 @@ export class DDGridStack {
148
147
return this ;
149
148
}
150
149
151
- /** @internal returns a list of DD elements, creating them on the fly by default */
152
- protected _getDDElements ( els : GridStackElement , create = true ) : DDElement [ ] {
150
+ /** @internal returns a list of DD elements, creating them on the fly by default unless option is to destroy or disable */
151
+ protected _getDDElements ( els : GridStackElement , opts ?: DDOpts ) : DDElement [ ] {
152
+ // don't force create if we're going to destroy it, unless it's a grid which is used as drop target for it's children
153
+ const create = ( els as GridHTMLElement ) . gridstack || opts !== 'destroy' && opts !== 'disable' ;
153
154
const hosts = Utils . getElements ( els ) as DDElementHost [ ] ;
154
155
if ( ! hosts . length ) return [ ] ;
155
- const list = hosts . map ( e => e . ddElement || ( create ? DDElement . init ( e ) : null ) ) ;
156
- if ( ! create ) { list . filter ( d => d ) ; } // remove nulls
156
+ const list = hosts . map ( e => e . ddElement || ( create ? DDElement . init ( e ) : null ) ) . filter ( d => d ) ; // remove nulls
157
157
return list ;
158
158
}
159
159
}
0 commit comments