@gravity-ui/dashkit 8.17.1-beta.1 → 8.17.2

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,18 +48,6 @@ 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
- _rectInterscectionObserver: (entries: any) => void;
52
- _renderRectBlock(element: any): void;
53
- _rectBlocks: {
54
- spacers: {
55
- top: HTMLDivElement;
56
- bottom: HTMLDivElement;
57
- };
58
- parent: any;
59
- scrollObserver: IntersectionObserver;
60
- } | null | undefined;
61
- _updateRectBlock(element: any): void;
62
- _cleanRectBlock(): void;
63
51
  _onDragStart(group: any, _newLayout: any, layoutItem: any, _newItem: any, _placeholder: any, e: any, element: any): void;
64
52
  _onDrag(group: any, layout: any, oldItem: any, newItem: any, placeholder: any, e: any, element: any): void;
65
53
  _onDragStop(group: any, layout: any, oldItem: any, newItem: any, placeholder: any, e: any, element: any): void;
@@ -57,14 +57,6 @@ class GridLayout extends react_1.default.PureComponent {
57
57
  }
58
58
  return this._memoForwardedPluginRef[refIndex];
59
59
  };
60
- this._rectInterscectionObserver = (entries) => {
61
- entries.forEach((entry) => {
62
- const { intersectionRatio } = entry;
63
- if (intersectionRatio === 0) {
64
- entry.target.scrollIntoView();
65
- }
66
- });
67
- };
68
60
  this._onStop = (group, newLayout) => {
69
61
  const { layoutChange, onDrop, temporaryLayout } = this.context;
70
62
  const { draggedOverGroup, currentDraggingElement } = this.state;
@@ -295,64 +287,9 @@ class GridLayout extends react_1.default.PureComponent {
295
287
  }
296
288
  this.setState({ currentDraggingElement, draggedOverGroup: group });
297
289
  }
298
- _renderRectBlock(element) {
299
- const parent = element.parentElement;
300
- const elementRect = element.getBoundingClientRect();
301
- this._rectBlocks = {
302
- spacers: {
303
- top: document.createElement('div'),
304
- bottom: document.createElement('div'),
305
- },
306
- parent,
307
- scrollObserver: new IntersectionObserver(this._rectInterscectionObserver, {
308
- rootMargin: '0px',
309
- threshold: 0,
310
- }),
311
- };
312
- Object.entries(this._rectBlocks.spacers).forEach(([pos, block]) => {
313
- block.style.position = 'absolute';
314
- block.style.width = `${elementRect.width}px`;
315
- block.style.height = '1px';
316
- block.style.left = '0px';
317
- if (pos === 'top') {
318
- block.style.top = '0px';
319
- }
320
- else {
321
- block.style.top = `${elementRect.height - 1}px`;
322
- }
323
- parent.appendChild(block);
324
- this._rectBlocks.scrollObserver.observe(block);
325
- });
326
- this._updateRectBlock(element);
327
- }
328
- _updateRectBlock(element) {
329
- if (!this._rectBlocks) {
330
- return;
331
- }
332
- const parent = this._rectBlocks.parent;
333
- const parentRect = parent.getBoundingClientRect();
334
- const elementRect = element.getBoundingClientRect();
335
- const left = elementRect.left - parentRect.left;
336
- const top = elementRect.top - parentRect.top;
337
- Object.values(this._rectBlocks.spacers).forEach((block) => {
338
- block.style.transform = `translate(${left}px, ${top}px)`;
339
- });
340
- }
341
- _cleanRectBlock() {
342
- if (this._rectBlocks) {
343
- this._rectBlocks.scrollObserver.disconnect();
344
- Object.values(this._rectBlocks.spacers).forEach((block) => {
345
- block.remove();
346
- });
347
- this._rectBlocks = null;
348
- }
349
- }
350
290
  _onDragStart(group, _newLayout, layoutItem, _newItem, _placeholder, e, element) {
351
291
  var _a;
352
292
  (_a = this.context.onDragStart) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, _newLayout, layoutItem, _newItem, _placeholder, e, element));
353
- if (!this.state.currentDraggingElement) {
354
- this._renderRectBlock(element);
355
- }
356
293
  if (this.context.dragOverPlugin) {
357
294
  this.setState({ isDragging: true });
358
295
  }
@@ -363,12 +300,10 @@ class GridLayout extends react_1.default.PureComponent {
363
300
  }
364
301
  _onDrag(group, layout, oldItem, newItem, placeholder, e, element) {
365
302
  var _a;
366
- this._updateRectBlock(element);
367
303
  (_a = this.context.onDrag) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
368
304
  }
369
305
  _onDragStop(group, layout, oldItem, newItem, placeholder, e, element) {
370
306
  var _a;
371
- this._cleanRectBlock();
372
307
  this._onStop(group, layout);
373
308
  (_a = this.context.onDragStop) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
374
309
  }
@@ -3,14 +3,21 @@ export default class MobileLayout extends React.PureComponent<any, any, any> {
3
3
  constructor(props: any);
4
4
  constructor(props: any, context: any);
5
5
  pluginsRefs: any[];
6
+ sortedLayoutItems: any;
7
+ _memoLayout: any;
8
+ _memoForwardedPluginRef: any[];
9
+ _memoAdjustWidgetLayout: any[];
6
10
  state: {
7
11
  activeTabId: null;
8
12
  indexesOfItemsWithActiveAutoheight: {};
9
13
  };
10
14
  componentDidUpdate(prevProps: any, prevState: any): void;
15
+ getSortedLayoutItems(): any;
16
+ getMemoForwardRefCallback: (refIndex: any) => any;
11
17
  adjustWidgetLayout: (index: any, { needSetDefault }: {
12
18
  needSetDefault: any;
13
19
  }) => void;
20
+ getMemoAdjustWidgetLayout: (index: any) => any;
14
21
  onMountChange: (isMounted: any) => void;
15
22
  _inited: boolean | undefined;
16
23
  onBeforeLoad: () => () => void;
@@ -11,10 +11,21 @@ class MobileLayout extends react_1.default.PureComponent {
11
11
  constructor() {
12
12
  super(...arguments);
13
13
  this.pluginsRefs = [];
14
+ this._memoLayout = this.context.layout;
15
+ this._memoForwardedPluginRef = [];
16
+ this._memoAdjustWidgetLayout = [];
14
17
  this.state = {
15
18
  activeTabId: null,
16
19
  indexesOfItemsWithActiveAutoheight: {},
17
20
  };
21
+ this.getMemoForwardRefCallback = (refIndex) => {
22
+ if (!this._memoForwardedPluginRef[refIndex]) {
23
+ this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
24
+ this.pluginsRefs[refIndex] = pluginRef;
25
+ };
26
+ }
27
+ return this._memoForwardedPluginRef[refIndex];
28
+ };
18
29
  this.adjustWidgetLayout = (index, { needSetDefault }) => {
19
30
  if (needSetDefault) {
20
31
  const indexesOfItemsWithActiveAutoheight = Object.assign({}, this.state.indexesOfItemsWithActiveAutoheight);
@@ -27,6 +38,12 @@ class MobileLayout extends react_1.default.PureComponent {
27
38
  });
28
39
  }
29
40
  };
41
+ this.getMemoAdjustWidgetLayout = (index) => {
42
+ if (!this._memoAdjustWidgetLayout[index]) {
43
+ this._memoAdjustWidgetLayout[index] = this.adjustWidgetLayout.bind(this, index);
44
+ }
45
+ return this._memoAdjustWidgetLayout[index];
46
+ };
30
47
  this.onMountChange = (isMounted) => {
31
48
  var _a, _b, _c, _d, _e, _f;
32
49
  if (isMounted) {
@@ -63,17 +80,23 @@ class MobileLayout extends react_1.default.PureComponent {
63
80
  });
64
81
  }
65
82
  }
83
+ getSortedLayoutItems() {
84
+ if (this.sortedLayoutItems && this.context.layout === this._memoLayout) {
85
+ return this.sortedLayoutItems;
86
+ }
87
+ this._memoLayout = this.context.layout;
88
+ const hasOrderId = Boolean(this.context.config.items.find((item) => item.orderId));
89
+ this.sortedLayoutItems = (0, helpers_1.getSortedConfigItems)(this.context.config, hasOrderId);
90
+ return this.sortedLayoutItems;
91
+ }
66
92
  render() {
67
93
  const { config, layout } = this.context;
68
94
  this.pluginsRefs.length = config.items.length;
69
- const hasOrderId = Boolean(config.items.find((item) => item.orderId));
70
- const sortedItems = (0, helpers_1.getSortedConfigItems)(config, hasOrderId);
95
+ const sortedItems = this.getSortedLayoutItems();
71
96
  return (react_1.default.createElement("div", { className: b() }, sortedItems.map((item, index) => {
72
97
  const isItemWithActiveAutoheight = index in this.state.indexesOfItemsWithActiveAutoheight;
73
98
  return (react_1.default.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
74
- react_1.default.createElement(Item_1.default, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.adjustWidgetLayout.bind(this, index), forwardedPluginRef: (pluginRef) => {
75
- this.pluginsRefs[index] = pluginRef;
76
- }, onMountChange: this.onMountChange, onBeforeLoad: this.onBeforeLoad })));
99
+ react_1.default.createElement(Item_1.default, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.getMemoAdjustWidgetLayout(index), forwardedPluginRef: this.getMemoForwardRefCallback(index), onMountChange: this.onMountChange, onBeforeLoad: this.onBeforeLoad })));
77
100
  })));
78
101
  }
79
102
  }
@@ -48,18 +48,6 @@ 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
- _rectInterscectionObserver: (entries: any) => void;
52
- _renderRectBlock(element: any): void;
53
- _rectBlocks: {
54
- spacers: {
55
- top: HTMLDivElement;
56
- bottom: HTMLDivElement;
57
- };
58
- parent: any;
59
- scrollObserver: IntersectionObserver;
60
- } | null | undefined;
61
- _updateRectBlock(element: any): void;
62
- _cleanRectBlock(): void;
63
51
  _onDragStart(group: any, _newLayout: any, layoutItem: any, _newItem: any, _placeholder: any, e: any, element: any): void;
64
52
  _onDrag(group: any, layout: any, oldItem: any, newItem: any, placeholder: any, e: any, element: any): void;
65
53
  _onDragStop(group: any, layout: any, oldItem: any, newItem: any, placeholder: any, e: any, element: any): void;
@@ -54,14 +54,6 @@ class GridLayout extends React.PureComponent {
54
54
  }
55
55
  return this._memoForwardedPluginRef[refIndex];
56
56
  };
57
- this._rectInterscectionObserver = (entries) => {
58
- entries.forEach((entry) => {
59
- const { intersectionRatio } = entry;
60
- if (intersectionRatio === 0) {
61
- entry.target.scrollIntoView();
62
- }
63
- });
64
- };
65
57
  this._onStop = (group, newLayout) => {
66
58
  const { layoutChange, onDrop, temporaryLayout } = this.context;
67
59
  const { draggedOverGroup, currentDraggingElement } = this.state;
@@ -292,64 +284,9 @@ class GridLayout extends React.PureComponent {
292
284
  }
293
285
  this.setState({ currentDraggingElement, draggedOverGroup: group });
294
286
  }
295
- _renderRectBlock(element) {
296
- const parent = element.parentElement;
297
- const elementRect = element.getBoundingClientRect();
298
- this._rectBlocks = {
299
- spacers: {
300
- top: document.createElement('div'),
301
- bottom: document.createElement('div'),
302
- },
303
- parent,
304
- scrollObserver: new IntersectionObserver(this._rectInterscectionObserver, {
305
- rootMargin: '0px',
306
- threshold: 0,
307
- }),
308
- };
309
- Object.entries(this._rectBlocks.spacers).forEach(([pos, block]) => {
310
- block.style.position = 'absolute';
311
- block.style.width = `${elementRect.width}px`;
312
- block.style.height = '1px';
313
- block.style.left = '0px';
314
- if (pos === 'top') {
315
- block.style.top = '0px';
316
- }
317
- else {
318
- block.style.top = `${elementRect.height - 1}px`;
319
- }
320
- parent.appendChild(block);
321
- this._rectBlocks.scrollObserver.observe(block);
322
- });
323
- this._updateRectBlock(element);
324
- }
325
- _updateRectBlock(element) {
326
- if (!this._rectBlocks) {
327
- return;
328
- }
329
- const parent = this._rectBlocks.parent;
330
- const parentRect = parent.getBoundingClientRect();
331
- const elementRect = element.getBoundingClientRect();
332
- const left = elementRect.left - parentRect.left;
333
- const top = elementRect.top - parentRect.top;
334
- Object.values(this._rectBlocks.spacers).forEach((block) => {
335
- block.style.transform = `translate(${left}px, ${top}px)`;
336
- });
337
- }
338
- _cleanRectBlock() {
339
- if (this._rectBlocks) {
340
- this._rectBlocks.scrollObserver.disconnect();
341
- Object.values(this._rectBlocks.spacers).forEach((block) => {
342
- block.remove();
343
- });
344
- this._rectBlocks = null;
345
- }
346
- }
347
287
  _onDragStart(group, _newLayout, layoutItem, _newItem, _placeholder, e, element) {
348
288
  var _a;
349
289
  (_a = this.context.onDragStart) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, _newLayout, layoutItem, _newItem, _placeholder, e, element));
350
- if (!this.state.currentDraggingElement) {
351
- this._renderRectBlock(element);
352
- }
353
290
  if (this.context.dragOverPlugin) {
354
291
  this.setState({ isDragging: true });
355
292
  }
@@ -360,12 +297,10 @@ class GridLayout extends React.PureComponent {
360
297
  }
361
298
  _onDrag(group, layout, oldItem, newItem, placeholder, e, element) {
362
299
  var _a;
363
- this._updateRectBlock(element);
364
300
  (_a = this.context.onDrag) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
365
301
  }
366
302
  _onDragStop(group, layout, oldItem, newItem, placeholder, e, element) {
367
303
  var _a;
368
- this._cleanRectBlock();
369
304
  this._onStop(group, layout);
370
305
  (_a = this.context.onDragStop) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
371
306
  }
@@ -3,14 +3,21 @@ export default class MobileLayout extends React.PureComponent<any, any, any> {
3
3
  constructor(props: any);
4
4
  constructor(props: any, context: any);
5
5
  pluginsRefs: any[];
6
+ sortedLayoutItems: any;
7
+ _memoLayout: any;
8
+ _memoForwardedPluginRef: any[];
9
+ _memoAdjustWidgetLayout: any[];
6
10
  state: {
7
11
  activeTabId: null;
8
12
  indexesOfItemsWithActiveAutoheight: {};
9
13
  };
10
14
  componentDidUpdate(prevProps: any, prevState: any): void;
15
+ getSortedLayoutItems(): any;
16
+ getMemoForwardRefCallback: (refIndex: any) => any;
11
17
  adjustWidgetLayout: (index: any, { needSetDefault }: {
12
18
  needSetDefault: any;
13
19
  }) => void;
20
+ getMemoAdjustWidgetLayout: (index: any) => any;
14
21
  onMountChange: (isMounted: any) => void;
15
22
  _inited: boolean | undefined;
16
23
  onBeforeLoad: () => () => void;
@@ -9,10 +9,21 @@ class MobileLayout extends React.PureComponent {
9
9
  constructor() {
10
10
  super(...arguments);
11
11
  this.pluginsRefs = [];
12
+ this._memoLayout = this.context.layout;
13
+ this._memoForwardedPluginRef = [];
14
+ this._memoAdjustWidgetLayout = [];
12
15
  this.state = {
13
16
  activeTabId: null,
14
17
  indexesOfItemsWithActiveAutoheight: {},
15
18
  };
19
+ this.getMemoForwardRefCallback = (refIndex) => {
20
+ if (!this._memoForwardedPluginRef[refIndex]) {
21
+ this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
22
+ this.pluginsRefs[refIndex] = pluginRef;
23
+ };
24
+ }
25
+ return this._memoForwardedPluginRef[refIndex];
26
+ };
16
27
  this.adjustWidgetLayout = (index, { needSetDefault }) => {
17
28
  if (needSetDefault) {
18
29
  const indexesOfItemsWithActiveAutoheight = Object.assign({}, this.state.indexesOfItemsWithActiveAutoheight);
@@ -25,6 +36,12 @@ class MobileLayout extends React.PureComponent {
25
36
  });
26
37
  }
27
38
  };
39
+ this.getMemoAdjustWidgetLayout = (index) => {
40
+ if (!this._memoAdjustWidgetLayout[index]) {
41
+ this._memoAdjustWidgetLayout[index] = this.adjustWidgetLayout.bind(this, index);
42
+ }
43
+ return this._memoAdjustWidgetLayout[index];
44
+ };
28
45
  this.onMountChange = (isMounted) => {
29
46
  var _a, _b, _c, _d, _e, _f;
30
47
  if (isMounted) {
@@ -61,17 +78,23 @@ class MobileLayout extends React.PureComponent {
61
78
  });
62
79
  }
63
80
  }
81
+ getSortedLayoutItems() {
82
+ if (this.sortedLayoutItems && this.context.layout === this._memoLayout) {
83
+ return this.sortedLayoutItems;
84
+ }
85
+ this._memoLayout = this.context.layout;
86
+ const hasOrderId = Boolean(this.context.config.items.find((item) => item.orderId));
87
+ this.sortedLayoutItems = getSortedConfigItems(this.context.config, hasOrderId);
88
+ return this.sortedLayoutItems;
89
+ }
64
90
  render() {
65
91
  const { config, layout } = this.context;
66
92
  this.pluginsRefs.length = config.items.length;
67
- const hasOrderId = Boolean(config.items.find((item) => item.orderId));
68
- const sortedItems = getSortedConfigItems(config, hasOrderId);
93
+ const sortedItems = this.getSortedLayoutItems();
69
94
  return (React.createElement("div", { className: b() }, sortedItems.map((item, index) => {
70
95
  const isItemWithActiveAutoheight = index in this.state.indexesOfItemsWithActiveAutoheight;
71
96
  return (React.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
72
- React.createElement(Item, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.adjustWidgetLayout.bind(this, index), forwardedPluginRef: (pluginRef) => {
73
- this.pluginsRefs[index] = pluginRef;
74
- }, onMountChange: this.onMountChange, onBeforeLoad: this.onBeforeLoad })));
97
+ React.createElement(Item, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.getMemoAdjustWidgetLayout(index), forwardedPluginRef: this.getMemoForwardRefCallback(index), onMountChange: this.onMountChange, onBeforeLoad: this.onBeforeLoad })));
75
98
  })));
76
99
  }
77
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.17.1-beta.1",
3
+ "version": "8.17.2",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {