@gravity-ui/dashkit 6.4.0 → 6.5.0-beta.1
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/DashKit/DashKit.d.ts +13 -1
- package/build/cjs/components/DashKit/DashKit.js +10 -1
- package/build/cjs/components/GridItem/GridItem.css +0 -8
- package/build/cjs/components/GridItem/GridItem.js +1 -2
- package/build/cjs/components/GridLayout/GridLayout.d.ts +1 -0
- package/build/cjs/components/GridLayout/GridLayout.js +5 -0
- package/build/cjs/hocs/withContext.js +11 -3
- package/build/esm/components/DashKit/DashKit.d.ts +13 -1
- package/build/esm/components/DashKit/DashKit.js +10 -1
- package/build/esm/components/GridItem/GridItem.css +0 -8
- package/build/esm/components/GridItem/GridItem.js +1 -2
- package/build/esm/components/GridLayout/GridLayout.d.ts +1 -0
- package/build/esm/components/GridLayout/GridLayout.js +5 -0
- package/build/esm/hocs/withContext.js +11 -3
- package/package.json +1 -1
|
@@ -21,7 +21,10 @@ interface DashKitDefaultProps {
|
|
|
21
21
|
settings: SettingsProps;
|
|
22
22
|
context: ContextProps;
|
|
23
23
|
noOverlay: boolean;
|
|
24
|
-
|
|
24
|
+
hideWidgetOverlayControl: (args: {
|
|
25
|
+
id: string;
|
|
26
|
+
controlId: string;
|
|
27
|
+
}) => void;
|
|
25
28
|
}
|
|
26
29
|
export interface DashKitProps extends DashKitGeneralProps, Partial<DashKitDefaultProps> {
|
|
27
30
|
}
|
|
@@ -47,5 +50,14 @@ export declare class DashKit extends React.PureComponent<DashKitInnerProps> {
|
|
|
47
50
|
metaRef: React.RefObject<GridLayout>;
|
|
48
51
|
render(): JSX.Element;
|
|
49
52
|
getItemsMeta(): any;
|
|
53
|
+
/**
|
|
54
|
+
* public method for hiding overlayControl item by id
|
|
55
|
+
* for ex. can be triggered after data render
|
|
56
|
+
* @param args
|
|
57
|
+
*/
|
|
58
|
+
hideWidgetOverlayControl(args: {
|
|
59
|
+
id: string;
|
|
60
|
+
controlId: string;
|
|
61
|
+
}): any;
|
|
50
62
|
}
|
|
51
63
|
export {};
|
|
@@ -54,11 +54,21 @@ class DashKit extends react_1.default.PureComponent {
|
|
|
54
54
|
var _a;
|
|
55
55
|
return (_a = this.metaRef.current) === null || _a === void 0 ? void 0 : _a.getItemsMeta();
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* public method for hiding overlayControl item by id
|
|
59
|
+
* for ex. can be triggered after data render
|
|
60
|
+
* @param args
|
|
61
|
+
*/
|
|
62
|
+
hideWidgetOverlayControl(args) {
|
|
63
|
+
var _a;
|
|
64
|
+
return (_a = this.metaRef.current) === null || _a === void 0 ? void 0 : _a.hideWidgetOverlayControl(args);
|
|
65
|
+
}
|
|
57
66
|
}
|
|
58
67
|
exports.DashKit = DashKit;
|
|
59
68
|
DashKit.defaultProps = {
|
|
60
69
|
onItemEdit: noop_1.default,
|
|
61
70
|
onChange: noop_1.default,
|
|
71
|
+
hideWidgetOverlayControl: noop_1.default,
|
|
62
72
|
defaultGlobalParams: {},
|
|
63
73
|
globalParams: {},
|
|
64
74
|
itemsStateAndParams: {},
|
|
@@ -68,5 +78,4 @@ DashKit.defaultProps = {
|
|
|
68
78
|
},
|
|
69
79
|
context: {},
|
|
70
80
|
noOverlay: false,
|
|
71
|
-
_experimentDisableItemAnimation: false,
|
|
72
81
|
};
|
|
@@ -30,14 +30,6 @@
|
|
|
30
30
|
transition: height 200ms ease;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
.react-grid-item {
|
|
34
|
-
transition: all 200ms ease;
|
|
35
|
-
transition-property: left, top;
|
|
36
|
-
}
|
|
37
|
-
.react-grid-item.dashkit-grid-item_disable-animation {
|
|
38
|
-
transition: none;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
33
|
.react-grid-item.cssTransforms {
|
|
42
34
|
transition-property: transform;
|
|
43
35
|
}
|
|
@@ -25,7 +25,7 @@ class GridItem extends react_1.default.PureComponent {
|
|
|
25
25
|
// из-за бага, что Grid Items unmounts при изменении static, isDraggable, isResaizable
|
|
26
26
|
// https://github.com/STRML/react-grid-layout/issues/721
|
|
27
27
|
const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, noOverlay, withCustomHandle, } = this.props;
|
|
28
|
-
const { editMode
|
|
28
|
+
const { editMode } = this.context;
|
|
29
29
|
const width = Number.parseInt(style.width, 10);
|
|
30
30
|
const height = Number.parseInt(style.height, 10);
|
|
31
31
|
const transform = style.transform;
|
|
@@ -40,7 +40,6 @@ class GridItem extends react_1.default.PureComponent {
|
|
|
40
40
|
return (react_1.default.createElement("div", Object.assign({ className: b({
|
|
41
41
|
'is-dragging': isDragging,
|
|
42
42
|
'with-custom-handle': withCustomHandle,
|
|
43
|
-
'disable-animation': _experimentDisableItemAnimation,
|
|
44
43
|
}, preparedClassName), "data-qa": "dashkit-grid-item", style: style, ref: this.props.forwardedRef }, reactGridLayoutProps),
|
|
45
44
|
react_1.default.createElement("div", { className: b('item', { editMode: editMode && !_editActive && !noOverlay }) },
|
|
46
45
|
react_1.default.createElement(Item_1.default, { id: this.props.id, item: this.props.item, shouldItemUpdate: !isDragging, width: width, height: height, transform: transform, adjustWidgetLayout: this.props.adjustWidgetLayout, layout: this.props.layout, forwardedPluginRef: this.props.forwardedPluginRef })),
|
|
@@ -18,6 +18,7 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
|
|
|
18
18
|
adjustedWidgetLayout: any;
|
|
19
19
|
}) => void;
|
|
20
20
|
getItemsMeta: () => any;
|
|
21
|
+
hideWidgetOverlayControl: (args: any) => any;
|
|
21
22
|
reloadItems(): void;
|
|
22
23
|
_onStart: () => void;
|
|
23
24
|
_onStop: (newLayout: any) => void;
|
|
@@ -30,6 +30,11 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
30
30
|
const { getItemsMeta } = this.context;
|
|
31
31
|
return getItemsMeta(this.pluginsRefs);
|
|
32
32
|
};
|
|
33
|
+
this.hideWidgetOverlayControl = (args) => {
|
|
34
|
+
const { hideWidgetOverlayControl } = this.context;
|
|
35
|
+
const plugin = this.pluginsRefs.find((item) => item.props.id);
|
|
36
|
+
return hideWidgetOverlayControl(Object.assign(Object.assign({}, args), { plugin }));
|
|
37
|
+
};
|
|
33
38
|
this._onStart = () => {
|
|
34
39
|
this.setState({ isDragging: true });
|
|
35
40
|
};
|
|
@@ -15,6 +15,7 @@ function useMemoStateContext(props) {
|
|
|
15
15
|
// (высота) из конфига будет запоминаться в originalLayouts, новое значение высоты в adjustedLayouts
|
|
16
16
|
const originalLayouts = react_1.default.useRef({});
|
|
17
17
|
const adjustedLayouts = react_1.default.useRef({});
|
|
18
|
+
const [filteredOverlayControls, setFilteredOverlayControls] = react_1.default.useState(props.overlayControls || []);
|
|
18
19
|
// TODO: need move originalLayouts, adjustedLayouts to state
|
|
19
20
|
const [layoutUpdateCounter, forceUpdateLayout] = react_1.default.useState(0);
|
|
20
21
|
const onChange = react_1.default.useCallback(({ config = props.config, itemsStateAndParams = props.itemsStateAndParams }) => {
|
|
@@ -110,6 +111,10 @@ function useMemoStateContext(props) {
|
|
|
110
111
|
})
|
|
111
112
|
.filter(Boolean);
|
|
112
113
|
}, []);
|
|
114
|
+
const hideWidgetOverlayControl = react_1.default.useCallback((args) => {
|
|
115
|
+
const newOverlayControls = props.overlayControls.allWidgetsControls.filter((item) => item.id !== args.controlId);
|
|
116
|
+
setFilteredOverlayControls(Object.assign(Object.assign({}, props.overlayControls), { allWidgetsControls: newOverlayControls }));
|
|
117
|
+
}, [props.overlayControls]);
|
|
113
118
|
const resultLayout = react_1.default.useMemo(() => {
|
|
114
119
|
return props.layout.map((item) => {
|
|
115
120
|
if (item.i in adjustedLayouts.current) {
|
|
@@ -140,12 +145,13 @@ function useMemoStateContext(props) {
|
|
|
140
145
|
editItem: props.onItemEdit,
|
|
141
146
|
layoutChange: onLayoutChange,
|
|
142
147
|
getItemsMeta,
|
|
148
|
+
hideWidgetOverlayControl,
|
|
149
|
+
filteredOverlayControls,
|
|
143
150
|
reloadItems,
|
|
144
151
|
memorizeOriginalLayout,
|
|
145
152
|
revertToOriginalLayout,
|
|
146
153
|
forwardedMetaRef: props.forwardedMetaRef,
|
|
147
154
|
draggableHandleClassName: props.draggableHandleClassName,
|
|
148
|
-
_experimentDisableItemAnimation: props._experimentDisableItemAnimation,
|
|
149
155
|
}), [
|
|
150
156
|
resultLayout,
|
|
151
157
|
props.config,
|
|
@@ -162,19 +168,21 @@ function useMemoStateContext(props) {
|
|
|
162
168
|
props.onItemEdit,
|
|
163
169
|
onLayoutChange,
|
|
164
170
|
getItemsMeta,
|
|
171
|
+
hideWidgetOverlayControl,
|
|
172
|
+
filteredOverlayControls,
|
|
165
173
|
reloadItems,
|
|
166
174
|
memorizeOriginalLayout,
|
|
167
175
|
revertToOriginalLayout,
|
|
168
176
|
props.forwardedMetaRef,
|
|
169
177
|
props.draggableHandleClassName,
|
|
170
|
-
props._experimentDisableItemAnimation,
|
|
171
178
|
]);
|
|
172
179
|
}
|
|
173
180
|
function withContext(Component) {
|
|
174
181
|
const WithContext = (props) => {
|
|
175
182
|
const contextValue = useMemoStateContext(props);
|
|
183
|
+
const overlayControls = contextValue.filteredOverlayControls;
|
|
176
184
|
return (react_1.default.createElement(DashKitContext_1.DashKitContext.Provider, { value: contextValue },
|
|
177
|
-
react_1.default.createElement(Component, { overlayControls:
|
|
185
|
+
react_1.default.createElement(Component, { overlayControls: overlayControls })));
|
|
178
186
|
};
|
|
179
187
|
WithContext.displayName = `withContext(${Component.displayName || Component.name || 'Component'}`;
|
|
180
188
|
return WithContext;
|
|
@@ -21,7 +21,10 @@ interface DashKitDefaultProps {
|
|
|
21
21
|
settings: SettingsProps;
|
|
22
22
|
context: ContextProps;
|
|
23
23
|
noOverlay: boolean;
|
|
24
|
-
|
|
24
|
+
hideWidgetOverlayControl: (args: {
|
|
25
|
+
id: string;
|
|
26
|
+
controlId: string;
|
|
27
|
+
}) => void;
|
|
25
28
|
}
|
|
26
29
|
export interface DashKitProps extends DashKitGeneralProps, Partial<DashKitDefaultProps> {
|
|
27
30
|
}
|
|
@@ -47,5 +50,14 @@ export declare class DashKit extends React.PureComponent<DashKitInnerProps> {
|
|
|
47
50
|
metaRef: React.RefObject<GridLayout>;
|
|
48
51
|
render(): JSX.Element;
|
|
49
52
|
getItemsMeta(): any;
|
|
53
|
+
/**
|
|
54
|
+
* public method for hiding overlayControl item by id
|
|
55
|
+
* for ex. can be triggered after data render
|
|
56
|
+
* @param args
|
|
57
|
+
*/
|
|
58
|
+
hideWidgetOverlayControl(args: {
|
|
59
|
+
id: string;
|
|
60
|
+
controlId: string;
|
|
61
|
+
}): any;
|
|
50
62
|
}
|
|
51
63
|
export {};
|
|
@@ -50,10 +50,20 @@ export class DashKit extends React.PureComponent {
|
|
|
50
50
|
var _a;
|
|
51
51
|
return (_a = this.metaRef.current) === null || _a === void 0 ? void 0 : _a.getItemsMeta();
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* public method for hiding overlayControl item by id
|
|
55
|
+
* for ex. can be triggered after data render
|
|
56
|
+
* @param args
|
|
57
|
+
*/
|
|
58
|
+
hideWidgetOverlayControl(args) {
|
|
59
|
+
var _a;
|
|
60
|
+
return (_a = this.metaRef.current) === null || _a === void 0 ? void 0 : _a.hideWidgetOverlayControl(args);
|
|
61
|
+
}
|
|
53
62
|
}
|
|
54
63
|
DashKit.defaultProps = {
|
|
55
64
|
onItemEdit: noop,
|
|
56
65
|
onChange: noop,
|
|
66
|
+
hideWidgetOverlayControl: noop,
|
|
57
67
|
defaultGlobalParams: {},
|
|
58
68
|
globalParams: {},
|
|
59
69
|
itemsStateAndParams: {},
|
|
@@ -63,5 +73,4 @@ DashKit.defaultProps = {
|
|
|
63
73
|
},
|
|
64
74
|
context: {},
|
|
65
75
|
noOverlay: false,
|
|
66
|
-
_experimentDisableItemAnimation: false,
|
|
67
76
|
};
|
|
@@ -30,14 +30,6 @@
|
|
|
30
30
|
transition: height 200ms ease;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
.react-grid-item {
|
|
34
|
-
transition: all 200ms ease;
|
|
35
|
-
transition-property: left, top;
|
|
36
|
-
}
|
|
37
|
-
.react-grid-item.dashkit-grid-item_disable-animation {
|
|
38
|
-
transition: none;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
33
|
.react-grid-item.cssTransforms {
|
|
42
34
|
transition-property: transform;
|
|
43
35
|
}
|
|
@@ -23,7 +23,7 @@ class GridItem extends React.PureComponent {
|
|
|
23
23
|
// из-за бага, что Grid Items unmounts при изменении static, isDraggable, isResaizable
|
|
24
24
|
// https://github.com/STRML/react-grid-layout/issues/721
|
|
25
25
|
const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, noOverlay, withCustomHandle, } = this.props;
|
|
26
|
-
const { editMode
|
|
26
|
+
const { editMode } = this.context;
|
|
27
27
|
const width = Number.parseInt(style.width, 10);
|
|
28
28
|
const height = Number.parseInt(style.height, 10);
|
|
29
29
|
const transform = style.transform;
|
|
@@ -38,7 +38,6 @@ class GridItem extends React.PureComponent {
|
|
|
38
38
|
return (React.createElement("div", Object.assign({ className: b({
|
|
39
39
|
'is-dragging': isDragging,
|
|
40
40
|
'with-custom-handle': withCustomHandle,
|
|
41
|
-
'disable-animation': _experimentDisableItemAnimation,
|
|
42
41
|
}, preparedClassName), "data-qa": "dashkit-grid-item", style: style, ref: this.props.forwardedRef }, reactGridLayoutProps),
|
|
43
42
|
React.createElement("div", { className: b('item', { editMode: editMode && !_editActive && !noOverlay }) },
|
|
44
43
|
React.createElement(Item, { id: this.props.id, item: this.props.item, shouldItemUpdate: !isDragging, width: width, height: height, transform: transform, adjustWidgetLayout: this.props.adjustWidgetLayout, layout: this.props.layout, forwardedPluginRef: this.props.forwardedPluginRef })),
|
|
@@ -18,6 +18,7 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
|
|
|
18
18
|
adjustedWidgetLayout: any;
|
|
19
19
|
}) => void;
|
|
20
20
|
getItemsMeta: () => any;
|
|
21
|
+
hideWidgetOverlayControl: (args: any) => any;
|
|
21
22
|
reloadItems(): void;
|
|
22
23
|
_onStart: () => void;
|
|
23
24
|
_onStop: (newLayout: any) => void;
|
|
@@ -27,6 +27,11 @@ export default class GridLayout extends React.PureComponent {
|
|
|
27
27
|
const { getItemsMeta } = this.context;
|
|
28
28
|
return getItemsMeta(this.pluginsRefs);
|
|
29
29
|
};
|
|
30
|
+
this.hideWidgetOverlayControl = (args) => {
|
|
31
|
+
const { hideWidgetOverlayControl } = this.context;
|
|
32
|
+
const plugin = this.pluginsRefs.find((item) => item.props.id);
|
|
33
|
+
return hideWidgetOverlayControl(Object.assign(Object.assign({}, args), { plugin }));
|
|
34
|
+
};
|
|
30
35
|
this._onStart = () => {
|
|
31
36
|
this.setState({ isDragging: true });
|
|
32
37
|
};
|
|
@@ -11,6 +11,7 @@ function useMemoStateContext(props) {
|
|
|
11
11
|
// (высота) из конфига будет запоминаться в originalLayouts, новое значение высоты в adjustedLayouts
|
|
12
12
|
const originalLayouts = React.useRef({});
|
|
13
13
|
const adjustedLayouts = React.useRef({});
|
|
14
|
+
const [filteredOverlayControls, setFilteredOverlayControls] = React.useState(props.overlayControls || []);
|
|
14
15
|
// TODO: need move originalLayouts, adjustedLayouts to state
|
|
15
16
|
const [layoutUpdateCounter, forceUpdateLayout] = React.useState(0);
|
|
16
17
|
const onChange = React.useCallback(({ config = props.config, itemsStateAndParams = props.itemsStateAndParams }) => {
|
|
@@ -106,6 +107,10 @@ function useMemoStateContext(props) {
|
|
|
106
107
|
})
|
|
107
108
|
.filter(Boolean);
|
|
108
109
|
}, []);
|
|
110
|
+
const hideWidgetOverlayControl = React.useCallback((args) => {
|
|
111
|
+
const newOverlayControls = props.overlayControls.allWidgetsControls.filter((item) => item.id !== args.controlId);
|
|
112
|
+
setFilteredOverlayControls(Object.assign(Object.assign({}, props.overlayControls), { allWidgetsControls: newOverlayControls }));
|
|
113
|
+
}, [props.overlayControls]);
|
|
109
114
|
const resultLayout = React.useMemo(() => {
|
|
110
115
|
return props.layout.map((item) => {
|
|
111
116
|
if (item.i in adjustedLayouts.current) {
|
|
@@ -136,12 +141,13 @@ function useMemoStateContext(props) {
|
|
|
136
141
|
editItem: props.onItemEdit,
|
|
137
142
|
layoutChange: onLayoutChange,
|
|
138
143
|
getItemsMeta,
|
|
144
|
+
hideWidgetOverlayControl,
|
|
145
|
+
filteredOverlayControls,
|
|
139
146
|
reloadItems,
|
|
140
147
|
memorizeOriginalLayout,
|
|
141
148
|
revertToOriginalLayout,
|
|
142
149
|
forwardedMetaRef: props.forwardedMetaRef,
|
|
143
150
|
draggableHandleClassName: props.draggableHandleClassName,
|
|
144
|
-
_experimentDisableItemAnimation: props._experimentDisableItemAnimation,
|
|
145
151
|
}), [
|
|
146
152
|
resultLayout,
|
|
147
153
|
props.config,
|
|
@@ -158,19 +164,21 @@ function useMemoStateContext(props) {
|
|
|
158
164
|
props.onItemEdit,
|
|
159
165
|
onLayoutChange,
|
|
160
166
|
getItemsMeta,
|
|
167
|
+
hideWidgetOverlayControl,
|
|
168
|
+
filteredOverlayControls,
|
|
161
169
|
reloadItems,
|
|
162
170
|
memorizeOriginalLayout,
|
|
163
171
|
revertToOriginalLayout,
|
|
164
172
|
props.forwardedMetaRef,
|
|
165
173
|
props.draggableHandleClassName,
|
|
166
|
-
props._experimentDisableItemAnimation,
|
|
167
174
|
]);
|
|
168
175
|
}
|
|
169
176
|
export function withContext(Component) {
|
|
170
177
|
const WithContext = (props) => {
|
|
171
178
|
const contextValue = useMemoStateContext(props);
|
|
179
|
+
const overlayControls = contextValue.filteredOverlayControls;
|
|
172
180
|
return (React.createElement(DashKitContext.Provider, { value: contextValue },
|
|
173
|
-
React.createElement(Component, { overlayControls:
|
|
181
|
+
React.createElement(Component, { overlayControls: overlayControls })));
|
|
174
182
|
};
|
|
175
183
|
WithContext.displayName = `withContext(${Component.displayName || Component.name || 'Component'}`;
|
|
176
184
|
return WithContext;
|