@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,156 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- import { Point } from '../Point.js'
3
- import { IEdgeDirections } from '../types.js'
4
- import { IAssociationTip, IVisualizationRectilinearLineShape } from '../VisualizationTypes.js'
5
- import { TipArtist } from './TipArtist.js'
6
-
7
- export class RectilinearTip extends TipArtist {
8
- override line: IVisualizationRectilinearLineShape
9
-
10
- constructor(position: 'start' | 'end', line: IVisualizationRectilinearLineShape, directions: IEdgeDirections) {
11
- super(position, line, directions)
12
- this.line = line
13
- }
14
-
15
- /**
16
- * Draws an tip representing a parent.
17
- */
18
- override parent(): IAssociationTip {
19
- const { line, directions, position } = this
20
- const coordinates = line.coordinates!
21
- const startPoint = position === 'start' ? coordinates[0] : coordinates[coordinates.length - 1]
22
- const { x, y } = startPoint
23
- const tv = new Point(0, 0)
24
- const lv = new Point(0, 0)
25
- const rv = new Point(0, 0)
26
- tv.x = x
27
- tv.y = y
28
- lv.x = x - 8
29
- lv.y = y + 16
30
- rv.x = x + 8
31
- rv.y = y + 16
32
- const vertexes = [tv, lv, rv]
33
- const path = vertexes.map((item) => `${item.x},${item.y}`).join(' ')
34
- let rotate
35
- switch (directions.end) {
36
- case 'east':
37
- rotate = 90
38
- break
39
- case 'west':
40
- rotate = 270
41
- break
42
- case 'south':
43
- rotate = 0
44
- break
45
- default:
46
- rotate = 180
47
- break
48
- }
49
- return {
50
- path,
51
- coordinates: vertexes,
52
- transformOrigin: `${x}px ${y}px`,
53
- rotate,
54
- svg: 'polygon',
55
- style: 'parent',
56
- }
57
- }
58
-
59
- /**
60
- * Draws an tip representing a direction to / from the point.
61
- * @returns {IAssociationTip}
62
- */
63
- override direction(): IAssociationTip {
64
- const { line, directions, position } = this
65
- const coordinates = line.coordinates!
66
- const startPoint = position === 'start' ? coordinates[0] : coordinates[coordinates.length - 1]
67
- const { x, y } = startPoint
68
- const tv = new Point(0, 0)
69
- const lv = new Point(0, 0)
70
- const rv = new Point(0, 0)
71
- tv.x = x
72
- tv.y = y
73
- lv.x = x - 8
74
- lv.y = y - 16
75
- rv.x = x + 8
76
- rv.y = y - 16
77
- const vertexes = [tv, lv, rv]
78
- const path = vertexes.map((item) => `${item.x},${item.y}`).join(' ')
79
- let rotate
80
- const origin = position === 'start' ? directions.start : directions.end
81
- switch (origin) {
82
- case 'east':
83
- rotate = position === 'start' ? 90 : 270
84
- break
85
- case 'west':
86
- rotate = position === 'start' ? 270 : 90
87
- break
88
- case 'south':
89
- rotate = 180
90
- break
91
- default:
92
- rotate = 0
93
- break
94
- }
95
- return {
96
- path,
97
- coordinates: vertexes,
98
- transformOrigin: `${x}px ${y}px`,
99
- rotate,
100
- svg: 'polygon',
101
- style: 'direction',
102
- }
103
- }
104
-
105
- /**
106
- * Draws an tip representing an association.
107
- * @param type The type of the association to draw.
108
- */
109
- override association(type = 'default'): IAssociationTip {
110
- switch (type) {
111
- case 'default':
112
- return this.defaultAssociation()
113
- default:
114
- throw new Error(`Unsupported association type.`)
115
- }
116
- }
117
-
118
- /**
119
- * Draws an tip representing an association with a default style.
120
- */
121
- defaultAssociation(): IAssociationTip {
122
- const { line, directions, position } = this
123
- const coordinates = line.coordinates!
124
- const startPoint = position === 'start' ? coordinates[0] : coordinates[coordinates.length - 1]
125
- const { x, y } = startPoint
126
- const tv = new Point(x - 8, y)
127
- const lv = new Point(x, y - 16)
128
- const rv = new Point(x + 8, y)
129
- const vertexes = [tv, lv, rv]
130
- const path = vertexes.map((item) => `${item.x} ${item.y}`).join(', ')
131
- let rotate
132
- const origin = position === 'start' ? directions.start : directions.end
133
- switch (origin) {
134
- case 'east':
135
- rotate = position === 'start' ? 90 : 270
136
- break
137
- case 'west':
138
- rotate = position === 'start' ? 270 : 90
139
- break
140
- case 'south':
141
- rotate = 180
142
- break
143
- default:
144
- rotate = 0
145
- break
146
- }
147
- return {
148
- path,
149
- coordinates: vertexes,
150
- transformOrigin: `${x}px ${y}px`,
151
- rotate,
152
- svg: 'polyline',
153
- style: 'association',
154
- }
155
- }
156
- }
@@ -1,34 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
-
3
- import { IEdgeDirections } from '../types.js'
4
- import { IAssociationTip, IVisualizationAssociationShape } from '../VisualizationTypes.js'
5
-
6
- export class TipArtist {
7
- constructor(
8
- public position: 'start' | 'end',
9
- public line: IVisualizationAssociationShape,
10
- public directions: IEdgeDirections
11
- ) {}
12
-
13
- /**
14
- * Draws an tip representing a parent.
15
- */
16
- parent(): IAssociationTip {
17
- throw new Error('Not implemented')
18
- }
19
-
20
- /**
21
- * Draws an tip representing a direction to / from the point.
22
- */
23
- direction(): IAssociationTip {
24
- throw new Error('Not implemented')
25
- }
26
-
27
- /**
28
- * Draws an tip representing an association.
29
- * @param type The type of the association to draw.
30
- */
31
- association(type = 'default'): IAssociationTip {
32
- throw new Error('Not implemented')
33
- }
34
- }
@@ -1,173 +0,0 @@
1
- import type { IAssociationShape } from './VisualizationTypes.js'
2
- import type { Point } from './Point.js'
3
-
4
- export type xPositionOrCoord = number | number[]
5
- export type GeoDirection = 'south' | 'west' | 'north' | 'east'
6
-
7
- /**
8
- * A workspace element edge definition.
9
- * This model is being visualized in the view.
10
- */
11
- export interface IWorkspaceEdge {
12
- /**
13
- * An unique id of the association.
14
- * Usually it is the domain id of the domain object, but it may be any value.
15
- */
16
- id: string
17
- /**
18
- * The domain id of the association's source
19
- */
20
- source: string
21
- /**
22
- * The domain id of the association's source
23
- */
24
- target: string
25
- /**
26
- * When true then the user is allowed to change the potion of the association in the source and the target.
27
- */
28
- positionChange: boolean
29
- /**
30
- * The directions of the end of the association line.
31
- */
32
- directions: IEdgeDirections
33
- /**
34
- * The computed shape of the association.
35
- */
36
- shape: IAssociationShape
37
- }
38
-
39
- export interface IEdgeDirections {
40
- /**
41
- * The direction the edge is pointing to when attached to the target of an association.
42
- */
43
- start: GeoDirection
44
- /**
45
- * The direction the edge is pointing at the beginning of the association.
46
- */
47
- end: GeoDirection
48
- }
49
-
50
- /**
51
- * An interface describing a structure of a selected domain object in the workspace.
52
- * This is used when reading value of `selection.selected` of the workspace element.
53
- */
54
- export interface ISelectedDomain {
55
- /**
56
- * The domain id of the selected object.
57
- */
58
- id: string
59
- /**
60
- * The HTML element name of the selected object.
61
- */
62
- name: string
63
- /**
64
- * A reference to the selected node.
65
- */
66
- node: Element
67
- }
68
-
69
- /**
70
- * A definition used by the `WorkspaceEdges` class to compute the visualization line representing an association.
71
- */
72
- export interface ICalculateEdgeOptions {
73
- /**
74
- * The visualization object that is the source of the association.
75
- */
76
- sourceElement: HTMLElement
77
- /**
78
- * The visualization object that is the target of the association.
79
- */
80
- targetElement: HTMLElement
81
- /**
82
- * The association domain id. Can be a random string not really being a domain id (parent visualization, for example)
83
- */
84
- id: string
85
- /**
86
- * The name of the association (rendered label)
87
- */
88
- name?: string
89
- /**
90
- * If supported by the source object, the name of the slot to use to start the line.
91
- */
92
- sourceSlot?: string
93
- /**
94
- * If supported by the target object, the name of the slot to use to end the line at.
95
- */
96
- targetSlot?: string
97
- /**
98
- * Other associations already built between the two objects.
99
- */
100
- others?: IWorkspaceEdge[]
101
- }
102
-
103
- export interface IWorkspaceRenderingOptions {
104
- /**
105
- * The domain if of the currently rendered object
106
- */
107
- id: string
108
- /**
109
- * The type of the currently rendered object. This is helpful for APIs where different views are possible.
110
- */
111
- type?: unknown
112
- }
113
-
114
- export interface IAnchorAssociationCreateEventDetail {
115
- source: {
116
- /**
117
- * The domain id of the association source
118
- */
119
- id: string
120
- /**
121
- * The workspace coordinates of the staring point
122
- */
123
- point: Point
124
- /**
125
- * The slot name of the source object
126
- */
127
- slot: string
128
- }
129
-
130
- target: {
131
- /**
132
- * The domain id of the association target
133
- */
134
- id: string
135
- /**
136
- * The workspace coordinates of the end point
137
- */
138
- point: Point
139
- /**
140
- * The slot name of the target object
141
- */
142
- slot: string
143
- }
144
- }
145
-
146
- export interface IAnchorAssociationUpdateEventDetail {
147
- source: {
148
- /**
149
- * The domain id of the association
150
- */
151
- associationId: string
152
- /**
153
- * The direction where the association changed (at the end changing
154
- * the target or at the beginning changing the source)
155
- */
156
- direction: 'start' | 'end'
157
- }
158
-
159
- target: {
160
- /**
161
- * The domain id of the new target/source (depending on the source.direction)
162
- */
163
- id: string
164
- /**
165
- * The workspace coordinates of the start/end point (depending on the source.direction)
166
- */
167
- point: Point
168
- /**
169
- * The slot name to use
170
- */
171
- slot: string
172
- }
173
- }
@@ -1,294 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- /* eslint-disable @typescript-eslint/no-unused-vars */
3
-
4
- import VizWorkspaceElement from '../../elements/VizWorkspaceElement.js'
5
- import { notifyMoved } from '../../lib/PositionUtils.js'
6
-
7
- export const observeItems = Symbol('observeItems')
8
- export const mutationHandler = Symbol('mutationHandler')
9
- export const mutationObserver = Symbol('mutationObserver')
10
- export const processAddedNodes = Symbol('processAddedNodes')
11
- export const processRemovedNodes = Symbol('processRemovedNodes')
12
- export const processAttributeChanged = Symbol('processAttributeChanged')
13
- export const dragEnterHandler = Symbol('dragEnterHandler')
14
- export const dragOverHandler = Symbol('dragOverHandler')
15
- export const dropHandler = Symbol('dropHandler')
16
- export const dragHandler = Symbol('dragHandler')
17
- export const observeCurrent = Symbol('observeCurrent')
18
- export const unobserveCurrent = Symbol('unobserveCurrent')
19
- export const connectedValue = Symbol('connectedValue')
20
-
21
- interface DragInfo {
22
- /**
23
- * click x position inside the dragged element
24
- */
25
- sx: number
26
- /**
27
- * click y position inside the dragged element
28
- */
29
- sy: number
30
- target: HTMLElement
31
- }
32
-
33
- /**
34
- * A plugin that adds drag and drop support to the visualization workspace.
35
- *
36
- * This is a base class that meant to be extended depending on what the workspace visualizes.
37
- * The implementation for a specific type of a workspace should override the `dropExternal()`
38
- * function to handle dropping onto the workspace a new object.
39
- *
40
- * Additionally the `[dropHandler]()` can be updated to handle custom logic for drop action of
41
- * already visualized object. The default behavior is to reposition all currently selected elements
42
- * relative to the dragged object position change.
43
- *
44
- * After the workspace is created initialize this class and call the `connect()` function to initialize
45
- * event listeners. When the plugin is no longer needed call `disconnect()` function to clean up listeners.
46
- *
47
- * For the visualized elements to be draggable set `draggable="true"` attribute on the element. If the attribute
48
- * is removed or changed the internal logic adds or removed the events from the element.
49
- */
50
- export class DragAndDropPlugin {
51
- [connectedValue] = false;
52
-
53
- [mutationObserver]?: MutationObserver
54
-
55
- dragInfo?: DragInfo
56
-
57
- /**
58
- * @returns True when the plug-in is listening for the input events.
59
- */
60
- get connected(): boolean {
61
- return this[connectedValue]
62
- }
63
-
64
- constructor(public workspace: VizWorkspaceElement) {
65
- this[dragEnterHandler] = this[dragEnterHandler].bind(this)
66
- this[dragOverHandler] = this[dragOverHandler].bind(this)
67
- this[dropHandler] = this[dropHandler].bind(this)
68
- this[dragHandler] = this[dragHandler].bind(this)
69
-
70
- this[mutationHandler] = this[mutationHandler].bind(this)
71
- this[connectedValue] = false
72
- }
73
-
74
- connect(): void {
75
- this.workspace.addEventListener('dragenter', this[dragEnterHandler])
76
- this.workspace.addEventListener('dragover', this[dragOverHandler])
77
- this.workspace.addEventListener('drop', this[dropHandler])
78
- this[mutationObserver] = this[observeItems]()
79
- this[observeCurrent]()
80
- this[connectedValue] = true
81
- }
82
-
83
- disconnect(): void {
84
- this.workspace.removeEventListener('dragenter', this[dragEnterHandler])
85
- this.workspace.removeEventListener('dragover', this[dragOverHandler])
86
- this.workspace.removeEventListener('drop', this[dropHandler])
87
- if (this[mutationObserver]) {
88
- this[mutationObserver]!.disconnect()
89
- this[mutationObserver] = undefined
90
- }
91
- this[unobserveCurrent]()
92
- this[connectedValue] = false
93
- }
94
-
95
- /**
96
- * Sets drag info value from the drag event
97
- */
98
- setDragInfo(e: DragEvent): void {
99
- const node = e.target as HTMLElement
100
- const { left, top } = node.getBoundingClientRect()
101
- const { clientX, clientY } = e
102
- const { scale } = this.workspace
103
- this.dragInfo = {
104
- sx: (clientX - left) / scale,
105
- sy: (clientY - top) / scale,
106
- target: node,
107
- }
108
- }
109
-
110
- /**
111
- * Repositions currently selected elements from a drop event.
112
- * This is called when the dropped element onto the workspace comes from the same workspace.
113
- */
114
- repositionFromDrop(e: DragEvent): void {
115
- const { target, sx, sy } = this.dragInfo!
116
- const dragTarget = target as HTMLElement
117
- const { left, top } = dragTarget.getBoundingClientRect()
118
- const { scale } = this.workspace
119
- const ex = (e.clientX - left) / scale
120
- const ey = (e.clientY - top) / scale
121
- // tests by how much the box was moved in the workspace so the same point can be applied
122
- // to all boxes in the move.
123
- const ddx = ex - sx
124
- const ddy = ey - sy
125
- let items: HTMLElement[] = []
126
- const selectionManager = this.workspace.selection
127
- selectionManager.selected.forEach((item) => {
128
- if (item.node.hasAttribute('draggable') && item.node.getAttribute('draggable') === 'true') {
129
- items.push(item.node as HTMLElement)
130
- }
131
- })
132
- if (!items.length || (items.length === 1 && items[0] !== target)) {
133
- items = [dragTarget]
134
- }
135
- items.forEach((item) => notifyMoved(item, ddx, ddy))
136
- }
137
-
138
- /**
139
- * This function is called when a new object is dropped onto the workspace.
140
- * A "new object" is an object that has a source different than the current workspace.
141
- */
142
- async dropExternal(e: DragEvent): Promise<void> {
143
- // to be implemented by child classes.
144
- }
145
-
146
- /**
147
- * @returns True if the element can be dragged.
148
- */
149
- isDraggable(element: Element): boolean {
150
- return element.hasAttribute('draggable') && element.getAttribute('draggable') === 'true'
151
- }
152
-
153
- // PRIVATE APIS
154
-
155
- /**
156
- * Observe items change in the element's light DOM
157
- * @returns The observer handler
158
- */
159
- [observeItems](): MutationObserver {
160
- const config = {
161
- attributes: true,
162
- childList: true,
163
- subtree: true,
164
- attributeFilter: ['draggable'],
165
- }
166
- const observer = new MutationObserver(this[mutationHandler])
167
- observer.observe(this.workspace, config)
168
- return observer
169
- }
170
-
171
- /**
172
- * Processes mutations in the workspace and manages selection state.
173
- * @param mutationsList List of mutations.
174
- */
175
- [mutationHandler](mutationsList: MutationRecord[]): void {
176
- for (const mutation of mutationsList) {
177
- // console.log(mutation);
178
- if (mutation.type === 'childList') {
179
- if (mutation.addedNodes.length) {
180
- this[processAddedNodes](mutation.addedNodes)
181
- }
182
- if (mutation.removedNodes.length) {
183
- this[processRemovedNodes](mutation.removedNodes)
184
- }
185
- } else if (mutation.type === 'attributes' && mutation.attributeName === 'draggable') {
186
- this[processAttributeChanged](mutation.target)
187
- }
188
- }
189
- }
190
-
191
- /**
192
- * Processes added children.
193
- * It adds drag and drop support.
194
- */
195
- [processAddedNodes](list: NodeList): void {
196
- Array.from(list).forEach((node) => {
197
- if (node.nodeType !== Node.ELEMENT_NODE) {
198
- return
199
- }
200
- const element = node as HTMLElement
201
- if (this.isDraggable(element)) {
202
- element.addEventListener('dragstart', this[dragHandler])
203
- }
204
- const childList = element.querySelectorAll('[draggable]')
205
- this[processAddedNodes](childList)
206
- })
207
- }
208
-
209
- /**
210
- * Processes removed children.
211
- * It removes drag and drop support.
212
- */
213
- [processRemovedNodes](list: NodeList): void {
214
- Array.from(list).forEach((node) => {
215
- if (node.nodeType !== Node.ELEMENT_NODE) {
216
- return
217
- }
218
- const element = node as HTMLElement
219
- element.removeEventListener('dragstart', this[dragHandler])
220
- const childList = element.querySelectorAll('[draggable]')
221
- this[processRemovedNodes](childList)
222
- })
223
- }
224
-
225
- /**
226
- * Adds or removes the `dragstart` event listener depending on the value oif the `draggable` attribute
227
- */
228
- [processAttributeChanged](node: Node): void {
229
- if (node.nodeType !== Node.ELEMENT_NODE) {
230
- return
231
- }
232
- const typed = node as Element
233
- typed.removeEventListener('dragstart', this[dragHandler] as EventListener)
234
- if (this.isDraggable(typed)) {
235
- typed.addEventListener('dragstart', this[dragHandler] as EventListener)
236
- }
237
- }
238
-
239
- /**
240
- * Handles the drag event on one of the children.
241
- */
242
- [dragHandler](e: DragEvent): void {
243
- // only elements are getting drag support so it is safe to set.
244
- e.dataTransfer!.setData('modeling/source', this.workspace.localName)
245
- this.setDragInfo(e)
246
- }
247
-
248
- /**
249
- * Handles the drag enter event on one of the children.
250
- */
251
- [dragEnterHandler](e: DragEvent): void {
252
- e.preventDefault()
253
- }
254
-
255
- /**
256
- * Handles the drag over event on one of the children.
257
- */
258
- [dragOverHandler](e: DragEvent): void {
259
- e.preventDefault()
260
- const { clientX, clientY } = e
261
- this.workspace.scrollIfNeeded(clientX, clientY)
262
- }
263
-
264
- /**
265
- * Handles the drop event on one of the visualization canvas to update position of them.
266
- *
267
- * Note, some workspace elements can handle its own drop event and cancel it. In this case
268
- * this function won't be called.
269
- */
270
- async [dropHandler](e: DragEvent): Promise<void> {
271
- const source = e.dataTransfer!.getData('modeling/source')
272
- if (source !== this.workspace.localName) {
273
- this.dropExternal(e)
274
- } else {
275
- this.repositionFromDrop(e)
276
- }
277
- }
278
-
279
- /**
280
- * Observers all current draggable items in the workspace.
281
- */
282
- [observeCurrent](): void {
283
- const nodes = Array.from(this.workspace.querySelectorAll('[draggable="true"]')) as HTMLElement[]
284
- nodes.forEach((node) => node.addEventListener('dragstart', this[dragHandler]))
285
- }
286
-
287
- /**
288
- * Removes drag start listener from all current draggable items in the workspace.
289
- */
290
- [unobserveCurrent](): void {
291
- const nodes = Array.from(this.workspace.querySelectorAll('[draggable="true"]')) as HTMLElement[]
292
- nodes.forEach((node) => node.removeEventListener('dragstart', this[dragHandler]))
293
- }
294
- }