File size: 5,014 Bytes
e9a4c3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dcd43e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// ---------------------------------------------------------------------------
// sheet/index.ts β€” the Sheet MODULE's route vocabulary, and nothing else.
//
// ⭐⭐ WAVE 49 Β· T01 (owner rulings R1, R2, R30) β€” Sheet is its own module.
//   R1  the module is called `Sheet`.
//   R2  a rail row immediately above `Data`, carrying the ordinary view rail with exactly ONE
//       view kind. Time-series and Chart views stay INTACT and are neither merged nor deprecated
//       (`customer-grid/types.ts::DISPLAY_MODES` is untouched by this ticket, on purpose).
//   R30 Sheet sits at the HEAD of the data band: Home Β· Starred Β· Inbox | Assistant Β· Agents |
//       Sheet Β· Data Β· Connectors.
//
// β›” WHY THE ROUTE CONSTANT LIVES HERE AND NOT IN `shell/nav.ts`, WHERE ITS SIBLINGS DO.
// The other chrome routes (`CONNECTORS_ROUTE`, `INBOX_ROUTE`, `STARRED_ROUTE` …) are declared in
// `shell/nav.ts`, and this constant would sit beside them if the ticket that added it owned that
// file. W49-T01's `files` fence does not include `shell/nav.ts`, so widening the fence to reach it
// was the one thing not on offer. Placing it here costs nothing the shell notices: `nav.ts::
// CHROME_ROUTES` has exactly ONE runtime consumer β€” `firstDestination`, which answers the LANDING
// question β€” and `sheet` is not in `LANDING_PREFERENCE`, so membership changes no behaviour today.
// Reachability comes from elsewhere and was read rather than assumed: `Shell.tsx`'s hash-normaliser
// rewrites only `route === LOGIN_ROUTE || route === ""`, and `nav.ts::resolveRoute` answers an
// unknown key with `undefined` (its fallback is `home`, which is chrome and therefore matches no
// nav entry) β€” so `#/sheet` renders its own branch instead of being bounced to Home.
// ⚠ MOVING IT INTO `CHROME_ROUTES` LATER IS A SAFE, PURELY ADDITIVE EDIT and is the tidier home
// for it; it is recorded in this ticket's handoff rather than done behind the fence.
//
// β›” THIS FILE IS NOT A BARREL. It deliberately does NOT re-export `SheetPage`: the shell reaches
// the page through `lazy(() => import("../sheet/SheetPage"))`, and a re-export here would pull the
// page into whatever chunk imports this constant β€” which is the entry chunk β€” making the lazy
// split cosmetic (see `shell/Shell.tsx`'s route-splitting note).
//
// β›” THE WORKBOOK / CELL VOCABULARY IS **NOT** HERE. `sheet/types.ts` belongs to W49-T02 and owns
// the cell, range and workbook types. This file carries the route and the view kind the rail
// paints, which is all T01 is allowed to know.
// ---------------------------------------------------------------------------

/** The hash route the rail row points at: `#/sheet`. */
export const SHEET_ROUTE = "sheet";

/**
 * The ONE view kind the Sheet rail offers (R2).
 *
 * ⚠ A LITERAL OF ITS OWN, NOT A MEMBER OF `customer-grid/types.ts::DISPLAY_MODES`. Adding `sheet`
 * to that union would edit the file where Time-series and Chart live, which R2 forbids touching β€”
 * and it would offer Sheet as a display mode of a customer-grid view, which is precisely the
 * "merged view" the ruling rejected in favour of a separate module.
 */
export const SHEET_VIEW_KIND = "sheet";

/** C2: null means no workbook was named; even an empty wb parameter is an explicit request. */
export type SheetAddress = {
  wb: string | null;
  tab?: string;
  cell?: string;
  chart?: string;
};

/** Route vocabulary only, keeping SheetPage in its lazy chunk. */
export function readSheetAddress(hash: string): SheetAddress | null {
  const route = hash.replace(/^#\/?/, "").split("#")[0];
  const queryAt = route.indexOf("?");
  if ((queryAt < 0 ? route : route.slice(0, queryAt)) !== SHEET_ROUTE) return null;
  const query = new URLSearchParams(queryAt < 0 ? "" : route.slice(queryAt + 1));
  const cell = query.get("cell") ?? "";
  return {
    wb: query.get("wb"),
    tab: query.get("tab") || undefined,
    cell: /^[A-Za-z]+[1-9]\d*$/.test(cell) ? cell.toUpperCase() : undefined,
    chart: query.get("chart") || undefined,
  };
}

export function sheetAddressHash(address: SheetAddress): string {
  if (address.wb === null) return `#/${SHEET_ROUTE}`;
  const query = new URLSearchParams({ wb: address.wb });
  if (address.tab) query.set("tab", address.tab);
  if (address.cell) query.set("cell", address.cell);
  if (address.chart) query.set("chart", address.chart);
  return `#/${SHEET_ROUTE}?${query.toString()}`;
}

/** Match the shell's History API notification; ordinary choices retain a Back entry. */
export function writeSheetAddress(address: SheetAddress, mode: "push" | "replace" = "push"): void {
  const hash = sheetAddressHash(address);
  if (window.location.hash === hash) return;
  const oldURL = window.location.href;
  if (mode === "replace") window.history.replaceState(window.history.state, "", hash);
  else window.history.pushState(window.history.state, "", hash);
  window.dispatchEvent(new HashChangeEvent("hashchange", { oldURL, newURL: window.location.href }));
}