@elementor/editor-canvas 4.3.0-985 → 4.3.0-987

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -495,8 +495,8 @@ function toGridTracks(computedStyle) {
495
495
  return {
496
496
  columns: parseTrackList(computedStyle.gridTemplateColumns),
497
497
  rows: parseTrackList(computedStyle.gridTemplateRows),
498
- columnGap: toPx(computedStyle.columnGap),
499
- rowGap: toPx(computedStyle.rowGap),
498
+ columnGap: resolveGapPx(computedStyle.columnGap, computedStyle.width),
499
+ rowGap: resolveGapPx(computedStyle.rowGap, computedStyle.height),
500
500
  padding: {
501
501
  top: toPx(computedStyle.paddingTop),
502
502
  right: toPx(computedStyle.paddingRight),
@@ -571,6 +571,14 @@ function toPx(value) {
571
571
  const parsed = parseFloat(value);
572
572
  return Number.isFinite(parsed) ? parsed : 0;
573
573
  }
574
+ function resolveGapPx(value, referenceSize) {
575
+ if (value.trim().endsWith("%")) {
576
+ const percent = parseFloat(value);
577
+ const reference = parseFloat(referenceSize);
578
+ return Number.isFinite(percent) && Number.isFinite(reference) ? percent / 100 * reference : 0;
579
+ }
580
+ return toPx(value);
581
+ }
574
582
 
575
583
  // src/hooks/use-grid-children.ts
576
584
  var import_react3 = require("react");
package/dist/index.mjs CHANGED
@@ -433,8 +433,8 @@ function toGridTracks(computedStyle) {
433
433
  return {
434
434
  columns: parseTrackList(computedStyle.gridTemplateColumns),
435
435
  rows: parseTrackList(computedStyle.gridTemplateRows),
436
- columnGap: toPx(computedStyle.columnGap),
437
- rowGap: toPx(computedStyle.rowGap),
436
+ columnGap: resolveGapPx(computedStyle.columnGap, computedStyle.width),
437
+ rowGap: resolveGapPx(computedStyle.rowGap, computedStyle.height),
438
438
  padding: {
439
439
  top: toPx(computedStyle.paddingTop),
440
440
  right: toPx(computedStyle.paddingRight),
@@ -509,6 +509,14 @@ function toPx(value) {
509
509
  const parsed = parseFloat(value);
510
510
  return Number.isFinite(parsed) ? parsed : 0;
511
511
  }
512
+ function resolveGapPx(value, referenceSize) {
513
+ if (value.trim().endsWith("%")) {
514
+ const percent = parseFloat(value);
515
+ const reference = parseFloat(referenceSize);
516
+ return Number.isFinite(percent) && Number.isFinite(reference) ? percent / 100 * reference : 0;
517
+ }
518
+ return toPx(value);
519
+ }
512
520
 
513
521
  // src/hooks/use-grid-children.ts
514
522
  import { useEffect as useEffect3, useState as useState2 } from "react";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-canvas",
3
3
  "description": "Elementor Editor Canvas",
4
- "version": "4.3.0-985",
4
+ "version": "4.3.0-987",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -37,26 +37,26 @@
37
37
  "react-dom": "^18.3.1"
38
38
  },
39
39
  "dependencies": {
40
- "@elementor/editor": "4.3.0-985",
41
- "@elementor/editor-controls": "4.3.0-985",
42
- "@elementor/editor-documents": "4.3.0-985",
43
- "@elementor/editor-elements": "4.3.0-985",
44
- "@elementor/editor-interactions": "4.3.0-985",
45
- "@elementor/editor-mcp": "4.3.0-985",
46
- "@elementor/editor-notifications": "4.3.0-985",
47
- "@elementor/editor-props": "4.3.0-985",
48
- "@elementor/editor-responsive": "4.3.0-985",
49
- "@elementor/editor-styles": "4.3.0-985",
50
- "@elementor/editor-styles-repository": "4.3.0-985",
51
- "@elementor/editor-ui": "4.3.0-985",
52
- "@elementor/editor-v1-adapters": "4.3.0-985",
53
- "@elementor/events": "4.3.0-985",
54
- "@elementor/http-client": "4.3.0-985",
55
- "@elementor/schema": "4.3.0-985",
56
- "@elementor/twing": "4.3.0-985",
40
+ "@elementor/editor": "4.3.0-987",
41
+ "@elementor/editor-controls": "4.3.0-987",
42
+ "@elementor/editor-documents": "4.3.0-987",
43
+ "@elementor/editor-elements": "4.3.0-987",
44
+ "@elementor/editor-interactions": "4.3.0-987",
45
+ "@elementor/editor-mcp": "4.3.0-987",
46
+ "@elementor/editor-notifications": "4.3.0-987",
47
+ "@elementor/editor-props": "4.3.0-987",
48
+ "@elementor/editor-responsive": "4.3.0-987",
49
+ "@elementor/editor-styles": "4.3.0-987",
50
+ "@elementor/editor-styles-repository": "4.3.0-987",
51
+ "@elementor/editor-ui": "4.3.0-987",
52
+ "@elementor/editor-v1-adapters": "4.3.0-987",
53
+ "@elementor/events": "4.3.0-987",
54
+ "@elementor/http-client": "4.3.0-987",
55
+ "@elementor/schema": "4.3.0-987",
56
+ "@elementor/twing": "4.3.0-987",
57
57
  "@elementor/ui": "1.37.5",
58
- "@elementor/utils": "4.3.0-985",
59
- "@elementor/wp-media": "4.3.0-985",
58
+ "@elementor/utils": "4.3.0-987",
59
+ "@elementor/wp-media": "4.3.0-987",
60
60
  "@floating-ui/react": "^0.27.5",
61
61
  "@wordpress/i18n": "^5.13.0",
62
62
  "dompurify": "^3.2.6"
@@ -3,6 +3,7 @@ import {
3
3
  computeCellRects,
4
4
  computeGridLines,
5
5
  parseTrackList,
6
+ resolveGapPx,
6
7
  snapToHalfPixel,
7
8
  toGridTracks,
8
9
  toPx,
@@ -215,11 +216,29 @@ describe( 'toPx', () => {
215
216
  } );
216
217
  } );
217
218
 
219
+ describe( 'resolveGapPx', () => {
220
+ it( 'resolves a percentage gap against the reference size', () => {
221
+ expect( resolveGapPx( '20%', '1000px' ) ).toBe( 200 );
222
+ expect( resolveGapPx( '10%', '500px' ) ).toBe( 50 );
223
+ } );
224
+
225
+ it( 'falls back to px parsing for non-percentage gaps', () => {
226
+ expect( resolveGapPx( '16px', '1000px' ) ).toBe( 16 );
227
+ expect( resolveGapPx( 'normal', '1000px' ) ).toBe( 0 );
228
+ } );
229
+
230
+ it( 'returns 0 when the reference size is not a finite number', () => {
231
+ expect( resolveGapPx( '20%', 'auto' ) ).toBe( 0 );
232
+ } );
233
+ } );
234
+
218
235
  type ComputedStyleParts = {
219
236
  gridTemplateColumns: string;
220
237
  gridTemplateRows: string;
221
238
  columnGap: string;
222
239
  rowGap: string;
240
+ width: string;
241
+ height: string;
223
242
  paddingTop: string;
224
243
  paddingRight: string;
225
244
  paddingBottom: string;
@@ -233,6 +252,8 @@ function mockComputedStyle( parts: Partial< ComputedStyleParts > = {} ): CSSStyl
233
252
  gridTemplateRows: 'none',
234
253
  columnGap: 'normal',
235
254
  rowGap: 'normal',
255
+ width: '1000px',
256
+ height: '500px',
236
257
  paddingTop: '0px',
237
258
  paddingRight: '0px',
238
259
  paddingBottom: '0px',
@@ -246,6 +267,8 @@ function mockComputedStyle( parts: Partial< ComputedStyleParts > = {} ): CSSStyl
246
267
  gridTemplateRows: resolved.gridTemplateRows,
247
268
  columnGap: resolved.columnGap,
248
269
  rowGap: resolved.rowGap,
270
+ width: resolved.width,
271
+ height: resolved.height,
249
272
  paddingTop: resolved.paddingTop,
250
273
  paddingRight: resolved.paddingRight,
251
274
  paddingBottom: resolved.paddingBottom,
@@ -286,6 +309,22 @@ describe( 'toGridTracks', () => {
286
309
  expect( tracks.rows ).toEqual( [] );
287
310
  } );
288
311
 
312
+ it( 'resolves percentage gaps against the content-box width and height', () => {
313
+ const tracks = toGridTracks(
314
+ mockComputedStyle( {
315
+ gridTemplateColumns: '100px 100px',
316
+ gridTemplateRows: '80px 80px',
317
+ columnGap: '20%',
318
+ rowGap: '10%',
319
+ width: '1000px',
320
+ height: '500px',
321
+ } )
322
+ );
323
+
324
+ expect( tracks.columnGap ).toBe( 200 );
325
+ expect( tracks.rowGap ).toBe( 50 );
326
+ } );
327
+
289
328
  it( 'reports gap as 0 when computed style returns "normal"', () => {
290
329
  const tracks = toGridTracks(
291
330
  mockComputedStyle( { gridTemplateColumns: '100px 100px', columnGap: 'normal', rowGap: 'normal' } )
@@ -28,8 +28,8 @@ export function toGridTracks( computedStyle: CSSStyleDeclaration ): GridTracks {
28
28
  return {
29
29
  columns: parseTrackList( computedStyle.gridTemplateColumns ),
30
30
  rows: parseTrackList( computedStyle.gridTemplateRows ),
31
- columnGap: toPx( computedStyle.columnGap ),
32
- rowGap: toPx( computedStyle.rowGap ),
31
+ columnGap: resolveGapPx( computedStyle.columnGap, computedStyle.width ),
32
+ rowGap: resolveGapPx( computedStyle.rowGap, computedStyle.height ),
33
33
  padding: {
34
34
  top: toPx( computedStyle.paddingTop ),
35
35
  right: toPx( computedStyle.paddingRight ),
@@ -142,3 +142,14 @@ export function toPx( value: string ): number {
142
142
 
143
143
  return Number.isFinite( parsed ) ? parsed : 0;
144
144
  }
145
+
146
+ export function resolveGapPx( value: string, referenceSize: string ): number {
147
+ if ( value.trim().endsWith( '%' ) ) {
148
+ const percent = parseFloat( value );
149
+ const reference = parseFloat( referenceSize );
150
+
151
+ return Number.isFinite( percent ) && Number.isFinite( reference ) ? ( percent / 100 ) * reference : 0;
152
+ }
153
+
154
+ return toPx( value );
155
+ }