Skip to content

feat(viewer): replaceable UI components for toolbars and dialogs - #7

Open
mkroemer wants to merge 16 commits into
p10node:mainfrom
mkroemer:ui-primitives
Open

mkroemer wants to merge 16 commits into
p10node:mainfrom
mkroemer:ui-primitives

Conversation

@mkroemer

@mkroemer mkroemer commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Hosts can supply Button, Select, Separator, Dialog and Toast implementations to use their design system in the viewer. Omitted components keep the built-in versions. Define the custom component types outside render so toolbar controls stay mounted.

Toolbar overflow reserves the natural width of the host's “More tools” button and measures again when component types change. Prompt actions work when a host puts the footer outside the form, and delayed inputs receive focus when they mount. Select portals within the same React tree work in popovers. The theming guide documents the props, built-in exceptions and focus behavior.

This layer follows #6 in the stack and includes v0.17.0. Regression coverage checks the rendered controls, keyboard and pointer interactions, prompts and layout.

@pierreneter pierreneter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 puts de-dialog-extra on the prompt's extra button, and DialogAction has 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 in test/ui.test.tsx leaves the dialogs out, so nothing catches it. Please restore the class (an extra flag on DialogAction would do) and add the dialogs to that test.

Non-blocking:

  • A host Select gets IconNames in its options, but Icon is not exported, so it cannot draw the built-in icons.
  • docs/theming.md defines Button and Separator inline in JSX, which remounts every toolbar button on each host render. Please hoist them in the example.

@mkroemer

Copy link
Copy Markdown
Contributor Author
  • Restored de-dialog-extra through DialogAction.extra, with regression coverage for action order, styling, and link removal.
  • Exported Icon so host Select components can render option icons using host overrides or built-in fallbacks.
  • Hoisted custom component definitions in docs/theming.md to avoid remounting controls on each host render.

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 main is merged.

@pierreneter pierreneter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

  1. 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 fixed width: 140, which cannot shrink, so the test passes. flex: none on the wrapper fixes it.
  2. src/react/common/Dialog.tsx:48: the prompt's primary action is { primary: true, submit: true } with no onClick. It only works when the host renders it as a submit button inside a form. A host Dialog that puts actions in a footer outside the form (MUI DialogActions, a Radix footer) gets an OK button that does nothing. Giving the action onClick: done, and skipping onClick for submit buttons in DefaultDialog, 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 when components does, for example through mount().update({ components }). The cut is then computed from the old widths.
  • A host Select that portals its list cannot be used inside the overflow popover or a Pop: useDismiss (Toolbar.tsx:239) checks DOM containment, so the popover closes on mousedown and onChange never fires. That deserves a line in the docs at least.
  • Dialog.tsx:25: PromptDialog focuses 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.icon is an IconName string while ButtonProps.icon is a node, and the docs table for Select leaves out icon, className and what label: null means. A host that writes {p.icon}{p.label} as for Button shows the literal name.
  • docs/theming.md:113 says the size list goes through Select, but SizeBox has 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 nested OfficeUIProvider without locale resets the texts to English, while icons and components merge with the outer one. And { ...outer, ...components } lets an explicit undefined erase the outer component.
  • docs/theming.md:110: the new table is not column-aligned.

mkroemer and others added 12 commits November 18, 2026 21:04
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>
@mkroemer

Copy link
Copy Markdown
Contributor Author

Fixed natural-width measurement for “More tools,” including component replacement and wrapper shrinking. Prompt actions now work with host footers outside the form, submit once, and focus delayed inputs correctly.

Also addressed provider inheritance, same-React-tree Select portals, and documentation limits. Replaced exact HTML assertions with parsed-element checks and removed the unused toolbar.more keys.

Rebased onto #6. Build, typecheck and browser regressions pass locally.

Upstream integration note: this candidate was reviewed and tested against fb718881 (v0.15.0). Since that validation, main advanced to 4a78390 (v0.16.0), with overlapping editor changes. This push publishes the reviewed fixes; resolving the new merge conflicts and validating that integration are still pending.

markus-kroemer and others added 4 commits November 19, 2026 11:07
The texts upstream added meanwhile go through the strings table, in
English and German: Duplicate sheet (now a real copy of the sheet), the
custom number format picker, the fill and merged-paste limits, the
message after a merge drops values, the cell field's label, and the
unsupported-file error saying what the file is instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pierreneter pierreneter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, both points and the non-blocking ones are done. I checked at b66f919:

  • More is measured at its natural width (flex: none, and it is in the measuring pass).
  • The prompt's OK works from a footer outside the form and submits once.
  • The widths are re-measured when components change.
  • A portaled Select in the same React tree works inside the overflow menu and a Pop.
  • The prompt input gets focus with a late-mounting host Dialog.
  • Nested providers inherit, and an explicit undefined does not erase the outer component.

In the VM, the unit tests (1218), the build, and the ui-layout, components, ui-built, locale-built and icons browser suites all pass. Nothing blocking from my side.

Non-blocking:

  • src/react/edit/Toolbar.tsx:594 and :626-643: item widths are measured only when measurement changes, and the ResizeObserver watches only the row. A host Select that sizes itself to its label (many design-system selects ignore width) grows when its value changes. The cut then stays where it was and More is pushed out of the row. A probe with a 400px row, a font Select and 16 buttons, after switching from "Arial" to a long font name: the Select grew from 43 to 236px, the cut stayed at 11, and More ended at x = 581. A window resize reuses the cached widths, so it stays there. Observing the [data-i] wrappers and the More wrapper as well would fix it. At least the docs could say that a host Select must keep the width it is given.
  • With no components, one more item can now fit than on main, because the built-in More measures 28px where 34 was reserved. In a sweep of 300-540px rows this happened at 48 of 241 widths, and More never overflowed. I'm fine with that, just noting it as a visible change.
  • docs/theming.md:123-124 says SizeBox keeps the built-in markup, but its − / + buttons go through the host Button (Toolbar.tsx:515, 552).
  • docs/api.md:77: the new components row is wider than the rest of the table, so its pipes don't line up.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants