homemanager-fe/src/modules/house-planner/clipboard.ts

30 lines
734 B
TypeScript

import deepUnref from '../../utils/deep-unref';
import { LayerObject } from './interfaces';
export class HousePlannerCanvasClipboard {
public storedObjects: LayerObject[] = [];
storeToClipboard(items: LayerObject[]) {
this.storedObjects = [
...items.map((item) => {
const itemCopy = {
...deepUnref(item),
visible: true,
name: item.name + ' Copy',
};
delete itemCopy.databaseId;
return itemCopy;
}),
];
}
getFromClipboard(newId: number, selected = true): LayerObject[] {
const newObjects = deepUnref(this.storedObjects);
return newObjects.map((item, index) => ({
...item,
id: newId + index,
selected,
}));
}
}