Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(sheets): make gridlines visible and save them per sheet (#8126)

teoc7dcd38c6432
diff --git a/apps/web/src/features/block-spreadsheet/README.md b/apps/web/src/features/block-spreadsheet/README.md
index 7693bbcbd0..ac1ebe895b 100644
--- a/apps/web/src/features/block-spreadsheet/README.md
+++ b/apps/web/src/features/block-spreadsheet/README.md
@@ -10,7 +10,12 @@ spreadsheet, then choose **Import…**.
The document title sits above a compact formatting ribbon. **Paste special** offers
paste and values-only paste; **View options** toggles gridlines, the formula bar,
-and formula display. **Functions** inserts formulas, while **Format and data**
+and formula display. Gridlines are saved with each sheet (`metadata.gridlines`,
+Excel's `showGridLines`), so only editors change them; the formula bar and
+formula display are local. Gridlines are the app's ink at 12% over the cell
+background (Google Sheets' `#e2e3e3` on white), in every theme. A fill hides the
+gridlines around its cell, and a border replaces the gridline it lies on.
+**Functions** inserts formulas, while **Format and data**
contains sorting, whitespace trimming, Goal Seek, fill, and clear actions. **Find and replace**
is a direct ribbon button. The footer's **Import and export** button also contains
Excel and CSV downloads and stays visible beside horizontally scrolling sheet tabs.
diff --git a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.ts b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.ts
index 90d168210a..32e83d5b5c 100644
--- a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.ts
+++ b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.ts
@@ -220,6 +220,85 @@ test('view options toggle display directly and return focus to the selected cell
await expect(grid).toBeFocused();
});
+test('saves gridlines with each sheet and keeps them through Excel', async ({
+ page,
+}) => {
+ const option = page.getByRole('menuitemcheckbox', {
+ name: 'Gridlines',
+ exact: true,
+ });
+ async function toggleGridlines() {
+ await page
+ .getByRole('button', { name: 'View options', exact: true })
+ .click();
+ await option.click();
+ await page.keyboard.press('Escape');
+ }
+ const cell = page.locator('[data-address="C3"]');
+ const hidden = 'rgba(0, 0, 0, 0)';
+ await page.getByRole('button', { name: 'Add sheet', exact: true }).click();
+ await expect(
+ page.getByRole('tab', { name: 'Sheet2', exact: true })
+ ).toHaveAttribute('aria-selected', 'true');
+ await page.getByRole('tab', { name: 'Sheet1', exact: true }).click();
+ await expect(cell).not.toHaveCSS('border-bottom-color', hidden);
+
+ await toggleGridlines();
+ await expect(cell).toHaveCSS('border-bottom-color', hidden);
+ expect(
+ await page.evaluate(() =>
+ window.spreadsheetFixture
+ .snapshot()
+ .map((sheet) => [sheet.name, sheet.metadata?.gridlines])
+ )
+ ).toEqual([
+ ['Sheet1', false],
+ ['Sheet2', undefined],
+ ]);
+ await page.getByRole('button', { name: 'Undo', exact: true }).click();
+ await expect(cell).not.toHaveCSS('border-bottom-color', hidden);
+ await page.getByRole('button', { name: 'Redo', exact: true }).click();
+ await expect(cell).toHaveCSS('border-bottom-color', hidden);
+
+ await page.getByRole('tab', { name: 'Sheet2', exact: true }).click();
+ await expect(cell).not.toHaveCSS('border-bottom-color', hidden);
+ await page.getByRole('tab', { name: 'Sheet1', exact: true }).click();
+ await expect(cell).toHaveCSS('border-bottom-color', hidden);
+
+ const downloaded = page.waitForEvent('download');
+ await menu(page, 'Import and export', 'Download as Excel (.xlsx)');
+ const path = await (await downloaded).path();
+ if (!path) throw new Error('Workbook download missing');
+ const exported = new ExcelJS.Workbook();
+ await exported.xlsx.readFile(path);
+ expect(exported.getWorksheet('Sheet1')!.views[0]?.showGridLines).toBe(false);
+ expect(exported.getWorksheet('Sheet2')!.views[0]?.showGridLines).not.toBe(
+ false
+ );
+
+ const input = new ExcelJS.Workbook();
+ input
+ .addWorksheet('No gridlines', { views: [{ showGridLines: false }] })
+ .getCell('A1').value = 'Imported';
+ await page.getByLabel('Import spreadsheet file').setInputFiles({
+ name: 'no-gridlines.xlsx',
+ mimeType:
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+ buffer: Buffer.from(await input.xlsx.writeBuffer()),
+ });
+ await page
+ .getByRole('button', { name: 'Import workbook', exact: true })
+ .click();
+ await expect(page.locator('[data-address="A1"]')).toHaveText('Imported');
+ await expect(cell).toHaveCSS('border-bottom-color', hidden);
+
+ await page.evaluate(() => window.spreadsheetFixture.setReadonly(true));
+ await page.getByRole('button', { name: 'View options', exact: true }).click();
+ await expect(option).toHaveAttribute('aria-checked', 'false');
+ await expect(option).toBeDisabled();
+ await page.keyboard.press('Escape');
+});
+
test('creates and renames sheets, recalculates cross-sheet formulas, and protects viewer edits', async ({
page,
}) => {
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetActionMenus.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetActionMenus.tsx
index 36070926f5..ad837dc8ee 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetActionMenus.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetActionMenus.tsx
@@ -174,6 +174,7 @@ export function ViewMenu(props: SpreadsheetToolbarProps) {
<Dropdown.Group>
<Dropdown.CheckboxItem
checked={props.showGridlines}
+ disabled={props.readonly}
onChange={() => props.onCommand('toggle-gridlines')}
>
Gridlines
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx
index 8a703d7f6c..0798007288 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx
@@ -895,6 +895,27 @@ describe('spreadsheet presentation', () => {
);
});
+ it('hides the gridlines a fill covers and those a neighboring border replaces', () => {
+ const view = renderGrid({
+ B2: { value: '', fillColor: '#fff2cc' },
+ B5: { value: 'Total', borderTop: true, borderTopColor: '#123456' },
+ E2: { value: '', borderLeft: true, borderLeftColor: '#123456' },
+ });
+ const style = (address: string) =>
+ view.container.querySelector<HTMLElement>(`[data-address="${address}"]`)!
+ .style;
+ expect(style('B2').borderRightColor).toBe('transparent');
+ expect(style('B2').borderBottomColor).toBe('transparent');
+ expect(style('A2').borderRightColor).toBe('transparent');
+ expect(style('B1').borderBottomColor).toBe('transparent');
+ expect(style('B4').borderBottomColor).toBe('transparent');
+ expect(style('D2').borderRightColor).toBe('transparent');
+ expect(style('B5').borderTopStyle).toBe('solid');
+ expect(style('E2').borderLeftStyle).toBe('solid');
+ expect(style('C3').borderRight).toBe('');
+ expect(style('C3').borderBottom).toBe('');
+ });
+
it('uses wrapped row geometry for active and range outlines at different zoom levels', () => {
const view = renderGrid(
{ A1: { value: 'one\ntwo\nthree', wrap: true } },
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
index a2ad3e910b..e288e3301a 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
@@ -1320,7 +1320,7 @@ export function SpreadsheetGrid(props: {
<div
role="columnheader"
aria-label="Select all cells"
- class="sticky left-0 z-30 shrink-0 border-b border-r border-edge bg-panel"
+ class="sticky left-0 z-30 shrink-0 border-b border-r border-ink/12 bg-panel"
style={{ width: `${headerWidth()}px` }}
>
<button
@@ -1347,7 +1347,7 @@ export function SpreadsheetGrid(props: {
width: width(column),
left: `${columnOffsets()[column]}px`,
}}
- class="absolute top-0 bottom-0 border-b border-r border-edge-muted"
+ class="absolute top-0 bottom-0 border-b border-r border-ink/12"
classList={{
'bg-accent-bg text-accent':
column >= bounds().left && column <= bounds().right,
@@ -1472,7 +1472,7 @@ export function SpreadsheetGrid(props: {
>
<div
role="rowheader"
- class="sticky left-0 z-10 shrink-0 border-b border-r border-edge-muted bg-panel text-center text-ink-muted select-none"
+ class="sticky left-0 z-10 shrink-0 border-b border-r border-ink/12 bg-panel text-center text-ink-muted select-none"
style={{
width: `${headerWidth()}px`,
'font-size': `${11 * scale()}px`,
@@ -1612,8 +1612,9 @@ export function SpreadsheetGrid(props: {
: 'solid';
return `${width}px ${line} ${cellBorderColor(cell()?.[`border${edge}Color`], fill())}`;
};
- // A fill covers the gridlines around its cell, as in
- // Excel; the right and bottom lines are drawn here.
+ // A fill covers the gridlines around its cell and a
+ // border replaces the gridline it lies on, as in Excel;
+ // the right and bottom lines are drawn here.
const gridline = (edge: 'Right' | 'Bottom') => {
const next = cellAddress(
edge === 'Right'
@@ -1623,7 +1624,10 @@ export function SpreadsheetGrid(props: {
return props.showGridlines === false ||
fill() ||
props.values[next]?.conditional?.fillColor ||
- props.cells[next]?.fillColor
+ props.cells[next]?.fillColor ||
+ props.cells[next]?.[
+ edge === 'Right' ? 'borderLeft' : 'borderTop'
+ ]
? '1px solid transparent'
: undefined;
};
@@ -1745,7 +1749,7 @@ export function SpreadsheetGrid(props: {
'var(--spreadsheet-cell-padding-y)',
'line-height': CELL_LINE_HEIGHT,
}}
- class="absolute top-0 bottom-0 flex flex-col border-b border-r border-edge-muted bg-panel text-ink select-none"
+ class="absolute top-0 bottom-0 flex flex-col border-b border-r border-ink/12 bg-panel text-ink select-none"
classList={{
'font-semibold': look()?.bold ?? cell()?.bold,
'tabular-nums': numeric(),
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetSkeleton.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetSkeleton.tsx
index b0f2a88d9c..d41d98e7fb 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetSkeleton.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetSkeleton.tsx
@@ -38,13 +38,13 @@ export function SpreadsheetSkeleton(props: { label?: string }) {
aria-hidden="true"
>
<div
- class="shrink-0 border-b border-r border-edge"
+ class="shrink-0 border-b border-r border-ink/12"
style={{ width: `${ROW_HEADER_WIDTH}px` }}
/>
<For each={COLUMNS}>
{(column) => (
<div
- class="flex shrink-0 items-center justify-center border-b border-r border-edge-muted text-[11px] font-medium opacity-60"
+ class="flex shrink-0 items-center justify-center border-b border-r border-ink/12 text-[11px] font-medium opacity-60"
style={{ width: `${DEFAULT_COLUMN_WIDTH}px` }}
>
{String.fromCharCode(65 + column)}
@@ -57,7 +57,7 @@ export function SpreadsheetSkeleton(props: { label?: string }) {
{(row) => (
<div class="flex" style={{ height: `${ROW_HEIGHT}px` }}>
<div
- class="flex shrink-0 items-center justify-center border-b border-r border-edge-muted bg-panel text-[11px] text-ink-muted opacity-60 select-none"
+ class="flex shrink-0 items-center justify-center border-b border-r border-ink/12 bg-panel text-[11px] text-ink-muted opacity-60 select-none"
style={{ width: `${ROW_HEADER_WIDTH}px` }}
>
{row + 1}
@@ -67,7 +67,7 @@ export function SpreadsheetSkeleton(props: { label?: string }) {
const bar = placeholder(row, column);
return (
<div
- class="flex shrink-0 items-center border-b border-r border-edge-muted px-1.5"
+ class="flex shrink-0 items-center border-b border-r border-ink/12 px-1.5"
classList={{ 'justify-end': bar && !bar.start }}
style={{ width: `${DEFAULT_COLUMN_WIDTH}px` }}
>
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.test.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.test.tsx
index 59172ebfb2..1fa9810104 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.test.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.test.tsx
@@ -177,6 +177,23 @@ describe('spreadsheet toolbar', () => {
expect(view.onCommand).toHaveBeenCalledWith('toggle-gridlines');
});
+ it('keeps view-only display settings available but not the saved gridlines', async () => {
+ const view = toolbar({ readonly: true });
+ fireEvent.keyDown(view.getByRole('button', { name: 'View options' }), {
+ key: 'ArrowDown',
+ });
+ const gridlines = await screen.findByRole('menuitemcheckbox', {
+ name: 'Gridlines',
+ });
+ expect(gridlines.getAttribute('aria-disabled')).toBe('true');
+ fireEvent.keyDown(gridlines, { key: 'Enter' });
+ fireEvent.keyDown(
+ screen.getByRole('menuitemcheckbox', { name: 'Formula bar' }),
+ { key: 'Enter' }
+ );
+ expect(view.onCommand.mock.calls).toEqual([['toggle-formula-bar']]);
+ });
+
it('closes a top menu with Escape and restores editor focus without executing a command', async () => {
const editor = document.createElement('textarea');
document.body.append(editor);
diff --git a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
index df14f26f95..b5fd6e2e45 100644
--- a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
+++ b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
@@ -97,7 +97,8 @@ export function SpreadsheetEditor(props: {
let editorElement!: HTMLElement;
let importInput!: HTMLInputElement;
const [zoom, setZoom] = createSignal(100);
- const [showGridlines, setShowGridlines] = createSignal(true);
+ const showGridlines = () =>
+ props.store.activeSheet().metadata?.gridlines !== false;
const [showFormulaBar, setShowFormulaBar] = createSignal(true);
const [showFormulas, setShowFormulas] = createSignal(false);
const [structureBusy, setStructureBusy] = createSignal(false);
@@ -524,7 +525,13 @@ export function SpreadsheetEditor(props: {
void workbookActions.exportExcel();
})
.with('add-rows', () => props.store.appendRows(100))
- .with('toggle-gridlines', () => setShowGridlines((value) => !value))
+ .with('toggle-gridlines', () => {
+ if (!editable()) return;
+ props.store.setMetadata({
+ ...props.store.activeSheet().metadata,
+ gridlines: showGridlines() ? false : undefined,
+ });
+ })
.with('toggle-formula-bar', () => setShowFormulaBar((value) => !value))
.with('toggle-formulas', () => setShowFormulas((value) => !value))
.with('sort-asc', () => {
diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.md
index 191566b273..28294dee38 100644
--- a/docs/agent-guide/documents.md
+++ b/docs/agent-guide/documents.md
@@ -324,8 +324,10 @@ Excel black text and borders on unfilled cells follow the app's foreground color
so imported sheets remain readable in dark mode. Explicit text/fill color pairs
remain unchanged; theme changes never alter saved or exported workbook colors.
-**View options** directly toggles gridlines, the formula bar, and formula display;
-these settings and zoom are local to the editor. **Go to cell** accepts ranges such
+**View options** directly toggles gridlines, the formula bar, and formula display.
+Gridlines are saved with the active sheet, undo like an edit, export as Excel's
+`showGridLines`, and are disabled for viewers; the formula bar, formula display,
+and zoom are local to the editor. **Go to cell** accepts ranges such
as `A3:E7`.
Escape from the address or font-size field returns keyboard navigation to the grid.
**Functions** starts an editable formula: for a selected range it proposes
diff --git a/packages/spreadsheet/src/workbook-metadata.ts b/packages/spreadsheet/src/workbook-metadata.ts
index 98b0ee7773..238507a554 100644
--- a/packages/spreadsheet/src/workbook-metadata.ts
+++ b/packages/spreadsheet/src/workbook-metadata.ts
@@ -27,7 +27,7 @@ export type WorkbookSheetMetadata = {
definedNames?: { name: string; formula: string; local?: boolean }[];
/** Legacy (Ctrl+Shift+Enter) array formulas: anchor address → fixed range. */
arrayFormulas?: Record<string, string>;
- /** False when Excel hid this sheet's gridlines. */
+ /** False when the sheet hides its gridlines (Excel's `showGridLines="0"`). */
gridlines?: boolean;
/** Sheet tab color as #RRGGBB. */
tabColor?: string;