mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-03 19:51:49 +00:00
Show the views in tool windows on the left
- Stripe toggles a Views window and a Contents window, as IntelliJ's tool windows - Views lists every view by group; a double click keeps its tab - Contents holds the shown view's own lists under Views, half the column - Remember which windows are open - Objects get a castle icon apart from the 3D world's box
This commit is contained in:
1 parent
fb083a4e25
commit
55af00b237
2 files changed
+123
-64
No files matched your search
@@ -152,6 +152,14 @@ export function MapStudio({ client, world, theme, onOpenPack, onDisconnect }: Ma
|
|||||||
useServerEvents(client, setPlayers, setUsage, tell, setConnected, packReloaded)
|
useServerEvents(client, setPlayers, setUsage, tell, setConnected, packReloaded)
|
||||||
|
|
||||||
const openView = useCallback((viewId: string) => setWorkbench((current) => showView(current, viewId, entryViews.has(viewId))), [entryViews])
|
const openView = useCallback((viewId: string) => setWorkbench((current) => showView(current, viewId, entryViews.has(viewId))), [entryViews])
|
||||||
|
const keepView = useCallback(
|
||||||
|
(viewId: string) =>
|
||||||
|
setWorkbench((current) => {
|
||||||
|
const shown = showView(current, viewId, false)
|
||||||
|
return keepTab(shown, focusedTab(shown).id)
|
||||||
|
}),
|
||||||
|
[]
|
||||||
|
)
|
||||||
const commands = useCommandRegistry()
|
const commands = useCommandRegistry()
|
||||||
const recent = useRecentTabs(setWorkbench)
|
const recent = useRecentTabs(setWorkbench)
|
||||||
|
|
||||||
@@ -232,7 +240,7 @@ export function MapStudio({ client, world, theme, onOpenPack, onDisconnect }: Ma
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<ViewList views={views} current={focused.viewId} onSelect={openView} slotRef={setSidebarSlot} />
|
<ViewList views={views} current={focused.viewId} onOpen={openView} onKeep={keepView} slotRef={setSidebarSlot} />
|
||||||
<TabCommands.Provider value={commands.register}>
|
<TabCommands.Provider value={commands.register}>
|
||||||
<PaneLayout workbench={workbench} change={change} viewLabel={viewLabel} renderTab={renderTab} keepsRunning={(tab) => showsMapOf(tab.viewId)} />
|
<PaneLayout workbench={workbench} change={change} viewLabel={viewLabel} renderTab={renderTab} keepsRunning={(tab) => showsMapOf(tab.viewId)} />
|
||||||
</TabCommands.Provider>
|
</TabCommands.Provider>
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
import { DropdownMenu } from 'radix-ui'
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import {
|
import {
|
||||||
AudioWaveform,
|
AudioWaveform,
|
||||||
Box,
|
Box,
|
||||||
|
Castle,
|
||||||
Boxes,
|
Boxes,
|
||||||
Droplets,
|
Droplets,
|
||||||
Fish,
|
Fish,
|
||||||
Flower2,
|
Flower2,
|
||||||
Gauge,
|
|
||||||
Gem,
|
Gem,
|
||||||
Globe,
|
|
||||||
HardDrive,
|
HardDrive,
|
||||||
ImageIcon,
|
ImageIcon,
|
||||||
Layers,
|
Layers,
|
||||||
|
LayoutGrid,
|
||||||
|
ListTree,
|
||||||
Map,
|
Map,
|
||||||
MountainSnow,
|
MountainSnow,
|
||||||
Package,
|
|
||||||
Palette,
|
Palette,
|
||||||
Pickaxe,
|
Pickaxe,
|
||||||
Pyramid,
|
Pyramid,
|
||||||
@@ -30,6 +29,8 @@ import {
|
|||||||
type LucideIcon
|
type LucideIcon
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
import { Kbd } from '@/components/ui/kbd'
|
import { Kbd } from '@/components/ui/kbd'
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import type { ViewInfo } from '../bridge/types'
|
import type { ViewInfo } from '../bridge/types'
|
||||||
import { viewShortcutId } from './shortcuts'
|
import { viewShortcutId } from './shortcuts'
|
||||||
@@ -54,22 +55,19 @@ const VIEW_ICONS: Record<string, LucideIcon> = {
|
|||||||
savedWorld: HardDrive,
|
savedWorld: HardDrive,
|
||||||
'iris:terrain/palettes': Palette,
|
'iris:terrain/palettes': Palette,
|
||||||
'iris:decorant/decorators': Flower2,
|
'iris:decorant/decorators': Flower2,
|
||||||
'iris:objects': Package,
|
'iris:objects': Castle,
|
||||||
'iris:objects/procedural': Workflow,
|
'iris:objects/procedural': Workflow,
|
||||||
noise: AudioWaveform,
|
noise: AudioWaveform,
|
||||||
imageMaps: ImageIcon,
|
imageMaps: ImageIcon,
|
||||||
pregen: Zap
|
pregen: Zap
|
||||||
}
|
}
|
||||||
const GROUP_ICONS: Record<string, LucideIcon> = {
|
|
||||||
WORLD: Globe,
|
|
||||||
BIOME_LAYERS: Layers,
|
|
||||||
DIAGNOSTICS: Gauge,
|
|
||||||
PACK: AudioWaveform,
|
|
||||||
BLOCKS: Boxes
|
|
||||||
}
|
|
||||||
const FALLBACK_ICON: LucideIcon = Shapes
|
const FALLBACK_ICON: LucideIcon = Shapes
|
||||||
|
/** Inset, because the stripe scrolls and so clips anything drawn outside its buttons. */
|
||||||
|
const STRIPE_BUTTON = 'flex size-[30px] shrink-0 items-center justify-center rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset'
|
||||||
|
const GROUP_LABEL = 'truncate px-2 pt-2 pb-1 text-[11px] font-semibold text-muted-foreground'
|
||||||
|
const OPEN_WINDOWS_KEY = 'studio.leftToolWindows'
|
||||||
|
|
||||||
/** The icon a view has on its tabs and in its group's list. */
|
/** The icon a view has on its tabs and in the list of views. */
|
||||||
export function ViewIcon({ viewId, className }: { viewId: string; className: string }): React.JSX.Element {
|
export function ViewIcon({ viewId, className }: { viewId: string; className: string }): React.JSX.Element {
|
||||||
const Icon = VIEW_ICONS[viewId] ?? FALLBACK_ICON
|
const Icon = VIEW_ICONS[viewId] ?? FALLBACK_ICON
|
||||||
return <Icon className={className} />
|
return <Icon className={className} />
|
||||||
@@ -79,29 +77,92 @@ interface ViewListProps {
|
|||||||
views: ViewInfo[]
|
views: ViewInfo[]
|
||||||
/** The view of the focused tab. */
|
/** The view of the focused tab. */
|
||||||
current: string
|
current: string
|
||||||
onSelect(view: string): void
|
onOpen(view: string): void
|
||||||
/** Receives the element the shown view fills with its own lists, beside the stripe. */
|
/** Opens a view in a tab of its own that the next view opened does not reuse. */
|
||||||
|
onKeep(view: string): void
|
||||||
|
/** Receives the element the shown view fills with its own lists, while the window holding them is open. */
|
||||||
slotRef(element: HTMLElement | null): void
|
slotRef(element: HTMLElement | null): void
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The views the server offers, as one button for each of their groups on the window's edge with the group's name under
|
* The tool windows on the window's left edge, as IntelliJ has them: the list of every view, and under it the lists of
|
||||||
* it, each opening the list of its views; beside it the island the focused tab's view fills with its own lists, which
|
* the view that is shown, each opened and closed from its icon on the stripe and both sharing the column when open.
|
||||||
* is not there for a view without any (IntelliJ's tool window stripe with its names shown).
|
|
||||||
*/
|
*/
|
||||||
export function ViewList({ views, current, onSelect, slotRef }: ViewListProps): React.JSX.Element {
|
export function ViewList({ views, current, onOpen, onKeep, slotRef }: ViewListProps): React.JSX.Element {
|
||||||
|
const [open, toggle] = useOpenWindows()
|
||||||
|
const currentLabel = views.find((view) => view.id === current)?.label ?? current
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<nav aria-label="Views" className="flex w-16 shrink-0 flex-col items-center gap-1 overflow-y-auto pt-1 pb-1.5">
|
<nav aria-label="Tool windows" className="flex w-10 shrink-0 flex-col items-center gap-2.5 overflow-y-auto pt-1 pb-1.5">
|
||||||
{groupsOf(views).map((group) => (
|
<WindowButton label="Views" Icon={LayoutGrid} open={open.views} onToggle={() => toggle('views')} />
|
||||||
<GroupButton key={group.id} group={group} current={current} onSelect={onSelect} />
|
<span className="my-0.5 h-px w-5 shrink-0 bg-input" />
|
||||||
))}
|
<WindowButton label="Contents" Icon={ListTree} open={open.contents} onToggle={() => toggle('contents')} />
|
||||||
</nav>
|
</nav>
|
||||||
<div ref={slotRef} className="flex w-60 shrink-0 flex-col overflow-hidden rounded-[10px] bg-card empty:hidden" />
|
<div className="flex w-60 shrink-0 flex-col overflow-hidden rounded-[10px] bg-card empty:hidden">
|
||||||
|
{open.views && <ViewsWindow views={views} current={current} onOpen={onOpen} onKeep={onKeep} />}
|
||||||
|
{open.contents && (
|
||||||
|
<section
|
||||||
|
aria-label="Contents"
|
||||||
|
className={cn(
|
||||||
|
'flex min-h-[50%] flex-1 flex-col has-[>div:empty]:min-h-0 has-[>div:empty]:flex-none',
|
||||||
|
open.views && 'border-t'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div ref={slotRef} className="peer flex min-h-0 flex-1 flex-col empty:hidden" />
|
||||||
|
<p className="hidden px-4 py-2.5 text-[12px] text-muted-foreground peer-empty:block">Nothing to show for {currentLabel}</p>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface OpenWindows {
|
||||||
|
views: boolean
|
||||||
|
contents: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Which tool windows are open, kept for the next time the studio opens; both are at first. */
|
||||||
|
function useOpenWindows(): [OpenWindows, (window: keyof OpenWindows) => void] {
|
||||||
|
const [open, setOpen] = useState<OpenWindows>(() => ({ views: true, contents: true, ...storedOpenWindows() }))
|
||||||
|
const toggle = (window: keyof OpenWindows): void => {
|
||||||
|
const next = { ...open, [window]: !open[window] }
|
||||||
|
localStorage.setItem(OPEN_WINDOWS_KEY, JSON.stringify(next))
|
||||||
|
setOpen(next)
|
||||||
|
}
|
||||||
|
return [open, toggle]
|
||||||
|
}
|
||||||
|
|
||||||
|
function storedOpenWindows(): Partial<OpenWindows> {
|
||||||
|
try {
|
||||||
|
const stored: unknown = JSON.parse(localStorage.getItem(OPEN_WINDOWS_KEY) ?? '{}')
|
||||||
|
return typeof stored === 'object' && stored !== null ? (stored as Partial<OpenWindows>) : {}
|
||||||
|
} catch {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WindowButtonProps {
|
||||||
|
label: string
|
||||||
|
Icon: LucideIcon
|
||||||
|
open: boolean
|
||||||
|
onToggle(): void
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A tool window's icon on the stripe, which opens it and closes it again. */
|
||||||
|
function WindowButton({ label, Icon, open, onToggle }: WindowButtonProps): React.JSX.Element {
|
||||||
|
return (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<button aria-label={label} aria-pressed={open} onClick={onToggle} className={cn(STRIPE_BUTTON, open ? 'bg-secondary' : 'hover:bg-accent')}>
|
||||||
|
<Icon className="size-5" />
|
||||||
|
</button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent side="right">{label}</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
interface ViewGroup {
|
interface ViewGroup {
|
||||||
id: string
|
id: string
|
||||||
label: string
|
label: string
|
||||||
@@ -116,47 +177,37 @@ function groupsOf(views: ViewInfo[]): ViewGroup[] {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function GroupButton({ group, current, onSelect }: { group: ViewGroup; current: string; onSelect(view: string): void }): React.JSX.Element {
|
/** Every view by group; a click shows one, a double click keeps its tab, as IntelliJ's project view opens files. */
|
||||||
|
function ViewsWindow({ views, current, onOpen, onKeep }: Omit<ViewListProps, 'slotRef'>): React.JSX.Element {
|
||||||
const keyText = useKeyText()
|
const keyText = useKeyText()
|
||||||
const [open, setOpen] = useState(false)
|
|
||||||
const Icon = GROUP_ICONS[group.id] ?? FALLBACK_ICON
|
|
||||||
const holdsCurrent = group.views.some((view) => view.id === current)
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu.Root open={open} onOpenChange={setOpen}>
|
<section aria-label="Views" className="flex min-h-0 flex-1 flex-col">
|
||||||
<DropdownMenu.Trigger asChild>
|
<h2 className="shrink-0 px-4 pt-2.5 pb-1 text-[13px] font-semibold">Views</h2>
|
||||||
<button
|
<ScrollArea className="min-h-0 flex-1">
|
||||||
aria-label={group.label}
|
<div className="px-2 pb-1.5">
|
||||||
className={cn(
|
{groupsOf(views).map((group) => (
|
||||||
'flex w-[60px] shrink-0 flex-col items-center gap-0.5 rounded-lg px-0.5 pt-1.5 pb-1 outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset',
|
<div key={group.id} role="group" aria-label={group.label}>
|
||||||
holdsCurrent || open ? 'bg-accent text-foreground' : 'text-secondary-text hover:bg-accent hover:text-foreground'
|
<h3 className={GROUP_LABEL}>{group.label}</h3>
|
||||||
)}
|
{group.views.map((view) => (
|
||||||
>
|
<button
|
||||||
<Icon className="size-5" strokeWidth={1.6} />
|
key={view.id}
|
||||||
<span className="line-clamp-2 w-full text-center text-[10px] leading-[1.15]">{group.label}</span>
|
title={view.description}
|
||||||
</button>
|
aria-current={view.id === current || undefined}
|
||||||
</DropdownMenu.Trigger>
|
onClick={() => onOpen(view.id)}
|
||||||
<DropdownMenu.Portal>
|
onDoubleClick={() => onKeep(view.id)}
|
||||||
<DropdownMenu.Content side="right" align="start" sideOffset={6} className="popup z-50 w-60 p-1 popup-motion">
|
className={cn('flex h-[26px] w-full items-center gap-2 rounded-md px-2 text-left', view.id === current ? 'bg-selection' : 'hover:bg-accent')}
|
||||||
<DropdownMenu.Label className="px-2 pt-1 pb-1 text-[11px] font-semibold text-muted-foreground">{group.label}</DropdownMenu.Label>
|
>
|
||||||
{group.views.map((view) => (
|
<ViewIcon viewId={view.id} className="size-3.5 shrink-0" />
|
||||||
<DropdownMenu.Item
|
<span className="min-w-0 flex-1 truncate">{view.label}</span>
|
||||||
key={view.id}
|
{keyText(viewShortcutId(view.id)) !== '' && (
|
||||||
title={view.description}
|
<Kbd className="h-4 min-w-4 border border-input/60 bg-transparent text-[10px] uppercase">{keyText(viewShortcutId(view.id))}</Kbd>
|
||||||
onSelect={() => onSelect(view.id)}
|
)}
|
||||||
className={cn(
|
</button>
|
||||||
'flex h-[26px] cursor-default items-center gap-2 rounded-md px-2 outline-none data-[highlighted]:bg-accent',
|
))}
|
||||||
view.id === current && 'bg-selection'
|
</div>
|
||||||
)}
|
|
||||||
>
|
|
||||||
<ViewIcon viewId={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.Content>
|
</div>
|
||||||
</DropdownMenu.Portal>
|
</ScrollArea>
|
||||||
</DropdownMenu.Root>
|
</section>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user