From 9dd89cc7b96319ddaab6fe381165476e46ab23b0 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Fri, 7 Mar 2025 15:12:24 +0200 Subject: [PATCH 1/7] Implemented tbel utils autocompletes and highlights --- .../shared/components/js-func.component.scss | 6 + .../shared/components/js-func.component.ts | 7 + .../shared/models/ace/tbel-utils.models.ts | 1287 +++++++++++++++++ 3 files changed, 1300 insertions(+) create mode 100644 ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts diff --git a/ui-ngx/src/app/shared/components/js-func.component.scss b/ui-ngx/src/app/shared/components/js-func.component.scss index eecfe72c3e..12b1d57ccc 100644 --- a/ui-ngx/src/app/shared/components/js-func.component.scss +++ b/ui-ngx/src/app/shared/components/js-func.component.scss @@ -79,4 +79,10 @@ background: #f3f3f3; } } + + .ace_tb { + &.ace_tbel-utils-func { + color: #0000A2; + } + } } diff --git a/ui-ngx/src/app/shared/components/js-func.component.ts b/ui-ngx/src/app/shared/components/js-func.component.ts index eccb5cb908..682cc872e6 100644 --- a/ui-ngx/src/app/shared/components/js-func.component.ts +++ b/ui-ngx/src/app/shared/components/js-func.component.ts @@ -50,6 +50,7 @@ import { JsFuncModulesComponent } from '@shared/components/js-func-modules.compo import { HttpClient } from '@angular/common/http'; import { map, Observable, of } from 'rxjs'; import { catchError } from 'rxjs/operators'; +import { tbelUtilsAutocompletes, tbelUtilsFuncHighlightRules } from '@shared/models/ace/tbel-utils.models'; @Component({ selector: 'tb-js-func', @@ -587,6 +588,9 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal newMode.$highlightRules.$rules[group] = this.highlightRules[group]; } } + if (this.scriptLanguage === ScriptLanguage.TBEL) { + newMode.$highlightRules.$rules.start = [...tbelUtilsFuncHighlightRules, ...newMode.$highlightRules.$rules.start]; + } const identifierRule = newMode.$highlightRules.$rules.no_regex.find(rule => rule.token?.includes('identifier')); if (identifierRule) { identifierRule.next = 'start'; @@ -641,6 +645,9 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal if (modulesCompleter) { completers.push(modulesCompleter); } + if (this.scriptLanguage === ScriptLanguage.TBEL) { + completers.push(tbelUtilsAutocompletes); + } completers.push(...this.initialCompleters); this.jsEditor.completers = completers; }); diff --git a/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts b/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts new file mode 100644 index 0000000000..24b6d9eaaf --- /dev/null +++ b/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts @@ -0,0 +1,1287 @@ +import { AceHighlightRule } from '@shared/models/ace/ace.models'; +import { TbEditorCompleter } from '@shared/models/ace/completion.models'; + +export const tbelUtilsAutocompletes = new TbEditorCompleter({ + btoa: { + meta: 'function', + description: 'Encodes a string to Base64.', + args: [ + { + name: 'input', + description: 'The string to encode', + type: 'string' + } + ], + return: { + description: 'The Base64 encoded string', + type: 'string' + } + }, + atob: { + meta: 'function', + description: 'Decodes a Base64 encoded string.', + args: [ + { + name: 'encoded', + description: 'The Base64 encoded string to decode', + type: 'string' + } + ], + return: { + description: 'The decoded string', + type: 'string' + } + }, + bytesToString: { + meta: 'function', + description: 'Converts a list of bytes to a string, optionally specifying the charset.', + args: [ + { + name: 'bytesList', + description: 'The list of bytes to convert', + type: 'array' + }, + { + name: 'charsetName', + description: 'The charset to use for conversion (e.g., "UTF-8")', + type: 'string', + optional: true + } + ], + return: { + description: 'The string representation of the bytes', + type: 'string' + } + }, + decodeToString: { + meta: 'function', + description: 'Converts a list of bytes to a string using the default charset.', + args: [ + { + name: 'bytesList', + description: 'The list of bytes to convert', + type: 'array' + } + ], + return: { + description: 'The string representation of the bytes', + type: 'string' + } + }, + decodeToJson: { + meta: 'function', + description: 'Parses a JSON string or converts a list of bytes to a string and parses it as JSON.', + args: [ + { + name: 'input', + description: 'The JSON string or list of bytes to parse', + type: 'string | array' + } + ], + return: { + description: 'The parsed JSON object (e.g., object, array, or primitive)', + type: 'object' + } + }, + stringToBytes: { + meta: 'function', + description: 'Converts a string to a list of bytes, optionally specifying the charset.', + args: [ + { + name: 'str', + description: 'The string to convert', + type: 'string' + }, + { + name: 'charsetName', + description: 'The charset to use for conversion (e.g., "UTF-8")', + type: 'string', + optional: true + } + ], + return: { + description: 'The list of bytes representing the string', + type: 'array' + } + }, + parseInt: { + meta: 'function', + description: 'Parses a string to an integer, optionally specifying the radix.', + args: [ + { + name: 'value', + description: 'The string to parse', + type: 'string' + }, + { + name: 'radix', + description: 'The radix for parsing (e.g., 2 for binary, 16 for hex, defaults to auto-detection if 0)', + type: 'number', + optional: true + } + ], + return: { + description: 'The parsed integer, or null if invalid', + type: 'number' + } + }, + parseLong: { + meta: 'function', + description: 'Parses a string to a long integer, optionally specifying the radix.', + args: [ + { + name: 'value', + description: 'The string to parse', + type: 'string' + }, + { + name: 'radix', + description: 'The radix for parsing (e.g., 2 for binary, 16 for hex, defaults to auto-detection if 0)', + type: 'number', + optional: true + } + ], + return: { + description: 'The parsed long integer, or null if invalid', + type: 'number' + } + }, + parseFloat: { + meta: 'function', + description: 'Parses a string to a float. If radix is 16, interprets the string as hexadecimal IEEE 754 float bits.', + args: [ + { + name: 'value', + description: 'The string to parse', + type: 'string' + }, + { + name: 'radix', + description: 'The radix for parsing (e.g., 16 for hex, defaults to 10 if 0)', + type: 'number', + optional: true + } + ], + return: { + description: 'The parsed float, or null if invalid', + type: 'number' + } + }, + parseHexIntLongToFloat: { + meta: 'function', + description: 'Parses a hexadecimal string to a float, treating it as an integer value.', + args: [ + { + name: 'value', + description: 'The hexadecimal string to parse (e.g., "0x0A" for 10.0)', + type: 'string' + }, + { + name: 'bigEndian', + description: 'Whether to interpret the string in big-endian order', + type: 'boolean' + } + ], + return: { + description: 'The parsed float, or null if invalid', + type: 'number' + } + }, + parseDouble: { + meta: 'function', + description: 'Parses a string to a double. If radix is 16, interprets the string as hexadecimal IEEE 754 double bits.', + args: [ + { + name: 'value', + description: 'The string to parse', + type: 'string' + }, + { + name: 'radix', + description: 'The radix for parsing (e.g., 16 for hex, defaults to 10 if unspecified)', + type: 'number', + optional: true + } + ], + return: { + description: 'The parsed double, or null if invalid', + type: 'number' + } + }, + parseLittleEndianHexToInt: { + meta: 'function', + description: 'Parses a little-endian hexadecimal string to an integer.', + args: [ + { + name: 'hex', + description: 'The hexadecimal string to parse', + type: 'string' + } + ], + return: { + description: 'The parsed integer', + type: 'number' + } + }, + parseBigEndianHexToInt: { + meta: 'function', + description: 'Parses a big-endian hexadecimal string to an integer.', + args: [ + { + name: 'hex', + description: 'The hexadecimal string to parse', + type: 'string' + } + ], + return: { + description: 'The parsed integer', + type: 'number' + } + }, + parseHexToInt: { + meta: 'function', + description: 'Parses a hexadecimal string to an integer, optionally specifying endianness.', + args: [ + { + name: 'value', + description: 'The hexadecimal string to parse', + type: 'string' + }, + { + name: 'bigEndian', + description: 'Whether to interpret the string in big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The parsed integer', + type: 'number' + } + }, + parseBytesToInt: { + meta: 'function', + description: 'Parses a list or array of bytes to an integer.', + args: [ + { + name: 'data', + description: 'The bytes to parse', + type: 'array' + }, + { + name: 'offset', + description: 'The starting index in the byte array', + type: 'number', + optional: true + }, + { + name: 'length', + description: 'The number of bytes to parse (max 4)', + type: 'number', + optional: true + }, + { + name: 'bigEndian', + description: 'Whether to interpret bytes in big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The parsed integer', + type: 'number' + } + }, + parseLittleEndianHexToLong: { + meta: 'function', + description: 'Parses a little-endian hexadecimal string to a long integer.', + args: [ + { + name: 'hex', + description: 'The hexadecimal string to parse', + type: 'string' + } + ], + return: { + description: 'The parsed long integer', + type: 'number' + } + }, + parseBigEndianHexToLong: { + meta: 'function', + description: 'Parses a big-endian hexadecimal string to a long integer.', + args: [ + { + name: 'hex', + description: 'The hexadecimal string to parse', + type: 'string' + } + ], + return: { + description: 'The parsed long integer', + type: 'number' + } + }, + parseHexToLong: { + meta: 'function', + description: 'Parses a hexadecimal string to a long integer, optionally specifying endianness.', + args: [ + { + name: 'value', + description: 'The hexadecimal string to parse', + type: 'string' + }, + { + name: 'bigEndian', + description: 'Whether to interpret the string in big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The parsed long integer', + type: 'number' + } + }, + parseBytesToLong: { + meta: 'function', + description: 'Parses a list or array of bytes to a long integer.', + args: [ + { + name: 'data', + description: 'The bytes to parse', + type: 'array' + }, + { + name: 'offset', + description: 'The starting index in the byte array', + type: 'number', + optional: true + }, + { + name: 'length', + description: 'The number of bytes to parse (max 8)', + type: 'number', + optional: true + }, + { + name: 'bigEndian', + description: 'Whether to interpret bytes in big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The parsed long integer', + type: 'number' + } + }, + parseLittleEndianHexToFloat: { + meta: 'function', + description: 'Parses a little-endian hexadecimal string to a float using IEEE 754 format.', + args: [ + { + name: 'hex', + description: 'The hexadecimal string to parse', + type: 'string' + } + ], + return: { + description: 'The parsed float', + type: 'number' + } + }, + parseBigEndianHexToFloat: { + meta: 'function', + description: 'Parses a big-endian hexadecimal string to a float using IEEE 754 format.', + args: [ + { + name: 'hex', + description: 'The hexadecimal string to parse', + type: 'string' + } + ], + return: { + description: 'The parsed float', + type: 'number' + } + }, + parseHexToFloat: { + meta: 'function', + description: 'Parses a hexadecimal string to a float using IEEE 754 format, optionally specifying endianness.', + args: [ + { + name: 'value', + description: 'The hexadecimal string to parse', + type: 'string' + }, + { + name: 'bigEndian', + description: 'Whether to interpret the string in big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The parsed float', + type: 'number' + } + }, + parseBytesToFloat: { + meta: 'function', + description: 'Parses a list or array of bytes to a float using IEEE 754 format.', + args: [ + { + name: 'data', + description: 'The bytes to parse', + type: 'array' + }, + { + name: 'offset', + description: 'The starting index in the byte array', + type: 'number', + optional: true + }, + { + name: 'length', + description: 'The number of bytes to parse (max 4)', + type: 'number', + optional: true + }, + { + name: 'bigEndian', + description: 'Whether to interpret bytes in big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The parsed float', + type: 'number' + } + }, + parseBytesIntToFloat: { + meta: 'function', + description: 'Parses a list or array of bytes to a float by first interpreting them as an integer.', + args: [ + { + name: 'data', + description: 'The bytes to parse', + type: 'array' + }, + { + name: 'offset', + description: 'The starting index in the byte array', + type: 'number', + optional: true + }, + { + name: 'length', + description: 'The number of bytes to parse (max 4)', + type: 'number', + optional: true + }, + { + name: 'bigEndian', + description: 'Whether to interpret bytes in big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The parsed float', + type: 'number' + } + }, + parseLittleEndianHexToDouble: { + meta: 'function', + description: 'Parses a little-endian hexadecimal string to a double using IEEE 754 format.', + args: [ + { + name: 'hex', + description: 'The hexadecimal string to parse', + type: 'string' + } + ], + return: { + description: 'The parsed double', + type: 'number' + } + }, + parseBigEndianHexToDouble: { + meta: 'function', + description: 'Parses a big-endian hexadecimal string to a double using IEEE 754 format.', + args: [ + { + name: 'hex', + description: 'The hexadecimal string to parse', + type: 'string' + } + ], + return: { + description: 'The parsed double', + type: 'number' + } + }, + parseHexToDouble: { + meta: 'function', + description: 'Parses a hexadecimal string to a double using IEEE 754 format, optionally specifying endianness.', + args: [ + { + name: 'value', + description: 'The hexadecimal string to parse', + type: 'string' + }, + { + name: 'bigEndian', + description: 'Whether to interpret the string in big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The parsed double', + type: 'number' + } + }, + parseBytesToDouble: { + meta: 'function', + description: 'Parses a list or array of bytes to a double using IEEE 754 format.', + args: [ + { + name: 'data', + description: 'The bytes to parse', + type: 'array' + }, + { + name: 'offset', + description: 'The starting index in the byte array', + type: 'number', + optional: true + }, + { + name: 'length', + description: 'The number of bytes to parse (max 8)', + type: 'number', + optional: true + }, + { + name: 'bigEndian', + description: 'Whether to interpret bytes in big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The parsed double', + type: 'number' + } + }, + parseBytesLongToDouble: { + meta: 'function', + description: 'Parses a list or array of bytes to a double by first interpreting them as a long integer.', + args: [ + { + name: 'data', + description: 'The bytes to parse', + type: 'array' + }, + { + name: 'offset', + description: 'The starting index in the byte array', + type: 'number', + optional: true + }, + { + name: 'length', + description: 'The number of bytes to parse (max 8)', + type: 'number', + optional: true + }, + { + name: 'bigEndian', + description: 'Whether to interpret bytes in big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The parsed double', + type: 'number' + } + }, + toFixed: { + meta: 'function', + description: 'Rounds a number to a specified number of decimal places.', + args: [ + { + name: 'value', + description: 'The number to round', + type: 'number' + }, + { + name: 'precision', + description: 'The number of decimal places', + type: 'number' + } + ], + return: { + description: 'The rounded number', + type: 'number' + } + }, + toInt: { + meta: 'function', + description: 'Converts a double to an integer by rounding.', + args: [ + { + name: 'value', + description: 'The double to convert', + type: 'number' + } + ], + return: { + description: 'The rounded integer', + type: 'number' + } + }, + hexToBytes: { + meta: 'function', + description: 'Converts a hexadecimal string to a list of bytes.', + args: [ + { + name: 'value', + description: 'The hexadecimal string to convert', + type: 'string' + } + ], + return: { + description: 'The list of bytes', + type: 'array' + } + }, + hexToBytesArray: { + meta: 'function', + description: 'Converts a hexadecimal string to an array of bytes.', + args: [ + { + name: 'value', + description: 'The hexadecimal string to convert', + type: 'string' + } + ], + return: { + description: 'The array of bytes', + type: 'array' + } + }, + intToHex: { + meta: 'function', + description: 'Converts an integer to a hexadecimal string.', + args: [ + { + name: 'i', + description: 'The integer to convert', + type: 'number' + }, + { + name: 'bigEndian', + description: 'Whether to use big-endian order (defaults to true)', + type: 'boolean', + optional: true + }, + { + name: 'pref', + description: 'Whether to prefix with "0x" (defaults to false)', + type: 'boolean', + optional: true + }, + { + name: 'len', + description: 'The desired length of the hex string (defaults to minimum required)', + type: 'number', + optional: true + } + ], + return: { + description: 'The hexadecimal string', + type: 'string' + } + }, + longToHex: { + meta: 'function', + description: 'Converts a long integer to a hexadecimal string.', + args: [ + { + name: 'l', + description: 'The long integer to convert', + type: 'number' + }, + { + name: 'bigEndian', + description: 'Whether to use big-endian order (defaults to true)', + type: 'boolean', + optional: true + }, + { + name: 'pref', + description: 'Whether to prefix with "0x" (defaults to false)', + type: 'boolean', + optional: true + }, + { + name: 'len', + description: 'The desired length of the hex string (defaults to minimum required)', + type: 'number', + optional: true + } + ], + return: { + description: 'The hexadecimal string', + type: 'string' + } + }, + intLongToRadixString: { + meta: 'function', + description: 'Converts a long integer to a string in the specified radix.', + args: [ + { + name: 'number', + description: 'The number to convert', + type: 'number' + }, + { + name: 'radix', + description: 'The radix for conversion (e.g., 2, 8, 10, 16, defaults to 10)', + type: 'number', + optional: true + }, + { + name: 'bigEndian', + description: 'Whether to use big-endian order for hex (defaults to true)', + type: 'boolean', + optional: true + }, + { + name: 'pref', + description: 'Whether to prefix hex with "0x" (defaults to false)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The string representation in the specified radix', + type: 'string' + } + }, + floatToHex: { + meta: 'function', + description: 'Converts a float to its IEEE 754 hexadecimal representation.', + args: [ + { + name: 'f', + description: 'The float to convert', + type: 'number' + }, + { + name: 'bigEndian', + description: 'Whether to use big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The hexadecimal string (e.g., "0x41200000" for 10.0)', + type: 'string' + } + }, + doubleToHex: { + meta: 'function', + description: 'Converts a double to its IEEE 754 hexadecimal representation.', + args: [ + { + name: 'd', + description: 'The double to convert', + type: 'number' + }, + { + name: 'bigEndian', + description: 'Whether to use big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The hexadecimal string (e.g., "0x4024000000000000" for 10.0)', + type: 'string' + } + }, + printUnsignedBytes: { + meta: 'function', + description: 'Converts a list of signed bytes to a list of unsigned integer values.', + args: [ + { + name: 'byteArray', + description: 'The list of bytes to convert', + type: 'array' + } + ], + return: { + description: 'The list of unsigned integers (0-255)', + type: 'array' + } + }, + base64ToHex: { + meta: 'function', + description: 'Converts a Base64 string to a hexadecimal string.', + args: [ + { + name: 'base64', + description: 'The Base64 string to convert', + type: 'string' + } + ], + return: { + description: 'The hexadecimal string', + type: 'string' + } + }, + hexToBase64: { + meta: 'function', + description: 'Converts a hexadecimal string to a Base64 string.', + args: [ + { + name: 'hex', + description: 'The hexadecimal string to convert', + type: 'string' + } + ], + return: { + description: 'The Base64 string', + type: 'string' + } + }, + base64ToBytes: { + meta: 'function', + description: 'Converts a Base64 string to an array of bytes.', + args: [ + { + name: 'input', + description: 'The Base64 string to convert', + type: 'string' + } + ], + return: { + description: 'The array of bytes', + type: 'array' + } + }, + base64ToBytesList: { + meta: 'function', + description: 'Converts a Base64 string to a list of bytes.', + args: [ + { + name: 'input', + description: 'The Base64 string to convert', + type: 'string' + } + ], + return: { + description: 'The list of bytes', + type: 'array' + } + }, + bytesToBase64: { + meta: 'function', + description: 'Converts an array of bytes to a Base64 string.', + args: [ + { + name: 'bytes', + description: 'The array of bytes to convert', + type: 'array' + } + ], + return: { + description: 'The Base64 string', + type: 'string' + } + }, + bytesToHex: { + meta: 'function', + description: 'Converts an array or list of bytes to a hexadecimal string.', + args: [ + { + name: 'bytes', + description: 'The bytes to convert', + type: 'array' + } + ], + return: { + description: 'The hexadecimal string', + type: 'string' + } + }, + toFlatMap: { + meta: 'function', + description: 'Converts a nested map to a flat map, with options for key paths and exclusions.', + args: [ + { + name: 'json', + description: 'The nested map to flatten', + type: 'object' + }, + { + name: 'excludeList', + description: 'List of keys to exclude from flattening', + type: 'array', + optional: true + }, + { + name: 'pathInKey', + description: 'Whether to include full path in keys (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The flattened map', + type: 'object' + } + }, + encodeURI: { + meta: 'function', + description: 'Encodes a URI string, preserving certain characters as per MDN standards.', + args: [ + { + name: 'uri', + description: 'The URI string to encode', + type: 'string' + } + ], + return: { + description: 'The encoded URI string', + type: 'string' + } + }, + decodeURI: { + meta: 'function', + description: 'Decodes a URI string previously encoded with encodeURI.', + args: [ + { + name: 'uri', + description: 'The URI string to decode', + type: 'string' + } + ], + return: { + description: 'The decoded URI string', + type: 'string' + } + }, + raiseError: { + meta: 'function', + description: 'Throws an error with a custom message.', + args: [ + { + name: 'message', + description: 'The error message to throw', + type: 'string' + } + ], + return: { + description: 'Does not return; throws an exception', + type: 'void' + } + }, + isBinary: { + meta: 'function', + description: 'Checks if a string is a binary number.', + args: [ + { + name: 'str', + description: 'The string to check', + type: 'string' + } + ], + return: { + description: '2 if the string is binary, -1 otherwise', + type: 'number' + } + }, + isOctal: { + meta: 'function', + description: 'Checks if a string is an octal number.', + args: [ + { + name: 'str', + description: 'The string to check', + type: 'string' + } + ], + return: { + description: '8 if the string is octal, -1 otherwise', + type: 'number' + } + }, + isDecimal: { + meta: 'function', + description: 'Checks if a string is a decimal number.', + args: [ + { + name: 'str', + description: 'The string to check', + type: 'string' + } + ], + return: { + description: '10 if the string is decimal, -1 otherwise', + type: 'number' + } + }, + isHexadecimal: { + meta: 'function', + description: 'Checks if a string is a hexadecimal number.', + args: [ + { + name: 'str', + description: 'The string to check', + type: 'string' + } + ], + return: { + description: '16 if the string is hexadecimal, -1 otherwise', + type: 'number' + } + }, + bytesToExecutionArrayList: { + meta: 'function', + description: 'Converts an array of bytes to an execution array list.', + args: [ + { + name: 'byteArray', + description: 'The array of bytes to convert', + type: 'array' + } + ], + return: { + description: 'The execution array list of bytes', + type: 'array' + } + }, + padStart: { + meta: 'function', + description: 'Pads the start of a string with a character until it reaches the target length.', + args: [ + { + name: 'str', + description: 'The string to pad', + type: 'string' + }, + { + name: 'targetLength', + description: 'The desired length of the resulting string', + type: 'number' + }, + { + name: 'padString', + description: 'The character to pad with (single character)', + type: 'string' + } + ], + return: { + description: 'The padded string', + type: 'string' + } + }, + padEnd: { + meta: 'function', + description: 'Pads the end of a string with a character until it reaches the target length.', + args: [ + { + name: 'str', + description: 'The string to pad', + type: 'string' + }, + { + name: 'targetLength', + description: 'The desired length of the resulting string', + type: 'number' + }, + { + name: 'padString', + description: 'The character to pad with (single character)', + type: 'string' + } + ], + return: { + description: 'The padded string', + type: 'string' + } + }, + parseByteToBinaryArray: { + meta: 'function', + description: 'Converts a byte to a binary array.', + args: [ + { + name: 'byteValue', + description: 'The byte value to convert', + type: 'number' + }, + { + name: 'binLength', + description: 'The length of the binary array (defaults to 8)', + type: 'number', + optional: true + }, + { + name: 'bigEndian', + description: 'Whether to use big-endian order (defaults to true)', + type: 'boolean', + optional: true + } + ], + return: { + description: 'The binary array (array of 0s and 1s)', + type: 'array' + } + }, + parseBytesToBinaryArray: { + meta: 'function', + description: 'Converts a list or array of bytes to a binary array.', + args: [ + { + name: 'value', + description: 'The bytes to convert', + type: 'array' + }, + { + name: 'binLength', + description: 'The total length of the binary array (defaults to bytes.length * 8)', + type: 'number', + optional: true + } + ], + return: { + description: 'The binary array (array of 0s and 1s)', + type: 'array' + } + }, + parseLongToBinaryArray: { + meta: 'function', + description: 'Converts a long integer to a binary array.', + args: [ + { + name: 'longValue', + description: 'The long integer to convert', + type: 'number' + }, + { + name: 'binLength', + description: 'The length of the binary array (defaults to 64)', + type: 'number', + optional: true + } + ], + return: { + description: 'The binary array (array of 0s and 1s)', + type: 'array' + } + }, + parseBinaryArrayToInt: { + meta: 'function', + description: 'Converts a binary array to an integer.', + args: [ + { + name: 'value', + description: 'The binary array to convert (array of 0s and 1s)', + type: 'array' + }, + { + name: 'offset', + description: 'The starting index in the array (defaults to 0)', + type: 'number', + optional: true + }, + { + name: 'length', + description: 'The number of bits to parse (defaults to array length)', + type: 'number', + optional: true + } + ], + return: { + description: 'The parsed integer', + type: 'number' + } + } +}); + +const tbelUtilsFuncNames = [ + "btoa", + "atob", + "bytesToString", + "decodeToString", + "decodeToJson", + "stringToBytes", + "parseInt", + "parseLong", + "parseFloat", + "parseHexIntLongToFloat", + "parseDouble", + "parseLittleEndianHexToInt", + "parseBigEndianHexToInt", + "parseHexToInt", + "parseBytesToInt", + "parseLittleEndianHexToLong", + "parseBigEndianHexToLong", + "parseHexToLong", + "parseBytesToLong", + "parseLittleEndianHexToFloat", + "parseBigEndianHexToFloat", + "parseHexToFloat", + "parseBytesToFloat", + "parseBytesIntToFloat", + "parseLittleEndianHexToDouble", + "parseBigEndianHexToDouble", + "parseHexToDouble", + "parseBytesToDouble", + "parseBytesLongToDouble", + "toFixed", + "toInt", + "hexToBytes", + "hexToBytesArray", + "intToHex", + "longToHex", + "intLongToRadixString", + "floatToHex", + "doubleToHex", + "printUnsignedBytes", + "base64ToHex", + "hexToBase64", + "base64ToBytes", + "base64ToBytesList", + "bytesToBase64", + "bytesToHex", + "toFlatMap", + "encodeURI", + "decodeURI", + "raiseError", + "isBinary", + "isOctal", + "isDecimal", + "isHexadecimal", + "bytesToExecutionArrayList", + "padStart", + "padEnd", + "parseByteToBinaryArray", + "parseBytesToBinaryArray", + "parseLongToBinaryArray", + "parseBinaryArrayToInt" +]; + +export const tbelUtilsFuncHighlightRules: Array = + tbelUtilsFuncNames.map(funcName => ({ + token: 'tb.tbel-utils-func', + regex: `\\b${funcName}\\b`, + next: 'no_regex' + })); From c55f9592f60543218b1f9c9eb07bde2832a5d57a Mon Sep 17 00:00:00 2001 From: mpetrov Date: Fri, 7 Mar 2025 15:33:19 +0200 Subject: [PATCH 2/7] Fixed for rulechains --- .../app/shared/components/js-func.component.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ui-ngx/src/app/shared/components/js-func.component.ts b/ui-ngx/src/app/shared/components/js-func.component.ts index 682cc872e6..9859fa543e 100644 --- a/ui-ngx/src/app/shared/components/js-func.component.ts +++ b/ui-ngx/src/app/shared/components/js-func.component.ts @@ -241,6 +241,7 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal this.updateJsWorkerGlobals(); this.initialCompleters = this.jsEditor.completers || []; this.updateCompleters(); + this.updateHighlightRules(); this.editorResize$ = new ResizeObserver(() => { this.onAceEditorResize(); }); @@ -577,22 +578,24 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal private updateHighlightRules(): void { // @ts-ignore - if (!!this.highlightRules && !!this.jsEditor.session.$mode) { + if (!!this.jsEditor.session.$mode) { // @ts-ignore const newMode = new this.jsEditor.session.$mode.constructor(); newMode.$highlightRules = new newMode.HighlightRules(); - for(const group in this.highlightRules) { - if(!!newMode.$highlightRules.$rules[group]) { - newMode.$highlightRules.$rules[group].unshift(...this.highlightRules[group]); - } else { - newMode.$highlightRules.$rules[group] = this.highlightRules[group]; + if (!!this.highlightRules) { + for(const group in this.highlightRules) { + if(!!newMode.$highlightRules.$rules[group]) { + newMode.$highlightRules.$rules[group].unshift(...this.highlightRules[group]); + } else { + newMode.$highlightRules.$rules[group] = this.highlightRules[group]; + } } } if (this.scriptLanguage === ScriptLanguage.TBEL) { newMode.$highlightRules.$rules.start = [...tbelUtilsFuncHighlightRules, ...newMode.$highlightRules.$rules.start]; } const identifierRule = newMode.$highlightRules.$rules.no_regex.find(rule => rule.token?.includes('identifier')); - if (identifierRule) { + if (identifierRule && identifierRule.next === 'no_regex') { identifierRule.next = 'start'; } // @ts-ignore From 5b1731b0d8eac6e0fdc45b6e1b3c40f115dd00c5 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Fri, 7 Mar 2025 15:41:18 +0200 Subject: [PATCH 3/7] license header --- .../app/shared/models/ace/tbel-utils.models.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts b/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts index 24b6d9eaaf..a595428e63 100644 --- a/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts +++ b/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts @@ -1,3 +1,19 @@ +/// +/// Copyright © 2016-2025 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + import { AceHighlightRule } from '@shared/models/ace/ace.models'; import { TbEditorCompleter } from '@shared/models/ace/completion.models'; From 9215231ba6eb8c6e1108419bc7a07e9ecdb419dc Mon Sep 17 00:00:00 2001 From: mpetrov Date: Fri, 7 Mar 2025 15:54:45 +0200 Subject: [PATCH 4/7] refactoring --- ui-ngx/src/app/shared/components/js-func.component.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/ui-ngx/src/app/shared/components/js-func.component.ts b/ui-ngx/src/app/shared/components/js-func.component.ts index 9859fa543e..f9674c550a 100644 --- a/ui-ngx/src/app/shared/components/js-func.component.ts +++ b/ui-ngx/src/app/shared/components/js-func.component.ts @@ -241,7 +241,6 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal this.updateJsWorkerGlobals(); this.initialCompleters = this.jsEditor.completers || []; this.updateCompleters(); - this.updateHighlightRules(); this.editorResize$ = new ResizeObserver(() => { this.onAceEditorResize(); }); From e7b931690aa48db8ac45602599a364f8e48df14b Mon Sep 17 00:00:00 2001 From: Artem Barysh Date: Tue, 11 Mar 2025 15:21:33 +0200 Subject: [PATCH 5/7] TBEL formatting --- .../shared/models/ace/tbel-utils.models.ts | 198 +++++++++--------- 1 file changed, 99 insertions(+), 99 deletions(-) diff --git a/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts b/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts index a595428e63..53d0ccdd15 100644 --- a/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts +++ b/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts @@ -23,7 +23,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Encodes a string to Base64.', args: [ { - name: 'input', + name: 'str', description: 'The string to encode', type: 'string' } @@ -38,7 +38,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Decodes a Base64 encoded string.', args: [ { - name: 'encoded', + name: 'str', description: 'The Base64 encoded string to decode', type: 'string' } @@ -53,9 +53,9 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a list of bytes to a string, optionally specifying the charset.', args: [ { - name: 'bytesList', + name: 'data', description: 'The list of bytes to convert', - type: 'array' + type: 'list' }, { name: 'charsetName', @@ -71,12 +71,12 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ }, decodeToString: { meta: 'function', - description: 'Converts a list of bytes to a string using the default charset.', + description: 'Converts a list of bytes to a string.', args: [ { - name: 'bytesList', + name: 'data', description: 'The list of bytes to convert', - type: 'array' + type: 'list' } ], return: { @@ -89,13 +89,13 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Parses a JSON string or converts a list of bytes to a string and parses it as JSON.', args: [ { - name: 'input', - description: 'The JSON string or list of bytes to parse', - type: 'string | array' + name: 'data', + description: 'The JSON string or list of bytes to parse into JSON object', + type: 'string | list' } ], return: { - description: 'The parsed JSON object (e.g., object, array, or primitive)', + description: 'The parsed JSON object', type: 'object' } }, @@ -117,7 +117,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ ], return: { description: 'The list of bytes representing the string', - type: 'array' + type: 'list' } }, parseInt: { @@ -125,13 +125,13 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Parses a string to an integer, optionally specifying the radix.', args: [ { - name: 'value', + name: 'str', description: 'The string to parse', type: 'string' }, { name: 'radix', - description: 'The radix for parsing (e.g., 2 for binary, 16 for hex, defaults to auto-detection if 0)', + description: 'The radix for parsing (e.g., 2 for binary, 16 for hex). If omitted, it is auto-detected (e.g., 0x for hex).', type: 'number', optional: true } @@ -146,13 +146,13 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Parses a string to a long integer, optionally specifying the radix.', args: [ { - name: 'value', + name: 'str', description: 'The string to parse', type: 'string' }, { name: 'radix', - description: 'The radix for parsing (e.g., 2 for binary, 16 for hex, defaults to auto-detection if 0)', + description: 'The radix for parsing (e.g., 2 for binary, 16 for hex). If omitted, it is auto-detected (e.g., 0x for hex).', type: 'number', optional: true } @@ -164,16 +164,16 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ }, parseFloat: { meta: 'function', - description: 'Parses a string to a float. If radix is 16, interprets the string as hexadecimal IEEE 754 float bits.', + description: 'Parses a string to a float, optionally specifying the radix.', args: [ { - name: 'value', + name: 'str', description: 'The string to parse', type: 'string' }, { name: 'radix', - description: 'The radix for parsing (e.g., 16 for hex, defaults to 10 if 0)', + description: 'The radix for parsing (e.g., 16 indicates a standard IEEE 754 hexadecimal float, defaults to 10 if unspecified)', type: 'number', optional: true } @@ -188,7 +188,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Parses a hexadecimal string to a float, treating it as an integer value.', args: [ { - name: 'value', + name: 'hex', description: 'The hexadecimal string to parse (e.g., "0x0A" for 10.0)', type: 'string' }, @@ -205,16 +205,16 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ }, parseDouble: { meta: 'function', - description: 'Parses a string to a double. If radix is 16, interprets the string as hexadecimal IEEE 754 double bits.', + description: 'Parses a string to a double, optionally specifying the radix.', args: [ { - name: 'value', + name: 'str', description: 'The string to parse', type: 'string' }, { name: 'radix', - description: 'The radix for parsing (e.g., 16 for hex, defaults to 10 if unspecified)', + description: 'The radix for parsing (e.g., 16 indicates a standard IEEE 754 double bits, defaults to 10 if unspecified)', type: 'number', optional: true } @@ -259,7 +259,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Parses a hexadecimal string to an integer, optionally specifying endianness.', args: [ { - name: 'value', + name: 'hex', description: 'The hexadecimal string to parse', type: 'string' }, @@ -282,11 +282,11 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ { name: 'data', description: 'The bytes to parse', - type: 'array' + type: 'list | array' }, { name: 'offset', - description: 'The starting index in the byte array', + description: 'The starting index in the byte list or array (defaults to 0)', type: 'number', optional: true }, @@ -343,7 +343,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Parses a hexadecimal string to a long integer, optionally specifying endianness.', args: [ { - name: 'value', + name: 'hex', description: 'The hexadecimal string to parse', type: 'string' }, @@ -366,11 +366,11 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ { name: 'data', description: 'The bytes to parse', - type: 'array' + type: 'list | array' }, { name: 'offset', - description: 'The starting index in the byte array', + description: 'The starting index in the byte list or array (defaults to 0)', type: 'number', optional: true }, @@ -427,7 +427,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Parses a hexadecimal string to a float using IEEE 754 format, optionally specifying endianness.', args: [ { - name: 'value', + name: 'hex', description: 'The hexadecimal string to parse', type: 'string' }, @@ -450,11 +450,11 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ { name: 'data', description: 'The bytes to parse', - type: 'array' + type: 'list | array' }, { name: 'offset', - description: 'The starting index in the byte array', + description: 'The starting index in the byte list or array (defaults to 0)', type: 'number', optional: true }, @@ -483,11 +483,11 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ { name: 'data', description: 'The bytes to parse', - type: 'array' + type: 'list | array' }, { name: 'offset', - description: 'The starting index in the byte array', + description: 'The starting index in the byte list or array (defaults to 0)', type: 'number', optional: true }, @@ -544,7 +544,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Parses a hexadecimal string to a double using IEEE 754 format, optionally specifying endianness.', args: [ { - name: 'value', + name: 'hex', description: 'The hexadecimal string to parse', type: 'string' }, @@ -567,11 +567,11 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ { name: 'data', description: 'The bytes to parse', - type: 'array' + type: 'list | array' }, { name: 'offset', - description: 'The starting index in the byte array', + description: 'The starting index in the byte list or array (defaults to 0)', type: 'number', optional: true }, @@ -600,11 +600,11 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ { name: 'data', description: 'The bytes to parse', - type: 'array' + type: 'list | array' }, { name: 'offset', - description: 'The starting index in the byte array', + description: 'The starting index in the byte list or array (defaults to 0)', type: 'number', optional: true }, @@ -628,11 +628,11 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ }, toFixed: { meta: 'function', - description: 'Rounds a number to a specified number of decimal places.', + description: 'Rounds a floating-point number to a set precision using half-up rounding.', args: [ { name: 'value', - description: 'The number to round', + description: 'The floating-point number', type: 'number' }, { @@ -642,17 +642,17 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ } ], return: { - description: 'The rounded number', + description: 'The rounded floating-point number.', type: 'number' } }, toInt: { meta: 'function', - description: 'Converts a double to an integer by rounding.', + description: 'Converts a floating-point number to an integer by half-up rounding.', args: [ { name: 'value', - description: 'The double to convert', + description: 'The floating-point number to convert', type: 'number' } ], @@ -666,14 +666,14 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a hexadecimal string to a list of bytes.', args: [ { - name: 'value', + name: 'hex', description: 'The hexadecimal string to convert', type: 'string' } ], return: { description: 'The list of bytes', - type: 'array' + type: 'list' } }, hexToBytesArray: { @@ -681,7 +681,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a hexadecimal string to an array of bytes.', args: [ { - name: 'value', + name: 'hex', description: 'The hexadecimal string to convert', type: 'string' } @@ -696,7 +696,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts an integer to a hexadecimal string.', args: [ { - name: 'i', + name: 'value', description: 'The integer to convert', type: 'number' }, @@ -707,13 +707,13 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ optional: true }, { - name: 'pref', + name: 'prefix', description: 'Whether to prefix with "0x" (defaults to false)', type: 'boolean', optional: true }, { - name: 'len', + name: 'length', description: 'The desired length of the hex string (defaults to minimum required)', type: 'number', optional: true @@ -729,7 +729,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a long integer to a hexadecimal string.', args: [ { - name: 'l', + name: 'value', description: 'The long integer to convert', type: 'number' }, @@ -740,13 +740,13 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ optional: true }, { - name: 'pref', + name: 'prefix', description: 'Whether to prefix with "0x" (defaults to false)', type: 'boolean', optional: true }, { - name: 'len', + name: 'length', description: 'The desired length of the hex string (defaults to minimum required)', type: 'number', optional: true @@ -762,13 +762,13 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a long integer to a string in the specified radix.', args: [ { - name: 'number', + name: 'value', description: 'The number to convert', type: 'number' }, { name: 'radix', - description: 'The radix for conversion (e.g., 2, 8, 10, 16, defaults to 10)', + description: 'The radix for conversion (e.g., 2 for binary, 16 for hex). If omitted, it defaults to 10.', type: 'number', optional: true }, @@ -779,7 +779,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ optional: true }, { - name: 'pref', + name: 'prefix', description: 'Whether to prefix hex with "0x" (defaults to false)', type: 'boolean', optional: true @@ -795,7 +795,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a float to its IEEE 754 hexadecimal representation.', args: [ { - name: 'f', + name: 'value', description: 'The float to convert', type: 'number' }, @@ -807,7 +807,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ } ], return: { - description: 'The hexadecimal string (e.g., "0x41200000" for 10.0)', + description: 'The hexadecimal string', type: 'string' } }, @@ -816,7 +816,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a double to its IEEE 754 hexadecimal representation.', args: [ { - name: 'd', + name: 'value', description: 'The double to convert', type: 'number' }, @@ -828,7 +828,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ } ], return: { - description: 'The hexadecimal string (e.g., "0x4024000000000000" for 10.0)', + description: 'The hexadecimal string', type: 'string' } }, @@ -837,14 +837,14 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a list of signed bytes to a list of unsigned integer values.', args: [ { - name: 'byteArray', + name: 'data', description: 'The list of bytes to convert', - type: 'array' + type: 'list' } ], return: { description: 'The list of unsigned integers (0-255)', - type: 'array' + type: 'list' } }, base64ToHex: { @@ -852,7 +852,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a Base64 string to a hexadecimal string.', args: [ { - name: 'base64', + name: 'str', description: 'The Base64 string to convert', type: 'string' } @@ -882,7 +882,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a Base64 string to an array of bytes.', args: [ { - name: 'input', + name: 'str', description: 'The Base64 string to convert', type: 'string' } @@ -897,14 +897,14 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a Base64 string to a list of bytes.', args: [ { - name: 'input', + name: 'str', description: 'The Base64 string to convert', type: 'string' } ], return: { description: 'The list of bytes', - type: 'array' + type: 'list' } }, bytesToBase64: { @@ -912,7 +912,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts an array of bytes to a Base64 string.', args: [ { - name: 'bytes', + name: 'data', description: 'The array of bytes to convert', type: 'array' } @@ -924,12 +924,12 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ }, bytesToHex: { meta: 'function', - description: 'Converts an array or list of bytes to a hexadecimal string.', + description: 'Converts a list or array of bytes to a hexadecimal string.', args: [ { - name: 'bytes', + name: 'data', description: 'The bytes to convert', - type: 'array' + type: 'list | array' } ], return: { @@ -939,7 +939,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ }, toFlatMap: { meta: 'function', - description: 'Converts a nested map to a flat map, with options for key paths and exclusions.', + description: 'Converts a nested map to a flat map, with customizable key paths and exclusions', args: [ { name: 'json', @@ -947,9 +947,9 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ type: 'object' }, { - name: 'excludeList', + name: 'excludeKeys', description: 'List of keys to exclude from flattening', - type: 'array', + type: 'list', optional: true }, { @@ -969,7 +969,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Encodes a URI string, preserving certain characters as per MDN standards.', args: [ { - name: 'uri', + name: 'str', description: 'The URI string to encode', type: 'string' } @@ -981,10 +981,10 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ }, decodeURI: { meta: 'function', - description: 'Decodes a URI string previously encoded with encodeURI.', + description: 'Decodes a URI string previously encoded.', args: [ { - name: 'uri', + name: 'str', description: 'The URI string to decode', type: 'string' } @@ -999,7 +999,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Throws an error with a custom message.', args: [ { - name: 'message', + name: 'str', description: 'The error message to throw', type: 'string' } @@ -1071,17 +1071,17 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ }, bytesToExecutionArrayList: { meta: 'function', - description: 'Converts an array of bytes to an execution array list.', + description: 'Converts an array of bytes to a list.', args: [ { - name: 'byteArray', + name: 'data', description: 'The array of bytes to convert', type: 'array' } ], return: { - description: 'The execution array list of bytes', - type: 'array' + description: 'The list of bytes', + type: 'list' } }, padStart: { @@ -1094,7 +1094,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ type: 'string' }, { - name: 'targetLength', + name: 'length', description: 'The desired length of the resulting string', type: 'number' }, @@ -1119,7 +1119,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ type: 'string' }, { - name: 'targetLength', + name: 'length', description: 'The desired length of the resulting string', type: 'number' }, @@ -1139,12 +1139,12 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a byte to a binary array.', args: [ { - name: 'byteValue', + name: 'value', description: 'The byte value to convert', type: 'number' }, { - name: 'binLength', + name: 'length', description: 'The length of the binary array (defaults to 8)', type: 'number', optional: true @@ -1157,7 +1157,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ } ], return: { - description: 'The binary array (array of 0s and 1s)', + description: 'The binary array', type: 'array' } }, @@ -1166,19 +1166,19 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a list or array of bytes to a binary array.', args: [ { - name: 'value', + name: 'data', description: 'The bytes to convert', - type: 'array' + type: 'list | array' }, { - name: 'binLength', + name: 'length', description: 'The total length of the binary array (defaults to bytes.length * 8)', type: 'number', optional: true } ], return: { - description: 'The binary array (array of 0s and 1s)', + description: 'The binary array', type: 'array' } }, @@ -1187,34 +1187,34 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'Converts a long integer to a binary array.', args: [ { - name: 'longValue', + name: 'value', description: 'The long integer to convert', type: 'number' }, { - name: 'binLength', + name: 'length', description: 'The length of the binary array (defaults to 64)', type: 'number', optional: true } ], return: { - description: 'The binary array (array of 0s and 1s)', + description: 'The binary array', type: 'array' } }, parseBinaryArrayToInt: { meta: 'function', - description: 'Converts a binary array to an integer.', + description: 'Converts a binary list or array to an integer.', args: [ { - name: 'value', - description: 'The binary array to convert (array of 0s and 1s)', - type: 'array' + name: 'data', + description: 'The binary list or array to convert', + type: 'list | array' }, { name: 'offset', - description: 'The starting index in the array (defaults to 0)', + description: 'The starting index in the binary list or array (defaults to 0)', type: 'number', optional: true }, From b3a4d460eddca715f5977d757c15f1c18c763666 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Wed, 12 Mar 2025 10:56:41 +0200 Subject: [PATCH 6/7] handled scriptlang change --- ui-ngx/src/app/shared/components/js-func.component.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui-ngx/src/app/shared/components/js-func.component.ts b/ui-ngx/src/app/shared/components/js-func.component.ts index f9674c550a..d6f2ded043 100644 --- a/ui-ngx/src/app/shared/components/js-func.component.ts +++ b/ui-ngx/src/app/shared/components/js-func.component.ts @@ -561,6 +561,9 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal break; case 'scriptLanguage': this.updatedScriptLanguage(); + this.updateHighlightRules(); + this.updateCompleters(); + this.updateJsWorkerGlobals(); break; case 'disableUndefinedCheck': case 'globalVariables': From 9f740a15df41c3d54d52111b6777e38cb909ad3e Mon Sep 17 00:00:00 2001 From: mpetrov Date: Wed, 12 Mar 2025 17:48:56 +0200 Subject: [PATCH 7/7] Updated default script --- .../shared/components/js-func.component.scss | 2 +- .../shared/models/ace/tbel-utils.models.ts | 26 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ui-ngx/src/app/shared/components/js-func.component.scss b/ui-ngx/src/app/shared/components/js-func.component.scss index 12b1d57ccc..44aab1abbf 100644 --- a/ui-ngx/src/app/shared/components/js-func.component.scss +++ b/ui-ngx/src/app/shared/components/js-func.component.scss @@ -82,7 +82,7 @@ .ace_tb { &.ace_tbel-utils-func { - color: #0000A2; + color: rgb(49, 132, 149); } } } diff --git a/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts b/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts index 53d0ccdd15..f0a04b4762 100644 --- a/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts +++ b/ui-ngx/src/app/shared/models/ace/tbel-utils.models.ts @@ -131,7 +131,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ }, { name: 'radix', - description: 'The radix for parsing (e.g., 2 for binary, 16 for hex). If omitted, it is auto-detected (e.g., 0x for hex).', + description: 'The radix for parsing (e.g., 2 for binary, 16 for hex). Defaults to auto-detected (e.g., 0x for hex).', type: 'number', optional: true } @@ -152,7 +152,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ }, { name: 'radix', - description: 'The radix for parsing (e.g., 2 for binary, 16 for hex). If omitted, it is auto-detected (e.g., 0x for hex).', + description: 'The radix for parsing (e.g., 2 for binary, 16 for hex). Defaults to auto-detected (e.g., 0x for hex).', type: 'number', optional: true } @@ -768,7 +768,7 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ }, { name: 'radix', - description: 'The radix for conversion (e.g., 2 for binary, 16 for hex). If omitted, it defaults to 10.', + description: 'The radix for conversion (e.g., 2 for binary, 16 for hex). Defaults to 10.', type: 'number', optional: true }, @@ -1229,7 +1229,22 @@ export const tbelUtilsAutocompletes = new TbEditorCompleter({ description: 'The parsed integer', type: 'number' } - } + }, + isNaN: { + meta: 'function', + description: 'Checks if the given number is NaN (Not a Number).', + args: [ + { + name: 'value', + description: 'The number to check', + type: 'number' + } + ], + return: { + description: 'True if the number is NaN, false otherwise', + type: 'boolean' + } + }, }); const tbelUtilsFuncNames = [ @@ -1292,7 +1307,8 @@ const tbelUtilsFuncNames = [ "parseByteToBinaryArray", "parseBytesToBinaryArray", "parseLongToBinaryArray", - "parseBinaryArrayToInt" + "parseBinaryArrayToInt", + "isNaN", ]; export const tbelUtilsFuncHighlightRules: Array =