@gravity-ui/dashkit 8.17.2 → 8.17.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/GridItem/GridItem.js +3 -28
- package/build/cjs/components/Item/Item.d.ts +2 -2
- package/build/cjs/components/Item/Item.js +38 -7
- package/build/cjs/components/MobileLayout/MobileLayout.d.ts +0 -5
- package/build/cjs/components/MobileLayout/MobileLayout.js +1 -28
- package/build/cjs/hocs/prepareItem.d.ts +2 -2
- package/build/cjs/hocs/prepareItem.js +5 -6
- package/build/esm/components/GridItem/GridItem.js +3 -28
- package/build/esm/components/Item/Item.d.ts +2 -2
- package/build/esm/components/Item/Item.js +38 -7
- package/build/esm/components/MobileLayout/MobileLayout.d.ts +0 -5
- package/build/esm/components/MobileLayout/MobileLayout.js +1 -28
- package/build/esm/hocs/prepareItem.d.ts +2 -2
- package/build/esm/hocs/prepareItem.js +5 -6
- package/package.json +1 -1
|
@@ -81,33 +81,6 @@ class GridItem extends react_1.default.PureComponent {
|
|
|
81
81
|
this.controller = null;
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
|
-
this.onMountChange = (isMounted) => {
|
|
85
|
-
var _a, _b, _c, _d, _e, _f;
|
|
86
|
-
if (isMounted) {
|
|
87
|
-
this._inited = true;
|
|
88
|
-
(_b = (_a = this.props).onItemMountChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item, {
|
|
89
|
-
isAsync: this._isAsyncItem,
|
|
90
|
-
isMounted: isMounted,
|
|
91
|
-
});
|
|
92
|
-
if (!this._isAsyncItem) {
|
|
93
|
-
(_d = (_c = this.props).onItemRender) === null || _d === void 0 ? void 0 : _d.call(_c, this.props.item);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
(_f = (_e = this.props).onItemMountChange) === null || _f === void 0 ? void 0 : _f.call(_e, this.props.item, {
|
|
98
|
-
isAsync: this._isAsyncItem,
|
|
99
|
-
isMounted: isMounted,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
this.onBeforeLoad = () => {
|
|
104
|
-
this._isAsyncItem = true;
|
|
105
|
-
return this.onLoad;
|
|
106
|
-
};
|
|
107
|
-
this.onLoad = () => {
|
|
108
|
-
var _a, _b;
|
|
109
|
-
(_b = (_a = this.props).onItemRender) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item);
|
|
110
|
-
};
|
|
111
84
|
}
|
|
112
85
|
renderOverlay() {
|
|
113
86
|
const { isPlaceholder } = this.props;
|
|
@@ -152,7 +125,7 @@ class GridItem extends react_1.default.PureComponent {
|
|
|
152
125
|
}
|
|
153
126
|
: {})),
|
|
154
127
|
react_1.default.createElement("div", { className: b('item', { editMode: editMode && !_editActive && !noOverlay }) },
|
|
155
|
-
react_1.default.createElement(Item_1.default, { id: this.props.id, item: this.props.item, shouldItemUpdate: !isDragging, width: width, height: height, transform: transform, isPlaceholder: isPlaceholder, adjustWidgetLayout: this.props.adjustWidgetLayout, layout: this.props.layout, forwardedPluginRef: this.props.forwardedPluginRef,
|
|
128
|
+
react_1.default.createElement(Item_1.default, { id: this.props.id, item: this.props.item, shouldItemUpdate: !isDragging, width: width, height: height, transform: transform, isPlaceholder: isPlaceholder, adjustWidgetLayout: this.props.adjustWidgetLayout, layout: this.props.layout, forwardedPluginRef: this.props.forwardedPluginRef, onItemMountChange: this.props.onItemMountChange, onItemRender: this.props.onItemRender })),
|
|
156
129
|
!noOverlay && this.renderOverlay(),
|
|
157
130
|
preparedChildren));
|
|
158
131
|
}
|
|
@@ -166,6 +139,8 @@ GridItem.propTypes = {
|
|
|
166
139
|
forwardedRef: prop_types_1.default.any,
|
|
167
140
|
forwardedPluginRef: prop_types_1.default.any,
|
|
168
141
|
isPlaceholder: prop_types_1.default.bool,
|
|
142
|
+
onItemMountChange: prop_types_1.default.func,
|
|
143
|
+
onItemRender: prop_types_1.default.func,
|
|
169
144
|
// from react-grid-layout:
|
|
170
145
|
children: prop_types_1.default.node,
|
|
171
146
|
className: prop_types_1.default.string,
|
|
@@ -61,9 +61,9 @@ declare const _default: {
|
|
|
61
61
|
height: PropTypes.Requireable<number>;
|
|
62
62
|
transform: PropTypes.Requireable<string>;
|
|
63
63
|
isPlaceholder: PropTypes.Requireable<boolean>;
|
|
64
|
-
|
|
64
|
+
onItemRender: PropTypes.Requireable<(...args: any[]) => any>;
|
|
65
|
+
onItemMountChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
65
66
|
forwardedPluginRef: PropTypes.Requireable<any>;
|
|
66
|
-
onMountChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
67
67
|
};
|
|
68
68
|
contextType: React.Context<any>;
|
|
69
69
|
};
|
|
@@ -7,26 +7,56 @@ const prepareItem_1 = require("../../hocs/prepareItem");
|
|
|
7
7
|
const cn_1 = require("../../utils/cn");
|
|
8
8
|
const b = (0, cn_1.cn)('dashkit-item');
|
|
9
9
|
// TODO: getDerivedStateFromError и заглушка с ошибкой
|
|
10
|
-
const Item = ({ registerManager, rendererProps, type, isPlaceholder, forwardedPluginRef,
|
|
10
|
+
const Item = ({ registerManager, rendererProps, type, isPlaceholder, forwardedPluginRef, onItemRender, onItemMountChange, item, }) => {
|
|
11
11
|
var _a, _b;
|
|
12
|
+
// to avoid too frequent re-creation of functions that do not affect the rendering
|
|
13
|
+
const isAsyncItemRef = react_1.default.useRef(false);
|
|
14
|
+
const itemRef = react_1.default.useRef(item);
|
|
15
|
+
const onItemRenderRef = react_1.default.useRef(onItemRender);
|
|
16
|
+
const onItemMountChangeRef = react_1.default.useRef(onItemMountChange);
|
|
17
|
+
itemRef.current = item;
|
|
18
|
+
onItemRenderRef.current = onItemRender;
|
|
19
|
+
onItemMountChangeRef.current = onItemMountChange;
|
|
12
20
|
const isRegisteredType = registerManager.check(type);
|
|
13
21
|
react_1.default.useLayoutEffect(() => {
|
|
22
|
+
var _a, _b;
|
|
14
23
|
if (isRegisteredType && !isPlaceholder) {
|
|
15
|
-
|
|
24
|
+
(_a = onItemMountChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onItemMountChangeRef, itemRef.current, {
|
|
25
|
+
isAsync: isAsyncItemRef.current,
|
|
26
|
+
isMounted: true,
|
|
27
|
+
});
|
|
28
|
+
if (!isAsyncItemRef.current) {
|
|
29
|
+
(_b = onItemRenderRef.current) === null || _b === void 0 ? void 0 : _b.call(onItemRenderRef, itemRef.current);
|
|
30
|
+
}
|
|
16
31
|
return () => {
|
|
17
|
-
|
|
32
|
+
var _a;
|
|
33
|
+
(_a = onItemMountChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onItemMountChangeRef, itemRef.current, {
|
|
34
|
+
isAsync: isAsyncItemRef.current,
|
|
35
|
+
isMounted: false,
|
|
36
|
+
});
|
|
18
37
|
};
|
|
19
38
|
}
|
|
20
39
|
}, []);
|
|
40
|
+
const onLoad = react_1.default.useCallback(() => {
|
|
41
|
+
var _a;
|
|
42
|
+
(_a = onItemRenderRef.current) === null || _a === void 0 ? void 0 : _a.call(onItemRenderRef, itemRef.current);
|
|
43
|
+
}, []);
|
|
44
|
+
const onBeforeLoad = react_1.default.useCallback(() => {
|
|
45
|
+
isAsyncItemRef.current = true;
|
|
46
|
+
return onLoad;
|
|
47
|
+
}, [onLoad]);
|
|
48
|
+
const itemRendererProps = react_1.default.useMemo(() => {
|
|
49
|
+
return Object.assign(Object.assign({}, rendererProps), { onBeforeLoad });
|
|
50
|
+
}, [rendererProps, onBeforeLoad]);
|
|
21
51
|
if (!isRegisteredType) {
|
|
22
52
|
console.warn(`type [${type}] не зарегистрирован`);
|
|
23
53
|
return null;
|
|
24
54
|
}
|
|
25
55
|
if (isPlaceholder) {
|
|
26
56
|
return (react_1.default.createElement("div", { className: b('placeholder') }, ((_b = (_a = registerManager
|
|
27
|
-
.getItem(type)).placeholderRenderer) === null || _b === void 0 ? void 0 : _b.call(_a,
|
|
57
|
+
.getItem(type)).placeholderRenderer) === null || _b === void 0 ? void 0 : _b.call(_a, itemRendererProps, forwardedPluginRef)) || null));
|
|
28
58
|
}
|
|
29
|
-
return (react_1.default.createElement("div", { className: b('renderer') }, registerManager.getItem(type).renderer(
|
|
59
|
+
return (react_1.default.createElement("div", { className: b('renderer') }, registerManager.getItem(type).renderer(itemRendererProps, forwardedPluginRef)));
|
|
30
60
|
};
|
|
31
61
|
Item.propTypes = {
|
|
32
62
|
forwardedPluginRef: prop_types_1.default.any,
|
|
@@ -34,7 +64,8 @@ Item.propTypes = {
|
|
|
34
64
|
registerManager: prop_types_1.default.object,
|
|
35
65
|
type: prop_types_1.default.string,
|
|
36
66
|
isPlaceholder: prop_types_1.default.bool,
|
|
37
|
-
|
|
38
|
-
|
|
67
|
+
onItemRender: prop_types_1.default.func,
|
|
68
|
+
onItemMountChange: prop_types_1.default.func,
|
|
69
|
+
item: prop_types_1.default.object,
|
|
39
70
|
};
|
|
40
71
|
exports.default = (0, prepareItem_1.prepareItem)(Item);
|
|
@@ -18,11 +18,6 @@ export default class MobileLayout extends React.PureComponent<any, any, any> {
|
|
|
18
18
|
needSetDefault: any;
|
|
19
19
|
}) => void;
|
|
20
20
|
getMemoAdjustWidgetLayout: (index: any) => any;
|
|
21
|
-
onMountChange: (isMounted: any) => void;
|
|
22
|
-
_inited: boolean | undefined;
|
|
23
|
-
onBeforeLoad: () => () => void;
|
|
24
|
-
_isAsyncItem: boolean | undefined;
|
|
25
|
-
onLoad: () => void;
|
|
26
21
|
render(): JSX.Element;
|
|
27
22
|
}
|
|
28
23
|
import React from 'react';
|
|
@@ -44,33 +44,6 @@ class MobileLayout extends react_1.default.PureComponent {
|
|
|
44
44
|
}
|
|
45
45
|
return this._memoAdjustWidgetLayout[index];
|
|
46
46
|
};
|
|
47
|
-
this.onMountChange = (isMounted) => {
|
|
48
|
-
var _a, _b, _c, _d, _e, _f;
|
|
49
|
-
if (isMounted) {
|
|
50
|
-
this._inited = true;
|
|
51
|
-
(_b = (_a = this.context).onItemMountChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item, {
|
|
52
|
-
isAsync: this._isAsyncItem,
|
|
53
|
-
isMounted: isMounted,
|
|
54
|
-
});
|
|
55
|
-
if (!this._isAsyncItem) {
|
|
56
|
-
(_d = (_c = this.context).onItemRender) === null || _d === void 0 ? void 0 : _d.call(_c, this.props.item);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
(_f = (_e = this.context).onItemMountChange) === null || _f === void 0 ? void 0 : _f.call(_e, this.props.item, {
|
|
61
|
-
isAsync: this._isAsyncItem,
|
|
62
|
-
isMounted: isMounted,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
this.onBeforeLoad = () => {
|
|
67
|
-
this._isAsyncItem = true;
|
|
68
|
-
return this.onLoad;
|
|
69
|
-
};
|
|
70
|
-
this.onLoad = () => {
|
|
71
|
-
var _a, _b;
|
|
72
|
-
(_b = (_a = this.context).onItemRender) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item);
|
|
73
|
-
};
|
|
74
47
|
}
|
|
75
48
|
componentDidUpdate(prevProps, prevState) {
|
|
76
49
|
if (prevState.activeTabId !== this.context.config.id) {
|
|
@@ -96,7 +69,7 @@ class MobileLayout extends react_1.default.PureComponent {
|
|
|
96
69
|
return (react_1.default.createElement("div", { className: b() }, sortedItems.map((item, index) => {
|
|
97
70
|
const isItemWithActiveAutoheight = index in this.state.indexesOfItemsWithActiveAutoheight;
|
|
98
71
|
return (react_1.default.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
|
|
99
|
-
react_1.default.createElement(Item_1.default, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.getMemoAdjustWidgetLayout(index), forwardedPluginRef: this.getMemoForwardRefCallback(index), onMountChange: this.onMountChange,
|
|
72
|
+
react_1.default.createElement(Item_1.default, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.getMemoAdjustWidgetLayout(index), forwardedPluginRef: this.getMemoForwardRefCallback(index), onMountChange: this.onMountChange, onItemMountChange: this.context.onItemMountChange, onItemRender: this.context.onItemRender })));
|
|
100
73
|
})));
|
|
101
74
|
}
|
|
102
75
|
}
|
|
@@ -61,9 +61,9 @@ export function prepareItem(Component: any): {
|
|
|
61
61
|
height: PropTypes.Requireable<number>;
|
|
62
62
|
transform: PropTypes.Requireable<string>;
|
|
63
63
|
isPlaceholder: PropTypes.Requireable<boolean>;
|
|
64
|
-
|
|
64
|
+
onItemRender: PropTypes.Requireable<(...args: any[]) => any>;
|
|
65
|
+
onItemMountChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
65
66
|
forwardedPluginRef: PropTypes.Requireable<any>;
|
|
66
|
-
onMountChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
67
67
|
};
|
|
68
68
|
contextType: React.Context<any>;
|
|
69
69
|
};
|
|
@@ -15,7 +15,7 @@ function prepareItem(Component) {
|
|
|
15
15
|
};
|
|
16
16
|
this._currentRenderProps = {};
|
|
17
17
|
this.getRenderProps = () => {
|
|
18
|
-
const { id, width, height, item, adjustWidgetLayout, layout, isPlaceholder
|
|
18
|
+
const { id, width, height, item, adjustWidgetLayout, layout, isPlaceholder } = this.props;
|
|
19
19
|
const { itemsState, itemsParams, registerManager, settings, context, editMode } = this.context;
|
|
20
20
|
const { data, defaults, namespace } = item;
|
|
21
21
|
const rendererProps = {
|
|
@@ -24,7 +24,6 @@ function prepareItem(Component) {
|
|
|
24
24
|
params: itemsParams[id],
|
|
25
25
|
state: itemsState[id],
|
|
26
26
|
onStateAndParamsChange: this._onStateAndParamsChange,
|
|
27
|
-
onBeforeLoad,
|
|
28
27
|
width,
|
|
29
28
|
height,
|
|
30
29
|
id,
|
|
@@ -56,10 +55,10 @@ function prepareItem(Component) {
|
|
|
56
55
|
return true;
|
|
57
56
|
}
|
|
58
57
|
render() {
|
|
59
|
-
const { item, isPlaceholder, forwardedPluginRef,
|
|
58
|
+
const { item, isPlaceholder, forwardedPluginRef, onItemMountChange, onItemRender } = this.props;
|
|
60
59
|
const { registerManager } = this.context;
|
|
61
60
|
const { type } = item;
|
|
62
|
-
return (react_1.default.createElement(Component, { forwardedPluginRef: forwardedPluginRef, rendererProps: this.getRenderProps(), registerManager: registerManager, type: type, isPlaceholder: isPlaceholder,
|
|
61
|
+
return (react_1.default.createElement(Component, { forwardedPluginRef: forwardedPluginRef, rendererProps: this.getRenderProps(), registerManager: registerManager, type: type, isPlaceholder: isPlaceholder, onItemMountChange: onItemMountChange, onItemRender: onItemRender, item: item }));
|
|
63
62
|
}
|
|
64
63
|
},
|
|
65
64
|
_a.propTypes = {
|
|
@@ -72,9 +71,9 @@ function prepareItem(Component) {
|
|
|
72
71
|
height: prop_types_1.default.number,
|
|
73
72
|
transform: prop_types_1.default.string,
|
|
74
73
|
isPlaceholder: prop_types_1.default.bool,
|
|
75
|
-
|
|
74
|
+
onItemRender: prop_types_1.default.func,
|
|
75
|
+
onItemMountChange: prop_types_1.default.func,
|
|
76
76
|
forwardedPluginRef: prop_types_1.default.any,
|
|
77
|
-
onMountChange: prop_types_1.default.func,
|
|
78
77
|
},
|
|
79
78
|
_a.contextType = DashKitContext_1.DashKitContext,
|
|
80
79
|
_a;
|
|
@@ -79,33 +79,6 @@ class GridItem extends React.PureComponent {
|
|
|
79
79
|
this.controller = null;
|
|
80
80
|
});
|
|
81
81
|
};
|
|
82
|
-
this.onMountChange = (isMounted) => {
|
|
83
|
-
var _a, _b, _c, _d, _e, _f;
|
|
84
|
-
if (isMounted) {
|
|
85
|
-
this._inited = true;
|
|
86
|
-
(_b = (_a = this.props).onItemMountChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item, {
|
|
87
|
-
isAsync: this._isAsyncItem,
|
|
88
|
-
isMounted: isMounted,
|
|
89
|
-
});
|
|
90
|
-
if (!this._isAsyncItem) {
|
|
91
|
-
(_d = (_c = this.props).onItemRender) === null || _d === void 0 ? void 0 : _d.call(_c, this.props.item);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
(_f = (_e = this.props).onItemMountChange) === null || _f === void 0 ? void 0 : _f.call(_e, this.props.item, {
|
|
96
|
-
isAsync: this._isAsyncItem,
|
|
97
|
-
isMounted: isMounted,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
this.onBeforeLoad = () => {
|
|
102
|
-
this._isAsyncItem = true;
|
|
103
|
-
return this.onLoad;
|
|
104
|
-
};
|
|
105
|
-
this.onLoad = () => {
|
|
106
|
-
var _a, _b;
|
|
107
|
-
(_b = (_a = this.props).onItemRender) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item);
|
|
108
|
-
};
|
|
109
82
|
}
|
|
110
83
|
renderOverlay() {
|
|
111
84
|
const { isPlaceholder } = this.props;
|
|
@@ -150,7 +123,7 @@ class GridItem extends React.PureComponent {
|
|
|
150
123
|
}
|
|
151
124
|
: {})),
|
|
152
125
|
React.createElement("div", { className: b('item', { editMode: editMode && !_editActive && !noOverlay }) },
|
|
153
|
-
React.createElement(Item, { id: this.props.id, item: this.props.item, shouldItemUpdate: !isDragging, width: width, height: height, transform: transform, isPlaceholder: isPlaceholder, adjustWidgetLayout: this.props.adjustWidgetLayout, layout: this.props.layout, forwardedPluginRef: this.props.forwardedPluginRef,
|
|
126
|
+
React.createElement(Item, { id: this.props.id, item: this.props.item, shouldItemUpdate: !isDragging, width: width, height: height, transform: transform, isPlaceholder: isPlaceholder, adjustWidgetLayout: this.props.adjustWidgetLayout, layout: this.props.layout, forwardedPluginRef: this.props.forwardedPluginRef, onItemMountChange: this.props.onItemMountChange, onItemRender: this.props.onItemRender })),
|
|
154
127
|
!noOverlay && this.renderOverlay(),
|
|
155
128
|
preparedChildren));
|
|
156
129
|
}
|
|
@@ -164,6 +137,8 @@ GridItem.propTypes = {
|
|
|
164
137
|
forwardedRef: PropTypes.any,
|
|
165
138
|
forwardedPluginRef: PropTypes.any,
|
|
166
139
|
isPlaceholder: PropTypes.bool,
|
|
140
|
+
onItemMountChange: PropTypes.func,
|
|
141
|
+
onItemRender: PropTypes.func,
|
|
167
142
|
// from react-grid-layout:
|
|
168
143
|
children: PropTypes.node,
|
|
169
144
|
className: PropTypes.string,
|
|
@@ -61,9 +61,9 @@ declare const _default: {
|
|
|
61
61
|
height: PropTypes.Requireable<number>;
|
|
62
62
|
transform: PropTypes.Requireable<string>;
|
|
63
63
|
isPlaceholder: PropTypes.Requireable<boolean>;
|
|
64
|
-
|
|
64
|
+
onItemRender: PropTypes.Requireable<(...args: any[]) => any>;
|
|
65
|
+
onItemMountChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
65
66
|
forwardedPluginRef: PropTypes.Requireable<any>;
|
|
66
|
-
onMountChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
67
67
|
};
|
|
68
68
|
contextType: React.Context<any>;
|
|
69
69
|
};
|
|
@@ -5,26 +5,56 @@ import { cn } from '../../utils/cn';
|
|
|
5
5
|
import './Item.css';
|
|
6
6
|
const b = cn('dashkit-item');
|
|
7
7
|
// TODO: getDerivedStateFromError и заглушка с ошибкой
|
|
8
|
-
const Item = ({ registerManager, rendererProps, type, isPlaceholder, forwardedPluginRef,
|
|
8
|
+
const Item = ({ registerManager, rendererProps, type, isPlaceholder, forwardedPluginRef, onItemRender, onItemMountChange, item, }) => {
|
|
9
9
|
var _a, _b;
|
|
10
|
+
// to avoid too frequent re-creation of functions that do not affect the rendering
|
|
11
|
+
const isAsyncItemRef = React.useRef(false);
|
|
12
|
+
const itemRef = React.useRef(item);
|
|
13
|
+
const onItemRenderRef = React.useRef(onItemRender);
|
|
14
|
+
const onItemMountChangeRef = React.useRef(onItemMountChange);
|
|
15
|
+
itemRef.current = item;
|
|
16
|
+
onItemRenderRef.current = onItemRender;
|
|
17
|
+
onItemMountChangeRef.current = onItemMountChange;
|
|
10
18
|
const isRegisteredType = registerManager.check(type);
|
|
11
19
|
React.useLayoutEffect(() => {
|
|
20
|
+
var _a, _b;
|
|
12
21
|
if (isRegisteredType && !isPlaceholder) {
|
|
13
|
-
|
|
22
|
+
(_a = onItemMountChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onItemMountChangeRef, itemRef.current, {
|
|
23
|
+
isAsync: isAsyncItemRef.current,
|
|
24
|
+
isMounted: true,
|
|
25
|
+
});
|
|
26
|
+
if (!isAsyncItemRef.current) {
|
|
27
|
+
(_b = onItemRenderRef.current) === null || _b === void 0 ? void 0 : _b.call(onItemRenderRef, itemRef.current);
|
|
28
|
+
}
|
|
14
29
|
return () => {
|
|
15
|
-
|
|
30
|
+
var _a;
|
|
31
|
+
(_a = onItemMountChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onItemMountChangeRef, itemRef.current, {
|
|
32
|
+
isAsync: isAsyncItemRef.current,
|
|
33
|
+
isMounted: false,
|
|
34
|
+
});
|
|
16
35
|
};
|
|
17
36
|
}
|
|
18
37
|
}, []);
|
|
38
|
+
const onLoad = React.useCallback(() => {
|
|
39
|
+
var _a;
|
|
40
|
+
(_a = onItemRenderRef.current) === null || _a === void 0 ? void 0 : _a.call(onItemRenderRef, itemRef.current);
|
|
41
|
+
}, []);
|
|
42
|
+
const onBeforeLoad = React.useCallback(() => {
|
|
43
|
+
isAsyncItemRef.current = true;
|
|
44
|
+
return onLoad;
|
|
45
|
+
}, [onLoad]);
|
|
46
|
+
const itemRendererProps = React.useMemo(() => {
|
|
47
|
+
return Object.assign(Object.assign({}, rendererProps), { onBeforeLoad });
|
|
48
|
+
}, [rendererProps, onBeforeLoad]);
|
|
19
49
|
if (!isRegisteredType) {
|
|
20
50
|
console.warn(`type [${type}] не зарегистрирован`);
|
|
21
51
|
return null;
|
|
22
52
|
}
|
|
23
53
|
if (isPlaceholder) {
|
|
24
54
|
return (React.createElement("div", { className: b('placeholder') }, ((_b = (_a = registerManager
|
|
25
|
-
.getItem(type)).placeholderRenderer) === null || _b === void 0 ? void 0 : _b.call(_a,
|
|
55
|
+
.getItem(type)).placeholderRenderer) === null || _b === void 0 ? void 0 : _b.call(_a, itemRendererProps, forwardedPluginRef)) || null));
|
|
26
56
|
}
|
|
27
|
-
return (React.createElement("div", { className: b('renderer') }, registerManager.getItem(type).renderer(
|
|
57
|
+
return (React.createElement("div", { className: b('renderer') }, registerManager.getItem(type).renderer(itemRendererProps, forwardedPluginRef)));
|
|
28
58
|
};
|
|
29
59
|
Item.propTypes = {
|
|
30
60
|
forwardedPluginRef: PropTypes.any,
|
|
@@ -32,7 +62,8 @@ Item.propTypes = {
|
|
|
32
62
|
registerManager: PropTypes.object,
|
|
33
63
|
type: PropTypes.string,
|
|
34
64
|
isPlaceholder: PropTypes.bool,
|
|
35
|
-
|
|
36
|
-
|
|
65
|
+
onItemRender: PropTypes.func,
|
|
66
|
+
onItemMountChange: PropTypes.func,
|
|
67
|
+
item: PropTypes.object,
|
|
37
68
|
};
|
|
38
69
|
export default prepareItem(Item);
|
|
@@ -18,11 +18,6 @@ export default class MobileLayout extends React.PureComponent<any, any, any> {
|
|
|
18
18
|
needSetDefault: any;
|
|
19
19
|
}) => void;
|
|
20
20
|
getMemoAdjustWidgetLayout: (index: any) => any;
|
|
21
|
-
onMountChange: (isMounted: any) => void;
|
|
22
|
-
_inited: boolean | undefined;
|
|
23
|
-
onBeforeLoad: () => () => void;
|
|
24
|
-
_isAsyncItem: boolean | undefined;
|
|
25
|
-
onLoad: () => void;
|
|
26
21
|
render(): JSX.Element;
|
|
27
22
|
}
|
|
28
23
|
import React from 'react';
|
|
@@ -42,33 +42,6 @@ class MobileLayout extends React.PureComponent {
|
|
|
42
42
|
}
|
|
43
43
|
return this._memoAdjustWidgetLayout[index];
|
|
44
44
|
};
|
|
45
|
-
this.onMountChange = (isMounted) => {
|
|
46
|
-
var _a, _b, _c, _d, _e, _f;
|
|
47
|
-
if (isMounted) {
|
|
48
|
-
this._inited = true;
|
|
49
|
-
(_b = (_a = this.context).onItemMountChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item, {
|
|
50
|
-
isAsync: this._isAsyncItem,
|
|
51
|
-
isMounted: isMounted,
|
|
52
|
-
});
|
|
53
|
-
if (!this._isAsyncItem) {
|
|
54
|
-
(_d = (_c = this.context).onItemRender) === null || _d === void 0 ? void 0 : _d.call(_c, this.props.item);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
(_f = (_e = this.context).onItemMountChange) === null || _f === void 0 ? void 0 : _f.call(_e, this.props.item, {
|
|
59
|
-
isAsync: this._isAsyncItem,
|
|
60
|
-
isMounted: isMounted,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
this.onBeforeLoad = () => {
|
|
65
|
-
this._isAsyncItem = true;
|
|
66
|
-
return this.onLoad;
|
|
67
|
-
};
|
|
68
|
-
this.onLoad = () => {
|
|
69
|
-
var _a, _b;
|
|
70
|
-
(_b = (_a = this.context).onItemRender) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item);
|
|
71
|
-
};
|
|
72
45
|
}
|
|
73
46
|
componentDidUpdate(prevProps, prevState) {
|
|
74
47
|
if (prevState.activeTabId !== this.context.config.id) {
|
|
@@ -94,7 +67,7 @@ class MobileLayout extends React.PureComponent {
|
|
|
94
67
|
return (React.createElement("div", { className: b() }, sortedItems.map((item, index) => {
|
|
95
68
|
const isItemWithActiveAutoheight = index in this.state.indexesOfItemsWithActiveAutoheight;
|
|
96
69
|
return (React.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
|
|
97
|
-
React.createElement(Item, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.getMemoAdjustWidgetLayout(index), forwardedPluginRef: this.getMemoForwardRefCallback(index), onMountChange: this.onMountChange,
|
|
70
|
+
React.createElement(Item, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.getMemoAdjustWidgetLayout(index), forwardedPluginRef: this.getMemoForwardRefCallback(index), onMountChange: this.onMountChange, onItemMountChange: this.context.onItemMountChange, onItemRender: this.context.onItemRender })));
|
|
98
71
|
})));
|
|
99
72
|
}
|
|
100
73
|
}
|
|
@@ -61,9 +61,9 @@ export function prepareItem(Component: any): {
|
|
|
61
61
|
height: PropTypes.Requireable<number>;
|
|
62
62
|
transform: PropTypes.Requireable<string>;
|
|
63
63
|
isPlaceholder: PropTypes.Requireable<boolean>;
|
|
64
|
-
|
|
64
|
+
onItemRender: PropTypes.Requireable<(...args: any[]) => any>;
|
|
65
|
+
onItemMountChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
65
66
|
forwardedPluginRef: PropTypes.Requireable<any>;
|
|
66
|
-
onMountChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
67
67
|
};
|
|
68
68
|
contextType: React.Context<any>;
|
|
69
69
|
};
|
|
@@ -11,7 +11,7 @@ export function prepareItem(Component) {
|
|
|
11
11
|
};
|
|
12
12
|
this._currentRenderProps = {};
|
|
13
13
|
this.getRenderProps = () => {
|
|
14
|
-
const { id, width, height, item, adjustWidgetLayout, layout, isPlaceholder
|
|
14
|
+
const { id, width, height, item, adjustWidgetLayout, layout, isPlaceholder } = this.props;
|
|
15
15
|
const { itemsState, itemsParams, registerManager, settings, context, editMode } = this.context;
|
|
16
16
|
const { data, defaults, namespace } = item;
|
|
17
17
|
const rendererProps = {
|
|
@@ -20,7 +20,6 @@ export function prepareItem(Component) {
|
|
|
20
20
|
params: itemsParams[id],
|
|
21
21
|
state: itemsState[id],
|
|
22
22
|
onStateAndParamsChange: this._onStateAndParamsChange,
|
|
23
|
-
onBeforeLoad,
|
|
24
23
|
width,
|
|
25
24
|
height,
|
|
26
25
|
id,
|
|
@@ -52,10 +51,10 @@ export function prepareItem(Component) {
|
|
|
52
51
|
return true;
|
|
53
52
|
}
|
|
54
53
|
render() {
|
|
55
|
-
const { item, isPlaceholder, forwardedPluginRef,
|
|
54
|
+
const { item, isPlaceholder, forwardedPluginRef, onItemMountChange, onItemRender } = this.props;
|
|
56
55
|
const { registerManager } = this.context;
|
|
57
56
|
const { type } = item;
|
|
58
|
-
return (React.createElement(Component, { forwardedPluginRef: forwardedPluginRef, rendererProps: this.getRenderProps(), registerManager: registerManager, type: type, isPlaceholder: isPlaceholder,
|
|
57
|
+
return (React.createElement(Component, { forwardedPluginRef: forwardedPluginRef, rendererProps: this.getRenderProps(), registerManager: registerManager, type: type, isPlaceholder: isPlaceholder, onItemMountChange: onItemMountChange, onItemRender: onItemRender, item: item }));
|
|
59
58
|
}
|
|
60
59
|
},
|
|
61
60
|
_a.propTypes = {
|
|
@@ -68,9 +67,9 @@ export function prepareItem(Component) {
|
|
|
68
67
|
height: PropTypes.number,
|
|
69
68
|
transform: PropTypes.string,
|
|
70
69
|
isPlaceholder: PropTypes.bool,
|
|
71
|
-
|
|
70
|
+
onItemRender: PropTypes.func,
|
|
71
|
+
onItemMountChange: PropTypes.func,
|
|
72
72
|
forwardedPluginRef: PropTypes.any,
|
|
73
|
-
onMountChange: PropTypes.func,
|
|
74
73
|
},
|
|
75
74
|
_a.contextType = DashKitContext,
|
|
76
75
|
_a;
|