@gravity-ui/dashkit 8.21.1 → 8.22.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 +14 -12
- package/build/cjs/components/DashKit/DashKit.js +2 -2
- package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.js +2 -2
- package/build/cjs/components/DashKitView/DashKitView.js +2 -2
- package/build/cjs/components/GridItem/GridItem.js +2 -2
- package/build/cjs/components/GridLayout/GridLayout.d.ts +1 -1
- package/build/cjs/components/GridLayout/GridLayout.js +4 -3
- package/build/cjs/components/Item/Item.d.ts +2 -1
- package/build/cjs/components/MobileLayout/MobileLayout.d.ts +28 -21
- package/build/cjs/components/MobileLayout/MobileLayout.js +60 -47
- package/build/cjs/components/OverlayControls/OverlayControls.d.ts +4 -16
- package/build/cjs/components/OverlayControls/OverlayControls.js +8 -9
- package/build/cjs/context/DashKitContext.d.ts +30 -3
- package/build/cjs/context/DashKitContext.js +2 -6
- package/build/cjs/context/DashKitDnDContext.d.ts +10 -0
- package/build/cjs/context/DashKitDnDContext.js +6 -0
- package/build/cjs/context/DashkitOverlayControlsContext.d.ts +13 -0
- package/build/cjs/context/DashkitOverlayControlsContext.js +6 -0
- package/build/cjs/context/index.d.ts +3 -0
- package/build/cjs/context/index.js +6 -0
- package/build/cjs/hocs/prepareItem.d.ts +2 -1
- package/build/cjs/hocs/prepareItem.js +2 -2
- package/build/cjs/hocs/withContext.js +23 -20
- package/build/cjs/hooks/useDnDItemProps.js +2 -2
- package/build/cjs/plugins/Title/Title.css +4 -0
- package/build/cjs/plugins/Title/Title.d.ts +2 -1
- package/build/cjs/shared/modules/helpers.d.ts +1 -1
- package/build/cjs/shared/modules/helpers.js +1 -1
- package/build/cjs/shared/types/state-and-params.d.ts +2 -1
- package/build/cjs/typings/config.d.ts +1 -0
- package/build/esm/components/DashKit/DashKit.d.ts +14 -12
- package/build/esm/components/DashKit/DashKit.js +1 -1
- package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.js +1 -1
- package/build/esm/components/DashKitView/DashKitView.js +1 -1
- package/build/esm/components/GridItem/GridItem.js +1 -1
- package/build/esm/components/GridLayout/GridLayout.d.ts +1 -1
- package/build/esm/components/GridLayout/GridLayout.js +3 -2
- package/build/esm/components/Item/Item.d.ts +2 -1
- package/build/esm/components/MobileLayout/MobileLayout.d.ts +29 -21
- package/build/esm/components/MobileLayout/MobileLayout.js +59 -46
- package/build/esm/components/OverlayControls/OverlayControls.d.ts +4 -16
- package/build/esm/components/OverlayControls/OverlayControls.js +7 -8
- package/build/esm/context/DashKitContext.d.ts +30 -3
- package/build/esm/context/DashKitContext.js +2 -4
- package/build/esm/context/DashKitDnDContext.d.ts +10 -0
- package/build/esm/context/DashKitDnDContext.js +2 -0
- package/build/esm/context/DashkitOverlayControlsContext.d.ts +13 -0
- package/build/esm/context/DashkitOverlayControlsContext.js +2 -0
- package/build/esm/context/index.d.ts +3 -0
- package/build/esm/context/index.js +3 -0
- package/build/esm/hocs/prepareItem.d.ts +2 -1
- package/build/esm/hocs/prepareItem.js +1 -1
- package/build/esm/hocs/withContext.js +20 -17
- package/build/esm/hooks/useDnDItemProps.js +1 -1
- package/build/esm/plugins/Title/Title.css +4 -0
- package/build/esm/plugins/Title/Title.d.ts +2 -1
- package/build/esm/shared/modules/helpers.d.ts +1 -1
- package/build/esm/shared/modules/helpers.js +1 -1
- package/build/esm/shared/types/state-and-params.d.ts +2 -1
- package/build/esm/typings/config.d.ts +1 -0
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ const react_1 = tslib_1.__importDefault(require("react"));
|
|
|
6
6
|
const isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
|
|
7
7
|
const pick_1 = tslib_1.__importDefault(require("lodash/pick"));
|
|
8
8
|
const common_1 = require("../constants/common");
|
|
9
|
-
const
|
|
9
|
+
const context_1 = require("../context");
|
|
10
10
|
const useDeepEqualMemo_1 = require("../hooks/useDeepEqualMemo");
|
|
11
11
|
const shared_1 = require("../shared");
|
|
12
12
|
const utils_1 = require("../utils");
|
|
@@ -22,7 +22,7 @@ function useMemoStateContext(props) {
|
|
|
22
22
|
const nowrapAdjustedLayouts = react_1.default.useRef({});
|
|
23
23
|
const [temporaryLayout, setTemporaryLayout] = react_1.default.useState(null);
|
|
24
24
|
const resetTemporaryLayout = react_1.default.useCallback(() => setTemporaryLayout(null), [setTemporaryLayout]);
|
|
25
|
-
const dndContext = react_1.default.useContext(
|
|
25
|
+
const dndContext = react_1.default.useContext(context_1.DashKitDnDContext);
|
|
26
26
|
const outerDnDEnable = Boolean(dndContext);
|
|
27
27
|
// TODO: need move originalLayouts, adjustedLayouts to state
|
|
28
28
|
const [layoutUpdateCounter, forceUpdateLayout] = react_1.default.useState(0);
|
|
@@ -286,6 +286,7 @@ function useMemoStateContext(props) {
|
|
|
286
286
|
}
|
|
287
287
|
return itemLayout;
|
|
288
288
|
}, [
|
|
289
|
+
props.registerManager,
|
|
289
290
|
resetTemporaryLayout,
|
|
290
291
|
temporaryLayout,
|
|
291
292
|
dragOverPlugin,
|
|
@@ -314,8 +315,6 @@ function useMemoStateContext(props) {
|
|
|
314
315
|
});
|
|
315
316
|
}, [dragPropsContext, onDropProp, setTemporaryLayout, resetTemporaryLayout]);
|
|
316
317
|
const dashkitContextValue = react_1.default.useMemo(() => ({
|
|
317
|
-
layout: resultLayout,
|
|
318
|
-
temporaryLayout,
|
|
319
318
|
config: props.config,
|
|
320
319
|
groups: props.groups,
|
|
321
320
|
context: props.context,
|
|
@@ -325,24 +324,26 @@ function useMemoStateContext(props) {
|
|
|
325
324
|
globalParams: props.globalParams,
|
|
326
325
|
editMode: props.editMode,
|
|
327
326
|
settings: props.settings,
|
|
328
|
-
itemsState,
|
|
329
|
-
itemsParams,
|
|
330
|
-
registerManager: props.registerManager,
|
|
331
|
-
onItemStateAndParamsChange,
|
|
332
|
-
onDrop,
|
|
333
|
-
onDropDragOver,
|
|
334
327
|
onItemMountChange: props.onItemMountChange,
|
|
335
328
|
onItemRender: props.onItemRender,
|
|
329
|
+
draggableHandleClassName: props.draggableHandleClassName,
|
|
330
|
+
registerManager: props.registerManager,
|
|
331
|
+
forwardedMetaRef: props.forwardedMetaRef,
|
|
332
|
+
layout: resultLayout,
|
|
333
|
+
temporaryLayout,
|
|
336
334
|
layoutChange: onLayoutChange,
|
|
337
|
-
getItemsMeta,
|
|
338
|
-
reloadItems,
|
|
339
335
|
memorizeOriginalLayout,
|
|
340
336
|
revertToOriginalLayout,
|
|
341
|
-
|
|
342
|
-
|
|
337
|
+
itemsState,
|
|
338
|
+
itemsParams,
|
|
339
|
+
onItemStateAndParamsChange,
|
|
340
|
+
getItemsMeta,
|
|
341
|
+
reloadItems,
|
|
342
|
+
onDrop,
|
|
343
|
+
onDropDragOver,
|
|
343
344
|
outerDnDEnable,
|
|
344
345
|
dragOverPlugin,
|
|
345
|
-
/* default
|
|
346
|
+
/* default handlers bypass */
|
|
346
347
|
onDragStart: props.onDragStart,
|
|
347
348
|
onDrag: props.onDrag,
|
|
348
349
|
onDragStop: props.onDragStop,
|
|
@@ -388,14 +389,15 @@ function useMemoStateContext(props) {
|
|
|
388
389
|
const controlsContextValue = react_1.default.useMemo(() => ({
|
|
389
390
|
overlayControls: props.overlayControls,
|
|
390
391
|
context: props.context,
|
|
391
|
-
menu: overlayMenuItems,
|
|
392
392
|
itemsStateAndParams: props.itemsStateAndParams,
|
|
393
|
+
itemsState,
|
|
393
394
|
itemsParams,
|
|
395
|
+
getPreparedCopyItemOptions: props.getPreparedCopyItemOptions,
|
|
396
|
+
onCopyFulfill: props.onCopyFulfill,
|
|
397
|
+
menu: overlayMenuItems,
|
|
394
398
|
editItem: props.onItemEdit,
|
|
395
399
|
removeItem: onItemRemove,
|
|
396
400
|
getLayoutItem: getLayoutItem,
|
|
397
|
-
getPreparedCopyItemOptions: props.getPreparedCopyItemOptions,
|
|
398
|
-
onCopyFulfill: props.onCopyFulfill,
|
|
399
401
|
}), [
|
|
400
402
|
props.overlayControls,
|
|
401
403
|
props.context,
|
|
@@ -404,6 +406,7 @@ function useMemoStateContext(props) {
|
|
|
404
406
|
props.getPreparedCopyItemOptions,
|
|
405
407
|
props.onCopyFulfill,
|
|
406
408
|
overlayMenuItems,
|
|
409
|
+
itemsState,
|
|
407
410
|
itemsParams,
|
|
408
411
|
onItemRemove,
|
|
409
412
|
getLayoutItem,
|
|
@@ -413,8 +416,8 @@ function useMemoStateContext(props) {
|
|
|
413
416
|
function withContext(Component) {
|
|
414
417
|
const WithContext = (props) => {
|
|
415
418
|
const { dashkitContextValue, controlsContextValue } = useMemoStateContext(props);
|
|
416
|
-
return (react_1.default.createElement(
|
|
417
|
-
react_1.default.createElement(
|
|
419
|
+
return (react_1.default.createElement(context_1.DashKitContext.Provider, { value: dashkitContextValue },
|
|
420
|
+
react_1.default.createElement(context_1.DashkitOvelayControlsContext.Provider, { value: controlsContextValue },
|
|
418
421
|
react_1.default.createElement(Component, null))));
|
|
419
422
|
};
|
|
420
423
|
WithContext.displayName = `withContext(${Component.displayName || Component.name || 'Component'}`;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useDnDItemProps = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
-
const
|
|
6
|
+
const context_1 = require("../context");
|
|
7
7
|
const useDnDItemProps = (item) => {
|
|
8
|
-
const dragContext = react_1.default.useContext(
|
|
8
|
+
const dragContext = react_1.default.useContext(context_1.DashKitDnDContext);
|
|
9
9
|
const onDragStart = react_1.default.useCallback((e) => {
|
|
10
10
|
if (dragContext && item.dragProps) {
|
|
11
11
|
dragContext.onDragStart(e, item.dragProps);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Plugin, PluginWidgetProps } from '../../typings';
|
|
3
|
+
export type PluginTitleSize = 'xl' | 'l' | 'm' | 's' | 'xs';
|
|
3
4
|
export interface PluginTitleProps extends PluginWidgetProps {
|
|
4
5
|
data: {
|
|
5
|
-
size:
|
|
6
|
+
size: PluginTitleSize;
|
|
6
7
|
text: string;
|
|
7
8
|
showInTOC: boolean;
|
|
8
9
|
} & PluginWidgetProps['data'];
|
|
@@ -18,7 +18,7 @@ export declare function formQueueData({ items, itemsStateAndParams, }: {
|
|
|
18
18
|
}): FormedQueueData[];
|
|
19
19
|
export declare function resolveItemInnerId({ item, itemsStateAndParams, }: {
|
|
20
20
|
item: Pick<ConfigItemWithTabs, 'data' | 'id'>;
|
|
21
|
-
itemsStateAndParams
|
|
21
|
+
itemsStateAndParams?: ItemsStateAndParams;
|
|
22
22
|
}): string;
|
|
23
23
|
export declare function getMapItemsIgnores({ items, ignores, itemsStateAndParams, isFirstVersion, }: {
|
|
24
24
|
items: (ConfigItem | ConfigItemGroup)[];
|
|
@@ -118,7 +118,7 @@ exports.formQueueData = formQueueData;
|
|
|
118
118
|
function resolveItemInnerId({ item, itemsStateAndParams, }) {
|
|
119
119
|
var _a, _b;
|
|
120
120
|
const { id } = item;
|
|
121
|
-
const stateTabId = (_b = (_a = itemsStateAndParams[id]) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.tabId;
|
|
121
|
+
const stateTabId = (_b = (_a = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.tabId;
|
|
122
122
|
const { tabs } = item.data;
|
|
123
123
|
if (stateTabId && tabs.some((tab) => tab.id === stateTabId)) {
|
|
124
124
|
return stateTabId;
|
|
@@ -3,6 +3,7 @@ import { StringParams } from './common';
|
|
|
3
3
|
export interface ItemState {
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
}
|
|
6
|
+
export type ItemParams = StringParams | Record<string, StringParams>;
|
|
6
7
|
export interface QueueItem {
|
|
7
8
|
id: string;
|
|
8
9
|
tabId?: string;
|
|
@@ -16,7 +17,7 @@ export type StateAndParamsMeta = {
|
|
|
16
17
|
[META_KEY]: StateAndParamsMetaData;
|
|
17
18
|
};
|
|
18
19
|
export type ItemStateAndParams = {
|
|
19
|
-
params?:
|
|
20
|
+
params?: ItemParams;
|
|
20
21
|
state?: ItemState;
|
|
21
22
|
};
|
|
22
23
|
export type ItemStateAndParamsChangeOptions = {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Config, ConfigItem, ConfigLayout, GlobalParams, ItemDropProps, ItemsStateAndParams } from '../../shared';
|
|
3
|
-
import { AddNewItemOptions, ContextProps, DashKitGroup, ItemManipulationCallback, MenuItem, Plugin, SetConfigItem, Settings, SettingsProps } from '../../typings';
|
|
3
|
+
import type { AddNewItemOptions, ContextProps, DashKitGroup, ItemManipulationCallback, MenuItem, Plugin, SetConfigItem, Settings, SettingsProps } from '../../typings';
|
|
4
4
|
import GridLayout from '../GridLayout/GridLayout';
|
|
5
|
-
import { OverlayControlItem,
|
|
6
|
-
interface DashKitGeneralProps
|
|
5
|
+
import type { OverlayControlItem, PreparedCopyItemOptions } from '../OverlayControls/OverlayControls';
|
|
6
|
+
interface DashKitGeneralProps {
|
|
7
7
|
config: Config;
|
|
8
8
|
editMode: boolean;
|
|
9
9
|
draggableHandleClassName?: string;
|
|
@@ -11,6 +11,14 @@ interface DashKitGeneralProps extends Pick<OverlayControlsCtxShape, 'getPrepared
|
|
|
11
11
|
overlayMenuItems?: MenuItem[] | null;
|
|
12
12
|
}
|
|
13
13
|
interface DashKitDefaultProps {
|
|
14
|
+
defaultGlobalParams: GlobalParams;
|
|
15
|
+
globalParams: GlobalParams;
|
|
16
|
+
itemsStateAndParams: ItemsStateAndParams;
|
|
17
|
+
settings: SettingsProps;
|
|
18
|
+
context: ContextProps;
|
|
19
|
+
noOverlay: boolean;
|
|
20
|
+
focusable?: boolean;
|
|
21
|
+
groups?: DashKitGroup[];
|
|
14
22
|
onItemEdit: (item: ConfigItem) => void;
|
|
15
23
|
onChange: (data: {
|
|
16
24
|
config: Config;
|
|
@@ -23,27 +31,21 @@ interface DashKitDefaultProps {
|
|
|
23
31
|
isMounted: boolean;
|
|
24
32
|
}) => void;
|
|
25
33
|
onItemRender?: (item: ConfigItem) => void;
|
|
34
|
+
getPreparedCopyItemOptions?: (options: PreparedCopyItemOptions) => PreparedCopyItemOptions;
|
|
35
|
+
onCopyFulfill?: (error: null | Error, data?: PreparedCopyItemOptions) => void;
|
|
26
36
|
onDragStart?: ItemManipulationCallback;
|
|
27
37
|
onDrag?: ItemManipulationCallback;
|
|
28
38
|
onDragStop?: ItemManipulationCallback;
|
|
29
39
|
onResizeStart?: ItemManipulationCallback;
|
|
30
40
|
onResize?: ItemManipulationCallback;
|
|
31
41
|
onResizeStop?: ItemManipulationCallback;
|
|
32
|
-
defaultGlobalParams: GlobalParams;
|
|
33
|
-
globalParams: GlobalParams;
|
|
34
|
-
itemsStateAndParams: ItemsStateAndParams;
|
|
35
|
-
settings: SettingsProps;
|
|
36
|
-
context: ContextProps;
|
|
37
|
-
noOverlay: boolean;
|
|
38
|
-
focusable?: boolean;
|
|
39
|
-
groups?: DashKitGroup[];
|
|
40
42
|
}
|
|
41
43
|
export interface DashKitProps extends DashKitGeneralProps, Partial<DashKitDefaultProps> {
|
|
42
44
|
}
|
|
43
45
|
type DashKitInnerProps = DashKitGeneralProps & DashKitDefaultProps;
|
|
44
46
|
export declare class DashKit extends React.PureComponent<DashKitInnerProps> {
|
|
45
47
|
static defaultProps: DashKitDefaultProps;
|
|
46
|
-
static contextType: React.Context<
|
|
48
|
+
static contextType: React.Context<void | import("../../context").DashKitDnDCtxShape>;
|
|
47
49
|
static registerPlugins(...plugins: Plugin[]): void;
|
|
48
50
|
static reloadPlugins(...plugins: Plugin[]): void;
|
|
49
51
|
static setSettings(settings: Settings): void;
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import noop from 'lodash/noop';
|
|
3
3
|
import pick from 'lodash/pick';
|
|
4
4
|
import { DEFAULT_GROUP, DEFAULT_NAMESPACE } from '../../constants';
|
|
5
|
-
import { DashKitDnDContext } from '../../context
|
|
5
|
+
import { DashKitDnDContext } from '../../context';
|
|
6
6
|
import { RegisterManager, UpdateManager, reflowLayout } from '../../utils';
|
|
7
7
|
import { DashKitDnDWrapper } from '../DashKitDnDWrapper/DashKitDnDWrapper';
|
|
8
8
|
import DashKitView from '../DashKitView/DashKitView';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { DashKitDnDContext } from '../../context
|
|
2
|
+
import { DashKitDnDContext } from '../../context';
|
|
3
3
|
const defaultImageSrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
|
|
4
4
|
export const DashKitDnDWrapper = (props) => {
|
|
5
5
|
const [dragProps, setDragProps] = React.useState(null);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { DashKitContext } from '../../context
|
|
2
|
+
import { DashKitContext } from '../../context';
|
|
3
3
|
import { withContext } from '../../hocs/withContext';
|
|
4
4
|
import { useCalcPropsLayout } from '../../hooks/useCalcLayout';
|
|
5
5
|
import { cn } from '../../utils/cn';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { FOCUSED_CLASS_NAME } from '../../constants';
|
|
4
|
-
import { DashKitContext } from '../../context
|
|
4
|
+
import { DashKitContext } from '../../context';
|
|
5
5
|
import { cn } from '../../utils/cn';
|
|
6
6
|
import Item from '../Item/Item';
|
|
7
7
|
import OverlayControls from '../OverlayControls/OverlayControls';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default class GridLayout extends React.PureComponent<any, any, any> {
|
|
2
|
-
static contextType: React.Context<
|
|
2
|
+
static contextType: React.Context<import("../../context").DashKitCtxShape>;
|
|
3
3
|
constructor(props: any, context: any);
|
|
4
4
|
pluginsRefs: any[];
|
|
5
5
|
state: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { COMPACT_TYPE_HORIZONTAL_NOWRAP, DEFAULT_GROUP, DRAGGABLE_CANCEL_CLASS_NAME, TEMPORARY_ITEM_ID, } from '../../constants';
|
|
3
|
-
import { DashKitContext } from '../../context
|
|
3
|
+
import { DashKitContext } from '../../context';
|
|
4
4
|
import { resolveLayoutGroup } from '../../utils';
|
|
5
5
|
import GridItem from '../GridItem/GridItem';
|
|
6
6
|
import { Layout } from './ReactGridLayout';
|
|
@@ -266,7 +266,7 @@ class GridLayout extends React.PureComponent {
|
|
|
266
266
|
}
|
|
267
267
|
this._timeout = setTimeout(() => this.reloadItems(), reloadIntervalRemains <= 0 ? autoupdateIntervalMs : reloadIntervalRemains);
|
|
268
268
|
}
|
|
269
|
-
else if (force
|
|
269
|
+
else if (force) {
|
|
270
270
|
reloadItems(targetPlugins, { silentLoading, noVeil: true });
|
|
271
271
|
}
|
|
272
272
|
}
|
|
@@ -498,6 +498,7 @@ class GridLayout extends React.PureComponent {
|
|
|
498
498
|
offset += items.length;
|
|
499
499
|
if (group.render) {
|
|
500
500
|
const groupContext = {
|
|
501
|
+
isMobile: false,
|
|
501
502
|
config,
|
|
502
503
|
editMode,
|
|
503
504
|
items,
|
|
@@ -66,7 +66,8 @@ declare const _default: {
|
|
|
66
66
|
onItemMountChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
67
67
|
forwardedPluginRef: PropTypes.Requireable<any>;
|
|
68
68
|
};
|
|
69
|
-
contextType: React.Context<
|
|
69
|
+
contextType: React.Context<import("../../context").DashKitCtxShape>;
|
|
70
70
|
};
|
|
71
71
|
export default _default;
|
|
72
72
|
import React from 'react';
|
|
73
|
+
import PropTypes from 'prop-types';
|
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
needSetDefault:
|
|
19
|
-
}) => void
|
|
20
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DashKitContext } from '../../context';
|
|
3
|
+
import { getSortedConfigItems } from './helpers';
|
|
4
|
+
import './MobileLayout.css';
|
|
5
|
+
type MobileLayoutProps = {};
|
|
6
|
+
type MobileLayoutState = {
|
|
7
|
+
itemsWithActiveAutoheight: Record<string, boolean>;
|
|
8
|
+
};
|
|
9
|
+
type PlugibRefObject = React.RefObject<any>;
|
|
10
|
+
export default class MobileLayout extends React.PureComponent<MobileLayoutProps, MobileLayoutState> {
|
|
11
|
+
static contextType: React.Context<import("../../context").DashKitCtxShape>;
|
|
12
|
+
context: React.ContextType<typeof DashKitContext>;
|
|
13
|
+
pluginsRefs: PlugibRefObject[];
|
|
14
|
+
sortedLayoutItems: Record<string, ReturnType<typeof getSortedConfigItems>> | null;
|
|
15
|
+
_memoLayout: import("../..").ConfigLayout[];
|
|
16
|
+
_memoForwardedPluginRef: Array<(refObject: PlugibRefObject) => void>;
|
|
17
|
+
_memoAdjustWidgetLayout: Record<string, (props: {
|
|
18
|
+
needSetDefault: boolean;
|
|
19
|
+
}) => void>;
|
|
20
|
+
state: MobileLayoutState;
|
|
21
21
|
render(): JSX.Element;
|
|
22
|
+
getSortedLayoutItems(): Record<string, (import("../..").ConfigItem & import("../..").ConfigLayout)[]>;
|
|
23
|
+
getMemoForwardRefCallback(refIndex: number): (refObject: PlugibRefObject) => void;
|
|
24
|
+
adjustWidgetLayout(id: string, { needSetDefault }: {
|
|
25
|
+
needSetDefault: boolean;
|
|
26
|
+
}): void;
|
|
27
|
+
getMemoAdjustWidgetLayout(id: string): (props: {
|
|
28
|
+
needSetDefault: boolean;
|
|
29
|
+
}) => void;
|
|
22
30
|
}
|
|
23
|
-
|
|
31
|
+
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import groupBy from 'lodash/groupBy';
|
|
3
|
+
import { DEFAULT_GROUP } from '../../constants';
|
|
4
|
+
import { DashKitContext } from '../../context';
|
|
3
5
|
import { cn } from '../../utils/cn';
|
|
4
6
|
import Item from '../Item/Item';
|
|
5
7
|
import { getSortedConfigItems } from './helpers';
|
|
@@ -9,47 +11,40 @@ class MobileLayout extends React.PureComponent {
|
|
|
9
11
|
constructor() {
|
|
10
12
|
super(...arguments);
|
|
11
13
|
this.pluginsRefs = [];
|
|
14
|
+
this.sortedLayoutItems = null;
|
|
12
15
|
this._memoLayout = this.context.layout;
|
|
13
16
|
this._memoForwardedPluginRef = [];
|
|
14
|
-
this._memoAdjustWidgetLayout =
|
|
17
|
+
this._memoAdjustWidgetLayout = {};
|
|
15
18
|
this.state = {
|
|
16
|
-
|
|
17
|
-
indexesOfItemsWithActiveAutoheight: {},
|
|
18
|
-
};
|
|
19
|
-
this.getMemoForwardRefCallback = (refIndex) => {
|
|
20
|
-
if (!this._memoForwardedPluginRef[refIndex]) {
|
|
21
|
-
this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
|
|
22
|
-
this.pluginsRefs[refIndex] = pluginRef;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return this._memoForwardedPluginRef[refIndex];
|
|
26
|
-
};
|
|
27
|
-
this.adjustWidgetLayout = (index, { needSetDefault }) => {
|
|
28
|
-
if (needSetDefault) {
|
|
29
|
-
const indexesOfItemsWithActiveAutoheight = Object.assign({}, this.state.indexesOfItemsWithActiveAutoheight);
|
|
30
|
-
delete indexesOfItemsWithActiveAutoheight[index];
|
|
31
|
-
this.setState({ indexesOfItemsWithActiveAutoheight });
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
this.setState({
|
|
35
|
-
indexesOfItemsWithActiveAutoheight: Object.assign({}, this.state.indexesOfItemsWithActiveAutoheight, { [index]: true }),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
this.getMemoAdjustWidgetLayout = (index) => {
|
|
40
|
-
if (!this._memoAdjustWidgetLayout[index]) {
|
|
41
|
-
this._memoAdjustWidgetLayout[index] = this.adjustWidgetLayout.bind(this, index);
|
|
42
|
-
}
|
|
43
|
-
return this._memoAdjustWidgetLayout[index];
|
|
19
|
+
itemsWithActiveAutoheight: {},
|
|
44
20
|
};
|
|
45
21
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
22
|
+
render() {
|
|
23
|
+
const { config, layout, groups = [{ id: DEFAULT_GROUP }], context, editMode } = this.context;
|
|
24
|
+
this.pluginsRefs.length = config.items.length;
|
|
25
|
+
const sortedItems = this.getSortedLayoutItems();
|
|
26
|
+
let indexOffset = 0;
|
|
27
|
+
return (React.createElement("div", { className: b() }, groups.map((group) => {
|
|
28
|
+
const groupId = group.id || DEFAULT_GROUP;
|
|
29
|
+
const items = sortedItems[groupId];
|
|
30
|
+
const children = (items || []).map((item, index) => {
|
|
31
|
+
const isItemWithActiveAutoheight = item.id in this.state.itemsWithActiveAutoheight;
|
|
32
|
+
return (React.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
|
|
33
|
+
React.createElement(Item, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.getMemoAdjustWidgetLayout(item.id), forwardedPluginRef: this.getMemoForwardRefCallback(indexOffset + index), onItemMountChange: this.context.onItemMountChange, onItemRender: this.context.onItemRender })));
|
|
51
34
|
});
|
|
52
|
-
|
|
35
|
+
indexOffset += items.length;
|
|
36
|
+
if (group.render) {
|
|
37
|
+
return group.render(groupId, children, {
|
|
38
|
+
isMobile: true,
|
|
39
|
+
config,
|
|
40
|
+
context,
|
|
41
|
+
editMode,
|
|
42
|
+
items,
|
|
43
|
+
layout,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return children;
|
|
47
|
+
})));
|
|
53
48
|
}
|
|
54
49
|
getSortedLayoutItems() {
|
|
55
50
|
if (this.sortedLayoutItems && this.context.layout === this._memoLayout) {
|
|
@@ -57,18 +52,36 @@ class MobileLayout extends React.PureComponent {
|
|
|
57
52
|
}
|
|
58
53
|
this._memoLayout = this.context.layout;
|
|
59
54
|
const hasOrderId = Boolean(this.context.config.items.find((item) => item.orderId));
|
|
60
|
-
this.sortedLayoutItems = getSortedConfigItems(this.context.config, hasOrderId);
|
|
55
|
+
this.sortedLayoutItems = groupBy(getSortedConfigItems(this.context.config, hasOrderId), (item) => item.parent || DEFAULT_GROUP);
|
|
61
56
|
return this.sortedLayoutItems;
|
|
62
57
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
getMemoForwardRefCallback(refIndex) {
|
|
59
|
+
if (!this._memoForwardedPluginRef[refIndex]) {
|
|
60
|
+
this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
|
|
61
|
+
this.pluginsRefs[refIndex] = pluginRef;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return this._memoForwardedPluginRef[refIndex];
|
|
65
|
+
}
|
|
66
|
+
adjustWidgetLayout(id, { needSetDefault }) {
|
|
67
|
+
if (needSetDefault) {
|
|
68
|
+
const indexesOfItemsWithActiveAutoheight = Object.assign({}, this.state.itemsWithActiveAutoheight);
|
|
69
|
+
delete indexesOfItemsWithActiveAutoheight[id];
|
|
70
|
+
this.setState({ itemsWithActiveAutoheight: indexesOfItemsWithActiveAutoheight });
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.setState({
|
|
74
|
+
itemsWithActiveAutoheight: Object.assign({}, this.state.itemsWithActiveAutoheight, {
|
|
75
|
+
[id]: true,
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
getMemoAdjustWidgetLayout(id) {
|
|
81
|
+
if (!this._memoAdjustWidgetLayout[id]) {
|
|
82
|
+
this._memoAdjustWidgetLayout[id] = this.adjustWidgetLayout.bind(this, id);
|
|
83
|
+
}
|
|
84
|
+
return this._memoAdjustWidgetLayout[id];
|
|
72
85
|
}
|
|
73
86
|
}
|
|
74
87
|
MobileLayout.contextType = DashKitContext;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ButtonSize, ButtonView, IconProps, MenuItemProps } from '@gravity-ui/uikit';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { OverlayControlsCtxShape } from '../../context';
|
|
4
|
+
import { type ConfigItem, type ItemParams, type ItemState, type PluginBase } from '../../shared';
|
|
5
5
|
import './OverlayControls.css';
|
|
6
6
|
export declare enum OverlayControlsPosition {
|
|
7
7
|
TopRight = "top_right",
|
|
@@ -25,7 +25,7 @@ export interface OverlayCustomControlItem {
|
|
|
25
25
|
title?: string;
|
|
26
26
|
icon?: MenuItemProps['icon'];
|
|
27
27
|
iconSize?: number | string;
|
|
28
|
-
handler?: (item: ConfigItem, params:
|
|
28
|
+
handler?: (item: ConfigItem, params: ItemParams, state: ItemState) => void;
|
|
29
29
|
visible?: (item: ConfigItem) => boolean;
|
|
30
30
|
className?: string;
|
|
31
31
|
qa?: string;
|
|
@@ -51,21 +51,9 @@ type PreparedCopyItemOptionsArg = Pick<ConfigItem, 'data' | 'type' | 'defaults'
|
|
|
51
51
|
export type PreparedCopyItemOptions<C extends object = {}> = PreparedCopyItemOptionsArg & {
|
|
52
52
|
copyContext?: C;
|
|
53
53
|
};
|
|
54
|
-
export interface OverlayControlsCtxShape {
|
|
55
|
-
overlayControls?: Record<string, OverlayControlItem[]>;
|
|
56
|
-
context: Record<string, any>;
|
|
57
|
-
menu: MenuItem[];
|
|
58
|
-
itemsStateAndParams: ItemsStateAndParamsBase;
|
|
59
|
-
itemsParams: Record<string, StringParams>;
|
|
60
|
-
editItem: (item: ConfigItem) => void;
|
|
61
|
-
removeItem: (id: string) => void;
|
|
62
|
-
getLayoutItem: (id: string) => ConfigLayout | void;
|
|
63
|
-
getPreparedCopyItemOptions?: (options: PreparedCopyItemOptions) => PreparedCopyItemOptions;
|
|
64
|
-
onCopyFulfill?: (error: null | Error, data?: PreparedCopyItemOptions) => void;
|
|
65
|
-
}
|
|
66
54
|
type OverlayControlsCtx = React.Context<OverlayControlsCtxShape>;
|
|
67
55
|
declare class OverlayControls extends React.Component<OverlayControlsProps> {
|
|
68
|
-
static contextType: React.Context<
|
|
56
|
+
static contextType: React.Context<void | OverlayControlsCtxShape>;
|
|
69
57
|
static defaultProps: OverlayControlsDefaultProps;
|
|
70
58
|
context: React.ContextType<OverlayControlsCtx>;
|
|
71
59
|
render(): JSX.Element;
|
|
@@ -3,7 +3,7 @@ import { Ellipsis, Gear, Xmark } from '@gravity-ui/icons';
|
|
|
3
3
|
import { Button, DropdownMenu, Icon, } from '@gravity-ui/uikit';
|
|
4
4
|
import noop from 'lodash/noop';
|
|
5
5
|
import { COPIED_WIDGET_STORE_KEY, DRAGGABLE_CANCEL_CLASS_NAME, MenuItems, OVERLAY_CONTROLS_CLASS_NAME, OVERLAY_ICON_SIZE, } from '../../constants';
|
|
6
|
-
import { DashkitOvelayControlsContext } from '../../context
|
|
6
|
+
import { DashkitOvelayControlsContext } from '../../context';
|
|
7
7
|
import { i18n } from '../../i18n';
|
|
8
8
|
import { isItemWithTabs, resolveItemInnerId, } from '../../shared';
|
|
9
9
|
import { cn } from '../../utils/cn';
|
|
@@ -119,9 +119,9 @@ class OverlayControls extends React.Component {
|
|
|
119
119
|
(_l = (_k = this.props).onItemClick) === null || _l === void 0 ? void 0 : _l.call(_k);
|
|
120
120
|
};
|
|
121
121
|
this.onEditItem = () => {
|
|
122
|
-
var _a, _b;
|
|
123
|
-
this.context.editItem(this.props.configItem);
|
|
124
|
-
(
|
|
122
|
+
var _a, _b, _c, _d;
|
|
123
|
+
(_b = (_a = this.context).editItem) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.configItem);
|
|
124
|
+
(_d = (_c = this.props).onItemClick) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
125
125
|
};
|
|
126
126
|
this.onRemoveItem = () => {
|
|
127
127
|
var _a, _b;
|
|
@@ -192,13 +192,12 @@ class OverlayControls extends React.Component {
|
|
|
192
192
|
return menu === null || menu === void 0 ? void 0 : menu.every((item) => Object.values(MenuItems).includes(String(item)));
|
|
193
193
|
}
|
|
194
194
|
renderDropdownMenu(isOnlyOneItem) {
|
|
195
|
-
var _a;
|
|
196
195
|
const { view, size, onItemClick } = this.props;
|
|
197
|
-
const { menu: contextMenu, itemsParams,
|
|
196
|
+
const { menu: contextMenu, itemsParams, itemsState } = this.context;
|
|
198
197
|
const configItem = this.props.configItem;
|
|
199
198
|
const itemParams = itemsParams[configItem.id];
|
|
200
|
-
const itemState = (
|
|
201
|
-
const menu =
|
|
199
|
+
const itemState = (itemsState === null || itemsState === void 0 ? void 0 : itemsState[configItem.id]) || {};
|
|
200
|
+
const menu = contextMenu && contextMenu.length > 0 ? contextMenu : DEFAULT_DROPDOWN_MENU;
|
|
202
201
|
const isDefaultMenu = this.isDefaultMenu(menu);
|
|
203
202
|
const items = isDefaultMenu
|
|
204
203
|
? (menu || []).reduce((memo, name) => {
|
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
export const DashkitOvelayControlsContext: React.Context<any>;
|
|
3
|
-
export const DashKitDnDContext: React.Context<any>;
|
|
1
|
+
/// <reference types="react-grid-layout" />
|
|
4
2
|
import React from 'react';
|
|
3
|
+
import type { RegisterManager } from '..//utils';
|
|
4
|
+
import type { DashKitProps } from '../components/DashKit';
|
|
5
|
+
import type { ConfigItem, ConfigLayout, ItemParams, ItemState, ItemStateAndParams, ItemStateAndParamsChangeOptions } from '../shared';
|
|
6
|
+
type DashkitPropsPassedToCtx = Pick<DashKitProps, 'config' | 'groups' | 'context' | 'noOverlay' | 'focusable' | 'globalParams' | 'editMode' | 'settings' | 'onItemMountChange' | 'onItemRender' | 'draggableHandleClassName' | 'onDragStart' | 'onDrag' | 'onDragStop' | 'onResizeStart' | 'onResize' | 'onResizeStop'>;
|
|
7
|
+
type PluginType = string;
|
|
8
|
+
export type DashKitCtxShape = DashkitPropsPassedToCtx & {
|
|
9
|
+
registerManager: RegisterManager;
|
|
10
|
+
forwardedMetaRef: React.ForwardedRef<any>;
|
|
11
|
+
layout: ConfigLayout[];
|
|
12
|
+
temporaryLayout: ConfigLayout[] | null;
|
|
13
|
+
memorizeOriginalLayout: (widgetId: string, preAutoHeightLayout: ConfigLayout, postAutoHeightLayout: ConfigLayout) => void;
|
|
14
|
+
revertToOriginalLayout: (widgetId: string) => void;
|
|
15
|
+
itemsState?: Record<string, ItemState>;
|
|
16
|
+
itemsParams: Record<string, ItemParams>;
|
|
17
|
+
onItemStateAndParamsChange: (id: string, stateAndParams: ItemStateAndParams, options: ItemStateAndParamsChangeOptions) => void;
|
|
18
|
+
getItemsMeta: (pluginsRefs: Array<React.RefObject<any>>) => Array<Promise<any>>;
|
|
19
|
+
reloadItems: (pluginsRefs: Array<React.RefObject<any>>, data: {
|
|
20
|
+
silentLoading: boolean;
|
|
21
|
+
noVeil: boolean;
|
|
22
|
+
}) => void;
|
|
23
|
+
onDrop: (newLayout: ConfigLayout, item: ConfigItem) => void;
|
|
24
|
+
onDropDragOver: (e: DragEvent | MouseEvent, group: string | void, gridProps: Partial<ReactGridLayout.ReactGridLayoutProps>, groupLayout: ConfigLayout[], sharedItem: (Partial<ConfigLayout> & {
|
|
25
|
+
type: PluginType;
|
|
26
|
+
}) | void) => void | boolean;
|
|
27
|
+
outerDnDEnable: boolean;
|
|
28
|
+
dragOverPlugin: null | PluginType;
|
|
29
|
+
};
|
|
30
|
+
declare const DashKitContext: React.Context<DashKitCtxShape>;
|
|
31
|
+
export { DashKitContext };
|