@@ -217,8 +217,8 @@ export class AssetDateGroup {
217
217
return { moveAssets, processedIds, unprocessedIds, changedGeometry } ;
218
218
}
219
219
220
- layout ( options : CommonLayoutOptions ) {
221
- if ( ! this . bucket . intersecting ) {
220
+ layout ( options : CommonLayoutOptions , noDefer : boolean ) {
221
+ if ( ! noDefer && ! this . bucket . intersecting ) {
222
222
this . deferredLayout = true ;
223
223
return ;
224
224
}
@@ -602,6 +602,8 @@ export class AssetBucket {
602
602
}
603
603
604
604
findAssetAbsolutePosition ( assetId : string ) {
605
+ this . store . clearDeferredLayout ( this ) ;
606
+
605
607
for ( const group of this . dateGroups ) {
606
608
const intersectingAsset = group . intersetingAssets . find ( ( asset ) => asset . id === assetId ) ;
607
609
if ( intersectingAsset ) {
@@ -658,6 +660,12 @@ type AssetStoreLayoutOptions = {
658
660
headerHeight ?: number ;
659
661
gap ?: number ;
660
662
} ;
663
+
664
+ interface UpdateGeometryOptions {
665
+ invalidateHeight : boolean ;
666
+ noDefer ?: boolean ;
667
+ }
668
+
661
669
export class AssetStore {
662
670
// --- public ----
663
671
isInitialized = $state ( false ) ;
@@ -932,6 +940,16 @@ export class AssetStore {
932
940
) ;
933
941
}
934
942
943
+ clearDeferredLayout ( bucket : AssetBucket ) {
944
+ const hasDeferred = bucket . dateGroups . some ( ( group ) => group . deferredLayout ) ;
945
+ if ( hasDeferred ) {
946
+ this . #updateGeometry( bucket , { invalidateHeight : true , noDefer : true } ) ;
947
+ for ( const group of bucket . dateGroups ) {
948
+ group . deferredLayout = false ;
949
+ }
950
+ }
951
+ }
952
+
935
953
#updateIntersection( bucket : AssetBucket ) {
936
954
const actuallyIntersecting = this . #calculateIntersecting( bucket , 0 , 0 ) ;
937
955
let preIntersecting = false ;
@@ -941,13 +959,7 @@ export class AssetStore {
941
959
bucket . intersecting = actuallyIntersecting || preIntersecting ;
942
960
bucket . actuallyIntersecting = actuallyIntersecting ;
943
961
if ( preIntersecting || actuallyIntersecting ) {
944
- const hasDeferred = bucket . dateGroups . some ( ( group ) => group . deferredLayout ) ;
945
- if ( hasDeferred ) {
946
- this . #updateGeometry( bucket , true ) ;
947
- for ( const group of bucket . dateGroups ) {
948
- group . deferredLayout = false ;
949
- }
950
- }
962
+ this . clearDeferredLayout ( bucket ) ;
951
963
}
952
964
}
953
965
@@ -1052,7 +1064,7 @@ export class AssetStore {
1052
1064
return ;
1053
1065
}
1054
1066
for ( const bucket of this . buckets ) {
1055
- this . #updateGeometry( bucket , changedWidth ) ;
1067
+ this . #updateGeometry( bucket , { invalidateHeight : changedWidth } ) ;
1056
1068
}
1057
1069
this . updateIntersections ( ) ;
1058
1070
this . #createScrubBuckets( ) ;
@@ -1079,7 +1091,8 @@ export class AssetStore {
1079
1091
} ;
1080
1092
}
1081
1093
1082
- #updateGeometry( bucket : AssetBucket , invalidateHeight : boolean ) {
1094
+ #updateGeometry( bucket : AssetBucket , options : UpdateGeometryOptions ) {
1095
+ const { invalidateHeight, noDefer = false } = options ;
1083
1096
if ( invalidateHeight ) {
1084
1097
bucket . isBucketHeightActual = false ;
1085
1098
}
@@ -1094,10 +1107,10 @@ export class AssetStore {
1094
1107
}
1095
1108
return ;
1096
1109
}
1097
- this . #layoutBucket( bucket ) ;
1110
+ this . #layoutBucket( bucket , noDefer ) ;
1098
1111
}
1099
1112
1100
- #layoutBucket( bucket : AssetBucket ) {
1113
+ #layoutBucket( bucket : AssetBucket , noDefer : boolean = false ) {
1101
1114
// these are top offsets, for each row
1102
1115
let cummulativeHeight = 0 ;
1103
1116
// these are left offsets of each group, for each row
@@ -1112,7 +1125,7 @@ export class AssetStore {
1112
1125
rowSpaceRemaining . fill ( this . viewportWidth , 0 , bucket . dateGroups . length ) ;
1113
1126
const options = this . createLayoutOptions ( ) ;
1114
1127
for ( const assetGroup of bucket . dateGroups ) {
1115
- assetGroup . layout ( options ) ;
1128
+ assetGroup . layout ( options , noDefer ) ;
1116
1129
rowSpaceRemaining [ dateGroupRow ] -= assetGroup . width - 1 ;
1117
1130
if ( dateGroupCol > 0 ) {
1118
1131
rowSpaceRemaining [ dateGroupRow ] -= this . gap ;
@@ -1266,7 +1279,7 @@ export class AssetStore {
1266
1279
1267
1280
for ( const bucket of addContext . updatedBuckets ) {
1268
1281
bucket . sortDateGroups ( ) ;
1269
- this . #updateGeometry( bucket , true ) ;
1282
+ this . #updateGeometry( bucket , { invalidateHeight : true } ) ;
1270
1283
}
1271
1284
this . updateIntersections ( ) ;
1272
1285
}
@@ -1357,7 +1370,7 @@ export class AssetStore {
1357
1370
}
1358
1371
const changedGeometry = changedBuckets . size > 0 ;
1359
1372
for ( const bucket of changedBuckets ) {
1360
- this . #updateGeometry( bucket , true ) ;
1373
+ this . #updateGeometry( bucket , { invalidateHeight : true } ) ;
1361
1374
}
1362
1375
if ( changedGeometry ) {
1363
1376
this . updateIntersections ( ) ;
@@ -1397,7 +1410,7 @@ export class AssetStore {
1397
1410
1398
1411
refreshLayout ( ) {
1399
1412
for ( const bucket of this . buckets ) {
1400
- this . #updateGeometry( bucket , true ) ;
1413
+ this . #updateGeometry( bucket , { invalidateHeight : true } ) ;
1401
1414
}
1402
1415
this . updateIntersections ( ) ;
1403
1416
}
0 commit comments