Skip to content

Commit

Permalink
fix(stage,playground): moveableOptions对多选无效
Browse files Browse the repository at this point in the history
fix #529
  • Loading branch information
roymondchen committed Aug 8, 2023
1 parent dacec71 commit 4c9ef87
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
10 changes: 7 additions & 3 deletions packages/stage/src/ActionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default class ActionManager extends EventEmitter {
this.dr = new StageDragResize({
container: config.container,
disabledDragStart: config.disabledDragStart,
moveableOptions: this.changeCallback(config.moveableOptions),
moveableOptions: this.changeCallback(config.moveableOptions, false),
dragResizeHelper: createDrHelper(),
getRootContainer: config.getRootContainer,
getRenderDocument: config.getRenderDocument,
Expand All @@ -121,7 +121,7 @@ export default class ActionManager extends EventEmitter {
});
this.multiDr = new StageMultiDragResize({
container: config.container,
multiMoveableOptions: config.multiMoveableOptions,
moveableOptions: this.changeCallback(config.moveableOptions, true),
dragResizeHelper: createDrHelper(),
getRootContainer: config.getRootContainer,
getRenderDocument: config.getRenderDocument,
Expand Down Expand Up @@ -353,14 +353,18 @@ export default class ActionManager extends EventEmitter {
this.highlightLayer.destroy();
}

private changeCallback(options: CustomizeMoveableOptions): CustomizeMoveableOptions {
private changeCallback(options: CustomizeMoveableOptions, isMulti: boolean): CustomizeMoveableOptions {
// 在actionManager才能获取到各种参数,在这里传好参数有比较好的扩展性
if (typeof options === 'function') {
return () => {
// 要再判断一次,不然过不了ts检查
if (typeof options === 'function') {
const cfg: CustomizeMoveableOptionsCallbackConfig = {
targetEl: this.selectedEl,
targetElId: this.selectedEl?.id,
targetEls: this.selectedElList,
targetElIds: this.selectedElList?.map((item) => item.id),
isMulti,
};
return options(cfg);
}
Expand Down
1 change: 0 additions & 1 deletion packages/stage/src/StageCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ export default class StageCore extends EventEmitter {
containerHighlightDuration: config.containerHighlightDuration,
containerHighlightType: config.containerHighlightType,
moveableOptions: config.moveableOptions,
multiMoveableOptions: config.multiMoveableOptions,
container: this.mask.content,
disabledDragStart: config.disabledDragStart,
canSelect: config.canSelect,
Expand Down
6 changes: 4 additions & 2 deletions packages/stage/src/StageMultiDragResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
constructor(config: StageMultiDragResizeConfig) {
const moveableOptionsManagerConfig: MoveableOptionsManagerConfig = {
container: config.container,
moveableOptions: config.multiMoveableOptions,
moveableOptions: config.moveableOptions,
getRootContainer: config.getRootContainer,
};
super(moveableOptionsManagerConfig);
Expand Down Expand Up @@ -170,10 +170,12 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
target: this.dragResizeHelper.getShadowEls(),
});

console.log(options);

Object.entries(options).forEach(([key, value]) => {
(this.moveableForMulti as any)[key] = value;
});
this.moveableForMulti.updateTarget();
this.moveableForMulti.updateRect();
}

/**
Expand Down
8 changes: 5 additions & 3 deletions packages/stage/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export interface StageCoreConfig {
containerHighlightDuration?: number;
containerHighlightType?: ContainerHighlightType;
moveableOptions?: CustomizeMoveableOptions;
multiMoveableOptions?: CustomizeMoveableOptions;
/** runtime 的HTML地址,可以是一个HTTP地址,如果和编辑器不同域,需要设置跨域,也可以是一个相对或绝对路径 */
runtimeUrl?: string;
render?: (renderer: StageCore) => Promise<HTMLElement> | HTMLElement;
Expand All @@ -80,7 +79,6 @@ export interface ActionManagerConfig {
containerHighlightDuration?: number;
containerHighlightType?: ContainerHighlightType;
moveableOptions?: CustomizeMoveableOptions;
multiMoveableOptions?: CustomizeMoveableOptions;
disabledDragStart?: boolean;
canSelect?: CanSelect;
isContainer: IsContainer;
Expand All @@ -98,7 +96,11 @@ export interface MoveableOptionsManagerConfig {
}

export interface CustomizeMoveableOptionsCallbackConfig {
targetEl?: HTMLElement;
targetElId?: string;
targetEls?: HTMLElement[];
targetElIds?: string[];
isMulti: boolean;
}

export interface StageRenderConfig {
Expand All @@ -125,7 +127,7 @@ export interface StageDragResizeConfig {
export interface StageMultiDragResizeConfig {
container: HTMLElement;
dragResizeHelper: DragResizeHelper;
multiMoveableOptions?: CustomizeMoveableOptions;
moveableOptions?: CustomizeMoveableOptions;
getRootContainer: GetRootContainer;
getRenderDocument: GetRenderDocument;
markContainerEnd: MarkContainerEnd;
Expand Down
16 changes: 11 additions & 5 deletions playground/src/pages/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,20 @@ const menu: MenuBarData = {
const moveableOptions = (config?: CustomizeMoveableOptionsCallbackConfig): MoveableOptions => {
const options: MoveableOptions = {};
const id = config?.targetElId;
if (!id || !editor.value) return options;
if (!editor.value) return options;
const node = editor.value.editorService.getNodeById(id);
const page = editor.value.editorService.get('page');
if (!node) return options;
const ids = config?.targetElIds || [];
let isPage = page && ids.includes(`${page.id}`);
const isPage = node.type === NodeType.PAGE;
if (!isPage) {
const id = config?.targetElId;
if (id) {
const node = editor.value.editorService.getNodeById(id);
isPage = node?.type === NodeType.PAGE;
}
}
options.draggable = !isPage;
options.resizable = !isPage;
Expand Down

0 comments on commit 4c9ef87

Please sign in to comment.