Skip to content

feat(ui): Cooklang toolbar above the recipe editor - #540

Merged
LeMyst merged 2 commits into
cooklang:mainfrom
LeMyst:feat/editor-toolbar
Sep 27, 2026
Merged

LeMyst merged 2 commits into
cooklang:mainfrom
LeMyst:feat/editor-toolbar

Conversation

@LeMyst

@LeMyst LeMyst commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #537

What

A toolbar above the web editor (/edit/{path}) with one-click Cooklang elements. Each button inserts the syntax, or wraps the selection in it:

Button No selection With selection x
Ingredient @{}, cursor after @ @x{}, cursor inside {}
Cookware #{} #x{}
Timer ~{%minutes}, cursor on the quantity ~x{%minutes}
Section == Section == on its own line, name selected == x ==
Note toggle > on the current line(s) same
Comment toggle -- on the current line(s) [- x -] for a selection inside a line (and unwraps it again)
Metadata adds ---\ntitle: \n--- at the top, or a new line at the end of the existing frontmatter —

Each action is one undo step (isolateHistory), and focus goes back to the editor afterwards. Surrounding whitespace in a selection stays outside the markup, and Section keeps blank lines around the heading.

How

  • static/js/src/toolbar.js: wrapSelection, prefixLines, insertBlock, findFrontmatter / ensureFrontmatter, built on changeByRange. A recipeActions registry is keyed by data-action, and initToolbar(root, view, actions) handles clicks and the ARIA toolbar keyboard pattern (single tab stop, arrow keys, Home/End). Everything is exposed on window.CooklangEditor, and the bundle keeps its single build-js entry.
  • templates/edit.html: role="toolbar" with data-mode="recipe" and two role="group" groups. Every button has an aria-label that matches its visible text, plus a title hint.
  • static/css/components.css: .editor-toolbar component, built on the existing tokens. It wraps at phone width, and the divider between groups is dropped there.
  • i18n: editor-toolbar-* keys in every locale (en-US, fr-FR, de-DE, es-ES, eu-ES, nl-NL, sv-SE). They reuse each locale's existing words for ingredients, cookware, timers and notes, and the default section name is localised too. de/es/eu/nl/sv are machine-assisted, so a native speaker's review is welcome.

Built for #538: the menu mode can pass {...recipeActions, ...menuActions} to initToolbar. Keyboard navigation already covers select / input items (it leaves arrow keys alone inside text fields). insertBlock and findFrontmatter are exported for Day blocks and the servings default.

Differences from the issue

  • Note toggles > instead of only adding it, for consistency with Comment. >> legacy metadata lines don't count as notes.
  • The tooltips describe the syntax without braces, because { is a placeable in Fluent.

Tests

  • New tests/e2e/editor-toolbar.spec.ts (31 tests): every button with and without a selection, undo steps, editor refocus, ARIA role/labels/tabindex, keyboard navigation, axe scans of the toolbar in light and dark, no overflow at 375px. PUT /api/recipes/** is intercepted so autosave never touches seed/.
  • cargo fmt, cargo clippy (no warnings), cargo test, and the full npm test (179 passed, 5 skipped) all pass.

Not in this PR

  • At 375px the edit page already scrolls ~15px horizontally, because the header bar's Delete button overflows. This is unrelated to the toolbar and happens without it too.
  • The editor status text is still hardcoded English, as the issue scoped out.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EpBcu3KakfhQ484WdtDE9q

@LeMyst

LeMyst commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author
image

@LeMyst
LeMyst marked this pull request as ready for review September 25, 2026 21:13
myst and others added 2 commits September 25, 2026 23:37
Add a toolbar above the web editor with one-click Ingredient, Cookware,
Timer, Section, Note, Comment and Metadata actions. Each inserts the
markup, or wraps the selection in it, as a single undo step and gives
focus back to the editor.

The transactions live in static/js/src/toolbar.js and are exposed on
window.CooklangEditor. The toolbar follows the ARIA toolbar pattern
(one tab stop, arrow keys, Home/End) and carries data-mode="recipe" so
a menu group can be added later (cooklang#538).

Closes cooklang#537

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EpBcu3KakfhQ484WdtDE9q
Add the editor-toolbar-* keys to de-DE, es-ES, eu-ES, nl-NL and sv-SE,
using each locale's existing words for ingredients, cookware, timers
and notes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EpBcu3KakfhQ484WdtDE9q
@LeMyst
LeMyst force-pushed the feat/editor-toolbar branch from ac84578 to c5791af Compare September 25, 2026 21:51
@LeMyst LeMyst mentioned this pull request Sep 25, 2026
3 of 4 tasks
@LeMyst
LeMyst requested a review from dubadub September 26, 2026 16:17

@dubadub dubadub 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.

Love it! Looks really neat!

@LeMyst
LeMyst merged commit b6f77c9 into cooklang:main Sep 27, 2026
7 checks passed
LeMyst added a commit that referenced this pull request Sep 28, 2026
- error-title and error-back-home in de-DE, es-ES, eu-ES, fr-FR and
  nl-NL, missing since dec59f1 added the error page.
- shopping-include-in-list in de-DE, es-ES, eu-ES, fr-FR, nl-NL and
  sv-SE, missing since #318.
- The 18 editor-toolbar-* messages #540 added to every locale but it-IT,
  which was merged (#543) while #540 was open.

Fluent falls back to en-US for a missing message, so nothing failed and
the pages came out half in English. tests/locales_test.rs now fails when
a locale lacks a message en-US has, naming the locale, file and ids.

Closes #566.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

feat(ui): Cooklang toolbar above the recipe editor

2 participants