feat(editor): 添加 stage beforeDblclick 钩子,支持拦截默认双击行为

在 StageOptions 和 EditorProps 中新增 beforeDblclick 配置项,
该函数返回 false 或 Promise<false> 时将阻止 stage 默认的双击处理逻辑。

Made-with: Cursor
This commit is contained in:
roymondchen 2026-04-07 19:19:00 +08:00
parent f583c7daec
commit 334569e2d7
4 changed files with 11 additions and 0 deletions

View File

@ -207,6 +207,7 @@ const stageOptions: StageOptions = {
renderType: props.renderType,
guidesOptions: props.guidesOptions,
disabledMultiSelect: props.disabledMultiSelect,
beforeDblclick: props.beforeDblclick,
};
stageOverlayService.set('stageOptions', stageOptions);

View File

@ -98,6 +98,8 @@ export interface EditorProps {
isContainer?: (el: HTMLElement) => boolean | Promise<boolean>;
/** 用于自定义组件树与画布的右键菜单 */
customContentMenu?: CustomContentMenuFunction;
/** 画布双击前的钩子函数,返回 false 则阻止默认的双击行为 */
beforeDblclick?: (event: MouseEvent) => Promise<boolean | void> | boolean | void;
extendFormState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
/** 页面顺序拖拽配置参数 */
pageBarSortOptions?: PageBarSortOptions;

View File

@ -164,10 +164,16 @@ watchEffect(() => {
});
stage.on('dblclick', async (event: MouseEvent) => {
if (props.stageOptions.beforeDblclick) {
const result = await props.stageOptions.beforeDblclick(event);
if (result === false) return;
}
const el = (await stage?.actionManager?.getElementFromPoint(event)) || null;
if (!el) return;
const id = getIdFromEl()(el);
if (id) {
const node = editorService.getNodeById(id);
if (node?.type === 'page-fragment-container' && node.pageFragmentId) {

View File

@ -164,6 +164,8 @@ export interface StageOptions {
disabledMultiSelect?: boolean;
disabledRule?: boolean;
zoom?: number;
/** 画布双击前的钩子函数,返回 false 则阻止默认的双击行为 */
beforeDblclick?: (event: MouseEvent) => Promise<boolean | void> | boolean | void;
}
export interface StoreState {