Skip to content

Commit bd69c99

Browse files
Implemented the duplicate web frame feature
1 parent 83320f3 commit bd69c99

File tree

1 file changed

+34
-31
lines changed
  • apps/web/client/src/components/store/editor/window

1 file changed

+34
-31
lines changed

apps/web/client/src/components/store/editor/window/index.ts

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { sendAnalytics } from '@/utils/analytics';
22
import { makeAutoObservable } from 'mobx';
33
import type { EditorEngine } from '../engine';
4+
import { nanoid } from 'nanoid/non-secure';
5+
import type { WebFrame } from '../../../../../../../../packages/models/src/project/frame';
6+
47

58
export class WindowManager {
69
constructor(private editorEngine: EditorEngine) {
@@ -112,38 +115,38 @@ export class WindowManager {
112115
}
113116

114117
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+
};
145148

146-
// this.canvas.frames = [...this.canvas.frames, newFrame];
149+
this.editorEngine.canvas.frames = [...this.editorEngine.canvas.frames, newFrame];
147150
sendAnalytics('window duplicate');
148151
}
149152
}

0 commit comments

Comments
 (0)