@gravity-ui/dashkit 8.1.0-beta.1 → 8.1.0-beta.3
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.d.ts +2 -11
- package/build/cjs/components/ActionPanel/ActionPanel.js +4 -4
- package/build/cjs/components/ActionPanel/types.d.ts +2 -1
- package/build/cjs/components/DashKit/DashKit.d.ts +2 -2
- package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.js +8 -8
- package/build/cjs/components/GridItem/GridItem.js +2 -2
- package/build/cjs/components/GridLayout/GridLayout.js +8 -9
- package/build/cjs/hocs/withContext.js +18 -19
- package/build/cjs/shared/types/config.d.ts +5 -0
- package/build/esm/components/ActionPanel/ActionPanel.d.ts +2 -11
- package/build/esm/components/ActionPanel/ActionPanel.js +4 -4
- package/build/esm/components/ActionPanel/types.d.ts +2 -1
- package/build/esm/components/DashKit/DashKit.d.ts +2 -2
- package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.js +8 -8
- package/build/esm/components/GridItem/GridItem.js +2 -2
- package/build/esm/components/GridLayout/GridLayout.js +8 -9
- package/build/esm/hocs/withContext.js +18 -19
- package/build/esm/shared/types/config.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { ActionPanelProps } from './types';
|
|
3
|
-
export type ActionPanelItem = {
|
|
4
|
-
id: string;
|
|
5
|
-
icon: React.ReactNode;
|
|
6
|
-
title: string;
|
|
7
|
-
onClick?: () => void;
|
|
8
|
-
className?: string;
|
|
9
|
-
qa?: string;
|
|
10
|
-
pluginType?: string;
|
|
11
|
-
};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ActionPanelItem, ActionPanelProps } from './types';
|
|
12
3
|
export declare const ActionPanelItemContainer: ({ item }: {
|
|
13
4
|
item: ActionPanelItem;
|
|
14
5
|
}) => JSX.Element;
|
|
@@ -10,13 +10,13 @@ const b = (0, cn_1.cn)('dashkit-action-panel');
|
|
|
10
10
|
const ActionPanelItemContainer = ({ item }) => {
|
|
11
11
|
const dragContext = react_1.default.useContext(DashKitContext_1.DashKitDnDContext);
|
|
12
12
|
const onDragStart = react_1.default.useCallback((e) => {
|
|
13
|
-
dragContext.onDragStart(e, item.
|
|
14
|
-
}, [dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragStart, item.
|
|
13
|
+
dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragStart(e, item.dragProps);
|
|
14
|
+
}, [dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragStart, item.dragProps]);
|
|
15
15
|
const onDragEnd = react_1.default.useCallback((e) => {
|
|
16
|
-
dragContext.onDragEnd(e);
|
|
16
|
+
dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragEnd(e);
|
|
17
17
|
}, [dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragEnd]);
|
|
18
18
|
let dndProps = {};
|
|
19
|
-
if (item.
|
|
19
|
+
if (item.dragProps) {
|
|
20
20
|
dndProps = {
|
|
21
21
|
draggable: true,
|
|
22
22
|
unselectable: 'on',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { DragProps } from '../../shared';
|
|
2
3
|
export type ActionPanelItem = {
|
|
3
4
|
id: string;
|
|
4
5
|
icon: React.ReactNode;
|
|
@@ -6,7 +7,7 @@ export type ActionPanelItem = {
|
|
|
6
7
|
onClick?: () => void;
|
|
7
8
|
className?: string;
|
|
8
9
|
qa?: string;
|
|
9
|
-
|
|
10
|
+
dragProps?: DragProps;
|
|
10
11
|
};
|
|
11
12
|
export type ActionPanelProps = {
|
|
12
13
|
items: ActionPanelItem[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { Config, ConfigItem, ConfigLayout, GlobalParams, ItemsStateAndParams } from '../../shared';
|
|
2
|
+
import type { Config, ConfigItem, ConfigLayout, DragProps, GlobalParams, 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';
|
|
@@ -17,7 +17,7 @@ interface DashKitDefaultProps {
|
|
|
17
17
|
}) => void;
|
|
18
18
|
onDrop: (dropProps: {
|
|
19
19
|
commit: () => void;
|
|
20
|
-
|
|
20
|
+
dragProps: DragProps;
|
|
21
21
|
itemLayout: ConfigLayout;
|
|
22
22
|
newLayout: ConfigLayout[];
|
|
23
23
|
}) => void;
|
|
@@ -5,20 +5,20 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const DashKitContext_1 = require("../../context/DashKitContext");
|
|
7
7
|
const DashKitDnDWrapper = (props) => {
|
|
8
|
-
const [
|
|
9
|
-
const onDragStart = react_1.default.useCallback((_,
|
|
10
|
-
|
|
11
|
-
}, [
|
|
8
|
+
const [dragProps, setDragProps] = react_1.default.useState(null);
|
|
9
|
+
const onDragStart = react_1.default.useCallback((_, currentProps) => {
|
|
10
|
+
setDragProps(currentProps);
|
|
11
|
+
}, [setDragProps]);
|
|
12
12
|
const onDragEnd = react_1.default.useCallback((_) => {
|
|
13
|
-
|
|
14
|
-
}, [
|
|
13
|
+
setDragProps(null);
|
|
14
|
+
}, [setDragProps]);
|
|
15
15
|
const contextValue = react_1.default.useMemo(() => {
|
|
16
16
|
return {
|
|
17
|
-
|
|
17
|
+
dragProps,
|
|
18
18
|
onDragStart,
|
|
19
19
|
onDragEnd,
|
|
20
20
|
};
|
|
21
|
-
}, [
|
|
21
|
+
}, [dragProps, onDragStart, onDragEnd]);
|
|
22
22
|
return (react_1.default.createElement(DashKitContext_1.DashKitDnDContext.Provider, { value: contextValue }, props.children));
|
|
23
23
|
};
|
|
24
24
|
exports.DashKitDnDWrapper = DashKitDnDWrapper;
|
|
@@ -58,9 +58,9 @@ class GridItem extends react_1.default.PureComponent {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
renderOverlay() {
|
|
61
|
-
const { overlayControls } = this.props;
|
|
61
|
+
const { overlayControls, isPlaceholder } = this.props;
|
|
62
62
|
const { editMode } = this.context;
|
|
63
|
-
if (!editMode || this.props.item.data._editActive) {
|
|
63
|
+
if (!editMode || this.props.item.data._editActive || isPlaceholder) {
|
|
64
64
|
return null;
|
|
65
65
|
}
|
|
66
66
|
const { item } = this.props;
|
|
@@ -24,12 +24,12 @@ class DragOverLayout extends react_grid_layout_1.default {
|
|
|
24
24
|
window.removeEventListener('dragend', this.dragReset);
|
|
25
25
|
}
|
|
26
26
|
processGridItem(child, isDroppingItem) {
|
|
27
|
+
const gridItem = super.processGridItem(child, isDroppingItem);
|
|
27
28
|
if (isDroppingItem) {
|
|
28
29
|
// Drop item from outside gets 0,0 droppingPosition
|
|
29
30
|
// centering cursor on newly creted grid item
|
|
30
31
|
// And cause grid-layout using it's own GridItem to make it look
|
|
31
32
|
// like overlay adding className
|
|
32
|
-
const gridItem = super.processGridItem(child, isDroppingItem);
|
|
33
33
|
if (!gridItem)
|
|
34
34
|
return null;
|
|
35
35
|
const { props } = gridItem;
|
|
@@ -41,7 +41,7 @@ class DragOverLayout extends react_grid_layout_1.default {
|
|
|
41
41
|
droppingPosition: Object.assign(Object.assign({}, props.droppingPosition), { left: props.droppingPosition.left - leftOffset, top: props.droppingPosition.top - topOffset }),
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
return
|
|
44
|
+
return gridItem;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
const Layout = (0, react_grid_layout_1.WidthProvider)(DragOverLayout); // eslint-disable-line new-cap
|
|
@@ -85,17 +85,16 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
85
85
|
this.setState({ isDragging: false });
|
|
86
86
|
};
|
|
87
87
|
this._onDropDragOver = (e) => {
|
|
88
|
-
const { editMode, onDropDragOver, temporaryLayout } = this.context;
|
|
89
|
-
if (!editMode) {
|
|
88
|
+
const { editMode, dragOverPlugin, onDropDragOver, temporaryLayout } = this.context;
|
|
89
|
+
if (!editMode || !dragOverPlugin || temporaryLayout) {
|
|
90
90
|
return false;
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
if (temporaryLayout) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
92
|
+
return onDropDragOver(e);
|
|
97
93
|
};
|
|
98
94
|
this._onDrop = (layout, item, e) => {
|
|
95
|
+
if (!item) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
99
98
|
const { editMode, temporaryLayout, onDrop } = this.context;
|
|
100
99
|
if (!editMode && temporaryLayout) {
|
|
101
100
|
return false;
|
|
@@ -8,6 +8,8 @@ const common_1 = require("../constants/common");
|
|
|
8
8
|
const DashKitContext_1 = require("../context/DashKitContext");
|
|
9
9
|
const shared_1 = require("../shared");
|
|
10
10
|
const utils_1 = require("../utils");
|
|
11
|
+
const DEFAULT_HEIGHT = 3;
|
|
12
|
+
const DEFAULT_WIDTH = 3;
|
|
11
13
|
function useMemoStateContext(props) {
|
|
12
14
|
// так как мы не хотим хранить параметры виджета с активированной автовысотой в сторе и на сервере, актуальный
|
|
13
15
|
// (видимый юзером в конкретный момент времени) лэйаут (массив объектов с данными о ширине, высоте,
|
|
@@ -144,20 +146,12 @@ function useMemoStateContext(props) {
|
|
|
144
146
|
const reloadItems = react_1.default.useCallback((pluginsRefs, data) => {
|
|
145
147
|
pluginsRefs.forEach((ref) => ref && ref.reload && ref.reload(data));
|
|
146
148
|
}, []);
|
|
147
|
-
const
|
|
148
|
-
react_1.default.useEffect(() => {
|
|
149
|
-
if (!(dndContext === null || dndContext === void 0 ? void 0 : dndContext.dragPluginType) && !temporaryLayout) {
|
|
150
|
-
draggedPluginRef.current = null;
|
|
151
|
-
}
|
|
152
|
-
else if (dndContext === null || dndContext === void 0 ? void 0 : dndContext.dragPluginType) {
|
|
153
|
-
draggedPluginRef.current = dndContext.dragPluginType;
|
|
154
|
-
}
|
|
155
|
-
}, [draggedPluginRef, dndContext === null || dndContext === void 0 ? void 0 : dndContext.dragPluginType, temporaryLayout]);
|
|
156
|
-
const dndPluginType = draggedPluginRef.current || (dndContext === null || dndContext === void 0 ? void 0 : dndContext.dragPluginType);
|
|
149
|
+
const dragProps = dndContext === null || dndContext === void 0 ? void 0 : dndContext.dragProps;
|
|
157
150
|
const dragOverPlugin = react_1.default.useMemo(() => {
|
|
158
|
-
|
|
159
|
-
if (pluginType === null && temporaryLayout === null)
|
|
151
|
+
if (dragProps === null) {
|
|
160
152
|
return null;
|
|
153
|
+
}
|
|
154
|
+
const pluginType = dragProps.type;
|
|
161
155
|
if (props.registerManager.check(pluginType)) {
|
|
162
156
|
return props.registerManager.getItem(pluginType);
|
|
163
157
|
}
|
|
@@ -166,22 +160,27 @@ function useMemoStateContext(props) {
|
|
|
166
160
|
console.error(`Uknown pluginType: ${pluginType}`);
|
|
167
161
|
return null;
|
|
168
162
|
}
|
|
169
|
-
}, [
|
|
163
|
+
}, [dragProps, props.registerManager]);
|
|
170
164
|
const onDropDragOver = react_1.default.useCallback(() => {
|
|
171
165
|
if (temporaryLayout) {
|
|
172
166
|
resetTemporaryLayout();
|
|
173
167
|
return false;
|
|
174
168
|
}
|
|
175
|
-
if (dragOverPlugin
|
|
176
|
-
const {
|
|
169
|
+
if (dragOverPlugin) {
|
|
170
|
+
const { defaultLayout } = dragOverPlugin;
|
|
171
|
+
const { h = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.h) || DEFAULT_HEIGHT, w = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.w) || DEFAULT_WIDTH } = dragProps;
|
|
177
172
|
return { h, w };
|
|
178
173
|
}
|
|
179
174
|
return false;
|
|
180
|
-
}, [resetTemporaryLayout, temporaryLayout, dragOverPlugin]);
|
|
175
|
+
}, [resetTemporaryLayout, temporaryLayout, dragOverPlugin, dragProps]);
|
|
176
|
+
const onDropProp = props.onDrop;
|
|
181
177
|
const onDrop = react_1.default.useCallback((newLayout, item) => {
|
|
178
|
+
if (!dragProps) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
182
181
|
setTemporaryLayout(newLayout);
|
|
183
182
|
const { i, w, h, x, y } = item;
|
|
184
|
-
|
|
183
|
+
onDropProp({
|
|
185
184
|
newLayout: newLayout.reduce((memo, l) => {
|
|
186
185
|
if (l.i !== i) {
|
|
187
186
|
memo.push({ i: l.i, w: l.w, h: l.h, x: l.x, y: l.y });
|
|
@@ -189,10 +188,10 @@ function useMemoStateContext(props) {
|
|
|
189
188
|
return memo;
|
|
190
189
|
}, []),
|
|
191
190
|
itemLayout: { w, h, x, y },
|
|
192
|
-
pluginType: dndPluginType,
|
|
193
191
|
commit: resetTemporaryLayout,
|
|
192
|
+
dragProps,
|
|
194
193
|
});
|
|
195
|
-
}, [
|
|
194
|
+
}, [dragProps, onDropProp, resetTemporaryLayout]);
|
|
196
195
|
return react_1.default.useMemo(() => ({
|
|
197
196
|
layout: resultLayout,
|
|
198
197
|
temporaryLayout,
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { ActionPanelProps } from './types';
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ActionPanelItem, ActionPanelProps } from './types';
|
|
3
3
|
import './ActionPanel.css';
|
|
4
|
-
export type ActionPanelItem = {
|
|
5
|
-
id: string;
|
|
6
|
-
icon: React.ReactNode;
|
|
7
|
-
title: string;
|
|
8
|
-
onClick?: () => void;
|
|
9
|
-
className?: string;
|
|
10
|
-
qa?: string;
|
|
11
|
-
pluginType?: string;
|
|
12
|
-
};
|
|
13
4
|
export declare const ActionPanelItemContainer: ({ item }: {
|
|
14
5
|
item: ActionPanelItem;
|
|
15
6
|
}) => JSX.Element;
|
|
@@ -7,13 +7,13 @@ const b = cn('dashkit-action-panel');
|
|
|
7
7
|
export const ActionPanelItemContainer = ({ item }) => {
|
|
8
8
|
const dragContext = React.useContext(DashKitDnDContext);
|
|
9
9
|
const onDragStart = React.useCallback((e) => {
|
|
10
|
-
dragContext.onDragStart(e, item.
|
|
11
|
-
}, [dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragStart, item.
|
|
10
|
+
dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragStart(e, item.dragProps);
|
|
11
|
+
}, [dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragStart, item.dragProps]);
|
|
12
12
|
const onDragEnd = React.useCallback((e) => {
|
|
13
|
-
dragContext.onDragEnd(e);
|
|
13
|
+
dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragEnd(e);
|
|
14
14
|
}, [dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragEnd]);
|
|
15
15
|
let dndProps = {};
|
|
16
|
-
if (item.
|
|
16
|
+
if (item.dragProps) {
|
|
17
17
|
dndProps = {
|
|
18
18
|
draggable: true,
|
|
19
19
|
unselectable: 'on',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { DragProps } from '../../shared';
|
|
2
3
|
export type ActionPanelItem = {
|
|
3
4
|
id: string;
|
|
4
5
|
icon: React.ReactNode;
|
|
@@ -6,7 +7,7 @@ export type ActionPanelItem = {
|
|
|
6
7
|
onClick?: () => void;
|
|
7
8
|
className?: string;
|
|
8
9
|
qa?: string;
|
|
9
|
-
|
|
10
|
+
dragProps?: DragProps;
|
|
10
11
|
};
|
|
11
12
|
export type ActionPanelProps = {
|
|
12
13
|
items: ActionPanelItem[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { Config, ConfigItem, ConfigLayout, GlobalParams, ItemsStateAndParams } from '../../shared';
|
|
2
|
+
import type { Config, ConfigItem, ConfigLayout, DragProps, GlobalParams, 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';
|
|
@@ -17,7 +17,7 @@ interface DashKitDefaultProps {
|
|
|
17
17
|
}) => void;
|
|
18
18
|
onDrop: (dropProps: {
|
|
19
19
|
commit: () => void;
|
|
20
|
-
|
|
20
|
+
dragProps: DragProps;
|
|
21
21
|
itemLayout: ConfigLayout;
|
|
22
22
|
newLayout: ConfigLayout[];
|
|
23
23
|
}) => void;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DashKitDnDContext } from '../../context/DashKitContext';
|
|
3
3
|
export const DashKitDnDWrapper = (props) => {
|
|
4
|
-
const [
|
|
5
|
-
const onDragStart = React.useCallback((_,
|
|
6
|
-
|
|
7
|
-
}, [
|
|
4
|
+
const [dragProps, setDragProps] = React.useState(null);
|
|
5
|
+
const onDragStart = React.useCallback((_, currentProps) => {
|
|
6
|
+
setDragProps(currentProps);
|
|
7
|
+
}, [setDragProps]);
|
|
8
8
|
const onDragEnd = React.useCallback((_) => {
|
|
9
|
-
|
|
10
|
-
}, [
|
|
9
|
+
setDragProps(null);
|
|
10
|
+
}, [setDragProps]);
|
|
11
11
|
const contextValue = React.useMemo(() => {
|
|
12
12
|
return {
|
|
13
|
-
|
|
13
|
+
dragProps,
|
|
14
14
|
onDragStart,
|
|
15
15
|
onDragEnd,
|
|
16
16
|
};
|
|
17
|
-
}, [
|
|
17
|
+
}, [dragProps, onDragStart, onDragEnd]);
|
|
18
18
|
return (React.createElement(DashKitDnDContext.Provider, { value: contextValue }, props.children));
|
|
19
19
|
};
|
|
@@ -56,9 +56,9 @@ class GridItem extends React.PureComponent {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
renderOverlay() {
|
|
59
|
-
const { overlayControls } = this.props;
|
|
59
|
+
const { overlayControls, isPlaceholder } = this.props;
|
|
60
60
|
const { editMode } = this.context;
|
|
61
|
-
if (!editMode || this.props.item.data._editActive) {
|
|
61
|
+
if (!editMode || this.props.item.data._editActive || isPlaceholder) {
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
64
64
|
const { item } = this.props;
|
|
@@ -21,12 +21,12 @@ class DragOverLayout extends ReactGridLayout {
|
|
|
21
21
|
window.removeEventListener('dragend', this.dragReset);
|
|
22
22
|
}
|
|
23
23
|
processGridItem(child, isDroppingItem) {
|
|
24
|
+
const gridItem = super.processGridItem(child, isDroppingItem);
|
|
24
25
|
if (isDroppingItem) {
|
|
25
26
|
// Drop item from outside gets 0,0 droppingPosition
|
|
26
27
|
// centering cursor on newly creted grid item
|
|
27
28
|
// And cause grid-layout using it's own GridItem to make it look
|
|
28
29
|
// like overlay adding className
|
|
29
|
-
const gridItem = super.processGridItem(child, isDroppingItem);
|
|
30
30
|
if (!gridItem)
|
|
31
31
|
return null;
|
|
32
32
|
const { props } = gridItem;
|
|
@@ -38,7 +38,7 @@ class DragOverLayout extends ReactGridLayout {
|
|
|
38
38
|
droppingPosition: Object.assign(Object.assign({}, props.droppingPosition), { left: props.droppingPosition.left - leftOffset, top: props.droppingPosition.top - topOffset }),
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
-
return
|
|
41
|
+
return gridItem;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
const Layout = WidthProvider(DragOverLayout); // eslint-disable-line new-cap
|
|
@@ -82,17 +82,16 @@ class GridLayout extends React.PureComponent {
|
|
|
82
82
|
this.setState({ isDragging: false });
|
|
83
83
|
};
|
|
84
84
|
this._onDropDragOver = (e) => {
|
|
85
|
-
const { editMode, onDropDragOver, temporaryLayout } = this.context;
|
|
86
|
-
if (!editMode) {
|
|
85
|
+
const { editMode, dragOverPlugin, onDropDragOver, temporaryLayout } = this.context;
|
|
86
|
+
if (!editMode || !dragOverPlugin || temporaryLayout) {
|
|
87
87
|
return false;
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
if (temporaryLayout) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
89
|
+
return onDropDragOver(e);
|
|
94
90
|
};
|
|
95
91
|
this._onDrop = (layout, item, e) => {
|
|
92
|
+
if (!item) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
96
95
|
const { editMode, temporaryLayout, onDrop } = this.context;
|
|
97
96
|
if (!editMode && temporaryLayout) {
|
|
98
97
|
return false;
|
|
@@ -4,6 +4,8 @@ import { TEMPORARY_ITEM_ID } from '../constants/common';
|
|
|
4
4
|
import { DashKitContext, DashKitDnDContext } from '../context/DashKitContext';
|
|
5
5
|
import { getItemsParams, getItemsState } from '../shared';
|
|
6
6
|
import { UpdateManager } from '../utils';
|
|
7
|
+
const DEFAULT_HEIGHT = 3;
|
|
8
|
+
const DEFAULT_WIDTH = 3;
|
|
7
9
|
function useMemoStateContext(props) {
|
|
8
10
|
// так как мы не хотим хранить параметры виджета с активированной автовысотой в сторе и на сервере, актуальный
|
|
9
11
|
// (видимый юзером в конкретный момент времени) лэйаут (массив объектов с данными о ширине, высоте,
|
|
@@ -140,20 +142,12 @@ function useMemoStateContext(props) {
|
|
|
140
142
|
const reloadItems = React.useCallback((pluginsRefs, data) => {
|
|
141
143
|
pluginsRefs.forEach((ref) => ref && ref.reload && ref.reload(data));
|
|
142
144
|
}, []);
|
|
143
|
-
const
|
|
144
|
-
React.useEffect(() => {
|
|
145
|
-
if (!(dndContext === null || dndContext === void 0 ? void 0 : dndContext.dragPluginType) && !temporaryLayout) {
|
|
146
|
-
draggedPluginRef.current = null;
|
|
147
|
-
}
|
|
148
|
-
else if (dndContext === null || dndContext === void 0 ? void 0 : dndContext.dragPluginType) {
|
|
149
|
-
draggedPluginRef.current = dndContext.dragPluginType;
|
|
150
|
-
}
|
|
151
|
-
}, [draggedPluginRef, dndContext === null || dndContext === void 0 ? void 0 : dndContext.dragPluginType, temporaryLayout]);
|
|
152
|
-
const dndPluginType = draggedPluginRef.current || (dndContext === null || dndContext === void 0 ? void 0 : dndContext.dragPluginType);
|
|
145
|
+
const dragProps = dndContext === null || dndContext === void 0 ? void 0 : dndContext.dragProps;
|
|
153
146
|
const dragOverPlugin = React.useMemo(() => {
|
|
154
|
-
|
|
155
|
-
if (pluginType === null && temporaryLayout === null)
|
|
147
|
+
if (dragProps === null) {
|
|
156
148
|
return null;
|
|
149
|
+
}
|
|
150
|
+
const pluginType = dragProps.type;
|
|
157
151
|
if (props.registerManager.check(pluginType)) {
|
|
158
152
|
return props.registerManager.getItem(pluginType);
|
|
159
153
|
}
|
|
@@ -162,22 +156,27 @@ function useMemoStateContext(props) {
|
|
|
162
156
|
console.error(`Uknown pluginType: ${pluginType}`);
|
|
163
157
|
return null;
|
|
164
158
|
}
|
|
165
|
-
}, [
|
|
159
|
+
}, [dragProps, props.registerManager]);
|
|
166
160
|
const onDropDragOver = React.useCallback(() => {
|
|
167
161
|
if (temporaryLayout) {
|
|
168
162
|
resetTemporaryLayout();
|
|
169
163
|
return false;
|
|
170
164
|
}
|
|
171
|
-
if (dragOverPlugin
|
|
172
|
-
const {
|
|
165
|
+
if (dragOverPlugin) {
|
|
166
|
+
const { defaultLayout } = dragOverPlugin;
|
|
167
|
+
const { h = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.h) || DEFAULT_HEIGHT, w = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.w) || DEFAULT_WIDTH } = dragProps;
|
|
173
168
|
return { h, w };
|
|
174
169
|
}
|
|
175
170
|
return false;
|
|
176
|
-
}, [resetTemporaryLayout, temporaryLayout, dragOverPlugin]);
|
|
171
|
+
}, [resetTemporaryLayout, temporaryLayout, dragOverPlugin, dragProps]);
|
|
172
|
+
const onDropProp = props.onDrop;
|
|
177
173
|
const onDrop = React.useCallback((newLayout, item) => {
|
|
174
|
+
if (!dragProps) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
178
177
|
setTemporaryLayout(newLayout);
|
|
179
178
|
const { i, w, h, x, y } = item;
|
|
180
|
-
|
|
179
|
+
onDropProp({
|
|
181
180
|
newLayout: newLayout.reduce((memo, l) => {
|
|
182
181
|
if (l.i !== i) {
|
|
183
182
|
memo.push({ i: l.i, w: l.w, h: l.h, x: l.x, y: l.y });
|
|
@@ -185,10 +184,10 @@ function useMemoStateContext(props) {
|
|
|
185
184
|
return memo;
|
|
186
185
|
}, []),
|
|
187
186
|
itemLayout: { w, h, x, y },
|
|
188
|
-
pluginType: dndPluginType,
|
|
189
187
|
commit: resetTemporaryLayout,
|
|
188
|
+
dragProps,
|
|
190
189
|
});
|
|
191
|
-
}, [
|
|
190
|
+
}, [dragProps, onDropProp, resetTemporaryLayout]);
|
|
192
191
|
return React.useMemo(() => ({
|
|
193
192
|
layout: resultLayout,
|
|
194
193
|
temporaryLayout,
|