From 3a11f73b26f388c934ea107bf0e8f1b148cf7043 Mon Sep 17 00:00:00 2001 From: janryWang Date: Sat, 12 Jun 2021 11:06:57 +0800 Subject: [PATCH] feat(react): support useNodeIdProps --- packages/core/src/effects/useDragDropEffect.ts | 2 +- packages/react/src/hooks/index.ts | 1 + packages/react/src/hooks/useNodeIdProps.ts | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 packages/react/src/hooks/useNodeIdProps.ts diff --git a/packages/core/src/effects/useDragDropEffect.ts b/packages/core/src/effects/useDragDropEffect.ts index ca8851c06..45986a143 100644 --- a/packages/core/src/effects/useDragDropEffect.ts +++ b/packages/core/src/effects/useDragDropEffect.ts @@ -5,7 +5,7 @@ import { DragStopEvent, ViewportScrollEvent, } from '../events' -import { Point, requestIdle } from '@designable/shared' +import { Point } from '@designable/shared' export const useDragDropEffect = (engine: Engine) => { engine.subscribeTo(DragStartEvent, (event) => { diff --git a/packages/react/src/hooks/index.ts b/packages/react/src/hooks/index.ts index 8a3cd1d10..0b4d61cb8 100644 --- a/packages/react/src/hooks/index.ts +++ b/packages/react/src/hooks/index.ts @@ -17,3 +17,4 @@ export * from './useRegistry' export * from './useValidNodeOffsetRect' export * from './useViewportDragon' export * from './useOutlineDragon' +export * from './useNodeIdProps' diff --git a/packages/react/src/hooks/useNodeIdProps.ts b/packages/react/src/hooks/useNodeIdProps.ts new file mode 100644 index 000000000..855914a19 --- /dev/null +++ b/packages/react/src/hooks/useNodeIdProps.ts @@ -0,0 +1,10 @@ +import { useDesigner } from './useDesigner' +import { useTreeNode } from './useTreeNode' + +export const useNodeIdProps = () => { + const node = useTreeNode() + const designer = useDesigner() + return { + [designer.props.nodeIdAttrName]: node.id, + } +}