From 1ec17b30981e6f084ba288a530ee08280ab1f2a6 Mon Sep 17 00:00:00 2001 From: DCCONSTRUCTIONS Date: Fri, 13 Nov 2026 17:52:26 +0300 Subject: [PATCH 1/3] Add reusable centered DOM modal resizing with preference adapter --- apps/catalog/src/CatalogApp.tsx | 2 + apps/catalog/src/ModalSizeExample.tsx | 21 ++++++++ docs/ADOPTION.md | 4 ++ docs/COMPONENTS.md | 2 + package.json | 5 +- packages/ui-dom/src/index.ts | 1 + packages/ui-dom/src/modalSize.ts | 69 +++++++++++++++++++++++++++ registry/components.json | 7 ++- scripts/modal-size.test.mjs | 40 ++++++++++++++++ 9 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 apps/catalog/src/ModalSizeExample.tsx create mode 100644 packages/ui-dom/src/modalSize.ts create mode 100644 scripts/modal-size.test.mjs diff --git a/apps/catalog/src/CatalogApp.tsx b/apps/catalog/src/CatalogApp.tsx index 1e6a8a8..6fa6e09 100644 --- a/apps/catalog/src/CatalogApp.tsx +++ b/apps/catalog/src/CatalogApp.tsx @@ -1,4 +1,5 @@ import { OperationalTypographyDemo } from "./OperationalTypographyDemo"; +import { ModalSizeExample } from './ModalSizeExample'; import { useCallback, useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from "react"; import { applyGlassMaterial, applyNodedcTheme, defaultGlassMaterial, type GlassMaterialSettings, type NodedcTheme, type RgbTuple } from "@nodedc/ui-core"; import { createTemplateFeatures, getPageTemplate, pageTemplates, type PageTemplateDefinition } from "@nodedc/page-patterns"; @@ -1542,6 +1543,7 @@ export function CatalogApp() { + diff --git a/apps/catalog/src/ModalSizeExample.tsx b/apps/catalog/src/ModalSizeExample.tsx new file mode 100644 index 0000000..977693c --- /dev/null +++ b/apps/catalog/src/ModalSizeExample.tsx @@ -0,0 +1,21 @@ +import { createPortal } from 'react-dom'; +import { useEffect, useRef } from 'react'; +import { createModalController, createModalSizeController } from '@nodedc/ui-dom'; +import { Button, Description } from '@nodedc/ui-react'; + +export function ModalSizeExample() { + const overlay = useRef(null), dialog = useRef(null); + const modal = useRef | null>(null); + const saved = useRef({ width: 800, height: 500 }); + useEffect(() => { + const size = createModalSizeController({ dialog: dialog.current!, initialSize: saved.current, onSizeCommit: value => { saved.current = value; } }); + modal.current = createModalController({ overlay: overlay.current!, dialog: dialog.current!, onOpenChange: open => { if (open) size.refresh(); } }); + return () => { modal.current?.destroy(); size.destroy(); }; + }, []); + return <> + {createPortal(, document.body)}; +} diff --git a/docs/ADOPTION.md b/docs/ADOPTION.md index c3969d7..d84482c 100644 --- a/docs/ADOPTION.md +++ b/docs/ADOPTION.md @@ -146,3 +146,7 @@ content cards. Collection entries and native JSON disclosures adopt the shared GlassSurface group material. No local palette, field colors or business logic are introduced. The prior soft-canvas composition is superseded in THEMING and the living catalog; soft itself remains available for recessed non-form areas. + +## CMS: размеры модальных окон + +CMS подключает `createModalSizeController` из immutable ui-dom package, без копии resize-кода. Тонкий адаптер связывает `media-library` с серверным пользовательским GUI JSON; оформление и размеры записываются через аутентифицированный API. Медиатека остаётся привязанной к сайту, геометрия — к пользователю. diff --git a/docs/COMPONENTS.md b/docs/COMPONENTS.md index ef27390..ba5ad84 100644 --- a/docs/COMPONENTS.md +++ b/docs/COMPONENTS.md @@ -133,6 +133,8 @@ Modeless Inspector закрывается независимо от резуль Для modeless Inspector доступен `draggable`: окно двигается за header, не блокирует приложение и ограничивается viewport. Modal-окна не становятся draggable автоматически. +DOM: `createModalSizeController({dialog, initialSize, minimum, onSizeCommit})` дополняет `createModalController` изменением размера за восемь краёв/углов. Шапка получает клавиатурный resize через Shift + стрелки. `setSize` восстанавливает сохранённый размер, `refresh` подгоняет окно после открытия. Подгонка под экран и pointercancel не записывают новое предпочтение. Контроллер не меняет modal/focus contract; приложение хранит размер отдельно для текущего пользователя. Живой пример: «Размер DOM-окна». + ## WorkspaceWindow `WorkspaceWindow` — modeless-окно внутри рабочей сцены приложения. Оно рендерится непосредственно в переданном workspace, не использует portal и не может перекрыть шапку, навигацию или соседние панели за пределами этого workspace. diff --git a/package.json b/package.json index 2bc81f9..195a772 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "scripts": { "build": "npm run build --workspace @nodedc/ui-core && npm run build --workspace @nodedc/ui-dom && npm run build --workspace @nodedc/ui-react && npm run build --workspace @nodedc/page-patterns && npm run build --workspace @nodedc/map-cesium-react && npm run build --workspace @nodedc/ui-catalog", "build:packages": "npm run build --workspace @nodedc/ui-core && npm run build --workspace @nodedc/ui-dom && npm run build --workspace @nodedc/ui-react && npm run build --workspace @nodedc/page-patterns && npm run build --workspace @nodedc/map-cesium-react", - "check": "npm run test:typography && npm run build:packages && npm run typecheck --workspaces --if-present && npm run validate:registry && npm run test:spark-governance && npm run test:analysis-controls && npm run test:activity-indicator && npm run test:control-density && npm run test:icon-contract && npm run test:toast-contract && npm run test:floating-position && npm run test:inspector-select && npm run test:range-control && npm run test:split-pane && npm run test:dock-layout && npm run test:hgeozone-projection && npm run test:map-grid-lod && npm run test:map-filters && npm run test:map-object-layers && npm run test:map-inspector-overlay-state && npm run test:map-reference-stations && npm run test:map-search && npm run test:map-subject-card && npm run test:map-subject-detail-profile && npm run test:environment-settings && npm run test:settings-surfaces && npm run test:window-geometry && npm run test:editor-dock && npm run test:flat-theme && npm run test:mission-theme", + "check": "npm run test:typography && npm run build:packages && npm run typecheck --workspaces --if-present && npm run validate:registry && npm run test:spark-governance && npm run test:analysis-controls && npm run test:activity-indicator && npm run test:control-density && npm run test:icon-contract && npm run test:toast-contract && npm run test:floating-position && npm run test:inspector-select && npm run test:range-control && npm run test:split-pane && npm run test:dock-layout && npm run test:hgeozone-projection && npm run test:map-grid-lod && npm run test:map-filters && npm run test:map-object-layers && npm run test:map-inspector-overlay-state && npm run test:map-reference-stations && npm run test:map-search && npm run test:map-subject-card && npm run test:map-subject-detail-profile && npm run test:environment-settings && npm run test:settings-surfaces && npm run test:window-geometry && npm run test:editor-dock && npm run test:flat-theme && npm run test:mission-theme && npm run test:modal-size", "dev": "npm run build:packages && npm run dev --workspace @nodedc/ui-catalog", "serve": "node server/catalog-server.mjs", "validate:registry": "node scripts/validate-registry.mjs", @@ -49,7 +49,8 @@ "test:typography": "node --test scripts/operational-typography.test.mjs", "prebuild": "npm run test:typography", "test:flat-theme": "node --test scripts/flat-theme.test.mjs", - "test:mission-theme": "node --test scripts/mission-theme.test.mjs" + "test:mission-theme": "node --test scripts/mission-theme.test.mjs", + "test:modal-size": "node --test scripts/modal-size.test.mjs" }, "engines": { "node": ">=20" diff --git a/packages/ui-dom/src/index.ts b/packages/ui-dom/src/index.ts index cfc342d..a174d41 100644 --- a/packages/ui-dom/src/index.ts +++ b/packages/ui-dom/src/index.ts @@ -3,6 +3,7 @@ export * from "./applicationWorkspace.js"; export * from "./floating.js"; export * from "./mediaSource.js"; export * from "./modal.js"; +export * from "./modalSize.js"; export * from "./select.js"; export * from "./shareLink.js"; export * from "./toolbar.js"; diff --git a/packages/ui-dom/src/modalSize.ts b/packages/ui-dom/src/modalSize.ts new file mode 100644 index 0000000..ae277a6 --- /dev/null +++ b/packages/ui-dom/src/modalSize.ts @@ -0,0 +1,69 @@ +export type ModalSize = { width: number; height: number }; +export function fitModalSize(size: ModalSize, viewport: ModalSize, minimum: ModalSize = { width: 320, height: 200 }): ModalSize { + const fit = (value: number, available: number, min: number) => Math.max(Math.min(min, Math.max(1, available - 32)), Math.min(value, Math.max(1, available - 32))); + return { width: fit(size.width, viewport.width, minimum.width), height: fit(size.height, viewport.height, minimum.height) }; +} +/** Resize a centered DOM modal without changing its focus/layer controller. + * Persistence belongs to the consumer; only completed user gestures commit. + */ +export function createModalSizeController({ dialog, initialSize, minimum, onSizeCommit }: { + dialog: HTMLElement; initialSize: ModalSize; minimum?: ModalSize; onSizeCommit?: (size: ModalSize) => void; +}) { + const head = dialog.querySelector('.nodedc-window__head'); + const previous = { width: dialog.style.width, height: dialog.style.height, maxHeight: dialog.style.maxHeight, tab: head?.getAttribute('tabindex'), title: head?.getAttribute('title') }; + let desired = { ...initialSize }; + let gesture: { id: number; x: number; y: number; edge: string; size: ModalSize; before: ModalSize } | null = null; + const viewport = () => ({ width: window.innerWidth, height: window.innerHeight }); + const visible = () => dialog.getClientRects().length > 0; + const apply = (size = desired) => { + const fitted = fitModalSize(size, viewport(), minimum); + dialog.style.width = `${fitted.width}px`; + dialog.style.height = `${fitted.height}px`; + dialog.style.maxHeight = 'calc(100dvh - 2rem)'; + return fitted; + }; + const handles = ['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw'].map(edge => { + const handle = document.createElement('div'); + handle.className = 'nodedc-window__resize'; handle.dataset.edge = edge; handle.setAttribute('aria-hidden', 'true'); + handle.addEventListener('pointerdown', event => { + if (event.button !== 0 || gesture) return; + const rect = dialog.getBoundingClientRect(); + gesture = { id: event.pointerId, x: event.clientX, y: event.clientY, edge, size: { width: rect.width, height: rect.height }, before: desired }; + handle.setPointerCapture(event.pointerId); event.preventDefault(); + }); + dialog.append(handle); return handle; + }); + const move = (event: PointerEvent) => { + if (!gesture || event.pointerId !== gesture.id) return; + const { size, edge, x, y } = gesture; + desired = apply({ width: size.width + (event.clientX - x) * (edge.includes('e') ? 2 : edge.includes('w') ? -2 : 0), height: size.height + (event.clientY - y) * (edge.includes('s') ? 2 : edge.includes('n') ? -2 : 0) }); + event.preventDefault(); + }; + const end = (event: PointerEvent) => { + if (!gesture || event.pointerId !== gesture.id) return; + const before = gesture.before; gesture = null; + if (event.type === 'pointercancel') { desired = before; apply(); return; } + if (desired.width !== before.width || desired.height !== before.height) onSizeCommit?.({ ...desired }); + }; + const key = (event: KeyboardEvent) => { + if (event.target !== head || !event.shiftKey || !event.key.startsWith('Arrow')) return; + event.preventDefault(); + const size = fitModalSize(desired, viewport(), minimum); + desired = apply({ width: size.width + (event.key === 'ArrowRight' ? 20 : event.key === 'ArrowLeft' ? -20 : 0), height: size.height + (event.key === 'ArrowDown' ? 20 : event.key === 'ArrowUp' ? -20 : 0) }); + onSizeCommit?.({ ...desired }); + }; + const refresh = () => { if (visible() && !gesture) apply(); }; + if (head) { head.tabIndex = 0; head.title = 'Размер окна: Shift + стрелки. Мышью — за край или угол.'; head.addEventListener('keydown', key); } + window.addEventListener('pointermove', move); window.addEventListener('pointerup', end); window.addEventListener('pointercancel', end); window.addEventListener('resize', refresh); + apply(); + return { + refresh, + setSize(size: ModalSize) { if (!gesture) { desired = { ...size }; apply(); } }, + destroy() { + window.removeEventListener('pointermove', move); window.removeEventListener('pointerup', end); window.removeEventListener('pointercancel', end); window.removeEventListener('resize', refresh); + head?.removeEventListener('keydown', key); handles.forEach(handle => handle.remove()); + for (const name of ['width', 'height', 'maxHeight'] as const) dialog.style[name] = previous[name]; + if (head) for (const [name, value] of [['tabindex', previous.tab], ['title', previous.title]]) { if (value == null) head.removeAttribute(name!); else head.setAttribute(name!, value); } + }, + }; +} diff --git a/registry/components.json b/registry/components.json index f6b98ef..cfdb207 100644 --- a/registry/components.json +++ b/registry/components.json @@ -420,7 +420,9 @@ ], "domPackage": "@nodedc/ui-dom", "domExports": [ - "createModalController" + "createModalController", + "createModalSizeController", + "fitModalSize" ], "domContract": [ "nodedc-overlay", @@ -437,7 +439,8 @@ "modal-only body scroll lock", "optional bounded dragging for modeless inspectors", "move toggle: preserve mounted contents and current size; remove dimming, backdrop close, scroll lock and focus trap; header drag and eight invisible resize regions", - "Escape and Tab belong to the focused or topmost visible modal; parent windows do not dismiss behind nested settings." + "Escape and Tab belong to the focused or topmost visible modal; parent windows do not dismiss behind nested settings.", + "DOM modal resizing shares eight canonical edge handles, centered viewport bounds and keyboard Shift+arrow control; onSizeCommit runs only for completed user changes." ], "rules": [ "headerActionsPlacement=before-close places context actions between the move toggle and close in both visual and keyboard order; the default preserves existing consumers.", diff --git a/scripts/modal-size.test.mjs b/scripts/modal-size.test.mjs new file mode 100644 index 0000000..6020732 --- /dev/null +++ b/scripts/modal-size.test.mjs @@ -0,0 +1,40 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { fitModalSize, createModalSizeController } from '../packages/ui-dom/dist/modalSize.js'; +test('modal dimensions fit narrow and desktop screens without mutating preference', () => { + const requested = { width: 1600, height: 900 }; + assert.deepEqual(fitModalSize(requested, { width: 375, height: 667 }), { width: 343, height: 635 }); + assert.deepEqual(fitModalSize(requested, { width: 1920, height: 1080 }), requested); + assert.deepEqual(requested, { width: 1600, height: 900 }); +}); +test('only completed gestures commit; viewport fitting and cancellation preserve preference', () => { + class Element extends EventTarget { + style = { width: '', height: '', maxHeight: '' }; dataset = {}; attributes = new Map(); children = []; + setAttribute(k,v) { this.attributes.set(k,v); } getAttribute(k) { return this.attributes.get(k) ?? null; } removeAttribute(k) { this.attributes.delete(k); } + append(value) { this.children.push(value); } remove() {} setPointerCapture() {} + getClientRects() { return [1]; } getBoundingClientRect() { return { width: parseFloat(this.style.width), height: parseFloat(this.style.height) }; } + querySelector() { return head; } + } + const head = new Element(), dialog = new Element(), commits = []; + const oldWindow = globalThis.window, oldDocument = globalThis.document; + globalThis.window = Object.assign(new EventTarget(), { innerWidth: 1600, innerHeight: 1000 }); + globalThis.document = { createElement: () => new Element() }; + const dispatch = (target, type, values) => target.dispatchEvent(Object.assign(new Event(type, { cancelable: true }), values)); + try { + const controller = createModalSizeController({ dialog, initialSize: { width: 800, height: 500 }, onSizeCommit: s => commits.push(s) }); + const edge = dialog.children.find(node => node.dataset.edge === 'se'); + dispatch(edge, 'pointerdown', {button: 0, pointerId: 1, clientX: 500, clientY: 500}); + dispatch(window, 'pointermove', {pointerId: 1, clientX: 650, clientY: 600}); + assert.equal(commits.length, 0); + dispatch(window, 'pointerup', {pointerId: 1}); + assert.deepEqual(commits, [{width: 1100, height: 700}]); + window.innerWidth = 500; window.innerHeight = 400; window.dispatchEvent(new Event('resize')); + assert.equal(dialog.style.width, '468px'); assert.equal(commits.length, 1); + window.innerWidth = 1600; window.innerHeight = 1000; window.dispatchEvent(new Event('resize')); + assert.equal(dialog.style.width, '1100px'); + dispatch(edge, 'pointerdown', {button: 0, pointerId: 2, clientX: 500, clientY: 500}); + dispatch(window, 'pointermove', {pointerId: 2, clientX: 650, clientY: 600}); + dispatch(window, 'pointercancel', {pointerId: 2}); assert.equal(dialog.style.width, '1100px'); assert.equal(commits.length, 1); + controller.destroy(); assert.equal(dialog.style.width, ''); + } finally { globalThis.window = oldWindow; globalThis.document = oldDocument; } +}); From 1326ec6cc9ee0a2f4f3e75eaf4e22250c3fbafe5 Mon Sep 17 00:00:00 2001 From: DCCONSTRUCTIONS Date: Fri, 13 Nov 2026 18:03:15 +0300 Subject: [PATCH 2/3] Add shared Finder-style path bar for DOM media browsers --- apps/catalog/src/ModalSizeExample.tsx | 10 ++++++--- docs/COMPONENTS.md | 4 ++++ packages/ui-dom/package.json | 6 ++++-- packages/ui-dom/src/index.ts | 1 + packages/ui-dom/src/pathBar.ts | 19 ++++++++++++++++ packages/ui-dom/styles.css | 31 +++++++++++++++++++++++++++ registry/components.json | 20 +++++++++++++++++ 7 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 packages/ui-dom/src/pathBar.ts create mode 100644 packages/ui-dom/styles.css diff --git a/apps/catalog/src/ModalSizeExample.tsx b/apps/catalog/src/ModalSizeExample.tsx index 977693c..08d63e5 100644 --- a/apps/catalog/src/ModalSizeExample.tsx +++ b/apps/catalog/src/ModalSizeExample.tsx @@ -1,13 +1,17 @@ import { createPortal } from 'react-dom'; import { useEffect, useRef } from 'react'; -import { createModalController, createModalSizeController } from '@nodedc/ui-dom'; -import { Button, Description } from '@nodedc/ui-react'; +import { createModalController, createModalSizeController, renderPathBar } from '@nodedc/ui-dom'; +import { renderToStaticMarkup } from 'react-dom/server'; +import '@nodedc/ui-dom/styles.css'; +import { Button, Description, Icon } from '@nodedc/ui-react'; export function ModalSizeExample() { const overlay = useRef(null), dialog = useRef(null); const modal = useRef | null>(null); + const path = useRef(null); const saved = useRef({ width: 800, height: 500 }); useEffect(() => { + renderPathBar(path.current!, [{label:'Файлы',path:'',kind:'folder'},{label:'Изображения',path:'images',kind:'folder'},{label:'example.png',path:'images/example.png',kind:'file',current:true}], {onNavigate: () => {}, icon: kind => { const span=document.createElement('span'); span.innerHTML=renderToStaticMarkup(); return span.firstElementChild!; }}); const size = createModalSizeController({ dialog: dialog.current!, initialSize: saved.current, onSizeCommit: value => { saved.current = value; } }); modal.current = createModalController({ overlay: overlay.current!, dialog: dialog.current!, onOpenChange: open => { if (open) size.refresh(); } }); return () => { modal.current?.destroy(); size.destroy(); }; @@ -15,7 +19,7 @@ export function ModalSizeExample() { return <> {createPortal(