@digipair/skill-web-editor 0.91.0-0 → 0.92.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.
- package/blockly-to-json.cjs.js +338 -0
- package/blockly-to-json.esm.js +336 -0
- package/index.cjs.d.ts +1 -0
- package/index.cjs.js +12 -0
- package/index.cjs2.js +72611 -0
- package/index.esm.js +1 -0
- package/index.esm2.js +72608 -0
- package/libs/skill-web-editor/src/lib/blocks/json.d.ts +145 -0
- package/libs/skill-web-editor/src/lib/editor.element.d.ts +24 -0
- package/libs/skill-web-editor/src/lib/generator/blockly-to-json.d.ts +1 -0
- package/libs/skill-web-editor/src/lib/generator/json-to-blockly.d.ts +1 -0
- package/libs/skill-web-editor/src/lib/generator/pins-to-blockly.d.ts +139 -0
- package/libs/skill-web-editor/src/lib/schemas/web.fr.schema.d.ts +4028 -0
- package/libs/skill-web-editor/src/lib/schemas/web.schema.d.ts +4028 -0
- package/libs/skill-web-editor/src/lib/skill-web-editor.d.ts +1 -0
- package/package.json +5 -21
- package/pins-to-blockly.cjs.js +628 -0
- package/pins-to-blockly.esm.js +624 -0
- package/.swcrc +0 -28
- package/README.md +0 -7
- package/eslint.config.mjs +0 -22
- package/rollup.config.cjs +0 -28
- package/src/lib/blocks/json.ts +0 -145
- package/src/lib/editor.element.ts +0 -279
- package/src/lib/generator/blockly-to-json.ts +0 -360
- package/src/lib/generator/json-to-blockly.ts +0 -757
- package/src/lib/generator/pins-to-blockly.ts +0 -927
- package/src/lib/schemas/web.fr.schema.ts +0 -34473
- package/src/lib/schemas/web.schema.ts +0 -34473
- package/src/lib/skill-web-editor.spec.ts +0 -7
- package/src/lib/skill-web-editor.ts +0 -1
- package/tsconfig.json +0 -13
- package/tsconfig.lib.json +0 -19
- /package/{src/index.d.ts → index.d.ts} +0 -0
- /package/{src/index.ts → libs/skill-web-editor/src/index.d.ts} +0 -0
- /package/{src/schema.fr.json → schema.fr.json} +0 -0
- /package/{src/schema.json → schema.json} +0 -0
@@ -1,927 +0,0 @@
|
|
1
|
-
declare const Blockly: any;
|
2
|
-
|
3
|
-
function getPinsBlockDefinition(
|
4
|
-
library: { info: { [x: string]: string; title: string } },
|
5
|
-
methodData: any,
|
6
|
-
pinsId: string,
|
7
|
-
) {
|
8
|
-
const blockDefinition: any = {
|
9
|
-
type: pinsId,
|
10
|
-
message0: library.info['x-icon'] + ' ' + methodData.summary,
|
11
|
-
args0: [], //Empty field, only used for the Pins display name
|
12
|
-
message1: '',
|
13
|
-
args1: [], //Parameters inputs field
|
14
|
-
message2: '',
|
15
|
-
args2: [], //Events inputs field
|
16
|
-
message3: '',
|
17
|
-
args3: [], //Pins input field
|
18
|
-
colour: '#b3aeee',
|
19
|
-
tooltip: 'library : ' + library.info.title,
|
20
|
-
inputsInline: false,
|
21
|
-
previousStatement: null,
|
22
|
-
nextStatement: null,
|
23
|
-
};
|
24
|
-
|
25
|
-
const parameters = methodData.parameters;
|
26
|
-
const metadata = methodData.metadata || [];
|
27
|
-
const events = methodData['x-events'] || [];
|
28
|
-
|
29
|
-
const requiredParamInputs = parameters.filter(
|
30
|
-
(param: { required: boolean }) => param.required === true,
|
31
|
-
);
|
32
|
-
const requiredEventInputs: any[] = [];
|
33
|
-
const requiredFields = requiredParamInputs.map((param: { name: any }) => param.name);
|
34
|
-
|
35
|
-
if (methodData['x-events']) {
|
36
|
-
methodData['x-events'].forEach((event: any) => {
|
37
|
-
if (event.required) {
|
38
|
-
requiredEventInputs.push(event);
|
39
|
-
requiredFields.push('__EVENT__/' + event.name);
|
40
|
-
}
|
41
|
-
});
|
42
|
-
}
|
43
|
-
|
44
|
-
requiredFields.push('');
|
45
|
-
const mutatorToolbox = [
|
46
|
-
...parameters
|
47
|
-
.map((param: { name: any }) => param.name)
|
48
|
-
.filter((name: any) => !requiredFields.includes(name)),
|
49
|
-
'__CONDITION__/if',
|
50
|
-
'__CONDITION__/each',
|
51
|
-
];
|
52
|
-
|
53
|
-
if (methodData.tags) {
|
54
|
-
if (methodData.tags.includes('needPins') && !methodData.tags.includes('requirePins')) {
|
55
|
-
mutatorToolbox.push('pins');
|
56
|
-
} else if (methodData.tags.includes('needPins') && methodData.tags.includes('requirePins')) {
|
57
|
-
blockDefinition['message3'] += '%1 %2 %3';
|
58
|
-
|
59
|
-
blockDefinition['args3'].push({
|
60
|
-
type: 'field_label',
|
61
|
-
name: `NAME_INPUT`,
|
62
|
-
text: 'pins*',
|
63
|
-
});
|
64
|
-
|
65
|
-
blockDefinition['args3'].push({
|
66
|
-
type: 'input_dummy',
|
67
|
-
});
|
68
|
-
|
69
|
-
blockDefinition['args3'].push({
|
70
|
-
type: 'input_statement',
|
71
|
-
name: 'pins',
|
72
|
-
});
|
73
|
-
|
74
|
-
requiredFields.push('pins');
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
if (methodData['x-events']) {
|
79
|
-
for (const event of methodData['x-events']) {
|
80
|
-
if (event.required === false || !event.required) {
|
81
|
-
mutatorToolbox.push('__EVENT__/' + event.name);
|
82
|
-
}
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
for (let i = 0; i < requiredParamInputs.length; i++) {
|
87
|
-
const position = blockDefinition['args1'].length;
|
88
|
-
|
89
|
-
blockDefinition['args1'].push({
|
90
|
-
type: 'field_label',
|
91
|
-
name: `NAME_INPUT`,
|
92
|
-
text: (requiredParamInputs[i].summary || requiredParamInputs[i].name) + '*',
|
93
|
-
});
|
94
|
-
if (
|
95
|
-
requiredParamInputs[i].schema?.type === 'array' &&
|
96
|
-
(requiredParamInputs[i].schema.items?.$ref === 'https://schemas.digipair.ai/pinsSettings' ||
|
97
|
-
requiredParamInputs[i].schema.items?.$ref?.includes('#/components/schemas/'))
|
98
|
-
) {
|
99
|
-
blockDefinition['message1'] +=
|
100
|
-
' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
|
101
|
-
blockDefinition['args1'].push({
|
102
|
-
type: 'input_dummy',
|
103
|
-
});
|
104
|
-
blockDefinition['args1'].push({
|
105
|
-
type: 'input_statement',
|
106
|
-
name: requiredParamInputs[i].name,
|
107
|
-
});
|
108
|
-
} else {
|
109
|
-
blockDefinition['message1'] += ' %' + (position + 1) + ' %' + (position + 2);
|
110
|
-
blockDefinition['args1'].push({
|
111
|
-
type: 'input_value',
|
112
|
-
name: requiredParamInputs[i].name,
|
113
|
-
});
|
114
|
-
}
|
115
|
-
}
|
116
|
-
|
117
|
-
for (let i = 0; i < requiredEventInputs.length; i++) {
|
118
|
-
const position = blockDefinition['args2'].length;
|
119
|
-
|
120
|
-
blockDefinition['args2'].push({
|
121
|
-
type: 'field_label',
|
122
|
-
name: `NAME_INPUT`,
|
123
|
-
text: '@' + (requiredEventInputs[i].summary || requiredEventInputs[i].name) + '*',
|
124
|
-
});
|
125
|
-
|
126
|
-
blockDefinition['message2'] +=
|
127
|
-
' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
|
128
|
-
blockDefinition['args2'].push({
|
129
|
-
type: 'input_dummy',
|
130
|
-
});
|
131
|
-
blockDefinition['args2'].push({
|
132
|
-
type: 'input_statement',
|
133
|
-
name: '__EVENT__/' + requiredEventInputs[i].name,
|
134
|
-
});
|
135
|
-
}
|
136
|
-
|
137
|
-
if (mutatorToolbox.length > 0) {
|
138
|
-
blockDefinition.mutator = pinsId + '/mutator';
|
139
|
-
generateMutator(pinsId + '/mutator', mutatorToolbox, requiredFields, [
|
140
|
-
...parameters,
|
141
|
-
...metadata,
|
142
|
-
...events,
|
143
|
-
]);
|
144
|
-
}
|
145
|
-
return blockDefinition;
|
146
|
-
}
|
147
|
-
|
148
|
-
function getComponentBlockDefinition(
|
149
|
-
library: { info: { [x: string]: string; title: string } },
|
150
|
-
componentName: string,
|
151
|
-
methodData: { summary: string; properties: any; required: any[] },
|
152
|
-
componentId: string,
|
153
|
-
) {
|
154
|
-
const blockDefinition: any = {
|
155
|
-
type: componentId,
|
156
|
-
message0: library.info['x-icon'] + ' ' + (methodData.summary || componentName),
|
157
|
-
args0: [],
|
158
|
-
message1: '',
|
159
|
-
args1: [],
|
160
|
-
colour: '#ffca28',
|
161
|
-
tooltip: 'library : ' + library.info.title,
|
162
|
-
inputsInline: false,
|
163
|
-
previousStatement: null,
|
164
|
-
nextStatement: null,
|
165
|
-
};
|
166
|
-
|
167
|
-
const properties = methodData.properties;
|
168
|
-
const requiredFields = methodData.required || [];
|
169
|
-
requiredFields.push('');
|
170
|
-
const mutatorToolbox: string[] = [];
|
171
|
-
const parameters = Object.keys(properties).map(propertyName => ({
|
172
|
-
name: propertyName,
|
173
|
-
summary: properties[propertyName].summary || propertyName,
|
174
|
-
schema: properties[propertyName],
|
175
|
-
}));
|
176
|
-
|
177
|
-
let messageIndex = 0;
|
178
|
-
parameters.forEach((parameter, _index) => {
|
179
|
-
if (!requiredFields.includes(parameter.name)) {
|
180
|
-
mutatorToolbox.push(parameter.name);
|
181
|
-
} else {
|
182
|
-
blockDefinition['args1'].push({
|
183
|
-
type: 'field_label',
|
184
|
-
name: 'NAME_INPUT',
|
185
|
-
text: parameter.summary + '*',
|
186
|
-
});
|
187
|
-
|
188
|
-
if (
|
189
|
-
parameter.schema?.type === 'array' &&
|
190
|
-
(parameter.schema.items?.$ref === 'https://schemas.digipair.ai/pinsSettings' ||
|
191
|
-
parameter.schema.items?.$ref.includes('#/components/schemas/'))
|
192
|
-
) {
|
193
|
-
blockDefinition['message1'] +=
|
194
|
-
' %' +
|
195
|
-
(messageIndex * 2 + 1) +
|
196
|
-
' %' +
|
197
|
-
(messageIndex * 2 + 2) +
|
198
|
-
' %' +
|
199
|
-
(messageIndex * 2 + 3);
|
200
|
-
blockDefinition['args1'].push({
|
201
|
-
type: 'input_dummy',
|
202
|
-
});
|
203
|
-
blockDefinition['args1'].push({
|
204
|
-
type: 'input_statement',
|
205
|
-
name: parameter.name,
|
206
|
-
});
|
207
|
-
} else {
|
208
|
-
blockDefinition['message1'] +=
|
209
|
-
' %' + (messageIndex * 2 + 1) + ' %' + (messageIndex * 2 + 2);
|
210
|
-
blockDefinition['args1'].push({
|
211
|
-
type: 'input_value',
|
212
|
-
name: parameter.name,
|
213
|
-
});
|
214
|
-
}
|
215
|
-
|
216
|
-
messageIndex++;
|
217
|
-
}
|
218
|
-
});
|
219
|
-
|
220
|
-
if (mutatorToolbox.length > 0) {
|
221
|
-
blockDefinition.mutator = componentId + '/mutator';
|
222
|
-
generateMutator(componentId + '/mutator', mutatorToolbox, requiredFields, parameters);
|
223
|
-
}
|
224
|
-
return blockDefinition;
|
225
|
-
}
|
226
|
-
|
227
|
-
export function generateToolboxFromLibraries(libraries: any[], tags: string[]) {
|
228
|
-
const sortedLibraries = libraries.sort((a, b) => {
|
229
|
-
const title1 = a.info.summary ?? a.info.title;
|
230
|
-
const title2 = b.info.summary ?? b.info.title;
|
231
|
-
|
232
|
-
if (title1 < title2) {
|
233
|
-
return -1;
|
234
|
-
}
|
235
|
-
if (title1 > title2) {
|
236
|
-
return 1;
|
237
|
-
}
|
238
|
-
return 0;
|
239
|
-
});
|
240
|
-
|
241
|
-
const toolbox = {
|
242
|
-
kind: 'categoryToolbox',
|
243
|
-
contents: [
|
244
|
-
{
|
245
|
-
kind: 'category',
|
246
|
-
name: '⚙️ Common',
|
247
|
-
contents: [
|
248
|
-
{
|
249
|
-
kind: 'block',
|
250
|
-
type: 'object',
|
251
|
-
},
|
252
|
-
{
|
253
|
-
kind: 'block',
|
254
|
-
type: 'member',
|
255
|
-
},
|
256
|
-
{
|
257
|
-
kind: 'block',
|
258
|
-
type: 'math_number',
|
259
|
-
},
|
260
|
-
{
|
261
|
-
kind: 'block',
|
262
|
-
type: 'text_multiline',
|
263
|
-
},
|
264
|
-
{
|
265
|
-
kind: 'block',
|
266
|
-
type: 'logic_boolean',
|
267
|
-
},
|
268
|
-
{
|
269
|
-
kind: 'block',
|
270
|
-
type: 'logic_null',
|
271
|
-
},
|
272
|
-
{
|
273
|
-
kind: 'block',
|
274
|
-
type: 'array',
|
275
|
-
},
|
276
|
-
{
|
277
|
-
kind: 'block',
|
278
|
-
type: 'array-input',
|
279
|
-
},
|
280
|
-
],
|
281
|
-
},
|
282
|
-
...sortedLibraries
|
283
|
-
.map(library => ({
|
284
|
-
kind: 'category',
|
285
|
-
name: library.info.summary ?? library.info.title,
|
286
|
-
contents: [
|
287
|
-
...(library.paths
|
288
|
-
? Object.entries(library.paths as { [x: string]: any })
|
289
|
-
.filter(([_path, pins]) =>
|
290
|
-
pins.post.tags.some((tag: string) => tags.includes(tag)),
|
291
|
-
)
|
292
|
-
.sort((a, b) => a[0].localeCompare(b[0])) // Tri alphabétique par path
|
293
|
-
.map(([path, _pins]) => ({
|
294
|
-
kind: 'block',
|
295
|
-
type: library.info.title + '/__PINS__' + path,
|
296
|
-
}))
|
297
|
-
: []),
|
298
|
-
...(library.components?.schemas
|
299
|
-
? Object.entries(library.components.schemas as { [x: string]: any })
|
300
|
-
.filter(([_componentName, schema]) =>
|
301
|
-
schema.tags.some((tag: string) => tags.includes(tag)),
|
302
|
-
)
|
303
|
-
.sort((a, b) => a[0].localeCompare(b[0])) // Tri alphabétique par componentName
|
304
|
-
.map(([componentName]) => ({
|
305
|
-
kind: 'block',
|
306
|
-
type: library.info.title + '/__COMPONENTS__/' + componentName,
|
307
|
-
}))
|
308
|
-
: []),
|
309
|
-
|
310
|
-
// // @todo: to comment to remove scene blocks
|
311
|
-
// ...(library['x-scene-blocks']
|
312
|
-
// ? Object.entries(library['x-scene-blocks'])
|
313
|
-
// .sort((a, b) => a[0].localeCompare(b[0])) // Tri alphabétique par sceneBlock
|
314
|
-
// .map(([sceneBlockName, _sceneBlockSchema]) => ({
|
315
|
-
// kind: 'block',
|
316
|
-
// type: library.info.title + '/__SCENEBLOCK__' + sceneBlockName,
|
317
|
-
// }))
|
318
|
-
// : []),
|
319
|
-
],
|
320
|
-
}))
|
321
|
-
.filter(library => library.contents.length > 0),
|
322
|
-
],
|
323
|
-
};
|
324
|
-
|
325
|
-
return toolbox;
|
326
|
-
}
|
327
|
-
|
328
|
-
function convertPinsLibrariesToBlocklyLibraries(pinsLibraries: any[]) {
|
329
|
-
return pinsLibraries.map(schema => ({
|
330
|
-
...schema,
|
331
|
-
paths: {
|
332
|
-
...Object.entries(schema.paths ?? {}).reduce(
|
333
|
-
(acc: any, [key, path]: [string, any]) => ({
|
334
|
-
...acc,
|
335
|
-
[key]: {
|
336
|
-
...path,
|
337
|
-
post: {
|
338
|
-
...path.post,
|
339
|
-
parameters: !path.post.parameters
|
340
|
-
? []
|
341
|
-
: [
|
342
|
-
...path.post.parameters,
|
343
|
-
...path.post.parameters
|
344
|
-
.filter(
|
345
|
-
(item: any) =>
|
346
|
-
item.schema?.type === 'array' &&
|
347
|
-
(item.schema.items?.$ref === 'https://schemas.digipair.ai/pinsSettings' ||
|
348
|
-
item.schema.items?.$ref?.includes('#/components/schemas/')),
|
349
|
-
)
|
350
|
-
.map((item: any) => ({
|
351
|
-
...item,
|
352
|
-
name: item.name + '__EVALUATE',
|
353
|
-
summary: (item.summary || item.name) + ' (evaluate)',
|
354
|
-
required: false,
|
355
|
-
schema: { type: 'string' },
|
356
|
-
})),
|
357
|
-
],
|
358
|
-
},
|
359
|
-
},
|
360
|
-
}),
|
361
|
-
{},
|
362
|
-
),
|
363
|
-
},
|
364
|
-
components: !schema.components
|
365
|
-
? {}
|
366
|
-
: {
|
367
|
-
...schema.components,
|
368
|
-
schemas: {
|
369
|
-
...Object.entries(schema.components.schemas || {}).reduce(
|
370
|
-
(acc: any, [key, component]: [string, any]) => ({
|
371
|
-
...acc,
|
372
|
-
[key]: {
|
373
|
-
...component,
|
374
|
-
properties: !component.properties
|
375
|
-
? {}
|
376
|
-
: {
|
377
|
-
...component.properties,
|
378
|
-
...Object.entries(component.properties)
|
379
|
-
.filter(
|
380
|
-
([_propertyKey, propertyValue]: any) =>
|
381
|
-
propertyValue.type === 'array' &&
|
382
|
-
(propertyValue.items?.$ref ===
|
383
|
-
'https://schemas.digipair.ai/pinsSettings' ||
|
384
|
-
propertyValue.items?.$ref?.includes('#/components/schemas/')),
|
385
|
-
)
|
386
|
-
.reduce(
|
387
|
-
(acc: any, [propertyKey, property]: [string, any]) => ({
|
388
|
-
...acc,
|
389
|
-
[propertyKey + '__EVALUATE']: {
|
390
|
-
...property,
|
391
|
-
summary: (property.summary || propertyKey) + ' (evaluate)',
|
392
|
-
required: false,
|
393
|
-
schema: { type: 'string' },
|
394
|
-
},
|
395
|
-
}),
|
396
|
-
{},
|
397
|
-
),
|
398
|
-
},
|
399
|
-
},
|
400
|
-
}),
|
401
|
-
{},
|
402
|
-
),
|
403
|
-
},
|
404
|
-
},
|
405
|
-
'x-scene-blocks': {
|
406
|
-
...Object.entries(schema['x-scene-blocks'] || {}).reduce(
|
407
|
-
(acc: any, [key, path]: [string, any]) => ({
|
408
|
-
...acc,
|
409
|
-
[key]: {
|
410
|
-
...path,
|
411
|
-
metadata: !path.metadata
|
412
|
-
? []
|
413
|
-
: [
|
414
|
-
...path.metadata,
|
415
|
-
...path.metadata
|
416
|
-
.filter(
|
417
|
-
(item: any) =>
|
418
|
-
item.schema?.type === 'array' &&
|
419
|
-
(item.schema.items?.$ref === 'https://schemas.digipair.ai/pinsSettings' ||
|
420
|
-
item.schema.items?.$ref?.includes('#/components/schemas/')),
|
421
|
-
)
|
422
|
-
.map((item: any) => ({
|
423
|
-
...item,
|
424
|
-
name: item.name + '__EVALUATE',
|
425
|
-
summary: (item.summary || item.name) + ' (evaluate)',
|
426
|
-
required: false,
|
427
|
-
schema: { type: 'string' },
|
428
|
-
})),
|
429
|
-
],
|
430
|
-
parameters: !path.parameters
|
431
|
-
? []
|
432
|
-
: [
|
433
|
-
...path.parameters,
|
434
|
-
...path.parameters
|
435
|
-
.filter(
|
436
|
-
(item: any) =>
|
437
|
-
item.schema?.type === 'array' &&
|
438
|
-
(item.schema.items?.$ref === 'https://schemas.digipair.ai/pinsSettings' ||
|
439
|
-
item.schema.items?.$ref?.includes('#/components/schemas/')),
|
440
|
-
)
|
441
|
-
.map((item: any) => ({
|
442
|
-
...item,
|
443
|
-
name: item.name + '__EVALUATE',
|
444
|
-
summary: (item.summary || item.name) + ' (evaluate)',
|
445
|
-
required: false,
|
446
|
-
schema: { type: 'string' },
|
447
|
-
})),
|
448
|
-
],
|
449
|
-
},
|
450
|
-
}),
|
451
|
-
{},
|
452
|
-
),
|
453
|
-
},
|
454
|
-
}));
|
455
|
-
}
|
456
|
-
|
457
|
-
export function generateBlocklyBlockFromLibraries(
|
458
|
-
pinsLibraries: any,
|
459
|
-
blocksLegacy: (
|
460
|
-
| {
|
461
|
-
type: string;
|
462
|
-
message0: string;
|
463
|
-
args0: (
|
464
|
-
| { type: string; name?: undefined; check?: undefined }
|
465
|
-
| { type: string; name: string; check: string }
|
466
|
-
)[];
|
467
|
-
output: null;
|
468
|
-
colour: string;
|
469
|
-
previousStatement?: undefined;
|
470
|
-
nextStatement?: undefined;
|
471
|
-
inputsInline?: undefined;
|
472
|
-
arg0?: undefined;
|
473
|
-
message1?: undefined;
|
474
|
-
args1?: undefined;
|
475
|
-
message2?: undefined;
|
476
|
-
args2?: undefined;
|
477
|
-
message3?: undefined;
|
478
|
-
args3?: undefined;
|
479
|
-
tooltip?: undefined;
|
480
|
-
helpUrl?: undefined;
|
481
|
-
}
|
482
|
-
| {
|
483
|
-
type: string;
|
484
|
-
message0: string;
|
485
|
-
args0: (
|
486
|
-
| { type: string; name: string; text: string }
|
487
|
-
| { type: string; name: string; text?: undefined }
|
488
|
-
)[];
|
489
|
-
previousStatement: string;
|
490
|
-
nextStatement: string;
|
491
|
-
colour: string;
|
492
|
-
output?: undefined;
|
493
|
-
inputsInline?: undefined;
|
494
|
-
arg0?: undefined;
|
495
|
-
message1?: undefined;
|
496
|
-
args1?: undefined;
|
497
|
-
message2?: undefined;
|
498
|
-
args2?: undefined;
|
499
|
-
message3?: undefined;
|
500
|
-
args3?: undefined;
|
501
|
-
tooltip?: undefined;
|
502
|
-
helpUrl?: undefined;
|
503
|
-
}
|
504
|
-
| {
|
505
|
-
type: string;
|
506
|
-
message0: string;
|
507
|
-
args0: never[];
|
508
|
-
colour: number;
|
509
|
-
inputsInline: boolean;
|
510
|
-
previousStatement: null;
|
511
|
-
nextStatement: null;
|
512
|
-
output?: undefined;
|
513
|
-
arg0?: undefined;
|
514
|
-
message1?: undefined;
|
515
|
-
args1?: undefined;
|
516
|
-
message2?: undefined;
|
517
|
-
args2?: undefined;
|
518
|
-
message3?: undefined;
|
519
|
-
args3?: undefined;
|
520
|
-
tooltip?: undefined;
|
521
|
-
helpUrl?: undefined;
|
522
|
-
}
|
523
|
-
| {
|
524
|
-
type: string;
|
525
|
-
message0: string;
|
526
|
-
args0: never[];
|
527
|
-
output: null;
|
528
|
-
colour: number;
|
529
|
-
previousStatement?: undefined;
|
530
|
-
nextStatement?: undefined;
|
531
|
-
inputsInline?: undefined;
|
532
|
-
arg0?: undefined;
|
533
|
-
message1?: undefined;
|
534
|
-
args1?: undefined;
|
535
|
-
message2?: undefined;
|
536
|
-
args2?: undefined;
|
537
|
-
message3?: undefined;
|
538
|
-
args3?: undefined;
|
539
|
-
tooltip?: undefined;
|
540
|
-
helpUrl?: undefined;
|
541
|
-
}
|
542
|
-
| {
|
543
|
-
type: string;
|
544
|
-
message0: string;
|
545
|
-
arg0: never[];
|
546
|
-
message1: string;
|
547
|
-
args1: { type: string; name: string; text: string }[];
|
548
|
-
message2: string;
|
549
|
-
args2: (
|
550
|
-
| { type: string; name: string; text: string }
|
551
|
-
| { type: string; name: string; text?: undefined }
|
552
|
-
)[];
|
553
|
-
message3: string;
|
554
|
-
args3: (
|
555
|
-
| { type: string; name: string; text: string }
|
556
|
-
| { type: string; name: string; text?: undefined }
|
557
|
-
)[];
|
558
|
-
colour: number;
|
559
|
-
tooltip: string;
|
560
|
-
helpUrl: string;
|
561
|
-
args0?: undefined;
|
562
|
-
output?: undefined;
|
563
|
-
previousStatement?: undefined;
|
564
|
-
nextStatement?: undefined;
|
565
|
-
inputsInline?: undefined;
|
566
|
-
}
|
567
|
-
)[],
|
568
|
-
): any[] {
|
569
|
-
const blocksLibrary = [...blocksLegacy];
|
570
|
-
const blocklyLibraries = convertPinsLibrariesToBlocklyLibraries(pinsLibraries);
|
571
|
-
|
572
|
-
for (const pinsLibrary of blocklyLibraries) {
|
573
|
-
//search for pins blocks
|
574
|
-
for (const endpoint in pinsLibrary.paths) {
|
575
|
-
if (Object.hasOwnProperty.call(pinsLibrary.paths, endpoint)) {
|
576
|
-
const endpointData = pinsLibrary.paths[endpoint];
|
577
|
-
const methodData = endpointData.post;
|
578
|
-
const pinsId = pinsLibrary.info.title + '/__PINS__' + endpoint;
|
579
|
-
|
580
|
-
blocksLibrary.push(getPinsBlockDefinition(pinsLibrary, methodData, pinsId));
|
581
|
-
}
|
582
|
-
}
|
583
|
-
}
|
584
|
-
|
585
|
-
for (const pinsLibrary of blocklyLibraries) {
|
586
|
-
//search for components blocks
|
587
|
-
if (!pinsLibrary.components || !pinsLibrary.components.schemas) {
|
588
|
-
continue;
|
589
|
-
}
|
590
|
-
|
591
|
-
for (const endpoint in pinsLibrary.components.schemas) {
|
592
|
-
if (Object.hasOwnProperty.call(pinsLibrary.components.schemas, endpoint)) {
|
593
|
-
const endpointData = pinsLibrary.components.schemas[endpoint];
|
594
|
-
|
595
|
-
if (!endpointData || !endpointData.properties) {
|
596
|
-
continue;
|
597
|
-
}
|
598
|
-
|
599
|
-
const componentId = pinsLibrary.info.title + '/__COMPONENTS__/' + endpoint;
|
600
|
-
const blockName = endpoint;
|
601
|
-
|
602
|
-
blocksLibrary.push(
|
603
|
-
getComponentBlockDefinition(pinsLibrary, blockName, endpointData, componentId),
|
604
|
-
);
|
605
|
-
}
|
606
|
-
}
|
607
|
-
}
|
608
|
-
|
609
|
-
for (const pinsLibrary of blocklyLibraries) {
|
610
|
-
//search for scene blocks
|
611
|
-
for (const endpoint in pinsLibrary['x-scene-blocks']) {
|
612
|
-
if (Object.hasOwnProperty.call(pinsLibrary['x-scene-blocks'], endpoint)) {
|
613
|
-
const endpointSceneblock = pinsLibrary['x-scene-blocks'][endpoint];
|
614
|
-
const sceneBlockId = pinsLibrary.info.title + '/__SCENEBLOCK__' + endpoint;
|
615
|
-
const block = getSceneBlockDefinition(pinsLibrary, endpointSceneblock, sceneBlockId);
|
616
|
-
|
617
|
-
blocksLibrary.push(block);
|
618
|
-
}
|
619
|
-
}
|
620
|
-
}
|
621
|
-
|
622
|
-
return blocksLibrary;
|
623
|
-
}
|
624
|
-
|
625
|
-
export function initializeMutator() {
|
626
|
-
Blockly.Blocks['mutator_container'] = {
|
627
|
-
init: function () {
|
628
|
-
this.appendDummyInput().appendField('Inputs');
|
629
|
-
this.appendStatementInput('STACK');
|
630
|
-
this.setColour(230);
|
631
|
-
this.setTooltip('');
|
632
|
-
|
633
|
-
this.workspace.addChangeListener((event: { type: any; newParentId: any }) => {
|
634
|
-
if (event.type === Blockly.Events.BLOCK_MOVE) {
|
635
|
-
let currentBlock = this.workspace.getBlockById(event.newParentId);
|
636
|
-
while (currentBlock) {
|
637
|
-
if (currentBlock.id === this.id) {
|
638
|
-
let firstBlock = this.getInputTargetBlock('STACK');
|
639
|
-
const seenTypes: any = {};
|
640
|
-
while (firstBlock) {
|
641
|
-
if (seenTypes[firstBlock.type]) {
|
642
|
-
firstBlock.unplug(true);
|
643
|
-
} else {
|
644
|
-
seenTypes[firstBlock.type] = true;
|
645
|
-
}
|
646
|
-
firstBlock = firstBlock.getNextBlock();
|
647
|
-
}
|
648
|
-
break;
|
649
|
-
}
|
650
|
-
currentBlock = currentBlock.getSurroundParent();
|
651
|
-
}
|
652
|
-
}
|
653
|
-
});
|
654
|
-
},
|
655
|
-
};
|
656
|
-
}
|
657
|
-
|
658
|
-
function generateMutator(
|
659
|
-
mutatorName: string,
|
660
|
-
toolboxItem: any[],
|
661
|
-
requiredFields: string | any[],
|
662
|
-
originParameters: any[],
|
663
|
-
) {
|
664
|
-
const parameters = [
|
665
|
-
...originParameters,
|
666
|
-
{ name: '__CONDITION__/if', schema: { type: 'boolean' } },
|
667
|
-
{ name: '__CONDITION__/each', schema: { type: 'array', items: { type: 'object' } } },
|
668
|
-
];
|
669
|
-
const toolboxList = [];
|
670
|
-
for (const item of toolboxItem) {
|
671
|
-
Blockly.Blocks[mutatorName + '/' + item] = {
|
672
|
-
init: function () {
|
673
|
-
this.appendDummyInput(item).appendField(
|
674
|
-
item.includes('__EVENT__/')
|
675
|
-
? item.replace('__EVENT__/', '@')
|
676
|
-
: item.includes('__CONDITION__/')
|
677
|
-
? item.replace('__CONDITION__/', '#')
|
678
|
-
: item,
|
679
|
-
);
|
680
|
-
this.setPreviousStatement(true);
|
681
|
-
this.setNextStatement(true);
|
682
|
-
this.setColour(0);
|
683
|
-
},
|
684
|
-
};
|
685
|
-
|
686
|
-
toolboxList.push(mutatorName + '/' + item);
|
687
|
-
}
|
688
|
-
toolboxList.sort((a, b) => a.localeCompare(b));
|
689
|
-
|
690
|
-
Blockly.Extensions.registerMutator(
|
691
|
-
mutatorName,
|
692
|
-
{
|
693
|
-
saveExtraState: function () {
|
694
|
-
return {
|
695
|
-
itemList: this.itemList_ || [],
|
696
|
-
};
|
697
|
-
},
|
698
|
-
|
699
|
-
loadExtraState: function (state: { [x: string]: any }) {
|
700
|
-
this.itemList_ = state['itemList'];
|
701
|
-
this.updateShape_();
|
702
|
-
},
|
703
|
-
|
704
|
-
decompose: function (workspace: { newBlock: (arg0: string) => any }) {
|
705
|
-
const containerBlock = workspace.newBlock('mutator_container');
|
706
|
-
containerBlock.initSvg();
|
707
|
-
let connection = containerBlock.getInput('STACK').connection;
|
708
|
-
for (let i = 0; i < this.inputList.length; i++) {
|
709
|
-
if (
|
710
|
-
requiredFields.includes(this.inputList[i].name) ||
|
711
|
-
/__INPUT$/g.test(this.inputList[i].name)
|
712
|
-
) {
|
713
|
-
continue;
|
714
|
-
}
|
715
|
-
const inputBlock = workspace.newBlock(mutatorName + '/' + this.inputList[i].name);
|
716
|
-
inputBlock.initSvg();
|
717
|
-
connection.connect(inputBlock.previousConnection);
|
718
|
-
connection = inputBlock.nextConnection;
|
719
|
-
}
|
720
|
-
|
721
|
-
return containerBlock;
|
722
|
-
},
|
723
|
-
|
724
|
-
compose: function (containerBlock: { getInputTargetBlock: (arg0: string) => any }) {
|
725
|
-
const inputConnectedArray = [];
|
726
|
-
|
727
|
-
let childBlock = containerBlock.getInputTargetBlock('STACK');
|
728
|
-
while (childBlock) {
|
729
|
-
const inputName = childBlock.inputList[0].name;
|
730
|
-
let fieldName = '';
|
731
|
-
|
732
|
-
if (childBlock.inputList[0]) {
|
733
|
-
const fieldRow = childBlock.inputList[0].fieldRow;
|
734
|
-
if (fieldRow.length > 0) {
|
735
|
-
fieldName = fieldRow[0].getText();
|
736
|
-
}
|
737
|
-
}
|
738
|
-
|
739
|
-
inputConnectedArray.push({
|
740
|
-
id: inputName,
|
741
|
-
name: fieldName,
|
742
|
-
});
|
743
|
-
|
744
|
-
childBlock = childBlock.nextConnection && childBlock.nextConnection.targetBlock();
|
745
|
-
}
|
746
|
-
|
747
|
-
this.itemList_ = inputConnectedArray;
|
748
|
-
this.updateShape_();
|
749
|
-
},
|
750
|
-
|
751
|
-
updateShape_: function () {
|
752
|
-
const inputToEnable = this.itemList_;
|
753
|
-
const inputLoaded = this.inputList.map((input: { name: any }) => input.name);
|
754
|
-
const inputToEnableIds = inputToEnable.map((input: { id: any }) => input.id);
|
755
|
-
|
756
|
-
for (const input of inputLoaded) {
|
757
|
-
if (requiredFields.includes(input)) continue;
|
758
|
-
if (!inputToEnableIds.includes(input.replace(/__INPUT$/g, ''))) {
|
759
|
-
this.removeInput(input);
|
760
|
-
}
|
761
|
-
}
|
762
|
-
|
763
|
-
for (const input of inputToEnable) {
|
764
|
-
if (requiredFields.includes(input)) {
|
765
|
-
continue;
|
766
|
-
}
|
767
|
-
if (!inputLoaded.includes(input.id)) {
|
768
|
-
const id = input.id.indexOf('/') < 0 ? input.id : input.id.split('/')[1];
|
769
|
-
const parameter = parameters.find((param: { name: any }) => param.name === id) ?? {};
|
770
|
-
|
771
|
-
if (
|
772
|
-
parameter.schema?.type === 'array' &&
|
773
|
-
(parameter.schema.items?.$ref === 'https://schemas.digipair.ai/pinsSettings' ||
|
774
|
-
parameter.schema.items?.$ref?.includes('#/components/schemas/'))
|
775
|
-
) {
|
776
|
-
this.appendDummyInput(input.id + '__INPUT').appendField(input.name);
|
777
|
-
this.appendStatementInput(input.id);
|
778
|
-
} else if (input.id === 'pins') {
|
779
|
-
this.appendDummyInput(input.id + '__INPUT').appendField(input.name);
|
780
|
-
this.appendStatementInput(input.id);
|
781
|
-
} else {
|
782
|
-
this.appendValueInput(input.id).appendField(input.name);
|
783
|
-
}
|
784
|
-
}
|
785
|
-
}
|
786
|
-
},
|
787
|
-
},
|
788
|
-
null,
|
789
|
-
toolboxList,
|
790
|
-
);
|
791
|
-
}
|
792
|
-
|
793
|
-
function getSceneBlockDefinition(
|
794
|
-
library: { info: { [x: string]: string; title: string } },
|
795
|
-
methodData: { summary: string; metadata: never[]; parameters: never[]; tags: string | string[] },
|
796
|
-
sceneBlockId: string,
|
797
|
-
) {
|
798
|
-
const blockDefinition: any = {
|
799
|
-
type: sceneBlockId,
|
800
|
-
message0: library.info['x-icon'] + ' ' + methodData.summary,
|
801
|
-
args0: [], //Empty field, only used for the scene block display name
|
802
|
-
message1: '',
|
803
|
-
args1: [], //parameters inputs field (going in metadata)
|
804
|
-
message2: '', // metadata inputs field
|
805
|
-
args2: [],
|
806
|
-
message3: '',
|
807
|
-
args3: [], //parameters inputs field (going in parameters)
|
808
|
-
colour: '#212e3c',
|
809
|
-
tooltip: 'library : ' + library.info.title,
|
810
|
-
};
|
811
|
-
|
812
|
-
const metadata: any[] = methodData.metadata || [];
|
813
|
-
const parameters: any[] = methodData.parameters || [];
|
814
|
-
|
815
|
-
if (methodData.tags && methodData.tags.includes('needPins')) {
|
816
|
-
const parameter = {
|
817
|
-
required: methodData.tags.includes('requirePins'),
|
818
|
-
name: 'EXECUTE_PINS',
|
819
|
-
summary: 'pins',
|
820
|
-
schema: {
|
821
|
-
type: 'array',
|
822
|
-
items: {
|
823
|
-
$ref: 'https://schemas.digipair.ai/pinsSettings',
|
824
|
-
},
|
825
|
-
},
|
826
|
-
};
|
827
|
-
parameters.push(parameter);
|
828
|
-
}
|
829
|
-
|
830
|
-
const requiredParamInputs = parameters.filter(
|
831
|
-
(param: { required: boolean }) => param.required === true,
|
832
|
-
);
|
833
|
-
const requiredFields = [
|
834
|
-
...requiredParamInputs.map((param: { name: any }) => param.name),
|
835
|
-
...metadata.map((param: { name: any }) => 'metadata--' + param.name),
|
836
|
-
];
|
837
|
-
requiredFields.push('');
|
838
|
-
|
839
|
-
// metadata
|
840
|
-
for (let i = 0; i < metadata?.length; i++) {
|
841
|
-
const parameter: any =
|
842
|
-
metadata.find((param: { name: any }) => param.name === metadata[i].name) ?? {};
|
843
|
-
const position = blockDefinition['args1'].length;
|
844
|
-
|
845
|
-
blockDefinition['args1'].push({
|
846
|
-
type: 'field_label',
|
847
|
-
name: `NAME_INPUT_METADATA`,
|
848
|
-
text: (parameter.summary || parameter.name) + '*',
|
849
|
-
});
|
850
|
-
|
851
|
-
if (
|
852
|
-
parameter.schema?.type === 'array' &&
|
853
|
-
(parameter.schema.items?.$ref === 'https://schemas.digipair.ai/pinsSettings' ||
|
854
|
-
parameter.schema.items?.$ref?.includes('#/components/schemas/'))
|
855
|
-
) {
|
856
|
-
blockDefinition['message1'] +=
|
857
|
-
' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
|
858
|
-
|
859
|
-
blockDefinition['args1'].push({
|
860
|
-
type: 'input_dummy',
|
861
|
-
});
|
862
|
-
blockDefinition['args1'].push({
|
863
|
-
type: 'input_statement',
|
864
|
-
name: 'metadata--' + parameter.name,
|
865
|
-
});
|
866
|
-
} else {
|
867
|
-
blockDefinition['message1'] += ' %' + (position + 1) + ' %' + (position + 2);
|
868
|
-
|
869
|
-
blockDefinition['args1'].push({
|
870
|
-
type: 'input_value',
|
871
|
-
name: 'metadata--' + parameter.name,
|
872
|
-
});
|
873
|
-
}
|
874
|
-
}
|
875
|
-
|
876
|
-
// mutator toolbox
|
877
|
-
const mutatorToolbox = parameters
|
878
|
-
.map((param: { name: any }) => param.name)
|
879
|
-
.filter((name: any) => !requiredFields.includes(name));
|
880
|
-
|
881
|
-
// parameters
|
882
|
-
for (let i = 0; i < requiredParamInputs.length; i++) {
|
883
|
-
const parameter =
|
884
|
-
parameters.find((param: { name: any }) => param.name === requiredParamInputs[i].name) ?? {};
|
885
|
-
const position = blockDefinition['args3'].length;
|
886
|
-
|
887
|
-
blockDefinition['args3'].push({
|
888
|
-
type: 'field_label',
|
889
|
-
name: `NAME_INPUT`,
|
890
|
-
text: (parameter.summary || parameter.name) + '*',
|
891
|
-
});
|
892
|
-
|
893
|
-
if (
|
894
|
-
parameter.schema?.type === 'array' &&
|
895
|
-
(parameter.schema.items?.$ref === 'https://schemas.digipair.ai/pinsSettings' ||
|
896
|
-
parameter.schema.items?.$ref?.includes('#/components/schemas/'))
|
897
|
-
) {
|
898
|
-
blockDefinition['message3'] +=
|
899
|
-
' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
|
900
|
-
|
901
|
-
blockDefinition['args3'].push({
|
902
|
-
type: 'input_dummy',
|
903
|
-
});
|
904
|
-
blockDefinition['args3'].push({
|
905
|
-
type: 'input_statement',
|
906
|
-
name: parameter.name,
|
907
|
-
});
|
908
|
-
} else {
|
909
|
-
blockDefinition['message3'] += ' %' + (position + 1) + ' %' + (position + 2);
|
910
|
-
|
911
|
-
blockDefinition['args3'].push({
|
912
|
-
type: 'input_value',
|
913
|
-
name: parameter.name,
|
914
|
-
});
|
915
|
-
}
|
916
|
-
}
|
917
|
-
|
918
|
-
if (mutatorToolbox.length > 0) {
|
919
|
-
blockDefinition.mutator = sceneBlockId + '/mutator';
|
920
|
-
generateMutator(sceneBlockId + '/mutator', mutatorToolbox, requiredFields, [
|
921
|
-
...parameters,
|
922
|
-
...(metadata || []),
|
923
|
-
]);
|
924
|
-
}
|
925
|
-
|
926
|
-
return blockDefinition;
|
927
|
-
}
|