@next-bricks/diagram 0.18.0 → 0.20.0

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 (52) hide show
  1. package/dist/bricks.json +8 -4
  2. package/dist/chunks/2680.440281fd.js +3 -0
  3. package/dist/chunks/2680.440281fd.js.map +1 -0
  4. package/dist/chunks/{2976.fcb2a439.js → 2976.375fa83c.js} +2 -2
  5. package/dist/chunks/{5356.931b1f12.js.map → 2976.375fa83c.js.map} +1 -1
  6. package/dist/chunks/{3322.63bf67fe.js → 3322.eaf8483d.js} +2 -2
  7. package/dist/chunks/{3322.63bf67fe.js.map → 3322.eaf8483d.js.map} +1 -1
  8. package/dist/chunks/3780.57b33842.js +3 -0
  9. package/dist/chunks/{720.fc86c182.js.LICENSE.txt → 3780.57b33842.js.LICENSE.txt} +0 -6
  10. package/dist/chunks/3780.57b33842.js.map +1 -0
  11. package/dist/chunks/4092.422e3ee4.js +2 -0
  12. package/dist/chunks/4092.422e3ee4.js.map +1 -0
  13. package/dist/chunks/{5356.931b1f12.js → 5356.ec95af1d.js} +2 -2
  14. package/dist/chunks/{2976.fcb2a439.js.map → 5356.ec95af1d.js.map} +1 -1
  15. package/dist/chunks/{8020.7d347956.js → 8020.528badbd.js} +2 -2
  16. package/dist/chunks/{8020.7d347956.js.map → 8020.528badbd.js.map} +1 -1
  17. package/dist/chunks/{eo-diagram.2b8615e9.js → eo-diagram.9d077ab7.js} +2 -2
  18. package/dist/chunks/{eo-diagram.2b8615e9.js.map → eo-diagram.9d077ab7.js.map} +1 -1
  19. package/dist/chunks/eo-draw-canvas.03073fd4.js +2 -0
  20. package/dist/chunks/eo-draw-canvas.03073fd4.js.map +1 -0
  21. package/dist/chunks/main.6831cfb7.js +2 -0
  22. package/dist/chunks/main.6831cfb7.js.map +1 -0
  23. package/dist/examples.json +3 -3
  24. package/dist/index.539888da.js +2 -0
  25. package/dist/index.539888da.js.map +1 -0
  26. package/dist/manifest.json +87 -36
  27. package/dist/types.json +230 -67
  28. package/dist-types/draw-canvas/CellComponent.d.ts +3 -1
  29. package/dist-types/draw-canvas/ConnectLineComponent.d.ts +10 -0
  30. package/dist-types/draw-canvas/ConnectLineComponent.spec.d.ts +1 -0
  31. package/dist-types/draw-canvas/decorators/DecoratorArea.d.ts +1 -1
  32. package/dist-types/draw-canvas/decorators/index.d.ts +1 -1
  33. package/dist-types/draw-canvas/index.d.ts +18 -2
  34. package/dist-types/draw-canvas/interfaces.d.ts +15 -0
  35. package/dist-types/draw-canvas/processors/handleMouseDown.d.ts +2 -1
  36. package/dist-types/draw-canvas/processors/initializeCells.d.ts +5 -0
  37. package/dist-types/draw-canvas/processors/transformToCenter.d.ts +8 -0
  38. package/dist-types/draw-canvas/processors/transformToCenter.spec.d.ts +1 -0
  39. package/dist-types/draw-canvas/reducers/interfaces.d.ts +10 -2
  40. package/docs/eo-draw-canvas.md +309 -282
  41. package/package.json +3 -2
  42. package/dist/chunks/6640.2234fe8b.js +0 -2
  43. package/dist/chunks/6640.2234fe8b.js.map +0 -1
  44. package/dist/chunks/720.fc86c182.js +0 -3
  45. package/dist/chunks/720.fc86c182.js.map +0 -1
  46. package/dist/chunks/eo-draw-canvas.6aeeb2f0.js +0 -3
  47. package/dist/chunks/eo-draw-canvas.6aeeb2f0.js.map +0 -1
  48. package/dist/chunks/main.56609245.js +0 -2
  49. package/dist/chunks/main.56609245.js.map +0 -1
  50. package/dist/index.5cba071e.js +0 -2
  51. package/dist/index.5cba071e.js.map +0 -1
  52. /package/dist/chunks/{eo-draw-canvas.6aeeb2f0.js.LICENSE.txt → 2680.440281fd.js.LICENSE.txt} +0 -0
@@ -7,297 +7,324 @@
7
7
  ### Basic
8
8
 
9
9
  ```yaml preview minHeight="600px"
10
- brick: div
11
- properties:
12
- style:
13
- display: flex
14
- height: 600px
15
- gap: 1em
16
- context:
17
- - name: dragging
18
- - name: activeTarget
19
- - name: targetCell
20
- children:
21
- - brick: div
22
- properties:
23
- style:
24
- width: 180px
25
- display: flex
26
- flexDirection: column
27
- gap: 1em
28
- children:
29
- - brick: eo-button
30
- properties:
31
- textContent: Add random nodes
32
- events:
33
- click:
34
- target: eo-draw-canvas
35
- method: addNodes
36
- args:
37
- - |
38
- <%
39
- ((...seeds) => seeds.map((seed) => ({
40
- id: seed,
41
- data: {
42
- name: String(seed),
43
- },
44
- })))(
45
- Math.round(Math.random() * 1e6),
46
- Math.round(Math.random() * 1e6),
47
- Math.round(Math.random() * 1e6),
48
- )
49
- %>
50
- callback:
51
- success:
52
- action: console.log
53
- args:
54
- - Added nodes
55
- - <% EVENT.detail %>
56
- - brick: eo-button
57
- properties:
58
- textContent: "Add edge: Y => Z"
59
- events:
60
- click:
61
- target: eo-draw-canvas
62
- method: addEdge
63
- args:
64
- - source: Y
65
- target: Z
66
- - brick: hr
67
- properties:
68
- style:
69
- width: 100%
70
- - brick: h3
71
- properties:
72
- textContent: Drag nodes below
73
- - brick: :forEach
74
- dataSource: |
75
- <%
76
- ["A", "B", "C"].map((id) => ({
77
- type: "node",
78
- id,
79
- data: {
80
- name: `Node ${id}`,
81
- },
82
- }))
83
- %>
84
- children:
85
- - brick: diagram.experimental-node
86
- properties:
87
- textContent: <% ITEM.data.name %>
88
- usage: library
89
- events:
90
- drag.move:
91
- action: context.replace
92
- args:
93
- - dragging
94
- - |
95
- <% {position: EVENT.detail, ...ITEM} %>
96
- drag.end:
97
- - action: context.replace
98
- args:
99
- - dragging
100
- - null
101
- - target: eo-draw-canvas
102
- method: dropNode
10
+ - brick: div
11
+ properties:
12
+ style:
13
+ display: flex
14
+ height: 600px
15
+ gap: 1em
16
+ context:
17
+ - name: dragging
18
+ - name: activeTarget
19
+ - name: targetCell
20
+ - name: scale
21
+ value: 1
22
+ children:
23
+ - brick: div
24
+ properties:
25
+ style:
26
+ width: 180px
27
+ display: flex
28
+ flexDirection: column
29
+ gap: 1em
30
+ children:
31
+ - brick: eo-button
32
+ properties:
33
+ textContent: Add random nodes
34
+ events:
35
+ click:
36
+ target: eo-draw-canvas
37
+ method: addNodes
38
+ args:
39
+ - |
40
+ <%
41
+ ((...seeds) => seeds.map((seed) => ({
42
+ id: seed,
43
+ data: {
44
+ name: String(seed),
45
+ },
46
+ })))(
47
+ Math.round(Math.random() * 1e6),
48
+ Math.round(Math.random() * 1e6),
49
+ Math.round(Math.random() * 1e6),
50
+ )
51
+ %>
52
+ callback:
53
+ success:
54
+ action: console.log
103
55
  args:
104
- - position: <% EVENT.detail %>
105
- id: <% ITEM.id %>
106
- data: <% ITEM.data %>
107
- callback:
108
- success:
109
- if: <% EVENT.detail %>
110
- then:
111
- # action: message.success
112
- # args:
113
- # - <% JSON.stringify(EVENT.detail) %>
114
- else:
115
- action: message.warn
116
- args:
117
- - Unexpected drop position
118
- - brick: hr
119
- properties:
120
- style:
121
- width: 100%
122
- - brick: h3
123
- properties:
124
- textContent: Drag decorators below
125
- - brick: :forEach
126
- dataSource:
127
- - area
128
- - text
129
- children:
130
- - brick: diagram.experimental-node
131
- properties:
132
- textContent: <% _.upperFirst(ITEM) %>
133
- usage: library
134
- events:
135
- drag.move:
136
- action: context.replace
137
- args:
138
- - dragging
139
- - |
140
- <% {position: EVENT.detail, type: "decorator", decorator: ITEM} %>
141
- drag.end:
142
- - action: context.replace
56
+ - Added nodes
57
+ - <% EVENT.detail %>
58
+ - brick: eo-button
59
+ properties:
60
+ textContent: "Add edge: Y => Z"
61
+ events:
62
+ click:
63
+ target: eo-draw-canvas
64
+ method: addEdge
65
+ args:
66
+ - source: Y
67
+ target: Z
68
+ - brick: hr
69
+ properties:
70
+ style:
71
+ width: 100%
72
+ - brick: h3
73
+ properties:
74
+ textContent: Drag nodes below
75
+ - brick: :forEach
76
+ dataSource: |
77
+ <%
78
+ ["A", "B", "C"].map((id) => ({
79
+ type: "node",
80
+ id,
81
+ data: {
82
+ name: `Node ${id}`,
83
+ },
84
+ }))
85
+ %>
86
+ children:
87
+ - brick: diagram.experimental-node
88
+ properties:
89
+ textContent: <% ITEM.data.name %>
90
+ usage: library
91
+ events:
92
+ drag.move:
93
+ action: context.replace
143
94
  args:
144
95
  - dragging
145
- - null
146
- - target: eo-draw-canvas
147
- method: dropDecorator
96
+ - |
97
+ <% {position: EVENT.detail, ...ITEM} %>
98
+ drag.end:
99
+ - action: context.replace
100
+ args:
101
+ - dragging
102
+ - null
103
+ - target: eo-draw-canvas
104
+ method: dropNode
105
+ args:
106
+ - position: <% EVENT.detail %>
107
+ id: <% ITEM.id %>
108
+ data: <% ITEM.data %>
109
+ callback:
110
+ success:
111
+ if: <% EVENT.detail %>
112
+ then:
113
+ # action: message.success
114
+ # args:
115
+ # - <% JSON.stringify(EVENT.detail) %>
116
+ else:
117
+ action: message.warn
118
+ args:
119
+ - Unexpected drop position
120
+ - brick: hr
121
+ properties:
122
+ style:
123
+ width: 100%
124
+ - brick: h3
125
+ properties:
126
+ textContent: Drag decorators below
127
+ - brick: :forEach
128
+ dataSource:
129
+ - area
130
+ - text
131
+ children:
132
+ - brick: diagram.experimental-node
133
+ properties:
134
+ textContent: <% _.upperFirst(ITEM) %>
135
+ usage: library
136
+ events:
137
+ drag.move:
138
+ action: context.replace
148
139
  args:
149
- - position: <% EVENT.detail %>
150
- decorator: <% ITEM %>
151
- callback:
152
- success:
153
- if: <% EVENT.detail %>
154
- then:
155
- # action: message.success
156
- # args:
157
- # - <% JSON.stringify(EVENT.detail) %>
158
- else:
159
- action: message.warn
160
- args:
161
- - Unexpected drop position
162
- - brick: div
163
- properties:
164
- style:
165
- flex: 1
166
- minWidth: 0
167
- children:
168
- - brick: eo-draw-canvas
169
- properties:
170
- style:
171
- width: 100%
172
- height: 100%
173
- activeTarget: <%= CTX.activeTarget %>
174
- # Initial nodes only
175
- defaultNodeSize: [60, 60]
176
- defaultNodeBricks:
177
- - useBrick:
178
- brick: diagram.experimental-node
179
- properties:
180
- textContent: <% `Node ${DATA.node.id}` %>
181
- status: |
182
- <%=
183
- CTX.activeTarget?.type === "node" && CTX.activeTarget.id === DATA.node.id
184
- ? "highlighted"
185
- // : CTX.activeTarget && CTX.activeTarget?.id !== DATA.node.id
186
- // ? "faded"
187
- : "default"
188
- %>
189
- cells: |
190
- <%
191
- [
192
- {
193
- type: "decorator",
194
- id: "area-1",
195
- decorator: "area",
196
- view: {
197
- x: 10,
198
- y: 20,
199
- width: 400,
200
- height: 300,
140
+ - dragging
141
+ - |
142
+ <% {position: EVENT.detail, type: "decorator", decorator: ITEM} %>
143
+ drag.end:
144
+ - action: context.replace
145
+ args:
146
+ - dragging
147
+ - null
148
+ - target: eo-draw-canvas
149
+ method: dropDecorator
150
+ args:
151
+ - position: <% EVENT.detail %>
152
+ decorator: <% ITEM %>
153
+ callback:
154
+ success:
155
+ if: <% EVENT.detail %>
156
+ then:
157
+ # action: message.success
158
+ # args:
159
+ # - <% JSON.stringify(EVENT.detail) %>
160
+ else:
161
+ action: message.warn
162
+ args:
163
+ - Unexpected drop position
164
+ - brick: div
165
+ properties:
166
+ style:
167
+ flex: 1
168
+ minWidth: 0
169
+ children:
170
+ - brick: eo-draw-canvas
171
+ properties:
172
+ style:
173
+ width: 100%
174
+ height: 100%
175
+ activeTarget: <%= CTX.activeTarget %>
176
+ # Initial nodes only
177
+ defaultNodeSize: [60, 60]
178
+ defaultNodeBricks:
179
+ - useBrick:
180
+ brick: diagram.experimental-node
181
+ properties:
182
+ textContent: <% `Node ${DATA.node.id}` %>
183
+ status: |
184
+ <%=
185
+ CTX.activeTarget?.type === "node" && CTX.activeTarget.id === DATA.node.id
186
+ ? "highlighted"
187
+ // : CTX.activeTarget && CTX.activeTarget?.id !== DATA.node.id
188
+ // ? "faded"
189
+ : "default"
190
+ %>
191
+ cells: |
192
+ <%
193
+ [
194
+ {
195
+ type: "decorator",
196
+ id: "area-1",
197
+ decorator: "area",
198
+ view: {
199
+ x: 10,
200
+ y: 20,
201
+ width: 400,
202
+ height: 300,
203
+ },
201
204
  },
202
- },
203
- {
204
- type: "decorator",
205
- id: "text-1",
206
- decorator: "text",
207
- view: {
208
- x: 100,
209
- y: 120,
210
- width: 100,
211
- height: 20,
212
- text: "Hello!"
205
+ {
206
+ type: "decorator",
207
+ id: "text-1",
208
+ decorator: "text",
209
+ view: {
210
+ x: 100,
211
+ y: 120,
212
+ width: 100,
213
+ height: 20,
214
+ text: "Hello!"
215
+ },
213
216
  },
214
- },
215
- {
216
- type: "edge",
217
- source: "X",
218
- target: "Y",
219
- },
220
- {
221
- type: "edge",
222
- source: "X",
223
- target: "Z",
224
- },
225
- ].concat(
226
- ["X", "Y", "Z"].map((id) => ({
227
- type: "node",
228
- id,
229
- data: {
230
- name: `Node ${id}`,
217
+ {
218
+ type: "edge",
219
+ source: "X",
220
+ target: "Y",
231
221
  },
232
- view: {
233
- x: Math.round(
234
- id === "X"
235
- ? 200 + Math.random() * 200
236
- : id === "Y"
237
- ? Math.random() * 300
238
- : 300 + Math.random() * 300
239
- ),
240
- y: (id === "X" ? 0 : 300) + Math.round((Math.random() * 200)),
241
- width: 60,
242
- height: 60,
243
- }
244
- }))
245
- )
246
- %>
247
- events:
248
- activeTarget.change:
249
- action: context.replace
250
- args:
251
- - activeTarget
252
- - <% EVENT.detail %>
253
- cell.move:
254
- action: message.info
255
- args:
256
- - <% `You just moved ${EVENT.detail.type} ${EVENT.detail.id} to (${Math.round(EVENT.detail.x)}, ${Math.round(EVENT.detail.y)})` %>
257
- cell.resize:
258
- action: message.info
259
- args:
260
- - <% `You just resized ${EVENT.detail.type} ${EVENT.detail.id} to (${Math.round(EVENT.detail.width)}, ${Math.round(EVENT.detail.height)})` %>
261
- cell.delete:
262
- action: message.warn
263
- args:
264
- - |
265
- <% `You wanna delete ${EVENT.detail.type} ${EVENT.detail.type === "edge" ? `(${EVENT.detail.source} => ${EVENT.detail.target})` : EVENT.detail.id}?` %>
266
- cell.contextmenu:
267
- - target: eo-context-menu
268
- method: open
222
+ {
223
+ type: "edge",
224
+ source: "X",
225
+ target: "Z",
226
+ },
227
+ ].concat(
228
+ ["X", "Y", "Z"].map((id) => ({
229
+ type: "node",
230
+ id,
231
+ data: {
232
+ name: `Node ${id}`,
233
+ },
234
+ view: {
235
+ x: Math.round(
236
+ id === "X"
237
+ ? 200 + Math.random() * 200
238
+ : id === "Y"
239
+ ? Math.random() * 300
240
+ : 300 + Math.random() * 300
241
+ ),
242
+ y: (id === "X" ? 0 : 300) + Math.round((Math.random() * 200)),
243
+ width: 60,
244
+ height: 60,
245
+ }
246
+ }))
247
+ )
248
+ %>
249
+ events:
250
+ activeTarget.change:
251
+ action: context.replace
269
252
  args:
270
- - position:
271
- - <% EVENT.detail.clientX %>
272
- - <% EVENT.detail.clientY %>
273
- - action: context.replace
253
+ - activeTarget
254
+ - <% EVENT.detail %>
255
+ cell.move:
256
+ action: message.info
274
257
  args:
275
- - targetCell
276
- - <% EVENT.detail.cell %>
277
- - brick: diagram.experimental-node
278
- properties:
279
- usage: dragging
280
- textContent: |
281
- <%= CTX.dragging?.type === "decorator" ? (CTX.dragging.decorator === "text" ? "未命名" : null) : CTX.dragging?.data.name %>
282
- decorator: |
283
- <%= CTX.dragging?.type === "decorator" ? CTX.dragging.decorator : null %>
284
- style: |
285
- <%=
258
+ - <% `You just moved ${EVENT.detail.type} ${EVENT.detail.id} to (${Math.round(EVENT.detail.x)}, ${Math.round(EVENT.detail.y)})` %>
259
+ cell.resize:
260
+ action: message.info
261
+ args:
262
+ - <% `You just resized ${EVENT.detail.type} ${EVENT.detail.id} to (${Math.round(EVENT.detail.width)}, ${Math.round(EVENT.detail.height)})` %>
263
+ cell.delete:
264
+ action: message.warn
265
+ args:
266
+ - |
267
+ <% `You wanna delete ${EVENT.detail.type} ${EVENT.detail.type === "edge" ? `(${EVENT.detail.source} => ${EVENT.detail.target})` : EVENT.detail.id}?` %>
268
+ cell.contextmenu:
269
+ - target: eo-context-menu
270
+ method: open
271
+ args:
272
+ - position:
273
+ - <% EVENT.detail.clientX %>
274
+ - <% EVENT.detail.clientY %>
275
+ - action: context.replace
276
+ args:
277
+ - targetCell
278
+ - <% EVENT.detail.cell %>
279
+ scale.change:
280
+ action: context.replace
281
+ args:
282
+ - scale
283
+ - <% EVENT.detail %>
284
+ - brick: diagram.experimental-node
285
+ properties:
286
+ usage: dragging
287
+ textContent: |
288
+ <%= CTX.dragging?.type === "decorator" ? (CTX.dragging.decorator === "text" ? "未命名" : null) : CTX.dragging?.data.name %>
289
+ decorator: |
290
+ <%= CTX.dragging?.type === "decorator" ? CTX.dragging.decorator : null %>
291
+ style: |
292
+ <%=
293
+ {
294
+ left: `${CTX.dragging?.position[0]}px`,
295
+ top: `${CTX.dragging?.position[1]}px`,
296
+ transform: `scale(${CTX.scale})`,
297
+ transformOrigin: "0 0",
298
+ }
299
+ %>
300
+ hidden: <%= !CTX.dragging %>
301
+ - brick: eo-context-menu
302
+ properties:
303
+ actions: |
304
+ <%=
305
+ CTX.targetCell?.type === "node" ? [
306
+ {
307
+ text: "添加边",
308
+ event: "add-edge",
309
+ }
310
+ ] : [
286
311
  {
287
- left: `${CTX.dragging?.position[0]}px`,
288
- top: `${CTX.dragging?.position[1]}px`,
312
+ text: `Test ${CTX.targetCell?.type}`,
313
+ event: `test-${CTX.targetCell?.type}`,
289
314
  }
290
- %>
291
- hidden: <%= !CTX.dragging %>
292
- - brick: eo-context-menu
293
- properties:
294
- actions: |
295
- <%=
296
- [
297
- {
298
- text: `Test ${CTX.targetCell?.type}`,
299
- event: "test-${CTX.targetCell?.type}",
300
- }
301
- ]
302
- %>
315
+ ]
316
+ %>
317
+ events:
318
+ add-edge:
319
+ target: eo-draw-canvas
320
+ method: manuallyConnectNodes
321
+ args:
322
+ - <% CTX.targetCell.id %>
323
+ callback:
324
+ success:
325
+ target: eo-draw-canvas
326
+ method: addEdge
327
+ args:
328
+ - source: <% EVENT.detail.source.id %>
329
+ target: <% EVENT.detail.target.id %>
303
330
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next-bricks/diagram",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "homepage": "https://github.com/easyops-cn/next-bricks/tree/master/bricks/diagram",
5
5
  "repository": {
6
6
  "type": "git",
@@ -38,7 +38,8 @@
38
38
  "@next-core/test-next": "^1.0.15"
39
39
  },
40
40
  "peerDependencies": {
41
+ "@next-bricks/basic": "*",
41
42
  "@next-bricks/icons": "*"
42
43
  },
43
- "gitHead": "c53fb5e5b7ac3f7cc42ec3af7411eb1123763ac7"
44
+ "gitHead": "ef33c9f839151daaefef8ae52efd37b9a5c8e662"
44
45
  }