mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-17 19:06:00 +08:00
parent
dacec716bc
commit
4c9ef87975
@ -112,7 +112,7 @@ export default class ActionManager extends EventEmitter {
|
|||||||
this.dr = new StageDragResize({
|
this.dr = new StageDragResize({
|
||||||
container: config.container,
|
container: config.container,
|
||||||
disabledDragStart: config.disabledDragStart,
|
disabledDragStart: config.disabledDragStart,
|
||||||
moveableOptions: this.changeCallback(config.moveableOptions),
|
moveableOptions: this.changeCallback(config.moveableOptions, false),
|
||||||
dragResizeHelper: createDrHelper(),
|
dragResizeHelper: createDrHelper(),
|
||||||
getRootContainer: config.getRootContainer,
|
getRootContainer: config.getRootContainer,
|
||||||
getRenderDocument: config.getRenderDocument,
|
getRenderDocument: config.getRenderDocument,
|
||||||
@ -121,7 +121,7 @@ export default class ActionManager extends EventEmitter {
|
|||||||
});
|
});
|
||||||
this.multiDr = new StageMultiDragResize({
|
this.multiDr = new StageMultiDragResize({
|
||||||
container: config.container,
|
container: config.container,
|
||||||
multiMoveableOptions: config.multiMoveableOptions,
|
moveableOptions: this.changeCallback(config.moveableOptions, true),
|
||||||
dragResizeHelper: createDrHelper(),
|
dragResizeHelper: createDrHelper(),
|
||||||
getRootContainer: config.getRootContainer,
|
getRootContainer: config.getRootContainer,
|
||||||
getRenderDocument: config.getRenderDocument,
|
getRenderDocument: config.getRenderDocument,
|
||||||
@ -353,14 +353,18 @@ export default class ActionManager extends EventEmitter {
|
|||||||
this.highlightLayer.destroy();
|
this.highlightLayer.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private changeCallback(options: CustomizeMoveableOptions): CustomizeMoveableOptions {
|
private changeCallback(options: CustomizeMoveableOptions, isMulti: boolean): CustomizeMoveableOptions {
|
||||||
// 在actionManager才能获取到各种参数,在这里传好参数有比较好的扩展性
|
// 在actionManager才能获取到各种参数,在这里传好参数有比较好的扩展性
|
||||||
if (typeof options === 'function') {
|
if (typeof options === 'function') {
|
||||||
return () => {
|
return () => {
|
||||||
// 要再判断一次,不然过不了ts检查
|
// 要再判断一次,不然过不了ts检查
|
||||||
if (typeof options === 'function') {
|
if (typeof options === 'function') {
|
||||||
const cfg: CustomizeMoveableOptionsCallbackConfig = {
|
const cfg: CustomizeMoveableOptionsCallbackConfig = {
|
||||||
|
targetEl: this.selectedEl,
|
||||||
targetElId: this.selectedEl?.id,
|
targetElId: this.selectedEl?.id,
|
||||||
|
targetEls: this.selectedElList,
|
||||||
|
targetElIds: this.selectedElList?.map((item) => item.id),
|
||||||
|
isMulti,
|
||||||
};
|
};
|
||||||
return options(cfg);
|
return options(cfg);
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,6 @@ export default class StageCore extends EventEmitter {
|
|||||||
containerHighlightDuration: config.containerHighlightDuration,
|
containerHighlightDuration: config.containerHighlightDuration,
|
||||||
containerHighlightType: config.containerHighlightType,
|
containerHighlightType: config.containerHighlightType,
|
||||||
moveableOptions: config.moveableOptions,
|
moveableOptions: config.moveableOptions,
|
||||||
multiMoveableOptions: config.multiMoveableOptions,
|
|
||||||
container: this.mask.content,
|
container: this.mask.content,
|
||||||
disabledDragStart: config.disabledDragStart,
|
disabledDragStart: config.disabledDragStart,
|
||||||
canSelect: config.canSelect,
|
canSelect: config.canSelect,
|
||||||
|
@ -47,7 +47,7 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
|
|||||||
constructor(config: StageMultiDragResizeConfig) {
|
constructor(config: StageMultiDragResizeConfig) {
|
||||||
const moveableOptionsManagerConfig: MoveableOptionsManagerConfig = {
|
const moveableOptionsManagerConfig: MoveableOptionsManagerConfig = {
|
||||||
container: config.container,
|
container: config.container,
|
||||||
moveableOptions: config.multiMoveableOptions,
|
moveableOptions: config.moveableOptions,
|
||||||
getRootContainer: config.getRootContainer,
|
getRootContainer: config.getRootContainer,
|
||||||
};
|
};
|
||||||
super(moveableOptionsManagerConfig);
|
super(moveableOptionsManagerConfig);
|
||||||
@ -170,10 +170,12 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
|
|||||||
target: this.dragResizeHelper.getShadowEls(),
|
target: this.dragResizeHelper.getShadowEls(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(options);
|
||||||
|
|
||||||
Object.entries(options).forEach(([key, value]) => {
|
Object.entries(options).forEach(([key, value]) => {
|
||||||
(this.moveableForMulti as any)[key] = value;
|
(this.moveableForMulti as any)[key] = value;
|
||||||
});
|
});
|
||||||
this.moveableForMulti.updateTarget();
|
this.moveableForMulti.updateRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,7 +65,6 @@ export interface StageCoreConfig {
|
|||||||
containerHighlightDuration?: number;
|
containerHighlightDuration?: number;
|
||||||
containerHighlightType?: ContainerHighlightType;
|
containerHighlightType?: ContainerHighlightType;
|
||||||
moveableOptions?: CustomizeMoveableOptions;
|
moveableOptions?: CustomizeMoveableOptions;
|
||||||
multiMoveableOptions?: CustomizeMoveableOptions;
|
|
||||||
/** runtime 的HTML地址,可以是一个HTTP地址,如果和编辑器不同域,需要设置跨域,也可以是一个相对或绝对路径 */
|
/** runtime 的HTML地址,可以是一个HTTP地址,如果和编辑器不同域,需要设置跨域,也可以是一个相对或绝对路径 */
|
||||||
runtimeUrl?: string;
|
runtimeUrl?: string;
|
||||||
render?: (renderer: StageCore) => Promise<HTMLElement> | HTMLElement;
|
render?: (renderer: StageCore) => Promise<HTMLElement> | HTMLElement;
|
||||||
@ -80,7 +79,6 @@ export interface ActionManagerConfig {
|
|||||||
containerHighlightDuration?: number;
|
containerHighlightDuration?: number;
|
||||||
containerHighlightType?: ContainerHighlightType;
|
containerHighlightType?: ContainerHighlightType;
|
||||||
moveableOptions?: CustomizeMoveableOptions;
|
moveableOptions?: CustomizeMoveableOptions;
|
||||||
multiMoveableOptions?: CustomizeMoveableOptions;
|
|
||||||
disabledDragStart?: boolean;
|
disabledDragStart?: boolean;
|
||||||
canSelect?: CanSelect;
|
canSelect?: CanSelect;
|
||||||
isContainer: IsContainer;
|
isContainer: IsContainer;
|
||||||
@ -98,7 +96,11 @@ export interface MoveableOptionsManagerConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface CustomizeMoveableOptionsCallbackConfig {
|
export interface CustomizeMoveableOptionsCallbackConfig {
|
||||||
|
targetEl?: HTMLElement;
|
||||||
targetElId?: string;
|
targetElId?: string;
|
||||||
|
targetEls?: HTMLElement[];
|
||||||
|
targetElIds?: string[];
|
||||||
|
isMulti: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StageRenderConfig {
|
export interface StageRenderConfig {
|
||||||
@ -125,7 +127,7 @@ export interface StageDragResizeConfig {
|
|||||||
export interface StageMultiDragResizeConfig {
|
export interface StageMultiDragResizeConfig {
|
||||||
container: HTMLElement;
|
container: HTMLElement;
|
||||||
dragResizeHelper: DragResizeHelper;
|
dragResizeHelper: DragResizeHelper;
|
||||||
multiMoveableOptions?: CustomizeMoveableOptions;
|
moveableOptions?: CustomizeMoveableOptions;
|
||||||
getRootContainer: GetRootContainer;
|
getRootContainer: GetRootContainer;
|
||||||
getRenderDocument: GetRenderDocument;
|
getRenderDocument: GetRenderDocument;
|
||||||
markContainerEnd: MarkContainerEnd;
|
markContainerEnd: MarkContainerEnd;
|
||||||
|
@ -149,14 +149,20 @@ const menu: MenuBarData = {
|
|||||||
const moveableOptions = (config?: CustomizeMoveableOptionsCallbackConfig): MoveableOptions => {
|
const moveableOptions = (config?: CustomizeMoveableOptionsCallbackConfig): MoveableOptions => {
|
||||||
const options: MoveableOptions = {};
|
const options: MoveableOptions = {};
|
||||||
|
|
||||||
|
if (!editor.value) return options;
|
||||||
|
|
||||||
|
const page = editor.value.editorService.get('page');
|
||||||
|
|
||||||
|
const ids = config?.targetElIds || [];
|
||||||
|
let isPage = page && ids.includes(`${page.id}`);
|
||||||
|
|
||||||
|
if (!isPage) {
|
||||||
const id = config?.targetElId;
|
const id = config?.targetElId;
|
||||||
if (!id || !editor.value) return options;
|
if (id) {
|
||||||
|
|
||||||
const node = editor.value.editorService.getNodeById(id);
|
const node = editor.value.editorService.getNodeById(id);
|
||||||
|
isPage = node?.type === NodeType.PAGE;
|
||||||
if (!node) return options;
|
}
|
||||||
|
}
|
||||||
const isPage = node.type === NodeType.PAGE;
|
|
||||||
|
|
||||||
options.draggable = !isPage;
|
options.draggable = !isPage;
|
||||||
options.resizable = !isPage;
|
options.resizable = !isPage;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user