fix(editor): frame strip follows the board's hint and format chip

This commit is contained in:
bchanot committed 2026-11-23 13:51:30 +01:00
1 parent de9f1a6921
commit cf3665c50e
5 files changed
+63 -13

No files matched your search

@@ -48,21 +48,31 @@ function Check({
) )
} }
const CHIP =
'rounded-full border border-[var(--color-border)] px-3 py-1 text-sm whitespace-nowrap'
/** The box's ratio, « Format 4:3 »: it follows the box. */ /** The box's ratio, « Format 4:3 »: it follows the box. */
function FormatChip({ box }: { box: Frame }) { function FormatChip({ box }: { box: Frame }) {
const t = useT() const t = useT()
const locale = useLocaleStore((s) => s.locale) const locale = useLocaleStore((s) => s.locale)
const ratio = ratioLabel(box.w, box.h, locale) const ratio = ratioLabel(box.w, box.h, locale)
return ( return (
<span <span data-testid="frame-format" className={CHIP}>
data-testid="frame-format"
className="rounded-full border border-[var(--color-border)] px-3 py-1 text-sm whitespace-nowrap"
>
{t('editor.annotations.frame.format').replace('{ratio}', () => ratio)} {t('editor.annotations.frame.format').replace('{ratio}', () => ratio)}
</span> </span>
) )
} }
/** Drawing: no box yet, so no simple ratio (D6). */
function FreeFormat() {
const t = useT()
return (
<span data-testid="frame-format" className={CHIP}>
{t('editor.annotations.frame.format_free')}
</span>
)
}
function Abandon() { function Abandon() {
const t = useT() const t = useT()
return ( return (
@@ -167,6 +177,7 @@ function RecropCommands({
className={COMMAND} className={COMMAND}
data-frame-primary="" data-frame-primary=""
onClick={onApply} onClick={onApply}
disabled={!onApply}
> >
{t('editor.annotations.frame.apply')} {t('editor.annotations.frame.apply')}
</Button> </Button>
@@ -186,7 +197,14 @@ export default function FrameCommands({
}: FrameCommandsProps) { }: FrameCommandsProps) {
const t = useT() const t = useT()
const { box } = frame const { box } = frame
if (box === null) return <Abandon /> if (box === null) {
return (
<div className="flex items-center gap-2">
<FreeFormat />
<Abandon />
</div>
)
}
if (frame.moving) return <FrameMoveBar box={box} bounds={bounds} /> if (frame.moving) return <FrameMoveBar box={box} bounds={bounds} />
return ( return (
<div data-testid="frame-commands" className="flex items-center gap-2"> <div data-testid="frame-commands" className="flex items-center gap-2">
@@ -2,9 +2,11 @@ import { flushSync } from 'react-dom'
import { focusPressedIfLost, guardDrawing } from './drawingGuard' import { focusPressedIfLost, guardDrawing } from './drawingGuard'
/** /**
* A tool, a view chip or an overview row, guarded like every move that drops the drawing's work (R-12, `guardDrawing`). Pressed with the focus still on * A tool, a view chip or an overview row, guarded like every move that drops the
* a handle (Safari focuses no clicked button), the change unmounts that handle: the focus * drawing's work (R-12, `guardDrawing`). Pressed with the focus still on a handle
* then lands on the pressed control, where the keyboard's press leaves it, never on `body` (rev 4 M-4). * (Safari focuses no clicked button), the change unmounts that handle: the focus then
* lands on the pressed control, where the keyboard's press leaves it, never on `body`
* (rev 4 M-4).
*/ */
export function guardedPress(button: HTMLElement, action: () => void) { export function guardedPress(button: HTMLElement, action: () => void) {
if (!guardDrawing(action)) return if (!guardDrawing(action)) return
+2 -1
View File
@@ -1920,10 +1920,11 @@ export const en: Dict = {
'editor.annotations.view.parent': 'Parent view', 'editor.annotations.view.parent': 'Parent view',
'editor.annotations.view.recrop': 'Recrop the view', 'editor.annotations.view.recrop': 'Recrop the view',
'editor.annotations.frame.draw_hint': 'editor.annotations.frame.draw_hint':
'Drag on the drawing to draw the frame, or click to place a default frame.', 'Drag on the drawing, or click for a default frame.',
'editor.annotations.frame.adjust_hint': 'editor.annotations.frame.adjust_hint':
'Drag a corner or a side to adjust, the inside to move.', 'Drag a corner or a side to adjust, the inside to move.',
'editor.annotations.frame.format': 'Ratio {ratio}', 'editor.annotations.frame.format': 'Ratio {ratio}',
'editor.annotations.frame.format_free': 'Free ratio',
'editor.annotations.frame.keep_ratio': 'Keep the proportions', 'editor.annotations.frame.keep_ratio': 'Keep the proportions',
'editor.annotations.frame.move': 'Move', 'editor.annotations.frame.move': 'Move',
'editor.annotations.frame.redraw': 'Draw again', 'editor.annotations.frame.redraw': 'Draw again',
+2 -1
View File
@@ -1990,10 +1990,11 @@ export const fr: Dict = {
'editor.annotations.view.parent': 'Vue parente', 'editor.annotations.view.parent': 'Vue parente',
'editor.annotations.view.recrop': 'Recadrer la vue', 'editor.annotations.view.recrop': 'Recadrer la vue',
'editor.annotations.frame.draw_hint': 'editor.annotations.frame.draw_hint':
'Glissez sur le dessin pour tracer le cadre, ou cliquez pour poser un cadre par défaut.', 'Glissez sur le dessin, ou cliquez pour un cadre par défaut.',
'editor.annotations.frame.adjust_hint': 'editor.annotations.frame.adjust_hint':
"Glissez un coin ou un côté pour ajuster, l'intérieur pour déplacer.", "Glissez un coin ou un côté pour ajuster, l'intérieur pour déplacer.",
'editor.annotations.frame.format': 'Format {ratio}', 'editor.annotations.frame.format': 'Format {ratio}',
'editor.annotations.frame.format_free': 'Format libre',
'editor.annotations.frame.keep_ratio': 'Garder les proportions', 'editor.annotations.frame.keep_ratio': 'Garder les proportions',
'editor.annotations.frame.move': 'Déplacer', 'editor.annotations.frame.move': 'Déplacer',
'editor.annotations.frame.redraw': 'Retracer', 'editor.annotations.frame.redraw': 'Retracer',
@@ -27,7 +27,8 @@ import {
insert, insert,
point, point,
} from '../helpers/editorFixtures' } from '../helpers/editorFixtures'
import { openReady, resetStore } from '../helpers/editorHarness' import { openReady, resetStore, serverHas } from '../helpers/editorHarness'
import { mountDraft, setWidth } from '../helpers/editorRoute'
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) })) vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
vi.mock('@faunosteo/supabase', async (orig) => ({ vi.mock('@faunosteo/supabase', async (orig) => ({
@@ -61,6 +62,7 @@ afterEach(() => {
cleanup() cleanup()
act(() => resetWork()) act(() => resetWork())
resetStore() resetStore()
setWidth(1024)
}) })
const withDetail = (text: string) => const withDetail = (text: string) =>
@@ -157,8 +159,9 @@ describe('the idle commands', () => {
'Nouvelle vue de détail', 'Nouvelle vue de détail',
) )
expect(within(strip()).getByTestId('edit-strip-detail')).toHaveTextContent( expect(within(strip()).getByTestId('edit-strip-detail')).toHaveTextContent(
'Glissez sur le dessin pour tracer le cadre, ou cliquez pour poser un cadre par défaut.', 'Glissez sur le dessin, ou cliquez pour un cadre par défaut.',
) )
expect(within(strip()).getByText('Format libre')).toBeVisible()
expect(inStrip('Abandonner')).not.toBeNull() expect(inStrip('Abandonner')).not.toBeNull()
expect(inStrip('Nouvelle vue de détail')).toBeNull() expect(inStrip('Nouvelle vue de détail')).toBeNull()
}) })
@@ -172,6 +175,31 @@ describe('the idle commands', () => {
}) })
}) })
describe('where the idle commands never show', () => {
const absent = () =>
expect(
screen.queryByRole('button', { name: 'Nouvelle vue de détail' }),
).toBeNull()
it('not in the read-only editor', async () => {
await openReady({ text: drawnText() })
render(<LayeredTab {...props} readOnly />)
await waitFor(() =>
expect(
screen.getByTestId('catalogue-canvas-drawing').querySelector('svg'),
).not.toBeNull(),
)
absent()
})
it('not under 1 024 px, where the route is read-only', async () => {
serverHas(drawnText(), 3)
mountDraft({ width: 800 })
expect(await screen.findByText('Lecture seule')).toBeInTheDocument()
absent()
})
})
describe('the commands follow the phase', () => { describe('the commands follow the phase', () => {
it('the commands box is remounted between drawing and adjusting', async () => { it('the commands box is remounted between drawing and adjusting', async () => {
await mount() await mount()
@@ -360,7 +388,7 @@ describe('the recrop phase', () => {
name: "Déplacer l'accès avec le cadre", name: "Déplacer l'accès avec le cadre",
}), }),
).not.toBeChecked() ).not.toBeChecked()
expect(inStrip('Appliquer')).not.toBeNull() expect(inStrip('Appliquer')).toBeDisabled()
expect(inStrip('Abandonner')).not.toBeNull() expect(inStrip('Abandonner')).not.toBeNull()
expect(inStrip('Valider le cadre')).toBeNull() expect(inStrip('Valider le cadre')).toBeNull()
}) })