|
|
@@ -1,4 +1,4 @@
|
|
1
|
|
-import { Data, GroupShape, ShapeType } from 'types'
|
|
|
1
|
+import { Data, GroupShape, Shape, ShapeType } from 'types'
|
|
2
|
2
|
import * as vec from 'utils/vec'
|
|
3
|
3
|
import BaseSession from './base-session'
|
|
4
|
4
|
import commands from 'state/commands'
|
|
|
@@ -54,13 +54,12 @@ export default class TranslateSession extends BaseSession {
|
|
54
|
54
|
for (const clone of clones) {
|
|
55
|
55
|
data.selectedIds.add(clone.id)
|
|
56
|
56
|
shapes[clone.id] = { ...clone }
|
|
57
|
|
- if (clone.parentId !== data.currentPageId) {
|
|
58
|
|
- const parent = shapes[clone.parentId]
|
|
59
|
|
- getShapeUtils(parent).setProperty(parent, 'children', [
|
|
60
|
|
- ...parent.children,
|
|
61
|
|
- clone.id,
|
|
62
|
|
- ])
|
|
63
|
|
- }
|
|
|
57
|
+ const parent = shapes[clone.parentId]
|
|
|
58
|
+ if (!parent) continue
|
|
|
59
|
+ getShapeUtils(parent).setProperty(parent, 'children', [
|
|
|
60
|
+ ...parent.children,
|
|
|
61
|
+ clone.id,
|
|
|
62
|
+ ])
|
|
64
|
63
|
}
|
|
65
|
64
|
}
|
|
66
|
65
|
|
|
|
@@ -164,6 +163,7 @@ export function getTranslateSnapshot(data: Data) {
|
|
164
|
163
|
const selectedShapes = getSelectedShapes(cData).filter(
|
|
165
|
164
|
(shape) => !shape.isLocked
|
|
166
|
165
|
)
|
|
|
166
|
+
|
|
167
|
167
|
const hasUnlockedShapes = selectedShapes.length > 0
|
|
168
|
168
|
|
|
169
|
169
|
const parents = Array.from(
|
|
|
@@ -181,13 +181,47 @@ export function getTranslateSnapshot(data: Data) {
|
|
181
|
181
|
point,
|
|
182
|
182
|
parentId,
|
|
183
|
183
|
})),
|
|
184
|
|
- clones: selectedShapes.map((shape) => ({
|
|
185
|
|
- ...shape,
|
|
186
|
|
- id: uuid(),
|
|
187
|
|
- parentId: shape.parentId,
|
|
188
|
|
- childIndex: getChildIndexAbove(cData, shape.id),
|
|
189
|
|
- })),
|
|
|
184
|
+ clones: selectedShapes
|
|
|
185
|
+ .filter((shape) => shape.type !== ShapeType.Group)
|
|
|
186
|
+ .flatMap((shape) => {
|
|
|
187
|
+ const clone = {
|
|
|
188
|
+ ...shape,
|
|
|
189
|
+ id: uuid(),
|
|
|
190
|
+ parentId: shape.parentId,
|
|
|
191
|
+ childIndex: getChildIndexAbove(cData, shape.id),
|
|
|
192
|
+ }
|
|
|
193
|
+
|
|
|
194
|
+ return clone
|
|
|
195
|
+
|
|
|
196
|
+ // cloneGroup(cData, {
|
|
|
197
|
+ // ...shape,
|
|
|
198
|
+ // id: uuid(),
|
|
|
199
|
+ // parentId: shape.parentId,
|
|
|
200
|
+ // childIndex: getChildIndexAbove(cData, shape.id),
|
|
|
201
|
+ // })
|
|
|
202
|
+ }),
|
|
190
|
203
|
}
|
|
191
|
204
|
}
|
|
192
|
205
|
|
|
193
|
206
|
export type TranslateSnapshot = ReturnType<typeof getTranslateSnapshot>
|
|
|
207
|
+
|
|
|
208
|
+function cloneGroup(data: Data, clone: Shape): Shape[] {
|
|
|
209
|
+ if (clone.type !== ShapeType.Group) {
|
|
|
210
|
+ return [clone]
|
|
|
211
|
+ }
|
|
|
212
|
+
|
|
|
213
|
+ const page = getPage(data)
|
|
|
214
|
+ const childClones = clone.children.flatMap((id) => {
|
|
|
215
|
+ const newId = uuid()
|
|
|
216
|
+ const source = page.shapes[id]
|
|
|
217
|
+ const next = { ...source, id: newId, parentId: clone.id }
|
|
|
218
|
+
|
|
|
219
|
+ if (next.type === ShapeType.Group) {
|
|
|
220
|
+ return [next, ...cloneGroup(data, next)]
|
|
|
221
|
+ }
|
|
|
222
|
+
|
|
|
223
|
+ return [next]
|
|
|
224
|
+ })
|
|
|
225
|
+
|
|
|
226
|
+ return [clone, ...childClones]
|
|
|
227
|
+}
|