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

Skip to content

Commit ec35618

Browse files
committed
restrict vertical resize with sizeToContent
* since sizeToContent:true will automatically size the content vertically, don't let the user change the height to start with Note: tried to change the feedback to have e,w arrows but we only have 10px area which is too narrow to show feedback (we have 20x20 for corners that may overlap content which is ok). Showing normal handles for now.
1 parent 1307def commit ec35618

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/dd-gridstack.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,18 @@ export class DDGridStack {
4040
} else if (opts === 'option') {
4141
dEl.setupResizable({ [key]: value });
4242
} else {
43-
const grid = dEl.el.gridstackNode.grid;
44-
let handles = dEl.el.getAttribute('gs-resize-handles') ? dEl.el.getAttribute('gs-resize-handles') : grid.opts.resizable.handles;
45-
let autoHide = !grid.opts.alwaysShowResizeHandle;
43+
const n = dEl.el.gridstackNode;
44+
const grid = n.grid;
45+
let handles = dEl.el.getAttribute('gs-resize-handles') || grid.opts.resizable.handles || 'e,s,se';
46+
if (handles === 'all') handles = 'n,e,s,w,se,sw,ne,nw';
47+
// NOTE: keep the resize handles as e,w don't have enough space (10px) to show resize corners anyway. limit during drag instead
48+
// restrict vertical resize if height is done to match content anyway... odd to have it spring back
49+
// if (Utils.shouldSizeToContent(n)) {
50+
// const doE = handles.indexOf('e') !== -1;
51+
// const doW = handles.indexOf('w') !== -1;
52+
// handles = doE ? (doW ? 'e,w' : 'e') : (doW ? 'w' : '');
53+
// }
54+
const autoHide = !grid.opts.alwaysShowResizeHandle;
4655
dEl.setupResizable({
4756
...grid.opts.resizable,
4857
...{ handles, autoHide },

src/dd-resizable.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { DDResizableHandle } from './dd-resizable-handle';
77
import { DDBaseImplement, HTMLElementExtendOpt } from './dd-base-impl';
88
import { Utils } from './utils';
9-
import { DDUIData, Rect, Size } from './types';
9+
import { DDUIData, GridItemHTMLElement, Rect, Size } from './types';
1010
import { DDManager } from './dd-manager';
1111

1212
// import { GridItemHTMLElement } from './types'; let count = 0; // TEST
@@ -32,7 +32,7 @@ interface RectScaleReciprocal {
3232
export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt<DDResizableOpt> {
3333

3434
// have to be public else complains for HTMLElementExtendOpt ?
35-
public el: HTMLElement;
35+
public el: GridItemHTMLElement;
3636
public option: DDResizableOpt;
3737

3838
/** @internal */
@@ -57,6 +57,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
5757
protected parentOriginStylePosition: string;
5858
/** @internal */
5959
protected static _originStyleProp = ['width', 'height', 'position', 'left', 'top', 'opacity', 'zIndex'];
60+
/** @internal */
61+
protected sizeToContent: boolean;
6062

6163
constructor(el: HTMLElement, opts: DDResizableOpt = {}) {
6264
super();
@@ -152,11 +154,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
152154

153155
/** @internal */
154156
protected _setupHandlers(): DDResizable {
155-
let handlerDirection = this.option.handles || 'e,s,se';
156-
if (handlerDirection === 'all') {
157-
handlerDirection = 'n,e,s,w,se,sw,ne,nw';
158-
}
159-
this.handlers = handlerDirection.split(',')
157+
this.handlers = this.option.handles.split(',')
160158
.map(dir => dir.trim())
161159
.map(dir => new DDResizableHandle(this.el, dir, {
162160
start: (event: MouseEvent) => {
@@ -174,6 +172,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
174172

175173
/** @internal */
176174
protected _resizeStart(event: MouseEvent): DDResizable {
175+
this.sizeToContent = Utils.shouldSizeToContent(this.el.gridstackNode);
177176
this.originalRect = this.el.getBoundingClientRect();
178177
this.scrollEl = Utils.getScrollElement(this.el);
179178
this.scrollY = this.scrollEl.scrollTop;
@@ -260,7 +259,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
260259
};
261260

262261
const offsetX = event.clientX - oEvent.clientX;
263-
const offsetY = event.clientY - oEvent.clientY;
262+
const offsetY = this.sizeToContent ? 0 : event.clientY - oEvent.clientY; // prevent vert resize
264263

265264
if (dir.indexOf('e') > -1) {
266265
newRect.width += offsetX;

0 commit comments

Comments
 (0)