@digipair/skill-web-editor 0.4.2
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 +327 -0
- package/blockly-to-json.esm.js +325 -0
- package/index.cjs.d.ts +1 -0
- package/index.cjs.js +14 -0
- package/index.cjs2.js +3242 -0
- package/index.d.ts +1 -0
- package/index.esm.js +1 -0
- package/index.esm2.js +3237 -0
- package/libs/skill-web-editor/src/index.d.ts +2 -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 +23 -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/skill-web-editor.d.ts +3 -0
- package/package.json +7 -0
- package/pins-to-blockly.cjs.js +519 -0
- package/pins-to-blockly.esm.js +515 -0
- package/schema.json +93 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
function getPinsBlockDefinition(library, methodData, pinsId) {
|
|
2
|
+
const blockDefinition = {
|
|
3
|
+
type: pinsId,
|
|
4
|
+
message0: library.info['x-icon'] + ' ' + methodData.summary,
|
|
5
|
+
args0: [],
|
|
6
|
+
message1: '',
|
|
7
|
+
args1: [],
|
|
8
|
+
message2: '',
|
|
9
|
+
args2: [],
|
|
10
|
+
message3: '',
|
|
11
|
+
args3: [],
|
|
12
|
+
colour: '#1e2835',
|
|
13
|
+
tooltip: 'library : ' + library.info.title,
|
|
14
|
+
inputsInline: false,
|
|
15
|
+
previousStatement: null,
|
|
16
|
+
nextStatement: null
|
|
17
|
+
};
|
|
18
|
+
const parameters = methodData.parameters;
|
|
19
|
+
const metadata = methodData.metadata || [];
|
|
20
|
+
const events = methodData['x-events'] || [];
|
|
21
|
+
const requiredParamInputs = parameters.filter((param)=>param.required === true);
|
|
22
|
+
const requiredEventInputs = [];
|
|
23
|
+
const requiredFields = requiredParamInputs.map((param)=>param.name);
|
|
24
|
+
if (methodData['x-events']) {
|
|
25
|
+
methodData['x-events'].forEach((event)=>{
|
|
26
|
+
if (event.required) {
|
|
27
|
+
requiredEventInputs.push(event);
|
|
28
|
+
requiredFields.push('__EVENT__/' + event.name);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
requiredFields.push('');
|
|
33
|
+
const mutatorToolbox = parameters.map((param)=>param.name).filter((name)=>!requiredFields.includes(name));
|
|
34
|
+
if (methodData.tags) {
|
|
35
|
+
if (methodData.tags.includes('needPins') && !methodData.tags.includes('requirePins')) {
|
|
36
|
+
mutatorToolbox.push('pins');
|
|
37
|
+
} else if (methodData.tags.includes('needPins') && methodData.tags.includes('requirePins')) {
|
|
38
|
+
blockDefinition['message3'] += '%1 %2 %3';
|
|
39
|
+
blockDefinition['args3'].push({
|
|
40
|
+
type: 'field_label',
|
|
41
|
+
name: `NAME_INPUT`,
|
|
42
|
+
text: 'pins*'
|
|
43
|
+
});
|
|
44
|
+
blockDefinition['args3'].push({
|
|
45
|
+
type: 'input_dummy'
|
|
46
|
+
});
|
|
47
|
+
blockDefinition['args3'].push({
|
|
48
|
+
type: 'input_statement',
|
|
49
|
+
name: 'pins'
|
|
50
|
+
});
|
|
51
|
+
requiredFields.push('pins');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (methodData['x-events']) {
|
|
55
|
+
for (const event of methodData['x-events']){
|
|
56
|
+
if (event.required === false || !event.required) {
|
|
57
|
+
mutatorToolbox.push('__EVENT__/' + event.name);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
for(let i = 0; i < requiredParamInputs.length; i++){
|
|
62
|
+
var _requiredParamInputs_i_schema, _requiredParamInputs_i_schema1, _requiredParamInputs_i_schema_items_$ref, _requiredParamInputs_i_schema2;
|
|
63
|
+
const position = blockDefinition['args1'].length;
|
|
64
|
+
blockDefinition['args1'].push({
|
|
65
|
+
type: 'field_label',
|
|
66
|
+
name: `NAME_INPUT`,
|
|
67
|
+
text: (requiredParamInputs[i].summary || requiredParamInputs[i].name) + '*'
|
|
68
|
+
});
|
|
69
|
+
if (((_requiredParamInputs_i_schema = requiredParamInputs[i].schema) == null ? void 0 : _requiredParamInputs_i_schema.type) === 'array' && (((_requiredParamInputs_i_schema1 = requiredParamInputs[i].schema) == null ? void 0 : _requiredParamInputs_i_schema1.items.$ref) === 'https://www.pinser.world/schemas/pinsSettings' || ((_requiredParamInputs_i_schema2 = requiredParamInputs[i].schema) == null ? void 0 : (_requiredParamInputs_i_schema_items_$ref = _requiredParamInputs_i_schema2.items.$ref) == null ? void 0 : _requiredParamInputs_i_schema_items_$ref.includes('#/components/schemas/')))) {
|
|
70
|
+
blockDefinition['message1'] += ' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
|
|
71
|
+
blockDefinition['args1'].push({
|
|
72
|
+
type: 'input_dummy'
|
|
73
|
+
});
|
|
74
|
+
blockDefinition['args1'].push({
|
|
75
|
+
type: 'input_statement',
|
|
76
|
+
name: requiredParamInputs[i].name
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
blockDefinition['message1'] += ' %' + (position + 1) + ' %' + (position + 2);
|
|
80
|
+
blockDefinition['args1'].push({
|
|
81
|
+
type: 'input_value',
|
|
82
|
+
name: requiredParamInputs[i].name
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for(let i = 0; i < requiredEventInputs.length; i++){
|
|
87
|
+
const position = blockDefinition['args2'].length;
|
|
88
|
+
blockDefinition['args2'].push({
|
|
89
|
+
type: 'field_label',
|
|
90
|
+
name: `NAME_INPUT`,
|
|
91
|
+
text: '@' + (requiredEventInputs[i].summary || requiredEventInputs[i].name) + '*'
|
|
92
|
+
});
|
|
93
|
+
blockDefinition['message2'] += ' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
|
|
94
|
+
blockDefinition['args2'].push({
|
|
95
|
+
type: 'input_dummy'
|
|
96
|
+
});
|
|
97
|
+
blockDefinition['args2'].push({
|
|
98
|
+
type: 'input_statement',
|
|
99
|
+
name: '__EVENT__/' + requiredEventInputs[i].name
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (mutatorToolbox.length > 0) {
|
|
103
|
+
blockDefinition.mutator = pinsId + '/mutator';
|
|
104
|
+
generateMutator(pinsId + '/mutator', mutatorToolbox, requiredFields, [
|
|
105
|
+
...parameters,
|
|
106
|
+
...metadata,
|
|
107
|
+
...events
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
return blockDefinition;
|
|
111
|
+
}
|
|
112
|
+
function getComponentBlockDefinition(library, componentName, methodData, componentId) {
|
|
113
|
+
const blockDefinition = {
|
|
114
|
+
type: componentId,
|
|
115
|
+
message0: library.info['x-icon'] + ' ' + componentName,
|
|
116
|
+
args0: [],
|
|
117
|
+
message1: '',
|
|
118
|
+
args1: [],
|
|
119
|
+
colour: '#74dc04',
|
|
120
|
+
tooltip: 'library : ' + library.info.title,
|
|
121
|
+
inputsInline: false,
|
|
122
|
+
previousStatement: null,
|
|
123
|
+
nextStatement: null
|
|
124
|
+
};
|
|
125
|
+
const properties = methodData.properties;
|
|
126
|
+
const requiredFields = methodData.required || [];
|
|
127
|
+
requiredFields.push('');
|
|
128
|
+
const mutatorToolbox = [];
|
|
129
|
+
const parameters = Object.keys(properties).map((propertyName)=>({
|
|
130
|
+
name: propertyName,
|
|
131
|
+
schema: properties[propertyName]
|
|
132
|
+
}));
|
|
133
|
+
let messageIndex = 0;
|
|
134
|
+
parameters.forEach((parameter, _index)=>{
|
|
135
|
+
const propertyName = parameter.name;
|
|
136
|
+
if (!requiredFields.includes(propertyName)) {
|
|
137
|
+
mutatorToolbox.push(propertyName);
|
|
138
|
+
} else {
|
|
139
|
+
var _parameter_schema, _parameter_schema1, _parameter_schema2;
|
|
140
|
+
blockDefinition['args1'].push({
|
|
141
|
+
type: 'field_label',
|
|
142
|
+
name: 'NAME_INPUT',
|
|
143
|
+
text: propertyName + '*'
|
|
144
|
+
});
|
|
145
|
+
if (((_parameter_schema = parameter.schema) == null ? void 0 : _parameter_schema.type) === 'array' && (((_parameter_schema1 = parameter.schema) == null ? void 0 : _parameter_schema1.items.$ref) === 'https://www.pinser.world/schemas/pinsSettings' || ((_parameter_schema2 = parameter.schema) == null ? void 0 : _parameter_schema2.items.$ref.includes('#/components/schemas/')))) {
|
|
146
|
+
blockDefinition['message1'] += ' %' + (messageIndex * 2 + 1) + ' %' + (messageIndex * 2 + 2) + ' %' + (messageIndex * 2 + 3);
|
|
147
|
+
blockDefinition['args1'].push({
|
|
148
|
+
type: 'input_dummy'
|
|
149
|
+
});
|
|
150
|
+
blockDefinition['args1'].push({
|
|
151
|
+
type: 'input_statement',
|
|
152
|
+
name: parameter.name
|
|
153
|
+
});
|
|
154
|
+
} else {
|
|
155
|
+
blockDefinition['message1'] += ' %' + (messageIndex * 2 + 1) + ' %' + (messageIndex * 2 + 2);
|
|
156
|
+
blockDefinition['args1'].push({
|
|
157
|
+
type: 'input_value',
|
|
158
|
+
name: parameter.name
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
messageIndex++;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
if (mutatorToolbox.length > 0) {
|
|
165
|
+
blockDefinition.mutator = componentId + '/mutator';
|
|
166
|
+
generateMutator(componentId + '/mutator', mutatorToolbox, requiredFields, parameters);
|
|
167
|
+
}
|
|
168
|
+
return blockDefinition;
|
|
169
|
+
}
|
|
170
|
+
function generateToolboxFromLibraries(libraries) {
|
|
171
|
+
const sortedLibraries = libraries.sort((a, b)=>{
|
|
172
|
+
var _a_info_summary;
|
|
173
|
+
const title1 = (_a_info_summary = a.info.summary) != null ? _a_info_summary : a.info.title;
|
|
174
|
+
var _b_info_summary;
|
|
175
|
+
const title2 = (_b_info_summary = b.info.summary) != null ? _b_info_summary : b.info.title;
|
|
176
|
+
if (title1 < title2) {
|
|
177
|
+
return -1;
|
|
178
|
+
}
|
|
179
|
+
if (title1 > title2) {
|
|
180
|
+
return 1;
|
|
181
|
+
}
|
|
182
|
+
return 0;
|
|
183
|
+
});
|
|
184
|
+
const toolbox = {
|
|
185
|
+
kind: 'categoryToolbox',
|
|
186
|
+
contents: [
|
|
187
|
+
{
|
|
188
|
+
kind: 'category',
|
|
189
|
+
name: '⚙️ Common',
|
|
190
|
+
contents: [
|
|
191
|
+
{
|
|
192
|
+
kind: 'block',
|
|
193
|
+
type: 'object'
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
kind: 'block',
|
|
197
|
+
type: 'member'
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
kind: 'block',
|
|
201
|
+
type: 'math_number'
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
kind: 'block',
|
|
205
|
+
type: 'text_multiline'
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
kind: 'block',
|
|
209
|
+
type: 'logic_boolean'
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
kind: 'block',
|
|
213
|
+
type: 'logic_null'
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
kind: 'block',
|
|
217
|
+
type: 'array'
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
kind: 'block',
|
|
221
|
+
type: 'array-input'
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
},
|
|
225
|
+
...sortedLibraries.map((library)=>{
|
|
226
|
+
var _library_components;
|
|
227
|
+
var _library_info_summary;
|
|
228
|
+
return {
|
|
229
|
+
kind: 'category',
|
|
230
|
+
name: library.info['x-icon'] + ' ' + ((_library_info_summary = library.info.summary) != null ? _library_info_summary : library.info.title),
|
|
231
|
+
contents: [
|
|
232
|
+
...library.paths ? Object.entries(library.paths).sort((a, b)=>a[0].localeCompare(b[0])) // Tri alphabétique par path
|
|
233
|
+
.map(([path, _pins])=>({
|
|
234
|
+
kind: 'block',
|
|
235
|
+
type: library.info.title + '/__PINS__' + path
|
|
236
|
+
})) : [],
|
|
237
|
+
...((_library_components = library.components) == null ? void 0 : _library_components.schemas) ? Object.entries(library.components.schemas).sort((a, b)=>a[0].localeCompare(b[0])) // Tri alphabétique par componentName
|
|
238
|
+
.map(([componentName, _componentSchema])=>({
|
|
239
|
+
kind: 'block',
|
|
240
|
+
type: library.info.title + '/__COMPONENTS__/' + componentName
|
|
241
|
+
})) : []
|
|
242
|
+
]
|
|
243
|
+
};
|
|
244
|
+
})
|
|
245
|
+
]
|
|
246
|
+
};
|
|
247
|
+
return toolbox;
|
|
248
|
+
}
|
|
249
|
+
function generateBlocklyBlockFromLibraries(pinsLibraries, blocksLegacy) {
|
|
250
|
+
const blocksLibrary = [
|
|
251
|
+
...blocksLegacy
|
|
252
|
+
];
|
|
253
|
+
for (const pinsLibrary of pinsLibraries){
|
|
254
|
+
//search for pins blocks
|
|
255
|
+
for(const endpoint in pinsLibrary.paths){
|
|
256
|
+
if (Object.hasOwnProperty.call(pinsLibrary.paths, endpoint)) {
|
|
257
|
+
const endpointData = pinsLibrary.paths[endpoint];
|
|
258
|
+
const methodData = endpointData.post;
|
|
259
|
+
const pinsId = pinsLibrary.info.title + '/__PINS__' + endpoint;
|
|
260
|
+
blocksLibrary.push(getPinsBlockDefinition(pinsLibrary, methodData, pinsId));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
for (const pinsLibrary of pinsLibraries){
|
|
265
|
+
//search for components blocks
|
|
266
|
+
if (!pinsLibrary.components || !pinsLibrary.components.schemas) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
for(const endpoint in pinsLibrary.components.schemas){
|
|
270
|
+
if (Object.hasOwnProperty.call(pinsLibrary.components.schemas, endpoint)) {
|
|
271
|
+
const endpointData = pinsLibrary.components.schemas[endpoint];
|
|
272
|
+
if (!endpointData || !endpointData.properties) {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const componentId = pinsLibrary.info.title + '/__COMPONENTS__/' + endpoint;
|
|
276
|
+
const blockName = endpoint;
|
|
277
|
+
blocksLibrary.push(getComponentBlockDefinition(pinsLibrary, blockName, endpointData, componentId));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
for (const pinsLibrary of pinsLibraries){
|
|
282
|
+
//search for scene blocks
|
|
283
|
+
for(const endpoint in pinsLibrary['x-scene-blocks']){
|
|
284
|
+
if (Object.hasOwnProperty.call(pinsLibrary['x-scene-blocks'], endpoint)) {
|
|
285
|
+
const endpointSceneblock = pinsLibrary['x-scene-blocks'][endpoint];
|
|
286
|
+
const sceneBlockId = pinsLibrary.info.title + '/__SCENEBLOCK__' + endpoint;
|
|
287
|
+
blocksLibrary.push(getSceneBlockDefinition(pinsLibrary, endpointSceneblock, sceneBlockId));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return blocksLibrary;
|
|
292
|
+
}
|
|
293
|
+
function initializeMutator() {
|
|
294
|
+
Blockly.Blocks['mutator_container'] = {
|
|
295
|
+
init: function() {
|
|
296
|
+
this.appendDummyInput().appendField('Inputs');
|
|
297
|
+
this.appendStatementInput('STACK');
|
|
298
|
+
this.setColour(230);
|
|
299
|
+
this.setTooltip('');
|
|
300
|
+
this.workspace.addChangeListener((event)=>{
|
|
301
|
+
if (event.type === Blockly.Events.BLOCK_MOVE) {
|
|
302
|
+
let currentBlock = this.workspace.getBlockById(event.newParentId);
|
|
303
|
+
while(currentBlock){
|
|
304
|
+
if (currentBlock.id === this.id) {
|
|
305
|
+
let firstBlock = this.getInputTargetBlock('STACK');
|
|
306
|
+
const seenTypes = {};
|
|
307
|
+
while(firstBlock){
|
|
308
|
+
if (seenTypes[firstBlock.type]) {
|
|
309
|
+
firstBlock.unplug(true);
|
|
310
|
+
} else {
|
|
311
|
+
seenTypes[firstBlock.type] = true;
|
|
312
|
+
}
|
|
313
|
+
firstBlock = firstBlock.getNextBlock();
|
|
314
|
+
}
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
currentBlock = currentBlock.getSurroundParent();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function generateMutator(mutatorName, toolboxItem, requiredFields, parameters) {
|
|
325
|
+
const toolboxList = [];
|
|
326
|
+
for (const item of toolboxItem){
|
|
327
|
+
Blockly.Blocks[mutatorName + '/' + item] = {
|
|
328
|
+
init: function() {
|
|
329
|
+
this.appendDummyInput(item).appendField(item.includes('__EVENT__/') ? item.replace('__EVENT__/', '@') : item);
|
|
330
|
+
this.setPreviousStatement(true);
|
|
331
|
+
this.setNextStatement(true);
|
|
332
|
+
this.setColour(0);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
toolboxList.push(mutatorName + '/' + item);
|
|
336
|
+
}
|
|
337
|
+
toolboxList.sort((a, b)=>a.localeCompare(b));
|
|
338
|
+
Blockly.Extensions.registerMutator(mutatorName, {
|
|
339
|
+
saveExtraState: function() {
|
|
340
|
+
return {
|
|
341
|
+
itemList: this.itemList_ || []
|
|
342
|
+
};
|
|
343
|
+
},
|
|
344
|
+
loadExtraState: function(state) {
|
|
345
|
+
this.itemList_ = state['itemList'];
|
|
346
|
+
this.updateShape_();
|
|
347
|
+
},
|
|
348
|
+
decompose: function(workspace) {
|
|
349
|
+
const containerBlock = workspace.newBlock('mutator_container');
|
|
350
|
+
containerBlock.initSvg();
|
|
351
|
+
let connection = containerBlock.getInput('STACK').connection;
|
|
352
|
+
for(let i = 0; i < this.inputList.length; i++){
|
|
353
|
+
if (requiredFields.includes(this.inputList[i].name)) {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const inputBlock = workspace.newBlock(mutatorName + '/' + this.inputList[i].name);
|
|
357
|
+
inputBlock.initSvg();
|
|
358
|
+
connection.connect(inputBlock.previousConnection);
|
|
359
|
+
connection = inputBlock.nextConnection;
|
|
360
|
+
}
|
|
361
|
+
return containerBlock;
|
|
362
|
+
},
|
|
363
|
+
compose: function(containerBlock) {
|
|
364
|
+
const inputConnectedArray = [];
|
|
365
|
+
let childBlock = containerBlock.getInputTargetBlock('STACK');
|
|
366
|
+
while(childBlock){
|
|
367
|
+
const inputName = childBlock.inputList[0].name;
|
|
368
|
+
let fieldName = '';
|
|
369
|
+
if (childBlock.inputList[0]) {
|
|
370
|
+
const fieldRow = childBlock.inputList[0].fieldRow;
|
|
371
|
+
if (fieldRow.length > 0) {
|
|
372
|
+
fieldName = fieldRow[0].getText();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
inputConnectedArray.push({
|
|
376
|
+
id: inputName,
|
|
377
|
+
name: fieldName
|
|
378
|
+
});
|
|
379
|
+
childBlock = childBlock.nextConnection && childBlock.nextConnection.targetBlock();
|
|
380
|
+
}
|
|
381
|
+
this.itemList_ = inputConnectedArray;
|
|
382
|
+
this.updateShape_();
|
|
383
|
+
},
|
|
384
|
+
updateShape_: function() {
|
|
385
|
+
const inputToEnable = this.itemList_;
|
|
386
|
+
const inputLoaded = this.inputList.map((input)=>input.name);
|
|
387
|
+
const inputToEnableIds = inputToEnable.map((input)=>input.id);
|
|
388
|
+
for (const input of inputLoaded){
|
|
389
|
+
if (requiredFields.includes(input)) continue;
|
|
390
|
+
if (!inputToEnableIds.includes(input)) {
|
|
391
|
+
this.removeInput(input);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
for (const input of inputToEnable){
|
|
395
|
+
if (requiredFields.includes(input)) {
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (!inputLoaded.includes(input.id)) {
|
|
399
|
+
var _parameter_schema, _parameter_schema1, _parameter_schema_items_$ref, _parameter_schema2;
|
|
400
|
+
const id = input.id.indexOf('/') < 0 ? input.id : input.id.split('/')[1];
|
|
401
|
+
var _parameters_find;
|
|
402
|
+
const parameter = (_parameters_find = parameters.find((param)=>param.name === id)) != null ? _parameters_find : {};
|
|
403
|
+
if (((_parameter_schema = parameter.schema) == null ? void 0 : _parameter_schema.type) === 'array' && (((_parameter_schema1 = parameter.schema) == null ? void 0 : _parameter_schema1.items.$ref) === 'https://www.pinser.world/schemas/pinsSettings' || ((_parameter_schema2 = parameter.schema) == null ? void 0 : (_parameter_schema_items_$ref = _parameter_schema2.items.$ref) == null ? void 0 : _parameter_schema_items_$ref.includes('#/components/schemas/')))) {
|
|
404
|
+
this.appendDummyInput().appendField(input.name);
|
|
405
|
+
this.appendStatementInput(input.id);
|
|
406
|
+
} else {
|
|
407
|
+
this.appendValueInput(input.id).appendField(input.name);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}, null, toolboxList);
|
|
413
|
+
}
|
|
414
|
+
function getSceneBlockDefinition(library, methodData, sceneBlockId) {
|
|
415
|
+
const blockDefinition = {
|
|
416
|
+
type: sceneBlockId,
|
|
417
|
+
message0: library.info['x-icon'] + ' ' + methodData.summary,
|
|
418
|
+
args0: [],
|
|
419
|
+
message1: '',
|
|
420
|
+
args1: [],
|
|
421
|
+
message2: '',
|
|
422
|
+
args2: [],
|
|
423
|
+
message3: '',
|
|
424
|
+
args3: [],
|
|
425
|
+
colour: 230,
|
|
426
|
+
tooltip: 'library : ' + library.info.title
|
|
427
|
+
};
|
|
428
|
+
const metadata = methodData.metadata || [];
|
|
429
|
+
const parameters = methodData.parameters || [];
|
|
430
|
+
if (methodData.tags && methodData.tags.includes('needPins')) {
|
|
431
|
+
const parameter = {
|
|
432
|
+
required: methodData.tags.includes('requirePins'),
|
|
433
|
+
name: 'EXECUTE_PINS',
|
|
434
|
+
summary: 'pins',
|
|
435
|
+
schema: {
|
|
436
|
+
type: 'array',
|
|
437
|
+
items: {
|
|
438
|
+
$ref: 'https://www.pinser.world/schemas/pinsSettings'
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
parameters.push(parameter);
|
|
443
|
+
}
|
|
444
|
+
const requiredParamInputs = parameters.filter((param)=>param.required === true);
|
|
445
|
+
const requiredFields = requiredParamInputs.map((param)=>param.name);
|
|
446
|
+
requiredFields.push('');
|
|
447
|
+
// metadata
|
|
448
|
+
for(let i = 0; i < (metadata == null ? void 0 : metadata.length); i++){
|
|
449
|
+
var _parameter_schema, _parameter_schema_items_$ref;
|
|
450
|
+
var _metadata_find;
|
|
451
|
+
const parameter = (_metadata_find = metadata.find((param)=>param.name === metadata[i].name)) != null ? _metadata_find : {};
|
|
452
|
+
const position = blockDefinition['args1'].length;
|
|
453
|
+
blockDefinition['args1'].push({
|
|
454
|
+
type: 'field_label',
|
|
455
|
+
name: `NAME_INPUT_METADATA`,
|
|
456
|
+
text: (parameter.summary || parameter.name) + '*'
|
|
457
|
+
});
|
|
458
|
+
if (((_parameter_schema = parameter.schema) == null ? void 0 : _parameter_schema.type) === 'array' && (parameter.schema.items.$ref === 'https://www.pinser.world/schemas/pinsSettings' || ((_parameter_schema_items_$ref = parameter.schema.items.$ref) == null ? void 0 : _parameter_schema_items_$ref.includes('#/components/schemas/')))) {
|
|
459
|
+
blockDefinition['message1'] += ' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
|
|
460
|
+
blockDefinition['args1'].push({
|
|
461
|
+
type: 'input_dummy'
|
|
462
|
+
});
|
|
463
|
+
blockDefinition['args1'].push({
|
|
464
|
+
type: 'input_statement',
|
|
465
|
+
name: 'metadata--' + parameter.name
|
|
466
|
+
});
|
|
467
|
+
} else {
|
|
468
|
+
blockDefinition['message1'] += ' %' + (position + 1) + ' %' + (position + 2);
|
|
469
|
+
blockDefinition['args1'].push({
|
|
470
|
+
type: 'input_value',
|
|
471
|
+
name: 'metadata--' + parameter.name
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
// mutator toolbox
|
|
476
|
+
const mutatorToolbox = parameters.map((param)=>param.name).filter((name)=>!requiredFields.includes(name));
|
|
477
|
+
// parameters
|
|
478
|
+
for(let i = 0; i < requiredParamInputs.length; i++){
|
|
479
|
+
var _parameter_schema1, _parameter_schema_items_$ref1;
|
|
480
|
+
var _parameters_find;
|
|
481
|
+
const parameter = (_parameters_find = parameters.find((param)=>param.name === requiredParamInputs[i].name)) != null ? _parameters_find : {};
|
|
482
|
+
const position = blockDefinition['args3'].length;
|
|
483
|
+
blockDefinition['args3'].push({
|
|
484
|
+
type: 'field_label',
|
|
485
|
+
name: `NAME_INPUT`,
|
|
486
|
+
text: (parameter.summary || parameter.name) + '*'
|
|
487
|
+
});
|
|
488
|
+
if (((_parameter_schema1 = parameter.schema) == null ? void 0 : _parameter_schema1.type) === 'array' && (parameter.schema.items.$ref === 'https://www.pinser.world/schemas/pinsSettings' || ((_parameter_schema_items_$ref1 = parameter.schema.items.$ref) == null ? void 0 : _parameter_schema_items_$ref1.includes('#/components/schemas/')))) {
|
|
489
|
+
blockDefinition['message3'] += ' %' + (position + 1) + ' %' + (position + 2) + ' %' + (position + 3);
|
|
490
|
+
blockDefinition['args3'].push({
|
|
491
|
+
type: 'input_dummy'
|
|
492
|
+
});
|
|
493
|
+
blockDefinition['args3'].push({
|
|
494
|
+
type: 'input_statement',
|
|
495
|
+
name: parameter.name
|
|
496
|
+
});
|
|
497
|
+
} else {
|
|
498
|
+
blockDefinition['message3'] += ' %' + (position + 1) + ' %' + (position + 2);
|
|
499
|
+
blockDefinition['args3'].push({
|
|
500
|
+
type: 'input_value',
|
|
501
|
+
name: parameter.name
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (mutatorToolbox.length > 0) {
|
|
506
|
+
blockDefinition.mutator = sceneBlockId + '/mutator';
|
|
507
|
+
generateMutator(sceneBlockId + '/mutator', mutatorToolbox, requiredFields, [
|
|
508
|
+
...parameters,
|
|
509
|
+
...metadata || []
|
|
510
|
+
]);
|
|
511
|
+
}
|
|
512
|
+
return blockDefinition;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export { generateBlocklyBlockFromLibraries, generateToolboxFromLibraries, initializeMutator };
|
package/schema.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.0.0",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "@digipair/skill-web-editor",
|
|
5
|
+
"description": "Edition de raisonnements IA.",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"x-icon": "🚀"
|
|
8
|
+
},
|
|
9
|
+
"paths": {
|
|
10
|
+
"/digipair-editor": {
|
|
11
|
+
"post": {
|
|
12
|
+
"tags": [],
|
|
13
|
+
"summary": "Editeur de raisonnements",
|
|
14
|
+
"description": "Editeur no-code de raisonnements IA",
|
|
15
|
+
"parameters": [
|
|
16
|
+
{
|
|
17
|
+
"name": "digipair",
|
|
18
|
+
"summary": "Digipair",
|
|
19
|
+
"required": true,
|
|
20
|
+
"description": "Propriétaire du raisonnement",
|
|
21
|
+
"schema": {
|
|
22
|
+
"type": "string"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "reasoning",
|
|
27
|
+
"summary": "Raisonnement",
|
|
28
|
+
"required": true,
|
|
29
|
+
"description": "Nom du raisonnement",
|
|
30
|
+
"schema": {
|
|
31
|
+
"type": "string"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"x-events": [
|
|
36
|
+
{
|
|
37
|
+
"name": "save",
|
|
38
|
+
"summary": "Lors de la sauvegarde",
|
|
39
|
+
"required": false,
|
|
40
|
+
"description": "Action déclenchée lors de la sauvegarde du raisonnement",
|
|
41
|
+
"schema": {
|
|
42
|
+
"type": "array",
|
|
43
|
+
"items": {
|
|
44
|
+
"$ref": "https://www.pinser.world/schemas/pinsSettings"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"/information": {
|
|
52
|
+
"post": {
|
|
53
|
+
"tags": [],
|
|
54
|
+
"summary": "Affiche des information",
|
|
55
|
+
"description": "Affiche des informations sur l'editeur de raisonnements",
|
|
56
|
+
"parameters": [
|
|
57
|
+
{
|
|
58
|
+
"name": "message",
|
|
59
|
+
"summary": "Message",
|
|
60
|
+
"required": true,
|
|
61
|
+
"description": "Message à afficher",
|
|
62
|
+
"schema": {
|
|
63
|
+
"type": "string"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
"x-events": []
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"/error": {
|
|
71
|
+
"post": {
|
|
72
|
+
"tags": [],
|
|
73
|
+
"summary": "Affiche une erreurs",
|
|
74
|
+
"description": "Affiche une erreur sur l'editeur de raisonnements",
|
|
75
|
+
"parameters": [
|
|
76
|
+
{
|
|
77
|
+
"name": "message",
|
|
78
|
+
"summary": "Message",
|
|
79
|
+
"required": true,
|
|
80
|
+
"description": "Message à afficher",
|
|
81
|
+
"schema": {
|
|
82
|
+
"type": "string"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"x-events": []
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"components": {
|
|
91
|
+
"schemas": {}
|
|
92
|
+
}
|
|
93
|
+
}
|