fix(editor): frame strip follows the board's hint and format chip
This commit is contained in:
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. */
|
||||
function FormatChip({ box }: { box: Frame }) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const ratio = ratioLabel(box.w, box.h, locale)
|
||||
return (
|
||||
<span
|
||||
data-testid="frame-format"
|
||||
className="rounded-full border border-[var(--color-border)] px-3 py-1 text-sm whitespace-nowrap"
|
||||
>
|
||||
<span data-testid="frame-format" className={CHIP}>
|
||||
{t('editor.annotations.frame.format').replace('{ratio}', () => ratio)}
|
||||
</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() {
|
||||
const t = useT()
|
||||
return (
|
||||
@@ -167,6 +177,7 @@ function RecropCommands({
|
||||
className={COMMAND}
|
||||
data-frame-primary=""
|
||||
onClick={onApply}
|
||||
disabled={!onApply}
|
||||
>
|
||||
{t('editor.annotations.frame.apply')}
|
||||
</Button>
|
||||
@@ -186,7 +197,14 @@ export default function FrameCommands({
|
||||
}: FrameCommandsProps) {
|
||||
const t = useT()
|
||||
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} />
|
||||
return (
|
||||
<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'
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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(<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', () => {
|
||||
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()
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user