@gravity-ui/dashkit 10.5.2 → 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 +1 -1
  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 +1 -1
  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
@@ -1,4 +1,3 @@
1
- import { __rest } from "tslib";
2
1
  import React from 'react';
3
2
  import { flushSync } from 'react-dom';
4
3
  // @ts-expect-error - utils is not exported in type definitions
@@ -25,158 +24,29 @@ const getGridItemStyle = ({ cols, containerPadding, margin, width, x, y, w, h, r
25
24
  width: Math.round(columnWidth * w + marginX * (w - 1)),
26
25
  };
27
26
  return useCSSTransforms
28
- ? Object.assign(Object.assign({}, utils.setTransform(position)), { left: '', top: '' }) : Object.assign(Object.assign({}, utils.setTopLeft(position)), { MozTransform: '', OTransform: '', WebkitTransform: '', msTransform: '', transform: '' });
27
+ ? { ...utils.setTransform(position), left: '', top: '' }
28
+ : {
29
+ ...utils.setTopLeft(position),
30
+ MozTransform: '',
31
+ OTransform: '',
32
+ WebkitTransform: '',
33
+ msTransform: '',
34
+ transform: '',
35
+ };
29
36
  };
30
37
  class DragOverLayout extends ReactGridLayout {
38
+ parentOnDrag;
39
+ parentOnDragStop;
40
+ parentOnDragOver;
41
+ _savedDraggedOutLayout = null;
42
+ // Suppresses onLayoutMaybeChanged during imperative layout restore actions.
43
+ // Without this flag, our setState would trigger onLayoutChange back to the consumer
44
+ // that just initiated the action, causing a spurious 'change' event.
45
+ _isRestoringExternalLayout = false;
46
+ touchTarget = null;
47
+ gridItemChildren = new WeakMap();
31
48
  constructor(props, context) {
32
49
  super(props, context);
33
- this._savedDraggedOutLayout = null;
34
- // Suppresses onLayoutMaybeChanged during imperative layout restore actions.
35
- // Without this flag, our setState would trigger onLayoutChange back to the consumer
36
- // that just initiated the action, causing a spurious 'change' event.
37
- this._isRestoringExternalLayout = false;
38
- this.touchTarget = null;
39
- this.gridItemChildren = new WeakMap();
40
- // Reset placeholder when item dragged from outside
41
- this.resetExternalPlaceholder = () => {
42
- // @ts-expect-error - dragEnterCounter is an internal property of parent class
43
- if (this.dragEnterCounter) {
44
- // @ts-expect-error - dragEnterCounter is an internal property of parent class
45
- this.dragEnterCounter = 0;
46
- // @ts-expect-error - removeDroppingPlaceholder is a protected method in parent class
47
- this.removeDroppingPlaceholder();
48
- }
49
- };
50
- // Hide placeholder when element is dragged out
51
- this.hideLocalPlaceholder = (i) => {
52
- const { layout } = this.state;
53
- const { cols } = this.props;
54
- const savedLayout = layout.map((item) => (Object.assign({}, item)));
55
- let hiddenElement;
56
- const newLayout = utils.compact(layout.filter((item) => {
57
- if (item.i === i) {
58
- hiddenElement = item;
59
- return false;
60
- }
61
- return true;
62
- }), utils.compactType(this.props), cols);
63
- if (hiddenElement) {
64
- newLayout.push(hiddenElement);
65
- }
66
- this.setState({
67
- activeDrag: null,
68
- layout: newLayout,
69
- });
70
- return savedLayout;
71
- };
72
- this.extendedOnDrag = (i, x, y, sintEv) => {
73
- if ('touches' in sintEv.e) {
74
- this.updateTouchTarget(sintEv.e);
75
- }
76
- if (this.props.isDragCaptured) {
77
- if (!this._savedDraggedOutLayout) {
78
- this._savedDraggedOutLayout = this.hideLocalPlaceholder(i);
79
- }
80
- return;
81
- }
82
- this._savedDraggedOutLayout = null;
83
- // parent onDrag will show new placeholder again
84
- this.parentOnDrag(i, x, y, sintEv);
85
- };
86
- this.extendedOnDragStop = (i, x, y, sintEv) => {
87
- var _a, _b;
88
- if ('changedTouches' in sintEv.e) {
89
- const position = getEventPosition(sintEv.e, (_a = this.props.dragStateRef) === null || _a === void 0 ? void 0 : _a.current.touchIdentifier);
90
- if (position) {
91
- (_b = this.touchTarget) === null || _b === void 0 ? void 0 : _b.dispatchEvent(new MouseEvent('mouseup', position));
92
- }
93
- this.touchTarget = null;
94
- }
95
- // Restoring layout if item was dropped outside of the grid
96
- if (this._savedDraggedOutLayout) {
97
- const savedLayout = this._savedDraggedOutLayout;
98
- const l = utils.getLayoutItem(savedLayout, i);
99
- // Create placeholder (display only)
100
- const placeholder = {
101
- w: l.w,
102
- h: l.h,
103
- x: l.x,
104
- y: l.y,
105
- placeholder: true,
106
- i: i,
107
- };
108
- this.setState({
109
- layout: savedLayout,
110
- activeDrag: placeholder,
111
- }, () => {
112
- this.parentOnDragStop(i, x, y, sintEv);
113
- });
114
- this._savedDraggedOutLayout = null;
115
- }
116
- else {
117
- this.parentOnDragStop(i, x, y, sintEv);
118
- }
119
- };
120
- this.extendedOnDragOver = (e) => {
121
- var _a, _b;
122
- (_b = (_a = this.props).onBeforeDragOver) === null || _b === void 0 ? void 0 : _b.call(_a);
123
- return this.parentOnDragOver(e);
124
- };
125
- this.isSharedDragTarget = () => {
126
- var _a;
127
- const drag = (_a = this.props.dragStateRef) === null || _a === void 0 ? void 0 : _a.current;
128
- return Boolean(drag === null || drag === void 0 ? void 0 : drag.isDragging);
129
- };
130
- // Proxy mouse events -> drag methods for dnd between groups
131
- this.mouseEnterHandler = (e) => {
132
- var _a, _b;
133
- if (this.isSharedDragTarget()) {
134
- // @ts-expect-error - onDragEnter is a protected method in parent class
135
- this.onDragEnter(e);
136
- }
137
- else if (this.props.isDragCaptured) {
138
- (_b = (_a = this.props).onDragTargetRestore) === null || _b === void 0 ? void 0 : _b.call(_a);
139
- }
140
- };
141
- this.mouseLeaveHandler = (e) => {
142
- var _a, _b;
143
- if (this.isSharedDragTarget()) {
144
- // @ts-expect-error - onDragLeave is a protected method in parent class
145
- this.onDragLeave(e);
146
- (_b = (_a = this.props).onDragTargetRestore) === null || _b === void 0 ? void 0 : _b.call(_a);
147
- }
148
- };
149
- this.mouseMoveHandler = (e) => {
150
- var _a;
151
- if (this.isSharedDragTarget() &&
152
- this.props.group !== ((_a = this.props.dragStateRef) === null || _a === void 0 ? void 0 : _a.current.sourceGroup)) {
153
- if (!e.nativeEvent) {
154
- // Emulate nativeEvent for firefox
155
- const target = this.getInnerElement() || e.target;
156
- e.nativeEvent = {
157
- clientX: e.clientX,
158
- clientY: e.clientY,
159
- target,
160
- };
161
- }
162
- // @ts-expect-error - onDragOver is a protected method in parent class
163
- this.onDragOver(e);
164
- }
165
- };
166
- this.mouseUpHandler = (e) => {
167
- var _a, _b, _c;
168
- if (this.isSharedDragTarget()) {
169
- e.preventDefault();
170
- const { droppingItem } = this.props;
171
- const { layout } = this.state;
172
- const item = layout.find((l) => l.i === (droppingItem === null || droppingItem === void 0 ? void 0 : droppingItem.i));
173
- // reset dragEnter counter on drop for all registered groups
174
- (_a = this.props.groupResetRegistryRef) === null || _a === void 0 ? void 0 : _a.current.forEach((reset) => reset());
175
- if (item) {
176
- (_c = (_b = this.props).onDrop) === null || _c === void 0 ? void 0 : _c.call(_b, layout, item, e);
177
- }
178
- }
179
- };
180
50
  // @ts-expect-error - onDrag is a protected method in parent class
181
51
  this.parentOnDrag = this.onDrag;
182
52
  // @ts-expect-error - assigning custom method to parent's onDrag
@@ -191,10 +61,9 @@ class DragOverLayout extends ReactGridLayout {
191
61
  this.onDragOver = this.extendedOnDragOver;
192
62
  }
193
63
  componentDidMount() {
194
- var _a, _b;
195
- (_a = super.componentDidMount) === null || _a === void 0 ? void 0 : _a.call(this);
64
+ super.componentDidMount?.();
196
65
  if (this.props.group !== undefined) {
197
- (_b = this.props.groupResetRegistryRef) === null || _b === void 0 ? void 0 : _b.current.set(this.props.group, this.resetExternalPlaceholder);
66
+ this.props.groupResetRegistryRef?.current.set(this.props.group, this.resetExternalPlaceholder);
198
67
  }
199
68
  // If cursor is moved out of the window there is a bug
200
69
  // which leaves placeholder element in grid, this action needed to reset this state
@@ -208,7 +77,6 @@ class DragOverLayout extends ReactGridLayout {
208
77
  }
209
78
  }
210
79
  componentDidUpdate(prevProps, prevState) {
211
- var _a;
212
80
  const revisionChanged = prevProps.externalLayoutRevision !== this.props.externalLayoutRevision;
213
81
  if (revisionChanged && this.props.layout) {
214
82
  const newLayout = utils.synchronizeLayoutWithChildren(this.props.layout, this.props.children, this.props.cols, utils.compactType(this.props), this.props.allowOverlap);
@@ -231,7 +99,7 @@ class DragOverLayout extends ReactGridLayout {
231
99
  return;
232
100
  }
233
101
  // Maintain parent behavior for all non-restore cycles (drag, resize, etc.).
234
- (_a = super.componentDidUpdate) === null || _a === void 0 ? void 0 : _a.call(this, prevProps, prevState);
102
+ super.componentDidUpdate?.(prevProps, prevState);
235
103
  }
236
104
  onLayoutMaybeChanged(newLayout, oldLayout) {
237
105
  if (this._isRestoringExternalLayout) {
@@ -241,9 +109,8 @@ class DragOverLayout extends ReactGridLayout {
241
109
  super.onLayoutMaybeChanged(newLayout, oldLayout);
242
110
  }
243
111
  componentWillUnmount() {
244
- var _a;
245
112
  if (this.props.group !== undefined) {
246
- (_a = this.props.groupResetRegistryRef) === null || _a === void 0 ? void 0 : _a.current.delete(this.props.group);
113
+ this.props.groupResetRegistryRef?.current.delete(this.props.group);
247
114
  }
248
115
  window.removeEventListener('dragend', this.resetExternalPlaceholder);
249
116
  const innerElement = this.getInnerElement();
@@ -274,10 +141,142 @@ class DragOverLayout extends ReactGridLayout {
274
141
  const { innerRef } = this.props;
275
142
  return innerRef && isRefObject(innerRef) && innerRef.current ? innerRef.current : null;
276
143
  }
144
+ // Reset placeholder when item dragged from outside
145
+ resetExternalPlaceholder = () => {
146
+ // @ts-expect-error - dragEnterCounter is an internal property of parent class
147
+ if (this.dragEnterCounter) {
148
+ // @ts-expect-error - dragEnterCounter is an internal property of parent class
149
+ this.dragEnterCounter = 0;
150
+ // @ts-expect-error - removeDroppingPlaceholder is a protected method in parent class
151
+ this.removeDroppingPlaceholder();
152
+ }
153
+ };
154
+ // Hide placeholder when element is dragged out
155
+ hideLocalPlaceholder = (i) => {
156
+ const { layout } = this.state;
157
+ const { cols } = this.props;
158
+ const savedLayout = layout.map((item) => ({ ...item }));
159
+ let hiddenElement;
160
+ const newLayout = utils.compact(layout.filter((item) => {
161
+ if (item.i === i) {
162
+ hiddenElement = item;
163
+ return false;
164
+ }
165
+ return true;
166
+ }), utils.compactType(this.props), cols);
167
+ if (hiddenElement) {
168
+ newLayout.push(hiddenElement);
169
+ }
170
+ this.setState({
171
+ activeDrag: null,
172
+ layout: newLayout,
173
+ });
174
+ return savedLayout;
175
+ };
176
+ extendedOnDrag = (i, x, y, sintEv) => {
177
+ if ('touches' in sintEv.e) {
178
+ this.updateTouchTarget(sintEv.e);
179
+ }
180
+ if (this.props.isDragCaptured) {
181
+ if (!this._savedDraggedOutLayout) {
182
+ this._savedDraggedOutLayout = this.hideLocalPlaceholder(i);
183
+ }
184
+ return;
185
+ }
186
+ this._savedDraggedOutLayout = null;
187
+ // parent onDrag will show new placeholder again
188
+ this.parentOnDrag(i, x, y, sintEv);
189
+ };
190
+ extendedOnDragStop = (i, x, y, sintEv) => {
191
+ if ('changedTouches' in sintEv.e) {
192
+ const position = getEventPosition(sintEv.e, this.props.dragStateRef?.current.touchIdentifier);
193
+ if (position) {
194
+ this.touchTarget?.dispatchEvent(new MouseEvent('mouseup', position));
195
+ }
196
+ this.touchTarget = null;
197
+ }
198
+ // Restoring layout if item was dropped outside of the grid
199
+ if (this._savedDraggedOutLayout) {
200
+ const savedLayout = this._savedDraggedOutLayout;
201
+ const l = utils.getLayoutItem(savedLayout, i);
202
+ // Create placeholder (display only)
203
+ const placeholder = {
204
+ w: l.w,
205
+ h: l.h,
206
+ x: l.x,
207
+ y: l.y,
208
+ placeholder: true,
209
+ i: i,
210
+ };
211
+ this.setState({
212
+ layout: savedLayout,
213
+ activeDrag: placeholder,
214
+ }, () => {
215
+ this.parentOnDragStop(i, x, y, sintEv);
216
+ });
217
+ this._savedDraggedOutLayout = null;
218
+ }
219
+ else {
220
+ this.parentOnDragStop(i, x, y, sintEv);
221
+ }
222
+ };
223
+ extendedOnDragOver = (e) => {
224
+ this.props.onBeforeDragOver?.();
225
+ return this.parentOnDragOver(e);
226
+ };
227
+ isSharedDragTarget = () => {
228
+ const drag = this.props.dragStateRef?.current;
229
+ return Boolean(drag?.isDragging);
230
+ };
231
+ // Proxy mouse events -> drag methods for dnd between groups
232
+ mouseEnterHandler = (e) => {
233
+ if (this.isSharedDragTarget()) {
234
+ // @ts-expect-error - onDragEnter is a protected method in parent class
235
+ this.onDragEnter(e);
236
+ }
237
+ else if (this.props.isDragCaptured) {
238
+ this.props.onDragTargetRestore?.();
239
+ }
240
+ };
241
+ mouseLeaveHandler = (e) => {
242
+ if (this.isSharedDragTarget()) {
243
+ // @ts-expect-error - onDragLeave is a protected method in parent class
244
+ this.onDragLeave(e);
245
+ this.props.onDragTargetRestore?.();
246
+ }
247
+ };
248
+ mouseMoveHandler = (e) => {
249
+ if (this.isSharedDragTarget() &&
250
+ this.props.group !== this.props.dragStateRef?.current.sourceGroup) {
251
+ if (!e.nativeEvent) {
252
+ // Emulate nativeEvent for firefox
253
+ const target = this.getInnerElement() || e.target;
254
+ e.nativeEvent = {
255
+ clientX: e.clientX,
256
+ clientY: e.clientY,
257
+ target,
258
+ };
259
+ }
260
+ // @ts-expect-error - onDragOver is a protected method in parent class
261
+ this.onDragOver(e);
262
+ }
263
+ };
264
+ mouseUpHandler = (e) => {
265
+ if (this.isSharedDragTarget()) {
266
+ e.preventDefault();
267
+ const { droppingItem } = this.props;
268
+ const { layout } = this.state;
269
+ const item = layout.find((l) => l.i === droppingItem?.i);
270
+ // reset dragEnter counter on drop for all registered groups
271
+ this.props.groupResetRegistryRef?.current.forEach((reset) => reset());
272
+ if (item) {
273
+ this.props.onDrop?.(layout, item, e);
274
+ }
275
+ }
276
+ };
277
277
  calculateDroppingPosition(itemProps) {
278
- var _a;
279
278
  const { containerWidth, cols, w, h, rowHeight, margin, transformScale, droppingPosition } = itemProps;
280
- const sharedDragPosition = (_a = this.props.sharedDragPositionRef) === null || _a === void 0 ? void 0 : _a.current;
279
+ const sharedDragPosition = this.props.sharedDragPositionRef?.current;
281
280
  let offsetX, offsetY;
282
281
  if (sharedDragPosition) {
283
282
  offsetX = sharedDragPosition.offsetX;
@@ -287,16 +286,19 @@ class DragOverLayout extends ReactGridLayout {
287
286
  offsetX = (((containerWidth / cols) * w) / 2 || 0) * transformScale;
288
287
  offsetY = ((h * rowHeight + (h - 1) * margin[1]) / 2 || 0) * transformScale;
289
288
  }
290
- return Object.assign(Object.assign({}, droppingPosition), { left: droppingPosition.left - offsetX, top: droppingPosition.top - offsetY });
289
+ return {
290
+ ...droppingPosition,
291
+ left: droppingPosition.left - offsetX,
292
+ top: droppingPosition.top - offsetY,
293
+ };
291
294
  }
292
295
  // Drop item from outside gets 0,0 droppingPosition
293
296
  // centering cursor on newly creted grid item
294
297
  // And cause grid-layout using it's own GridItem to make it look
295
298
  // like overlay adding className
296
299
  processGridItem(child, isDroppingItem) {
297
- var _a;
298
300
  // @ts-expect-error - processGridItem is a protected method in parent class
299
- const gridItem = (_a = super.processGridItem) === null || _a === void 0 ? void 0 : _a.call(this, child, isDroppingItem);
301
+ const gridItem = super.processGridItem?.(child, isDroppingItem);
300
302
  if (!gridItem) {
301
303
  return gridItem;
302
304
  }
@@ -323,10 +325,15 @@ class DragOverLayout extends ReactGridLayout {
323
325
  : undefined;
324
326
  if (isDroppingItem) {
325
327
  // React.cloneElement is just cleaner then copy-paste whole processGridItem method
326
- return React.cloneElement(gridItem, Object.assign(Object.assign({}, (lazyScale !== undefined && { transformScale: lazyScale })), {
328
+ return React.cloneElement(gridItem, {
329
+ ...(lazyScale !== undefined && { transformScale: lazyScale }),
327
330
  // hiding preview if dragging shared item
328
331
  style: this.isSharedDragTarget()
329
- ? Object.assign(Object.assign({}, gridItem.props.style), { opacity: 0 }) : gridItem.props.style, className: `${OVERLAY_CLASS_NAME} ${DROPPING_ELEMENT_CLASS_NAME}`, droppingPosition: this.calculateDroppingPosition(gridItem.props) }));
332
+ ? { ...gridItem.props.style, opacity: 0 }
333
+ : gridItem.props.style,
334
+ className: `${OVERLAY_CLASS_NAME} ${DROPPING_ELEMENT_CLASS_NAME}`,
335
+ droppingPosition: this.calculateDroppingPosition(gridItem.props),
336
+ });
330
337
  }
331
338
  const gridChild = gridItem.props.children;
332
339
  const cachedGridItemChild = this.gridItemChildren.get(gridChild);
@@ -334,7 +341,7 @@ class DragOverLayout extends ReactGridLayout {
334
341
  Object.keys(gridItemMetadata).every((key) => cachedGridItemChild.metadata[key] === gridItemMetadata[key])
335
342
  ? cachedGridItemChild.child
336
343
  : React.cloneElement(gridChild, gridItemMetadata);
337
- if (gridItemChild !== (cachedGridItemChild === null || cachedGridItemChild === void 0 ? void 0 : cachedGridItemChild.child)) {
344
+ if (gridItemChild !== cachedGridItemChild?.child) {
338
345
  this.gridItemChildren.set(gridChild, {
339
346
  child: gridItemChild,
340
347
  metadata: gridItemMetadata,
@@ -349,8 +356,7 @@ class DragOverLayout extends ReactGridLayout {
349
356
  return React.cloneElement(gridItem, { children: gridItemChild });
350
357
  }
351
358
  updateTouchTarget(event) {
352
- var _a, _b;
353
- const position = getEventPosition(event, (_a = this.props.dragStateRef) === null || _a === void 0 ? void 0 : _a.current.touchIdentifier);
359
+ const position = getEventPosition(event, this.props.dragStateRef?.current.touchIdentifier);
354
360
  if (!position) {
355
361
  return;
356
362
  }
@@ -359,140 +365,23 @@ class DragOverLayout extends ReactGridLayout {
359
365
  .find((element) => element.classList.contains(GRID_LAYOUT_CLASS_NAME)) || null;
360
366
  // Touch events keep their original target, so route group transitions explicitly.
361
367
  if (target !== this.touchTarget) {
362
- (_b = this.touchTarget) === null || _b === void 0 ? void 0 : _b.dispatchEvent(new MouseEvent('mouseleave', position));
363
- target === null || target === void 0 ? void 0 : target.dispatchEvent(new MouseEvent('mouseenter', position));
368
+ this.touchTarget?.dispatchEvent(new MouseEvent('mouseleave', position));
369
+ target?.dispatchEvent(new MouseEvent('mouseenter', position));
364
370
  this.touchTarget = target;
365
371
  }
366
- target === null || target === void 0 ? void 0 : target.dispatchEvent(new MouseEvent('mousemove', position));
372
+ target?.dispatchEvent(new MouseEvent('mousemove', position));
367
373
  }
368
374
  }
369
375
  class PassiveWidthProvider extends React.Component {
370
- constructor() {
371
- super(...arguments);
372
- this.state = { interactionRevision: 0, isMounted: false, settledWidth: 1280 };
373
- this.element = null;
374
- this.elementRef = React.createRef();
375
- this.widthRef = { current: 1280 };
376
- this.gridItems = [];
377
- this.isComponentMounted = false;
378
- this.cacheGridItems = () => {
379
- const node = this.element;
380
- this.gridItems = node
381
- ? Array.from(node.children).filter((child) => child instanceof HTMLElement &&
382
- child.matches('.react-grid-item[data-dashkit-grid-cols]'))
383
- : [];
384
- this.lastAppliedWidth = undefined;
385
- };
386
- this.updateGridItems = (width) => {
387
- if (width === this.lastAppliedWidth) {
388
- return;
389
- }
390
- this.lastAppliedWidth = width;
391
- this.gridItems.forEach((item) => {
392
- if (item.classList.contains('react-draggable-dragging') ||
393
- item.classList.contains('resizing')) {
394
- return;
395
- }
396
- const { dataset, style } = item;
397
- const cols = Number(dataset.dashkitGridCols);
398
- const x = Number(dataset.dashkitGridX);
399
- const y = Number(dataset.dashkitGridY);
400
- const w = Number(dataset.dashkitGridW);
401
- const h = Number(dataset.dashkitGridH);
402
- const marginX = Number(dataset.dashkitGridMarginX);
403
- const marginY = Number(dataset.dashkitGridMarginY);
404
- const paddingX = Number(dataset.dashkitGridPaddingX);
405
- const paddingY = Number(dataset.dashkitGridPaddingY);
406
- const rowHeight = Number(dataset.dashkitGridRowHeight);
407
- const useCSSTransforms = dataset.dashkitGridUseCssTransforms === 'true';
408
- if ([cols, x, y, w, h, marginX, marginY, paddingX, paddingY, rowHeight].some((value) => !Number.isFinite(value))) {
409
- return;
410
- }
411
- Object.assign(style, getGridItemStyle({
412
- cols,
413
- containerPadding: [paddingX, paddingY],
414
- h,
415
- margin: [marginX, marginY],
416
- rowHeight,
417
- useCSSTransforms,
418
- w,
419
- width,
420
- x,
421
- y,
422
- }));
423
- });
424
- };
425
- this.handlePointerDown = () => {
426
- if (!this.props.isDraggable && !this.props.isResizable) {
427
- return;
428
- }
429
- this.cancelSettledWidthCommit();
430
- flushSync(() => {
431
- this.setState((state) => ({
432
- interactionRevision: state.interactionRevision + 1,
433
- settledWidth: this.widthRef.current,
434
- }));
435
- });
436
- };
437
- this.syncSettledWidth = () => {
438
- this.cancelSettledWidthCommit();
439
- if (this.state.settledWidth === this.widthRef.current) {
440
- return;
441
- }
442
- flushSync(() => {
443
- this.setState({ settledWidth: this.widthRef.current });
444
- });
445
- };
446
- this.cancelSettledWidthCommit = () => {
447
- if (this.settledWidthCommitTimer === undefined) {
448
- return;
449
- }
450
- window.clearTimeout(this.settledWidthCommitTimer);
451
- this.settledWidthCommitTimer = undefined;
452
- };
453
- this.scheduleSettledWidthCommit = () => {
454
- this.cancelSettledWidthCommit();
455
- // DOM grid items update in ResizeObserver; React reconciles only after resizing settles.
456
- this.settledWidthCommitTimer = window.setTimeout(() => {
457
- this.settledWidthCommitTimer = undefined;
458
- if (this.isComponentMounted && this.state.settledWidth !== this.widthRef.current) {
459
- this.setState({ settledWidth: this.widthRef.current });
460
- }
461
- }, SETTLED_WIDTH_COMMIT_DELAY);
462
- };
463
- this.syncElement = () => {
464
- var _a;
465
- const node = this.elementRef.current;
466
- if (node === this.element) {
467
- return;
468
- }
469
- if (this.element) {
470
- (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.unobserve(this.element);
471
- this.element.removeEventListener('pointerdown', this.handlePointerDown, true);
472
- }
473
- this.element = node;
474
- if (node && this.isComponentMounted) {
475
- this.observeElement(node);
476
- }
477
- };
478
- this.observeElement = (node) => {
479
- var _a;
480
- this.widthRef.current = node.clientWidth;
481
- this.cacheGridItems();
482
- this.updateGridItems(this.widthRef.current);
483
- node.addEventListener('pointerdown', this.handlePointerDown, true);
484
- (_a = this.resizeObserver) !== null && _a !== void 0 ? _a : (this.resizeObserver = new (typeof ResizeObserver === 'function' ? ResizeObserver : ResizeObserverPolyfill)((entries) => {
485
- const entry = entries.find((currentEntry) => currentEntry.target === this.element);
486
- if (!entry) {
487
- return;
488
- }
489
- this.widthRef.current = entry.contentRect.width;
490
- this.updateGridItems(this.widthRef.current);
491
- this.scheduleSettledWidthCommit();
492
- }));
493
- this.resizeObserver.observe(node);
494
- };
495
- }
376
+ state = { interactionRevision: 0, isMounted: false, settledWidth: 1280 };
377
+ element = null;
378
+ elementRef = React.createRef();
379
+ widthRef = { current: 1280 };
380
+ gridItems = [];
381
+ lastAppliedWidth;
382
+ resizeObserver;
383
+ settledWidthCommitTimer;
384
+ isComponentMounted = false;
496
385
  componentDidMount() {
497
386
  this.isComponentMounted = true;
498
387
  this.syncElement();
@@ -504,21 +393,135 @@ class PassiveWidthProvider extends React.Component {
504
393
  this.updateGridItems(this.widthRef.current);
505
394
  }
506
395
  componentWillUnmount() {
507
- var _a, _b;
508
396
  this.isComponentMounted = false;
509
- (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
397
+ this.resizeObserver?.disconnect();
510
398
  this.resizeObserver = undefined;
511
399
  this.cancelSettledWidthCommit();
512
- (_b = this.element) === null || _b === void 0 ? void 0 : _b.removeEventListener('pointerdown', this.handlePointerDown, true);
400
+ this.element?.removeEventListener('pointerdown', this.handlePointerDown, true);
513
401
  this.element = null;
514
402
  }
515
403
  render() {
516
- const _a = this.props, { measureBeforeMount } = _a, props = __rest(_a, ["measureBeforeMount"]);
404
+ const { measureBeforeMount, ...props } = this.props;
517
405
  if (measureBeforeMount && !this.state.isMounted) {
518
406
  return (React.createElement("div", { className: [props.className, GRID_LAYOUT_CLASS_NAME].filter(Boolean).join(' '), ref: this.elementRef, style: props.style }));
519
407
  }
520
- return (React.createElement(DragOverLayout, Object.assign({}, props, { innerRef: this.elementRef, onBeforeDragOver: this.syncSettledWidth, width: this.state.settledWidth })));
408
+ return (React.createElement(DragOverLayout, { ...props, innerRef: this.elementRef, onBeforeDragOver: this.syncSettledWidth, width: this.state.settledWidth }));
521
409
  }
410
+ cacheGridItems = () => {
411
+ const node = this.element;
412
+ this.gridItems = node
413
+ ? Array.from(node.children).filter((child) => child instanceof HTMLElement &&
414
+ child.matches('.react-grid-item[data-dashkit-grid-cols]'))
415
+ : [];
416
+ this.lastAppliedWidth = undefined;
417
+ };
418
+ updateGridItems = (width) => {
419
+ if (width === this.lastAppliedWidth) {
420
+ return;
421
+ }
422
+ this.lastAppliedWidth = width;
423
+ this.gridItems.forEach((item) => {
424
+ if (item.classList.contains('react-draggable-dragging') ||
425
+ item.classList.contains('resizing')) {
426
+ return;
427
+ }
428
+ const { dataset, style } = item;
429
+ const cols = Number(dataset.dashkitGridCols);
430
+ const x = Number(dataset.dashkitGridX);
431
+ const y = Number(dataset.dashkitGridY);
432
+ const w = Number(dataset.dashkitGridW);
433
+ const h = Number(dataset.dashkitGridH);
434
+ const marginX = Number(dataset.dashkitGridMarginX);
435
+ const marginY = Number(dataset.dashkitGridMarginY);
436
+ const paddingX = Number(dataset.dashkitGridPaddingX);
437
+ const paddingY = Number(dataset.dashkitGridPaddingY);
438
+ const rowHeight = Number(dataset.dashkitGridRowHeight);
439
+ const useCSSTransforms = dataset.dashkitGridUseCssTransforms === 'true';
440
+ if ([cols, x, y, w, h, marginX, marginY, paddingX, paddingY, rowHeight].some((value) => !Number.isFinite(value))) {
441
+ return;
442
+ }
443
+ Object.assign(style, getGridItemStyle({
444
+ cols,
445
+ containerPadding: [paddingX, paddingY],
446
+ h,
447
+ margin: [marginX, marginY],
448
+ rowHeight,
449
+ useCSSTransforms,
450
+ w,
451
+ width,
452
+ x,
453
+ y,
454
+ }));
455
+ });
456
+ };
457
+ handlePointerDown = () => {
458
+ if (!this.props.isDraggable && !this.props.isResizable) {
459
+ return;
460
+ }
461
+ this.cancelSettledWidthCommit();
462
+ flushSync(() => {
463
+ this.setState((state) => ({
464
+ interactionRevision: state.interactionRevision + 1,
465
+ settledWidth: this.widthRef.current,
466
+ }));
467
+ });
468
+ };
469
+ syncSettledWidth = () => {
470
+ this.cancelSettledWidthCommit();
471
+ if (this.state.settledWidth === this.widthRef.current) {
472
+ return;
473
+ }
474
+ flushSync(() => {
475
+ this.setState({ settledWidth: this.widthRef.current });
476
+ });
477
+ };
478
+ cancelSettledWidthCommit = () => {
479
+ if (this.settledWidthCommitTimer === undefined) {
480
+ return;
481
+ }
482
+ window.clearTimeout(this.settledWidthCommitTimer);
483
+ this.settledWidthCommitTimer = undefined;
484
+ };
485
+ scheduleSettledWidthCommit = () => {
486
+ this.cancelSettledWidthCommit();
487
+ // DOM grid items update in ResizeObserver; React reconciles only after resizing settles.
488
+ this.settledWidthCommitTimer = window.setTimeout(() => {
489
+ this.settledWidthCommitTimer = undefined;
490
+ if (this.isComponentMounted && this.state.settledWidth !== this.widthRef.current) {
491
+ this.setState({ settledWidth: this.widthRef.current });
492
+ }
493
+ }, SETTLED_WIDTH_COMMIT_DELAY);
494
+ };
495
+ syncElement = () => {
496
+ const node = this.elementRef.current;
497
+ if (node === this.element) {
498
+ return;
499
+ }
500
+ if (this.element) {
501
+ this.resizeObserver?.unobserve(this.element);
502
+ this.element.removeEventListener('pointerdown', this.handlePointerDown, true);
503
+ }
504
+ this.element = node;
505
+ if (node && this.isComponentMounted) {
506
+ this.observeElement(node);
507
+ }
508
+ };
509
+ observeElement = (node) => {
510
+ this.widthRef.current = node.clientWidth;
511
+ this.cacheGridItems();
512
+ this.updateGridItems(this.widthRef.current);
513
+ node.addEventListener('pointerdown', this.handlePointerDown, true);
514
+ this.resizeObserver ??= new (typeof ResizeObserver === 'function' ? ResizeObserver : ResizeObserverPolyfill)((entries) => {
515
+ const entry = entries.find((currentEntry) => currentEntry.target === this.element);
516
+ if (!entry) {
517
+ return;
518
+ }
519
+ this.widthRef.current = entry.contentRect.width;
520
+ this.updateGridItems(this.widthRef.current);
521
+ this.scheduleSettledWidthCommit();
522
+ });
523
+ this.resizeObserver.observe(node);
524
+ };
522
525
  }
523
526
  export const Layout = PassiveWidthProvider;
524
527
  //# sourceMappingURL=ReactGridLayout.js.map