@linzjs/windows 4.1.2 → 5.0.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.
Files changed (41) hide show
  1. package/dist/LuiModalAsync/LuiModalAsync.scss +1 -1
  2. package/dist/LuiModalAsync/LuiModalAsync.tsx +17 -13
  3. package/dist/LuiModalAsync/LuiModalAsyncButtonGroup.tsx +12 -12
  4. package/dist/LuiModalAsync/LuiModalAsyncContent.tsx +2 -2
  5. package/dist/LuiModalAsync/LuiModalAsyncContext.tsx +10 -7
  6. package/dist/LuiModalAsync/LuiModalAsyncContextProvider.tsx +25 -16
  7. package/dist/LuiModalAsync/LuiModalAsyncHeader.tsx +18 -18
  8. package/dist/LuiModalAsync/LuiModalAsyncInstanceContext.ts +3 -2
  9. package/dist/LuiModalAsync/LuiModalAsyncMain.tsx +2 -2
  10. package/dist/LuiModalAsync/index.ts +10 -10
  11. package/dist/LuiModalAsync/useLuiModalPrefab.tsx +50 -49
  12. package/dist/LuiModalAsync/useShowAsyncModal.ts +6 -4
  13. package/dist/common/index.ts +1 -1
  14. package/dist/common/useConstFunction.ts +1 -1
  15. package/dist/index.ts +4 -4
  16. package/dist/panel/OpenPanelButton.tsx +4 -3
  17. package/dist/panel/OpenPanelIcon.scss +3 -4
  18. package/dist/panel/OpenPanelIcon.tsx +12 -12
  19. package/dist/panel/Panel.scss +6 -6
  20. package/dist/panel/Panel.tsx +30 -17
  21. package/dist/panel/PanelBlue.scss +3 -3
  22. package/dist/panel/PanelContext.ts +4 -3
  23. package/dist/panel/PanelDock.tsx +6 -5
  24. package/dist/panel/PanelHeader.tsx +25 -25
  25. package/dist/panel/PanelHeaderButton.tsx +8 -8
  26. package/dist/panel/PanelInstanceContext.ts +5 -5
  27. package/dist/panel/PanelInstanceContextProvider.tsx +6 -5
  28. package/dist/panel/PanelsContext.tsx +5 -4
  29. package/dist/panel/PanelsContextProvider.tsx +12 -11
  30. package/dist/panel/PopinWIndow.tsx +23 -22
  31. package/dist/panel/PopoutWindow.tsx +18 -26
  32. package/dist/panel/generateId.ts +12 -12
  33. package/dist/panel/handleStyleSheetsChanges.ts +7 -7
  34. package/dist/panel/index.ts +12 -13
  35. package/dist/panel/types/PanelProps.ts +5 -4
  36. package/dist/panel/types/PanelRestoredState.ts +2 -2
  37. package/dist/panel/types/PanelState.ts +3 -3
  38. package/dist/panel/types/PanelStateOptions.ts +3 -3
  39. package/dist/panel/types/index.ts +6 -6
  40. package/dist/panel/usePanelStateHandler.tsx +12 -11
  41. package/package.json +47 -66
@@ -1,5 +1,4 @@
1
- @use "node_modules/@linzjs/lui/dist/scss/Core" as lui;
2
- @use "node_modules/@linzjs/lui/dist/scss/Foundation/Variables/ColorVars.scss" as colours;
1
+ @use "@linzjs/lui/dist/scss/Core" as lui;
3
2
 
4
3
  .lui-button.lui-button-toolbar {
5
4
  border-color: transparent;
@@ -53,7 +52,7 @@
53
52
  margin: 6px 0;
54
53
  height: 2px;
55
54
  width: 100%;
56
- background-color: colours.$grey-10;
55
+ background-color: lui.$grey-10;
57
56
  }
58
57
  }
59
58
 
@@ -68,6 +67,6 @@
68
67
  margin-top: -3px;
69
68
  padding-bottom: 8px;
70
69
  width: 2px;
71
- background-color: colours.$grey-10;
70
+ background-color: lui.$grey-10;
72
71
  }
73
72
  }
@@ -1,21 +1,21 @@
1
- import "./OpenPanelIcon.scss";
1
+ import './OpenPanelIcon.scss';
2
2
 
3
- import { OpenPanelOptions, PanelsContext } from "./PanelsContext";
4
- import clsx from "clsx";
5
- import { ReactNode, useContext } from "react";
3
+ import { LuiIcon } from '@linzjs/lui';
4
+ import { IconName } from '@linzjs/lui/dist/components/LuiIcon/LuiIcon';
5
+ import clsx from 'clsx';
6
+ import { ReactNode, useContext } from 'react';
6
7
 
7
- import { LuiIcon } from "@linzjs/lui";
8
- import { IconName } from "@linzjs/lui/dist/components/LuiIcon/LuiIcon";
8
+ import { OpenPanelOptions, PanelsContext } from './PanelsContext';
9
9
 
10
10
  export const ButtonIconHorizontalGroup = ({ children }: { children: ReactNode }) => (
11
11
  <div>
12
- <div className={"OpenPanelIcon-horizontalGroup"}>{children}</div>
12
+ <div className={'OpenPanelIcon-horizontalGroup'}>{children}</div>
13
13
  </div>
14
14
  );
15
15
 
16
16
  export const ButtonIconVerticalGroup = ({ children }: { children: ReactNode }) => (
17
17
  <div>
18
- <div className={"OpenPanelIcon-verticalGroup"}>{children}</div>
18
+ <div className={'OpenPanelIcon-verticalGroup'}>{children}</div>
19
19
  </div>
20
20
  );
21
21
 
@@ -45,16 +45,16 @@ export const OpenPanelIcon = ({
45
45
  type="button"
46
46
  className={clsx(
47
47
  className,
48
- "lui-button lui-button-secondary lui-button-toolbar panel-button",
49
- openPanels.has(uniqueId) && "OpenPanelIcon-selected",
50
- disabled && "OpenPanelIcon-disabled",
48
+ 'lui-button lui-button-secondary lui-button-toolbar panel-button',
49
+ openPanels.has(uniqueId) && 'OpenPanelIcon-selected',
50
+ disabled && 'OpenPanelIcon-disabled',
51
51
  )}
52
52
  title={iconTitle}
53
53
  onClick={() => openPanel({ uniqueId, ...openPanelOptions })}
54
54
  disabled={disabled}
55
55
  data-testid={testId}
56
56
  >
57
- <LuiIcon name={icon} alt={iconTitle} size={"md"} />
57
+ <LuiIcon name={icon} alt={iconTitle} size={'md'} />
58
58
  </button>
59
59
  );
60
60
  };
@@ -1,4 +1,4 @@
1
- @use "node_modules/@linzjs/lui/dist/scss/Foundation/Variables/ColorVars.scss" as colours;
1
+ @use "@linzjs/lui/dist/scss/Core" as lui;
2
2
 
3
3
  .panelDock > .panelDock-content:not(:empty) + .panelDock-empty {
4
4
  display: none;
@@ -14,12 +14,12 @@
14
14
  .WindowPanel-header {
15
15
  height: 48px;
16
16
  line-height: 48px;
17
- color: colours.$charcoal;
17
+ color: lui.$charcoal;
18
18
  padding: 0 16px;
19
19
  display: flex;
20
20
  overflow: hidden;
21
21
  justify-content: space-between;
22
- border-bottom: 2px colours.$lily solid;
22
+ border-bottom: 2px lui.$lily solid;
23
23
  font-size: 1em;
24
24
  font-weight: 600;
25
25
  flex-direction: row;
@@ -69,8 +69,8 @@
69
69
  }
70
70
 
71
71
  %WindowPanel-divider {
72
- border-left: 2px solid colours.$lily;
73
- background-color: colours.$lily;
72
+ border-left: 2px solid lui.$lily;
73
+ background-color: lui.$lily;
74
74
  width: 0;
75
75
  height: 19px;
76
76
  }
@@ -110,7 +110,7 @@
110
110
  }
111
111
 
112
112
  .WindowPanel-header-title-icon {
113
- fill: colours.$fuscous !important;
113
+ fill: lui.$fuscous !important;
114
114
  margin-right: 8px;
115
115
  }
116
116
 
@@ -1,18 +1,20 @@
1
- import "./Panel.scss";
2
- import "./PanelBlue.scss";
3
- import "@linzjs/lui/dist/scss/base.scss";
1
+ import './Panel.scss';
2
+ import './PanelBlue.scss';
3
+ import '@linzjs/lui/dist/scss/base.scss';
4
4
 
5
- import { PanelInstanceContext } from "./PanelInstanceContext";
6
- import { PanelsContext } from "./PanelsContext";
7
- import { PopoutWindow } from "./PopoutWindow";
8
- import clsx from "clsx";
9
- import { PropsWithChildren, ReactElement, useContext, useEffect, useMemo } from "react";
10
- import { createPortal } from "react-dom";
11
- import { PopinWindow } from "./PopinWIndow";
12
- import { PanelProps } from "./types/PanelProps";
13
- import { useConstFunction } from "../common";
5
+ import clsx from 'clsx';
6
+ import { PropsWithChildren, ReactElement, useContext, useEffect, useMemo, useRef } from 'react';
7
+ import { createPortal } from 'react-dom';
8
+
9
+ import { useConstFunction } from '../common';
10
+ import { PanelInstanceContext } from './PanelInstanceContext';
11
+ import { PanelsContext } from './PanelsContext';
12
+ import { PopinWindow } from './PopinWIndow';
13
+ import { PopoutWindow } from './PopoutWindow';
14
+ import { PanelProps } from './types/PanelProps';
14
15
 
15
16
  export const Panel = (props: PanelProps): ReactElement => {
17
+ const panelRef = useRef<HTMLDivElement>(null);
16
18
  const { title, size = { width: 320, height: 200 }, className, children, onClose } = props;
17
19
 
18
20
  const { dockElements, nextStackPosition } = useContext(PanelsContext);
@@ -30,6 +32,16 @@ export const Panel = (props: PanelProps): ReactElement => {
30
32
  setTitle(title);
31
33
  }, [setTitle, title]);
32
34
 
35
+ // We only want to update the title when it changes
36
+ useEffect(() => {
37
+ if (panelRef.current) {
38
+ const doc = panelRef.current.ownerDocument;
39
+ if (doc) {
40
+ doc.title = title;
41
+ }
42
+ }
43
+ }, [title]);
44
+
33
45
  const dockElement = docked && dockId && dockElements[dockId];
34
46
 
35
47
  /**
@@ -38,7 +50,7 @@ export const Panel = (props: PanelProps): ReactElement => {
38
50
 
39
51
  const memoizeNextStackPosition = useMemo(
40
52
  () => {
41
- if (props.position === undefined || props.position === "tile") {
53
+ if (props.position === undefined || props.position === 'tile') {
42
54
  return nextStackPosition();
43
55
  }
44
56
 
@@ -55,11 +67,12 @@ export const Panel = (props: PanelProps): ReactElement => {
55
67
  ) : panelPoppedOut ? (
56
68
  <PopoutWindow name={uniqueId} title={title} size={size}>
57
69
  <div
70
+ ref={panelRef}
58
71
  style={{
59
- display: "flex",
60
- flexDirection: "column",
61
- width: "100%",
62
- height: "100%",
72
+ display: 'flex',
73
+ flexDirection: 'column',
74
+ width: '100%',
75
+ height: '100%',
63
76
  }}
64
77
  className={className}
65
78
  >
@@ -1,4 +1,4 @@
1
- @use "node_modules/@linzjs/lui/dist/scss/Foundation/Variables/ColorVars.scss" as colours;
1
+ @use "@linzjs/lui/dist/scss/Core" as lui;
2
2
 
3
3
  .WindowPanel-blue.WindowPanel-header, .WindowPanel-blue .WindowPanel-header {
4
4
  background: linear-gradient(270deg,#007198,#00425b 100%);
@@ -10,9 +10,9 @@
10
10
  }
11
11
 
12
12
  .WindowPanel-blue .LuiTab {
13
- color: colours.$iceberg
13
+ color: lui.$iceberg
14
14
  }
15
15
 
16
16
  .WindowPanel-blue .LuiTab.LuiTab--active {
17
- color: colours.$downy
17
+ color: lui.$downy
18
18
  }
@@ -1,5 +1,6 @@
1
- import { createContext } from "react";
2
- import { PanelSize } from "./types";
1
+ import { createContext } from 'react';
2
+
3
+ import { PanelSize } from './types';
3
4
 
4
5
  export interface PanelContextType {
5
6
  resizePanel: (size: Partial<PanelSize>) => void;
@@ -7,7 +8,7 @@ export interface PanelContextType {
7
8
  }
8
9
 
9
10
  const NoContextError = () => {
10
- console.error("Missing PanelContext Provider");
11
+ console.error('Missing PanelContext Provider');
11
12
  };
12
13
 
13
14
  /**
@@ -1,5 +1,6 @@
1
- import { PanelsContext } from "./PanelsContext";
2
- import { PropsWithChildren, ReactElement, useContext } from "react";
1
+ import { PropsWithChildren, ReactElement, useContext } from 'react';
2
+
3
+ import { PanelsContext } from './PanelsContext';
3
4
 
4
5
  export interface PanelDockProps {
5
6
  id: string;
@@ -11,9 +12,9 @@ export const PanelDock = ({ id, children }: PropsWithChildren<PanelDockProps>):
11
12
  const setElement = (element: HTMLDivElement) => setDockElement(id, element);
12
13
 
13
14
  return (
14
- <div className={"panelDock"}>
15
- <div ref={setElement} className={"panelDock-content"} />
16
- <div className={"panelDock-empty"}>{children}</div>
15
+ <div className={'panelDock'}>
16
+ <div ref={setElement} className={'panelDock-content'} />
17
+ <div className={'panelDock-empty'}>{children}</div>
17
18
  </div>
18
19
  );
19
20
  };
@@ -1,11 +1,11 @@
1
- import { PanelHeaderButton } from "./PanelHeaderButton";
2
- import { PanelInstanceContext } from "./PanelInstanceContext";
3
- import { ReactNode, useContext, useState } from "react";
1
+ import { LuiIcon } from '@linzjs/lui';
2
+ import { LuiIconName } from '@linzjs/lui/dist/assets/svg-content';
3
+ import clsx from 'clsx';
4
+ import { ReactNode, useContext, useState } from 'react';
4
5
 
5
- import { LuiIcon } from "@linzjs/lui";
6
- import { LuiIconName } from "@linzjs/lui/dist/assets/svg-content";
7
- import { PanelContext } from "./PanelContext";
8
- import clsx from "clsx";
6
+ import { PanelContext } from './PanelContext';
7
+ import { PanelHeaderButton } from './PanelHeaderButton';
8
+ import { PanelInstanceContext } from './PanelInstanceContext';
9
9
 
10
10
  export interface PanelHeaderProps {
11
11
  icon?: LuiIconName;
@@ -33,49 +33,49 @@ export const PanelHeader = ({
33
33
  const { resizeable } = useContext(PanelContext);
34
34
  const { panelClose, panelTogglePopout, panelPoppedOut, title, dock, undock, docked } =
35
35
  useContext(PanelInstanceContext);
36
- const [cursor, setCursor] = useState<"grab" | "grabbing">("grab");
36
+ const [cursor, setCursor] = useState<'grab' | 'grabbing'>('grab');
37
37
 
38
38
  const headerMouseDown = () => {
39
- !panelPoppedOut && setCursor("grabbing");
39
+ !panelPoppedOut && setCursor('grabbing');
40
40
  };
41
41
 
42
42
  return (
43
43
  <div
44
- className={clsx("WindowPanel-header", resizeable && "draggable-handle")}
44
+ className={clsx('WindowPanel-header', resizeable && 'draggable-handle')}
45
45
  onMouseDown={headerMouseDown}
46
- onMouseUp={() => !panelPoppedOut && setCursor("grab")}
46
+ onMouseUp={() => !panelPoppedOut && setCursor('grab')}
47
47
  style={resizeable ? { cursor } : {}}
48
48
  >
49
- <div className={"WindowPanel-header-title"}>
50
- {icon && <LuiIcon name={icon} alt={"icon"} size={"md"} className={"WindowPanel-header-title-icon"} />}
49
+ <div className={'WindowPanel-header-title'}>
50
+ {icon && <LuiIcon name={icon} alt={'icon'} size={'md'} className={'WindowPanel-header-title-icon'} />}
51
51
  {title}
52
52
  </div>
53
- {extraLeft && <div className={"WindowPanel-divider-left"} />}
54
- <div className={"WindowPanel-children"}>{extraLeft}</div>
55
- <div className={"WindowPanel-buttons"}>
53
+ {extraLeft && <div className={'WindowPanel-divider-left'} />}
54
+ <div className={'WindowPanel-children'}>{extraLeft}</div>
55
+ <div className={'WindowPanel-buttons'}>
56
56
  {extraRight}
57
57
  {(helpUrl || onHelpClick) && (
58
- <PanelHeaderButton aria-label={"Help"} href={helpUrl} onClick={onHelpClick} icon={"ic_help_outline"} />
58
+ <PanelHeaderButton aria-label={'Help'} href={helpUrl} onClick={onHelpClick} icon={'ic_help_outline'} />
59
59
  )}
60
60
  </div>
61
- {(dockTo || !disablePopout || !disableClose) && <div className={"WindowPanel-divider-right"} />}
62
- <div className={"WindowPanel-buttons"}>
63
- {onDockClick && <PanelHeaderButton aria-label={"Dock"} onClick={() => onDockClick()} icon={"ic_left_col"} />}
61
+ {(dockTo || !disablePopout || !disableClose) && <div className={'WindowPanel-divider-right'} />}
62
+ <div className={'WindowPanel-buttons'}>
63
+ {onDockClick && <PanelHeaderButton aria-label={'Dock'} onClick={() => onDockClick()} icon={'ic_left_col'} />}
64
64
  {!onDockClick &&
65
65
  dockTo &&
66
66
  (docked ? (
67
- <PanelHeaderButton aria-label={"Undock"} onClick={undock} icon={"ic_close_list"} />
67
+ <PanelHeaderButton aria-label={'Undock'} onClick={undock} icon={'ic_close_list'} />
68
68
  ) : (
69
- <PanelHeaderButton aria-label={"Dock"} onClick={() => dock(dockTo)} icon={"ic_left_col"} />
69
+ <PanelHeaderButton aria-label={'Dock'} onClick={() => dock(dockTo)} icon={'ic_left_col'} />
70
70
  ))}
71
71
  {!disablePopout && (
72
72
  <PanelHeaderButton
73
- aria-label={panelPoppedOut ? "Pop-in" : "Pop-out"}
73
+ aria-label={panelPoppedOut ? 'Pop-in' : 'Pop-out'}
74
74
  onClick={panelTogglePopout}
75
- icon={panelPoppedOut ? "ic_pop_back" : "ic_launch_new window_open"}
75
+ icon={panelPoppedOut ? 'ic_pop_back' : 'ic_launch_new window_open'}
76
76
  />
77
77
  )}
78
- {!disableClose && <PanelHeaderButton aria-label={"Close"} onClick={panelClose} icon={"ic_clear"} />}
78
+ {!disableClose && <PanelHeaderButton aria-label={'Close'} onClick={panelClose} icon={'ic_clear'} />}
79
79
  </div>
80
80
  </div>
81
81
  );
@@ -1,18 +1,18 @@
1
- import { LuiButton, LuiIcon } from "@linzjs/lui";
2
- import { LuiIconName } from "@linzjs/lui/dist/assets/svg-content";
1
+ import { LuiButton, LuiIcon } from '@linzjs/lui';
2
+ import { LuiIconName } from '@linzjs/lui/dist/assets/svg-content';
3
3
 
4
4
  export interface PanelHeaderButtonProps {
5
- "aria-label": string;
5
+ 'aria-label': string;
6
6
  href?: string;
7
7
  icon: LuiIconName;
8
8
  onClick?: () => void;
9
9
  }
10
10
 
11
- export const PanelHeaderButton = ({ "aria-label": ariaLabel, href, icon, onClick }: PanelHeaderButtonProps) => (
11
+ export const PanelHeaderButton = ({ 'aria-label': ariaLabel, href, icon, onClick }: PanelHeaderButtonProps) => (
12
12
  <LuiButton
13
- level={"plain-text"}
14
- className={"lui-button-icon-only"}
15
- size={"sm"}
13
+ level={'plain-text'}
14
+ className={'lui-button-icon-only'}
15
+ size={'sm'}
16
16
  href={href}
17
17
  onClick={onClick}
18
18
  openInNewTab={!!href}
@@ -20,6 +20,6 @@ export const PanelHeaderButton = ({ "aria-label": ariaLabel, href, icon, onClick
20
20
  onTouchStart: onClick,
21
21
  }}
22
22
  >
23
- <LuiIcon name={icon} alt={ariaLabel} size={"md"} />
23
+ <LuiIcon name={icon} alt={ariaLabel} size={'md'} />
24
24
  </LuiButton>
25
25
  );
@@ -1,4 +1,4 @@
1
- import { createContext } from "react";
1
+ import { createContext } from 'react';
2
2
 
3
3
  export interface PanelInstanceContextType {
4
4
  title: string;
@@ -19,16 +19,16 @@ export interface PanelInstanceContextType {
19
19
  }
20
20
 
21
21
  const NoContextError = () => {
22
- console.error("Missing PanelInstanceContext Provider");
22
+ console.error('Missing PanelInstanceContext Provider');
23
23
  };
24
24
 
25
25
  /**
26
26
  * Provides access to closing/popping panels
27
27
  */
28
28
  export const PanelInstanceContext = createContext<PanelInstanceContextType>({
29
- title: "Missing PanelInstanceContext Provider: title",
30
- uniqueId: "Missing PanelInstanceContext Provider: uniqueId",
31
- panelName: "Missing PanelInstanceContext Provider: panelName",
29
+ title: 'Missing PanelInstanceContext Provider: title',
30
+ uniqueId: 'Missing PanelInstanceContext Provider: uniqueId',
31
+ panelName: 'Missing PanelInstanceContext Provider: panelName',
32
32
  bounds: document.body,
33
33
  setTitle: NoContextError,
34
34
  panelTogglePopout: NoContextError,
@@ -1,7 +1,8 @@
1
- import { PanelInstanceContext } from "./PanelInstanceContext";
2
- import { PanelInstance, PanelsContext } from "./PanelsContext";
3
- import { ReactElement, ReactNode, useCallback, useContext, useState } from "react";
4
- import { useRestoreStateFrom } from "./usePanelStateHandler";
1
+ import { ReactElement, ReactNode, useCallback, useContext, useState } from 'react';
2
+
3
+ import { PanelInstanceContext } from './PanelInstanceContext';
4
+ import { PanelInstance, PanelsContext } from './PanelsContext';
5
+ import { useRestoreStateFrom } from './usePanelStateHandler';
5
6
 
6
7
  /**
7
8
  * Provides access to closing/popping panels
@@ -16,7 +17,7 @@ export const PanelInstanceContextProvider = ({
16
17
  children: ReactNode;
17
18
  }): ReactElement => {
18
19
  const { closePanel, bringPanelToFront, dockElements } = useContext(PanelsContext);
19
- const [title, setTitle] = useState("");
20
+ const [title, setTitle] = useState('');
20
21
  const [dockId, setDockId] = useState<string>();
21
22
 
22
23
  const savedState = useRestoreStateFrom({ uniqueId: panelInstance.uniqueId });
@@ -1,6 +1,7 @@
1
- import { ReactElement, createContext } from "react";
2
- import { PanelStateOptions } from "./types/PanelStateOptions";
3
- import { PanelPosition } from "./types";
1
+ import { createContext, ReactElement } from 'react';
2
+
3
+ import { PanelPosition } from './types';
4
+ import { PanelStateOptions } from './types/PanelStateOptions';
4
5
 
5
6
  export interface PanelInstance {
6
7
  uniqueId: string;
@@ -28,7 +29,7 @@ export interface PanelsContextType {
28
29
  }
29
30
 
30
31
  const NoContext = () => {
31
- console.error("Missing PanelContext Provider");
32
+ console.error('Missing PanelContext Provider');
32
33
  };
33
34
 
34
35
  export const PanelsContext = createContext<PanelsContextType>({
@@ -1,11 +1,12 @@
1
- import { PanelInstanceContextProvider } from "./PanelInstanceContextProvider";
2
- import { OpenPanelOptions, PanelInstance, PanelsContext } from "./PanelsContext";
3
- import { castArray, maxBy, sortBy } from "lodash-es";
4
- import React, { Fragment, PropsWithChildren, ReactElement, useCallback, useMemo, useRef, useState } from "react";
5
- import { useInterval } from "usehooks-ts";
6
- import { PanelStateOptions } from "./types/PanelStateOptions";
7
- import { PanelPosition } from "./types";
8
- import { v4 } from "uuid";
1
+ import { castArray, maxBy, sortBy } from 'lodash-es';
2
+ import React, { Fragment, PropsWithChildren, ReactElement, useCallback, useMemo, useRef, useState } from 'react';
3
+ import { useInterval } from 'usehooks-ts';
4
+ import { v4 } from 'uuid';
5
+
6
+ import { PanelInstanceContextProvider } from './PanelInstanceContextProvider';
7
+ import { OpenPanelOptions, PanelInstance, PanelsContext } from './PanelsContext';
8
+ import { PanelPosition } from './types';
9
+ import { PanelStateOptions } from './types/PanelStateOptions';
9
10
 
10
11
  export interface PanelsContextProviderProps {
11
12
  baseZIndex?: number;
@@ -46,7 +47,7 @@ export const PanelsContextProvider = ({
46
47
  if (panelInstance.window) {
47
48
  panelInstance.window.focus();
48
49
  } else {
49
- const maxZIndexPanelInstance = maxBy(panelInstances, "zIndex");
50
+ const maxZIndexPanelInstance = maxBy(panelInstances, 'zIndex');
50
51
  // Prevent unnecessary state updates
51
52
  if (maxZIndexPanelInstance === panelInstance) return;
52
53
  sortBy(panelInstances, (pi) => (panelInstance === pi ? 32768 : pi.zIndex)).forEach(
@@ -134,14 +135,14 @@ export const PanelsContextProvider = ({
134
135
  panelStateOptions,
135
136
  }}
136
137
  >
137
- <Fragment key={"panels"}>
138
+ <Fragment key={'panels'}>
138
139
  {panelInstances.map((panelInstance) => (
139
140
  <PanelInstanceContextProvider key={panelInstance.uniqueId} panelInstance={panelInstance} bounds={bounds}>
140
141
  {panelInstance.componentInstance}
141
142
  </PanelInstanceContextProvider>
142
143
  ))}
143
144
  </Fragment>
144
- <Fragment key={"children"}>{children}</Fragment>
145
+ <Fragment key={'children'}>{children}</Fragment>
145
146
  </PanelsContext.Provider>
146
147
  );
147
148
  };
@@ -1,11 +1,12 @@
1
- import { Rnd } from "react-rnd";
2
- import { useCallback, useContext, useEffect, useRef, useState } from "react";
3
- import clsx from "clsx";
4
- import { PanelInstanceContext } from "./PanelInstanceContext";
5
- import { PanelProps } from "./types/PanelProps";
6
- import { PanelPosition, PanelSize } from "./types";
7
- import { PanelContext } from "./PanelContext";
8
- import { useRestoreStateFrom, useSaveStateIn } from "./usePanelStateHandler";
1
+ import clsx from 'clsx';
2
+ import { useCallback, useContext, useEffect, useRef, useState } from 'react';
3
+ import { Rnd } from 'react-rnd';
4
+
5
+ import { PanelContext } from './PanelContext';
6
+ import { PanelInstanceContext } from './PanelInstanceContext';
7
+ import { PanelPosition, PanelSize } from './types';
8
+ import { PanelProps } from './types/PanelProps';
9
+ import { useRestoreStateFrom, useSaveStateIn } from './usePanelStateHandler';
9
10
 
10
11
  export function PopinWindow({
11
12
  children,
@@ -16,7 +17,7 @@ export function PopinWindow({
16
17
  minWidth,
17
18
  modal,
18
19
  nextStackPosition,
19
- position = modal ? "center" : "tile",
20
+ position = modal ? 'center' : 'tile',
20
21
  resizeable = modal !== true,
21
22
  size = { height: 200, width: 320 },
22
23
  }: PanelProps & { nextStackPosition: () => PanelPosition }): JSX.Element {
@@ -32,12 +33,12 @@ export function PopinWindow({
32
33
  }
33
34
 
34
35
  switch (position) {
35
- case "center":
36
+ case 'center':
36
37
  return {
37
38
  x: Math.max((window.innerWidth - size.width) / 2, 0),
38
39
  y: Math.max((window.innerHeight - size.height) / 2, 0),
39
40
  };
40
- case "tile":
41
+ case 'tile':
41
42
  return nextStackPosition();
42
43
  default:
43
44
  return position ?? nextStackPosition();
@@ -61,11 +62,11 @@ export function PopinWindow({
61
62
  }, [size]);
62
63
 
63
64
  useEffect(() => {
64
- if (position === "center" && !resizeable) {
65
+ if (position === 'center' && !resizeable) {
65
66
  centerWindow();
66
67
 
67
- window.addEventListener("resize", centerWindow);
68
- return () => window.removeEventListener("resize", centerWindow);
68
+ window.addEventListener('resize', centerWindow);
69
+ return () => window.removeEventListener('resize', centerWindow);
69
70
  }
70
71
  return;
71
72
  }, [centerWindow, position, resizeable]);
@@ -91,20 +92,20 @@ export function PopinWindow({
91
92
  {modal && (
92
93
  <div
93
94
  style={{
94
- position: "absolute",
95
+ position: 'absolute',
95
96
  top: 0,
96
97
  left: 0,
97
98
  bottom: 0,
98
99
  right: 0,
99
- backgroundColor: "rgb(0,0,0,0.1)",
100
+ backgroundColor: 'rgb(0,0,0,0.1)',
100
101
  zIndex,
101
102
  }}
102
103
  />
103
104
  )}
104
105
  <Rnd
105
106
  ref={panelRef}
106
- className={clsx("WindowPanel", className)}
107
- dragHandleClassName={"draggable-handle"}
107
+ className={clsx('WindowPanel', className)}
108
+ dragHandleClassName={'draggable-handle'}
108
109
  maxHeight={maxHeight}
109
110
  maxWidth={maxWidth}
110
111
  minWidth={minWidth}
@@ -129,10 +130,10 @@ export function PopinWindow({
129
130
  >
130
131
  <div
131
132
  style={{
132
- display: "flex",
133
- flexDirection: "column",
134
- width: "100%",
135
- height: "100%",
133
+ display: 'flex',
134
+ flexDirection: 'column',
135
+ width: '100%',
136
+ height: '100%',
136
137
  }}
137
138
  >
138
139
  {children}