Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(sheets): enter @ dates as date values and pick them from an @date calendar (#8160)
teob3668bc6cdd3
diff --git a/apps/web/src/features/block-spreadsheet/README.md b/apps/web/src/features/block-spreadsheet/README.mdindex 2f0b54b777..d3d6db7379 100644--- a/apps/web/src/features/block-spreadsheet/README.md+++ b/apps/web/src/features/block-spreadsheet/README.md@@ -386,6 +386,12 @@ compare formula, error, and formatting behavior before replacing it.goes through the normal commit and validation, written the way the cell storesdates (`core/cell-date.ts`): a serial keeps its time of day, a date pill stays apill, ISO text stays ISO, and other text becomes month/day/year.+ Dates from the cell editor's `@` menu (`@today`, `@tomorrow`, `@friday` and so+ on) enter as typed date text in the locale's order, not a pill, so a cell+ holding only that date commits as a date value like any typed date; around+ other text it stays text. `@date` shows the same calendar in place of the menu+ (`views/DateMentionMenu.tsx`), starting at today: it takes the calendar's keys+ before the editor, Enter or a click enters the day, and Escape closes it.Plain text treats formula-looking input literally. Wrapped rows grow to 160px at100% zoom; larger content remains available in the formula bar/editor.- Internal copying preserves formatting and translates relative/mixed referencesdiff --git a/apps/web/src/features/block-spreadsheet/browser-test/README.md b/apps/web/src/features/block-spreadsheet/browser-test/README.mdindex 24c7d0a6bf..54a6688d09 100644--- a/apps/web/src/features/block-spreadsheet/browser-test/README.md+++ b/apps/web/src/features/block-spreadsheet/browser-test/README.md@@ -117,6 +117,10 @@ explicit test document/socket query parameters are supplied.## Editor interaction regressions+`spreadsheet.browser.e2e.ts` also enters `@` dates (a menu pick, and the `@date`+calendar by keyboard, pointer and Escape) as date values that `=A6+30`, `DATEDIF`+and the Excel download read as dates; the phone suite taps an `@date` day.+`range-move.browser.e2e.ts` drags a selection by its border: the destinationoutline and label, formulas following the moved cells, a single undo, theconfirmation before replacing values, auto-scroll past the grid's bottom edge,diff --git a/apps/web/src/features/block-spreadsheet/browser-test/fixture.tsx b/apps/web/src/features/block-spreadsheet/browser-test/fixture.tsxindex 30909b7cfd..6cd2163a8f 100644--- a/apps/web/src/features/block-spreadsheet/browser-test/fixture.tsx+++ b/apps/web/src/features/block-spreadsheet/browser-test/fixture.tsx@@ -22,6 +22,7 @@ import type { SpreadsheetWorkbookSheet } from '../core/workbook-document';import { createLocalSpreadsheetSource } from '../primitives/create-local-spreadsheet-source';import { createSpreadsheetStore } from '../primitives/create-spreadsheet-store';import { createSpreadsheetSession } from '../queries/spreadsheet-session';+import { DateMentionMenu } from '../views/DateMentionMenu';import { SpreadsheetEditor } from '../views/SpreadsheetEditor';declare global {@@ -132,26 +133,40 @@ function Fixture() {<CellMentionEditor{...props}convertPaste={(value) => value}- renderMenu={(menu, _anchor, pick) => (- <button- type="button"- class="fixed right-4 top-4 z-[100]"- aria-label="Mention Taylor"- onPointerDown={(e) => e.preventDefault()}- onMouseDown={(e) => e.preventDefault()}- onClick={() =>- pick(- encodeCellMention({- type: 'user',- userId: 'macro|[email protected]',- email: '[email protected]',- displayName: 'Taylor',- })- )- }- >- Taylor ({menu.searchTerm()})- </button>+ renderMenu={(menu, anchor, pick) => (+ <DateMentionMenu menu={menu} anchor={anchor} pick={pick}>+ {(pickDate) => (+ <div class="fixed right-4 top-4 z-[100] flex gap-2">+ <button+ type="button"+ aria-label="Mention Taylor"+ onPointerDown={(e) => e.preventDefault()}+ onMouseDown={(e) => e.preventDefault()}+ onClick={() =>+ pick(+ encodeCellMention({+ type: 'user',+ userId: 'macro|[email protected]',+ email: '[email protected]',+ displayName: 'Taylor',+ })+ )+ }+ >+ Taylor ({menu.searchTerm()})+ </button>+ <button+ type="button"+ aria-label="Pick today"+ onPointerDown={(e) => e.preventDefault()}+ onMouseDown={(e) => e.preventDefault()}+ onClick={() => pickDate(new Date())}+ >+ Today+ </button>+ </div>+ )}+ </DateMentionMenu>)}/>),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.tsindex 32e83d5b5c..670b9c79cd 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@@ -1016,6 +1016,103 @@ test('mention editing switches back from formulas and leaves other inputs focusa).toBeFocused();});+test('@ dates enter date values that formulas and Excel read as dates', async ({+ page,+}) => {+ await page.clock.setFixedTime(new Date(2026, 9, 16, 12));+ await page.goto('/?mentions');+ await expect(page.locator('[data-address="B4"]')).toHaveText('30');+ await page.locator('[data-address="A6"]').dblclick();+ const editor = page.getByRole('textbox', { name: 'Edit A6', exact: true });+ await editor.pressSequentially('@tod');+ await page.getByRole('button', { name: 'Pick today' }).click();+ await expect(editor).toBeFocused();+ await expect(editor).toHaveText('10/16/2026 ');+ await expect(editor.locator('[data-cell-mention]')).toHaveCount(0);+ await editor.press('Enter');+ await expect(page.locator('[data-address="A6"]')).toHaveText('10/16/2026');+ // Stored like a typed date: its serial number, shown as a date.+ expect(+ await page.evaluate(() => window.spreadsheetFixture.snapshot()[0].cells.A6)+ ).toEqual({ value: '46311', format: 'date' });++ for (const [address, formula] of [+ ['B6', '=A6+30'],+ ['C6', '=DATEDIF(A6,B6,"d")'],+ ]) {+ await page.locator(`[data-address="${address}"]`).dblclick();+ await page+ .getByRole('textbox', { name: `Edit ${address}`, exact: true })+ .pressSequentially(formula);+ await page.keyboard.press('Enter');+ }+ await expect(page.locator('[data-address="B6"]')).toHaveText('11/15/2026');+ await expect(page.locator('[data-address="C6"]')).toHaveText('30');++ 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 workbook = new ExcelJS.Workbook();+ await workbook.xlsx.readFile(path);+ const cell = workbook.worksheets[0].getCell('A6');+ expect(cell.value).toEqual(new Date(Date.UTC(2026, 9, 16)));+ expect(cell.numFmt).toMatch(/[dy]/);+});++test('@date opens a calendar that picks a day by keyboard or pointer while the cell keeps its draft', async ({+ page,+}) => {+ await page.clock.setFixedTime(new Date(2026, 9, 16, 12));+ await page.goto('/?mentions');+ await expect(page.locator('[data-address="B4"]')).toHaveText('30');+ const picker = page.locator('[data-cell-date-picker]');++ await page.locator('[data-address="A6"]').dblclick();+ let editor = page.getByRole('textbox', { name: 'Edit A6', exact: true });+ await editor.pressSequentially('@date');+ await expect(picker).toBeVisible();+ await expect(picker.locator('[data-active]')).toHaveText('16');+ await editor.press('ArrowRight');+ await expect(picker.locator('[data-active]')).toHaveText('17');+ await editor.press('Enter');+ await expect(picker).toBeHidden();+ await expect(editor).toBeFocused();+ await expect(editor).toHaveText('10/17/2026 ');+ await editor.press('Enter');+ await expect(page.locator('[data-address="A6"]')).toHaveText('10/17/2026');++ // Around other text, the date stays text.+ await page.locator('[data-address="A7"]').dblclick();+ editor = page.getByRole('textbox', { name: 'Edit A7', exact: true });+ await editor.pressSequentially('Due @date');+ await picker+ .getByRole('gridcell', { name: '15', exact: true, disabled: false })+ .click();+ await expect(picker).toBeHidden();+ await expect(editor).toBeFocused();+ await expect(editor).toHaveText('Due 10/15/2026 ');+ await editor.press('Enter');+ await expect(page.locator('[data-address="A7"]')).toHaveText(+ 'Due 10/15/2026'+ );++ await page.locator('[data-address="A8"]').dblclick();+ editor = page.getByRole('textbox', { name: 'Edit A8', exact: true });+ await editor.pressSequentially('@date');+ await expect(picker).toBeVisible();+ await editor.press('Escape');+ await expect(picker).toBeHidden();+ await expect(editor).toBeFocused();+ await expect(editor).toHaveText('@date');++ const cells = await page.evaluate(+ () => window.spreadsheetFixture.snapshot()[0].cells+ );+ expect(cells.A6).toEqual({ value: '46312', format: 'date' });+ expect(cells.A7).toEqual({ value: 'Due 10/15/2026 ' });+});+test('header menu keyboard navigation keeps the targeted row selected', async ({page,}) => {diff --git a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.tsindex 4768080abe..e4a6887a20 100644--- a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts+++ b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts@@ -348,6 +348,32 @@ test('touch formatting and sheet navigation preserve workbook state', async ({await expect(addressBar(page)).toHaveValue('A2');});+test('touch taps pick an @date day on screen without dropping the cell editor', async ({+ page,+}) => {+ await page.clock.setFixedTime(new Date(2026, 9, 16, 12));+ await page.goto('/?mentions');+ await expect(cell(page, 'B4')).toHaveText('30');+ await cell(page, 'A6').tap();+ await cell(page, 'A6').tap();+ const input = page.getByRole('textbox', { name: 'Edit A6' });+ await expect(input).toBeFocused();+ await input.pressSequentially('@date');+ const picker = page.locator('[data-cell-date-picker]');+ await expectInsideViewport(page, picker);+ await picker+ .getByRole('gridcell', { name: '15', exact: true, disabled: false })+ .tap();+ await expect(picker).toBeHidden();+ await expect(input).toBeFocused();+ await expect(input).toHaveText('10/15/2026 ');+ await button(page, 'Apply edit').tap();+ await expect(cell(page, 'A6')).toHaveText('10/15/2026');+ expect(+ await page.evaluate(() => window.spreadsheetFixture.snapshot()[0].cells.A6)+ ).toEqual({ value: '46310', format: 'date' });+});+test('tapping another dropdown cell moves the open list there, and other cells close it', async ({page,}) => {diff --git a/apps/web/src/features/block-spreadsheet/core/cell-dates.test.ts b/apps/web/src/features/block-spreadsheet/core/cell-dates.test.tsindex b16822b011..d878c49766 100644--- a/apps/web/src/features/block-spreadsheet/core/cell-dates.test.ts+++ b/apps/web/src/features/block-spreadsheet/core/cell-dates.test.ts@@ -1,6 +1,11 @@import { format as formatExcelNumber } from 'ssf';import { describe, expect, it } from 'vitest';-import { dateFormatStyle, parseTypedDate, typedDateText } from './cell-dates';+import {+ dateFormatStyle,+ parseTypedDate,+ typedDateText,+ typedDayText,+} from './cell-dates';import { SPREADSHEET_DATE_FORMATS } from './toolbar-types';const isoDate = (serial: number) => formatExcelNumber('yyyy-mm-dd', serial);@@ -99,6 +104,18 @@ describe('typed dates', () => {).toBe(serial);});+ it('enters a picked local day as text that reads back as that day', () => {+ // Late in the evening, so a UTC conversion would land on the next day.+ const day = new Date(2026, 9, 16, 23, 59);+ expect(typedDayText(day, 'en-US')).toBe('10/16/2026');+ expect(typedDayText(day, 'en-GB')).toBe('16/10/2026');+ expect(typedDayText(day, 'ja-JP')).toBe('2026/10/16');+ for (const locale of ['en-US', 'en-GB', 'de-DE', 'ja-JP'])+ expect(+ parseTypedDate(`${typedDayText(day, locale)} `, locale)?.serial+ ).toBe(46311);+ });+it('leaves times of day and out-of-range serials to the raw number', () => {expect(typedDateText(46023.5, 'en-US')).toBeUndefined();expect(typedDateText(60, 'en-US')).toBeUndefined();diff --git a/apps/web/src/features/block-spreadsheet/core/cell-dates.ts b/apps/web/src/features/block-spreadsheet/core/cell-dates.tsindex c5533c0580..f8bdebd302 100644--- a/apps/web/src/features/block-spreadsheet/core/cell-dates.ts+++ b/apps/web/src/features/block-spreadsheet/core/cell-dates.ts@@ -225,6 +225,15 @@ export function typedDateText(}}+/**+ * A local calendar day as the numeric date `parseTypedDate` reads back in the+ * same locale, for entering a picked day as if it were typed.+ */+export function typedDayText(day: Date, locale: string): string | undefined {+ const time = Date.UTC(day.getFullYear(), day.getMonth(), day.getDate());+ return typedDateText((time - SERIAL_EPOCH) / DAY_MILLISECONDS, locale);+}+const readDateFormat = Result.fromThrowable((code: string): SpreadsheetCellStyle | undefined => {if (!is_date(code)) return;diff --git a/apps/web/src/features/block-spreadsheet/spreadsheet-mentions.tsx b/apps/web/src/features/block-spreadsheet/spreadsheet-mentions.tsxindex 578c05b99c..0ce4c03a12 100644--- a/apps/web/src/features/block-spreadsheet/spreadsheet-mentions.tsx+++ b/apps/web/src/features/block-spreadsheet/spreadsheet-mentions.tsx@@ -20,6 +20,7 @@ import ClockIcon from '@phosphor/clock.svg';import { For, Suspense } from 'solid-js';import type { SpreadsheetMentions } from './context/spreadsheet-mentions';import { SpreadsheetCellLinks } from './spreadsheet-cell-links';+import { DateMentionMenu } from './views/DateMentionMenu';export function linkMentions(value: string,@@ -61,14 +62,12 @@ function fromItem(item: MentionItem): string | undefined {documentName: item.data.name ?? '',blockName: getBlockNameFromEntity(item),});- if (item.kind === 'date')- return encodeCellMention({- type: 'date',- date: item.data.date.toISOString(),- displayFormat: item.data.displayText,- });}-/** Same chip as docs, without the picker: edit the cell to change the date. */+/**+ * Same chip as docs, without the picker: edit the cell to change the date.+ * The `@` menu enters dates as date values, so chips come from older cells+ * and AI edits.+ */function CellDateChip(props: CellDateMention) {const date = () => new Date(props.date);return (@@ -127,16 +126,21 @@ function SpreadsheetMentionEditor(props: CellTextEditorProps) {{...props}convertPaste={(text) => linkMentions(text, resolveAppLink)}renderMenu={(menu, anchor, pick) => (- <MentionsMenu- menu={menu}- anchor={anchor}- sources={['users', 'documents', 'channels', 'emails', 'dates']}- showOpenTabs={false}- onPick={(item) => {- const value = fromItem(item);- if (value) pick(value);- }}- />+ <DateMentionMenu menu={menu} anchor={anchor} pick={pick}>+ {(pickDate) => (+ <MentionsMenu+ menu={menu}+ anchor={anchor}+ sources={['users', 'documents', 'channels', 'emails', 'dates']}+ showOpenTabs={false}+ onPick={(item) => {+ if (item.kind === 'date') return pickDate(item.data.date);+ const value = fromItem(item);+ if (value) pick(value);+ }}+ />+ )}+ </DateMentionMenu>)}/>);diff --git a/apps/web/src/features/block-spreadsheet/views/DateMentionMenu.test.tsx b/apps/web/src/features/block-spreadsheet/views/DateMentionMenu.test.tsxnew file mode 100644index 0000000000..97ef65536c--- /dev/null+++ b/apps/web/src/features/block-spreadsheet/views/DateMentionMenu.test.tsx@@ -0,0 +1,65 @@+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';+import { createSignal, Show } from 'solid-js';+import { afterEach, describe, expect, it, vi } from 'vitest';+import { DateMentionMenu } from './DateMentionMenu';++describe('dates from the @ menu', () => {+ afterEach(() => {+ cleanup();+ vi.useRealTimers();+ });++ function renderMenu(term: string) {+ vi.useFakeTimers({ toFake: ['Date'] });+ vi.setSystemTime(new Date(2026, 9, 16, 23, 30));+ const pick = vi.fn();+ const [open, setOpen] = createSignal(true);+ const anchor = document.createElement('span');+ document.body.append(anchor);+ render(() => (+ <Show when={open()}>+ <DateMentionMenu+ menu={{ searchTerm: () => term, closeMenu: () => setOpen(false) }}+ anchor={anchor}+ pick={pick}+ >+ {(pickDate) => (+ <button type="button" onClick={() => pickDate(new Date())}>+ Today+ </button>+ )}+ </DateMentionMenu>+ </Show>+ ));+ return { pick, open };+ }++ it('enters a picked day as typed date text, not a chip', () => {+ const { pick } = renderMenu('tod');+ fireEvent.click(screen.getByRole('button', { name: 'Today' }));+ expect(pick).toHaveBeenCalledWith('10/16/2026');+ });++ it('shows a calendar for @date whose keys pick a day before the editor sees them', () => {+ const { pick } = renderMenu('date');+ const editor = document.createElement('div');+ document.body.append(editor);+ const editorKeys = vi.fn();+ editor.addEventListener('keydown', editorKeys);+ expect(document.querySelector('[data-cell-date-picker]')).not.toBeNull();+ fireEvent.keyDown(editor, { key: 'ArrowRight' });+ fireEvent.keyDown(editor, { key: 'ArrowDown' });+ fireEvent.keyDown(editor, { key: 'Enter' });+ expect(pick).toHaveBeenCalledWith('10/24/2026');+ expect(editorKeys).not.toHaveBeenCalled();+ editor.remove();+ });++ it('closes the @date calendar on Escape without picking', () => {+ const { pick, open } = renderMenu('Date');+ fireEvent.keyDown(document.body, { key: 'Escape' });+ expect(open()).toBe(false);+ expect(pick).not.toHaveBeenCalled();+ expect(document.querySelector('[data-cell-date-picker]')).toBeNull();+ });+});diff --git a/apps/web/src/features/block-spreadsheet/views/DateMentionMenu.tsx b/apps/web/src/features/block-spreadsheet/views/DateMentionMenu.tsxnew file mode 100644index 0000000000..b0e559db4e--- /dev/null+++ b/apps/web/src/features/block-spreadsheet/views/DateMentionMenu.tsx@@ -0,0 +1,72 @@+import { createSignal, type JSX, onCleanup, onMount, Show } from 'solid-js';+import { CellDatePicker, datePickerKeyDay } from '../components/CellDatePicker';+import { typedDayText } from '../core/cell-dates';++/**+ * A cell editor's `@` menu that enters dates as typed date text, so a cell+ * holding only a picked date commits as a date value, as if it were typed.+ * `@date` shows a calendar in place of the menu.+ */+export function DateMentionMenu(props: {+ menu: { searchTerm: () => string; closeMenu: () => void };+ anchor: HTMLElement;+ pick: (text: string) => void;+ children: (pickDate: (day: Date) => void) => JSX.Element;+}) {+ // Commits read typed numeric dates in the browser locale's order.+ const pickDate = (day: Date) => {+ const text = typedDayText(day, navigator.language);+ if (text) props.pick(text);+ };+ return (+ <Show+ when={props.menu.searchTerm().trim().toLowerCase() === 'date'}+ fallback={props.children(pickDate)}+ >+ <MentionDatePicker+ anchor={props.anchor}+ onPick={pickDate}+ onClose={props.menu.closeMenu}+ />+ </Show>+ );+}++/**+ * The `@date` calendar. The editor keeps focus and its draft, so this takes+ * the calendar's keys before the editor does: arrows and Page Up/Down move the+ * day from today, Enter picks it and Escape closes the calendar.+ */+function MentionDatePicker(props: {+ anchor: HTMLElement;+ onPick: (day: Date) => void;+ onClose: () => void;+}) {+ const now = new Date();+ const [day, setDay] = createSignal(+ new Date(now.getFullYear(), now.getMonth(), now.getDate())+ );+ onMount(() => {+ const keyDown = (event: KeyboardEvent) => {+ if (event.isComposing) return;+ const next = datePickerKeyDay(event, day());+ if (next) setDay(next);+ else if (event.key === 'Enter') props.onPick(day());+ else if (event.key === 'Escape') props.onClose();+ else return;+ event.preventDefault();+ event.stopPropagation();+ };+ document.addEventListener('keydown', keyDown, true);+ onCleanup(() => document.removeEventListener('keydown', keyDown, true));+ });+ return (+ <CellDatePicker+ anchor={props.anchor}+ day={day()}+ onDayChange={setDay}+ onPick={props.onPick}+ onDismiss={props.onClose}+ />+ );+}diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.mdindex 39add0f7c5..0bd2e4f526 100644--- a/docs/agent-guide/documents.md+++ b/docs/agent-guide/documents.md@@ -434,10 +434,17 @@ or use the formula bar to edit link text. AI `set_cells` accepts Macro URLs or tsame `<m-user-mention>` / `<m-document-mention>` / `<m-date-mention>` encoding as docs.Formula references to mention cells use literal labels, never execute a label as a formula.-Dates: `@tomorrow`, `@next friday` or `@sep 28` offer a **Dates** bucket and insert-the same clock chip as docs; hover it for the full date, and edit the cell to change-it. A cell holding only a date chip is a date value: `=A1+7` produces a date, and-Excel export writes a dated number rather than the label. Typing a date stores it+Dates: `@today`, `@tomorrow`, `@next friday` or `@sep 28` offer a **Dates** bucket.+Choosing one enters the date as text such as `10/16/2026` (in the browser locale's+day/month order), not a chip, so a cell holding only that date becomes a date value+like any typed date; around other text it stays text. Typing `@date` shows a+calendar (`[data-cell-date-picker]`) in place of the menu, starting at today: arrow+keys and Page Up/Down move the highlighted day, Enter or a click enters it, Escape+closes it, and the cell editor keeps focus throughout. Date chips written earlier,+or by AI `set_cells`, still show as clock chips; hover one for the full date, and+edit the cell to change it. A cell holding only a date chip is a date value:+`=A1+7` produces a date, and Excel export writes a dated number rather than the+label. Typing a date stores itas a date in a matching format: `01/2026` or `Jan 2026` shows `Jan 2026`,`Jan 01 2026` shows `Jan 01, 2026`, `2026-01-01` stays ISO and `1/1/26` shows`1/1/2026` (day first in day-first browser locales). The snapshot value is the