Repository navigation
Conversation
…s props
The viewer's texts come from one typed table, `Strings` (src/react/strings/en.ts),
with a complete German table next to it (de.ts, Swiss spelling, Word / Excel /
PowerPoint terms). `DocViewer`, `mount()` and `<office-viewer>` take `locale`
('en' | 'de', default 'en') and `strings`, a partial table merged over the
locale key by key; `StringsProvider` / `useStrings()` give standalone views the
same texts. Numbers and dates in the UI go through Intl with the table's locale;
the English output is unchanged.
This change converts the top bar, the details rows, the common dialogs, the
zoom control, the shared toolbar controls, the source pane and the picture view.
The shared groups (`edit`, `find`, `table`, `format`) are in the table already,
so the document, sheet and slide views can be converted in separate changes.
A unit test checks that every locale has all keys of `en`, no empty text and no
sharp s in German.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A host can render its own Button, Select, Separator, Dialog and Toast in the
engine's toolbars and dialogs (`components` prop, UIComponentsProvider), for
a design system's controls where design tokens are not enough. Each one left
out keeps the built-in one, whose markup is unchanged.
- every toolbar button goes through Button: Btn, the color, picker and
overflow toggles, the font size steps; Dropdown/Select through Select
- PromptDialog and ConfirmDialog build their actions and body and render
them through Dialog; Toast keeps its timer and renders through Toast
- OfficeUIProvider carries icons, components, locale and strings to views
mounted without DocViewer
- the overflow button's title is its accessible name ("More tools"), so the
unused "More" text goes
- docs/theming.md "Your own components"; unit tests for each component and
nested providers; e2e with host components: toolbar, formatting keeps the
selection, overflow at a narrow width, the link prompt
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xts from the strings table The document view's status line, toolbar, context menu, outline, find bar, page setup and header / footer dialogs and the tracked-change tooltips take their texts from the docx, pageSetup and headerFooter groups. The Page 1 of 5 footer preset inserts its text in the UI's language. e2e/locale-docx.spec.ts checks the German texts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s from the strings table The sheet view's status line, document details, sheet tabs, context menu, find options, print notice and the toolbar (number formats, borders, merge, alignment, rotation, rows, functions, sort, view) take their texts from the xlsx group. Number format previews stay as they are. e2e/locale-xlsx.spec.ts checks the German texts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heir texts from the strings table The slide view's toolbar, shape and slide menus, status line and present button, the comments panel and its notices, the File menu, the details dialog, the unsupported-file message and the collaboration chip take their texts from the pptx, comments, file and collab groups. The empty text box placeholder is a data-placeholder attribute shown through attr(), so it follows the locale. e2e/locale.spec.ts checks the German bar, File menu, details dialog and slide view, a partial override and the English default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A host that draws its own controls around the document gets
`<DocViewer controller={createViewerController()} headless />`.
`headless` leaves the viewer with the document alone: no top bar, zoom
control, outline panel or button, sheet tabs, slide list or Present
button. While editing, the formatting toolbar keeps its row, and an
explicit `toolbar` brings back the top bar (File menu, comments, Save).
The controller (src/react/controller.ts, framework-free) holds the
state - kind, loading, editing, canEdit, dirty, saving, canUndo/canRedo,
zoom, page, outline (headings, sheets or slides), status - and runs the
commands: setEditing, save, undo, redo, zoomIn/zoomOut/setZoom, goto,
gotoPage, present, print, fileAction, toggleComments. The viewer and its
mounted view publish to it and register their commands; without one from
the host the viewer keeps its own, so nothing else changes. When the
viewer or its view unmounts, its part of the state is cleared, so a
controller that outlives it shows no document.
`useViewerState(ctl)` reads the state in React.
- DOCX: headings are read for the controller whether or not the outline
panel is open (once edits rest), with the current one, which stays the
heading jumped to while its page is in view; DocxEditor reports its
undo/redo history after each step, offered only while editing.
- XLSX: the visible sheets as the outline; undo/redo counted per edit,
cleared when a sheet is added, deleted, moved, renamed or imported, as
the worker's history is. A sheet switched to through the controller
keeps a formula being typed open, for cross-sheet references, as the
built-in tabs do.
- PPTX: slides titled by their title placeholder, read by a title-only
worker call (`pptx.titles`, no layout) only while a host subscribes
(`observed`, `watchObserved`), and kept current as slides are edited;
symbol-font characters in titles as their Unicode look-alikes. Undo and
redo through the controller do nothing outside edit mode.
- `onLoad` fires once per opened document, also with an inline callback.
- mount() returns the controller; <office-viewer headless> has .controller.
- e2e harness: PLAYWRIGHT_CHANNEL picks an installed browser.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One formatting API for documents, cells and slide text, so a host can draw its own formatting toolbar: `ViewerState.format` (a TextFormat: bold, italic, underline, strike, font, size, color, highlight, align, list) and `ViewerController.format(command)`. - DocxEditor and PptxEditor publish their formatting state to subscribers (`subscribeState`) beside the toolbar's `onState`; a subscriber hears the current state at once, so a controller attached while text is selected reports its format without waiting for the selection to change - src/react/edit/format.ts maps the editors' states and the active cell's CSS to TextFormat and commands to editor calls or cell format patches - the format is null while viewing, and in a presentation unless text is being edited; a command a kind has no use for does nothing - spreadsheet undo, redo and format commands through the controller run only while editing, and canUndo / canRedo follow the editing state - docs: "Formatting" under headless mode; unit tests for the mappings; e2e: bold and size through the controller in a document (saved), bold and fill on a cell, and an undo while viewing that leaves the cell as is Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pierreneter
left a comment
There was a problem hiding this comment.
Thank you. This one looks good to me: the mapping in src/react/edit/format.ts mirrors the built-in toolbars, and the tests round-trip DOCX and XLSX formatting.
No changes needed here. It sits on #8, so I'll merge it as soon as #8 is fixed.
Worth settling before a release, since they become API:
{ op: 'list' }toggles although it reads as a setter, and there is no way to remove a list.list === undefinedalso means "this kind has no lists".state.formatgoes null as soon as focus leaves the document, including into a host's own<input>, so the documenteddisabled={!f}pattern disables the field being typed in. The docs should say so, or the format should stay while the selection does.
…xts from the strings table The document view's status line, toolbar, context menu, outline, find bar, page setup and header / footer dialogs and the tracked-change tooltips take their texts from the docx, pageSetup and headerFooter groups. The Page 1 of 5 footer preset inserts its text in the UI's language. e2e/locale-docx.spec.ts checks the German texts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s from the strings table The sheet view's status line, document details, sheet tabs, context menu, find options, print notice and the toolbar (number formats, borders, merge, alignment, rotation, rows, functions, sort, view) take their texts from the xlsx group. Number format previews stay as they are. e2e/locale-xlsx.spec.ts checks the German texts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heir texts from the strings table The slide view's toolbar, shape and slide menus, status line and present button, the comments panel and its notices, the File menu, the details dialog, the unsupported-file message and the collaboration chip take their texts from the pptx, comments, file and collab groups. The empty text box placeholder is a data-placeholder attribute shown through attr(), so it follows the locale. e2e/locale.spec.ts checks the German bar, File menu, details dialog and slide view, a partial override and the English default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # e2e/controller.spec.ts
Integrated the current #6–#8 changes, including the asynchronous XLSX history fix for #20. The inherited PPTX save race and DOCX conversion notification fix remain separate in #21 and #22. Verification: 578 unit tests, 22 controller/formatting browser tests, typecheck and the full library build pass locally. An independent review and a fresh converted-size boundary recheck approved this candidate. The reviewer also checked model/history/dirty-state preservation and saved XML for the original overflow/underflow repros. |
pierreneter
left a comment
There was a problem hiding this comment.
Thanks for the follow-ups. I went through what this adds on top of #6-#8 at 71db05c. This is from reading the code, I have not run it, so please check me where it does not match what you see.
To fix first:
src/react/xlsx/XlsxView.tsx:1207: the controller'sformaton a sheet goes throughfmt()tofmtAt(), which always callsfocusGrid()(:1190). With the docs' own example,<input type="number" onChange={(e) => ctl.format({ op: 'size', pt: e.currentTarget.valueAsNumber })}>: typing14applies 1pt on the1and moves focus to the grid, the4then starts a cell edit and overwrites the active cell, and Backspace clears the selected range.e2e/format-controls.spec.tsloops over docx and pptx only. A controller command should not move focus.src/react/edit/input.ts:375:detach()now also clearslastSel,formatTargetandformatControl.DocxViewdetaches and attaches again whenever the viewer context object changes identity (DocxView.tsx:277), which as far as I can tell happens whensavingflips and with every newonSave/onError/onDirtyChangereference:- a host with an inline
onSaveanduseViewerState(ctl)in one component: selecting text re-renders the host, the context changes, the target is wiped, and clicking the size input givesformat: nullagain, which is the case from my last review; - with no controller at all: Ctrl+S, then Ctrl+K, type a URL, OK.
setLinkhas no selection and inserts nothing.lastSelsurvived a re-attach before this PR.
- a host with an inline
src/react/edit/format.ts:24:colorandhighlighttake any string (the type says "CSS color"), but the writers only take hex throughofficeHex.ctl.format({ op: 'color', color: 'red' })shows red and updates history and dirty, and the save then removesw:color(src/core/docx/writer.ts:127), which also loses the colour that was there before. Same forrgb(...)and for#ff0000fffrom a picker with alpha. Either convert CSS colours or reject what cannot be written.format.ts:28and:44: both chains end in a bareelse ed.clearFormat(), so any op outside the known ones, from a plain-JS host or the web component ({ op: 'bold' }), clears the formatting. The docs say a command with no use does nothing.
API, before a release:
{ op: 'list' }still toggles. It is documented now, but there is no explicit removal, and a selection whose first paragraph is bulleted and second is not needs two calls. I'd still likelist: null(or'none'), so "make this a numbered list" can be said once and a repeated command does not flip the result.format.ts:79: sizes only have to be positive and finite, which is looser than the built-in box (1-400pt in half points,src/react/edit/Toolbar.tsx:490) and than the formats:pt: 0.5writessz="50"on a slide,pt: 1000writes<sz val="1000"/>in a cell, where Excel stops at 409.test/controller.test.tsasserts that 0.25 and 1000 pass. Please use the same range asSizeBox, in one place.fontis not validated at all. An empty name writes<w:rFonts w:ascii="" .../>, and a live text input appliesA,Ar,Ari, ... as separate undo steps.
Non-blocking:
- The command gate and the published state use
formatSelection(), whileapplyDocx/applyPptxact oninput.sel(). In a collab session a peer's edit rebaseslastSelonly, so the two can point at different paragraphs. Passing the publishedSelinto the command, with a do-not-refocus flag, would remove the focus heuristic inRichInputand fix 1 the same way. XlsxView.tsx:1211publishesformat,canUndoandcanRedostraight throughviewer.ctl?.update(), without the ownership check that81cd557added for docx and pptx.formatControlis cleared only by a selection inside the editor. After one command from a host input,ctl.undo()orctl.goto()from another host button restores no caret.- Merge
a4fceabre-addstoolbar.more(en.ts:143,de.ts:139), which #7 removed as unused. I found nothing else dropped or duplicated by the merges. cellFormatrepeats whatXlsxToolbar.tsx:108-114andtoggleinXlsxViewderive. The toolbar should read from it, so the two cannot disagree.docs/api.md:134: the newformatrow is out of line with the table.
On the stack as a whole: this branch contains the heads of #6, #7 and #8, but those three do not merge one after another. #6 conflicts with #7 in 4 files and with #8 in 16 (#8 still has the older strings commits), and all of them conflict with main since v0.14.0 in docs/api.md, src/react/DocViewer.tsx and src/react/file/importFile.ts. Could you rebase them onto main as a linear stack, 6 → 7 → 8 → 9, so each one merges cleanly after the one before? #10 would then sit on top of this one.
Builds on #8 (headless mode and controller). Until it is merged this PR shows its commits too; the formatting part is the last commit.
This lets a host draw its own formatting toolbar for a headless viewer, with one API for documents, cells and slide text:
ViewerState.formatis aTextFormat(bold, italic, underline, strike, font, size, color, highlight, align, list) andViewerController.format(command)takes aFormatCommand(toggle a mark, font, size, color, highlight, align, list, clear).DocxEditorandPptxEditorpublish their formatting state to subscribers (subscribeState) beside the toolbar'sonState. A subscriber hears the current state at once, so a controller attached while text is selected reports its format without waiting for the selection to change.src/react/edit/format.tsmaps the editors' states and the active cell's CSS toTextFormat, and commands to editor calls or cell format patches.canUndo/canRedofollow the editing state.Tables, pictures, tracked changes and cell borders stay with the built-in toolbars.
docs/api.mdhas a "Formatting" section under headless mode.test/format.test.tscovers the mappings.e2e/controller.spec.tsbolds and resizes text in a document through the controller and checks the saved file, bolds and fills a cell, and checks that an undo while viewing leaves the cell as it is.bun run typecheck,bun testand the e2e suite pass in CI.🤖 Generated with Claude Code