@api-client/ui 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/package.json +7 -2
  2. package/test/env.ts +15 -0
  3. package/test/tsconfig.json +1 -7
  4. package/web-test-runner.config.js +5 -1
  5. package/build/src/visualization/elements/VizAssociationElement.d.ts +0 -4
  6. package/build/src/visualization/elements/VizAssociationElement.d.ts.map +0 -1
  7. package/build/src/visualization/elements/VizAssociationElement.js +0 -4
  8. package/build/src/visualization/elements/VizAssociationElement.js.map +0 -1
  9. package/build/src/visualization/elements/VizWorkspaceElement.d.ts +0 -110
  10. package/build/src/visualization/elements/VizWorkspaceElement.d.ts.map +0 -1
  11. package/build/src/visualization/elements/VizWorkspaceElement.js +0 -321
  12. package/build/src/visualization/elements/VizWorkspaceElement.js.map +0 -1
  13. package/build/src/visualization/elements/WorkspaceStyles.d.ts +0 -3
  14. package/build/src/visualization/elements/WorkspaceStyles.d.ts.map +0 -1
  15. package/build/src/visualization/elements/WorkspaceStyles.js +0 -168
  16. package/build/src/visualization/elements/WorkspaceStyles.js.map +0 -1
  17. package/build/src/visualization/lib/AnchorFinder.d.ts +0 -64
  18. package/build/src/visualization/lib/AnchorFinder.d.ts.map +0 -1
  19. package/build/src/visualization/lib/AnchorFinder.js +0 -107
  20. package/build/src/visualization/lib/AnchorFinder.js.map +0 -1
  21. package/build/src/visualization/lib/AnchorUtils.d.ts +0 -10
  22. package/build/src/visualization/lib/AnchorUtils.d.ts.map +0 -1
  23. package/build/src/visualization/lib/AnchorUtils.js +0 -44
  24. package/build/src/visualization/lib/AnchorUtils.js.map +0 -1
  25. package/build/src/visualization/lib/AssociationAnchors.d.ts +0 -134
  26. package/build/src/visualization/lib/AssociationAnchors.d.ts.map +0 -1
  27. package/build/src/visualization/lib/AssociationAnchors.js +0 -351
  28. package/build/src/visualization/lib/AssociationAnchors.js.map +0 -1
  29. package/build/src/visualization/lib/LabelSketch.d.ts +0 -16
  30. package/build/src/visualization/lib/LabelSketch.d.ts.map +0 -1
  31. package/build/src/visualization/lib/LabelSketch.js +0 -53
  32. package/build/src/visualization/lib/LabelSketch.js.map +0 -1
  33. package/build/src/visualization/lib/LineSketch.d.ts +0 -26
  34. package/build/src/visualization/lib/LineSketch.d.ts.map +0 -1
  35. package/build/src/visualization/lib/LineSketch.js +0 -55
  36. package/build/src/visualization/lib/LineSketch.js.map +0 -1
  37. package/build/src/visualization/lib/Point.d.ts +0 -74
  38. package/build/src/visualization/lib/Point.d.ts.map +0 -1
  39. package/build/src/visualization/lib/Point.js +0 -121
  40. package/build/src/visualization/lib/Point.js.map +0 -1
  41. package/build/src/visualization/lib/PositionUtils.d.ts +0 -65
  42. package/build/src/visualization/lib/PositionUtils.d.ts.map +0 -1
  43. package/build/src/visualization/lib/PositionUtils.js +0 -205
  44. package/build/src/visualization/lib/PositionUtils.js.map +0 -1
  45. package/build/src/visualization/lib/SelectionManager.d.ts +0 -183
  46. package/build/src/visualization/lib/SelectionManager.d.ts.map +0 -1
  47. package/build/src/visualization/lib/SelectionManager.js +0 -481
  48. package/build/src/visualization/lib/SelectionManager.js.map +0 -1
  49. package/build/src/visualization/lib/ShapeArtist.d.ts +0 -45
  50. package/build/src/visualization/lib/ShapeArtist.d.ts.map +0 -1
  51. package/build/src/visualization/lib/ShapeArtist.js +0 -209
  52. package/build/src/visualization/lib/ShapeArtist.js.map +0 -1
  53. package/build/src/visualization/lib/SvgMarkers.d.ts +0 -14
  54. package/build/src/visualization/lib/SvgMarkers.d.ts.map +0 -1
  55. package/build/src/visualization/lib/SvgMarkers.js +0 -77
  56. package/build/src/visualization/lib/SvgMarkers.js.map +0 -1
  57. package/build/src/visualization/lib/TipSketch.d.ts +0 -26
  58. package/build/src/visualization/lib/TipSketch.d.ts.map +0 -1
  59. package/build/src/visualization/lib/TipSketch.js +0 -77
  60. package/build/src/visualization/lib/TipSketch.js.map +0 -1
  61. package/build/src/visualization/lib/TouchSupport.d.ts +0 -14
  62. package/build/src/visualization/lib/TouchSupport.d.ts.map +0 -1
  63. package/build/src/visualization/lib/TouchSupport.js +0 -55
  64. package/build/src/visualization/lib/TouchSupport.js.map +0 -1
  65. package/build/src/visualization/lib/Utils.d.ts +0 -25
  66. package/build/src/visualization/lib/Utils.d.ts.map +0 -1
  67. package/build/src/visualization/lib/Utils.js +0 -59
  68. package/build/src/visualization/lib/Utils.js.map +0 -1
  69. package/build/src/visualization/lib/VisualizationTypes.d.ts +0 -216
  70. package/build/src/visualization/lib/VisualizationTypes.d.ts.map +0 -1
  71. package/build/src/visualization/lib/VisualizationTypes.js +0 -3
  72. package/build/src/visualization/lib/VisualizationTypes.js.map +0 -1
  73. package/build/src/visualization/lib/WorkspaceAlignment.d.ts +0 -51
  74. package/build/src/visualization/lib/WorkspaceAlignment.d.ts.map +0 -1
  75. package/build/src/visualization/lib/WorkspaceAlignment.js +0 -243
  76. package/build/src/visualization/lib/WorkspaceAlignment.js.map +0 -1
  77. package/build/src/visualization/lib/WorkspaceDebugging.d.ts +0 -104
  78. package/build/src/visualization/lib/WorkspaceDebugging.d.ts.map +0 -1
  79. package/build/src/visualization/lib/WorkspaceDebugging.js +0 -286
  80. package/build/src/visualization/lib/WorkspaceDebugging.js.map +0 -1
  81. package/build/src/visualization/lib/WorkspaceEdges.d.ts +0 -293
  82. package/build/src/visualization/lib/WorkspaceEdges.d.ts.map +0 -1
  83. package/build/src/visualization/lib/WorkspaceEdges.js +0 -1073
  84. package/build/src/visualization/lib/WorkspaceEdges.js.map +0 -1
  85. package/build/src/visualization/lib/WorkspaceGestures.d.ts +0 -119
  86. package/build/src/visualization/lib/WorkspaceGestures.d.ts.map +0 -1
  87. package/build/src/visualization/lib/WorkspaceGestures.js +0 -376
  88. package/build/src/visualization/lib/WorkspaceGestures.js.map +0 -1
  89. package/build/src/visualization/lib/WorkspaceSizing.d.ts +0 -66
  90. package/build/src/visualization/lib/WorkspaceSizing.d.ts.map +0 -1
  91. package/build/src/visualization/lib/WorkspaceSizing.js +0 -168
  92. package/build/src/visualization/lib/WorkspaceSizing.js.map +0 -1
  93. package/build/src/visualization/lib/lines/RectilinearLine.d.ts +0 -114
  94. package/build/src/visualization/lib/lines/RectilinearLine.d.ts.map +0 -1
  95. package/build/src/visualization/lib/lines/RectilinearLine.js +0 -605
  96. package/build/src/visualization/lib/lines/RectilinearLine.js.map +0 -1
  97. package/build/src/visualization/lib/tips/RectilinearTip.d.ts +0 -26
  98. package/build/src/visualization/lib/tips/RectilinearTip.d.ts.map +0 -1
  99. package/build/src/visualization/lib/tips/RectilinearTip.js +0 -149
  100. package/build/src/visualization/lib/tips/RectilinearTip.js.map +0 -1
  101. package/build/src/visualization/lib/tips/TipArtist.d.ts +0 -22
  102. package/build/src/visualization/lib/tips/TipArtist.d.ts.map +0 -1
  103. package/build/src/visualization/lib/tips/TipArtist.js +0 -31
  104. package/build/src/visualization/lib/tips/TipArtist.js.map +0 -1
  105. package/build/src/visualization/lib/types.d.ts +0 -164
  106. package/build/src/visualization/lib/types.d.ts.map +0 -1
  107. package/build/src/visualization/lib/types.js +0 -2
  108. package/build/src/visualization/lib/types.js.map +0 -1
  109. package/build/src/visualization/plugin/dnd/DragAndDropPlugin.d.ts +0 -126
  110. package/build/src/visualization/plugin/dnd/DragAndDropPlugin.d.ts.map +0 -1
  111. package/build/src/visualization/plugin/dnd/DragAndDropPlugin.js +0 -260
  112. package/build/src/visualization/plugin/dnd/DragAndDropPlugin.js.map +0 -1
  113. package/build/src/visualization/plugin/group-selection/GroupSelection.d.ts +0 -93
  114. package/build/src/visualization/plugin/group-selection/GroupSelection.d.ts.map +0 -1
  115. package/build/src/visualization/plugin/group-selection/GroupSelection.js +0 -250
  116. package/build/src/visualization/plugin/group-selection/GroupSelection.js.map +0 -1
  117. package/build/src/visualization/plugin/positioning/DataModelLayout.d.ts +0 -10
  118. package/build/src/visualization/plugin/positioning/DataModelLayout.d.ts.map +0 -1
  119. package/build/src/visualization/plugin/positioning/DataModelLayout.js +0 -105
  120. package/build/src/visualization/plugin/positioning/DataModelLayout.js.map +0 -1
  121. package/build/src/visualization/plugin/positioning/WorkspaceLayout.d.ts +0 -93
  122. package/build/src/visualization/plugin/positioning/WorkspaceLayout.d.ts.map +0 -1
  123. package/build/src/visualization/plugin/positioning/WorkspaceLayout.js +0 -96
  124. package/build/src/visualization/plugin/positioning/WorkspaceLayout.js.map +0 -1
  125. package/build/src/visualization/viz-association.d.ts +0 -7
  126. package/build/src/visualization/viz-association.d.ts.map +0 -1
  127. package/build/src/visualization/viz-association.js +0 -3
  128. package/build/src/visualization/viz-association.js.map +0 -1
  129. package/build/src/visualization/viz-workspace.d.ts +0 -7
  130. package/build/src/visualization/viz-workspace.d.ts.map +0 -1
  131. package/build/src/visualization/viz-workspace.js +0 -3
  132. package/build/src/visualization/viz-workspace.js.map +0 -1
  133. package/src/visualization/elements/VizAssociationElement.ts +0 -3
  134. package/src/visualization/elements/VizWorkspaceElement.ts +0 -302
  135. package/src/visualization/elements/WorkspaceStyles.ts +0 -168
  136. package/src/visualization/lib/AnchorFinder.ts +0 -112
  137. package/src/visualization/lib/AnchorUtils.ts +0 -53
  138. package/src/visualization/lib/AssociationAnchors.ts +0 -418
  139. package/src/visualization/lib/LabelSketch.ts +0 -67
  140. package/src/visualization/lib/LineSketch.ts +0 -62
  141. package/src/visualization/lib/Point.ts +0 -134
  142. package/src/visualization/lib/PositionUtils.ts +0 -218
  143. package/src/visualization/lib/SelectionManager.ts +0 -513
  144. package/src/visualization/lib/ShapeArtist.ts +0 -222
  145. package/src/visualization/lib/SvgMarkers.ts +0 -80
  146. package/src/visualization/lib/TipSketch.ts +0 -91
  147. package/src/visualization/lib/TouchSupport.ts +0 -72
  148. package/src/visualization/lib/Utils.ts +0 -63
  149. package/src/visualization/lib/VisualizationTypes.ts +0 -232
  150. package/src/visualization/lib/WorkspaceAlignment.ts +0 -261
  151. package/src/visualization/lib/WorkspaceDebugging.ts +0 -313
  152. package/src/visualization/lib/WorkspaceEdges.ts +0 -1153
  153. package/src/visualization/lib/WorkspaceGestures.ts +0 -400
  154. package/src/visualization/lib/WorkspaceSizing.ts +0 -181
  155. package/src/visualization/lib/lines/RectilinearLine.ts +0 -589
  156. package/src/visualization/lib/tips/RectilinearTip.ts +0 -156
  157. package/src/visualization/lib/tips/TipArtist.ts +0 -34
  158. package/src/visualization/lib/types.ts +0 -173
  159. package/src/visualization/plugin/dnd/DragAndDropPlugin.ts +0 -294
  160. package/src/visualization/plugin/group-selection/GroupSelection.ts +0 -271
  161. package/src/visualization/plugin/positioning/DataModelLayout.ts +0 -114
  162. package/src/visualization/plugin/positioning/WorkspaceLayout.ts +0 -149
  163. package/src/visualization/viz-association.ts +0 -9
  164. package/src/visualization/viz-workspace.ts +0 -9
  165. package/test/env.d.ts +0 -9
  166. package/test/env.js +0 -7
  167. package/test/visualization/lib/AnchorFinder.test.ts +0 -313
  168. package/test/visualization/lib/AnchorUtils.test.ts +0 -178
  169. package/test/visualization/lib/PositionUtils.test.ts +0 -406
  170. package/test/visualization/lib/test-styles.css +0 -80
@@ -1,400 +0,0 @@
1
- import * as TouchSupport from './TouchSupport.js'
2
- // import { cancelEvent } from './Utils.js';
3
- import VizWorkspaceElement from '../elements/VizWorkspaceElement.js'
4
- import { TouchMoveResult } from './TouchSupport.js'
5
-
6
- const scrollSize = 25 // 25
7
- const scaleFactor = 0.03 // 25
8
-
9
- const xValue = Symbol('xValue')
10
- const yValue = Symbol('yValue')
11
-
12
- /**
13
- * A class that adds gestures support for the visualization workspace.
14
- * It controls the scrolling of the workspace canvas.
15
- */
16
- export class WorkspaceGestures {
17
- [xValue]?: number;
18
-
19
- [yValue]?: number
20
-
21
- /**
22
- * @return value The x-axis position value
23
- */
24
- get left(): number | null {
25
- return this[xValue] || null
26
- }
27
-
28
- /**
29
- * @param value The x-axis position value
30
- */
31
- set left(value: number | null) {
32
- const localValue = Number(value)
33
- if (Number.isNaN(localValue)) {
34
- return
35
- }
36
- const old = this[xValue]
37
- if (old === localValue) {
38
- return
39
- }
40
- this[xValue] = localValue
41
- this.workspace.requestUpdate('scrollLeft', old)
42
- }
43
-
44
- /**
45
- * @returns value The y-axis position value
46
- */
47
- get top(): number | null {
48
- return this[yValue] || null
49
- }
50
-
51
- /**
52
- * @param value The y-axis position value
53
- */
54
- set top(value: number | null) {
55
- const localValue = Number(value)
56
- if (Number.isNaN(localValue)) {
57
- return
58
- }
59
- const old = this[yValue]
60
- if (old === localValue) {
61
- return
62
- }
63
- this[yValue] = localValue
64
- this.workspace.requestUpdate('scrollTop', old)
65
- }
66
-
67
- constructor(public workspace: VizWorkspaceElement) {
68
- this.workspace = workspace
69
- this.top = null
70
- this.left = null
71
- this.wheelHandler = this.wheelHandler.bind(this)
72
- this.touchstartHandler = this.touchstartHandler.bind(this)
73
- this.touchmoveHandler = this.touchmoveHandler.bind(this)
74
- this.touchendHandler = this.touchendHandler.bind(this)
75
- this.clickHandler = this.clickHandler.bind(this)
76
- }
77
-
78
- connect(): void {
79
- this.workspace.addEventListener('mousewheel', this.wheelHandler as EventListener, { passive: true })
80
- this.workspace.addEventListener('touchstart', this.touchstartHandler, { capture: false, passive: true })
81
- this.workspace.addEventListener('touchmove', this.touchmoveHandler, { passive: true })
82
- this.workspace.addEventListener('touchend', this.touchendHandler, { capture: false })
83
- this.workspace.addEventListener('touchcancel', this.touchendHandler)
84
- this.workspace.addEventListener('click', this.clickHandler as EventListener, { capture: false })
85
- }
86
-
87
- disconnect(): void {
88
- this.workspace.removeEventListener('mousewheel', this.wheelHandler as EventListener)
89
- this.workspace.removeEventListener('touchstart', this.touchstartHandler, { capture: true })
90
- this.workspace.removeEventListener('touchmove', this.touchmoveHandler)
91
- this.workspace.removeEventListener('touchend', this.touchendHandler)
92
- this.workspace.removeEventListener('touchcancel', this.touchendHandler, { capture: false })
93
- this.workspace.removeEventListener('click', this.clickHandler as EventListener, { capture: false })
94
- }
95
-
96
- /**
97
- * An event handler for the mouse wheel action.
98
- * Zooms in/out the workspace.
99
- */
100
- wheelHandler(e: WheelEvent): void {
101
- // cancelEvent(e);
102
- if (e.ctrlKey || e.metaKey) {
103
- this.handleZoomEvent(e)
104
- } else {
105
- this.scrollFromEvent(e)
106
- }
107
- }
108
-
109
- /**
110
- * Zooms in/out the workspace.
111
- */
112
- handleZoomEvent(e: WheelEvent): void {
113
- let { scale = 1 } = this.workspace
114
- let pressure = e.deltaY
115
- const max = 10
116
- const mousePressure = 7
117
- if (pressure < -max) {
118
- pressure = -mousePressure
119
- } else if (pressure > max) {
120
- pressure = mousePressure
121
- }
122
- scale += pressure / 100
123
- if (scale > 3) {
124
- scale = 3
125
- }
126
- if (scale < 0.2) {
127
- scale = 0.2
128
- }
129
- this.workspace.scale = scale
130
- // const { zoom=0 } = this.workspace;
131
- // const zoomOut = e.deltaY > 0;
132
- // let factor = 1;
133
- // if (zoomOut) {
134
- // factor = -1;
135
- // }
136
- // const value = zoom + factor;
137
- // if (value <= -31) {
138
- // return;
139
- // }
140
- // this.workspace.zoom = zoom + factor;
141
- // this.workspace[notifyZoom]();
142
- }
143
-
144
- updateScale(): void {
145
- const { zoom } = this.workspace
146
- const scale = 1 + zoom * scaleFactor
147
- this.workspace.scale = scale
148
- this.workspace.requestUpdate()
149
- }
150
-
151
- /**
152
- * @returns true when there is an element that is draggable in the event's path.
153
- */
154
- hasDraggable(e: TouchEvent): boolean {
155
- const path = e.composedPath()
156
- let current = path.shift()
157
- while (current) {
158
- const typedNode = current as Node
159
- if (typedNode.nodeType !== Node.ELEMENT_NODE) {
160
- current = path.shift()
161
- continue
162
- }
163
- const element = current as HTMLElement
164
- if (element.draggable) {
165
- return true
166
- }
167
- current = path.shift()
168
- }
169
- return false
170
- }
171
-
172
- touchstartHandler(e: TouchEvent): void {
173
- if (this.hasDraggable(e)) {
174
- return
175
- }
176
- TouchSupport.add(e)
177
- }
178
-
179
- touchmoveHandler(e: TouchEvent): void {
180
- if (this.hasDraggable(e)) {
181
- return
182
- }
183
- const moves = TouchSupport.move(e)
184
- if (moves.length === 1) {
185
- this.scrollFromTouch(moves[0])
186
- } else if (moves.length === 2) {
187
- this.zoomFromTouch(moves)
188
- }
189
- }
190
-
191
- touchendHandler(e: TouchEvent): void {
192
- if (this.hasDraggable(e)) {
193
- return
194
- }
195
- TouchSupport.end(e)
196
- }
197
-
198
- /**
199
- * Dispatches the `scroll` event on the workspace.
200
- */
201
- notifyScroll(): void {
202
- this.workspace.dispatchEvent(new Event('scroll'))
203
- }
204
-
205
- /**
206
- * Handles scrolling from a touch event
207
- */
208
- async zoomFromTouch(moves: TouchMoveResult[]): Promise<void> {
209
- const [m1, m2] = moves
210
- const { scale } = this.workspace
211
- // I needed to come up with a number that would make the move a little bit more natural
212
- // and I came up with this..
213
- const anArbitraryNumber = 300
214
- if (m1.dy > 0 && m2.dy < 0) {
215
- const factor = m1.dy - m2.dy
216
- // zoom in
217
- this.workspace.scale = scale + (scale * factor) / anArbitraryNumber
218
- this.workspace.requestUpdate()
219
- } else if (m1.dy < 0 && m2.dy > 0) {
220
- // zoom out
221
- const factor = -m1.dy + m2.dy
222
- this.workspace.scale = scale - (scale * factor) / anArbitraryNumber
223
- this.workspace.requestUpdate()
224
- }
225
- }
226
-
227
- /**
228
- * Scrolls the current viewport to a given location.
229
- * @param forward Defines whether to scroll forward or backward.
230
- * For the `x` (the `left` value) axis it means going right when true and going left when false.
231
- * For the `y` (the `top` value) axis this means going down when true and up when false.
232
- * @param axis Scroll axis. Either `x` or `y`.
233
- */
234
- scroll(forward: boolean, axis: 'top' | 'left'): void {
235
- const { workspace } = this
236
- const { scale } = workspace
237
- const value = this[axis] || 0
238
- const scaledSize = scrollSize / scale
239
- const newValue = forward ? value - scaledSize : value + scaledSize
240
- this[axis] = newValue
241
- this.notifyScroll()
242
- }
243
-
244
- /**
245
- * Scrolls the view if the position defined by `x` and `y` arguments requires
246
- * the view to be moved.
247
- *
248
- * @param x The x coordinate of the point
249
- * @param y The y coordinate of the point
250
- * @returns true if the workspace was moved
251
- */
252
- scrollIfNeeded(x: number, y: number): boolean {
253
- const { workspace } = this
254
- const { bottom, top, right, left } = workspace.getBoundingClientRect()
255
- const scrollMargin = 40
256
- if (y - scrollMargin < top) {
257
- // requires workspace' viewport to scroll up
258
- this.scroll(false, 'top')
259
- this.notifyScroll()
260
- return true
261
- }
262
- if (y + scrollMargin > bottom) {
263
- // requires workspace' viewport to scroll down
264
- this.scroll(true, 'top')
265
- this.notifyScroll()
266
- return true
267
- }
268
- if (x - scrollMargin < left) {
269
- // requires workspace' viewport to scroll left
270
- this.scroll(false, 'left')
271
- this.notifyScroll()
272
- return true
273
- }
274
- if (x + scrollMargin > right) {
275
- // requires workspace' viewport to scroll right
276
- this.scroll(true, 'left')
277
- this.notifyScroll()
278
- return true
279
- }
280
- return false
281
- }
282
-
283
- /**
284
- * Scrolls the element by the given amount.
285
- * @param xCoordOrOptions The horizontal pixel value that you want to scroll by
286
- * or the scroll options. When passed value is the `ScrollToOptions` interface then
287
- * the second argument is ignored.
288
- * @param yCoord The vertical pixel value that you want to scroll by.
289
- */
290
- scrollBy(xCoordOrOptions: number | ScrollToOptions, yCoord?: number): void {
291
- const [byX, byY] = this.getScrollOptionsSafe(xCoordOrOptions, yCoord)
292
- let [x, y] = this.getXYSafe()
293
- x -= byX
294
- y -= byY
295
- this.left = x
296
- this.top = y
297
- this.notifyScroll()
298
- }
299
-
300
- /**
301
- * Scrolls to a particular set of coordinates inside the element.
302
- *
303
- * @param xCoordOrOptions The pixel along the horizontal axis of the element
304
- * that you want displayed in the upper left. When passed value is the `ScrollToOptions` interface then
305
- * the second argument is ignored.
306
- * @param yCoord The pixel along the vertical axis of the element that you want displayed in the upper left.
307
- */
308
- scrollTo(xCoordOrOptions: number | ScrollToOptions, yCoord?: number): void {
309
- const [x, y] = this.getScrollOptionsSafe(xCoordOrOptions, yCoord)
310
- this.left = x
311
- this.top = y
312
- this.notifyScroll()
313
- }
314
-
315
- /**
316
- * Scrolls from the event values.
317
- */
318
- scrollFromEvent(e: WheelEvent): void {
319
- let [x, y] = this.getXYSafe()
320
- const factor = 1 / this.workspace.scale // 1;
321
- let dx = e.deltaX
322
- let dy = e.deltaY
323
- if (e.shiftKey && e.deltaX === 0) {
324
- // Under linux (possibly windows too) when shift is pressed
325
- // then the `e.deltaX` is not populated as it happens on MacOS.
326
- // This sets dx value to the dy and resets dy.
327
- dx = dy
328
- dy = -0
329
- }
330
- x -= dx * factor
331
- y -= dy * factor
332
- this.left = x
333
- this.top = y
334
- this.notifyScroll()
335
- }
336
-
337
- /**
338
- * Handles scrolling from a touch event
339
- */
340
- scrollFromTouch(move: TouchMoveResult): void {
341
- let [x, y] = this.getXYSafe()
342
- const factor = 1
343
- const { dx, dy } = move
344
- x -= dx * factor
345
- y -= dy * factor
346
- this.left = x
347
- this.top = y
348
- this.notifyScroll()
349
- }
350
-
351
- /**
352
- * Reads the `x` and `y` point from the parameters that can be just a `xy` pair
353
- * or arguments or a value of the `ScrollToOptions` interface.
354
- *
355
- * @param xCoordOrOptions The horizontal pixel value or the scroll options.
356
- * When passed value is the `ScrollToOptions` interface then the second argument is ignored.
357
- * @param yCoord The vertical pixel value
358
- *
359
- * @returns A point of the X and Y read from the options with default values.
360
- */
361
- getScrollOptionsSafe(xCoordOrOptions: ScrollToOptions | number, yCoord?: number): number[] {
362
- const typedX = Number(xCoordOrOptions)
363
- const typedY = Number(yCoord)
364
- let byX
365
- let byY
366
- if (Number.isNaN(typedX) && Number.isNaN(typedY)) {
367
- const { top = 0, left = 0 } = xCoordOrOptions as ScrollToOptions
368
- byX = Number(left)
369
- byY = Number(top)
370
- } else {
371
- byX = typedX || 0
372
- byY = typedY || 0
373
- }
374
- return [byX, byY]
375
- }
376
-
377
- /**
378
- * Reads current left and top values and returns the numbers, even when not defined.
379
- *
380
- * @returns A point of the left and top position of the workspace.
381
- */
382
- getXYSafe(): number[] {
383
- let { left = 0, top = 0 } = this
384
- if (left === null) {
385
- left = 0
386
- }
387
- if (top === null) {
388
- top = 0
389
- }
390
- return [left, top]
391
- }
392
-
393
- clickHandler(e: PointerEvent): void {
394
- if (e.detail === 3) {
395
- this.workspace.zoom = 0
396
- this.scrollTo(0, 0)
397
- // this.center();
398
- }
399
- }
400
- }
@@ -1,181 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- import VizWorkspaceElement from '../elements/VizWorkspaceElement.js'
3
- import { getObjectBoundingClientRect } from './PositionUtils.js'
4
-
5
- export const observeItems = Symbol('observeItems')
6
- export const mutationHandler = Symbol('mutationHandler')
7
- export const mutationObserver = Symbol('mutationObserver')
8
- export const processAddedNodes = Symbol('processAddedNodes')
9
- export const processAttributeChanged = Symbol('processAttributeChanged')
10
- export const connectedValue = Symbol('connectedValue')
11
- export const queueDebouncer = Symbol('queueDebouncer')
12
-
13
- /**
14
- * A class that controls the `autoResize` property of the workspace.
15
- * When this property is set it keeps track of elements moving in the workspace and when they
16
- * are positioned outside the bounds of the current workspace it resizes it.
17
- *
18
- * Note, currently it only works when placing items to the right or below workspace.
19
- */
20
- export class WorkspaceSizing {
21
- [connectedValue] = false
22
-
23
- /**
24
- * @returns True when the plug-in is listening for the input events.
25
- */
26
- get connected(): boolean {
27
- return this[connectedValue]
28
- }
29
-
30
- processElementsQueue: HTMLElement[] = [];
31
-
32
- [mutationObserver]?: MutationObserver
33
-
34
- constructor(public workspace: VizWorkspaceElement) {
35
- this[mutationHandler] = this[mutationHandler].bind(this)
36
- }
37
-
38
- /**
39
- * Starts listening on user events
40
- */
41
- connect(): void {
42
- if (this[connectedValue]) {
43
- return
44
- }
45
- this[mutationObserver] = this[observeItems]()
46
- this[connectedValue] = true
47
- }
48
-
49
- /**
50
- * Cleans up the listeners
51
- */
52
- disconnect(): void {
53
- const mo = this[mutationObserver]
54
- if (mo) {
55
- mo.disconnect()
56
- this[mutationObserver] = undefined
57
- }
58
- this[connectedValue] = false
59
- }
60
-
61
- /**
62
- * Processes a single element to check whether the workspace has to be resized
63
- * to account for the element's position.
64
- */
65
- processElement(node: HTMLElement): void {
66
- const box = getObjectBoundingClientRect(node, this.workspace)
67
- const { width, height } = this.workspace
68
- if (box.right > width) {
69
- this.workspace.width = box.right + 40
70
- }
71
- if (box.bottom > height) {
72
- this.workspace.height = box.bottom + 40
73
- }
74
- }
75
-
76
- [queueDebouncer]?: number
77
-
78
- /**
79
- * Adds an element to the processing queue. The queue runs after a next frame so the workspace is computed.
80
- */
81
- queueElement(node: HTMLElement): void {
82
- if (!Array.isArray(this.processElementsQueue)) {
83
- this.processElementsQueue = []
84
- }
85
- this.processElementsQueue.push(node)
86
- if (this[queueDebouncer]) {
87
- clearTimeout(this[queueDebouncer])
88
- }
89
- this[queueDebouncer] = setTimeout(() => {
90
- this[queueDebouncer] = undefined
91
- this.runQueue()
92
- }, 0) as unknown as number
93
- }
94
-
95
- runQueue(): void {
96
- const { processElementsQueue } = this
97
- if (!Array.isArray(processElementsQueue) || !processElementsQueue.length) {
98
- return
99
- }
100
- processElementsQueue.forEach((node) => this.processElement(node))
101
- this.processElementsQueue = []
102
- }
103
-
104
- /**
105
- * Observe items change in the element's light DOM
106
- * @return The observer handler
107
- */
108
- [observeItems](): MutationObserver {
109
- const config: MutationObserverInit = { attributes: true, childList: true, subtree: true, attributeOldValue: true }
110
- const observer = new MutationObserver(this[mutationHandler])
111
- observer.observe(this.workspace, config)
112
- return observer
113
- }
114
-
115
- /**
116
- * Processes mutations in the workspace and manages selection state.
117
- * @param mutationsList List of mutations.
118
- */
119
- async [mutationHandler](mutationsList: MutationRecord[]): Promise<void> {
120
- await this.workspace.updateComplete
121
- for (const mutation of mutationsList) {
122
- if (mutation.type === 'childList') {
123
- this[processAddedNodes](mutation.addedNodes)
124
- } else if (mutation.type === 'attributes') {
125
- this[processAttributeChanged](mutation)
126
- }
127
- }
128
- }
129
-
130
- /**
131
- * Processes added to the canvas elements.
132
- * @param nodes The list of added nodes
133
- */
134
- [processAddedNodes](nodes: NodeList): void {
135
- nodes.forEach((node) => {
136
- if (node.nodeType !== Node.ELEMENT_NODE) {
137
- return
138
- }
139
- const typed = node as HTMLElement
140
- const name = typed.localName
141
- if (['viz-workspace', 'viz-association'].includes(name)) {
142
- return
143
- }
144
- const { dataset } = typed
145
- if (!dataset) {
146
- return
147
- }
148
- if (dataset.associationSlot) {
149
- return
150
- }
151
- this.queueElement(typed)
152
- this[processAddedNodes](typed.querySelectorAll('*'))
153
- })
154
- }
155
-
156
- /**
157
- * Processes changed attribute on any element in the canvas
158
- * @param mutation The record associated with the change
159
- */
160
- [processAttributeChanged](mutation: MutationRecord): void {
161
- const att = mutation.attributeName!
162
- const nodeName = mutation.target.nodeName.toLowerCase()
163
- if (['viz-workspace', 'viz-association'].includes(nodeName)) {
164
- return
165
- }
166
- const isView = nodeName === 'modeling-view'
167
- const { processElementsQueue } = this
168
- let typed = mutation.target as HTMLElement
169
- if (isView && ['name', 'value'].includes(att)) {
170
- typed = typed.parentElement as HTMLElement
171
- } else if (isView) {
172
- return
173
- }
174
- if (processElementsQueue.includes(typed)) {
175
- return
176
- }
177
- if (isView) {
178
- this.queueElement(typed)
179
- }
180
- }
181
- }