Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update prep for NR v4 #8

Merged
merged 8 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ and you should see monaco editor with the monokai theme and French menus (try op
### Add to node-red src

```bash
cp -r output/monaco/dist \
<node-red-source-directory>/packages/node_modules/@node-red/editor-client/src/vendor/monaco/
export nr_src=~/repos/github/node-red-org/node-red
# clean up
rm -rf $nr_src/packages/node_modules/@node-red/editor-client/src/vendor/monaco/dist/*
rm -rf $nr_src/packages/node_modules/@node-red/editor-client/src/types/node/*
rm -rf $nr_src/packages/node_modules/@node-red/editor-client/src/types/node-red/*

# copy
cp -r output/monaco/dist \
$nr_src/packages/node_modules/@node-red/editor-client/src/vendor/monaco/
cp -r output/types \
<node-red-source-directory>/packages/node_modules/@node-red/editor-client/src/
$nr_src/packages/node_modules/@node-red/editor-client/src/
```
23 changes: 15 additions & 8 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ <h3>Things to check...</h3>
(function () {
const base = "./output/monaco/dist/";
const types = "./output/types/";
const defCode = `const fs = require("fs"); //<< should be of type fs & have intellisense
const os = require("os"); //<< should be of type os & have intellisense
const buf = Buffer.from([1,2,3]); //<< should be of type Buffer & have intellisense
let m = RED.util.cloneMessage({}); //<< hover over cloneMessage - see rich tips
let t = msg.topic; //<< see msg properties after entering msg.
let e = env.get("host"); //<< hover over get - see rich tips
const defCode = `const fs = require("fs/promises") //<< should be of type fs/promises & have intellisense
const os = require("os") // << should be of type os & have intellisense
const buf = Buffer.from([1,2,3]) // << should be of type Buffer & have intellisense
let m = RED.util.cloneMessage({}) // << hover over cloneMessage - see rich tips
let t = msg.topic // << see msg properties after entering msg.
let e = env.get("host") // << hover over get - see rich tips
const path = node.path // << should be recognised by editor
node.status({fill:"red",shape:"ring",text:"hello"}) // << should be recognised by editor
node.error("hello") // << should be recognised by editor
node.warn("hello") // << should be recognised by editor
`

const compilerOptions = {
Expand All @@ -49,7 +53,7 @@ <h3>Things to check...</h3>
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
module: monaco.languages.typescript.ModuleKind.CommonJS,
typeRoots: ["types"],
lib: ["esnext"] //dont load DOM by default,
lib: ["esnext"] // don't load DOM by default,
}
monaco.languages.typescript.javascriptDefaults.setCompilerOptions(compilerOptions);

Expand All @@ -74,7 +78,7 @@ <h3>Things to check...</h3>
value: defCode,
language: "javascript"
});
var themeName = "forge-dark"
const themeName = "forge-dark"
fetch(base + "theme/" + themeName + ".json").then(response => {
return response.json();
}).then(theme => {
Expand All @@ -92,8 +96,11 @@ <h3>Things to check...</h3>
types + "node-red/func.d.ts",
types + "node/globals.d.ts",
types + "node/buffer.d.ts",
types + "node/console.d.ts",
types + "node/fs.d.ts",
types + "node/fs/promises.d.ts",
types + "node/os.d.ts",
types + "node/timers.d.ts",
]
var promises = urls.map(url => fetch(url).then(y => y.text()));
Promise.all(promises).then(results => {
Expand Down
6 changes: 3 additions & 3 deletions generate-monaco-esm-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
vsCodeLocDir,
vsCodeLocI18nDir,
generatedSourceLocaleDir,
} = require("./paths");
} = require("./setup");

const langDirPrefix = "vscode-language-pack-";
const vsCodeRepository = "https://github.com/Microsoft/vscode-loc.git";
Expand Down Expand Up @@ -131,7 +131,7 @@ function injectSourcePath(monacoVersion, callback) {
});
}).catch(err => {
callback(err);
});
})
}

/**
Expand Down Expand Up @@ -213,7 +213,7 @@ async function main() {
mkdirp.sync(gitDir);
injectSourcePath(monacoVersion, err => {
if (err) throw err;
gitPullOrClone(vsCodeRepository, vsCodeLocDir, function (err) {
gitPullOrClone(vsCodeRepository, vsCodeLocDir, { shell: true }, function (err) {
if (err) throw err;

fs.readdir(vsCodeLocI18nDir, (err, langDirs) => {
Expand Down
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as monaco from 'monaco-editor-esm-i18n';
const parent = self || window || globalThis;
// import * as monaco from 'monaco-editor-esm-i18n';
// window.monaco = monaco;
// window.MonacoEnvironment = window.MonacoEnvironment || {};
// if(!window.MonacoEnvironment.Locale) {
// window.MonacoEnvironment.Locale = window.MonacoLocale
// }

import * as monaco from 'monaco-editor-esm-i18n';
const parent = typeof globalThis === "object" ? globalThis : typeof window === "object" ? window : typeof self === "object" ? self : global;
parent.monaco = monaco;
monaco.parent = parent;
parent.MonacoEnvironment = parent.MonacoEnvironment || {};
Expand Down
48 changes: 44 additions & 4 deletions nls-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const globalScope = typeof globalThis === "object" ? globalThis : typeof window === "object" ? window : typeof self === "object" ? self : global;
let isPseudo = (typeof document !== 'undefined' && document.location && document.location.hash.indexOf('pseudo=true') >= 0);

function _format(message, args) {
let result;
if (args.length === 0) {
Expand All @@ -14,22 +17,55 @@ function _format(message, args) {
return typeof args[index] !== 'undefined' ? args[index] : match;
});
}
if (isPseudo) {
// FF3B and FF3D is the Unicode zenkaku representation for [ and ]
result = '\uFF3B' + result.replace(/[aouei]/g, '$&$&') + '\uFF3D';
}
return result;
}

export function localize(path, data, defaultMessage) {
const key = typeof data === "object" ? data.key : data;
const localeData = ((self.MonacoLocale || {}) || {}).data || {};
/**
* @skipMangle
*/
export function localize(path, data, defaultMessage, ...args) {
const key = typeof data=== "object" ? data.key : data;
// data = ((globalScope.MonacoEnvironment||{}).Locale||{}).data||{};
// data = ((globalScope.MonacoLocale || {}) || {}).data || {};
// let message = (data[path]||{})[key];
const localeData = ((globalScope.MonacoLocale || {}) || {}).data || {};
let message = (localeData[path] || {})[key];
if (!message) {
message = defaultMessage;
}
const args = [];
args = [];
for (let _i = 3; _i < arguments.length; _i++) {
args[_i - 3] = arguments[_i];
}
return _format(message, args);
}
/**
* @skipMangle
*/
export function localize2(path, data, defaultMessage, ...args) {
const key = typeof data=== "object" ? data.key : data;
// data = ((globalScope.MonacoEnvironment||{}).Locale||{}).data||{};
// data = ((globalScope.MonacoLocale || {}) || {}).data || {};
// let message = (data[path]||{})[key];
const localeData = ((globalScope.MonacoLocale || {}) || {}).data || {};
let message = (localeData[path] || {})[key];
if (!message) {
message = defaultMessage;
}
args = [];
for (let _i = 3; _i < arguments.length; _i++) {
args[_i - 3] = arguments[_i];
}
const original = _format(message, args);
return {
value: original,
original
};
}

export function loadMessageBundle(file) {
return localize;
Expand All @@ -39,6 +75,10 @@ export function config(opt) {
return loadMessageBundle;
}

/**
* @skipMangle
*/
export function getConfiguredDefaultLocale() {
return (self.MonacoLocale || {}).language;
}

41 changes: 25 additions & 16 deletions node-red-types/func.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interface NodeMessage {
topic?: string;
payload?: any;
_msgid?: string;
/** `_msgid` is generated internally. It not something you typically need to set or modify. */ _msgid?: string;
[other: string]: any; //permit other properties
}

Expand All @@ -16,15 +16,15 @@ declare const promisify:typeof import('util').promisify
/**
* @typedef NodeStatus
* @type {object}
* @property {string} [fill] The fill property can be: red, green, yellow, blue or grey.
* @property {string} [shape] The shape property can be: ring or dot.
* @property {string} [text] The text to display
* @property {'red'|'green'|'yellow'|'blue'|'grey'|string} [fill] - The fill property can be: red, green, yellow, blue or grey.
* @property {'ring'|'dot'|string} [shape] The shape property can be: ring or dot.
* @property {string|boolean|number} [text] The text to display
*/
interface NodeStatus {
/** The fill property can be: red, green, yellow, blue or grey */
fill?: string,
fill?: 'red'|'green'|'yellow'|'blue'|'grey'|string,
/** The shape property can be: ring or dot */
shape?: string,
shape?: 'ring'|'dot'|string,
/** The text to display */
text?: string|boolean|number
}
Expand All @@ -34,25 +34,24 @@ declare class node {
* Send 1 or more messages asynchronously
* @param {object | object[]} msg The msg object
* @param {Boolean} [clone=true] Flag to indicate the `msg` should be cloned. Default = `true`
* @see node-red documentation [writing-functions: sending messages asynchronously](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)
* @see Node-RED documentation [writing-functions: sending messages asynchronously](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)
*/
static send(msg:object|object[], clone?:Boolean): void;
static send(msg:NodeMessage|NodeMessage[], clone?:Boolean): void;
/** Inform runtime this instance has completed its operation */
static done();
/** Send an error to the console and debug side bar. Include `msg` in the 2nd parameter to trigger the catch node. */
static error(err:string|Error, msg?:object);
static error(err:string|Error, msg?:NodeMessage);
/** Log a warn message to the console and debug sidebar */
static warn(warning:string|object);
/** Log an info message to the console (not sent to sidebar)' */
static log(info:string|object);
/** Sets the status icon and text underneath the node.
* @param {NodeStatus} status - The status object `{fill, shape, text}`
* @see node-red documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
* @see Node-RED documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
*/
static status(status:NodeStatus);
/** Sets the status text underneath the node.
* @param {string} status - The status to display
* @see node-red documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
* @see Node-RED documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
*/
static status(status:string|boolean|number);
/** the id of this node */
Expand Down Expand Up @@ -261,9 +260,12 @@ declare class global {
/** Get an array of the keys in the context store */
static keys(store: string, callback: Function);
}

// (string & {}) is a workaround for offering string type completion without enforcing it. See https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939
type NR_ENV_NAME_STRING = 'NR_NODE_ID'|'NR_NODE_NAME'|'NR_NODE_PATH'|'NR_GROUP_ID'|'NR_GROUP_NAME'|'NR_FLOW_ID'|'NR_FLOW_NAME'|'NR_SUBFLOW_ID'|'NR_SUBFLOW_NAME'|'NR_SUBFLOW_PATH' | (string & {})
declare class env {
/**
* Get an environment variable value
* Get an environment variable value defined in the OS, or in the global/flow/subflow/group environment variables.
*
* Predefined node-red variables...
* * `NR_NODE_ID` - the ID of the node
Expand All @@ -273,9 +275,16 @@ declare class env {
* * `NR_GROUP_NAME` - the Name of the containing group
* * `NR_FLOW_ID` - the ID of the flow the node is on
* * `NR_FLOW_NAME` - the Name of the flow the node is on
* @param name Name of the environment variable to get
* * `NR_SUBFLOW_ID` - the ID of the subflow the node is in
* * `NR_SUBFLOW_NAME` - the Name of the subflow the node is in
* * `NR_SUBFLOW_PATH` - the Path of the subflow the node is in
* @param name - The name of the environment variable
* @example
* ```const flowName = env.get("NR_FLOW_NAME") // get the name of the flow```
* @example
* ```const systemHomeDir = env.get("HOME") // get the user's home directory```
* @example
* ```const flowName = env.get("NR_FLOW_NAME");```
* ```const systemHomeDir = env.get("LABEL1") // get the value of a global/flow/subflow/group defined variable named "LABEL1"```
*/
static get(name:string) :any;
static get(name:NR_ENV_NAME_STRING) :any;
}
Loading