@linzjs/windows 3.7.0 → 3.8.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/index.ts
CHANGED
package/dist/panel/Panel.tsx
CHANGED
|
@@ -19,6 +19,7 @@ import React, {
|
|
|
19
19
|
} from "react";
|
|
20
20
|
import { createPortal } from "react-dom";
|
|
21
21
|
import { Rnd } from "react-rnd";
|
|
22
|
+
import { useConstFunction } from "../common/useConstFunction";
|
|
22
23
|
|
|
23
24
|
export interface PanelProps {
|
|
24
25
|
title: string;
|
|
@@ -32,10 +33,12 @@ export interface PanelProps {
|
|
|
32
33
|
minWidth?: number | string;
|
|
33
34
|
modal?: boolean;
|
|
34
35
|
resizeable?: boolean;
|
|
36
|
+
onClose?: () => void;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
export const Panel = ({
|
|
38
40
|
title,
|
|
41
|
+
onClose,
|
|
39
42
|
size = { width: 320, height: 200 },
|
|
40
43
|
maxHeight,
|
|
41
44
|
maxWidth,
|
|
@@ -53,6 +56,14 @@ export const Panel = ({
|
|
|
53
56
|
const { panelPoppedOut, bounds, zIndex, bringPanelToFront, uniqueId, setTitle, dockId, docked } =
|
|
54
57
|
useContext(PanelInstanceContext);
|
|
55
58
|
|
|
59
|
+
const onCloseConstFn = useConstFunction(onClose ?? (() => {}));
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
return () => {
|
|
63
|
+
onCloseConstFn?.();
|
|
64
|
+
};
|
|
65
|
+
}, [onCloseConstFn]);
|
|
66
|
+
|
|
56
67
|
const [panelPosition, setPanelPosition] = useState(() => {
|
|
57
68
|
switch (position) {
|
|
58
69
|
case "center":
|
|
@@ -62,7 +62,7 @@ export const PanelHeader = ({
|
|
|
62
62
|
(docked ? (
|
|
63
63
|
<PanelHeaderButton aria-label={"Undock"} onClick={undock} icon={"ic_close_list"} />
|
|
64
64
|
) : (
|
|
65
|
-
<PanelHeaderButton aria-label={"
|
|
65
|
+
<PanelHeaderButton aria-label={"Dock"} onClick={() => dock(dockTo)} icon={"ic_left_col"} />
|
|
66
66
|
))}
|
|
67
67
|
{!disablePopout && (
|
|
68
68
|
<PanelHeaderButton
|
|
@@ -14,7 +14,7 @@ export const PanelInstanceContextProvider = ({
|
|
|
14
14
|
panelInstance: PanelInstance;
|
|
15
15
|
children: ReactNode;
|
|
16
16
|
}): ReactElement => {
|
|
17
|
-
const { closePanel, bringPanelToFront } = useContext(PanelsContext);
|
|
17
|
+
const { closePanel, bringPanelToFront, dockElements } = useContext(PanelsContext);
|
|
18
18
|
const [title, setTitle] = useState("");
|
|
19
19
|
const [dockId, setDockId] = useState<string>();
|
|
20
20
|
|
|
@@ -55,7 +55,7 @@ export const PanelInstanceContextProvider = ({
|
|
|
55
55
|
},
|
|
56
56
|
bringPanelToFront: () => bringPanelToFront(panelInstance),
|
|
57
57
|
zIndex: panelInstance.zIndex,
|
|
58
|
-
docked: !poppedOut && !!dockId,
|
|
58
|
+
docked: !poppedOut && !!dockId && !!dockElements[dockId],
|
|
59
59
|
dockId,
|
|
60
60
|
dock,
|
|
61
61
|
undock,
|
|
@@ -13,15 +13,16 @@ export interface PanelInstance {
|
|
|
13
13
|
window: Window | null;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export interface
|
|
17
|
-
componentFn: () => ReactElement;
|
|
18
|
-
isPoppedOut?: boolean;
|
|
16
|
+
export interface OpenPanelOptions {
|
|
19
17
|
uniqueId: string;
|
|
18
|
+
componentFn: () => ReactElement;
|
|
19
|
+
poppedOut?: boolean;
|
|
20
|
+
docked?: boolean;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export interface PanelsContextType {
|
|
23
24
|
openPanels: Set<string>;
|
|
24
|
-
openPanel: (args:
|
|
25
|
+
openPanel: (args: OpenPanelOptions) => void;
|
|
25
26
|
closePanel: (panelInstance: PanelInstance) => void;
|
|
26
27
|
bringPanelToFront: (panelInstance: PanelInstance) => void;
|
|
27
28
|
nextStackPosition: () => PanelPosition;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PanelInstanceContextProvider } from "./PanelInstanceContextProvider";
|
|
2
|
-
import {
|
|
2
|
+
import { OpenPanelOptions, PanelInstance, PanelPosition, PanelsContext } from "./PanelsContext";
|
|
3
3
|
import { castArray, maxBy, sortBy } from "lodash-es";
|
|
4
4
|
import React, { Fragment, PropsWithChildren, ReactElement, useCallback, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { useInterval } from "usehooks-ts";
|
|
@@ -54,7 +54,7 @@ export const PanelsContextProvider = ({
|
|
|
54
54
|
);
|
|
55
55
|
|
|
56
56
|
const openPanel = useCallback(
|
|
57
|
-
({ componentFn,
|
|
57
|
+
({ componentFn, poppedOut = false, uniqueId }: OpenPanelOptions): void => {
|
|
58
58
|
try {
|
|
59
59
|
const existingPanelInstance = panelInstances.find((pi) => pi.uniqueId === uniqueId);
|
|
60
60
|
if (existingPanelInstance) {
|
|
@@ -73,7 +73,7 @@ export const PanelsContextProvider = ({
|
|
|
73
73
|
uniqueId,
|
|
74
74
|
componentInstance: componentFn(),
|
|
75
75
|
zIndex: baseZIndex + panelInstances.length,
|
|
76
|
-
poppedOut
|
|
76
|
+
poppedOut,
|
|
77
77
|
window: null,
|
|
78
78
|
},
|
|
79
79
|
]);
|