Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

composerControlsOwnership.ts

35 lines1.7 KB

1/**
2 * Where the permissions chip shows, whether the mode block overflows, and which control answers
3 * the composer.mode shortcut. The model picker's footer always holds Permissions, so the chip
4 * only shows while the mode differs from the default. The rule: composer.mode has one target.
5 */
6export function resolveComposerControlsOwnership(input: {
7 /** Permissions hide while the mode is the default, or while the new-thread strip names it. */
8 readonly matchesDefault: boolean;
9 readonly planModeUiEnabled: boolean;
10 readonly collapsed: boolean;
11 /** How many trailing blocks the width measurement moved into the overflow menu. */
12 readonly measuredHiddenBlockCount: number;
13}) {
14 const accessDisplay = input.matchesDefault
15 ? ("hidden" as const)
16 : input.collapsed
17 ? ("icon" as const)
18 : ("label" as const);
19 const showModeBlock = accessDisplay !== "hidden" || input.planModeUiEnabled;
20 const modeHidden = showModeBlock && input.measuredHiddenBlockCount > 0;
21 const hiddenBlockIds = modeHidden ? (["mode"] as const) : ([] as const);
22 // An overflowed chip needs a home for Permissions only when the Plan toggle is not there to fill
23 // the overflow menu; otherwise Permissions stay in the model picker.
24 const overflowShowsPermissions =
25 modeHidden && accessDisplay !== "hidden" && !input.planModeUiEnabled;
26 return {
27 accessDisplay,
28 showModeBlock,
29 hiddenBlockCount: hiddenBlockIds.length,
30 hiddenBlockIds,
31 overflowShowsPermissions,
32 /** Without a visible chip or an overflow menu holding it, the model picker answers composer.mode. */
33 pickerOwnsModeShortcut: !overflowShowsPermissions && (accessDisplay === "hidden" || modeHidden),
34 };