-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathlayout.js
266 lines (212 loc) · 7.49 KB
/
layout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { select } from './select';
import {
actionEvent,
cursorPosition,
dragging,
dragVector,
gestureEnd,
gestureState,
metaHeld,
mouseButton,
mouseDowned,
mouseIsDown,
optionHeld,
shiftHeld,
} from './gestures';
import {
applyLocalTransforms,
cascadeProperties,
draggingShape,
getAdHocChildrenAnnotations,
getAlignAction,
getAlignDistributeTransformIntents,
getAlignmentGuideAnnotations,
getAlterSnapGesture,
getAnnotatedShapes,
getConfiguration,
getConstrainedShapesWithPreexistingAnnotations,
getCursor,
getDistributeAction,
getDragBox,
getDragBoxAnnotation,
getDragboxHighlighted,
getDraggedPrimaryShape,
getFocusedShape,
getGroupAction,
getGroupedSelectedPrimaryShapeIds,
getGroupedSelectedShapeIds,
getGroupedSelectedShapes,
getGrouping,
getGroupingTuple,
getHoverAnnotations,
getHoveredShape,
getHoveredShapes,
getMouseTransformGesture,
getMouseTransformGesturePrev,
getMouseTransformState,
getNextScene,
getResizeManipulator,
getRotationAnnotations,
getRotationTooltipAnnotation,
getSelectedPrimaryShapeIds,
getSelectedShapeObjects,
getSelectedShapes,
getSelectedShapesPrev,
getSelectionState,
getSelectionStateFull,
getShapes,
getShapesToHover,
getSnappedShapes,
getTransformIntents,
resizeAnnotationsFunction,
updaterFun,
} from './layout_functions';
import { primaryUpdate, scene } from './common';
export const shapes = select(getShapes)(scene);
const configuration = select(getConfiguration)(scene);
const hoveredShapes = select(getHoveredShapes)(configuration, shapes, cursorPosition);
const hoveredShape = select(getHoveredShape)(hoveredShapes);
const draggedShape = select(draggingShape)(scene, hoveredShape, mouseIsDown, mouseDowned);
export const focusedShape = select(getFocusedShape)(draggedShape, hoveredShape);
const alterSnapGesture = select(getAlterSnapGesture)(metaHeld);
const multiselectModifier = shiftHeld; // todo abstract out keybindings
const mouseTransformGesturePrev = select(getMouseTransformGesturePrev)(scene);
const mouseTransformState = select(getMouseTransformState)(
mouseTransformGesturePrev,
dragging,
dragVector
);
const directManipulationTransformGestures = select(getMouseTransformGesture)(mouseTransformState);
const dragBox = select(getDragBox)(dragging, draggedShape, dragVector);
const selectedShapeObjects = select(getSelectedShapeObjects)(scene, shapes);
const selectedShapesPrev = select(getSelectedShapesPrev)(scene);
const boxHighlightedShapes = select(getDragboxHighlighted)(dragBox, shapes);
const selectionStateFull = select(getSelectionStateFull)(
selectedShapesPrev,
configuration,
selectedShapeObjects,
hoveredShapes,
mouseButton,
metaHeld,
multiselectModifier,
boxHighlightedShapes
);
const selectionState = select(getSelectionState)(selectionStateFull);
const selectedShapes = select(getSelectedShapes)(selectionStateFull);
const selectedPrimaryShapeIds = select(getSelectedPrimaryShapeIds)(selectedShapes); // fixme unify with contentShape
const symmetricManipulation = optionHeld; // as in comparable software applications, todo: make configurable
const resizeManipulator = select(getResizeManipulator)(configuration, symmetricManipulation);
const directManipulationTransformIntents = select(getTransformIntents)(
configuration,
directManipulationTransformGestures,
selectedShapes,
shapes,
cursorPosition,
alterSnapGesture,
resizeManipulator
);
const alignAction = select(getAlignAction)(actionEvent);
const distributeAction = select(getDistributeAction)(actionEvent);
const alignDistributeTransformIntents = select(getAlignDistributeTransformIntents)(
alignAction,
distributeAction,
shapes,
selectedShapes
);
const commandTransformIntents = alignDistributeTransformIntents; // will expand in the future, eg. nudge
const transformIntents = select((directIntents, commandIntents) =>
directIntents.concat(commandIntents)
)(directManipulationTransformIntents, commandTransformIntents);
const transformedShapes = select(applyLocalTransforms)(shapes, transformIntents);
const draggedPrimaryShape = select(getDraggedPrimaryShape)(shapes, draggedShape);
const alignmentGuideAnnotations = select(getAlignmentGuideAnnotations)(
configuration,
transformedShapes,
draggedPrimaryShape,
draggedShape
);
const shapesToHover = select(getShapesToHover)(dragBox, hoveredShapes, boxHighlightedShapes);
const hoverAnnotations = select(getHoverAnnotations)(
configuration,
shapesToHover,
selectedPrimaryShapeIds,
draggedShape
);
// Once the interaction is over, ensure that the shape stays put where the constraint led it - distance is no longer relevant
// Note that this is what standard software (Adobe Illustrator, Google Slides, PowerPoint, Sketch etc.) do, but it's in
// stark contrast with the concept of StickyLines - whose central idea is that constraints remain applied until explicitly
const snappedShapes = select(getSnappedShapes)(
configuration,
transformedShapes,
draggedShape,
draggedPrimaryShape,
alignmentGuideAnnotations,
alterSnapGesture,
symmetricManipulation
);
const constrainedShapesWithPreexistingAnnotations = select(
getConstrainedShapesWithPreexistingAnnotations
)(snappedShapes, transformedShapes);
const rotationTooltipAnnotation = select(getRotationTooltipAnnotation)(
configuration,
draggedPrimaryShape,
draggedShape,
transformIntents,
cursorPosition
);
const groupAction = select(getGroupAction)(actionEvent, mouseIsDown);
const groupingTuple = select(getGroupingTuple)(
configuration,
constrainedShapesWithPreexistingAnnotations,
selectedShapes
);
const grouping = select(getGrouping)(
configuration,
constrainedShapesWithPreexistingAnnotations,
selectedShapes,
groupAction,
groupingTuple
);
const groupedSelectedShapes = select(getGroupedSelectedShapes)(grouping);
const groupedSelectedShapeIds = select(getGroupedSelectedShapeIds)(groupedSelectedShapes);
const groupedSelectedPrimaryShapeIds = select(getGroupedSelectedPrimaryShapeIds)(
groupedSelectedShapes
);
const adHocChildrenAnnotations = select(getAdHocChildrenAnnotations)(configuration, grouping);
const resizeAnnotations = select(resizeAnnotationsFunction)(configuration, grouping);
const rotationAnnotations = select(getRotationAnnotations)(configuration, grouping);
const dragBoxAnnotation = select(getDragBoxAnnotation)(configuration, dragBox);
const annotatedShapes = select(getAnnotatedShapes)(
grouping,
alignmentGuideAnnotations,
hoverAnnotations,
rotationAnnotations,
resizeAnnotations,
rotationTooltipAnnotation,
adHocChildrenAnnotations,
dragBoxAnnotation
);
const globalTransformShapes = select(cascadeProperties)(annotatedShapes);
const cursor = select(getCursor)(configuration, focusedShape, draggedPrimaryShape);
// this is the core scenegraph update invocation: upon new cursor position etc. emit the new scenegraph
// it's _the_ state representation (at a PoC level...) comprising of transient properties eg. draggedShape, and the
export const nextScene = select(getNextScene)(
configuration,
hoveredShape,
groupedSelectedShapeIds,
groupedSelectedPrimaryShapeIds,
globalTransformShapes,
gestureEnd,
draggedShape,
cursor,
selectionState,
mouseTransformState,
gestureState
);
export const updater = select(updaterFun)(nextScene, primaryUpdate);