mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Name the shown view in its island and list every view by name from the stripe
This commit is contained in:
1 parent
49e8bf7885
commit
0812c55425
4 files changed
+87
-16
No files matched your search
@@ -18,12 +18,12 @@ import { SceneStudio } from './SceneStudio'
|
||||
import { WorldStudio3D } from './WorldStudio3D'
|
||||
import { isTypingInto, shortcutRows, viewOfShortcutId, windowShortcutFor, type ShortcutAction } from './shortcuts'
|
||||
import { ShortcutSettings } from './ShortcutSettings'
|
||||
import { Panel, SidebarPanel, SidebarSlot, ViewIsland } from './Sidebar'
|
||||
import { Panel, ShownViewIcon, SidebarPanel, SidebarSlot, ViewIsland } from './Sidebar'
|
||||
import { StatusBar } from './StatusBar'
|
||||
import { MapTools, StudioToolbar } from './StudioToolbar'
|
||||
import { useBindings } from './useBindings'
|
||||
import { usePickInspection } from './usePickInspection'
|
||||
import { ViewList } from './ViewList'
|
||||
import { ViewList, viewIcon } from './ViewList'
|
||||
|
||||
const KEYBOARD_ZOOM_FACTOR = 2 ** 0.25
|
||||
const ENTITY_POLL_MILLIS = 2000
|
||||
@@ -214,6 +214,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps
|
||||
return (
|
||||
<div className="window-frame flex h-full flex-col">
|
||||
<StudioToolbar world={world} theme={theme} onHelp={() => setHelpOpen(true)} onSettings={() => setSettingsOpen(true)} onDisconnect={onDisconnect} />
|
||||
<ShownViewIcon.Provider value={viewIcon(viewId)}>
|
||||
<SidebarSlot.Provider value={sidebarSlot}>
|
||||
<div className="flex min-h-0 flex-1 gap-1.5 px-1.5">
|
||||
<ViewList views={views} current={viewId} onSelect={selectView} slotRef={setSidebarSlot} />
|
||||
@@ -300,6 +301,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps
|
||||
)}
|
||||
</div>
|
||||
</SidebarSlot.Provider>
|
||||
</ShownViewIcon.Provider>
|
||||
<StatusBar viewLabel={statusLabel(view.label, previewName, showsMap ? null : sceneSummary)} status={showsMap ? status : null} notice={notice} usage={usage} progress={showsMap ? null : sceneProgress} />
|
||||
<HelpDialog open={helpOpen} onOpenChange={setHelpOpen} views={views} />
|
||||
<ShortcutSettings open={settingsOpen} onOpenChange={setSettingsOpen} views={views} />
|
||||
|
||||
@@ -167,7 +167,7 @@ function SceneArea({ title, entry, variant, shown, status, onVariant, onPick }:
|
||||
return (
|
||||
<ViewIsland
|
||||
className="flex-[11]"
|
||||
title={entry === null ? title : entry.name}
|
||||
title={entry === null ? title : `${title} · ${entry.name}`}
|
||||
tools={
|
||||
entry !== null &&
|
||||
entry.variants > 1 && (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createContext, useContext } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { IdeIcon } from '@/components/IdeIcon'
|
||||
import { IdeIcon, type IdeIconName } from '@/components/IdeIcon'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
@@ -52,11 +52,16 @@ interface ViewIslandProps {
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
/** The island a view draws in, under a header with the view's name and its tools, as an IntelliJ tool window has. */
|
||||
/** The shown view's icon in the stripe, which its island repeats beside its name so the two are learned together. */
|
||||
export const ShownViewIcon = createContext<IdeIconName | null>(null)
|
||||
|
||||
/** The island a view draws in, under a header with the view's icon, its name and its tools, as an IntelliJ tool window has. */
|
||||
export function ViewIsland({ title, tools, className, children }: ViewIslandProps): React.JSX.Element {
|
||||
const icon = useContext(ShownViewIcon)
|
||||
return (
|
||||
<section className={cn('flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-lg bg-card', className)}>
|
||||
<header className="flex h-9 shrink-0 items-center gap-1 pr-1.5 pl-3">
|
||||
{icon !== null && <IdeIcon name={icon} className="mr-1" />}
|
||||
<h2 className="truncate text-[13px] font-semibold">{title}</h2>
|
||||
<span className="flex-1" />
|
||||
{tools}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DropdownMenu } from 'radix-ui'
|
||||
import { Fragment } from 'react'
|
||||
import { IdeIcon, type IdeIconName } from '@/components/IdeIcon'
|
||||
import { Kbd } from '@/components/ui/kbd'
|
||||
@@ -23,6 +24,11 @@ const VIEW_ICONS: Record<string, IdeIconName> = {
|
||||
}
|
||||
const FALLBACK_ICON: IdeIconName = 'views/regions'
|
||||
|
||||
/** The icon a view has in the stripe, which its island's header repeats beside its name. */
|
||||
export function viewIcon(viewId: string): IdeIconName {
|
||||
return VIEW_ICONS[viewId] ?? FALLBACK_ICON
|
||||
}
|
||||
|
||||
interface ViewListProps {
|
||||
views: ViewInfo[]
|
||||
current: string
|
||||
@@ -32,30 +38,45 @@ interface ViewListProps {
|
||||
}
|
||||
|
||||
/**
|
||||
* The views the server offers, as a stripe of buttons on the window's edge in their groups, and beside it the island
|
||||
* the shown view fills with its own lists, which is not there for a view without any (IntelliJ's tool window stripe).
|
||||
* The views the server offers, as a stripe of buttons on the window's edge in their groups with a list of their names
|
||||
* under them, and beside it the island the shown view fills with its own lists, which is not there for a view without
|
||||
* any (IntelliJ's tool window stripe).
|
||||
*/
|
||||
export function ViewList({ views, current, onSelect, slotRef }: ViewListProps): React.JSX.Element {
|
||||
const groups = [...new Set(views.map((view) => view.groupLabel))]
|
||||
const groups = groupsOf(views)
|
||||
return (
|
||||
<>
|
||||
<nav className="flex w-8 shrink-0 flex-col items-center gap-1.5 overflow-y-auto">
|
||||
{groups.map((group, index) => (
|
||||
<Fragment key={group}>
|
||||
{index > 0 && <span className="my-0.5 h-px w-5 shrink-0 bg-input" />}
|
||||
{views
|
||||
.filter((view) => view.groupLabel === group)
|
||||
.map((view) => (
|
||||
<ViewButton key={view.id} view={view} selected={view.id === current} onSelect={() => onSelect(view.id)} />
|
||||
))}
|
||||
<Fragment key={group.label}>
|
||||
{index > 0 && <StripeLine />}
|
||||
{group.views.map((view) => (
|
||||
<ViewButton key={view.id} view={view} selected={view.id === current} onSelect={() => onSelect(view.id)} />
|
||||
))}
|
||||
</Fragment>
|
||||
))}
|
||||
<StripeLine />
|
||||
<NamedViews groups={groups} current={current} onSelect={onSelect} />
|
||||
</nav>
|
||||
<div ref={slotRef} className="flex w-60 shrink-0 flex-col overflow-hidden rounded-lg bg-card empty:hidden" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
interface ViewGroup {
|
||||
label: string
|
||||
views: ViewInfo[]
|
||||
}
|
||||
|
||||
function groupsOf(views: ViewInfo[]): ViewGroup[] {
|
||||
const labels = [...new Set(views.map((view) => view.groupLabel))]
|
||||
return labels.map((label) => ({ label, views: views.filter((view) => view.groupLabel === label) }))
|
||||
}
|
||||
|
||||
function StripeLine(): React.JSX.Element {
|
||||
return <span className="my-0.5 h-px w-5 shrink-0 bg-input" />
|
||||
}
|
||||
|
||||
function ViewButton({ view, selected, onSelect }: { view: ViewInfo; selected: boolean; onSelect(): void }): React.JSX.Element {
|
||||
const keyText = useKeyText()(viewShortcutId(view.id))
|
||||
return (
|
||||
@@ -67,7 +88,7 @@ function ViewButton({ view, selected, onSelect }: { view: ViewInfo; selected: bo
|
||||
aria-pressed={selected}
|
||||
className={cn('flex size-8 shrink-0 items-center justify-center rounded-lg', selected ? 'bg-primary [&_img]:brightness-0 [&_img]:invert' : 'hover:bg-selection')}
|
||||
>
|
||||
<IdeIcon name={VIEW_ICONS[view.id] ?? FALLBACK_ICON} className="size-[18px]" />
|
||||
<IdeIcon name={viewIcon(view.id)} className="size-[18px]" />
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="right" className="flex max-w-64 flex-col items-start gap-0.5">
|
||||
@@ -80,3 +101,46 @@ function ViewButton({ view, selected, onSelect }: { view: ViewInfo; selected: bo
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
/** Every view by name, for when its icon alone does not say which it is (IntelliJ's "more tool windows"). */
|
||||
function NamedViews({ groups, current, onSelect }: { groups: ViewGroup[]; current: string; onSelect(view: string): void }): React.JSX.Element {
|
||||
const keyText = useKeyText()
|
||||
return (
|
||||
<DropdownMenu.Root>
|
||||
<DropdownMenu.Trigger asChild>
|
||||
<button aria-label="All views" title="All views" className="flex size-8 shrink-0 items-center justify-center rounded-lg text-secondary-text hover:bg-selection data-[state=open]:bg-selection">
|
||||
<svg viewBox="0 0 16 16" className="size-4" fill="currentColor">
|
||||
<circle cx="3" cy="8" r="1.25" />
|
||||
<circle cx="8" cy="8" r="1.25" />
|
||||
<circle cx="13" cy="8" r="1.25" />
|
||||
</svg>
|
||||
</button>
|
||||
</DropdownMenu.Trigger>
|
||||
<DropdownMenu.Portal>
|
||||
<DropdownMenu.Content side="right" align="end" sideOffset={8} className="z-50 w-56 rounded-lg border border-overlay-border bg-popover p-1 text-popover-foreground shadow-lg">
|
||||
{groups.map((group) => (
|
||||
<DropdownMenu.Group key={group.label}>
|
||||
<DropdownMenu.Label className="px-2 pt-1.5 pb-1 text-[11px] font-semibold text-muted-foreground">{group.label}</DropdownMenu.Label>
|
||||
{group.views.map((view) => (
|
||||
<DropdownMenu.Item
|
||||
key={view.id}
|
||||
onSelect={() => onSelect(view.id)}
|
||||
className={cn(
|
||||
'flex h-[26px] cursor-default items-center gap-2 rounded-md px-2 outline-none data-[highlighted]:bg-accent',
|
||||
view.id === current && 'bg-selection'
|
||||
)}
|
||||
>
|
||||
<IdeIcon name={viewIcon(view.id)} className="size-3.5" />
|
||||
<span className="min-w-0 flex-1 truncate">{view.label}</span>
|
||||
{keyText(viewShortcutId(view.id)) !== '' && (
|
||||
<Kbd className="h-4 min-w-4 border border-input/60 bg-transparent text-[10px] uppercase">{keyText(viewShortcutId(view.id))}</Kbd>
|
||||
)}
|
||||
</DropdownMenu.Item>
|
||||
))}
|
||||
</DropdownMenu.Group>
|
||||
))}
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu.Portal>
|
||||
</DropdownMenu.Root>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user