@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.
Files changed (37) hide show
  1. package/blockly-to-json.cjs.js +338 -0
  2. package/blockly-to-json.esm.js +336 -0
  3. package/index.cjs.d.ts +1 -0
  4. package/index.cjs.js +12 -0
  5. package/index.cjs2.js +72611 -0
  6. package/index.esm.js +1 -0
  7. package/index.esm2.js +72608 -0
  8. package/libs/skill-web-editor/src/lib/blocks/json.d.ts +145 -0
  9. package/libs/skill-web-editor/src/lib/editor.element.d.ts +24 -0
  10. package/libs/skill-web-editor/src/lib/generator/blockly-to-json.d.ts +1 -0
  11. package/libs/skill-web-editor/src/lib/generator/json-to-blockly.d.ts +1 -0
  12. package/libs/skill-web-editor/src/lib/generator/pins-to-blockly.d.ts +139 -0
  13. package/libs/skill-web-editor/src/lib/schemas/web.fr.schema.d.ts +4028 -0
  14. package/libs/skill-web-editor/src/lib/schemas/web.schema.d.ts +4028 -0
  15. package/libs/skill-web-editor/src/lib/skill-web-editor.d.ts +1 -0
  16. package/package.json +5 -21
  17. package/pins-to-blockly.cjs.js +628 -0
  18. package/pins-to-blockly.esm.js +624 -0
  19. package/.swcrc +0 -28
  20. package/README.md +0 -7
  21. package/eslint.config.mjs +0 -22
  22. package/rollup.config.cjs +0 -28
  23. package/src/lib/blocks/json.ts +0 -145
  24. package/src/lib/editor.element.ts +0 -279
  25. package/src/lib/generator/blockly-to-json.ts +0 -360
  26. package/src/lib/generator/json-to-blockly.ts +0 -757
  27. package/src/lib/generator/pins-to-blockly.ts +0 -927
  28. package/src/lib/schemas/web.fr.schema.ts +0 -34473
  29. package/src/lib/schemas/web.schema.ts +0 -34473
  30. package/src/lib/skill-web-editor.spec.ts +0 -7
  31. package/src/lib/skill-web-editor.ts +0 -1
  32. package/tsconfig.json +0 -13
  33. package/tsconfig.lib.json +0 -19
  34. /package/{src/index.d.ts → index.d.ts} +0 -0
  35. /package/{src/index.ts → libs/skill-web-editor/src/index.d.ts} +0 -0
  36. /package/{src/schema.fr.json → schema.fr.json} +0 -0
  37. /package/{src/schema.json → schema.json} +0 -0
@@ -0,0 +1 @@
1
+ export * from './editor.element';
package/package.json CHANGED
@@ -1,28 +1,12 @@
1
1
  {
2
2
  "name": "@digipair/skill-web-editor",
3
- "version": "0.91.0-0",
4
- "type": "module",
5
- "main": "dist/libs/skill-web-editor/index.cjs.js",
6
- "module": "dist/libs/skill-web-editor/index.esm.js",
7
- "types": "dist/libs/skill-web-editor/index.esm.d.ts",
8
- "exports": {
9
- "./package.json": "./libs/skill-web-editor/package.json",
10
- ".": {
11
- "development": "./dist/libs/skill-web-editor/src/index.ts",
12
- "types": "./dist/libs/skill-web-editor/index.esm.d.ts",
13
- "import": "./dist/libs/skill-web-editor/index.esm.js",
14
- "default": "./dist/libs/skill-web-editor/index.cjs.js"
15
- }
16
- },
3
+ "version": "0.92.0",
17
4
  "keywords": [
18
5
  "digipair",
19
6
  "web",
20
7
  "util"
21
8
  ],
22
- "nx": {
23
- "name": "skill-web-editor"
24
- },
25
- "dependencies": {
26
- "@digipair/engine": "0.91.0-0"
27
- }
28
- }
9
+ "dependencies": {},
10
+ "main": "./index.cjs.js",
11
+ "module": "./index.esm.js"
12
+ }
@@ -0,0 +1,628 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index.cjs2.js');
4
+
5
+ function getPinsBlockDefinition(library, methodData, pinsId) {
6
+ const blockDefinition = {
7
+ type: pinsId,
8
+ message0: library.info['x-icon'] + ' ' + methodData.summary,
9
+ args0: [],
10
+ message1: '',
11
+ args1: [],
12
+ message2: '',
13
+ args2: [],
14
+ message3: '',
15
+ args3: [],
16
+ colour: '#b3aeee',
17
+ tooltip: 'library : ' + library.info.title,
18
+ inputsInline: false,
19
+ previousStatement: null,
20
+ nextStatement: null
21
+ };
22
+ const parameters = methodData.parameters;
23
+ const metadata = methodData.metadata || [];
24
+ const events = methodData['x-events'] || [];
25
+ const requiredParamInputs = parameters.filter((param)=>param.required === true);
26
+ const requiredEventInputs = [];
27
+ const requiredFields = requiredParamInputs.map((param)=>param.name);
28
+ if (methodData['x-events']) {
29
+ methodData['x-events'].forEach((event)=>{
30
+ if (event.required) {
31
+ requiredEventInputs.push(event);
32
+ requiredFields.push('__EVENT__/' + event.name);
33
+ }
34
+ });
35
+ }
36
+ requiredFields.push('');
37
+ const mutatorToolbox = [
38
+ ...parameters.map((param)=>param.name).filter((name)=>!requiredFields.includes(name)),
39
+ '__CONDITION__/if',
40
+ '__CONDITION__/each'
41
+ ];
42
+ if (methodData.tags) {
43
+ if (methodData.tags.includes('needPins') && !methodData.tags.includes('requirePins')) {
44
+ mutatorToolbox.push('pins');
45
+ } else if (methodData.tags.includes('needPins') && methodData.tags.includes('requirePins')) {
46
+ blockDefinition['message3'] += '%1 %2 %3';
47
+ blockDefinition['args3'].push({
48
+ type: 'field_label',
49
+ name: `NAME_INPUT`,
50
+ text: 'pins*'
51
+ });
52
+ blockDefinition['args3'].push({
53
+ type: 'input_dummy'
54
+ });
55
+ blockDefinition['args3'].push({
56
+ type: 'input_statement',
57
+ name: 'pins'
58
+ });
59
+ requiredFields.push('pins');
60
+ }
61
+ }
62
+ if (methodData['x-events']) {
63
+ for (const event of methodData['x-events']){
64
+ if (event.required === false || !event.required) {
65
+ mutatorToolbox.push('__EVENT__/' + event.name);
66
+ }
67
+ }
68
+ }
69
+ for(let i = 0; i < requiredParamInputs.length; i++){
70
+ var _requiredParamInputs_i_schema, _requiredParamInputs_i_schema_items, _requiredParamInputs_i_schema_items_$ref, _requiredParamInputs_i_schema_items1;
71
+ const position = blockDefinition['args1'].length;
72
+ blockDefinition['args1'].push({
73
+ type: 'field_label',
74
+ name: `NAME_INPUT`,
75
+ text: (requiredParamInputs[i].summary || requiredParamInputs[i].name) + '*'
76
+ });
77
+ if (((_requiredParamInputs_i_schema = requiredParamInputs[i].schema) == null ? void 0 : _requiredParamInputs_i_schema.type) === 'array' && (((_requiredParamInputs_i_schema_items = requiredParamInputs[i].schema.items) == null ? void 0 : _requiredParamInputs_i_schema_items.$ref) === 'https://schemas.digipair.ai/pinsSettings' || ((_requiredParamInputs_i_schema_items1 = requiredParamInputs[i].schema.items) == null ? void 0 : (_requiredParamInputs_i_schema_items_$ref = _requiredParamInputs_i_schema_items1.$ref) == null ? void 0 : _requiredParamInputs_i_schema_items_$ref.includes('#/components/schemas/')))) {
78
+ blockDefinition['message1'] += ' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
79
+ blockDefinition['args1'].push({
80
+ type: 'input_dummy'
81
+ });
82
+ blockDefinition['args1'].push({
83
+ type: 'input_statement',
84
+ name: requiredParamInputs[i].name
85
+ });
86
+ } else {
87
+ blockDefinition['message1'] += ' %' + (position + 1) + ' %' + (position + 2);
88
+ blockDefinition['args1'].push({
89
+ type: 'input_value',
90
+ name: requiredParamInputs[i].name
91
+ });
92
+ }
93
+ }
94
+ for(let i = 0; i < requiredEventInputs.length; i++){
95
+ const position = blockDefinition['args2'].length;
96
+ blockDefinition['args2'].push({
97
+ type: 'field_label',
98
+ name: `NAME_INPUT`,
99
+ text: '@' + (requiredEventInputs[i].summary || requiredEventInputs[i].name) + '*'
100
+ });
101
+ blockDefinition['message2'] += ' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
102
+ blockDefinition['args2'].push({
103
+ type: 'input_dummy'
104
+ });
105
+ blockDefinition['args2'].push({
106
+ type: 'input_statement',
107
+ name: '__EVENT__/' + requiredEventInputs[i].name
108
+ });
109
+ }
110
+ if (mutatorToolbox.length > 0) {
111
+ blockDefinition.mutator = pinsId + '/mutator';
112
+ generateMutator(pinsId + '/mutator', mutatorToolbox, requiredFields, [
113
+ ...parameters,
114
+ ...metadata,
115
+ ...events
116
+ ]);
117
+ }
118
+ return blockDefinition;
119
+ }
120
+ function getComponentBlockDefinition(library, componentName, methodData, componentId) {
121
+ const blockDefinition = {
122
+ type: componentId,
123
+ message0: library.info['x-icon'] + ' ' + (methodData.summary || componentName),
124
+ args0: [],
125
+ message1: '',
126
+ args1: [],
127
+ colour: '#ffca28',
128
+ tooltip: 'library : ' + library.info.title,
129
+ inputsInline: false,
130
+ previousStatement: null,
131
+ nextStatement: null
132
+ };
133
+ const properties = methodData.properties;
134
+ const requiredFields = methodData.required || [];
135
+ requiredFields.push('');
136
+ const mutatorToolbox = [];
137
+ const parameters = Object.keys(properties).map((propertyName)=>({
138
+ name: propertyName,
139
+ summary: properties[propertyName].summary || propertyName,
140
+ schema: properties[propertyName]
141
+ }));
142
+ let messageIndex = 0;
143
+ parameters.forEach((parameter, _index)=>{
144
+ if (!requiredFields.includes(parameter.name)) {
145
+ mutatorToolbox.push(parameter.name);
146
+ } else {
147
+ var _parameter_schema, _parameter_schema_items, _parameter_schema_items1;
148
+ blockDefinition['args1'].push({
149
+ type: 'field_label',
150
+ name: 'NAME_INPUT',
151
+ text: parameter.summary + '*'
152
+ });
153
+ if (((_parameter_schema = parameter.schema) == null ? void 0 : _parameter_schema.type) === 'array' && (((_parameter_schema_items = parameter.schema.items) == null ? void 0 : _parameter_schema_items.$ref) === 'https://schemas.digipair.ai/pinsSettings' || ((_parameter_schema_items1 = parameter.schema.items) == null ? void 0 : _parameter_schema_items1.$ref.includes('#/components/schemas/')))) {
154
+ blockDefinition['message1'] += ' %' + (messageIndex * 2 + 1) + ' %' + (messageIndex * 2 + 2) + ' %' + (messageIndex * 2 + 3);
155
+ blockDefinition['args1'].push({
156
+ type: 'input_dummy'
157
+ });
158
+ blockDefinition['args1'].push({
159
+ type: 'input_statement',
160
+ name: parameter.name
161
+ });
162
+ } else {
163
+ blockDefinition['message1'] += ' %' + (messageIndex * 2 + 1) + ' %' + (messageIndex * 2 + 2);
164
+ blockDefinition['args1'].push({
165
+ type: 'input_value',
166
+ name: parameter.name
167
+ });
168
+ }
169
+ messageIndex++;
170
+ }
171
+ });
172
+ if (mutatorToolbox.length > 0) {
173
+ blockDefinition.mutator = componentId + '/mutator';
174
+ generateMutator(componentId + '/mutator', mutatorToolbox, requiredFields, parameters);
175
+ }
176
+ return blockDefinition;
177
+ }
178
+ function generateToolboxFromLibraries(libraries, tags) {
179
+ const sortedLibraries = libraries.sort((a, b)=>{
180
+ var _a_info_summary;
181
+ const title1 = (_a_info_summary = a.info.summary) != null ? _a_info_summary : a.info.title;
182
+ var _b_info_summary;
183
+ const title2 = (_b_info_summary = b.info.summary) != null ? _b_info_summary : b.info.title;
184
+ if (title1 < title2) {
185
+ return -1;
186
+ }
187
+ if (title1 > title2) {
188
+ return 1;
189
+ }
190
+ return 0;
191
+ });
192
+ const toolbox = {
193
+ kind: 'categoryToolbox',
194
+ contents: [
195
+ {
196
+ kind: 'category',
197
+ name: '⚙️ Common',
198
+ contents: [
199
+ {
200
+ kind: 'block',
201
+ type: 'object'
202
+ },
203
+ {
204
+ kind: 'block',
205
+ type: 'member'
206
+ },
207
+ {
208
+ kind: 'block',
209
+ type: 'math_number'
210
+ },
211
+ {
212
+ kind: 'block',
213
+ type: 'text_multiline'
214
+ },
215
+ {
216
+ kind: 'block',
217
+ type: 'logic_boolean'
218
+ },
219
+ {
220
+ kind: 'block',
221
+ type: 'logic_null'
222
+ },
223
+ {
224
+ kind: 'block',
225
+ type: 'array'
226
+ },
227
+ {
228
+ kind: 'block',
229
+ type: 'array-input'
230
+ }
231
+ ]
232
+ },
233
+ ...sortedLibraries.map((library)=>{
234
+ var _library_components;
235
+ var _library_info_summary;
236
+ return {
237
+ kind: 'category',
238
+ name: (_library_info_summary = library.info.summary) != null ? _library_info_summary : library.info.title,
239
+ contents: [
240
+ ...library.paths ? Object.entries(library.paths).filter(([_path, pins])=>pins.post.tags.some((tag)=>tags.includes(tag))).sort((a, b)=>a[0].localeCompare(b[0])) // Tri alphabétique par path
241
+ .map(([path, _pins])=>({
242
+ kind: 'block',
243
+ type: library.info.title + '/__PINS__' + path
244
+ })) : [],
245
+ ...((_library_components = library.components) == null ? void 0 : _library_components.schemas) ? Object.entries(library.components.schemas).filter(([_componentName, schema])=>schema.tags.some((tag)=>tags.includes(tag))).sort((a, b)=>a[0].localeCompare(b[0])) // Tri alphabétique par componentName
246
+ .map(([componentName])=>({
247
+ kind: 'block',
248
+ type: library.info.title + '/__COMPONENTS__/' + componentName
249
+ })) : []
250
+ ]
251
+ };
252
+ }).filter((library)=>library.contents.length > 0)
253
+ ]
254
+ };
255
+ return toolbox;
256
+ }
257
+ function convertPinsLibrariesToBlocklyLibraries(pinsLibraries) {
258
+ return pinsLibraries.map((schema)=>{
259
+ var _schema_paths;
260
+ return index._extends({}, schema, {
261
+ paths: index._extends({}, Object.entries((_schema_paths = schema.paths) != null ? _schema_paths : {}).reduce((acc, [key, path])=>index._extends({}, acc, {
262
+ [key]: index._extends({}, path, {
263
+ post: index._extends({}, path.post, {
264
+ parameters: !path.post.parameters ? [] : [
265
+ ...path.post.parameters,
266
+ ...path.post.parameters.filter((item)=>{
267
+ var _item_schema, _item_schema_items, _item_schema_items_$ref, _item_schema_items1;
268
+ return ((_item_schema = item.schema) == null ? void 0 : _item_schema.type) === 'array' && (((_item_schema_items = item.schema.items) == null ? void 0 : _item_schema_items.$ref) === 'https://schemas.digipair.ai/pinsSettings' || ((_item_schema_items1 = item.schema.items) == null ? void 0 : (_item_schema_items_$ref = _item_schema_items1.$ref) == null ? void 0 : _item_schema_items_$ref.includes('#/components/schemas/')));
269
+ }).map((item)=>index._extends({}, item, {
270
+ name: item.name + '__EVALUATE',
271
+ summary: (item.summary || item.name) + ' (evaluate)',
272
+ required: false,
273
+ schema: {
274
+ type: 'string'
275
+ }
276
+ }))
277
+ ]
278
+ })
279
+ })
280
+ }), {})),
281
+ components: !schema.components ? {} : index._extends({}, schema.components, {
282
+ schemas: index._extends({}, Object.entries(schema.components.schemas || {}).reduce((acc, [key, component])=>index._extends({}, acc, {
283
+ [key]: index._extends({}, component, {
284
+ properties: !component.properties ? {} : index._extends({}, component.properties, Object.entries(component.properties).filter(([_propertyKey, propertyValue])=>{
285
+ var _propertyValue_items, _propertyValue_items_$ref, _propertyValue_items1;
286
+ return propertyValue.type === 'array' && (((_propertyValue_items = propertyValue.items) == null ? void 0 : _propertyValue_items.$ref) === 'https://schemas.digipair.ai/pinsSettings' || ((_propertyValue_items1 = propertyValue.items) == null ? void 0 : (_propertyValue_items_$ref = _propertyValue_items1.$ref) == null ? void 0 : _propertyValue_items_$ref.includes('#/components/schemas/')));
287
+ }).reduce((acc, [propertyKey, property])=>index._extends({}, acc, {
288
+ [propertyKey + '__EVALUATE']: index._extends({}, property, {
289
+ summary: (property.summary || propertyKey) + ' (evaluate)',
290
+ required: false,
291
+ schema: {
292
+ type: 'string'
293
+ }
294
+ })
295
+ }), {}))
296
+ })
297
+ }), {}))
298
+ }),
299
+ 'x-scene-blocks': index._extends({}, Object.entries(schema['x-scene-blocks'] || {}).reduce((acc, [key, path])=>index._extends({}, acc, {
300
+ [key]: index._extends({}, path, {
301
+ metadata: !path.metadata ? [] : [
302
+ ...path.metadata,
303
+ ...path.metadata.filter((item)=>{
304
+ var _item_schema, _item_schema_items, _item_schema_items_$ref, _item_schema_items1;
305
+ return ((_item_schema = item.schema) == null ? void 0 : _item_schema.type) === 'array' && (((_item_schema_items = item.schema.items) == null ? void 0 : _item_schema_items.$ref) === 'https://schemas.digipair.ai/pinsSettings' || ((_item_schema_items1 = item.schema.items) == null ? void 0 : (_item_schema_items_$ref = _item_schema_items1.$ref) == null ? void 0 : _item_schema_items_$ref.includes('#/components/schemas/')));
306
+ }).map((item)=>index._extends({}, item, {
307
+ name: item.name + '__EVALUATE',
308
+ summary: (item.summary || item.name) + ' (evaluate)',
309
+ required: false,
310
+ schema: {
311
+ type: 'string'
312
+ }
313
+ }))
314
+ ],
315
+ parameters: !path.parameters ? [] : [
316
+ ...path.parameters,
317
+ ...path.parameters.filter((item)=>{
318
+ var _item_schema, _item_schema_items, _item_schema_items_$ref, _item_schema_items1;
319
+ return ((_item_schema = item.schema) == null ? void 0 : _item_schema.type) === 'array' && (((_item_schema_items = item.schema.items) == null ? void 0 : _item_schema_items.$ref) === 'https://schemas.digipair.ai/pinsSettings' || ((_item_schema_items1 = item.schema.items) == null ? void 0 : (_item_schema_items_$ref = _item_schema_items1.$ref) == null ? void 0 : _item_schema_items_$ref.includes('#/components/schemas/')));
320
+ }).map((item)=>index._extends({}, item, {
321
+ name: item.name + '__EVALUATE',
322
+ summary: (item.summary || item.name) + ' (evaluate)',
323
+ required: false,
324
+ schema: {
325
+ type: 'string'
326
+ }
327
+ }))
328
+ ]
329
+ })
330
+ }), {}))
331
+ });
332
+ });
333
+ }
334
+ function generateBlocklyBlockFromLibraries(pinsLibraries, blocksLegacy) {
335
+ const blocksLibrary = [
336
+ ...blocksLegacy
337
+ ];
338
+ const blocklyLibraries = convertPinsLibrariesToBlocklyLibraries(pinsLibraries);
339
+ for (const pinsLibrary of blocklyLibraries){
340
+ //search for pins blocks
341
+ for(const endpoint in pinsLibrary.paths){
342
+ if (Object.hasOwnProperty.call(pinsLibrary.paths, endpoint)) {
343
+ const endpointData = pinsLibrary.paths[endpoint];
344
+ const methodData = endpointData.post;
345
+ const pinsId = pinsLibrary.info.title + '/__PINS__' + endpoint;
346
+ blocksLibrary.push(getPinsBlockDefinition(pinsLibrary, methodData, pinsId));
347
+ }
348
+ }
349
+ }
350
+ for (const pinsLibrary of blocklyLibraries){
351
+ //search for components blocks
352
+ if (!pinsLibrary.components || !pinsLibrary.components.schemas) {
353
+ continue;
354
+ }
355
+ for(const endpoint in pinsLibrary.components.schemas){
356
+ if (Object.hasOwnProperty.call(pinsLibrary.components.schemas, endpoint)) {
357
+ const endpointData = pinsLibrary.components.schemas[endpoint];
358
+ if (!endpointData || !endpointData.properties) {
359
+ continue;
360
+ }
361
+ const componentId = pinsLibrary.info.title + '/__COMPONENTS__/' + endpoint;
362
+ const blockName = endpoint;
363
+ blocksLibrary.push(getComponentBlockDefinition(pinsLibrary, blockName, endpointData, componentId));
364
+ }
365
+ }
366
+ }
367
+ for (const pinsLibrary of blocklyLibraries){
368
+ //search for scene blocks
369
+ for(const endpoint in pinsLibrary['x-scene-blocks']){
370
+ if (Object.hasOwnProperty.call(pinsLibrary['x-scene-blocks'], endpoint)) {
371
+ const endpointSceneblock = pinsLibrary['x-scene-blocks'][endpoint];
372
+ const sceneBlockId = pinsLibrary.info.title + '/__SCENEBLOCK__' + endpoint;
373
+ const block = getSceneBlockDefinition(pinsLibrary, endpointSceneblock, sceneBlockId);
374
+ blocksLibrary.push(block);
375
+ }
376
+ }
377
+ }
378
+ return blocksLibrary;
379
+ }
380
+ function initializeMutator() {
381
+ Blockly.Blocks['mutator_container'] = {
382
+ init: function() {
383
+ this.appendDummyInput().appendField('Inputs');
384
+ this.appendStatementInput('STACK');
385
+ this.setColour(230);
386
+ this.setTooltip('');
387
+ this.workspace.addChangeListener((event)=>{
388
+ if (event.type === Blockly.Events.BLOCK_MOVE) {
389
+ let currentBlock = this.workspace.getBlockById(event.newParentId);
390
+ while(currentBlock){
391
+ if (currentBlock.id === this.id) {
392
+ let firstBlock = this.getInputTargetBlock('STACK');
393
+ const seenTypes = {};
394
+ while(firstBlock){
395
+ if (seenTypes[firstBlock.type]) {
396
+ firstBlock.unplug(true);
397
+ } else {
398
+ seenTypes[firstBlock.type] = true;
399
+ }
400
+ firstBlock = firstBlock.getNextBlock();
401
+ }
402
+ break;
403
+ }
404
+ currentBlock = currentBlock.getSurroundParent();
405
+ }
406
+ }
407
+ });
408
+ }
409
+ };
410
+ }
411
+ function generateMutator(mutatorName, toolboxItem, requiredFields, originParameters) {
412
+ const parameters = [
413
+ ...originParameters,
414
+ {
415
+ name: '__CONDITION__/if',
416
+ schema: {
417
+ type: 'boolean'
418
+ }
419
+ },
420
+ {
421
+ name: '__CONDITION__/each',
422
+ schema: {
423
+ type: 'array',
424
+ items: {
425
+ type: 'object'
426
+ }
427
+ }
428
+ }
429
+ ];
430
+ const toolboxList = [];
431
+ for (const item of toolboxItem){
432
+ Blockly.Blocks[mutatorName + '/' + item] = {
433
+ init: function() {
434
+ this.appendDummyInput(item).appendField(item.includes('__EVENT__/') ? item.replace('__EVENT__/', '@') : item.includes('__CONDITION__/') ? item.replace('__CONDITION__/', '#') : item);
435
+ this.setPreviousStatement(true);
436
+ this.setNextStatement(true);
437
+ this.setColour(0);
438
+ }
439
+ };
440
+ toolboxList.push(mutatorName + '/' + item);
441
+ }
442
+ toolboxList.sort((a, b)=>a.localeCompare(b));
443
+ Blockly.Extensions.registerMutator(mutatorName, {
444
+ saveExtraState: function() {
445
+ return {
446
+ itemList: this.itemList_ || []
447
+ };
448
+ },
449
+ loadExtraState: function(state) {
450
+ this.itemList_ = state['itemList'];
451
+ this.updateShape_();
452
+ },
453
+ decompose: function(workspace) {
454
+ const containerBlock = workspace.newBlock('mutator_container');
455
+ containerBlock.initSvg();
456
+ let connection = containerBlock.getInput('STACK').connection;
457
+ for(let i = 0; i < this.inputList.length; i++){
458
+ if (requiredFields.includes(this.inputList[i].name) || /__INPUT$/g.test(this.inputList[i].name)) {
459
+ continue;
460
+ }
461
+ const inputBlock = workspace.newBlock(mutatorName + '/' + this.inputList[i].name);
462
+ inputBlock.initSvg();
463
+ connection.connect(inputBlock.previousConnection);
464
+ connection = inputBlock.nextConnection;
465
+ }
466
+ return containerBlock;
467
+ },
468
+ compose: function(containerBlock) {
469
+ const inputConnectedArray = [];
470
+ let childBlock = containerBlock.getInputTargetBlock('STACK');
471
+ while(childBlock){
472
+ const inputName = childBlock.inputList[0].name;
473
+ let fieldName = '';
474
+ if (childBlock.inputList[0]) {
475
+ const fieldRow = childBlock.inputList[0].fieldRow;
476
+ if (fieldRow.length > 0) {
477
+ fieldName = fieldRow[0].getText();
478
+ }
479
+ }
480
+ inputConnectedArray.push({
481
+ id: inputName,
482
+ name: fieldName
483
+ });
484
+ childBlock = childBlock.nextConnection && childBlock.nextConnection.targetBlock();
485
+ }
486
+ this.itemList_ = inputConnectedArray;
487
+ this.updateShape_();
488
+ },
489
+ updateShape_: function() {
490
+ const inputToEnable = this.itemList_;
491
+ const inputLoaded = this.inputList.map((input)=>input.name);
492
+ const inputToEnableIds = inputToEnable.map((input)=>input.id);
493
+ for (const input of inputLoaded){
494
+ if (requiredFields.includes(input)) continue;
495
+ if (!inputToEnableIds.includes(input.replace(/__INPUT$/g, ''))) {
496
+ this.removeInput(input);
497
+ }
498
+ }
499
+ for (const input of inputToEnable){
500
+ if (requiredFields.includes(input)) {
501
+ continue;
502
+ }
503
+ if (!inputLoaded.includes(input.id)) {
504
+ var _parameter_schema, _parameter_schema_items, _parameter_schema_items_$ref, _parameter_schema_items1;
505
+ const id = input.id.indexOf('/') < 0 ? input.id : input.id.split('/')[1];
506
+ var _parameters_find;
507
+ const parameter = (_parameters_find = parameters.find((param)=>param.name === id)) != null ? _parameters_find : {};
508
+ if (((_parameter_schema = parameter.schema) == null ? void 0 : _parameter_schema.type) === 'array' && (((_parameter_schema_items = parameter.schema.items) == null ? void 0 : _parameter_schema_items.$ref) === 'https://schemas.digipair.ai/pinsSettings' || ((_parameter_schema_items1 = parameter.schema.items) == null ? void 0 : (_parameter_schema_items_$ref = _parameter_schema_items1.$ref) == null ? void 0 : _parameter_schema_items_$ref.includes('#/components/schemas/')))) {
509
+ this.appendDummyInput(input.id + '__INPUT').appendField(input.name);
510
+ this.appendStatementInput(input.id);
511
+ } else if (input.id === 'pins') {
512
+ this.appendDummyInput(input.id + '__INPUT').appendField(input.name);
513
+ this.appendStatementInput(input.id);
514
+ } else {
515
+ this.appendValueInput(input.id).appendField(input.name);
516
+ }
517
+ }
518
+ }
519
+ }
520
+ }, null, toolboxList);
521
+ }
522
+ function getSceneBlockDefinition(library, methodData, sceneBlockId) {
523
+ const blockDefinition = {
524
+ type: sceneBlockId,
525
+ message0: library.info['x-icon'] + ' ' + methodData.summary,
526
+ args0: [],
527
+ message1: '',
528
+ args1: [],
529
+ message2: '',
530
+ args2: [],
531
+ message3: '',
532
+ args3: [],
533
+ colour: '#212e3c',
534
+ tooltip: 'library : ' + library.info.title
535
+ };
536
+ const metadata = methodData.metadata || [];
537
+ const parameters = methodData.parameters || [];
538
+ if (methodData.tags && methodData.tags.includes('needPins')) {
539
+ const parameter = {
540
+ required: methodData.tags.includes('requirePins'),
541
+ name: 'EXECUTE_PINS',
542
+ summary: 'pins',
543
+ schema: {
544
+ type: 'array',
545
+ items: {
546
+ $ref: 'https://schemas.digipair.ai/pinsSettings'
547
+ }
548
+ }
549
+ };
550
+ parameters.push(parameter);
551
+ }
552
+ const requiredParamInputs = parameters.filter((param)=>param.required === true);
553
+ const requiredFields = [
554
+ ...requiredParamInputs.map((param)=>param.name),
555
+ ...metadata.map((param)=>'metadata--' + param.name)
556
+ ];
557
+ requiredFields.push('');
558
+ // metadata
559
+ for(let i = 0; i < (metadata == null ? void 0 : metadata.length); i++){
560
+ var _parameter_schema, _parameter_schema_items, _parameter_schema_items_$ref, _parameter_schema_items1;
561
+ var _metadata_find;
562
+ const parameter = (_metadata_find = metadata.find((param)=>param.name === metadata[i].name)) != null ? _metadata_find : {};
563
+ const position = blockDefinition['args1'].length;
564
+ blockDefinition['args1'].push({
565
+ type: 'field_label',
566
+ name: `NAME_INPUT_METADATA`,
567
+ text: (parameter.summary || parameter.name) + '*'
568
+ });
569
+ if (((_parameter_schema = parameter.schema) == null ? void 0 : _parameter_schema.type) === 'array' && (((_parameter_schema_items = parameter.schema.items) == null ? void 0 : _parameter_schema_items.$ref) === 'https://schemas.digipair.ai/pinsSettings' || ((_parameter_schema_items1 = parameter.schema.items) == null ? void 0 : (_parameter_schema_items_$ref = _parameter_schema_items1.$ref) == null ? void 0 : _parameter_schema_items_$ref.includes('#/components/schemas/')))) {
570
+ blockDefinition['message1'] += ' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
571
+ blockDefinition['args1'].push({
572
+ type: 'input_dummy'
573
+ });
574
+ blockDefinition['args1'].push({
575
+ type: 'input_statement',
576
+ name: 'metadata--' + parameter.name
577
+ });
578
+ } else {
579
+ blockDefinition['message1'] += ' %' + (position + 1) + ' %' + (position + 2);
580
+ blockDefinition['args1'].push({
581
+ type: 'input_value',
582
+ name: 'metadata--' + parameter.name
583
+ });
584
+ }
585
+ }
586
+ // mutator toolbox
587
+ const mutatorToolbox = parameters.map((param)=>param.name).filter((name)=>!requiredFields.includes(name));
588
+ // parameters
589
+ for(let i = 0; i < requiredParamInputs.length; i++){
590
+ var _parameter_schema1, _parameter_schema_items2, _parameter_schema_items_$ref1, _parameter_schema_items3;
591
+ var _parameters_find;
592
+ const parameter = (_parameters_find = parameters.find((param)=>param.name === requiredParamInputs[i].name)) != null ? _parameters_find : {};
593
+ const position = blockDefinition['args3'].length;
594
+ blockDefinition['args3'].push({
595
+ type: 'field_label',
596
+ name: `NAME_INPUT`,
597
+ text: (parameter.summary || parameter.name) + '*'
598
+ });
599
+ if (((_parameter_schema1 = parameter.schema) == null ? void 0 : _parameter_schema1.type) === 'array' && (((_parameter_schema_items2 = parameter.schema.items) == null ? void 0 : _parameter_schema_items2.$ref) === 'https://schemas.digipair.ai/pinsSettings' || ((_parameter_schema_items3 = parameter.schema.items) == null ? void 0 : (_parameter_schema_items_$ref1 = _parameter_schema_items3.$ref) == null ? void 0 : _parameter_schema_items_$ref1.includes('#/components/schemas/')))) {
600
+ blockDefinition['message3'] += ' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
601
+ blockDefinition['args3'].push({
602
+ type: 'input_dummy'
603
+ });
604
+ blockDefinition['args3'].push({
605
+ type: 'input_statement',
606
+ name: parameter.name
607
+ });
608
+ } else {
609
+ blockDefinition['message3'] += ' %' + (position + 1) + ' %' + (position + 2);
610
+ blockDefinition['args3'].push({
611
+ type: 'input_value',
612
+ name: parameter.name
613
+ });
614
+ }
615
+ }
616
+ if (mutatorToolbox.length > 0) {
617
+ blockDefinition.mutator = sceneBlockId + '/mutator';
618
+ generateMutator(sceneBlockId + '/mutator', mutatorToolbox, requiredFields, [
619
+ ...parameters,
620
+ ...metadata || []
621
+ ]);
622
+ }
623
+ return blockDefinition;
624
+ }
625
+
626
+ exports.generateBlocklyBlockFromLibraries = generateBlocklyBlockFromLibraries;
627
+ exports.generateToolboxFromLibraries = generateToolboxFromLibraries;
628
+ exports.initializeMutator = initializeMutator;