From f7a37be6ddc15e6fc528cdb4c99043beedec68d1 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 26 Nov 2018 16:46:27 +0100 Subject: [PATCH] support associating an id with a resize item/handle --- src/components/views/elements/ResizeHandle.js | 2 +- src/resizer/resizer.js | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/components/views/elements/ResizeHandle.js b/src/components/views/elements/ResizeHandle.js index 4c09278f84..b5487b1fc1 100644 --- a/src/components/views/elements/ResizeHandle.js +++ b/src/components/views/elements/ResizeHandle.js @@ -14,7 +14,7 @@ const ResizeHandle = (props) => { classNames.push('mx_ResizeHandle_reverse'); } return ( -
+
); }; diff --git a/src/resizer/resizer.js b/src/resizer/resizer.js index b7d17bc807..7ef542a6e1 100644 --- a/src/resizer/resizer.js +++ b/src/resizer/resizer.js @@ -64,8 +64,19 @@ export class Resizer { forHandleAt(handleIndex) { const handles = this._getResizeHandles(); const handle = handles[handleIndex]; - const {distributor} = this._createSizerAndDistributor(handle); - return distributor; + if (handle) { + const {distributor} = this._createSizerAndDistributor(handle); + return distributor; + } + } + + forHandleWithId(id) { + const handles = this._getResizeHandles(); + const handle = handles.find((h) => h.getAttribute("data-id") === id); + if (handle) { + const {distributor} = this._createSizerAndDistributor(handle); + return distributor; + } } _isResizeHandle(el) { @@ -79,6 +90,7 @@ export class Resizer { } // prevent starting a drag operation event.preventDefault(); + // mark as currently resizing if (this.classNames.resizing) { this.container.classList.add(this.classNames.resizing); @@ -115,9 +127,10 @@ export class Resizer { // if reverse, resize the item after the handle instead of before, so + 1 const itemIndex = items.indexOf(prevItem) + (reverse ? 1 : 0); const item = items[itemIndex]; + const id = resizeHandle.getAttribute("data-id"); // eslint-disable-next-line new-cap const distributor = new this.distributorCtor( - sizer, item, this.distributorCfg, + sizer, item, id, this.distributorCfg, items, this.container); return {sizer, distributor}; }