Skip to content

Commit 452854b

Browse files
committed
fitToContent -> sizeToContent rename
* better long term naming (with upcoming size number option as ell)
1 parent 5032b8f commit 452854b

File tree

8 files changed

+26
-25
lines changed

8 files changed

+26
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ Possible breaking change if you use nested grid JSON format, or original Angular
446446
447447
## Migrating to v9
448448
449-
New addition - see release notes about `fitToContent` feature.
449+
New addition - see release notes about `sizeToContent` feature.
450450
Possible break:
451451
* `GridStack.onParentResize()` is now called `onResize()` as grid now directly track size change, no longer involving parent per say to tell us anything. Note sure why it was public.
452452

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ <h1>Demos</h1>
1212
<li><a href="anijs.html">AniJS</a></li>
1313
<li><a href="cell-height.html">Cell Height</a></li>
1414
<li><a href="column.html">Column</a></li>
15-
<li><a href="fitToContent.html">Fit To Content</a></li>
1615
<li><a href="float.html">Float grid</a></li>
1716
<li><a href="knockout.html">Knockout.js</a></li>
1817
<li><a href="mobile.html">Mobile touch</a></li>
@@ -26,6 +25,7 @@ <h1>Demos</h1>
2625
<li><a href="responsive.html">Responsive</a></li>
2726
<li><a href="right-to-left(rtl).html">Right-To-Left (RTL)</a></li>
2827
<li><a href="serialization.html">Serialization</a></li>
28+
<li><a href="sizeToContent.html">Size To Content</a></li>
2929
<li><a href="static.html">Static</a></li>
3030
<li><a href="title_drag.html">Title drag</a></li>
3131
<li><a href="two.html">Two grids</a></li>

demo/fitToContent.html renamed to demo/sizeToContent.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
7-
<title>FitToContent demo</title>
7+
<title>sizeToContent demo</title>
88

99
<link rel="stylesheet" href="demo.css"/>
1010
<link rel="stylesheet" href="../dist/gridstack-extra.css"/>
@@ -17,9 +17,9 @@
1717
</head>
1818
<body>
1919
<div class="container">
20-
<h1>Cell FitToContent options demo</h1>
20+
<h1>Cell sizeToContent options demo</h1>
2121
<p>new 9.x feature that size the items to fit their content height as to not have scroll bars
22-
(unless `fitToContent:false` in C: case). Defaulting to different initial size (see code) to show grow/shrink behavior.</p>
22+
(unless `sizeToContent:false` in C: case). Defaulting to different initial size (see code) to show grow/shrink behavior.</p>
2323
<div>
2424
column:
2525
<a onClick="column(8)" class="btn btn-primary" href="#">8</a>
@@ -39,17 +39,17 @@ <h1>Cell FitToContent options demo</h1>
3939
let opts = {
4040
margin: 5,
4141
cellHeight: 50,
42-
fitToContent: true, // default to make them all fit
42+
sizeToContent: true, // default to make them all fit
4343
resizable: { handles: 'all'} // do all sides for testing
44-
// cellHeightThrottle: 100, // ms before fitToContent happens
44+
// cellHeightThrottle: 100, // ms before sizeToContent happens
4545
}
4646
let grid = GridStack.init(opts);
4747
let text ='some very large content that will normally not fit in the window.'
4848
text = text + text;
4949
let items = [
5050
{x:0, y:0, w:2, content: `<div>A no h: ${text}</div>`},
5151
{x:2, y:0, w:1, h:2, content: '<div>B: shrink h=2</div>'}, // make taller than needed upfront
52-
{x:3, y:0, w:2, fitToContent: false, content: `<div>C: WILL SCROLL. ${text}</div>`}, // prevent this from fitting testing
52+
{x:3, y:0, w:2, sizeToContent: false, content: `<div>C: WILL SCROLL. ${text}</div>`}, // prevent this from fitting testing
5353
{x:0, y:1, w:3, content: `<div>D no h: ${text} ${text}</div>`},
5454
];
5555
grid.load(items);

doc/CHANGES.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,18 @@ Change log
9797
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
9898

9999
## 9.0.2-dev (TBD)
100+
* renamed fitToContent to sizeToContent (API BREAK)
100101

101102
## 9.0.2 (2023-08-29)
102103
* fix 'resizecontent' event fix not called.
103-
* partial fix [#2427](https://github.com/gridstack/gridstack.js/issues/2427) fitToContent when calling cellHeight()/addWidget()/MakeWidget()
104+
* partial fix [#2427](https://github.com/gridstack/gridstack.js/issues/2427) sizeToContent when calling cellHeight()/addWidget()/MakeWidget()
104105

105106
## 9.0.1 (2023-08-27)
106107
* fix [#2413](https://github.com/gridstack/gridstack.js/issues/2413) support touchscreen+mouse devices. Thank you [@Ruslan207](https://github.com/Ruslan207)
107-
* tweak to `fitToContent` from [#2412](https://github.com/gridstack/gridstack.js/pull/2412#issuecomment-1690219018). Thank you [@JonSohn](https://github.com/JonSohn)
108+
* tweak to `sizeToContent` from [#2412](https://github.com/gridstack/gridstack.js/pull/2412#issuecomment-1690219018). Thank you [@JonSohn](https://github.com/JonSohn)
108109

109110
## 9.0.0 (2023-08-23)
110-
- feat [#404](https://github.com/gridstack/gridstack.js/issues/404) added `GridStackOptions.fitToContent` and `GridStackWidget.fitToContent` to make gridItems size themselves to their content (no scroll bar), calling `GridStack.resizeToContent(el)` whenever the grid or item is resized.
111+
- feat [#404](https://github.com/gridstack/gridstack.js/issues/404) added `GridStackOptions.sizeToContent` and `GridStackWidget.sizeToContent` to make gridItems size themselves to their content (no scroll bar), calling `GridStack.resizeToContent(el)` whenever the grid or item is resized.
111112
- also added new `'resizecontent'` event, and `resizeToContentCB` and `resizeToContentParent` vars.
112113
- fix [#2406](https://github.com/gridstack/gridstack.js/issues/2406) inf loop when autoPosition after loading into 1 column, then 2.
113114

doc/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ gridstack.js API
9999
- `draggable` - allows to override draggable options - see `DDDragOpt`. (default: `{handle: '.grid-stack-item-content', appendTo: 'body', scroll: true}`)
100100
- `dragOut` to let user drag nested grid items out of a parent or not (default false) See [example](http://gridstackjs.com/demo/nested.html)
101101
- `engineClass` - the type of engine to create (so you can subclass) default to GridStackEngine
102-
- `fitToContent` - make gridItems size themselves to their content, calling `resizeToContent(el)` whenever the grid or item is resized.
102+
- `sizeToContent` - make gridItems size themselves to their content, calling `resizeToContent(el)` whenever the grid or item is resized.
103103
- `float` - enable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html)
104104
- `handle` - draggable handle selector (default: `'.grid-stack-item-content'`)
105105
- `handleClass` - draggable handle class (e.g. `'grid-stack-item-content'`). If set `handle` is ignored (default: `null`)
@@ -159,7 +159,7 @@ You need to add `noResize` and `noMove` attributes to completely lock the widget
159159
- `noMove` - disable element moving
160160
- `id`- (number | string) good for quick identification (for example in change event)
161161
- `content` - (string) html content to be added when calling `grid.load()/addWidget()` as content inside the item
162-
- `fitToContent` - make gridItem size itself to the content, calling `GridStack.resizeToContent(el)` whenever the grid or item is resized.
162+
- `sizeToContent` - make gridItem size itself to the content, calling `GridStack.resizeToContent(el)` whenever the grid or item is resized.
163163
- `subGrid`?: GridStackOptions - optional nested grid options and list of children
164164
- `subGridDynamic`?: boolean - enable/disable the creation of sub-grids on the fly by dragging items completely over others (nest) vs partially (push). Forces `DDDragOpt.pause=true` to accomplish that.
165165

src/gridstack.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ export class GridStack {
15071507
if (!Utils.same(node, copy)) {
15081508
this._writeAttr(el, node);
15091509
}
1510-
if (Utils.shouldFitToContent(node)) el.classList.add('fit-to-content');
1510+
if (Utils.shouldSizeToContent(node)) el.classList.add('fit-to-content');
15111511
this._prepareDragDropByNode(node);
15121512
return this;
15131513
}
@@ -1601,7 +1601,7 @@ export class GridStack {
16011601
/**
16021602
* called when we are being resized - check if the one Column Mode needs to be turned on/off
16031603
* and remember the prev columns we used, or get our count from parent, as well as check for cellHeight==='auto' (square)
1604-
* or `fitToContent` gridItem options.
1604+
* or `sizeToContent` gridItem options.
16051605
*/
16061606
public onResize(): GridStack {
16071607
if (!this.el?.clientWidth) return; // return if we're gone or no size yet (will get called again)
@@ -1623,7 +1623,7 @@ export class GridStack {
16231623
let oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize ||
16241624
(this.opts.column === 1 && !this._prevColumn);
16251625
if ((this.opts.column === 1) !== oneColumn) {
1626-
// if (this.opts.animate) this.setAnimation(false); // 1 <-> 12 is too radical, turn off animation and we need it for fitToContent
1626+
// if (this.opts.animate) this.setAnimation(false); // 1 <-> 12 is too radical, turn off animation and we need it for sizeToContent
16271627
this.column(oneColumn ? 1 : this._prevColumn);
16281628
// if (this.opts.animate) setTimeout(() => this.setAnimation(true));
16291629
columnChanged = true;
@@ -1645,16 +1645,16 @@ export class GridStack {
16451645
}
16461646

16471647
private doContentResize(delay = true, n: GridStackNode = undefined) {
1648-
// update any gridItem height with fitToContent, but wait for DOM $animation_speed to settle if we changed column count
1648+
// update any gridItem height with sizeToContent, but wait for DOM $animation_speed to settle if we changed column count
16491649
// TODO: is there a way to know what the final (post animation) size of the content will be so we can animate the column width and height together rather than sequentially ?
16501650
setTimeout(() => {
16511651
if (n) {
1652-
if (Utils.shouldFitToContent(n)) this.resizeToContentCheck(n.el);
1652+
if (Utils.shouldSizeToContent(n)) this.resizeToContentCheck(n.el);
16531653
} else {
16541654
const nodes = [...this.engine.nodes]; // in case order changes while resizing one
16551655
this.batchUpdate();
16561656
nodes.forEach(n => {
1657-
if (Utils.shouldFitToContent(n)) this.resizeToContentCheck(n.el);
1657+
if (Utils.shouldSizeToContent(n)) this.resizeToContentCheck(n.el);
16581658
});
16591659
this.batchUpdate(false);
16601660
}
@@ -1665,8 +1665,8 @@ export class GridStack {
16651665
/** add or remove the grid element size event handler */
16661666
protected _updateResizeEvent(forceRemove = false): GridStack {
16671667
// only add event if we're not nested (parent will call us) and we're auto sizing cells or supporting oneColumn (i.e. doing work)
1668-
// or supporting new fitToContent option.
1669-
const trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.fitToContent || !this.opts.disableOneColumnMode || this.engine.nodes.find(n => n.fitToContent));
1668+
// or supporting new sizeToContent option.
1669+
const trackSize = !this.parentGridItem && (this._isAutoCellHeight || this.opts.sizeToContent || !this.opts.disableOneColumnMode || this.engine.nodes.find(n => n.sizeToContent));
16701670

16711671
if (!forceRemove && trackSize && !this.resizeObserver) {
16721672
this._sizeThrottle = Utils.throttle(() => this.onResize(), this.opts.cellHeightThrottle);

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export interface GridStackOptions {
164164

165165
/** set to true if all grid items (by default, but item can also override) height should be based on content size instead of WidgetItem.h to avoid v-scrollbars.
166166
Note: this is still row based, not pixels, so it will use ceil(getBoundingClientRect().height / getCellHeight()) */
167-
fitToContent?: boolean;
167+
sizeToContent?: boolean;
168168

169169
/** enable floating widgets (default?: false) See example (http://gridstack.github.io/gridstack.js/demo/float.html) */
170170
float?: boolean;
@@ -322,7 +322,7 @@ export interface GridStackWidget extends GridStackPosition {
322322
/** html to append inside as content */
323323
content?: string;
324324
/** local (grid) override - see GridStackOptions */
325-
fitToContent?: boolean;
325+
sizeToContent?: boolean;
326326
/** optional nested grid options and list of children, which then turns into actual instance at runtime to get options from */
327327
subGridOpts?: GridStackOptions;
328328
}

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ export class Utils {
103103
}
104104

105105
/** true if we should resize to content */
106-
static shouldFitToContent(n: GridStackNode | undefined): boolean {
107-
return n?.grid && (n.fitToContent || (n.grid.opts.fitToContent && n.fitToContent !== false));
106+
static shouldSizeToContent(n: GridStackNode | undefined): boolean {
107+
return n?.grid && (n.sizeToContent || (n.grid.opts.sizeToContent && n.sizeToContent !== false));
108108
}
109109

110110
/** returns true if a and b overlap */

0 commit comments

Comments
 (0)