Skip to content

Commit 9bc4512

Browse files
authored
Merge pull request #2545 from adumesny/master
more responsive tweaks.
2 parents 1590251 + a2c136e commit 9bc4512

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ Possible break:
453453
454454
## Migrating to v10
455455
456-
we now support much richer responsive behavior with `GridStackOptions.responsive` including any breakpoint width:column pairs, or automatic column sizing.
456+
we now support much richer responsive behavior with `GridStackOptions.columnOpts` including any breakpoint width:column pairs, or automatic column sizing.
457457
458458
breaking change:
459459
* `disableOneColumnMode`, `oneColumnSize` have been removed (thought we temporary convert if you have them). use `{ responsive: breakpoints: [{w:768, c:1}] }` for the same behavior.

demo/responsive.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
<body>
1111
<div>
1212
<h1>Responsive: by column size</h1>
13-
<p>Using new v10 <code>GridStackOptions.responsive: { columnWidth: x }</code></p>
13+
<p>Using new v10 <code>GridStackOptions.columnOpts: { columnWidth: x }</code></p>
1414

1515
<div>
1616
<span>Number of Columns:</span> <span id="column-text"></span>
1717
</div>
1818
<div>
1919
<label>Choose re-layout:</label>
20-
<select onchange="grid.opts.responsive.layout = this.value">
20+
<select onchange="grid.opts.columnOpts.layout = this.value">
2121
<option value="moveScale">move + scale</option>
2222
<option value="move">move</option>
2323
<option value="scale">scale</option>
@@ -54,7 +54,7 @@ <h1>Responsive: by column size</h1>
5454
let grid = GridStack.init({
5555
cellHeight: 80, // use 'auto' to make square
5656
animate: false, // show immediate (animate: true is nice for user dragging though)
57-
responsive: {
57+
columnOpts: {
5858
columnWidth: 100, // wanted width
5959
},
6060
children: items,

demo/responsive_break.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
<body>
1111
<div>
1212
<h1>Responsive: using breakpoint</h1>
13-
<p>Using new v10 <code>GridStackOptions.responsive: { breakpoints: [] }</code></p>
13+
<p>Using new v10 <code>GridStackOptions.columnOpts: { breakpoints: [] }</code></p>
1414
<div>
1515
<span>Number of Columns:</span> <span id="column-text"></span>
1616
</div>
1717
<div>
1818
<label>Choose re-layout:</label>
19-
<select onchange="grid.opts.responsive.layout = this.value">
19+
<select onchange="grid.opts.columnOpts.layout = this.value">
2020
<option value="moveScale">move + scale</option>
2121
<option value="move">move</option>
2222
<option value="scale">scale</option>
@@ -53,7 +53,7 @@ <h1>Responsive: using breakpoint</h1>
5353
let grid = GridStack.init({
5454
cellHeight: 80,
5555
animate: false, // show immediate (animate: true is nice for user dragging though)
56-
responsive: {
56+
columnOpts: {
5757
breakpointForWindow: true, // test window vs grid size
5858
breakpoints: [{w:700, c:1},{w:850, c:3},{w:950, c:6},{w:1100, c:8}]
5959
},

doc/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Change log
106106
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
107107

108108
## 10.0.0 (TBD)
109-
* feat [#2542](https://github.com/gridstack/gridstack.js/pull/2542) we now support much richer responsive behavior with `GridStackOptions.responsive` including any breakpoint width:column pairs, or automatic column sizing.
109+
* feat [#2542](https://github.com/gridstack/gridstack.js/pull/2542) we now support much richer responsive behavior with `GridStackOptions.columnOpts` including any breakpoint width:column pairs, or automatic column sizing.
110110
* `disableOneColumnMode`, `oneColumnSize`, `oneColumnModeDomSort` have been removed (see v10 migration doc)
111111

112112
## 9.5.1 (2023-11-11)

doc/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ gridstack.js API
77

88
- [Grid Options](#grid-options)
99
- [Responsive](#responsive)
10-
- [ResponsiveBreakpoint](#responsivebreakpoint)
10+
- [Breakpoint](#breakpoint)
1111
- [DDDragOpt](#dddragopt)
1212
- [DDDragInOpt extends DDDragOpt](#dddraginopt-extends-dddragopt)
1313
- [Grid attributes](#grid-attributes)
@@ -95,6 +95,7 @@ gridstack.js API
9595
* A value of 0 will make it instant at a cost of re-creating the CSS file at ever window resize event!
9696
- `children`?: GridStackWidget[] - list of children item to create when calling load() or addGrid()
9797
- `column` - Integer > 0 (default 12) which can change on the fly with `column(N)` API, or `'auto'` for nested grids to size themselves to the parent grid container (to make sub-items are the same size). See [column](http://gridstackjs.com/demo/column.html) and [nested](http://gridstackjs.com/demo/nested.html)
98+
- `columnOpts`?:Responsive - describes the responsive nature of the column grid. see `Responsive` interface.
9899
- `class`?: string - additional class on top of '.grid-stack' (which is required for our CSS) to differentiate this instance
99100
- `disableDrag` - disallows dragging of widgets (default: `false`).
100101
- `disableResize` - disallows resizing of widgets (default: `false`).
@@ -122,7 +123,6 @@ GridStack will add it to the `<style>` elements it creates.
122123
- `resizable` - allows to override resizable options. (default: `{handles: 'se'}`). `handles` can be any combo of `n,ne,e,se,s,sw,w,nw` or `all`.
123124
- `removable` - if `true` widgets could be removed by dragging outside of the grid. It could also be a selector string, in this case widgets will be removed by dropping them there (default: `false`) See [example](http://gridstackjs.com/demo/two.html)
124125
- `removeTimeout` - time in milliseconds before widget is being removed while dragging outside of the grid. (default: `2000`)
125-
- `responsive` - describes the responsive nature of the grid. see `Responsive` interface.
126126
- `row` - fix grid number of rows. This is a shortcut of writing `minRow:N, maxRow:N`. (default `0` no constrain)
127127
- `rtl` - if `true` turns grid to RTL. Possible values are `true`, `false`, `'auto'` (default: `'auto'`) See [example](https://gridstackjs.com/demo/right-to-left(rtl).html)
128128
- `staticGrid` - removes drag|drop|resize (default `false`). If `true` widgets are not movable/resizable by the user, but code can still move and oneColumnMode will still work. You can use the smaller gridstack-static.js lib. A CSS class `grid-stack-static` is also added to the container.
@@ -134,9 +134,9 @@ v10.x supports a much richer responsive behavior, you can have breakpoints of wi
134134
- `columnMax`?: number - maximum number of columns allowed (default: 12). Note: make sure to have correct CSS to support this.
135135
- `layout`?: ColumnOptions - global re-layout mode when changing columns
136136
- `breakpointForWindow`?: boolean - specify if breakpoints are for window size or grid size (default:false = grid)
137-
- `breakpoints`?: ResponsiveBreakpoint[] - explicit width:column breakpoints instead of automatic 'columnWidth'. Note: make sure to have correct CSS to support this.
137+
- `breakpoints`?: Breakpoint[] - explicit width:column breakpoints instead of automatic 'columnWidth'. Note: make sure to have correct CSS to support this.
138138

139-
#### ResponsiveBreakpoint
139+
#### Breakpoint
140140
- `w`?: number - width
141141
- `c`: number - column
142142
- `layout`?: ColumnOptions - re-layout mode if different from global one

src/gridstack.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,19 @@ export class GridStack {
289289
if (opts.alwaysShowResizeHandle !== undefined) {
290290
(opts as InternalGridStackOptions)._alwaysShowResizeHandle = opts.alwaysShowResizeHandle;
291291
}
292-
let bk = opts.responsive?.breakpoints;
292+
let bk = opts.columnOpts?.breakpoints;
293293
// LEGACY: oneColumnMode stuff changed in v10.x - check if user explicitly set something to convert over
294294
const oldOpts: OldOneColumnOpts = opts;
295295
if (oldOpts.oneColumnModeDomSort) {
296296
delete oldOpts.oneColumnModeDomSort;
297-
console.log('Error: Gridstack oneColumnModeDomSort no longer supported. Check GridStackOptions.responsive instead.')
297+
console.log('Error: Gridstack oneColumnModeDomSort no longer supported. Check GridStackOptions.columnOpts instead.')
298298
}
299299
if (oldOpts.oneColumnSize || oldOpts.disableOneColumnMode === false) {
300300
const oneSize = oldOpts.oneColumnSize || 768;
301301
delete oldOpts.oneColumnSize;
302302
delete oldOpts.disableOneColumnMode;
303-
opts.responsive = opts.responsive || {};
304-
bk = opts.responsive.breakpoints = opts.responsive.breakpoints || [];
303+
opts.columnOpts = opts.columnOpts || {};
304+
bk = opts.columnOpts.breakpoints = opts.columnOpts.breakpoints || [];
305305
let oneColumn = bk.find(b => b.c === 1);
306306
if (!oneColumn) {
307307
oneColumn = {c: 1, w: oneSize};
@@ -310,10 +310,10 @@ export class GridStack {
310310
}
311311
//...end LEGACY
312312
// cleanup responsive opts (must have columnWidth | breakpoints) then sort breakpoints by size (so we can match during resize)
313-
const resp = opts.responsive;
313+
const resp = opts.columnOpts;
314314
if (resp) {
315315
if (!resp.columnWidth && !resp.breakpoints?.length) {
316-
delete opts.responsive;
316+
delete opts.columnOpts;
317317
bk = undefined;
318318
} else {
319319
resp.columnMax = resp.columnMax || 12;
@@ -534,7 +534,7 @@ export class GridStack {
534534
if (ops.column === 'auto') {
535535
autoColumn = true;
536536
ops.column = Math.max(node.w || 1, nodeToAdd?.w || 1);
537-
delete ops.responsive; // driven by parent
537+
delete ops.columnOpts; // driven by parent
538538
}
539539

540540
// if we're converting an existing full item, move over the content to be the first sub item in the new grid
@@ -871,11 +871,11 @@ export class GridStack {
871871
protected _widthOrContainer(forBreakpoint = false): number {
872872
// use `offsetWidth` or `clientWidth` (no scrollbar) ?
873873
// https://stackoverflow.com/questions/21064101/understanding-offsetwidth-clientwidth-scrollwidth-and-height-respectively
874-
return forBreakpoint && this.opts.responsive?.breakpointForWindow ? window.innerWidth : (this.el.clientWidth || this.el.parentElement.clientWidth || window.innerWidth);
874+
return forBreakpoint && this.opts.columnOpts?.breakpointForWindow ? window.innerWidth : (this.el.clientWidth || this.el.parentElement.clientWidth || window.innerWidth);
875875
}
876876
/** checks for dynamic column count for our current size, returning true if changed */
877877
protected checkDynamicColumn(): boolean {
878-
const resp = this.opts.responsive;
878+
const resp = this.opts.columnOpts;
879879
if (!resp || (!resp.columnWidth && !resp.breakpoints?.length)) return false;
880880
const column = this.getColumn();
881881
let newColumn = column;
@@ -932,7 +932,7 @@ export class GridStack {
932932
this.el.classList.add('gs-' + column);
933933

934934
// update the items now, checking if we have a custom children layout
935-
/*const newChildren = this.opts.responsive?.breakpoints?.find(r => r.c === column)?.children;
935+
/*const newChildren = this.opts.columnOpts?.breakpoints?.find(r => r.c === column)?.children;
936936
if (newChildren) this.load(newChildren);
937937
else*/ this.engine.columnChanged(oldColumn, column, undefined, layout);
938938
if (this._isAutoCellHeight) this.cellHeight();
@@ -1761,7 +1761,7 @@ export class GridStack {
17611761
protected _updateResizeEvent(forceRemove = false): GridStack {
17621762
// only add event if we're not nested (parent will call us) and we're auto sizing cells or supporting dynamic column (i.e. doing work)
17631763
// or supporting new sizeToContent option.
1764-
const trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.sizeToContent || this.opts.responsive
1764+
const trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.sizeToContent || this.opts.columnOpts
17651765
|| this.engine.nodes.find(n => n.sizeToContent));
17661766

17671767
if (!forceRemove && trackSize && !this.resizeObserver) {

src/types.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,20 @@ export type ResizeToContentFcn = (el: GridItemHTMLElement, useAttr?: boolean) =>
8989
export interface Responsive {
9090
/** wanted width to maintain (+-50%) to dynamically pick a column count */
9191
columnWidth?: number;
92-
/** maximum number of columns allowed (default: 12). Note: make sure to have correct CSS to support this.*/
92+
/** maximum number of columns allowed (default: 12). Note: make sure to have correct extra CSS to support this.*/
9393
columnMax?: number;
9494
/** global re-layout mode when changing columns */
9595
layout?: ColumnOptions;
9696
/** specify if breakpoints are for window size or grid size (default:false = grid) */
9797
breakpointForWindow?: boolean;
98-
/** explicit width:column breakpoints instead of automatic 'columnWidth'. Note: make sure to have correct CSS to support this.*/
99-
breakpoints?: ResponsiveBreakpoint[];
98+
/** explicit width:column breakpoints instead of automatic 'columnWidth'. Note: make sure to have correct extra CSS to support this.*/
99+
breakpoints?: Breakpoint[];
100100
}
101101

102-
export interface ResponsiveBreakpoint {
103-
/** width */
102+
export interface Breakpoint {
103+
/** <= width for the breakpoint to trigger */
104104
w?: number;
105-
/** column */
105+
/** column count */
106106
c: number;
107107
/** re-layout mode if different from global one */
108108
layout?: ColumnOptions;
@@ -162,6 +162,9 @@ export interface GridStackOptions {
162162
*/
163163
column?: number | 'auto';
164164

165+
/** responsive column layout for width:column behavior */
166+
columnOpts?: Responsive;
167+
165168
/** additional class on top of '.grid-stack' (which is required for our CSS) to differentiate this instance.
166169
Note: only used by addGrid(), else your element should have the needed class */
167170
class?: string;
@@ -232,9 +235,6 @@ export interface GridStackOptions {
232235
/** allows to override UI resizable options. (default?: { handles: 'se' }) */
233236
resizable?: DDResizeOpt;
234237

235-
/** responsive layout for width->column behavior */
236-
responsive?: Responsive;
237-
238238
/**
239239
* if true widgets could be removed by dragging outside of the grid. It could also be a selector string (ex: ".trash"),
240240
* in this case widgets will be removed by dropping them there (default?: false)

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ module.exports = {
55
'gridstack-all': './src/gridstack.ts',
66
},
77
mode: 'production', // production vs development
8-
devtool: 'source-map',
9-
// devtool: 'eval-source-map', // for best (large .js) debugging. see https://survivejs.com/webpack/building/source-maps/
8+
// devtool: 'source-map',
9+
devtool: 'eval-source-map', // for best (large .js) debugging. see https://survivejs.com/webpack/building/source-maps/
1010
module: {
1111
rules: [
1212
{

0 commit comments

Comments
 (0)