fix(editor): deletion undo and Back, Plus focus to the panel

This commit is contained in:
bchanot committed 2026-11-14 14:24:06 +01:00
1 parent 270444e2ec
commit 085c56877c
14 files changed
+252 -18

No files matched your search

@@ -40,6 +40,10 @@ interface Props extends EditorPlaceProps {
annotations: AnnotationNav
}
/** A panel takes the focus after « Plus »: the ring shows for the keyboard only. */
const PANEL_FOCUS =
'focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
function TabPanel({
id,
active,
@@ -54,6 +58,8 @@ function TabPanel({
visible={active}
id={panelDomId(id)}
role="tabpanel"
tabIndex={-1}
className={PANEL_FOCUS}
aria-label={t(`editor.tab.${id}`)}
>
{Body ? (
+17 -2
View File
@@ -1,4 +1,4 @@
import type { KeyboardEvent } from 'react'
import { useEffect, useState, type KeyboardEvent } from 'react'
import {
AnimatePresence,
motion,
@@ -147,12 +147,27 @@ function MoreList({ more, active, onPick }: MoreListProps) {
)
}
/**
* The panel of a tab picked in « Plus » takes the focus once that tab is the shown one: the
* entry that held it is gone with the list, so the focus would fall to the page.
*/
function usePanelFocus(active: EditorTabId) {
const [wanted, setWanted] = useState<EditorTabId | null>(null)
useEffect(() => {
if (wanted === null || wanted !== active) return
document.getElementById(panelDomId(active))?.focus()
setWanted(null)
}, [wanted, active])
return setWanted
}
/** Below 640 px: « Plus » and its dropdown of the tabs that do not fit. */
function MoreTabs({ more, active, onSelect }: MoreTabsProps) {
const t = useT()
const { open, close, toggle } = useMoreMenu(active)
const wantPanel = usePanelFocus(active)
const pick = (tab: EditorTabId) => {
onSelect(tab)
if (onSelect(tab) !== false) wantPanel(tab)
close()
}
useMoreDismiss(open, close)
@@ -1,4 +1,4 @@
import { useMemo, useState, type ReactNode } from 'react'
import { useEffect, useMemo, useState, type ReactNode } from 'react'
import { useLocation } from 'react-router-dom'
import type { OfficialSheetAdmin } from '@faunosteo/supabase'
import Notice from '@/components/ui/Notice'
@@ -140,6 +140,16 @@ function useRestoredView(owner: HistoryOwner) {
return view
}
/** A step that brought a finding back shows Constats, where its row is revealed. */
function useShowRestored(nav: EditorNavigation) {
const revealed = useEditorStore((s) => s.revealed)
const { tab } = nav.state
const { selectTab } = nav
useEffect(() => {
if (revealed && tab !== 'findings') selectTab('findings')
}, [revealed, tab, selectTab])
}
/**
* The navigation of this sheet for this account: the first tab known at mount
* (`initialTab`), the view a kept entry holds, the browser history in step with it, and
@@ -151,6 +161,7 @@ function useWorkspaceNavigation(sheetId: string, tier: TabTier) {
const owner = useOwner(sheetId)
const nav = useEditorNavigation(tab, useRestoredView(owner))
useEditorHistory(nav, owner, defaultView(tab))
useShowRestored(nav)
return { nav, left: useLeftDraft(nav, owner) }
}
@@ -24,6 +24,7 @@ import { useEditorStore } from '@/editor/state/editorStore'
import { useSheetDocument } from '@/editor/sheetDocument'
import type { EditorPlaceProps, FindingLayer } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import { usePlaceVisible } from '@/lib/placeVisibility'
import { useLocaleStore } from '@/state/localeStore'
/** The tree as the store holds it right now (a commit is already in). */
@@ -61,8 +62,8 @@ function useFindingDeletion(
const target = { key: item.key, label: item.name[locale] }
setAsk({ target, fallback: fallbackAfterRemoval(items, item) })
}
// The element is gone: its dialog closes in the same move (replace, no Back step) and
// the focus lands on the nearest row once every dialog is closed, unless a newer
// The element is gone: its dialog closes in the same move, by the pop of its entry (a
// Back step that was taken, never a dead one left behind) and the focus lands on the nearest row once every dialog is closed, unless a newer
// landing supersedes it.
const closeDelete = () => {
setAsk(null)
@@ -229,13 +230,34 @@ function useLayerFollow(focus: EditorPlaceProps['focus'], ctx: TabContext) {
useSelectionOfLayer(layer, items, sel.reveal)
}
/**
* A step of « Défaire » or « Refaire » brought a finding back: its branch opens, its row is
* selected and takes the focus. Only the shown tab answers; the workspace shows it first.
*/
function useRevealRestored(items: readonly FindingItem[], ctx: TabContext) {
const revealed = useEditorStore((s) => s.revealed)
const visible = usePlaceVisible()
const { sel, land } = ctx
const reveal = useRef({ sel, land })
reveal.current = { sel, land }
useEffect(() => {
if (!revealed || !visible) return
const found = itemForKey(items, revealed.key)
if (found) {
reveal.current.sel.reveal(found)
reveal.current.land(found.item.id)
}
useEditorStore.getState().clearRevealed()
}, [revealed, visible, items])
}
/** What the tab does with the layer: creation, a row's dialog, deletion. */
function useFindingActions(ctx: TabContext) {
const { layer, sel } = ctx
const deletion = useFindingDeletion(ctx.items, sel.selectedId, {
select: sel.select,
focusItem: ctx.land,
closeLayer: () => layer.replace(null),
closeLayer: () => void layer.close(true),
})
const created = (
id: string,
@@ -273,6 +295,7 @@ function useFindingsTab(focus: EditorPlaceProps['focus'], layer: FindingLayer) {
const ctx = { layer, items: data.items, sel, land: landing.land }
useLayerFollow(focus, ctx)
useGoneRule(layer, data.doc !== null)
useRevealRestored(data.items, ctx)
return {
...data,
sel,