@plesk/ui-library 3.39.0 → 3.40.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.
Files changed (80) hide show
  1. package/cjs/components/Button/Button.js +4 -22
  2. package/cjs/components/Card/CardButton.js +2 -3
  3. package/cjs/components/CardList/CardListToolbar.js +3 -8
  4. package/cjs/components/Dialog/Dialog.js +5 -27
  5. package/cjs/components/Drawer/Drawer.js +7 -20
  6. package/cjs/components/Dropdown/Dropdown.js +3 -11
  7. package/cjs/components/FormField/FormField.js +13 -26
  8. package/cjs/components/List/List.js +1 -14
  9. package/cjs/components/Progress/Progress.js +6 -5
  10. package/cjs/components/ProgressStep/ProgressStep.js +5 -14
  11. package/cjs/components/ProgressStep/index.js +6 -0
  12. package/cjs/components/Section/Section.js +11 -19
  13. package/cjs/components/TextArea/TextArea.js +49 -97
  14. package/cjs/components/TextArea/calculateNodeHeight.js +8 -8
  15. package/cjs/components/Toolbar/RegistryContextBeta.js +112 -0
  16. package/cjs/components/Toolbar/Toolbar.js +46 -2
  17. package/cjs/components/Toolbar/ToolbarBetaProvider.js +23 -0
  18. package/cjs/components/Toolbar/ToolbarGroup.js +66 -4
  19. package/cjs/components/Toolbar/ToolbarItem.js +27 -12
  20. package/cjs/components/Toolbar/ToolbarMenu.js +2 -1
  21. package/cjs/components/Toolbar/index.js +8 -1
  22. package/cjs/components/index.js +15 -1
  23. package/cjs/hooks/index.js +12 -0
  24. package/cjs/hooks/useResizeObserver.js +29 -0
  25. package/cjs/hooks/useSqueeze.js +48 -0
  26. package/cjs/index.js +1 -1
  27. package/dist/plesk-ui-library.js +586 -303
  28. package/dist/plesk-ui-library.js.map +1 -1
  29. package/dist/plesk-ui-library.min.js +6 -6
  30. package/dist/plesk-ui-library.min.js.map +1 -1
  31. package/esm/components/Button/Button.js +3 -21
  32. package/esm/components/Card/CardButton.js +2 -3
  33. package/esm/components/CardList/CardListToolbar.js +3 -8
  34. package/esm/components/Dialog/Dialog.js +5 -27
  35. package/esm/components/Drawer/Drawer.js +7 -20
  36. package/esm/components/Dropdown/Dropdown.js +3 -11
  37. package/esm/components/FormField/FormField.js +13 -26
  38. package/esm/components/List/List.js +1 -14
  39. package/esm/components/Progress/Progress.js +7 -6
  40. package/esm/components/ProgressStep/ProgressStep.js +4 -13
  41. package/esm/components/ProgressStep/index.js +1 -1
  42. package/esm/components/Section/Section.js +11 -19
  43. package/esm/components/TextArea/TextArea.js +50 -98
  44. package/esm/components/TextArea/calculateNodeHeight.js +8 -8
  45. package/esm/components/Toolbar/RegistryContextBeta.js +103 -0
  46. package/esm/components/Toolbar/Toolbar.js +47 -3
  47. package/esm/components/Toolbar/ToolbarBetaProvider.js +16 -0
  48. package/esm/components/Toolbar/ToolbarGroup.js +67 -5
  49. package/esm/components/Toolbar/ToolbarItem.js +27 -12
  50. package/esm/components/Toolbar/ToolbarMenu.js +2 -1
  51. package/esm/components/Toolbar/index.js +2 -1
  52. package/esm/components/index.js +2 -2
  53. package/esm/hooks/index.js +3 -0
  54. package/esm/hooks/useResizeObserver.js +22 -0
  55. package/esm/hooks/useSqueeze.js +41 -0
  56. package/esm/index.js +1 -1
  57. package/package.json +10 -10
  58. package/styleguide/build/bundle.505bc865.js +2 -0
  59. package/styleguide/index.html +2 -2
  60. package/types/src/components/Button/Button.d.ts +1 -0
  61. package/types/src/components/Dialog/Dialog.d.ts +1 -25
  62. package/types/src/components/Drawer/Drawer.d.ts +2 -5
  63. package/types/src/components/FormField/FormField.d.ts +1 -23
  64. package/types/src/components/ProgressStep/ProgressStep.d.ts +2 -13
  65. package/types/src/components/ProgressStep/index.d.ts +1 -1
  66. package/types/src/components/Section/Section.d.ts +2 -32
  67. package/types/src/components/TextArea/TextArea.d.ts +5 -32
  68. package/types/src/components/TextArea/calculateNodeHeight.d.ts +2 -6
  69. package/types/src/components/Toolbar/RegistryContextBeta.d.ts +25 -0
  70. package/types/src/components/Toolbar/Toolbar.d.ts +2 -22
  71. package/types/src/components/Toolbar/ToolbarBetaProvider.d.ts +5 -0
  72. package/types/src/components/Toolbar/ToolbarGroup.d.ts +2 -5
  73. package/types/src/components/Toolbar/ToolbarItem.d.ts +1 -1
  74. package/types/src/components/Toolbar/index.d.ts +1 -0
  75. package/types/src/components/index.d.ts +2 -2
  76. package/types/src/hooks/index.d.ts +1 -0
  77. package/types/src/hooks/useResizeObserver.d.ts +7 -0
  78. package/types/src/hooks/useSqueeze.d.ts +10 -0
  79. package/styleguide/build/bundle.c34e3753.js +0 -2
  80. /package/styleguide/build/{bundle.c34e3753.js.LICENSE.txt → bundle.505bc865.js.LICENSE.txt} +0 -0
@@ -0,0 +1,103 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ // Copyright 1999-2023. Plesk International GmbH. All rights reserved.
3
+
4
+ import { createContext, useContext, useState, useLayoutEffect } from 'react';
5
+ const RegistryContext = /*#__PURE__*/createContext(undefined);
6
+ RegistryContext.displayName = 'RegistryContext';
7
+ const useRegistryContext = () => useContext(RegistryContext);
8
+ export default RegistryContext;
9
+ class Registry {
10
+ constructor() {
11
+ _defineProperty(this, "items", []);
12
+ }
13
+ register(item) {
14
+ this.items.push(item);
15
+ }
16
+ unregister(item) {
17
+ this.items = this.items.filter(i => i !== item);
18
+ }
19
+ compact() {
20
+ let changed = false;
21
+ for (const item of [...this.items].reverse()) {
22
+ if (!item.isCompact) {
23
+ item.compact();
24
+ changed = true;
25
+ break;
26
+ }
27
+ }
28
+ return changed;
29
+ }
30
+ expand() {
31
+ let changed = false;
32
+ for (const item of this.items) {
33
+ if (this.checkItemIsCompactOrHasCompactItems(item)) {
34
+ item.expand();
35
+ changed = true;
36
+ break;
37
+ }
38
+ }
39
+ return changed;
40
+ }
41
+ get isCompact() {
42
+ return this.items.every(_ref => {
43
+ let {
44
+ isCompact
45
+ } = _ref;
46
+ return isCompact;
47
+ });
48
+ }
49
+ get hasCompactItems() {
50
+ return this.items.some(this.checkItemIsCompactOrHasCompactItems);
51
+ }
52
+ checkItemIsCompactOrHasCompactItems(item) {
53
+ return item.isCompact || 'hasCompactItems' in item && item.hasCompactItems;
54
+ }
55
+ }
56
+ class RegistryItem {
57
+ constructor(_ref2) {
58
+ let {
59
+ onCompactStateChange
60
+ } = _ref2;
61
+ _defineProperty(this, "_isCompact", false);
62
+ _defineProperty(this, "onCompactStateChange", void 0);
63
+ this.onCompactStateChange = onCompactStateChange;
64
+ }
65
+ compact() {
66
+ this._isCompact = true;
67
+ this.onCompactStateChange(true);
68
+ }
69
+ expand() {
70
+ this._isCompact = false;
71
+ this.onCompactStateChange(false);
72
+ }
73
+ get isCompact() {
74
+ return this._isCompact;
75
+ }
76
+ }
77
+ export const useRegistry = () => {
78
+ const parentRegistry = useRegistryContext();
79
+ const [registry] = useState(() => new Registry());
80
+ useLayoutEffect(() => {
81
+ if (!parentRegistry) return undefined;
82
+ parentRegistry.register(registry);
83
+ return () => {
84
+ parentRegistry.unregister(registry);
85
+ };
86
+ }, [parentRegistry, registry]);
87
+ return registry;
88
+ };
89
+ export const useRegistryItem = () => {
90
+ const registry = useRegistryContext();
91
+ const [isCompact, setIsCompact] = useState(false);
92
+ const [registryItem] = useState(() => new RegistryItem({
93
+ onCompactStateChange: setIsCompact
94
+ }));
95
+ useLayoutEffect(() => {
96
+ if (!registry) return undefined;
97
+ registry.register(registryItem);
98
+ return () => {
99
+ registry.unregister(registryItem);
100
+ };
101
+ }, [registry, registryItem]);
102
+ return [isCompact];
103
+ };
@@ -1,13 +1,16 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  // Copyright 1999-2023. Plesk International GmbH. All rights reserved.
3
3
 
4
- import { Component } from 'react';
4
+ import { Component, useRef, useState, useMemo } from 'react';
5
5
  import classNames from 'classnames';
6
6
  import { CLS_PREFIX } from '../../constants';
7
7
  import RegistryContext, { createRegistry } from './RegistryContext';
8
+ import RegistryContextBeta, { useRegistry } from './RegistryContextBeta';
8
9
  import DistractionFreeModeContext from '../DistractionFreeModeContext';
9
10
  import { toToolbarItems } from './ToolbarItem';
10
11
  import Squeezer from '../Squeezer';
12
+ import { useSqueeze } from '../../hooks';
13
+ import { useToolbarBetaContext } from './ToolbarBetaProvider';
11
14
 
12
15
  /**
13
16
  * `Toolbar` component is a panel containing various instruments used for managing the contents of a large content block.
@@ -17,7 +20,7 @@ import Squeezer from '../Squeezer';
17
20
  * @since 0.0.57
18
21
  */
19
22
  import { jsx as _jsx } from "react/jsx-runtime";
20
- class Toolbar extends Component {
23
+ class ToolbarClassComponent extends Component {
21
24
  constructor(props) {
22
25
  super(props);
23
26
  _defineProperty(this, "state", {
@@ -74,9 +77,50 @@ class Toolbar extends Component {
74
77
  });
75
78
  }
76
79
  }
77
- _defineProperty(Toolbar, "defaultProps", {
80
+ _defineProperty(ToolbarClassComponent, "defaultProps", {
78
81
  children: null,
79
82
  className: null,
80
83
  baseClassName: `${CLS_PREFIX}toolbar`
81
84
  });
85
+ const ToolbarBeta = _ref2 => {
86
+ let {
87
+ children,
88
+ className,
89
+ baseClassName = `${CLS_PREFIX}toolbar`,
90
+ ...props
91
+ } = _ref2;
92
+ const containerRef = useRef(null);
93
+ const [isDistractionFreeModeEnabled, setIsDistractionFreeModeEnabled] = useState(false);
94
+ const distractionFreeModeContextValue = useMemo(() => ({
95
+ enabled: isDistractionFreeModeEnabled,
96
+ toggle: () => setIsDistractionFreeModeEnabled(current => !current)
97
+ }), [isDistractionFreeModeEnabled]);
98
+ const registry = useRegistry();
99
+ useSqueeze({
100
+ ref: containerRef,
101
+ compact: () => registry.compact(),
102
+ expand: () => registry.expand()
103
+ });
104
+ const toolbarItems = toToolbarItems(children, true);
105
+ return /*#__PURE__*/_jsx("div", {
106
+ ref: containerRef,
107
+ className: classNames(baseClassName, className),
108
+ ...props,
109
+ children: /*#__PURE__*/_jsx(RegistryContextBeta.Provider, {
110
+ value: registry,
111
+ children: /*#__PURE__*/_jsx(DistractionFreeModeContext.Provider, {
112
+ value: distractionFreeModeContextValue,
113
+ children: toolbarItems
114
+ })
115
+ })
116
+ });
117
+ };
118
+ const Toolbar = props => {
119
+ const isToolbarBeta = useToolbarBetaContext();
120
+ return isToolbarBeta ? /*#__PURE__*/_jsx(ToolbarBeta, {
121
+ ...props
122
+ }) : /*#__PURE__*/_jsx(ToolbarClassComponent, {
123
+ ...props
124
+ });
125
+ };
82
126
  export default Toolbar;
@@ -0,0 +1,16 @@
1
+ // Copyright 1999-2024. Plesk International GmbH. All rights reserved.
2
+
3
+ import { createContext, useContext } from 'react';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ const ToolbarBetaContext = /*#__PURE__*/createContext(false);
6
+ export const useToolbarBetaContext = () => useContext(ToolbarBetaContext);
7
+ const ToolbarBetaProvider = _ref => {
8
+ let {
9
+ children
10
+ } = _ref;
11
+ return /*#__PURE__*/_jsx(ToolbarBetaContext.Provider, {
12
+ value: true,
13
+ children: children
14
+ });
15
+ };
16
+ export default ToolbarBetaProvider;
@@ -1,15 +1,17 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  // Copyright 1999-2023. Plesk International GmbH. All rights reserved.
3
3
 
4
- import { Component, Children, useContext, isValidElement } from 'react';
4
+ import { Component, Children, useContext, isValidElement, useState } from 'react';
5
5
  import classNames from 'classnames';
6
6
  import { CLS_PREFIX } from '../../constants';
7
7
  import Dropdown from '../Dropdown';
8
8
  import ToolbarMenu from './ToolbarMenu';
9
9
  import RegistryContext, { createRegistry } from './RegistryContext';
10
+ import RegistryContextBeta, { useRegistry, useRegistryItem } from './RegistryContextBeta';
10
11
  import DistractionFreeModeContext from '../DistractionFreeModeContext';
11
12
  import { toToolbarItems } from './ToolbarItem';
12
13
  import ToolbarExpander from './ToolbarExpander';
14
+ import { useToolbarBetaContext } from './ToolbarBetaProvider';
13
15
 
14
16
  /**
15
17
  * `ToolbarGroup` is a part of [Toolbar](#!/Toolbar) component.
@@ -17,7 +19,7 @@ import ToolbarExpander from './ToolbarExpander';
17
19
  * @since 0.0.57
18
20
  */
19
21
  import { jsx as _jsx } from "react/jsx-runtime";
20
- class ToolbarGroup extends Component {
22
+ class ToolbarGroupClassComponent extends Component {
21
23
  constructor(props) {
22
24
  super(props);
23
25
  _defineProperty(this, "state", {
@@ -137,7 +139,7 @@ class ToolbarGroup extends Component {
137
139
  });
138
140
  }
139
141
  }
140
- _defineProperty(ToolbarGroup, "defaultProps", {
142
+ _defineProperty(ToolbarGroupClassComponent, "defaultProps", {
141
143
  registry: undefined,
142
144
  distractionFreeMode: undefined
143
145
  });
@@ -149,7 +151,7 @@ const ToolbarGroupWrapper = _ref => {
149
151
  } = _ref;
150
152
  const registry = useContext(RegistryContext);
151
153
  const distractionFreeMode = useContext(DistractionFreeModeContext);
152
- return /*#__PURE__*/_jsx(ToolbarGroup, {
154
+ return /*#__PURE__*/_jsx(ToolbarGroupClassComponent, {
153
155
  groupable: groupable,
154
156
  baseClassName: baseClassName,
155
157
  ...props,
@@ -158,4 +160,64 @@ const ToolbarGroupWrapper = _ref => {
158
160
  });
159
161
  };
160
162
  ToolbarGroupWrapper.displayName = 'ToolbarGroup';
161
- export default ToolbarGroupWrapper;
163
+ const ToolbarGroupBeta = _ref2 => {
164
+ let {
165
+ baseClassName = `${CLS_PREFIX}toolbar__group`,
166
+ className,
167
+ title,
168
+ children,
169
+ groupable = true,
170
+ ...props
171
+ } = _ref2;
172
+ const [compact] = useRegistryItem();
173
+ const registry = useRegistry();
174
+ const [availableInDistractionFreeMode, setAvailableInDistractionFreeMode] = useState(false);
175
+ const distractionFreeMode = useContext(DistractionFreeModeContext);
176
+ const distractionFreeModeContextValue = {
177
+ enabled: distractionFreeMode?.enabled ?? false,
178
+ toggle: () => {
179
+ if (distractionFreeMode) {
180
+ distractionFreeMode.toggle();
181
+ setAvailableInDistractionFreeMode(current => !current);
182
+ }
183
+ }
184
+ };
185
+ let hasExpander = Children.toArray(children).some(child => /*#__PURE__*/isValidElement(child) && child.type === ToolbarExpander);
186
+ if (groupable && compact && Children.count(children) > 1) {
187
+ hasExpander = false;
188
+ children = /*#__PURE__*/_jsx(Dropdown, {
189
+ menu: /*#__PURE__*/_jsx(ToolbarMenu, {
190
+ onItemClick: () => {},
191
+ children: children
192
+ }),
193
+ children: title
194
+ });
195
+ } else {
196
+ children = /*#__PURE__*/_jsx(RegistryContextBeta.Provider, {
197
+ value: registry,
198
+ children: /*#__PURE__*/_jsx(DistractionFreeModeContext.Provider, {
199
+ value: distractionFreeModeContextValue,
200
+ children: toToolbarItems(children, true)
201
+ })
202
+ });
203
+ }
204
+ if (distractionFreeModeContextValue.enabled && !availableInDistractionFreeMode) {
205
+ return null;
206
+ }
207
+ return /*#__PURE__*/_jsx("div", {
208
+ className: classNames(baseClassName, className, {
209
+ [`${baseClassName}--grow`]: hasExpander || distractionFreeModeContextValue.enabled && availableInDistractionFreeMode
210
+ }),
211
+ ...props,
212
+ children: children
213
+ });
214
+ };
215
+ const ToolbarGroup = props => {
216
+ const isToolbarBeta = useToolbarBetaContext();
217
+ return isToolbarBeta ? /*#__PURE__*/_jsx(ToolbarGroupBeta, {
218
+ ...props
219
+ }) : /*#__PURE__*/_jsx(ToolbarGroupWrapper, {
220
+ ...props
221
+ });
222
+ };
223
+ export default ToolbarGroup;
@@ -8,6 +8,7 @@ import ResponsiveContext from '../ResponsiveContext';
8
8
  import RegistryContext from './RegistryContext';
9
9
  import ToolbarGroup from './ToolbarGroup';
10
10
  import ToolbarExpander from './ToolbarExpander';
11
+ import { useRegistryItem } from './RegistryContextBeta';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  class ToolbarItem extends Component {
13
14
  constructor() {
@@ -47,16 +48,30 @@ class ToolbarItem extends Component {
47
48
  }
48
49
  }
49
50
  ToolbarItem.contextType = RegistryContext;
50
- export const toToolbarItems = children => Children.map(children, child => {
51
- if (! /*#__PURE__*/isValidElement(child)) {
52
- return child;
53
- }
54
- if (child.type === ToolbarGroup || child.type === ToolbarExpander) {
55
- return child;
56
- }
57
- return /*#__PURE__*/_jsx(ToolbarItem, {
58
- children: /*#__PURE__*/cloneElement(child, {
59
- className: classNames(child.props.className, `${CLS_PREFIX}toolbar__group-item`)
60
- })
51
+ const ToolbarItemBeta = _ref => {
52
+ let {
53
+ children
54
+ } = _ref;
55
+ const [isCompact] = useRegistryItem();
56
+ return /*#__PURE__*/_jsx(ResponsiveContext.Provider, {
57
+ value: isCompact,
58
+ children: children
59
+ });
60
+ };
61
+ export const toToolbarItems = function (children) {
62
+ let isBeta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
63
+ return Children.map(children, child => {
64
+ if (! /*#__PURE__*/isValidElement(child)) {
65
+ return child;
66
+ }
67
+ if (child.type === ToolbarGroup || child.type === ToolbarExpander) {
68
+ return child;
69
+ }
70
+ const Component = isBeta ? ToolbarItemBeta : ToolbarItem;
71
+ return /*#__PURE__*/_jsx(Component, {
72
+ children: /*#__PURE__*/cloneElement(child, {
73
+ className: classNames(child.props.className, `${CLS_PREFIX}toolbar__group-item`)
74
+ })
75
+ });
61
76
  });
62
- });
77
+ };
@@ -8,6 +8,7 @@ import Button from '../Button';
8
8
  import Dropdown from '../Dropdown';
9
9
  import { ListOperation } from '../List';
10
10
  import { wrapFunction } from '../utils';
11
+ import { BUTTON_PROP_NAMES } from '../Button/Button';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  const toMenuItem = (child, isLast, onItemClick) => {
13
14
  switch (child.type) {
@@ -24,7 +25,7 @@ const toMenuItem = (child, isLast, onItemClick) => {
24
25
  } = child.props);
25
26
  props.onClick = wrapFunction(props.onClick, onItemClick);
26
27
  Object.keys(other).forEach(k => {
27
- if (!(Button.defaultProps && k in Button.defaultProps)) {
28
+ if (!BUTTON_PROP_NAMES.includes(k)) {
28
29
  props[k] = other[k];
29
30
  }
30
31
  });
@@ -2,4 +2,5 @@
2
2
 
3
3
  export { default } from './Toolbar';
4
4
  export { default as ToolbarGroup } from './ToolbarGroup';
5
- export { default as ToolbarExpander } from './ToolbarExpander';
5
+ export { default as ToolbarExpander } from './ToolbarExpander';
6
+ export { default as ToolbarBetaProvider } from './ToolbarBetaProvider';
@@ -69,7 +69,7 @@ export { default as Progress } from './Progress';
69
69
  export { default as ProgressBar } from './ProgressBar';
70
70
  export { default as ProgressDialog } from './ProgressDialog';
71
71
  export { default as ProgressDialogStep } from './ProgressDialogStep';
72
- export { default as ProgressStep } from './ProgressStep';
72
+ export { default as ProgressStep, PROGRESS_STEP_DEFAULT_STATUS } from './ProgressStep';
73
73
  export { default as Rating } from './Rating';
74
74
  export { default as Section } from './Section';
75
75
  export * from './Section';
@@ -86,7 +86,7 @@ export { default as SwitchesPanelItem } from './SwitchesPanelItem';
86
86
  export { default as Tabs, Tab, SearchBar } from './Tabs';
87
87
  export { default as Text } from './Text';
88
88
  export { default as Toaster } from './Toaster';
89
- export { default as Toolbar, ToolbarGroup, ToolbarExpander } from './Toolbar';
89
+ export { default as Toolbar, ToolbarGroup, ToolbarExpander, ToolbarBetaProvider } from './Toolbar';
90
90
  export { default as Tooltip } from './Tooltip';
91
91
  export { default as Tour } from './Tour';
92
92
  export { default as Translate } from './Translate';
@@ -0,0 +1,3 @@
1
+ // Copyright 1999-2024. Plesk International GmbH. All rights reserved.
2
+
3
+ export { useSqueeze } from './useSqueeze';
@@ -0,0 +1,22 @@
1
+ // Copyright 1999-2024. Plesk International GmbH. All rights reserved.
2
+
3
+ import { useEffect, useRef } from 'react';
4
+ export const useResizeObserver = _ref => {
5
+ let {
6
+ ref,
7
+ onResize
8
+ } = _ref;
9
+ const onResizeRef = useRef(undefined);
10
+ onResizeRef.current = onResize;
11
+ useEffect(() => {
12
+ if (!ref.current) return undefined;
13
+ if (typeof window === 'undefined' || !('ResizeObserver' in window)) return undefined;
14
+ const observer = new ResizeObserver(() => {
15
+ onResizeRef.current?.();
16
+ });
17
+ observer.observe(ref.current);
18
+ return () => {
19
+ observer.disconnect();
20
+ };
21
+ }, [ref]);
22
+ };
@@ -0,0 +1,41 @@
1
+ // Copyright 1999-2023. Plesk International GmbH. All rights reserved.
2
+
3
+ import { useRef, useLayoutEffect, useState } from 'react';
4
+ import { useResizeObserver } from './useResizeObserver';
5
+ export const useSqueeze = _ref => {
6
+ let {
7
+ ref,
8
+ compact,
9
+ expand
10
+ } = _ref;
11
+ const minWidth = useRef(0);
12
+ const lastAction = useRef(null);
13
+ const [recheck, setRecheck] = useState(false);
14
+ const checkRef = useRef();
15
+ const check = () => {
16
+ if (!ref.current) return;
17
+ const root = ref.current;
18
+ const width = Math.ceil(root.getBoundingClientRect().width);
19
+ const scrollWidth = Math.floor(root.scrollWidth);
20
+ let isCompactChanged = false;
21
+ if (scrollWidth > width) {
22
+ isCompactChanged = compact();
23
+ minWidth.current = scrollWidth;
24
+ lastAction.current = 'compact';
25
+ } else if (minWidth.current && width > minWidth.current || lastAction.current === 'expand') {
26
+ isCompactChanged = expand();
27
+ lastAction.current = 'expand';
28
+ }
29
+ if (isCompactChanged) {
30
+ setRecheck(c => !c);
31
+ }
32
+ };
33
+ checkRef.current = check;
34
+ useLayoutEffect(() => {
35
+ checkRef.current?.();
36
+ }, [recheck]);
37
+ useResizeObserver({
38
+ ref,
39
+ onResize: check
40
+ });
41
+ };
package/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Copyright 1999-2023. Plesk International GmbH. All rights reserved.
2
2
  import svg4everybody from 'svg4everybody';
3
- const version = "3.39.0";
3
+ const version = "3.40.1";
4
4
  export * from './publicPath';
5
5
  export { version };
6
6
  export * from './utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plesk/ui-library",
3
- "version": "3.39.0",
3
+ "version": "3.40.1",
4
4
  "description": "Plesk UI Library",
5
5
  "main": "index.js",
6
6
  "module": "esm/index.js",
@@ -43,7 +43,7 @@
43
43
  "/index.js"
44
44
  ],
45
45
  "dependencies": {
46
- "@babel/runtime": "^7.24.4",
46
+ "@babel/runtime": "^7.24.5",
47
47
  "@plesk/react-movable": "^2.7.1",
48
48
  "classnames": "^2.5.1",
49
49
  "codemirror": "5.58.2",
@@ -59,19 +59,19 @@
59
59
  "use-focus-visible": "^1.0.2"
60
60
  },
61
61
  "devDependencies": {
62
- "@babel/core": "^7.24.4",
62
+ "@babel/core": "^7.24.5",
63
63
  "@babel/plugin-proposal-class-properties": "^7.18.6",
64
64
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
65
65
  "@babel/plugin-transform-runtime": "^7.24.3",
66
- "@babel/preset-env": "^7.24.4",
66
+ "@babel/preset-env": "^7.24.5",
67
67
  "@babel/preset-react": "^7.24.1",
68
68
  "@babel/preset-typescript": "^7.24.1",
69
- "@babel/types": "^7.24.0",
69
+ "@babel/types": "^7.24.5",
70
70
  "@csstools/postcss-logical-float-and-clear": "^1.0.1",
71
71
  "@plesk/eslint-config": "^3.0.0",
72
72
  "@plesk/stylelint-config": "^2.0.0",
73
73
  "@testing-library/dom": "^9.3.4",
74
- "@testing-library/jest-dom": "^6.4.2",
74
+ "@testing-library/jest-dom": "^6.4.5",
75
75
  "@testing-library/react": "^14.3.1",
76
76
  "@testing-library/user-event": "^14.5.2",
77
77
  "@types/buble": "^0.20.5",
@@ -82,8 +82,8 @@
82
82
  "@types/jest-image-snapshot": "^6.4.0",
83
83
  "@types/marked": "^4.3.2",
84
84
  "@types/node": "^16.18.96",
85
- "@types/react": "^18.2.79",
86
- "@types/react-dom": "^18.2.25",
85
+ "@types/react": "^18.3.1",
86
+ "@types/react-dom": "^18.3.0",
87
87
  "@types/react-measure": "2.0.9",
88
88
  "@types/react-transition-group": "^4.4.10",
89
89
  "@types/svg4everybody": "2.1.2",
@@ -114,9 +114,9 @@
114
114
  "postcss-logical": "^6.2.0",
115
115
  "prettier": "^2.8.8",
116
116
  "puppeteer-core": "21.7.0",
117
- "react": "^18.2.0",
117
+ "react": "^18.3.1",
118
118
  "react-docgen-typescript": "^2.2.2",
119
- "react-dom": "^18.2.0",
119
+ "react-dom": "^18.3.1",
120
120
  "react-styleguidist": "^13.1.2",
121
121
  "rimraf": "^5.0.5",
122
122
  "rtlcss": "^4.1.1",