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