@jetbrains/ring-ui 5.0.87 → 5.0.88

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.
@@ -23,7 +23,7 @@ export interface PositionAttrs {
23
23
  autoCorrectTopOverflow: boolean;
24
24
  }
25
25
  export declare const positionPropKeys: readonly ["directions", "autoPositioning", "autoCorrectTopOverflow", "sidePadding", "top", "left", "offset", "maxHeight", "minWidth"];
26
- export declare function maxHeightForDirection(direction: Directions, anchorNode: Element, containerNode?: Element | null): number | null;
26
+ export declare function maxHeightForDirection(direction: Directions, anchorNode: Element, containerNode?: Element | null): number;
27
27
  export default function position(attrs: PositionAttrs): {
28
28
  styles: PositionStyles;
29
29
  direction: Directions | null;
@@ -76,25 +76,6 @@ const defaultcontainerRect = {
76
76
  top: 0,
77
77
  left: 0
78
78
  };
79
- function handleTopOffScreen({ sidePadding, styles, anchorRect, maxHeight, popupScrollHeight, direction, scroll }) {
80
- const BORDER_COMPENSATION = 1;
81
- const { TOP_LEFT, TOP_RIGHT, TOP_CENTER, RIGHT_TOP, LEFT_TOP } = Directions;
82
- const openedToTop = direction != null && [TOP_LEFT, TOP_RIGHT, TOP_CENTER, RIGHT_TOP, LEFT_TOP].includes(direction);
83
- if (!openedToTop) {
84
- return styles;
85
- }
86
- const isAttachedToAnchorTop = direction != null && [TOP_LEFT, TOP_CENTER, TOP_RIGHT].includes(direction);
87
- const attachingPointY = (isAttachedToAnchorTop ? anchorRect.top : anchorRect.bottom);
88
- const effectiveHeight = maxHeight && typeof maxHeight === 'number'
89
- ? Math.min(popupScrollHeight, maxHeight)
90
- : popupScrollHeight;
91
- const hypotheticalTop = attachingPointY - effectiveHeight;
92
- if (hypotheticalTop <= sidePadding) {
93
- styles.top = sidePadding + scroll.top;
94
- styles.maxHeight = attachingPointY - sidePadding + BORDER_COMPENSATION;
95
- }
96
- return styles;
97
- }
98
79
  export function maxHeightForDirection(direction, anchorNode, containerNode) {
99
80
  const container = containerNode || document.documentElement;
100
81
  const domRect = anchorNode.getBoundingClientRect();
@@ -104,7 +85,7 @@ export function maxHeightForDirection(direction, anchorNode, containerNode) {
104
85
  // XXX
105
86
  // If container is the document element
106
87
  // then we check client height too because we may have situation when
107
- // "height" from "getBoundingClientRect" less then "clientHeight".
88
+ // "height" from "getBoundingClientRect" less than "clientHeight".
108
89
  container === document.documentElement ? container.clientHeight : 0);
109
90
  const bottomMaxHeight = Math.max(containerHeight - (topMaxHeight + domRect.height), 0);
110
91
  switch (direction) {
@@ -126,7 +107,8 @@ export function maxHeightForDirection(direction, anchorNode, containerNode) {
126
107
  case Directions.LEFT_CENTER:
127
108
  return (domRect.height / 2) + Math.min(bottomMaxHeight / 2, topMaxHeight / 2);
128
109
  default:
129
- return null;
110
+ const exhaustiveCheck = direction;
111
+ throw new Error(exhaustiveCheck);
130
112
  }
131
113
  }
132
114
  export default function position(attrs) {
@@ -178,16 +160,11 @@ export default function position(attrs) {
178
160
  else if (maxHeight) {
179
161
  styles.maxHeight = maxHeight;
180
162
  }
181
- if (autoCorrectTopOverflow) {
182
- styles = handleTopOffScreen({
183
- sidePadding,
184
- styles,
185
- anchorRect,
186
- maxHeight,
187
- direction: chosenDirection,
188
- popupScrollHeight: popup?.scrollHeight ?? 0,
189
- scroll
190
- });
163
+ if (autoCorrectTopOverflow && chosenDirection && anchor) {
164
+ styles.maxHeight = maxHeightForDirection(chosenDirection, anchor, container) - sidePadding;
165
+ if (styles.top === 0) {
166
+ styles.top = sidePadding;
167
+ }
191
168
  }
192
169
  if (minWidth === MinWidth.TARGET || minWidth === 'target') {
193
170
  styles.minWidth = anchorRect.width;
@@ -23,7 +23,7 @@ export interface PositionAttrs {
23
23
  autoCorrectTopOverflow: boolean;
24
24
  }
25
25
  export declare const positionPropKeys: readonly ["directions", "autoPositioning", "autoCorrectTopOverflow", "sidePadding", "top", "left", "offset", "maxHeight", "minWidth"];
26
- export declare function maxHeightForDirection(direction: Directions, anchorNode: Element, containerNode?: Element | null): number | null;
26
+ export declare function maxHeightForDirection(direction: Directions, anchorNode: Element, containerNode?: Element | null): number;
27
27
  export default function position(attrs: PositionAttrs): {
28
28
  styles: PositionStyles;
29
29
  direction: Directions | null;
@@ -101,38 +101,6 @@ const defaultcontainerRect = {
101
101
  top: 0,
102
102
  left: 0
103
103
  };
104
- function handleTopOffScreen(_ref) {
105
- let {
106
- sidePadding,
107
- styles,
108
- anchorRect,
109
- maxHeight,
110
- popupScrollHeight,
111
- direction,
112
- scroll
113
- } = _ref;
114
- const BORDER_COMPENSATION = 1;
115
- const {
116
- TOP_LEFT,
117
- TOP_RIGHT,
118
- TOP_CENTER,
119
- RIGHT_TOP,
120
- LEFT_TOP
121
- } = Directions;
122
- const openedToTop = direction != null && [TOP_LEFT, TOP_RIGHT, TOP_CENTER, RIGHT_TOP, LEFT_TOP].includes(direction);
123
- if (!openedToTop) {
124
- return styles;
125
- }
126
- const isAttachedToAnchorTop = direction != null && [TOP_LEFT, TOP_CENTER, TOP_RIGHT].includes(direction);
127
- const attachingPointY = isAttachedToAnchorTop ? anchorRect.top : anchorRect.bottom;
128
- const effectiveHeight = maxHeight && typeof maxHeight === 'number' ? Math.min(popupScrollHeight, maxHeight) : popupScrollHeight;
129
- const hypotheticalTop = attachingPointY - effectiveHeight;
130
- if (hypotheticalTop <= sidePadding) {
131
- styles.top = sidePadding + scroll.top;
132
- styles.maxHeight = attachingPointY - sidePadding + BORDER_COMPENSATION;
133
- }
134
- return styles;
135
- }
136
104
  function maxHeightForDirection(direction, anchorNode, containerNode) {
137
105
  const container = containerNode || document.documentElement;
138
106
  const domRect = anchorNode.getBoundingClientRect();
@@ -142,7 +110,7 @@ function maxHeightForDirection(direction, anchorNode, containerNode) {
142
110
  // XXX
143
111
  // If container is the document element
144
112
  // then we check client height too because we may have situation when
145
- // "height" from "getBoundingClientRect" less then "clientHeight".
113
+ // "height" from "getBoundingClientRect" less than "clientHeight".
146
114
  container === document.documentElement ? container.clientHeight : 0);
147
115
  const bottomMaxHeight = Math.max(containerHeight - (topMaxHeight + domRect.height), 0);
148
116
  switch (direction) {
@@ -164,7 +132,8 @@ function maxHeightForDirection(direction, anchorNode, containerNode) {
164
132
  case Directions.LEFT_CENTER:
165
133
  return domRect.height / 2 + Math.min(bottomMaxHeight / 2, topMaxHeight / 2);
166
134
  default:
167
- return null;
135
+ const exhaustiveCheck = direction;
136
+ throw new Error(exhaustiveCheck);
168
137
  }
169
138
  }
170
139
  function position(attrs) {
@@ -208,13 +177,13 @@ function position(attrs) {
208
177
  concat(directions[0]).filter(direction => directionsMatrix[direction]).map(direction => ({
209
178
  styles: directionsMatrix[direction],
210
179
  direction
211
- })).sort((_ref2, _ref3) => {
180
+ })).sort((_ref, _ref2) => {
212
181
  let {
213
182
  styles: stylesA
214
- } = _ref2;
183
+ } = _ref;
215
184
  let {
216
185
  styles: stylesB
217
- } = _ref3;
186
+ } = _ref2;
218
187
  const overflowA = verticalOverflow(stylesA, scroll, overflowAttrs) + horizontalOverflow(stylesA, scroll, overflowAttrs);
219
188
  const overflowB = verticalOverflow(stylesB, scroll, overflowAttrs) + horizontalOverflow(stylesB, scroll, overflowAttrs);
220
189
  return overflowA - overflowB;
@@ -235,17 +204,11 @@ function position(attrs) {
235
204
  } else if (maxHeight) {
236
205
  styles.maxHeight = maxHeight;
237
206
  }
238
- if (autoCorrectTopOverflow) {
239
- var _popup$scrollHeight;
240
- styles = handleTopOffScreen({
241
- sidePadding,
242
- styles,
243
- anchorRect,
244
- maxHeight,
245
- direction: chosenDirection,
246
- popupScrollHeight: (_popup$scrollHeight = popup?.scrollHeight) !== null && _popup$scrollHeight !== void 0 ? _popup$scrollHeight : 0,
247
- scroll
248
- });
207
+ if (autoCorrectTopOverflow && chosenDirection && anchor) {
208
+ styles.maxHeight = maxHeightForDirection(chosenDirection, anchor, container) - sidePadding;
209
+ if (styles.top === 0) {
210
+ styles.top = sidePadding;
211
+ }
249
212
  }
250
213
  if (minWidth === MinWidth.TARGET || minWidth === 'target') {
251
214
  styles.minWidth = anchorRect.width;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetbrains/ring-ui",
3
- "version": "5.0.87",
3
+ "version": "5.0.88",
4
4
  "description": "JetBrains UI library",
5
5
  "author": "JetBrains",
6
6
  "license": "Apache-2.0",
@@ -78,7 +78,7 @@
78
78
  "@babel/eslint-parser": "^7.19.1",
79
79
  "@jetbrains/eslint-config": "^5.4.1",
80
80
  "@jetbrains/stylelint-config": "^3.0.2",
81
- "@primer/octicons": "^17.10.0",
81
+ "@primer/octicons": "^17.10.1",
82
82
  "@rollup/plugin-babel": "^6.0.3",
83
83
  "@rollup/plugin-node-resolve": "^15.0.1",
84
84
  "@rollup/plugin-replace": "^5.0.2",
@@ -108,8 +108,8 @@
108
108
  "@types/react-dom": "^18.0.10",
109
109
  "@types/sinon": "^10.0.13",
110
110
  "@types/sinon-chai": "^3.2.9",
111
- "@typescript-eslint/eslint-plugin": "^5.47.1",
112
- "@typescript-eslint/parser": "^5.47.1",
111
+ "@typescript-eslint/eslint-plugin": "^5.48.0",
112
+ "@typescript-eslint/parser": "^5.48.0",
113
113
  "@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
114
114
  "angular": "^1.8.3",
115
115
  "angular-mocks": "^1.8.3",
@@ -124,7 +124,7 @@
124
124
  "core-js": "^3.27.1",
125
125
  "cpy-cli": "^3.1.1",
126
126
  "enzyme": "^3.11.0",
127
- "eslint": "^8.30.0",
127
+ "eslint": "^8.31.0",
128
128
  "eslint-import-resolver-webpack": "^0.13.2",
129
129
  "eslint-plugin-angular": "^4.1.0",
130
130
  "eslint-plugin-bdd": "^2.1.1",
@@ -134,7 +134,7 @@
134
134
  "events": "^3.3.0",
135
135
  "glob": "^8.0.3",
136
136
  "html-webpack-plugin": "^5.5.0",
137
- "husky": "^8.0.2",
137
+ "husky": "^8.0.3",
138
138
  "identity-obj-proxy": "^3.0.0",
139
139
  "imports-loader": "^4.0.1",
140
140
  "jest": "~29.3.1",
@@ -157,7 +157,7 @@
157
157
  "react-test-renderer": "^18.2.0",
158
158
  "regenerator-runtime": "^0.13.11",
159
159
  "rimraf": "^3.0.2",
160
- "rollup": "^3.9.0",
160
+ "rollup": "^3.9.1",
161
161
  "rollup-plugin-clear": "^2.0.7",
162
162
  "rollup-plugin-styles": "^4.0.0",
163
163
  "sinon": "^15.0.1",