@theotherwillembotha/node-red-plugincore 0.0.52 → 0.0.53

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.
@@ -1,7 +1,7 @@
1
1
 
2
2
  import { DelegatedConfigReferenceNode } from "./core/other/node/DelegatedConfigReferenceNode.js";
3
3
  import { NodeTypeService } from "./core/tagging/service/NodeTypeService.js";
4
- import { NodeGenerator, SettingsService, BasicTemplate, SettingsTemplate, TimerMetricTemplate, ConsoleLoggerConfigNode, RestLoggerConfigNode, LokiLoggerConfigNode, UIHelperTemplate } from "./index.js"
4
+ import { NodeGenerator, SettingsService, BasicTemplate, SettingsTemplate, TimerMetricTemplate, ConsoleLoggerConfigNode, RestLoggerConfigNode, LokiLoggerConfigNode, UIHelperTemplate, ScriptEditorTemplate } from "./index.js"
5
5
  import { WebhookServerConfigNode, WebhookServerService, WebhookTemplate, } from "./index.js"
6
6
 
7
7
  import {LoggerService, LoggerTemplate } from "./index.js";
@@ -27,6 +27,7 @@ new NodeGenerator("./src/core/")
27
27
  .registerTemplate(TimerMetricTemplate)
28
28
  .registerTemplate(WebhookTemplate)
29
29
  .registerTemplate(UIHelperTemplate)
30
+ .registerTemplate(ScriptEditorTemplate)
30
31
 
31
32
  // nodes
32
33
  .registerNode(DelegatedConfigReferenceNode)
@@ -0,0 +1,50 @@
1
+
2
+ <div template-section="onIncludeOnce">
3
+
4
+ <script src="resources/@theotherwillembotha/node-red-plugincore/editorLanguageExtension.js"></script>
5
+
6
+ <script type="text/javascript">
7
+
8
+ window.PluginCore = window.PluginCore || {};
9
+
10
+ /**
11
+ * PluginCore.createScriptEditor(elementId, template, initialValue)
12
+ *
13
+ * Creates a Monaco editor instance with TypeScript-aware diagnostics,
14
+ * completions, and hover info scoped to the provided type template.
15
+ *
16
+ * @param {string} elementId - DOM id of the container element.
17
+ * @param {string} template - TypeScript template string. Use `${script}`
18
+ * as the placeholder for the user's code.
19
+ * @param {string} initialValue - The starting content of the editor.
20
+ * @returns \{{ getValue(): string, dispose(): void \}}
21
+ */
22
+ PluginCore.createScriptEditor = function(elementId, template, initialValue) {
23
+ var editorInstance = null;
24
+ var currentValue = initialValue || '';
25
+
26
+ ScriptEditorLanguageManager.createLanguage(monaco, template).then(function(language) {
27
+ editorInstance = monaco.editor.create(document.getElementById(elementId), {
28
+ value: currentValue,
29
+ language: language.getName(),
30
+ automaticLayout: true,
31
+ wordBasedSuggestions: 'currentDocument',
32
+ });
33
+ });
34
+
35
+ return {
36
+ getValue: function() {
37
+ return editorInstance ? editorInstance.getValue() : currentValue;
38
+ },
39
+ dispose: function() {
40
+ if (editorInstance) {
41
+ editorInstance.dispose();
42
+ editorInstance = null;
43
+ }
44
+ }
45
+ };
46
+ };
47
+
48
+ </script>
49
+
50
+ </div>
@@ -0,0 +1,14 @@
1
+ import { Template, TemplateDescriptor } from "../../NodeConstructor"
2
+ import { SourceUtility } from "../../NodeGenerator";
3
+
4
+ export class ScriptEditorTemplate extends Template {
5
+
6
+ public static getTemplateDescriptor(): TemplateDescriptor {
7
+ return new TemplateDescriptor(
8
+ "script-editor",
9
+ ScriptEditorTemplate,
10
+ SourceUtility.getSourcePath("/build/", "/src/") + "ScriptEditorTemplate.html",
11
+ []
12
+ );
13
+ }
14
+ }
package/src/index.ts CHANGED
@@ -26,6 +26,7 @@ export * from "./core/tagging/NodeDescriptionDecorator";
26
26
 
27
27
  // UI
28
28
  export * from "./core/ui/template/UIHelperTemplate";
29
+ export * from "./core/ui/template/ScriptEditorTemplate";
29
30
 
30
31
  // OTHER
31
32
  export * from "./core/other/node/DelegatedConfigReferenceNode";