Files
Endoleap/src/components/canvas/edge-editing.tsx
T

15 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 连线编辑的React动作上下文。让连线组件调用begin/patch/finish/cancel,并读取当前活动集合。
* 真正的命令、事务和history由Provider注入,默认空实现仅支持未接入编辑器的渲染环境。
*/
"use client";
import { createContext } from "react";
import type { EditingLease } from "./editing-lease";
import type { EdgeData } from "@/lib/canvas-v2";
/** begin可拒绝、使用旧版无返回值模式,或返回绑定手势的EditingLease;patch的transient区分临时预览。
* finish/cancel可选,active为当前活动连线ID集合;默认Set不代表全项目状态仓库。 */
const defaultEditing = { finish: undefined as undefined | (() => void), cancel: undefined as undefined | (() => void), begin: (_id?: string): boolean | void | EditingLease<NonNullable<EdgeData['path']>> => {}, patch: (_id: string, _data: EdgeData, _transient = false) => {}, active: new Set<string>() };
// 默认 active Set 与动作对象是共享引用,未冻结;消费方只能读取,不应通过修改默认对象来发布状态。
/** Context的类型保留可选结束钩子,兼容旧画布与新版租约式交互,不在此创建编辑任务队列。 */
export const EdgeEditing = createContext<Omit<typeof defaultEditing, 'finish' | 'cancel'> & Partial<Pick<typeof defaultEditing, 'finish' | 'cancel'>>>(defaultEditing);