|
|
@@ -44,13 +44,13 @@ const state = createState({
|
|
44
|
44
|
do: "panCamera",
|
|
45
|
45
|
},
|
|
46
|
46
|
SELECTED_SELECT_TOOL: { to: "selecting" },
|
|
47
|
|
- SELECTED_DOT_TOOL: { unless: "isReadOnly", to: "creatingDot" },
|
|
48
|
|
- SELECTED_CIRCLE_TOOL: { unless: "isReadOnly", to: "creatingCircle" },
|
|
49
|
|
- SELECTED_ELLIPSE_TOOL: { unless: "isReadOnly", to: "creatingEllipse" },
|
|
50
|
|
- SELECTED_RAY_TOOL: { unless: "isReadOnly", to: "creatingRay" },
|
|
51
|
|
- SELECTED_LINE_TOOL: { unless: "isReadOnly", to: "creatingLine" },
|
|
52
|
|
- SELECTED_POLYLINE_TOOL: { unless: "isReadOnly", to: "creatingPolyline" },
|
|
53
|
|
- SELECTED_RECTANGLE_TOOL: { unless: "isReadOnly", to: "creatingRectangle" },
|
|
|
47
|
+ SELECTED_DOT_TOOL: { unless: "isReadOnly", to: "dot" },
|
|
|
48
|
+ SELECTED_CIRCLE_TOOL: { unless: "isReadOnly", to: "circle" },
|
|
|
49
|
+ SELECTED_ELLIPSE_TOOL: { unless: "isReadOnly", to: "ellipse" },
|
|
|
50
|
+ SELECTED_RAY_TOOL: { unless: "isReadOnly", to: "ray" },
|
|
|
51
|
+ SELECTED_LINE_TOOL: { unless: "isReadOnly", to: "line" },
|
|
|
52
|
+ SELECTED_POLYLINE_TOOL: { unless: "isReadOnly", to: "polyline" },
|
|
|
53
|
+ SELECTED_RECTANGLE_TOOL: { unless: "isReadOnly", to: "rectangle" },
|
|
54
|
54
|
},
|
|
55
|
55
|
initial: "selecting",
|
|
56
|
56
|
states: {
|
|
|
@@ -154,18 +154,18 @@ const state = createState({
|
|
154
|
154
|
},
|
|
155
|
155
|
},
|
|
156
|
156
|
},
|
|
157
|
|
- creatingDot: {
|
|
|
157
|
+ dot: {
|
|
158
|
158
|
initial: "creating",
|
|
159
|
159
|
states: {
|
|
160
|
160
|
creating: {
|
|
161
|
161
|
on: {
|
|
162
|
162
|
POINTED_CANVAS: {
|
|
163
|
163
|
do: "createDot",
|
|
164
|
|
- to: "creatingDot.positioning",
|
|
|
164
|
+ to: "dot.editing",
|
|
165
|
165
|
},
|
|
166
|
166
|
},
|
|
167
|
167
|
},
|
|
168
|
|
- positioning: {
|
|
|
168
|
+ editing: {
|
|
169
|
169
|
onEnter: "startTranslateSession",
|
|
170
|
170
|
on: {
|
|
171
|
171
|
MOVED_POINTER: "updateTranslateSession",
|
|
|
@@ -179,12 +179,36 @@ const state = createState({
|
|
179
|
179
|
},
|
|
180
|
180
|
},
|
|
181
|
181
|
},
|
|
182
|
|
- creatingCircle: {},
|
|
183
|
|
- creatingEllipse: {},
|
|
184
|
|
- creatingRay: {},
|
|
185
|
|
- creatingLine: {},
|
|
186
|
|
- creatingPolyline: {},
|
|
187
|
|
- creatingRectangle: {},
|
|
|
182
|
+ circle: {},
|
|
|
183
|
+ ellipse: {},
|
|
|
184
|
+ ray: {
|
|
|
185
|
+ initial: "creating",
|
|
|
186
|
+ states: {
|
|
|
187
|
+ creating: {
|
|
|
188
|
+ on: {
|
|
|
189
|
+ POINTED_CANVAS: {
|
|
|
190
|
+ do: "createRay",
|
|
|
191
|
+ to: "ray.editing",
|
|
|
192
|
+ },
|
|
|
193
|
+ },
|
|
|
194
|
+ },
|
|
|
195
|
+ editing: {
|
|
|
196
|
+ onEnter: "startDirectionSession",
|
|
|
197
|
+ on: {
|
|
|
198
|
+ MOVED_POINTER: "updateDirectionSession",
|
|
|
199
|
+ PANNED_CAMERA: "updateDirectionSession",
|
|
|
200
|
+ STOPPED_POINTING: { do: "completeSession", to: "selecting" },
|
|
|
201
|
+ CANCELLED: {
|
|
|
202
|
+ do: ["cancelSession", "deleteSelectedIds"],
|
|
|
203
|
+ to: "selecting",
|
|
|
204
|
+ },
|
|
|
205
|
+ },
|
|
|
206
|
+ },
|
|
|
207
|
+ },
|
|
|
208
|
+ },
|
|
|
209
|
+ line: {},
|
|
|
210
|
+ polyline: {},
|
|
|
211
|
+ rectangle: {},
|
|
188
|
212
|
},
|
|
189
|
213
|
conditions: {
|
|
190
|
214
|
isPointingBounds(data, payload: PointerInfo) {
|
|
|
@@ -216,41 +240,31 @@ const state = createState({
|
|
216
|
240
|
},
|
|
217
|
241
|
},
|
|
218
|
242
|
actions: {
|
|
219
|
|
- // Shapes
|
|
|
243
|
+ /* --------------------- Shapes --------------------- */
|
|
|
244
|
+
|
|
|
245
|
+ // Dot
|
|
220
|
246
|
createDot(data, payload: PointerInfo) {
|
|
221
|
247
|
const shape = shapeUtilityMap[ShapeType.Dot].create({
|
|
222
|
248
|
point: screenToWorld(payload.point, data),
|
|
223
|
249
|
})
|
|
224
|
250
|
|
|
225
|
251
|
commands.createShape(data, shape)
|
|
|
252
|
+ data.selectedIds.add(shape.id)
|
|
226
|
253
|
},
|
|
227
|
254
|
|
|
228
|
|
- // History
|
|
229
|
|
- enableHistory() {
|
|
230
|
|
- history.enable()
|
|
231
|
|
- },
|
|
232
|
|
- disableHistory() {
|
|
233
|
|
- history.disable()
|
|
234
|
|
- },
|
|
235
|
|
- undo(data) {
|
|
236
|
|
- history.undo(data)
|
|
237
|
|
- },
|
|
238
|
|
- redo(data) {
|
|
239
|
|
- history.redo(data)
|
|
240
|
|
- },
|
|
|
255
|
+ // Ray
|
|
|
256
|
+ createRay(data, payload: PointerInfo) {
|
|
|
257
|
+ const shape = shapeUtilityMap[ShapeType.Ray].create({
|
|
|
258
|
+ point: screenToWorld(payload.point, data),
|
|
|
259
|
+ })
|
|
241
|
260
|
|
|
242
|
|
- // Code
|
|
243
|
|
- setGeneratedShapes(data, payload: { shapes: Shape[] }) {
|
|
244
|
|
- commands.generateShapes(data, data.currentPageId, payload.shapes)
|
|
245
|
|
- },
|
|
246
|
|
- increaseCodeFontSize(data) {
|
|
247
|
|
- data.settings.fontSize++
|
|
248
|
|
- },
|
|
249
|
|
- decreaseCodeFontSize(data) {
|
|
250
|
|
- data.settings.fontSize--
|
|
|
261
|
+ commands.createShape(data, shape)
|
|
|
262
|
+ data.selectedIds.add(shape.id)
|
|
251
|
263
|
},
|
|
252
|
264
|
|
|
253
|
|
- // Sessions
|
|
|
265
|
+ /* -------------------- Sessions -------------------- */
|
|
|
266
|
+
|
|
|
267
|
+ // Shared
|
|
254
|
268
|
cancelSession(data) {
|
|
255
|
269
|
session.cancel(data)
|
|
256
|
270
|
session = undefined
|
|
|
@@ -297,20 +311,19 @@ const state = createState({
|
|
297
|
311
|
session.update(data, screenToWorld(payload.point, data))
|
|
298
|
312
|
},
|
|
299
|
313
|
|
|
300
|
|
- // Selection
|
|
301
|
|
- deleteSelectedIds(data) {
|
|
302
|
|
- const { document, currentPageId } = data
|
|
303
|
|
- const shapes = document.pages[currentPageId].shapes
|
|
|
314
|
+ // Direction
|
|
|
315
|
+ startDirectionSession(data, payload: PointerInfo) {
|
|
|
316
|
+ session = new Sessions.DirectionSession(
|
|
|
317
|
+ data,
|
|
|
318
|
+ screenToWorld(payload.point, data)
|
|
|
319
|
+ )
|
|
|
320
|
+ },
|
|
|
321
|
+ updateDirectionSession(data, payload: PointerInfo) {
|
|
|
322
|
+ session.update(data, screenToWorld(payload.point, data))
|
|
|
323
|
+ },
|
|
304
|
324
|
|
|
305
|
|
- data.selectedIds.forEach((id) => {
|
|
306
|
|
- delete shapes[id]
|
|
307
|
|
- // TODO: recursively delete children
|
|
308
|
|
- })
|
|
|
325
|
+ /* -------------------- Selection ------------------- */
|
|
309
|
326
|
|
|
310
|
|
- data.selectedIds.clear()
|
|
311
|
|
- data.hoveredId = undefined
|
|
312
|
|
- data.pointedId = undefined
|
|
313
|
|
- },
|
|
314
|
327
|
setHoveredId(data, payload: PointerInfo) {
|
|
315
|
328
|
data.hoveredId = payload.target
|
|
316
|
329
|
},
|
|
|
@@ -357,6 +370,46 @@ const state = createState({
|
|
357
|
370
|
vec.div(payload.delta, camera.zoom)
|
|
358
|
371
|
)
|
|
359
|
372
|
},
|
|
|
373
|
+ deleteSelectedIds(data) {
|
|
|
374
|
+ const { document, currentPageId } = data
|
|
|
375
|
+ const shapes = document.pages[currentPageId].shapes
|
|
|
376
|
+
|
|
|
377
|
+ data.selectedIds.forEach((id) => {
|
|
|
378
|
+ delete shapes[id]
|
|
|
379
|
+ // TODO: recursively delete children
|
|
|
380
|
+ })
|
|
|
381
|
+
|
|
|
382
|
+ data.selectedIds.clear()
|
|
|
383
|
+ data.hoveredId = undefined
|
|
|
384
|
+ data.pointedId = undefined
|
|
|
385
|
+ },
|
|
|
386
|
+
|
|
|
387
|
+ /* ---------------------- Misc ---------------------- */
|
|
|
388
|
+
|
|
|
389
|
+ // History
|
|
|
390
|
+ enableHistory() {
|
|
|
391
|
+ history.enable()
|
|
|
392
|
+ },
|
|
|
393
|
+ disableHistory() {
|
|
|
394
|
+ history.disable()
|
|
|
395
|
+ },
|
|
|
396
|
+ undo(data) {
|
|
|
397
|
+ history.undo(data)
|
|
|
398
|
+ },
|
|
|
399
|
+ redo(data) {
|
|
|
400
|
+ history.redo(data)
|
|
|
401
|
+ },
|
|
|
402
|
+
|
|
|
403
|
+ // Code
|
|
|
404
|
+ setGeneratedShapes(data, payload: { shapes: Shape[] }) {
|
|
|
405
|
+ commands.generateShapes(data, data.currentPageId, payload.shapes)
|
|
|
406
|
+ },
|
|
|
407
|
+ increaseCodeFontSize(data) {
|
|
|
408
|
+ data.settings.fontSize++
|
|
|
409
|
+ },
|
|
|
410
|
+ decreaseCodeFontSize(data) {
|
|
|
411
|
+ data.settings.fontSize--
|
|
|
412
|
+ },
|
|
360
|
413
|
},
|
|
361
|
414
|
values: {
|
|
362
|
415
|
selectedIds(data) {
|