From 8bf85d4bc3e0577525dedb9d1b0334a235d162dc Mon Sep 17 00:00:00 2001 From: arvinxx Date: Wed, 14 Jun 2023 20:41:33 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20feat(pro-editor):=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20updateCanvasInteraction=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ProEditor/hooks/useProEditor.ts | 4 +++- src/ProEditor/store/slices/canvas.ts | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/ProEditor/hooks/useProEditor.ts b/src/ProEditor/hooks/useProEditor.ts index 2516da89..e22cf577 100644 --- a/src/ProEditor/hooks/useProEditor.ts +++ b/src/ProEditor/hooks/useProEditor.ts @@ -25,6 +25,7 @@ export const useProEditor = (): ProEditorInstance => { resetConfig, undo, redo, + updateCanvasInteraction, } = storeApi.getState(); const getViewport = useMemoizedFn(() => storeApi.getState().editorAwareness.viewport); @@ -35,10 +36,11 @@ export const useProEditor = (): ProEditorInstance => { return useMemo( () => ({ updateConfig, + updateViewport, + updateCanvasInteraction, deselectCanvas, exportConfig, resetConfig, - updateViewport, undo, redo, undoStack, diff --git a/src/ProEditor/store/slices/canvas.ts b/src/ProEditor/store/slices/canvas.ts index 5b0f68f5..6f71dfff 100644 --- a/src/ProEditor/store/slices/canvas.ts +++ b/src/ProEditor/store/slices/canvas.ts @@ -2,6 +2,7 @@ import { Viewport } from 'reactflow'; import { StateCreator } from 'zustand'; import { InteractStatus, OnInteractionStatusChange } from '@/InteractContainer'; +import { UserActionParams } from '@/ProEditor/utils/yjs'; import { InternalProEditorStore } from '../createStore'; // ======== state ======== // @@ -35,9 +36,16 @@ const initialCanvasState: CanvasSliceState = { export interface CanvasPublicAction { deselectCanvas: () => void; updateViewport: (viewPort: Partial) => void; + updateCanvasInteraction: ( + interaction: InteractStatus, + action?: Partial, + ) => void; } export interface CanvasSlice extends CanvasPublicAction, CanvasSliceState { - internalUpdateCanvasInteract: (interaction: InteractStatus) => void; + internalUpdateCanvasInteract: ( + interaction: InteractStatus, + action?: Partial, + ) => void; toggleCanvasInteraction: () => void; } @@ -49,10 +57,12 @@ export const canvasSlice: StateCreator< > = (set, get) => ({ ...initialCanvasState, //内部更新交互参数方法 - internalUpdateCanvasInteract: (interact) => { + internalUpdateCanvasInteract: (interact, action) => { const { onInteractionChange } = get(); - set({ interaction: interact }, false, '🕹内部更新:interaction'); + set({ interaction: interact }, false, { + type: action?.type || '🕹内部更新:interaction', + }); onInteractionChange?.(interact); }, @@ -72,6 +82,10 @@ export const canvasSlice: StateCreator< internalUpdateCanvasInteract({ status: 'unSelected' }); }, + updateCanvasInteraction: (interaction) => { + get().internalUpdateCanvasInteract(interaction, { name: 'updateCanvasInteraction 触发' }); + }, + updateViewport: (viewPort) => { const { internalUpdateEditorAwareness, editorAwareness } = get();