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>
pierreneter
left a comment
There was a problem hiding this comment.
Thank you, the five components are a sensible set and the built-in markup is otherwise unchanged.
One regression for hosts that pass no components, so I can't merge it yet:
DefaultDialog(src/react/ui.tsx:124) no longer putsde-dialog-extraon the prompt's extra button, andDialogActionhas no field for it..de-dialog-extra { margin-right: auto }is dead, so "Remove link" in the edit-link prompt moves from the left edge to beside Cancel / OK. The "built-in markup is unchanged" test intest/ui.test.tsxleaves the dialogs out, so nothing catches it. Please restore the class (anextraflag onDialogActionwould do) and add the dialogs to that test.
Non-blocking:
- A host
SelectgetsIconNames in its options, butIconis not exported, so it cannot draw the built-in icons. docs/theming.mddefinesButtonandSeparatorinline in JSX, which remounts every toolbar button on each host render. Please hoist them in the example.
I also found that toolbar overflow reserved a fixed 34px for “More tools,” which could clip wider host buttons. It now measures the rendered button’s width, with regression coverage. Verification: 553 unit tests, typecheck, library/SDK builds, package checks, and the full CI browser suite pass. Current |
pierreneter
left a comment
There was a problem hiding this comment.
Thanks, all three points are done: de-dialog-extra is back through DialogAction.extra and the dialogs are in the markup test, Icon is exported, and the docs example is hoisted.
Two things in the new code (line numbers are at 8fa9681):
src/react/edit/Toolbar.tsx:615: the More wrapper is measured after the row has already squeezed it, because.de-ebar-morewrap(styles.css:686) can shrink. Host More button<button>More tools</button>, 600px row, 17 items: in Chromium the wrapper is squeezed to 56px (natural width 78px), the effect stores 56, the cut stays the same and the label wraps. The e2e fixture gives the button a fixedwidth: 140, which cannot shrink, so the test passes.flex: noneon the wrapper fixes it.src/react/common/Dialog.tsx:48: the prompt's primary action is{ primary: true, submit: true }with noonClick. It only works when the host renders it as a submit button inside a form. A host Dialog that putsactionsin a footer outside the form (MUIDialogActions, a Radix footer) gets an OK button that does nothing. Giving the actiononClick: done, and skippingonClickfor submit buttons inDefaultDialog, covers both.
It also needs a rebase onto main (conflicts in docs/api.md and src/react/DocViewer.tsx), and at its current head it conflicts with #6 in four files. See my note on #9 about the order of the stack.
Non-blocking:
- The overflow effect has no deps and calls
getBoundingClientRect()on every toolbar render. It also changes the built-in toolbar: the reserve was 34 and the built-in wrapper measures 28, so one more item can fit and the slack is gone. Rendering More in the measuring pass and measuring it with the items needs no guess and no second effect. - Item widths are cached by
sig(type name and title), which does not change whencomponentsdoes, for example throughmount().update({ components }). The cut is then computed from the old widths. - A host
Selectthat portals its list cannot be used inside the overflow popover or aPop:useDismiss(Toolbar.tsx:239) checks DOM containment, so the popover closes on mousedown andonChangenever fires. That deserves a line in the docs at least. Dialog.tsx:25:PromptDialogfocuses and selects its input in a mount-only effect. With a host Dialog that mounts its children one pass later, nothing is focused and the rename text is not preselected. A callback ref would do.SelectProps.iconis anIconNamestring whileButtonProps.iconis a node, and the docs table forSelectleaves outicon,classNameand whatlabel: nullmeans. A host that writes{p.icon}{p.label}as for Button shows the literal name.docs/theming.md:113says the size list goes throughSelect, butSizeBoxhas its own listbox. The Page setup, Header / footer and Details dialogs and the border-picker buttons keep the built-in markup as well.src/react/ui.tsx:106: a nestedOfficeUIProviderwithoutlocaleresets the texts to English, while icons and components merge with the outer one. And{ ...outer, ...components }lets an explicitundefinederase the outer component.docs/theming.md:110: the new table is not column-aligned.
Builds on #6 (UI texts), #5 (icons) and #4 (theming). Until those are merged this PR shows their commits too; the components part is the last commit.
This lets a host render the toolbars and dialogs with its own design system's controls, for when design tokens are not enough. Each component a host leaves out keeps the built-in one, whose markup is unchanged.
There are five:
Button,Select,Separator,DialogandToast, with typed props (ButtonProps,SelectProps,DialogProps,ToastProps).Button: the plain buttons, the toggles that open the color, table and border pickers, the overflow button and the font size steps. The dropdowns go throughSelect.PromptDialogandConfirmDialogbuild their body and actions and render them throughDialog;Toastkeeps its timer and renders throughToast.componentsis a prop ofDocViewer, andUIComponentsProvidergives it to views mounted on their own.OfficeUIProvidercarries icons, components, locale and strings in one provider.The one thing a host component has to get right is the focus: the document must keep it while a toolbar control is used, or the command loses its selection.
docs/theming.md("Your own components") says how, forButton(passonMouseDownon) andSelect(open on mouse down, handle keys without focusing the list), and lists every prop.test/ui.test.tsxcovers each component and nested providers.e2e/components.spec.tsruns the viewer with host components: the toolbar renders them, formatting through a host button keeps the selection, the overflow menu still works at a narrow width, and the link prompt opens and submits through a host dialog.bun run typecheck,bun testand the e2e suite pass in CI.🤖 Generated with Claude Code