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

Skip to content

Commit 6e4e64c

Browse files
authored
Merge pull request gridstack#2040 from adumesny/master
options cleanup
2 parents ab9ac0c + 7bf9bb8 commit 6e4e64c

File tree

3 files changed

+51
-59
lines changed

3 files changed

+51
-59
lines changed

src/dd-gridstack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class DDGridStack {
7676
dEl.setupDraggable({
7777
...grid.opts.draggable,
7878
...{
79-
// containment: (grid.opts._isNested && !grid.opts.dragOut) ? grid.el.parentElement : (grid.opts.draggable.containment || null),
79+
// containment: (grid._isNested && !grid.opts.dragOut) ? grid.el.parentElement : (grid.opts.draggable.containment || null),
8080
start: opts.start,
8181
stop: opts.stop,
8282
drag: opts.drag

src/gridstack.ts

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import { GridStackEngine } from './gridstack-engine';
99
import { Utils, HeightData, obsolete } from './utils';
10-
import { ColumnOptions, GridItemHTMLElement, GridStackElement, GridStackEventHandlerCallback,
10+
import { GridDefaults, ColumnOptions, GridItemHTMLElement, GridStackElement, GridStackEventHandlerCallback,
1111
GridStackNode, GridStackOptions, GridStackWidget, numberOrString, DDUIData, DDDragInOpt, GridStackPosition } from './types';
1212

1313
// export all dependent file as well to make it easier for users to just import the main file
@@ -39,46 +39,6 @@ interface GridCSSStyleSheet extends CSSStyleSheet {
3939
_max?: number; // internal tracker of the max # of rows we created\
4040
}
4141

42-
// default values for grid options - used during init and when saving out
43-
const GridDefaults: GridStackOptions = {
44-
column: 12,
45-
minRow: 0,
46-
maxRow: 0,
47-
itemClass: 'grid-stack-item',
48-
placeholderClass: 'grid-stack-placeholder',
49-
placeholderText: '',
50-
handle: '.grid-stack-item-content',
51-
handleClass: null,
52-
styleInHead: false,
53-
cellHeight: 'auto',
54-
cellHeightThrottle: 100,
55-
margin: 10,
56-
auto: true,
57-
oneColumnSize: 768,
58-
float: false,
59-
staticGrid: false,
60-
animate: true,
61-
alwaysShowResizeHandle: 'mobile',
62-
resizable: {
63-
handles: 'se'
64-
},
65-
draggable: {
66-
handle: '.grid-stack-item-content',
67-
appendTo: 'body'
68-
},
69-
disableDrag: false,
70-
disableResize: false,
71-
rtl: 'auto',
72-
removable: false,
73-
removableOptions: {
74-
accept: '.grid-stack-item'
75-
},
76-
marginUnit: 'px',
77-
cellHeightUnit: 'px',
78-
disableOneColumnMode: false,
79-
oneColumnModeDomSort: false,
80-
};
81-
8242
/**
8343
* Main gridstack class - you will need to call `GridStack.init()` first to initialize your grid.
8444
* Note: your grid elements MUST have the following classes for the CSS layout to work:
@@ -200,6 +160,11 @@ export class GridStack {
200160

201161
protected static engineClass: typeof GridStackEngine;
202162

163+
/** @internal point to a parent grid item if we're nested */
164+
protected _isNested?: GridStackNode;
165+
/** @internal unique class name for our generated CSS style sheet */
166+
protected _styleSheetClass?: string;
167+
203168
/** @internal create placeholder DIV as needed */
204169
public get placeholder(): HTMLElement {
205170
if (!this._placeholder) {
@@ -275,7 +240,6 @@ export class GridStack {
275240
minRow: rowAttr ? rowAttr : Utils.toNumber(el.getAttribute('gs-min-row')) || GridDefaults.minRow,
276241
maxRow: rowAttr ? rowAttr : Utils.toNumber(el.getAttribute('gs-max-row')) || GridDefaults.maxRow,
277242
staticGrid: Utils.toBool(el.getAttribute('gs-static')) || GridDefaults.staticGrid,
278-
_styleSheetClass: 'grid-stack-instance-' + (Math.random() * 10000).toFixed(0),
279243
draggable: {
280244
handle: (opts.handleClass ? '.' + opts.handleClass : (opts.handle ? opts.handle : '')) || GridDefaults.draggable.handle,
281245
},
@@ -307,8 +271,8 @@ export class GridStack {
307271
// check if we're been nested, and if so update our style and keep pointer around (used during save)
308272
let parentGridItemEl = Utils.closestByClass(this.el, GridDefaults.itemClass) as GridItemHTMLElement;
309273
if (parentGridItemEl && parentGridItemEl.gridstackNode) {
310-
this.opts._isNested = parentGridItemEl.gridstackNode;
311-
this.opts._isNested.subGrid = this;
274+
this._isNested = parentGridItemEl.gridstackNode;
275+
this._isNested.subGrid = this;
312276
parentGridItemEl.classList.add('grid-stack-nested');
313277
this.el.classList.add('grid-stack-nested');
314278
}
@@ -331,7 +295,8 @@ export class GridStack {
331295
this.opts.alwaysShowResizeHandle = isTouch;
332296
}
333297

334-
this.el.classList.add(this.opts._styleSheetClass);
298+
this._styleSheetClass = 'grid-stack-instance-' + (Math.random() * 10000).toFixed(0)
299+
this.el.classList.add(this._styleSheetClass);
335300

336301
this._setStaticClass();
337302

@@ -771,13 +736,13 @@ export class GridStack {
771736
this.setAnimation(false);
772737
if (!removeDOM) {
773738
this.removeAll(removeDOM);
774-
this.el.classList.remove(this.opts._styleSheetClass);
739+
this.el.classList.remove(this._styleSheetClass);
775740
} else {
776741
this.el.parentNode.removeChild(this.el);
777742
}
778743
this._removeStylesheet();
779744
this.el.removeAttribute('gs-current-row');
780-
delete this.opts._isNested;
745+
delete this._isNested;
781746
delete this.opts;
782747
delete this._placeholder;
783748
delete this.engine;
@@ -1207,7 +1172,7 @@ export class GridStack {
12071172

12081173
let cellHeight = this.opts.cellHeight as number;
12091174
let cellHeightUnit = this.opts.cellHeightUnit;
1210-
let prefix = `.${this.opts._styleSheetClass} > .${this.opts.itemClass}`;
1175+
let prefix = `.${this._styleSheetClass} > .${this.opts.itemClass}`;
12111176

12121177
// create one as needed
12131178
if (!this._styles) {
@@ -1227,7 +1192,7 @@ export class GridStack {
12271192
let right: string = this.opts.marginRight + this.opts.marginUnit;
12281193
let left: string = this.opts.marginLeft + this.opts.marginUnit;
12291194
let content = `${prefix} > .grid-stack-item-content`;
1230-
let placeholder = `.${this.opts._styleSheetClass} > .grid-stack-placeholder > .placeholder-content`;
1195+
let placeholder = `.${this._styleSheetClass} > .grid-stack-placeholder > .placeholder-content`;
12311196
Utils.addCSSRule(this._styles, content, `top: ${top}; right: ${right}; bottom: ${bottom}; left: ${left};`);
12321197
Utils.addCSSRule(this._styles, placeholder, `top: ${top}; right: ${right}; bottom: ${bottom}; left: ${left};`);
12331198
// resize handles offset (to match margin)
@@ -1389,10 +1354,10 @@ export class GridStack {
13891354
let changedColumn = false;
13901355

13911356
// see if we're nested and take our column count from our parent....
1392-
if (this._autoColumn && this.opts._isNested) {
1393-
if (this.opts.column !== this.opts._isNested.w) {
1357+
if (this._autoColumn && this._isNested) {
1358+
if (this.opts.column !== this._isNested.w) {
13941359
changedColumn = true;
1395-
this.column(this.opts._isNested.w, 'none');
1360+
this.column(this._isNested.w, 'none');
13961361
}
13971362
} else {
13981363
// else check for 1 column in/out behavior
@@ -1429,7 +1394,7 @@ export class GridStack {
14291394
/** add or remove the window size event handler */
14301395
protected _updateWindowResizeEvent(forceRemove = false): GridStack {
14311396
// 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)
1432-
const workTodo = (this._isAutoCellHeight || !this.opts.disableOneColumnMode) && !this.opts._isNested;
1397+
const workTodo = (this._isAutoCellHeight || !this.opts.disableOneColumnMode) && !this._isNested;
14331398

14341399
if (!forceRemove && workTodo && !this._windowResizeBind) {
14351400
this._windowResizeBind = this.onParentResize.bind(this); // so we can properly remove later

src/types.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,38 @@
66
import { GridStack } from './gridstack';
77
import { GridStackEngine } from './gridstack-engine';
88

9+
// default values for grid options - used during init and when saving out
10+
export const GridDefaults: GridStackOptions = {
11+
alwaysShowResizeHandle: 'mobile',
12+
animate: true,
13+
auto: true,
14+
cellHeight: 'auto',
15+
cellHeightThrottle: 100,
16+
cellHeightUnit: 'px',
17+
column: 12,
18+
draggable: { handle: '.grid-stack-item-content', appendTo: 'body' },
19+
handle: '.grid-stack-item-content',
20+
itemClass: 'grid-stack-item',
21+
margin: 10,
22+
marginUnit: 'px',
23+
oneColumnSize: 768,
24+
placeholderClass: 'grid-stack-placeholder',
25+
placeholderText: '',
26+
removableOptions: { accept: '.grid-stack-item' },
27+
resizable: { handles: 'se' },
28+
rtl: 'auto',
29+
30+
// **** same as not being set ****
31+
// disableDrag: false,
32+
// disableOneColumnMode: false,
33+
// disableResize: false,
34+
// float: false,
35+
// handleClass: null,
36+
// oneColumnModeDomSort: false,
37+
// removable: false,
38+
// staticGrid: false,
39+
// styleInHead: false,
40+
};
941

1042
/** different layout options when changing # of columns,
1143
* including a custom function that takes new/old column count, and array of new/old positions
@@ -198,11 +230,6 @@ export interface GridStackOptions {
198230

199231
/** if `true` will add style element to `<head>` otherwise will add it to element's parent node (default `false`). */
200232
styleInHead?: boolean;
201-
202-
/** @internal point to a parent grid item if we're nested */
203-
_isNested?: GridStackNode;
204-
/** @internal unique class name for our generated CSS style sheet */
205-
_styleSheetClass?: string;
206233
}
207234

208235
/** options used during GridStackEngine.moveNode() */

0 commit comments

Comments
 (0)