Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2e65b0

Browse files
committed
new public prepareDragDrop(el)
* internal `_prepareDragDropByNode(n)` is now public as `prepareDragDrop(el)` so Angular, React, and others can call once the DOM content elements have been added (the outside griditem divs are always created for content)
1 parent 21ff397 commit a2e65b0

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Change log
127127
* fix: [#2955](https://github.com/gridstack/gridstack.js/issues/2955) angular circular dependency
128128
* fix: [#2951](https://github.com/gridstack/gridstack.js/issues/2951) shadow DOM dragging re-appending fix
129129
* fix: [#2964](https://github.com/gridstack/gridstack.js/pull/2964) minW larger than column fix
130+
* feat: [#2965](https://github.com/gridstack/gridstack.js/pull/2965) internal `_prepareDragDropByNode(n)` is now public as `prepareDragDrop(el)` so Angular, React, and others can call once the DOM content elements have been added (the outside griditem divs are always created for content)
130131

131132
## 11.3.0 (2025-01-26)
132133
* feat: added `isIgnoreChangeCB()` if changeCB should be ignored due to column change, sizeToContent, loading, etc...

src/gridstack.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ export class GridStack {
551551
newItem.appendChild(content);
552552
content = Utils.createDiv(['grid-stack-item-content'], node.el);
553553
}
554-
this._prepareDragDropByNode(node); // ... and restore original D&D
554+
this.prepareDragDrop(node.el); // ... and restore original D&D
555555
}
556556

557557
// if we're adding an additional item, make the container large enough to have them both
@@ -1278,7 +1278,7 @@ export class GridStack {
12781278
this._setupRemoveDrop();
12791279
this._setupAcceptWidget();
12801280
this.engine.nodes.forEach(n => {
1281-
this._prepareDragDropByNode(n); // either delete or init Drag&drop
1281+
this.prepareDragDrop(n.el); // either delete or init Drag&drop
12821282
if (n.subGrid && recurse) n.subGrid.setStatic(val, updateClass, recurse);
12831283
});
12841284
if (updateClass) { this._setStaticClass(); }
@@ -1367,7 +1367,7 @@ export class GridStack {
13671367
this._writeAttr(el, n);
13681368
}
13691369
if (ddChanged) {
1370-
this._prepareDragDropByNode(n);
1370+
this.prepareDragDrop(n.el);
13711371
}
13721372
});
13731373

@@ -1697,7 +1697,7 @@ export class GridStack {
16971697
sizeToContent ? el.classList.add('size-to-content') : el.classList.remove('size-to-content');
16981698
if (sizeToContent) this.resizeToContentCheck(false, node);
16991699

1700-
if (!Utils.lazyLoad(node)) this._prepareDragDropByNode(node);
1700+
if (!Utils.lazyLoad(node)) this.prepareDragDrop(node.el);
17011701

17021702
return this;
17031703
}
@@ -1994,7 +1994,7 @@ export class GridStack {
19941994
const n = el.gridstackNode;
19951995
if (!n) return;
19961996
val ? delete n.noMove : n.noMove = true;
1997-
this._prepareDragDropByNode(n); // init DD if need be, and adjust
1997+
this.prepareDragDrop(n.el); // init DD if need be, and adjust
19981998
});
19991999
return this;
20002000
}
@@ -2010,7 +2010,7 @@ export class GridStack {
20102010
const n = el.gridstackNode;
20112011
if (!n) return;
20122012
val ? delete n.noResize : n.noResize = true;
2013-
this._prepareDragDropByNode(n); // init DD if need be, and adjust
2013+
this.prepareDragDrop(n.el); // init DD if need be, and adjust
20142014
});
20152015
return this;
20162016
}
@@ -2057,7 +2057,7 @@ export class GridStack {
20572057
if (this.opts.staticGrid) return this; // can't move a static grid!
20582058
doEnable ? delete this.opts.disableDrag : this.opts.disableDrag = true; // FIRST before we update children as grid overrides #1658
20592059
this.engine.nodes.forEach(n => {
2060-
this._prepareDragDropByNode(n);
2060+
this.prepareDragDrop(n.el);
20612061
if (n.subGrid && recurse) n.subGrid.enableMove(doEnable, recurse);
20622062
});
20632063
return this;
@@ -2071,7 +2071,7 @@ export class GridStack {
20712071
if (this.opts.staticGrid) return this; // can't size a static grid!
20722072
doEnable ? delete this.opts.disableResize : this.opts.disableResize = true; // FIRST before we update children as grid overrides #1658
20732073
this.engine.nodes.forEach(n => {
2074-
this._prepareDragDropByNode(n);
2074+
this.prepareDragDrop(n.el);
20752075
if (n.subGrid && recurse) n.subGrid.enableResize(doEnable, recurse);
20762076
});
20772077
return this;
@@ -2399,9 +2399,9 @@ export class GridStack {
23992399
return this;
24002400
}
24012401

2402-
/** @internal prepares the element for drag&drop */
2403-
protected _prepareDragDropByNode(node: GridStackNode): GridStack {
2404-
const el = node.el;
2402+
/** prepares the element for drag&drop - this is normally called by makeWiget() unless are are delay loading */
2403+
public prepareDragDrop(el: GridItemHTMLElement): GridStack {
2404+
const node = el.gridstackNode;
24052405
const noMove = node.noMove || this.opts.disableDrag;
24062406
const noResize = node.noResize || this.opts.disableResize;
24072407

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export interface GridStackOptions {
153153

154154
/** number of columns (default?: 12). Note: IF you change this, CSS also have to change. See https://github.com/gridstack/gridstack.js#change-grid-columns.
155155
* Note: for nested grids, it is recommended to use 'auto' which will always match the container grid-item current width (in column) to keep inside and outside
156-
* items always to same. flag is not supported for regular non-nested grids.
156+
* items always the same. flag is NOT supported for regular non-nested grids.
157157
*/
158158
column?: number | 'auto';
159159

src/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ export class Utils {
126126
n.visibleObservable?.disconnect();
127127
delete n.visibleObservable;
128128
GridStack.renderCB(cont, n);
129-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
130-
(n.grid as any)?._prepareDragDropByNode(n); // access protected method. TODO: do we expose that for React to call too (after dom is ready)
129+
n.grid?.prepareDragDrop(n.el);
131130
}});
132131
window.setTimeout(() => n.visibleObservable?.observe(el)); // wait until callee sets position attributes
133132
}

0 commit comments

Comments
 (0)