@gravity-ui/dashkit 8.1.0-beta.6 → 8.1.0-beta.8
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/build/cjs/components/ActionPanel/ActionPanel.js +2 -2
- package/build/cjs/components/DashKit/DashKit.d.ts +2 -7
- package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.d.ts +3 -0
- package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.js +10 -6
- package/build/cjs/components/GridLayout/GridLayout.js +10 -10
- package/build/cjs/hocs/withContext.js +7 -5
- package/build/cjs/shared/types/common.d.ts +7 -0
- package/build/esm/components/ActionPanel/ActionPanel.js +2 -2
- package/build/esm/components/DashKit/DashKit.d.ts +2 -7
- package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.d.ts +3 -0
- package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.js +10 -6
- package/build/esm/components/GridLayout/GridLayout.js +10 -10
- package/build/esm/hocs/withContext.js +7 -5
- package/build/esm/shared/types/common.d.ts +7 -0
- package/package.json +1 -1
|
@@ -9,7 +9,7 @@ const cn_1 = require("../../utils/cn");
|
|
|
9
9
|
const b = (0, cn_1.cn)('dashkit-action-panel');
|
|
10
10
|
const ActionPanelItemContainer = ({ item }) => {
|
|
11
11
|
const dndProps = (0, useDnDItemProps_1.useDnDItemProps)(item);
|
|
12
|
-
return (react_1.default.createElement("div", Object.assign({ role: "button", className: b('item', { draggable: Boolean(dndProps) }, item.className),
|
|
12
|
+
return (react_1.default.createElement("div", Object.assign({ role: "button", className: b('item', { draggable: Boolean(dndProps) }, item.className), onClick: item.onClick, "data-qa": item.qa }, dndProps),
|
|
13
13
|
react_1.default.createElement("div", { className: b('icon') }, item.icon),
|
|
14
14
|
react_1.default.createElement("div", { className: b('title'), title: item.title }, item.title)));
|
|
15
15
|
};
|
|
@@ -19,7 +19,7 @@ const ActionPanel = (props) => {
|
|
|
19
19
|
const isDisabled = (_a = props.disable) !== null && _a !== void 0 ? _a : false;
|
|
20
20
|
const isAnimated = (_b = props.toggleAnimation) !== null && _b !== void 0 ? _b : false;
|
|
21
21
|
const nodeRef = react_1.default.useRef(null);
|
|
22
|
-
const content = (react_1.default.createElement("div", { ref: nodeRef, className: b(null, props.className) }, props.items.map((item
|
|
22
|
+
const content = (react_1.default.createElement("div", { ref: nodeRef, className: b(null, props.className) }, props.items.map((item) => (react_1.default.createElement(exports.ActionPanelItemContainer, { key: `dk-action-panel-${item.id}`, item: item })))));
|
|
23
23
|
if (isAnimated) {
|
|
24
24
|
return (react_1.default.createElement(react_transition_group_1.CSSTransition, { in: !isDisabled, nodeRef: nodeRef, classNames: b(null), timeout: 300, unmountOnExit: true }, content));
|
|
25
25
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { Config, ConfigItem,
|
|
2
|
+
import type { Config, ConfigItem, GlobalParams, ItemDropProps, ItemsStateAndParams } from '../../shared';
|
|
3
3
|
import { ContextProps, Plugin, SetConfigItem, SetNewItemOptions, Settings, SettingsProps } from '../../typings';
|
|
4
4
|
import GridLayout from '../GridLayout/GridLayout';
|
|
5
5
|
import { OverlayControlItem } from '../OverlayControls/OverlayControls';
|
|
@@ -15,12 +15,7 @@ interface DashKitDefaultProps {
|
|
|
15
15
|
config: Config;
|
|
16
16
|
itemsStateAndParams: ItemsStateAndParams;
|
|
17
17
|
}) => void;
|
|
18
|
-
onDrop: (dropProps:
|
|
19
|
-
commit: () => void;
|
|
20
|
-
dragProps: ItemDragProps;
|
|
21
|
-
itemLayout: ConfigLayout;
|
|
22
|
-
newLayout: ConfigLayout[];
|
|
23
|
-
}) => void;
|
|
18
|
+
onDrop: (dropProps: ItemDropProps) => void;
|
|
24
19
|
defaultGlobalParams: GlobalParams;
|
|
25
20
|
globalParams: GlobalParams;
|
|
26
21
|
itemsStateAndParams: ItemsStateAndParams;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { ItemDragProps } from '../../shared';
|
|
2
3
|
type DashKitDnDWrapperProps = {
|
|
3
4
|
dragImageSrc?: string;
|
|
5
|
+
onDragStart?: (dragProps: ItemDragProps) => void;
|
|
6
|
+
onDragEnd?: () => void;
|
|
4
7
|
children: React.ReactElement;
|
|
5
8
|
};
|
|
6
9
|
export declare const DashKitDnDWrapper: React.FC<DashKitDnDWrapperProps>;
|
|
@@ -8,16 +8,20 @@ const defaultImageSrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC
|
|
|
8
8
|
const DashKitDnDWrapper = (props) => {
|
|
9
9
|
const [dragProps, setDragProps] = react_1.default.useState(null);
|
|
10
10
|
const dragImagePreview = react_1.default.useMemo(() => {
|
|
11
|
-
const img = new Image(
|
|
11
|
+
const img = new Image();
|
|
12
12
|
img.src = props.dragImageSrc || defaultImageSrc;
|
|
13
13
|
return img;
|
|
14
|
-
}, [props]);
|
|
15
|
-
const onDragStart = react_1.default.useCallback((_,
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
}, [props.dragImageSrc]);
|
|
15
|
+
const onDragStart = react_1.default.useCallback((_, itemDragProps) => {
|
|
16
|
+
var _a;
|
|
17
|
+
setDragProps(itemDragProps);
|
|
18
|
+
(_a = props.onDragStart) === null || _a === void 0 ? void 0 : _a.call(props, itemDragProps);
|
|
19
|
+
}, [setDragProps, props.onDragStart]);
|
|
18
20
|
const onDragEnd = react_1.default.useCallback((_) => {
|
|
21
|
+
var _a;
|
|
19
22
|
setDragProps(null);
|
|
20
|
-
|
|
23
|
+
(_a = props.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
24
|
+
}, [setDragProps, props.onDragEnd]);
|
|
21
25
|
const contextValue = react_1.default.useMemo(() => {
|
|
22
26
|
return {
|
|
23
27
|
dragProps,
|
|
@@ -46,8 +46,8 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
46
46
|
this.setState({ isDragging: false });
|
|
47
47
|
};
|
|
48
48
|
this._onDropDragOver = (e) => {
|
|
49
|
-
const { editMode, dragOverPlugin, onDropDragOver
|
|
50
|
-
if (!editMode || !dragOverPlugin
|
|
49
|
+
const { editMode, dragOverPlugin, onDropDragOver } = this.context;
|
|
50
|
+
if (!editMode || !dragOverPlugin) {
|
|
51
51
|
return false;
|
|
52
52
|
}
|
|
53
53
|
return onDropDragOver(e);
|
|
@@ -56,8 +56,8 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
56
56
|
if (!item) {
|
|
57
57
|
return false;
|
|
58
58
|
}
|
|
59
|
-
const { editMode,
|
|
60
|
-
if (!editMode
|
|
59
|
+
const { editMode, onDrop } = this.context;
|
|
60
|
+
if (!editMode) {
|
|
61
61
|
return false;
|
|
62
62
|
}
|
|
63
63
|
onDrop === null || onDrop === void 0 ? void 0 : onDrop(layout, item, e);
|
|
@@ -95,18 +95,18 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
renderTemporaryPlaceholder() {
|
|
98
|
-
const { temporaryLayout,
|
|
99
|
-
if (!temporaryLayout || !
|
|
98
|
+
const { temporaryLayout, noOverlay, draggableHandleClassName } = this.context;
|
|
99
|
+
if (!temporaryLayout || !temporaryLayout.dragProps) {
|
|
100
100
|
return null;
|
|
101
101
|
}
|
|
102
102
|
const id = constants_1.TEMPORARY_ITEM_ID;
|
|
103
|
-
const type =
|
|
104
|
-
return (react_1.default.createElement(GridItem_1.default, { key: id, id: id, item: { id, type, data: {} }, layout: temporaryLayout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, isPlaceholder: true, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
|
|
103
|
+
const { type } = temporaryLayout.dragProps;
|
|
104
|
+
return (react_1.default.createElement(GridItem_1.default, { key: id, id: id, item: { id, type, data: {} }, layout: temporaryLayout.data, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, isPlaceholder: true, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
|
|
105
105
|
}
|
|
106
106
|
render() {
|
|
107
107
|
const { layout, temporaryLayout, config, registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, } = this.context;
|
|
108
108
|
this.pluginsRefs.length = config.items.length;
|
|
109
|
-
return (react_1.default.createElement(ReactGridLayout_1.Layout, Object.assign({}, registerManager.gridLayout, { layout: temporaryLayout || layout, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: this._onStop, onResizeStart: this._onStart, onResizeStop: this._onStop }, (draggableHandleClassName
|
|
109
|
+
return (react_1.default.createElement(ReactGridLayout_1.Layout, Object.assign({}, registerManager.gridLayout, { layout: (temporaryLayout === null || temporaryLayout === void 0 ? void 0 : temporaryLayout.data) || layout, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: this._onStop, onResizeStart: this._onStart, onResizeStop: this._onStop }, (draggableHandleClassName
|
|
110
110
|
? { draggableHandle: `.${draggableHandleClassName}` }
|
|
111
111
|
: null), (outerDnDEnable
|
|
112
112
|
? {
|
|
@@ -118,7 +118,7 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
118
118
|
config.items.map((item, i) => {
|
|
119
119
|
return (react_1.default.createElement(GridItem_1.default, { forwardedPluginRef: (pluginRef) => {
|
|
120
120
|
this.pluginsRefs[i] = pluginRef;
|
|
121
|
-
}, key: item.id, id: item.id, item: item, layout: temporaryLayout || layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
|
|
121
|
+
}, key: item.id, id: item.id, item: item, layout: (temporaryLayout === null || temporaryLayout === void 0 ? void 0 : temporaryLayout.data) || layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
|
|
122
122
|
}),
|
|
123
123
|
this.renderTemporaryPlaceholder()));
|
|
124
124
|
}
|
|
@@ -55,7 +55,7 @@ function useMemoStateContext(props) {
|
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
57
|
if (temporaryLayout) {
|
|
58
|
-
setTemporaryLayout(temporaryLayout.filter(({ i }) => i !== id));
|
|
58
|
+
setTemporaryLayout(Object.assign(Object.assign({}, temporaryLayout), { data: temporaryLayout.filter(({ i }) => i !== id) }));
|
|
59
59
|
}
|
|
60
60
|
onChange(utils_1.UpdateManager.removeItem({
|
|
61
61
|
id,
|
|
@@ -171,14 +171,16 @@ function useMemoStateContext(props) {
|
|
|
171
171
|
}
|
|
172
172
|
return false;
|
|
173
173
|
}, [resetTemporaryLayout, temporaryLayout, dragOverPlugin, dragProps]);
|
|
174
|
-
const onDropProp = props.onDrop;
|
|
175
174
|
const onDrop = react_1.default.useCallback((newLayout, item) => {
|
|
176
175
|
if (!dragProps) {
|
|
177
176
|
return;
|
|
178
177
|
}
|
|
179
|
-
setTemporaryLayout(
|
|
178
|
+
setTemporaryLayout({
|
|
179
|
+
data: newLayout,
|
|
180
|
+
dragProps,
|
|
181
|
+
});
|
|
180
182
|
const { i, w, h, x, y } = item;
|
|
181
|
-
|
|
183
|
+
props.onDrop({
|
|
182
184
|
newLayout: newLayout.reduce((memo, l) => {
|
|
183
185
|
if (l.i !== i) {
|
|
184
186
|
memo.push({ i: l.i, w: l.w, h: l.h, x: l.x, y: l.y });
|
|
@@ -189,7 +191,7 @@ function useMemoStateContext(props) {
|
|
|
189
191
|
commit: resetTemporaryLayout,
|
|
190
192
|
dragProps,
|
|
191
193
|
});
|
|
192
|
-
}, [dragProps,
|
|
194
|
+
}, [dragProps, props.onDrop, setTemporaryLayout, resetTemporaryLayout]);
|
|
193
195
|
return react_1.default.useMemo(() => ({
|
|
194
196
|
layout: resultLayout,
|
|
195
197
|
temporaryLayout,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConfigLayout } from './config';
|
|
1
2
|
export type Dictionary<T = unknown> = Record<string, T>;
|
|
2
3
|
export interface StringParams extends Dictionary<string | string[]> {
|
|
3
4
|
}
|
|
@@ -11,3 +12,9 @@ export type ItemDragProps = {
|
|
|
11
12
|
};
|
|
12
13
|
extra?: any;
|
|
13
14
|
};
|
|
15
|
+
export type ItemDropProps = {
|
|
16
|
+
commit: () => void;
|
|
17
|
+
dragProps: ItemDragProps;
|
|
18
|
+
itemLayout: ConfigLayout;
|
|
19
|
+
newLayout: ConfigLayout[];
|
|
20
|
+
};
|
|
@@ -6,7 +6,7 @@ import './ActionPanel.css';
|
|
|
6
6
|
const b = cn('dashkit-action-panel');
|
|
7
7
|
export const ActionPanelItemContainer = ({ item }) => {
|
|
8
8
|
const dndProps = useDnDItemProps(item);
|
|
9
|
-
return (React.createElement("div", Object.assign({ role: "button", className: b('item', { draggable: Boolean(dndProps) }, item.className),
|
|
9
|
+
return (React.createElement("div", Object.assign({ role: "button", className: b('item', { draggable: Boolean(dndProps) }, item.className), onClick: item.onClick, "data-qa": item.qa }, dndProps),
|
|
10
10
|
React.createElement("div", { className: b('icon') }, item.icon),
|
|
11
11
|
React.createElement("div", { className: b('title'), title: item.title }, item.title)));
|
|
12
12
|
};
|
|
@@ -15,7 +15,7 @@ export const ActionPanel = (props) => {
|
|
|
15
15
|
const isDisabled = (_a = props.disable) !== null && _a !== void 0 ? _a : false;
|
|
16
16
|
const isAnimated = (_b = props.toggleAnimation) !== null && _b !== void 0 ? _b : false;
|
|
17
17
|
const nodeRef = React.useRef(null);
|
|
18
|
-
const content = (React.createElement("div", { ref: nodeRef, className: b(null, props.className) }, props.items.map((item
|
|
18
|
+
const content = (React.createElement("div", { ref: nodeRef, className: b(null, props.className) }, props.items.map((item) => (React.createElement(ActionPanelItemContainer, { key: `dk-action-panel-${item.id}`, item: item })))));
|
|
19
19
|
if (isAnimated) {
|
|
20
20
|
return (React.createElement(CSSTransition, { in: !isDisabled, nodeRef: nodeRef, classNames: b(null), timeout: 300, unmountOnExit: true }, content));
|
|
21
21
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { Config, ConfigItem,
|
|
2
|
+
import type { Config, ConfigItem, GlobalParams, ItemDropProps, ItemsStateAndParams } from '../../shared';
|
|
3
3
|
import { ContextProps, Plugin, SetConfigItem, SetNewItemOptions, Settings, SettingsProps } from '../../typings';
|
|
4
4
|
import GridLayout from '../GridLayout/GridLayout';
|
|
5
5
|
import { OverlayControlItem } from '../OverlayControls/OverlayControls';
|
|
@@ -15,12 +15,7 @@ interface DashKitDefaultProps {
|
|
|
15
15
|
config: Config;
|
|
16
16
|
itemsStateAndParams: ItemsStateAndParams;
|
|
17
17
|
}) => void;
|
|
18
|
-
onDrop: (dropProps:
|
|
19
|
-
commit: () => void;
|
|
20
|
-
dragProps: ItemDragProps;
|
|
21
|
-
itemLayout: ConfigLayout;
|
|
22
|
-
newLayout: ConfigLayout[];
|
|
23
|
-
}) => void;
|
|
18
|
+
onDrop: (dropProps: ItemDropProps) => void;
|
|
24
19
|
defaultGlobalParams: GlobalParams;
|
|
25
20
|
globalParams: GlobalParams;
|
|
26
21
|
itemsStateAndParams: ItemsStateAndParams;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { ItemDragProps } from '../../shared';
|
|
2
3
|
type DashKitDnDWrapperProps = {
|
|
3
4
|
dragImageSrc?: string;
|
|
5
|
+
onDragStart?: (dragProps: ItemDragProps) => void;
|
|
6
|
+
onDragEnd?: () => void;
|
|
4
7
|
children: React.ReactElement;
|
|
5
8
|
};
|
|
6
9
|
export declare const DashKitDnDWrapper: React.FC<DashKitDnDWrapperProps>;
|
|
@@ -4,16 +4,20 @@ const defaultImageSrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC
|
|
|
4
4
|
export const DashKitDnDWrapper = (props) => {
|
|
5
5
|
const [dragProps, setDragProps] = React.useState(null);
|
|
6
6
|
const dragImagePreview = React.useMemo(() => {
|
|
7
|
-
const img = new Image(
|
|
7
|
+
const img = new Image();
|
|
8
8
|
img.src = props.dragImageSrc || defaultImageSrc;
|
|
9
9
|
return img;
|
|
10
|
-
}, [props]);
|
|
11
|
-
const onDragStart = React.useCallback((_,
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
}, [props.dragImageSrc]);
|
|
11
|
+
const onDragStart = React.useCallback((_, itemDragProps) => {
|
|
12
|
+
var _a;
|
|
13
|
+
setDragProps(itemDragProps);
|
|
14
|
+
(_a = props.onDragStart) === null || _a === void 0 ? void 0 : _a.call(props, itemDragProps);
|
|
15
|
+
}, [setDragProps, props.onDragStart]);
|
|
14
16
|
const onDragEnd = React.useCallback((_) => {
|
|
17
|
+
var _a;
|
|
15
18
|
setDragProps(null);
|
|
16
|
-
|
|
19
|
+
(_a = props.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
20
|
+
}, [setDragProps, props.onDragEnd]);
|
|
17
21
|
const contextValue = React.useMemo(() => {
|
|
18
22
|
return {
|
|
19
23
|
dragProps,
|
|
@@ -43,8 +43,8 @@ class GridLayout extends React.PureComponent {
|
|
|
43
43
|
this.setState({ isDragging: false });
|
|
44
44
|
};
|
|
45
45
|
this._onDropDragOver = (e) => {
|
|
46
|
-
const { editMode, dragOverPlugin, onDropDragOver
|
|
47
|
-
if (!editMode || !dragOverPlugin
|
|
46
|
+
const { editMode, dragOverPlugin, onDropDragOver } = this.context;
|
|
47
|
+
if (!editMode || !dragOverPlugin) {
|
|
48
48
|
return false;
|
|
49
49
|
}
|
|
50
50
|
return onDropDragOver(e);
|
|
@@ -53,8 +53,8 @@ class GridLayout extends React.PureComponent {
|
|
|
53
53
|
if (!item) {
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
|
-
const { editMode,
|
|
57
|
-
if (!editMode
|
|
56
|
+
const { editMode, onDrop } = this.context;
|
|
57
|
+
if (!editMode) {
|
|
58
58
|
return false;
|
|
59
59
|
}
|
|
60
60
|
onDrop === null || onDrop === void 0 ? void 0 : onDrop(layout, item, e);
|
|
@@ -92,18 +92,18 @@ class GridLayout extends React.PureComponent {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
renderTemporaryPlaceholder() {
|
|
95
|
-
const { temporaryLayout,
|
|
96
|
-
if (!temporaryLayout || !
|
|
95
|
+
const { temporaryLayout, noOverlay, draggableHandleClassName } = this.context;
|
|
96
|
+
if (!temporaryLayout || !temporaryLayout.dragProps) {
|
|
97
97
|
return null;
|
|
98
98
|
}
|
|
99
99
|
const id = TEMPORARY_ITEM_ID;
|
|
100
|
-
const type =
|
|
101
|
-
return (React.createElement(GridItem, { key: id, id: id, item: { id, type, data: {} }, layout: temporaryLayout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, isPlaceholder: true, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
|
|
100
|
+
const { type } = temporaryLayout.dragProps;
|
|
101
|
+
return (React.createElement(GridItem, { key: id, id: id, item: { id, type, data: {} }, layout: temporaryLayout.data, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, isPlaceholder: true, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
|
|
102
102
|
}
|
|
103
103
|
render() {
|
|
104
104
|
const { layout, temporaryLayout, config, registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, } = this.context;
|
|
105
105
|
this.pluginsRefs.length = config.items.length;
|
|
106
|
-
return (React.createElement(Layout, Object.assign({}, registerManager.gridLayout, { layout: temporaryLayout || layout, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: this._onStop, onResizeStart: this._onStart, onResizeStop: this._onStop }, (draggableHandleClassName
|
|
106
|
+
return (React.createElement(Layout, Object.assign({}, registerManager.gridLayout, { layout: (temporaryLayout === null || temporaryLayout === void 0 ? void 0 : temporaryLayout.data) || layout, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: this._onStop, onResizeStart: this._onStart, onResizeStop: this._onStop }, (draggableHandleClassName
|
|
107
107
|
? { draggableHandle: `.${draggableHandleClassName}` }
|
|
108
108
|
: null), (outerDnDEnable
|
|
109
109
|
? {
|
|
@@ -115,7 +115,7 @@ class GridLayout extends React.PureComponent {
|
|
|
115
115
|
config.items.map((item, i) => {
|
|
116
116
|
return (React.createElement(GridItem, { forwardedPluginRef: (pluginRef) => {
|
|
117
117
|
this.pluginsRefs[i] = pluginRef;
|
|
118
|
-
}, key: item.id, id: item.id, item: item, layout: temporaryLayout || layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
|
|
118
|
+
}, key: item.id, id: item.id, item: item, layout: (temporaryLayout === null || temporaryLayout === void 0 ? void 0 : temporaryLayout.data) || layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
|
|
119
119
|
}),
|
|
120
120
|
this.renderTemporaryPlaceholder()));
|
|
121
121
|
}
|
|
@@ -51,7 +51,7 @@ function useMemoStateContext(props) {
|
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
53
|
if (temporaryLayout) {
|
|
54
|
-
setTemporaryLayout(temporaryLayout.filter(({ i }) => i !== id));
|
|
54
|
+
setTemporaryLayout(Object.assign(Object.assign({}, temporaryLayout), { data: temporaryLayout.filter(({ i }) => i !== id) }));
|
|
55
55
|
}
|
|
56
56
|
onChange(UpdateManager.removeItem({
|
|
57
57
|
id,
|
|
@@ -167,14 +167,16 @@ function useMemoStateContext(props) {
|
|
|
167
167
|
}
|
|
168
168
|
return false;
|
|
169
169
|
}, [resetTemporaryLayout, temporaryLayout, dragOverPlugin, dragProps]);
|
|
170
|
-
const onDropProp = props.onDrop;
|
|
171
170
|
const onDrop = React.useCallback((newLayout, item) => {
|
|
172
171
|
if (!dragProps) {
|
|
173
172
|
return;
|
|
174
173
|
}
|
|
175
|
-
setTemporaryLayout(
|
|
174
|
+
setTemporaryLayout({
|
|
175
|
+
data: newLayout,
|
|
176
|
+
dragProps,
|
|
177
|
+
});
|
|
176
178
|
const { i, w, h, x, y } = item;
|
|
177
|
-
|
|
179
|
+
props.onDrop({
|
|
178
180
|
newLayout: newLayout.reduce((memo, l) => {
|
|
179
181
|
if (l.i !== i) {
|
|
180
182
|
memo.push({ i: l.i, w: l.w, h: l.h, x: l.x, y: l.y });
|
|
@@ -185,7 +187,7 @@ function useMemoStateContext(props) {
|
|
|
185
187
|
commit: resetTemporaryLayout,
|
|
186
188
|
dragProps,
|
|
187
189
|
});
|
|
188
|
-
}, [dragProps,
|
|
190
|
+
}, [dragProps, props.onDrop, setTemporaryLayout, resetTemporaryLayout]);
|
|
189
191
|
return React.useMemo(() => ({
|
|
190
192
|
layout: resultLayout,
|
|
191
193
|
temporaryLayout,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConfigLayout } from './config';
|
|
1
2
|
export type Dictionary<T = unknown> = Record<string, T>;
|
|
2
3
|
export interface StringParams extends Dictionary<string | string[]> {
|
|
3
4
|
}
|
|
@@ -11,3 +12,9 @@ export type ItemDragProps = {
|
|
|
11
12
|
};
|
|
12
13
|
extra?: any;
|
|
13
14
|
};
|
|
15
|
+
export type ItemDropProps = {
|
|
16
|
+
commit: () => void;
|
|
17
|
+
dragProps: ItemDragProps;
|
|
18
|
+
itemLayout: ConfigLayout;
|
|
19
|
+
newLayout: ConfigLayout[];
|
|
20
|
+
};
|