@linzjs/windows 5.6.0 → 6.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.
package/README.md CHANGED
@@ -15,7 +15,11 @@ based boilerplate / inline-components.
15
15
 
16
16
  So you can simply do this in your react-app:
17
17
  ```
18
- const result = await showModal(TestModal)
18
+ const result = await showModal(TestModal, { props... })
19
+
20
+ <button onClick={() => openPanel({ componentFn: () => <Panel.../>, onClose=onClose)}>
21
+ Open panel
22
+ </button>
19
23
  ```
20
24
 
21
25
  ## Features
@@ -4,10 +4,18 @@ import '@linzjs/lui/dist/scss/base.scss';
4
4
 
5
5
  import clsx from 'clsx';
6
6
  import { NumberSize } from 're-resizable';
7
- import { PropsWithChildren, ReactElement, useCallback, useContext, useEffect, useRef, useState } from 'react';
7
+ import {
8
+ forwardRef,
9
+ PropsWithChildren,
10
+ ReactElement,
11
+ useCallback,
12
+ useContext,
13
+ useEffect,
14
+ useRef,
15
+ useState,
16
+ } from 'react';
8
17
  import { createPortal } from 'react-dom';
9
18
 
10
- import { useConstFunction } from '../common';
11
19
  import { PanelInstanceContext } from './PanelInstanceContext';
12
20
  import { PanelsContext } from './PanelsContext';
13
21
  import { PopinWindow } from './PopinWIndow';
@@ -16,26 +24,16 @@ import { PanelProps } from './types/PanelProps';
16
24
  import { useRestoreStateFrom } from './usePanelStateHandler';
17
25
 
18
26
  const defaultInitialSize = { width: 320, height: 200 };
19
- const nullOpFunction = () => {};
20
27
 
21
28
  export const Panel = (props: PanelProps): ReactElement => {
22
29
  const panelRef = useRef<HTMLDivElement>(null);
23
- const { title, size = defaultInitialSize, className, children, onClose } = props;
30
+ const { title, size = defaultInitialSize, className, children } = props;
24
31
 
25
32
  const { dockElements, nextStackPosition } = useContext(PanelsContext);
26
33
  const { panelPoppedOut, uniqueId, setTitle, dockId, docked } = useContext(PanelInstanceContext);
27
34
 
28
35
  const savedState = useRestoreStateFrom({ uniqueId, panelPoppedOut: false });
29
36
 
30
- // The function has to be const as the panel must no re-render as that would cause popout windows to close
31
- const onCloseConstFn = useConstFunction(onClose ?? nullOpFunction);
32
-
33
- useEffect(() => {
34
- return () => {
35
- onCloseConstFn?.();
36
- };
37
- }, [onCloseConstFn]);
38
-
39
37
  useEffect(() => {
40
38
  setTitle(title);
41
39
  }, [setTitle, title]);
@@ -136,6 +134,13 @@ export interface PanelContentProps {
136
134
  className?: string | undefined;
137
135
  }
138
136
 
139
- export const PanelContent = ({ children, className }: PropsWithChildren<PanelContentProps>) => (
140
- <div className={clsx(`WindowPanel-content`, className)}>{children}</div>
141
- );
137
+ export const PanelContent = forwardRef<HTMLDivElement, PropsWithChildren<PanelContentProps>>(function PanelContentFr(
138
+ { children, className },
139
+ ref,
140
+ ) {
141
+ return (
142
+ <div className={clsx(`WindowPanel-content`, className)} ref={ref}>
143
+ {children}
144
+ </div>
145
+ );
146
+ });
@@ -9,12 +9,14 @@ export interface PanelInstance {
9
9
  zIndex: number;
10
10
  poppedOut: boolean;
11
11
  window: Window | null;
12
+ onClose?: () => void;
12
13
  }
13
14
 
14
15
  export interface OpenPanelOptions {
15
16
  uniqueId?: string;
16
17
  componentFn: () => ReactElement;
17
18
  poppedOut?: boolean;
19
+ onClose?: () => void;
18
20
  }
19
21
 
20
22
  export interface PanelsContextType {
@@ -1,4 +1,4 @@
1
- import { castArray, maxBy, sortBy } from 'lodash-es';
1
+ import { castArray, isEmpty, maxBy, partition, sortBy } from 'lodash-es';
2
2
  import React, { Fragment, PropsWithChildren, ReactElement, useCallback, useMemo, useRef, useState } from 'react';
3
3
  import { useInterval } from 'usehooks-ts';
4
4
  import { v4 } from 'uuid';
@@ -67,7 +67,7 @@ export const PanelsContextProvider = ({
67
67
  );
68
68
 
69
69
  const openPanel = useCallback(
70
- ({ componentFn, poppedOut = false, uniqueId = v4() }: OpenPanelOptions): void => {
70
+ ({ componentFn, poppedOut = false, uniqueId = v4(), onClose }: OpenPanelOptions): void => {
71
71
  try {
72
72
  const existingPanelInstance = panelInstances.find((pi) => pi.uniqueId === uniqueId);
73
73
  if (existingPanelInstance) {
@@ -88,6 +88,7 @@ export const PanelsContextProvider = ({
88
88
  zIndex: baseZIndex + panelInstances.length,
89
89
  poppedOut,
90
90
  window: null,
91
+ onClose,
91
92
  },
92
93
  ]);
93
94
  } catch (e) {
@@ -98,10 +99,17 @@ export const PanelsContextProvider = ({
98
99
  );
99
100
 
100
101
  const closePanel = useCallback(
101
- (panelInstance: PanelInstance | PanelInstance[]) => {
102
- const panelNames = castArray(panelInstance).map((pi) => pi.uniqueId);
103
- const newPanelInstances = panelInstances.filter((pi) => !panelNames.includes(pi.uniqueId));
104
- if (panelInstances.length !== newPanelInstances.length) setPanelInstances(newPanelInstances);
102
+ (closePanelInstance: PanelInstance | PanelInstance[]) => {
103
+ const panelNames = castArray(closePanelInstance).map((pi) => pi.uniqueId);
104
+ const [closedPanelInstances, stillOpenPanelInstances] = partition(panelInstances, (pi) =>
105
+ panelNames.includes(pi.uniqueId),
106
+ );
107
+ if (!isEmpty(closedPanelInstances)) {
108
+ closedPanelInstances.forEach(({ onClose }) => {
109
+ onClose?.();
110
+ });
111
+ setPanelInstances(stillOpenPanelInstances);
112
+ }
105
113
  },
106
114
  [panelInstances],
107
115
  );
@@ -11,7 +11,6 @@ export interface PanelProps {
11
11
  minHeight?: number | string;
12
12
  minWidth?: number | string;
13
13
  modal?: boolean;
14
- onClose?: () => void;
15
14
  position?: PanelPosition | 'tile' | 'center';
16
15
  resizeable?: boolean;
17
16
  size?: PanelSize;
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "popout"
14
14
  ],
15
15
  "main": "./dist/index.ts",
16
- "version": "5.6.0",
16
+ "version": "6.0.0",
17
17
  "peerDependencies": {
18
18
  "@linzjs/lui": ">=21",
19
19
  "lodash-es": ">=4",
@@ -52,65 +52,65 @@
52
52
  "@emotion/cache": "^11.14.0",
53
53
  "@emotion/react": "^11.14.0",
54
54
  "@emotion/styled": "11.14.1",
55
- "@types/uuid": "^10.0.0",
55
+ "@types/uuid": "^11.0.0",
56
56
  "lodash-es": ">=4",
57
57
  "react-rnd": "^10.5.2",
58
58
  "usehooks-ts": "^3.1.1",
59
- "uuid": "^11.1.0"
59
+ "uuid": "^13.0.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@chromatic-com/storybook": "^4.1.1",
63
- "@linzjs/lui": "^23.11.1",
63
+ "@linzjs/lui": "^23.14.2",
64
64
  "@linzjs/step-ag-grid": "^28.5.1",
65
65
  "@linzjs/style": "^5.4.0",
66
- "@rollup/plugin-commonjs": "^28.0.6",
66
+ "@rollup/plugin-commonjs": "^28.0.8",
67
67
  "@rollup/plugin-json": "^6.1.0",
68
- "@rollup/plugin-node-resolve": "^16.0.1",
69
- "@storybook/addon-docs": "^9.1.4",
70
- "@storybook/addon-links": "^9.1.4",
71
- "@storybook/react-vite": "^9.1.4",
68
+ "@rollup/plugin-node-resolve": "^16.0.3",
69
+ "@storybook/addon-docs": "^9.1.13",
70
+ "@storybook/addon-links": "^9.1.13",
71
+ "@storybook/react-vite": "^9.1.13",
72
72
  "@testing-library/dom": "^10.4.1",
73
73
  "@testing-library/react": "^16.3.0",
74
74
  "@testing-library/user-event": "^14.6.1",
75
75
  "@types/lodash-es": "^4.17.12",
76
- "@types/node": "^22.15.34",
77
- "@types/react": "^18.3.23",
76
+ "@types/node": "^22.18.11",
77
+ "@types/react": "^18.3.26",
78
78
  "@types/react-dom": "^18.3.7",
79
79
  "@vitejs/plugin-react-swc": "^3.10.2",
80
80
  "@vitest/ui": "^3.2.4",
81
- "ag-grid-community": "^34.1.2",
82
- "ag-grid-react": "^34.1.2",
81
+ "ag-grid-community": "^34.2.0",
82
+ "ag-grid-react": "^34.2.0",
83
83
  "babel-preset-react-app": "^10.1.0",
84
84
  "eslint-plugin-react": "^7.37.5",
85
- "eslint-plugin-storybook": "9.1.4",
85
+ "eslint-plugin-storybook": "9.1.13",
86
86
  "jsdom": "^26.1.0",
87
87
  "mkdirp": "^3.0.1",
88
88
  "npm-run-all": "^4.1.5",
89
89
  "react": "^18.3.1",
90
90
  "react-app-polyfill": "^3.0.0",
91
91
  "react-dom": "^18.3.1",
92
- "rollup": "^4.50.0",
92
+ "rollup": "^4.52.5",
93
93
  "rollup-plugin-copy": "^3.5.0",
94
- "sass": "^1.92.0",
94
+ "sass": "^1.93.2",
95
95
  "sass-loader": "^16.0.5",
96
- "semantic-release": "^24.2.7",
97
- "storybook": "^9.1.4",
96
+ "semantic-release": "^24.2.9",
97
+ "storybook": "^9.1.13",
98
98
  "style-loader": "^4.0.0",
99
- "stylelint": "^16.23.1",
99
+ "stylelint": "^16.25.0",
100
100
  "stylelint-config-recommended": "^15.0.0",
101
101
  "stylelint-config-recommended-scss": "^14.1.0",
102
102
  "stylelint-config-standard": "^38.0.0",
103
103
  "stylelint-prettier": "5.0.3",
104
104
  "stylelint-scss": "6.12.1",
105
- "typescript": "^5.9.2",
106
- "vite": "^6.3.5",
105
+ "typescript": "^5.9.3",
106
+ "vite": "^7.1.11",
107
107
  "vite-plugin-html": "^3.2.2",
108
108
  "vite-tsconfig-paths": "^5.1.4",
109
109
  "vitest": "^3.2.4"
110
110
  },
111
111
  "optionalDependencies": {
112
- "@rollup/rollup-linux-x64-gnu": "^4.50.0",
113
- "@swc/core-linux-x64-gnu": "^1.13.5"
112
+ "@rollup/rollup-linux-x64-gnu": "^4.52.5",
113
+ "@swc/core-linux-x64-gnu": "^1.13.20"
114
114
  },
115
115
  "browserslist": {
116
116
  "production": [