@gravity-ui/dashkit 8.8.1 → 8.9.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 (45) hide show
  1. package/build/cjs/components/GridItem/GridItem.css +1 -0
  2. package/build/cjs/components/GridLayout/GridLayout.d.ts +8 -2
  3. package/build/cjs/components/GridLayout/GridLayout.js +111 -23
  4. package/build/cjs/components/GridLayout/ReactGridLayout.js +142 -24
  5. package/build/cjs/components/OverlayControls/OverlayControls.js +5 -7
  6. package/build/cjs/constants/common.d.ts +1 -0
  7. package/build/cjs/constants/common.js +2 -1
  8. package/build/cjs/hocs/withContext.js +24 -6
  9. package/build/esm/components/GridItem/GridItem.css +1 -0
  10. package/build/esm/components/GridLayout/GridLayout.d.ts +8 -2
  11. package/build/esm/components/GridLayout/GridLayout.js +111 -23
  12. package/build/esm/components/GridLayout/ReactGridLayout.js +143 -25
  13. package/build/esm/components/OverlayControls/OverlayControls.js +6 -8
  14. package/build/esm/constants/common.d.ts +1 -0
  15. package/build/esm/constants/common.js +1 -0
  16. package/build/esm/hocs/withContext.js +24 -6
  17. package/package.json +1 -1
  18. package/build/cjs/icons/CloseIcon.d.ts +0 -2
  19. package/build/cjs/icons/CloseIcon.js +0 -10
  20. package/build/cjs/icons/CogIcon.d.ts +0 -2
  21. package/build/cjs/icons/CogIcon.js +0 -10
  22. package/build/cjs/icons/CopyIcon.d.ts +0 -2
  23. package/build/cjs/icons/CopyIcon.js +0 -10
  24. package/build/cjs/icons/DeleteIcon.d.ts +0 -2
  25. package/build/cjs/icons/DeleteIcon.js +0 -12
  26. package/build/cjs/icons/DotsIcon.d.ts +0 -2
  27. package/build/cjs/icons/DotsIcon.js +0 -10
  28. package/build/cjs/icons/TickIcon.d.ts +0 -2
  29. package/build/cjs/icons/TickIcon.js +0 -10
  30. package/build/cjs/icons/WarningIcon.d.ts +0 -2
  31. package/build/cjs/icons/WarningIcon.js +0 -10
  32. package/build/esm/icons/CloseIcon.d.ts +0 -2
  33. package/build/esm/icons/CloseIcon.js +0 -5
  34. package/build/esm/icons/CogIcon.d.ts +0 -2
  35. package/build/esm/icons/CogIcon.js +0 -5
  36. package/build/esm/icons/CopyIcon.d.ts +0 -2
  37. package/build/esm/icons/CopyIcon.js +0 -5
  38. package/build/esm/icons/DeleteIcon.d.ts +0 -2
  39. package/build/esm/icons/DeleteIcon.js +0 -7
  40. package/build/esm/icons/DotsIcon.d.ts +0 -2
  41. package/build/esm/icons/DotsIcon.js +0 -5
  42. package/build/esm/icons/TickIcon.d.ts +0 -2
  43. package/build/esm/icons/TickIcon.js +0 -5
  44. package/build/esm/icons/WarningIcon.d.ts +0 -2
  45. package/build/esm/icons/WarningIcon.js +0 -5
@@ -53,17 +53,18 @@ class GridLayout extends React.PureComponent {
53
53
  };
54
54
  this.getMemoGroupCallbacks = (group) => {
55
55
  if (!this._memoCallbacksForGroups[group]) {
56
- const onStart = this._onStart;
56
+ const onDragStart = this._onDragStart.bind(this, group);
57
57
  const onStop = this._onStop.bind(this, group);
58
58
  const onDrop = this._onDrop.bind(this, group);
59
59
  const onDropDragOver = this._onDropDragOver.bind(this, group);
60
+ const onDragTargetRestore = this._onTargetRestore.bind(this, group);
60
61
  this._memoCallbacksForGroups[group] = {
61
- onDragStart: onStart,
62
- onResizeStart: onStart,
62
+ onDragStart,
63
63
  onDragStop: onStop,
64
64
  onResizeStop: onStop,
65
- onDrop: onDrop,
65
+ onDrop,
66
66
  onDropDragOver,
67
+ onDragTargetRestore,
67
68
  };
68
69
  }
69
70
  return this._memoCallbacksForGroups[group];
@@ -90,48 +91,131 @@ class GridLayout extends React.PureComponent {
90
91
  }
91
92
  return this._memoForwardedPluginRef[refIndex];
92
93
  };
93
- this._onStart = () => {
94
+ this._onDragStart = (group, _newLayout, layoutItem) => {
94
95
  if (this.temporaryLayout)
95
96
  return;
96
- this.setState({ isDragging: true });
97
+ if (this.context.dragOverPlugin) {
98
+ this.setState({ isDragging: true });
99
+ }
100
+ else {
101
+ let currentDraggingElement = this.state.currentDraggingElement;
102
+ if (!currentDraggingElement) {
103
+ const _id = layoutItem.i;
104
+ const item = this.context.config.items.find(({ id }) => id === _id);
105
+ currentDraggingElement = [group, layoutItem, item];
106
+ }
107
+ this.setState({
108
+ isDragging: true,
109
+ currentDraggingElement,
110
+ draggedOverGroup: group,
111
+ });
112
+ }
113
+ };
114
+ this._onResizeStart = () => {
115
+ this.setState({
116
+ isDragging: true,
117
+ });
118
+ };
119
+ this._onTargetRestore = () => {
120
+ const { currentDraggingElement } = this.state;
121
+ if (currentDraggingElement) {
122
+ this.setState({
123
+ draggedOverGroup: currentDraggingElement[0],
124
+ });
125
+ }
97
126
  };
98
127
  this._onStop = (group, newLayout) => {
99
128
  const { layoutChange, onDrop, temporaryLayout } = this.context;
129
+ const { draggedOverGroup, currentDraggingElement } = this.state;
130
+ if (currentDraggingElement &&
131
+ draggedOverGroup !== null &&
132
+ draggedOverGroup !== currentDraggingElement[0]) {
133
+ // Skipping layout update when change event called for source grid
134
+ // and waiting _onDrop
135
+ return;
136
+ }
100
137
  const groupedLayout = this.mergeGroupsLayout(group, newLayout);
138
+ this.setState({
139
+ isDragging: false,
140
+ currentDraggingElement: null,
141
+ draggedOverGroup: null,
142
+ });
101
143
  if (temporaryLayout) {
102
144
  onDrop === null || onDrop === void 0 ? void 0 : onDrop(groupedLayout, groupedLayout.find(({ i }) => i === TEMPORARY_ITEM_ID));
103
145
  }
104
146
  else {
105
147
  layoutChange(groupedLayout);
106
148
  }
107
- this.setState({ isDragging: false });
108
149
  };
109
- this._onDropDragOver = (group, e) => {
110
- const { editMode, dragOverPlugin } = this.context;
111
- if (!editMode || !dragOverPlugin) {
112
- return false;
150
+ this._onSharedDrop = (targetGroup, newLayout, tempItem) => {
151
+ const { currentDraggingElement } = this.state;
152
+ const { layoutChange } = this.context;
153
+ if (!currentDraggingElement) {
154
+ return;
113
155
  }
114
- const { properties, layout } = this.getLayoutAndPropsByGroup(group);
115
- return this.context.onDropDragOver(e, properties, layout);
156
+ const [, sourceItem] = currentDraggingElement;
157
+ const groupedLayout = this.mergeGroupsLayout(targetGroup, newLayout, tempItem).map((item) => {
158
+ if (item.i === sourceItem.i) {
159
+ const copy = Object.assign({}, tempItem);
160
+ delete copy.parent;
161
+ if (targetGroup !== DEFAULT_GROUP) {
162
+ copy.parent = targetGroup;
163
+ }
164
+ copy.i = sourceItem.i;
165
+ return copy;
166
+ }
167
+ return item;
168
+ });
169
+ this.setState({
170
+ isDragging: false,
171
+ currentDraggingElement: null,
172
+ draggedOverGroup: null,
173
+ });
174
+ layoutChange(groupedLayout);
175
+ };
176
+ this._onExternalDrop = (group, newLayout, item, e) => {
177
+ const { onDrop } = this.context;
178
+ if (group !== DEFAULT_GROUP) {
179
+ item.parent = group;
180
+ }
181
+ const groupedLayout = this.mergeGroupsLayout(group, newLayout, item);
182
+ this.setState({ isDragging: false });
183
+ onDrop === null || onDrop === void 0 ? void 0 : onDrop(groupedLayout, item, e);
116
184
  };
117
185
  this._onDrop = (group, newLayout, item, e) => {
118
- if (!item) {
186
+ if (!item || !this.context.editMode) {
119
187
  return false;
120
188
  }
121
- const { editMode, onDrop } = this.context;
122
- if (!editMode) {
189
+ const { draggedOverGroup, currentDraggingElement } = this.state;
190
+ if (currentDraggingElement && draggedOverGroup === group) {
191
+ this._onSharedDrop(group, newLayout, item);
192
+ }
193
+ else {
194
+ this._onExternalDrop(group, newLayout, item, e);
195
+ }
196
+ };
197
+ this._onDropDragOver = (group, e) => {
198
+ const { editMode, dragOverPlugin, onDropDragOver } = this.context;
199
+ const { currentDraggingElement } = this.state;
200
+ if (!editMode || (!dragOverPlugin && !currentDraggingElement)) {
123
201
  return false;
124
202
  }
125
- if (group !== DEFAULT_GROUP) {
126
- item.parent = group;
203
+ const { properties, layout } = this.getLayoutAndPropsByGroup(group);
204
+ if (currentDraggingElement) {
205
+ const [, { h, w, i }, { type }] = currentDraggingElement;
206
+ return onDropDragOver(e, properties, layout, { h, w, i, type });
127
207
  }
128
- const groupedLayout = this.mergeGroupsLayout(group, newLayout, item);
129
- onDrop === null || onDrop === void 0 ? void 0 : onDrop(groupedLayout, item, e);
208
+ if (dragOverPlugin) {
209
+ return onDropDragOver(e, properties, layout);
210
+ }
211
+ return false;
130
212
  };
131
213
  this.pluginsRefs = [];
132
214
  this.state = {
133
215
  isDragging: false,
134
216
  isPageHidden: false,
217
+ currentDraggingElement: null,
218
+ draggedOverGroup: null,
135
219
  };
136
220
  }
137
221
  componentDidMount() {
@@ -201,6 +285,7 @@ class GridLayout extends React.PureComponent {
201
285
  }
202
286
  renderGroup(group, renderLayout, renderItems, offset = 0, groupGridProperties) {
203
287
  const { registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, } = this.context;
288
+ const { currentDraggingElement, draggedOverGroup } = this.state;
204
289
  const properties = groupGridProperties
205
290
  ? groupGridProperties(Object.assign({}, registerManager.gridLayout))
206
291
  : registerManager.gridLayout;
@@ -209,13 +294,16 @@ class GridLayout extends React.PureComponent {
209
294
  compactType = 'horizontal';
210
295
  }
211
296
  const { callbacks, layout } = this.getMemoGroupProps(group, renderLayout, properties);
212
- return (React.createElement(Layout, Object.assign({}, properties, { compactType: compactType, layout: layout, key: `group_${group}`, isDraggable: editMode, isResizable: editMode, onDragStart: callbacks.onDragStart, onDragStop: callbacks.onDragStop, onResizeStart: callbacks.onResizeStart, onResizeStop: callbacks.onResizeStop }, (draggableHandleClassName
297
+ const hasSharedDragItem = Boolean(currentDraggingElement && currentDraggingElement[0] !== group);
298
+ const isDragCaptured = currentDraggingElement &&
299
+ group === currentDraggingElement[0] &&
300
+ draggedOverGroup !== null &&
301
+ draggedOverGroup !== group;
302
+ return (React.createElement(Layout, Object.assign({}, properties, { compactType: compactType, layout: layout, key: `group_${group}`, isDraggable: editMode, isResizable: editMode, onResizeStart: this._onResizeStart, onDragStart: callbacks.onDragStart, onDragStop: callbacks.onDragStop, onResizeStop: callbacks.onResizeStop, onDragTargetRestore: callbacks.onDragTargetRestore, onDropDragOver: callbacks.onDropDragOver, onDrop: callbacks.onDrop, hasSharedDragItem: hasSharedDragItem, isDragCaptured: isDragCaptured }, (draggableHandleClassName
213
303
  ? { draggableHandle: `.${draggableHandleClassName}` }
214
304
  : null), (outerDnDEnable
215
305
  ? {
216
306
  isDroppable: true,
217
- onDropDragOver: callbacks.onDropDragOver,
218
- onDrop: callbacks.onDrop,
219
307
  }
220
308
  : null), { draggableCancel: `.${OVERLAY_CONTROLS_CLASS_NAME}` }),
221
309
  renderItems.map((item, i) => {
@@ -1,62 +1,180 @@
1
1
  import React from 'react';
2
- import ReactGridLayout, { WidthProvider } from 'react-grid-layout';
2
+ import ReactGridLayout, { WidthProvider, utils } from 'react-grid-layout';
3
3
  import { OVERLAY_CLASS_NAME } from '../../constants';
4
4
  class DragOverLayout extends ReactGridLayout {
5
5
  constructor(...args) {
6
6
  super(...args);
7
- this.dragReset = () => {
7
+ this._savedDraggedOutLayout = null;
8
+ // Reset placeholder when item dragged from outside
9
+ this.resetExternalPlaceholder = () => {
8
10
  if (this.dragEnterCounter) {
9
11
  this.dragEnterCounter = 0;
10
12
  this.removeDroppingPlaceholder();
11
13
  }
12
14
  };
15
+ // Hide placeholder when element is dragged out
16
+ this.hideLocalPlaceholder = (i) => {
17
+ const { layout } = this.state;
18
+ const { cols } = this.props;
19
+ const savedLayout = layout.map((item) => (Object.assign({}, item)));
20
+ let hiddenElement;
21
+ const newLayout = utils.compact(layout.filter((item) => {
22
+ if (item.i === i) {
23
+ hiddenElement = item;
24
+ return false;
25
+ }
26
+ return true;
27
+ }), utils.compactType(this.props), cols);
28
+ if (hiddenElement) {
29
+ newLayout.push(hiddenElement);
30
+ }
31
+ this.setState({
32
+ activeDrag: null,
33
+ layout: newLayout,
34
+ });
35
+ return savedLayout;
36
+ };
37
+ this.extendedOnDrag = (i, x, y, sintEv) => {
38
+ if (this.props.isDragCaptured) {
39
+ if (!this._savedDraggedOutLayout) {
40
+ this._savedDraggedOutLayout = this.hideLocalPlaceholder(i);
41
+ }
42
+ return;
43
+ }
44
+ this._savedDraggedOutLayout = null;
45
+ // parent onDrag will show new placeholder again
46
+ this.parentOnDrag(i, x, y, sintEv);
47
+ };
48
+ this.extendedOnDragStop = (i, x, y, sintEv) => {
49
+ // Restoring layout if item was dropped outside of the grid
50
+ if (this._savedDraggedOutLayout) {
51
+ const savedLayout = this._savedDraggedOutLayout;
52
+ const l = utils.getLayoutItem(savedLayout, i);
53
+ // Create placeholder (display only)
54
+ const placeholder = {
55
+ w: l.w,
56
+ h: l.h,
57
+ x: l.x,
58
+ y: l.y,
59
+ placeholder: true,
60
+ i: i,
61
+ };
62
+ this.setState({
63
+ layout: savedLayout,
64
+ activeDrag: placeholder,
65
+ }, () => {
66
+ this.parentOnDragStop(i, x, y, sintEv);
67
+ });
68
+ this._savedDraggedOutLayout = null;
69
+ }
70
+ else {
71
+ this.parentOnDragStop(i, x, y, sintEv);
72
+ }
73
+ };
74
+ // Proxy mouse events -> drag methods for dnd between groups
75
+ this.mouseEnterHandler = (e) => {
76
+ var _a, _b;
77
+ if (this.props.hasSharedDragItem) {
78
+ this.onDragEnter(e);
79
+ }
80
+ else if (this.props.isDragCaptured) {
81
+ (_b = (_a = this.props).onDragTargetRestore) === null || _b === void 0 ? void 0 : _b.call(_a);
82
+ }
83
+ };
13
84
  this.mouseLeaveHandler = (e) => {
14
- var _a;
15
- const rect = ((_a = this.props.innerRef) === null || _a === void 0 ? void 0 : _a.current.getBoundingClientRect()) || {};
16
- if (rect.bottom <= e.clientY ||
17
- rect.top >= e.clientY ||
18
- rect.left >= e.clientX ||
19
- rect.right <= e.clientX) {
20
- this.dragReset();
85
+ var _a, _b;
86
+ if (this.props.hasSharedDragItem) {
87
+ this.onDragLeave(e);
88
+ (_b = (_a = this.props).onDragTargetRestore) === null || _b === void 0 ? void 0 : _b.call(_a);
21
89
  }
22
90
  };
23
- this.parentOnDrag = this.onDrag;
24
- this.onDrag = (i, x, y, sintE) => {
25
- this.parentOnDrag(i, x, y, sintE);
26
- this.mouseLeaveHandler(sintE.e);
91
+ this.mouseMoveHandler = (e) => {
92
+ if (this.props.hasSharedDragItem) {
93
+ this.onDragOver(e);
94
+ }
27
95
  };
96
+ this.mouseUpHandler = (e) => {
97
+ var _a, _b;
98
+ if (this.props.hasSharedDragItem) {
99
+ e.preventDefault();
100
+ const { droppingItem } = this.props;
101
+ const { layout } = this.state;
102
+ const item = layout.find((l) => l.i === droppingItem.i);
103
+ // reset dragEnter counter on drop
104
+ this.resetExternalPlaceholder();
105
+ (_b = (_a = this.props).onDrop) === null || _b === void 0 ? void 0 : _b.call(_a, layout, item, e);
106
+ }
107
+ };
108
+ this.parentOnDrag = this.onDrag;
109
+ this.onDrag = this.extendedOnDrag;
110
+ this.parentOnDragStop = this.onDragStop;
111
+ this.onDragStop = this.extendedOnDragStop;
28
112
  }
29
113
  componentDidMount() {
30
114
  var _a;
31
115
  (_a = super.componentDidMount) === null || _a === void 0 ? void 0 : _a.call(this);
32
- window.addEventListener('dragend', this.dragReset);
116
+ // If cursor is moved out of the window there is a bug
117
+ // which leaves placeholder element in grid, this action needed to reset this state
118
+ window.addEventListener('dragend', this.resetExternalPlaceholder);
119
+ const innerElement = this.getInnerElement();
120
+ if (innerElement) {
121
+ innerElement.addEventListener('mouseup', this.mouseUpHandler);
122
+ innerElement.addEventListener('mouseenter', this.mouseEnterHandler);
123
+ innerElement.addEventListener('mouseleave', this.mouseLeaveHandler);
124
+ innerElement.addEventListener('mousemove', this.mouseMoveHandler);
125
+ }
33
126
  }
34
127
  componentWillUnmount() {
35
- window.removeEventListener('dragend', this.dragReset);
128
+ window.removeEventListener('dragend', this.resetExternalPlaceholder);
129
+ const innerElement = this.getInnerElement();
130
+ if (innerElement) {
131
+ innerElement.removeEventListener('mouseup', this.mouseUpHandler);
132
+ innerElement.removeEventListener('mouseenter', this.mouseEnterHandler);
133
+ innerElement.removeEventListener('mouseleave', this.mouseLeaveHandler);
134
+ innerElement.removeEventListener('mousemove', this.mouseMoveHandler);
135
+ }
36
136
  }
137
+ // react-grid-layout doens't calculate it's height when last element is removed
138
+ // and just keeps the previous value
139
+ // so for autosize to work in that case we are resetting it's height value
37
140
  containerHeight() {
38
141
  if (this.props.autoSize && this.state.layout.length === 0) {
39
- return 'unset';
142
+ return;
40
143
  }
144
+ // eslint-disable-next-line consistent-return
41
145
  return super.containerHeight();
42
146
  }
147
+ // innerRef is passed by WithProvider without this wrapper there are only
148
+ // * findDOMNode - deprecated
149
+ // * rewrite whole ReactGridLayout.render method
150
+ // so in that case don't try to use this class on it's own
151
+ // or pass innerRef: React.MutableRef as it's not optional prop
152
+ getInnerElement() {
153
+ var _a;
154
+ return ((_a = this.props.innerRef) === null || _a === void 0 ? void 0 : _a.current) || null;
155
+ }
156
+ // Drop item from outside gets 0,0 droppingPosition
157
+ // centering cursor on newly creted grid item
158
+ // And cause grid-layout using it's own GridItem to make it look
159
+ // like overlay adding className
43
160
  processGridItem(child, isDroppingItem) {
44
161
  var _a;
45
162
  const gridItem = (_a = super.processGridItem) === null || _a === void 0 ? void 0 : _a.call(this, child, isDroppingItem);
163
+ if (!gridItem) {
164
+ return gridItem;
165
+ }
166
+ const { props: itemProps } = gridItem;
46
167
  if (isDroppingItem) {
47
- // Drop item from outside gets 0,0 droppingPosition
48
- // centering cursor on newly creted grid item
49
- // And cause grid-layout using it's own GridItem to make it look
50
- // like overlay adding className
51
- if (!gridItem)
52
- return null;
53
- const { props } = gridItem;
54
- const { containerWidth, cols, w, h, rowHeight, margin, transformScale } = props;
168
+ const { containerWidth, cols, w, h, rowHeight, margin, transformScale, droppingPosition, } = itemProps;
55
169
  const leftOffset = (((containerWidth / cols) * w) / 2 || 0) * transformScale;
56
170
  const topOffset = ((h * rowHeight + (h - 1) * margin[1]) / 2 || 0) * transformScale;
171
+ const style = gridItem.props.style || null;
172
+ // React.cloneElement is just cleaner then copy-paste whole processGridItem method
57
173
  return React.cloneElement(gridItem, {
174
+ // hiding previre if dragging shared item
175
+ style: this.props.hasSharedDragItem ? Object.assign(Object.assign({}, style), { opacity: 0 }) : style,
58
176
  className: OVERLAY_CLASS_NAME,
59
- droppingPosition: Object.assign(Object.assign({}, props.droppingPosition), { left: props.droppingPosition.left - leftOffset, top: props.droppingPosition.top - topOffset }),
177
+ droppingPosition: Object.assign(Object.assign({}, droppingPosition), { left: droppingPosition.left - leftOffset, top: droppingPosition.top - topOffset }),
60
178
  });
61
179
  }
62
180
  return gridItem;
@@ -1,12 +1,10 @@
1
1
  import React from 'react';
2
+ import { Ellipsis, Gear, Xmark } from '@gravity-ui/icons';
2
3
  import { Button, DropdownMenu, Icon, } from '@gravity-ui/uikit';
3
4
  import noop from 'lodash/noop';
4
- import { COPIED_WIDGET_STORE_KEY, MenuItems, OVERLAY_CONTROLS_CLASS_NAME } from '../../constants';
5
+ import { COPIED_WIDGET_STORE_KEY, MenuItems, OVERLAY_CONTROLS_CLASS_NAME, OVERLAY_ICON_SIZE, } from '../../constants';
5
6
  import { DashkitOvelayControlsContext } from '../../context/DashKitContext';
6
7
  import { i18n } from '../../i18n';
7
- import { CloseIcon } from '../../icons/CloseIcon';
8
- import { CogIcon } from '../../icons/CogIcon';
9
- import { DotsIcon } from '../../icons/DotsIcon';
10
8
  import { cn } from '../../utils/cn';
11
9
  import './OverlayControls.css';
12
10
  const b = cn(OVERLAY_CONTROLS_CLASS_NAME);
@@ -31,7 +29,7 @@ class OverlayControls extends React.Component {
31
29
  const { title, handler, icon, iconSize, qa } = item;
32
30
  const onItemClickHandler = typeof handler === 'function' ? handler : noop;
33
31
  return (React.createElement(Button, { key: index, view: view, size: size, title: title, pin: this.getControlItemPinStyle(index, length), onClick: () => onItemClickHandler(this.props.configItem), qa: qa },
34
- React.createElement(Icon, { data: icon || CogIcon, size: icon ? iconSize : 24 })));
32
+ React.createElement(Icon, { data: icon || Gear, size: icon ? iconSize : OVERLAY_ICON_SIZE })));
35
33
  };
36
34
  this.getDefaultControls = () => {
37
35
  const { view, size } = this.props;
@@ -39,7 +37,7 @@ class OverlayControls extends React.Component {
39
37
  return null;
40
38
  }
41
39
  return (React.createElement(Button, { view: view, size: size, title: i18n('label_settings'), pin: "round-brick", onClick: this.onEditItem, qa: "dashkit-overlay-control-settings" },
42
- React.createElement(Icon, { data: CogIcon, size: "24" })));
40
+ React.createElement(Icon, { data: Gear, size: OVERLAY_ICON_SIZE })));
43
41
  };
44
42
  this.getCustomLeftOverlayControls = () => {
45
43
  // выбираем только items-ы у которых проставлено поле `allWidgetsControls:true`
@@ -154,7 +152,7 @@ class OverlayControls extends React.Component {
154
152
  return dropdown;
155
153
  }
156
154
  return (React.createElement(Button, { key: 'delete-control', view: view, size: size, title: i18n('label_delete'), pin: isOnlyOneItem ? 'round-round' : 'brick-round', onClick: this.onRemoveItem, qa: "dashkit-overlay-control-menu" },
157
- React.createElement(Icon, { data: CloseIcon, size: "12" })));
155
+ React.createElement(Icon, { data: Xmark, size: OVERLAY_ICON_SIZE })));
158
156
  }
159
157
  isDefaultMenu(menu) {
160
158
  return menu === null || menu === void 0 ? void 0 : menu.every((item) => Object.values(MenuItems).includes(String(item)));
@@ -202,7 +200,7 @@ class OverlayControls extends React.Component {
202
200
  return null;
203
201
  }
204
202
  return (React.createElement(DropdownMenu, { items: items, renderSwitcher: (props) => (React.createElement(Button, Object.assign({}, props, { view: view, size: size, pin: isOnlyOneItem ? 'round-round' : 'brick-round', qa: "dashkit-overlay-control-menu" }),
205
- React.createElement(Icon, { data: DotsIcon, size: "16" }))) }));
203
+ React.createElement(Icon, { data: Ellipsis, size: OVERLAY_ICON_SIZE }))) }));
206
204
  }
207
205
  getControlItemPinStyle(index, itemsLength) {
208
206
  const isOnlyOneItem = itemsLength === 1;
@@ -2,6 +2,7 @@ export declare const COPIED_WIDGET_STORE_KEY = "dashCopiedItem";
2
2
  export declare const DEFAULT_NAMESPACE = "default";
3
3
  export declare const OVERLAY_CONTROLS_CLASS_NAME = "dashkit-overlay-controls";
4
4
  export declare const OVERLAY_CLASS_NAME = "dashkit-grid-item__overlay";
5
+ export declare const OVERLAY_ICON_SIZE = 16;
5
6
  export declare const TEMPORARY_ITEM_ID = "__dropping-elem__";
6
7
  export declare const MenuItems: {
7
8
  readonly Copy: "copy";
@@ -2,6 +2,7 @@ export const COPIED_WIDGET_STORE_KEY = 'dashCopiedItem';
2
2
  export const DEFAULT_NAMESPACE = 'default';
3
3
  export const OVERLAY_CONTROLS_CLASS_NAME = 'dashkit-overlay-controls';
4
4
  export const OVERLAY_CLASS_NAME = 'dashkit-grid-item__overlay';
5
+ export const OVERLAY_ICON_SIZE = 16;
5
6
  export const TEMPORARY_ITEM_ID = '__dropping-elem__';
6
7
  export const MenuItems = {
7
8
  Copy: 'copy',
@@ -29,7 +29,7 @@ function useMemoStateContext(props) {
29
29
  isEqual(groups, props.groups))) {
30
30
  props.onChange({ config, itemsStateAndParams, groups });
31
31
  }
32
- }, [props.config, props.itemsStateAndParams, props.onChange]);
32
+ }, [props.config, props.groups, props.itemsStateAndParams, props.onChange]);
33
33
  // каллбэк вызывающийся при изменение лэйаута сетки, первым аргументом приходит актуальный конфиг лэйаута,
34
34
  // т.е. если на текущей сетке есть виджеты, с активированной опцией автовысоты, их параметр "h" будет
35
35
  // "подстроенный"; чтобы, для сохранения в сторе "ушли" значения без учёта подстройки (как если бы у этих
@@ -37,7 +37,17 @@ function useMemoStateContext(props) {
37
37
  const onLayoutChange = React.useCallback((layout) => {
38
38
  const currentInnerLayout = layout.map((item) => {
39
39
  if (item.i in originalLayouts.current) {
40
- return Object.assign(Object.assign({}, originalLayouts.current[item.i]), { w: item.w, x: item.x, y: item.y });
40
+ // eslint-disable-next-line no-unused-vars
41
+ const _a = originalLayouts.current[item.i], { parent } = _a, originalCopy = __rest(_a, ["parent"]);
42
+ // Updating original if parent has changed and saving copy as original
43
+ // or leaving default
44
+ if (item.parent) {
45
+ originalCopy.parent = item.parent;
46
+ }
47
+ originalCopy.w = item.w;
48
+ originalCopy.x = item.x;
49
+ originalCopy.y = item.y;
50
+ return originalCopy;
41
51
  }
42
52
  else {
43
53
  return Object.assign({}, item);
@@ -234,16 +244,24 @@ function useMemoStateContext(props) {
234
244
  return null;
235
245
  }
236
246
  }, [dragProps, props.registerManager]);
237
- const onDropDragOver = React.useCallback((_e, gridProps, groupLayout) => {
247
+ const onDropDragOver = React.useCallback((_e, gridProps, groupLayout, sharedItem) => {
238
248
  if (temporaryLayout) {
239
249
  resetTemporaryLayout();
240
250
  return false;
241
251
  }
242
- if (!dragOverPlugin) {
252
+ let defaultLayout;
253
+ if (sharedItem) {
254
+ const { type, h, w } = sharedItem;
255
+ const _defaults = props.registerManager.getItem(type);
256
+ defaultLayout = _defaults ? Object.assign(Object.assign({}, _defaults.defaultLayout), { h, w }) : { h, w };
257
+ }
258
+ else if (dragOverPlugin) {
259
+ defaultLayout = dragOverPlugin.defaultLayout;
260
+ }
261
+ else {
243
262
  return false;
244
263
  }
245
264
  let maxW = gridProps.cols;
246
- const { defaultLayout } = dragOverPlugin;
247
265
  const maxH = Math.min(gridProps.maxRows || Infinity, defaultLayout.maxH || Infinity);
248
266
  if (gridProps.compactType === COMPACT_TYPE_HORIZONTAL_NOWRAP) {
249
267
  maxW = groupLayout.reduce((memo, item) => memo - item.w, gridProps.cols);
@@ -254,7 +272,7 @@ function useMemoStateContext(props) {
254
272
  maxH < defaultLayout.minH) {
255
273
  return false;
256
274
  }
257
- const { h = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.h) || DEFAULT_WIDGET_HEIGHT, w = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.w) || DEFAULT_WIDGET_WIDTH, } = dragProps.layout || {};
275
+ const { h = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.h) || DEFAULT_WIDGET_HEIGHT, w = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.w) || DEFAULT_WIDGET_WIDTH, } = (dragProps === null || dragProps === void 0 ? void 0 : dragProps.layout) || {};
258
276
  return {
259
277
  h: maxH ? Math.min(h, maxH) : h,
260
278
  w: maxW ? Math.min(w, maxW) : w,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.8.1",
3
+ "version": "8.9.1",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare function CloseIcon(props: React.SVGProps<SVGSVGElement>): JSX.Element;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CloseIcon = void 0;
4
- const tslib_1 = require("tslib");
5
- const react_1 = tslib_1.__importDefault(require("react"));
6
- function CloseIcon(props) {
7
- return (react_1.default.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 10 10", width: "10", height: "10", fill: "currentColor" }, props),
8
- react_1.default.createElement("path", { d: "M9.75592 8.57741C10.0814 8.90285 10.0814 9.43049 9.75592 9.75592C9.43049 10.0814 8.90285 10.0814 8.57741 9.75592L5 6.17851L1.42259 9.75592C1.09715 10.0814 0.569515 10.0814 0.244078 9.75592C-0.0813592 9.43049 -0.0813592 8.90285 0.244078 8.57741L3.82149 5L0.244078 1.42259C-0.0813592 1.09715 -0.0813592 0.569515 0.244078 0.244078C0.569515 -0.0813592 1.09715 -0.0813592 1.42259 0.244078L5 3.82149L8.57741 0.244078C8.90285 -0.0813592 9.43049 -0.0813592 9.75592 0.244078C10.0814 0.569515 10.0814 1.09715 9.75592 1.42259L6.17851 5L9.75592 8.57741Z" })));
9
- }
10
- exports.CloseIcon = CloseIcon;
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare function CogIcon(props: React.SVGProps<SVGSVGElement>): JSX.Element;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CogIcon = void 0;
4
- const tslib_1 = require("tslib");
5
- const react_1 = tslib_1.__importDefault(require("react"));
6
- function CogIcon(props) {
7
- return (react_1.default.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24", fill: "currentColor" }, props),
8
- react_1.default.createElement("path", { d: "M11.844 16.156a4 4 0 1 1 0-8 4 4 0 0 1 0 8m6-4c0-.029-.004-.058-.004-.087l1.848-.34-.362-1.968-1.852.342a5.992 5.992 0 0 0-1.454-2.246l1.068-1.55-1.646-1.134-1.07 1.55a5.95 5.95 0 0 0-2.528-.567c-.03 0-.058.004-.087.004l-.341-1.848-1.967.363.34 1.851A5.996 5.996 0 0 0 7.546 7.98l-1.55-1.068L4.86 8.558l1.55 1.07a5.95 5.95 0 0 0-.567 2.528c0 .03.004.058.004.087L4 12.584l.362 1.967 1.852-.342a5.992 5.992 0 0 0 1.454 2.246L6.6 18.005l1.646 1.134 1.069-1.55a5.95 5.95 0 0 0 2.529.567c.029 0 .058-.004.087-.004L12.27 20l1.968-.363-.341-1.85a5.996 5.996 0 0 0 2.245-1.455l1.55 1.068 1.134-1.646-1.55-1.069a5.95 5.95 0 0 0 .567-2.529" })));
9
- }
10
- exports.CogIcon = CogIcon;
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare function CopyIcon(props: React.SVGProps<SVGSVGElement>): JSX.Element;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CopyIcon = void 0;
4
- const tslib_1 = require("tslib");
5
- const react_1 = tslib_1.__importDefault(require("react"));
6
- function CopyIcon(props) {
7
- return (react_1.default.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", width: "16", height: "16", fill: "currentColor" }, props),
8
- react_1.default.createElement("path", { d: "M7 14h7V7H7v7zM5 5h11v11H5V5zm4-2v1-1zm1-3H0v10V0h10zM0 10v1h4-4v-1zM10 0h1v4-4h-1zM3 9h1-1zM0 0h11v4H9V2H2v7h2v2H0V0z" })));
9
- }
10
- exports.CopyIcon = CopyIcon;
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare function DeleteIcon(props: React.SVGProps<SVGSVGElement>): JSX.Element;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeleteIcon = void 0;
4
- const tslib_1 = require("tslib");
5
- const react_1 = tslib_1.__importDefault(require("react"));
6
- function DeleteIcon(props) {
7
- return (react_1.default.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", width: "16", height: "16", fill: "currentColor" }, props),
8
- react_1.default.createElement("g", null,
9
- react_1.default.createElement("path", { d: "M13.29 1.605h-2.857V.522A.522.522 0 0 0 9.91 0H6.089a.522.522 0 0 0-.522.522v1.083H2.71a.522.522 0 0 0-.521.522v1.605a.52.52 0 0 0 .521.521h.159L3.345 15.5c.012.28.242.5.521.5h8.268c.28 0 .51-.22.521-.5l.477-11.247h.159a.522.522 0 0 0 .521-.521V2.127a.522.522 0 0 0-.521-.522zm-6.679-.562h2.778v.562H6.611v-.562zm5.023 13.914H4.366L3.912 4.253h8.176l-.454 10.704zM12.769 3.21H3.23v-.562h9.538v.562z" }),
10
- react_1.default.createElement("path", { d: "M5.901 5.853a.522.522 0 0 0-.522.522v6.46a.522.522 0 0 0 1.044 0v-6.46a.522.522 0 0 0-.522-.522zm2.099 0a.522.522 0 0 0-.522.522v6.46a.522.522 0 1 0 1.044 0v-6.46A.522.522 0 0 0 8 5.853zm2.099 0a.522.522 0 0 0-.522.522v6.46a.522.522 0 0 0 1.044 0v-6.46a.522.522 0 0 0-.522-.522z" }))));
11
- }
12
- exports.DeleteIcon = DeleteIcon;
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare function DotsIcon(props: React.SVGProps<SVGSVGElement>): JSX.Element;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DotsIcon = void 0;
4
- const tslib_1 = require("tslib");
5
- const react_1 = tslib_1.__importDefault(require("react"));
6
- function DotsIcon(props) {
7
- return (react_1.default.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", width: "16", height: "16", fill: "currentColor" }, props),
8
- react_1.default.createElement("path", { d: "M14 6.125a1.874 1.874 0 1 1 .001 3.749A1.874 1.874 0 0 1 14 6.125zm-5.906 0a1.874 1.874 0 1 1 0 3.749 1.874 1.874 0 0 1 0-3.749zM2 6.125a1.874 1.874 0 1 1 .001 3.749A1.874 1.874 0 0 1 2 6.125z" })));
9
- }
10
- exports.DotsIcon = DotsIcon;
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare function TickIcon(props: React.SVGProps<SVGSVGElement>): JSX.Element;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TickIcon = void 0;
4
- const tslib_1 = require("tslib");
5
- const react_1 = tslib_1.__importDefault(require("react"));
6
- function TickIcon(props) {
7
- return (react_1.default.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", width: "16", height: "16", fill: "currentColor" }, props),
8
- react_1.default.createElement("path", { fillRule: "evenodd", d: "M5.95 11.008L1.863 6.572.392 7.927l5.533 6.003 9.67-10.114-1.444-1.381z" })));
9
- }
10
- exports.TickIcon = TickIcon;