-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): remove dndkit in split view
- Loading branch information
Showing
20 changed files
with
546 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'; | ||
import type { | ||
BaseEventPayload, | ||
ElementDragType, | ||
} from '@atlaskit/pragmatic-drag-and-drop/types'; | ||
import { useEffect, useMemo } from 'react'; | ||
|
||
import type { DNDData } from './types'; | ||
|
||
type MonitorGetFeedback<D extends DNDData = DNDData> = Parameters< | ||
NonNullable<Parameters<typeof monitorForElements>[0]['canMonitor']> | ||
>[0] & { | ||
source: { | ||
data: D['draggable']; | ||
}; | ||
}; | ||
|
||
type MonitorGet<T, D extends DNDData = DNDData> = | ||
| T | ||
| ((data: MonitorGetFeedback<D>) => T); | ||
|
||
export interface MonitorOptions<D extends DNDData = DNDData> { | ||
canMonitor?: MonitorGet<boolean, D>; | ||
onDragStart?: (data: BaseEventPayload<ElementDragType>) => void; | ||
onDrag?: (data: BaseEventPayload<ElementDragType>) => void; | ||
onDrop?: (data: BaseEventPayload<ElementDragType>) => void; | ||
onDropTargetChange?: (data: BaseEventPayload<ElementDragType>) => void; | ||
} | ||
|
||
function monitorGet<T>( | ||
get: T | ||
): T extends undefined | ||
? undefined | ||
: T extends MonitorGet<infer I> | ||
? (args: MonitorGetFeedback) => I | ||
: never { | ||
if (get === undefined) { | ||
return undefined as any; | ||
} | ||
return ((args: MonitorGetFeedback) => | ||
typeof get === 'function' ? (get as any)(args) : get) as any; | ||
} | ||
|
||
export const useDndMonitor = <D extends DNDData = DNDData>( | ||
getOptions: () => MonitorOptions<D> = () => ({}), | ||
deps: any[] = [] | ||
) => { | ||
const options = useMemo(() => { | ||
const opts = getOptions(); | ||
return { | ||
...opts, | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [...deps, getOptions]); | ||
|
||
useEffect(() => { | ||
return monitorForElements({ | ||
canMonitor: monitorGet(options.canMonitor), | ||
onDragStart: monitorGet(options.onDragStart), | ||
onDrag: monitorGet(options.onDrag), | ||
onDrop: monitorGet(options.onDrop), | ||
onDropTargetChange: monitorGet(options.onDropTargetChange), | ||
}); | ||
}, [options]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './observe-intersection'; | ||
export * from './observe-resize'; | ||
export * from './shallow-equal'; | ||
export { startScopedViewTransition } from './view-transition'; | ||
export * from './with-unit'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// credit: https://github.com/facebook/fbjs/blob/main/packages/fbjs/src/core/shallowEqual.js | ||
export function shallowEqual(objA: any, objB: any) { | ||
if (Object.is(objA, objB)) { | ||
return true; | ||
} | ||
|
||
if ( | ||
typeof objA !== 'object' || | ||
objA === null || | ||
typeof objB !== 'object' || | ||
objB === null | ||
) { | ||
return false; | ||
} | ||
|
||
const keysA = Object.keys(objA); | ||
const keysB = Object.keys(objB); | ||
|
||
if (keysA.length !== keysB.length) { | ||
return false; | ||
} | ||
|
||
// Test for A's keys different from B. | ||
for (const key of keysA) { | ||
if ( | ||
!Object.prototype.hasOwnProperty.call(objB, key) || | ||
!Object.is(objA[key], objB[key]) | ||
) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/frontend/core/src/modules/workbench/view/split-view/context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createContext } from 'react'; | ||
|
||
import type { View } from '../../entities/view'; | ||
|
||
export interface SplitViewContextType { | ||
draggingView: View | null; | ||
setDraggingView: (view: View | null) => void; | ||
droppingIndex: number | null; | ||
setDroppingIndex: (index: number | null) => void; | ||
} | ||
|
||
export const SplitViewContext = createContext<SplitViewContextType>({ | ||
draggingView: null, | ||
setDraggingView: () => {}, | ||
droppingIndex: null, | ||
setDroppingIndex: () => {}, | ||
}); |
Oops, something went wrong.