@@ -8,6 +8,7 @@ import { GridItemHTMLElement, GridStackElement, DDDragOpt } from './types';
88import { Utils } from './utils' ;
99import { DDManager } from './dd-manager' ;
1010import { DDElement , DDElementHost } from './dd-element' ;
11+ import { GridHTMLElement } from './gridstack' ;
1112
1213/** Drag&Drop drop options */
1314export type DDDropOpt = {
@@ -32,7 +33,7 @@ export type DDCallback = (event: Event, arg2: GridItemHTMLElement, helper?: Grid
3233export class DDGridStack {
3334
3435 public resizable ( el : GridItemHTMLElement , opts : DDOpts , key ?: DDKey , value ?: DDValue ) : DDGridStack {
35- this . _getDDElements ( el ) . forEach ( dEl => {
36+ this . _getDDElements ( el , opts ) . forEach ( dEl => {
3637 if ( opts === 'disable' || opts === 'enable' ) {
3738 dEl . ddResizable && dEl . ddResizable [ opts ] ( ) ; // can't create DD as it requires options for setupResizable()
3839 } else if ( opts === 'destroy' ) {
@@ -67,7 +68,7 @@ export class DDGridStack {
6768 }
6869
6970 public draggable ( el : GridItemHTMLElement , opts : DDOpts , key ?: DDKey , value ?: DDValue ) : DDGridStack {
70- this . _getDDElements ( el ) . forEach ( dEl => {
71+ this . _getDDElements ( el , opts ) . forEach ( dEl => {
7172 if ( opts === 'disable' || opts === 'enable' ) {
7273 dEl . ddDraggable && dEl . ddDraggable [ opts ] ( ) ; // can't create DD as it requires options for setupDraggable()
7374 } else if ( opts === 'destroy' ) {
@@ -100,13 +101,11 @@ export class DDGridStack {
100101 opts . _accept = opts . accept ;
101102 opts . accept = ( el ) => opts . _accept ( el ) ;
102103 }
103- this . _getDDElements ( el ) . forEach ( dEl => {
104+ this . _getDDElements ( el , opts ) . forEach ( dEl => {
104105 if ( opts === 'disable' || opts === 'enable' ) {
105106 dEl . ddDroppable && dEl . ddDroppable [ opts ] ( ) ;
106107 } else if ( opts === 'destroy' ) {
107- if ( dEl . ddDroppable ) { // error to call destroy if not there
108- dEl . cleanDroppable ( ) ;
109- }
108+ dEl . ddDroppable && dEl . cleanDroppable ( ) ;
110109 } else if ( opts === 'option' ) {
111110 dEl . setupDroppable ( { [ key ] : value } ) ;
112111 } else {
@@ -148,12 +147,13 @@ export class DDGridStack {
148147 return this ;
149148 }
150149
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' ;
153154 const hosts = Utils . getElements ( els ) as DDElementHost [ ] ;
154155 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
157157 return list ;
158158 }
159159}
0 commit comments