| 19 | export const innerDragonSymbol = Symbol('innerDragonSymbol'); |
| 20 | |
| 21 | export class Dragon implements IPublicModelDragon { |
| 22 | private readonly [innerDragonSymbol]: IDragon; |
| 23 | |
| 24 | constructor(innerDragon: IDragon, readonly workspaceMode: boolean) { |
| 25 | this[innerDragonSymbol] = innerDragon; |
| 26 | } |
| 27 | |
| 28 | get [dragonSymbol](): IDragon { |
| 29 | if (this.workspaceMode) { |
| 30 | return this[innerDragonSymbol]; |
| 31 | } |
| 32 | const workspace = globalContext.get('workspace'); |
| 33 | let editor = globalContext.get('editor'); |
| 34 | |
| 35 | if (workspace.isActive) { |
| 36 | editor = workspace.window.editor; |
| 37 | } |
| 38 | |
| 39 | const designer = editor.get('designer'); |
| 40 | return designer.dragon; |
| 41 | } |
| 42 | |
| 43 | static create( |
| 44 | dragon: IDragon | null, |
| 45 | workspaceMode: boolean, |
| 46 | ): IPublicModelDragon | null { |
| 47 | if (!dragon) { |
| 48 | return null; |
| 49 | } |
| 50 | return new Dragon(dragon, workspaceMode); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * is dragging or not |
| 55 | */ |
| 56 | get dragging(): boolean { |
| 57 | return this[dragonSymbol].dragging; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * 绑定 dragstart 事件 |
| 62 | * @param func |
| 63 | * @returns |
| 64 | */ |
| 65 | onDragstart(func: (e: IPublicModelLocateEvent) => any): () => void { |
| 66 | return this[dragonSymbol].onDragstart((e: InnerLocateEvent) => func(LocateEvent.create(e)!)); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * 绑定 drag 事件 |
| 71 | * @param func |
| 72 | * @returns |
| 73 | */ |
| 74 | onDrag(func: (e: IPublicModelLocateEvent) => any): () => void { |
| 75 | return this[dragonSymbol].onDrag((e: InnerLocateEvent) => func(LocateEvent.create(e)!)); |
| 76 | } |
| 77 | |
| 78 | /** |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…