@linzjs/windows 5.5.1 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/panel/Panel.tsx +44 -12
- package/dist/panel/PanelContext.ts +2 -0
- package/dist/panel/PopinWIndow.tsx +22 -7
- package/package.json +1 -1
package/dist/panel/Panel.tsx
CHANGED
|
@@ -3,7 +3,17 @@ import './PanelBlue.scss';
|
|
|
3
3
|
import '@linzjs/lui/dist/scss/base.scss';
|
|
4
4
|
|
|
5
5
|
import clsx from 'clsx';
|
|
6
|
-
import {
|
|
6
|
+
import { NumberSize } from 're-resizable';
|
|
7
|
+
import {
|
|
8
|
+
forwardRef,
|
|
9
|
+
PropsWithChildren,
|
|
10
|
+
ReactElement,
|
|
11
|
+
useCallback,
|
|
12
|
+
useContext,
|
|
13
|
+
useEffect,
|
|
14
|
+
useRef,
|
|
15
|
+
useState,
|
|
16
|
+
} from 'react';
|
|
7
17
|
import { createPortal } from 'react-dom';
|
|
8
18
|
|
|
9
19
|
import { useConstFunction } from '../common';
|
|
@@ -14,14 +24,20 @@ import { PopoutWindow } from './PopoutWindow';
|
|
|
14
24
|
import { PanelProps } from './types/PanelProps';
|
|
15
25
|
import { useRestoreStateFrom } from './usePanelStateHandler';
|
|
16
26
|
|
|
27
|
+
const defaultInitialSize = { width: 320, height: 200 };
|
|
28
|
+
const nullOpFunction = () => {};
|
|
29
|
+
|
|
17
30
|
export const Panel = (props: PanelProps): ReactElement => {
|
|
18
31
|
const panelRef = useRef<HTMLDivElement>(null);
|
|
19
|
-
const { title, size =
|
|
32
|
+
const { title, size = defaultInitialSize, className, children, onClose } = props;
|
|
20
33
|
|
|
21
|
-
const { dockElements } = useContext(PanelsContext);
|
|
34
|
+
const { dockElements, nextStackPosition } = useContext(PanelsContext);
|
|
22
35
|
const { panelPoppedOut, uniqueId, setTitle, dockId, docked } = useContext(PanelInstanceContext);
|
|
23
36
|
|
|
24
|
-
const
|
|
37
|
+
const savedState = useRestoreStateFrom({ uniqueId, panelPoppedOut: false });
|
|
38
|
+
|
|
39
|
+
// The function has to be const as the panel must no re-render as that would cause popout windows to close
|
|
40
|
+
const onCloseConstFn = useConstFunction(onClose ?? nullOpFunction);
|
|
25
41
|
|
|
26
42
|
useEffect(() => {
|
|
27
43
|
return () => {
|
|
@@ -43,10 +59,6 @@ export const Panel = (props: PanelProps): ReactElement => {
|
|
|
43
59
|
}
|
|
44
60
|
}, [title]);
|
|
45
61
|
|
|
46
|
-
const { nextStackPosition } = useContext(PanelsContext);
|
|
47
|
-
|
|
48
|
-
const savedState = useRestoreStateFrom({ uniqueId, panelPoppedOut: false });
|
|
49
|
-
|
|
50
62
|
const [panelPosition, setPanelPosition] = useState(() => {
|
|
51
63
|
if (savedState?.panelPosition) {
|
|
52
64
|
return savedState.panelPosition;
|
|
@@ -66,7 +78,7 @@ export const Panel = (props: PanelProps): ReactElement => {
|
|
|
66
78
|
return nextStackPosition();
|
|
67
79
|
});
|
|
68
80
|
|
|
69
|
-
const [panelSize, setPanelSize] = useState(() => {
|
|
81
|
+
const [panelSize, setPanelSize] = useState<NumberSize>(() => {
|
|
70
82
|
if (savedState?.panelSize) {
|
|
71
83
|
return savedState.panelSize;
|
|
72
84
|
}
|
|
@@ -74,6 +86,18 @@ export const Panel = (props: PanelProps): ReactElement => {
|
|
|
74
86
|
return size ?? { width: 320, height: 200 };
|
|
75
87
|
});
|
|
76
88
|
|
|
89
|
+
const setInitialPanelSize = useCallback(
|
|
90
|
+
(size: NumberSize) => {
|
|
91
|
+
// If panel was already sized from state, then don't resize
|
|
92
|
+
if (savedState?.panelSize) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
setPanelSize(size);
|
|
97
|
+
},
|
|
98
|
+
[savedState?.panelSize],
|
|
99
|
+
);
|
|
100
|
+
|
|
77
101
|
const dockElement = docked && dockId && dockElements[dockId];
|
|
78
102
|
|
|
79
103
|
return (
|
|
@@ -108,6 +132,7 @@ export const Panel = (props: PanelProps): ReactElement => {
|
|
|
108
132
|
setPanelPosition={setPanelPosition}
|
|
109
133
|
panelSize={panelSize}
|
|
110
134
|
setPanelSize={setPanelSize}
|
|
135
|
+
setInitialPanelSize={setInitialPanelSize}
|
|
111
136
|
>
|
|
112
137
|
{children}
|
|
113
138
|
</PopinWindow>
|
|
@@ -120,6 +145,13 @@ export interface PanelContentProps {
|
|
|
120
145
|
className?: string | undefined;
|
|
121
146
|
}
|
|
122
147
|
|
|
123
|
-
export const PanelContent =
|
|
124
|
-
|
|
125
|
-
|
|
148
|
+
export const PanelContent = forwardRef<HTMLDivElement, PropsWithChildren<PanelContentProps>>(function PanelContentFr(
|
|
149
|
+
{ children, className },
|
|
150
|
+
ref,
|
|
151
|
+
) {
|
|
152
|
+
return (
|
|
153
|
+
<div className={clsx(`WindowPanel-content`, className)} ref={ref}>
|
|
154
|
+
{children}
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
});
|
|
@@ -4,6 +4,7 @@ import { PanelSize } from './types';
|
|
|
4
4
|
|
|
5
5
|
export interface PanelContextType {
|
|
6
6
|
resizePanel: (size: Partial<PanelSize>) => void;
|
|
7
|
+
initialResizePanel: (size: Partial<PanelSize>) => void;
|
|
7
8
|
resizeable: boolean;
|
|
8
9
|
}
|
|
9
10
|
|
|
@@ -16,5 +17,6 @@ const NoContextError = () => {
|
|
|
16
17
|
*/
|
|
17
18
|
export const PanelContext = createContext<PanelContextType>({
|
|
18
19
|
resizePanel: NoContextError,
|
|
20
|
+
initialResizePanel: NoContextError,
|
|
19
21
|
resizeable: true,
|
|
20
22
|
});
|
|
@@ -23,11 +23,13 @@ export function PopinWindow({
|
|
|
23
23
|
setPanelPosition,
|
|
24
24
|
panelSize,
|
|
25
25
|
setPanelSize,
|
|
26
|
+
setInitialPanelSize,
|
|
26
27
|
}: PanelProps & {
|
|
27
28
|
panelPosition: PanelPosition;
|
|
28
29
|
setPanelPosition: Dispatch<PanelPosition>;
|
|
29
30
|
panelSize: PanelSize;
|
|
30
31
|
setPanelSize: Dispatch<PanelSize>;
|
|
32
|
+
setInitialPanelSize: Dispatch<PanelSize>;
|
|
31
33
|
}): ReactNode {
|
|
32
34
|
const panelRef = useRef<Rnd>(null);
|
|
33
35
|
|
|
@@ -51,12 +53,25 @@ export function PopinWindow({
|
|
|
51
53
|
return;
|
|
52
54
|
}, [centerWindow, position, resizeable]);
|
|
53
55
|
|
|
54
|
-
const resizePanel = (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
const resizePanel = useCallback(
|
|
57
|
+
(newPanelSize: Partial<PanelSize>) => {
|
|
58
|
+
const newSize = { ...panelSize, ...newPanelSize };
|
|
59
|
+
if (newSize.width !== panelSize.width || newSize.height !== panelSize.height) {
|
|
60
|
+
setPanelSize(newSize);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
[panelSize, setPanelSize],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const initialResizePanel = useCallback(
|
|
67
|
+
(newPanelSize: Partial<PanelSize>) => {
|
|
68
|
+
const newSize = { ...panelSize, ...newPanelSize };
|
|
69
|
+
if (newSize.width !== panelSize.width || newSize.height !== panelSize.height) {
|
|
70
|
+
setInitialPanelSize(newSize);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
[panelSize, setInitialPanelSize],
|
|
74
|
+
);
|
|
60
75
|
|
|
61
76
|
const saveStateIn = useSaveStateIn({ uniqueId });
|
|
62
77
|
|
|
@@ -68,7 +83,7 @@ export function PopinWindow({
|
|
|
68
83
|
}, [panelPosition, panelSize, saveStateIn]);
|
|
69
84
|
|
|
70
85
|
return (
|
|
71
|
-
<PanelContext.Provider value={{ resizePanel, resizeable }}>
|
|
86
|
+
<PanelContext.Provider value={{ resizePanel, initialResizePanel, resizeable }}>
|
|
72
87
|
{modal && (
|
|
73
88
|
<div
|
|
74
89
|
style={{
|