|
2 | 2 | <html> |
3 | 3 |
|
4 | 4 | <head> |
5 | | - <meta charset="utf-8"> |
6 | | - <title></title> |
7 | | - <meta name="author" content=""> |
8 | | - <meta name="description" content=""> |
9 | | - <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 5 | + <meta charset="utf-8"> |
| 6 | + <title></title> |
| 7 | + <meta name="author" content=""> |
| 8 | + <meta name="description" content=""> |
| 9 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
10 | 10 | </head> |
11 | 11 |
|
12 | 12 | <body> |
13 | 13 |
|
14 | | - <p>Demonstrating monaco editor esm with i18n, cobalt theme and added types (node-red & nodejs) </p> |
15 | | - <p>Monaco lang should be french (right click inside the editor) </p> |
| 14 | + <h2>Demonstrating monaco editor esm with i18n</h2> |
| 15 | + <h3>Things to check...</h3> |
| 16 | + <ul> |
| 17 | + <li>Theme should be set to <code>forge</code></li> |
| 18 | + <li>Intellisense for node globals, node-red utility functions should be present</li> |
| 19 | + <li>Monaco lang should be spanish (right click inside the editor, check palette menu <kbd>F1</kbd> or <kbd>CTRL-SHIFT-P</kbd>) </li> |
| 20 | + </ul> |
16 | 21 |
|
17 | | - <div id="monaco-editor" style="height: 500px;">MONACO</div> |
| 22 | + <div id="monaco-editor" style="height: 500px;">MONACO</div> |
18 | 23 |
|
19 | | - <script src="./output/monaco/dist/locale/fr.js"></script> |
20 | | - <script src="./output/monaco/dist/editor.js" ></script> |
| 24 | + <script src="./output/monaco/dist/locale/es.js"></script> |
| 25 | + <script src="./output/monaco/dist/editor.js"></script> |
21 | 26 |
|
22 | | - <script> |
23 | | - var editor; |
24 | | - (function() { |
25 | | - var base = "./output/monaco/dist/"; |
26 | | - var types = "./output/types/"; |
27 | | - window.MonacoEnvironment = window.MonacoEnvironment || {}; |
28 | | - window.MonacoEnvironment.getWorkerUrl = function (moduleId, label) { |
29 | | - if (label === 'json') return base + 'json.worker.js'; |
30 | | - if (label === 'css') return base + 'worker.js'; |
31 | | - if (label === 'html') return base + 'html.worker.js'; |
32 | | - if (label === 'typescript' || label === 'javascript') return base + 'ts.worker.js'; |
33 | | - return base + 'editor.worker.js'; |
34 | | - } |
35 | | - |
36 | | - const defCode = `const fs = require("fs"); //<< should be of type fs & have intellisense |
| 27 | + <script> |
| 28 | + let editor; |
| 29 | + (function () { |
| 30 | + const base = "./output/monaco/dist/"; |
| 31 | + const types = "./output/types/"; |
| 32 | + const defCode = `const fs = require("fs"); //<< should be of type fs & have intellisense |
37 | 33 | const os = require("os"); //<< should be of type os & have intellisense |
38 | 34 | const buf = Buffer.from([1,2,3]); //<< should be of type Buffer & have intellisense |
39 | 35 | let m = RED.util.cloneMessage({}); //<< hover over cloneMessage - see rich tips |
40 | 36 | let t = msg.topic; //<< see msg properties after entering msg. |
41 | 37 | let e = env.get("host"); //<< hover over get - see rich tips |
42 | 38 | ` |
43 | 39 |
|
44 | | - const compilerOptions = { |
45 | | - allowJs: true, |
46 | | - checkJs: true, |
47 | | - allowNonTsExtensions: true, |
48 | | - target: monaco.languages.typescript.ScriptTarget.ESNext, |
49 | | - strictNullChecks: false, |
50 | | - strictPropertyInitialization: true, |
51 | | - strictFunctionTypes: true, |
52 | | - strictBindCallApply: true, |
53 | | - moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs, |
54 | | - module: monaco.languages.typescript.ModuleKind.CommonJS, |
55 | | - typeRoots: ["types"], |
56 | | - lib: ["esnext"] //dont load DOM by default, |
57 | | - } |
58 | | - monaco.languages.typescript.javascriptDefaults.setCompilerOptions(compilerOptions); |
| 40 | + const compilerOptions = { |
| 41 | + allowJs: true, |
| 42 | + checkJs: true, |
| 43 | + allowNonTsExtensions: true, |
| 44 | + target: monaco.languages.typescript.ScriptTarget.ESNext, |
| 45 | + strictNullChecks: false, |
| 46 | + strictPropertyInitialization: true, |
| 47 | + strictFunctionTypes: true, |
| 48 | + strictBindCallApply: true, |
| 49 | + moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs, |
| 50 | + module: monaco.languages.typescript.ModuleKind.CommonJS, |
| 51 | + typeRoots: ["types"], |
| 52 | + lib: ["esnext"] //dont load DOM by default, |
| 53 | + } |
| 54 | + monaco.languages.typescript.javascriptDefaults.setCompilerOptions(compilerOptions); |
59 | 55 |
|
60 | | - const diagnosticOptions = { |
61 | | - noSemanticValidation: false, |
62 | | - noSyntaxValidation: false, |
63 | | - diagnosticCodesToIgnore: [ |
64 | | - 1108, //return not inside function |
65 | | - //2304, //Cannot find name - this one is heavy handed and prevents user seeing stupid errors. Would provide better ACE feature parity (i.e. no need for declaration of vars) but misses lots of errors. Lets be bold & leave it out! |
66 | | - 2307, //Cannot find module 'xxx' or its corresponding type declarations |
67 | | - 2322, //Type 'unknown' is not assignable to type 'string' |
68 | | - 2339, //property does not exist on |
69 | | - 2345, //Argument of type xxx is not assignable to parameter of type 'DateTimeFormatOptions' |
70 | | - 7043, //i forget what this one is, |
71 | | - 80001, //Convert to ES6 module |
72 | | - 80004, //JSDoc types may be moved to TypeScript types. |
73 | | - ] |
74 | | - }; |
75 | | - monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions(diagnosticOptions); |
| 56 | + const diagnosticOptions = { |
| 57 | + noSemanticValidation: false, |
| 58 | + noSyntaxValidation: false, |
| 59 | + diagnosticCodesToIgnore: [ |
| 60 | + 1108, //return not inside function |
| 61 | + //2304, //Cannot find name - this one is heavy handed and prevents user seeing stupid errors. Would provide better ACE feature parity (i.e. no need for declaration of vars) but misses lots of errors. Lets be bold & leave it out! |
| 62 | + 2307, //Cannot find module 'xxx' or its corresponding type declarations |
| 63 | + 2322, //Type 'unknown' is not assignable to type 'string' |
| 64 | + 2339, //property does not exist on |
| 65 | + 2345, //Argument of type xxx is not assignable to parameter of type 'DateTimeFormatOptions' |
| 66 | + 7043, //i forget what this one is, |
| 67 | + 80001, //Convert to ES6 module |
| 68 | + 80004, //JSDoc types may be moved to TypeScript types. |
| 69 | + ] |
| 70 | + }; |
| 71 | + monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions(diagnosticOptions); |
76 | 72 |
|
77 | | - editor = monaco.editor.create(document.getElementById("monaco-editor"), { |
78 | | - value: defCode, |
79 | | - language: "javascript" |
80 | | - }); |
81 | | - var themeName = "monokai" |
82 | | - fetch(base + "theme/" + themeName + ".json").then(response => { |
83 | | - return response.json(); |
84 | | - }).then(theme => { |
85 | | - if ((theme.rules && Array.isArray(theme.rules)) || theme.colors) { |
86 | | - monaco.editor.defineTheme(themeName, theme); |
87 | | - monaco.editor.setTheme(themeName); |
88 | | - } else { |
89 | | - console.warn("theme is not valid") |
90 | | - } |
91 | | - }).catch(err => { |
92 | | - console.error(err); |
93 | | - }); |
94 | | - const urls = [ |
95 | | - types + "node-red/util.d.ts", |
96 | | - types + "node-red/func.d.ts", |
97 | | - types + "node/globals.d.ts", |
98 | | - types + "node/fs.d.ts", |
99 | | - types + "node/os.d.ts", |
100 | | - ] |
101 | | - var promises = urls.map(url => fetch(url).then(y => y.text())); |
102 | | - Promise.all(promises).then(results => { |
103 | | - console.log(results); |
104 | | - for (let index = 0; index < results.length; index++) { |
105 | | - const ts = results[index]; |
106 | | - const fn = urls[index].replace(types,""); |
107 | | - monaco.languages.typescript.javascriptDefaults.addExtraLib(ts, `file://types/${fn}`); |
108 | | - } |
109 | | - }); |
110 | | - })(); |
| 73 | + editor = monaco.editor.create(document.getElementById("monaco-editor"), { |
| 74 | + value: defCode, |
| 75 | + language: "javascript" |
| 76 | + }); |
| 77 | + var themeName = "forge" |
| 78 | + fetch(base + "theme/" + themeName + ".json").then(response => { |
| 79 | + return response.json(); |
| 80 | + }).then(theme => { |
| 81 | + if ((theme.rules && Array.isArray(theme.rules)) || theme.colors) { |
| 82 | + monaco.editor.defineTheme(themeName, theme); |
| 83 | + monaco.editor.setTheme(themeName); |
| 84 | + } else { |
| 85 | + console.warn("theme is not valid") |
| 86 | + } |
| 87 | + }).catch(err => { |
| 88 | + console.error(err); |
| 89 | + }); |
| 90 | + const urls = [ |
| 91 | + types + "node-red/util.d.ts", |
| 92 | + types + "node-red/func.d.ts", |
| 93 | + types + "node/globals.d.ts", |
| 94 | + types + "node/fs.d.ts", |
| 95 | + types + "node/os.d.ts", |
| 96 | + ] |
| 97 | + var promises = urls.map(url => fetch(url).then(y => y.text())); |
| 98 | + Promise.all(promises).then(results => { |
| 99 | + console.log(results); |
| 100 | + for (let index = 0; index < results.length; index++) { |
| 101 | + const ts = results[index]; |
| 102 | + const fn = urls[index].replace(types, ""); |
| 103 | + monaco.languages.typescript.javascriptDefaults.addExtraLib(ts, `file://types/${fn}`); |
| 104 | + } |
| 105 | + }); |
| 106 | + })(); |
111 | 107 |
|
112 | | - </script> |
| 108 | + </script> |
113 | 109 |
|
114 | 110 | </body> |
115 | 111 |
|
|
0 commit comments