mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-06-16 21:03:58 +08:00
feat(ConfigPage, VisualConfigEditor): integrate page transition layer for improved rendering control
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
} from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { usePageTransitionLayer } from '@/components/common/PageTransitionLayer';
|
||||
import { Input } from '@/components/ui/Input';
|
||||
import { Select } from '@/components/ui/Select';
|
||||
import { ToggleSwitch } from '@/components/ui/ToggleSwitch';
|
||||
@@ -177,8 +178,11 @@ export function VisualConfigEditor({
|
||||
onChange,
|
||||
}: VisualConfigEditorProps) {
|
||||
const { t } = useTranslation();
|
||||
const pageTransitionLayer = usePageTransitionLayer();
|
||||
const isCurrentLayer = pageTransitionLayer ? pageTransitionLayer.status === 'current' : true;
|
||||
const isMobile = useMediaQuery('(max-width: 768px)');
|
||||
const isFloatingSidebar = useMediaQuery('(min-width: 1025px)');
|
||||
const shouldRenderFloatingSidebar = !isMobile && isFloatingSidebar && isCurrentLayer;
|
||||
const routingStrategyLabelId = useId();
|
||||
const routingStrategyHintId = `${routingStrategyLabelId}-hint`;
|
||||
const keepaliveInputId = useId();
|
||||
@@ -371,7 +375,7 @@ export function VisualConfigEditor({
|
||||
floatingElement.style.removeProperty('pointer-events');
|
||||
};
|
||||
|
||||
if (isMobile || !isFloatingSidebar || !anchorElement || !workspaceElement) {
|
||||
if (!shouldRenderFloatingSidebar || !anchorElement || !workspaceElement) {
|
||||
clearFloatingStyles();
|
||||
return undefined;
|
||||
}
|
||||
@@ -441,7 +445,7 @@ export function VisualConfigEditor({
|
||||
contentScroller?.removeEventListener('scroll', requestPositionUpdate);
|
||||
clearFloatingStyles();
|
||||
};
|
||||
}, [isFloatingSidebar, isMobile]);
|
||||
}, [shouldRenderFloatingSidebar]);
|
||||
|
||||
const navContent = (
|
||||
<div className={styles.navList}>
|
||||
@@ -1042,7 +1046,7 @@ export function VisualConfigEditor({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!isMobile && isFloatingSidebar && typeof document !== 'undefined'
|
||||
{shouldRenderFloatingSidebar && typeof document !== 'undefined'
|
||||
? createPortal(
|
||||
<div ref={floatingSidebarRef} className={styles.floatingSidebarContainer}>
|
||||
<div className={styles.floatingSidebarRail}>{navContent}</div>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { yaml } from '@codemirror/lang-yaml';
|
||||
import { search, searchKeymap, highlightSelectionMatches } from '@codemirror/search';
|
||||
import { keymap } from '@codemirror/view';
|
||||
import { parse as parseYaml, parseDocument } from 'yaml';
|
||||
import { usePageTransitionLayer } from '@/components/common/PageTransitionLayer';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Input } from '@/components/ui/Input';
|
||||
import {
|
||||
@@ -36,6 +37,8 @@ function readCommercialModeFromYaml(yamlContent: string): boolean {
|
||||
|
||||
export function ConfigPage() {
|
||||
const { t } = useTranslation();
|
||||
const pageTransitionLayer = usePageTransitionLayer();
|
||||
const isCurrentLayer = pageTransitionLayer ? pageTransitionLayer.status === 'current' : true;
|
||||
const showNotification = useNotificationStore((state) => state.showNotification);
|
||||
const showConfirmation = useNotificationStore((state) => state.showConfirmation);
|
||||
const connectionStatus = useAuthStore((state) => state.connectionStatus);
|
||||
@@ -79,6 +82,7 @@ export function ConfigPage() {
|
||||
|
||||
const disableControls = connectionStatus !== 'connected';
|
||||
const isDirty = dirty || visualDirty;
|
||||
const shouldRenderFloatingActions = isCurrentLayer;
|
||||
const hasVisualModeError = !!visualParseError;
|
||||
const hasVisualValidationErrors =
|
||||
activeTab === 'visual' &&
|
||||
@@ -358,7 +362,7 @@ export function ConfigPage() {
|
||||
|
||||
// Keep bottom floating actions from covering page content by syncing its height to a CSS variable.
|
||||
useLayoutEffect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
if (typeof window === 'undefined' || !shouldRenderFloatingActions) return;
|
||||
|
||||
const actionsEl = floatingActionsRef.current;
|
||||
if (!actionsEl) return;
|
||||
@@ -379,7 +383,7 @@ export function ConfigPage() {
|
||||
window.removeEventListener('resize', updatePadding);
|
||||
document.documentElement.style.removeProperty('--config-action-bar-height');
|
||||
};
|
||||
}, []);
|
||||
}, [shouldRenderFloatingActions]);
|
||||
|
||||
// CodeMirror extensions
|
||||
const extensions = useMemo(
|
||||
@@ -622,7 +626,9 @@ export function ConfigPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{typeof document !== 'undefined' ? createPortal(floatingActions, document.body) : null}
|
||||
{shouldRenderFloatingActions && typeof document !== 'undefined'
|
||||
? createPortal(floatingActions, document.body)
|
||||
: null}
|
||||
<DiffModal
|
||||
open={diffModalOpen}
|
||||
original={serverYaml}
|
||||
|
||||
Reference in New Issue
Block a user