@node-projects/web-component-designer-visualization-addons 0.1.145 → 0.1.146

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.
@@ -2,6 +2,7 @@ import { BaseCustomWebComponentConstructorAppend } from "@node-projects/base-cus
2
2
  import { IContextMenuItem, IDesignItem, IEvent, InstanceServiceContainer } from "@node-projects/web-component-designer";
3
3
  import { VisualizationShell } from "../interfaces/VisualizationShell.js";
4
4
  import { VisualizationHandler } from "../interfaces/VisualizationHandler.js";
5
+ import { ScriptCommandHelp } from "../scripting/ScriptCommandsDescriptions.js";
5
6
  type eventWithDesignItem = IEvent & {
6
7
  designItem: IDesignItem;
7
8
  };
@@ -27,10 +28,11 @@ export declare class EventAssignment extends BaseCustomWebComponentConstructorAp
27
28
  private _visualizationShell;
28
29
  private _scriptCommandsTypeInfo;
29
30
  private _propertiesTypeInfo;
31
+ private _commandDescriptions;
30
32
  events: (IEvent & {
31
33
  designItem: IDesignItem;
32
34
  })[];
33
- initialize(visualizationHandler: VisualizationHandler, visualizationShell: VisualizationShell, scriptCommandsTypeInfo: any, propertiesTypeInfo: any, blocklyToolbox: any): void;
35
+ initialize(visualizationHandler: VisualizationHandler, visualizationShell: VisualizationShell, scriptCommandsTypeInfo: any, propertiesTypeInfo: any, blocklyToolbox: any, commandDescriptions?: Record<string, ScriptCommandHelp>): void;
34
36
  set instanceServiceContainer(value: InstanceServiceContainer);
35
37
  protected _createControlsForScript(eventItem: eventWithDesignItem): any;
36
38
  protected _getScriptName(eventItem: IEvent): any;
@@ -75,13 +75,15 @@ export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
75
75
  _visualizationShell;
76
76
  _scriptCommandsTypeInfo;
77
77
  _propertiesTypeInfo;
78
+ _commandDescriptions;
78
79
  events;
79
- initialize(visualizationHandler, visualizationShell, scriptCommandsTypeInfo, propertiesTypeInfo, blocklyToolbox) {
80
+ initialize(visualizationHandler, visualizationShell, scriptCommandsTypeInfo, propertiesTypeInfo, blocklyToolbox, commandDescriptions) {
80
81
  this._visualizationHandler = visualizationHandler;
81
82
  this._visualizationShell = visualizationShell;
82
83
  this._scriptCommandsTypeInfo = scriptCommandsTypeInfo;
83
84
  this._propertiesTypeInfo = propertiesTypeInfo;
84
85
  this._blocklyToolbox = blocklyToolbox;
86
+ this._commandDescriptions = commandDescriptions;
85
87
  }
86
88
  set instanceServiceContainer(value) {
87
89
  this._instanceServiceContainer = value;
@@ -375,9 +377,12 @@ export class EventAssignment extends BaseCustomWebComponentConstructorAppend {
375
377
  sc.propertiesTypeInfo = this._propertiesTypeInfo;
376
378
  sc.visualizationShell = this._visualizationShell;
377
379
  sc.visualizationHandler = this._visualizationHandler;
380
+ if (this._commandDescriptions) {
381
+ sc.commandDescriptions = { ...sc.commandDescriptions, ...this._commandDescriptions };
382
+ }
378
383
  sc.loadScript(script);
379
384
  sc.title = "Script '" + eventItem.name + "' on " + eventItem.designItem.name;
380
- let res = await this._visualizationShell.openConfirmation(sc, { x: 100, y: 100, width: 600, height: 500 });
385
+ let res = await this._visualizationShell.openConfirmation(sc, { title: sc.title, width: 600, height: 500 });
381
386
  if (res) {
382
387
  let scriptCommands = sc.getScriptCommands();
383
388
  if (scriptCommands && scriptCommands.length) {
@@ -0,0 +1,25 @@
1
+ import { BaseCustomWebComponentConstructorAppend, TypedEvent } from "@node-projects/base-custom-webcomponent";
2
+ import { ScriptCommandHelp } from "../scripting/ScriptCommandsDescriptions.js";
3
+ export declare class SimpleScriptCommandPicker extends BaseCustomWebComponentConstructorAppend {
4
+ static readonly style: CSSStyleSheet;
5
+ static readonly template: HTMLTemplateElement;
6
+ static readonly is = "node-projects-visualization-simple-script-command-picker";
7
+ private _title;
8
+ get title(): string;
9
+ set title(value: string);
10
+ selectedType: string;
11
+ commandTypeChosen: TypedEvent<void>;
12
+ closeRequested: TypedEvent<void>;
13
+ private _tree;
14
+ private _filter;
15
+ private _descriptionDiv;
16
+ private _addBtn;
17
+ private _typeInfo;
18
+ private _descriptions;
19
+ constructor();
20
+ ready(): Promise<void>;
21
+ addClicked(): void;
22
+ closeClicked(): void;
23
+ private _renderDescription;
24
+ loadCommands(scriptCommandsTypeInfo: any, descriptions?: Record<string, ScriptCommandHelp>): void;
25
+ }
@@ -0,0 +1,271 @@
1
+ import { BaseCustomWebComponentConstructorAppend, TypedEvent, css, html } from "@node-projects/base-custom-webcomponent";
2
+ import { defaultOptions, defaultStyle } from "@node-projects/web-component-designer-widgets-wunderbaum";
3
+ import { Wunderbaum } from 'wunderbaum';
4
+ //@ts-ignore
5
+ import wunderbaumStyle from 'wunderbaum/dist/wunderbaum.css' with { type: 'css' };
6
+ import { highlightJson } from "../scripting/JsonSnippetHighlighter.js";
7
+ export class SimpleScriptCommandPicker extends BaseCustomWebComponentConstructorAppend {
8
+ static style = css `
9
+ :host {
10
+ display: block;
11
+ background: white;
12
+ }
13
+
14
+ .root {
15
+ width: calc(100% - 8px);
16
+ height: calc(100% - 8px);
17
+ margin: 4px;
18
+ box-sizing: border-box;
19
+ display: flex;
20
+ flex-direction: column;
21
+ }
22
+
23
+ #filter {
24
+ width: 100%;
25
+ height: 26px;
26
+ box-sizing: border-box;
27
+ }
28
+
29
+ .content {
30
+ flex: 1 1 auto;
31
+ min-height: 0;
32
+ display: flex;
33
+ }
34
+
35
+ #commandList {
36
+ width: 40%;
37
+ overflow: auto;
38
+ box-sizing: border-box;
39
+ }
40
+
41
+ #description {
42
+ width: 60%;
43
+ }
44
+
45
+ .detail {
46
+ padding: 8px;
47
+ overflow: auto;
48
+ box-sizing: border-box;
49
+ }
50
+
51
+ .cmd-title {
52
+ font-size: 14px;
53
+ font-weight: bold;
54
+ color: #24405c;
55
+ border-bottom: 2px solid #2c6e9b;
56
+ padding-bottom: 4px;
57
+ margin-bottom: 6px;
58
+ }
59
+
60
+ .cmd-title .hint {
61
+ font-size: 11px;
62
+ font-weight: normal;
63
+ color: #808080;
64
+ margin-left: 6px;
65
+ }
66
+
67
+ .snippet {
68
+ font-family: Consolas, "Courier New", monospace;
69
+ font-size: 11px;
70
+ background: #f6f8fa;
71
+ color: #24292e;
72
+ border: 1px solid #e1e4e8;
73
+ border-radius: 4px;
74
+ padding: 6px 10px;
75
+ white-space: pre;
76
+ overflow-x: auto;
77
+ line-height: 1.5;
78
+ }
79
+
80
+ .cs-key { color: #22863a; }
81
+ .cs-str { color: #032f62; }
82
+ .cs-bool { color: #d73a49; }
83
+ .cs-num { color: #e36209; }
84
+
85
+ .note {
86
+ font-size: 11px;
87
+ color: #666;
88
+ font-style: italic;
89
+ margin-top: 6px;
90
+ }
91
+
92
+ .toolbar {
93
+ display: flex;
94
+ align-items: center;
95
+ gap: 8px;
96
+ box-sizing: border-box;
97
+ flex: 0 0 auto;
98
+ width: 100%;
99
+ height: 40px;
100
+ padding: 4px 8px;
101
+ border-top: 1px solid #ccc;
102
+ background-color: rgb(230, 230, 230);
103
+ }
104
+
105
+ .toolbar button {
106
+ box-sizing: border-box;
107
+ padding: 6px 16px;
108
+ border-radius: 4px;
109
+ border: 1px solid #b0b0b0;
110
+ background: white;
111
+ font-size: 12px;
112
+ cursor: pointer;
113
+ }
114
+
115
+ .toolbar button:hover:not(:disabled) {
116
+ background: #f0f0f0;
117
+ border-color: #909090;
118
+ }
119
+
120
+ .toolbar button:active:not(:disabled) {
121
+ background: #e2e2e2;
122
+ }
123
+
124
+ .toolbar button:disabled {
125
+ opacity: 0.5;
126
+ cursor: not-allowed;
127
+ }
128
+
129
+ .toolbar button.primary {
130
+ background: #2c6e9b;
131
+ border-color: #2c6e9b;
132
+ color: white;
133
+ }
134
+
135
+ .toolbar button.primary:hover:not(:disabled) {
136
+ background: #255d83;
137
+ border-color: #255d83;
138
+ }
139
+
140
+ .toolbar button.primary:active:not(:disabled) {
141
+ background: #1e4d6b;
142
+ }
143
+
144
+ .toolbar .spacer {
145
+ flex: 1 1 auto;
146
+ }
147
+
148
+ .toolbar .hint {
149
+ font-size: 11px;
150
+ font-style: italic;
151
+ color: #666;
152
+ }
153
+ `;
154
+ static template = html `
155
+ <div class="root">
156
+ <input id="filter" placeholder="Filter..." autocomplete="off">
157
+ <div class="content">
158
+ <div id="commandList"></div>
159
+ <div id="description" class="detail"></div>
160
+ </div>
161
+ <div class="toolbar">
162
+ <button id="addBtn" class="primary" disabled @click="[[this.addClicked()]]">Add</button>
163
+ <span class="hint">or drag a command into the script list</span>
164
+ <span class="spacer"></span>
165
+ <button id="closeBtn" @click="[[this.closeClicked()]]">Close</button>
166
+ </div>
167
+ </div>
168
+ `;
169
+ static is = 'node-projects-visualization-simple-script-command-picker';
170
+ _title;
171
+ get title() {
172
+ return this._title;
173
+ }
174
+ set title(value) {
175
+ this._title = value;
176
+ }
177
+ selectedType;
178
+ commandTypeChosen = new TypedEvent();
179
+ closeRequested = new TypedEvent();
180
+ _tree;
181
+ _filter;
182
+ _descriptionDiv;
183
+ _addBtn;
184
+ _typeInfo;
185
+ _descriptions;
186
+ constructor() {
187
+ super();
188
+ this._restoreCachedInititalValues();
189
+ this.shadowRoot.adoptedStyleSheets = [wunderbaumStyle, defaultStyle, SimpleScriptCommandPicker.style];
190
+ this._descriptionDiv = this._getDomElement('description');
191
+ this._addBtn = this._getDomElement('addBtn');
192
+ this._filter = this._getDomElement('filter');
193
+ this._filter.onkeyup = () => {
194
+ const match = this._filter.value;
195
+ this._tree.filterNodes((node) => new RegExp(match, "i").test(node.title), {});
196
+ };
197
+ this._tree = new Wunderbaum({
198
+ ...defaultOptions,
199
+ element: this._getDomElement('commandList'),
200
+ icon: false,
201
+ filter: {
202
+ autoExpand: true,
203
+ mode: 'hide',
204
+ highlight: true
205
+ },
206
+ activate: (e) => {
207
+ this.selectedType = e.node.title;
208
+ this._addBtn.disabled = false;
209
+ this._renderDescription(e.node.title);
210
+ },
211
+ dblclick: (e) => {
212
+ this.selectedType = e.node.title;
213
+ this.commandTypeChosen.emit();
214
+ return false;
215
+ },
216
+ render: (e) => {
217
+ if (e.isNew) {
218
+ e.nodeElem.oncontextmenu = (ev) => {
219
+ ev.preventDefault();
220
+ return false;
221
+ };
222
+ }
223
+ },
224
+ dnd: {
225
+ guessDropEffect: false,
226
+ serializeClipboardData: true,
227
+ dragStart: (e) => {
228
+ e.event.dataTransfer.effectAllowed = 'copy';
229
+ e.event.dataTransfer.dropEffect = 'copy';
230
+ return true;
231
+ }
232
+ }
233
+ });
234
+ }
235
+ async ready() {
236
+ this._parseAttributesToProperties();
237
+ this._bindingsParse(null, true);
238
+ this._assignEvents();
239
+ }
240
+ addClicked() {
241
+ if (this.selectedType)
242
+ this.commandTypeChosen.emit();
243
+ }
244
+ closeClicked() {
245
+ this.closeRequested.emit();
246
+ }
247
+ _renderDescription(type) {
248
+ const help = this._descriptions?.[type];
249
+ if (help) {
250
+ this._descriptionDiv.innerHTML = `
251
+ <div class="cmd-title">${type}<span class="hint">${help.description}</span></div>
252
+ <pre class="snippet">${highlightJson(help.example)}</pre>
253
+ ${help.note ? `<div class="note">${help.note}</div>` : ''}
254
+ `;
255
+ return;
256
+ }
257
+ const schemaDescription = this._typeInfo?.definitions?.[type]?.description;
258
+ this._descriptionDiv.innerHTML = `
259
+ <div class="cmd-title">${type}</div>
260
+ ${schemaDescription ? `<div class="note">${schemaDescription}</div>` : ''}
261
+ `;
262
+ }
263
+ loadCommands(scriptCommandsTypeInfo, descriptions) {
264
+ this._typeInfo = scriptCommandsTypeInfo;
265
+ this._descriptions = descriptions ?? {};
266
+ const names = Object.keys(scriptCommandsTypeInfo.definitions)
267
+ .filter(x => scriptCommandsTypeInfo.definitions[x].type === 'object' && x !== 'ScriptCommands');
268
+ this._tree.root.addChildren(names.map(n => ({ title: n })));
269
+ }
270
+ }
271
+ customElements.define(SimpleScriptCommandPicker.is, SimpleScriptCommandPicker);
@@ -1,29 +1,45 @@
1
- import { BaseCustomWebComponentConstructorAppend } from "@node-projects/base-custom-webcomponent";
1
+ import { BaseCustomWebComponentConstructorAppend, TypedEvent } from "@node-projects/base-custom-webcomponent";
2
2
  import { Script } from "../scripting/Script.js";
3
3
  import { InstanceServiceContainer, ServiceContainer } from "@node-projects/web-component-designer";
4
+ import { ScriptCommandHelp } from "../scripting/ScriptCommandsDescriptions.js";
4
5
  import { VisualizationHandler } from "../interfaces/VisualizationHandler.js";
5
6
  import { VisualizationShell } from "../interfaces/VisualizationShell.js";
6
- import '@node-projects/splitview.webcomponent';
7
+ import "@node-projects/splitview.webcomponent";
7
8
  export declare class SimpleScriptEditor extends BaseCustomWebComponentConstructorAppend {
8
9
  static readonly style: CSSStyleSheet;
9
10
  static readonly template: HTMLTemplateElement;
10
11
  static readonly is = "node-projects-visualization-simple-script-editor";
12
+ private _title;
13
+ get title(): string;
14
+ set title(value: string);
11
15
  serviceContainer: ServiceContainer;
12
16
  instanceServiceContainer: InstanceServiceContainer;
13
17
  visualizationHandler: VisualizationHandler;
14
18
  visualizationShell: VisualizationShell;
15
19
  scriptCommandsTypeInfo: any;
16
20
  propertiesTypeInfo: any;
21
+ helpRequested: TypedEvent<void>;
22
+ commandDescriptions: Record<string, ScriptCommandHelp>;
17
23
  private _script;
18
24
  private _commandListDiv;
19
25
  private _commandListFancyTree;
20
- private _possibleCommands;
21
26
  private _propertygrid;
27
+ private _splitView;
28
+ private _codeView;
29
+ private _codeToggleBtn;
30
+ private _addCommandBtn;
31
+ private _showingCode;
32
+ private _dragFromHandle;
33
+ private _draggedNode;
22
34
  constructor();
23
35
  ready(): Promise<void>;
24
- private addPossibleCommands;
36
+ helpClicked(): void;
37
+ toggleCodeView(): void;
38
+ private _showCodeView;
39
+ /** Parses+validates the code view's JSON. Returns null (and alerts) on invalid JSON. */
40
+ private _parseCodeViewScript;
25
41
  loadScript(script: Script): void;
26
42
  private createTreeItem;
27
- addItem(): void;
43
+ addCommand(): Promise<void>;
28
44
  getScriptCommands(): any[];
29
45
  }