@gravity-ui/dashkit 8.17.3-beta.0 → 8.17.4

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.
@@ -76,6 +76,14 @@
76
76
  user-select: none;
77
77
  }
78
78
 
79
+ .react-grid-focus-capture {
80
+ position: absolute;
81
+ display: block;
82
+ z-index: 6;
83
+ max-width: 100%;
84
+ max-height: 100%;
85
+ }
86
+
79
87
  .react-grid-item .react-resizable-handle {
80
88
  position: absolute;
81
89
  width: 20px;
@@ -96,7 +96,7 @@ class GridItem extends react_1.default.PureComponent {
96
96
  render() {
97
97
  // из-за бага, что Grid Items unmounts при изменении static, isDraggable, isResaizable
98
98
  // https://github.com/STRML/react-grid-layout/issues/721
99
- const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, draggedOut, noOverlay, focusable, withCustomHandle, isPlaceholder = false, } = this.props;
99
+ const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, isDraggedOut, noOverlay, focusable, withCustomHandle, isPlaceholder = false, } = this.props;
100
100
  const { editMode } = this.context;
101
101
  const width = Number.parseInt(style.width, 10);
102
102
  const height = Number.parseInt(style.height, 10);
@@ -115,7 +115,7 @@ class GridItem extends react_1.default.PureComponent {
115
115
  const { _editActive } = this.props.item.data;
116
116
  return (react_1.default.createElement("div", Object.assign({ className: b({
117
117
  'is-dragging': isDragging,
118
- 'is-dragged-out': draggedOut,
118
+ 'is-dragged-out': isDraggedOut,
119
119
  'is-focused': this.state.isFocused,
120
120
  'with-custom-handle': withCustomHandle,
121
121
  }, preparedClassName), "data-qa": "dashkit-grid-item", style: style, ref: this.props.forwardedRef }, reactGridLayoutProps, (focusable
@@ -136,7 +136,7 @@ GridItem.propTypes = {
136
136
  id: prop_types_1.default.string,
137
137
  item: prop_types_1.default.object,
138
138
  isDragging: prop_types_1.default.bool,
139
- draggedOut: prop_types_1.default.bool,
139
+ isDraggedOut: prop_types_1.default.bool,
140
140
  layout: prop_types_1.default.array,
141
141
  forwardedRef: prop_types_1.default.any,
142
142
  forwardedPluginRef: prop_types_1.default.any,
@@ -48,10 +48,10 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
48
48
  e: any;
49
49
  element: any;
50
50
  };
51
- updateeDraggingElementState(group: any, layoutItem: any, e: any): void;
51
+ updateDraggingElementState(group: any, layoutItem: any, e: any): void;
52
52
  _initDragCoordinatesWatcher(element: any): void;
53
53
  _parendDragNode: any;
54
- _forceCursorCapture(parentElement: any, position: any): void;
54
+ _forceCursorCapture(parentElement: any, position: any, parentRect: any): void;
55
55
  _updateDragCoordinates(e: any): void;
56
56
  _resetDragWatcher(): void;
57
57
  _onDragStart(group: any, _newLayout: any, layoutItem: any, _newItem: any, _placeholder: any, e: any, element: any): void;
@@ -270,7 +270,7 @@ class GridLayout extends react_1.default.PureComponent {
270
270
  element,
271
271
  };
272
272
  }
273
- updateeDraggingElementState(group, layoutItem, e) {
273
+ updateDraggingElementState(group, layoutItem, e) {
274
274
  let currentDraggingElement = this.state.currentDraggingElement;
275
275
  if (!currentDraggingElement) {
276
276
  const { temporaryLayout } = this.context;
@@ -294,20 +294,23 @@ class GridLayout extends react_1.default.PureComponent {
294
294
  this.setState({ draggedOut: false });
295
295
  }
296
296
  }
297
- _forceCursorCapture(parentElement, position) {
298
- const div = document.createElement('div');
299
- const blockSize = 50;
297
+ // When element is going back and prointer-event: none is removed mouse enter event is not fired
298
+ // So to trigger it we are forcing this event by adding transparent block under the mouse
299
+ _forceCursorCapture(parentElement, position, parentRect) {
300
+ const block = document.createElement('div');
301
+ block.classList.add('react-grid-focus-capture');
302
+ const blockSize = 44;
300
303
  const offset = blockSize / 2;
301
- div.style.position = 'absolute';
302
- div.style.display = 'block';
303
- div.style.zIndex = 10;
304
- div.style.width = `${blockSize}px`;
305
- div.style.height = `${blockSize}px`;
306
- div.style.top = `${position.top - offset}px`;
307
- div.style.left = `${position.left - offset}px`;
308
- parentElement.appendChild(div);
304
+ // Keeping elemnt inside current grid
305
+ const top = Math.min(Math.max(position.top - offset, 0), parentRect.height - blockSize);
306
+ const left = Math.min(Math.max(position.left - offset, 0), parentRect.width - blockSize);
307
+ block.style.width = `${blockSize}px`;
308
+ block.style.height = `${blockSize}px`;
309
+ block.style.top = `${top}px`;
310
+ block.style.left = `${left}px`;
311
+ parentElement.appendChild(block);
309
312
  setTimeout(() => {
310
- div.remove();
313
+ block.remove();
311
314
  }, 100);
312
315
  }
313
316
  _updateDragCoordinates(e) {
@@ -325,12 +328,14 @@ class GridLayout extends react_1.default.PureComponent {
325
328
  draggedOut = false;
326
329
  }
327
330
  if (draggedOut !== this.state.draggedOut) {
328
- this._forceCursorCapture(parent, {
329
- top: clientY - parentRect.top,
330
- left: clientX - parentRect.left,
331
- });
331
+ this.setState({ draggedOut });
332
+ if (!draggedOut) {
333
+ this._forceCursorCapture(parent, {
334
+ top: clientY - parentRect.top,
335
+ left: clientX - parentRect.left,
336
+ }, parentRect);
337
+ }
332
338
  }
333
- this.setState({ draggedOut });
334
339
  }
335
340
  _resetDragWatcher() {
336
341
  this._parendDragNode = null;
@@ -344,13 +349,13 @@ class GridLayout extends react_1.default.PureComponent {
344
349
  this.setState({ isDragging: true });
345
350
  }
346
351
  else {
347
- this.updateeDraggingElementState(group, layoutItem, e);
352
+ this.updateDraggingElementState(group, layoutItem, e);
348
353
  this.setState({ isDragging: true });
349
354
  }
350
355
  }
351
356
  _onDrag(group, layout, oldItem, newItem, placeholder, e, element) {
352
357
  var _a;
353
- this._updateDragCoordinates(e, element);
358
+ this._updateDragCoordinates(e);
354
359
  (_a = this.context.onDrag) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
355
360
  }
356
361
  _onDragStop(group, layout, oldItem, newItem, placeholder, e, element) {
@@ -379,7 +384,6 @@ class GridLayout extends react_1.default.PureComponent {
379
384
  if (this.context.temporaryLayout) {
380
385
  return;
381
386
  }
382
- console.log('_onTargetRestore');
383
387
  const { currentDraggingElement } = this.state;
384
388
  if (currentDraggingElement) {
385
389
  this.setState({
@@ -428,7 +432,9 @@ class GridLayout extends react_1.default.PureComponent {
428
432
  }
429
433
  : null)),
430
434
  renderItems.map((item, i) => {
431
- return (react_1.default.createElement(GridItem_1.default, { forwardedPluginRef: this.getMemoForwardRefCallback(offset + i), key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, draggedOut: this.state.draggedOut, noOverlay: noOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), onItemMountChange: onItemMountChange, onItemRender: onItemRender }));
435
+ const isCurrentItem = (currentDraggingElement === null || currentDraggingElement === void 0 ? void 0 : currentDraggingElement.item.id) === item.id;
436
+ const isDraggedOut = isCurrentItem && this.state.draggedOut;
437
+ return (react_1.default.createElement(GridItem_1.default, { forwardedPluginRef: this.getMemoForwardRefCallback(offset + i), key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, isDraggedOut: isDraggedOut, noOverlay: noOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), onItemMountChange: onItemMountChange, onItemRender: onItemRender }));
432
438
  }),
433
439
  this.renderTemporaryPlaceholder()));
434
440
  }
@@ -76,6 +76,14 @@
76
76
  user-select: none;
77
77
  }
78
78
 
79
+ .react-grid-focus-capture {
80
+ position: absolute;
81
+ display: block;
82
+ z-index: 6;
83
+ max-width: 100%;
84
+ max-height: 100%;
85
+ }
86
+
79
87
  .react-grid-item .react-resizable-handle {
80
88
  position: absolute;
81
89
  width: 20px;
@@ -94,7 +94,7 @@ class GridItem extends React.PureComponent {
94
94
  render() {
95
95
  // из-за бага, что Grid Items unmounts при изменении static, isDraggable, isResaizable
96
96
  // https://github.com/STRML/react-grid-layout/issues/721
97
- const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, draggedOut, noOverlay, focusable, withCustomHandle, isPlaceholder = false, } = this.props;
97
+ const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, isDraggedOut, noOverlay, focusable, withCustomHandle, isPlaceholder = false, } = this.props;
98
98
  const { editMode } = this.context;
99
99
  const width = Number.parseInt(style.width, 10);
100
100
  const height = Number.parseInt(style.height, 10);
@@ -113,7 +113,7 @@ class GridItem extends React.PureComponent {
113
113
  const { _editActive } = this.props.item.data;
114
114
  return (React.createElement("div", Object.assign({ className: b({
115
115
  'is-dragging': isDragging,
116
- 'is-dragged-out': draggedOut,
116
+ 'is-dragged-out': isDraggedOut,
117
117
  'is-focused': this.state.isFocused,
118
118
  'with-custom-handle': withCustomHandle,
119
119
  }, preparedClassName), "data-qa": "dashkit-grid-item", style: style, ref: this.props.forwardedRef }, reactGridLayoutProps, (focusable
@@ -134,7 +134,7 @@ GridItem.propTypes = {
134
134
  id: PropTypes.string,
135
135
  item: PropTypes.object,
136
136
  isDragging: PropTypes.bool,
137
- draggedOut: PropTypes.bool,
137
+ isDraggedOut: PropTypes.bool,
138
138
  layout: PropTypes.array,
139
139
  forwardedRef: PropTypes.any,
140
140
  forwardedPluginRef: PropTypes.any,
@@ -48,10 +48,10 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
48
48
  e: any;
49
49
  element: any;
50
50
  };
51
- updateeDraggingElementState(group: any, layoutItem: any, e: any): void;
51
+ updateDraggingElementState(group: any, layoutItem: any, e: any): void;
52
52
  _initDragCoordinatesWatcher(element: any): void;
53
53
  _parendDragNode: any;
54
- _forceCursorCapture(parentElement: any, position: any): void;
54
+ _forceCursorCapture(parentElement: any, position: any, parentRect: any): void;
55
55
  _updateDragCoordinates(e: any): void;
56
56
  _resetDragWatcher(): void;
57
57
  _onDragStart(group: any, _newLayout: any, layoutItem: any, _newItem: any, _placeholder: any, e: any, element: any): void;
@@ -267,7 +267,7 @@ class GridLayout extends React.PureComponent {
267
267
  element,
268
268
  };
269
269
  }
270
- updateeDraggingElementState(group, layoutItem, e) {
270
+ updateDraggingElementState(group, layoutItem, e) {
271
271
  let currentDraggingElement = this.state.currentDraggingElement;
272
272
  if (!currentDraggingElement) {
273
273
  const { temporaryLayout } = this.context;
@@ -291,20 +291,23 @@ class GridLayout extends React.PureComponent {
291
291
  this.setState({ draggedOut: false });
292
292
  }
293
293
  }
294
- _forceCursorCapture(parentElement, position) {
295
- const div = document.createElement('div');
296
- const blockSize = 50;
294
+ // When element is going back and prointer-event: none is removed mouse enter event is not fired
295
+ // So to trigger it we are forcing this event by adding transparent block under the mouse
296
+ _forceCursorCapture(parentElement, position, parentRect) {
297
+ const block = document.createElement('div');
298
+ block.classList.add('react-grid-focus-capture');
299
+ const blockSize = 44;
297
300
  const offset = blockSize / 2;
298
- div.style.position = 'absolute';
299
- div.style.display = 'block';
300
- div.style.zIndex = 10;
301
- div.style.width = `${blockSize}px`;
302
- div.style.height = `${blockSize}px`;
303
- div.style.top = `${position.top - offset}px`;
304
- div.style.left = `${position.left - offset}px`;
305
- parentElement.appendChild(div);
301
+ // Keeping elemnt inside current grid
302
+ const top = Math.min(Math.max(position.top - offset, 0), parentRect.height - blockSize);
303
+ const left = Math.min(Math.max(position.left - offset, 0), parentRect.width - blockSize);
304
+ block.style.width = `${blockSize}px`;
305
+ block.style.height = `${blockSize}px`;
306
+ block.style.top = `${top}px`;
307
+ block.style.left = `${left}px`;
308
+ parentElement.appendChild(block);
306
309
  setTimeout(() => {
307
- div.remove();
310
+ block.remove();
308
311
  }, 100);
309
312
  }
310
313
  _updateDragCoordinates(e) {
@@ -322,12 +325,14 @@ class GridLayout extends React.PureComponent {
322
325
  draggedOut = false;
323
326
  }
324
327
  if (draggedOut !== this.state.draggedOut) {
325
- this._forceCursorCapture(parent, {
326
- top: clientY - parentRect.top,
327
- left: clientX - parentRect.left,
328
- });
328
+ this.setState({ draggedOut });
329
+ if (!draggedOut) {
330
+ this._forceCursorCapture(parent, {
331
+ top: clientY - parentRect.top,
332
+ left: clientX - parentRect.left,
333
+ }, parentRect);
334
+ }
329
335
  }
330
- this.setState({ draggedOut });
331
336
  }
332
337
  _resetDragWatcher() {
333
338
  this._parendDragNode = null;
@@ -341,13 +346,13 @@ class GridLayout extends React.PureComponent {
341
346
  this.setState({ isDragging: true });
342
347
  }
343
348
  else {
344
- this.updateeDraggingElementState(group, layoutItem, e);
349
+ this.updateDraggingElementState(group, layoutItem, e);
345
350
  this.setState({ isDragging: true });
346
351
  }
347
352
  }
348
353
  _onDrag(group, layout, oldItem, newItem, placeholder, e, element) {
349
354
  var _a;
350
- this._updateDragCoordinates(e, element);
355
+ this._updateDragCoordinates(e);
351
356
  (_a = this.context.onDrag) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
352
357
  }
353
358
  _onDragStop(group, layout, oldItem, newItem, placeholder, e, element) {
@@ -376,7 +381,6 @@ class GridLayout extends React.PureComponent {
376
381
  if (this.context.temporaryLayout) {
377
382
  return;
378
383
  }
379
- console.log('_onTargetRestore');
380
384
  const { currentDraggingElement } = this.state;
381
385
  if (currentDraggingElement) {
382
386
  this.setState({
@@ -425,7 +429,9 @@ class GridLayout extends React.PureComponent {
425
429
  }
426
430
  : null)),
427
431
  renderItems.map((item, i) => {
428
- return (React.createElement(GridItem, { forwardedPluginRef: this.getMemoForwardRefCallback(offset + i), key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, draggedOut: this.state.draggedOut, noOverlay: noOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), onItemMountChange: onItemMountChange, onItemRender: onItemRender }));
432
+ const isCurrentItem = (currentDraggingElement === null || currentDraggingElement === void 0 ? void 0 : currentDraggingElement.item.id) === item.id;
433
+ const isDraggedOut = isCurrentItem && this.state.draggedOut;
434
+ return (React.createElement(GridItem, { forwardedPluginRef: this.getMemoForwardRefCallback(offset + i), key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, isDraggedOut: isDraggedOut, noOverlay: noOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), onItemMountChange: onItemMountChange, onItemRender: onItemRender }));
429
435
  }),
430
436
  this.renderTemporaryPlaceholder()));
431
437
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.17.3-beta.0",
3
+ "version": "8.17.4",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {