@gravity-ui/dashkit 3.1.0-alpha.0 → 3.1.0-alpha.2
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/DashKitView/DashKitView.js +2 -2
- package/build/cjs/components/GridItem/GridItem.js +4 -2
- package/build/cjs/components/GridLayout/GridLayout.js +1 -1
- package/build/cjs/components/OverlayControls/OverlayControls.d.ts +1 -0
- package/build/cjs/components/OverlayControls/OverlayControls.js +1 -1
- package/build/cjs/hocs/withContext.d.ts +0 -2
- package/build/cjs/hocs/withContext.js +15 -8
- package/build/esm/components/DashKitView/DashKitView.js +2 -2
- package/build/esm/components/GridItem/GridItem.js +4 -2
- package/build/esm/components/GridLayout/GridLayout.js +1 -1
- package/build/esm/components/OverlayControls/OverlayControls.d.ts +1 -0
- package/build/esm/components/OverlayControls/OverlayControls.js +1 -1
- package/build/esm/hocs/withContext.d.ts +0 -2
- package/build/esm/hocs/withContext.js +15 -8
- package/package.json +1 -1
|
@@ -9,10 +9,10 @@ const MobileLayout_1 = tslib_1.__importDefault(require("../MobileLayout/MobileLa
|
|
|
9
9
|
const withContext_1 = require("../../hocs/withContext");
|
|
10
10
|
const useCalcLayout_1 = require("../../hooks/useCalcLayout");
|
|
11
11
|
const b = (0, bem_cn_lite_1.default)('dashkit');
|
|
12
|
-
function DashKitView() {
|
|
12
|
+
function DashKitView(props) {
|
|
13
13
|
const context = react_1.default.useContext(DashKitContext_1.DashKitContext);
|
|
14
14
|
const { registerManager, forwardedMetaRef } = context;
|
|
15
|
-
return (react_1.default.createElement("div", { className: b({ theme: registerManager.settings.theme }) }, registerManager.settings.isMobile ? (react_1.default.createElement(MobileLayout_1.default, null)) : (react_1.default.createElement(GridLayout_1.default, { ref: forwardedMetaRef }))));
|
|
15
|
+
return (react_1.default.createElement("div", { className: b({ theme: registerManager.settings.theme }) }, registerManager.settings.isMobile ? (react_1.default.createElement(MobileLayout_1.default, null)) : (react_1.default.createElement(GridLayout_1.default, { ref: forwardedMetaRef, overlayControls: props.overlayControls }))));
|
|
16
16
|
}
|
|
17
17
|
const DashKitViewWithContext = (0, withContext_1.withContext)(DashKitView);
|
|
18
18
|
const DashKitViewWithMemoContext = (0, withContext_1.withMemoContext)(DashKitView);
|
|
@@ -10,7 +10,8 @@ const OverlayControls_1 = tslib_1.__importDefault(require("../OverlayControls/Ov
|
|
|
10
10
|
const b = (0, bem_cn_lite_1.default)('dashkit-grid-item');
|
|
11
11
|
class GridItem extends react_1.default.PureComponent {
|
|
12
12
|
renderOverlay() {
|
|
13
|
-
const {
|
|
13
|
+
const { overlayControls } = this.props;
|
|
14
|
+
const { editMode } = this.context;
|
|
14
15
|
if (!editMode || this.props.item.data._editActive) {
|
|
15
16
|
return null;
|
|
16
17
|
}
|
|
@@ -18,7 +19,7 @@ class GridItem extends react_1.default.PureComponent {
|
|
|
18
19
|
const controls = overlayControls && overlayControls[item.type];
|
|
19
20
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
20
21
|
react_1.default.createElement("div", { className: b('overlay') }),
|
|
21
|
-
react_1.default.createElement(OverlayControls_1.default, { configItem: item, items: controls })));
|
|
22
|
+
react_1.default.createElement(OverlayControls_1.default, { configItem: item, items: controls, overlayControls: overlayControls })));
|
|
22
23
|
}
|
|
23
24
|
render() {
|
|
24
25
|
// из-за бага, что Grid Items unmounts при изменении static, isDraggable, isResaizable
|
|
@@ -52,6 +53,7 @@ GridItem.propTypes = {
|
|
|
52
53
|
item: prop_types_1.default.object,
|
|
53
54
|
isDragging: prop_types_1.default.bool,
|
|
54
55
|
layout: prop_types_1.default.array,
|
|
56
|
+
overlayControls: prop_types_1.default.object,
|
|
55
57
|
forwardedPluginRef: prop_types_1.default.any,
|
|
56
58
|
// from react-grid-layout:
|
|
57
59
|
children: prop_types_1.default.node,
|
|
@@ -81,7 +81,7 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
81
81
|
: null)), config.items.map((item, i) => {
|
|
82
82
|
return (react_1.default.createElement(GridItem_1.default, { ref: (pluginRef) => {
|
|
83
83
|
this.pluginsRefs[i] = pluginRef;
|
|
84
|
-
}, key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName) }));
|
|
84
|
+
}, key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
|
|
85
85
|
})));
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -33,6 +33,7 @@ interface OverlayControlsDefaultProps {
|
|
|
33
33
|
interface OverlayControlsProps extends OverlayControlsDefaultProps {
|
|
34
34
|
configItem: ConfigItem;
|
|
35
35
|
items?: OverlayControlItem[];
|
|
36
|
+
overlayControls?: Record<string, OverlayControlItem[]>;
|
|
36
37
|
}
|
|
37
38
|
declare class OverlayControls extends React.Component<OverlayControlsProps> {
|
|
38
39
|
static contextType: React.Context<any>;
|
|
@@ -35,7 +35,7 @@ class OverlayControls extends react_1.default.Component {
|
|
|
35
35
|
// выбираем только items-ы у которых проставлено поле `allWidgetsControls:true`
|
|
36
36
|
// те контролы, которые будут показываться слева от меню
|
|
37
37
|
let controls = [];
|
|
38
|
-
for (const controlItem of Object.values(this.
|
|
38
|
+
for (const controlItem of Object.values(this.props.overlayControls || {})) {
|
|
39
39
|
controls = controls.concat((controlItem.filter((item) => {
|
|
40
40
|
var _a;
|
|
41
41
|
// если тип виджета-плагина в списке исключаемых, то не показываем такой контрол
|
|
@@ -26,7 +26,6 @@ export function withContext(Component: any): {
|
|
|
26
26
|
getLayout: () => any;
|
|
27
27
|
config: any;
|
|
28
28
|
context: any;
|
|
29
|
-
overlayControls: any;
|
|
30
29
|
noOverlay: any;
|
|
31
30
|
defaultGlobalParams: any;
|
|
32
31
|
globalParams: any;
|
|
@@ -98,7 +97,6 @@ export function withContext(Component: any): {
|
|
|
98
97
|
getLayout: () => any;
|
|
99
98
|
config: any;
|
|
100
99
|
context: any;
|
|
101
|
-
overlayControls: any;
|
|
102
100
|
noOverlay: any;
|
|
103
101
|
defaultGlobalParams: any;
|
|
104
102
|
globalParams: any;
|
|
@@ -154,7 +154,6 @@ function withContext(Component) {
|
|
|
154
154
|
getLayout: this._getLayout,
|
|
155
155
|
config: this.props.config,
|
|
156
156
|
context: this.props.context,
|
|
157
|
-
overlayControls: this.props.overlayControls,
|
|
158
157
|
noOverlay: this.props.noOverlay,
|
|
159
158
|
defaultGlobalParams: this.props.globalParams,
|
|
160
159
|
globalParams: this.props.globalParams,
|
|
@@ -177,7 +176,7 @@ function withContext(Component) {
|
|
|
177
176
|
}
|
|
178
177
|
render() {
|
|
179
178
|
return (react_1.default.createElement(DashKitContext_1.DashKitContext.Provider, { value: this._contextValue },
|
|
180
|
-
react_1.default.createElement(Component,
|
|
179
|
+
react_1.default.createElement(Component, { overlayControls: this.props.overlayControls })));
|
|
181
180
|
}
|
|
182
181
|
},
|
|
183
182
|
_a.propTypes = {
|
|
@@ -264,16 +263,26 @@ function useMemoStateContext(props) {
|
|
|
264
263
|
});
|
|
265
264
|
}, [props.config, props.itemsStateAndParams, onChange]);
|
|
266
265
|
const memorizeOriginalLayout = react_1.default.useCallback((widgetId, preAutoHeightLayout, postAutoHeightLayout) => {
|
|
266
|
+
let needUpdateLayout = false;
|
|
267
267
|
if (!(widgetId in originalLayouts.current)) {
|
|
268
268
|
originalLayouts.current[widgetId] = preAutoHeightLayout;
|
|
269
|
+
needUpdateLayout = true;
|
|
270
|
+
}
|
|
271
|
+
if (adjustedLayouts.current[widgetId] !== postAutoHeightLayout) {
|
|
272
|
+
adjustedLayouts.current[widgetId] = postAutoHeightLayout;
|
|
273
|
+
needUpdateLayout = true;
|
|
274
|
+
}
|
|
275
|
+
if (needUpdateLayout) {
|
|
276
|
+
forceUpdateLayout((prev) => prev + 1);
|
|
269
277
|
}
|
|
270
|
-
adjustedLayouts.current[widgetId] = postAutoHeightLayout;
|
|
271
|
-
forceUpdateLayout((prev) => prev + 1);
|
|
272
278
|
}, []);
|
|
273
279
|
const revertToOriginalLayout = react_1.default.useCallback((widgetId) => {
|
|
280
|
+
const needUpdateLayout = widgetId in adjustedLayouts.current || widgetId in originalLayouts.current;
|
|
274
281
|
delete adjustedLayouts.current[widgetId];
|
|
275
282
|
delete originalLayouts.current[widgetId];
|
|
276
|
-
|
|
283
|
+
if (needUpdateLayout) {
|
|
284
|
+
forceUpdateLayout((prev) => prev + 1);
|
|
285
|
+
}
|
|
277
286
|
}, []);
|
|
278
287
|
const itemsParams = react_1.default.useMemo(() => (0, shared_1.getItemsParams)({
|
|
279
288
|
defaultGlobalParams: props.defaultGlobalParams,
|
|
@@ -322,7 +331,6 @@ function useMemoStateContext(props) {
|
|
|
322
331
|
getLayout,
|
|
323
332
|
config: props.config,
|
|
324
333
|
context: props.context,
|
|
325
|
-
overlayControls: props.overlayControls,
|
|
326
334
|
noOverlay: props.noOverlay,
|
|
327
335
|
defaultGlobalParams: props.globalParams,
|
|
328
336
|
globalParams: props.globalParams,
|
|
@@ -345,7 +353,6 @@ function useMemoStateContext(props) {
|
|
|
345
353
|
getLayout,
|
|
346
354
|
props.config,
|
|
347
355
|
props.context,
|
|
348
|
-
props.overlayControls,
|
|
349
356
|
props.noOverlay,
|
|
350
357
|
props.globalParams,
|
|
351
358
|
props.editMode,
|
|
@@ -369,7 +376,7 @@ function withMemoContext(Component) {
|
|
|
369
376
|
const WithMemoContext = (props) => {
|
|
370
377
|
const contextValue = useMemoStateContext(props);
|
|
371
378
|
return (react_1.default.createElement(DashKitContext_1.DashKitContext.Provider, { value: contextValue },
|
|
372
|
-
react_1.default.createElement(Component,
|
|
379
|
+
react_1.default.createElement(Component, { overlayControls: props.overlayControls })));
|
|
373
380
|
};
|
|
374
381
|
WithMemoContext.displayName = `withMemoContext(${Component.displayName || Component.name || 'Component'}`;
|
|
375
382
|
return WithMemoContext;
|
|
@@ -7,10 +7,10 @@ import { withContext, withMemoContext } from '../../hocs/withContext';
|
|
|
7
7
|
import { useCalcPropsLayout } from '../../hooks/useCalcLayout';
|
|
8
8
|
import './DashKitView.css';
|
|
9
9
|
const b = block('dashkit');
|
|
10
|
-
function DashKitView() {
|
|
10
|
+
function DashKitView(props) {
|
|
11
11
|
const context = React.useContext(DashKitContext);
|
|
12
12
|
const { registerManager, forwardedMetaRef } = context;
|
|
13
|
-
return (React.createElement("div", { className: b({ theme: registerManager.settings.theme }) }, registerManager.settings.isMobile ? (React.createElement(MobileLayout, null)) : (React.createElement(GridLayout, { ref: forwardedMetaRef }))));
|
|
13
|
+
return (React.createElement("div", { className: b({ theme: registerManager.settings.theme }) }, registerManager.settings.isMobile ? (React.createElement(MobileLayout, null)) : (React.createElement(GridLayout, { ref: forwardedMetaRef, overlayControls: props.overlayControls }))));
|
|
14
14
|
}
|
|
15
15
|
const DashKitViewWithContext = withContext(DashKitView);
|
|
16
16
|
const DashKitViewWithMemoContext = withMemoContext(DashKitView);
|
|
@@ -8,7 +8,8 @@ import OverlayControls from '../OverlayControls/OverlayControls';
|
|
|
8
8
|
const b = block('dashkit-grid-item');
|
|
9
9
|
class GridItem extends React.PureComponent {
|
|
10
10
|
renderOverlay() {
|
|
11
|
-
const {
|
|
11
|
+
const { overlayControls } = this.props;
|
|
12
|
+
const { editMode } = this.context;
|
|
12
13
|
if (!editMode || this.props.item.data._editActive) {
|
|
13
14
|
return null;
|
|
14
15
|
}
|
|
@@ -16,7 +17,7 @@ class GridItem extends React.PureComponent {
|
|
|
16
17
|
const controls = overlayControls && overlayControls[item.type];
|
|
17
18
|
return (React.createElement(React.Fragment, null,
|
|
18
19
|
React.createElement("div", { className: b('overlay') }),
|
|
19
|
-
React.createElement(OverlayControls, { configItem: item, items: controls })));
|
|
20
|
+
React.createElement(OverlayControls, { configItem: item, items: controls, overlayControls: overlayControls })));
|
|
20
21
|
}
|
|
21
22
|
render() {
|
|
22
23
|
// из-за бага, что Grid Items unmounts при изменении static, isDraggable, isResaizable
|
|
@@ -50,6 +51,7 @@ GridItem.propTypes = {
|
|
|
50
51
|
item: PropTypes.object,
|
|
51
52
|
isDragging: PropTypes.bool,
|
|
52
53
|
layout: PropTypes.array,
|
|
54
|
+
overlayControls: PropTypes.object,
|
|
53
55
|
forwardedPluginRef: PropTypes.any,
|
|
54
56
|
// from react-grid-layout:
|
|
55
57
|
children: PropTypes.node,
|
|
@@ -78,7 +78,7 @@ export default class GridLayout extends React.PureComponent {
|
|
|
78
78
|
: null)), config.items.map((item, i) => {
|
|
79
79
|
return (React.createElement(GridItem, { ref: (pluginRef) => {
|
|
80
80
|
this.pluginsRefs[i] = pluginRef;
|
|
81
|
-
}, key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName) }));
|
|
81
|
+
}, key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
|
|
82
82
|
})));
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -34,6 +34,7 @@ interface OverlayControlsDefaultProps {
|
|
|
34
34
|
interface OverlayControlsProps extends OverlayControlsDefaultProps {
|
|
35
35
|
configItem: ConfigItem;
|
|
36
36
|
items?: OverlayControlItem[];
|
|
37
|
+
overlayControls?: Record<string, OverlayControlItem[]>;
|
|
37
38
|
}
|
|
38
39
|
declare class OverlayControls extends React.Component<OverlayControlsProps> {
|
|
39
40
|
static contextType: React.Context<any>;
|
|
@@ -32,7 +32,7 @@ class OverlayControls extends React.Component {
|
|
|
32
32
|
// выбираем только items-ы у которых проставлено поле `allWidgetsControls:true`
|
|
33
33
|
// те контролы, которые будут показываться слева от меню
|
|
34
34
|
let controls = [];
|
|
35
|
-
for (const controlItem of Object.values(this.
|
|
35
|
+
for (const controlItem of Object.values(this.props.overlayControls || {})) {
|
|
36
36
|
controls = controls.concat((controlItem.filter((item) => {
|
|
37
37
|
var _a;
|
|
38
38
|
// если тип виджета-плагина в списке исключаемых, то не показываем такой контрол
|
|
@@ -26,7 +26,6 @@ export function withContext(Component: any): {
|
|
|
26
26
|
getLayout: () => any;
|
|
27
27
|
config: any;
|
|
28
28
|
context: any;
|
|
29
|
-
overlayControls: any;
|
|
30
29
|
noOverlay: any;
|
|
31
30
|
defaultGlobalParams: any;
|
|
32
31
|
globalParams: any;
|
|
@@ -98,7 +97,6 @@ export function withContext(Component: any): {
|
|
|
98
97
|
getLayout: () => any;
|
|
99
98
|
config: any;
|
|
100
99
|
context: any;
|
|
101
|
-
overlayControls: any;
|
|
102
100
|
noOverlay: any;
|
|
103
101
|
defaultGlobalParams: any;
|
|
104
102
|
globalParams: any;
|
|
@@ -150,7 +150,6 @@ export function withContext(Component) {
|
|
|
150
150
|
getLayout: this._getLayout,
|
|
151
151
|
config: this.props.config,
|
|
152
152
|
context: this.props.context,
|
|
153
|
-
overlayControls: this.props.overlayControls,
|
|
154
153
|
noOverlay: this.props.noOverlay,
|
|
155
154
|
defaultGlobalParams: this.props.globalParams,
|
|
156
155
|
globalParams: this.props.globalParams,
|
|
@@ -173,7 +172,7 @@ export function withContext(Component) {
|
|
|
173
172
|
}
|
|
174
173
|
render() {
|
|
175
174
|
return (React.createElement(DashKitContext.Provider, { value: this._contextValue },
|
|
176
|
-
React.createElement(Component,
|
|
175
|
+
React.createElement(Component, { overlayControls: this.props.overlayControls })));
|
|
177
176
|
}
|
|
178
177
|
},
|
|
179
178
|
_a.propTypes = {
|
|
@@ -259,16 +258,26 @@ function useMemoStateContext(props) {
|
|
|
259
258
|
});
|
|
260
259
|
}, [props.config, props.itemsStateAndParams, onChange]);
|
|
261
260
|
const memorizeOriginalLayout = React.useCallback((widgetId, preAutoHeightLayout, postAutoHeightLayout) => {
|
|
261
|
+
let needUpdateLayout = false;
|
|
262
262
|
if (!(widgetId in originalLayouts.current)) {
|
|
263
263
|
originalLayouts.current[widgetId] = preAutoHeightLayout;
|
|
264
|
+
needUpdateLayout = true;
|
|
265
|
+
}
|
|
266
|
+
if (adjustedLayouts.current[widgetId] !== postAutoHeightLayout) {
|
|
267
|
+
adjustedLayouts.current[widgetId] = postAutoHeightLayout;
|
|
268
|
+
needUpdateLayout = true;
|
|
269
|
+
}
|
|
270
|
+
if (needUpdateLayout) {
|
|
271
|
+
forceUpdateLayout((prev) => prev + 1);
|
|
264
272
|
}
|
|
265
|
-
adjustedLayouts.current[widgetId] = postAutoHeightLayout;
|
|
266
|
-
forceUpdateLayout((prev) => prev + 1);
|
|
267
273
|
}, []);
|
|
268
274
|
const revertToOriginalLayout = React.useCallback((widgetId) => {
|
|
275
|
+
const needUpdateLayout = widgetId in adjustedLayouts.current || widgetId in originalLayouts.current;
|
|
269
276
|
delete adjustedLayouts.current[widgetId];
|
|
270
277
|
delete originalLayouts.current[widgetId];
|
|
271
|
-
|
|
278
|
+
if (needUpdateLayout) {
|
|
279
|
+
forceUpdateLayout((prev) => prev + 1);
|
|
280
|
+
}
|
|
272
281
|
}, []);
|
|
273
282
|
const itemsParams = React.useMemo(() => getItemsParams({
|
|
274
283
|
defaultGlobalParams: props.defaultGlobalParams,
|
|
@@ -317,7 +326,6 @@ function useMemoStateContext(props) {
|
|
|
317
326
|
getLayout,
|
|
318
327
|
config: props.config,
|
|
319
328
|
context: props.context,
|
|
320
|
-
overlayControls: props.overlayControls,
|
|
321
329
|
noOverlay: props.noOverlay,
|
|
322
330
|
defaultGlobalParams: props.globalParams,
|
|
323
331
|
globalParams: props.globalParams,
|
|
@@ -340,7 +348,6 @@ function useMemoStateContext(props) {
|
|
|
340
348
|
getLayout,
|
|
341
349
|
props.config,
|
|
342
350
|
props.context,
|
|
343
|
-
props.overlayControls,
|
|
344
351
|
props.noOverlay,
|
|
345
352
|
props.globalParams,
|
|
346
353
|
props.editMode,
|
|
@@ -364,7 +371,7 @@ export function withMemoContext(Component) {
|
|
|
364
371
|
const WithMemoContext = (props) => {
|
|
365
372
|
const contextValue = useMemoStateContext(props);
|
|
366
373
|
return (React.createElement(DashKitContext.Provider, { value: contextValue },
|
|
367
|
-
React.createElement(Component,
|
|
374
|
+
React.createElement(Component, { overlayControls: props.overlayControls })));
|
|
368
375
|
};
|
|
369
376
|
WithMemoContext.displayName = `withMemoContext(${Component.displayName || Component.name || 'Component'}`;
|
|
370
377
|
return WithMemoContext;
|