Skip to content

Commit

Permalink
✨ feat(pro-editor): 增加 updateCanvasInteraction 方法
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Jun 14, 2023
1 parent 951d3ac commit 8bf85d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/ProEditor/hooks/useProEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const useProEditor = <T>(): ProEditorInstance<T> => {
resetConfig,
undo,
redo,
updateCanvasInteraction,
} = storeApi.getState();

const getViewport = useMemoizedFn(() => storeApi.getState().editorAwareness.viewport);
Expand All @@ -35,10 +36,11 @@ export const useProEditor = <T>(): ProEditorInstance<T> => {
return useMemo(
() => ({
updateConfig,
updateViewport,
updateCanvasInteraction,
deselectCanvas,
exportConfig,
resetConfig,
updateViewport,
undo,
redo,
undoStack,
Expand Down
20 changes: 17 additions & 3 deletions src/ProEditor/store/slices/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ======== //
Expand Down Expand Up @@ -35,9 +36,16 @@ const initialCanvasState: CanvasSliceState = {
export interface CanvasPublicAction {
deselectCanvas: () => void;
updateViewport: (viewPort: Partial<Viewport>) => void;
updateCanvasInteraction: (
interaction: InteractStatus,
action?: Partial<UserActionParams>,
) => void;
}
export interface CanvasSlice extends CanvasPublicAction, CanvasSliceState {
internalUpdateCanvasInteract: (interaction: InteractStatus) => void;
internalUpdateCanvasInteract: (
interaction: InteractStatus,
action?: Partial<UserActionParams>,
) => void;
toggleCanvasInteraction: () => void;
}

Expand All @@ -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);
},
Expand All @@ -72,6 +82,10 @@ export const canvasSlice: StateCreator<
internalUpdateCanvasInteract({ status: 'unSelected' });
},

updateCanvasInteraction: (interaction) => {
get().internalUpdateCanvasInteract(interaction, { name: 'updateCanvasInteraction 触发' });
},

updateViewport: (viewPort) => {
const { internalUpdateEditorAwareness, editorAwareness } = get();

Expand Down

0 comments on commit 8bf85d4

Please sign in to comment.