@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
@@ -57,6 +57,7 @@
57
57
  transition: none;
58
58
  z-index: 3;
59
59
  will-change: transform;
60
+ pointer-events: none;
60
61
  }
61
62
 
62
63
  .react-grid-item.dashkit-grid-item_is-focused {
@@ -5,6 +5,8 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
5
5
  state: {
6
6
  isDragging: boolean;
7
7
  isPageHidden: boolean;
8
+ currentDraggingElement: null;
9
+ draggedOverGroup: null;
8
10
  };
9
11
  componentDidMount(): void;
10
12
  componentDidUpdate(): void;
@@ -36,10 +38,14 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
36
38
  getMemoForwardRefCallback: (refIndex: any) => any;
37
39
  mergeGroupsLayout(group: any, newLayout: any, temporaryItem: any): any;
38
40
  reloadItems(): void;
39
- _onStart: () => void;
41
+ _onDragStart: (group: any, _newLayout: any, layoutItem: any) => void;
42
+ _onResizeStart: () => void;
43
+ _onTargetRestore: () => void;
40
44
  _onStop: (group: any, newLayout: any) => void;
41
- _onDropDragOver: (group: any, e: any) => any;
45
+ _onSharedDrop: (targetGroup: any, newLayout: any, tempItem: any) => void;
46
+ _onExternalDrop: (group: any, newLayout: any, item: any, e: any) => void;
42
47
  _onDrop: (group: any, newLayout: any, item: any, e: any) => false | undefined;
48
+ _onDropDragOver: (group: any, e: any) => any;
43
49
  renderTemporaryPlaceholder(): JSX.Element | null;
44
50
  renderGroup(group: any, renderLayout: any, renderItems: any, offset: number | undefined, groupGridProperties: any): JSX.Element;
45
51
  render(): any;
@@ -56,17 +56,18 @@ class GridLayout extends react_1.default.PureComponent {
56
56
  };
57
57
  this.getMemoGroupCallbacks = (group) => {
58
58
  if (!this._memoCallbacksForGroups[group]) {
59
- const onStart = this._onStart;
59
+ const onDragStart = this._onDragStart.bind(this, group);
60
60
  const onStop = this._onStop.bind(this, group);
61
61
  const onDrop = this._onDrop.bind(this, group);
62
62
  const onDropDragOver = this._onDropDragOver.bind(this, group);
63
+ const onDragTargetRestore = this._onTargetRestore.bind(this, group);
63
64
  this._memoCallbacksForGroups[group] = {
64
- onDragStart: onStart,
65
- onResizeStart: onStart,
65
+ onDragStart,
66
66
  onDragStop: onStop,
67
67
  onResizeStop: onStop,
68
- onDrop: onDrop,
68
+ onDrop,
69
69
  onDropDragOver,
70
+ onDragTargetRestore,
70
71
  };
71
72
  }
72
73
  return this._memoCallbacksForGroups[group];
@@ -93,48 +94,131 @@ class GridLayout extends react_1.default.PureComponent {
93
94
  }
94
95
  return this._memoForwardedPluginRef[refIndex];
95
96
  };
96
- this._onStart = () => {
97
+ this._onDragStart = (group, _newLayout, layoutItem) => {
97
98
  if (this.temporaryLayout)
98
99
  return;
99
- this.setState({ isDragging: true });
100
+ if (this.context.dragOverPlugin) {
101
+ this.setState({ isDragging: true });
102
+ }
103
+ else {
104
+ let currentDraggingElement = this.state.currentDraggingElement;
105
+ if (!currentDraggingElement) {
106
+ const _id = layoutItem.i;
107
+ const item = this.context.config.items.find(({ id }) => id === _id);
108
+ currentDraggingElement = [group, layoutItem, item];
109
+ }
110
+ this.setState({
111
+ isDragging: true,
112
+ currentDraggingElement,
113
+ draggedOverGroup: group,
114
+ });
115
+ }
116
+ };
117
+ this._onResizeStart = () => {
118
+ this.setState({
119
+ isDragging: true,
120
+ });
121
+ };
122
+ this._onTargetRestore = () => {
123
+ const { currentDraggingElement } = this.state;
124
+ if (currentDraggingElement) {
125
+ this.setState({
126
+ draggedOverGroup: currentDraggingElement[0],
127
+ });
128
+ }
100
129
  };
101
130
  this._onStop = (group, newLayout) => {
102
131
  const { layoutChange, onDrop, temporaryLayout } = this.context;
132
+ const { draggedOverGroup, currentDraggingElement } = this.state;
133
+ if (currentDraggingElement &&
134
+ draggedOverGroup !== null &&
135
+ draggedOverGroup !== currentDraggingElement[0]) {
136
+ // Skipping layout update when change event called for source grid
137
+ // and waiting _onDrop
138
+ return;
139
+ }
103
140
  const groupedLayout = this.mergeGroupsLayout(group, newLayout);
141
+ this.setState({
142
+ isDragging: false,
143
+ currentDraggingElement: null,
144
+ draggedOverGroup: null,
145
+ });
104
146
  if (temporaryLayout) {
105
147
  onDrop === null || onDrop === void 0 ? void 0 : onDrop(groupedLayout, groupedLayout.find(({ i }) => i === constants_1.TEMPORARY_ITEM_ID));
106
148
  }
107
149
  else {
108
150
  layoutChange(groupedLayout);
109
151
  }
110
- this.setState({ isDragging: false });
111
152
  };
112
- this._onDropDragOver = (group, e) => {
113
- const { editMode, dragOverPlugin } = this.context;
114
- if (!editMode || !dragOverPlugin) {
115
- return false;
153
+ this._onSharedDrop = (targetGroup, newLayout, tempItem) => {
154
+ const { currentDraggingElement } = this.state;
155
+ const { layoutChange } = this.context;
156
+ if (!currentDraggingElement) {
157
+ return;
116
158
  }
117
- const { properties, layout } = this.getLayoutAndPropsByGroup(group);
118
- return this.context.onDropDragOver(e, properties, layout);
159
+ const [, sourceItem] = currentDraggingElement;
160
+ const groupedLayout = this.mergeGroupsLayout(targetGroup, newLayout, tempItem).map((item) => {
161
+ if (item.i === sourceItem.i) {
162
+ const copy = Object.assign({}, tempItem);
163
+ delete copy.parent;
164
+ if (targetGroup !== constants_1.DEFAULT_GROUP) {
165
+ copy.parent = targetGroup;
166
+ }
167
+ copy.i = sourceItem.i;
168
+ return copy;
169
+ }
170
+ return item;
171
+ });
172
+ this.setState({
173
+ isDragging: false,
174
+ currentDraggingElement: null,
175
+ draggedOverGroup: null,
176
+ });
177
+ layoutChange(groupedLayout);
178
+ };
179
+ this._onExternalDrop = (group, newLayout, item, e) => {
180
+ const { onDrop } = this.context;
181
+ if (group !== constants_1.DEFAULT_GROUP) {
182
+ item.parent = group;
183
+ }
184
+ const groupedLayout = this.mergeGroupsLayout(group, newLayout, item);
185
+ this.setState({ isDragging: false });
186
+ onDrop === null || onDrop === void 0 ? void 0 : onDrop(groupedLayout, item, e);
119
187
  };
120
188
  this._onDrop = (group, newLayout, item, e) => {
121
- if (!item) {
189
+ if (!item || !this.context.editMode) {
122
190
  return false;
123
191
  }
124
- const { editMode, onDrop } = this.context;
125
- if (!editMode) {
192
+ const { draggedOverGroup, currentDraggingElement } = this.state;
193
+ if (currentDraggingElement && draggedOverGroup === group) {
194
+ this._onSharedDrop(group, newLayout, item);
195
+ }
196
+ else {
197
+ this._onExternalDrop(group, newLayout, item, e);
198
+ }
199
+ };
200
+ this._onDropDragOver = (group, e) => {
201
+ const { editMode, dragOverPlugin, onDropDragOver } = this.context;
202
+ const { currentDraggingElement } = this.state;
203
+ if (!editMode || (!dragOverPlugin && !currentDraggingElement)) {
126
204
  return false;
127
205
  }
128
- if (group !== constants_1.DEFAULT_GROUP) {
129
- item.parent = group;
206
+ const { properties, layout } = this.getLayoutAndPropsByGroup(group);
207
+ if (currentDraggingElement) {
208
+ const [, { h, w, i }, { type }] = currentDraggingElement;
209
+ return onDropDragOver(e, properties, layout, { h, w, i, type });
130
210
  }
131
- const groupedLayout = this.mergeGroupsLayout(group, newLayout, item);
132
- onDrop === null || onDrop === void 0 ? void 0 : onDrop(groupedLayout, item, e);
211
+ if (dragOverPlugin) {
212
+ return onDropDragOver(e, properties, layout);
213
+ }
214
+ return false;
133
215
  };
134
216
  this.pluginsRefs = [];
135
217
  this.state = {
136
218
  isDragging: false,
137
219
  isPageHidden: false,
220
+ currentDraggingElement: null,
221
+ draggedOverGroup: null,
138
222
  };
139
223
  }
140
224
  componentDidMount() {
@@ -204,6 +288,7 @@ class GridLayout extends react_1.default.PureComponent {
204
288
  }
205
289
  renderGroup(group, renderLayout, renderItems, offset = 0, groupGridProperties) {
206
290
  const { registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, } = this.context;
291
+ const { currentDraggingElement, draggedOverGroup } = this.state;
207
292
  const properties = groupGridProperties
208
293
  ? groupGridProperties(Object.assign({}, registerManager.gridLayout))
209
294
  : registerManager.gridLayout;
@@ -212,13 +297,16 @@ class GridLayout extends react_1.default.PureComponent {
212
297
  compactType = 'horizontal';
213
298
  }
214
299
  const { callbacks, layout } = this.getMemoGroupProps(group, renderLayout, properties);
215
- return (react_1.default.createElement(ReactGridLayout_1.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
300
+ const hasSharedDragItem = Boolean(currentDraggingElement && currentDraggingElement[0] !== group);
301
+ const isDragCaptured = currentDraggingElement &&
302
+ group === currentDraggingElement[0] &&
303
+ draggedOverGroup !== null &&
304
+ draggedOverGroup !== group;
305
+ return (react_1.default.createElement(ReactGridLayout_1.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
216
306
  ? { draggableHandle: `.${draggableHandleClassName}` }
217
307
  : null), (outerDnDEnable
218
308
  ? {
219
309
  isDroppable: true,
220
- onDropDragOver: callbacks.onDropDragOver,
221
- onDrop: callbacks.onDrop,
222
310
  }
223
311
  : null), { draggableCancel: `.${constants_1.OVERLAY_CONTROLS_CLASS_NAME}` }),
224
312
  renderItems.map((item, i) => {
@@ -8,59 +8,177 @@ const constants_1 = require("../../constants");
8
8
  class DragOverLayout extends react_grid_layout_1.default {
9
9
  constructor(...args) {
10
10
  super(...args);
11
- this.dragReset = () => {
11
+ this._savedDraggedOutLayout = null;
12
+ // Reset placeholder when item dragged from outside
13
+ this.resetExternalPlaceholder = () => {
12
14
  if (this.dragEnterCounter) {
13
15
  this.dragEnterCounter = 0;
14
16
  this.removeDroppingPlaceholder();
15
17
  }
16
18
  };
19
+ // Hide placeholder when element is dragged out
20
+ this.hideLocalPlaceholder = (i) => {
21
+ const { layout } = this.state;
22
+ const { cols } = this.props;
23
+ const savedLayout = layout.map((item) => (Object.assign({}, item)));
24
+ let hiddenElement;
25
+ const newLayout = react_grid_layout_1.utils.compact(layout.filter((item) => {
26
+ if (item.i === i) {
27
+ hiddenElement = item;
28
+ return false;
29
+ }
30
+ return true;
31
+ }), react_grid_layout_1.utils.compactType(this.props), cols);
32
+ if (hiddenElement) {
33
+ newLayout.push(hiddenElement);
34
+ }
35
+ this.setState({
36
+ activeDrag: null,
37
+ layout: newLayout,
38
+ });
39
+ return savedLayout;
40
+ };
41
+ this.extendedOnDrag = (i, x, y, sintEv) => {
42
+ if (this.props.isDragCaptured) {
43
+ if (!this._savedDraggedOutLayout) {
44
+ this._savedDraggedOutLayout = this.hideLocalPlaceholder(i);
45
+ }
46
+ return;
47
+ }
48
+ this._savedDraggedOutLayout = null;
49
+ // parent onDrag will show new placeholder again
50
+ this.parentOnDrag(i, x, y, sintEv);
51
+ };
52
+ this.extendedOnDragStop = (i, x, y, sintEv) => {
53
+ // Restoring layout if item was dropped outside of the grid
54
+ if (this._savedDraggedOutLayout) {
55
+ const savedLayout = this._savedDraggedOutLayout;
56
+ const l = react_grid_layout_1.utils.getLayoutItem(savedLayout, i);
57
+ // Create placeholder (display only)
58
+ const placeholder = {
59
+ w: l.w,
60
+ h: l.h,
61
+ x: l.x,
62
+ y: l.y,
63
+ placeholder: true,
64
+ i: i,
65
+ };
66
+ this.setState({
67
+ layout: savedLayout,
68
+ activeDrag: placeholder,
69
+ }, () => {
70
+ this.parentOnDragStop(i, x, y, sintEv);
71
+ });
72
+ this._savedDraggedOutLayout = null;
73
+ }
74
+ else {
75
+ this.parentOnDragStop(i, x, y, sintEv);
76
+ }
77
+ };
78
+ // Proxy mouse events -> drag methods for dnd between groups
79
+ this.mouseEnterHandler = (e) => {
80
+ var _a, _b;
81
+ if (this.props.hasSharedDragItem) {
82
+ this.onDragEnter(e);
83
+ }
84
+ else if (this.props.isDragCaptured) {
85
+ (_b = (_a = this.props).onDragTargetRestore) === null || _b === void 0 ? void 0 : _b.call(_a);
86
+ }
87
+ };
17
88
  this.mouseLeaveHandler = (e) => {
18
- var _a;
19
- const rect = ((_a = this.props.innerRef) === null || _a === void 0 ? void 0 : _a.current.getBoundingClientRect()) || {};
20
- if (rect.bottom <= e.clientY ||
21
- rect.top >= e.clientY ||
22
- rect.left >= e.clientX ||
23
- rect.right <= e.clientX) {
24
- this.dragReset();
89
+ var _a, _b;
90
+ if (this.props.hasSharedDragItem) {
91
+ this.onDragLeave(e);
92
+ (_b = (_a = this.props).onDragTargetRestore) === null || _b === void 0 ? void 0 : _b.call(_a);
25
93
  }
26
94
  };
27
- this.parentOnDrag = this.onDrag;
28
- this.onDrag = (i, x, y, sintE) => {
29
- this.parentOnDrag(i, x, y, sintE);
30
- this.mouseLeaveHandler(sintE.e);
95
+ this.mouseMoveHandler = (e) => {
96
+ if (this.props.hasSharedDragItem) {
97
+ this.onDragOver(e);
98
+ }
31
99
  };
100
+ this.mouseUpHandler = (e) => {
101
+ var _a, _b;
102
+ if (this.props.hasSharedDragItem) {
103
+ e.preventDefault();
104
+ const { droppingItem } = this.props;
105
+ const { layout } = this.state;
106
+ const item = layout.find((l) => l.i === droppingItem.i);
107
+ // reset dragEnter counter on drop
108
+ this.resetExternalPlaceholder();
109
+ (_b = (_a = this.props).onDrop) === null || _b === void 0 ? void 0 : _b.call(_a, layout, item, e);
110
+ }
111
+ };
112
+ this.parentOnDrag = this.onDrag;
113
+ this.onDrag = this.extendedOnDrag;
114
+ this.parentOnDragStop = this.onDragStop;
115
+ this.onDragStop = this.extendedOnDragStop;
32
116
  }
33
117
  componentDidMount() {
34
118
  var _a;
35
119
  (_a = super.componentDidMount) === null || _a === void 0 ? void 0 : _a.call(this);
36
- window.addEventListener('dragend', this.dragReset);
120
+ // If cursor is moved out of the window there is a bug
121
+ // which leaves placeholder element in grid, this action needed to reset this state
122
+ window.addEventListener('dragend', this.resetExternalPlaceholder);
123
+ const innerElement = this.getInnerElement();
124
+ if (innerElement) {
125
+ innerElement.addEventListener('mouseup', this.mouseUpHandler);
126
+ innerElement.addEventListener('mouseenter', this.mouseEnterHandler);
127
+ innerElement.addEventListener('mouseleave', this.mouseLeaveHandler);
128
+ innerElement.addEventListener('mousemove', this.mouseMoveHandler);
129
+ }
37
130
  }
38
131
  componentWillUnmount() {
39
- window.removeEventListener('dragend', this.dragReset);
132
+ window.removeEventListener('dragend', this.resetExternalPlaceholder);
133
+ const innerElement = this.getInnerElement();
134
+ if (innerElement) {
135
+ innerElement.removeEventListener('mouseup', this.mouseUpHandler);
136
+ innerElement.removeEventListener('mouseenter', this.mouseEnterHandler);
137
+ innerElement.removeEventListener('mouseleave', this.mouseLeaveHandler);
138
+ innerElement.removeEventListener('mousemove', this.mouseMoveHandler);
139
+ }
40
140
  }
141
+ // react-grid-layout doens't calculate it's height when last element is removed
142
+ // and just keeps the previous value
143
+ // so for autosize to work in that case we are resetting it's height value
41
144
  containerHeight() {
42
145
  if (this.props.autoSize && this.state.layout.length === 0) {
43
- return 'unset';
146
+ return;
44
147
  }
148
+ // eslint-disable-next-line consistent-return
45
149
  return super.containerHeight();
46
150
  }
151
+ // innerRef is passed by WithProvider without this wrapper there are only
152
+ // * findDOMNode - deprecated
153
+ // * rewrite whole ReactGridLayout.render method
154
+ // so in that case don't try to use this class on it's own
155
+ // or pass innerRef: React.MutableRef as it's not optional prop
156
+ getInnerElement() {
157
+ var _a;
158
+ return ((_a = this.props.innerRef) === null || _a === void 0 ? void 0 : _a.current) || null;
159
+ }
160
+ // Drop item from outside gets 0,0 droppingPosition
161
+ // centering cursor on newly creted grid item
162
+ // And cause grid-layout using it's own GridItem to make it look
163
+ // like overlay adding className
47
164
  processGridItem(child, isDroppingItem) {
48
165
  var _a;
49
166
  const gridItem = (_a = super.processGridItem) === null || _a === void 0 ? void 0 : _a.call(this, child, isDroppingItem);
167
+ if (!gridItem) {
168
+ return gridItem;
169
+ }
170
+ const { props: itemProps } = gridItem;
50
171
  if (isDroppingItem) {
51
- // Drop item from outside gets 0,0 droppingPosition
52
- // centering cursor on newly creted grid item
53
- // And cause grid-layout using it's own GridItem to make it look
54
- // like overlay adding className
55
- if (!gridItem)
56
- return null;
57
- const { props } = gridItem;
58
- const { containerWidth, cols, w, h, rowHeight, margin, transformScale } = props;
172
+ const { containerWidth, cols, w, h, rowHeight, margin, transformScale, droppingPosition, } = itemProps;
59
173
  const leftOffset = (((containerWidth / cols) * w) / 2 || 0) * transformScale;
60
174
  const topOffset = ((h * rowHeight + (h - 1) * margin[1]) / 2 || 0) * transformScale;
175
+ const style = gridItem.props.style || null;
176
+ // React.cloneElement is just cleaner then copy-paste whole processGridItem method
61
177
  return react_1.default.cloneElement(gridItem, {
178
+ // hiding previre if dragging shared item
179
+ style: this.props.hasSharedDragItem ? Object.assign(Object.assign({}, style), { opacity: 0 }) : style,
62
180
  className: constants_1.OVERLAY_CLASS_NAME,
63
- droppingPosition: Object.assign(Object.assign({}, props.droppingPosition), { left: props.droppingPosition.left - leftOffset, top: props.droppingPosition.top - topOffset }),
181
+ droppingPosition: Object.assign(Object.assign({}, droppingPosition), { left: droppingPosition.left - leftOffset, top: droppingPosition.top - topOffset }),
64
182
  });
65
183
  }
66
184
  return gridItem;
@@ -3,14 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OverlayControlsPosition = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
+ const icons_1 = require("@gravity-ui/icons");
6
7
  const uikit_1 = require("@gravity-ui/uikit");
7
8
  const noop_1 = tslib_1.__importDefault(require("lodash/noop"));
8
9
  const constants_1 = require("../../constants");
9
10
  const DashKitContext_1 = require("../../context/DashKitContext");
10
11
  const i18n_1 = require("../../i18n");
11
- const CloseIcon_1 = require("../../icons/CloseIcon");
12
- const CogIcon_1 = require("../../icons/CogIcon");
13
- const DotsIcon_1 = require("../../icons/DotsIcon");
14
12
  const cn_1 = require("../../utils/cn");
15
13
  const b = (0, cn_1.cn)(constants_1.OVERLAY_CONTROLS_CLASS_NAME);
16
14
  var OverlayControlsPosition;
@@ -34,7 +32,7 @@ class OverlayControls extends react_1.default.Component {
34
32
  const { title, handler, icon, iconSize, qa } = item;
35
33
  const onItemClickHandler = typeof handler === 'function' ? handler : noop_1.default;
36
34
  return (react_1.default.createElement(uikit_1.Button, { key: index, view: view, size: size, title: title, pin: this.getControlItemPinStyle(index, length), onClick: () => onItemClickHandler(this.props.configItem), qa: qa },
37
- react_1.default.createElement(uikit_1.Icon, { data: icon || CogIcon_1.CogIcon, size: icon ? iconSize : 24 })));
35
+ react_1.default.createElement(uikit_1.Icon, { data: icon || icons_1.Gear, size: icon ? iconSize : constants_1.OVERLAY_ICON_SIZE })));
38
36
  };
39
37
  this.getDefaultControls = () => {
40
38
  const { view, size } = this.props;
@@ -42,7 +40,7 @@ class OverlayControls extends react_1.default.Component {
42
40
  return null;
43
41
  }
44
42
  return (react_1.default.createElement(uikit_1.Button, { view: view, size: size, title: (0, i18n_1.i18n)('label_settings'), pin: "round-brick", onClick: this.onEditItem, qa: "dashkit-overlay-control-settings" },
45
- react_1.default.createElement(uikit_1.Icon, { data: CogIcon_1.CogIcon, size: "24" })));
43
+ react_1.default.createElement(uikit_1.Icon, { data: icons_1.Gear, size: constants_1.OVERLAY_ICON_SIZE })));
46
44
  };
47
45
  this.getCustomLeftOverlayControls = () => {
48
46
  // выбираем только items-ы у которых проставлено поле `allWidgetsControls:true`
@@ -157,7 +155,7 @@ class OverlayControls extends react_1.default.Component {
157
155
  return dropdown;
158
156
  }
159
157
  return (react_1.default.createElement(uikit_1.Button, { key: 'delete-control', view: view, size: size, title: (0, i18n_1.i18n)('label_delete'), pin: isOnlyOneItem ? 'round-round' : 'brick-round', onClick: this.onRemoveItem, qa: "dashkit-overlay-control-menu" },
160
- react_1.default.createElement(uikit_1.Icon, { data: CloseIcon_1.CloseIcon, size: "12" })));
158
+ react_1.default.createElement(uikit_1.Icon, { data: icons_1.Xmark, size: constants_1.OVERLAY_ICON_SIZE })));
161
159
  }
162
160
  isDefaultMenu(menu) {
163
161
  return menu === null || menu === void 0 ? void 0 : menu.every((item) => Object.values(constants_1.MenuItems).includes(String(item)));
@@ -205,7 +203,7 @@ class OverlayControls extends react_1.default.Component {
205
203
  return null;
206
204
  }
207
205
  return (react_1.default.createElement(uikit_1.DropdownMenu, { items: items, renderSwitcher: (props) => (react_1.default.createElement(uikit_1.Button, Object.assign({}, props, { view: view, size: size, pin: isOnlyOneItem ? 'round-round' : 'brick-round', qa: "dashkit-overlay-control-menu" }),
208
- react_1.default.createElement(uikit_1.Icon, { data: DotsIcon_1.DotsIcon, size: "16" }))) }));
206
+ react_1.default.createElement(uikit_1.Icon, { data: icons_1.Ellipsis, size: constants_1.OVERLAY_ICON_SIZE }))) }));
209
207
  }
210
208
  getControlItemPinStyle(index, itemsLength) {
211
209
  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";
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.COMPACT_TYPE_HORIZONTAL_NOWRAP = exports.DEFAULT_GROUP = exports.DEFAULT_WIDGET_WIDTH = exports.DEFAULT_WIDGET_HEIGHT = exports.MenuItems = exports.TEMPORARY_ITEM_ID = exports.OVERLAY_CLASS_NAME = exports.OVERLAY_CONTROLS_CLASS_NAME = exports.DEFAULT_NAMESPACE = exports.COPIED_WIDGET_STORE_KEY = void 0;
3
+ exports.COMPACT_TYPE_HORIZONTAL_NOWRAP = exports.DEFAULT_GROUP = exports.DEFAULT_WIDGET_WIDTH = exports.DEFAULT_WIDGET_HEIGHT = exports.MenuItems = exports.TEMPORARY_ITEM_ID = exports.OVERLAY_ICON_SIZE = exports.OVERLAY_CLASS_NAME = exports.OVERLAY_CONTROLS_CLASS_NAME = exports.DEFAULT_NAMESPACE = exports.COPIED_WIDGET_STORE_KEY = void 0;
4
4
  exports.COPIED_WIDGET_STORE_KEY = 'dashCopiedItem';
5
5
  exports.DEFAULT_NAMESPACE = 'default';
6
6
  exports.OVERLAY_CONTROLS_CLASS_NAME = 'dashkit-overlay-controls';
7
7
  exports.OVERLAY_CLASS_NAME = 'dashkit-grid-item__overlay';
8
+ exports.OVERLAY_ICON_SIZE = 16;
8
9
  exports.TEMPORARY_ITEM_ID = '__dropping-elem__';
9
10
  exports.MenuItems = {
10
11
  Copy: 'copy',
@@ -32,7 +32,7 @@ function useMemoStateContext(props) {
32
32
  (0, isEqual_1.default)(groups, props.groups))) {
33
33
  props.onChange({ config, itemsStateAndParams, groups });
34
34
  }
35
- }, [props.config, props.itemsStateAndParams, props.onChange]);
35
+ }, [props.config, props.groups, props.itemsStateAndParams, props.onChange]);
36
36
  // каллбэк вызывающийся при изменение лэйаута сетки, первым аргументом приходит актуальный конфиг лэйаута,
37
37
  // т.е. если на текущей сетке есть виджеты, с активированной опцией автовысоты, их параметр "h" будет
38
38
  // "подстроенный"; чтобы, для сохранения в сторе "ушли" значения без учёта подстройки (как если бы у этих
@@ -40,7 +40,17 @@ function useMemoStateContext(props) {
40
40
  const onLayoutChange = react_1.default.useCallback((layout) => {
41
41
  const currentInnerLayout = layout.map((item) => {
42
42
  if (item.i in originalLayouts.current) {
43
- return Object.assign(Object.assign({}, originalLayouts.current[item.i]), { w: item.w, x: item.x, y: item.y });
43
+ // eslint-disable-next-line no-unused-vars
44
+ const _a = originalLayouts.current[item.i], { parent } = _a, originalCopy = tslib_1.__rest(_a, ["parent"]);
45
+ // Updating original if parent has changed and saving copy as original
46
+ // or leaving default
47
+ if (item.parent) {
48
+ originalCopy.parent = item.parent;
49
+ }
50
+ originalCopy.w = item.w;
51
+ originalCopy.x = item.x;
52
+ originalCopy.y = item.y;
53
+ return originalCopy;
44
54
  }
45
55
  else {
46
56
  return Object.assign({}, item);
@@ -237,16 +247,24 @@ function useMemoStateContext(props) {
237
247
  return null;
238
248
  }
239
249
  }, [dragProps, props.registerManager]);
240
- const onDropDragOver = react_1.default.useCallback((_e, gridProps, groupLayout) => {
250
+ const onDropDragOver = react_1.default.useCallback((_e, gridProps, groupLayout, sharedItem) => {
241
251
  if (temporaryLayout) {
242
252
  resetTemporaryLayout();
243
253
  return false;
244
254
  }
245
- if (!dragOverPlugin) {
255
+ let defaultLayout;
256
+ if (sharedItem) {
257
+ const { type, h, w } = sharedItem;
258
+ const _defaults = props.registerManager.getItem(type);
259
+ defaultLayout = _defaults ? Object.assign(Object.assign({}, _defaults.defaultLayout), { h, w }) : { h, w };
260
+ }
261
+ else if (dragOverPlugin) {
262
+ defaultLayout = dragOverPlugin.defaultLayout;
263
+ }
264
+ else {
246
265
  return false;
247
266
  }
248
267
  let maxW = gridProps.cols;
249
- const { defaultLayout } = dragOverPlugin;
250
268
  const maxH = Math.min(gridProps.maxRows || Infinity, defaultLayout.maxH || Infinity);
251
269
  if (gridProps.compactType === common_1.COMPACT_TYPE_HORIZONTAL_NOWRAP) {
252
270
  maxW = groupLayout.reduce((memo, item) => memo - item.w, gridProps.cols);
@@ -257,7 +275,7 @@ function useMemoStateContext(props) {
257
275
  maxH < defaultLayout.minH) {
258
276
  return false;
259
277
  }
260
- const { h = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.h) || common_1.DEFAULT_WIDGET_HEIGHT, w = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.w) || common_1.DEFAULT_WIDGET_WIDTH, } = dragProps.layout || {};
278
+ const { h = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.h) || common_1.DEFAULT_WIDGET_HEIGHT, w = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.w) || common_1.DEFAULT_WIDGET_WIDTH, } = (dragProps === null || dragProps === void 0 ? void 0 : dragProps.layout) || {};
261
279
  return {
262
280
  h: maxH ? Math.min(h, maxH) : h,
263
281
  w: maxW ? Math.min(w, maxW) : w,
@@ -57,6 +57,7 @@
57
57
  transition: none;
58
58
  z-index: 3;
59
59
  will-change: transform;
60
+ pointer-events: none;
60
61
  }
61
62
 
62
63
  .react-grid-item.dashkit-grid-item_is-focused {
@@ -5,6 +5,8 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
5
5
  state: {
6
6
  isDragging: boolean;
7
7
  isPageHidden: boolean;
8
+ currentDraggingElement: null;
9
+ draggedOverGroup: null;
8
10
  };
9
11
  componentDidMount(): void;
10
12
  componentDidUpdate(): void;
@@ -36,10 +38,14 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
36
38
  getMemoForwardRefCallback: (refIndex: any) => any;
37
39
  mergeGroupsLayout(group: any, newLayout: any, temporaryItem: any): any;
38
40
  reloadItems(): void;
39
- _onStart: () => void;
41
+ _onDragStart: (group: any, _newLayout: any, layoutItem: any) => void;
42
+ _onResizeStart: () => void;
43
+ _onTargetRestore: () => void;
40
44
  _onStop: (group: any, newLayout: any) => void;
41
- _onDropDragOver: (group: any, e: any) => any;
45
+ _onSharedDrop: (targetGroup: any, newLayout: any, tempItem: any) => void;
46
+ _onExternalDrop: (group: any, newLayout: any, item: any, e: any) => void;
42
47
  _onDrop: (group: any, newLayout: any, item: any, e: any) => false | undefined;
48
+ _onDropDragOver: (group: any, e: any) => any;
43
49
  renderTemporaryPlaceholder(): JSX.Element | null;
44
50
  renderGroup(group: any, renderLayout: any, renderItems: any, offset: number | undefined, groupGridProperties: any): JSX.Element;
45
51
  render(): any;