mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-04-23 10:18:55 +00:00
feat(editor): 添加 stage beforeDblclick 钩子,支持拦截默认双击行为
在 StageOptions 和 EditorProps 中新增 beforeDblclick 配置项, 该函数返回 false 或 Promise<false> 时将阻止 stage 默认的双击处理逻辑。 Made-with: Cursor
This commit is contained in:
parent
f583c7daec
commit
334569e2d7
@ -207,6 +207,7 @@ const stageOptions: StageOptions = {
|
|||||||
renderType: props.renderType,
|
renderType: props.renderType,
|
||||||
guidesOptions: props.guidesOptions,
|
guidesOptions: props.guidesOptions,
|
||||||
disabledMultiSelect: props.disabledMultiSelect,
|
disabledMultiSelect: props.disabledMultiSelect,
|
||||||
|
beforeDblclick: props.beforeDblclick,
|
||||||
};
|
};
|
||||||
|
|
||||||
stageOverlayService.set('stageOptions', stageOptions);
|
stageOverlayService.set('stageOptions', stageOptions);
|
||||||
|
|||||||
@ -98,6 +98,8 @@ export interface EditorProps {
|
|||||||
isContainer?: (el: HTMLElement) => boolean | Promise<boolean>;
|
isContainer?: (el: HTMLElement) => boolean | Promise<boolean>;
|
||||||
/** 用于自定义组件树与画布的右键菜单 */
|
/** 用于自定义组件树与画布的右键菜单 */
|
||||||
customContentMenu?: CustomContentMenuFunction;
|
customContentMenu?: CustomContentMenuFunction;
|
||||||
|
/** 画布双击前的钩子函数,返回 false 则阻止默认的双击行为 */
|
||||||
|
beforeDblclick?: (event: MouseEvent) => Promise<boolean | void> | boolean | void;
|
||||||
extendFormState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
extendFormState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
||||||
/** 页面顺序拖拽配置参数 */
|
/** 页面顺序拖拽配置参数 */
|
||||||
pageBarSortOptions?: PageBarSortOptions;
|
pageBarSortOptions?: PageBarSortOptions;
|
||||||
|
|||||||
@ -164,10 +164,16 @@ watchEffect(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
stage.on('dblclick', async (event: MouseEvent) => {
|
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;
|
const el = (await stage?.actionManager?.getElementFromPoint(event)) || null;
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
|
|
||||||
const id = getIdFromEl()(el);
|
const id = getIdFromEl()(el);
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
const node = editorService.getNodeById(id);
|
const node = editorService.getNodeById(id);
|
||||||
if (node?.type === 'page-fragment-container' && node.pageFragmentId) {
|
if (node?.type === 'page-fragment-container' && node.pageFragmentId) {
|
||||||
|
|||||||
@ -164,6 +164,8 @@ export interface StageOptions {
|
|||||||
disabledMultiSelect?: boolean;
|
disabledMultiSelect?: boolean;
|
||||||
disabledRule?: boolean;
|
disabledRule?: boolean;
|
||||||
zoom?: number;
|
zoom?: number;
|
||||||
|
/** 画布双击前的钩子函数,返回 false 则阻止默认的双击行为 */
|
||||||
|
beforeDblclick?: (event: MouseEvent) => Promise<boolean | void> | boolean | void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StoreState {
|
export interface StoreState {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user