@tantawowa/hosanna-ui 2.1.0 → 2.3.0
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-manifest.json +26 -22
- package/package.json +1 -1
- package/src/hosanna-bridge-core/color.ts +140 -0
- package/src/hosanna-game/color.ts +3 -115
- package/src/hosanna-list/BaseCell.ts +4 -0
- package/src/hosanna-list/BaseCollectionViewLayout.ts +59 -6
- package/src/hosanna-list/CollectionView.ts +14 -5
- package/src/hosanna-list/CollectionViewAPI.ts +41 -5
- package/src/hosanna-list/CollectionViewFocusManager.ts +415 -6
- package/src/hosanna-list/CollectionViewSupplementaryView.ts +49 -1
- package/src/hosanna-list/DynamicCell.ts +132 -2
- package/src/hosanna-list/EPGProgramLayout.ts +1 -0
- package/src/hosanna-list/GridRowLayout.ts +1 -0
- package/src/hosanna-list/HorizontalRowLayout.ts +1 -0
- package/src/hosanna-list/ListRowLayout.ts +1 -0
- package/src/hosanna-ui/lib/FragmentUtils.ts +26 -10
- package/src/hosanna-ui/lib/animation.ts +358 -235
- package/src/hosanna-ui/views/controls/Button.ts +16 -1
- package/src/hosanna-ui/views/lib/AppConfig.ts +26 -0
- package/src/hosanna-ui/views/lib/BaseView.ts +109 -16
- package/src/hosanna-ui/views/lib/ViewFragmentProvider.ts +39 -5
- package/src/hosanna-ui/views/primitives/Image.ts +1 -1
- package/src/hosanna-ui/views/primitives/Label.ts +3 -3
|
@@ -22,7 +22,7 @@ import { InstancePool } from '@hs-src/hosanna-ui/lib/InstancePool';
|
|
|
22
22
|
import { scrollJankDuration, scrollJankLog, scrollJankNow } from '@hs-src/hosanna-ui/lib/ScrollJankLogger';
|
|
23
23
|
import { BaseApp } from '@hs-src/hosanna-ui/lib/BaseApp';
|
|
24
24
|
import { state, view } from '@hs-src/hosanna-ui/lib/decorators';
|
|
25
|
-
import { getUniqueViewId, IHosannaView, NextViewFocus, ViewEvent, ViewEventHandler, ViewState } from '@hs-src/hosanna-ui/views/lib/view-api';
|
|
25
|
+
import { getUniqueViewId, IHosannaView, NextViewFocus, ViewEvent, ViewEventHandler, ViewState, FocusChildChangeEvent } from '@hs-src/hosanna-ui/views/lib/view-api';
|
|
26
26
|
import { BaseView } from '@hs-src/hosanna-ui/views/lib/BaseView';
|
|
27
27
|
import { ViewPhase } from '@hs-src/hosanna-ui/lib/renderer-api';
|
|
28
28
|
import { Direction, ViewStatus } from '@hs-src/hosanna-ui/hosanna-api';
|
|
@@ -4692,6 +4692,7 @@ export class CollectionViewView extends BaseView<CollectionViewState, ISGNGroup>
|
|
|
4692
4692
|
this.clearSupplementaryFocus(false);
|
|
4693
4693
|
}
|
|
4694
4694
|
this.focusedSupplementary = { kind, rowIndex };
|
|
4695
|
+
this.collectionViewFocusManager.setFocusPercentSupplementary?.(rowIndex);
|
|
4695
4696
|
supplementary.setFocused(true);
|
|
4696
4697
|
this.collectionViewFocusManager.applyCellViewStatus(
|
|
4697
4698
|
this.focusedIndices[0],
|
|
@@ -4707,6 +4708,7 @@ export class CollectionViewView extends BaseView<CollectionViewState, ISGNGroup>
|
|
|
4707
4708
|
private clearSupplementaryFocus(restoreCellGraphics: boolean): void {
|
|
4708
4709
|
const focused = this.focusedSupplementary;
|
|
4709
4710
|
this.focusedSupplementary = undefined;
|
|
4711
|
+
this.collectionViewFocusManager.setFocusPercentSupplementary?.();
|
|
4710
4712
|
if (focused) {
|
|
4711
4713
|
this.getSupplementaryView(focused.rowIndex, focused.kind)?.setFocused(false);
|
|
4712
4714
|
}
|
|
@@ -5035,20 +5037,26 @@ export class CollectionViewView extends BaseView<CollectionViewState, ISGNGroup>
|
|
|
5035
5037
|
* Uses the same vertical math as {@link jumpToRow} so grid rows scrolled within
|
|
5036
5038
|
* the collection stay aligned after blur/focus or aggregate reappear.
|
|
5037
5039
|
*/
|
|
5038
|
-
private syncFocusIndicatorToFocusedItem(): void {
|
|
5040
|
+
private syncFocusIndicatorToFocusedItem(preserveFocusPercentTransition = false): void {
|
|
5039
5041
|
const rowIndex = clamp(this.focusedIndices[0], 0, this.rows.length - 1);
|
|
5040
5042
|
const focusedRow = this.rows[rowIndex];
|
|
5041
5043
|
if (!focusedRow) {
|
|
5042
5044
|
return;
|
|
5043
5045
|
}
|
|
5044
5046
|
const itemIndex = clamp(this.focusedIndices[1], 0, focusedRow.layout.numberOfItems - 1);
|
|
5045
|
-
this.collectionViewFocusManager.setAndRenderFocusInfo(this.getFocusInfo(rowIndex, itemIndex));
|
|
5047
|
+
this.collectionViewFocusManager.setAndRenderFocusInfo(this.getFocusInfo(rowIndex, itemIndex), preserveFocusPercentTransition);
|
|
5048
|
+
}
|
|
5049
|
+
|
|
5050
|
+
override notifyOnFocusedChildChange(event: FocusChildChangeEvent): void {
|
|
5051
|
+
this.collectionViewFocusManager.syncFocusPercentFocusChain?.();
|
|
5052
|
+
super.notifyOnFocusedChildChange(event);
|
|
5046
5053
|
}
|
|
5047
5054
|
|
|
5048
5055
|
/**
|
|
5049
5056
|
* Called when the collection view receives focus.
|
|
5050
5057
|
*/
|
|
5051
5058
|
override onFocus(): void {
|
|
5059
|
+
this.collectionViewFocusManager.syncFocusPercentFocusChain?.();
|
|
5052
5060
|
if (this.isInternalRefocusing) {
|
|
5053
5061
|
console.debug('CollectionView is internal refocusing, skipping focus');
|
|
5054
5062
|
return;
|
|
@@ -5069,7 +5077,7 @@ export class CollectionViewView extends BaseView<CollectionViewState, ISGNGroup>
|
|
|
5069
5077
|
const focusedRow = this.rows[this.focusedIndices[0]];
|
|
5070
5078
|
if (focusedRow) {
|
|
5071
5079
|
console.debug('Setting focus info for focused row', this.focusedIndices[0]);
|
|
5072
|
-
this.syncFocusIndicatorToFocusedItem();
|
|
5080
|
+
this.syncFocusIndicatorToFocusedItem(true);
|
|
5073
5081
|
} else {
|
|
5074
5082
|
console.debug('No focused row found, setting focus info for first row');
|
|
5075
5083
|
};
|
|
@@ -5082,6 +5090,7 @@ export class CollectionViewView extends BaseView<CollectionViewState, ISGNGroup>
|
|
|
5082
5090
|
* Called when the collection view loses focus.
|
|
5083
5091
|
*/
|
|
5084
5092
|
override onBlur(): void {
|
|
5093
|
+
this.collectionViewFocusManager.syncFocusPercentFocusChain?.();
|
|
5085
5094
|
if (this.isInternalRefocusing) {
|
|
5086
5095
|
// Clear so that when we leave the screen (e.g. press OK to navigate), the next onFocus runs. Key release
|
|
5087
5096
|
// may be handled by the new screen, so we might never get a chance to set this to false.
|
|
@@ -5098,7 +5107,7 @@ export class CollectionViewView extends BaseView<CollectionViewState, ISGNGroup>
|
|
|
5098
5107
|
)?.setFocused(false);
|
|
5099
5108
|
return;
|
|
5100
5109
|
}
|
|
5101
|
-
this.syncFocusIndicatorToFocusedItem();
|
|
5110
|
+
this.syncFocusIndicatorToFocusedItem(true);
|
|
5102
5111
|
this.collectionViewFocusManager.applyFocusToRow(false);
|
|
5103
5112
|
this.dispatchRowItemFocusEventForFocus(false);
|
|
5104
5113
|
this.focusEventStateManager.resetDirectChangeFlags();
|
|
@@ -250,6 +250,17 @@ export interface ICollectionView extends IHosannaView<ViewState> {
|
|
|
250
250
|
* Handles rendering and updating focus info and animations.
|
|
251
251
|
*/
|
|
252
252
|
export interface ICollectionViewFocusManager {
|
|
253
|
+
/** Registers a realized cell after its content and optional progress callbacks are bound. */
|
|
254
|
+
registerFocusPercentCell?(cell: ICollectionViewCell, force?: boolean): void;
|
|
255
|
+
/** Detaches a cell before hiding, rebinding or releasing it. */
|
|
256
|
+
unregisterFocusPercentCell?(cell: ICollectionViewCell): void;
|
|
257
|
+
/** Registers a visible complex header; legacy label headers never participate. */
|
|
258
|
+
registerRowFocusPercentHeader?(rowIndex: number, header: ICollectionViewRowFocusPercentHeader, force?: boolean): void;
|
|
259
|
+
unregisterRowFocusPercentHeader?(header: ICollectionViewRowFocusPercentHeader): void;
|
|
260
|
+
/** Reconciles effective focus without changing navigation or the active progress pair. */
|
|
261
|
+
syncFocusPercentFocusChain?(): void;
|
|
262
|
+
/** Uses -1 when ordinary item focus replaces supplementary focus. */
|
|
263
|
+
setFocusPercentSupplementary?(rowIndex?: number): void;
|
|
253
264
|
/** Applies the cell view status. */
|
|
254
265
|
applyCellViewStatus(rowIndex: number, itemIndex: number, focused: boolean, isFootprint?: boolean): void;
|
|
255
266
|
/** Starts the active strategy's gesture-level long-press lifecycle. */
|
|
@@ -267,7 +278,7 @@ export interface ICollectionViewFocusManager {
|
|
|
267
278
|
/** Suppresses or restores focus indicator visibility without changing committed focus. */
|
|
268
279
|
setFocusIndicatorSuppressed?(suppressed: boolean): void;
|
|
269
280
|
/** Sets and renders the focus info. */
|
|
270
|
-
setAndRenderFocusInfo(info: IFocusInfo | undefined): void;
|
|
281
|
+
setAndRenderFocusInfo(info: IFocusInfo | undefined, preserveFocusPercentTransition?: boolean): void;
|
|
271
282
|
/** Renders the next focus info. */
|
|
272
283
|
renderNextFocusInfo(): void;
|
|
273
284
|
/** Sets the next focus info for animation or transition. */
|
|
@@ -697,11 +708,30 @@ export function createFocusInfoForRowItem(
|
|
|
697
708
|
return info;
|
|
698
709
|
}
|
|
699
710
|
|
|
700
|
-
/**
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
711
|
+
/** @internal Reusable cell-owned storage; only active bindings have an owner. */
|
|
712
|
+
export interface ICollectionViewFocusPercentRegistration {
|
|
713
|
+
owner?: ICollectionViewFocusManager;
|
|
714
|
+
ownerId: string;
|
|
715
|
+
cell?: ICollectionViewCell;
|
|
716
|
+
rowKey: string;
|
|
717
|
+
itemIndex: number;
|
|
718
|
+
rowCellIndex: number;
|
|
719
|
+
supportsFocusPercent: boolean;
|
|
720
|
+
supportsRowFocusPercent: boolean;
|
|
721
|
+
needsInitialization: boolean;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/** Interface for a collection view cell. Extends IReusable. */
|
|
704
725
|
export interface ICollectionViewCell extends IReusable {
|
|
726
|
+
/** @internal Retained through pooling, detached from the manager when hidden. */
|
|
727
|
+
_focusPercentRegistration?: ICollectionViewFocusPercentRegistration;
|
|
728
|
+
/** Optional presentation capabilities, resolved when the cell's fragment is acquired. */
|
|
729
|
+
supportsFocusPercent?: boolean;
|
|
730
|
+
supportsRowFocusPercent?: boolean;
|
|
731
|
+
focusPercent?: number;
|
|
732
|
+
rowFocusPercent?: number;
|
|
733
|
+
/** Stores both supported values before notifying either callback. */
|
|
734
|
+
setFocusPercents?(focusPercent: number, rowFocusPercent: number, force?: boolean): void;
|
|
705
735
|
/** The item associated with the cell. */
|
|
706
736
|
item?: IIdentifiable;
|
|
707
737
|
/** The row this cell belongs to. */
|
|
@@ -722,6 +752,12 @@ export interface ICollectionViewCell extends IReusable {
|
|
|
722
752
|
getFocusHolder(): ISGNGroup | undefined;
|
|
723
753
|
}
|
|
724
754
|
|
|
755
|
+
/** Narrow reusable-header contract for CollectionView-owned row focus presentation. */
|
|
756
|
+
export interface ICollectionViewRowFocusPercentHeader extends IReusable {
|
|
757
|
+
supportsRowFocusPercent: boolean;
|
|
758
|
+
setRowFocusPercent(percent: number, force?: boolean): void;
|
|
759
|
+
}
|
|
760
|
+
|
|
725
761
|
/*******************************************************************
|
|
726
762
|
* Data Source
|
|
727
763
|
*******************************************************************/
|
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
CollectionViewFocusIndicatorTransitionType,
|
|
9
9
|
ICollectionView,
|
|
10
10
|
ICollectionViewFocusManager,
|
|
11
|
+
ICollectionViewCell,
|
|
12
|
+
ICollectionViewFocusPercentRegistration,
|
|
13
|
+
ICollectionViewRowFocusPercentHeader,
|
|
11
14
|
IFocusInfo,
|
|
12
15
|
createFocusInfo,
|
|
13
16
|
} from './CollectionViewAPI';
|
|
@@ -15,6 +18,7 @@ import { BaseCollectionViewLayout } from './BaseCollectionViewLayout';
|
|
|
15
18
|
import { BaseCollectionViewRow } from './BaseCollectionViewRow';
|
|
16
19
|
import type { BaseView } from '@hs-src/hosanna-ui/views/lib/BaseView';
|
|
17
20
|
import type { IHosannaView, ViewState } from '@hs-src/hosanna-ui/views/lib/view-api';
|
|
21
|
+
import { getUniqueViewId } from '@hs-src/hosanna-ui/views/lib/view-api';
|
|
18
22
|
import {
|
|
19
23
|
ContinuousFocusTransitionStrategy,
|
|
20
24
|
ICollectionViewFocusTransitionHost,
|
|
@@ -23,6 +27,22 @@ import {
|
|
|
23
27
|
StartEndFocusTransitionStrategy,
|
|
24
28
|
} from './focusTransitions/CollectionViewFocusTransitionStrategy';
|
|
25
29
|
|
|
30
|
+
interface FocusPercentEndpoint {
|
|
31
|
+
rowKey: string;
|
|
32
|
+
itemIndex: number;
|
|
33
|
+
itemStart: number;
|
|
34
|
+
rowStart: number;
|
|
35
|
+
hasRecipients: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface FocusPercentRowRecipients {
|
|
39
|
+
cells: Record<string, ICollectionViewFocusPercentRegistration>;
|
|
40
|
+
rowCells: ICollectionViewFocusPercentRegistration[];
|
|
41
|
+
cellCount: number;
|
|
42
|
+
header?: ICollectionViewRowFocusPercentHeader;
|
|
43
|
+
lastRowPercent: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
26
46
|
/**
|
|
27
47
|
* `CollectionViewFocusManager` manages the focus rectangle and animations for a collection view.
|
|
28
48
|
* It handles focus transitions, rendering, and applying focus to rows and items.
|
|
@@ -50,9 +70,22 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
50
70
|
private isAnimatingFocus = false;
|
|
51
71
|
|
|
52
72
|
/**
|
|
53
|
-
* The
|
|
73
|
+
* The shared movement clock for the indicator and opt-in percentage recipients.
|
|
74
|
+
* A settled or reset manager has no transition in flight.
|
|
54
75
|
*/
|
|
55
|
-
private focusPercent: number =
|
|
76
|
+
private focusPercent: number = 1;
|
|
77
|
+
|
|
78
|
+
// Keep endpoint history even without recipients for late acquisition and reversals.
|
|
79
|
+
private percentSource: FocusPercentEndpoint | undefined;
|
|
80
|
+
private percentTarget: FocusPercentEndpoint | undefined;
|
|
81
|
+
private percentInFocusChain = false;
|
|
82
|
+
private percentSupplementaryRowKey = '';
|
|
83
|
+
private percentOwnerId = '';
|
|
84
|
+
private percentRows: Record<string, FocusPercentRowRecipients> = {};
|
|
85
|
+
private percentHeaderRows: Record<string, string> = {};
|
|
86
|
+
private percentRecipientCount = 0;
|
|
87
|
+
private percentHasActiveRecipients = false;
|
|
88
|
+
private percentSupplementaryHasRecipients = false;
|
|
56
89
|
|
|
57
90
|
/** Internal transition strategies share this manager's one pooled focus-indicator poster. */
|
|
58
91
|
private continuousTransitionStrategy: ContinuousFocusTransitionStrategy;
|
|
@@ -266,6 +299,7 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
266
299
|
return;
|
|
267
300
|
}
|
|
268
301
|
this.nextFocusInfo = info;
|
|
302
|
+
this.acceptFocusPercentTarget(info);
|
|
269
303
|
this.selectTransitionStrategy(info);
|
|
270
304
|
this.activeTransitionStrategy.onTargetAccepted();
|
|
271
305
|
}
|
|
@@ -275,7 +309,7 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
275
309
|
* @param info - The focus information to set and render.
|
|
276
310
|
* @returns
|
|
277
311
|
*/
|
|
278
|
-
setAndRenderFocusInfo(info: IFocusInfo | undefined): void {
|
|
312
|
+
setAndRenderFocusInfo(info: IFocusInfo | undefined, preserveFocusPercentTransition = false): void {
|
|
279
313
|
if (info === undefined) {
|
|
280
314
|
info = this.nullFocusInfo;
|
|
281
315
|
}
|
|
@@ -286,6 +320,11 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
286
320
|
}
|
|
287
321
|
this.focusInfo = info;
|
|
288
322
|
this.nextFocusInfo = info;
|
|
323
|
+
if (!preserveFocusPercentTransition || this.percentTarget === undefined || this.focusPercent >= 1) {
|
|
324
|
+
this.acceptFocusPercentTarget(info);
|
|
325
|
+
this.focusPercent = 1;
|
|
326
|
+
if (this.percentHasActiveRecipients) this.publishFocusPercents();
|
|
327
|
+
}
|
|
289
328
|
this.selectTransitionStrategy(info);
|
|
290
329
|
this.activeTransitionStrategy.onFocusRendered();
|
|
291
330
|
this.renderTransitionAppearance(1);
|
|
@@ -300,8 +339,9 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
300
339
|
*/
|
|
301
340
|
renderWhileMovingBetweenItems(percent: number): void {
|
|
302
341
|
this.focusPercent = percent;
|
|
303
|
-
this.
|
|
304
|
-
|
|
342
|
+
if (this.percentHasActiveRecipients) this.publishFocusPercents();
|
|
343
|
+
this.activeTransitionStrategy.onProgress(percent);
|
|
344
|
+
if (percent >= 1.0) {
|
|
305
345
|
this.setFocusComplete();
|
|
306
346
|
}
|
|
307
347
|
}
|
|
@@ -413,6 +453,8 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
413
453
|
* Marks the focus transition as complete and applies the focus to the row.
|
|
414
454
|
*/
|
|
415
455
|
setFocusComplete(): void {
|
|
456
|
+
this.focusPercent = 1;
|
|
457
|
+
if (this.percentHasActiveRecipients) this.publishFocusPercents();
|
|
416
458
|
console.debug('CollectionViewFocusManager: Focus transition complete');
|
|
417
459
|
|
|
418
460
|
if (this.focusInfo) {
|
|
@@ -446,6 +488,9 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
446
488
|
if (this.textToSpeechManager.getEnabled()) {
|
|
447
489
|
console.debug('CollectionViewFocusManager: Speaking focus information');
|
|
448
490
|
const focusedRow = this.collectionView.getFocusedRow();
|
|
491
|
+
if (!focusedRow) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
449
494
|
const item = this.collectionView.getFocusedDataSourceItem();
|
|
450
495
|
const currentRowIndex = this.focusInfo.rowIndex;
|
|
451
496
|
const currentItemIndex = this.focusInfo.itemIndex;
|
|
@@ -527,6 +572,22 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
527
572
|
* Called when the collection view is cleared (e.g. DataSourceChangeType.Clear).
|
|
528
573
|
*/
|
|
529
574
|
reset(): void {
|
|
575
|
+
// Invalidate active bindings without delivering into released presentation objects.
|
|
576
|
+
for (const rowKey in this.percentRows) {
|
|
577
|
+
const row = this.percentRows[rowKey];
|
|
578
|
+
for (const itemKey in row.cells) {
|
|
579
|
+
row.cells[itemKey].owner = undefined;
|
|
580
|
+
row.cells[itemKey].cell = undefined;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
this.percentRows = {};
|
|
584
|
+
this.percentHeaderRows = {};
|
|
585
|
+
this.percentRecipientCount = 0;
|
|
586
|
+
this.percentHasActiveRecipients = false;
|
|
587
|
+
this.percentSupplementaryHasRecipients = false;
|
|
588
|
+
this.percentSource = undefined;
|
|
589
|
+
this.percentTarget = undefined;
|
|
590
|
+
this.percentSupplementaryRowKey = '';
|
|
530
591
|
this.focusInfo = this.nullFocusInfo;
|
|
531
592
|
this.nextFocusInfo = this.nullFocusInfo;
|
|
532
593
|
this.isAnimatingFocus = false;
|
|
@@ -534,13 +595,361 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
534
595
|
this.instantTransitionStrategy.reset();
|
|
535
596
|
this.startEndTransitionStrategy.reset();
|
|
536
597
|
this.activeTransitionStrategy = this.continuousTransitionStrategy;
|
|
537
|
-
this.focusPercent =
|
|
598
|
+
this.focusPercent = 1;
|
|
538
599
|
this.lastSpokenRowIndex = -1;
|
|
539
600
|
this.lastSpokenItemIndex = -1;
|
|
540
601
|
this.isFocusShown = false;
|
|
541
602
|
this.updateFocusIndicatorPosterVisibility();
|
|
542
603
|
}
|
|
543
604
|
|
|
605
|
+
/** Registers only realized, opted-in cells. Called after content/style binding. */
|
|
606
|
+
registerFocusPercentCell(cell: ICollectionViewCell, force = false): void {
|
|
607
|
+
if ((!cell.supportsFocusPercent && !cell.supportsRowFocusPercent) || !cell.setFocusPercents) {
|
|
608
|
+
cell._focusPercentRegistration?.owner?.unregisterFocusPercentCell?.(cell);
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
if (this.percentOwnerId === '') this.percentOwnerId = `${getUniqueViewId()}`;
|
|
612
|
+
// Layout already bound this row; do not resolve it again through the collection.
|
|
613
|
+
const cellRow = cell.row;
|
|
614
|
+
const rowKey = cellRow.content?.id || cellRow.id || cellRow.index.toString();
|
|
615
|
+
let registration = cell._focusPercentRegistration;
|
|
616
|
+
if (registration?.owner !== undefined) {
|
|
617
|
+
if (registration.ownerId !== this.percentOwnerId || registration.rowKey !== rowKey || registration.itemIndex !== cell.index
|
|
618
|
+
|| registration.supportsFocusPercent !== (cell.supportsFocusPercent === true)
|
|
619
|
+
|| registration.supportsRowFocusPercent !== (cell.supportsRowFocusPercent === true)) {
|
|
620
|
+
registration.owner.unregisterFocusPercentCell?.(cell);
|
|
621
|
+
} else if (!force
|
|
622
|
+
&& !registration.needsInitialization
|
|
623
|
+
&& (!cell.supportsFocusPercent || cell.focusPercent !== undefined)
|
|
624
|
+
&& (!cell.supportsRowFocusPercent || cell.rowFocusPercent !== undefined)) {
|
|
625
|
+
// Retained bindings receive movement/focus updates through dispatch. Hide,
|
|
626
|
+
// rebind and reset detach them; forced or uninitialized bindings continue below.
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (registration === undefined) {
|
|
631
|
+
registration = {
|
|
632
|
+
cell, rowKey, itemIndex: cell.index, rowCellIndex: -1, ownerId: '',
|
|
633
|
+
supportsFocusPercent: cell.supportsFocusPercent === true,
|
|
634
|
+
supportsRowFocusPercent: cell.supportsRowFocusPercent === true,
|
|
635
|
+
needsInitialization: true,
|
|
636
|
+
};
|
|
637
|
+
cell._focusPercentRegistration = registration;
|
|
638
|
+
}
|
|
639
|
+
if (registration.owner === undefined) {
|
|
640
|
+
registration.owner = this;
|
|
641
|
+
registration.cell = cell;
|
|
642
|
+
registration.ownerId = this.percentOwnerId;
|
|
643
|
+
registration.rowKey = rowKey;
|
|
644
|
+
registration.itemIndex = cell.index;
|
|
645
|
+
registration.rowCellIndex = -1;
|
|
646
|
+
registration.supportsFocusPercent = cell.supportsFocusPercent === true;
|
|
647
|
+
registration.supportsRowFocusPercent = cell.supportsRowFocusPercent === true;
|
|
648
|
+
const row = this.getFocusPercentRowRecipients(rowKey);
|
|
649
|
+
row.cells[cell.index.toString()] = registration;
|
|
650
|
+
row.cellCount++;
|
|
651
|
+
if (cell.supportsRowFocusPercent) {
|
|
652
|
+
registration.rowCellIndex = row.rowCells.length;
|
|
653
|
+
row.rowCells.push(registration);
|
|
654
|
+
// Inactive rows stop sampling. A newly initialized recipient must not
|
|
655
|
+
// inherit the row's old delivery cache, especially across a subsequent blur.
|
|
656
|
+
row.lastRowPercent = -1;
|
|
657
|
+
}
|
|
658
|
+
this.percentRecipientCount++;
|
|
659
|
+
this.refreshFocusPercentRecipients(rowKey);
|
|
660
|
+
force = true;
|
|
661
|
+
}
|
|
662
|
+
force = force || registration.needsInitialization;
|
|
663
|
+
registration.needsInitialization = false;
|
|
664
|
+
this.percentInFocusChain = this.collectionView.isInFocusChain();
|
|
665
|
+
this.publishFocusPercentCell(registration, force);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
unregisterFocusPercentCell(cell: ICollectionViewCell): void {
|
|
669
|
+
const registration = cell._focusPercentRegistration;
|
|
670
|
+
if (registration?.owner === undefined || registration.ownerId !== this.percentOwnerId) return;
|
|
671
|
+
const row = this.percentRows[registration.rowKey];
|
|
672
|
+
if (row !== undefined) {
|
|
673
|
+
delete row.cells[registration.itemIndex.toString()];
|
|
674
|
+
const index = registration.rowCellIndex;
|
|
675
|
+
if (index >= 0) {
|
|
676
|
+
// Cross-cell callback order is unspecified. Keep removal constant-time,
|
|
677
|
+
// and skip the row array entirely for item-only recipients.
|
|
678
|
+
const last = row.rowCells.pop();
|
|
679
|
+
if (last !== undefined && index < row.rowCells.length) {
|
|
680
|
+
row.rowCells[index] = last;
|
|
681
|
+
last.rowCellIndex = index;
|
|
682
|
+
}
|
|
683
|
+
registration.rowCellIndex = -1;
|
|
684
|
+
}
|
|
685
|
+
row.cellCount--;
|
|
686
|
+
if (row.cellCount === 0 && !row.header) delete this.percentRows[registration.rowKey];
|
|
687
|
+
}
|
|
688
|
+
registration.owner = undefined;
|
|
689
|
+
// Break the cell -> storage -> cell cycle while the storage stays reusable.
|
|
690
|
+
registration.cell = undefined;
|
|
691
|
+
this.percentRecipientCount--;
|
|
692
|
+
this.refreshFocusPercentRecipients(registration.rowKey);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
registerRowFocusPercentHeader(rowIndex: number, header: ICollectionViewRowFocusPercentHeader, force = false): void {
|
|
696
|
+
if (!header.supportsRowFocusPercent) return;
|
|
697
|
+
if (!header._hid) header._hid = `${getUniqueViewId()}`;
|
|
698
|
+
const rowKey = this.getFocusPercentRowKey(rowIndex);
|
|
699
|
+
const previousRowKey = this.percentHeaderRows[header._hid];
|
|
700
|
+
if (previousRowKey !== undefined && previousRowKey !== rowKey) {
|
|
701
|
+
this.unregisterRowFocusPercentHeader(header);
|
|
702
|
+
}
|
|
703
|
+
const row = this.getFocusPercentRowRecipients(rowKey);
|
|
704
|
+
if (row.header?._hid !== header._hid) {
|
|
705
|
+
if (!row.header) this.percentRecipientCount++;
|
|
706
|
+
if (row.header?._hid) delete this.percentHeaderRows[row.header._hid];
|
|
707
|
+
row.header = header;
|
|
708
|
+
this.percentHeaderRows[header._hid] = rowKey;
|
|
709
|
+
row.lastRowPercent = -1;
|
|
710
|
+
this.refreshFocusPercentRecipients(rowKey);
|
|
711
|
+
force = true;
|
|
712
|
+
}
|
|
713
|
+
this.percentInFocusChain = this.collectionView.isInFocusChain();
|
|
714
|
+
header.setRowFocusPercent(this.getPublishedRowFocusPercent(rowKey), force);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
unregisterRowFocusPercentHeader(header: ICollectionViewRowFocusPercentHeader): void {
|
|
718
|
+
const id = header._hid;
|
|
719
|
+
if (!id) return;
|
|
720
|
+
const rowKey = this.percentHeaderRows[id];
|
|
721
|
+
if (rowKey === undefined) return;
|
|
722
|
+
delete this.percentHeaderRows[id];
|
|
723
|
+
// Visibility changes detach headers during rendering. Use the saved row,
|
|
724
|
+
// not the header's mutable row binding or a scan of unrelated recipients.
|
|
725
|
+
const row = this.percentRows[rowKey];
|
|
726
|
+
if (row?.header?._hid !== id) return;
|
|
727
|
+
row.header = undefined;
|
|
728
|
+
this.percentRecipientCount--;
|
|
729
|
+
if (row.cellCount === 0) delete this.percentRows[rowKey];
|
|
730
|
+
this.refreshFocusPercentRecipients(rowKey);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
syncFocusPercentFocusChain(): void {
|
|
734
|
+
if (!this.percentHasActiveRecipients) return;
|
|
735
|
+
if (this.percentInFocusChain === this.collectionView.isInFocusChain()) return;
|
|
736
|
+
this.publishFocusPercents();
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
setFocusPercentSupplementary(rowIndex = -1): void {
|
|
740
|
+
const rowKey = rowIndex < 0 ? '' : this.getFocusPercentRowKey(rowIndex);
|
|
741
|
+
if (this.percentSupplementaryRowKey === rowKey) return;
|
|
742
|
+
const previousRowKey = this.percentSupplementaryRowKey;
|
|
743
|
+
this.percentSupplementaryRowKey = rowKey;
|
|
744
|
+
if (this.percentRecipientCount === 0) return;
|
|
745
|
+
this.refreshFocusPercentRecipients();
|
|
746
|
+
this.publishFocusPercents();
|
|
747
|
+
if (previousRowKey !== '') this.publishFocusPercentRow(previousRowKey);
|
|
748
|
+
if (rowKey !== '') this.publishFocusPercentRow(rowKey);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
private getFocusPercentRowKey(rowIndex: number): string {
|
|
752
|
+
const row = this.collectionView.getRowForIndex(rowIndex);
|
|
753
|
+
const contentId = row?.content?.id;
|
|
754
|
+
if (contentId) return contentId;
|
|
755
|
+
const rowId = row?.id;
|
|
756
|
+
if (rowId) return rowId;
|
|
757
|
+
return rowIndex.toString();
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
private getFocusPercentRowRecipients(rowKey: string): FocusPercentRowRecipients {
|
|
761
|
+
let row = this.percentRows[rowKey];
|
|
762
|
+
if (row === undefined) {
|
|
763
|
+
row = { cells: {}, rowCells: [], cellCount: 0, lastRowPercent: -1 };
|
|
764
|
+
this.percentRows[rowKey] = row;
|
|
765
|
+
}
|
|
766
|
+
return row;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/** Membership changes at target/registration boundaries, never on movement ticks. */
|
|
770
|
+
private refreshFocusPercentRecipients(changedRowKey?: string): void {
|
|
771
|
+
const source = this.percentSource;
|
|
772
|
+
const target = this.percentTarget;
|
|
773
|
+
if (source !== undefined && (changedRowKey === undefined || source.rowKey === changedRowKey)) {
|
|
774
|
+
source.hasRecipients = this.hasFocusPercentRecipients(source);
|
|
775
|
+
}
|
|
776
|
+
if (target !== undefined && (changedRowKey === undefined || target.rowKey === changedRowKey)) {
|
|
777
|
+
target.hasRecipients = this.hasFocusPercentRecipients(target);
|
|
778
|
+
}
|
|
779
|
+
if (changedRowKey === undefined || this.percentSupplementaryRowKey === changedRowKey) {
|
|
780
|
+
const supplementary = this.percentRows[this.percentSupplementaryRowKey];
|
|
781
|
+
this.percentSupplementaryHasRecipients = supplementary !== undefined
|
|
782
|
+
&& (supplementary.rowCells.length > 0 || supplementary.header !== undefined);
|
|
783
|
+
}
|
|
784
|
+
this.percentHasActiveRecipients = source?.hasRecipients === true
|
|
785
|
+
|| target?.hasRecipients === true
|
|
786
|
+
|| this.percentSupplementaryHasRecipients;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
private hasFocusPercentRecipients(endpoint: FocusPercentEndpoint): boolean {
|
|
790
|
+
if (this.percentRecipientCount === 0) return false;
|
|
791
|
+
const row = this.percentRows[endpoint.rowKey];
|
|
792
|
+
if (row === undefined) return false;
|
|
793
|
+
if (row.rowCells.length > 0 || row.header !== undefined) return true;
|
|
794
|
+
return row.cells[endpoint.itemIndex.toString()]?.cell?.supportsFocusPercent === true;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
private acceptFocusPercentTarget(info: IFocusInfo): void {
|
|
798
|
+
const rowKey = this.getFocusPercentRowKey(info.rowIndex);
|
|
799
|
+
const previousTarget = this.percentTarget;
|
|
800
|
+
if (previousTarget !== undefined) {
|
|
801
|
+
if (previousTarget.rowKey === rowKey) {
|
|
802
|
+
if (previousTarget.itemIndex === info.itemIndex) return;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
const previousSource = this.percentSource;
|
|
806
|
+
// Save the retiring identity before reusing the records. A third destination
|
|
807
|
+
// must still clear its old source even when the new pair has no listeners.
|
|
808
|
+
const retiredRowKey = previousSource?.rowKey;
|
|
809
|
+
const retiredItemIndex = previousSource?.itemIndex ?? -1;
|
|
810
|
+
const retireSource = previousSource?.hasRecipients === true;
|
|
811
|
+
// A completed transition has only one focused endpoint. Only interruptions need
|
|
812
|
+
// interpolation; normal focus changes can use the known settled values directly.
|
|
813
|
+
const isSettled = this.focusPercent >= 1;
|
|
814
|
+
const targetItemStart = isSettled ? 0 : this.getLogicalItemFocusPercent(rowKey, info.itemIndex);
|
|
815
|
+
let targetRowStart = 0;
|
|
816
|
+
if (isSettled) {
|
|
817
|
+
if (previousTarget !== undefined) {
|
|
818
|
+
if (previousTarget.rowKey === rowKey) targetRowStart = 1;
|
|
819
|
+
}
|
|
820
|
+
} else {
|
|
821
|
+
targetRowStart = this.getLogicalRowFocusPercent(rowKey);
|
|
822
|
+
}
|
|
823
|
+
let source: FocusPercentEndpoint | undefined;
|
|
824
|
+
if (previousTarget !== undefined) {
|
|
825
|
+
const itemStart = isSettled ? 1 : this.getLogicalItemFocusPercent(previousTarget.rowKey, previousTarget.itemIndex);
|
|
826
|
+
const rowStart = isSettled ? 1 : this.getLogicalRowFocusPercent(previousTarget.rowKey);
|
|
827
|
+
// Sample both endpoints before mutating either retained record.
|
|
828
|
+
if (previousSource !== undefined) {
|
|
829
|
+
source = previousSource;
|
|
830
|
+
source.rowKey = previousTarget.rowKey;
|
|
831
|
+
source.itemIndex = previousTarget.itemIndex;
|
|
832
|
+
source.itemStart = itemStart;
|
|
833
|
+
source.rowStart = rowStart;
|
|
834
|
+
} else {
|
|
835
|
+
source = { rowKey: previousTarget.rowKey, itemIndex: previousTarget.itemIndex, itemStart, rowStart, hasRecipients: false };
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
this.percentSource = source;
|
|
839
|
+
if (previousTarget !== undefined) {
|
|
840
|
+
previousTarget.rowKey = rowKey;
|
|
841
|
+
previousTarget.itemIndex = info.itemIndex;
|
|
842
|
+
previousTarget.itemStart = targetItemStart;
|
|
843
|
+
previousTarget.rowStart = targetRowStart;
|
|
844
|
+
} else {
|
|
845
|
+
this.percentTarget = { rowKey, itemIndex: info.itemIndex, itemStart: targetItemStart, rowStart: targetRowStart, hasRecipients: false };
|
|
846
|
+
}
|
|
847
|
+
this.focusPercent = 0;
|
|
848
|
+
// Keep transition history for first acquisition and reversals, but do not
|
|
849
|
+
// resolve membership in an empty registry. Registration refreshes it when
|
|
850
|
+
// the first recipient arrives; final removal clears the cached flags.
|
|
851
|
+
if (this.percentRecipientCount === 0) return;
|
|
852
|
+
this.refreshFocusPercentRecipients();
|
|
853
|
+
this.publishFocusPercents();
|
|
854
|
+
// Third destinations retire old endpoints once; no growing collection of trailing animations.
|
|
855
|
+
if (retireSource && retiredRowKey !== undefined) {
|
|
856
|
+
this.publishFocusPercentRow(retiredRowKey);
|
|
857
|
+
this.publishFocusPercentEndpoint(retiredRowKey, retiredItemIndex);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
private getLogicalItemFocusPercent(rowKey: string, itemIndex: number): number {
|
|
862
|
+
// Bound samples on consumption, not on callbacks-disabled movement ticks. The
|
|
863
|
+
// indicator retains its original progress semantics, including the negative guard.
|
|
864
|
+
const progress = this.focusPercent;
|
|
865
|
+
const target = this.percentTarget;
|
|
866
|
+
if (target?.rowKey === rowKey && target.itemIndex === itemIndex) {
|
|
867
|
+
if (progress >= 1) return 1;
|
|
868
|
+
if (progress <= 0) return target.itemStart;
|
|
869
|
+
return target.itemStart + (1 - target.itemStart) * progress;
|
|
870
|
+
}
|
|
871
|
+
const source = this.percentSource;
|
|
872
|
+
if (source?.rowKey === rowKey && source.itemIndex === itemIndex) {
|
|
873
|
+
if (progress >= 1) return 0;
|
|
874
|
+
if (progress <= 0) return source.itemStart;
|
|
875
|
+
return source.itemStart * (1 - progress);
|
|
876
|
+
}
|
|
877
|
+
return 0;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
private getLogicalRowFocusPercent(rowKey: string): number {
|
|
881
|
+
const progress = this.focusPercent;
|
|
882
|
+
const target = this.percentTarget;
|
|
883
|
+
if (target?.rowKey === rowKey) {
|
|
884
|
+
if (progress >= 1) return 1;
|
|
885
|
+
if (progress <= 0) return target.rowStart;
|
|
886
|
+
return target.rowStart + (1 - target.rowStart) * progress;
|
|
887
|
+
}
|
|
888
|
+
const source = this.percentSource;
|
|
889
|
+
if (source?.rowKey === rowKey) {
|
|
890
|
+
if (progress >= 1) return 0;
|
|
891
|
+
if (progress <= 0) return source.rowStart;
|
|
892
|
+
return source.rowStart * (1 - progress);
|
|
893
|
+
}
|
|
894
|
+
return 0;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
private getPublishedRowFocusPercent(rowKey: string): number {
|
|
898
|
+
if (!this.percentInFocusChain) return 0;
|
|
899
|
+
if (this.percentSupplementaryRowKey !== '') return this.percentSupplementaryRowKey === rowKey ? 1 : 0;
|
|
900
|
+
return this.getLogicalRowFocusPercent(rowKey);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
private publishFocusPercentCell(registration: ICollectionViewFocusPercentRegistration, force = false): void {
|
|
904
|
+
// Only active row membership reaches publication.
|
|
905
|
+
const cell = registration.cell!;
|
|
906
|
+
const itemPercent = this.percentInFocusChain && this.percentSupplementaryRowKey === ''
|
|
907
|
+
? this.getLogicalItemFocusPercent(registration.rowKey, registration.itemIndex)
|
|
908
|
+
: 0;
|
|
909
|
+
const rowPercent = this.getPublishedRowFocusPercent(registration.rowKey);
|
|
910
|
+
if (!force
|
|
911
|
+
&& (!cell.supportsFocusPercent || cell.focusPercent === itemPercent)
|
|
912
|
+
&& (!cell.supportsRowFocusPercent || cell.rowFocusPercent === rowPercent)) return;
|
|
913
|
+
cell.setFocusPercents?.(itemPercent, rowPercent, force);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
private publishFocusPercentEndpoint(rowKey: string, itemIndex: number): void {
|
|
917
|
+
const registration = this.percentRows[rowKey]?.cells[itemIndex.toString()];
|
|
918
|
+
if (registration?.cell?.supportsFocusPercent) this.publishFocusPercentCell(registration);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
private publishFocusPercentRow(rowKey: string): void {
|
|
922
|
+
const row = this.percentRows[rowKey];
|
|
923
|
+
if (!row) return;
|
|
924
|
+
const rowPercent = this.getPublishedRowFocusPercent(rowKey);
|
|
925
|
+
if (row.lastRowPercent === rowPercent) return;
|
|
926
|
+
row.lastRowPercent = rowPercent;
|
|
927
|
+
// Swap-removal during a callback can only move an already visited tail into
|
|
928
|
+
// an earlier slot. Equal samples are skipped, so remaining cells are not missed.
|
|
929
|
+
for (let index = row.rowCells.length - 1; index >= 0; index--) {
|
|
930
|
+
const registration = row.rowCells[index];
|
|
931
|
+
// A callback may remove several cells and shorten the array past this slot.
|
|
932
|
+
if (registration !== undefined) this.publishFocusPercentCell(registration);
|
|
933
|
+
}
|
|
934
|
+
row.header?.setRowFocusPercent(rowPercent);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
private publishFocusPercents(): void {
|
|
938
|
+
if (!this.percentHasActiveRecipients) return;
|
|
939
|
+
this.percentInFocusChain = this.collectionView.isInFocusChain();
|
|
940
|
+
const source = this.percentSource;
|
|
941
|
+
const target = this.percentTarget;
|
|
942
|
+
if (source?.hasRecipients) {
|
|
943
|
+
this.publishFocusPercentRow(source.rowKey);
|
|
944
|
+
this.publishFocusPercentEndpoint(source.rowKey, source.itemIndex);
|
|
945
|
+
}
|
|
946
|
+
if (target?.hasRecipients) {
|
|
947
|
+
this.publishFocusPercentRow(target.rowKey);
|
|
948
|
+
this.publishFocusPercentEndpoint(target.rowKey, target.itemIndex);
|
|
949
|
+
}
|
|
950
|
+
if (this.percentSupplementaryHasRecipients) this.publishFocusPercentRow(this.percentSupplementaryRowKey);
|
|
951
|
+
}
|
|
952
|
+
|
|
544
953
|
/**
|
|
545
954
|
* Applies focus to the currently focused row in the collection view.
|
|
546
955
|
* @param focused - Whether the collection view remains in the focus chain.
|