diff --git a/frontend/src/frameworks/components/layout/CenterCanvas.tsx b/frontend/src/frameworks/components/layout/CenterCanvas.tsx index 7b6a492..f4b5846 100644 --- a/frontend/src/frameworks/components/layout/CenterCanvas.tsx +++ b/frontend/src/frameworks/components/layout/CenterCanvas.tsx @@ -1,9 +1,6 @@ 'use client'; -import React, { useMemo } from 'react'; -import { Responsive } from 'react-grid-layout'; -// eslint-disable-next-line @typescript-eslint/no-require-imports -const WidthProvider = require('react-grid-layout').WidthProvider; +import React, { useMemo, useState, useEffect } from 'react'; import { useAppSelector } from '@/adapters/state/redux/store'; import { useLayout } from '@/frameworks/hooks/useLayout'; import { ChartWrapper } from '@/frameworks/components/charts/ChartWrapper'; @@ -13,8 +10,6 @@ import { useUIStore } from '@/adapters/state/zustand/uiStore'; import 'react-grid-layout/css/styles.css'; import 'react-resizable/css/styles.css'; -const ResponsiveGridLayout = WidthProvider(Responsive); - /** Placeholder shown when the canvas is empty. */ function DropZonePlaceholder() { const setImportModalVisible = useUIStore((s) => s.setImportModalVisible); @@ -46,6 +41,17 @@ function DropZonePlaceholder() { export function CenterCanvas() { const charts = useAppSelector((s) => s.chart.charts); const { layouts, onLayoutChange } = useLayout(); + const [GridLayout, setGridLayout] = useState(null); + + useEffect(() => { + import('react-grid-layout').then((mod: any) => { + const WP = mod.WidthProvider || mod.default?.WidthProvider; + const Resp = mod.Responsive || mod.default?.Responsive; + if (WP && Resp) { + setGridLayout(() => WP(Resp)); + } + }); + }, []); const gridLayouts = useMemo(() => { return layouts.map((item) => ({ @@ -73,9 +79,13 @@ export function CenterCanvas() { ); } + if (!GridLayout) { + return
加载中...
; + } + return (
-
))} - + ); }