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