@sima-land/ui-nucleons 44.2.6 → 44.2.9

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.
@@ -91,7 +91,6 @@ const Autocomplete = (_a) => {
91
91
  }, onBlur: () => {
92
92
  toggleMenu(false);
93
93
  }, onChange: (event) => {
94
- toggleMenu(true);
95
94
  setRealValue(event.target.value);
96
95
  setActiveIndex(0);
97
96
  onChange === null || onChange === void 0 ? void 0 : onChange(event);
@@ -6,6 +6,7 @@ export interface Control {
6
6
  isGrabbed: () => boolean;
7
7
  setOffset: typeof Draggable.prototype.setOffset;
8
8
  toggleTransition: typeof Draggable.prototype.toggleTransition;
9
+ isTransitionEnabled: () => boolean;
9
10
  }
10
11
  export declare type Delta2d = {
11
12
  dx: number;
@@ -92,6 +93,11 @@ export default class Draggable extends Component<DraggableProps> {
92
93
  * @param active Нужен ли плавный переход.
93
94
  */
94
95
  toggleTransition(active: boolean): void;
96
+ /**
97
+ * Возвращает true, если css свойство transition активно, false в противном случае.
98
+ * @return Активно ли css свойство transition.
99
+ */
100
+ isTransitionEnabled(): boolean;
95
101
  /**
96
102
  * Сохраняет данные позиции на экземпляре.
97
103
  * @param event Событие.
@@ -90,6 +90,7 @@ class Draggable extends react_1.Component {
90
90
  isGrabbed: () => this.isGrabbed,
91
91
  setOffset: this.setOffset.bind(this),
92
92
  toggleTransition: this.toggleTransition.bind(this),
93
+ isTransitionEnabled: this.isTransitionEnabled.bind(this),
93
94
  });
94
95
  }
95
96
  /**
@@ -207,6 +208,13 @@ class Draggable extends react_1.Component {
207
208
  draggableEl.style.transition = active ? (0, styles_1.getTransitionStyle)(duration, 'transform') : '';
208
209
  }
209
210
  }
211
+ /**
212
+ * Возвращает true, если css свойство transition активно, false в противном случае.
213
+ * @return Активно ли css свойство transition.
214
+ */
215
+ isTransitionEnabled() {
216
+ return this.hasTransition;
217
+ }
210
218
  /**
211
219
  * Сохраняет данные позиции на экземпляре.
212
220
  * @param event Событие.
@@ -61,6 +61,7 @@ export declare class Carousel extends Component<CarouselProps, State> {
61
61
  dragStartOffset: IPoint;
62
62
  currentIndex: number;
63
63
  containerRef: React.RefObject<HTMLDivElement>;
64
+ rootElementRef: React.RefObject<HTMLDivElement>;
64
65
  wrapperRef: React.RefObject<HTMLDivElement>;
65
66
  timerId?: number;
66
67
  canAutoMove?: boolean;
@@ -69,6 +70,7 @@ export declare class Carousel extends Component<CarouselProps, State> {
69
70
  toggleDragTransition: Control['toggleTransition'];
70
71
  setDragOffset: Control['setOffset'];
71
72
  isGrabbed: Control['isGrabbed'];
73
+ isTransitionEnabled: Control['isTransitionEnabled'];
72
74
  /**
73
75
  * Конструктор.
74
76
  * @param props Свойства.
@@ -125,6 +127,15 @@ export declare class Carousel extends Component<CarouselProps, State> {
125
127
  * Обновляет информацию о состоянии отображения элементов.
126
128
  */
127
129
  componentDidMount(): void;
130
+ /**
131
+ * Подписывается на изменение размера корневого элемента.
132
+ * @param Observer Класс ResizeObserver.
133
+ */
134
+ observeResize(Observer?: typeof ResizeObserver): void;
135
+ /**
136
+ * Корректирует смещение при изменении размеров.
137
+ */
138
+ handleResize(): void;
128
139
  /**
129
140
  * По необходимости обновляет индекс текущего элемента.
130
141
  * Обновляет информацию о состоянии отображения элементов.
@@ -286,9 +297,9 @@ export declare class Carousel extends Component<CarouselProps, State> {
286
297
  }): void;
287
298
  /**
288
299
  * Получает управление от Draggable.
289
- * @param draggableControls Функции управления Draggable.
300
+ * @param control Функции управления Draggable.
290
301
  */
291
- takeDragControl({ isGrabbed, setOffset, toggleTransition }: Control): void;
302
+ takeDragControl(control: Control): void;
292
303
  /** @inheritdoc */
293
304
  render(): JSX.Element;
294
305
  /**
package/carousel/index.js CHANGED
@@ -37,7 +37,6 @@ const max_index_of_1 = __importDefault(require("../helpers/max-index-of"));
37
37
  const get_relative_pos_1 = __importDefault(require("../helpers/get-relative-pos"));
38
38
  const find_child_element_1 = __importDefault(require("../helpers/find-child-element"));
39
39
  const arrow_button_1 = require("../arrow-button");
40
- const on_1 = __importDefault(require("../helpers/on"));
41
40
  const bind_1 = __importDefault(require("classnames/bind"));
42
41
  const carousel_module_scss_1 = __importDefault(require("./carousel.module.scss"));
43
42
  const is_browser_1 = __importDefault(require("../helpers/is-browser"));
@@ -66,6 +65,7 @@ class Carousel extends react_1.Component {
66
65
  isAllItemsVisible: false,
67
66
  };
68
67
  // refs
68
+ this.rootElementRef = (0, react_1.createRef)(); // для слежки за изменением размера
69
69
  this.containerRef = (0, react_1.createRef)(); // для определения размеров списка элементов
70
70
  this.wrapperRef = (0, react_1.createRef)(); // для определения viewport'а карусели
71
71
  // bound methods
@@ -80,6 +80,7 @@ class Carousel extends react_1.Component {
80
80
  this.toggleDragTransition = lodash_1.noop;
81
81
  this.setDragOffset = lodash_1.noop;
82
82
  this.isGrabbed = lodash_1.stubFalse;
83
+ this.isTransitionEnabled = lodash_1.stubFalse;
83
84
  }
84
85
  /**
85
86
  * Возвращает элемент списка.
@@ -154,12 +155,7 @@ class Carousel extends react_1.Component {
154
155
  */
155
156
  componentDidMount() {
156
157
  const { autoplay, onReady } = this.props;
157
- this.offWindowResize = (0, on_1.default)(window, 'resize', () => {
158
- this.toggleDragTransition(false);
159
- this.scrollToItem({ needTransition: false });
160
- this.updateItemsVisibility();
161
- this.toggleDragTransition(true);
162
- });
158
+ this.observeResize(window.ResizeObserver);
163
159
  this.toggleMounted(true);
164
160
  this.forceUpdate(() => {
165
161
  this.scrollToItem({ needTransition: false });
@@ -168,6 +164,27 @@ class Carousel extends react_1.Component {
168
164
  autoplay && this.enableAutoplay();
169
165
  onReady && onReady(this.currentIndex);
170
166
  }
167
+ /**
168
+ * Подписывается на изменение размера корневого элемента.
169
+ * @param Observer Класс ResizeObserver.
170
+ */
171
+ observeResize(Observer) {
172
+ if (Observer && this.rootElementRef.current) {
173
+ const observer = new Observer(() => this.handleResize());
174
+ observer.observe(this.rootElementRef.current);
175
+ this.offWindowResize = () => observer.disconnect();
176
+ }
177
+ }
178
+ /**
179
+ * Корректирует смещение при изменении размеров.
180
+ */
181
+ handleResize() {
182
+ const wasEnabled = this.isTransitionEnabled();
183
+ wasEnabled && this.toggleDragTransition(false);
184
+ this.scrollToItem({ needTransition: false });
185
+ this.updateItemsVisibility();
186
+ wasEnabled && this.toggleDragTransition(true);
187
+ }
171
188
  /**
172
189
  * По необходимости обновляет индекс текущего элемента.
173
190
  * Обновляет информацию о состоянии отображения элементов.
@@ -560,19 +577,20 @@ class Carousel extends react_1.Component {
560
577
  }
561
578
  /**
562
579
  * Получает управление от Draggable.
563
- * @param draggableControls Функции управления Draggable.
580
+ * @param control Функции управления Draggable.
564
581
  */
565
- takeDragControl({ isGrabbed, setOffset, toggleTransition }) {
566
- this.toggleDragTransition = toggleTransition;
567
- this.setDragOffset = setOffset;
568
- this.isGrabbed = isGrabbed;
582
+ takeDragControl(control) {
583
+ this.toggleDragTransition = control.toggleTransition;
584
+ this.setDragOffset = control.setOffset;
585
+ this.isGrabbed = control.isGrabbed;
586
+ this.isTransitionEnabled = control.isTransitionEnabled;
569
587
  }
570
588
  /** @inheritdoc */
571
589
  render() {
572
590
  const { currentOffset, isAllItemsVisible } = this.state;
573
591
  const { autoplay, autoplayHoverPause, vertical, containerProps = {}, viewportElementProps = {}, withControls = 'auto', renderControl = Carousel.defaultRenderControl, controlProps, } = this.props;
574
592
  const needShowControls = (isAuto(withControls) && !isAllItemsVisible) || withControls === true;
575
- return (react_1.default.createElement("div", Object.assign({}, containerProps, { className: cx('carousel-wrapper', containerProps.className), onMouseEnter: () => {
593
+ return (react_1.default.createElement("div", Object.assign({ ref: this.rootElementRef }, containerProps, { className: cx('carousel-wrapper', containerProps.className), onMouseEnter: () => {
576
594
  autoplay && autoplayHoverPause && this.toggleAutoMove(false);
577
595
  }, onMouseLeave: () => {
578
596
  autoplay && autoplayHoverPause && !this.isGrabbed() && this.toggleAutoMove(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sima-land/ui-nucleons",
3
- "version": "44.2.6",
3
+ "version": "44.2.9",
4
4
  "repository": "ssh://git@github.com:sima-land/ui-nucleons.git",
5
5
  "author": "www.sima-land.ru team",
6
6
  "license": "Apache-2.0",
package/screen/slots.js CHANGED
@@ -48,6 +48,7 @@ const hooks_1 = require("../hooks");
48
48
  const loading_overlay_1 = require("../loading-overlay");
49
49
  const utils_1 = require("./utils");
50
50
  const screen_module_scss_1 = __importDefault(require("./screen.module.scss"));
51
+ const constants_1 = require("../constants");
51
52
  /**
52
53
  * Слот шапки экрана.
53
54
  * @param props Свойства.
@@ -90,7 +91,7 @@ exports.BodySlot = (0, react_1.forwardRef)(function BodySlot({ children }, outer
90
91
  (0, hooks_1.useInfiniteScroll)(ref, { onFullScroll, threshold: fullScrollThreshold });
91
92
  return (
92
93
  // ВАЖНО: элемент с ref должен выводиться всегда (без условий), т.к. он нужен для блокировки прокрутки
93
- react_1.default.createElement("div", { ref: ref, className: screen_module_scss_1.default.body, "data-testid": 'screen:body' }, loading ? (react_1.default.createElement(loading_overlay_1.LoadingOverlay, Object.assign({}, loadingOverlayProps, { fill: false, style: { height: '100%' } }))) : (children)));
94
+ react_1.default.createElement("div", Object.assign({ ref: ref, className: screen_module_scss_1.default.body, "data-testid": 'screen:body' }, { [constants_1.BSL_IGNORE_ATTR]: true }), loading ? (react_1.default.createElement(loading_overlay_1.LoadingOverlay, Object.assign({}, loadingOverlayProps, { fill: false, style: { height: '100%' } }))) : (children)));
94
95
  });
95
96
  /**
96
97
  * Слот футера экрана.