|
|
@@ -5,26 +5,27 @@
|
|
|
|
|
|
import { useEffect, startTransition, useState, useRef } from 'react';
|
|
|
|
|
|
-import { useStoreWithEqualityFn } from 'zustand/traditional';
|
|
|
-import { shallow } from 'zustand/shallow';
|
|
|
-import clsx from 'clsx';
|
|
|
+import { clsx } from 'clsx';
|
|
|
|
|
|
import { Area } from '../../types';
|
|
|
import { PanelEntity } from '../../services/panel-factory';
|
|
|
import { usePanelManager } from '../../hooks/use-panel-manager';
|
|
|
+import { usePanelStore } from '../../hooks/use-panel';
|
|
|
import { PanelContext } from '../../contexts';
|
|
|
|
|
|
const PanelItem: React.FC<{ panel: PanelEntity }> = ({ panel }) => {
|
|
|
const panelManager = usePanelManager();
|
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
|
- const resize =
|
|
|
- panel.factory.resize !== undefined ? panel.factory.resize : panelManager.config.autoResize;
|
|
|
|
|
|
const isHorizontal = ['right', 'docked-right'].includes(panel.area);
|
|
|
|
|
|
- const size = useStoreWithEqualityFn(panel.store, (s) => s.size, shallow);
|
|
|
+ const { size, fullscreen } = usePanelStore((s) => ({ size: s.size, fullscreen: s.fullscreen }));
|
|
|
|
|
|
- const sizeStyle = isHorizontal ? { width: size } : { height: size };
|
|
|
+ const [layerSize, setLayerSize] = useState(size);
|
|
|
+
|
|
|
+ const currentSize = fullscreen ? layerSize : size;
|
|
|
+
|
|
|
+ const sizeStyle = isHorizontal ? { width: currentSize } : { height: currentSize };
|
|
|
const handleResize = (next: number) => {
|
|
|
let nextSize = next;
|
|
|
if (typeof panel.factory.maxSize === 'number' && nextSize > panel.factory.maxSize) {
|
|
|
@@ -37,12 +38,28 @@ const PanelItem: React.FC<{ panel: PanelEntity }> = ({ panel }) => {
|
|
|
|
|
|
useEffect(() => {
|
|
|
/** The set size may be illegal and needs to be updated according to the real element rendered for the first time. */
|
|
|
- if (ref.current) {
|
|
|
+ if (ref.current && !fullscreen) {
|
|
|
const { width, height } = ref.current.getBoundingClientRect();
|
|
|
const realSize = isHorizontal ? width : height;
|
|
|
panel.store.setState({ size: realSize });
|
|
|
}
|
|
|
- }, []);
|
|
|
+ }, [fullscreen]);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (!fullscreen) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const layer = panel.layer;
|
|
|
+ if (!layer) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const observer = new ResizeObserver(([entry]) => {
|
|
|
+ const { width, height } = entry.contentRect;
|
|
|
+ setLayerSize(isHorizontal ? width : height);
|
|
|
+ });
|
|
|
+ observer.observe(layer);
|
|
|
+ return () => observer.disconnect();
|
|
|
+ }, [fullscreen]);
|
|
|
|
|
|
return (
|
|
|
<div
|
|
|
@@ -54,7 +71,7 @@ const PanelItem: React.FC<{ panel: PanelEntity }> = ({ panel }) => {
|
|
|
ref={ref}
|
|
|
style={{ ...panel.factory.style, ...panel.config.style, ...sizeStyle }}
|
|
|
>
|
|
|
- {resize &&
|
|
|
+ {panel.resizable &&
|
|
|
panelManager.config.resizeBarRender({
|
|
|
size,
|
|
|
direction: isHorizontal ? 'vertical' : 'horizontal',
|