From 6a34cc1491817ef1d70ecc44ed31179db57db2aa Mon Sep 17 00:00:00 2001 From: JzoNg Date: Tue, 2 Jun 2026 11:32:05 +0800 Subject: [PATCH] fix(web): fix merge error --- .../workflow/store/workflow/workflow-slice.ts | 144 +++++++++--------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/web/app/components/workflow/store/workflow/workflow-slice.ts b/web/app/components/workflow/store/workflow/workflow-slice.ts index 0034e9f229e..f80944d0dcd 100644 --- a/web/app/components/workflow/store/workflow/workflow-slice.ts +++ b/web/app/components/workflow/store/workflow/workflow-slice.ts @@ -1,4 +1,5 @@ import type { StateCreator } from 'zustand' +import type { PointerPosition } from '../../utils/pointer-position' import type { Edge, Node, @@ -6,7 +7,7 @@ import type { WorkflowRunningData, } from '@/app/components/workflow/types' import type { FileUploadConfigResponse } from '@/models/common' -import { getLocalStorageItem, setLocalStorageItem } from '@/utils/local-storage' +import { DEFAULT_POINTER_POSITION } from '../../utils/pointer-position' type PreviewRunningData = WorkflowRunningData & { resultTabActive?: boolean @@ -15,21 +16,6 @@ type PreviewRunningData = WorkflowRunningData & { extraContentAndFormData?: Record } -type MousePosition = { - pageX: number - pageY: number - elementX: number - elementY: number -} - -const getStoredControlMode = () => { - const storedControlMode = getLocalStorageItem('workflow-operation-mode') - if (storedControlMode === 'pointer' || storedControlMode === 'hand' || storedControlMode === 'comment') - return storedControlMode - - return 'pointer' -} - export type WorkflowSliceShape = { workflowRunningData?: PreviewRunningData setWorkflowRunningData: (workflowData: PreviewRunningData) => void @@ -56,7 +42,7 @@ export type WorkflowSliceShape = { setBundleNodeSize: (bundleNodeSize: WorkflowSliceShape['bundleNodeSize']) => void controlMode: 'pointer' | 'hand' | 'comment' setControlMode: (controlMode: WorkflowSliceShape['controlMode']) => void - pendingComment: MousePosition | null + pendingComment: PointerPosition | null setPendingComment: (pendingComment: WorkflowSliceShape['pendingComment']) => void isCommentPlacing: boolean setCommentPlacing: (isCommentPlacing: boolean) => void @@ -64,8 +50,9 @@ export type WorkflowSliceShape = { setCommentQuickAdd: (isCommentQuickAdd: boolean) => void isCommentPreviewHovering: boolean setCommentPreviewHovering: (hovering: boolean) => void - mousePosition: { pageX: number, pageY: number, elementX: number, elementY: number } - setMousePosition: (mousePosition: WorkflowSliceShape['mousePosition']) => void + pointerPositionRef: { current: PointerPosition } + getPointerPosition: () => PointerPosition + setPointerPosition: (pointerPosition: PointerPosition) => void showConfirm?: { title: string, desc?: string, onConfirm: () => void } setShowConfirm: (showConfirm: WorkflowSliceShape['showConfirm']) => void controlPromptEditorRerenderKey: number @@ -76,56 +63,69 @@ export type WorkflowSliceShape = { setFileUploadConfig: (fileUploadConfig: FileUploadConfigResponse) => void } -export const createWorkflowSlice: StateCreator = set => ({ - workflowRunningData: undefined, - setWorkflowRunningData: workflowRunningData => set(() => ({ workflowRunningData })), - isListening: false, - setIsListening: listening => set(() => ({ isListening: listening })), - canvasReadOnly: false, - setCanvasReadOnly: canvasReadOnly => set(() => ({ canvasReadOnly })), - listeningTriggerType: null, - setListeningTriggerType: triggerType => set(() => ({ listeningTriggerType: triggerType })), - listeningTriggerNodeId: null, - setListeningTriggerNodeId: nodeId => set(() => ({ listeningTriggerNodeId: nodeId })), - listeningTriggerNodeIds: [], - setListeningTriggerNodeIds: nodeIds => set(() => ({ listeningTriggerNodeIds: nodeIds })), - listeningTriggerIsAll: false, - setListeningTriggerIsAll: isAll => set(() => ({ listeningTriggerIsAll: isAll })), - clipboardElements: [], - clipboardEdges: [], - setClipboardElements: clipboardElements => set(() => ({ clipboardElements })), - setClipboardEdges: clipboardEdges => set(() => ({ clipboardEdges })), - setClipboardData: ({ nodes, edges }) => { - set(() => ({ - clipboardElements: nodes, - clipboardEdges: edges, - })) - }, - selection: null, - setSelection: selection => set(() => ({ selection })), - bundleNodeSize: null, - setBundleNodeSize: bundleNodeSize => set(() => ({ bundleNodeSize })), - controlMode: getStoredControlMode(), - setControlMode: (controlMode) => { - set(() => ({ controlMode })) - setLocalStorageItem('workflow-operation-mode', controlMode) - }, - pendingComment: null, - setPendingComment: pendingComment => set(() => ({ pendingComment })), - isCommentPlacing: false, - setCommentPlacing: isCommentPlacing => set(() => ({ isCommentPlacing })), - isCommentQuickAdd: false, - setCommentQuickAdd: isCommentQuickAdd => set(() => ({ isCommentQuickAdd })), - mousePosition: { pageX: 0, pageY: 0, elementX: 0, elementY: 0 }, - setMousePosition: mousePosition => set(() => ({ mousePosition })), - isCommentPreviewHovering: false, - setCommentPreviewHovering: hovering => set(() => ({ isCommentPreviewHovering: hovering })), - showConfirm: undefined, - setShowConfirm: showConfirm => set(() => ({ showConfirm })), - controlPromptEditorRerenderKey: 0, - setControlPromptEditorRerenderKey: controlPromptEditorRerenderKey => set(() => ({ controlPromptEditorRerenderKey })), - showImportDSLModal: false, - setShowImportDSLModal: showImportDSLModal => set(() => ({ showImportDSLModal })), - fileUploadConfig: undefined, - setFileUploadConfig: fileUploadConfig => set(() => ({ fileUploadConfig })), -}) +export const createWorkflowSlice: StateCreator = (set) => { + const pointerPositionRef = { current: DEFAULT_POINTER_POSITION } + + return { + workflowRunningData: undefined, + setWorkflowRunningData: workflowRunningData => set(() => ({ workflowRunningData })), + isListening: false, + setIsListening: listening => set(() => ({ isListening: listening })), + canvasReadOnly: false, + setCanvasReadOnly: canvasReadOnly => set(() => ({ canvasReadOnly })), + listeningTriggerType: null, + setListeningTriggerType: triggerType => set(() => ({ listeningTriggerType: triggerType })), + listeningTriggerNodeId: null, + setListeningTriggerNodeId: nodeId => set(() => ({ listeningTriggerNodeId: nodeId })), + listeningTriggerNodeIds: [], + setListeningTriggerNodeIds: nodeIds => set(() => ({ listeningTriggerNodeIds: nodeIds })), + listeningTriggerIsAll: false, + setListeningTriggerIsAll: isAll => set(() => ({ listeningTriggerIsAll: isAll })), + clipboardElements: [], + clipboardEdges: [], + setClipboardElements: clipboardElements => set(() => ({ clipboardElements })), + setClipboardEdges: clipboardEdges => set(() => ({ clipboardEdges })), + setClipboardData: ({ nodes, edges }) => { + set(() => ({ + clipboardElements: nodes, + clipboardEdges: edges, + })) + }, + selection: null, + setSelection: selection => set(() => ({ selection })), + bundleNodeSize: null, + setBundleNodeSize: bundleNodeSize => set(() => ({ bundleNodeSize })), + controlMode: (() => { + const storedControlMode = localStorage.getItem('workflow-operation-mode') + if (storedControlMode === 'pointer' || storedControlMode === 'hand' || storedControlMode === 'comment') + return storedControlMode + + return 'pointer' + })(), + setControlMode: (controlMode) => { + set(() => ({ controlMode })) + localStorage.setItem('workflow-operation-mode', controlMode) + }, + pendingComment: null, + setPendingComment: pendingComment => set(() => ({ pendingComment })), + isCommentPlacing: false, + setCommentPlacing: isCommentPlacing => set(() => ({ isCommentPlacing })), + isCommentQuickAdd: false, + setCommentQuickAdd: isCommentQuickAdd => set(() => ({ isCommentQuickAdd })), + pointerPositionRef, + getPointerPosition: () => pointerPositionRef.current, + setPointerPosition: (pointerPosition) => { + pointerPositionRef.current = pointerPosition + }, + isCommentPreviewHovering: false, + setCommentPreviewHovering: hovering => set(() => ({ isCommentPreviewHovering: hovering })), + showConfirm: undefined, + setShowConfirm: showConfirm => set(() => ({ showConfirm })), + controlPromptEditorRerenderKey: 0, + setControlPromptEditorRerenderKey: controlPromptEditorRerenderKey => set(() => ({ controlPromptEditorRerenderKey })), + showImportDSLModal: false, + setShowImportDSLModal: showImportDSLModal => set(() => ({ showImportDSLModal })), + fileUploadConfig: undefined, + setFileUploadConfig: fileUploadConfig => set(() => ({ fileUploadConfig })), + } +}