@gravity-ui/dashkit 8.8.1 → 8.9.1-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/DashKit/DashKit.d.ts +5 -0
- package/build/cjs/components/GridItem/GridItem.css +1 -0
- package/build/cjs/components/GridItem/GridItem.js +30 -2
- package/build/cjs/components/GridLayout/GridLayout.d.ts +8 -2
- package/build/cjs/components/GridLayout/GridLayout.js +113 -25
- package/build/cjs/components/GridLayout/ReactGridLayout.js +142 -24
- package/build/cjs/components/Item/Item.d.ts +2 -0
- package/build/cjs/components/Item/Item.js +13 -2
- package/build/cjs/hocs/prepareItem.d.ts +2 -0
- package/build/cjs/hocs/prepareItem.js +6 -3
- package/build/cjs/hocs/withContext.js +28 -6
- package/build/cjs/plugins/Text/Text.d.ts +1 -0
- package/build/cjs/plugins/Text/Text.js +2 -0
- package/build/cjs/typings/plugin.d.ts +1 -0
- package/build/esm/components/DashKit/DashKit.d.ts +5 -0
- package/build/esm/components/GridItem/GridItem.css +1 -0
- package/build/esm/components/GridItem/GridItem.js +30 -2
- package/build/esm/components/GridLayout/GridLayout.d.ts +8 -2
- package/build/esm/components/GridLayout/GridLayout.js +113 -25
- package/build/esm/components/GridLayout/ReactGridLayout.js +143 -25
- package/build/esm/components/Item/Item.d.ts +2 -0
- package/build/esm/components/Item/Item.js +13 -2
- package/build/esm/hocs/prepareItem.d.ts +2 -0
- package/build/esm/hocs/prepareItem.js +6 -3
- package/build/esm/hocs/withContext.js +28 -6
- package/build/esm/plugins/Text/Text.d.ts +1 -0
- package/build/esm/plugins/Text/Text.js +2 -0
- package/build/esm/typings/plugin.d.ts +1 -0
- package/package.json +1 -1
|
@@ -5,9 +5,18 @@ 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, onMountChange, }) => {
|
|
9
9
|
var _a, _b;
|
|
10
|
-
|
|
10
|
+
const isRegisteredType = registerManager.check(type);
|
|
11
|
+
React.useLayoutEffect(() => {
|
|
12
|
+
if (isRegisteredType && !isPlaceholder) {
|
|
13
|
+
onMountChange === null || onMountChange === void 0 ? void 0 : onMountChange(true);
|
|
14
|
+
return () => {
|
|
15
|
+
onMountChange === null || onMountChange === void 0 ? void 0 : onMountChange(false);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}, []);
|
|
19
|
+
if (!isRegisteredType) {
|
|
11
20
|
console.warn(`type [${type}] не зарегистрирован`);
|
|
12
21
|
return null;
|
|
13
22
|
}
|
|
@@ -23,5 +32,7 @@ Item.propTypes = {
|
|
|
23
32
|
registerManager: PropTypes.object,
|
|
24
33
|
type: PropTypes.string,
|
|
25
34
|
isPlaceholder: PropTypes.bool,
|
|
35
|
+
onMountChange: PropTypes.func,
|
|
36
|
+
onBeforeLoad: PropTypes.func,
|
|
26
37
|
};
|
|
27
38
|
export default prepareItem(Item);
|
|
@@ -61,7 +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
|
+
onBeforeLoad: PropTypes.Requireable<(...args: any[]) => any>;
|
|
64
65
|
forwardedPluginRef: PropTypes.Requireable<any>;
|
|
66
|
+
onMountChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
65
67
|
};
|
|
66
68
|
contextType: React.Context<any>;
|
|
67
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 } = this.props;
|
|
14
|
+
const { id, width, height, item, adjustWidgetLayout, layout, isPlaceholder, onBeforeLoad, } = 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,6 +20,7 @@ export function prepareItem(Component) {
|
|
|
20
20
|
params: itemsParams[id],
|
|
21
21
|
state: itemsState[id],
|
|
22
22
|
onStateAndParamsChange: this._onStateAndParamsChange,
|
|
23
|
+
onBeforeLoad,
|
|
23
24
|
width,
|
|
24
25
|
height,
|
|
25
26
|
id,
|
|
@@ -51,10 +52,10 @@ export function prepareItem(Component) {
|
|
|
51
52
|
return true;
|
|
52
53
|
}
|
|
53
54
|
render() {
|
|
54
|
-
const { item, isPlaceholder } = this.props;
|
|
55
|
+
const { item, isPlaceholder, forwardedPluginRef, onMountChange } = this.props;
|
|
55
56
|
const { registerManager } = this.context;
|
|
56
57
|
const { type } = item;
|
|
57
|
-
return (React.createElement(Component, { forwardedPluginRef:
|
|
58
|
+
return (React.createElement(Component, { forwardedPluginRef: forwardedPluginRef, rendererProps: this.getRenderProps(), registerManager: registerManager, type: type, isPlaceholder: isPlaceholder, onMountChange: onMountChange }));
|
|
58
59
|
}
|
|
59
60
|
},
|
|
60
61
|
_a.propTypes = {
|
|
@@ -67,7 +68,9 @@ export function prepareItem(Component) {
|
|
|
67
68
|
height: PropTypes.number,
|
|
68
69
|
transform: PropTypes.string,
|
|
69
70
|
isPlaceholder: PropTypes.bool,
|
|
71
|
+
onBeforeLoad: PropTypes.func,
|
|
70
72
|
forwardedPluginRef: PropTypes.any,
|
|
73
|
+
onMountChange: PropTypes.func,
|
|
71
74
|
},
|
|
72
75
|
_a.contextType = DashKitContext,
|
|
73
76
|
_a;
|
|
@@ -29,7 +29,7 @@ function useMemoStateContext(props) {
|
|
|
29
29
|
isEqual(groups, props.groups))) {
|
|
30
30
|
props.onChange({ config, itemsStateAndParams, groups });
|
|
31
31
|
}
|
|
32
|
-
}, [props.config, props.itemsStateAndParams, props.onChange]);
|
|
32
|
+
}, [props.config, props.groups, props.itemsStateAndParams, props.onChange]);
|
|
33
33
|
// каллбэк вызывающийся при изменение лэйаута сетки, первым аргументом приходит актуальный конфиг лэйаута,
|
|
34
34
|
// т.е. если на текущей сетке есть виджеты, с активированной опцией автовысоты, их параметр "h" будет
|
|
35
35
|
// "подстроенный"; чтобы, для сохранения в сторе "ушли" значения без учёта подстройки (как если бы у этих
|
|
@@ -37,7 +37,17 @@ function useMemoStateContext(props) {
|
|
|
37
37
|
const onLayoutChange = React.useCallback((layout) => {
|
|
38
38
|
const currentInnerLayout = layout.map((item) => {
|
|
39
39
|
if (item.i in originalLayouts.current) {
|
|
40
|
-
|
|
40
|
+
// eslint-disable-next-line no-unused-vars
|
|
41
|
+
const _a = originalLayouts.current[item.i], { parent } = _a, originalCopy = __rest(_a, ["parent"]);
|
|
42
|
+
// Updating original if parent has changed and saving copy as original
|
|
43
|
+
// or leaving default
|
|
44
|
+
if (item.parent) {
|
|
45
|
+
originalCopy.parent = item.parent;
|
|
46
|
+
}
|
|
47
|
+
originalCopy.w = item.w;
|
|
48
|
+
originalCopy.x = item.x;
|
|
49
|
+
originalCopy.y = item.y;
|
|
50
|
+
return originalCopy;
|
|
41
51
|
}
|
|
42
52
|
else {
|
|
43
53
|
return Object.assign({}, item);
|
|
@@ -234,16 +244,24 @@ function useMemoStateContext(props) {
|
|
|
234
244
|
return null;
|
|
235
245
|
}
|
|
236
246
|
}, [dragProps, props.registerManager]);
|
|
237
|
-
const onDropDragOver = React.useCallback((_e, gridProps, groupLayout) => {
|
|
247
|
+
const onDropDragOver = React.useCallback((_e, gridProps, groupLayout, sharedItem) => {
|
|
238
248
|
if (temporaryLayout) {
|
|
239
249
|
resetTemporaryLayout();
|
|
240
250
|
return false;
|
|
241
251
|
}
|
|
242
|
-
|
|
252
|
+
let defaultLayout;
|
|
253
|
+
if (sharedItem) {
|
|
254
|
+
const { type, h, w } = sharedItem;
|
|
255
|
+
const _defaults = props.registerManager.getItem(type);
|
|
256
|
+
defaultLayout = _defaults ? Object.assign(Object.assign({}, _defaults.defaultLayout), { h, w }) : { h, w };
|
|
257
|
+
}
|
|
258
|
+
else if (dragOverPlugin) {
|
|
259
|
+
defaultLayout = dragOverPlugin.defaultLayout;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
243
262
|
return false;
|
|
244
263
|
}
|
|
245
264
|
let maxW = gridProps.cols;
|
|
246
|
-
const { defaultLayout } = dragOverPlugin;
|
|
247
265
|
const maxH = Math.min(gridProps.maxRows || Infinity, defaultLayout.maxH || Infinity);
|
|
248
266
|
if (gridProps.compactType === COMPACT_TYPE_HORIZONTAL_NOWRAP) {
|
|
249
267
|
maxW = groupLayout.reduce((memo, item) => memo - item.w, gridProps.cols);
|
|
@@ -254,7 +272,7 @@ function useMemoStateContext(props) {
|
|
|
254
272
|
maxH < defaultLayout.minH) {
|
|
255
273
|
return false;
|
|
256
274
|
}
|
|
257
|
-
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 || {};
|
|
275
|
+
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 === null || dragProps === void 0 ? void 0 : dragProps.layout) || {};
|
|
258
276
|
return {
|
|
259
277
|
h: maxH ? Math.min(h, maxH) : h,
|
|
260
278
|
w: maxW ? Math.min(w, maxW) : w,
|
|
@@ -299,6 +317,8 @@ function useMemoStateContext(props) {
|
|
|
299
317
|
onItemStateAndParamsChange,
|
|
300
318
|
onDrop,
|
|
301
319
|
onDropDragOver,
|
|
320
|
+
onItemMountChange: props.onItemMountChange,
|
|
321
|
+
onItemRender: props.onItemRender,
|
|
302
322
|
layoutChange: onLayoutChange,
|
|
303
323
|
getItemsMeta,
|
|
304
324
|
reloadItems,
|
|
@@ -326,6 +346,8 @@ function useMemoStateContext(props) {
|
|
|
326
346
|
onDrop,
|
|
327
347
|
onDropDragOver,
|
|
328
348
|
onLayoutChange,
|
|
349
|
+
props.onItemMountChange,
|
|
350
|
+
props.onItemRender,
|
|
329
351
|
getItemsMeta,
|
|
330
352
|
reloadItems,
|
|
331
353
|
memorizeOriginalLayout,
|
|
@@ -77,6 +77,7 @@ export class PluginText extends React.PureComponent {
|
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
this.setState({ status: LoadStatus.Pending });
|
|
80
|
+
const onLoadComplete = this.props.onBeforeLoad();
|
|
80
81
|
try {
|
|
81
82
|
let htmlText = '';
|
|
82
83
|
if (this.state.text && this.state.text.trim()) {
|
|
@@ -97,6 +98,7 @@ export class PluginText extends React.PureComponent {
|
|
|
97
98
|
}
|
|
98
99
|
this.setState({ status: LoadStatus.Fail });
|
|
99
100
|
}
|
|
101
|
+
onLoadComplete();
|
|
100
102
|
}
|
|
101
103
|
get withMarkdown() {
|
|
102
104
|
return typeof this.props.apiHandler === 'function';
|
|
@@ -8,6 +8,7 @@ export interface PluginWidgetProps<T = StringParams> {
|
|
|
8
8
|
params: T;
|
|
9
9
|
state: ItemState;
|
|
10
10
|
onStateAndParamsChange: (stateAndParams: ItemStateAndParams, options?: ItemStateAndParamsChangeOptions) => void;
|
|
11
|
+
onBeforeLoad: () => () => void;
|
|
11
12
|
width: number;
|
|
12
13
|
height: number;
|
|
13
14
|
data: ConfigItem['data'];
|