@@ -76,7 +76,6 @@ import {
76
76
getGlobalFrameOfGridCellFromMetadata ,
77
77
getGridRelatedIndexes ,
78
78
getGridElementPinState ,
79
- gridPositionToValue ,
80
79
printPin ,
81
80
getGridIdentifierContainerOrComponentPath ,
82
81
gridIdentifierToString ,
@@ -120,6 +119,7 @@ import { styleStringInArray } from '../../../utils/common-constants'
120
119
import { gridContainerIdentifier , type GridIdentifier } from '../../editor/store/editor-state'
121
120
import type { RulerMarkerType } from './grid-controls-ruler-markers'
122
121
import { rulerMarkerIcons } from './grid-controls-ruler-markers'
122
+ import { isFeatureEnabled } from '../../../utils/feature-switches'
123
123
124
124
const CELL_ANIMATION_DURATION = 0.15 // seconds
125
125
@@ -1213,9 +1213,12 @@ export const GridControlsComponent = ({ targets }: GridControlsProps) => {
1213
1213
)
1214
1214
} ) }
1215
1215
{ /* Ruler markers */ }
1216
- { selectedGridItems . map ( ( path ) => {
1217
- return < RulerMarkers key = { `ruler-markers-${ EP . toString ( path ) } ` } path = { path } />
1218
- } ) }
1216
+ { when (
1217
+ isFeatureEnabled ( 'Grid Ruler Markers' ) ,
1218
+ selectedGridItems . map ( ( path ) => {
1219
+ return < RulerMarkers key = { `ruler-markers-${ EP . toString ( path ) } ` } path = { path } />
1220
+ } ) ,
1221
+ ) }
1219
1222
< AbsoluteDistanceIndicators targetRootCell = { targetRootCell } />
1220
1223
</ CanvasOffsetWrapper >
1221
1224
</ div >
@@ -2186,6 +2189,7 @@ function useSelectedGridItems(): ElementPath[] {
2186
2189
const rulerMarkerIconSize = 12 // px
2187
2190
2188
2191
type RulerMarkerData = {
2192
+ parentGrid : GridContainerProperties
2189
2193
columnStart : RulerMarkerPositionData
2190
2194
columnEnd : RulerMarkerPositionData
2191
2195
rowStart : RulerMarkerPositionData
@@ -2196,7 +2200,6 @@ type RulerMarkerPositionData = {
2196
2200
top : number
2197
2201
left : number
2198
2202
position : GridPositionOrSpan | null
2199
- counterpart : GridPositionOrSpan | null
2200
2203
bound : 'start' | 'end'
2201
2204
}
2202
2205
@@ -2217,6 +2220,8 @@ const RulerMarkers = React.memo((props: { path: ElementPath }) => {
2217
2220
return null
2218
2221
}
2219
2222
2223
+ const parentGrid = elementMetadata . specialSizeMeasurements . parentContainerGridProperties
2224
+
2220
2225
const originalGrid = findOriginalGrid ( store . editor . jsxMetadata , EP . parentPath ( props . path ) )
2221
2226
if ( originalGrid == null ) {
2222
2227
return null
@@ -2269,32 +2274,29 @@ const RulerMarkers = React.memo((props: { path: ElementPath }) => {
2269
2274
)
2270
2275
2271
2276
return {
2277
+ parentGrid : parentGrid ,
2272
2278
columnStart : {
2273
2279
top : gridRect . y ,
2274
2280
left : left ,
2275
2281
position : elementGridProperties . gridColumnStart ,
2276
- counterpart : elementGridProperties . gridColumnEnd ,
2277
2282
bound : 'start' ,
2278
2283
} ,
2279
2284
columnEnd : {
2280
2285
top : gridRect . y ,
2281
2286
left : left + width ,
2282
2287
position : elementGridProperties . gridColumnEnd ,
2283
- counterpart : elementGridProperties . gridColumnStart ,
2284
2288
bound : 'end' ,
2285
2289
} ,
2286
2290
rowStart : {
2287
2291
top : top ,
2288
2292
left : gridRect . x ,
2289
2293
position : elementGridProperties . gridRowStart ,
2290
- counterpart : elementGridProperties . gridRowEnd ,
2291
2294
bound : 'start' ,
2292
2295
} ,
2293
2296
rowEnd : {
2294
2297
top : top + height ,
2295
2298
left : gridRect . x ,
2296
2299
position : elementGridProperties . gridRowEnd ,
2297
- counterpart : elementGridProperties . gridRowStart ,
2298
2300
bound : 'end' ,
2299
2301
} ,
2300
2302
}
@@ -2308,22 +2310,37 @@ const RulerMarkers = React.memo((props: { path: ElementPath }) => {
2308
2310
2309
2311
return (
2310
2312
< React . Fragment >
2311
- < RulerMarkerIndicator marker = { markers . columnStart } axis = { 'column' } />
2312
- < RulerMarkerIndicator marker = { markers . columnEnd } axis = { 'column' } />
2313
- < RulerMarkerIndicator marker = { markers . rowStart } axis = { 'row' } />
2314
- < RulerMarkerIndicator marker = { markers . rowEnd } axis = { 'row' } />
2313
+ < RulerMarkerIndicator
2314
+ parentGrid = { markers . parentGrid }
2315
+ marker = { markers . columnStart }
2316
+ axis = { 'column' }
2317
+ />
2318
+ < RulerMarkerIndicator
2319
+ parentGrid = { markers . parentGrid }
2320
+ marker = { markers . columnEnd }
2321
+ axis = { 'column' }
2322
+ />
2323
+ < RulerMarkerIndicator
2324
+ parentGrid = { markers . parentGrid }
2325
+ marker = { markers . rowStart }
2326
+ axis = { 'row' }
2327
+ />
2328
+ < RulerMarkerIndicator parentGrid = { markers . parentGrid } marker = { markers . rowEnd } axis = { 'row' } />
2315
2329
</ React . Fragment >
2316
2330
)
2317
2331
} )
2318
2332
RulerMarkers . displayName = 'RulerMarkers'
2319
2333
2320
2334
const RulerMarkerIndicator = React . memo (
2321
- ( props : { marker : RulerMarkerPositionData ; axis : 'row' | 'column' } ) => {
2335
+ ( props : {
2336
+ parentGrid : GridContainerProperties
2337
+ marker : RulerMarkerPositionData
2338
+ axis : 'row' | 'column'
2339
+ } ) => {
2322
2340
const colorTheme = useColorTheme ( )
2323
2341
2324
2342
const markerType = getRulerMarkerType ( {
2325
2343
position : props . marker . position ,
2326
- counterpart : props . marker . counterpart ,
2327
2344
bound : props . marker . bound ,
2328
2345
} )
2329
2346
const markerIcon = rulerMarkerIcons [ markerType ] [ props . axis ]
@@ -2334,21 +2351,24 @@ const RulerMarkerIndicator = React.memo(
2334
2351
'RulerMarkerIndicator canvasScale' ,
2335
2352
)
2336
2353
2337
- function skewMarkerPosition ( axis : 'column' | 'row' ) {
2338
- if ( props . axis === axis ) {
2339
- return rulerMarkerIconSize
2340
- } else if ( markerType === 'span-end' ) {
2341
- return rulerMarkerIconSize - 1 // adjust span end position so it just touches the grid line
2342
- } else {
2343
- return rulerMarkerIconSize / 2
2344
- }
2345
- }
2346
-
2347
2354
const scaledTop = props . marker . top * canvasScale
2348
- const top = scaledTop - skewMarkerPosition ( 'column' )
2355
+ const top =
2356
+ scaledTop -
2357
+ skewMarkerPosition ( props . axis === 'column' , props . axis , props . marker . bound , markerType )
2349
2358
2350
2359
const scaledLeft = props . marker . left * canvasScale
2351
- const left = scaledLeft - skewMarkerPosition ( 'row' )
2360
+ const left =
2361
+ scaledLeft -
2362
+ skewMarkerPosition ( props . axis === 'row' , props . axis , props . marker . bound , markerType )
2363
+
2364
+ const labelText = React . useMemo ( ( ) => {
2365
+ if ( props . marker . position == null ) {
2366
+ return null
2367
+ }
2368
+ return printPin ( props . parentGrid , props . marker . position , props . axis )
2369
+ } , [ props . marker , props . parentGrid , props . axis ] )
2370
+
2371
+ const labelClass = 'ruler-marker-label'
2352
2372
2353
2373
return (
2354
2374
< div
@@ -2357,15 +2377,45 @@ const RulerMarkerIndicator = React.memo(
2357
2377
top : top ,
2358
2378
left : left ,
2359
2379
color : colorTheme . primary . value ,
2380
+ maxHeight : rulerMarkerIconSize ,
2381
+ maxWidth : rulerMarkerIconSize ,
2360
2382
display : 'flex' ,
2361
- alignItems : 'center' ,
2362
- justifyContent : 'center' ,
2363
- height : rulerMarkerIconSize ,
2364
- width : rulerMarkerIconSize ,
2365
2383
zoom : 1 / canvasScale ,
2366
2384
} }
2385
+ css = { {
2386
+ [ `> .${ labelClass } ` ] : {
2387
+ visibility : 'hidden' ,
2388
+ } ,
2389
+ ':hover' : {
2390
+ [ `> .${ labelClass } ` ] : {
2391
+ visibility : 'visible' ,
2392
+ } ,
2393
+ } ,
2394
+ } }
2367
2395
>
2368
2396
{ markerIcon }
2397
+ { when (
2398
+ labelText != null ,
2399
+ < div
2400
+ className = { labelClass }
2401
+ style = { {
2402
+ position : 'absolute' ,
2403
+ background : colorTheme . primary . value ,
2404
+ borderRadius : 2 ,
2405
+ padding : '3px 6px' ,
2406
+ color : colorTheme . white . value ,
2407
+ height : 20 ,
2408
+ display : 'flex' ,
2409
+ alignItems : 'center' ,
2410
+ justifyContent : 'center' ,
2411
+ top : props . axis === 'column' ? - 23 : 0 ,
2412
+ left : props . axis === 'column' ? 0 : undefined ,
2413
+ right : props . axis === 'row' ? rulerMarkerIconSize + 1 : undefined ,
2414
+ } }
2415
+ >
2416
+ { labelText }
2417
+ </ div > ,
2418
+ ) }
2369
2419
</ div >
2370
2420
)
2371
2421
} ,
@@ -2374,16 +2424,11 @@ RulerMarkerIndicator.displayName = 'RulerMarkerIndicator'
2374
2424
2375
2425
function getRulerMarkerType ( props : {
2376
2426
position : GridPositionOrSpan | null
2377
- counterpart : GridPositionOrSpan | null
2378
2427
bound : 'start' | 'end'
2379
2428
} ) : RulerMarkerType {
2380
- const isAuto =
2381
- isAutoGridPin ( props . position ) ||
2382
- ( props . bound === 'start' && isGridSpan ( props . position ) && isAutoGridPin ( props . counterpart ) )
2383
- const isSpanStart =
2384
- props . bound === 'start' && isGridSpan ( props . position ) && isGridSpan ( props . counterpart )
2385
- const isSpanEnd =
2386
- props . bound === 'end' && ( isGridSpan ( props . position ) || isGridSpan ( props . counterpart ) )
2429
+ const isAuto = isAutoGridPin ( props . position )
2430
+ const isSpanStart = props . bound === 'start' && isGridSpan ( props . position )
2431
+ const isSpanEnd = props . bound === 'end' && isGridSpan ( props . position )
2387
2432
2388
2433
if ( isSpanStart ) {
2389
2434
return 'span-start'
@@ -2454,3 +2499,66 @@ function getCellCanvasHeightFromBounds(
2454
2499
return acc + curr . height + padding
2455
2500
} , currentColumn . height )
2456
2501
}
2502
+
2503
+ // This function returns the amount of pixels used to adjust the position of
2504
+ // individual ruler markers, which need specific skews based on their shape.
2505
+ function skewMarkerPosition (
2506
+ isOnTheSameAxis : boolean ,
2507
+ axis : 'column' | 'row' ,
2508
+ bound : 'start' | 'end' ,
2509
+ markerType : RulerMarkerType ,
2510
+ ) : number {
2511
+ if ( isOnTheSameAxis ) {
2512
+ return rulerMarkerIconSize
2513
+ }
2514
+
2515
+ // span-end triangle, on the column
2516
+ const spanEndColumn = axis === 'column' && markerType === 'span-end'
2517
+ if ( spanEndColumn ) {
2518
+ return 10
2519
+ }
2520
+ const pinnedEndColumn = axis === 'column' && markerType === 'pinned'
2521
+ if ( pinnedEndColumn ) {
2522
+ return 5
2523
+ }
2524
+ // any other ending marker, on the column
2525
+ const endColumn = bound === 'end' && axis === 'column'
2526
+ if ( endColumn ) {
2527
+ return 2
2528
+ }
2529
+
2530
+ // span-end triangle, on the row
2531
+ const spanEndRow = axis === 'row' && markerType === 'span-end'
2532
+ if ( spanEndRow ) {
2533
+ return 9
2534
+ }
2535
+ // any other ending marker, on the row
2536
+ const endRow = bound === 'end' && axis === 'row'
2537
+ if ( endRow ) {
2538
+ return 6
2539
+ }
2540
+
2541
+ // span-start triangle, on the column
2542
+ const spanStartColumn = axis === 'column' && markerType === 'span-start'
2543
+ if ( spanStartColumn ) {
2544
+ return 0
2545
+ }
2546
+ // any starting marker, on the column
2547
+ const startColumn = bound === 'start' && axis === 'column'
2548
+ if ( startColumn ) {
2549
+ return 5
2550
+ }
2551
+
2552
+ // span-start starting triangle, on the row
2553
+ const spanStartRow = axis === 'row' && markerType === 'span-start'
2554
+ if ( spanStartRow ) {
2555
+ return 0
2556
+ }
2557
+ // any other starting marker, on the row
2558
+ const startRow = bound === 'start' && axis === 'row'
2559
+ if ( startRow ) {
2560
+ return 4
2561
+ }
2562
+
2563
+ return 0
2564
+ }
0 commit comments