diff --git a/apps/catalog/src/CatalogApp.tsx b/apps/catalog/src/CatalogApp.tsx index 1daff7e..d035e4e 100644 --- a/apps/catalog/src/CatalogApp.tsx +++ b/apps/catalog/src/CatalogApp.tsx @@ -250,6 +250,7 @@ const iconGroups: Array<{ title: string; note: string; icons: IconName[] }> = [ ]; const iconLabels: Record = { + pipette: "Пипетка", ruler: "Линейка", section: "Секущая плоскость", isolate: "Изолировать элемент", power: "Питание", move: "Свободное окно", diff --git a/apps/catalog/src/EditorDockExample.tsx b/apps/catalog/src/EditorDockExample.tsx index ac6fd85..10c5f43 100644 --- a/apps/catalog/src/EditorDockExample.tsx +++ b/apps/catalog/src/EditorDockExample.tsx @@ -1,6 +1,7 @@ import {useState} from 'react'; -import {Button,Window,Description,EditorDockLayout,EditorWorkspace,type EditorDockState} from '@nodedc/ui-react'; +import {Button,Window,Description,ColorField,ControlRow,Inspector,EditorDockLayout,EditorWorkspace,type EditorDockState} from '@nodedc/ui-react'; export function EditorDockExample({inWindow=false}:{inWindow?:boolean}){ + const [color,setColor]=useState('#292929'); const [modal,setModal]=useState(false),[purpose,setPurpose]=useState<'edit'|'view'>('edit'); const [editing,setEditing]=useState(false),[open,setOpen]=useState({objects:true,materials:true}); const [layout,setLayout]=useState({tree:{axis:'y',ratio:70,first:{axis:'x',ratio:25,first:{id:'objects'},second:{id:'viewport'}},second:{id:'materials'}},floating:{}}); @@ -8,7 +9,7 @@ export function EditorDockExample({inWindow=false}:{inWindow?:boolean}){ setEditing(false)} headerActions={purpose==='view'?:undefined}> Закреплённая сцена} tools={[{id:'objects',title:'Объекты',label:'Объекты',open:open.objects,onClose:()=>setOpen(v=>({...v,objects:false})),content:Сцена → Модель → Детали}, - {id:'materials',title:'Материалы',label:'Материалы',open:open.materials,onClose:()=>setOpen(v=>({...v,materials:false})),content:Перетащите шапку к краю, рядом с другим инструментом или в центр сцены. Скругляются только внешние углы общей области; стыки остаются прямыми.}]}/> + {id:'materials',title:'Материалы',label:'Материалы',minimumSize:{width:380,height:280},footer:,open:open.materials,onClose:()=>setOpen(v=>({...v,materials:false})),content:}]} defaultOpen={["color"]} header={Минимум 380 × 280. Пипетка берёт цвет с экрана после нажатия; Escape отменяет выбор. Нижняя кнопка не прокручивается.}/>}]}/> ; } diff --git a/docs/COMPONENTS.md b/docs/COMPONENTS.md index 6922ddf..636249d 100644 --- a/docs/COMPONENTS.md +++ b/docs/COMPONENTS.md @@ -579,3 +579,8 @@ EditorDockLayout rounds only the external corners of its complete tiled area usi Viewport-scoped Toolbar buttons use the same scene Glass V4 material as the top viewport controls, preserving pressed, disabled and keyboard states. Its rail remains transparent. Compact Tree information actions use `info-plain` at 14 px beside the existing eye. Tree supports optional controlled `selectedIds` for multi-selection. Its selection callback includes keyboard modifiers and the Shift range across displayed rows only. Consumers own set semantics and geometry identities; existing single-selection callers remain unchanged. Pointer and keyboard selection share the same path. Visibility and information actions do not alter the selection. The living Tree example demonstrates Shift range, Ctrl add and Command toggle. + + +ColorField screen sampling (owner direction, 2026-11-14): the shared palette includes a Pipette action. In secure browsers supporting EyeDropper, click “Цвет с экрана”, then any screen pixel, including another application or desktop. Escape cancels without a change. Sampling never starts on pointer leave, never captures a screenshot, and is aborted when the control closes, disables or unmounts. Unsupported browsers expose “Системная палитра”; desktop sampling there depends on the native browser/OS picker. Palette/HEX remain usable regardless. This explicit fallback is the approved exception to the old no-native-dialog rule. + +Floating EditorDockLayout tools honor minimumSize on restore, all eight resize edges and keyboard resize. If the available viewport is smaller, they fit that viewport; Inspector fields stack below a 330px content width instead of clipping. Tool footer is separate from the scrolling body; a Button width="full" is the canonical adaptive bottom action. The catalog's scene editor example demonstrates minimum size, a ColorField and fixed reset footer. diff --git a/docs/WINDOWS_AND_LAYERS.md b/docs/WINDOWS_AND_LAYERS.md index 9765f3f..ed6b37b 100644 --- a/docs/WINDOWS_AND_LAYERS.md +++ b/docs/WINDOWS_AND_LAYERS.md @@ -165,3 +165,5 @@ Portal typography is self-contained: Window text base is md/13 px, its title is Dock tool headings inherit the focused drag-header foreground, including title and subtitle, so the canonical inverted keyboard-focus fill retains readable text. Keyboard-focused dock headers keep their action/close glyphs on the inherited contrast color, as well as title/subtitle. + +Tool minimumSize governs floating and docked geometry alike, including restored JSON, pointer and keyboard resize. Screen bounds take priority when smaller. Put fixed bottom actions in EditorDockTool.footer; never append them to scrollable inspector content. diff --git a/packages/ui-core/styles.css b/packages/ui-core/styles.css index 997e951..d07eb40 100644 --- a/packages/ui-core/styles.css +++ b/packages/ui-core/styles.css @@ -3567,7 +3567,11 @@ textarea.nodedc-field__control { } .nodedc-inspector { + container-type: inline-size; + container-name: nodedc-inspector; display: grid; + min-width: 0; + grid-template-columns: minmax(0, 1fr); width: min(var(--nodedc-inspector-inner-width), 100%); gap: var(--nodedc-space-3); } @@ -3577,6 +3581,8 @@ textarea.nodedc-field__control { .nodedc-inspector__group { display: grid; + min-width: 0; + grid-template-columns: minmax(0, 1fr); gap: var(--nodedc-space-3); } @@ -3658,6 +3664,8 @@ textarea.nodedc-field__control { .nodedc-inspector__section-content { display: grid; + min-width: 0; + grid-template-columns: minmax(0, 1fr); gap: var(--nodedc-space-3); padding: var(--nodedc-space-3) 0 var(--nodedc-space-2); animation: nodedc-section-in var(--nodedc-duration-fast) ease; @@ -3755,7 +3763,7 @@ textarea.nodedc-field__control { display: grid; width: min(var(--nodedc-inspector-inner-width), 100%); min-height: var(--nodedc-control-height); - grid-template-columns: var(--nodedc-inspector-label-width) var(--nodedc-inspector-control-width); + grid-template-columns: minmax(0, 1fr) minmax(0, var(--nodedc-inspector-control-width)); align-items: center; gap: var(--nodedc-inspector-control-gap); } @@ -4752,3 +4760,9 @@ textarea.nodedc-field__control { /* A backdrop root on the transparent rail would prevent button glass sampling the scene. */ .nodedc-toolbar-wrap[data-scope="viewport"] .nodedc-toolbar {will-change:transform;} + +/* Floating inspectors may be narrower than the browser; respond to their own width. */ +@container nodedc-inspector (max-width: 329px) { + .nodedc-control-row { grid-template-columns: minmax(0, 1fr); gap: var(--nodedc-space-2); } +} +.nodedc-color-field__native-picker { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; } diff --git a/packages/ui-react/src/EditorDockLayout.tsx b/packages/ui-react/src/EditorDockLayout.tsx index 1545c37..6f2eed1 100644 --- a/packages/ui-react/src/EditorDockLayout.tsx +++ b/packages/ui-react/src/EditorDockLayout.tsx @@ -39,7 +39,7 @@ export function EditorDockLayout({value,onChange,primary,primaryId='viewport',pr const required=dockMinimum(visibleTree,minimums),area={...bounds,width:Math.max(bounds.width,required.width),height:Math.max(bounds.height,required.height)}; const constrained=constrainDockTree(visibleTree,area,minimums)!; const rects=dockRects(constrained,area); - const floatingRect=(id:string)=>fitWindow(value.floating[id]??tools.find(t=>t.id===id)?.initialRect??{left:Math.max(8,bounds.width-380),top:24,width:360,height:540},bounds); + const floatingRect=(id:string)=>fitWindow(value.floating[id]??tools.find(t=>t.id===id)?.initialRect??{left:Math.max(8,bounds.width-380),top:24,width:360,height:540},bounds,tools.find(t=>t.id===id)?.minimumSize); const latest=useRef({value,onChange,rects,bounds,enabled,tools});latest.current={value,onChange,rects,bounds,enabled,tools}; const activate=(id:string)=>setOrder(v=>[...v.filter(x=>x!==id),id]); useLayoutEffect(()=>{const v=viewport.current!;const measure=()=>setBounds({left:0,top:0,width:v.clientWidth,height:v.clientHeight});measure();const ro=new ResizeObserver(measure);ro.observe(v);return()=>ro.disconnect();},[]); @@ -57,8 +57,8 @@ export function EditorDockLayout({value,onChange,primary,primaryId='viewport',pr const p=point(e),dx=p.x-g.x,dy=p.y-g.y; if(!g.moved&&Math.hypot(dx,dy)<6)return; g.moved=true; - const b=latest.current.bounds; - g.current=g.edge?resizeWindow(g.rect,g.edge,dx,dy,b):fitWindow({...g.rect,left:g.rect.left+dx,top:g.rect.top+dy},b); + const b=latest.current.bounds,minimum=latest.current.tools.find(t=>t.id===g.id)?.minimumSize; + g.current=g.edge?resizeWindow(g.rect,g.edge,dx,dy,b,minimum):fitWindow({...g.rect,left:g.rect.left+dx,top:g.rect.top+dy},b,minimum); const visibleBounds={...b,left:viewport.current?.scrollLeft??0,top:viewport.current?.scrollTop??0}; g.target=g.edge?null:editorDockTarget(visibleBounds,latest.current.rects,primaryId,g.id,p.x,p.y); setDrag({...g});e.preventDefault(); @@ -85,7 +85,7 @@ export function EditorDockLayout({value,onChange,primary,primaryId='viewport',pr else if(position)setKeyboard({id,target:{activeId:id,overId:keyboard.target?.overId??primaryId,position,scope:e.shiftKey||!keyboard.target?'workspace':keyboard.target.scope}}); else return; }else if(e.key==='Enter'||e.key===' '){setKeyboard({id,target:null});activate(id);} - else if(position&&!rects[id]){const r=floatingRect(id),delta=e.altKey?1:10,dx=position==='left'?-delta:position==='right'?delta:0,dy=position==='top'?-delta:position==='bottom'?delta:0;onChange({...value,floating:{...value.floating,[id]:e.shiftKey?resizeWindow(r,'se',dx,dy,bounds):fitWindow({...r,left:r.left+dx,top:r.top+dy},bounds)}});} + else if(position&&!rects[id]){const r=floatingRect(id),delta=e.altKey?1:10,dx=position==='left'?-delta:position==='right'?delta:0,dy=position==='top'?-delta:position==='bottom'?delta:0;onChange({...value,floating:{...value.floating,[id]:e.shiftKey?resizeWindow(r,'se',dx,dy,bounds,tools.find(t=>t.id===id)?.minimumSize):fitWindow({...r,left:r.left+dx,top:r.top+dy},bounds,tools.find(t=>t.id===id)?.minimumSize)}});} else return; e.preventDefault();e.stopPropagation(); }; diff --git a/packages/ui-react/src/Icon.tsx b/packages/ui-react/src/Icon.tsx index ee224ba..c0455ae 100644 --- a/packages/ui-react/src/Icon.tsx +++ b/packages/ui-react/src/Icon.tsx @@ -1,5 +1,6 @@ import { MousePointer2, + Pipette, createLucideIcon, Glasses, Cuboid, @@ -85,6 +86,7 @@ const InformationPlain = createLucideIcon('InformationPlain', [ ['path', {d:'M12 4h.01M10 9h2v11M9 20h6',key:'information'}], ]); const icons = { + pipette: Pipette, "add-point": CirclePlus, ruler: DimensionLine, section: SectionPlane, diff --git a/packages/ui-react/src/RangeControl.tsx b/packages/ui-react/src/RangeControl.tsx index f584abf..0599f1e 100644 --- a/packages/ui-react/src/RangeControl.tsx +++ b/packages/ui-react/src/RangeControl.tsx @@ -3,6 +3,10 @@ import { VerticalRangeBand, type RangeBandControlProps } from "./VerticalRangeBa export type { RangeBandControlProps } from "./VerticalRangeBand.js"; import { cn } from "./cn.js"; import { Dropdown } from "./Dropdown.js"; +import { Button } from "./Button.js"; +import { Icon } from "./Icon.js"; +import { Description } from "./Description.js"; +import { screenColorPicker } from "./screenColorPicker.js"; export interface RangeControlProps extends Omit, "type" | "value" | "onChange"> { label: string; @@ -277,7 +281,27 @@ function hsvToHex({ h, s, v }: Hsv): string { export function ColorField({ value, onChange, label = "Цвет", className, disabled = false, onBlur, onKeyDown, ...props }: ColorFieldProps) { const [draft, setDraft] = useState(value); + const [paletteOpen, setPaletteOpen] = useState(false), [picking, setPicking] = useState(false), [pickError, setPickError] = useState(false); + const nativePicker = useRef(null), sampling = useRef(null); + const screenPicker = screenColorPicker(); + useEffect(() => () => { sampling.current?.abort(); }, []); + useEffect(() => { if (disabled || !paletteOpen) { sampling.current?.abort(); sampling.current = null; setPicking(false); } }, [disabled, paletteOpen]); useEffect(() => setDraft(value), [value]); + const sampleScreen = async () => { + if (disabled || sampling.current) return; + setPickError(false); + if (!screenPicker) { nativePicker.current?.click(); return; } + const controller = new AbortController(); sampling.current = controller; setPicking(true); + try { + // open() executes synchronously in this trusted click before the first await. + const result = await new screenPicker().open({ signal: controller.signal }); + if (!controller.signal.aborted && parseHexColor(result.sRGBHex)) { setDraft(result.sRGBHex.toLowerCase()); onChange(result.sRGBHex.toLowerCase()); } + } catch (error) { + if (!controller.signal.aborted && !(error instanceof Error && error.name === 'AbortError')) setPickError(true); + } finally { + if (!controller.signal.aborted) { setPicking(false); sampling.current = null; } + } + }; const validColor = hexToHsv(value); const [hsv, setHsv] = useState(() => validColor ?? { h: 330, s: 82, v: 100 }); const style = { "--nodedc-color-value": validColor ? hsvToHex(validColor) : hsvToHex(hsv) } as CSSProperties; @@ -302,6 +326,7 @@ export function ColorField({ value, onChange, label = "Цвет", className, dis
Оттенок commit({ ...hsv, h: Number(event.target.value) })} /> + + {pickError && Не удалось включить пипетку. Повторите попытку.}
{palettePresets.map((preset) => (
+ { setDraft(event.target.value); onChange(event.target.value); }}/> { open(options: { signal: AbortSignal }): Promise<{ sRGBHex: string }> }; +export function screenColorPicker(): ScreenColorPicker | undefined { + return (globalThis as typeof globalThis & { EyeDropper?: ScreenColorPicker }).EyeDropper; +} diff --git a/packages/ui-react/src/windowGeometry.ts b/packages/ui-react/src/windowGeometry.ts index 0b046dd..c1154ec 100644 --- a/packages/ui-react/src/windowGeometry.ts +++ b/packages/ui-react/src/windowGeometry.ts @@ -3,15 +3,16 @@ export type WindowRect = { left: number; top: number; width: number; height: num export type ResizeEdge = 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 'sw'; export const windowResizeEdges: ResizeEdge[] = ['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw']; type Bounds = { width: number; height: number }; +const defaultMinimum: Bounds = { width: 320, height: 200 }; const clamp = (value: number, min: number, max: number) => Math.max(min, Math.min(max, value)); -export function fitWindow(rect: WindowRect, bounds: Bounds): WindowRect { - const width = clamp(rect.width, Math.min(320, bounds.width - 16), Math.max(1, bounds.width - 16)); - const height = clamp(rect.height, Math.min(200, bounds.height - 16), Math.max(1, bounds.height - 16)); +export function fitWindow(rect: WindowRect, bounds: Bounds, minimum: Bounds = defaultMinimum): WindowRect { + const width = clamp(rect.width, Math.max(1, Math.min(minimum.width, bounds.width - 16)), Math.max(1, bounds.width - 16)); + const height = clamp(rect.height, Math.max(1, Math.min(minimum.height, bounds.height - 16)), Math.max(1, bounds.height - 16)); return { width, height, left: clamp(rect.left, 8, Math.max(8, bounds.width - width - 8)), top: clamp(rect.top, 8, Math.max(8, bounds.height - height - 8)) }; } -export function resizeWindow(rect: WindowRect, edge: ResizeEdge, dx: number, dy: number, bounds: Bounds): WindowRect { - const r = fitWindow(rect, bounds), right = r.left + r.width, bottom = r.top + r.height; - const minWidth = Math.min(320, bounds.width - 16), minHeight = Math.min(200, bounds.height - 16); +export function resizeWindow(rect: WindowRect, edge: ResizeEdge, dx: number, dy: number, bounds: Bounds, minimum: Bounds = defaultMinimum): WindowRect { + const r = fitWindow(rect, bounds, minimum), right = r.left + r.width, bottom = r.top + r.height; + const minWidth = Math.max(1, Math.min(minimum.width, bounds.width - 16)), minHeight = Math.max(1, Math.min(minimum.height, bounds.height - 16)); const left = edge.includes('w') ? clamp(r.left + dx, 8, right - minWidth) : r.left; const top = edge.includes('n') ? clamp(r.top + dy, 8, bottom - minHeight) : r.top; const endX = edge.includes('e') ? clamp(right + dx, left + minWidth, bounds.width - 8) : right; diff --git a/registry/components.json b/registry/components.json index 795b880..89079f8 100644 --- a/registry/components.json +++ b/registry/components.json @@ -332,12 +332,13 @@ "hue slider", "quick colors", "portal palette", - "keyboard spectrum adjustment" + "keyboard spectrum adjustment", + "explicit screen eyedropper with cancellation; system palette fallback when EyeDropper is unavailable" ], "rules": [ - "Do not expose a browser-native color dialog as the product runtime UI.", "The palette owns choice geometry; the consumer owns color validation, persistence and domain reaction.", - "HEX text keeps incomplete drafts; valid six-digit colors apply live, invalid drafts revert on blur/Escape, Enter commits; external undo updates the field." + "HEX text keeps incomplete drafts; valid six-digit colors apply live, invalid drafts revert on blur/Escape, Enter commits; external undo updates the field.", + "The themed palette remains primary. Screen sampling starts only on a trusted button click, never pointer leave; unsupported browsers expose an explicit system-palette fallback. No screenshots are captured or stored. Escape, closing or unmount cancels sampling without applying a color." ] }, { @@ -1138,7 +1139,8 @@ "The panel variant reuses AdminNavigationPanel pill, icon and theme tokens while retaining the same controlled accordion state and domain-owned content.", "A section action is a sibling IconButton before the disclosure chevron, never nested in the trigger. It does not toggle the section. Panel chevrons point down when collapsed and up when expanded.", "Accent-filled section headers belong to Environment Settings; neutral headers remain available for other approved inspector contexts.", - "Default sections and optional header fields use the canonical 12 px spacing token; footer actions are centered with the same gap. Nested Inspectors retain this rhythm; the panel variant retains its compact row geometry." + "Default sections and optional header fields use the canonical 12 px spacing token; footer actions are centered with the same gap. Nested Inspectors retain this rhythm; the panel variant retains its compact row geometry.", + "Inspector responds to its own container width: fields stack below 330px and intrinsic tracks must not clip content." ] }, { @@ -1411,7 +1413,8 @@ "EditorWorkspace keeps one mounted portal host, moves it atomically when supported, and restores its original slot on return. It never changes the source-view layout.", "The fixed editor header is outside docking bounds. Back, edit completion and close return to the original view.", "When opened inside Window, the editor suspends that overlay, backdrop and focus trap without unmounting; returning restores the same window.", - "EditorWorkspace purpose=view uses the same mounted host, return/fullscreen behavior and optional fixed headerActions; purpose=edit remains the compatible default." + "EditorWorkspace purpose=view uses the same mounted host, return/fullscreen behavior and optional fixed headerActions; purpose=edit remains the compatible default.", + "Tool minimumSize applies to floating restore, pointer and keyboard resize as well as docked splits; small screens clamp to available space. Footer remains outside the body scroller." ] }, { diff --git a/registry/icons.json b/registry/icons.json index 155db4f..8951287 100644 --- a/registry/icons.json +++ b/registry/icons.json @@ -33,7 +33,8 @@ "apps", "layers", "move", - "power" + "power", + "pipette" ] }, { diff --git a/scripts/window-geometry.test.mjs b/scripts/window-geometry.test.mjs index cbed7fa..4886abb 100644 --- a/scripts/window-geometry.test.mjs +++ b/scripts/window-geometry.test.mjs @@ -15,3 +15,15 @@ test('viewport shrink retains reachable header and fits small screens',()=>{ assert.deepEqual(v,{left:8,top:8,width:264,height:164}); assert.deepEqual(fitWindow(r,bounds),r); }); + +test('custom tool minimum applies to restored geometry and every resize edge',()=>{ + const minimum={width:380,height:280}; + const restored=fitWindow({...r,width:320,height:200},bounds,minimum); + assert.equal(restored.width,380);assert.equal(restored.height,280); + for(const edge of windowResizeEdges)for(const delta of [-3000,3000]){ + const resized=resizeWindow(r,edge,delta,delta,bounds,minimum); + assert.ok(resized.width>=380&&resized.height>=280); + } + assert.deepEqual(fitWindow(r,{width:280,height:180},minimum),{left:8,top:8,width:264,height:164}); + const tiny=fitWindow(r,{width:10,height:10},minimum);assert.equal(tiny.width,1);assert.equal(tiny.height,1); +});