@linzjs/windows 10.3.1 → 11.0.1
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/LuiModalAsync/LuiModalAsync.d.ts +14 -0
- package/dist/LuiModalAsync/LuiModalAsync.js +45 -0
- package/dist/LuiModalAsync/LuiModalAsync.js.map +1 -0
- package/dist/LuiModalAsync/LuiModalAsync.scss +1 -2
- package/dist/LuiModalAsync/LuiModalAsyncButtonGroup.d.ts +19 -0
- package/dist/LuiModalAsync/LuiModalAsyncButtonGroup.js +27 -0
- package/dist/LuiModalAsync/LuiModalAsyncButtonGroup.js.map +1 -0
- package/dist/LuiModalAsync/LuiModalAsyncContent.d.ts +6 -0
- package/dist/LuiModalAsync/LuiModalAsyncContent.js +7 -0
- package/dist/LuiModalAsync/LuiModalAsyncContent.js.map +1 -0
- package/dist/LuiModalAsync/LuiModalAsyncContext.d.ts +28 -0
- package/dist/LuiModalAsync/LuiModalAsyncContext.js +9 -0
- package/dist/LuiModalAsync/LuiModalAsyncContext.js.map +1 -0
- package/dist/LuiModalAsync/LuiModalAsyncContextProvider.d.ts +54 -0
- package/dist/LuiModalAsync/LuiModalAsyncContextProvider.js +160 -0
- package/dist/LuiModalAsync/LuiModalAsyncContextProvider.js.map +1 -0
- package/dist/LuiModalAsync/LuiModalAsyncHeader.d.ts +15 -0
- package/dist/LuiModalAsync/LuiModalAsyncHeader.js +23 -0
- package/dist/LuiModalAsync/LuiModalAsyncHeader.js.map +1 -0
- package/dist/LuiModalAsync/LuiModalAsyncInstanceContext.d.ts +13 -0
- package/dist/LuiModalAsync/LuiModalAsyncInstanceContext.js +13 -0
- package/dist/LuiModalAsync/LuiModalAsyncInstanceContext.js.map +1 -0
- package/dist/LuiModalAsync/LuiModalAsyncMain.d.ts +5 -0
- package/dist/LuiModalAsync/LuiModalAsyncMain.js +6 -0
- package/dist/LuiModalAsync/LuiModalAsyncMain.js.map +1 -0
- package/dist/LuiModalAsync/index.js +12 -0
- package/dist/LuiModalAsync/index.js.map +1 -0
- package/dist/LuiModalAsync/useLuiModalPrefab.d.ts +56 -0
- package/dist/LuiModalAsync/useLuiModalPrefab.js +118 -0
- package/dist/LuiModalAsync/useLuiModalPrefab.js.map +1 -0
- package/dist/LuiModalAsync/useLuiModalUpload.d.ts +16 -0
- package/dist/LuiModalAsync/useLuiModalUpload.js +34 -0
- package/dist/LuiModalAsync/useLuiModalUpload.js.map +1 -0
- package/dist/LuiModalAsync/useShowAsyncModal.d.ts +6 -0
- package/dist/LuiModalAsync/useShowAsyncModal.js +13 -0
- package/dist/LuiModalAsync/useShowAsyncModal.js.map +1 -0
- package/dist/common/debug.d.ts +1 -0
- package/dist/common/debug.js +11 -0
- package/dist/common/debug.js.map +1 -0
- package/dist/common/index.js +3 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/useConstFunction.d.ts +5 -0
- package/dist/common/useConstFunction.js +17 -0
- package/dist/common/useConstFunction.js.map +1 -0
- package/dist/common/useInterval.d.ts +17 -0
- package/dist/common/{useInterval.ts → useInterval.js} +21 -25
- package/dist/common/useInterval.js.map +1 -0
- package/dist/common/useIsomorphicLayoutEffect.d.ts +17 -0
- package/dist/common/{useIsomorphicLayoutEffect.ts → useIsomorphicLayoutEffect.js} +1 -1
- package/dist/common/useIsomorphicLayoutEffect.js.map +1 -0
- package/dist/common/util.d.ts +3 -0
- package/dist/common/util.js +25 -0
- package/dist/common/util.js.map +1 -0
- package/dist/common/uuid.d.ts +1 -0
- package/dist/common/{uuid.ts → uuid.js} +1 -1
- package/dist/common/uuid.js.map +1 -0
- package/dist/components/CopyableText.d.ts +9 -0
- package/dist/components/CopyableText.js +29 -0
- package/dist/components/CopyableText.js.map +1 -0
- package/dist/components/index.js +2 -0
- package/dist/components/index.js.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/panel/OpenPanelButton.d.ts +8 -0
- package/dist/panel/OpenPanelButton.js +11 -0
- package/dist/panel/OpenPanelButton.js.map +1 -0
- package/dist/panel/Panel.d.ts +10 -0
- package/dist/panel/Panel.js +122 -0
- package/dist/panel/Panel.js.map +1 -0
- package/dist/panel/PanelContext.d.ts +10 -0
- package/dist/panel/PanelContext.js +13 -0
- package/dist/panel/PanelContext.js.map +1 -0
- package/dist/panel/PanelDock.d.ts +5 -0
- package/dist/panel/PanelDock.js +9 -0
- package/dist/panel/PanelDock.js.map +1 -0
- package/dist/panel/PanelHeader.d.ts +15 -0
- package/dist/panel/PanelHeader.js +33 -0
- package/dist/panel/PanelHeader.js.map +1 -0
- package/dist/panel/PanelHeaderButton.d.ts +8 -0
- package/dist/panel/PanelHeaderButton.js +16 -0
- package/dist/panel/PanelHeaderButton.js.map +1 -0
- package/dist/panel/PanelInline.d.ts +10 -0
- package/dist/panel/PanelInline.js +26 -0
- package/dist/panel/PanelInline.js.map +1 -0
- package/dist/panel/PanelInstanceContext.d.ts +21 -0
- package/dist/panel/PanelInstanceContext.js +25 -0
- package/dist/panel/PanelInstanceContext.js.map +1 -0
- package/dist/panel/PanelInstanceContextProvider.d.ts +11 -0
- package/dist/panel/PanelInstanceContextProvider.js +50 -0
- package/dist/panel/PanelInstanceContextProvider.js.map +1 -0
- package/dist/panel/PanelsContext.d.ts +33 -0
- package/dist/panel/PanelsContext.js +19 -0
- package/dist/panel/PanelsContext.js.map +1 -0
- package/dist/panel/PanelsContextProvider.d.ts +12 -0
- package/dist/panel/PanelsContextProvider.js +145 -0
- package/dist/panel/PanelsContextProvider.js.map +1 -0
- package/dist/panel/PopinWIndow.d.ts +11 -0
- package/dist/panel/PopinWIndow.js +74 -0
- package/dist/panel/PopinWIndow.js.map +1 -0
- package/dist/panel/PopoutWindow.d.ts +17 -0
- package/dist/panel/PopoutWindow.js +72 -0
- package/dist/panel/PopoutWindow.js.map +1 -0
- package/dist/panel/generateId.d.ts +6 -0
- package/dist/panel/{generateId.ts → generateId.js} +3 -4
- package/dist/panel/generateId.js.map +1 -0
- package/dist/panel/handleStyleSheetsChanges.d.ts +9 -0
- package/dist/panel/handleStyleSheetsChanges.js +65 -0
- package/dist/panel/handleStyleSheetsChanges.js.map +1 -0
- package/dist/panel/index.js +13 -0
- package/dist/panel/index.js.map +1 -0
- package/dist/panel/openExternalWindow.d.ts +23 -0
- package/dist/panel/openExternalWindow.js +62 -0
- package/dist/panel/openExternalWindow.js.map +1 -0
- package/dist/panel/types/{PanelPosition.ts → PanelPosition.d.ts} +2 -2
- package/dist/panel/types/PanelPosition.js +2 -0
- package/dist/panel/types/PanelPosition.js.map +1 -0
- package/dist/panel/types/PanelProps.d.ts +19 -0
- package/dist/panel/types/PanelProps.js +2 -0
- package/dist/panel/types/PanelProps.js.map +1 -0
- package/dist/panel/types/{PanelRestoredState.ts → PanelRestoredState.d.ts} +3 -4
- package/dist/panel/types/PanelRestoredState.js +2 -0
- package/dist/panel/types/PanelRestoredState.js.map +1 -0
- package/dist/panel/types/PanelSize.d.ts +8 -0
- package/dist/panel/types/PanelSize.js +2 -0
- package/dist/panel/types/PanelSize.js.map +1 -0
- package/dist/panel/types/{PanelState.ts → PanelState.d.ts} +5 -8
- package/dist/panel/types/PanelState.js +2 -0
- package/dist/panel/types/PanelState.js.map +1 -0
- package/dist/panel/types/{PanelStateOptions.ts → PanelStateOptions.d.ts} +4 -6
- package/dist/panel/types/PanelStateOptions.js +2 -0
- package/dist/panel/types/PanelStateOptions.js.map +1 -0
- package/dist/panel/types/index.js +7 -0
- package/dist/panel/types/index.js.map +1 -0
- package/dist/panel/usePanelStateHandler.d.ts +8 -0
- package/dist/panel/usePanelStateHandler.js +81 -0
- package/dist/panel/usePanelStateHandler.js.map +1 -0
- package/dist/ribbon/RibbonButton.d.ts +21 -0
- package/dist/ribbon/RibbonButton.js +28 -0
- package/dist/ribbon/RibbonButton.js.map +1 -0
- package/dist/ribbon/RibbonButtonLink.d.ts +12 -0
- package/dist/ribbon/RibbonButtonLink.js +11 -0
- package/dist/ribbon/RibbonButtonLink.js.map +1 -0
- package/dist/ribbon/RibbonButtonOpenPanel.d.ts +5 -0
- package/dist/ribbon/RibbonButtonOpenPanel.js +11 -0
- package/dist/ribbon/RibbonButtonOpenPanel.js.map +1 -0
- package/dist/ribbon/RibbonButtonSlider.d.ts +11 -0
- package/dist/ribbon/RibbonButtonSlider.js +28 -0
- package/dist/ribbon/RibbonButtonSlider.js.map +1 -0
- package/dist/ribbon/RibbonButtonSliderContext.d.ts +25 -0
- package/dist/ribbon/RibbonButtonSliderContext.js +25 -0
- package/dist/ribbon/RibbonButtonSliderContext.js.map +1 -0
- package/dist/ribbon/RibbonContainer.d.ts +10 -0
- package/dist/ribbon/RibbonContainer.js +7 -0
- package/dist/ribbon/RibbonContainer.js.map +1 -0
- package/dist/ribbon/RibbonDeprecated.d.ts +10 -0
- package/dist/ribbon/RibbonDeprecated.js +13 -0
- package/dist/ribbon/RibbonDeprecated.js.map +1 -0
- package/dist/ribbon/RibbonMenu.d.ts +7 -0
- package/dist/ribbon/RibbonMenu.js +12 -0
- package/dist/ribbon/RibbonMenu.js.map +1 -0
- package/dist/ribbon/RibbonMenuOption.d.ts +17 -0
- package/dist/ribbon/RibbonMenuOption.js +26 -0
- package/dist/ribbon/RibbonMenuOption.js.map +1 -0
- package/dist/ribbon/RibbonMenuSeparator.d.ts +2 -0
- package/dist/ribbon/RibbonMenuSeparator.js +6 -0
- package/dist/ribbon/RibbonMenuSeparator.js.map +1 -0
- package/dist/ribbon/RibbonSeparator.d.ts +2 -0
- package/dist/ribbon/RibbonSeparator.js +4 -0
- package/dist/ribbon/RibbonSeparator.js.map +1 -0
- package/dist/ribbon/index.js +12 -0
- package/dist/ribbon/index.js.map +1 -0
- package/package.json +15 -8
- package/dist/LuiModalAsync/LuiModalAsync.tsx +0 -82
- package/dist/LuiModalAsync/LuiModalAsyncButtonGroup.tsx +0 -55
- package/dist/LuiModalAsync/LuiModalAsyncContent.tsx +0 -9
- package/dist/LuiModalAsync/LuiModalAsyncContext.tsx +0 -52
- package/dist/LuiModalAsync/LuiModalAsyncContextProvider.tsx +0 -223
- package/dist/LuiModalAsync/LuiModalAsyncHeader.tsx +0 -67
- package/dist/LuiModalAsync/LuiModalAsyncInstanceContext.ts +0 -24
- package/dist/LuiModalAsync/LuiModalAsyncMain.tsx +0 -8
- package/dist/LuiModalAsync/useLuiModalPrefab.tsx +0 -227
- package/dist/LuiModalAsync/useLuiModalUpload.tsx +0 -79
- package/dist/LuiModalAsync/useShowAsyncModal.ts +0 -34
- package/dist/common/debug.ts +0 -9
- package/dist/common/useConstFunction.ts +0 -22
- package/dist/common/util.ts +0 -31
- package/dist/components/CopyableText.tsx +0 -58
- package/dist/panel/OpenPanelButton.tsx +0 -52
- package/dist/panel/Panel.tsx +0 -211
- package/dist/panel/PanelContext.ts +0 -22
- package/dist/panel/PanelDock.tsx +0 -20
- package/dist/panel/PanelHeader.tsx +0 -105
- package/dist/panel/PanelHeaderButton.tsx +0 -26
- package/dist/panel/PanelInline.tsx +0 -46
- package/dist/panel/PanelInstanceContext.ts +0 -44
- package/dist/panel/PanelInstanceContextProvider.tsx +0 -75
- package/dist/panel/PanelsContext.tsx +0 -56
- package/dist/panel/PanelsContextProvider.tsx +0 -220
- package/dist/panel/PopinWIndow.tsx +0 -147
- package/dist/panel/PopoutWindow.tsx +0 -117
- package/dist/panel/handleStyleSheetsChanges.ts +0 -71
- package/dist/panel/openExternalWindow.ts +0 -98
- package/dist/panel/types/PanelProps.ts +0 -22
- package/dist/panel/types/PanelSize.ts +0 -9
- package/dist/panel/usePanelStateHandler.tsx +0 -102
- package/dist/ribbon/RibbonButton.tsx +0 -112
- package/dist/ribbon/RibbonButtonLink.tsx +0 -27
- package/dist/ribbon/RibbonButtonOpenPanel.tsx +0 -23
- package/dist/ribbon/RibbonButtonSlider.tsx +0 -66
- package/dist/ribbon/RibbonButtonSliderContext.tsx +0 -34
- package/dist/ribbon/RibbonContainer.tsx +0 -19
- package/dist/ribbon/RibbonDeprecated.tsx +0 -27
- package/dist/ribbon/RibbonMenu.tsx +0 -25
- package/dist/ribbon/RibbonMenuOption.tsx +0 -67
- package/dist/ribbon/RibbonMenuSeparator.tsx +0 -5
- package/dist/ribbon/RibbonSeparator.tsx +0 -3
- /package/dist/LuiModalAsync/{index.ts → index.d.ts} +0 -0
- /package/dist/common/{index.ts → index.d.ts} +0 -0
- /package/dist/components/{index.ts → index.d.ts} +0 -0
- /package/dist/{index.ts → index.d.ts} +0 -0
- /package/dist/panel/{index.ts → index.d.ts} +0 -0
- /package/dist/panel/types/{index.ts → index.d.ts} +0 -0
- /package/dist/ribbon/{index.ts → index.d.ts} +0 -0
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { castArray, isEmpty, maxBy, partition, sortBy } from 'lodash-es';
|
|
2
|
-
import React, { Fragment, PropsWithChildren, ReactElement, useCallback, useMemo, useRef, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import { PanelInstanceContextProvider } from './PanelInstanceContextProvider';
|
|
5
|
-
import { OpenPanelOptions, PanelInstance, PanelsContext } from './PanelsContext';
|
|
6
|
-
import { PanelPosition } from './types';
|
|
7
|
-
import { PanelStateOptions } from './types/PanelStateOptions';
|
|
8
|
-
import { v4 } from '../common/uuid';
|
|
9
|
-
import { useInterval } from '../common/useInterval';
|
|
10
|
-
|
|
11
|
-
export interface PanelsContextProviderProps {
|
|
12
|
-
baseZIndex?: number;
|
|
13
|
-
bounds?: string | Element;
|
|
14
|
-
panelStateOptions?: PanelStateOptions | null;
|
|
15
|
-
tilingStart?: PanelPosition;
|
|
16
|
-
tilingOffset?: PanelPosition;
|
|
17
|
-
tilingMax?: PanelPosition;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const defaultPanelStateOptions: PanelStateOptions = {
|
|
21
|
-
saveStateIn: 'localStorage',
|
|
22
|
-
saveStateKey: 'userId',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const PanelsContextProvider = ({
|
|
26
|
-
bounds,
|
|
27
|
-
baseZIndex = 500,
|
|
28
|
-
children,
|
|
29
|
-
panelStateOptions: _panelStateOptions,
|
|
30
|
-
tilingStart = { x: 30, y: 30 },
|
|
31
|
-
tilingOffset = { x: 30, y: 50 },
|
|
32
|
-
tilingMax = { x: 200, y: 300 },
|
|
33
|
-
}: PropsWithChildren<PanelsContextProviderProps>): ReactElement => {
|
|
34
|
-
const panelStateOptions = _panelStateOptions === undefined ? defaultPanelStateOptions : _panelStateOptions;
|
|
35
|
-
|
|
36
|
-
const stackPositionRef = useRef(tilingStart);
|
|
37
|
-
|
|
38
|
-
// Can't use a map here as we need to retain render order for performance
|
|
39
|
-
const [panelInstances, setPanelInstances] = useState<PanelInstance[]>([]);
|
|
40
|
-
|
|
41
|
-
const [dockElements, setDockElements] = useState<Record<string, HTMLDivElement>>({});
|
|
42
|
-
|
|
43
|
-
const setDockElement = useCallback(
|
|
44
|
-
(id: string, element: HTMLDivElement) => {
|
|
45
|
-
if (dockElements[id] !== element) {
|
|
46
|
-
setDockElements({ ...dockElements, [id]: element });
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
[dockElements],
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const bringPanelToFront = useCallback(
|
|
53
|
-
(panelUniqueId: string) => {
|
|
54
|
-
setPanelInstances((panelInstances): PanelInstance[] => {
|
|
55
|
-
const panelInstance = panelInstances.find((panelInstance) => panelInstance.uniqueId === panelUniqueId);
|
|
56
|
-
if (!panelInstance) {
|
|
57
|
-
console.warn(`bringPanelToFront cannot find panel with uniqueId: ${panelUniqueId}`);
|
|
58
|
-
return panelInstances;
|
|
59
|
-
}
|
|
60
|
-
if (panelInstance.window) {
|
|
61
|
-
panelInstance.window.focus();
|
|
62
|
-
return panelInstances;
|
|
63
|
-
}
|
|
64
|
-
const maxZIndexPanelInstance = maxBy(panelInstances, 'zIndex');
|
|
65
|
-
// Prevent unnecessary state updates
|
|
66
|
-
if (maxZIndexPanelInstance === panelInstance) {
|
|
67
|
-
return panelInstances;
|
|
68
|
-
}
|
|
69
|
-
sortBy(panelInstances, (pi) => (panelInstance === pi ? 32768 : pi.zIndex)).forEach(
|
|
70
|
-
(pi, i) => (pi.zIndex = baseZIndex + i),
|
|
71
|
-
);
|
|
72
|
-
return [...panelInstances];
|
|
73
|
-
});
|
|
74
|
-
},
|
|
75
|
-
[baseZIndex],
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
const showHidePanel = useCallback((hidePanelIds: string | string[], hidden: boolean) => {
|
|
79
|
-
setPanelInstances((panelInstances) => {
|
|
80
|
-
const panelIds = castArray(hidePanelIds);
|
|
81
|
-
return panelInstances.map((pi) => {
|
|
82
|
-
return panelIds.includes(pi.uniqueId) && pi.hidden !== hidden ? { ...pi, hidden } : pi;
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
}, []);
|
|
86
|
-
|
|
87
|
-
const hidePanel = useCallback(
|
|
88
|
-
(hidePanelIds: string | string[]) => {
|
|
89
|
-
showHidePanel(hidePanelIds, true);
|
|
90
|
-
},
|
|
91
|
-
[showHidePanel],
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const unhidePanel = useCallback(
|
|
95
|
-
(hidePanelIds: string | string[]) => {
|
|
96
|
-
showHidePanel(hidePanelIds, false);
|
|
97
|
-
},
|
|
98
|
-
[showHidePanel],
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const hasHiddenPanel = useCallback(
|
|
102
|
-
(panelId: string) => {
|
|
103
|
-
return panelInstances.find((pi) => pi.uniqueId === panelId)?.hidden === true;
|
|
104
|
-
},
|
|
105
|
-
[panelInstances],
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const openPanel = useCallback(
|
|
109
|
-
({ componentFn, poppedOut = false, uniqueId = v4(), onClose }: OpenPanelOptions): string | null => {
|
|
110
|
-
try {
|
|
111
|
-
setPanelInstances((panelInstances) => {
|
|
112
|
-
const existingPanelInstance = panelInstances.find((pi) => pi.uniqueId === uniqueId);
|
|
113
|
-
if (existingPanelInstance) {
|
|
114
|
-
if (existingPanelInstance.window) {
|
|
115
|
-
existingPanelInstance.window?.focus();
|
|
116
|
-
} else {
|
|
117
|
-
if (existingPanelInstance.hidden) {
|
|
118
|
-
setTimeout(() => unhidePanel(uniqueId), 0);
|
|
119
|
-
}
|
|
120
|
-
setTimeout(() => bringPanelToFront(uniqueId), 0);
|
|
121
|
-
}
|
|
122
|
-
return panelInstances;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return [
|
|
126
|
-
...panelInstances,
|
|
127
|
-
{
|
|
128
|
-
uniqueId,
|
|
129
|
-
componentInstance: componentFn(),
|
|
130
|
-
zIndex: baseZIndex + panelInstances.length,
|
|
131
|
-
poppedOut,
|
|
132
|
-
window: null,
|
|
133
|
-
onClose,
|
|
134
|
-
hidden: false,
|
|
135
|
-
},
|
|
136
|
-
];
|
|
137
|
-
});
|
|
138
|
-
return uniqueId;
|
|
139
|
-
} catch (e) {
|
|
140
|
-
console.error(e);
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
[baseZIndex, bringPanelToFront, unhidePanel],
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
const closePanel = useCallback((closePanelUniqueIds: string | string[]) => {
|
|
148
|
-
const panelIds = castArray(closePanelUniqueIds);
|
|
149
|
-
setPanelInstances((panelInstances) => {
|
|
150
|
-
const [closedPanelInstances, stillOpenPanelInstances] = partition(panelInstances, (pi) =>
|
|
151
|
-
panelIds.includes(pi.uniqueId),
|
|
152
|
-
);
|
|
153
|
-
if (!isEmpty(closedPanelInstances)) {
|
|
154
|
-
closedPanelInstances.forEach(({ onClose }) => {
|
|
155
|
-
onClose?.();
|
|
156
|
-
});
|
|
157
|
-
return stillOpenPanelInstances;
|
|
158
|
-
}
|
|
159
|
-
return panelInstances;
|
|
160
|
-
});
|
|
161
|
-
}, []);
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* It's not easy to tell the difference between a window closing and a window popping in via events,
|
|
165
|
-
* so we're periodically checking instead.
|
|
166
|
-
*/
|
|
167
|
-
useInterval(() => {
|
|
168
|
-
// close any panels that have a window that is closed
|
|
169
|
-
closePanel(panelInstances.filter((pi) => pi.window?.closed).map((panel) => panel.uniqueId));
|
|
170
|
-
}, 500);
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Tile the panel position relative to previous panel
|
|
174
|
-
*/
|
|
175
|
-
const nextStackPosition = useCallback(() => {
|
|
176
|
-
const p = { ...stackPositionRef.current };
|
|
177
|
-
const result = { ...p };
|
|
178
|
-
p.x += tilingOffset.x;
|
|
179
|
-
p.y += tilingOffset.y;
|
|
180
|
-
stackPositionRef.current = p.x > tilingMax.x || p.y > tilingMax.y ? tilingStart : p;
|
|
181
|
-
return result;
|
|
182
|
-
}, [tilingMax.x, tilingMax.y, tilingOffset.x, tilingOffset.y, tilingStart]);
|
|
183
|
-
|
|
184
|
-
const openPanels = useMemo(() => new Set(panelInstances.map((pi) => pi.uniqueId)), [panelInstances]);
|
|
185
|
-
|
|
186
|
-
const hasOpenPanel = useCallback((panelId: string): boolean => openPanels.has(panelId), [openPanels]);
|
|
187
|
-
|
|
188
|
-
return (
|
|
189
|
-
<PanelsContext.Provider
|
|
190
|
-
value={{
|
|
191
|
-
openPanels,
|
|
192
|
-
hasOpenPanel,
|
|
193
|
-
openPanel,
|
|
194
|
-
closePanel,
|
|
195
|
-
hasHiddenPanel,
|
|
196
|
-
bringPanelToFront,
|
|
197
|
-
nextStackPosition,
|
|
198
|
-
dockElements,
|
|
199
|
-
setDockElement,
|
|
200
|
-
panelStateOptions,
|
|
201
|
-
hidePanel,
|
|
202
|
-
unhidePanel,
|
|
203
|
-
}}
|
|
204
|
-
>
|
|
205
|
-
<Fragment key={'panels'}>
|
|
206
|
-
{panelInstances.map((panelInstance) => (
|
|
207
|
-
<PanelInstanceContextProvider
|
|
208
|
-
key={panelInstance.uniqueId}
|
|
209
|
-
panelInstance={panelInstance}
|
|
210
|
-
bounds={bounds}
|
|
211
|
-
hidden={panelInstance.hidden}
|
|
212
|
-
>
|
|
213
|
-
{panelInstance.componentInstance}
|
|
214
|
-
</PanelInstanceContextProvider>
|
|
215
|
-
))}
|
|
216
|
-
</Fragment>
|
|
217
|
-
<Fragment key={'children'}>{children}</Fragment>
|
|
218
|
-
</PanelsContext.Provider>
|
|
219
|
-
);
|
|
220
|
-
};
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
|
-
import { pick } from 'lodash-es';
|
|
3
|
-
import { Dispatch, ReactElement, useCallback, useContext, useEffect, useRef } from 'react';
|
|
4
|
-
import { Rnd } from 'react-rnd';
|
|
5
|
-
|
|
6
|
-
import { PanelContext } from './PanelContext';
|
|
7
|
-
import { PanelInstanceContext } from './PanelInstanceContext';
|
|
8
|
-
import { PanelPosition, PanelSize } from './types';
|
|
9
|
-
import { PanelProps } from './types/PanelProps';
|
|
10
|
-
import { useSaveStateIn } from './usePanelStateHandler';
|
|
11
|
-
|
|
12
|
-
export function PopinWindow({
|
|
13
|
-
children,
|
|
14
|
-
className,
|
|
15
|
-
maxHeight,
|
|
16
|
-
maxWidth,
|
|
17
|
-
minHeight,
|
|
18
|
-
minWidth,
|
|
19
|
-
modal,
|
|
20
|
-
position = modal ? 'center' : 'tile',
|
|
21
|
-
resizeable = modal !== true,
|
|
22
|
-
size = { height: 200, width: 320 },
|
|
23
|
-
panelPosition,
|
|
24
|
-
setPanelPosition,
|
|
25
|
-
panelSize,
|
|
26
|
-
setPanelSize,
|
|
27
|
-
setInitialPanelSize,
|
|
28
|
-
hidden,
|
|
29
|
-
}: PanelProps & {
|
|
30
|
-
panelPosition: PanelPosition;
|
|
31
|
-
setPanelPosition: Dispatch<PanelPosition>;
|
|
32
|
-
panelSize: PanelSize;
|
|
33
|
-
setPanelSize: Dispatch<PanelSize>;
|
|
34
|
-
setInitialPanelSize: Dispatch<PanelSize>;
|
|
35
|
-
hidden?: boolean;
|
|
36
|
-
}): ReactElement {
|
|
37
|
-
const panelRef = useRef<Rnd>(null);
|
|
38
|
-
|
|
39
|
-
const { bounds, zIndex, bringPanelToFront, uniqueId } = useContext(PanelInstanceContext);
|
|
40
|
-
|
|
41
|
-
const centerWindow = useCallback(() => {
|
|
42
|
-
const b = panelRef.current?.getSelfElement()?.getBoundingClientRect();
|
|
43
|
-
let height = b?.height ?? size.height;
|
|
44
|
-
// You can't auto height a centered panel
|
|
45
|
-
if (height === 'auto') {
|
|
46
|
-
height = 400;
|
|
47
|
-
}
|
|
48
|
-
setPanelPosition({
|
|
49
|
-
x: Math.max((window.innerWidth - (b?.width ?? size.width)) / 2, 0),
|
|
50
|
-
y: Math.max((window.innerHeight - height) / 2, 0),
|
|
51
|
-
});
|
|
52
|
-
}, [setPanelPosition, size.height, size.width]);
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (position === 'center' && !resizeable) {
|
|
56
|
-
centerWindow();
|
|
57
|
-
|
|
58
|
-
window.addEventListener('resize', centerWindow);
|
|
59
|
-
return () => window.removeEventListener('resize', centerWindow);
|
|
60
|
-
}
|
|
61
|
-
return;
|
|
62
|
-
}, [centerWindow, position, resizeable]);
|
|
63
|
-
|
|
64
|
-
const resizePanel = useCallback(
|
|
65
|
-
(newPanelSize: Partial<PanelSize>) => {
|
|
66
|
-
const newSize = { ...panelSize, ...newPanelSize };
|
|
67
|
-
if (newSize.width !== panelSize.width || newSize.height !== panelSize.height) {
|
|
68
|
-
setPanelSize(newSize);
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
[panelSize, setPanelSize],
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const initialResizePanel = useCallback(
|
|
75
|
-
(newPanelSize: Partial<PanelSize>) => {
|
|
76
|
-
const newSize = { ...panelSize, ...newPanelSize };
|
|
77
|
-
if (newSize.width !== panelSize.width || newSize.height !== panelSize.height) {
|
|
78
|
-
setInitialPanelSize(newSize);
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
[panelSize, setInitialPanelSize],
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
const saveStateIn = useSaveStateIn({ uniqueId });
|
|
85
|
-
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
saveStateIn({
|
|
88
|
-
panelPosition,
|
|
89
|
-
panelSize,
|
|
90
|
-
});
|
|
91
|
-
}, [panelPosition, panelSize, saveStateIn]);
|
|
92
|
-
|
|
93
|
-
return (
|
|
94
|
-
<PanelContext.Provider value={{ resizePanel, initialResizePanel, resizeable }}>
|
|
95
|
-
{modal && (
|
|
96
|
-
<div
|
|
97
|
-
style={{
|
|
98
|
-
position: 'absolute',
|
|
99
|
-
top: 0,
|
|
100
|
-
left: 0,
|
|
101
|
-
bottom: 0,
|
|
102
|
-
right: 0,
|
|
103
|
-
backgroundColor: 'rgb(0,0,0,0.1)',
|
|
104
|
-
zIndex,
|
|
105
|
-
}}
|
|
106
|
-
/>
|
|
107
|
-
)}
|
|
108
|
-
<Rnd
|
|
109
|
-
ref={panelRef}
|
|
110
|
-
className={clsx('WindowPanel', className)}
|
|
111
|
-
dragHandleClassName={'draggable-handle'}
|
|
112
|
-
maxHeight={maxHeight}
|
|
113
|
-
maxWidth={maxWidth}
|
|
114
|
-
minWidth={minWidth}
|
|
115
|
-
minHeight={minHeight}
|
|
116
|
-
position={panelPosition}
|
|
117
|
-
size={panelSize.height === 'auto' ? (pick(panelSize, 'width') as PanelSize) : panelSize}
|
|
118
|
-
style={{ zIndex, visibility: hidden ? 'hidden' : undefined }}
|
|
119
|
-
disableDragging={!resizeable}
|
|
120
|
-
enableResizing={resizeable}
|
|
121
|
-
bounds={bounds ?? document.body}
|
|
122
|
-
onDragStop={(_evt, data) => {
|
|
123
|
-
setPanelPosition({ x: data.x, y: data.y });
|
|
124
|
-
}}
|
|
125
|
-
onResizeStop={(_evt, _dir, ref, _delta, position) => {
|
|
126
|
-
setPanelPosition(position);
|
|
127
|
-
setPanelSize({
|
|
128
|
-
width: parseInt(ref.style.width),
|
|
129
|
-
height: parseInt(ref.style.height),
|
|
130
|
-
});
|
|
131
|
-
}}
|
|
132
|
-
onMouseDown={bringPanelToFront}
|
|
133
|
-
>
|
|
134
|
-
<div
|
|
135
|
-
style={{
|
|
136
|
-
display: 'flex',
|
|
137
|
-
flexDirection: 'column',
|
|
138
|
-
width: '100%',
|
|
139
|
-
height: '100%',
|
|
140
|
-
}}
|
|
141
|
-
>
|
|
142
|
-
{children}
|
|
143
|
-
</div>
|
|
144
|
-
</Rnd>
|
|
145
|
-
</PanelContext.Provider>
|
|
146
|
-
);
|
|
147
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import createCache from '@emotion/cache';
|
|
2
|
-
import { CacheProvider } from '@emotion/react';
|
|
3
|
-
import { PropsWithChildren, ReactElement, useContext, useEffect, useState } from 'react';
|
|
4
|
-
import ReactDOM from 'react-dom';
|
|
5
|
-
|
|
6
|
-
import { makePopoutId } from './generateId';
|
|
7
|
-
import { openExternalWindow, OpenExternalWindowResponse } from './openExternalWindow';
|
|
8
|
-
import { PanelInstanceContext } from './PanelInstanceContext';
|
|
9
|
-
import { PanelPosition, PanelSizeExact } from './types';
|
|
10
|
-
import { useRestoreStateFrom, useSaveStateIn } from './usePanelStateHandler';
|
|
11
|
-
|
|
12
|
-
interface _PopoutWindowProps {
|
|
13
|
-
name: string;
|
|
14
|
-
title?: string; // The title of the popout window
|
|
15
|
-
size: PanelSizeExact;
|
|
16
|
-
popInPanelPosition: PanelPosition;
|
|
17
|
-
popInPanelSize: PanelSizeExact;
|
|
18
|
-
|
|
19
|
-
//says if we want to watch for any dynamic style changes
|
|
20
|
-
//only needed when using UI libraries like MUI
|
|
21
|
-
observeStyleChanges?: boolean;
|
|
22
|
-
|
|
23
|
-
/** Testing seam to avoid extensively mocking the window object. */
|
|
24
|
-
openExternalWindowFn?: () => OpenExternalWindowResponse;
|
|
25
|
-
className?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type PopoutWindowProps = PropsWithChildren<_PopoutWindowProps>;
|
|
29
|
-
|
|
30
|
-
export const PopoutWindow = ({
|
|
31
|
-
name,
|
|
32
|
-
title = name,
|
|
33
|
-
size,
|
|
34
|
-
popInPanelPosition,
|
|
35
|
-
popInPanelSize,
|
|
36
|
-
observeStyleChanges,
|
|
37
|
-
className,
|
|
38
|
-
openExternalWindowFn,
|
|
39
|
-
children,
|
|
40
|
-
}: PopoutWindowProps): ReactElement | null => {
|
|
41
|
-
const { setPanelWindow } = useContext(PanelInstanceContext);
|
|
42
|
-
|
|
43
|
-
const [containerElement, setContainerElement] = useState<HTMLElement>();
|
|
44
|
-
const [headElement, setHeadElement] = useState<HTMLElement>();
|
|
45
|
-
|
|
46
|
-
const savedState = useRestoreStateFrom({ uniqueId: name, panelPoppedOut: true });
|
|
47
|
-
|
|
48
|
-
// If we use a popped in position as a popped out position we must adjust for which screen the window is on.
|
|
49
|
-
const poppedInPosition = popInPanelPosition;
|
|
50
|
-
const poppedInPositionAdjusted = {
|
|
51
|
-
x: window.screenX + poppedInPosition.x,
|
|
52
|
-
y: window.screenY + poppedInPosition.y,
|
|
53
|
-
};
|
|
54
|
-
const position = savedState?.panelPosition ?? poppedInPositionAdjusted;
|
|
55
|
-
const panelSize = savedState?.panelSize ?? popInPanelSize ?? size;
|
|
56
|
-
|
|
57
|
-
const saveStateIn = useSaveStateIn({ panelPoppedOut: true, uniqueId: name });
|
|
58
|
-
|
|
59
|
-
// When we create this component, open a new window
|
|
60
|
-
useEffect(
|
|
61
|
-
() => {
|
|
62
|
-
const oew = openExternalWindowFn ?? openExternalWindow;
|
|
63
|
-
const { externalWindow, onCloseExternalWindow } = oew({
|
|
64
|
-
title,
|
|
65
|
-
size: panelSize.height === 'auto' ? { ...panelSize, height: 400 } : (panelSize as PanelSizeExact),
|
|
66
|
-
setContainerElement,
|
|
67
|
-
setHeadElement,
|
|
68
|
-
observeStyleChanges,
|
|
69
|
-
className,
|
|
70
|
-
position,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
if (!externalWindow) return;
|
|
74
|
-
|
|
75
|
-
setPanelWindow(externalWindow);
|
|
76
|
-
|
|
77
|
-
const closeExternalWindow = () => {
|
|
78
|
-
externalWindow.close();
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const savePanelState = () => {
|
|
82
|
-
saveStateIn({
|
|
83
|
-
panelPosition: {
|
|
84
|
-
x: externalWindow.screenX,
|
|
85
|
-
y: externalWindow.screenY,
|
|
86
|
-
},
|
|
87
|
-
panelSize: {
|
|
88
|
-
height: externalWindow.innerHeight,
|
|
89
|
-
width: externalWindow.innerWidth,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
externalWindow.addEventListener('beforeunload', savePanelState);
|
|
95
|
-
|
|
96
|
-
// When the main window closes or reloads, close the popout
|
|
97
|
-
window.addEventListener('beforeunload', closeExternalWindow, { once: true });
|
|
98
|
-
|
|
99
|
-
return () => {
|
|
100
|
-
onCloseExternalWindow?.();
|
|
101
|
-
};
|
|
102
|
-
},
|
|
103
|
-
// These deps MUST be empty
|
|
104
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
105
|
-
[],
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
// Render this component's children into the root element of the popout window
|
|
109
|
-
// The `@emotion/react/CacheProvider`provides a cache derived from createCache for inline styles
|
|
110
|
-
// these will be generated into the `container` and prefixed with the `key` below, ensuring
|
|
111
|
-
// the styles are in the popout rather than the root window.
|
|
112
|
-
const myCache = createCache({ key: makePopoutId(name), container: headElement });
|
|
113
|
-
|
|
114
|
-
const wrappedChildren = <CacheProvider value={myCache}>{children}</CacheProvider>;
|
|
115
|
-
|
|
116
|
-
return containerElement ? ReactDOM.createPortal(wrappedChildren, containerElement) : null;
|
|
117
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { throttle } from 'lodash-es';
|
|
2
|
-
|
|
3
|
-
// Copy the app's styles into the new window
|
|
4
|
-
export const copyStyleSheets = (newHeadMountElement: HTMLDivElement) => {
|
|
5
|
-
const stylesheets = Array.from(document.styleSheets);
|
|
6
|
-
|
|
7
|
-
stylesheets.forEach((stylesheet) => {
|
|
8
|
-
if (stylesheet.href) {
|
|
9
|
-
const newStyleElement = document.createElement('link');
|
|
10
|
-
newStyleElement.rel = 'stylesheet';
|
|
11
|
-
newStyleElement.href = stylesheet.href;
|
|
12
|
-
newHeadMountElement.appendChild(newStyleElement);
|
|
13
|
-
} else {
|
|
14
|
-
const css = stylesheet;
|
|
15
|
-
if (css && css.cssRules && css.cssRules.length > 0) {
|
|
16
|
-
const newStyleElement = document.createElement('style');
|
|
17
|
-
Array.from(css.cssRules).forEach((rule) => {
|
|
18
|
-
newStyleElement.appendChild(document.createTextNode(rule.cssText));
|
|
19
|
-
});
|
|
20
|
-
newHeadMountElement.appendChild(newStyleElement);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Add listener for dynamic style changes
|
|
27
|
-
* This works by listening to any changes to the head element
|
|
28
|
-
* If there are any changes it replaces all the styles in the floating window
|
|
29
|
-
* at most every 100ms
|
|
30
|
-
* @param newHeadMountElement
|
|
31
|
-
*/
|
|
32
|
-
export const observeStyleSheetChanges = (newHeadMountElement: HTMLDivElement) => {
|
|
33
|
-
const targetNode = document.querySelector('head');
|
|
34
|
-
|
|
35
|
-
if (!targetNode) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
// Options for the observer (which mutations to observe)
|
|
39
|
-
const config = { /*attributes: true,*/ childList: true /*, subtree: true */ };
|
|
40
|
-
|
|
41
|
-
//throttle the copying of the all the styles at most 100ms
|
|
42
|
-
const throttleCopyStyleSheets = throttle(() => {
|
|
43
|
-
copyStyleSheets(newHeadMountElement);
|
|
44
|
-
}, 100);
|
|
45
|
-
|
|
46
|
-
// Callback function to execute when mutations are observed
|
|
47
|
-
const callback: MutationCallback = function (mutationList) {
|
|
48
|
-
for (const mutation of mutationList) {
|
|
49
|
-
if (mutation.type === 'childList') {
|
|
50
|
-
// console.log("A child node has been added or removed.", mutation);
|
|
51
|
-
//naive way up updating style sheets
|
|
52
|
-
//the observer tells us what has been added and removed, but syncing the changes with the
|
|
53
|
-
//floating window is complicated, so the easiest way is to just wait for modifications for finish
|
|
54
|
-
//updating, then replace them all
|
|
55
|
-
//we could probably just copy all style on every modification, by that might have a performance hit
|
|
56
|
-
throttleCopyStyleSheets();
|
|
57
|
-
} /*else if (mutation.type === "attributes") {
|
|
58
|
-
//Do we need to handle attribute modifications?
|
|
59
|
-
// console.log("The " + mutation.attributeName + " attribute was modified.");
|
|
60
|
-
}*/
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// Create an observer instance linked to the callback function
|
|
65
|
-
const observer = new MutationObserver(callback);
|
|
66
|
-
|
|
67
|
-
// Start observing the target node for configured mutations
|
|
68
|
-
observer.observe(targetNode, config);
|
|
69
|
-
|
|
70
|
-
return observer;
|
|
71
|
-
};
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
|
|
3
|
-
import { makePopoutId, popoutWindowDivId } from './generateId';
|
|
4
|
-
import { copyStyleSheets, observeStyleSheetChanges } from './handleStyleSheetsChanges';
|
|
5
|
-
import { PanelPosition, PanelSizeExact } from './types';
|
|
6
|
-
|
|
7
|
-
export type OpenExternalWindowResponse = {
|
|
8
|
-
externalWindow: Window | null;
|
|
9
|
-
onCloseExternalWindow: (() => void) | null;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Open and scaffold the new external window.
|
|
13
|
-
*
|
|
14
|
-
* The main motivation for extracting these procedures into a function is for testing ease. JSDOM does not mock out the
|
|
15
|
-
* entire window object, making the PopoutWindow component difficult to unit test without extensive mocking. Instead, we
|
|
16
|
-
* can avoid mocking most of the window methods entirely by conditionally calling an alternative to `openExternalWindow`
|
|
17
|
-
* during unit testing by providing a truthy `openExternalWindowFn` prop.
|
|
18
|
-
*/
|
|
19
|
-
export const openExternalWindow = ({
|
|
20
|
-
title,
|
|
21
|
-
size,
|
|
22
|
-
setContainerElement,
|
|
23
|
-
setHeadElement,
|
|
24
|
-
observeStyleChanges = false,
|
|
25
|
-
className,
|
|
26
|
-
position,
|
|
27
|
-
}: {
|
|
28
|
-
title: string;
|
|
29
|
-
size: PanelSizeExact;
|
|
30
|
-
setContainerElement: Dispatch<SetStateAction<HTMLElement | undefined>>;
|
|
31
|
-
setHeadElement: Dispatch<SetStateAction<HTMLElement | undefined>>;
|
|
32
|
-
observeStyleChanges?: boolean;
|
|
33
|
-
className?: string;
|
|
34
|
-
position: PanelPosition;
|
|
35
|
-
}): OpenExternalWindowResponse => {
|
|
36
|
-
const response: OpenExternalWindowResponse = { externalWindow: null, onCloseExternalWindow: null };
|
|
37
|
-
|
|
38
|
-
// NOTE:
|
|
39
|
-
// 1/ Edge ignores the left and top settings
|
|
40
|
-
// 2/ Chrome has a bug that screws up the window size by a factor dependent on your windows scaling settings
|
|
41
|
-
// if you open the browser in a window with a scaling and drag it to a window with a different scaling
|
|
42
|
-
const features =
|
|
43
|
-
`scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,` +
|
|
44
|
-
`width=${size.width},height=${size.height},left=${position.x},top=${position.y}`;
|
|
45
|
-
response.externalWindow = window.open('', makePopoutId(title), features);
|
|
46
|
-
|
|
47
|
-
if (response.externalWindow) {
|
|
48
|
-
const { externalWindow } = response;
|
|
49
|
-
|
|
50
|
-
// Reset the default body style applied by the browser
|
|
51
|
-
externalWindow.document.body.style.margin = '0';
|
|
52
|
-
externalWindow.document.body.style.padding = '0';
|
|
53
|
-
|
|
54
|
-
// Remove any existing body HTML from this window
|
|
55
|
-
const existingBodyMountElement = externalWindow.document.body?.firstChild;
|
|
56
|
-
if (existingBodyMountElement) {
|
|
57
|
-
externalWindow.document.body.removeChild(existingBodyMountElement);
|
|
58
|
-
}
|
|
59
|
-
// Create a new HTML element to hang our rendering off
|
|
60
|
-
const newMountElement = externalWindow.document.createElement('div');
|
|
61
|
-
newMountElement.className = `PopoutWindowContainer ${className || ''}`;
|
|
62
|
-
setContainerElement(newMountElement);
|
|
63
|
-
externalWindow.document.body.appendChild(newMountElement);
|
|
64
|
-
|
|
65
|
-
// Do the same for the head node (where all the styles are added)
|
|
66
|
-
const existingHeadMountElement = externalWindow.document.head?.firstChild;
|
|
67
|
-
if (existingHeadMountElement) {
|
|
68
|
-
externalWindow.document.head.removeChild(existingHeadMountElement);
|
|
69
|
-
}
|
|
70
|
-
// and an HTML element to hang our copied styles off
|
|
71
|
-
const newHeadMountElement = externalWindow.document.createElement('div');
|
|
72
|
-
externalWindow.document.head.appendChild(newHeadMountElement);
|
|
73
|
-
setHeadElement(newHeadMountElement);
|
|
74
|
-
|
|
75
|
-
// Set External window title
|
|
76
|
-
externalWindow.document.title = title;
|
|
77
|
-
|
|
78
|
-
// Set an id to the external window div to be queried and used by react-modal as parentSelector
|
|
79
|
-
// so the modal shows up in the popped out window instead the main window
|
|
80
|
-
newMountElement.id = popoutWindowDivId(title);
|
|
81
|
-
|
|
82
|
-
copyStyleSheets(newHeadMountElement);
|
|
83
|
-
|
|
84
|
-
let observer: MutationObserver | null = null;
|
|
85
|
-
if (observeStyleChanges) {
|
|
86
|
-
observer = observeStyleSheetChanges(newHeadMountElement);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
externalWindow.onbeforeunload = () => observer?.disconnect();
|
|
90
|
-
|
|
91
|
-
response.onCloseExternalWindow = () => {
|
|
92
|
-
// Make sure the window closes when the component unmounts
|
|
93
|
-
externalWindow.close();
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return response;
|
|
98
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
2
|
-
|
|
3
|
-
import { PanelPosition } from './PanelPosition';
|
|
4
|
-
import { PanelSize } from './PanelSize';
|
|
5
|
-
|
|
6
|
-
export type PanelBounds = PanelPosition & PanelSize;
|
|
7
|
-
|
|
8
|
-
interface _PanelProps {
|
|
9
|
-
className?: string;
|
|
10
|
-
maxHeight?: number | string;
|
|
11
|
-
maxWidth?: number | string;
|
|
12
|
-
minHeight?: number | string;
|
|
13
|
-
minWidth?: number | string;
|
|
14
|
-
modal?: boolean;
|
|
15
|
-
dynamicBounds?: () => PanelBounds | null;
|
|
16
|
-
position?: PanelPosition | 'tile' | 'center';
|
|
17
|
-
resizeable?: boolean;
|
|
18
|
-
size?: PanelSize;
|
|
19
|
-
title: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type PanelProps = PropsWithChildren<_PanelProps>;
|