|
1 | 1 | import { sendAnalytics } from '@/utils/analytics';
|
2 | 2 | import { makeAutoObservable } from 'mobx';
|
3 | 3 | import type { EditorEngine } from '../engine';
|
| 4 | +import { nanoid } from 'nanoid/non-secure'; |
| 5 | +import type { WebFrame } from '../../../../../../../../packages/models/src/project/frame'; |
| 6 | + |
4 | 7 |
|
5 | 8 | export class WindowManager {
|
6 | 9 | constructor(private editorEngine: EditorEngine) {
|
@@ -112,38 +115,38 @@ export class WindowManager {
|
112 | 115 | }
|
113 | 116 |
|
114 | 117 | duplicate(id?: string) {
|
115 |
| - // let settings: Frames | null = null; |
116 |
| - // if (id) { |
117 |
| - // settings = this.canvas.getFrame(id) || null; |
118 |
| - // } else if (this.webviews.selected.length === 0) { |
119 |
| - // console.error('No window selected'); |
120 |
| - // return; |
121 |
| - // } else { |
122 |
| - // settings = this.canvas.getFrame(this.webviews.selected[0].id) || null; |
123 |
| - // } |
124 |
| - // if (!settings) { |
125 |
| - // console.error('Window not found'); |
126 |
| - // return; |
127 |
| - // } |
128 |
| - // const currentFrame = settings; |
129 |
| - // const newFrame: Frames = { |
130 |
| - // id: nanoid(), |
131 |
| - // url: currentFrame.url, |
132 |
| - // dimension: { |
133 |
| - // width: currentFrame.dimension.width, |
134 |
| - // height: currentFrame.dimension.height, |
135 |
| - // }, |
136 |
| - // position: { |
137 |
| - // x: currentFrame.position.x + currentFrame.dimension.width + 100, |
138 |
| - // y: currentFrame.position.y, |
139 |
| - // }, |
140 |
| - // aspectRatioLocked: currentFrame.aspectRatioLocked, |
141 |
| - // orientation: currentFrame.orientation, |
142 |
| - // device: currentFrame.device, |
143 |
| - // theme: currentFrame.theme, |
144 |
| - // }; |
| 118 | + console.log('Duplicating window', id); |
| 119 | + let settings: WebFrame | null = null; |
| 120 | + if (id) { |
| 121 | + settings = this.editorEngine.canvas.getFrame(id) || null; |
| 122 | + } else if (this.editorEngine.frames.selected.length === 0) { |
| 123 | + console.error('No window selected'); |
| 124 | + return; |
| 125 | + } else { |
| 126 | + settings = this.editorEngine.canvas.getFrame(this.editorEngine.frames.selected[0].id) || null; |
| 127 | + } |
| 128 | + if (!settings) { |
| 129 | + console.error('Window not found'); |
| 130 | + return; |
| 131 | + } |
| 132 | + const currentFrame = settings; |
| 133 | + console.log('Current frame', currentFrame); |
| 134 | + const newFrame: WebFrame = { |
| 135 | + id: nanoid(), |
| 136 | + url: currentFrame.url, |
| 137 | + dimension: { |
| 138 | + width: currentFrame.dimension.width, |
| 139 | + height: currentFrame.dimension.height, |
| 140 | + }, |
| 141 | + position: { |
| 142 | + x: currentFrame.position.x + currentFrame.dimension.width + 100, |
| 143 | + y: currentFrame.position.y, |
| 144 | + }, |
| 145 | + type: currentFrame.type, |
| 146 | + windowMetadata : currentFrame.windowMetadata, |
| 147 | + }; |
145 | 148 |
|
146 |
| - // this.canvas.frames = [...this.canvas.frames, newFrame]; |
| 149 | + this.editorEngine.canvas.frames = [...this.editorEngine.canvas.frames, newFrame]; |
147 | 150 | sendAnalytics('window duplicate');
|
148 | 151 | }
|
149 | 152 | }
|
0 commit comments