@digipair/skill-web-editor 0.4.10 → 0.4.12

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/index.esm2.js CHANGED
@@ -2650,11 +2650,8 @@ function generateBlockFromPins(pinsSettings, workspace) {
2650
2650
  connectBlock(pinsBlock, pinsConnection);
2651
2651
  }
2652
2652
  }
2653
- if (!pinsSettings || !pinsSettings.properties) {
2654
- return pinsBlock;
2655
- }
2656
2653
  for (const parameter of pinsDefinition.parameters){
2657
- if (!Object.prototype.hasOwnProperty.call(pinsSettings.properties, parameter.name)) {
2654
+ if (!pinsSettings.properties || !Object.prototype.hasOwnProperty.call(pinsSettings.properties, parameter.name)) {
2658
2655
  continue;
2659
2656
  }
2660
2657
  const valueToLoad = pinsSettings.properties[parameter.name];
@@ -2662,16 +2659,16 @@ function generateBlockFromPins(pinsSettings, workspace) {
2662
2659
  const parameterType = getParameterType(parameter.schema.items);
2663
2660
  for (const propertyValue of valueToLoad.reverse()){
2664
2661
  const parameterBlock = parameterType === 'component' ? generateBlockFromComponent(propertyValue, workspace, library, parameter.schema.items.$ref) : generateBlockFromPins(propertyValue, workspace);
2665
- const sceneInputConnection = pinsBlock.getInput(parameter.name).connection;
2666
- connectBlock(parameterBlock, sceneInputConnection);
2662
+ const inputConnection = pinsBlock.getInput(parameter.name).connection;
2663
+ connectBlock(parameterBlock, inputConnection);
2667
2664
  }
2668
2665
  } else {
2669
2666
  const parameterBlock = generateParameterBlock(parameter.schema, valueToLoad, workspace, library);
2670
- const sceneInputConnection = pinsBlock.getInput(parameter.name).connection;
2671
- connectBlock(parameterBlock, sceneInputConnection);
2667
+ const inputConnection = pinsBlock.getInput(parameter.name).connection;
2668
+ connectBlock(parameterBlock, inputConnection);
2672
2669
  }
2673
2670
  }
2674
- for (const event of pinsDefinition['x-events']){
2671
+ for (const event of pinsDefinition['x-events'] || []){
2675
2672
  if (!pinsSettings.events || !Object.prototype.hasOwnProperty.call(pinsSettings.events, event.name)) {
2676
2673
  continue;
2677
2674
  }
@@ -2682,6 +2679,42 @@ function generateBlockFromPins(pinsSettings, workspace) {
2682
2679
  connectBlock(parameterBlock, inputConnection);
2683
2680
  }
2684
2681
  }
2682
+ const conditions = [
2683
+ {
2684
+ name: 'if',
2685
+ schema: {
2686
+ type: 'boolean'
2687
+ }
2688
+ },
2689
+ {
2690
+ name: 'each',
2691
+ schema: {
2692
+ type: 'array',
2693
+ items: {
2694
+ type: 'object'
2695
+ }
2696
+ }
2697
+ }
2698
+ ];
2699
+ for (const parameter of conditions){
2700
+ var _parameter_schema_items;
2701
+ if (!pinsSettings.conditions || !Object.prototype.hasOwnProperty.call(pinsSettings.conditions, parameter.name)) {
2702
+ continue;
2703
+ }
2704
+ const valueToLoad = pinsSettings.conditions[parameter.name];
2705
+ if (parameter.schema.type === 'array' && ((_parameter_schema_items = parameter.schema.items) == null ? void 0 : _parameter_schema_items.$ref)) {
2706
+ const parameterType = getParameterType(parameter.schema.items);
2707
+ for (const propertyValue of valueToLoad.reverse()){
2708
+ const parameterBlock = parameterType === 'component' ? generateBlockFromComponent(propertyValue, workspace, library, parameter.schema.items.$ref) : generateBlockFromPins(propertyValue, workspace);
2709
+ const inputConnection = pinsBlock.getInput('__CONDITION__/' + parameter.name).connection;
2710
+ connectBlock(parameterBlock, inputConnection);
2711
+ }
2712
+ } else {
2713
+ const parameterBlock = generateParameterBlock(parameter.schema, valueToLoad, workspace, library);
2714
+ const inputConnection = pinsBlock.getInput('__CONDITION__/' + parameter.name).connection;
2715
+ connectBlock(parameterBlock, inputConnection);
2716
+ }
2717
+ }
2685
2718
  return pinsBlock;
2686
2719
  }
2687
2720
  function generateBlockFromComponent(componentSettings, workspace, library, component$ref) {
@@ -2918,6 +2951,20 @@ function itemListFromPinsSettings(pinsSettings, pinsDefinition) {
2918
2951
  });
2919
2952
  }
2920
2953
  }
2954
+ if (pinsSettings.conditions) {
2955
+ if (pinsSettings.conditions.if) {
2956
+ inputArray.push({
2957
+ id: '__CONDITION__/if',
2958
+ name: '#if'
2959
+ });
2960
+ }
2961
+ if (pinsSettings.conditions.each) {
2962
+ inputArray.push({
2963
+ id: '__CONDITION__/each',
2964
+ name: '#each'
2965
+ });
2966
+ }
2967
+ }
2921
2968
  return inputArray;
2922
2969
  }
2923
2970
  function itemListFromComponentSettings(componentSettings, componentDefinition) {
@@ -2949,6 +2996,321 @@ function itemListFromSceneSettings(sceneSettings, sceneDefinition) {
2949
2996
  return inputArray;
2950
2997
  }
2951
2998
 
2999
+ const schemas = {
3000
+ openapi: '3.0.0',
3001
+ info: {
3002
+ title: 'web',
3003
+ summary: 'Web: bases',
3004
+ description: 'description de la librairie de pins web',
3005
+ version: '1.0.11',
3006
+ 'x-icon': '🌐'
3007
+ },
3008
+ paths: {
3009
+ '/section': {
3010
+ post: {
3011
+ tags: [
3012
+ 'needPins',
3013
+ 'web'
3014
+ ],
3015
+ summary: 'Section',
3016
+ parameters: [
3017
+ {
3018
+ name: 'class',
3019
+ in: 'query',
3020
+ description: '',
3021
+ schema: {
3022
+ type: 'string'
3023
+ }
3024
+ },
3025
+ {
3026
+ name: 'textContent',
3027
+ in: 'query',
3028
+ description: '',
3029
+ schema: {
3030
+ type: 'string'
3031
+ }
3032
+ }
3033
+ ]
3034
+ }
3035
+ },
3036
+ '/h1': {
3037
+ post: {
3038
+ tags: [
3039
+ 'web'
3040
+ ],
3041
+ summary: 'h1',
3042
+ parameters: [
3043
+ {
3044
+ name: 'textContent',
3045
+ in: 'query',
3046
+ description: '',
3047
+ schema: {
3048
+ type: 'string'
3049
+ }
3050
+ }
3051
+ ]
3052
+ }
3053
+ },
3054
+ '/nav': {
3055
+ post: {
3056
+ tags: [
3057
+ 'needPins',
3058
+ 'web'
3059
+ ],
3060
+ summary: 'nav',
3061
+ parameters: [
3062
+ {
3063
+ name: 'class',
3064
+ in: 'query',
3065
+ description: '',
3066
+ schema: {
3067
+ type: 'string'
3068
+ }
3069
+ }
3070
+ ]
3071
+ }
3072
+ },
3073
+ '/a': {
3074
+ post: {
3075
+ tags: [
3076
+ 'needPins',
3077
+ 'web'
3078
+ ],
3079
+ summary: 'a',
3080
+ parameters: [
3081
+ {
3082
+ name: 'class',
3083
+ in: 'query',
3084
+ description: '',
3085
+ schema: {
3086
+ type: 'string'
3087
+ }
3088
+ },
3089
+ {
3090
+ name: 'href',
3091
+ in: 'query',
3092
+ description: '',
3093
+ schema: {
3094
+ type: 'string'
3095
+ }
3096
+ },
3097
+ {
3098
+ name: 'textContent',
3099
+ in: 'query',
3100
+ description: '',
3101
+ schema: {
3102
+ type: 'string'
3103
+ }
3104
+ },
3105
+ {
3106
+ name: 'id',
3107
+ in: 'query',
3108
+ description: '',
3109
+ schema: {
3110
+ type: 'string'
3111
+ }
3112
+ },
3113
+ {
3114
+ name: 'role',
3115
+ in: 'query',
3116
+ description: '',
3117
+ schema: {
3118
+ type: 'string'
3119
+ }
3120
+ },
3121
+ {
3122
+ name: 'data-toggle',
3123
+ in: 'query',
3124
+ description: '',
3125
+ schema: {
3126
+ type: 'string'
3127
+ }
3128
+ },
3129
+ {
3130
+ name: 'aria-haspopup',
3131
+ in: 'query',
3132
+ description: '',
3133
+ schema: {
3134
+ type: 'string'
3135
+ }
3136
+ },
3137
+ {
3138
+ name: 'aria-expanded',
3139
+ in: 'query',
3140
+ description: '',
3141
+ schema: {
3142
+ type: 'string'
3143
+ }
3144
+ }
3145
+ ]
3146
+ }
3147
+ },
3148
+ '/button': {
3149
+ post: {
3150
+ tags: [
3151
+ 'needPins',
3152
+ 'web'
3153
+ ],
3154
+ summary: 'button',
3155
+ parameters: [
3156
+ {
3157
+ name: 'class',
3158
+ in: 'query',
3159
+ description: '',
3160
+ schema: {
3161
+ type: 'string'
3162
+ }
3163
+ },
3164
+ {
3165
+ name: 'type',
3166
+ in: 'query',
3167
+ description: '',
3168
+ schema: {
3169
+ type: 'string'
3170
+ }
3171
+ },
3172
+ {
3173
+ name: 'data-toggle',
3174
+ in: 'query',
3175
+ description: '',
3176
+ schema: {
3177
+ type: 'string'
3178
+ }
3179
+ },
3180
+ {
3181
+ name: 'data-target',
3182
+ in: 'query',
3183
+ description: '',
3184
+ schema: {
3185
+ type: 'string'
3186
+ }
3187
+ },
3188
+ {
3189
+ name: 'aria-controls',
3190
+ in: 'query',
3191
+ description: '',
3192
+ schema: {
3193
+ type: 'string'
3194
+ }
3195
+ },
3196
+ {
3197
+ name: 'aria-expanded',
3198
+ in: 'query',
3199
+ description: '',
3200
+ schema: {
3201
+ type: 'string'
3202
+ }
3203
+ },
3204
+ {
3205
+ name: 'aria-label',
3206
+ in: 'query',
3207
+ description: '',
3208
+ schema: {
3209
+ type: 'string'
3210
+ }
3211
+ }
3212
+ ]
3213
+ }
3214
+ },
3215
+ '/span': {
3216
+ post: {
3217
+ tags: [
3218
+ 'needPins',
3219
+ 'web'
3220
+ ],
3221
+ summary: 'span',
3222
+ parameters: [
3223
+ {
3224
+ name: 'class',
3225
+ in: 'query',
3226
+ description: '',
3227
+ schema: {
3228
+ type: 'string'
3229
+ }
3230
+ }
3231
+ ]
3232
+ }
3233
+ },
3234
+ '/div': {
3235
+ post: {
3236
+ tags: [
3237
+ 'needPins',
3238
+ 'web'
3239
+ ],
3240
+ summary: 'div',
3241
+ parameters: [
3242
+ {
3243
+ name: 'class',
3244
+ in: 'query',
3245
+ description: '',
3246
+ schema: {
3247
+ type: 'string'
3248
+ }
3249
+ },
3250
+ {
3251
+ name: 'id',
3252
+ in: 'query',
3253
+ description: '',
3254
+ schema: {
3255
+ type: 'string'
3256
+ }
3257
+ },
3258
+ {
3259
+ name: 'aria-labelledby',
3260
+ in: 'query',
3261
+ description: '',
3262
+ schema: {
3263
+ type: 'string'
3264
+ }
3265
+ }
3266
+ ]
3267
+ }
3268
+ },
3269
+ '/ul': {
3270
+ post: {
3271
+ tags: [
3272
+ 'needPins',
3273
+ 'web'
3274
+ ],
3275
+ summary: 'ul',
3276
+ parameters: [
3277
+ {
3278
+ name: 'class',
3279
+ in: 'query',
3280
+ description: '',
3281
+ schema: {
3282
+ type: 'string'
3283
+ }
3284
+ }
3285
+ ]
3286
+ }
3287
+ },
3288
+ '/li': {
3289
+ post: {
3290
+ tags: [
3291
+ 'needPins',
3292
+ 'web'
3293
+ ],
3294
+ summary: 'li',
3295
+ parameters: [
3296
+ {
3297
+ name: 'class',
3298
+ in: 'query',
3299
+ description: '',
3300
+ schema: {
3301
+ type: 'string'
3302
+ }
3303
+ }
3304
+ ]
3305
+ }
3306
+ }
3307
+ },
3308
+ components: {
3309
+ schemas: {}
3310
+ },
3311
+ 'x-scene-blocks': {}
3312
+ };
3313
+
2952
3314
  const Toastify$1 = toastify;
2953
3315
  const BASE_URL = 'https://cdn.jsdelivr.net/npm';
2954
3316
  const BLOCKLY_VERSION = '10.4.3';
@@ -2998,32 +3360,9 @@ class GenericSceneElement extends s {
2998
3360
  setTimeout(()=>this.loadScene(this.digipair, this.reasoning), 1);
2999
3361
  this.addEventListener('setReasoning', ({ detail })=>this.loadReasoning(detail));
3000
3362
  }
3001
- loadReasoning(detail) {
3002
- const scene = _extends({}, detail, {
3003
- properties: _extends({}, (detail.properties.trigger || []).reduce((acc, { name, value })=>_extends({}, acc, {
3004
- [name]: value
3005
- }), {}), {
3006
- actions: detail.properties.actions.map((action)=>{
3007
- var _action_properties;
3008
- return _extends({}, action, {
3009
- properties: (_action_properties = action.properties) == null ? void 0 : _action_properties.reduce((acc, { name, value })=>_extends({}, acc, {
3010
- [name]: value
3011
- }), {})
3012
- });
3013
- }),
3014
- conditions: detail.properties.conditions.map((action)=>{
3015
- var _action_properties;
3016
- return _extends({}, action, {
3017
- properties: (_action_properties = action.properties) == null ? void 0 : _action_properties.reduce((acc, { name, value })=>_extends({}, acc, {
3018
- [name]: value
3019
- }), {})
3020
- });
3021
- }),
3022
- pins: []
3023
- })
3024
- });
3363
+ loadReasoning(reasoning) {
3025
3364
  Blockly.Events.disable();
3026
- initializeWorkspaceFromPinsAndLibraries(scene, this.workspace, this.librariesToLoad);
3365
+ initializeWorkspaceFromPinsAndLibraries(reasoning, this.workspace, this.librariesToLoad);
3027
3366
  Blockly.Events.enable();
3028
3367
  }
3029
3368
  async getReasoning(digipair, reasoning) {
@@ -3041,7 +3380,10 @@ class GenericSceneElement extends s {
3041
3380
  return content;
3042
3381
  }
3043
3382
  async getLibraries(libraries) {
3044
- const list = await Promise.all(Object.keys(libraries).map(async (library, i)=>fetch(`${BASE_URL}/${library}@${libraries[library]}/schema.json`).then((res)=>res.json())));
3383
+ const list = [
3384
+ schemas,
3385
+ ...await Promise.all(Object.keys(libraries).map(async (library, i)=>fetch(`${BASE_URL}/${library}@${libraries[library]}/schema.json`).then((res)=>res.json())))
3386
+ ];
3045
3387
  return list;
3046
3388
  }
3047
3389
  async loadScene(digipair, reasoning) {
@@ -3089,10 +3431,12 @@ class GenericSceneElement extends s {
3089
3431
  }
3090
3432
  }
3091
3433
  loadBlockly(scene) {
3434
+ var _this_librariesToLoad_find_xsceneblocks_, _this_librariesToLoad_find_xsceneblocks, _this_librariesToLoad_find;
3092
3435
  initializeMutator();
3093
3436
  const generatedBlocks = generateBlocklyBlockFromLibraries(this.librariesToLoad, blocksLegacy);
3094
3437
  this.blocks = Blockly.common.createBlockDefinitionsFromJsonArray(generatedBlocks);
3095
- this.toolbox = generateToolboxFromLibraries(this.librariesToLoad);
3438
+ const tags = ((_this_librariesToLoad_find = this.librariesToLoad.find((library)=>library.info.title === scene.library)) == null ? void 0 : (_this_librariesToLoad_find_xsceneblocks = _this_librariesToLoad_find['x-scene-blocks']) == null ? void 0 : (_this_librariesToLoad_find_xsceneblocks_ = _this_librariesToLoad_find_xsceneblocks[`/${scene.element}`]) == null ? void 0 : _this_librariesToLoad_find_xsceneblocks_.tags) || [];
3439
+ this.toolbox = generateToolboxFromLibraries(this.librariesToLoad, tags);
3096
3440
  Blockly.common.defineBlocks(this.blocks);
3097
3441
  const container = this.renderRoot.querySelector('[data-scene]');
3098
3442
  this.workspace = Blockly.inject(container, {
@@ -3104,7 +3448,51 @@ class GenericSceneElement extends s {
3104
3448
  scrollbars: true,
3105
3449
  drag: true,
3106
3450
  wheel: true
3107
- }
3451
+ },
3452
+ theme: Blockly.Theme.defineTheme('modest', {
3453
+ blockStyles: {
3454
+ logic_blocks: {
3455
+ colourPrimary: '#D1C4E9',
3456
+ colourSecondary: '#EDE7F6',
3457
+ colorTertiary: '#B39DDB'
3458
+ },
3459
+ loop_blocks: {
3460
+ colourPrimary: '#A5D6A7',
3461
+ colourSecondary: '#E8F5E9',
3462
+ colorTertiary: '#66BB6A'
3463
+ },
3464
+ math_blocks: {
3465
+ colourPrimary: '#2196F3',
3466
+ colourSecondary: '#1E88E5',
3467
+ colorTertiary: '#0D47A1'
3468
+ },
3469
+ text_blocks: {
3470
+ colourPrimary: '#FFCA28',
3471
+ colourSecondary: '#FFF8E1',
3472
+ colorTertiary: '#FF8F00'
3473
+ },
3474
+ list_blocks: {
3475
+ colourPrimary: '#4DB6AC',
3476
+ colourSecondary: '#B2DFDB',
3477
+ colorTertiary: '#009688'
3478
+ },
3479
+ variable_blocks: {
3480
+ colourPrimary: '#EF9A9A',
3481
+ colourSecondary: '#FFEBEE',
3482
+ colorTertiary: '#EF5350'
3483
+ },
3484
+ variable_dynamic_blocks: {
3485
+ colourPrimary: '#EF9A9A',
3486
+ colourSecondary: '#FFEBEE',
3487
+ colorTertiary: '#EF5350'
3488
+ },
3489
+ procedure_blocks: {
3490
+ colourPrimary: '#D7CCC8',
3491
+ colourSecondary: '#EFEBE9',
3492
+ colorTertiary: '#BCAAA4'
3493
+ }
3494
+ }
3495
+ })
3108
3496
  });
3109
3497
  this.workspace.addChangeListener((e)=>{
3110
3498
  if (e.isUiEvent || e.type == Blockly.Events.FINISHED_LOADING) {
@@ -3155,6 +3543,14 @@ class GenericSceneElement extends s {
3155
3543
  height: 30px;
3156
3544
  line-height: 30px;
3157
3545
  }
3546
+
3547
+ .blocklyPath {
3548
+ stroke: #fff;
3549
+ }
3550
+
3551
+ .blocklyPathDark {
3552
+ fill: #fff;
3553
+ }
3158
3554
  </style>
3159
3555
 
3160
3556
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
@@ -1,4 +1,4 @@
1
- export declare function generateToolboxFromLibraries(libraries: any[]): {
1
+ export declare function generateToolboxFromLibraries(libraries: any[], tags: string[]): {
2
2
  kind: string;
3
3
  contents: {
4
4
  kind: string;
@@ -0,0 +1,142 @@
1
+ export declare const schemas: {
2
+ openapi: string;
3
+ info: {
4
+ title: string;
5
+ summary: string;
6
+ description: string;
7
+ version: string;
8
+ 'x-icon': string;
9
+ };
10
+ paths: {
11
+ '/section': {
12
+ post: {
13
+ tags: string[];
14
+ summary: string;
15
+ parameters: {
16
+ name: string;
17
+ in: string;
18
+ description: string;
19
+ schema: {
20
+ type: string;
21
+ };
22
+ }[];
23
+ };
24
+ };
25
+ '/h1': {
26
+ post: {
27
+ tags: string[];
28
+ summary: string;
29
+ parameters: {
30
+ name: string;
31
+ in: string;
32
+ description: string;
33
+ schema: {
34
+ type: string;
35
+ };
36
+ }[];
37
+ };
38
+ };
39
+ '/nav': {
40
+ post: {
41
+ tags: string[];
42
+ summary: string;
43
+ parameters: {
44
+ name: string;
45
+ in: string;
46
+ description: string;
47
+ schema: {
48
+ type: string;
49
+ };
50
+ }[];
51
+ };
52
+ };
53
+ '/a': {
54
+ post: {
55
+ tags: string[];
56
+ summary: string;
57
+ parameters: {
58
+ name: string;
59
+ in: string;
60
+ description: string;
61
+ schema: {
62
+ type: string;
63
+ };
64
+ }[];
65
+ };
66
+ };
67
+ '/button': {
68
+ post: {
69
+ tags: string[];
70
+ summary: string;
71
+ parameters: {
72
+ name: string;
73
+ in: string;
74
+ description: string;
75
+ schema: {
76
+ type: string;
77
+ };
78
+ }[];
79
+ };
80
+ };
81
+ '/span': {
82
+ post: {
83
+ tags: string[];
84
+ summary: string;
85
+ parameters: {
86
+ name: string;
87
+ in: string;
88
+ description: string;
89
+ schema: {
90
+ type: string;
91
+ };
92
+ }[];
93
+ };
94
+ };
95
+ '/div': {
96
+ post: {
97
+ tags: string[];
98
+ summary: string;
99
+ parameters: {
100
+ name: string;
101
+ in: string;
102
+ description: string;
103
+ schema: {
104
+ type: string;
105
+ };
106
+ }[];
107
+ };
108
+ };
109
+ '/ul': {
110
+ post: {
111
+ tags: string[];
112
+ summary: string;
113
+ parameters: {
114
+ name: string;
115
+ in: string;
116
+ description: string;
117
+ schema: {
118
+ type: string;
119
+ };
120
+ }[];
121
+ };
122
+ };
123
+ '/li': {
124
+ post: {
125
+ tags: string[];
126
+ summary: string;
127
+ parameters: {
128
+ name: string;
129
+ in: string;
130
+ description: string;
131
+ schema: {
132
+ type: string;
133
+ };
134
+ }[];
135
+ };
136
+ };
137
+ };
138
+ components: {
139
+ schemas: {};
140
+ };
141
+ 'x-scene-blocks': {};
142
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digipair/skill-web-editor",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "dependencies": {},
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js"