@linzjs/windows 7.1.1 → 7.2.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.
@@ -48,7 +48,7 @@ export const PanelInstanceContextProvider = ({
48
48
  panelClose: () => {
49
49
  panelInstance.window?.close();
50
50
  panelInstance.window = null;
51
- closePanel(panelInstance);
51
+ closePanel(panelInstance.uniqueId);
52
52
  },
53
53
  panelTogglePopout: togglePopOut,
54
54
  panelPoppedOut: poppedOut,
@@ -21,8 +21,9 @@ export interface OpenPanelOptions {
21
21
 
22
22
  export interface PanelsContextType {
23
23
  openPanels: Set<string>;
24
- openPanel: (args: OpenPanelOptions) => void;
25
- closePanel: (panelInstance: PanelInstance) => void;
24
+ // returns unique id of panel that was created/or arleady found, otherwise null on error.
25
+ openPanel: (args: OpenPanelOptions) => string | null;
26
+ closePanel: (uniqueId: string) => void;
26
27
  bringPanelToFront: (panelInstance: PanelInstance) => void;
27
28
  nextStackPosition: () => PanelPosition;
28
29
  dockElements: Record<string, HTMLDivElement>;
@@ -30,8 +31,9 @@ export interface PanelsContextType {
30
31
  panelStateOptions?: PanelStateOptions | null;
31
32
  }
32
33
 
33
- const NoContext = () => {
34
+ const NoContext = <T,>(): T => {
34
35
  console.error('Missing PanelContext Provider');
36
+ return undefined as T;
35
37
  };
36
38
 
37
39
  export const PanelsContext = createContext<PanelsContextType>({
@@ -67,7 +67,7 @@ export const PanelsContextProvider = ({
67
67
  );
68
68
 
69
69
  const openPanel = useCallback(
70
- ({ componentFn, poppedOut = false, uniqueId = v4(), onClose }: OpenPanelOptions): void => {
70
+ ({ componentFn, poppedOut = false, uniqueId = v4(), onClose }: OpenPanelOptions): string | null => {
71
71
  try {
72
72
  const existingPanelInstance = panelInstances.find((pi) => pi.uniqueId === uniqueId);
73
73
  if (existingPanelInstance) {
@@ -76,7 +76,7 @@ export const PanelsContextProvider = ({
76
76
  } else {
77
77
  bringPanelToFront(existingPanelInstance);
78
78
  }
79
- return;
79
+ return existingPanelInstance.uniqueId;
80
80
  }
81
81
 
82
82
  // If there are any exceptions the modal won't show
@@ -91,16 +91,18 @@ export const PanelsContextProvider = ({
91
91
  onClose,
92
92
  },
93
93
  ]);
94
+ return uniqueId;
94
95
  } catch (e) {
95
96
  console.error(e);
97
+ return null;
96
98
  }
97
99
  },
98
100
  [baseZIndex, bringPanelToFront, panelInstances],
99
101
  );
100
102
 
101
103
  const closePanel = useCallback(
102
- (closePanelInstance: PanelInstance | PanelInstance[]) => {
103
- const panelNames = castArray(closePanelInstance).map((pi) => pi.uniqueId);
104
+ (closePanelUniqueIds: string | string[]) => {
105
+ const panelNames = castArray(closePanelUniqueIds);
104
106
  const [closedPanelInstances, stillOpenPanelInstances] = partition(panelInstances, (pi) =>
105
107
  panelNames.includes(pi.uniqueId),
106
108
  );
@@ -120,7 +122,7 @@ export const PanelsContextProvider = ({
120
122
  */
121
123
  useInterval(() => {
122
124
  // close any panels that have a window that is closed
123
- closePanel(panelInstances.filter((pi) => pi.window?.closed));
125
+ closePanel(panelInstances.filter((pi) => pi.window?.closed).map((panel) => panel.uniqueId));
124
126
  }, 500);
125
127
 
126
128
  /**
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "popout"
14
14
  ],
15
15
  "main": "./dist/index.ts",
16
- "version": "7.1.1",
16
+ "version": "7.2.0",
17
17
  "peerDependencies": {
18
18
  "@linzjs/lui": ">=21",
19
19
  "lodash-es": ">=4",