Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 10,982 Bytes
82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 c1fc133 82cdb59 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | // 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 (
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className="sheet-ribbon-icon">
<rect x="2.3" y="3.2" width="11.4" height="9.6" rx="1" />
<path d="M6.1 3.2v9.6M9.9 3.2v9.6M2.3 6.4h11.4M2.3 9.6h11.4" />
</svg>
);
}
function IconPageBreak() {
return (
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className="sheet-ribbon-icon">
<rect x="2.3" y="3.2" width="11.4" height="9.6" rx="1" />
<path d="M8 3.2v9.6M2.3 8h11.4" strokeDasharray="2 2" />
</svg>
);
}
function IconPageLayout() {
return (
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className="sheet-ribbon-icon">
<rect x="3.2" y="1.8" width="9.6" height="12.4" rx="1" />
<rect x="5.2" y="4.2" width="5.6" height="7.6" rx="0.5" />
</svg>
);
}
function IconGridlines() {
return (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon">
<rect x="2.3" y="3.2" width="11.4" height="9.6" rx="1" />
<path d="M8 3.2v9.6M2.3 8h11.4" />
</svg>
);
}
function IconHeadings() {
return (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon">
<path d="M2.3 3.2h11.4v3H5.3v6.6h-3Z" fill="currentColor" fillOpacity="0.18" stroke="none" />
<rect x="2.3" y="3.2" width="11.4" height="9.6" rx="1" />
<path d="M5.3 3.2v9.6M2.3 6.2h11.4" />
</svg>
);
}
function IconZoom() {
return (
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className="sheet-ribbon-icon">
<circle cx="6.7" cy="6.7" r="4.2" />
<path d="m9.8 9.8 3.7 3.7" />
</svg>
);
}
function IconZoomReset() {
return (
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className="sheet-ribbon-icon">
<path d="M3.2 5.2A5.1 5.1 0 1 1 2.9 10M3.2 2.5v3.1h3.1M7 6.3l1-.8v5" />
</svg>
);
}
function IconZoomSelection() {
return (
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className="sheet-ribbon-icon">
<path d="M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10" />
<rect x="5.5" y="5.5" width="5" height="5" rx="0.5" />
</svg>
);
}
function IconFreeze() {
return (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon">
<rect x="2.4" y="2.4" width="11.2" height="11.2" rx="1" />
<path d="M6.2 2.4v11.2M2.4 6.2h11.2" />
</svg>
);
}
function IconHide() {
return (
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className="sheet-ribbon-icon">
<path d="M6.5 4.2A6.6 6.6 0 0 1 8 4c3.7 0 6 4 6 4a12 12 0 0 1-2.1 2.5M9.5 11.8A6.6 6.6 0 0 1 8 12c-3.7 0-6-4-6-4a12 12 0 0 1 2.1-2.5M2.5 2.5l11 11" />
<path d="M6.6 6.6a2 2 0 0 0 2.8 2.8" />
</svg>
);
}
function IconUnhide() {
return (
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className="sheet-ribbon-icon">
<path d="M2 8s2.3-4 6-4 6 4 6 4-2.3 4-6 4-6-4-6-4Z" />
<circle cx="8" cy="8" r="2" />
</svg>
);
}
function IconNewWindow() {
return (
<svg viewBox="0 0 16 16" stroke="currentColor" aria-hidden="true" className="sheet-ribbon-icon">
<rect x="5.5" y="5.5" width="8" height="8" rx="1" />
<path d="M10.5 5.5v-2a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2" />
</svg>
);
}
function IconFullScreen() {
return (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon">
<path d="M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10" />
</svg>
);
}
function IconGoTo() {
return (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon">
<circle cx="8" cy="8" r="5.2" />
<circle cx="8" cy="8" r="1.8" />
</svg>
);
}
// R19 changes the shape only. Split stays unavailable until the grid supports two scroll origins.
function IconSplit() {
return <svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon"><path d="M2 2h12v12H2ZM8 2v12M2 8h12" strokeDasharray="2 1" /></svg>;
}
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<SheetTabView>) => 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", <><IconNormal />{word("Normal")}</>,
() => setView({ pageView: "normal" }), pageView === "normal", undefined, "L")}
</>)}
{stack(
<>
{control("view-page-break", "Page Break Preview", <IconPageBreak />,
() => setView({ pageView: "pageBreak" }), pageView === "pageBreak", undefined, "P")}
</>,
<>
{control("view-page-layout", "Page Layout", <IconPageLayout />,
() => setView({ pageView: "pageLayout" }), pageView === "pageLayout", undefined, "K")}
</>
)}
</>)}
{group("Show", stack(
<>
{control(
"view-gridlines", "Gridlines", <IconGridlines />,
() => setView({ gridlines: !gridlines }), gridlines, undefined, "G",
)}
</>,
<>
{control(
"view-headings", "Headings", <IconHeadings />,
() => setView({ headings: !headings }), headings, undefined, "H",
)}
</>
))}
{group("Zoom", <>
{large(<>
{control("view-zoom", "Zoom", <><IconZoom />{word(`${Math.round(zoomPercent)}%`)}</>,
openPop("view-zoom"), false, open === "view-zoom", "Q", "gallery")}
</>)}
{open === "view-zoom" && (
<AnchoredOverlay
anchor={anchorEl}
className="sheet-ribbon-pop sheet-ribbon-pop-portal"
onDismiss={closePop}
role="menu"
ariaLabel="Zoom"
initialFocus="none"
>
{ZOOM_STEPS.map(percent => item(
`${percent}%`, () => { setView({ zoom: percent }); closePop(); },
percent === zoomPercent, "menuitemradio",
))}
</AnchoredOverlay>
)}
{stack(
<>
{control("view-zoom-100", "100%", <IconZoomReset />,
() => setView({ zoom: 100 }), zoomPercent === 100, undefined, "J")}
</>,
<>
{control("view-zoom-selection", "Zoom to Selection",
<IconZoomSelection />,
zoomToSelection, false, undefined, "S")}
</>
)}
</>)}
{group("Window", <>
{large(<>
{control(
"view-freeze", "Freeze Panes", <><IconFreeze />{word("Freeze Panes")}</>,
() => act("freeze"), frozen, undefined, "F",
)}
</>)}
{stack(
<>
{control(
"view-new-window", "New Window", <IconNewWindow />,
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", <IconSplit />)}
</>
)}
{stack(
<>
{control("view-hide", "Hide", <IconHide />,
() => ctx.insert?.onTabVisibility?.(ctx.insert.tabId ?? "", "hidden"),
false, undefined, "D", undefined, !ctx.insert?.canHideTab)}
</>,
<>
{control("view-unhide", "Unhide", <IconUnhide />,
openPop("view-unhide"), false, open === "view-unhide", "E", "gallery")}
</>
)}
{open === "view-unhide" && (
<AnchoredOverlay anchor={anchorEl} className="sheet-ribbon-pop sheet-ribbon-pop-portal"
onDismiss={closePop} role="menu" ariaLabel="Unhide a Sheet" initialFocus="none">
{hidden.length
? hidden.map(sheet => item(sheet.name, () => {
ctx.insert?.onTabVisibility?.(sheet.id, "visible");
closePop();
}))
: <p className="sheet-ribbon-state" role="status">No sheets are hidden.</p>}
</AnchoredOverlay>
)}
{newWindowBlocked && (
<span className="sheet-ribbon-state sheet-ribbon-window-message" role="status">
The browser blocked the new window. Allow popups for this site.
</span>
)}
</>)}
{group("Screen", large(control(
"view-fullscreen", fullscreenLabel,
<><IconFullScreen />{word(fullscreenLabel)}</>,
toggleFullscreen, fullscreen, undefined, "U",
)))}
{group("Navigation", large(control(
"view-go-to", "Go To", <><IconGoTo />{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;
|