@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
package/eslint.config.mjs DELETED
@@ -1,22 +0,0 @@
1
- import baseConfig from '../../eslint.config.mjs';
2
-
3
- export default [
4
- ...baseConfig,
5
- {
6
- files: ['**/*.json'],
7
- rules: {
8
- '@nx/dependency-checks': [
9
- 'error',
10
- {
11
- ignoredFiles: [
12
- '{projectRoot}/eslint.config.{js,cjs,mjs}',
13
- '{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}',
14
- ],
15
- },
16
- ],
17
- },
18
- languageOptions: {
19
- parser: await import('jsonc-eslint-parser'),
20
- },
21
- },
22
- ];
package/rollup.config.cjs DELETED
@@ -1,28 +0,0 @@
1
- const { withNx } = require('@nx/rollup/with-nx');
2
-
3
- module.exports = withNx(
4
- {
5
- main: 'libs/skill-web-editor/src/index.ts',
6
- outputPath: 'dist/libs/skill-web-editor',
7
- tsConfig: 'libs/skill-web-editor/tsconfig.lib.json',
8
- compiler: 'swc',
9
- format: ['esm', "cjs"],
10
- assets: [
11
- {
12
- input: 'libs/skill-web-editor/',
13
- glob: 'package.json',
14
- output: '.'
15
- },
16
- {
17
- input: 'libs/skill-web-editor/src/',
18
- glob: '*.json',
19
- output: '.'
20
- }
21
- ]
22
- },
23
- {
24
- // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
25
- // e.g.
26
- // output: { sourcemap: true },
27
- }
28
- );
@@ -1,145 +0,0 @@
1
- export const blocksLegacy = [
2
- {
3
- type: 'object',
4
- message0: '{ %1 %2 }',
5
- args0: [
6
- {
7
- type: 'input_dummy',
8
- },
9
- {
10
- type: 'input_statement',
11
- name: 'MEMBERS',
12
- check: 'MEMBER',
13
- },
14
- ],
15
- output: null,
16
- colour: '#48c6be',
17
- },
18
- {
19
- type: 'array',
20
- message0: '[ %1 %2 ]',
21
- args0: [
22
- {
23
- type: 'input_dummy',
24
- },
25
- {
26
- type: 'input_statement',
27
- name: 'MEMBERS',
28
- check: 'ARRAY_INPUT',
29
- },
30
- ],
31
- output: null,
32
- colour: '#48c6be',
33
- },
34
- {
35
- type: 'member',
36
- message0: '%1 %2 %3',
37
- args0: [
38
- {
39
- type: 'field_input',
40
- name: 'MEMBER_NAME',
41
- text: '',
42
- },
43
- {
44
- type: 'field_label',
45
- name: 'COLON',
46
- text: ':',
47
- },
48
- {
49
- type: 'input_value',
50
- name: 'MEMBER_VALUE',
51
- },
52
- ],
53
- previousStatement: 'MEMBER',
54
- nextStatement: 'MEMBER',
55
- colour: '#35b3ab',
56
- },
57
- {
58
- type: 'array-input',
59
- message0: '%1',
60
- args0: [
61
- {
62
- type: 'input_value',
63
- name: 'MEMBER_VALUE',
64
- },
65
- ],
66
- previousStatement: 'ARRAY_INPUT',
67
- nextStatement: 'ARRAY_INPUT',
68
- colour: '#35b3ab',
69
- },
70
- {
71
- type: 'unknown-pins',
72
- message0: 'unknown-pins',
73
- args0: [],
74
- colour: 0,
75
- inputsInline: false,
76
- previousStatement: null,
77
- nextStatement: null,
78
- },
79
- {
80
- type: 'unknown-format',
81
- message0: 'unknown-format',
82
- args0: [],
83
- output: null,
84
- colour: 0,
85
- },
86
- {
87
- type: 'unknown-component',
88
- message0: 'unknown-component',
89
- args0: [],
90
- output: null,
91
- colour: 0,
92
- },
93
- {
94
- type: 'generic-scene-block',
95
- message0: 'Error - Generic Scene Block',
96
- arg0: [],
97
- message1: 'type = %1',
98
- args1: [
99
- {
100
- type: 'field_input',
101
- name: 'SCENE_TYPE',
102
- text: 'default-type',
103
- },
104
- ],
105
- message2: '%1 %2',
106
- args2: [
107
- {
108
- type: 'field_label_serializable',
109
- name: 'NAME_EXECUTE',
110
- text: 'Execute*',
111
- },
112
- {
113
- type: 'input_statement',
114
- name: 'EXECUTE_PINS',
115
- },
116
- ],
117
- message3: '%1 %2',
118
- args3: [
119
- {
120
- type: 'field_label_serializable',
121
- name: 'NAME_METADATA',
122
- text: 'Metadata',
123
- },
124
- {
125
- type: 'input_value',
126
- name: 'METADATA_INPUT',
127
- },
128
- ],
129
- message4: '%1 %2',
130
- args4: [
131
- {
132
- type: 'field_label_serializable',
133
- name: 'NAME_EVENTS',
134
- text: 'Events',
135
- },
136
- {
137
- type: 'input_value',
138
- name: 'EVENTS_INPUT',
139
- },
140
- ],
141
- colour: 0,
142
- tooltip: '',
143
- helpUrl: '',
144
- },
145
- ];
@@ -1,279 +0,0 @@
1
- import { LitElement, TemplateResult, html } from 'lit';
2
- import { customElement, property } from 'lit/decorators.js';
3
- import { PinsSettings } from '@digipair/engine';
4
- import { blocksLegacy } from './blocks/json';
5
- import { initializeWorkspaceFromPinsAndLibraries } from './generator/json-to-blockly';
6
- import { schemas as schemasWeb } from './schemas/web.schema';
7
- import { schemas as schemasWebFr } from './schemas/web.fr.schema';
8
-
9
- declare const Blockly: any;
10
- let jsonGenerator: any,
11
- generateBlocklyBlockFromLibraries: any,
12
- generateToolboxFromLibraries: any,
13
- initializeMutator: any;
14
-
15
- @customElement('digipair-editor')
16
- export class EditorElement extends LitElement {
17
- @property()
18
- reasoning!: any;
19
-
20
- @property()
21
- schemas: any[] = [];
22
-
23
- @property()
24
- menuColor = 'white';
25
-
26
- @property()
27
- menuBackgroundColor = 'rgb(66, 133, 244)';
28
-
29
- @property()
30
- contentStyle = 'position: fixed; top: 0; right: 0; bottom: 0; left: 0;';
31
-
32
- @property()
33
- language = 'en';
34
-
35
- @property()
36
- canSave = false;
37
-
38
- @property()
39
- codeInWorkspace: any;
40
-
41
- private workspace: any;
42
- private blocks: any;
43
- private toolbox: any;
44
- private librariesToLoad: any;
45
-
46
- override createRenderRoot() {
47
- return this;
48
- }
49
-
50
- override connectedCallback(): void {
51
- super.connectedCallback();
52
- this.initialize();
53
- }
54
-
55
- private async initialize() {
56
- const globalInstance: any = typeof window === 'undefined' ? global : window;
57
- const config = globalInstance.__DIGIPAIR_CONFIG__;
58
- const baseUrl = config.BASE_URL;
59
- const blocklyVersion = '10.4.3';
60
- let script: any, promise: any;
61
-
62
- script = document.createElement('script');
63
- script.src = `${baseUrl}/blockly@${blocklyVersion}/blockly_compressed.js`;
64
- promise = new Promise(resolve => {
65
- script.onload = resolve;
66
- });
67
- document.head.appendChild(script);
68
- await promise;
69
-
70
- script = document.createElement('script');
71
- script.src = `${baseUrl}/blockly@${blocklyVersion}/blocks_compressed.js`;
72
- promise = new Promise(resolve => {
73
- script.onload = resolve;
74
- });
75
- document.head.appendChild(script);
76
- await promise;
77
-
78
- script = document.createElement('script');
79
- script.src = `${baseUrl}/blockly@${blocklyVersion}/msg/${this.language}.js`;
80
- promise = new Promise(resolve => {
81
- script.onload = resolve;
82
- });
83
- document.head.appendChild(script);
84
- await promise;
85
-
86
- const blocklyToJson = await import('./generator/blockly-to-json');
87
- jsonGenerator = blocklyToJson.jsonGenerator;
88
-
89
- const pinsToBlockly = await import('./generator/pins-to-blockly');
90
- generateBlocklyBlockFromLibraries = pinsToBlockly.generateBlocklyBlockFromLibraries;
91
- generateToolboxFromLibraries = pinsToBlockly.generateToolboxFromLibraries;
92
- initializeMutator = pinsToBlockly.initializeMutator;
93
-
94
- setTimeout(() => this.loadScene(this.reasoning), 1);
95
- this.addEventListener('setReasoning' as any, ({ detail }: CustomEvent) =>
96
- this.loadReasoning(detail),
97
- );
98
- }
99
-
100
- private loadReasoning(reasoning: PinsSettings) {
101
- Blockly.Events.disable();
102
- initializeWorkspaceFromPinsAndLibraries(reasoning, this.workspace, this.librariesToLoad);
103
- Blockly.Events.enable();
104
- }
105
-
106
- private async getLibraries(): Promise<any[]> {
107
- const list = [this.language === 'fr' ? schemasWebFr : schemasWeb, ...this.schemas];
108
-
109
- return list;
110
- }
111
-
112
- private async loadScene(reasoning: PinsSettings): Promise<void> {
113
- const scene = reasoning;
114
- this.librariesToLoad = await this.getLibraries();
115
-
116
- this.loadBlockly(scene);
117
- if (!scene) {
118
- return;
119
- }
120
- this.canSave = this.verifyCanSaveAndGetCode();
121
- }
122
-
123
- private verifyCanSaveAndGetCode(): boolean {
124
- const code = jsonGenerator.workspaceToCode(this.workspace);
125
-
126
- try {
127
- this.codeInWorkspace = {
128
- description: this.reasoning.description,
129
- summary: this.reasoning.summary,
130
- ...JSON.parse(code),
131
- };
132
-
133
- return true;
134
- } catch (e) {
135
- return false;
136
- }
137
- }
138
-
139
- private loadBlockly(scene: PinsSettings) {
140
- initializeMutator();
141
- const generatedBlocks = generateBlocklyBlockFromLibraries(this.librariesToLoad, blocksLegacy);
142
- this.blocks = Blockly.common.createBlockDefinitionsFromJsonArray(generatedBlocks);
143
-
144
- const tags =
145
- this.librariesToLoad.find((library: any) => library.info.title === scene.library)?.[
146
- 'x-scene-blocks'
147
- ]?.[`/${scene.element}`]?.tags || [];
148
- this.toolbox = generateToolboxFromLibraries(this.librariesToLoad, tags);
149
- Blockly.common.defineBlocks(this.blocks);
150
- const container = this.renderRoot.querySelector('[data-scene]');
151
-
152
- this.workspace = Blockly.inject(
153
- container as any,
154
- {
155
- toolbox: this.toolbox,
156
- scrollbars: true,
157
- infiniteBlocks: true,
158
- trashcan: false,
159
- move: {
160
- scrollbars: true,
161
- drag: true,
162
- wheel: true,
163
- },
164
- theme: Blockly.Theme.defineTheme('modest', {
165
- blockStyles: {
166
- logic_blocks: {
167
- colourPrimary: '#D1C4E9',
168
- colourSecondary: '#EDE7F6',
169
- colorTertiary: '#B39DDB',
170
- },
171
- loop_blocks: {
172
- colourPrimary: '#A5D6A7',
173
- colourSecondary: '#E8F5E9',
174
- colorTertiary: '#66BB6A',
175
- },
176
- math_blocks: {
177
- colourPrimary: '#2196F3',
178
- colourSecondary: '#1E88E5',
179
- colorTertiary: '#0D47A1',
180
- },
181
- text_blocks: {
182
- colourPrimary: '#FFCA28',
183
- colourSecondary: '#FFF8E1',
184
- colorTertiary: '#FF8F00',
185
- },
186
- list_blocks: {
187
- colourPrimary: '#4DB6AC',
188
- colourSecondary: '#B2DFDB',
189
- colorTertiary: '#009688',
190
- },
191
- variable_blocks: {
192
- colourPrimary: '#EF9A9A',
193
- colourSecondary: '#FFEBEE',
194
- colorTertiary: '#EF5350',
195
- },
196
- variable_dynamic_blocks: {
197
- colourPrimary: '#EF9A9A',
198
- colourSecondary: '#FFEBEE',
199
- colorTertiary: '#EF5350',
200
- },
201
- procedure_blocks: {
202
- colourPrimary: '#D7CCC8',
203
- colourSecondary: '#EFEBE9',
204
- colorTertiary: '#BCAAA4',
205
- },
206
- },
207
- }),
208
- } as any,
209
- );
210
-
211
- this.workspace.addChangeListener((e: any) => {
212
- if (e.isUiEvent || e.type == Blockly.Events.FINISHED_LOADING) {
213
- return;
214
- }
215
- if (this.workspace.isDragging()) {
216
- return;
217
- }
218
- this.canSave = this.verifyCanSaveAndGetCode();
219
- });
220
-
221
- Blockly.Events.disable();
222
- initializeWorkspaceFromPinsAndLibraries(scene, this.workspace, this.librariesToLoad);
223
- Blockly.Events.enable();
224
- }
225
-
226
- override render(): TemplateResult {
227
- return html`
228
- <style>
229
- @import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
230
-
231
- .blocklyToolboxDiv {
232
- background-color: ${this.menuBackgroundColor};
233
- color: ${this.menuColor};
234
- width: 370px;
235
- }
236
-
237
- .header {
238
- position: unset !important;
239
- }
240
-
241
- .menu-item > a::after {
242
- content: '> ';
243
- margin-left: 30px;
244
- }
245
-
246
- .header__logo {
247
- margin-left: 80px;
248
- }
249
-
250
- .header .main-nav {
251
- position: unset;
252
- margin-top: 50px;
253
- margin-left: 60px;
254
- }
255
-
256
- .header .container {
257
- margin: 0;
258
- }
259
-
260
- .blocklyTreeRow {
261
- height: 30px;
262
- line-height: 30px;
263
- }
264
-
265
- .blocklyPath {
266
- stroke: #fff;
267
- }
268
-
269
- .blocklyPathDark {
270
- fill: #fff;
271
- }
272
- </style>
273
-
274
- <div>
275
- <div style=${this.contentStyle} data-scene></div>
276
- </div>
277
- `;
278
- }
279
- }