feat(editor): browser history for tabs, sections and Aller a
EditorView held by the navigation reducer (restore_view), a history adapter hook mounted in EditorWorkspace (push, replace, back, mount rule, ownership, write budget, scroll map, refused POP), a guard stack by layer, an announcer queue joined after open dialogs.
This commit is contained in:
1 parent
69e225ca7a
commit
792394d3b2
11 files changed
+1268
-40
No files matched your search
@@ -41,7 +41,10 @@ function ErrorCount({ tab }: { tab: EditorTabId }) {
|
||||
}
|
||||
|
||||
/** Answers false when the change was refused (a field of the open panel refused to apply). */
|
||||
type SelectTab = (tab: EditorTabId) => boolean | void
|
||||
type SelectTab = (
|
||||
tab: EditorTabId,
|
||||
options?: { replace?: boolean },
|
||||
) => boolean | void
|
||||
|
||||
interface TabListProps {
|
||||
shown: readonly EditorTabId[]
|
||||
@@ -59,7 +62,8 @@ function TabList({ shown, active, onSelect }: TabListProps) {
|
||||
if (step === 0 || at < 0) return
|
||||
event.preventDefault()
|
||||
const next = shown[(at + step + shown.length) % shown.length]
|
||||
if (onSelect(next) === false) return
|
||||
// An arrow-key walk along the row replaces its history entry instead of adding one.
|
||||
if (onSelect(next, { replace: true }) === false) return
|
||||
document.getElementById(tabDomId(next))?.focus()
|
||||
}
|
||||
return (
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useRef, type ReactNode } from 'react'
|
||||
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { AnimatePresence } from 'motion/react'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import type { OfficialSheetAdmin } from '@faunosteo/supabase'
|
||||
@@ -12,6 +13,9 @@ import {
|
||||
import { saveFailureMessage } from '@/editor/messages'
|
||||
import type { EditorMode } from '@/editor/mode'
|
||||
import { useEditorStore } from '@/editor/state/editorStore'
|
||||
import { ownedEntry } from '@/editor/history/entry'
|
||||
import useEditorHistory from '@/editor/history/useEditorHistory'
|
||||
import { defaultView } from '@/editor/navigation'
|
||||
import { initialTab } from '@/editor/tabs'
|
||||
import {
|
||||
useEditorNavigation,
|
||||
@@ -19,6 +23,7 @@ import {
|
||||
} from '@/editor/useEditorNavigation'
|
||||
import type { TabTier } from '@/editor/useViewport'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import ConflictDialog from './ConflictDialog'
|
||||
import CopyIssueNotice from './CopyIssueNotice'
|
||||
import DraftHeader from './DraftHeader'
|
||||
@@ -156,9 +161,17 @@ function useBodyEscape(open: boolean, close: () => void) {
|
||||
export default function EditorWorkspace(props: Props) {
|
||||
const { sheet, mode, readOnly, tier, reloadSheet } = props
|
||||
const previewState = useEditorStore((s) => s.previewState)
|
||||
const nav = useEditorNavigation(
|
||||
previewState ? initialTab(previewState, tier) : 'annotations',
|
||||
const tab = previewState ? initialTab(previewState, tier) : 'annotations'
|
||||
const userId = useAuthStore((s) => s.user?.id ?? '')
|
||||
const owner = useMemo(
|
||||
() => ({ sheetId: sheet.sheet_id, userId }),
|
||||
[sheet.sheet_id, userId],
|
||||
)
|
||||
// A reload or a reopened entry shows the view the history kept, never a layer.
|
||||
const { state } = useLocation()
|
||||
const [entry] = useState(() => ownedEntry(state, owner))
|
||||
const nav = useEditorNavigation(tab, entry?.view)
|
||||
useEditorHistory(nav, owner, defaultView(tab))
|
||||
const open = nav.state.citationsOf !== null
|
||||
useBodyEscape(open, nav.closeCitations)
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user