Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download web/src/sheet/ribbonView.tsx from fsanyoto/runloopable: direct link, hf CLI and curl.
- Browser
- Download file 11 kB
-
https://huggingface.co/spaces/fsanyoto/runloopable/resolve/main/web/src/sheet/ribbonView.tsx
- Command line
-
hf download hf://spaces/fsanyoto/runloopable/web/src/sheet/ribbonView.tsx
-
curl -L -o ribbonView.tsx https://huggingface.co/spaces/fsanyoto/runloopable/resolve/main/web/src/sheet/ribbonView.tsx
11 kB
| // 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; | |