@gravity-ui/dashkit 8.4.0 → 8.5.0-beta.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/build/cjs/components/GridLayout/GridLayout.d.ts +4 -2
- package/build/cjs/components/GridLayout/GridLayout.js +33 -6
- package/build/cjs/constants/common.d.ts +1 -0
- package/build/cjs/constants/common.js +2 -1
- package/build/cjs/hocs/withContext.js +5 -2
- package/build/cjs/typings/config.d.ts +5 -0
- package/build/esm/components/GridLayout/GridLayout.d.ts +4 -2
- package/build/esm/components/GridLayout/GridLayout.js +34 -7
- package/build/esm/constants/common.d.ts +1 -0
- package/build/esm/constants/common.js +1 -0
- package/build/esm/hocs/withContext.js +5 -2
- package/build/esm/typings/config.d.ts +5 -0
- package/package.json +1 -1
|
@@ -23,10 +23,12 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
|
|
|
23
23
|
reloadItems(): void;
|
|
24
24
|
_onStart: () => void;
|
|
25
25
|
_onStop: (group: any, newLayout: any) => void;
|
|
26
|
-
_onDropDragOver: (e: any) => any;
|
|
26
|
+
_onDropDragOver: (e: any, gridProperties: any, layout: any) => any;
|
|
27
27
|
_onDrop: (group: any, newLayout: any, item: any, e: any) => false | undefined;
|
|
28
28
|
renderTemporaryPlaceholder(): JSX.Element | null;
|
|
29
|
-
|
|
29
|
+
caclculateEmptyHorizontalSpace(layout: any, cols: any): any;
|
|
30
|
+
getElementLayout(layout: any, properties: any): any;
|
|
31
|
+
renderGroup(group: any, renderLayout: any, renderItems: any, offset: number | undefined, groupGridProperties: any): JSX.Element;
|
|
30
32
|
render(): any;
|
|
31
33
|
}
|
|
32
34
|
import React from 'react';
|
|
@@ -46,12 +46,20 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
46
46
|
}
|
|
47
47
|
this.setState({ isDragging: false });
|
|
48
48
|
};
|
|
49
|
-
this._onDropDragOver = (e) => {
|
|
49
|
+
this._onDropDragOver = (e, gridProperties, layout) => {
|
|
50
50
|
const { editMode, dragOverPlugin, onDropDragOver } = this.context;
|
|
51
51
|
if (!editMode || !dragOverPlugin) {
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
let maxW = gridProperties.cols;
|
|
55
|
+
const maxH = gridProperties.maxRows;
|
|
56
|
+
if (gridProperties.compactType === constants_1.COMPACT_TYPE_HORIZONTAL_NOWRAP) {
|
|
57
|
+
maxW = this.caclculateEmptyHorizontalSpace(layout, gridProperties.cols);
|
|
58
|
+
}
|
|
59
|
+
if (maxW === 0 || maxH === 0) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return onDropDragOver(e, { maxH, maxW });
|
|
55
63
|
};
|
|
56
64
|
this._onDrop = (group, newLayout, item, e) => {
|
|
57
65
|
if (!item) {
|
|
@@ -131,14 +139,33 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
131
139
|
const { type } = temporaryLayout.dragProps;
|
|
132
140
|
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 }));
|
|
133
141
|
}
|
|
134
|
-
|
|
142
|
+
caclculateEmptyHorizontalSpace(layout, cols) {
|
|
143
|
+
return layout.reduce((memo, item) => memo - item.w, cols);
|
|
144
|
+
}
|
|
145
|
+
getElementLayout(layout, properties) {
|
|
146
|
+
let maxH;
|
|
147
|
+
if (properties.maxRows) {
|
|
148
|
+
maxH = properties.maxRows;
|
|
149
|
+
}
|
|
150
|
+
const leftSpace = this.caclculateEmptyHorizontalSpace(layout, properties.cols);
|
|
151
|
+
return layout.map((item) => (Object.assign(Object.assign({}, item), { maxW: item.w + leftSpace, maxH })));
|
|
152
|
+
}
|
|
153
|
+
renderGroup(group, renderLayout, renderItems, offset = 0, groupGridProperties) {
|
|
135
154
|
const { registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, } = this.context;
|
|
136
|
-
|
|
155
|
+
const properties = groupGridProperties
|
|
156
|
+
? groupGridProperties(Object.assign({}, registerManager.gridLayout))
|
|
157
|
+
: registerManager.gridLayout;
|
|
158
|
+
let { compactType } = properties;
|
|
159
|
+
if (compactType === constants_1.COMPACT_TYPE_HORIZONTAL_NOWRAP) {
|
|
160
|
+
renderLayout = this.getElementLayout(renderLayout, properties);
|
|
161
|
+
compactType = 'horizontal';
|
|
162
|
+
}
|
|
163
|
+
return (react_1.default.createElement(ReactGridLayout_1.Layout, Object.assign({}, properties, { compactType: compactType, layout: renderLayout, key: `group_${group}`, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: (...args) => this._onStop(group, ...args), onResizeStart: this._onStart, onResizeStop: (...args) => this._onStop(group, ...args) }, (draggableHandleClassName
|
|
137
164
|
? { draggableHandle: `.${draggableHandleClassName}` }
|
|
138
165
|
: null), (outerDnDEnable
|
|
139
166
|
? {
|
|
140
167
|
isDroppable: true,
|
|
141
|
-
onDropDragOver: this._onDropDragOver,
|
|
168
|
+
onDropDragOver: (e) => this._onDropDragOver(e, properties, renderLayout),
|
|
142
169
|
onDrop: (...args) => this._onDrop(group, ...args),
|
|
143
170
|
}
|
|
144
171
|
: null), { draggableCancel: `.${constants_1.OVERLAY_CONTROLS_CLASS_NAME}` }),
|
|
@@ -194,7 +221,7 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
194
221
|
layout = groupedLayout[id] || [];
|
|
195
222
|
items = itemsByGroup[id] || [];
|
|
196
223
|
}
|
|
197
|
-
const element = this.renderGroup(id, layout, items, offset);
|
|
224
|
+
const element = this.renderGroup(id, layout, items, offset, group.gridProperties);
|
|
198
225
|
offset += items.length;
|
|
199
226
|
if (group.render) {
|
|
200
227
|
return group.render(id, element, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_GROUP = exports.DEFAULT_WIDGET_WIDTH = exports.DEFAULT_WIDGET_HEIGHT = exports.MenuItems = exports.TEMPORARY_ITEM_ID = exports.OVERLAY_CLASS_NAME = exports.OVERLAY_CONTROLS_CLASS_NAME = exports.DEFAULT_NAMESPACE = exports.COPIED_WIDGET_STORE_KEY = void 0;
|
|
3
|
+
exports.COMPACT_TYPE_HORIZONTAL_NOWRAP = exports.DEFAULT_GROUP = exports.DEFAULT_WIDGET_WIDTH = exports.DEFAULT_WIDGET_HEIGHT = exports.MenuItems = exports.TEMPORARY_ITEM_ID = exports.OVERLAY_CLASS_NAME = exports.OVERLAY_CONTROLS_CLASS_NAME = exports.DEFAULT_NAMESPACE = exports.COPIED_WIDGET_STORE_KEY = void 0;
|
|
4
4
|
exports.COPIED_WIDGET_STORE_KEY = 'dashCopiedItem';
|
|
5
5
|
exports.DEFAULT_NAMESPACE = 'default';
|
|
6
6
|
exports.OVERLAY_CONTROLS_CLASS_NAME = 'dashkit-overlay-controls';
|
|
@@ -14,3 +14,4 @@ exports.MenuItems = {
|
|
|
14
14
|
exports.DEFAULT_WIDGET_HEIGHT = 3;
|
|
15
15
|
exports.DEFAULT_WIDGET_WIDTH = 3;
|
|
16
16
|
exports.DEFAULT_GROUP = '__default';
|
|
17
|
+
exports.COMPACT_TYPE_HORIZONTAL_NOWRAP = 'horizontal-nowrap';
|
|
@@ -161,7 +161,7 @@ function useMemoStateContext(props) {
|
|
|
161
161
|
return null;
|
|
162
162
|
}
|
|
163
163
|
}, [dragProps, props.registerManager]);
|
|
164
|
-
const onDropDragOver = react_1.default.useCallback(() => {
|
|
164
|
+
const onDropDragOver = react_1.default.useCallback((_e, gridProps = {}) => {
|
|
165
165
|
if (temporaryLayout) {
|
|
166
166
|
resetTemporaryLayout();
|
|
167
167
|
return false;
|
|
@@ -169,7 +169,10 @@ function useMemoStateContext(props) {
|
|
|
169
169
|
if (dragOverPlugin) {
|
|
170
170
|
const { defaultLayout } = dragOverPlugin;
|
|
171
171
|
const { h = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.h) || common_1.DEFAULT_WIDGET_HEIGHT, w = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.w) || common_1.DEFAULT_WIDGET_WIDTH, } = dragProps.layout || {};
|
|
172
|
-
return {
|
|
172
|
+
return {
|
|
173
|
+
h: gridProps.maxH ? Math.min(h, gridProps.maxH) : h,
|
|
174
|
+
w: gridProps.maxW ? Math.min(w, gridProps.maxW) : w,
|
|
175
|
+
};
|
|
173
176
|
}
|
|
174
177
|
return false;
|
|
175
178
|
}, [resetTemporaryLayout, temporaryLayout, dragOverPlugin, dragProps]);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react-grid-layout" />
|
|
1
2
|
/// <reference types="react" />
|
|
2
3
|
import type { Config, ConfigItem, ConfigLayout } from '../shared';
|
|
3
4
|
export interface AddConfigItem extends Omit<ConfigItem, 'id' | 'namespace'> {
|
|
@@ -18,7 +19,11 @@ export interface DashkitGroupRenderProps {
|
|
|
18
19
|
items: ConfigItem[];
|
|
19
20
|
layout: ConfigLayout[];
|
|
20
21
|
}
|
|
22
|
+
export type ReactGridLayoutProps = Omit<ReactGridLayout.ReactGridLayoutProps, 'children' | 'compactType' | 'innerRef' | 'key' | 'layout' | 'isDraggable' | 'isResizable' | 'onDragStart' | 'onDragStop' | 'onResizeStart' | 'onResizeStop' | 'draggableHandle' | 'isDroppable' | 'onDropDragOver' | 'onDrop' | 'draggableCancel'> & {
|
|
23
|
+
compactType?: ReactGridLayout.ReactGridLayoutProps['compactType'] | 'horizontal-nowrap';
|
|
24
|
+
};
|
|
21
25
|
export interface DashKitGroup {
|
|
22
26
|
id?: string;
|
|
23
27
|
render?: (id: string, children: React.ReactNode, props: DashkitGroupRenderProps) => React.ReactNode;
|
|
28
|
+
gridProperties?: (props: ReactGridLayoutProps) => ReactGridLayoutProps;
|
|
24
29
|
}
|
|
@@ -23,10 +23,12 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
|
|
|
23
23
|
reloadItems(): void;
|
|
24
24
|
_onStart: () => void;
|
|
25
25
|
_onStop: (group: any, newLayout: any) => void;
|
|
26
|
-
_onDropDragOver: (e: any) => any;
|
|
26
|
+
_onDropDragOver: (e: any, gridProperties: any, layout: any) => any;
|
|
27
27
|
_onDrop: (group: any, newLayout: any, item: any, e: any) => false | undefined;
|
|
28
28
|
renderTemporaryPlaceholder(): JSX.Element | null;
|
|
29
|
-
|
|
29
|
+
caclculateEmptyHorizontalSpace(layout: any, cols: any): any;
|
|
30
|
+
getElementLayout(layout: any, properties: any): any;
|
|
31
|
+
renderGroup(group: any, renderLayout: any, renderItems: any, offset: number | undefined, groupGridProperties: any): JSX.Element;
|
|
30
32
|
render(): any;
|
|
31
33
|
}
|
|
32
34
|
import React from 'react';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { DEFAULT_GROUP, OVERLAY_CONTROLS_CLASS_NAME, TEMPORARY_ITEM_ID } from '../../constants';
|
|
2
|
+
import { COMPACT_TYPE_HORIZONTAL_NOWRAP, DEFAULT_GROUP, OVERLAY_CONTROLS_CLASS_NAME, TEMPORARY_ITEM_ID, } from '../../constants';
|
|
3
3
|
import { DashKitContext } from '../../context/DashKitContext';
|
|
4
4
|
import GridItem from '../GridItem/GridItem';
|
|
5
5
|
import { Layout } from './ReactGridLayout';
|
|
@@ -43,12 +43,20 @@ class GridLayout extends React.PureComponent {
|
|
|
43
43
|
}
|
|
44
44
|
this.setState({ isDragging: false });
|
|
45
45
|
};
|
|
46
|
-
this._onDropDragOver = (e) => {
|
|
46
|
+
this._onDropDragOver = (e, gridProperties, layout) => {
|
|
47
47
|
const { editMode, dragOverPlugin, onDropDragOver } = this.context;
|
|
48
48
|
if (!editMode || !dragOverPlugin) {
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
let maxW = gridProperties.cols;
|
|
52
|
+
const maxH = gridProperties.maxRows;
|
|
53
|
+
if (gridProperties.compactType === COMPACT_TYPE_HORIZONTAL_NOWRAP) {
|
|
54
|
+
maxW = this.caclculateEmptyHorizontalSpace(layout, gridProperties.cols);
|
|
55
|
+
}
|
|
56
|
+
if (maxW === 0 || maxH === 0) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return onDropDragOver(e, { maxH, maxW });
|
|
52
60
|
};
|
|
53
61
|
this._onDrop = (group, newLayout, item, e) => {
|
|
54
62
|
if (!item) {
|
|
@@ -128,14 +136,33 @@ class GridLayout extends React.PureComponent {
|
|
|
128
136
|
const { type } = temporaryLayout.dragProps;
|
|
129
137
|
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 }));
|
|
130
138
|
}
|
|
131
|
-
|
|
139
|
+
caclculateEmptyHorizontalSpace(layout, cols) {
|
|
140
|
+
return layout.reduce((memo, item) => memo - item.w, cols);
|
|
141
|
+
}
|
|
142
|
+
getElementLayout(layout, properties) {
|
|
143
|
+
let maxH;
|
|
144
|
+
if (properties.maxRows) {
|
|
145
|
+
maxH = properties.maxRows;
|
|
146
|
+
}
|
|
147
|
+
const leftSpace = this.caclculateEmptyHorizontalSpace(layout, properties.cols);
|
|
148
|
+
return layout.map((item) => (Object.assign(Object.assign({}, item), { maxW: item.w + leftSpace, maxH })));
|
|
149
|
+
}
|
|
150
|
+
renderGroup(group, renderLayout, renderItems, offset = 0, groupGridProperties) {
|
|
132
151
|
const { registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, } = this.context;
|
|
133
|
-
|
|
152
|
+
const properties = groupGridProperties
|
|
153
|
+
? groupGridProperties(Object.assign({}, registerManager.gridLayout))
|
|
154
|
+
: registerManager.gridLayout;
|
|
155
|
+
let { compactType } = properties;
|
|
156
|
+
if (compactType === COMPACT_TYPE_HORIZONTAL_NOWRAP) {
|
|
157
|
+
renderLayout = this.getElementLayout(renderLayout, properties);
|
|
158
|
+
compactType = 'horizontal';
|
|
159
|
+
}
|
|
160
|
+
return (React.createElement(Layout, Object.assign({}, properties, { compactType: compactType, layout: renderLayout, key: `group_${group}`, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: (...args) => this._onStop(group, ...args), onResizeStart: this._onStart, onResizeStop: (...args) => this._onStop(group, ...args) }, (draggableHandleClassName
|
|
134
161
|
? { draggableHandle: `.${draggableHandleClassName}` }
|
|
135
162
|
: null), (outerDnDEnable
|
|
136
163
|
? {
|
|
137
164
|
isDroppable: true,
|
|
138
|
-
onDropDragOver: this._onDropDragOver,
|
|
165
|
+
onDropDragOver: (e) => this._onDropDragOver(e, properties, renderLayout),
|
|
139
166
|
onDrop: (...args) => this._onDrop(group, ...args),
|
|
140
167
|
}
|
|
141
168
|
: null), { draggableCancel: `.${OVERLAY_CONTROLS_CLASS_NAME}` }),
|
|
@@ -191,7 +218,7 @@ class GridLayout extends React.PureComponent {
|
|
|
191
218
|
layout = groupedLayout[id] || [];
|
|
192
219
|
items = itemsByGroup[id] || [];
|
|
193
220
|
}
|
|
194
|
-
const element = this.renderGroup(id, layout, items, offset);
|
|
221
|
+
const element = this.renderGroup(id, layout, items, offset, group.gridProperties);
|
|
195
222
|
offset += items.length;
|
|
196
223
|
if (group.render) {
|
|
197
224
|
return group.render(id, element, {
|
|
@@ -157,7 +157,7 @@ function useMemoStateContext(props) {
|
|
|
157
157
|
return null;
|
|
158
158
|
}
|
|
159
159
|
}, [dragProps, props.registerManager]);
|
|
160
|
-
const onDropDragOver = React.useCallback(() => {
|
|
160
|
+
const onDropDragOver = React.useCallback((_e, gridProps = {}) => {
|
|
161
161
|
if (temporaryLayout) {
|
|
162
162
|
resetTemporaryLayout();
|
|
163
163
|
return false;
|
|
@@ -165,7 +165,10 @@ function useMemoStateContext(props) {
|
|
|
165
165
|
if (dragOverPlugin) {
|
|
166
166
|
const { defaultLayout } = dragOverPlugin;
|
|
167
167
|
const { h = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.h) || DEFAULT_WIDGET_HEIGHT, w = (defaultLayout === null || defaultLayout === void 0 ? void 0 : defaultLayout.w) || DEFAULT_WIDGET_WIDTH, } = dragProps.layout || {};
|
|
168
|
-
return {
|
|
168
|
+
return {
|
|
169
|
+
h: gridProps.maxH ? Math.min(h, gridProps.maxH) : h,
|
|
170
|
+
w: gridProps.maxW ? Math.min(w, gridProps.maxW) : w,
|
|
171
|
+
};
|
|
169
172
|
}
|
|
170
173
|
return false;
|
|
171
174
|
}, [resetTemporaryLayout, temporaryLayout, dragOverPlugin, dragProps]);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react-grid-layout" />
|
|
1
2
|
/// <reference types="react" />
|
|
2
3
|
import type { Config, ConfigItem, ConfigLayout } from '../shared';
|
|
3
4
|
export interface AddConfigItem extends Omit<ConfigItem, 'id' | 'namespace'> {
|
|
@@ -18,7 +19,11 @@ export interface DashkitGroupRenderProps {
|
|
|
18
19
|
items: ConfigItem[];
|
|
19
20
|
layout: ConfigLayout[];
|
|
20
21
|
}
|
|
22
|
+
export type ReactGridLayoutProps = Omit<ReactGridLayout.ReactGridLayoutProps, 'children' | 'compactType' | 'innerRef' | 'key' | 'layout' | 'isDraggable' | 'isResizable' | 'onDragStart' | 'onDragStop' | 'onResizeStart' | 'onResizeStop' | 'draggableHandle' | 'isDroppable' | 'onDropDragOver' | 'onDrop' | 'draggableCancel'> & {
|
|
23
|
+
compactType?: ReactGridLayout.ReactGridLayoutProps['compactType'] | 'horizontal-nowrap';
|
|
24
|
+
};
|
|
21
25
|
export interface DashKitGroup {
|
|
22
26
|
id?: string;
|
|
23
27
|
render?: (id: string, children: React.ReactNode, props: DashkitGroupRenderProps) => React.ReactNode;
|
|
28
|
+
gridProperties?: (props: ReactGridLayoutProps) => ReactGridLayoutProps;
|
|
24
29
|
}
|