feat(ui): extend shared tree actions and BIM tool menus

This commit is contained in:
Codex
2026-11-14 21:55:07 +03:00
parent 91a5ebe8da
commit 6f2f9644fe
8 changed files with 35 additions and 13 deletions
+4 -3
View File
@@ -230,7 +230,7 @@ const iconGroups: Array<{ title: string; note: string; icons: IconName[] }> = [
{
title: "Редактирование",
note: "Launcher / SEO",
icons: ["save", "edit", "trash", "copy", "upload", "download", "external", "rotate-clockwise", "add-point", "orthographic", "perspective", "select", "pen", "rectangle", "curve", "undo", "redo"],
icons: ["save", "edit", "trash", "copy", "upload", "download", "external", "rotate-clockwise", "add-point", "ruler", "section", "isolate", "orthographic", "perspective", "select", "pen", "rectangle", "curve", "undo", "redo"],
},
{
title: "Состояние и доступ",
@@ -250,6 +250,7 @@ const iconGroups: Array<{ title: string; note: string; icons: IconName[] }> = [
];
const iconLabels: Record<IconName, string> = {
ruler: "Линейка", section: "Секущая плоскость", isolate: "Изолировать элемент",
power: "Питание",
move: "Свободное окно",
"add-point":"Добавить точку",orthographic:"Ортографическая проекция",perspective:"Перспективная проекция",select:"Выделение",pen:"Перо",rectangle:"Прямоугольник",curve:"Кривая",undo:"Отменить",redo:"Повторить",
@@ -2357,7 +2358,7 @@ export function CatalogApp() {
maxSize={toolbarMaxSize}
lensCount={toolbarLensCount}
autoHide={toolbarAutoHide}
hideDelay={toolbarHideDelay} gap={toolbarGap}
hideDelay={toolbarHideDelay} gap={toolbarGap} menuWidth={320}
items={[{id:"hold",label:toolbarAutoHide?"Hold · Закрепить тулбар":"Hold · Открепить тулбар",icon:"lock",active:!toolbarAutoHide,onSelect:()=>setToolbarAutoHide(v=>!v)}, ...(Object.entries(sectionDefinitions) as Array<[CatalogSection, (typeof sectionDefinitions)[CatalogSection]]>).map(([id, item]) => ({
id,
label: item.title,
@@ -2370,7 +2371,7 @@ export function CatalogApp() {
) : null}
<Window open={treeDemoOpen} title="Объекты сцены" placement="end" resizable draggable rect={treeDemoRect} onRectCommit={setTreeDemoRect} onClose={()=>setTreeDemoOpen(false)}>
<Tree label="Пример дерева объектов" selected={treeSelected} onSelect={setTreeSelected} onVisibilityChange={(_,visible)=>setTreeVisible(visible)} nodes={[{id:'scene',label:'Сцена',children:[{id:'model',label:'Модель',children:[{id:'cells',label:'Ячейки / внутренний блок',visible:treeVisible},{id:'panel',label:'Боковая панель корпуса / длинное название детали'}]}]}]}/>
<Tree defaultExpandedDepth={2} renderActions={node=><Dropdown width={320} trigger={({setTriggerRef,show,toggle,open})=><IconButton ref={setTriggerRef} label={`Информация: ${node.label}`} aria-expanded={open} onMouseEnter={show} onFocus={show} onClick={toggle}><Icon name="info"/></IconButton>}><Description>{node.label}</Description></Dropdown>} label="Пример дерева объектов" selected={treeSelected} onSelect={setTreeSelected} onVisibilityChange={(_,visible)=>setTreeVisible(visible)} nodes={[{id:'scene',label:'Сцена',children:[{id:'model',label:'Модель',children:[{id:'cells',label:'Ячейки / внутренний блок',visible:treeVisible},{id:'panel',label:'Боковая панель корпуса / длинное название детали'}]}]}]}/>
</Window>
<Window
open={inspectorOpen}
+2
View File
@@ -568,3 +568,5 @@ The shared theme supports `edges: "flat"` for borderless surfaces, including por
## PathBar (DOM)
`renderPathBar(target, items, {icon, onNavigate})` — компактная строка пути в стиле Finder: нейтральные иконки папок, текст и разделители `›`, без pill-кнопок. Подключается `@nodedc/ui-dom/styles.css`. Папки — клавиатурно доступные кнопки; конечный файл — текст с `aria-current`. Длинный путь прокручивается по горизонтали. Consumer передаёт пути и существующий Icon, хранение и навигация остаются в приложении. Живой пример: «Размер DOM-окна».
Toolbar `menuWidth` controls inspector menu width (default 220 px, bounded 180–600 px); Dropdown retains viewport clamping. Tree `renderActions(node)` supports per-item information menus without duplicating the outliner. `defaultExpandedDepth` limits initial expansion; selecting an item still reveals and scrolls to its ancestors. BIM uses canonical `ruler` (Ruler), `section` (Slice), and `isolate` (Focus) glyphs.
+3
View File
@@ -4740,3 +4740,6 @@ textarea.nodedc-field__control {
:is(.nodedc-viewport-controls, .nodedc-scene-controls) :is(.nodedc-icon-button, .nodedc-button:is([data-variant="secondary"], [data-variant="ghost"]), .nodedc-workspace-window__action):hover:not(:disabled):not([aria-pressed="true"]) {
background: color-mix(in srgb, var(--nodedc-text-primary) 12%, rgb(var(--nodedc-modal-glass-tint-rgb) / var(--nodedc-scene-glass-opacity)));
}
.nodedc-tree__actions {display:flex;flex:none;align-items:center;}
.nodedc-tree__actions .nodedc-icon-button {width:24px;height:24px;min-width:24px;padding:0;}
+6
View File
@@ -1,5 +1,8 @@
import {
MousePointer2,
Ruler,
Slice,
Focus,
Move,
CirclePlus,
Box,
@@ -72,6 +75,9 @@ import {
const icons = {
"add-point": CirclePlus,
ruler: Ruler,
section: Slice,
isolate: Focus,
perspective: Box,
orthographic: Scan,
select: MousePointer2,
+4 -1
View File
@@ -38,6 +38,8 @@ export interface ToolbarProps<T extends string = string> {
hideDelay?: number;
gap?: number;
label?: string;
/** Dropdown width; placement still clamps to the visible viewport. */
menuWidth?: number;
className?: string;
/** Render inside a positioned viewport; edge reveal follows that viewport. */
container?: HTMLElement;
@@ -66,6 +68,7 @@ export function Toolbar<T extends string = string>({
hideDelay = NODEDC_TOOLBAR_DEFAULTS.hideDelay,
gap = NODEDC_TOOLBAR_DEFAULTS.gap,
label = "Панель инструментов",
menuWidth = 220,
className,
container,
}: ToolbarProps<T>) {
@@ -392,7 +395,7 @@ export function Toolbar<T extends string = string>({
if(placement==="left")return {...b.toJSON(),left:t.left,right:t.left+pad,width:pad};
if(placement==="bottom")return {...b.toJSON(),top:t.bottom-pad,bottom:t.bottom,height:pad};
return {...b.toJSON(),top:t.top,bottom:t.top+pad,height:pad};
}} width={220} trigger={button} onPointerDownOutside={event=>{
}} width={Number.isFinite(menuWidth)?Math.max(180,Math.min(600,menuWidth)):220} trigger={button} onPointerDownOutside={event=>{
const target=event.target as Element;
// Dismiss a menu before a viewport tool can turn this same click into an edit.
if(container?.contains(target)&&!target.closest('button,input,select,textarea,a,[role="button"],[role="tab"]')){
+8 -7
View File
@@ -1,12 +1,12 @@
import {useLayoutEffect,useRef,useState,type CSSProperties} from 'react';
import {useLayoutEffect,useRef,useState,type CSSProperties,type ReactNode} from 'react';
import {Icon,type IconName} from './Icon.js';
export interface TreeNode {id:string;label:string;children?:TreeNode[];icon?:IconName;visible?:boolean}
export interface TreeProps {nodes:TreeNode[];selected:string|null;onSelect:(id:string)=>void;onVisibilityChange?:(id:string,visible:boolean)=>void;label:string;query?:string;revealKey?:number}
export interface TreeProps {nodes:TreeNode[];selected:string|null;onSelect:(id:string)=>void;onVisibilityChange?:(id:string,visible:boolean)=>void;label:string;query?:string;revealKey?:number;defaultExpandedDepth?:number;renderActions?:(node:TreeNode)=>ReactNode}
/** Compact outliner. Selection reveals ancestors without scrolling its host page. */
export function Tree({nodes,selected,onSelect,onVisibilityChange,label,query='',revealKey}:TreeProps){
const [collapsed,setCollapsed]=useState<Set<string>>(()=>new Set());
export function Tree({nodes,selected,onSelect,onVisibilityChange,label,query='',revealKey,defaultExpandedDepth=Infinity,renderActions}:TreeProps){
const [collapsed,setCollapsed]=useState<Map<string,boolean>>(()=>new Map());
const [focus,setFocus]=useState<string|null>(null);
const host=useRef<HTMLDivElement>(null),elements=useRef(new Map<string,HTMLDivElement>());
const parents=new Map<string,string>(),index=new Map<string,TreeNode>();
@@ -14,11 +14,11 @@ export function Tree({nodes,selected,onSelect,onVisibilityChange,label,query='',
const ancestors=new Set<string>();let parent=selected?parents.get(selected):undefined;while(parent){ancestors.add(parent);parent=parents.get(parent);}
const matches=(item:TreeNode):boolean=>!query||item.label.toLocaleLowerCase().includes(query.toLocaleLowerCase())||!!item.children?.some(matches);
const rows:{node:TreeNode;depth:number;open:boolean}[]=[];
const flatten=(items:TreeNode[],depth=0)=>{for(const node of items){if(!matches(node))continue;const open=!!query||!collapsed.has(node.id);rows.push({node,depth,open});if(open)flatten(node.children??[],depth+1);}};flatten(nodes);
const flatten=(items:TreeNode[],depth=0)=>{for(const node of items){if(!matches(node))continue;const open=!!query||!(collapsed.get(node.id)??depth>=defaultExpandedDepth);rows.push({node,depth,open});if(open)flatten(node.children??[],depth+1);}};flatten(nodes);
const reveal=(id:string)=>{const target=elements.current.get(id),container=host.current;if(!target||!container)return;const row=target.getBoundingClientRect(),box=container.getBoundingClientRect();if(row.top<box.top)container.scrollTop-=box.top-row.top;else if(row.bottom>box.bottom)container.scrollTop+=row.bottom-box.bottom;};
useLayoutEffect(()=>{if(selected){setFocus(selected);setCollapsed(old=>{if(![...ancestors].some(id=>old.has(id)))return old;const next=new Set(old);for(const id of ancestors)next.delete(id);return next;});}},[selected,revealKey]);
useLayoutEffect(()=>{if(selected){setFocus(selected);setCollapsed(old=>{if([...ancestors].every(id=>old.get(id)===false))return old;const next=new Map(old);for(const id of ancestors)next.set(id,false);return next;});}},[selected,revealKey,nodes]);
useLayoutEffect(()=>{if(selected)reveal(selected);},[selected,revealKey,query,collapsed]);
const toggle=(id:string)=>setCollapsed(old=>{const next=new Set(old);if(next.has(id))next.delete(id);else next.add(id);return next;});
const toggle=(id:string)=>setCollapsed(old=>{const next=new Map(old);const depth=rows.find(row=>row.node.id===id)?.depth??0;next.set(id,!(old.get(id)??depth>=defaultExpandedDepth));return next;});
const select=(id:string)=>{setFocus(id);onSelect(id);elements.current.get(id)?.focus({preventScroll:true});reveal(id);};
return <div ref={host} className="nodedc-tree" role="tree" aria-label={label}>
{rows.map(({node,depth,open},position)=><div key={node.id} ref={element=>{if(element)elements.current.set(node.id,element);else elements.current.delete(node.id);}} role="treeitem" aria-level={depth+1} aria-selected={selected===node.id} aria-expanded={node.children?.length?open:undefined} tabIndex={(focus??selected??rows[0]?.node.id)===node.id?0:-1} className="nodedc-tree__row" style={{'--tree-depth':depth} as CSSProperties} title={node.label} onFocus={()=>setFocus(node.id)} onClick={()=>select(node.id)} onDoubleClick={()=>node.children?.length&&toggle(node.id)} onKeyDown={event=>{
@@ -37,6 +37,7 @@ export function Tree({nodes,selected,onSelect,onVisibilityChange,label,query='',
<span className="nodedc-tree__branch">{node.children?.length?<button type="button" tabIndex={-1} aria-label={`${open?'Свернуть':'Развернуть'} ${node.label}`} onClick={event=>{event.stopPropagation();toggle(node.id);}}><Icon name={open?'chevron-down':'chevron-right'} size={14}/></button>:null}</span>
<Icon name={node.icon??(node.children?.length?'folder':'layers')} size={14}/>
<span className="nodedc-tree__label">{node.label}</span>
{renderActions&&<span className="nodedc-tree__actions" onClick={event=>event.stopPropagation()} onDoubleClick={event=>event.stopPropagation()}>{renderActions(node)}</span>}
{onVisibilityChange&&node.visible!==undefined&&<button type="button" className="nodedc-tree__visibility" tabIndex={focus===node.id?0:-1} aria-label={`${node.visible?'Скрыть':'Показать'} ${node.label}`} aria-pressed={node.visible} onClick={event=>{event.stopPropagation();onVisibilityChange(node.id,!node.visible);}}><Icon name={node.visible?'eye':'eye-off'} size={14}/></button>}
</div>)}
</div>;
+4 -1
View File
@@ -813,6 +813,7 @@
"viewport container scope with local edge reveal",
"native tooltips with keyboard shortcut hints",
"optional canonical dropdown for toolbar item menus",
"bounded menuWidth for rich inspectors; default remains 220 px",
"theme-independent geometry",
"menus outside maximum magnified icon envelope",
"bounded triangle intent corridor before sibling menu activation",
@@ -1292,7 +1293,9 @@
"selection expands ancestors and scrolls only the tree container",
"Arrow/Home/End navigation, disclosure and optional visibility actions",
"long names ellipsize without growing row height",
"filter retains matching ancestors"
"filter retains matching ancestors",
"optional renderActions slot composes canonical controls without selecting the row",
"defaultExpandedDepth limits initial expansion; external selection reveals ancestors"
],
"rules": [
"Use for object hierarchies; no nested ResourceRow cards.",
+4 -1
View File
@@ -79,7 +79,10 @@
"curve",
"undo",
"redo",
"add-point"
"add-point",
"ruler",
"section",
"isolate"
]
},
{