mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-04 08:38:34 +00:00
feat(core): init organize (#7456)
This commit is contained in:
@@ -43,10 +43,16 @@ export interface DraggableOptions<D extends DNDData = DNDData> {
|
||||
}>;
|
||||
canDrag?: DraggableGet<boolean>;
|
||||
disableDragPreview?: boolean;
|
||||
dragPreviewPosition?: DraggableDragPreviewPosition;
|
||||
}
|
||||
|
||||
export type DraggableDragPreviewPosition =
|
||||
| 'pointer-outside'
|
||||
| 'pointer-center'
|
||||
| 'native';
|
||||
|
||||
export type DraggableCustomDragPreviewProps = React.PropsWithChildren<{
|
||||
position?: 'pointer-outside' | 'pointer-center' | 'native';
|
||||
position?: DraggableDragPreviewPosition;
|
||||
}>;
|
||||
|
||||
export const useDraggable = <D extends DNDData = DNDData>(
|
||||
@@ -172,9 +178,11 @@ export const useDraggable = <D extends DNDData = DNDData>(
|
||||
disableNativeDragPreview({ nativeSetDragImage });
|
||||
return;
|
||||
}
|
||||
|
||||
let previewPosition: DraggableDragPreviewPosition =
|
||||
options.dragPreviewPosition ?? 'native';
|
||||
|
||||
if (enableCustomDragPreview.current) {
|
||||
let previewPosition: DraggableCustomDragPreviewProps['position'] =
|
||||
'native';
|
||||
setCustomNativeDragPreview({
|
||||
getOffset: (...args) => {
|
||||
if (previewPosition === 'pointer-center') {
|
||||
@@ -199,7 +207,7 @@ export const useDraggable = <D extends DNDData = DNDData>(
|
||||
children,
|
||||
position,
|
||||
}: DraggableCustomDragPreviewProps) => {
|
||||
previewPosition = position;
|
||||
previewPosition = position || previewPosition;
|
||||
return ReactDOM.createPortal(children, container);
|
||||
}
|
||||
);
|
||||
@@ -208,6 +216,28 @@ export const useDraggable = <D extends DNDData = DNDData>(
|
||||
},
|
||||
nativeSetDragImage,
|
||||
});
|
||||
} else if (previewPosition !== 'native') {
|
||||
setCustomNativeDragPreview({
|
||||
getOffset: (...args) => {
|
||||
if (previewPosition === 'pointer-center') {
|
||||
return centerUnderPointer(...args);
|
||||
} else if (previewPosition === 'pointer-outside') {
|
||||
return pointerOutsideOfPreview({
|
||||
x: '8px',
|
||||
y: '4px',
|
||||
})(...args);
|
||||
} else {
|
||||
return preserveOffsetOnSource({
|
||||
element: source.element,
|
||||
input: location.current.input,
|
||||
})(...args);
|
||||
}
|
||||
},
|
||||
render({ container }) {
|
||||
container.append(source.element.cloneNode(true));
|
||||
},
|
||||
nativeSetDragImage,
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user