@gravity-ui/dashkit 10.5.1 → 11.0.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.
Files changed (186) hide show
  1. package/README.md +20 -1
  2. package/build/cjs/components/ActionPanel/ActionPanel.css +7 -5
  3. package/build/cjs/components/ActionPanel/ActionPanel.js +7 -9
  4. package/build/cjs/components/ActionPanel/ActionPanel.js.map +1 -1
  5. package/build/cjs/components/DashKit/DashKit.d.ts +1 -2
  6. package/build/cjs/components/DashKit/DashKit.js +50 -52
  7. package/build/cjs/components/DashKit/DashKit.js.map +1 -1
  8. package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.js +2 -2
  9. package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.js.map +1 -1
  10. package/build/cjs/components/DashKitView/DashKitView.js +1 -1
  11. package/build/cjs/components/DashKitView/DashKitView.js.map +1 -1
  12. package/build/cjs/components/GridItem/GridItem.js +79 -75
  13. package/build/cjs/components/GridItem/GridItem.js.map +1 -1
  14. package/build/cjs/components/GridLayout/GridLayout.d.ts +2 -2
  15. package/build/cjs/components/GridLayout/GridLayout.js +184 -187
  16. package/build/cjs/components/GridLayout/GridLayout.js.map +1 -1
  17. package/build/cjs/components/GridLayout/GroupLayout.js +1 -1
  18. package/build/cjs/components/GridLayout/GroupLayout.js.map +1 -1
  19. package/build/cjs/components/GridLayout/ReactGridLayout.js +303 -299
  20. package/build/cjs/components/GridLayout/ReactGridLayout.js.map +1 -1
  21. package/build/cjs/components/GridLayout/types.d.ts +1 -1
  22. package/build/cjs/components/GridLayout/types.js.map +1 -1
  23. package/build/cjs/components/Item/Item.js +8 -11
  24. package/build/cjs/components/Item/Item.js.map +1 -1
  25. package/build/cjs/components/MobileLayout/MobileLayout.d.ts +2 -2
  26. package/build/cjs/components/MobileLayout/MobileLayout.js +14 -14
  27. package/build/cjs/components/MobileLayout/MobileLayout.js.map +1 -1
  28. package/build/cjs/components/OverlayControls/OverlayControls.css +1 -1
  29. package/build/cjs/components/OverlayControls/OverlayControls.d.ts +7 -32
  30. package/build/cjs/components/OverlayControls/OverlayControls.js +164 -151
  31. package/build/cjs/components/OverlayControls/OverlayControls.js.map +1 -1
  32. package/build/cjs/hocs/prepareItem.js +65 -70
  33. package/build/cjs/hocs/prepareItem.js.map +1 -1
  34. package/build/cjs/hocs/withContext.js +27 -17
  35. package/build/cjs/hocs/withContext.js.map +1 -1
  36. package/build/cjs/hooks/useDeepEqualMemo.js +1 -1
  37. package/build/cjs/hooks/useDeepEqualMemo.js.map +1 -1
  38. package/build/cjs/i18n/index.d.ts +8 -0
  39. package/build/cjs/package.json +1 -1
  40. package/build/cjs/plugins/Text/Text.js +14 -17
  41. package/build/cjs/plugins/Text/Text.js.map +1 -1
  42. package/build/cjs/plugins/Title/Title.js +3 -4
  43. package/build/cjs/plugins/Title/Title.js.map +1 -1
  44. package/build/cjs/plugins/Title/index.d.ts +1 -1
  45. package/build/cjs/plugins/Title/index.js.map +1 -1
  46. package/build/cjs/shared/modules/helpers.js +34 -23
  47. package/build/cjs/shared/modules/helpers.js.map +1 -1
  48. package/build/cjs/shared/modules/state-and-params.js +30 -14
  49. package/build/cjs/shared/modules/state-and-params.js.map +1 -1
  50. package/build/cjs/shared/units/datalens/index.js +5 -2
  51. package/build/cjs/shared/units/datalens/index.js.map +1 -1
  52. package/build/cjs/utils/enrichLayoutWithDefaults.d.ts +1 -1
  53. package/build/cjs/utils/enrichLayoutWithDefaults.js +4 -1
  54. package/build/cjs/utils/enrichLayoutWithDefaults.js.map +1 -1
  55. package/build/cjs/utils/events.js +1 -1
  56. package/build/cjs/utils/events.js.map +1 -1
  57. package/build/cjs/utils/get-layout-patches.js +1 -1
  58. package/build/cjs/utils/get-layout-patches.js.map +1 -1
  59. package/build/cjs/utils/register-manager.js +25 -24
  60. package/build/cjs/utils/register-manager.js.map +1 -1
  61. package/build/cjs/utils/update-manager.js +103 -66
  62. package/build/cjs/utils/update-manager.js.map +1 -1
  63. package/build/docs/INDEX.md +24 -1
  64. package/build/docs/guides/migration-to-v11.md +122 -0
  65. package/build/esm/components/ActionPanel/ActionPanel.css +7 -5
  66. package/build/esm/components/ActionPanel/ActionPanel.js +7 -10
  67. package/build/esm/components/ActionPanel/ActionPanel.js.map +1 -1
  68. package/build/esm/components/DashKit/DashKit.d.ts +1 -2
  69. package/build/esm/components/DashKit/DashKit.js +50 -52
  70. package/build/esm/components/DashKit/DashKit.js.map +1 -1
  71. package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.js +2 -2
  72. package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.js.map +1 -1
  73. package/build/esm/components/DashKitView/DashKitView.js +1 -1
  74. package/build/esm/components/DashKitView/DashKitView.js.map +1 -1
  75. package/build/esm/components/GridItem/GridItem.js +79 -75
  76. package/build/esm/components/GridItem/GridItem.js.map +1 -1
  77. package/build/esm/components/GridLayout/GridLayout.d.ts +2 -2
  78. package/build/esm/components/GridLayout/GridLayout.js +185 -189
  79. package/build/esm/components/GridLayout/GridLayout.js.map +1 -1
  80. package/build/esm/components/GridLayout/GroupLayout.js +1 -1
  81. package/build/esm/components/GridLayout/GroupLayout.js.map +1 -1
  82. package/build/esm/components/GridLayout/ReactGridLayout.js +303 -300
  83. package/build/esm/components/GridLayout/ReactGridLayout.js.map +1 -1
  84. package/build/esm/components/GridLayout/types.d.ts +1 -1
  85. package/build/esm/components/GridLayout/types.js.map +1 -1
  86. package/build/esm/components/Item/Item.js +8 -11
  87. package/build/esm/components/Item/Item.js.map +1 -1
  88. package/build/esm/components/MobileLayout/MobileLayout.d.ts +2 -2
  89. package/build/esm/components/MobileLayout/MobileLayout.js +15 -16
  90. package/build/esm/components/MobileLayout/MobileLayout.js.map +1 -1
  91. package/build/esm/components/OverlayControls/OverlayControls.css +1 -1
  92. package/build/esm/components/OverlayControls/OverlayControls.d.ts +7 -32
  93. package/build/esm/components/OverlayControls/OverlayControls.js +165 -152
  94. package/build/esm/components/OverlayControls/OverlayControls.js.map +1 -1
  95. package/build/esm/hocs/prepareItem.js +65 -70
  96. package/build/esm/hocs/prepareItem.js.map +1 -1
  97. package/build/esm/hocs/withContext.js +27 -18
  98. package/build/esm/hocs/withContext.js.map +1 -1
  99. package/build/esm/hooks/useDeepEqualMemo.js +1 -1
  100. package/build/esm/hooks/useDeepEqualMemo.js.map +1 -1
  101. package/build/esm/i18n/index.d.ts +8 -0
  102. package/build/esm/package.json +1 -1
  103. package/build/esm/plugins/Text/Text.js +14 -17
  104. package/build/esm/plugins/Text/Text.js.map +1 -1
  105. package/build/esm/plugins/Title/Title.js +3 -4
  106. package/build/esm/plugins/Title/Title.js.map +1 -1
  107. package/build/esm/plugins/Title/index.d.ts +1 -1
  108. package/build/esm/plugins/Title/index.js.map +1 -1
  109. package/build/esm/shared/modules/helpers.js +34 -23
  110. package/build/esm/shared/modules/helpers.js.map +1 -1
  111. package/build/esm/shared/modules/state-and-params.js +30 -14
  112. package/build/esm/shared/modules/state-and-params.js.map +1 -1
  113. package/build/esm/shared/units/datalens/index.js +5 -2
  114. package/build/esm/shared/units/datalens/index.js.map +1 -1
  115. package/build/esm/utils/enrichLayoutWithDefaults.d.ts +1 -1
  116. package/build/esm/utils/enrichLayoutWithDefaults.js +4 -1
  117. package/build/esm/utils/enrichLayoutWithDefaults.js.map +1 -1
  118. package/build/esm/utils/events.js +1 -1
  119. package/build/esm/utils/events.js.map +1 -1
  120. package/build/esm/utils/get-layout-patches.js +1 -1
  121. package/build/esm/utils/get-layout-patches.js.map +1 -1
  122. package/build/esm/utils/register-manager.js +25 -24
  123. package/build/esm/utils/register-manager.js.map +1 -1
  124. package/build/esm/utils/update-manager.js +103 -66
  125. package/build/esm/utils/update-manager.js.map +1 -1
  126. package/package.json +25 -19
  127. package/build/cjs/components/DashKit/__tests__/controlled-layout.test.d.ts +0 -4
  128. package/build/cjs/components/DashKit/__tests__/controlled-layout.test.js +0 -260
  129. package/build/cjs/components/DashKit/__tests__/controlled-layout.test.js.map +0 -1
  130. package/build/cjs/components/DashKit/__tests__/events.test.d.ts +0 -1
  131. package/build/cjs/components/DashKit/__tests__/events.test.js +0 -227
  132. package/build/cjs/components/DashKit/__tests__/events.test.js.map +0 -1
  133. package/build/cjs/components/GridLayout/__tests__/passive-resize.test.d.ts +0 -2
  134. package/build/cjs/components/GridLayout/__tests__/passive-resize.test.js +0 -386
  135. package/build/cjs/components/GridLayout/__tests__/passive-resize.test.js.map +0 -1
  136. package/build/cjs/hooks/__tests__/useDnDItemProps.test.d.ts +0 -2
  137. package/build/cjs/hooks/__tests__/useDnDItemProps.test.js +0 -45
  138. package/build/cjs/hooks/__tests__/useDnDItemProps.test.js.map +0 -1
  139. package/build/cjs/shared/modules/__tests__/global-items.test.d.ts +0 -1
  140. package/build/cjs/shared/modules/__tests__/global-items.test.js +0 -372
  141. package/build/cjs/shared/modules/__tests__/global-items.test.js.map +0 -1
  142. package/build/cjs/shared/modules/__tests__/helpers.test.d.ts +0 -1
  143. package/build/cjs/shared/modules/__tests__/helpers.test.js +0 -505
  144. package/build/cjs/shared/modules/__tests__/helpers.test.js.map +0 -1
  145. package/build/cjs/shared/modules/__tests__/uniq-id.test.d.ts +0 -1
  146. package/build/cjs/shared/modules/__tests__/uniq-id.test.js +0 -78
  147. package/build/cjs/shared/modules/__tests__/uniq-id.test.js.map +0 -1
  148. package/build/cjs/shared/units/__tests__/state-and-params.test.d.ts +0 -241
  149. package/build/cjs/shared/units/__tests__/state-and-params.test.js +0 -724
  150. package/build/cjs/shared/units/__tests__/state-and-params.test.js.map +0 -1
  151. package/build/cjs/utils/__tests__/get-layout-patches.test.d.ts +0 -1
  152. package/build/cjs/utils/__tests__/get-layout-patches.test.js +0 -51
  153. package/build/cjs/utils/__tests__/get-layout-patches.test.js.map +0 -1
  154. package/build/cjs/utils/__tests__/update-manager.test.d.ts +0 -1
  155. package/build/cjs/utils/__tests__/update-manager.test.js +0 -824
  156. package/build/cjs/utils/__tests__/update-manager.test.js.map +0 -1
  157. package/build/esm/components/DashKit/__tests__/controlled-layout.test.d.ts +0 -4
  158. package/build/esm/components/DashKit/__tests__/controlled-layout.test.js +0 -257
  159. package/build/esm/components/DashKit/__tests__/controlled-layout.test.js.map +0 -1
  160. package/build/esm/components/DashKit/__tests__/events.test.d.ts +0 -1
  161. package/build/esm/components/DashKit/__tests__/events.test.js +0 -225
  162. package/build/esm/components/DashKit/__tests__/events.test.js.map +0 -1
  163. package/build/esm/components/GridLayout/__tests__/passive-resize.test.d.ts +0 -2
  164. package/build/esm/components/GridLayout/__tests__/passive-resize.test.js +0 -383
  165. package/build/esm/components/GridLayout/__tests__/passive-resize.test.js.map +0 -1
  166. package/build/esm/hooks/__tests__/useDnDItemProps.test.d.ts +0 -2
  167. package/build/esm/hooks/__tests__/useDnDItemProps.test.js +0 -42
  168. package/build/esm/hooks/__tests__/useDnDItemProps.test.js.map +0 -1
  169. package/build/esm/shared/modules/__tests__/global-items.test.d.ts +0 -1
  170. package/build/esm/shared/modules/__tests__/global-items.test.js +0 -370
  171. package/build/esm/shared/modules/__tests__/global-items.test.js.map +0 -1
  172. package/build/esm/shared/modules/__tests__/helpers.test.d.ts +0 -1
  173. package/build/esm/shared/modules/__tests__/helpers.test.js +0 -503
  174. package/build/esm/shared/modules/__tests__/helpers.test.js.map +0 -1
  175. package/build/esm/shared/modules/__tests__/uniq-id.test.d.ts +0 -1
  176. package/build/esm/shared/modules/__tests__/uniq-id.test.js +0 -75
  177. package/build/esm/shared/modules/__tests__/uniq-id.test.js.map +0 -1
  178. package/build/esm/shared/units/__tests__/state-and-params.test.d.ts +0 -241
  179. package/build/esm/shared/units/__tests__/state-and-params.test.js +0 -720
  180. package/build/esm/shared/units/__tests__/state-and-params.test.js.map +0 -1
  181. package/build/esm/utils/__tests__/get-layout-patches.test.d.ts +0 -1
  182. package/build/esm/utils/__tests__/get-layout-patches.test.js +0 -49
  183. package/build/esm/utils/__tests__/get-layout-patches.test.js.map +0 -1
  184. package/build/esm/utils/__tests__/update-manager.test.d.ts +0 -1
  185. package/build/esm/utils/__tests__/update-manager.test.js +0 -822
  186. package/build/esm/utils/__tests__/update-manager.test.js.map +0 -1
@@ -17,176 +17,23 @@ const hasPluginId = (value) => {
17
17
  typeof value.props.id === 'string');
18
18
  };
19
19
  class GridLayout extends react_1.default.PureComponent {
20
+ static contextType = context_1.DashKitContext;
21
+ pluginsRefs;
22
+ _memoForwardedPluginRef = [];
23
+ _memoGroupsProps = {};
24
+ _memoGroupsLayouts = {};
25
+ _memoCallbacksForGroups = {};
26
+ _memoGroupsItems = {};
27
+ _sharedDragRef = { current: { isDragging: false, sourceGroup: null } };
28
+ _sharedDragPositionRef = { current: null };
29
+ _groupResetRegistryRef = {
30
+ current: new Map(),
31
+ };
32
+ _timeout;
33
+ _lastReloadAt;
34
+ _parendDragNode = null;
20
35
  constructor(props, context) {
21
36
  super(props, context);
22
- this._memoForwardedPluginRef = [];
23
- this._memoGroupsProps = {};
24
- this._memoGroupsLayouts = {};
25
- this._memoCallbacksForGroups = {};
26
- this._memoGroupsItems = {};
27
- this._sharedDragRef = { current: { isDragging: false, sourceGroup: null } };
28
- this._sharedDragPositionRef = { current: null };
29
- this._groupResetRegistryRef = {
30
- current: new Map(),
31
- };
32
- this._parendDragNode = null;
33
- this.onVisibilityChange = () => {
34
- this.setState({
35
- isPageHidden: document.hidden,
36
- });
37
- };
38
- this.adjustWidgetLayout = ({ widgetId, needSetDefault, adjustedWidgetLayout, }) => {
39
- const { layout, memorizeOriginalLayout, revertToOriginalLayout } = this.context;
40
- if (needSetDefault) {
41
- revertToOriginalLayout(widgetId);
42
- return;
43
- }
44
- if (!adjustedWidgetLayout) {
45
- return;
46
- }
47
- const correspondedLayoutItemIndex = layout.findIndex((layoutItem) => layoutItem.i === widgetId);
48
- memorizeOriginalLayout(widgetId, Object.assign({}, layout[correspondedLayoutItemIndex]), adjustedWidgetLayout);
49
- };
50
- this.getItemsMeta = () => {
51
- const { getItemsMeta } = this.context;
52
- return getItemsMeta(this.pluginsRefs);
53
- };
54
- this.getMemoGroupProps = (group, renderLayout, nextProperties) => {
55
- // Return stable ref to prevent useMemo invalidation when properties are shallowly equal.
56
- const prevProperties = this._memoGroupsProps[group];
57
- const keysNext = Object.keys(nextProperties);
58
- const stableProperties = prevProperties &&
59
- Object.keys(prevProperties).length === keysNext.length &&
60
- keysNext.every((k) => prevProperties[k] === nextProperties[k])
61
- ? prevProperties
62
- : nextProperties;
63
- // Needed for _onDropDragOver
64
- this._memoGroupsProps[group] = stableProperties;
65
- return {
66
- layout: this.getMemoGroupLayout(group, renderLayout).layout,
67
- callbacks: this.getMemoGroupCallbacks(group),
68
- stableProperties,
69
- };
70
- };
71
- this.getLayoutAndPropsByGroup = (group) => {
72
- return {
73
- properties: this._memoGroupsProps[group],
74
- layout: this._memoGroupsLayouts[group].layout,
75
- };
76
- };
77
- this.getMemoForwardRefCallback = (refIndex) => {
78
- if (!this._memoForwardedPluginRef[refIndex]) {
79
- this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
80
- this.pluginsRefs[refIndex] = pluginRef;
81
- };
82
- }
83
- return this._memoForwardedPluginRef[refIndex];
84
- };
85
- this._onStop = (group, newLayout) => {
86
- const { layoutChange, onDrop, temporaryLayout } = this.context;
87
- const { draggedOverGroup, currentDraggingElement } = this.state;
88
- if (currentDraggingElement &&
89
- draggedOverGroup !== null &&
90
- draggedOverGroup !== currentDraggingElement.group) {
91
- // Skipping layout update when change event called for source grid
92
- // and waiting _onDrop
93
- return;
94
- }
95
- const groupedLayout = this.mergeGroupsLayout(group, newLayout);
96
- this._clearSharedDragState();
97
- this.setState({
98
- isDragging: false,
99
- currentDraggingElement: null,
100
- draggedOverGroup: null,
101
- });
102
- if (temporaryLayout) {
103
- const temporaryItem = groupedLayout.find(({ i }) => i === constants_1.TEMPORARY_ITEM_ID);
104
- if (onDrop && temporaryItem) {
105
- onDrop(groupedLayout, temporaryItem);
106
- }
107
- }
108
- else {
109
- layoutChange(groupedLayout);
110
- }
111
- };
112
- this._onSharedDrop = (targetGroup, newLayout, tempItem) => {
113
- const { currentDraggingElement } = this.state;
114
- const { layoutChange } = this.context;
115
- if (!currentDraggingElement) {
116
- return;
117
- }
118
- const sourceLayoutItem = currentDraggingElement.layoutItem;
119
- const groupedLayout = this.mergeGroupsLayout(targetGroup, newLayout, tempItem).map((item) => {
120
- if (item.i === sourceLayoutItem.i) {
121
- const copy = Object.assign({}, tempItem);
122
- delete copy.parent;
123
- if (targetGroup !== constants_1.DEFAULT_GROUP) {
124
- copy.parent = targetGroup;
125
- }
126
- copy.i = sourceLayoutItem.i;
127
- return copy;
128
- }
129
- return item;
130
- });
131
- this._clearSharedDragState();
132
- this.setState({
133
- isDragging: false,
134
- currentDraggingElement: null,
135
- draggedOverGroup: null,
136
- });
137
- // TODO temporaryLayout
138
- layoutChange(groupedLayout);
139
- };
140
- this._onExternalDrop = (group, newLayout, item, e) => {
141
- const { onDrop } = this.context;
142
- if (group !== constants_1.DEFAULT_GROUP) {
143
- item.parent = group;
144
- }
145
- const groupedLayout = this.mergeGroupsLayout(group, newLayout, item);
146
- this._sharedDragRef.current = { isDragging: false, sourceGroup: null };
147
- this.setState({ isDragging: false });
148
- onDrop === null || onDrop === void 0 ? void 0 : onDrop(groupedLayout, item, e);
149
- };
150
- this._onDrop = (group, newLayout, item, e) => {
151
- if (!item || !this.context.editMode) {
152
- return false;
153
- }
154
- const { draggedOverGroup, currentDraggingElement } = this.state;
155
- if (currentDraggingElement && draggedOverGroup === group) {
156
- this._onSharedDrop(group, newLayout, item);
157
- }
158
- else {
159
- this._onExternalDrop(group, newLayout, item, e);
160
- }
161
- };
162
- this._onDropDragOver = (group, e) => {
163
- const { editMode, dragOverPlugin, onDropDragOver, temporaryLayout } = this.context;
164
- const { currentDraggingElement } = this.state;
165
- // TODO If temporary item is trying to change group
166
- if (temporaryLayout && currentDraggingElement) {
167
- return false;
168
- }
169
- if (!editMode || (!dragOverPlugin && !currentDraggingElement)) {
170
- return false;
171
- }
172
- const { properties, layout } = this.getLayoutAndPropsByGroup(group);
173
- if (currentDraggingElement) {
174
- const { h, w, i } = currentDraggingElement.layoutItem;
175
- const { type } = currentDraggingElement.item;
176
- const sharedItem = {
177
- h,
178
- w,
179
- i,
180
- type,
181
- parent: currentDraggingElement.group,
182
- };
183
- return onDropDragOver(e, group, properties, layout, sharedItem);
184
- }
185
- if (dragOverPlugin) {
186
- return onDropDragOver(e, group, properties, layout);
187
- }
188
- return false;
189
- };
190
37
  this.pluginsRefs = [];
191
38
  this.state = {
192
39
  isDragging: false,
@@ -213,9 +60,30 @@ class GridLayout extends react_1.default.PureComponent {
213
60
  this._memoGroupsItems = {};
214
61
  this._memoForwardedPluginRef = [];
215
62
  }
63
+ onVisibilityChange = () => {
64
+ this.setState({
65
+ isPageHidden: document.hidden,
66
+ });
67
+ };
68
+ adjustWidgetLayout = ({ widgetId, needSetDefault, adjustedWidgetLayout, }) => {
69
+ const { layout, memorizeOriginalLayout, revertToOriginalLayout } = this.context;
70
+ if (needSetDefault) {
71
+ revertToOriginalLayout(widgetId);
72
+ return;
73
+ }
74
+ if (!adjustedWidgetLayout) {
75
+ return;
76
+ }
77
+ const correspondedLayoutItemIndex = layout.findIndex((layoutItem) => layoutItem.i === widgetId);
78
+ memorizeOriginalLayout(widgetId, { ...layout[correspondedLayoutItemIndex] }, adjustedWidgetLayout);
79
+ };
80
+ getItemsMeta = () => {
81
+ const { getItemsMeta } = this.context;
82
+ return getItemsMeta(this.pluginsRefs);
83
+ };
216
84
  getActiveLayout() {
217
85
  const { layout, temporaryLayout } = this.context;
218
- return (temporaryLayout === null || temporaryLayout === void 0 ? void 0 : temporaryLayout.data) || layout;
86
+ return temporaryLayout?.data || layout;
219
87
  }
220
88
  getMemoGroupLayout(group, layout) {
221
89
  // fastest possible way to match json
@@ -272,6 +140,37 @@ class GridLayout extends react_1.default.PureComponent {
272
140
  this._memoGroupsItems[group] = nextItems;
273
141
  return nextItems;
274
142
  }
143
+ getMemoGroupProps = (group, renderLayout, nextProperties) => {
144
+ // Return stable ref to prevent useMemo invalidation when properties are shallowly equal.
145
+ const prevProperties = this._memoGroupsProps[group];
146
+ const keysNext = Object.keys(nextProperties);
147
+ const stableProperties = prevProperties &&
148
+ Object.keys(prevProperties).length === keysNext.length &&
149
+ keysNext.every((k) => prevProperties[k] === nextProperties[k])
150
+ ? prevProperties
151
+ : nextProperties;
152
+ // Needed for _onDropDragOver
153
+ this._memoGroupsProps[group] = stableProperties;
154
+ return {
155
+ layout: this.getMemoGroupLayout(group, renderLayout).layout,
156
+ callbacks: this.getMemoGroupCallbacks(group),
157
+ stableProperties,
158
+ };
159
+ };
160
+ getLayoutAndPropsByGroup = (group) => {
161
+ return {
162
+ properties: this._memoGroupsProps[group],
163
+ layout: this._memoGroupsLayouts[group].layout,
164
+ };
165
+ };
166
+ getMemoForwardRefCallback = (refIndex) => {
167
+ if (!this._memoForwardedPluginRef[refIndex]) {
168
+ this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
169
+ this.pluginsRefs[refIndex] = pluginRef;
170
+ };
171
+ }
172
+ return this._memoForwardedPluginRef[refIndex];
173
+ };
275
174
  mergeGroupsLayout(group, newLayout, temporaryItem) {
276
175
  const renderLayout = this.getActiveLayout();
277
176
  const itemsByGroup = renderLayout.reduce((memo, item) => {
@@ -279,9 +178,8 @@ class GridLayout extends react_1.default.PureComponent {
279
178
  return memo;
280
179
  }, temporaryItem ? { [temporaryItem.i]: temporaryItem } : {});
281
180
  const newItemsLayoutById = newLayout.reduce((memo, item) => {
282
- var _a;
283
- const parent = (_a = itemsByGroup[item.i]) === null || _a === void 0 ? void 0 : _a.parent;
284
- memo[item.i] = Object.assign({}, item);
181
+ const parent = itemsByGroup[item.i]?.parent;
182
+ memo[item.i] = { ...item };
285
183
  if (parent) {
286
184
  memo[item.i].parent = parent;
287
185
  }
@@ -421,8 +319,7 @@ class GridLayout extends react_1.default.PureComponent {
421
319
  this.setState({ isDraggedOut: false });
422
320
  }
423
321
  _onDragStart(group, _newLayout, layoutItem, _newItem, _placeholder, e, element) {
424
- var _a;
425
- (_a = this.context.onDragStart) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, _newLayout, layoutItem, _newItem, _placeholder, e, element));
322
+ this.context.onDragStart?.call(this, this.prepareDefaultArguments(group, _newLayout, layoutItem, _newItem, _placeholder, e, element));
426
323
  if (this.context.dragOverPlugin) {
427
324
  this.setState({ isDragging: true });
428
325
  }
@@ -444,33 +341,28 @@ class GridLayout extends react_1.default.PureComponent {
444
341
  }
445
342
  }
446
343
  _onDrag(group, layout, oldItem, newItem, placeholder, e, element) {
447
- var _a;
448
344
  if (!this.context.dragOverPlugin) {
449
345
  this._updateDragCoordinates(e);
450
346
  }
451
- (_a = this.context.onDrag) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
347
+ this.context.onDrag?.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
452
348
  }
453
349
  _onDragStop(group, layout, oldItem, newItem, placeholder, e, element) {
454
- var _a;
455
350
  this._resetDragWatcher();
456
351
  this._onStop(group, layout);
457
- (_a = this.context.onDragStop) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
352
+ this.context.onDragStop?.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
458
353
  }
459
354
  _onResizeStart(group, layout, oldItem, newItem, placeholder, e, element) {
460
- var _a;
461
355
  this.setState({
462
356
  isDragging: true,
463
357
  });
464
- (_a = this.context.onResizeStart) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
358
+ this.context.onResizeStart?.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
465
359
  }
466
360
  _onResize(group, layout, oldItem, newItem, placeholder, e, element) {
467
- var _a;
468
- (_a = this.context.onResize) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
361
+ this.context.onResize?.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
469
362
  }
470
363
  _onResizeStop(group, layout, oldItem, newItem, placeholder, e, element) {
471
- var _a;
472
364
  this._onStop(group, layout);
473
- (_a = this.context.onResizeStop) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
365
+ this.context.onResizeStop?.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
474
366
  }
475
367
  _onTargetRestore() {
476
368
  if (this.context.temporaryLayout) {
@@ -483,6 +375,111 @@ class GridLayout extends react_1.default.PureComponent {
483
375
  });
484
376
  }
485
377
  }
378
+ _onStop = (group, newLayout) => {
379
+ const { layoutChange, onDrop, temporaryLayout } = this.context;
380
+ const { draggedOverGroup, currentDraggingElement } = this.state;
381
+ if (currentDraggingElement &&
382
+ draggedOverGroup !== null &&
383
+ draggedOverGroup !== currentDraggingElement.group) {
384
+ // Skipping layout update when change event called for source grid
385
+ // and waiting _onDrop
386
+ return;
387
+ }
388
+ const groupedLayout = this.mergeGroupsLayout(group, newLayout);
389
+ this._clearSharedDragState();
390
+ this.setState({
391
+ isDragging: false,
392
+ currentDraggingElement: null,
393
+ draggedOverGroup: null,
394
+ });
395
+ if (temporaryLayout) {
396
+ const temporaryItem = groupedLayout.find(({ i }) => i === constants_1.TEMPORARY_ITEM_ID);
397
+ if (onDrop && temporaryItem) {
398
+ onDrop(groupedLayout, temporaryItem);
399
+ }
400
+ }
401
+ else {
402
+ layoutChange(groupedLayout);
403
+ }
404
+ };
405
+ _onSharedDrop = (targetGroup, newLayout, tempItem) => {
406
+ const { currentDraggingElement } = this.state;
407
+ const { layoutChange } = this.context;
408
+ if (!currentDraggingElement) {
409
+ return;
410
+ }
411
+ const sourceLayoutItem = currentDraggingElement.layoutItem;
412
+ const groupedLayout = this.mergeGroupsLayout(targetGroup, newLayout, tempItem).map((item) => {
413
+ if (item.i === sourceLayoutItem.i) {
414
+ const copy = { ...tempItem };
415
+ delete copy.parent;
416
+ if (targetGroup !== constants_1.DEFAULT_GROUP) {
417
+ copy.parent = targetGroup;
418
+ }
419
+ copy.i = sourceLayoutItem.i;
420
+ return copy;
421
+ }
422
+ return item;
423
+ });
424
+ this._clearSharedDragState();
425
+ this.setState({
426
+ isDragging: false,
427
+ currentDraggingElement: null,
428
+ draggedOverGroup: null,
429
+ });
430
+ // TODO temporaryLayout
431
+ layoutChange(groupedLayout);
432
+ };
433
+ _onExternalDrop = (group, newLayout, item, e) => {
434
+ const { onDrop } = this.context;
435
+ if (group !== constants_1.DEFAULT_GROUP) {
436
+ item.parent = group;
437
+ }
438
+ const groupedLayout = this.mergeGroupsLayout(group, newLayout, item);
439
+ this._sharedDragRef.current = { isDragging: false, sourceGroup: null };
440
+ this.setState({ isDragging: false });
441
+ onDrop?.(groupedLayout, item, e);
442
+ };
443
+ _onDrop = (group, newLayout, item, e) => {
444
+ if (!item || !this.context.editMode) {
445
+ return false;
446
+ }
447
+ const { draggedOverGroup, currentDraggingElement } = this.state;
448
+ if (currentDraggingElement && draggedOverGroup === group) {
449
+ this._onSharedDrop(group, newLayout, item);
450
+ }
451
+ else {
452
+ this._onExternalDrop(group, newLayout, item, e);
453
+ }
454
+ };
455
+ _onDropDragOver = (group, e) => {
456
+ const { editMode, dragOverPlugin, onDropDragOver, temporaryLayout } = this.context;
457
+ const { currentDraggingElement } = this.state;
458
+ // TODO If temporary item is trying to change group
459
+ if (temporaryLayout && currentDraggingElement) {
460
+ return false;
461
+ }
462
+ if (!editMode || (!dragOverPlugin && !currentDraggingElement)) {
463
+ return false;
464
+ }
465
+ const { properties, layout } = this.getLayoutAndPropsByGroup(group);
466
+ if (currentDraggingElement) {
467
+ const { h, w, i } = currentDraggingElement.layoutItem;
468
+ const { type } = currentDraggingElement.item;
469
+ const sharedItem = {
470
+ h,
471
+ w,
472
+ i,
473
+ type,
474
+ parent: currentDraggingElement.group,
475
+ };
476
+ return onDropDragOver(e, group, properties, layout, sharedItem);
477
+ }
478
+ if (dragOverPlugin) {
479
+ return onDropDragOver(e, group, properties, layout);
480
+ }
481
+ return false;
482
+ };
486
483
  _clearSharedDragState() {
487
484
  this._sharedDragRef.current = { isDragging: false, sourceGroup: null };
488
485
  this._sharedDragPositionRef.current = null;
@@ -504,7 +501,7 @@ class GridLayout extends react_1.default.PureComponent {
504
501
  const { currentDraggingElement, draggedOverGroup, isDragging, isDraggedOut } = this.state;
505
502
  const hasOwnGroupProperties = typeof groupGridProperties === 'function';
506
503
  const properties = hasOwnGroupProperties
507
- ? groupGridProperties(Object.assign({}, registerManager.gridLayout))
504
+ ? groupGridProperties({ ...registerManager.gridLayout })
508
505
  : registerManager.gridLayout;
509
506
  const { callbacks, layout, stableProperties } = this.getMemoGroupProps(group, renderLayout, properties);
510
507
  const compactType = stableProperties.compactType === constants_1.COMPACT_TYPE_HORIZONTAL_NOWRAP
@@ -518,12 +515,13 @@ class GridLayout extends react_1.default.PureComponent {
518
515
  ? currentDraggingElement.item.id
519
516
  : null;
520
517
  // Non-source groups get stable false/null — memo skips re-render on drag move.
521
- const isSourceGroup = Boolean((currentDraggingElement === null || currentDraggingElement === void 0 ? void 0 : currentDraggingElement.group) === group);
518
+ const isSourceGroup = Boolean(currentDraggingElement?.group === group);
522
519
  const groupIsAnyDragging = isDragging && isSourceGroup;
523
520
  const groupCurrentDraggingItemId = isSourceGroup ? currentDraggingItemId : null;
524
521
  const groupIsAnyDraggedOut = isSourceGroup ? isDraggedOut : false;
525
522
  return (react_1.default.createElement(GroupLayout_1.GroupLayout, { key: `group_${group}`, group: group, renderItems: renderItems, offset: offset, properties: stableProperties, compactType: compactType, callbacks: callbacks, layout: layout, temporaryPlaceholder: this.renderTemporaryPlaceholder(stableProperties), dragStateRef: this._sharedDragRef, sharedDragPositionRef: this._sharedDragPositionRef, groupResetRegistryRef: this._groupResetRegistryRef, isDragCaptured: isDragCaptured, isAnyDragging: groupIsAnyDragging, currentDraggingItemId: groupCurrentDraggingItemId, isAnyDraggedOut: groupIsAnyDraggedOut, adjustWidgetLayout: this.adjustWidgetLayout, getMemoForwardRefCallback: this.getMemoForwardRefCallback }));
526
523
  }
524
+ // An explicit type: the inferred one spells out ReactNode of the @types/react the package is built with
527
525
  render() {
528
526
  const { config, groups, editMode, context } = this.context;
529
527
  this.pluginsRefs.length = this.context.configItems.length;
@@ -592,6 +590,5 @@ class GridLayout extends react_1.default.PureComponent {
592
590
  }
593
591
  }
594
592
  }
595
- GridLayout.contextType = context_1.DashKitContext;
596
593
  exports.default = GridLayout;
597
594
  //# sourceMappingURL=GridLayout.js.map