@datagrok/compute 0.2.7 → 0.4.1

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.
@@ -0,0 +1,507 @@
1
+ import * as grok from 'datagrok-api/grok';
2
+ import * as ui from 'datagrok-api/ui';
3
+ import * as DG from 'datagrok-api/dg';
4
+ import CodeMirror from 'codemirror';
5
+ import 'codemirror/lib/codemirror.css';
6
+ import {_package} from '../package';
7
+
8
+ const enum FUNC_PROPS_FIELDS {
9
+ NAME = 'name',
10
+ DESCRIPTION = 'description',
11
+ LANGUAGE = 'language',
12
+ HELP_URL = 'helpUrl',
13
+ REFERENCE = 'reference',
14
+ LOGIN = 'author?.login',
15
+ SAMPLE = 'sample',
16
+ ENVIRONMENT = 'environment',
17
+ TAGS = 'tags'
18
+ };
19
+
20
+ const obligatoryFuncProps = ['name', 'description', 'helpUrl', 'language'];
21
+
22
+ const functionPropsLabels = (key: FUNC_PROPS_FIELDS) => {
23
+ switch (key) {
24
+ case FUNC_PROPS_FIELDS.NAME: return 'Name';
25
+ case FUNC_PROPS_FIELDS.DESCRIPTION: return 'Description';
26
+ case FUNC_PROPS_FIELDS.LOGIN: return 'Author';
27
+ case FUNC_PROPS_FIELDS.HELP_URL: return 'Help URL';
28
+ case FUNC_PROPS_FIELDS.LANGUAGE: return 'Language';
29
+ case FUNC_PROPS_FIELDS.REFERENCE: return 'Reference';
30
+ case FUNC_PROPS_FIELDS.SAMPLE: return 'Sample';
31
+ case FUNC_PROPS_FIELDS.ENVIRONMENT: return 'Environment';
32
+ case FUNC_PROPS_FIELDS.TAGS: return 'Tags';
33
+ }
34
+ };
35
+
36
+ const functionPropsCode = (key: FUNC_PROPS_FIELDS) => {
37
+ switch (key) {
38
+ case FUNC_PROPS_FIELDS.NAME: return 'name';
39
+ case FUNC_PROPS_FIELDS.DESCRIPTION: return 'description';
40
+ case FUNC_PROPS_FIELDS.LOGIN: return 'author';
41
+ case FUNC_PROPS_FIELDS.HELP_URL: return 'helpUrl';
42
+ case FUNC_PROPS_FIELDS.LANGUAGE: return 'language';
43
+ case FUNC_PROPS_FIELDS.REFERENCE: return 'reference';
44
+ case FUNC_PROPS_FIELDS.SAMPLE: return 'sample';
45
+ case FUNC_PROPS_FIELDS.ENVIRONMENT: return 'environment';
46
+ case FUNC_PROPS_FIELDS.TAGS: return 'tags';
47
+ }
48
+ };
49
+
50
+ type FuncPropsState = {
51
+ [FUNC_PROPS_FIELDS.NAME]: string | null,
52
+ [FUNC_PROPS_FIELDS.DESCRIPTION]: string | null,
53
+ [FUNC_PROPS_FIELDS.LANGUAGE]: string | null,
54
+ [FUNC_PROPS_FIELDS.HELP_URL]: string | null,
55
+ [FUNC_PROPS_FIELDS.REFERENCE]: string | null,
56
+ [FUNC_PROPS_FIELDS.LOGIN]: string | null,
57
+ [FUNC_PROPS_FIELDS.SAMPLE]: string | null,
58
+ [FUNC_PROPS_FIELDS.ENVIRONMENT]: string | null,
59
+ [FUNC_PROPS_FIELDS.TAGS]: string | null,
60
+ }
61
+
62
+ const funcParamTypes = [
63
+ DG.TYPE.BOOL,
64
+ DG.TYPE.COLUMN_LIST,
65
+ DG.TYPE.COLUMN,
66
+ DG.TYPE.DATA_FRAME,
67
+ DG.TYPE.DATE_TIME,
68
+ DG.TYPE.FLOAT,
69
+ DG.TYPE.GRAPHICS,
70
+ DG.TYPE.INT,
71
+ DG.TYPE.STRING,
72
+ ];
73
+
74
+ const enum FUNC_PARAM_FIELDS {
75
+ DIRECTION = 'direction',
76
+ TYPE = 'propertyType',
77
+ NAME = 'name',
78
+ DEFAULT_VALUE = 'defaultValue',
79
+ DESCRIPTION = 'description',
80
+ CATEGORY = 'category',
81
+ };
82
+
83
+ const enum DIRECTION {
84
+ INPUT= 'input',
85
+ OUTPUT= 'output',
86
+ }
87
+
88
+ const functionParamsLabels = (key: FUNC_PARAM_FIELDS) => {
89
+ switch (key) {
90
+ case FUNC_PARAM_FIELDS.DIRECTION: return 'Direction';
91
+ case FUNC_PARAM_FIELDS.TYPE: return 'Type';
92
+ case FUNC_PARAM_FIELDS.NAME: return 'Name';
93
+ case FUNC_PARAM_FIELDS.DEFAULT_VALUE: return 'Default value';
94
+ case FUNC_PARAM_FIELDS.DESCRIPTION: return 'Description';
95
+ case FUNC_PARAM_FIELDS.CATEGORY: return 'Category';
96
+ }
97
+ };
98
+
99
+ enum COMMON_TAG_NAME {
100
+ VALIDATORS = 'validators',
101
+ CAPTION = 'caption',
102
+ POSTFIX = 'postfix',
103
+ UNITS = 'units'
104
+ }
105
+
106
+ enum OPTIONAL_TAG_NAME {
107
+ COLUMNS = 'columns',
108
+ CATEGORICAL = 'categorical',
109
+ TYPE = 'type',
110
+ FORMAT = 'format',
111
+ ALLOW_NULLS = 'allowNulls',
112
+ ACTION = 'action',
113
+ CHOICES = 'choices',
114
+ SUGGESTIONS = 'suggestions',
115
+ SEM_TYPE = 'semType'
116
+ }
117
+
118
+ type DF_TAG_NAME = COMMON_TAG_NAME | OPTIONAL_TAG_NAME.COLUMNS | OPTIONAL_TAG_NAME.CATEGORICAL;
119
+ type COLUMN_TAG_NAME = COMMON_TAG_NAME |
120
+ OPTIONAL_TAG_NAME.TYPE | OPTIONAL_TAG_NAME.FORMAT |
121
+ OPTIONAL_TAG_NAME.ALLOW_NULLS | OPTIONAL_TAG_NAME.ACTION | OPTIONAL_TAG_NAME.SEM_TYPE
122
+
123
+ type STRING_TAG_NAME = COMMON_TAG_NAME |
124
+ OPTIONAL_TAG_NAME.CHOICES | OPTIONAL_TAG_NAME.SUGGESTIONS
125
+
126
+ const DF_TAG_NAMES = [...Object.values(COMMON_TAG_NAME), OPTIONAL_TAG_NAME.COLUMNS, OPTIONAL_TAG_NAME.CATEGORICAL];
127
+ const COLUMN_TAG_NAMES = [...Object.values(COMMON_TAG_NAME), OPTIONAL_TAG_NAME.TYPE, OPTIONAL_TAG_NAME.FORMAT,
128
+ OPTIONAL_TAG_NAME.ALLOW_NULLS, OPTIONAL_TAG_NAME.ACTION, OPTIONAL_TAG_NAME.SEM_TYPE];
129
+ const STRING_TAG_NAMES = [...Object.values(COMMON_TAG_NAME), OPTIONAL_TAG_NAME.CHOICES, OPTIONAL_TAG_NAME.SUGGESTIONS];
130
+
131
+ type FuncParamBase = {
132
+ direction: DIRECTION,
133
+ name?: string,
134
+ defaultValue?: string,
135
+ description?: string
136
+ }
137
+
138
+ type FuncParam =
139
+ FuncParamBase & {
140
+ type: DG.TYPE.BOOL | DG.TYPE.DATE_TIME | DG.TYPE.FLOAT | DG.TYPE.GRAPHICS | DG.TYPE.INT
141
+ options?: {tag: COMMON_TAG_NAME, value: string}[]
142
+ } | FuncParamBase & {
143
+ type: DG.TYPE.DATA_FRAME,
144
+ options?: {tag: DF_TAG_NAME, value: string}[]
145
+ } | FuncParamBase & {
146
+ type: DG.TYPE.COLUMN_LIST | DG.TYPE.COLUMN,
147
+ options?: {tag: COLUMN_TAG_NAME, value: string}[]
148
+ } | FuncParamBase & {
149
+ type: DG.TYPE.STRING
150
+ options?: {tag: STRING_TAG_NAME, value: string}[]
151
+ }
152
+
153
+ const generateParamLine = (param: DG.Property, direction: string) => {
154
+ const optionTags = `{${
155
+ COLUMN_TAG_NAMES
156
+ .map((tag) => {
157
+ console.log(param.name, tag, param.options(), (param.options() as any)[tag]);
158
+ return {tag: tag, val: (param.options() as any)[tag]};
159
+ })
160
+ .filter((value) => !!value.val)
161
+ .map(({tag, val}) => `${tag}:${val}`)
162
+ .join('; ')
163
+ }}`;
164
+ const result =`#${direction}: ${param.propertyType} ${param.name || ''} ${param.defaultValue ? `= ${param.defaultValue}` : ''} ${optionTags} ${param.description ? ` [${param.description}]` : ''}\n`;
165
+ return result;
166
+ };
167
+
168
+ export function _functionEditor(functionCode: string) {
169
+ const inputScript = DG.Script.create(functionCode);
170
+
171
+ const editorView = DG.View.create();
172
+ editorView.name = 'Function Editor';
173
+
174
+ const functionPropsCopy: FuncPropsState = {
175
+ [FUNC_PROPS_FIELDS.NAME]: inputScript.name || null,
176
+ [FUNC_PROPS_FIELDS.DESCRIPTION]: inputScript.description || null,
177
+ [FUNC_PROPS_FIELDS.LANGUAGE]: inputScript.language || null,
178
+ [FUNC_PROPS_FIELDS.HELP_URL]: inputScript.helpUrl || null,
179
+ [FUNC_PROPS_FIELDS.REFERENCE]: inputScript.reference || null,
180
+ [FUNC_PROPS_FIELDS.LOGIN]: inputScript.author?.login || null,
181
+ [FUNC_PROPS_FIELDS.SAMPLE]: inputScript.sample || null,
182
+ [FUNC_PROPS_FIELDS.ENVIRONMENT]: inputScript.environment || null,
183
+ [FUNC_PROPS_FIELDS.TAGS]: inputScript.tags?.join(' ') || null,
184
+ };
185
+
186
+ const getNewProps = () => {
187
+ const newProps = [];
188
+ for (const key of Object.keys(functionPropsCopy)) {
189
+ if (functionPropsCopy[key as keyof FuncPropsState] == null) {
190
+ newProps.push(key);
191
+ }
192
+ }
193
+ return newProps;
194
+ };
195
+
196
+ let addButton = ui.div();
197
+ let propsForm = ui.div();
198
+ let inputs = ui.div();
199
+
200
+ const renderAddPropButton = () => {
201
+ if (!getNewProps().length) return ui.div();
202
+
203
+ const onItemClick = (item: string) => {
204
+ functionPropsCopy[item as keyof FuncPropsState] = '';
205
+ const newInputs = ui.inputs(
206
+ Object.keys(functionPropsCopy)
207
+ .filter((prop) => functionPropsCopy[prop as keyof FuncPropsState] !== null)
208
+ .map((prop) => addFullWidthInput(
209
+ ui.stringInput(
210
+ functionPropsLabels(prop as keyof FuncPropsState),
211
+ functionPropsCopy[prop as keyof FuncPropsState] || ''), prop,
212
+ )),
213
+ );
214
+ inputs.replaceWith(newInputs);
215
+ inputs = newInputs;
216
+ refreshPreview();
217
+ const newAddButton = renderAddPropButton();
218
+ addButton.replaceWith(newAddButton);
219
+ addButton = newAddButton;
220
+ };
221
+ const menu = DG.Menu.popup().items(getNewProps(), onItemClick);
222
+
223
+ const shevron = ui.iconFA('chevron-down');
224
+ const button = ui.button([ui.icons.add(()=>{}), shevron], () => {
225
+ menu.show();
226
+ });
227
+
228
+ const div = ui.div([button]);
229
+ div.style.cssText += 'margin-left: 152px';
230
+ return div;
231
+ };
232
+
233
+ const addFullWidthInput = (input: DG.InputBase, propName: string) => {
234
+ (input.root.lastChild as HTMLElement).style.cssText+='width: 400px; max-width: inherit;';
235
+ input.onInput(() => {
236
+ functionPropsCopy[propName as keyof typeof functionPropsCopy] = input.stringValue;
237
+ refreshPreview();
238
+ });
239
+ (input.root as HTMLInputElement).placeholder = 'Enter your value...';
240
+ input.root.append(ui.button(ui.icons.delete(()=>{}), () => {
241
+ functionPropsCopy[propName as keyof typeof functionPropsCopy] = null;
242
+ refreshPreview();
243
+ input.root.remove();
244
+ const newAddButton = renderAddPropButton();
245
+ addButton.replaceWith(newAddButton);
246
+ addButton = newAddButton;
247
+ }));
248
+ (input.root.lastChild as HTMLElement).style.cssText+='display: inline-flex; justify-content: center; flex-direction: column';
249
+ if (obligatoryFuncProps.includes(propName)) {
250
+ input.root.style.cssText += 'padding-right: 35.375px';
251
+ (input.root.lastChild as HTMLElement).style.cssText+='display: none;';
252
+ }
253
+ return input;
254
+ };
255
+
256
+ const functionPropsForm = () => {
257
+ addButton = renderAddPropButton();
258
+
259
+ inputs = ui.inputs(
260
+ Object.keys(functionPropsCopy)
261
+ .filter((prop) => !!functionPropsCopy[prop as keyof FuncPropsState])
262
+ .map((prop) => addFullWidthInput(
263
+ ui.stringInput(
264
+ functionPropsLabels(prop as keyof FuncPropsState),
265
+ functionPropsCopy[prop as keyof FuncPropsState] || ''), prop,
266
+ )),
267
+ );
268
+ return ui.panel([
269
+ ui.divV([
270
+ inputs,
271
+ addButton,
272
+ ]),
273
+ ]);
274
+ };
275
+
276
+ let functionInputParamsCopy = inputScript.inputs;
277
+ let functionOutputParamsCopy = inputScript.outputs;
278
+
279
+ const iconsByTypes = (type: DG.TYPE) => {
280
+ switch (type) {
281
+ case DG.TYPE.BOOL: return ui.iconImage(DG.TYPE.BOOL, `${_package.webRoot}/icons/Bool.svg`);
282
+ case DG.TYPE.COLUMN_LIST: return ui.iconImage(DG.TYPE.BOOL, `${_package.webRoot}/icons/Column-list.svg`);
283
+ case DG.TYPE.COLUMN: return ui.iconImage(DG.TYPE.COLUMN, `${_package.webRoot}/icons/Column.svg`);
284
+ case DG.TYPE.DATA_FRAME: return ui.iconImage(DG.TYPE.DATA_FRAME, `${_package.webRoot}/icons/Dataframe.svg`);
285
+ case DG.TYPE.DATE_TIME: return ui.iconImage(DG.TYPE.COLUMN, `${_package.webRoot}/icons/Datetime.svg`);
286
+ case DG.TYPE.FLOAT: return ui.iconImage(DG.TYPE.FLOAT, `${_package.webRoot}/icons/Double.svg`);
287
+ case DG.TYPE.GRAPHICS: return ui.iconImage(DG.TYPE.GRAPHICS, `${_package.webRoot}/icons/Graphics.svg`);
288
+ case DG.TYPE.INT: return ui.iconImage(DG.TYPE.FLOAT, `${_package.webRoot}/icons/Int.svg`);
289
+ case DG.TYPE.STRING: return ui.iconImage(DG.TYPE.STRING, `${_package.webRoot}/icons/String.svg`);
290
+ default: return ui.iconImage('Blob', `${_package.webRoot}/icons/Blob.svg`);
291
+ }
292
+ };
293
+
294
+ const onFunctionParamClick = (paramName: string, card: HTMLElement, direction: DIRECTION) => {
295
+ const acc = ui.accordion();
296
+ acc.root.style.cssText += 'min-width: 400px';
297
+
298
+ acc.addPane('General', ()=> {
299
+ let paramIndex: number;
300
+ let param: DG.Property;
301
+
302
+ if (direction === DIRECTION.INPUT) {
303
+ paramIndex = functionInputParamsCopy.findIndex((input) => input.name === paramName);
304
+ param = functionInputParamsCopy[paramIndex];
305
+ } else {
306
+ paramIndex= functionOutputParamsCopy.findIndex((input) => input.name === paramName);
307
+ param = functionOutputParamsCopy[paramIndex];
308
+ }
309
+
310
+ if (!param) return ui.div('');
311
+
312
+ const updateCard = (propName: string, v: any) => {
313
+ (param as any)[propName] = v;
314
+ const newCard = renderCard(param, direction);
315
+ card.replaceWith(newCard);
316
+ card = newCard;
317
+ refreshPreview();
318
+ };
319
+
320
+ const funcParams: DG.Property[] = [
321
+ (() => {
322
+ const temp = DG.Property.create(FUNC_PARAM_FIELDS.DIRECTION, DG.TYPE.STRING, (x: any) => x[FUNC_PARAM_FIELDS.DIRECTION], (x: any, v) => updateCard(FUNC_PARAM_FIELDS.DIRECTION, v), '');
323
+ temp.options({choices: ['input', 'output']});
324
+ return temp;
325
+ })(),
326
+ (() => {
327
+ const temp = DG.Property.create(FUNC_PARAM_FIELDS.TYPE, DG.TYPE.STRING, (x: any) => x[FUNC_PARAM_FIELDS.TYPE], (x: any, v) => updateCard(FUNC_PARAM_FIELDS.TYPE, v), '');
328
+ temp.options({choices: funcParamTypes});
329
+ return temp;
330
+ })(),
331
+ DG.Property.create(FUNC_PARAM_FIELDS.NAME, DG.TYPE.STRING, (x: any) => x[FUNC_PARAM_FIELDS.NAME], (x: any, v) => updateCard(FUNC_PARAM_FIELDS.NAME, v), ''),
332
+ DG.Property.create(FUNC_PARAM_FIELDS.DEFAULT_VALUE, DG.TYPE.STRING, (x: any) => x[FUNC_PARAM_FIELDS.DEFAULT_VALUE], (x: any, v) => updateCard(FUNC_PARAM_FIELDS.DEFAULT_VALUE, v), ''),
333
+ (() => {
334
+ const temp = DG.Property.create(FUNC_PARAM_FIELDS.DESCRIPTION, DG.TYPE.STRING, (x: any) => x[FUNC_PARAM_FIELDS.DESCRIPTION], (x: any, v) => updateCard(FUNC_PARAM_FIELDS.DESCRIPTION, v), '');
335
+ temp.options({editor: 'textarea'});
336
+ return temp;
337
+ })(),
338
+ DG.Property.create(FUNC_PARAM_FIELDS.CATEGORY, DG.TYPE.STRING, (x: any) => x[FUNC_PARAM_FIELDS.CATEGORY], (x: any, v) => updateCard(FUNC_PARAM_FIELDS.CATEGORY, v), ''),
339
+ ];
340
+
341
+ const paramProps = funcParams
342
+ .filter((param) => param.name !== FUNC_PARAM_FIELDS.DIRECTION);
343
+
344
+ const result = ui.input.form(param, paramProps);
345
+
346
+ return ui.div(result);
347
+ });
348
+
349
+ acc.addPane('Tags', ()=> {
350
+ return ui.div();
351
+ });
352
+
353
+ grok.shell.o = ui.divV([ui.h1(`Param: ${paramName}`), acc.root]);
354
+ };
355
+
356
+ const funcParams: DG.Property[] = [
357
+ DG.Property.jsString(FUNC_PARAM_FIELDS.DIRECTION),
358
+ DG.Property.jsString(FUNC_PARAM_FIELDS.TYPE),
359
+ DG.Property.jsString(FUNC_PARAM_FIELDS.NAME),
360
+ DG.Property.jsString(FUNC_PARAM_FIELDS.DEFAULT_VALUE),
361
+ DG.Property.jsString(FUNC_PARAM_FIELDS.DESCRIPTION),
362
+ DG.Property.jsString(FUNC_PARAM_FIELDS.CATEGORY),
363
+ ];
364
+
365
+
366
+ const renderCard = (functionParam: DG.Property, direction: DIRECTION) => {
367
+ const iconStyle = {style: {
368
+ 'display': 'flex',
369
+ 'flex-direction': 'column',
370
+ 'justify-content': 'center',
371
+ 'width': '32.5px',
372
+ 'align-items': 'center',
373
+ }};
374
+
375
+ const editButtonDiv = ui.div(ui.button(ui.icons.edit(()=>{}), () =>{
376
+ onFunctionParamClick(functionParam.name, tempCard, direction);
377
+ }), {
378
+ style: {
379
+ ...iconStyle.style,
380
+ 'visibility': 'hidden',
381
+ },
382
+ });
383
+
384
+ const tempCard = ui.divH([
385
+ ui.div(iconsByTypes(functionParam.propertyType), iconStyle),
386
+ ui.divV([
387
+ ui.span([functionParam.name], {style: {'font-weight': 'bold'}}),
388
+ ui.span([funcParams
389
+ .filter((param) => param.name !== FUNC_PARAM_FIELDS.NAME)
390
+ .map((param) => (functionParam as any)[param.name])
391
+ .filter((paramValue) => !!paramValue).join(' | '),
392
+ ]),
393
+ ], {style: {'width': '100%', 'padding': '5px'}}),
394
+ editButtonDiv,
395
+ ui.div(ui.button(ui.icons.delete(()=>{}), () =>{
396
+ if (direction === DIRECTION.INPUT) {
397
+ functionInputParamsCopy = functionInputParamsCopy.filter((param) => param !== functionParam);
398
+ } else {
399
+ functionOutputParamsCopy = functionOutputParamsCopy.filter((param) => param !== functionParam);
400
+ }
401
+ refreshPreview();
402
+ tempCard.remove();
403
+ }), iconStyle),
404
+ ], {style: {'border-bottom': 'thin solid #ECEFF2'}});
405
+ tempCard.addEventListener('click', () => onFunctionParamClick(functionParam.name, tempCard, direction));
406
+ tempCard.addEventListener('mouseover', () => editButtonDiv.style.visibility = 'visible');
407
+ tempCard.addEventListener('mouseout', () => editButtonDiv.style.visibility = 'hidden');
408
+ return tempCard;
409
+ };
410
+
411
+ let inputParamCards = ui.divV(
412
+ functionInputParamsCopy.map((functionParam) => renderCard(functionParam, DIRECTION.INPUT)),
413
+ );
414
+ const outputParamCards = ui.divV(
415
+ functionOutputParamsCopy.map((functionParam) => renderCard(functionParam, DIRECTION.OUTPUT)),
416
+ );
417
+
418
+ const area = ui.textInput('', '');
419
+ const myCM = CodeMirror.fromTextArea((area.input as HTMLTextAreaElement));
420
+
421
+ const previewDiv = ui.panel([ui.divV([ui.h1('Code preview'), area])]);
422
+ previewDiv.style.flexGrow = '1';
423
+
424
+ propsForm = functionPropsForm();
425
+
426
+ const renderAddParamButton = () => {
427
+ const paramProps = funcParams
428
+ .filter((param) => param.name !== FUNC_PARAM_FIELDS.DIRECTION);
429
+
430
+ const newParam: DG.PropertyOptions = {};
431
+
432
+ const onItemClick = () => {
433
+ ui.dialog('Add parameter')
434
+ .add(ui.input.form(newParam, paramProps))
435
+ .onOK(() => {
436
+ functionInputParamsCopy.push(DG.Property.fromOptions(newParam));
437
+ const newInputParamsCards = ui.divV(
438
+ functionInputParamsCopy.map((functionParam) => renderCard(functionParam, DIRECTION.INPUT)),
439
+ );
440
+ inputParamCards.replaceWith(newInputParamsCards);
441
+ inputParamCards = newInputParamsCards;
442
+ refreshPreview();
443
+ })
444
+ .show();
445
+ };
446
+
447
+ const menu = DG.Menu.popup().items(funcParamTypes, onItemClick);
448
+
449
+ const shevron = ui.iconFA('chevron-down');
450
+ const button = ui.button([ui.icons.add(()=>{}), shevron], () => {
451
+ menu.show();
452
+ });
453
+
454
+ const div = ui.div([button]);
455
+ return div;
456
+ };
457
+ const addInputButton = renderAddParamButton();
458
+ const addOutputButton = renderAddParamButton();
459
+
460
+ const tabs = ui.tabControl({
461
+ 'PROPERTIES': propsForm,
462
+ 'PARAMETERS': ui.divV([
463
+ ui.div(ui.h1('Input: '), {style: {'padding': '12px 12px 0px 12px'}}),
464
+ inputParamCards,
465
+ addInputButton,
466
+ ui.div(ui.h1('Output: '), {style: {'padding': '12px 12px 0px 12px'}}),
467
+ outputParamCards,
468
+ addOutputButton,
469
+ ]),
470
+ });
471
+ tabs.root.style.width = '100%';
472
+ tabs.root.style.flexGrow = '3';
473
+
474
+ editorView.append(
475
+ ui.divV([
476
+ tabs,
477
+ previewDiv,
478
+ ]),
479
+ );
480
+ editorView.box = true;
481
+ editorView.setRibbonPanels([
482
+ [
483
+ ui.iconFA('eye', () => {
484
+ previewDiv.hidden ? previewDiv.hidden = false : previewDiv.hidden = true;
485
+ }),
486
+ ui.bigButton('Save', () => grok.shell.info('plus')),
487
+ ],
488
+ ]);
489
+
490
+ const refreshPreview = () => {
491
+ let result = '';
492
+ Object.keys(functionPropsCopy).map((propField) => {
493
+ const propValue = functionPropsCopy[propField as keyof FuncPropsState];
494
+ if (propValue) result += `#${functionPropsCode(propField as keyof FuncPropsState)}: ${propValue}\n`;
495
+ });
496
+ functionInputParamsCopy.map((param) => {
497
+ result += generateParamLine(param, DIRECTION.INPUT);
498
+ });
499
+ functionOutputParamsCopy.map((param) => {
500
+ result += generateParamLine(param, DIRECTION.OUTPUT);
501
+ });
502
+ myCM.setValue(result);
503
+ };
504
+
505
+ grok.shell.addView(editorView);
506
+ refreshPreview();
507
+ }