@fugood/bricks-project 2.21.0-beta.14.test1 → 2.21.0-beta.14.test10
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.
- package/api/index.ts +1 -1
- package/api/instance.ts +180 -0
- package/compile/action-name-map.ts +502 -0
- package/compile/index.ts +207 -71
- package/compile/util.ts +2 -2
- package/index.ts +4 -9
- package/package.json +3 -1
- package/tools/deploy.ts +24 -0
- package/tools/postinstall.ts +12 -0
- package/tools/preview-main.mjs +51 -0
- package/tools/preview.ts +37 -0
- package/tools/pull.ts +51 -0
- package/types/bricks.ts +77 -76
- package/types/canvas.ts +4 -4
- package/types/common.ts +12 -9
- package/types/data-calc.ts +33 -1
- package/types/data.ts +43 -3
- package/types/generators.ts +151 -145
- package/types/subspace.ts +21 -6
- package/types/switch.ts +10 -7
- package/types/system.ts +58 -57
- package/utils/calc.ts +118 -0
- package/utils/data.ts +397 -0
- package/{uuid.ts → utils/id.ts} +26 -10
- package/api/application.ts +0 -65
package/types/subspace.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Brick, Generator, LocalSyncStrategy, EventAction } from './common'
|
|
2
|
-
import { Animation } from './animation'
|
|
3
|
-
import { Canvas } from './canvas'
|
|
4
|
-
import { Data } from './data'
|
|
5
|
-
import { DataCalculation } from './data-calc'
|
|
1
|
+
import type { Brick, Generator, LocalSyncStrategy, EventAction, SubspaceID } from './common'
|
|
2
|
+
import type { Animation } from './animation'
|
|
3
|
+
import type { Canvas } from './canvas'
|
|
4
|
+
import type { Data } from './data'
|
|
5
|
+
import type { DataCalculation } from './data-calc'
|
|
6
6
|
|
|
7
7
|
export type Subspace = {
|
|
8
8
|
__typename: 'Subspace'
|
|
@@ -10,6 +10,21 @@ export type Subspace = {
|
|
|
10
10
|
title: string
|
|
11
11
|
description?: string
|
|
12
12
|
localSyncChangeCanvas?: LocalSyncStrategy
|
|
13
|
+
module?: {
|
|
14
|
+
id: string
|
|
15
|
+
version: string
|
|
16
|
+
selectedRequirements?: Array<{
|
|
17
|
+
subspace: SubspaceID
|
|
18
|
+
id: string
|
|
19
|
+
version: string
|
|
20
|
+
}>
|
|
21
|
+
// Module only
|
|
22
|
+
requirements?: Array<{
|
|
23
|
+
subspace: SubspaceID
|
|
24
|
+
id: string
|
|
25
|
+
version: string
|
|
26
|
+
}>
|
|
27
|
+
}
|
|
13
28
|
layout: {
|
|
14
29
|
width: number
|
|
15
30
|
height: number
|
|
@@ -21,6 +36,7 @@ export type Subspace = {
|
|
|
21
36
|
bricks: Array<Brick>
|
|
22
37
|
generators: Array<Generator>
|
|
23
38
|
data: Array<Data>
|
|
39
|
+
dataRouting: Array<Data>
|
|
24
40
|
dataCalculation: Array<DataCalculation>
|
|
25
41
|
actions?: {
|
|
26
42
|
[key: string]: {
|
|
@@ -30,4 +46,3 @@ export type Subspace = {
|
|
|
30
46
|
}
|
|
31
47
|
events?: { [key: string]: Array<EventAction> }
|
|
32
48
|
}
|
|
33
|
-
|
package/types/switch.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Canvas } from './canvas'
|
|
2
|
-
import { Data } from './data'
|
|
1
|
+
import type { Canvas } from './canvas'
|
|
2
|
+
import type { Data } from './data'
|
|
3
3
|
export type SwitchCondInnerStateCurrentCanvas = {
|
|
4
4
|
__typename: 'SwitchCondInnerStateCurrentCanvas'
|
|
5
5
|
value: () => Canvas
|
|
@@ -36,10 +36,13 @@ export interface SwitchDef {
|
|
|
36
36
|
animation?: {}
|
|
37
37
|
conds?: Array<{
|
|
38
38
|
method: '==' | '!=' | '>' | '<' | '>=' | '<='
|
|
39
|
-
cond:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
cond:
|
|
40
|
+
| SwitchCondInnerStateCurrentCanvas
|
|
41
|
+
| SwitchCondData
|
|
42
|
+
| {
|
|
43
|
+
__typename: 'SwitchCondInnerStateOutlet'
|
|
44
|
+
outlet: string
|
|
45
|
+
value: any
|
|
46
|
+
}
|
|
44
47
|
}>
|
|
45
48
|
}
|
package/types/system.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Action, ActionWithDataParams, ActionWithParams, Brick, Generator } from './common'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { Action, ActionWithDataParams, ActionWithParams, Brick, Generator } from './common'
|
|
2
|
+
import type { Animation } from './animation'
|
|
3
|
+
import type { Canvas } from './canvas'
|
|
4
|
+
import type { Data, DataLink } from './data'
|
|
4
5
|
|
|
5
6
|
/* Change Data value */
|
|
6
7
|
export type SystemActionPropertyBank = ActionWithDataParams & {
|
|
@@ -14,27 +15,27 @@ export type SystemActionPropertyBankExpression = ActionWithParams & {
|
|
|
14
15
|
| {
|
|
15
16
|
input: 'expression'
|
|
16
17
|
value?: string | DataLink
|
|
17
|
-
mapping?:
|
|
18
|
+
mapping?: string
|
|
18
19
|
}
|
|
19
20
|
| {
|
|
20
21
|
input: 'variables'
|
|
21
22
|
value?: {} | DataLink
|
|
22
|
-
mapping?:
|
|
23
|
+
mapping?: string
|
|
23
24
|
}
|
|
24
25
|
| {
|
|
25
26
|
input: 'result'
|
|
26
27
|
value?: string | DataLink | (() => Data)
|
|
27
|
-
mapping?:
|
|
28
|
+
mapping?: string
|
|
28
29
|
}
|
|
29
30
|
| {
|
|
30
31
|
input: 'resultAssignPath'
|
|
31
32
|
value?: string | DataLink
|
|
32
|
-
mapping?:
|
|
33
|
+
mapping?: string
|
|
33
34
|
}
|
|
34
35
|
| {
|
|
35
36
|
input: 'errorResult'
|
|
36
37
|
value?: string | DataLink | (() => Data)
|
|
37
|
-
mapping?:
|
|
38
|
+
mapping?: string
|
|
38
39
|
}
|
|
39
40
|
>
|
|
40
41
|
}
|
|
@@ -51,27 +52,27 @@ export type SystemActionDynamicBrick = ActionWithParams & {
|
|
|
51
52
|
| {
|
|
52
53
|
input: 'addList'
|
|
53
54
|
value?: string | DataLink
|
|
54
|
-
mapping?:
|
|
55
|
+
mapping?: string
|
|
55
56
|
}
|
|
56
57
|
| {
|
|
57
58
|
input: 'preferAfterItemId'
|
|
58
59
|
value?: string | DataLink
|
|
59
|
-
mapping?:
|
|
60
|
+
mapping?: string
|
|
60
61
|
}
|
|
61
62
|
| {
|
|
62
63
|
input: 'reset'
|
|
63
64
|
value?: boolean | DataLink
|
|
64
|
-
mapping?:
|
|
65
|
+
mapping?: string
|
|
65
66
|
}
|
|
66
67
|
| {
|
|
67
68
|
input: 'removeItemId'
|
|
68
69
|
value?: string | DataLink
|
|
69
|
-
mapping?:
|
|
70
|
+
mapping?: string
|
|
70
71
|
}
|
|
71
72
|
| {
|
|
72
73
|
input: 'removeItems'
|
|
73
74
|
value?: string | DataLink
|
|
74
|
-
mapping?:
|
|
75
|
+
mapping?: string
|
|
75
76
|
}
|
|
76
77
|
>
|
|
77
78
|
}
|
|
@@ -88,22 +89,22 @@ export type SystemActionDynamicAnimation = ActionWithParams & {
|
|
|
88
89
|
| {
|
|
89
90
|
input: 'brickId'
|
|
90
91
|
value?: string | DataLink | (() => Brick)
|
|
91
|
-
mapping?:
|
|
92
|
+
mapping?: string
|
|
92
93
|
}
|
|
93
94
|
| {
|
|
94
95
|
input: 'animationId'
|
|
95
96
|
value?: string | DataLink | (() => Animation)
|
|
96
|
-
mapping?:
|
|
97
|
+
mapping?: string
|
|
97
98
|
}
|
|
98
99
|
| {
|
|
99
100
|
input: 'runType'
|
|
100
101
|
value?: 'once' | 'loop' | DataLink
|
|
101
|
-
mapping?:
|
|
102
|
+
mapping?: string
|
|
102
103
|
}
|
|
103
104
|
| {
|
|
104
105
|
input: 'resetInitialValue'
|
|
105
106
|
value?: boolean | DataLink
|
|
106
|
-
mapping?:
|
|
107
|
+
mapping?: string
|
|
107
108
|
}
|
|
108
109
|
>
|
|
109
110
|
}
|
|
@@ -114,7 +115,7 @@ export type SystemActionDynamicAnimationReset = ActionWithParams & {
|
|
|
114
115
|
params?: Array<{
|
|
115
116
|
input: 'dynamicAnimationBrickId'
|
|
116
117
|
value?: string | DataLink | (() => Brick)
|
|
117
|
-
mapping?:
|
|
118
|
+
mapping?: string
|
|
118
119
|
}>
|
|
119
120
|
}
|
|
120
121
|
|
|
@@ -124,7 +125,7 @@ export type SystemActionDynamicAnimationStop = ActionWithParams & {
|
|
|
124
125
|
params?: Array<{
|
|
125
126
|
input: 'dynamicAnimationBrickId'
|
|
126
127
|
value?: string | DataLink | (() => Brick)
|
|
127
|
-
mapping?:
|
|
128
|
+
mapping?: string
|
|
128
129
|
}>
|
|
129
130
|
}
|
|
130
131
|
|
|
@@ -135,12 +136,12 @@ export type SystemActionChangeCanvas = ActionWithParams & {
|
|
|
135
136
|
| {
|
|
136
137
|
input: 'canvasId'
|
|
137
138
|
value?: string | DataLink | (() => Canvas)
|
|
138
|
-
mapping?:
|
|
139
|
+
mapping?: string
|
|
139
140
|
}
|
|
140
141
|
| {
|
|
141
142
|
input: 'canvasTitleLike'
|
|
142
143
|
value?: string | DataLink
|
|
143
|
-
mapping?:
|
|
144
|
+
mapping?: string
|
|
144
145
|
}
|
|
145
146
|
>
|
|
146
147
|
}
|
|
@@ -157,17 +158,17 @@ export type SystemActionMessage = ActionWithParams & {
|
|
|
157
158
|
| 'SYSTEM_MESSAGE_TYPE_WARNING'
|
|
158
159
|
| 'SYSTEM_MESSAGE_TYPE_ERROR'
|
|
159
160
|
| DataLink
|
|
160
|
-
mapping?:
|
|
161
|
+
mapping?: string
|
|
161
162
|
}
|
|
162
163
|
| {
|
|
163
164
|
input: 'title'
|
|
164
165
|
value?: string | DataLink
|
|
165
|
-
mapping?:
|
|
166
|
+
mapping?: string
|
|
166
167
|
}
|
|
167
168
|
| {
|
|
168
169
|
input: 'message'
|
|
169
170
|
value?: string | DataLink
|
|
170
|
-
mapping?:
|
|
171
|
+
mapping?: string
|
|
171
172
|
}
|
|
172
173
|
>
|
|
173
174
|
}
|
|
@@ -179,37 +180,37 @@ export type SystemActionAlert = ActionWithParams & {
|
|
|
179
180
|
| {
|
|
180
181
|
input: 'id'
|
|
181
182
|
value?: string | DataLink
|
|
182
|
-
mapping?:
|
|
183
|
+
mapping?: string
|
|
183
184
|
}
|
|
184
185
|
| {
|
|
185
186
|
input: 'type'
|
|
186
187
|
value?: 'info' | 'success' | 'warning' | 'error' | DataLink
|
|
187
|
-
mapping?:
|
|
188
|
+
mapping?: string
|
|
188
189
|
}
|
|
189
190
|
| {
|
|
190
191
|
input: 'title'
|
|
191
192
|
value?: string | DataLink
|
|
192
|
-
mapping?:
|
|
193
|
+
mapping?: string
|
|
193
194
|
}
|
|
194
195
|
| {
|
|
195
196
|
input: 'message'
|
|
196
197
|
value?: string | DataLink
|
|
197
|
-
mapping?:
|
|
198
|
+
mapping?: string
|
|
198
199
|
}
|
|
199
200
|
| {
|
|
200
201
|
input: 'selections'
|
|
201
202
|
value?: {} | DataLink
|
|
202
|
-
mapping?:
|
|
203
|
+
mapping?: string
|
|
203
204
|
}
|
|
204
205
|
| {
|
|
205
206
|
input: 'selectionResult'
|
|
206
207
|
value?: string | DataLink | (() => Data)
|
|
207
|
-
mapping?:
|
|
208
|
+
mapping?: string
|
|
208
209
|
}
|
|
209
210
|
| {
|
|
210
211
|
input: 'timeout'
|
|
211
212
|
value?: number | DataLink
|
|
212
|
-
mapping?:
|
|
213
|
+
mapping?: string
|
|
213
214
|
}
|
|
214
215
|
>
|
|
215
216
|
}
|
|
@@ -221,12 +222,12 @@ export type SystemActionPopupReset = ActionWithParams & {
|
|
|
221
222
|
| {
|
|
222
223
|
input: 'popupClearType'
|
|
223
224
|
value?: 'all' | 'alert' | 'generator' | DataLink
|
|
224
|
-
mapping?:
|
|
225
|
+
mapping?: string
|
|
225
226
|
}
|
|
226
227
|
| {
|
|
227
228
|
input: 'popupId'
|
|
228
229
|
value?: string | DataLink
|
|
229
|
-
mapping?:
|
|
230
|
+
mapping?: string
|
|
230
231
|
}
|
|
231
232
|
>
|
|
232
233
|
}
|
|
@@ -238,32 +239,32 @@ export type SystemActionTakeScreenshot = ActionWithParams & {
|
|
|
238
239
|
| {
|
|
239
240
|
input: 'currentSubspace'
|
|
240
241
|
value?: boolean | DataLink
|
|
241
|
-
mapping?:
|
|
242
|
+
mapping?: string
|
|
242
243
|
}
|
|
243
244
|
| {
|
|
244
245
|
input: 'format'
|
|
245
246
|
value?: 'jpg' | 'png' | DataLink
|
|
246
|
-
mapping?:
|
|
247
|
+
mapping?: string
|
|
247
248
|
}
|
|
248
249
|
| {
|
|
249
250
|
input: 'quality'
|
|
250
251
|
value?: number | DataLink
|
|
251
|
-
mapping?:
|
|
252
|
+
mapping?: string
|
|
252
253
|
}
|
|
253
254
|
| {
|
|
254
255
|
input: 'width'
|
|
255
256
|
value?: number | DataLink
|
|
256
|
-
mapping?:
|
|
257
|
+
mapping?: string
|
|
257
258
|
}
|
|
258
259
|
| {
|
|
259
260
|
input: 'height'
|
|
260
261
|
value?: number | DataLink
|
|
261
|
-
mapping?:
|
|
262
|
+
mapping?: string
|
|
262
263
|
}
|
|
263
264
|
| {
|
|
264
265
|
input: 'saveProperty'
|
|
265
266
|
value?: string | DataLink | (() => Data)
|
|
266
|
-
mapping?:
|
|
267
|
+
mapping?: string
|
|
267
268
|
}
|
|
268
269
|
>
|
|
269
270
|
}
|
|
@@ -275,32 +276,32 @@ export type SystemActionUseShareApplication = ActionWithParams & {
|
|
|
275
276
|
| {
|
|
276
277
|
input: 'applicationId'
|
|
277
278
|
value?: string | DataLink
|
|
278
|
-
mapping?:
|
|
279
|
+
mapping?: string
|
|
279
280
|
}
|
|
280
281
|
| {
|
|
281
282
|
input: 'releaseVersion'
|
|
282
283
|
value?: string | DataLink
|
|
283
|
-
mapping?:
|
|
284
|
+
mapping?: string
|
|
284
285
|
}
|
|
285
286
|
| {
|
|
286
287
|
input: 'useType'
|
|
287
288
|
value?: 'run' | 'use-after-bind' | 'cancel-use' | DataLink
|
|
288
|
-
mapping?:
|
|
289
|
+
mapping?: string
|
|
289
290
|
}
|
|
290
291
|
| {
|
|
291
292
|
input: 'viewportPresetNameLike'
|
|
292
293
|
value?: string | DataLink
|
|
293
|
-
mapping?:
|
|
294
|
+
mapping?: string
|
|
294
295
|
}
|
|
295
296
|
| {
|
|
296
297
|
input: 'viewportPresetDeviceTarget'
|
|
297
298
|
value?: string | DataLink
|
|
298
|
-
mapping?:
|
|
299
|
+
mapping?: string
|
|
299
300
|
}
|
|
300
301
|
| {
|
|
301
302
|
input: 'enableLocalSync'
|
|
302
303
|
value?: boolean | DataLink
|
|
303
|
-
mapping?:
|
|
304
|
+
mapping?: string
|
|
304
305
|
}
|
|
305
306
|
>
|
|
306
307
|
}
|
|
@@ -322,17 +323,17 @@ export type SystemActionOpenUrl = ActionWithParams & {
|
|
|
322
323
|
| {
|
|
323
324
|
input: 'url'
|
|
324
325
|
value?: string | DataLink
|
|
325
|
-
mapping?:
|
|
326
|
+
mapping?: string
|
|
326
327
|
}
|
|
327
328
|
| {
|
|
328
329
|
input: 'behavior'
|
|
329
330
|
value?: 'in-app' | 'new-window' | DataLink
|
|
330
|
-
mapping?:
|
|
331
|
+
mapping?: string
|
|
331
332
|
}
|
|
332
333
|
| {
|
|
333
334
|
input: 'inAppTintColor'
|
|
334
335
|
value?: string | DataLink
|
|
335
|
-
mapping?:
|
|
336
|
+
mapping?: string
|
|
336
337
|
}
|
|
337
338
|
>
|
|
338
339
|
}
|
|
@@ -344,37 +345,37 @@ export type SystemActionOpenFile = ActionWithParams & {
|
|
|
344
345
|
| {
|
|
345
346
|
input: 'pickType'
|
|
346
347
|
value?: 'file' | 'multiple' | 'directory' | DataLink
|
|
347
|
-
mapping?:
|
|
348
|
+
mapping?: string
|
|
348
349
|
}
|
|
349
350
|
| {
|
|
350
351
|
input: 'fileType'
|
|
351
352
|
value?: any
|
|
352
|
-
mapping?:
|
|
353
|
+
mapping?: string
|
|
353
354
|
}
|
|
354
355
|
| {
|
|
355
356
|
input: 'copyTo'
|
|
356
357
|
value?: 'cache' | 'document' | DataLink
|
|
357
|
-
mapping?:
|
|
358
|
+
mapping?: string
|
|
358
359
|
}
|
|
359
360
|
| {
|
|
360
361
|
input: 'mode'
|
|
361
362
|
value?: 'import' | 'open' | DataLink
|
|
362
|
-
mapping?:
|
|
363
|
+
mapping?: string
|
|
363
364
|
}
|
|
364
365
|
| {
|
|
365
366
|
input: 'saveProperty'
|
|
366
367
|
value?: string | DataLink | (() => Data)
|
|
367
|
-
mapping?:
|
|
368
|
+
mapping?: string
|
|
368
369
|
}
|
|
369
370
|
| {
|
|
370
371
|
input: 'saveDetailProperty'
|
|
371
372
|
value?: string | DataLink | (() => Data)
|
|
372
|
-
mapping?:
|
|
373
|
+
mapping?: string
|
|
373
374
|
}
|
|
374
375
|
| {
|
|
375
376
|
input: 'errorSaveProperty'
|
|
376
377
|
value?: string | DataLink | (() => Data)
|
|
377
|
-
mapping?:
|
|
378
|
+
mapping?: string
|
|
378
379
|
}
|
|
379
380
|
>
|
|
380
381
|
}
|
|
@@ -386,12 +387,12 @@ export type SystemActionThrowException = ActionWithParams & {
|
|
|
386
387
|
| {
|
|
387
388
|
input: 'behavior'
|
|
388
389
|
value?: 'application' | 'application-render' | 'native' | DataLink
|
|
389
|
-
mapping?:
|
|
390
|
+
mapping?: string
|
|
390
391
|
}
|
|
391
392
|
| {
|
|
392
393
|
input: 'exceptionMessage'
|
|
393
394
|
value?: string | DataLink
|
|
394
|
-
mapping?:
|
|
395
|
+
mapping?: string
|
|
395
396
|
}
|
|
396
397
|
>
|
|
397
398
|
}
|
package/utils/calc.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { DataCalculationMap, DataCalculationData, DataCommand } from '../types/data-calc'
|
|
2
|
+
|
|
3
|
+
const GRID = {
|
|
4
|
+
WIDTH: 300, // Distance between columns
|
|
5
|
+
HEIGHT: 150, // Distance between rows
|
|
6
|
+
PADDING: 15, // Edge padding
|
|
7
|
+
COLUMNS: 4, // Max columns in grid
|
|
8
|
+
ROWS: 3, // Max rows in grid
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// TODO: Improve the algorithm to minimize crossing lines
|
|
12
|
+
|
|
13
|
+
// If we are too lazy to describe nodes in the editing interface,
|
|
14
|
+
// we can let it generate it automatically
|
|
15
|
+
export const generateDataCalculationMapEditorInfo = (
|
|
16
|
+
nodes: Array<DataCalculationData | DataCommand>,
|
|
17
|
+
) => {
|
|
18
|
+
const editorInfo: DataCalculationMap['editorInfo'] = []
|
|
19
|
+
|
|
20
|
+
// Track node relationships
|
|
21
|
+
const inputCounts = new Map<DataCalculationData | DataCommand, number>()
|
|
22
|
+
const outputCounts = new Map<DataCalculationData | DataCommand, number>()
|
|
23
|
+
const connectedTo = new Map<
|
|
24
|
+
DataCalculationData | DataCommand,
|
|
25
|
+
Set<DataCalculationData | DataCommand>
|
|
26
|
+
>()
|
|
27
|
+
|
|
28
|
+
// Analyze node connections
|
|
29
|
+
nodes.forEach((node) => {
|
|
30
|
+
// Count and track inputs
|
|
31
|
+
if ('inputs' in node) {
|
|
32
|
+
const inputs = node.inputs
|
|
33
|
+
.filter((input) => input !== null)
|
|
34
|
+
.map((input) => (Array.isArray(input) ? input.length : 1))
|
|
35
|
+
.reduce((sum, count) => sum + count, 0)
|
|
36
|
+
inputCounts.set(node, inputs)
|
|
37
|
+
|
|
38
|
+
// Track connections
|
|
39
|
+
node.inputs.forEach((input) => {
|
|
40
|
+
if (Array.isArray(input)) {
|
|
41
|
+
input.forEach((conn) => {
|
|
42
|
+
if (!connectedTo.has(node)) {
|
|
43
|
+
connectedTo.set(node, new Set())
|
|
44
|
+
}
|
|
45
|
+
const sourceNode = nodes.find((n) => 'id' in n && n.id === conn.id)
|
|
46
|
+
if (sourceNode) {
|
|
47
|
+
connectedTo.get(node)!.add(sourceNode)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
} else {
|
|
53
|
+
inputCounts.set(node, 0)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Count outputs
|
|
57
|
+
if ('outputs' in node) {
|
|
58
|
+
const outputs = node.outputs
|
|
59
|
+
.filter((output) => output !== null)
|
|
60
|
+
.map((output) => (Array.isArray(output) ? output.length : 1))
|
|
61
|
+
.reduce((sum, count) => sum + count, 0)
|
|
62
|
+
outputCounts.set(node, outputs)
|
|
63
|
+
} else {
|
|
64
|
+
outputCounts.set(node, 0)
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Calculate layers
|
|
69
|
+
const layers: Array<Array<DataCalculationData | DataCommand>> = [[], [], [], []]
|
|
70
|
+
|
|
71
|
+
nodes.forEach((node) => {
|
|
72
|
+
const inputs = inputCounts.get(node) || 0
|
|
73
|
+
const outputs = outputCounts.get(node) || 0
|
|
74
|
+
const connections = connectedTo.get(node)?.size || 0
|
|
75
|
+
|
|
76
|
+
if (inputs === 0) {
|
|
77
|
+
// Input nodes (leftmost)
|
|
78
|
+
layers[0].push(node)
|
|
79
|
+
} else if (outputs === 0) {
|
|
80
|
+
// Output nodes (rightmost)
|
|
81
|
+
layers[3].push(node)
|
|
82
|
+
} else if (connections > 1) {
|
|
83
|
+
// Nodes with multiple connections (middle-right)
|
|
84
|
+
layers[2].push(node)
|
|
85
|
+
} else {
|
|
86
|
+
// Processing nodes (middle-left)
|
|
87
|
+
layers[1].push(node)
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
// Position nodes in each layer
|
|
92
|
+
layers.forEach((layerNodes, layerIndex) => {
|
|
93
|
+
// Sort nodes by their connections to try to minimize crossing lines
|
|
94
|
+
layerNodes.sort((a, b) => {
|
|
95
|
+
const aConns = connectedTo.get(a)?.size || 0
|
|
96
|
+
const bConns = connectedTo.get(b)?.size || 0
|
|
97
|
+
return bConns - aConns
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
// Position nodes in the layer
|
|
101
|
+
layerNodes.forEach((node, nodeIndex) => {
|
|
102
|
+
// Distribute nodes evenly within their layer
|
|
103
|
+
const row = nodeIndex % GRID.ROWS
|
|
104
|
+
const offset = Math.floor(nodeIndex / GRID.ROWS) * (GRID.HEIGHT / 2)
|
|
105
|
+
|
|
106
|
+
editorInfo.push({
|
|
107
|
+
node,
|
|
108
|
+
position: {
|
|
109
|
+
x: GRID.PADDING + layerIndex * GRID.WIDTH,
|
|
110
|
+
y: GRID.PADDING + row * GRID.HEIGHT + offset,
|
|
111
|
+
},
|
|
112
|
+
points: [],
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
return editorInfo
|
|
118
|
+
}
|