@@ -66,6 +66,11 @@ export interface ConvertPxToUnitProps {
6666 el : HTMLElement ;
6767 valuePx : number ;
6868 unit ?: LiteralUnion < ConvertUnitsToPx , string > ;
69+ elComputedStyle ?: CSSStyleDeclaration ;
70+ /**
71+ * If true, the conversion will be done as height (requred for % units).
72+ */
73+ isHeight ?: boolean ;
6974 /**
7075 * @default 3
7176 */
@@ -116,6 +121,7 @@ export default {
116121 const el = elOpts || componentView ?. el || component . getEl ( ) ! ;
117122 const resizeEventOpts = { component, el } ;
118123 let modelToStyle : StyleableModel ;
124+ let elComputedStyle : CSSStyleDeclaration ;
119125
120126 const toggleBodyClass = ( method : string , e : any , opts : any ) => {
121127 const docs = opts . docs ;
@@ -133,26 +139,28 @@ export default {
133139 posFetcher : canvasView . getElementPos . bind ( canvasView ) ,
134140 mousePosFetcher : Canvas . getMouseRelativePos . bind ( Canvas ) ,
135141 docs : [ document ] ,
136- onStart ( ev , opts ) {
142+ updateOnMove : true ,
143+ skipUnitAdjustments : true ,
144+ onStart : ( ev , opts ) => {
137145 onStart ( ev , opts ) ;
138146 const { el, config, resizer } = opts ;
139147 const { keyHeight, keyWidth, currentUnit, keepAutoHeight, keepAutoWidth } = config ;
140148 toggleBodyClass ( 'add' , ev , opts ) ;
141149 modelToStyle = em . Styles . getModelToStyle ( component ) ;
142- const computedStyle = getComputedStyle ( el ) ;
150+ elComputedStyle = getComputedStyle ( el ) ;
143151 const modelStyle = modelToStyle . getStyle ( ) ;
144152 const rectStart = { ...resizer . startDim ! } ;
145153
146154 let currentWidth = modelStyle [ keyWidth ! ] as string ;
147155 config . autoWidth = keepAutoWidth && currentWidth === 'auto' ;
148156 if ( isNaN ( parseFloat ( currentWidth ) ) ) {
149- currentWidth = computedStyle [ keyWidth as any ] ;
157+ currentWidth = elComputedStyle [ keyWidth as any ] ;
150158 }
151159
152160 let currentHeight = modelStyle [ keyHeight ! ] as string ;
153161 config . autoHeight = keepAutoHeight && currentHeight === 'auto' ;
154162 if ( isNaN ( parseFloat ( currentHeight ) ) ) {
155- currentHeight = computedStyle [ keyHeight as any ] ;
163+ currentHeight = elComputedStyle [ keyHeight as any ] ;
156164 }
157165
158166 const valueWidth = parseFloat ( currentWidth ) ;
@@ -188,8 +196,7 @@ export default {
188196 options . afterStart ?.( ) ;
189197 } ,
190198
191- // Update all positioned elements (eg. component toolbar)
192- onMove ( event , opts ) {
199+ onMove : ( event , opts ) => {
193200 onMove ( event , opts ) ;
194201 const { resizer } = opts ;
195202 const eventProps : ComponentResizeEventMoveProps = {
@@ -203,7 +210,7 @@ export default {
203210 editor . trigger ( ComponentsEvents . resize , { ...eventProps , type : 'move' } ) ;
204211 } ,
205212
206- onEnd ( event , opts ) {
213+ onEnd : ( event , opts ) => {
207214 onEnd ( event , opts ) ;
208215 toggleBodyClass ( 'remove' , event , opts ) ;
209216 const { resizer } = opts ;
@@ -238,6 +245,7 @@ export default {
238245 ? 'auto'
239246 : this . convertPxToUnit ( {
240247 el,
248+ elComputedStyle,
241249 valuePx : width ,
242250 unit : unitWidth ,
243251 } ) ;
@@ -248,8 +256,10 @@ export default {
248256 ? 'auto'
249257 : this . convertPxToUnit ( {
250258 el,
259+ elComputedStyle,
251260 valuePx : rect . h ,
252261 unit : unitHeight ,
262+ isHeight : true ,
253263 } ) ;
254264 }
255265
@@ -274,7 +284,8 @@ export default {
274284 event,
275285 style,
276286 updateStyle,
277- convertPxToUnit : ( props : Omit < ConvertPxToUnitProps , 'el' > ) => this . convertPxToUnit ( { el, ...props } ) ,
287+ convertPxToUnit : ( props : Omit < ConvertPxToUnitProps , 'el' > ) =>
288+ this . convertPxToUnit ( { el, elComputedStyle, ...props } ) ,
278289 delta : resizer . delta ! ,
279290 pointer : resizer . currentPos ! ,
280291 } ;
@@ -304,7 +315,7 @@ export default {
304315 } ,
305316
306317 convertPxToUnit ( props : ConvertPxToUnitProps ) : string {
307- const { el, valuePx, unit, dpi = 96 , roundDecimals = 3 } = props ;
318+ const { el, valuePx, unit, dpi = 96 , roundDecimals = 3 , isHeight , elComputedStyle } = props ;
308319 const win = el . ownerDocument . defaultView ;
309320 const winWidth = win ?. innerWidth || 1 ;
310321 const winHeight = window . innerHeight || 1 ;
@@ -344,7 +355,11 @@ export default {
344355 break ;
345356 }
346357 case ConvertUnitsToPx . perc : {
347- const parentSize = el . parentElement ?. offsetWidth || 1 ;
358+ const { parentElement, offsetParent } = el ;
359+ const parentEl = elComputedStyle ?. position === 'absolute' ? ( offsetParent as HTMLElement ) : parentElement ;
360+ const parentWidth = parentEl ?. offsetWidth || 1 ;
361+ const parentHeight = parentEl ?. offsetHeight || 1 ;
362+ const parentSize = isHeight ? parentHeight : parentWidth ;
348363 valueResult = ( valuePx / parentSize ) * 100 ;
349364 break ;
350365 }
0 commit comments