diff --git a/apps/catalog/package.json b/apps/catalog/package.json index 1f258f5..bcbd885 100644 --- a/apps/catalog/package.json +++ b/apps/catalog/package.json @@ -11,8 +11,8 @@ }, "dependencies": { "@nodedc/page-patterns": "0.1.0", - "@nodedc/ui-core": "0.7.3", - "@nodedc/ui-react": "0.7.8", + "@nodedc/ui-core": "0.7.4", + "@nodedc/ui-react": "0.7.9", "cesium": "1.147.0", "react": "^19.1.0", "react-dom": "^19.1.0" diff --git a/docs/COMPONENTS.md b/docs/COMPONENTS.md index 1e25d64..65da06c 100644 --- a/docs/COMPONENTS.md +++ b/docs/COMPONENTS.md @@ -626,3 +626,5 @@ window kind alongside `rect/onRectCommit`. See WINDOWS_AND_LAYERS.md. keeps the shared drag handle and activation threshold. The default stays vertical. Для ручки поверх фотографии используйте `DragHandle surface="control"` или `SortableList handleSurface="control"`: видимый круг с общим стеклом внутри `nodedc-viewport-controls`. Bare-ручка остаётся вариантом по умолчанию для обычных строк. + +Window `headerLayout="adaptive"` keeps contextual actions on one trailing row. The complete title moves below actions before clipping. The measured action width sets the minimum for all resize edges, keyboard resizing and restored layout; only an undersized device viewport allows horizontal action scrolling. `expanded` temporarily fits the window to the available viewport while retaining modal/floating presentation. Users can resize the expanded window; restoration returns the previous geometry without persisting the temporary rectangle. diff --git a/package-lock.json b/package-lock.json index cbb9293..7cb378f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,8 +28,8 @@ "version": "0.7.0", "dependencies": { "@nodedc/page-patterns": "0.1.0", - "@nodedc/ui-core": "0.7.3", - "@nodedc/ui-react": "0.7.8", + "@nodedc/ui-core": "0.7.4", + "@nodedc/ui-react": "0.7.9", "cesium": "1.147.0", "react": "^19.1.0", "react-dom": "^19.1.0" @@ -2516,7 +2516,7 @@ }, "packages/ui-core": { "name": "@nodedc/ui-core", - "version": "0.7.3", + "version": "0.7.4", "dependencies": { "@nodedc/tokens": "0.6.0" } @@ -2525,17 +2525,17 @@ "name": "@nodedc/ui-dom", "version": "0.7.0", "dependencies": { - "@nodedc/ui-core": "0.7.3" + "@nodedc/ui-core": "0.7.4" } }, "packages/ui-react": { "name": "@nodedc/ui-react", - "version": "0.7.8", + "version": "0.7.9", "dependencies": { "@dnd-kit/core": "^6.3.1", "@dnd-kit/sortable": "^10.0.0", "@dnd-kit/utilities": "^3.2.2", - "@nodedc/ui-core": "0.7.3", + "@nodedc/ui-core": "0.7.4", "lucide-react": "^0.468.0" }, "devDependencies": { diff --git a/packages/ui-core/package.json b/packages/ui-core/package.json index 4434347..4a03732 100644 --- a/packages/ui-core/package.json +++ b/packages/ui-core/package.json @@ -1,6 +1,6 @@ { "name": "@nodedc/ui-core", - "version": "0.7.3", + "version": "0.7.4", "type": "module", "files": [ "dist", diff --git a/packages/ui-core/styles.css b/packages/ui-core/styles.css index e45a4cf..a6844a2 100644 --- a/packages/ui-core/styles.css +++ b/packages/ui-core/styles.css @@ -4902,3 +4902,11 @@ textarea.nodedc-field__control { -webkit-backdrop-filter:blur(var(--nodedc-scene-glass-blur)) saturate(var(--nodedc-modal-glass-saturation)); } .nodedc-drag-handle[data-surface="control"]:hover {background:var(--nodedc-glass-control-hover);} + +/* An adaptive action row defines the minimum resizable width. */ +.nodedc-window[data-header-layout="adaptive"]>.nodedc-window__head>.nodedc-window__actions{flex-wrap:nowrap;width:max-content;max-width:100%;justify-self:end;overflow-x:auto} +.nodedc-window[data-header-stacked="true"]>.nodedc-window__head{grid-template-columns:minmax(0,1fr)} +.nodedc-window[data-header-stacked="true"]>.nodedc-window__head>.nodedc-window__actions{grid-row:1} +.nodedc-window[data-header-stacked="true"]>.nodedc-window__head>.nodedc-window__titles{grid-row:2} + +.nodedc-window[data-header-layout="adaptive"]>.nodedc-window__head>.nodedc-window__actions>*{flex-shrink:0} diff --git a/packages/ui-dom/package.json b/packages/ui-dom/package.json index 518d549..93696ab 100644 --- a/packages/ui-dom/package.json +++ b/packages/ui-dom/package.json @@ -20,6 +20,6 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@nodedc/ui-core": "0.7.3" + "@nodedc/ui-core": "0.7.4" } } diff --git a/packages/ui-react/package.json b/packages/ui-react/package.json index 4b37e1d..79f66b1 100644 --- a/packages/ui-react/package.json +++ b/packages/ui-react/package.json @@ -1,6 +1,6 @@ { "name": "@nodedc/ui-react", - "version": "0.7.8", + "version": "0.7.9", "type": "module", "files": [ "dist" @@ -21,7 +21,7 @@ "@dnd-kit/core": "^6.3.1", "@dnd-kit/sortable": "^10.0.0", "@dnd-kit/utilities": "^3.2.2", - "@nodedc/ui-core": "0.7.3", + "@nodedc/ui-core": "0.7.4", "lucide-react": "^0.468.0" }, "peerDependencies": { diff --git a/packages/ui-react/src/Window.tsx b/packages/ui-react/src/Window.tsx index bcebe37..6b9dc19 100644 --- a/packages/ui-react/src/Window.tsx +++ b/packages/ui-react/src/Window.tsx @@ -40,6 +40,10 @@ export interface WindowProps extends Omit, "title footer?: ReactNode; /** Context actions beside close, using canonical IconButton controls. */ headerActions?: ReactNode; + /** Keep actions on one line; place title below them when space is limited. */ + headerLayout?: "inline" | "adaptive"; + /** Temporarily enlarge within the viewport; restoring retains prior geometry and presentation. */ + expanded?: boolean; /** Keep contextual actions immediately before close when requested. */ headerActionsPlacement?: "before-move" | "before-close"; size?: WindowSize; @@ -72,6 +76,8 @@ export function Window({ children, footer, headerActions, + headerLayout = "inline", + expanded = false, headerActionsPlacement = "before-move", size = "md", placement = "center", @@ -99,6 +105,9 @@ export function Window({ const titleId = useId(); const descriptionId = useId(); const dialogRef = useRef(null); + const minimumRef = useRef({width:320,height:200}); + const [headerMinimum,setHeaderMinimum]=useState(320); + const [stackedTitle,setStackedTitle]=useState(false); const portalHostRef = useRef(null); const onCloseRef = useRef(onClose); const dragRef = useRef<{ pointerId: number; offsetX: number; offsetY: number } | null>(null); @@ -107,13 +116,15 @@ export function Window({ const [floatingRect, setFloatingRect] = useState(null); const rectRef = useRef(null); const initialRectRef = useRef(null); + const expansionRestoreRef = useRef(null); const commitRef = useRef(onRectCommit); - commitRef.current = onRectCommit; + // Temporary media expansion never replaces the application-owned window layout. + commitRef.current = expanded ? undefined : onRectCommit; const changeRect = (next: WindowRect | null) => { rectRef.current = next; setFloatingRect(next); }; const gestureChanged = useRef(false); const resizeRef = useRef<{ pointerId: number; x: number; y: number; rect: WindowRect; edge: ResizeEdge } | null>(null); const isFloating = (controlledFloating ?? floating) && allowFloating && placement === "center"; - const freeGeometry = isFloating || (resizable && placement === "end"); + const freeGeometry = expanded || isFloating || (resizable && placement === "end"); const canDrag = draggable || freeGeometry; const shouldLockBodyScroll = !suspended && !isFloating && (lockBodyScroll ?? placement === "center"); const shouldTrapFocus = !suspended && !isFloating && (trapFocus ?? placement === "center"); @@ -121,6 +132,31 @@ export function Window({ modeRef.current = { shouldTrapFocus, isFloating, suspended }; onCloseRef.current = onClose; + useLayoutEffect(()=>{ + if(!open || headerLayout!=="adaptive")return; + const dialog=dialogRef.current,head=dialog?.querySelector(".nodedc-window__head"),actions=head?.querySelector(".nodedc-window__actions"),heading=head?.querySelector(".nodedc-window__title"); + if(!dialog||!head||!actions||!heading)return; + const measure=()=>{ + const headStyle=window.getComputedStyle(head),input=heading.querySelector("input"),copyStyle=window.getComputedStyle(input??heading); + const sample=document.createElement("span"); + Object.assign(sample.style,{position:"fixed",visibility:"hidden",pointerEvents:"none",whiteSpace:"pre",font:copyStyle.font,letterSpacing:copyStyle.letterSpacing}); + sample.textContent=input?.value??heading.textContent??"";head.appendChild(sample); + const titleWidth=sample.getBoundingClientRect().width+(parseFloat(copyStyle.paddingLeft)||0)+(parseFloat(copyStyle.paddingRight)||0);sample.remove(); + const padding=(parseFloat(headStyle.paddingLeft)||0)+(parseFloat(headStyle.paddingRight)||0),actionWidth=actions.scrollWidth; + const minimum=Math.max(320,Math.ceil(actionWidth+padding+2)); + minimumRef.current={width:minimum,height:200};setHeaderMinimum(minimum); + setStackedTitle(head.clientWidth < padding+actionWidth+titleWidth+(parseFloat(headStyle.columnGap)||0)+2); + if(freeGeometry&&rectRef.current){ + const fitted=fitWindow(rectRef.current,{width:window.innerWidth,height:window.innerHeight},minimumRef.current); + if(fitted.left!==rectRef.current.left||fitted.top!==rectRef.current.top||fitted.width!==rectRef.current.width||fitted.height!==rectRef.current.height){changeRect(fitted);if(!resizeRef.current&&!dragRef.current)commitRef.current?.(fitted);} + } + }; + measure(); + const observer=typeof ResizeObserver!=="undefined"?new ResizeObserver(measure):null; + observer?.observe(head);observer?.observe(actions);window.addEventListener("resize",measure); + return()=>{observer?.disconnect();window.removeEventListener("resize",measure);}; + },[open,headerLayout,title,headerActions,freeGeometry]); + useEffect(() => { if (!open || typeof document === "undefined") return; const previousActiveElement = document.activeElement instanceof HTMLElement ? document.activeElement : null; @@ -183,20 +219,37 @@ export function Window({ }, [open, shouldLockBodyScroll]); useLayoutEffect(() => { - if (open && freeGeometry && !dragRef.current && !resizeRef.current) { + if (!open) return; + const viewport={width:window.innerWidth,height:window.innerHeight}; + if(expanded){ + if(!expansionRestoreRef.current){ + const bounds=dialogRef.current?.getBoundingClientRect(); + if(bounds){ + expansionRestoreRef.current=rectRef.current??{left:bounds.left,top:bounds.top,width:bounds.width,height:bounds.height}; + changeRect(fitWindow({left:16,top:16,width:viewport.width-32,height:viewport.height-32},viewport,minimumRef.current)); + } + } + return; + } + if(expansionRestoreRef.current){ + changeRect(fitWindow(expansionRestoreRef.current,viewport,minimumRef.current)); + expansionRestoreRef.current=null; + return; + } + if (freeGeometry && !dragRef.current && !resizeRef.current) { // The modal move toggle already restores its local rectangle. An // uncontrolled floating window must retain it when toggled twice. if (placement === "center" && !onRectCommit && !rect && rectRef.current) return; const bounds=dialogRef.current?.getBoundingClientRect(); if(bounds){ initialRectRef.current ??= initialRect??{left:bounds.left,top:bounds.top,width:bounds.width,height:bounds.height}; - changeRect(fitWindow(rect??initialRectRef.current,{width:window.innerWidth,height:window.innerHeight})); + changeRect(fitWindow(rect??initialRectRef.current,{width:window.innerWidth,height:window.innerHeight},minimumRef.current)); } } - },[open,freeGeometry,rect?.left,rect?.top,rect?.width,rect?.height]); + },[open,expanded,freeGeometry,rect?.left,rect?.top,rect?.width,rect?.height]); useEffect(() => { - if (!open) { setDragPosition(null); setFloating(false); changeRect(null); initialRectRef.current = null; dragRef.current = null; resizeRef.current = null; } + if (!open) { setDragPosition(null); setFloating(false); changeRect(null); initialRectRef.current = null; expansionRestoreRef.current = null; dragRef.current = null; resizeRef.current = null; } }, [open]); useEffect(() => { @@ -205,7 +258,7 @@ export function Window({ const resizing = resizeRef.current; if (resizing && event.pointerId === resizing.pointerId) { gestureChanged.current = true; - changeRect(resizeWindow(resizing.rect, resizing.edge, event.clientX - resizing.x, event.clientY - resizing.y, { width: window.innerWidth, height: window.innerHeight })); + changeRect(resizeWindow(resizing.rect, resizing.edge, event.clientX - resizing.x, event.clientY - resizing.y, { width: window.innerWidth, height: window.innerHeight },minimumRef.current)); return; } const drag = dragRef.current; @@ -214,7 +267,7 @@ export function Window({ const bounds = dialog.getBoundingClientRect(); if (freeGeometry) { gestureChanged.current = true; - changeRect(fitWindow({ left: event.clientX - drag.offsetX, top: event.clientY - drag.offsetY, width: bounds.width, height: bounds.height }, { width: window.innerWidth, height: window.innerHeight })); + changeRect(fitWindow({ left: event.clientX - drag.offsetX, top: event.clientY - drag.offsetY, width: bounds.width, height: bounds.height }, { width: window.innerWidth, height: window.innerHeight },minimumRef.current)); return; } const left = Math.max(8, Math.min(window.innerWidth - bounds.width - 8, event.clientX - drag.offsetX)); @@ -239,10 +292,10 @@ export function Window({ useEffect(() => { if (!freeGeometry || !open) return; - const fit = () => { if(rectRef.current) changeRect(fitWindow(rect ?? rectRef.current, { width: window.innerWidth, height: window.innerHeight })); }; + const fit = () => { if(rectRef.current) changeRect(fitWindow((expanded ? null : rect) ?? rectRef.current, { width: window.innerWidth, height: window.innerHeight },minimumRef.current)); }; window.addEventListener("resize", fit); return () => window.removeEventListener("resize", fit); - }, [freeGeometry, open, rect]); + }, [freeGeometry, open, rect, expanded]); if (!open || typeof document === "undefined") return null; @@ -258,12 +311,16 @@ export function Window({ if (!portalHostRef.current || !fullscreen || !dialogRef.current?.contains(fullscreen)) { portalHostRef.current = fullscreen ?? document.body; } + const baseStyle={...style,...(headerLayout==="adaptive"?{minWidth:Math.min(headerMinimum,Math.max(1,window.innerWidth-16))}:{})}; return createPortal(
{ @@ -313,7 +370,7 @@ export function Window({ dragRef.current = null; resizeRef.current = null; if (!isFloating) { const rect = dialogRef.current?.getBoundingClientRect(); - if (rect) changeRect(fitWindow(rectRef.current ?? { left: rect.left, top: rect.top, width: rect.width, height: rect.height }, { width: window.innerWidth, height: window.innerHeight })); + if (rect) changeRect(fitWindow(rectRef.current ?? { left: rect.left, top: rect.top, width: rect.width, height: rect.height }, { width: window.innerWidth, height: window.innerHeight },minimumRef.current)); } if (rectRef.current) commitRef.current?.({...rectRef.current}); setFloating(!isFloating); diff --git a/registry/components.json b/registry/components.json index 3b82f5e..fba44a4 100644 --- a/registry/components.json +++ b/registry/components.json @@ -473,7 +473,8 @@ "Enforced operational typography: independent md/13px base for UI roots and portals; section/value text md, Description/status/error copy sm/12px, only canonical page/window titles use title/18px. Shared build-time typography contract and catalog example prevent browser-default size regressions.", "Drag headers never draw perimeter outlines or inherit keyboard-focus fill on pointer grab. Keyboard focus remains visible through the canonical surface; arrows, Shift+arrows and docking shortcuts remain available.", "Detached center windows automatically use scene Glass V4; fixed confirmations opt out of detachment with allowFloating=false. Unsaved profile confirmation is owned by the application.", - "floating/onFloatingChange and rect/onRectCommit allow durable application-owned presentation by window kind, independent of the currently displayed entity. Reopening restores mode and fitted geometry. Fixed confirmations do not inherit this state." + "floating/onFloatingChange and rect/onRectCommit allow durable application-owned presentation by window kind, independent of the currently displayed entity. Reopening restores mode and fitted geometry. Fixed confirmations do not inherit this state.", + "Adaptive headers keep actions on one row, place the full title below before clipping, and derive the resize minimum from actual actions. Expanded media fits the viewport temporarily, remains resizable and restores the previous rectangle without overwriting durable geometry." ] }, {