@gravity-ui/dashkit 3.3.0 → 3.5.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/CHANGELOG.md +14 -0
- package/README.md +1 -2
- package/build/cjs/components/DashKit/DashKit.d.ts +0 -1
- package/build/cjs/components/DashKit/DashKit.js +0 -1
- package/build/cjs/components/DashKitView/DashKitView.js +1 -2
- package/build/cjs/components/GridLayout/GridLayout.js +2 -4
- package/build/cjs/components/MobileLayout/MobileLayout.js +2 -2
- package/build/cjs/hocs/withContext.d.ts +0 -163
- package/build/cjs/hocs/withContext.js +8 -202
- package/build/cjs/index.d.ts +1 -0
- package/build/cjs/index.js +1 -0
- package/build/cjs/plugins/Text/index.d.ts +1 -0
- package/build/cjs/plugins/Text/index.js +9 -0
- package/build/cjs/plugins/Title/index.d.ts +1 -0
- package/build/cjs/plugins/Title/index.js +9 -0
- package/build/cjs/plugins/index.d.ts +2 -0
- package/build/cjs/plugins/index.js +5 -0
- package/build/esm/components/DashKit/DashKit.d.ts +0 -1
- package/build/esm/components/DashKit/DashKit.js +0 -1
- package/build/esm/components/DashKitView/DashKitView.js +2 -3
- package/build/esm/components/GridLayout/GridLayout.js +2 -4
- package/build/esm/components/MobileLayout/MobileLayout.js +2 -2
- package/build/esm/hocs/withContext.d.ts +0 -163
- package/build/esm/hocs/withContext.js +6 -199
- package/build/esm/index.d.ts +1 -0
- package/build/esm/index.js +1 -0
- package/build/esm/plugins/Text/index.d.ts +1 -0
- package/build/esm/plugins/Text/index.js +1 -0
- package/build/esm/plugins/Title/index.d.ts +1 -0
- package/build/esm/plugins/Title/index.js +1 -0
- package/build/esm/plugins/index.d.ts +2 -0
- package/build/esm/plugins/index.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [3.5.0](https://github.com/gravity-ui/dashkit/compare/v3.4.0...v3.5.0) (2022-12-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* export plugins ([#29](https://github.com/gravity-ui/dashkit/issues/29)) ([d589546](https://github.com/gravity-ui/dashkit/commit/d5895469e9917f4c5f43aaf5802b5d8a865bd185))
|
|
9
|
+
|
|
10
|
+
## [3.4.0](https://github.com/gravity-ui/dashkit/compare/v3.3.0...v3.4.0) (2022-11-16)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* delete _EXPERIMENTAL_memoContext props ([#27](https://github.com/gravity-ui/dashkit/issues/27)) ([c9d6b64](https://github.com/gravity-ui/dashkit/commit/c9d6b644e0235fd6d08d24090bb959c1fe112936))
|
|
16
|
+
|
|
3
17
|
## [3.3.0](https://github.com/gravity-ui/dashkit/compare/v3.2.0...v3.3.0) (2022-11-10)
|
|
4
18
|
|
|
5
19
|
|
package/README.md
CHANGED
|
@@ -95,8 +95,7 @@ Before using `DashKit` as a react component, it must be configured.
|
|
|
95
95
|
|
|
96
96
|
```js
|
|
97
97
|
import {DashKit} from '@gravity-ui/dashkit';
|
|
98
|
-
import pluginTitle from '@gravity-ui/dashkit
|
|
99
|
-
import pluginText from '@gravity-ui/dashkit/build/esm/plugins/Text/Text';
|
|
98
|
+
import {pluginTitle, pluginText} from '@gravity-ui/dashkit';
|
|
100
99
|
|
|
101
100
|
DashKit.registerPlugins(
|
|
102
101
|
pluginTitle,
|
|
@@ -22,7 +22,6 @@ interface DashKitDefaultProps {
|
|
|
22
22
|
noOverlay?: boolean;
|
|
23
23
|
draggableHandleClassName?: string;
|
|
24
24
|
_EXPERIMENTAL_preventDoubleCompact?: boolean;
|
|
25
|
-
_EXPERIMENTAL_memoContext?: boolean;
|
|
26
25
|
}
|
|
27
26
|
export interface DashKitProps extends DashKitGeneralProps, Partial<DashKitDefaultProps> {
|
|
28
27
|
}
|
|
@@ -15,10 +15,9 @@ function DashKitView(props) {
|
|
|
15
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
|
-
const DashKitViewWithMemoContext = (0, withContext_1.withMemoContext)(DashKitView);
|
|
19
18
|
const DashKitViewForwardedMeta = react_1.default.forwardRef((props, ref) => {
|
|
20
19
|
const layout = (0, useCalcLayout_1.useCalcPropsLayout)(props.config, props.registerManager);
|
|
21
|
-
return
|
|
20
|
+
return react_1.default.createElement(DashKitViewWithContext, Object.assign({}, props, { layout: layout, forwardedMetaRef: ref }));
|
|
22
21
|
});
|
|
23
22
|
DashKitViewForwardedMeta.displayName = 'DashKitViewForwardedMeta';
|
|
24
23
|
exports.default = DashKitViewForwardedMeta;
|
|
@@ -15,7 +15,7 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
17
|
this.adjustWidgetLayout = ({ widgetId, needSetDefault, adjustedWidgetLayout }) => {
|
|
18
|
-
const {
|
|
18
|
+
const { layout, memorizeOriginalLayout, revertToOriginalLayout } = this.context;
|
|
19
19
|
if (needSetDefault) {
|
|
20
20
|
revertToOriginalLayout(widgetId);
|
|
21
21
|
return;
|
|
@@ -23,7 +23,6 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
23
23
|
if (!adjustedWidgetLayout) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const layout = getLayout();
|
|
27
26
|
const correspondedLayoutItemIndex = layout.findIndex((layoutItem) => layoutItem.i === widgetId);
|
|
28
27
|
memorizeOriginalLayout(widgetId, Object.assign({}, layout[correspondedLayoutItemIndex]), adjustedWidgetLayout);
|
|
29
28
|
};
|
|
@@ -72,9 +71,8 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
73
|
render() {
|
|
75
|
-
const {
|
|
74
|
+
const { layout, config, registerManager, editMode, noOverlay, draggableHandleClassName } = this.context;
|
|
76
75
|
this.pluginsRefs.length = config.items.length;
|
|
77
|
-
const layout = getLayout();
|
|
78
76
|
return (react_1.default.createElement(Layout, Object.assign({}, registerManager.gridLayout, { layout: layout, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: this._onStop, onResizeStart: this._onStart, onResizeStop: this._onStop }, (draggableHandleClassName
|
|
79
77
|
? { draggableHandle: `.${draggableHandleClassName}` }
|
|
80
78
|
: null)), config.items.map((item, i) => {
|
|
@@ -37,14 +37,14 @@ class MobileLayout extends react_1.default.PureComponent {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
render() {
|
|
40
|
-
const { config,
|
|
40
|
+
const { config, layout } = this.context;
|
|
41
41
|
this.pluginsRefs.length = config.items.length;
|
|
42
42
|
const hasOrderId = Boolean(config.items.find((item) => item.orderId));
|
|
43
43
|
const sortedItems = (0, helpers_1.getSortedConfigItems)(config, hasOrderId);
|
|
44
44
|
return (react_1.default.createElement("div", { className: b() }, sortedItems.map((item, index) => {
|
|
45
45
|
const isItemWithActiveAutoheight = index in this.state.indexesOfItemsWithActiveAutoheight;
|
|
46
46
|
return (react_1.default.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
|
|
47
|
-
react_1.default.createElement(Item_1.default, { id: item.id, item: item, layout:
|
|
47
|
+
react_1.default.createElement(Item_1.default, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.adjustWidgetLayout.bind(this, index), forwardedPluginRef: (pluginRef) => {
|
|
48
48
|
this.pluginsRefs[index] = pluginRef;
|
|
49
49
|
} })));
|
|
50
50
|
})));
|
|
@@ -1,167 +1,4 @@
|
|
|
1
1
|
export function withContext(Component: any): {
|
|
2
|
-
new (props: any): {
|
|
3
|
-
state: {
|
|
4
|
-
currentLayout: any;
|
|
5
|
-
};
|
|
6
|
-
originalLayouts: {};
|
|
7
|
-
adjustedLayouts: {};
|
|
8
|
-
_onChange({ config, itemsStateAndParams, }: {
|
|
9
|
-
config?: any;
|
|
10
|
-
itemsStateAndParams?: any;
|
|
11
|
-
}): void;
|
|
12
|
-
_onLayoutChange: (layout: any) => void;
|
|
13
|
-
_onItemRemove: (id: any) => void;
|
|
14
|
-
_onItemEdit: (configItem: any) => void;
|
|
15
|
-
_onItemStateAndParamsChange: (id: any, stateAndParams: any) => void;
|
|
16
|
-
_memorizeOriginalLayout: (widgetId: any, preAutoHeightLayout: any, postAutoHeightLayout: any) => void;
|
|
17
|
-
_revertToOriginalLayout: (widgetId: any) => void;
|
|
18
|
-
readonly _itemsParams: {
|
|
19
|
-
[x: string]: import("../shared").StringParams;
|
|
20
|
-
};
|
|
21
|
-
readonly _itemsState: Record<string, import("../shared").ItemState>;
|
|
22
|
-
_getItemsMeta: (pluginsRefs: any) => any;
|
|
23
|
-
_getLayout: () => any;
|
|
24
|
-
_reloadItems: (pluginsRefs: any, data: any) => void;
|
|
25
|
-
readonly _contextValue: {
|
|
26
|
-
getLayout: () => any;
|
|
27
|
-
config: any;
|
|
28
|
-
context: any;
|
|
29
|
-
noOverlay: any;
|
|
30
|
-
defaultGlobalParams: any;
|
|
31
|
-
globalParams: any;
|
|
32
|
-
editMode: any;
|
|
33
|
-
settings: any;
|
|
34
|
-
itemsState: Record<string, import("../shared").ItemState>;
|
|
35
|
-
itemsParams: {
|
|
36
|
-
[x: string]: import("../shared").StringParams;
|
|
37
|
-
};
|
|
38
|
-
registerManager: any;
|
|
39
|
-
onItemStateAndParamsChange: (id: any, stateAndParams: any) => void;
|
|
40
|
-
removeItem: (id: any) => void;
|
|
41
|
-
editItem: (configItem: any) => void;
|
|
42
|
-
layoutChange: (layout: any) => void;
|
|
43
|
-
getItemsMeta: (pluginsRefs: any) => any;
|
|
44
|
-
reloadItems: (pluginsRefs: any, data: any) => void;
|
|
45
|
-
memorizeOriginalLayout: (widgetId: any, preAutoHeightLayout: any, postAutoHeightLayout: any) => void;
|
|
46
|
-
revertToOriginalLayout: (widgetId: any) => void;
|
|
47
|
-
forwardedMetaRef: any;
|
|
48
|
-
draggableHandleClassName: any;
|
|
49
|
-
};
|
|
50
|
-
render(): JSX.Element;
|
|
51
|
-
context: any;
|
|
52
|
-
setState<K extends string | number | symbol>(state: any, callback?: (() => void) | undefined): void;
|
|
53
|
-
forceUpdate(callback?: (() => void) | undefined): void;
|
|
54
|
-
readonly props: Readonly<any> & Readonly<{
|
|
55
|
-
children?: React.ReactNode;
|
|
56
|
-
}>;
|
|
57
|
-
refs: {
|
|
58
|
-
[key: string]: React.ReactInstance;
|
|
59
|
-
};
|
|
60
|
-
componentDidMount?(): void;
|
|
61
|
-
shouldComponentUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): boolean;
|
|
62
|
-
componentWillUnmount?(): void;
|
|
63
|
-
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
64
|
-
getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>): any;
|
|
65
|
-
componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>, snapshot?: any): void;
|
|
66
|
-
componentWillMount?(): void;
|
|
67
|
-
UNSAFE_componentWillMount?(): void;
|
|
68
|
-
componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
69
|
-
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
70
|
-
componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
|
|
71
|
-
UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
|
|
72
|
-
};
|
|
73
|
-
new (props: any, context: any): {
|
|
74
|
-
state: {
|
|
75
|
-
currentLayout: any;
|
|
76
|
-
};
|
|
77
|
-
originalLayouts: {};
|
|
78
|
-
adjustedLayouts: {};
|
|
79
|
-
_onChange({ config, itemsStateAndParams, }: {
|
|
80
|
-
config?: any;
|
|
81
|
-
itemsStateAndParams?: any;
|
|
82
|
-
}): void;
|
|
83
|
-
_onLayoutChange: (layout: any) => void;
|
|
84
|
-
_onItemRemove: (id: any) => void;
|
|
85
|
-
_onItemEdit: (configItem: any) => void;
|
|
86
|
-
_onItemStateAndParamsChange: (id: any, stateAndParams: any) => void;
|
|
87
|
-
_memorizeOriginalLayout: (widgetId: any, preAutoHeightLayout: any, postAutoHeightLayout: any) => void;
|
|
88
|
-
_revertToOriginalLayout: (widgetId: any) => void;
|
|
89
|
-
readonly _itemsParams: {
|
|
90
|
-
[x: string]: import("../shared").StringParams;
|
|
91
|
-
};
|
|
92
|
-
readonly _itemsState: Record<string, import("../shared").ItemState>;
|
|
93
|
-
_getItemsMeta: (pluginsRefs: any) => any;
|
|
94
|
-
_getLayout: () => any;
|
|
95
|
-
_reloadItems: (pluginsRefs: any, data: any) => void;
|
|
96
|
-
readonly _contextValue: {
|
|
97
|
-
getLayout: () => any;
|
|
98
|
-
config: any;
|
|
99
|
-
context: any;
|
|
100
|
-
noOverlay: any;
|
|
101
|
-
defaultGlobalParams: any;
|
|
102
|
-
globalParams: any;
|
|
103
|
-
editMode: any;
|
|
104
|
-
settings: any;
|
|
105
|
-
itemsState: Record<string, import("../shared").ItemState>;
|
|
106
|
-
itemsParams: {
|
|
107
|
-
[x: string]: import("../shared").StringParams;
|
|
108
|
-
};
|
|
109
|
-
registerManager: any;
|
|
110
|
-
onItemStateAndParamsChange: (id: any, stateAndParams: any) => void;
|
|
111
|
-
removeItem: (id: any) => void;
|
|
112
|
-
editItem: (configItem: any) => void;
|
|
113
|
-
layoutChange: (layout: any) => void;
|
|
114
|
-
getItemsMeta: (pluginsRefs: any) => any;
|
|
115
|
-
reloadItems: (pluginsRefs: any, data: any) => void;
|
|
116
|
-
memorizeOriginalLayout: (widgetId: any, preAutoHeightLayout: any, postAutoHeightLayout: any) => void;
|
|
117
|
-
revertToOriginalLayout: (widgetId: any) => void;
|
|
118
|
-
forwardedMetaRef: any;
|
|
119
|
-
draggableHandleClassName: any;
|
|
120
|
-
};
|
|
121
|
-
render(): JSX.Element;
|
|
122
|
-
context: any;
|
|
123
|
-
setState<K extends string | number | symbol>(state: any, callback?: (() => void) | undefined): void;
|
|
124
|
-
forceUpdate(callback?: (() => void) | undefined): void;
|
|
125
|
-
readonly props: Readonly<any> & Readonly<{
|
|
126
|
-
children?: React.ReactNode;
|
|
127
|
-
}>;
|
|
128
|
-
refs: {
|
|
129
|
-
[key: string]: React.ReactInstance;
|
|
130
|
-
};
|
|
131
|
-
componentDidMount?(): void;
|
|
132
|
-
shouldComponentUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): boolean;
|
|
133
|
-
componentWillUnmount?(): void;
|
|
134
|
-
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
135
|
-
getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>): any;
|
|
136
|
-
componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>, snapshot?: any): void;
|
|
137
|
-
componentWillMount?(): void;
|
|
138
|
-
UNSAFE_componentWillMount?(): void;
|
|
139
|
-
componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
140
|
-
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
141
|
-
componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
|
|
142
|
-
UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
|
|
143
|
-
};
|
|
144
|
-
propTypes: {
|
|
145
|
-
editMode: PropTypes.Requireable<boolean>;
|
|
146
|
-
context: PropTypes.Requireable<object>;
|
|
147
|
-
overlayControls: PropTypes.Requireable<object>;
|
|
148
|
-
config: PropTypes.Requireable<object>;
|
|
149
|
-
onItemEdit: PropTypes.Requireable<(...args: any[]) => any>;
|
|
150
|
-
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
151
|
-
defaultGlobalParams: PropTypes.Requireable<object>;
|
|
152
|
-
globalParams: PropTypes.Requireable<object>;
|
|
153
|
-
itemsStateAndParams: PropTypes.Requireable<object>;
|
|
154
|
-
registerManager: PropTypes.Requireable<object>;
|
|
155
|
-
layout: PropTypes.Requireable<any[]>;
|
|
156
|
-
settings: PropTypes.Requireable<object>;
|
|
157
|
-
forwardedMetaRef: PropTypes.Requireable<object>;
|
|
158
|
-
noOverlay: PropTypes.Requireable<boolean>;
|
|
159
|
-
draggableHandleClassName: PropTypes.Requireable<string>;
|
|
160
|
-
_EXPERIMENTAL_preventDoubleCompact: PropTypes.Requireable<boolean>;
|
|
161
|
-
};
|
|
162
|
-
contextType?: React.Context<any> | undefined;
|
|
163
|
-
};
|
|
164
|
-
export function withMemoContext(Component: any): {
|
|
165
2
|
(props: any): JSX.Element;
|
|
166
3
|
displayName: string;
|
|
167
4
|
};
|
|
@@ -1,205 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.withContext = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const DashKitContext_1 = require("../context/DashKitContext");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const shared_1 = require("../shared");
|
|
9
|
-
const prop_types_1 = tslib_1.__importDefault(require("prop-types"));
|
|
10
9
|
const isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
|
|
11
10
|
const react_grid_layout_1 = require("react-grid-layout");
|
|
12
11
|
const LAYOUT_COMPACTING_TYPE = 'vertical';
|
|
13
|
-
function withContext(Component) {
|
|
14
|
-
var _a;
|
|
15
|
-
return _a = class DashKitWithContext extends react_1.default.Component {
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
// так как мы не хотим хранить параметры виджета с активированной автовысотой в сторе и на сервере, актуальный
|
|
19
|
-
// (видимый юзером в конкретный момент времени) лэйаут (массив объектов с данными о ширине, высоте,
|
|
20
|
-
// расположении конкретного виджета на сетке) будет храниться в стейте, но, для того, чтобы в стор попадал
|
|
21
|
-
// лэйаут без учета вижетов с активированной автовысотой, в момент "подстройки" высоты виджета значение h
|
|
22
|
-
// (высота) из конфига будет запоминаться в originalLayouts, новое значение высоты в adjustedLayouts
|
|
23
|
-
this.state = { currentLayout: this.props.layout };
|
|
24
|
-
this.originalLayouts = {};
|
|
25
|
-
this.adjustedLayouts = {};
|
|
26
|
-
// каллбэк вызывающийся при изменение лэйаута сетки, первым аргументом приходит актуальный конфиг лэйаута,
|
|
27
|
-
// т.е. если на текущей сетке есть виджеты, с активированной опцией автовысоты, их параметр "h" будет
|
|
28
|
-
// "подстроенный"; чтобы, для сохранения в сторе "ушли" значения без учёта подстройки (как если бы у этих
|
|
29
|
-
// виджетов автовысота была деактивирована) корректируем их используя this.originalLayouts
|
|
30
|
-
this._onLayoutChange = (layout) => {
|
|
31
|
-
const currentLayout = layout.map((item) => {
|
|
32
|
-
if (item.i in this.originalLayouts) {
|
|
33
|
-
return Object.assign(Object.assign({}, this.originalLayouts[item.i]), { w: item.w, x: item.x, y: item.y });
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return Object.assign({}, item);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
// [experimental] if the _prevent Double Compact is enabled, then skip recalculate layout with auto height
|
|
40
|
-
// после того, как у виждета активировали автовысоту и его параметр "h" изменился, это приведёт, также, и к
|
|
41
|
-
// изменению параметра (координаты) "y" у элементов расположенных под ним, поэтому, после того, как
|
|
42
|
-
// значения параметра "h" виджетов с активированной автовысотой были изменены, необходимо изменить и
|
|
43
|
-
// координату "y" виджетов расположенных ниже
|
|
44
|
-
const compactedLayout = this.props._EXPERIMENTAL_preventDoubleCompact
|
|
45
|
-
? currentLayout
|
|
46
|
-
: react_grid_layout_1.utils.compact(currentLayout, LAYOUT_COMPACTING_TYPE, this.props.registerManager.gridLayout.cols);
|
|
47
|
-
const newConfig = utils_1.UpdateManager.updateLayout({
|
|
48
|
-
layout: compactedLayout,
|
|
49
|
-
config: this.props.config,
|
|
50
|
-
});
|
|
51
|
-
if (!(0, isEqual_1.default)(newConfig.layout, this.props.config.layout)) {
|
|
52
|
-
this._onChange({
|
|
53
|
-
config: newConfig,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
this._onItemRemove = (id) => {
|
|
58
|
-
const { config, itemsStateAndParams } = this.props;
|
|
59
|
-
this._onChange(utils_1.UpdateManager.removeItem({ id, config, itemsStateAndParams }));
|
|
60
|
-
};
|
|
61
|
-
this._onItemEdit = (configItem) => {
|
|
62
|
-
this.props.onItemEdit(configItem);
|
|
63
|
-
};
|
|
64
|
-
this._onItemStateAndParamsChange = (id, stateAndParams) => {
|
|
65
|
-
const { config, itemsStateAndParams } = this.props;
|
|
66
|
-
this._onChange({
|
|
67
|
-
itemsStateAndParams: utils_1.UpdateManager.changeStateAndParams({
|
|
68
|
-
id,
|
|
69
|
-
config,
|
|
70
|
-
stateAndParams,
|
|
71
|
-
itemsStateAndParams,
|
|
72
|
-
}),
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
this._memorizeOriginalLayout = (widgetId, preAutoHeightLayout, postAutoHeightLayout) => {
|
|
76
|
-
if (!(widgetId in this.originalLayouts)) {
|
|
77
|
-
this.originalLayouts[widgetId] = preAutoHeightLayout;
|
|
78
|
-
}
|
|
79
|
-
this.adjustedLayouts[widgetId] = postAutoHeightLayout;
|
|
80
|
-
this.setState({
|
|
81
|
-
currentLayout: this.props.layout.map((item) => {
|
|
82
|
-
if (item.i in this.adjustedLayouts) {
|
|
83
|
-
return Object.assign(Object.assign({}, this.adjustedLayouts[item.i]), { w: item.w, x: item.x, y: item.y });
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
return Object.assign({}, item);
|
|
87
|
-
}
|
|
88
|
-
}),
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
this._revertToOriginalLayout = (widgetId) => {
|
|
92
|
-
this.setState({
|
|
93
|
-
currentLayout: this.state.currentLayout.map((item) => {
|
|
94
|
-
if (item.i === widgetId) {
|
|
95
|
-
return Object.assign(Object.assign({}, this.originalLayouts[item.i]), { w: item.w, x: item.x, y: item.y });
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
return Object.assign({}, item);
|
|
99
|
-
}
|
|
100
|
-
}),
|
|
101
|
-
});
|
|
102
|
-
delete this.adjustedLayouts[widgetId];
|
|
103
|
-
delete this.originalLayouts[widgetId];
|
|
104
|
-
};
|
|
105
|
-
this._getItemsMeta = (pluginsRefs) => {
|
|
106
|
-
return pluginsRefs
|
|
107
|
-
.map((ref) => {
|
|
108
|
-
if (!(ref && typeof ref.getMeta === 'function')) {
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
return ref.getMeta();
|
|
112
|
-
})
|
|
113
|
-
.filter(Boolean);
|
|
114
|
-
};
|
|
115
|
-
this._getLayout = () => {
|
|
116
|
-
return this.props.layout.map((item) => {
|
|
117
|
-
if (item.i in this.adjustedLayouts) {
|
|
118
|
-
return Object.assign(Object.assign({}, this.adjustedLayouts[item.i]), { w: item.w, x: item.x, y: item.y });
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
return Object.assign({}, item);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
this._reloadItems = (pluginsRefs, data) => {
|
|
126
|
-
pluginsRefs.forEach((ref) => ref && ref.reload && ref.reload(data));
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
_onChange({ config = this.props.config, itemsStateAndParams = this.props.itemsStateAndParams, }) {
|
|
130
|
-
if (!((0, isEqual_1.default)(config, this.props.config) &&
|
|
131
|
-
(0, isEqual_1.default)(itemsStateAndParams, this.props.itemsStateAndParams))) {
|
|
132
|
-
this.props.onChange({
|
|
133
|
-
config,
|
|
134
|
-
itemsStateAndParams,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
get _itemsParams() {
|
|
139
|
-
const { config, itemsStateAndParams, globalParams, defaultGlobalParams, registerManager, } = this.props;
|
|
140
|
-
return (0, shared_1.getItemsParams)({
|
|
141
|
-
defaultGlobalParams,
|
|
142
|
-
globalParams,
|
|
143
|
-
config,
|
|
144
|
-
itemsStateAndParams,
|
|
145
|
-
plugins: registerManager.getPlugins(),
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
get _itemsState() {
|
|
149
|
-
const { config, itemsStateAndParams } = this.props;
|
|
150
|
-
return (0, shared_1.getItemsState)({ config, itemsStateAndParams });
|
|
151
|
-
}
|
|
152
|
-
get _contextValue() {
|
|
153
|
-
return {
|
|
154
|
-
getLayout: this._getLayout,
|
|
155
|
-
config: this.props.config,
|
|
156
|
-
context: this.props.context,
|
|
157
|
-
noOverlay: this.props.noOverlay,
|
|
158
|
-
defaultGlobalParams: this.props.globalParams,
|
|
159
|
-
globalParams: this.props.globalParams,
|
|
160
|
-
editMode: this.props.editMode,
|
|
161
|
-
settings: this.props.settings,
|
|
162
|
-
itemsState: this._itemsState,
|
|
163
|
-
itemsParams: this._itemsParams,
|
|
164
|
-
registerManager: this.props.registerManager,
|
|
165
|
-
onItemStateAndParamsChange: this._onItemStateAndParamsChange,
|
|
166
|
-
removeItem: this._onItemRemove,
|
|
167
|
-
editItem: this._onItemEdit,
|
|
168
|
-
layoutChange: this._onLayoutChange,
|
|
169
|
-
getItemsMeta: this._getItemsMeta,
|
|
170
|
-
reloadItems: this._reloadItems,
|
|
171
|
-
memorizeOriginalLayout: this._memorizeOriginalLayout,
|
|
172
|
-
revertToOriginalLayout: this._revertToOriginalLayout,
|
|
173
|
-
forwardedMetaRef: this.props.forwardedMetaRef,
|
|
174
|
-
draggableHandleClassName: this.props.draggableHandleClassName,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
render() {
|
|
178
|
-
return (react_1.default.createElement(DashKitContext_1.DashKitContext.Provider, { value: this._contextValue },
|
|
179
|
-
react_1.default.createElement(Component, { overlayControls: this.props.overlayControls })));
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
_a.propTypes = {
|
|
183
|
-
editMode: prop_types_1.default.bool,
|
|
184
|
-
context: prop_types_1.default.object,
|
|
185
|
-
overlayControls: prop_types_1.default.object,
|
|
186
|
-
config: prop_types_1.default.object,
|
|
187
|
-
onItemEdit: prop_types_1.default.func,
|
|
188
|
-
onChange: prop_types_1.default.func,
|
|
189
|
-
defaultGlobalParams: prop_types_1.default.object,
|
|
190
|
-
globalParams: prop_types_1.default.object,
|
|
191
|
-
itemsStateAndParams: prop_types_1.default.object,
|
|
192
|
-
registerManager: prop_types_1.default.object,
|
|
193
|
-
layout: prop_types_1.default.array,
|
|
194
|
-
settings: prop_types_1.default.object,
|
|
195
|
-
forwardedMetaRef: prop_types_1.default.object,
|
|
196
|
-
noOverlay: prop_types_1.default.bool,
|
|
197
|
-
draggableHandleClassName: prop_types_1.default.string,
|
|
198
|
-
_EXPERIMENTAL_preventDoubleCompact: prop_types_1.default.bool,
|
|
199
|
-
},
|
|
200
|
-
_a;
|
|
201
|
-
}
|
|
202
|
-
exports.withContext = withContext;
|
|
203
12
|
function useMemoStateContext(props) {
|
|
204
13
|
// так как мы не хотим хранить параметры виджета с активированной автовысотой в сторе и на сервере, актуальный
|
|
205
14
|
// (видимый юзером в конкретный момент времени) лэйаут (массив объектов с данными о ширине, высоте,
|
|
@@ -321,14 +130,11 @@ function useMemoStateContext(props) {
|
|
|
321
130
|
}
|
|
322
131
|
});
|
|
323
132
|
}, [props.layout, layoutUpdateCounter]);
|
|
324
|
-
// TODO: don't use getLayout when finished experiment _EXPERIMENTAL_memoContext
|
|
325
|
-
// need use resultLayout like layout props
|
|
326
|
-
const getLayout = react_1.default.useCallback(() => resultLayout, [resultLayout]);
|
|
327
133
|
const reloadItems = react_1.default.useCallback((pluginsRefs, data) => {
|
|
328
134
|
pluginsRefs.forEach((ref) => ref && ref.reload && ref.reload(data));
|
|
329
135
|
}, []);
|
|
330
136
|
return react_1.default.useMemo(() => ({
|
|
331
|
-
|
|
137
|
+
layout: resultLayout,
|
|
332
138
|
config: props.config,
|
|
333
139
|
context: props.context,
|
|
334
140
|
noOverlay: props.noOverlay,
|
|
@@ -350,7 +156,7 @@ function useMemoStateContext(props) {
|
|
|
350
156
|
forwardedMetaRef: props.forwardedMetaRef,
|
|
351
157
|
draggableHandleClassName: props.draggableHandleClassName,
|
|
352
158
|
}), [
|
|
353
|
-
|
|
159
|
+
resultLayout,
|
|
354
160
|
props.config,
|
|
355
161
|
props.context,
|
|
356
162
|
props.noOverlay,
|
|
@@ -372,13 +178,13 @@ function useMemoStateContext(props) {
|
|
|
372
178
|
props.draggableHandleClassName,
|
|
373
179
|
]);
|
|
374
180
|
}
|
|
375
|
-
function
|
|
376
|
-
const
|
|
181
|
+
function withContext(Component) {
|
|
182
|
+
const WithContext = (props) => {
|
|
377
183
|
const contextValue = useMemoStateContext(props);
|
|
378
184
|
return (react_1.default.createElement(DashKitContext_1.DashKitContext.Provider, { value: contextValue },
|
|
379
185
|
react_1.default.createElement(Component, { overlayControls: props.overlayControls })));
|
|
380
186
|
};
|
|
381
|
-
|
|
382
|
-
return
|
|
187
|
+
WithContext.displayName = `withContext(${Component.displayName || Component.name || 'Component'}`;
|
|
188
|
+
return WithContext;
|
|
383
189
|
}
|
|
384
|
-
exports.
|
|
190
|
+
exports.withContext = withContext;
|
package/build/cjs/index.d.ts
CHANGED
package/build/cjs/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PluginTextApiHandler, PluginTextProps, PluginText, PluginObjectSettings as PluginTextObjectSettings, PluginObject as PluginTextObject, default as pluginText, } from './Text';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pluginText = exports.PluginText = void 0;
|
|
7
|
+
var Text_1 = require("./Text");
|
|
8
|
+
Object.defineProperty(exports, "PluginText", { enumerable: true, get: function () { return Text_1.PluginText; } });
|
|
9
|
+
Object.defineProperty(exports, "pluginText", { enumerable: true, get: function () { return __importDefault(Text_1).default; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PluginTitle, PluginTitleProps, default as pluginTitle } from './Title';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pluginTitle = exports.PluginTitle = void 0;
|
|
7
|
+
var Title_1 = require("./Title");
|
|
8
|
+
Object.defineProperty(exports, "PluginTitle", { enumerable: true, get: function () { return Title_1.PluginTitle; } });
|
|
9
|
+
Object.defineProperty(exports, "pluginTitle", { enumerable: true, get: function () { return __importDefault(Title_1).default; } });
|
|
@@ -22,7 +22,6 @@ interface DashKitDefaultProps {
|
|
|
22
22
|
noOverlay?: boolean;
|
|
23
23
|
draggableHandleClassName?: string;
|
|
24
24
|
_EXPERIMENTAL_preventDoubleCompact?: boolean;
|
|
25
|
-
_EXPERIMENTAL_memoContext?: boolean;
|
|
26
25
|
}
|
|
27
26
|
export interface DashKitProps extends DashKitGeneralProps, Partial<DashKitDefaultProps> {
|
|
28
27
|
}
|
|
@@ -3,7 +3,7 @@ import block from 'bem-cn-lite';
|
|
|
3
3
|
import { DashKitContext } from '../../context/DashKitContext';
|
|
4
4
|
import GridLayout from '../GridLayout/GridLayout';
|
|
5
5
|
import MobileLayout from '../MobileLayout/MobileLayout';
|
|
6
|
-
import { withContext
|
|
6
|
+
import { withContext } from '../../hocs/withContext';
|
|
7
7
|
import { useCalcPropsLayout } from '../../hooks/useCalcLayout';
|
|
8
8
|
import './DashKitView.css';
|
|
9
9
|
const b = block('dashkit');
|
|
@@ -13,10 +13,9 @@ function DashKitView(props) {
|
|
|
13
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
|
-
const DashKitViewWithMemoContext = withMemoContext(DashKitView);
|
|
17
16
|
const DashKitViewForwardedMeta = React.forwardRef((props, ref) => {
|
|
18
17
|
const layout = useCalcPropsLayout(props.config, props.registerManager);
|
|
19
|
-
return
|
|
18
|
+
return React.createElement(DashKitViewWithContext, Object.assign({}, props, { layout: layout, forwardedMetaRef: ref }));
|
|
20
19
|
});
|
|
21
20
|
DashKitViewForwardedMeta.displayName = 'DashKitViewForwardedMeta';
|
|
22
21
|
export default DashKitViewForwardedMeta;
|
|
@@ -12,7 +12,7 @@ export default class GridLayout extends React.PureComponent {
|
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
14
|
this.adjustWidgetLayout = ({ widgetId, needSetDefault, adjustedWidgetLayout }) => {
|
|
15
|
-
const {
|
|
15
|
+
const { layout, memorizeOriginalLayout, revertToOriginalLayout } = this.context;
|
|
16
16
|
if (needSetDefault) {
|
|
17
17
|
revertToOriginalLayout(widgetId);
|
|
18
18
|
return;
|
|
@@ -20,7 +20,6 @@ export default class GridLayout extends React.PureComponent {
|
|
|
20
20
|
if (!adjustedWidgetLayout) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
const layout = getLayout();
|
|
24
23
|
const correspondedLayoutItemIndex = layout.findIndex((layoutItem) => layoutItem.i === widgetId);
|
|
25
24
|
memorizeOriginalLayout(widgetId, Object.assign({}, layout[correspondedLayoutItemIndex]), adjustedWidgetLayout);
|
|
26
25
|
};
|
|
@@ -69,9 +68,8 @@ export default class GridLayout extends React.PureComponent {
|
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
render() {
|
|
72
|
-
const {
|
|
71
|
+
const { layout, config, registerManager, editMode, noOverlay, draggableHandleClassName } = this.context;
|
|
73
72
|
this.pluginsRefs.length = config.items.length;
|
|
74
|
-
const layout = getLayout();
|
|
75
73
|
return (React.createElement(Layout, Object.assign({}, registerManager.gridLayout, { layout: layout, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: this._onStop, onResizeStart: this._onStart, onResizeStop: this._onStop }, (draggableHandleClassName
|
|
76
74
|
? { draggableHandle: `.${draggableHandleClassName}` }
|
|
77
75
|
: null)), config.items.map((item, i) => {
|
|
@@ -35,14 +35,14 @@ export default class MobileLayout extends React.PureComponent {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
render() {
|
|
38
|
-
const { config,
|
|
38
|
+
const { config, layout } = this.context;
|
|
39
39
|
this.pluginsRefs.length = config.items.length;
|
|
40
40
|
const hasOrderId = Boolean(config.items.find((item) => item.orderId));
|
|
41
41
|
const sortedItems = getSortedConfigItems(config, hasOrderId);
|
|
42
42
|
return (React.createElement("div", { className: b() }, sortedItems.map((item, index) => {
|
|
43
43
|
const isItemWithActiveAutoheight = index in this.state.indexesOfItemsWithActiveAutoheight;
|
|
44
44
|
return (React.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
|
|
45
|
-
React.createElement(Item, { id: item.id, item: item, layout:
|
|
45
|
+
React.createElement(Item, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.adjustWidgetLayout.bind(this, index), forwardedPluginRef: (pluginRef) => {
|
|
46
46
|
this.pluginsRefs[index] = pluginRef;
|
|
47
47
|
} })));
|
|
48
48
|
})));
|
|
@@ -1,167 +1,4 @@
|
|
|
1
1
|
export function withContext(Component: any): {
|
|
2
|
-
new (props: any): {
|
|
3
|
-
state: {
|
|
4
|
-
currentLayout: any;
|
|
5
|
-
};
|
|
6
|
-
originalLayouts: {};
|
|
7
|
-
adjustedLayouts: {};
|
|
8
|
-
_onChange({ config, itemsStateAndParams, }: {
|
|
9
|
-
config?: any;
|
|
10
|
-
itemsStateAndParams?: any;
|
|
11
|
-
}): void;
|
|
12
|
-
_onLayoutChange: (layout: any) => void;
|
|
13
|
-
_onItemRemove: (id: any) => void;
|
|
14
|
-
_onItemEdit: (configItem: any) => void;
|
|
15
|
-
_onItemStateAndParamsChange: (id: any, stateAndParams: any) => void;
|
|
16
|
-
_memorizeOriginalLayout: (widgetId: any, preAutoHeightLayout: any, postAutoHeightLayout: any) => void;
|
|
17
|
-
_revertToOriginalLayout: (widgetId: any) => void;
|
|
18
|
-
readonly _itemsParams: {
|
|
19
|
-
[x: string]: import("../shared").StringParams;
|
|
20
|
-
};
|
|
21
|
-
readonly _itemsState: Record<string, import("../shared").ItemState>;
|
|
22
|
-
_getItemsMeta: (pluginsRefs: any) => any;
|
|
23
|
-
_getLayout: () => any;
|
|
24
|
-
_reloadItems: (pluginsRefs: any, data: any) => void;
|
|
25
|
-
readonly _contextValue: {
|
|
26
|
-
getLayout: () => any;
|
|
27
|
-
config: any;
|
|
28
|
-
context: any;
|
|
29
|
-
noOverlay: any;
|
|
30
|
-
defaultGlobalParams: any;
|
|
31
|
-
globalParams: any;
|
|
32
|
-
editMode: any;
|
|
33
|
-
settings: any;
|
|
34
|
-
itemsState: Record<string, import("../shared").ItemState>;
|
|
35
|
-
itemsParams: {
|
|
36
|
-
[x: string]: import("../shared").StringParams;
|
|
37
|
-
};
|
|
38
|
-
registerManager: any;
|
|
39
|
-
onItemStateAndParamsChange: (id: any, stateAndParams: any) => void;
|
|
40
|
-
removeItem: (id: any) => void;
|
|
41
|
-
editItem: (configItem: any) => void;
|
|
42
|
-
layoutChange: (layout: any) => void;
|
|
43
|
-
getItemsMeta: (pluginsRefs: any) => any;
|
|
44
|
-
reloadItems: (pluginsRefs: any, data: any) => void;
|
|
45
|
-
memorizeOriginalLayout: (widgetId: any, preAutoHeightLayout: any, postAutoHeightLayout: any) => void;
|
|
46
|
-
revertToOriginalLayout: (widgetId: any) => void;
|
|
47
|
-
forwardedMetaRef: any;
|
|
48
|
-
draggableHandleClassName: any;
|
|
49
|
-
};
|
|
50
|
-
render(): JSX.Element;
|
|
51
|
-
context: any;
|
|
52
|
-
setState<K extends string | number | symbol>(state: any, callback?: (() => void) | undefined): void;
|
|
53
|
-
forceUpdate(callback?: (() => void) | undefined): void;
|
|
54
|
-
readonly props: Readonly<any> & Readonly<{
|
|
55
|
-
children?: React.ReactNode;
|
|
56
|
-
}>;
|
|
57
|
-
refs: {
|
|
58
|
-
[key: string]: React.ReactInstance;
|
|
59
|
-
};
|
|
60
|
-
componentDidMount?(): void;
|
|
61
|
-
shouldComponentUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): boolean;
|
|
62
|
-
componentWillUnmount?(): void;
|
|
63
|
-
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
64
|
-
getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>): any;
|
|
65
|
-
componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>, snapshot?: any): void;
|
|
66
|
-
componentWillMount?(): void;
|
|
67
|
-
UNSAFE_componentWillMount?(): void;
|
|
68
|
-
componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
69
|
-
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
70
|
-
componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
|
|
71
|
-
UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
|
|
72
|
-
};
|
|
73
|
-
new (props: any, context: any): {
|
|
74
|
-
state: {
|
|
75
|
-
currentLayout: any;
|
|
76
|
-
};
|
|
77
|
-
originalLayouts: {};
|
|
78
|
-
adjustedLayouts: {};
|
|
79
|
-
_onChange({ config, itemsStateAndParams, }: {
|
|
80
|
-
config?: any;
|
|
81
|
-
itemsStateAndParams?: any;
|
|
82
|
-
}): void;
|
|
83
|
-
_onLayoutChange: (layout: any) => void;
|
|
84
|
-
_onItemRemove: (id: any) => void;
|
|
85
|
-
_onItemEdit: (configItem: any) => void;
|
|
86
|
-
_onItemStateAndParamsChange: (id: any, stateAndParams: any) => void;
|
|
87
|
-
_memorizeOriginalLayout: (widgetId: any, preAutoHeightLayout: any, postAutoHeightLayout: any) => void;
|
|
88
|
-
_revertToOriginalLayout: (widgetId: any) => void;
|
|
89
|
-
readonly _itemsParams: {
|
|
90
|
-
[x: string]: import("../shared").StringParams;
|
|
91
|
-
};
|
|
92
|
-
readonly _itemsState: Record<string, import("../shared").ItemState>;
|
|
93
|
-
_getItemsMeta: (pluginsRefs: any) => any;
|
|
94
|
-
_getLayout: () => any;
|
|
95
|
-
_reloadItems: (pluginsRefs: any, data: any) => void;
|
|
96
|
-
readonly _contextValue: {
|
|
97
|
-
getLayout: () => any;
|
|
98
|
-
config: any;
|
|
99
|
-
context: any;
|
|
100
|
-
noOverlay: any;
|
|
101
|
-
defaultGlobalParams: any;
|
|
102
|
-
globalParams: any;
|
|
103
|
-
editMode: any;
|
|
104
|
-
settings: any;
|
|
105
|
-
itemsState: Record<string, import("../shared").ItemState>;
|
|
106
|
-
itemsParams: {
|
|
107
|
-
[x: string]: import("../shared").StringParams;
|
|
108
|
-
};
|
|
109
|
-
registerManager: any;
|
|
110
|
-
onItemStateAndParamsChange: (id: any, stateAndParams: any) => void;
|
|
111
|
-
removeItem: (id: any) => void;
|
|
112
|
-
editItem: (configItem: any) => void;
|
|
113
|
-
layoutChange: (layout: any) => void;
|
|
114
|
-
getItemsMeta: (pluginsRefs: any) => any;
|
|
115
|
-
reloadItems: (pluginsRefs: any, data: any) => void;
|
|
116
|
-
memorizeOriginalLayout: (widgetId: any, preAutoHeightLayout: any, postAutoHeightLayout: any) => void;
|
|
117
|
-
revertToOriginalLayout: (widgetId: any) => void;
|
|
118
|
-
forwardedMetaRef: any;
|
|
119
|
-
draggableHandleClassName: any;
|
|
120
|
-
};
|
|
121
|
-
render(): JSX.Element;
|
|
122
|
-
context: any;
|
|
123
|
-
setState<K extends string | number | symbol>(state: any, callback?: (() => void) | undefined): void;
|
|
124
|
-
forceUpdate(callback?: (() => void) | undefined): void;
|
|
125
|
-
readonly props: Readonly<any> & Readonly<{
|
|
126
|
-
children?: React.ReactNode;
|
|
127
|
-
}>;
|
|
128
|
-
refs: {
|
|
129
|
-
[key: string]: React.ReactInstance;
|
|
130
|
-
};
|
|
131
|
-
componentDidMount?(): void;
|
|
132
|
-
shouldComponentUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): boolean;
|
|
133
|
-
componentWillUnmount?(): void;
|
|
134
|
-
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
135
|
-
getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>): any;
|
|
136
|
-
componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>, snapshot?: any): void;
|
|
137
|
-
componentWillMount?(): void;
|
|
138
|
-
UNSAFE_componentWillMount?(): void;
|
|
139
|
-
componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
140
|
-
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
141
|
-
componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
|
|
142
|
-
UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
|
|
143
|
-
};
|
|
144
|
-
propTypes: {
|
|
145
|
-
editMode: PropTypes.Requireable<boolean>;
|
|
146
|
-
context: PropTypes.Requireable<object>;
|
|
147
|
-
overlayControls: PropTypes.Requireable<object>;
|
|
148
|
-
config: PropTypes.Requireable<object>;
|
|
149
|
-
onItemEdit: PropTypes.Requireable<(...args: any[]) => any>;
|
|
150
|
-
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
151
|
-
defaultGlobalParams: PropTypes.Requireable<object>;
|
|
152
|
-
globalParams: PropTypes.Requireable<object>;
|
|
153
|
-
itemsStateAndParams: PropTypes.Requireable<object>;
|
|
154
|
-
registerManager: PropTypes.Requireable<object>;
|
|
155
|
-
layout: PropTypes.Requireable<any[]>;
|
|
156
|
-
settings: PropTypes.Requireable<object>;
|
|
157
|
-
forwardedMetaRef: PropTypes.Requireable<object>;
|
|
158
|
-
noOverlay: PropTypes.Requireable<boolean>;
|
|
159
|
-
draggableHandleClassName: PropTypes.Requireable<string>;
|
|
160
|
-
_EXPERIMENTAL_preventDoubleCompact: PropTypes.Requireable<boolean>;
|
|
161
|
-
};
|
|
162
|
-
contextType?: React.Context<any> | undefined;
|
|
163
|
-
};
|
|
164
|
-
export function withMemoContext(Component: any): {
|
|
165
2
|
(props: any): JSX.Element;
|
|
166
3
|
displayName: string;
|
|
167
4
|
};
|
|
@@ -2,199 +2,9 @@ import React from 'react';
|
|
|
2
2
|
import { DashKitContext } from '../context/DashKitContext';
|
|
3
3
|
import { UpdateManager } from '../utils';
|
|
4
4
|
import { getItemsParams, getItemsState } from '../shared';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
5
|
import isEqual from 'lodash/isEqual';
|
|
7
6
|
import { utils as gridLayoutUtils } from 'react-grid-layout';
|
|
8
7
|
const LAYOUT_COMPACTING_TYPE = 'vertical';
|
|
9
|
-
export function withContext(Component) {
|
|
10
|
-
var _a;
|
|
11
|
-
return _a = class DashKitWithContext extends React.Component {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(...arguments);
|
|
14
|
-
// так как мы не хотим хранить параметры виджета с активированной автовысотой в сторе и на сервере, актуальный
|
|
15
|
-
// (видимый юзером в конкретный момент времени) лэйаут (массив объектов с данными о ширине, высоте,
|
|
16
|
-
// расположении конкретного виджета на сетке) будет храниться в стейте, но, для того, чтобы в стор попадал
|
|
17
|
-
// лэйаут без учета вижетов с активированной автовысотой, в момент "подстройки" высоты виджета значение h
|
|
18
|
-
// (высота) из конфига будет запоминаться в originalLayouts, новое значение высоты в adjustedLayouts
|
|
19
|
-
this.state = { currentLayout: this.props.layout };
|
|
20
|
-
this.originalLayouts = {};
|
|
21
|
-
this.adjustedLayouts = {};
|
|
22
|
-
// каллбэк вызывающийся при изменение лэйаута сетки, первым аргументом приходит актуальный конфиг лэйаута,
|
|
23
|
-
// т.е. если на текущей сетке есть виджеты, с активированной опцией автовысоты, их параметр "h" будет
|
|
24
|
-
// "подстроенный"; чтобы, для сохранения в сторе "ушли" значения без учёта подстройки (как если бы у этих
|
|
25
|
-
// виджетов автовысота была деактивирована) корректируем их используя this.originalLayouts
|
|
26
|
-
this._onLayoutChange = (layout) => {
|
|
27
|
-
const currentLayout = layout.map((item) => {
|
|
28
|
-
if (item.i in this.originalLayouts) {
|
|
29
|
-
return Object.assign(Object.assign({}, this.originalLayouts[item.i]), { w: item.w, x: item.x, y: item.y });
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
return Object.assign({}, item);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
// [experimental] if the _prevent Double Compact is enabled, then skip recalculate layout with auto height
|
|
36
|
-
// после того, как у виждета активировали автовысоту и его параметр "h" изменился, это приведёт, также, и к
|
|
37
|
-
// изменению параметра (координаты) "y" у элементов расположенных под ним, поэтому, после того, как
|
|
38
|
-
// значения параметра "h" виджетов с активированной автовысотой были изменены, необходимо изменить и
|
|
39
|
-
// координату "y" виджетов расположенных ниже
|
|
40
|
-
const compactedLayout = this.props._EXPERIMENTAL_preventDoubleCompact
|
|
41
|
-
? currentLayout
|
|
42
|
-
: gridLayoutUtils.compact(currentLayout, LAYOUT_COMPACTING_TYPE, this.props.registerManager.gridLayout.cols);
|
|
43
|
-
const newConfig = UpdateManager.updateLayout({
|
|
44
|
-
layout: compactedLayout,
|
|
45
|
-
config: this.props.config,
|
|
46
|
-
});
|
|
47
|
-
if (!isEqual(newConfig.layout, this.props.config.layout)) {
|
|
48
|
-
this._onChange({
|
|
49
|
-
config: newConfig,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
this._onItemRemove = (id) => {
|
|
54
|
-
const { config, itemsStateAndParams } = this.props;
|
|
55
|
-
this._onChange(UpdateManager.removeItem({ id, config, itemsStateAndParams }));
|
|
56
|
-
};
|
|
57
|
-
this._onItemEdit = (configItem) => {
|
|
58
|
-
this.props.onItemEdit(configItem);
|
|
59
|
-
};
|
|
60
|
-
this._onItemStateAndParamsChange = (id, stateAndParams) => {
|
|
61
|
-
const { config, itemsStateAndParams } = this.props;
|
|
62
|
-
this._onChange({
|
|
63
|
-
itemsStateAndParams: UpdateManager.changeStateAndParams({
|
|
64
|
-
id,
|
|
65
|
-
config,
|
|
66
|
-
stateAndParams,
|
|
67
|
-
itemsStateAndParams,
|
|
68
|
-
}),
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
this._memorizeOriginalLayout = (widgetId, preAutoHeightLayout, postAutoHeightLayout) => {
|
|
72
|
-
if (!(widgetId in this.originalLayouts)) {
|
|
73
|
-
this.originalLayouts[widgetId] = preAutoHeightLayout;
|
|
74
|
-
}
|
|
75
|
-
this.adjustedLayouts[widgetId] = postAutoHeightLayout;
|
|
76
|
-
this.setState({
|
|
77
|
-
currentLayout: this.props.layout.map((item) => {
|
|
78
|
-
if (item.i in this.adjustedLayouts) {
|
|
79
|
-
return Object.assign(Object.assign({}, this.adjustedLayouts[item.i]), { w: item.w, x: item.x, y: item.y });
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return Object.assign({}, item);
|
|
83
|
-
}
|
|
84
|
-
}),
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
this._revertToOriginalLayout = (widgetId) => {
|
|
88
|
-
this.setState({
|
|
89
|
-
currentLayout: this.state.currentLayout.map((item) => {
|
|
90
|
-
if (item.i === widgetId) {
|
|
91
|
-
return Object.assign(Object.assign({}, this.originalLayouts[item.i]), { w: item.w, x: item.x, y: item.y });
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
return Object.assign({}, item);
|
|
95
|
-
}
|
|
96
|
-
}),
|
|
97
|
-
});
|
|
98
|
-
delete this.adjustedLayouts[widgetId];
|
|
99
|
-
delete this.originalLayouts[widgetId];
|
|
100
|
-
};
|
|
101
|
-
this._getItemsMeta = (pluginsRefs) => {
|
|
102
|
-
return pluginsRefs
|
|
103
|
-
.map((ref) => {
|
|
104
|
-
if (!(ref && typeof ref.getMeta === 'function')) {
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
return ref.getMeta();
|
|
108
|
-
})
|
|
109
|
-
.filter(Boolean);
|
|
110
|
-
};
|
|
111
|
-
this._getLayout = () => {
|
|
112
|
-
return this.props.layout.map((item) => {
|
|
113
|
-
if (item.i in this.adjustedLayouts) {
|
|
114
|
-
return Object.assign(Object.assign({}, this.adjustedLayouts[item.i]), { w: item.w, x: item.x, y: item.y });
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
return Object.assign({}, item);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
|
-
this._reloadItems = (pluginsRefs, data) => {
|
|
122
|
-
pluginsRefs.forEach((ref) => ref && ref.reload && ref.reload(data));
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
_onChange({ config = this.props.config, itemsStateAndParams = this.props.itemsStateAndParams, }) {
|
|
126
|
-
if (!(isEqual(config, this.props.config) &&
|
|
127
|
-
isEqual(itemsStateAndParams, this.props.itemsStateAndParams))) {
|
|
128
|
-
this.props.onChange({
|
|
129
|
-
config,
|
|
130
|
-
itemsStateAndParams,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
get _itemsParams() {
|
|
135
|
-
const { config, itemsStateAndParams, globalParams, defaultGlobalParams, registerManager, } = this.props;
|
|
136
|
-
return getItemsParams({
|
|
137
|
-
defaultGlobalParams,
|
|
138
|
-
globalParams,
|
|
139
|
-
config,
|
|
140
|
-
itemsStateAndParams,
|
|
141
|
-
plugins: registerManager.getPlugins(),
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
get _itemsState() {
|
|
145
|
-
const { config, itemsStateAndParams } = this.props;
|
|
146
|
-
return getItemsState({ config, itemsStateAndParams });
|
|
147
|
-
}
|
|
148
|
-
get _contextValue() {
|
|
149
|
-
return {
|
|
150
|
-
getLayout: this._getLayout,
|
|
151
|
-
config: this.props.config,
|
|
152
|
-
context: this.props.context,
|
|
153
|
-
noOverlay: this.props.noOverlay,
|
|
154
|
-
defaultGlobalParams: this.props.globalParams,
|
|
155
|
-
globalParams: this.props.globalParams,
|
|
156
|
-
editMode: this.props.editMode,
|
|
157
|
-
settings: this.props.settings,
|
|
158
|
-
itemsState: this._itemsState,
|
|
159
|
-
itemsParams: this._itemsParams,
|
|
160
|
-
registerManager: this.props.registerManager,
|
|
161
|
-
onItemStateAndParamsChange: this._onItemStateAndParamsChange,
|
|
162
|
-
removeItem: this._onItemRemove,
|
|
163
|
-
editItem: this._onItemEdit,
|
|
164
|
-
layoutChange: this._onLayoutChange,
|
|
165
|
-
getItemsMeta: this._getItemsMeta,
|
|
166
|
-
reloadItems: this._reloadItems,
|
|
167
|
-
memorizeOriginalLayout: this._memorizeOriginalLayout,
|
|
168
|
-
revertToOriginalLayout: this._revertToOriginalLayout,
|
|
169
|
-
forwardedMetaRef: this.props.forwardedMetaRef,
|
|
170
|
-
draggableHandleClassName: this.props.draggableHandleClassName,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
render() {
|
|
174
|
-
return (React.createElement(DashKitContext.Provider, { value: this._contextValue },
|
|
175
|
-
React.createElement(Component, { overlayControls: this.props.overlayControls })));
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
_a.propTypes = {
|
|
179
|
-
editMode: PropTypes.bool,
|
|
180
|
-
context: PropTypes.object,
|
|
181
|
-
overlayControls: PropTypes.object,
|
|
182
|
-
config: PropTypes.object,
|
|
183
|
-
onItemEdit: PropTypes.func,
|
|
184
|
-
onChange: PropTypes.func,
|
|
185
|
-
defaultGlobalParams: PropTypes.object,
|
|
186
|
-
globalParams: PropTypes.object,
|
|
187
|
-
itemsStateAndParams: PropTypes.object,
|
|
188
|
-
registerManager: PropTypes.object,
|
|
189
|
-
layout: PropTypes.array,
|
|
190
|
-
settings: PropTypes.object,
|
|
191
|
-
forwardedMetaRef: PropTypes.object,
|
|
192
|
-
noOverlay: PropTypes.bool,
|
|
193
|
-
draggableHandleClassName: PropTypes.string,
|
|
194
|
-
_EXPERIMENTAL_preventDoubleCompact: PropTypes.bool,
|
|
195
|
-
},
|
|
196
|
-
_a;
|
|
197
|
-
}
|
|
198
8
|
function useMemoStateContext(props) {
|
|
199
9
|
// так как мы не хотим хранить параметры виджета с активированной автовысотой в сторе и на сервере, актуальный
|
|
200
10
|
// (видимый юзером в конкретный момент времени) лэйаут (массив объектов с данными о ширине, высоте,
|
|
@@ -316,14 +126,11 @@ function useMemoStateContext(props) {
|
|
|
316
126
|
}
|
|
317
127
|
});
|
|
318
128
|
}, [props.layout, layoutUpdateCounter]);
|
|
319
|
-
// TODO: don't use getLayout when finished experiment _EXPERIMENTAL_memoContext
|
|
320
|
-
// need use resultLayout like layout props
|
|
321
|
-
const getLayout = React.useCallback(() => resultLayout, [resultLayout]);
|
|
322
129
|
const reloadItems = React.useCallback((pluginsRefs, data) => {
|
|
323
130
|
pluginsRefs.forEach((ref) => ref && ref.reload && ref.reload(data));
|
|
324
131
|
}, []);
|
|
325
132
|
return React.useMemo(() => ({
|
|
326
|
-
|
|
133
|
+
layout: resultLayout,
|
|
327
134
|
config: props.config,
|
|
328
135
|
context: props.context,
|
|
329
136
|
noOverlay: props.noOverlay,
|
|
@@ -345,7 +152,7 @@ function useMemoStateContext(props) {
|
|
|
345
152
|
forwardedMetaRef: props.forwardedMetaRef,
|
|
346
153
|
draggableHandleClassName: props.draggableHandleClassName,
|
|
347
154
|
}), [
|
|
348
|
-
|
|
155
|
+
resultLayout,
|
|
349
156
|
props.config,
|
|
350
157
|
props.context,
|
|
351
158
|
props.noOverlay,
|
|
@@ -367,12 +174,12 @@ function useMemoStateContext(props) {
|
|
|
367
174
|
props.draggableHandleClassName,
|
|
368
175
|
]);
|
|
369
176
|
}
|
|
370
|
-
export function
|
|
371
|
-
const
|
|
177
|
+
export function withContext(Component) {
|
|
178
|
+
const WithContext = (props) => {
|
|
372
179
|
const contextValue = useMemoStateContext(props);
|
|
373
180
|
return (React.createElement(DashKitContext.Provider, { value: contextValue },
|
|
374
181
|
React.createElement(Component, { overlayControls: props.overlayControls })));
|
|
375
182
|
};
|
|
376
|
-
|
|
377
|
-
return
|
|
183
|
+
WithContext.displayName = `withContext(${Component.displayName || Component.name || 'Component'}`;
|
|
184
|
+
return WithContext;
|
|
378
185
|
}
|
package/build/esm/index.d.ts
CHANGED
package/build/esm/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PluginTextApiHandler, PluginTextProps, PluginText, PluginObjectSettings as PluginTextObjectSettings, PluginObject as PluginTextObject, default as pluginText, } from './Text';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PluginText, default as pluginText, } from './Text';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PluginTitle, PluginTitleProps, default as pluginTitle } from './Title';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PluginTitle, default as pluginTitle } from './Title';
|