Skip to content

Commit fbfcdfb

Browse files
author
Yury Kornilov
committed
fix: move withContext from JS to TS
1 parent 224c892 commit fbfcdfb

5 files changed

Lines changed: 165 additions & 59 deletions

File tree

src/components/DashKitView/DashKitView.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ import React from 'react';
22

33
import {DashKitContext} from '../../context';
44
import {withContext} from '../../hocs/withContext';
5+
import type {DashKitWithContextProps} from '../../hocs/withContext';
56
import {useCalcPropsLayout} from '../../hooks/useCalcLayout';
6-
import type {RegisterManager} from '../../utils';
77
import {cn} from '../../utils/cn';
8-
import type {DashKitProps} from '../DashKit';
98
import GridLayout from '../GridLayout/GridLayout';
109
import MobileLayout from '../MobileLayout/MobileLayout';
1110

1211
import './DashKitView.scss';
1312

1413
const b = cn('dashkit');
1514

16-
type DashKitViewProps = DashKitProps & {
17-
registerManager: RegisterManager;
18-
};
15+
type DashKitViewProps = Omit<DashKitWithContextProps, 'layout' | 'forwardedMetaRef'>;
1916

2017
function DashKitView() {
2118
const context = React.useContext(DashKitContext);

src/components/GridLayout/GridLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from '../../constants';
1313
import {DashKitContext} from '../../context';
1414
import type {DashKitCtxShape} from '../../context';
15-
import type {ConfigItem, ConfigLayout} from '../../shared';
15+
import type {ConfigItem, ConfigLayout, DraggedOverItem} from '../../shared';
1616
import {resolveLayoutGroup} from '../../utils';
1717
import GridItem from '../GridItem/GridItem';
1818

@@ -682,7 +682,7 @@ export default class GridLayout extends React.PureComponent<GridLayoutProps, Gri
682682
if (currentDraggingElement) {
683683
const {h, w, i} = currentDraggingElement.layoutItem;
684684
const {type} = currentDraggingElement.item;
685-
const sharedItem = {
685+
const sharedItem: DraggedOverItem = {
686686
h,
687687
w,
688688
i,

src/context/DashKitContext.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React from 'react';
22

3-
import type {RegisterManager} from '..//utils';
3+
import type {DragOverEvent} from 'react-grid-layout';
4+
5+
import type {RegisterManager, RegisterManagerPlugin} from '..//utils';
46
import type {DashKitProps} from '../components/DashKit';
57
import type {
68
ConfigItem,
79
ConfigLayout,
10+
DraggedOverItem,
811
ItemDragProps,
912
ItemParams,
1013
ItemState,
@@ -35,9 +38,7 @@ type DashkitPropsPassedToCtx = Pick<
3538
| 'onResizeStop'
3639
>;
3740

38-
type PluginType = string;
39-
40-
type TemporaryLayout = {
41+
export type TemporaryLayout = {
4142
data: ConfigLayout[];
4243
dragProps: ItemDragProps;
4344
};
@@ -76,16 +77,16 @@ export type DashKitCtxShape = Omit<DashkitPropsPassedToCtx, 'context' | 'setting
7677

7778
onDrop: (newLayout: ConfigLayout[], item: ConfigLayout, e?: MouseEvent) => void;
7879
onDropDragOver: (
79-
e: DragEvent | MouseEvent,
80-
group: string | void,
80+
e: DragOverEvent,
81+
group: string | undefined,
8182
gridProps: ReactGridLayoutProps,
8283
groupLayout: ConfigLayout[],
83-
sharedItem: (Partial<ConfigLayout> & {type: PluginType}) | void,
84+
sharedItem?: DraggedOverItem,
8485
) => {w?: number; h?: number} | false | undefined;
85-
onItemBlur: (item: ConfigItem) => void;
86-
onItemFocus: (item: ConfigItem) => void;
86+
onItemBlur?: (item: ConfigItem) => void;
87+
onItemFocus?: (item: ConfigItem) => void;
8788
outerDnDEnable: boolean;
88-
dragOverPlugin: null | PluginType;
89+
dragOverPlugin: null | RegisterManagerPlugin;
8990
};
9091

9192
const DashKitContext = React.createContext<DashKitCtxShape>({} as DashKitCtxShape);

0 commit comments

Comments
 (0)