// Sheet View ribbon, adapted from the behavior and grouping in the Wave 55 public Excel audit.
// Workbook Views, Show and Zoom use the tab view.
import type { RibbonTabContext } from "./Ribbon";
import type { SheetTabView } from "./types";
import { AnchoredOverlay } from "../customer-grid/OverlaySurface";
const WORKBOOK_VIEWS = ["view-normal", "view-page-break", "view-page-layout"] as const;
const SHOW = ["view-gridlines", "view-headings"] as const;
const ZOOM = ["view-zoom", "view-zoom-100", "view-zoom-selection"] as const;
const ZOOM_STEPS = [10, 25, 50, 75, 100, 125, 150, 200, 300, 400] as const;
const WINDOW = ["view-new-window", "view-freeze", "view-hide", "view-unhide", "view-fullscreen"] as const;
const NAVIGATION = ["view-go-to"] as const;
export const VIEW_KEYS = [...WORKBOOK_VIEWS, ...SHOW, ...ZOOM, ...WINDOW, ...NAVIGATION] as const;
function IconNormal() {
return (
);
}
function IconPageBreak() {
return (
);
}
function IconPageLayout() {
return (
);
}
function IconGridlines() {
return (
);
}
function IconHeadings() {
return (
);
}
function IconZoom() {
return (
);
}
function IconZoomReset() {
return (
);
}
function IconZoomSelection() {
return (
);
}
function IconFreeze() {
return (
);
}
function IconHide() {
return (
);
}
function IconUnhide() {
return (
);
}
function IconNewWindow() {
return (
);
}
function IconFullScreen() {
return (
);
}
function IconGoTo() {
return (
);
}
// R19 changes the shape only. Split stays unavailable until the grid supports two scroll origins.
function IconSplit() {
return ;
}
export const viewGroups = (ctx: RibbonTabContext) => {
const view = ctx.insert?.view;
const hidden = ctx.insert?.hiddenTabs ?? [];
const gridlines = view?.gridlines !== false;
const headings = view?.headings !== false;
const zoomPercent = view?.zoom ?? 100;
const pageView = view?.pageView ?? "normal";
const setView = (patch: Partial) => ctx.insert?.onTabView?.(patch);
const zoomToSelection = () => ctx.insert?.zoomToSelection?.();
const {
act, anchorEl, closePop, control, frozen, fullscreen, group, item,
newWindowBlocked, open, openNewWindow, openPop,
toggleFullscreen, unavailable, word, large, stack,
} = ctx;
const fullscreenLabel = fullscreen ? "Exit Full Screen" : "Full Screen";
return (
<>
{group("Workbook Views", <>
{large(<>
{control("view-normal", "Normal", <>{word("Normal")}>,
() => setView({ pageView: "normal" }), pageView === "normal", undefined, "L")}
>)}
{stack(
<>
{control("view-page-break", "Page Break Preview", ,
() => setView({ pageView: "pageBreak" }), pageView === "pageBreak", undefined, "P")}
>,
<>
{control("view-page-layout", "Page Layout", ,
() => setView({ pageView: "pageLayout" }), pageView === "pageLayout", undefined, "K")}
>
)}
>)}
{group("Show", stack(
<>
{control(
"view-gridlines", "Gridlines", ,
() => setView({ gridlines: !gridlines }), gridlines, undefined, "G",
)}
>,
<>
{control(
"view-headings", "Headings", ,
() => setView({ headings: !headings }), headings, undefined, "H",
)}
>
))}
{group("Zoom", <>
{large(<>
{control("view-zoom", "Zoom", <>{word(`${Math.round(zoomPercent)}%`)}>,
openPop("view-zoom"), false, open === "view-zoom", "Q", "gallery")}
>)}
{open === "view-zoom" && (
{ZOOM_STEPS.map(percent => item(
`${percent}%`, () => { setView({ zoom: percent }); closePop(); },
percent === zoomPercent, "menuitemradio",
))}
)}
{stack(
<>
{control("view-zoom-100", "100%", ,
() => setView({ zoom: 100 }), zoomPercent === 100, undefined, "J")}
>,
<>
{control("view-zoom-selection", "Zoom to Selection",
,
zoomToSelection, false, undefined, "S")}
>
)}
>)}
{group("Window", <>
{large(<>
{control(
"view-freeze", "Freeze Panes", <>{word("Freeze Panes")}>,
() => act("freeze"), frozen, undefined, "F",
)}
>)}
{stack(
<>
{control(
"view-new-window", "New Window", ,
openNewWindow, undefined, undefined, "W",
)}
>,
<>
{/* ⛔ THE ONE CONTROL ON THIS TAB THAT STILL READS UNAVAILABLE, AND IT SAYS SO ON
PURPOSE. W60-T22 could not land Split safely: the grid keeps ONE lockstep scroll
axis, driven one way from the main grid into the frozen band, and
`sheetState.ts::chartPaneProjections` models a FREEZE quadrant with a single scroll
origin. Labelling the gap is honest; a button that did nothing would not be. The
full cause is in lanes/B/LANE_CONTEXT.md. ⚠ W61-T12 MADE THIS ICON ONLY, so the
word "Split" now reaches a reader ONLY through `unavailable()`'s own status text
and the tooltip: that is the whole of the explanation on screen. */}
{unavailable("Split", )}
>
)}
{stack(
<>
{control("view-hide", "Hide", ,
() => ctx.insert?.onTabVisibility?.(ctx.insert.tabId ?? "", "hidden"),
false, undefined, "D", undefined, !ctx.insert?.canHideTab)}
>,
<>
{control("view-unhide", "Unhide", ,
openPop("view-unhide"), false, open === "view-unhide", "E", "gallery")}
>
)}
{open === "view-unhide" && (
{hidden.length
? hidden.map(sheet => item(sheet.name, () => {
ctx.insert?.onTabVisibility?.(sheet.id, "visible");
closePop();
}))
: No sheets are hidden.
}
)}
{newWindowBlocked && (
The browser blocked the new window. Allow popups for this site.
)}
>)}
{group("Screen", large(control(
"view-fullscreen", fullscreenLabel,
<>{word(fullscreenLabel)}>,
toggleFullscreen, fullscreen, undefined, "U",
)))}
{group("Navigation", large(control(
"view-go-to", "Go To", <>{word("Go To")}>,
() => act("go-to"), false, undefined, "N",
)))}
>
);
};
export const VIEW_TAB = {
id: "view",
key: "tab-view",
kt: "W",
label: "View",
bodyClass: "sheet-ribbon-view",
toolbarLabel: "View",
keys: VIEW_KEYS,
groups: viewGroups,
} as const;