mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 04:55:06 +09:00
cleaning up
This commit is contained in:
1 parent
62158f7df5
commit
9631258c45
2 files changed
+24
-27
No files matched your search
+10
-15
@@ -4,6 +4,7 @@ import { TouchBackend } from "react-dnd-touch-backend";
|
||||
import {
|
||||
type Instance,
|
||||
type ChildrenUpdates,
|
||||
type OnChangeChildren,
|
||||
type Data,
|
||||
type Tree,
|
||||
useAllUserProps,
|
||||
@@ -31,8 +32,8 @@ const useElementsTree = (
|
||||
Component: typeof WrapperComponentDev,
|
||||
setRootInstance: (instance: Instance) => void
|
||||
) => {
|
||||
const onChangeChildren = useCallback(
|
||||
(change) => {
|
||||
return useMemo(() => {
|
||||
const onChangeChildren: OnChangeChildren = (change) => {
|
||||
const { instanceId, updates } = change;
|
||||
const updatedRoot = setInstanceChildren(
|
||||
instanceId,
|
||||
@@ -47,19 +48,13 @@ const useElementsTree = (
|
||||
type: "syncInstanceChildrenChange",
|
||||
payload: change,
|
||||
});
|
||||
},
|
||||
[rootInstance, setRootInstance]
|
||||
);
|
||||
|
||||
return useMemo(
|
||||
() =>
|
||||
createElementsTree({
|
||||
instance: rootInstance,
|
||||
Component,
|
||||
onChangeChildren,
|
||||
}),
|
||||
[rootInstance, onChangeChildren, Component]
|
||||
);
|
||||
};
|
||||
return createElementsTree({
|
||||
instance: rootInstance,
|
||||
Component,
|
||||
onChangeChildren,
|
||||
});
|
||||
}, [rootInstance, Component]);
|
||||
};
|
||||
|
||||
const useIsPreviewMode = () => {
|
||||
|
||||
@@ -19,18 +19,20 @@ export type CustomDragLayerProps = {
|
||||
};
|
||||
|
||||
export const CustomDragLayer = ({ onDrag }: CustomDragLayerProps) => {
|
||||
const { itemType, isDragging, initialOffset, clientOffset } = useDragLayer(
|
||||
(monitor) => ({
|
||||
item: monitor.getItem(),
|
||||
itemType: monitor.getItemType() as Instance["component"],
|
||||
initialOffset: monitor.getInitialSourceClientOffset(),
|
||||
isDragging: monitor.isDragging(),
|
||||
clientOffset: monitor.getClientOffset(),
|
||||
})
|
||||
);
|
||||
const {
|
||||
itemType: component,
|
||||
isDragging,
|
||||
initialOffset,
|
||||
clientOffset,
|
||||
} = useDragLayer((monitor) => ({
|
||||
itemType: monitor.getItemType() as Instance["component"],
|
||||
initialOffset: monitor.getInitialSourceClientOffset(),
|
||||
isDragging: monitor.isDragging(),
|
||||
clientOffset: monitor.getClientOffset(),
|
||||
}));
|
||||
|
||||
useEffect(() => {
|
||||
if (clientOffset === null || initialOffset === null || itemType === null) {
|
||||
if (clientOffset === null || initialOffset === null || component === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -41,9 +43,9 @@ export const CustomDragLayer = ({ onDrag }: CustomDragLayerProps) => {
|
||||
|
||||
onDrag({
|
||||
currentOffset,
|
||||
component: itemType,
|
||||
component,
|
||||
});
|
||||
}, [clientOffset, initialOffset, itemType, onDrag]);
|
||||
}, [clientOffset, initialOffset, component, onDrag]);
|
||||
|
||||
if (isDragging === false) return null;
|
||||
|
||||
|
||||
Reference in new issue
Block a user