|
|
@@ -20,6 +20,7 @@ export default class TranslateSession extends BaseSession {
|
|
20
|
20
|
update(data: Data, point: number[], isAligned: boolean, isCloning: boolean) {
|
|
21
|
21
|
const { currentPageId, clones, initialShapes } = this.snapshot
|
|
22
|
22
|
const { shapes } = data.document.pages[currentPageId]
|
|
|
23
|
+
|
|
23
|
24
|
const delta = vec.vec(this.origin, point)
|
|
24
|
25
|
|
|
25
|
26
|
if (isAligned) {
|
|
|
@@ -30,22 +31,41 @@ export default class TranslateSession extends BaseSession {
|
|
30
|
31
|
}
|
|
31
|
32
|
}
|
|
32
|
33
|
|
|
33
|
|
- if (isCloning && !this.isCloning) {
|
|
34
|
|
- this.isCloning = true
|
|
35
|
|
- for (let id in clones) {
|
|
36
|
|
- const clone = clones[id]
|
|
37
|
|
- shapes[clone.id] = clone
|
|
|
34
|
+ if (isCloning) {
|
|
|
35
|
+ if (!this.isCloning) {
|
|
|
36
|
+ this.isCloning = true
|
|
|
37
|
+ data.selectedIds.clear()
|
|
|
38
|
+
|
|
|
39
|
+ for (const { id, point } of initialShapes) {
|
|
|
40
|
+ shapes[id].point = point
|
|
|
41
|
+ }
|
|
|
42
|
+
|
|
|
43
|
+ for (const clone of clones) {
|
|
|
44
|
+ shapes[clone.id] = { ...clone }
|
|
|
45
|
+ data.selectedIds.add(clone.id)
|
|
|
46
|
+ }
|
|
38
|
47
|
}
|
|
39
|
|
- } else if (!isCloning && this.isCloning) {
|
|
40
|
|
- this.isCloning = false
|
|
41
|
|
- for (let id in clones) {
|
|
42
|
|
- const clone = clones[id]
|
|
43
|
|
- delete shapes[clone.id]
|
|
|
48
|
+
|
|
|
49
|
+ for (const { id, point } of clones) {
|
|
|
50
|
+ shapes[id].point = vec.add(point, delta)
|
|
44
|
51
|
}
|
|
45
|
|
- }
|
|
|
52
|
+ } else {
|
|
|
53
|
+ if (this.isCloning) {
|
|
|
54
|
+ this.isCloning = false
|
|
|
55
|
+ data.selectedIds.clear()
|
|
|
56
|
+
|
|
|
57
|
+ for (const { id } of initialShapes) {
|
|
|
58
|
+ data.selectedIds.add(id)
|
|
|
59
|
+ }
|
|
46
|
60
|
|
|
47
|
|
- for (let id in initialShapes) {
|
|
48
|
|
- shapes[id].point = vec.add(initialShapes[id].point, delta)
|
|
|
61
|
+ for (const clone of clones) {
|
|
|
62
|
+ delete shapes[clone.id]
|
|
|
63
|
+ }
|
|
|
64
|
+ }
|
|
|
65
|
+
|
|
|
66
|
+ for (const { id, point } of initialShapes) {
|
|
|
67
|
+ shapes[id].point = vec.add(point, delta)
|
|
|
68
|
+ }
|
|
49
|
69
|
}
|
|
50
|
70
|
}
|
|
51
|
71
|
|
|
|
@@ -53,9 +73,12 @@ export default class TranslateSession extends BaseSession {
|
|
53
|
73
|
const { initialShapes, clones, currentPageId } = this.snapshot
|
|
54
|
74
|
const { shapes } = data.document.pages[currentPageId]
|
|
55
|
75
|
|
|
56
|
|
- for (let id in initialShapes) {
|
|
57
|
|
- shapes[id].point = initialShapes[id].point
|
|
58
|
|
- delete shapes[clones[id].id]
|
|
|
76
|
+ for (const { id, point } of initialShapes) {
|
|
|
77
|
+ shapes[id].point = point
|
|
|
78
|
+ }
|
|
|
79
|
+
|
|
|
80
|
+ for (const { id } of clones) {
|
|
|
81
|
+ delete shapes[id]
|
|
59
|
82
|
}
|
|
60
|
83
|
}
|
|
61
|
84
|
|
|
|
@@ -70,24 +93,16 @@ export default class TranslateSession extends BaseSession {
|
|
70
|
93
|
}
|
|
71
|
94
|
|
|
72
|
95
|
export function getTranslateSnapshot(data: Data) {
|
|
73
|
|
- const {
|
|
74
|
|
- document: { pages },
|
|
75
|
|
- currentPageId,
|
|
76
|
|
- } = current(data)
|
|
|
96
|
+ const { document, selectedIds, currentPageId } = current(data)
|
|
77
|
97
|
|
|
78
|
|
- const shapes = Array.from(data.selectedIds.values()).map(
|
|
79
|
|
- (id) => pages[currentPageId].shapes[id]
|
|
|
98
|
+ const shapes = Array.from(selectedIds.values()).map(
|
|
|
99
|
+ (id) => document.pages[currentPageId].shapes[id]
|
|
80
|
100
|
)
|
|
81
|
101
|
|
|
82
|
|
- // Clones and shapes are keyed under the same id, though the clone itself
|
|
83
|
|
- // has a different id.
|
|
84
|
|
-
|
|
85
|
102
|
return {
|
|
86
|
103
|
currentPageId,
|
|
87
|
|
- initialShapes: Object.fromEntries(shapes.map((shape) => [shape.id, shape])),
|
|
88
|
|
- clones: Object.fromEntries(
|
|
89
|
|
- shapes.map((shape) => [shape.id, { ...shape, id: uuid() }])
|
|
90
|
|
- ),
|
|
|
104
|
+ initialShapes: shapes.map(({ id, point }) => ({ id, point })),
|
|
|
105
|
+ clones: shapes.map((shape) => ({ ...shape, id: uuid() })),
|
|
91
|
106
|
}
|
|
92
|
107
|
}
|
|
93
|
108
|
|