Google Doc
The canonical page
Written by Commit
Implementation plan
An author changes words, images, and layout on a preview of the page. Commit writes those changes into the Doc. Publish renders the last committed revision and uploads a static snapshot to Cloudflare. Sign-in is Google, and edit rights are whatever Google already grants on that Doc.
The canonical page
Written by Commit
Uncommitted page structure
Written by Typing, images, layout
Static HTML, CSS, and copied assets
Written by Publish
The preview is a draft. After every commit the server re-reads the Doc, and the editor renders that result.
01
The signed-in token reads the Doc. The parser builds the page. Named ranges are the anchors.
02
Words, images, and block order change the draft. Keystrokes stay in the browser.
03
Operations become a Docs batchUpdate. A revision that moved returns 409 and writes nothing.
04
The same renderer runs in publish mode. Images leave Drive. HTML on that URL is purged.
Edge Delivery Services document authoring is doc-first. The author writes in a Google Doc, preview turns that Doc into HTML, and publish copies the result to the CDN.
DA.live is page-first. Its editor loads HTML from the source API and writes HTML back. Preview and publish happen after that write.
This app uses the page-editing gesture and keeps the Doc as the source. The CDN holds a snapshot of one revision and is never read back into the Doc.
About the studio
A one-paragraph introduction.
hero
The work, plainly described.
columns (contained)
Left columnFirst point.
Right columnSecond point.
The metadata table (title, description, template) is parsed and kept off the preview.
Ids live in named ranges, not in the text. Opening the Doc in Google shows ordinary headings, paragraphs, and tables. The first commit of an untagged Doc creates the ranges and changes no visible content.
| Page node | In the Doc | Range |
|---|---|---|
| Section break | A paragraph whose text is --- | pg/section/{id} |
| Prose | Heading, paragraph, list, or image | pg/node/{id} |
| Block | A table. First cell is hero or columns (contained) | pg/node/{id} on the table |
| Page metadata | A two-column table named metadata. It is kept off the page. | pg/meta |
| Section style | A section metadata table at the end of a section | pg/node/{id} |
| Image bytes | An inline image after insert. Drive is the upload source. | Inside the node range |
The client sends the revision it loaded and a list of operations. The server resolves ranges, writes from the highest index downward, and re-reads the Doc before responding.
| Operation | Doc write |
|---|---|
| replaceText | Replace the text inside that named range and keep the paragraph style. |
| setBlockOptions | Rewrite the parenthetical in the name cell. |
| setMetadata | Update one row of the metadata table. |
| insertBlock / insertSection | Insert a table or a --- paragraph at the resolved index. |
| removeNode | Delete the content covered by the named range. |
| moveNode | Rebuild the table at the destination, then delete the original. Docs has no move. |
| setImage | Temporary link share, insertInlineImage, then remove the share. |
Comments, suggestions, drawings, and unknown tables are opaque spans. A commit that would overlap one is rejected. The writer never replaces the document body.
A slice is done when its check passes against a real Google Doc. The Docs API is called in that slice, not mocked and deferred.
1
Sign in with Google, open a Doc, and show it as a page. This slice proves the parser against a real document.
Done when. The About fixture renders as a title, a hero, and a columns block. A Doc this account cannot edit shows Google's error.
2
Inline text stays in a draft. Commit writes it through named ranges, then the server re-reads the Doc and the editor renders that result.
Done when. The new sentence is visible in Google Docs itself. An edit made in Docs between load and commit returns 409 and writes nothing.
3
Layout is reorder, insert, remove, and block options. The palette is prose, hero, columns, and cards. Image bytes end up stored in the Doc.
Done when. Table order in the Doc matches the preview. The image still loads after the share is removed. A pre-existing comment is still on the Doc.
4
Publish renders the last committed revision with the same function as the preview, copies images off Drive, and uploads the directory.
Done when. The public URL has no editor and no Google sign-in. Publishing the same revision again does not upload.
5
The Drive folder is the site. Home is the doc named index. Shared chrome is a fragment Doc. Redirects are a Sheet.
Done when. Two pages share one header. Publishing both after a header edit updates both. A redirects row publishes a redirect.
Each of these is checked inside the slice that introduces it.
| Risk | What we do | Checked in |
|---|---|---|
| Docs indexes shift on every edit | Resolve named ranges on each commit. Re-read after writing. Never reuse an index. | Slice 2 |
| drive.file hides files the author expects | The app creates the site folder. Existing docs enter through the Picker. The first screen says so. | Slice 1 |
| insertInlineImage requires a public URL | Link-share for the insert call only. The Doc stores the bytes. Publish copies them out. | Slice 3 |
| A commit drops content the parser skipped | Opaque spans reject an overlapping edit. The writer never replaces the body. | Slice 3 |
| Preview HTML and the public page diverge | One render function, two modes. Diff them with editor attributes removed. | Slice 4 |
| A dirty draft gets published | Publish loads the revision from Google and refuses uncommitted operations. | Slice 4 |