@gravity-ui/dashkit 8.16.0 → 8.17.1-beta.0

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.
@@ -48,6 +48,16 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
48
48
  element: any;
49
49
  };
50
50
  updateeDraggingElementState(group: any, layoutItem: any, e: any): void;
51
+ _renderRectBlock(element: any): void;
52
+ _rectBlocks: {
53
+ spacers: {
54
+ top: HTMLDivElement;
55
+ bottom: HTMLDivElement;
56
+ };
57
+ parent: any;
58
+ } | null | undefined;
59
+ _updateRectBlock(element: any): void;
60
+ _cleanRectBlock(): void;
51
61
  _onDragStart(group: any, _newLayout: any, layoutItem: any, _newItem: any, _placeholder: any, e: any, element: any): void;
52
62
  _onDrag(group: any, layout: any, oldItem: any, newItem: any, placeholder: any, e: any, element: any): void;
53
63
  _onDragStop(group: any, layout: any, oldItem: any, newItem: any, placeholder: any, e: any, element: any): void;
@@ -60,6 +70,7 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
60
70
  _onExternalDrop: (group: any, newLayout: any, item: any, e: any) => void;
61
71
  _onDrop: (group: any, newLayout: any, item: any, e: any) => false | undefined;
62
72
  _onDropDragOver: (group: any, e: any) => any;
73
+ renderRectBlocks(): JSX.Element;
63
74
  renderTemporaryPlaceholder(): JSX.Element | null;
64
75
  renderGroup(group: any, renderLayout: any, renderItems: any, offset: number | undefined, groupGridProperties: any): JSX.Element;
65
76
  render(): any;
@@ -287,9 +287,58 @@ class GridLayout extends react_1.default.PureComponent {
287
287
  }
288
288
  this.setState({ currentDraggingElement, draggedOverGroup: group });
289
289
  }
290
+ _renderRectBlock(element) {
291
+ const parent = element.parentElement;
292
+ const elementRect = element.getBoundingClientRect();
293
+ this._rectBlocks = {
294
+ spacers: {
295
+ top: document.createElement('div'),
296
+ bottom: document.createElement('div'),
297
+ },
298
+ parent,
299
+ };
300
+ Object.entries(this._rectBlocks.spacers).forEach(([pos, block]) => {
301
+ block.style.position = 'absolute';
302
+ block.style.width = `${elementRect.width}px`;
303
+ block.style.height = '1px';
304
+ block.style.left = '0px';
305
+ if (pos === 'top') {
306
+ block.style.top = '0px';
307
+ }
308
+ else {
309
+ block.style.top = `${elementRect.height - 1}px`;
310
+ }
311
+ parent.appendChild(block);
312
+ });
313
+ this._updateRectBlock(element);
314
+ }
315
+ _updateRectBlock(element) {
316
+ if (!this._rectBlocks) {
317
+ return;
318
+ }
319
+ const parent = this._rectBlocks.parent;
320
+ const parentRect = parent.getBoundingClientRect();
321
+ const elementRect = element.getBoundingClientRect();
322
+ const left = elementRect.left - parentRect.left;
323
+ const top = elementRect.top - parentRect.top;
324
+ Object.values(this._rectBlocks.spacers).forEach((block) => {
325
+ block.style.transform = `translate(${left}px, ${top}px)`;
326
+ });
327
+ }
328
+ _cleanRectBlock() {
329
+ if (this._rectBlocks) {
330
+ Object.values(this._rectBlocks.spacers).forEach((block) => {
331
+ block.remove();
332
+ });
333
+ this._rectBlocks = null;
334
+ }
335
+ }
290
336
  _onDragStart(group, _newLayout, layoutItem, _newItem, _placeholder, e, element) {
291
337
  var _a;
292
338
  (_a = this.context.onDragStart) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, _newLayout, layoutItem, _newItem, _placeholder, e, element));
339
+ if (!this.state.currentDraggingElement) {
340
+ this._renderRectBlock(element);
341
+ }
293
342
  if (this.context.dragOverPlugin) {
294
343
  this.setState({ isDragging: true });
295
344
  }
@@ -300,10 +349,12 @@ class GridLayout extends react_1.default.PureComponent {
300
349
  }
301
350
  _onDrag(group, layout, oldItem, newItem, placeholder, e, element) {
302
351
  var _a;
352
+ this._updateRectBlock(element);
303
353
  (_a = this.context.onDrag) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
304
354
  }
305
355
  _onDragStop(group, layout, oldItem, newItem, placeholder, e, element) {
306
356
  var _a;
357
+ this._cleanRectBlock();
307
358
  this._onStop(group, layout);
308
359
  (_a = this.context.onDragStop) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
309
360
  }
@@ -334,6 +385,9 @@ class GridLayout extends react_1.default.PureComponent {
334
385
  });
335
386
  }
336
387
  }
388
+ renderRectBlocks() {
389
+ return react_1.default.createElement("div", { className: "test" }, "123");
390
+ }
337
391
  renderTemporaryPlaceholder() {
338
392
  const { temporaryLayout, noOverlay, draggableHandleClassName } = this.context;
339
393
  if (!temporaryLayout || !temporaryLayout.dragProps) {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ButtonSize, ButtonView, IconProps, MenuItemProps } from '@gravity-ui/uikit';
3
- import type { ConfigItem, ConfigLayout, ItemState, PluginBase, StringParams } from '../../shared';
3
+ import { type ConfigItem, type ConfigLayout, type ItemState, type ItemsStateAndParamsBase, type PluginBase, type StringParams } from '../../shared';
4
4
  import { MenuItem } from '../../typings';
5
5
  export declare enum OverlayControlsPosition {
6
6
  TopRight = "top_right",
@@ -44,6 +44,8 @@ type PreparedCopyItemOptionsArg = Pick<ConfigItem, 'data' | 'type' | 'defaults'
44
44
  w: number;
45
45
  h: number;
46
46
  };
47
+ targetId?: string;
48
+ targetInnerId?: string;
47
49
  };
48
50
  export type PreparedCopyItemOptions<C extends object = {}> = PreparedCopyItemOptionsArg & {
49
51
  copyContext?: C;
@@ -52,8 +54,8 @@ type DashKitCtx = React.Context<{
52
54
  overlayControls?: Record<string, OverlayControlItem[]>;
53
55
  context: Record<string, any>;
54
56
  menu: MenuItem[];
57
+ itemsStateAndParams: ItemsStateAndParamsBase;
55
58
  itemsParams: Record<string, StringParams>;
56
- itemsState: Record<string, ItemState>;
57
59
  editItem: (item: ConfigItem) => void;
58
60
  removeItem: (id: string) => void;
59
61
  getLayoutItem: (id: string) => ConfigLayout | void;
@@ -9,6 +9,7 @@ const noop_1 = tslib_1.__importDefault(require("lodash/noop"));
9
9
  const constants_1 = require("../../constants");
10
10
  const DashKitContext_1 = require("../../context/DashKitContext");
11
11
  const i18n_1 = require("../../i18n");
12
+ const shared_1 = require("../../shared");
12
13
  const cn_1 = require("../../utils/cn");
13
14
  const b = (0, cn_1.cn)(constants_1.OVERLAY_CONTROLS_CLASS_NAME);
14
15
  var OverlayControlsPosition;
@@ -81,6 +82,13 @@ class OverlayControls extends react_1.default.Component {
81
82
  var _a, _b, _c;
82
83
  const { configItem } = this.props;
83
84
  const correspondedItemLayout = this.context.getLayoutItem(configItem.id);
85
+ let targetInnerId;
86
+ if ((0, shared_1.isItemWithTabs)(this.props.configItem)) {
87
+ targetInnerId = (0, shared_1.resolveItemInnerId)({
88
+ item: this.props.configItem,
89
+ itemsStateAndParams: this.context.itemsStateAndParams,
90
+ });
91
+ }
84
92
  let options = {
85
93
  timestamp: Date.now(),
86
94
  data: configItem.data,
@@ -91,6 +99,8 @@ class OverlayControls extends react_1.default.Component {
91
99
  w: correspondedItemLayout.w,
92
100
  h: correspondedItemLayout.h,
93
101
  },
102
+ targetId: this.props.configItem.id,
103
+ targetInnerId,
94
104
  };
95
105
  if (typeof ((_a = this.context.context) === null || _a === void 0 ? void 0 : _a.getPreparedCopyItemOptions) === 'function') {
96
106
  options = this.context.context.getPreparedCopyItemOptions(options);
@@ -175,11 +185,12 @@ class OverlayControls extends react_1.default.Component {
175
185
  return menu === null || menu === void 0 ? void 0 : menu.every((item) => Object.values(constants_1.MenuItems).includes(String(item)));
176
186
  }
177
187
  renderDropdownMenu(isOnlyOneItem) {
188
+ var _a;
178
189
  const { view, size, onItemClick } = this.props;
179
- const { menu: contextMenu, itemsParams, itemsState } = this.context;
190
+ const { menu: contextMenu, itemsParams, itemsStateAndParams } = this.context;
180
191
  const configItem = this.props.configItem;
181
192
  const itemParams = itemsParams[configItem.id];
182
- const itemState = itemsState[configItem.id];
193
+ const itemState = ((_a = itemsStateAndParams[configItem.id]) === null || _a === void 0 ? void 0 : _a.state) || {};
183
194
  const menu = (contextMenu === null || contextMenu === void 0 ? void 0 : contextMenu.length) > 0 ? contextMenu : DEFAULT_DROPDOWN_MENU;
184
195
  const isDefaultMenu = this.isDefaultMenu(menu);
185
196
  const items = isDefaultMenu
@@ -378,19 +378,19 @@ function useMemoStateContext(props) {
378
378
  overlayControls: props.overlayControls,
379
379
  context: props.context,
380
380
  menu: overlayMenuItems,
381
- itemsParams: itemsParams,
382
- itemsState: itemsState,
381
+ itemsStateAndParams: props.itemsStateAndParams,
382
+ itemsParams,
383
383
  editItem: props.onItemEdit,
384
384
  removeItem: onItemRemove,
385
385
  getLayoutItem: getLayoutItem,
386
386
  }), [
387
- itemsParams,
388
- itemsState,
387
+ props.overlayControls,
389
388
  props.context,
389
+ props.itemsStateAndParams,
390
390
  props.onItemEdit,
391
- onItemRemove,
392
- props.overlayControls,
393
391
  overlayMenuItems,
392
+ itemsParams,
393
+ onItemRemove,
394
394
  getLayoutItem,
395
395
  ]);
396
396
  return { controlsContextValue, dashkitContextValue };
@@ -48,6 +48,16 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
48
48
  element: any;
49
49
  };
50
50
  updateeDraggingElementState(group: any, layoutItem: any, e: any): void;
51
+ _renderRectBlock(element: any): void;
52
+ _rectBlocks: {
53
+ spacers: {
54
+ top: HTMLDivElement;
55
+ bottom: HTMLDivElement;
56
+ };
57
+ parent: any;
58
+ } | null | undefined;
59
+ _updateRectBlock(element: any): void;
60
+ _cleanRectBlock(): void;
51
61
  _onDragStart(group: any, _newLayout: any, layoutItem: any, _newItem: any, _placeholder: any, e: any, element: any): void;
52
62
  _onDrag(group: any, layout: any, oldItem: any, newItem: any, placeholder: any, e: any, element: any): void;
53
63
  _onDragStop(group: any, layout: any, oldItem: any, newItem: any, placeholder: any, e: any, element: any): void;
@@ -60,6 +70,7 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
60
70
  _onExternalDrop: (group: any, newLayout: any, item: any, e: any) => void;
61
71
  _onDrop: (group: any, newLayout: any, item: any, e: any) => false | undefined;
62
72
  _onDropDragOver: (group: any, e: any) => any;
73
+ renderRectBlocks(): JSX.Element;
63
74
  renderTemporaryPlaceholder(): JSX.Element | null;
64
75
  renderGroup(group: any, renderLayout: any, renderItems: any, offset: number | undefined, groupGridProperties: any): JSX.Element;
65
76
  render(): any;
@@ -284,9 +284,58 @@ class GridLayout extends React.PureComponent {
284
284
  }
285
285
  this.setState({ currentDraggingElement, draggedOverGroup: group });
286
286
  }
287
+ _renderRectBlock(element) {
288
+ const parent = element.parentElement;
289
+ const elementRect = element.getBoundingClientRect();
290
+ this._rectBlocks = {
291
+ spacers: {
292
+ top: document.createElement('div'),
293
+ bottom: document.createElement('div'),
294
+ },
295
+ parent,
296
+ };
297
+ Object.entries(this._rectBlocks.spacers).forEach(([pos, block]) => {
298
+ block.style.position = 'absolute';
299
+ block.style.width = `${elementRect.width}px`;
300
+ block.style.height = '1px';
301
+ block.style.left = '0px';
302
+ if (pos === 'top') {
303
+ block.style.top = '0px';
304
+ }
305
+ else {
306
+ block.style.top = `${elementRect.height - 1}px`;
307
+ }
308
+ parent.appendChild(block);
309
+ });
310
+ this._updateRectBlock(element);
311
+ }
312
+ _updateRectBlock(element) {
313
+ if (!this._rectBlocks) {
314
+ return;
315
+ }
316
+ const parent = this._rectBlocks.parent;
317
+ const parentRect = parent.getBoundingClientRect();
318
+ const elementRect = element.getBoundingClientRect();
319
+ const left = elementRect.left - parentRect.left;
320
+ const top = elementRect.top - parentRect.top;
321
+ Object.values(this._rectBlocks.spacers).forEach((block) => {
322
+ block.style.transform = `translate(${left}px, ${top}px)`;
323
+ });
324
+ }
325
+ _cleanRectBlock() {
326
+ if (this._rectBlocks) {
327
+ Object.values(this._rectBlocks.spacers).forEach((block) => {
328
+ block.remove();
329
+ });
330
+ this._rectBlocks = null;
331
+ }
332
+ }
287
333
  _onDragStart(group, _newLayout, layoutItem, _newItem, _placeholder, e, element) {
288
334
  var _a;
289
335
  (_a = this.context.onDragStart) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, _newLayout, layoutItem, _newItem, _placeholder, e, element));
336
+ if (!this.state.currentDraggingElement) {
337
+ this._renderRectBlock(element);
338
+ }
290
339
  if (this.context.dragOverPlugin) {
291
340
  this.setState({ isDragging: true });
292
341
  }
@@ -297,10 +346,12 @@ class GridLayout extends React.PureComponent {
297
346
  }
298
347
  _onDrag(group, layout, oldItem, newItem, placeholder, e, element) {
299
348
  var _a;
349
+ this._updateRectBlock(element);
300
350
  (_a = this.context.onDrag) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
301
351
  }
302
352
  _onDragStop(group, layout, oldItem, newItem, placeholder, e, element) {
303
353
  var _a;
354
+ this._cleanRectBlock();
304
355
  this._onStop(group, layout);
305
356
  (_a = this.context.onDragStop) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
306
357
  }
@@ -331,6 +382,9 @@ class GridLayout extends React.PureComponent {
331
382
  });
332
383
  }
333
384
  }
385
+ renderRectBlocks() {
386
+ return React.createElement("div", { className: "test" }, "123");
387
+ }
334
388
  renderTemporaryPlaceholder() {
335
389
  const { temporaryLayout, noOverlay, draggableHandleClassName } = this.context;
336
390
  if (!temporaryLayout || !temporaryLayout.dragProps) {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ButtonSize, ButtonView, IconProps, MenuItemProps } from '@gravity-ui/uikit';
3
- import type { ConfigItem, ConfigLayout, ItemState, PluginBase, StringParams } from '../../shared';
3
+ import { type ConfigItem, type ConfigLayout, type ItemState, type ItemsStateAndParamsBase, type PluginBase, type StringParams } from '../../shared';
4
4
  import { MenuItem } from '../../typings';
5
5
  import './OverlayControls.css';
6
6
  export declare enum OverlayControlsPosition {
@@ -45,6 +45,8 @@ type PreparedCopyItemOptionsArg = Pick<ConfigItem, 'data' | 'type' | 'defaults'
45
45
  w: number;
46
46
  h: number;
47
47
  };
48
+ targetId?: string;
49
+ targetInnerId?: string;
48
50
  };
49
51
  export type PreparedCopyItemOptions<C extends object = {}> = PreparedCopyItemOptionsArg & {
50
52
  copyContext?: C;
@@ -53,8 +55,8 @@ type DashKitCtx = React.Context<{
53
55
  overlayControls?: Record<string, OverlayControlItem[]>;
54
56
  context: Record<string, any>;
55
57
  menu: MenuItem[];
58
+ itemsStateAndParams: ItemsStateAndParamsBase;
56
59
  itemsParams: Record<string, StringParams>;
57
- itemsState: Record<string, ItemState>;
58
60
  editItem: (item: ConfigItem) => void;
59
61
  removeItem: (id: string) => void;
60
62
  getLayoutItem: (id: string) => ConfigLayout | void;
@@ -5,6 +5,7 @@ import noop from 'lodash/noop';
5
5
  import { COPIED_WIDGET_STORE_KEY, DRAGGABLE_CANCEL_CLASS_NAME, MenuItems, OVERLAY_CONTROLS_CLASS_NAME, OVERLAY_ICON_SIZE, } from '../../constants';
6
6
  import { DashkitOvelayControlsContext } from '../../context/DashKitContext';
7
7
  import { i18n } from '../../i18n';
8
+ import { isItemWithTabs, resolveItemInnerId, } from '../../shared';
8
9
  import { cn } from '../../utils/cn';
9
10
  import './OverlayControls.css';
10
11
  const b = cn(OVERLAY_CONTROLS_CLASS_NAME);
@@ -78,6 +79,13 @@ class OverlayControls extends React.Component {
78
79
  var _a, _b, _c;
79
80
  const { configItem } = this.props;
80
81
  const correspondedItemLayout = this.context.getLayoutItem(configItem.id);
82
+ let targetInnerId;
83
+ if (isItemWithTabs(this.props.configItem)) {
84
+ targetInnerId = resolveItemInnerId({
85
+ item: this.props.configItem,
86
+ itemsStateAndParams: this.context.itemsStateAndParams,
87
+ });
88
+ }
81
89
  let options = {
82
90
  timestamp: Date.now(),
83
91
  data: configItem.data,
@@ -88,6 +96,8 @@ class OverlayControls extends React.Component {
88
96
  w: correspondedItemLayout.w,
89
97
  h: correspondedItemLayout.h,
90
98
  },
99
+ targetId: this.props.configItem.id,
100
+ targetInnerId,
91
101
  };
92
102
  if (typeof ((_a = this.context.context) === null || _a === void 0 ? void 0 : _a.getPreparedCopyItemOptions) === 'function') {
93
103
  options = this.context.context.getPreparedCopyItemOptions(options);
@@ -172,11 +182,12 @@ class OverlayControls extends React.Component {
172
182
  return menu === null || menu === void 0 ? void 0 : menu.every((item) => Object.values(MenuItems).includes(String(item)));
173
183
  }
174
184
  renderDropdownMenu(isOnlyOneItem) {
185
+ var _a;
175
186
  const { view, size, onItemClick } = this.props;
176
- const { menu: contextMenu, itemsParams, itemsState } = this.context;
187
+ const { menu: contextMenu, itemsParams, itemsStateAndParams } = this.context;
177
188
  const configItem = this.props.configItem;
178
189
  const itemParams = itemsParams[configItem.id];
179
- const itemState = itemsState[configItem.id];
190
+ const itemState = ((_a = itemsStateAndParams[configItem.id]) === null || _a === void 0 ? void 0 : _a.state) || {};
180
191
  const menu = (contextMenu === null || contextMenu === void 0 ? void 0 : contextMenu.length) > 0 ? contextMenu : DEFAULT_DROPDOWN_MENU;
181
192
  const isDefaultMenu = this.isDefaultMenu(menu);
182
193
  const items = isDefaultMenu
@@ -375,19 +375,19 @@ function useMemoStateContext(props) {
375
375
  overlayControls: props.overlayControls,
376
376
  context: props.context,
377
377
  menu: overlayMenuItems,
378
- itemsParams: itemsParams,
379
- itemsState: itemsState,
378
+ itemsStateAndParams: props.itemsStateAndParams,
379
+ itemsParams,
380
380
  editItem: props.onItemEdit,
381
381
  removeItem: onItemRemove,
382
382
  getLayoutItem: getLayoutItem,
383
383
  }), [
384
- itemsParams,
385
- itemsState,
384
+ props.overlayControls,
386
385
  props.context,
386
+ props.itemsStateAndParams,
387
387
  props.onItemEdit,
388
- onItemRemove,
389
- props.overlayControls,
390
388
  overlayMenuItems,
389
+ itemsParams,
390
+ onItemRemove,
391
391
  getLayoutItem,
392
392
  ]);
393
393
  return { controlsContextValue, dashkitContextValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.16.0",
3
+ "version": "8.17.1-beta.0",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {