mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-04 10:49:51 +08:00 
			
		
		
		
	feat(stage): elementGuidelines可以配置
This commit is contained in:
		
							parent
							
								
									a320823992
								
							
						
					
					
						commit
						85164ec432
					
				@ -166,16 +166,12 @@ export default class StageDragResize extends EventEmitter {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    this.updateDragEl(el);
 | 
					    this.updateDragEl(el);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.setElementGuidelines(el);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    this.moveableOptions = this.getOptions({
 | 
					    this.moveableOptions = this.getOptions({
 | 
				
			||||||
      target: this.dragEl,
 | 
					      target: this.dragEl,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private setElementGuidelines(el: HTMLElement) {
 | 
					  private setElementGuidelines(nodes: HTMLElement[]) {
 | 
				
			||||||
    const nodes = el.parentElement?.children || [];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    this.elementGuidelines.forEach((node) => {
 | 
					    this.elementGuidelines.forEach((node) => {
 | 
				
			||||||
      node.remove();
 | 
					      node.remove();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
@ -186,7 +182,7 @@ export default class StageDragResize extends EventEmitter {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      for (const node of nodes) {
 | 
					      for (const node of nodes) {
 | 
				
			||||||
        const { width, height } = node.getBoundingClientRect();
 | 
					        const { width, height } = node.getBoundingClientRect();
 | 
				
			||||||
        if (node === el) continue;
 | 
					        if (node === this.target) continue;
 | 
				
			||||||
        const { left, top } = getOffset(node as HTMLElement);
 | 
					        const { left, top } = getOffset(node as HTMLElement);
 | 
				
			||||||
        const elementGuideline = document.createElement('div');
 | 
					        const elementGuideline = document.createElement('div');
 | 
				
			||||||
        elementGuideline.style.cssText = `position: absolute;width: ${width}px;height: ${height}px;top: ${top}px;left: ${left}px`;
 | 
					        elementGuideline.style.cssText = `position: absolute;width: ${width}px;height: ${height}px;top: ${top}px;left: ${left}px`;
 | 
				
			||||||
@ -404,6 +400,14 @@ export default class StageDragResize extends EventEmitter {
 | 
				
			|||||||
      moveableOptions = moveableOptions(this.core);
 | 
					      moveableOptions = moveableOptions(this.core);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const elementGuidelines: any = moveableOptions.elementGuidelines || this.target.parentElement?.children || [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this.setElementGuidelines(elementGuidelines);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (moveableOptions.elementGuidelines) {
 | 
				
			||||||
 | 
					      delete moveableOptions.elementGuidelines;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      origin: false,
 | 
					      origin: false,
 | 
				
			||||||
      rootContainer: this.core.container,
 | 
					      rootContainer: this.core.container,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user