diff --git a/apps/app/src/components/editor/annotations/FrameCommands.tsx b/apps/app/src/components/editor/annotations/FrameCommands.tsx index 9af62eca..1bf60d88 100644 --- a/apps/app/src/components/editor/annotations/FrameCommands.tsx +++ b/apps/app/src/components/editor/annotations/FrameCommands.tsx @@ -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. */ function FormatChip({ box }: { box: Frame }) { const t = useT() const locale = useLocaleStore((s) => s.locale) const ratio = ratioLabel(box.w, box.h, locale) return ( - + {t('editor.annotations.frame.format').replace('{ratio}', () => ratio)} ) } +/** Drawing: no box yet, so no simple ratio (D6). */ +function FreeFormat() { + const t = useT() + return ( + + {t('editor.annotations.frame.format_free')} + + ) +} + function Abandon() { const t = useT() return ( @@ -167,6 +177,7 @@ function RecropCommands({ className={COMMAND} data-frame-primary="" onClick={onApply} + disabled={!onApply} > {t('editor.annotations.frame.apply')} @@ -186,7 +197,14 @@ export default function FrameCommands({ }: FrameCommandsProps) { const t = useT() const { box } = frame - if (box === null) return + if (box === null) { + return ( +
+ + +
+ ) + } if (frame.moving) return return (
diff --git a/apps/app/src/editor/annotations/guardedPress.ts b/apps/app/src/editor/annotations/guardedPress.ts index fe33dbd3..c3637a10 100644 --- a/apps/app/src/editor/annotations/guardedPress.ts +++ b/apps/app/src/editor/annotations/guardedPress.ts @@ -2,9 +2,11 @@ import { flushSync } from 'react-dom' 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 handle (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). + * 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 handle + * (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) { if (!guardDrawing(action)) return diff --git a/apps/app/src/i18n/en.ts b/apps/app/src/i18n/en.ts index 573512ef..8a12c253 100644 --- a/apps/app/src/i18n/en.ts +++ b/apps/app/src/i18n/en.ts @@ -1920,10 +1920,11 @@ export const en: Dict = { 'editor.annotations.view.parent': 'Parent view', 'editor.annotations.view.recrop': 'Recrop the view', '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': 'Drag a corner or a side to adjust, the inside to move.', 'editor.annotations.frame.format': 'Ratio {ratio}', + 'editor.annotations.frame.format_free': 'Free ratio', 'editor.annotations.frame.keep_ratio': 'Keep the proportions', 'editor.annotations.frame.move': 'Move', 'editor.annotations.frame.redraw': 'Draw again', diff --git a/apps/app/src/i18n/fr.ts b/apps/app/src/i18n/fr.ts index a847c247..46011d74 100644 --- a/apps/app/src/i18n/fr.ts +++ b/apps/app/src/i18n/fr.ts @@ -1990,10 +1990,11 @@ export const fr: Dict = { 'editor.annotations.view.parent': 'Vue parente', 'editor.annotations.view.recrop': 'Recadrer la vue', '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': "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_free': 'Format libre', 'editor.annotations.frame.keep_ratio': 'Garder les proportions', 'editor.annotations.frame.move': 'Déplacer', 'editor.annotations.frame.redraw': 'Retracer', diff --git a/apps/app/tests/unit/editor-view-commands.test.tsx b/apps/app/tests/unit/editor-view-commands.test.tsx index 911e19b2..a02bcd5e 100644 --- a/apps/app/tests/unit/editor-view-commands.test.tsx +++ b/apps/app/tests/unit/editor-view-commands.test.tsx @@ -27,7 +27,8 @@ import { insert, point, } 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('@faunosteo/supabase', async (orig) => ({ @@ -61,6 +62,7 @@ afterEach(() => { cleanup() act(() => resetWork()) resetStore() + setWidth(1024) }) const withDetail = (text: string) => @@ -157,8 +159,9 @@ describe('the idle commands', () => { 'Nouvelle vue de détail', ) 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('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() + 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', () => { it('the commands box is remounted between drawing and adjusting', async () => { await mount() @@ -360,7 +388,7 @@ describe('the recrop phase', () => { name: "Déplacer l'accès avec le cadre", }), ).not.toBeChecked() - expect(inStrip('Appliquer')).not.toBeNull() + expect(inStrip('Appliquer')).toBeDisabled() expect(inStrip('Abandonner')).not.toBeNull() expect(inStrip('Valider le cadre')).toBeNull() })