Skip to content

Commit 9bc5ba4

Browse files
authored
Merge pull request #3028 from adumesny/master
`updateOptions()` no longer modifies passed in struct
2 parents f1aaa85 + 6e2e59d commit 9bc5ba4

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

doc/CHANGES.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ Change log
126126
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
127127

128128
## 12.0.0-dev (TBD)
129-
* [#3022](https://github.com/gridstack/gridstack.js/pull/3022) removed ES5 support (IE doesn't support CSS vars needed now)
130-
* [#3024](https://github.com/gridstack/gridstack.js/pull/3024) remove legacy code support for disableOneColumnMode, oneColumnSize, oneColumnModeDomSort
129+
* rem [#3022](https://github.com/gridstack/gridstack.js/pull/3022) removed ES5 support (IE doesn't support CSS vars needed now)
130+
* rem [#3027](https://github.com/gridstack/gridstack.js/pull/3027) remove legacy code support for disableOneColumnMode, oneColumnSize, oneColumnModeDomSort
131+
* fix [#3028](https://github.com/gridstack/gridstack.js/pull/3028) `updateOptions()` no longer modifies passed in struct. only field we check are being handled too.
131132

132133
## 12.0.0 (2025-04-12)
133134
* feat: [#2854](https://github.com/gridstack/gridstack.js/pull/2854) Removed dynamic stylesheet and migrated to CSS vars. Thank you [lmartorella](https://github.com/lmartorella)

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
}
2626
],
2727
"scripts": {
28-
"build": "yarn --no-progress && yarn build:ng && grunt && yarn build:es6 && yarn doc",
29-
"build:es6": "webpack && tsc --stripInternal",
28+
"build": "yarn --no-progress && yarn build:ng && grunt && webpack && tsc --stripInternal && yarn doc",
3029
"build:ng": "cd angular && yarn --no-progress && yarn build lib",
3130
"w": "webpack",
3231
"t": "rm -rf dist/* && grunt && tsc --stripInternal",

src/gridstack.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,14 @@ export class GridStack {
277277
// cleanup responsive opts (must have columnWidth | breakpoints) then sort breakpoints by size (so we can match during resize)
278278
const resp = opts.columnOpts;
279279
if (resp) {
280-
if (!resp.columnWidth && !resp.breakpoints?.length) {
280+
const bk = resp.breakpoints;
281+
if (!resp.columnWidth && !bk?.length) {
281282
delete opts.columnOpts;
282-
bk = undefined;
283283
} else {
284284
resp.columnMax = resp.columnMax || 12;
285+
if (bk?.length > 1) bk.sort((a, b) => (b.w || 0) - (a.w || 0));
285286
}
286287
}
287-
if (bk?.length > 1) bk.sort((a, b) => (b.w || 0) - (a.w || 0));
288288

289289
// elements DOM attributes override any passed options (like CSS style) - merge the two together
290290
const defaults: GridStackOptions = {
@@ -1246,6 +1246,7 @@ export class GridStack {
12461246
} else {
12471247
this.el.classList.remove('grid-stack-animate');
12481248
}
1249+
this.opts.animate = doAnimate;
12491250
return this;
12501251
}
12511252

@@ -1279,22 +1280,32 @@ export class GridStack {
12791280
*/
12801281
public updateOptions(o: GridStackOptions): GridStack {
12811282
const opts = this.opts;
1282-
if (o.acceptWidgets !== undefined) this._setupAcceptWidget();
1283-
if (o.animate !== undefined) this.setAnimation();
1284-
if (o.cellHeight) { this.cellHeight(o.cellHeight); delete o.cellHeight; }
1285-
if (o.class && o.class !== opts.class) { if (opts.class) this.el.classList.remove(opts.class); this.el.classList.add(o.class); }
1286-
if (typeof(o.column) === 'number' && !o.columnOpts) { this.column(o.column); delete o.column; }// responsive column take over actual count
1283+
if (o === opts) return this; // nothing to do
1284+
if (o.acceptWidgets !== undefined) { opts.acceptWidgets = o.acceptWidgets; this._setupAcceptWidget(); }
1285+
if (o.animate !== undefined) this.setAnimation(o.animate);
1286+
if (o.cellHeight) this.cellHeight(o.cellHeight);
1287+
if (o.class !== undefined && o.class !== opts.class) { if (opts.class) this.el.classList.remove(opts.class); if (o.class) this.el.classList.add(o.class); }
1288+
// responsive column take over actual count (keep what we have now)
1289+
if (o.columnOpts) {
1290+
this.opts.columnOpts = o.columnOpts;
1291+
this.checkDynamicColumn();
1292+
} else if (o.columnOpts === null && this.opts.columnOpts) {
1293+
delete this.opts.columnOpts;
1294+
this._updateResizeEvent();
1295+
} else if (typeof(o.column) === 'number') this.column(o.column);
12871296
if (o.margin !== undefined) this.margin(o.margin);
12881297
if (o.staticGrid !== undefined) this.setStatic(o.staticGrid);
12891298
if (o.disableDrag !== undefined && !o.staticGrid) this.enableMove(!o.disableDrag);
12901299
if (o.disableResize !== undefined && !o.staticGrid) this.enableResize(!o.disableResize);
12911300
if (o.float !== undefined) this.float(o.float);
1292-
if (o.row !== undefined) { opts.minRow = opts.maxRow = o.row; }
1293-
if (o.children?.length) { this.load(o.children); delete o.children; }
1301+
if (o.row !== undefined) { opts.minRow = opts.maxRow = opts.row = o.row; }
1302+
else {
1303+
if (opts.minRow !== undefined) opts.minRow = o.minRow;
1304+
if (opts.maxRow !== undefined) opts.maxRow = o.maxRow;
1305+
}
1306+
if (o.children?.length) this.load(o.children);
12941307
// TBD if we have a real need for these (more complex code)
12951308
// alwaysShowResizeHandle, draggable, handle, handleClass, itemClass, layout, placeholderClass, placeholderText, resizable, removable, row,...
1296-
// rest are just copied over...
1297-
this.opts = {...this.opts, ...o};
12981309
return this;
12991310
}
13001311

0 commit comments

Comments
 (0)