@jetbrains/ring-ui 5.0.87 → 5.0.89

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;
@@ -9,7 +9,7 @@
9
9
  display: flex;
10
10
  flex-direction: row;
11
11
 
12
- padding: 6px 0;
12
+ padding: 2px 0;
13
13
 
14
14
  text-align: left;
15
15
 
@@ -1,6 +1,6 @@
1
1
  import angular from 'angular';
2
2
 
3
- import React from 'react';
3
+ import React, {cloneElement} from 'react';
4
4
 
5
5
  import {render, hydrate} from '../global/react-render-adapter';
6
6
  import {RerenderableSelect} from '../select/select';
@@ -68,9 +68,12 @@ class SelectLazy {
68
68
  _clickHandler() {
69
69
  this.detachEvents();
70
70
  if (this.type === 'dropdown') {
71
- render(this.reactSelect, this.container);
72
- // Hack for React17, where click event is not triggered on just rendered Select node
73
- this.selectInstance?._openPopupIfClosed?.();
71
+ render(cloneElement(this.reactSelect, {
72
+ ref: node => {
73
+ this.selectRef(node);
74
+ node?._openPopupIfClosed?.();
75
+ }
76
+ }), this.container);
74
77
  } else {
75
78
  hydrate(this.reactSelect, this.container);
76
79
  }
@@ -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;
@@ -1,6 +1,6 @@
1
1
  import { _ as _defineProperty, a as _extends } from '../_helpers/_rollupPluginBabelHelpers.js';
2
2
  import angular from 'angular';
3
- import React from 'react';
3
+ import React, { cloneElement } from 'react';
4
4
  import { render, hydrate } from '../global/react-render-adapter.js';
5
5
  import { RerenderableSelect } from '../select/select.js';
6
6
  import 'react-dom';
@@ -138,9 +138,12 @@ class SelectLazy {
138
138
  _clickHandler() {
139
139
  this.detachEvents();
140
140
  if (this.type === 'dropdown') {
141
- render(this.reactSelect, this.container);
142
- // Hack for React17, where click event is not triggered on just rendered Select node
143
- this.selectInstance?._openPopupIfClosed?.();
141
+ render( /*#__PURE__*/cloneElement(this.reactSelect, {
142
+ ref: node => {
143
+ this.selectRef(node);
144
+ node?._openPopupIfClosed?.();
145
+ }
146
+ }), this.container);
144
147
  } else {
145
148
  hydrate(this.reactSelect, this.container);
146
149
  }