Steve Ruiz 4 лет назад
Родитель
Сommit
9626461ea7
4 измененных файлов: 66 добавлений и 16 удалений
  1. 12
    0
      state/commands/delete-selected.ts
  2. 5
    1
      state/commands/translate.ts
  3. 48
    14
      state/sessions/translate-session.ts
  4. 1
    1
      state/state.ts

+ 12
- 0
state/commands/delete-selected.ts Просмотреть файл

58
           page.shapes[shape.id] = shape
58
           page.shapes[shape.id] = shape
59
         }
59
         }
60
 
60
 
61
+        for (let shape of childrenToDelete) {
62
+          if (shape.parentId !== data.currentPageId) {
63
+            const parent = page.shapes[shape.parentId]
64
+            getShapeUtils(parent)
65
+              .setProperty(parent, 'children', [...parent.children, shape.id])
66
+              .onChildrenChange(
67
+                parent,
68
+                parent.children.map((id) => page.shapes[id])
69
+              )
70
+          }
71
+        }
72
+
61
         data.selectedIds = new Set(selectedIds)
73
         data.selectedIds = new Set(selectedIds)
62
       },
74
       },
63
     })
75
     })

+ 5
- 1
state/commands/translate.ts Просмотреть файл

1
 import Command from './command'
1
 import Command from './command'
2
 import history from '../history'
2
 import history from '../history'
3
 import { TranslateSnapshot } from 'state/sessions/translate-session'
3
 import { TranslateSnapshot } from 'state/sessions/translate-session'
4
-import { Data } from 'types'
4
+import { Data, GroupShape, Shape, ShapeType } from 'types'
5
 import { getPage, updateParents } from 'utils/utils'
5
 import { getPage, updateParents } from 'utils/utils'
6
 import { getShapeUtils } from 'lib/shape-utils'
6
 import { getShapeUtils } from 'lib/shape-utils'
7
+import { v4 as uuid } from 'uuid'
7
 
8
 
8
 export default function translateCommand(
9
 export default function translateCommand(
9
   data: Data,
10
   data: Data,
33
                 ...parent.children,
34
                 ...parent.children,
34
                 clone.id,
35
                 clone.id,
35
               ])
36
               ])
37
+
38
+              if (clone.type === ShapeType.Group) {
39
+              }
36
             }
40
             }
37
           }
41
           }
38
         }
42
         }

+ 48
- 14
state/sessions/translate-session.ts Просмотреть файл

1
-import { Data, GroupShape, ShapeType } from 'types'
1
+import { Data, GroupShape, Shape, ShapeType } from 'types'
2
 import * as vec from 'utils/vec'
2
 import * as vec from 'utils/vec'
3
 import BaseSession from './base-session'
3
 import BaseSession from './base-session'
4
 import commands from 'state/commands'
4
 import commands from 'state/commands'
54
         for (const clone of clones) {
54
         for (const clone of clones) {
55
           data.selectedIds.add(clone.id)
55
           data.selectedIds.add(clone.id)
56
           shapes[clone.id] = { ...clone }
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
   const selectedShapes = getSelectedShapes(cData).filter(
163
   const selectedShapes = getSelectedShapes(cData).filter(
165
     (shape) => !shape.isLocked
164
     (shape) => !shape.isLocked
166
   )
165
   )
166
+
167
   const hasUnlockedShapes = selectedShapes.length > 0
167
   const hasUnlockedShapes = selectedShapes.length > 0
168
 
168
 
169
   const parents = Array.from(
169
   const parents = Array.from(
181
       point,
181
       point,
182
       parentId,
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
 export type TranslateSnapshot = ReturnType<typeof getTranslateSnapshot>
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
+}

+ 1
- 1
state/state.ts Просмотреть файл

1385
     },
1385
     },
1386
 
1386
 
1387
     restoreSavedData(data) {
1387
     restoreSavedData(data) {
1388
-      history.load(data)
1388
+      // history.load(data)
1389
     },
1389
     },
1390
 
1390
 
1391
     clearBoundsRotation(data) {
1391
     clearBoundsRotation(data) {

Загрузка…
Отмена
Сохранить