@hpcc-js/other 3.4.8 → 3.4.10

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,758 +1,758 @@
1
- import { HTMLWidget } from "@hpcc-js/common";
2
- import * as Persist from "./Persist.ts";
3
-
4
- import "../src/ThemeEditor.css";
5
-
6
- function hasLocalStorage(): boolean {
7
- const mod = "@hpcc-js/other";
8
- try {
9
- localStorage.setItem(mod, mod);
10
- localStorage.removeItem(mod);
11
- return true;
12
- } catch (e) {
13
- return false;
14
- }
15
- }
16
-
17
- // Polyfill for IE in file:// mode ----
18
- const _localStorage: { getItem: (id: string) => any; } = hasLocalStorage() ? localStorage : {
19
- getItem(id: string): any {
20
- return undefined;
21
- }
22
- };
23
-
24
- const getThemes = function (idx?) {
25
- if (typeof ((window as any).g_defaultThemes) === "function") {
26
- (window as any).g_defaultThemes(idx);
27
- }
28
- return JSON.parse(_localStorage.getItem("themeEditorThemes") || "{}");
29
- };
30
- const getSerials = function (idx?) {
31
- if (typeof ((window as any).g_defaultSerials) === "function") {
32
- (window as any).g_defaultSerials(idx);
33
- }
34
- return JSON.parse(_localStorage.getItem("themeEditorSerials") || "{}");
35
- };
36
- const getThemeNames = function (idx?) {
37
- const loadedThemes = getThemes();
38
- let themes = [];
39
- for (const themeName in loadedThemes) {
40
- themes.push(themeName);
41
- }
42
- if (typeof (idx) !== "undefined" && typeof (themes[idx]) !== "undefined") {
43
- themes = themes[idx];
44
- }
45
- return themes;
46
- };
47
- const getSerialNames = function (idx?) {
48
- const loadedSerials = getSerials();
49
- let serials = [];
50
- for (const serialName in loadedSerials) {
51
- serials.push(serialName);
52
- }
53
- if (typeof (idx) !== "undefined" && typeof (serials[idx]) !== "undefined") {
54
- serials = serials[idx];
55
- }
56
- return serials;
57
- };
58
- const tableNeedsRedraw = function (context) {
59
- let needsRedraw = false;
60
- if (typeof (context._current_grouping) === "undefined") {
61
- context._current_grouping = context._group_params_by;
62
- } else if (context._current_grouping !== context._group_params_by) {
63
- needsRedraw = true;
64
- }
65
- if (typeof (context._showing_columns) === "undefined") {
66
- context._showing_columns = context.showColumns();
67
- } else if (context._showing_columns !== context.showColumns()) {
68
- needsRedraw = true;
69
- }
70
- if (typeof (context._showing_data) === "undefined") {
71
- context._showing_data = context.showData();
72
- } else if (context._showing_data !== context.showData()) {
73
- needsRedraw = true;
74
- }
75
- return needsRedraw;
76
- };
77
- const camelizeString = function (str) {
78
- const spacedText = str.split(/(?=[0-9A-Z])/).map(function (n) { return n.length > 1 ? n + " " : n; }).join("");
79
- return spacedText.replace(/(?:^|\s)\S/g, function (a) { return a.toUpperCase(); });
80
- };
81
-
82
- const tableInputHtml = function (rowObj, value, widgetArr, idSuffix) {
83
- let inputHtml = "";
84
- let id = "te-input-" + rowObj.id + "-" + idSuffix;
85
-
86
- let inputType;
87
- if (typeof (rowObj.ext) !== "undefined" && typeof (rowObj.ext.inputType) !== "undefined") {
88
- inputType = rowObj.ext.inputType;
89
- }
90
-
91
- if (typeof (rowObj.inputID) !== "undefined") {
92
- id = rowObj.inputID;
93
- }
94
-
95
- const dataWIDs = "data-paramid='" + rowObj.id + "' data-wids='" + widgetArr.map(function (w) {
96
- if (typeof (w.widget) === "object") {
97
- return w.widget._id;
98
- } else {
99
- return w;
100
- }
101
- }).join(",") + "'";
102
- switch (rowObj.type) {
103
- case "boolean":
104
- const checked = value ? " checked" : "";
105
- inputHtml = "<input id='" + id + "' " + dataWIDs + " type='checkbox' class='te-checkbox te-input'" + checked + ">"; break;
106
- case "number":
107
- if (typeof (inputType) !== "undefined") {
108
- if (inputType === "textarea") {
109
- inputHtml = "<textarea id='" + id + "' class='te-textarea te-input' " + dataWIDs + ">" + value + "</textarea>";
110
- } else if (inputType === "range") {
111
- inputHtml = "<input id='" + id + "' class='te-input' type='range' " + dataWIDs + " value='" + value + "' min='" + rowObj.ext.min + "' max='" + rowObj.ext.max + "' step='" + rowObj.ext.step + "'>";
112
- }
113
- } else {
114
- inputHtml = "<input id='" + id + "' type='text' class='te-text te-input' " + dataWIDs + " value='" + value + "'>";
115
- }
116
- break;
117
- case "string":
118
- if (typeof (inputType) !== "undefined") {
119
- if (inputType === "textarea") {
120
- inputHtml = "<textarea id='" + id + "' class='te-textarea te-input' " + dataWIDs + ">" + value + "</textarea>";
121
- }
122
- } else {
123
- inputHtml = "<input id='" + id + "' type='text' class='te-text te-input' value='" + value + "' " + dataWIDs + ">";
124
- }
125
- break;
126
- case "html-color":
127
- const valueAttr = value === "" ? "" : " value='" + value + "'";
128
- inputHtml = "<input id='" + id + "' type='text' class='te-html-color-input te-input' " + dataWIDs + " " + valueAttr + ">";
129
- inputHtml += "<input type='color' class='te-html-color-button te-input' " + dataWIDs + " " + valueAttr + ">";
130
- break;
131
- case "set":
132
- const options = _options(rowObj, value);
133
- inputHtml = "<select id='" + id + "' class='te-select te-input'" + dataWIDs + ">" + options + "</select>";
134
- break;
135
- case "array":
136
- inputHtml = "<textarea id='" + id + "' class='te-textarea te-input' data-type='array' " + dataWIDs + ">" + value + "</textarea>";
137
- break;
138
- default:
139
- break;
140
- }
141
- if (typeof (rowObj.ext.saveButton) !== "undefined") {
142
- inputHtml += "<button id='" + rowObj.ext.saveButtonID + "'>" + rowObj.ext.saveButton + "</button>";
143
- }
144
- return inputHtml;
145
-
146
- function _options(obj, val) {
147
- let options = "";
148
- obj.set.forEach(function (s) {
149
- const selected = s === val ? " selected" : "";
150
- options += "<option value='" + s + "'" + selected + ">" + s + "</option>";
151
- });
152
- return options;
153
- }
154
- };
155
-
156
- export class ThemeEditor extends HTMLWidget {
157
- _current_grouping;
158
- _showing_columns;
159
- _showing_data;
160
- _contentEditors;
161
- _showSettings;
162
- _defaultThemes;
163
- _widgetObjsById;
164
- _sharedProperties;
165
- getThemes;
166
- getSerials;
167
- getDefaultThemes;
168
- getDefaultSerials;
169
-
170
- constructor() {
171
- super();
172
-
173
- this._tag = "div";
174
- this._current_grouping = undefined;
175
- this._showing_columns = undefined;
176
- this._showing_data = undefined;
177
- this.columns(["Key", "Value"]);
178
- this._contentEditors = [];
179
- this._showSettings = true;
180
-
181
- this._defaultThemes = [];
182
-
183
- this._widgetObjsById = {};
184
- }
185
-
186
- showSettings(_?) {
187
- if (!arguments.length) {
188
- return this._showSettings;
189
- }
190
- this._showSettings = _;
191
- return this;
192
- }
193
-
194
- onChange(widget, propID) { }
195
-
196
- enter(domNode, element) {
197
- super.enter(domNode, element);
198
- this._placeholderElement.style("overflow", "auto");
199
- }
200
-
201
- widgetProperty(widget, propID, _?) {
202
- if (_ === undefined) {
203
- return widget[propID]();
204
- }
205
- return widget[propID](_);
206
- }
207
-
208
- load(elmValue) { }
209
-
210
- save(themeName) { }
211
-
212
- needsPropTableRedraw() {
213
- const ret = document.getElementById("te-themeEditorOptions") === null;
214
- return ret;
215
- }
216
-
217
- update(domNode, element) {
218
- super.update(domNode, element);
219
- if (tableNeedsRedraw(this)) {
220
- element.selectAll("#" + this._id + " > table").remove();
221
- }
222
- this._current_grouping = this.paramGrouping();
223
- this._widgetObjsById[this._id] = this;
224
- this._sharedProperties = this.findSharedProperties(this.data());
225
-
226
- const needsPropertiesTableRedraw = this.needsPropTableRedraw();
227
- if (needsPropertiesTableRedraw && this.showSettings()) {
228
- const teParams = Persist.discover(this);
229
- for (const i in teParams) {
230
- if (teParams[i].ext.tags.indexOf(this.editorComplexity()) !== -1) {
231
- const teParamVal = this[teParams[i].id]();
232
- if (teParams[i].id === "loadedTheme" || teParams[i].id === "loadedSerial") {
233
- teParams[i].inputID = "te-load-theme";
234
- }
235
- teParams[i].input = tableInputHtml(teParams[i], teParamVal, [this._id], this._id);
236
- } else {
237
- delete teParams[i];
238
- }
239
- }
240
- domNode.innerHTML = this.propertiesTableHtml(teParams);
241
- const evt = document.createEvent("Events");
242
- evt.initEvent("TE Properties Ready", true, true);
243
- document.dispatchEvent(evt);
244
- }
245
-
246
- this.buildTableObjects(domNode, this._sharedProperties);
247
-
248
- this.initFunctionality(domNode);
249
- }
250
-
251
- exit(domNode, element) {
252
- super.exit(domNode, element);
253
- }
254
-
255
- click(d) {
256
- }
257
-
258
- propertiesTableHtml(editorParams) {
259
- const tableObj = {
260
- id: "te-themeEditorOptions",
261
- label: "Editor Options",
262
- rowArr: []
263
- };
264
- const modeTableObj = {
265
- id: "te-tableModeOptions",
266
- label: this.themeMode() ? "Save/Load Theme" : "Save/Load Serial",
267
- rowArr: []
268
- };
269
- for (const i in editorParams) {
270
- if (this.themeMode()) {
271
- if (editorParams[i].ext.tags.indexOf("Theme") === -1 && editorParams[i].ext.tags.indexOf("Serial") === -1) {
272
- tableObj.rowArr.push({
273
- th: camelizeString(editorParams[i].id),
274
- td: editorParams[i].input,
275
- trClass: "propertyRow"
276
- });
277
- } else if (editorParams[i].ext.tags.indexOf("Theme") !== -1) {
278
- modeTableObj.rowArr.push({
279
- th: camelizeString(editorParams[i].id),
280
- td: editorParams[i].input,
281
- trClass: "propertyRow"
282
- });
283
- }
284
- } else {
285
- if (editorParams[i].ext.tags.indexOf("Serial") === -1 && editorParams[i].ext.tags.indexOf("Theme") === -1) {
286
- tableObj.rowArr.push({
287
- th: camelizeString(editorParams[i].id),
288
- td: editorParams[i].input,
289
- trClass: "propertyRow"
290
- });
291
- } else if (editorParams[i].ext.tags.indexOf("Serial") !== -1) {
292
- modeTableObj.rowArr.push({
293
- th: camelizeString(editorParams[i].id),
294
- td: editorParams[i].input,
295
- trClass: "propertyRow"
296
- });
297
- }
298
- }
299
-
300
- }
301
- let html = "";
302
- if (tableObj.rowArr.length > 0) {
303
- html += this.tableObjHtml(tableObj);
304
- }
305
- if (modeTableObj.rowArr.length > 0) {
306
- html += this.tableObjHtml(modeTableObj);
307
- }
308
- return html;
309
- }
310
- buildTableObjects(targetElement, propObjs) {
311
- let sectionObjs = {};
312
- if (this.themeMode()) {
313
- sectionObjs = {
314
- chartColorSection: {
315
- id: "te-colorOptions",
316
- label: "Chart Colors",
317
- rowObjArr: []
318
- },
319
- surfaceSection: {
320
- id: "te-containerOptions",
321
- label: "Container Styles/Colors",
322
- rowObjArr: []
323
- },
324
- fontSection: {
325
- id: "te-fontOptions",
326
- label: "Font Styles/Colors",
327
- rowObjArr: []
328
- }
329
- };
330
- } else {
331
- sectionObjs = {
332
- nonSurfaceSection: {
333
- id: "te-chartOptions",
334
- label: "Chart Properties",
335
- rowObjArr: []
336
- }
337
- };
338
- }
339
- for (const p in propObjs) {
340
- if (this.themeMode()) {
341
- if (p.toUpperCase().indexOf("FONT") !== -1 && !(propObjs[p].arr[0].widget._class.indexOf("layout_Surface") !== -1 && p.toUpperCase().indexOf("COLOR") !== -1)) {
342
- sectionObjs["fontSection"].rowObjArr.push(propObjs[p]);
343
- } else if (p === "paletteID") {
344
- sectionObjs["chartColorSection"].rowObjArr.push(propObjs[p]);
345
- } else if (propObjs[p].arr[0].widget._class.indexOf("layout_Surface") !== -1) {
346
- sectionObjs["surfaceSection"].rowObjArr.push(propObjs[p]);
347
- }
348
- } else {
349
- if (propObjs[p].arr[0].widget._class.indexOf("layout_Surface") === -1) {
350
- sectionObjs["nonSurfaceSection"].rowObjArr.push(propObjs[p]);
351
- }
352
- }
353
- }
354
- let html = "";
355
- for (const i in sectionObjs) {
356
- html += this.sharedPropertyTableHtml(sectionObjs[i]);
357
- }
358
- targetElement.innerHTML += html;
359
- }
360
-
361
- initFunctionality(elm) {
362
- const context = this;
363
- _expandCollapse(elm);
364
- _inputOnChange(elm);
365
- _inputOnClick(elm);
366
- function _inputOnClick(elm2) {
367
- if (context.showSettings()) {
368
- const saveBtn = document.getElementById("te-save-button");
369
- saveBtn.onclick = function (e) {
370
- const clickedElm: any = e.target;
371
- const themeName = clickedElm.previousSibling.value;
372
- if (themeName.length > 1) {
373
- const loadSelect = document.getElementById("te-load-theme");
374
- const loadOptions = loadSelect.getElementsByTagName("option");
375
- let saveExists = false;
376
- for (const i in loadOptions) {
377
- const val = loadOptions[i].value;
378
- if (val === themeName) {
379
- saveExists = true;
380
- }
381
- }
382
- if (!saveExists) {
383
- loadSelect.innerHTML += "<option value='" + themeName + "'>" + themeName + "</option>";
384
- }
385
- clickedElm.previousSibling.value = "";
386
- (loadSelect as any).value = themeName;
387
- } else {
388
- alert("Save Name cannot be empty.");
389
- }
390
- };
391
- }
392
- }
393
- function _inputOnChange(elm2) {
394
- const teInputs = elm2.getElementsByClassName("te-input");
395
- for (const i in teInputs) {
396
- if (isNaN(parseInt(i))) break;
397
- const inputElm = teInputs[i];
398
- const inputID = inputElm.getAttribute("id");
399
- if (inputID === "te-load-theme") {
400
- inputElm.onchange = function (e) {
401
- const elm3 = e.srcElement;
402
- context.load(elm3.value);
403
- };
404
- } else if (inputID !== null && inputID.indexOf("te-input-themeMode") !== -1) {
405
- inputElm.onchange = function (e) {
406
- const elm3 = e.srcElement;
407
- context.themeMode(elm3.checked);
408
-
409
- const name = document.getElementById("te-load-theme");
410
- const nameToLoad = name !== null ? (name as any).value : "Default";
411
- context.load(nameToLoad);
412
- };
413
- } else if (inputElm.tagName === "INPUT" || inputElm.tagName === "SELECT" || inputElm.tagName === "TEXTAREA") {
414
- inputElm.onchange = function (e) {
415
- const elm3 = e.srcElement;
416
-
417
- let id = elm3.getAttribute("id");
418
-
419
- if (elm3.className.split(" ").indexOf("te-html-color-button") !== -1) {
420
- id = elm3.previousSibling.getAttribute("id");
421
- elm3.previousSibling.value = elm3.value;
422
- }
423
- const elmType = elm3.getAttribute("type");
424
- const splitId = id.split("-");
425
- const genericId = splitId.slice(0, splitId.length - 1).join("-") + "-";
426
-
427
- const widsStr = elm3.getAttribute("data-wids");
428
- const paramId = elm3.getAttribute("data-paramid");
429
- const widArr = widsStr.split(",");
430
- widArr.forEach(function (wid) {
431
- const individualId = genericId + wid;
432
- const indElm = document.getElementById(individualId);
433
- if (elmType === "checkbox") {
434
- (indElm as any).checked = elm3.checked;
435
- context._widgetObjsById[wid][paramId](elm3.checked);
436
- } else if (elm3.getAttribute("data-type") === "array") {
437
- (indElm as any).value = elm3.value;
438
- try {
439
- context._widgetObjsById[wid][paramId](JSON.parse(elm3.value));
440
- } catch (e) { }
441
- } else {
442
- (indElm as any).value = elm3.value;
443
- context._widgetObjsById[wid][paramId](elm3.value);
444
-
445
- if (indElm.className.split(" ").indexOf("te-html-color-input") !== -1) {
446
- (indElm.nextSibling as any).value = elm3.value;
447
- } else if (indElm.className.split(" ").indexOf("te-html-color-button") !== -1) {
448
- (indElm.previousSibling as any).value = elm3.value;
449
- }
450
- }
451
- });
452
- context.data().forEach(function (d) {
453
- d.render();
454
- });
455
- };
456
- }
457
- }
458
- }
459
- function _expandCollapse(elm2) {
460
- const tableArr = elm2.getElementsByClassName("te-section-table");
461
- for (const i in tableArr) {
462
- if (typeof (tableArr[i].getElementsByTagName) === "function") {
463
- const thead = tableArr[i].getElementsByTagName("thead");
464
- thead[0].onclick = function (e) {
465
- let elm3 = e.toElement;
466
- if (elm3.tagName === "TH") {
467
- elm3 = elm3.parentElement.parentElement;
468
- }
469
- const parent = elm3.parentElement;
470
- let tbodyClass = "";
471
- if (parent.className.split(" ").indexOf("expanded") === -1) {
472
- parent.className = "te-section-table expanded";
473
- tbodyClass = "shown";
474
- } else {
475
- parent.className = "te-section-table collapsed";
476
- tbodyClass = "hidden";
477
- }
478
- const tbody = parent.getElementsByTagName("tbody");
479
- tbody[0].className = tbodyClass;
480
- };
481
- }
482
- }
483
- const sharedRowArr = elm2.getElementsByClassName("sharedPropertyRow");
484
- for (const n in sharedRowArr) {
485
- if (typeof (sharedRowArr[n].getElementsByClassName) === "function") {
486
- const label = sharedRowArr[n].getElementsByClassName("te-label");
487
- label[0].onclick = function (e) {
488
- const elm3 = e.toElement;
489
- const parent = elm3.parentElement;
490
- let subRowClass = "";
491
- if (parent.className.split(" ").indexOf("expanded") === -1) {
492
- parent.className = "sharedPropertyRow expanded";
493
- subRowClass = "shown";
494
- } else {
495
- parent.className = "sharedPropertyRow collapsed";
496
- subRowClass = "hidden";
497
- }
498
- let nextSib = parent.nextSibling;
499
- while (nextSib !== null) {
500
- if (nextSib.className.split(" ").indexOf("sharedPropertyRow") === -1) {
501
- nextSib.className = "propertyRow " + subRowClass;
502
- nextSib = nextSib.nextSibling;
503
- } else {
504
- nextSib = null;
505
- }
506
- }
507
- };
508
- }
509
- }
510
- }
511
- }
512
- sharedPropertyTableHtml(sectionObj) {
513
- const tableObj = {
514
- id: sectionObj.id,
515
- label: sectionObj.label,
516
- rowArr: []
517
- };
518
- sectionObj.rowObjArr.forEach(function (rowObj) {
519
- rowObj.arr.forEach(function (widgetObj, widgetIdx) {
520
- if (widgetIdx === 0) {
521
- tableObj.rowArr.push({
522
- th: _sharedPropertyLabel(rowObj),
523
- td: _sharedPropertyInput(rowObj),
524
- trClass: "sharedPropertyRow collapsed"
525
- });
526
- }
527
- tableObj.rowArr.push({
528
- th: _propertyLabel(widgetObj),
529
- td: _propertyInput(rowObj, widgetIdx),
530
- trClass: "propertyRow hidden"
531
- });
532
- });
533
- });
534
-
535
- return this.tableObjHtml(tableObj);
536
-
537
- function _propertyLabel(widgetObj) {
538
- const splitClass = widgetObj.widget.classID().split("_");
539
- const displayClass = splitClass.join("/");
540
- return displayClass + " <i>[" + widgetObj.widget._id + "]</i>";
541
- }
542
- function _sharedPropertyLabel(rowObj) {
543
- return camelizeString(rowObj.id);
544
- }
545
-
546
- function _propertyInput(rowObj, idx) {
547
- const value = _value(rowObj, idx);
548
- const html = tableInputHtml(rowObj, value, [rowObj.arr[idx]], rowObj.arr[idx].widget._id);
549
- return html;
550
-
551
- function _value(rowObj2, idx2) {
552
- const value2 = rowObj2.arr[idx2].widget[rowObj2.id]();
553
- return value2 !== null ? value2 : "";
554
- }
555
- }
556
- function _sharedPropertyInput(rowObj) {
557
- const value = _sharedValue(rowObj);
558
- const html = tableInputHtml(rowObj, value, rowObj.arr, "shared");
559
- return html;
560
-
561
- function _sharedValue(rowObj2) {
562
- const value2 = rowObj2.arr[0].widget[rowObj2.id]();
563
- rowObj2.arr.forEach(function (w, i) {
564
- if (value2 !== w.widget[w.id]()) {
565
- return "";
566
- }
567
- });
568
- if (value2 !== null) {
569
- if (rowObj2.type === "array") {
570
- return JSON.stringify(value2);
571
- }
572
- return value2;
573
- }
574
- return "";
575
- }
576
- }
577
- }
578
-
579
- tableObjHtml(tableObj) {
580
- let html = "<table id='" + tableObj.id + "' class='te-section-table expanded'>";
581
- html += "<thead><tr><th colspan='2'>" + tableObj.label + "</th></tr></thead>";
582
- html += "<tbody>";
583
- tableObj.rowArr.forEach(function (rowObj) {
584
- html += this.tableRowObjHtml(rowObj);
585
- }, this);
586
- html += "</tbody>";
587
- return html + "</table>";
588
- }
589
- tableRowObjHtml(rowObj) {
590
- let html = typeof (rowObj.trClass) !== "undefined" ? "<tr class='" + rowObj.trClass + "'>" : "<tr>";
591
- html += "<th class='te-label'>" + rowObj.th + "</th>";
592
- html += "<td>" + rowObj.td + "</td>";
593
- return html + "</tr>";
594
- }
595
-
596
- setWidgetObjsById(widgetProp) {
597
- const context = this;
598
- const val = widgetProp.widget[widgetProp.id]();
599
- if (widgetProp.type === "widgetArray") {
600
- val.forEach(function (widget) {
601
- context._widgetObjsById[widget._id] = widget;
602
- });
603
- } else if (widgetProp.type === "widget" && val !== null) {
604
- this._widgetObjsById[val._id] = val;
605
- }
606
- }
607
- checkTagFilter(tagArr) {
608
- const allowTags = ["Basic"];
609
- let ret = false;
610
- tagArr.forEach(function (tag) {
611
- if (allowTags.indexOf(tag) !== -1) {
612
- ret = true;
613
- }
614
- });
615
- return ret;
616
- }
617
- findSharedProperties(data) {
618
- const context = this;
619
- let propsByID;
620
- if (typeof (data) !== "undefined" && data.length > 0) {
621
- let allProps = [];
622
- propsByID = {};
623
- const surfacePropsByID = {};
624
- const nonSurfacePropsByID = {};
625
- data.forEach(function (widget) {
626
- const gpResponse = _getParams(widget, 0);
627
- allProps = allProps.concat(gpResponse);
628
- });
629
- allProps.forEach(function (prop) {
630
- if (["widget", "widgetArray"].indexOf(prop.type) !== -1) {
631
- context.setWidgetObjsById(prop);
632
- } else if (context.checkTagFilter(prop.ext.tags)) {
633
- const tempIdx = prop.id;
634
- if (prop.widget._class.indexOf("Surface") !== -1) {
635
- if (typeof (surfacePropsByID[tempIdx]) === "undefined") {
636
- surfacePropsByID[tempIdx] = { arr: [] };
637
- }
638
- surfacePropsByID[tempIdx].id = prop.id;
639
- surfacePropsByID[tempIdx].description = prop.description;
640
- surfacePropsByID[tempIdx].type = prop.type;
641
- surfacePropsByID[tempIdx].set = prop.set;
642
- surfacePropsByID[tempIdx].ext = prop.ext;
643
- surfacePropsByID[tempIdx].arr.push(prop);
644
- } else {
645
- if (typeof (nonSurfacePropsByID[tempIdx]) === "undefined") {
646
- nonSurfacePropsByID[tempIdx] = { arr: [] };
647
- }
648
- nonSurfacePropsByID[tempIdx].id = prop.id;
649
- nonSurfacePropsByID[tempIdx].description = prop.description;
650
- nonSurfacePropsByID[tempIdx].type = prop.type;
651
- nonSurfacePropsByID[tempIdx].set = prop.set;
652
- nonSurfacePropsByID[tempIdx].ext = prop.ext;
653
- nonSurfacePropsByID[tempIdx].arr.push(prop);
654
- }
655
- if (typeof (propsByID[tempIdx]) === "undefined") {
656
- propsByID[tempIdx] = { arr: [] };
657
- }
658
- propsByID[tempIdx].id = prop.id;
659
- propsByID[tempIdx].description = prop.description;
660
- propsByID[tempIdx].type = prop.type;
661
- propsByID[tempIdx].set = prop.set;
662
- propsByID[tempIdx].ext = prop.ext;
663
- propsByID[tempIdx].arr.push(prop);
664
- }
665
- });
666
- }
667
- return propsByID;
668
-
669
- function _getParams(widgetObj, depth) {
670
- let retArr = [];
671
- if (widgetObj !== null) {
672
- const paramArr = Persist.discover(widgetObj);
673
- paramArr.forEach(function (param, i1) {
674
- if (typeof (param.ext.tags) !== "undefined") {
675
- retArr.push({
676
- id: param.id,
677
- type: param.type,
678
- description: param.description,
679
- set: param.set,
680
- ext: param.ext,
681
- widget: widgetObj
682
- });
683
- }
684
- if (param.type === "widgetArray") {
685
- const childWidgetArray = context.widgetProperty(widgetObj, param.id);
686
- childWidgetArray.forEach(function (childWidget) {
687
- const cwArr = _getParams(childWidget, depth + 1);
688
- retArr = retArr.concat(cwArr);
689
- });
690
- } else if (param.type === "widget") {
691
- const childWidget = context.widgetProperty(widgetObj, param.id);
692
- const temp = _getParams(childWidget, depth + 1);
693
- retArr = retArr.concat(temp);
694
- }
695
- });
696
- }
697
- return retArr;
698
- }
699
- }
700
- }
701
- ThemeEditor.prototype._class += " other_ThemeEditor";
702
-
703
- export interface ThemeEditor {
704
- themeMode(): boolean;
705
- themeMode(_: boolean): this;
706
- themeMode_exists(): boolean;
707
- saveTheme(): string;
708
- saveTheme(_: string): this;
709
- saveTheme_exists(): boolean;
710
- loadedTheme(): string;
711
- loadedTheme(_: string): this;
712
- loadedTheme_exists(): boolean;
713
- saveSerial(): string;
714
- saveSerial(_: string): this;
715
- saveSerial_exists(): boolean;
716
- loadedSerial(): string;
717
- loadedSerial(_: string): this;
718
- loadedSerial_exists(): boolean;
719
- showColumns(): boolean;
720
- showColumns(_: boolean): this;
721
- showColumns_exists(): boolean;
722
- showData(): boolean;
723
- showData(_: boolean): this;
724
- showData_exists(): boolean;
725
- shareCountMin(): number;
726
- shareCountMin(_: number): this;
727
- shareCountMin_exists(): boolean;
728
- paramGrouping(): string;
729
- paramGrouping(_: string): this;
730
- paramGrouping_exists(): boolean
731
- editorComplexity(): string;
732
- editorComplexity(_: string): this;
733
- editorComplexity_exists(): boolean;
734
- sectionTitle(): string;
735
- sectionTitle(_: string): this;
736
- sectionTitle_exists(): boolean;
737
- collapsibleSections(): boolean;
738
- collapsibleSections(_: boolean): this;
739
- collapsibleSections_exists(): boolean;
740
- }
741
-
742
- ThemeEditor.prototype.publish("themeMode", true, "boolean", "Edit default values", null, { tags: ["Basic"] });
743
- ThemeEditor.prototype.publish("saveTheme", "", "string", "Save Theme", null, { tags: ["Basic", "Theme"], saveButton: "Save", saveButtonID: "te-save-button" });
744
- ThemeEditor.prototype.publish("loadedTheme", getThemeNames(1), "set", "Loaded Theme", getThemeNames(), { tags: ["Basic", "Theme"] });
745
- ThemeEditor.prototype.publish("saveSerial", "", "string", "Save Serial", null, { tags: ["Basic", "Serial"], saveButton: "Save", saveButtonID: "te-save-button" });
746
- ThemeEditor.prototype.publish("loadedSerial", getSerialNames(0), "set", "Loaded Serial", getSerialNames(), { tags: ["Basic", "Serial"] });
747
- ThemeEditor.prototype.publish("showColumns", true, "boolean", "Show Columns", null, { tags: ["Intermediate"] });
748
- ThemeEditor.prototype.publish("showData", true, "boolean", "Show Data", null, { tags: ["Intermediate"] });
749
- ThemeEditor.prototype.publish("shareCountMin", 1, "number", "Share Count Min", null, { tags: ["Private"] });
750
- ThemeEditor.prototype.publish("paramGrouping", "By Param", "set", "Param Grouping", ["By Param", "By Widget"], { tags: ["Private"] });
751
- ThemeEditor.prototype.publish("editorComplexity", "Basic", "set", "Choose what publish properties to display within the editor.", ["Basic", "Intermediate", "Advanced", "Private"], { tags: ["Private"] });
752
- ThemeEditor.prototype.publish("sectionTitle", "", "string", "Section Title", null, { tags: ["Private"] });
753
- ThemeEditor.prototype.publish("collapsibleSections", true, "boolean", "Collapsible Sections", null, { tags: ["Intermediate"] });
754
-
755
- ThemeEditor.prototype.getThemes = getThemes;
756
- ThemeEditor.prototype.getSerials = getSerials;
757
- ThemeEditor.prototype.getDefaultThemes = getThemeNames;
758
- ThemeEditor.prototype.getDefaultSerials = getSerialNames;
1
+ import { HTMLWidget } from "@hpcc-js/common";
2
+ import * as Persist from "./Persist.ts";
3
+
4
+ import "../src/ThemeEditor.css";
5
+
6
+ function hasLocalStorage(): boolean {
7
+ const mod = "@hpcc-js/other";
8
+ try {
9
+ localStorage.setItem(mod, mod);
10
+ localStorage.removeItem(mod);
11
+ return true;
12
+ } catch (e) {
13
+ return false;
14
+ }
15
+ }
16
+
17
+ // Polyfill for IE in file:// mode ----
18
+ const _localStorage: { getItem: (id: string) => any; } = hasLocalStorage() ? localStorage : {
19
+ getItem(id: string): any {
20
+ return undefined;
21
+ }
22
+ };
23
+
24
+ const getThemes = function (idx?) {
25
+ if (typeof ((window as any).g_defaultThemes) === "function") {
26
+ (window as any).g_defaultThemes(idx);
27
+ }
28
+ return JSON.parse(_localStorage.getItem("themeEditorThemes") || "{}");
29
+ };
30
+ const getSerials = function (idx?) {
31
+ if (typeof ((window as any).g_defaultSerials) === "function") {
32
+ (window as any).g_defaultSerials(idx);
33
+ }
34
+ return JSON.parse(_localStorage.getItem("themeEditorSerials") || "{}");
35
+ };
36
+ const getThemeNames = function (idx?) {
37
+ const loadedThemes = getThemes();
38
+ let themes = [];
39
+ for (const themeName in loadedThemes) {
40
+ themes.push(themeName);
41
+ }
42
+ if (typeof (idx) !== "undefined" && typeof (themes[idx]) !== "undefined") {
43
+ themes = themes[idx];
44
+ }
45
+ return themes;
46
+ };
47
+ const getSerialNames = function (idx?) {
48
+ const loadedSerials = getSerials();
49
+ let serials = [];
50
+ for (const serialName in loadedSerials) {
51
+ serials.push(serialName);
52
+ }
53
+ if (typeof (idx) !== "undefined" && typeof (serials[idx]) !== "undefined") {
54
+ serials = serials[idx];
55
+ }
56
+ return serials;
57
+ };
58
+ const tableNeedsRedraw = function (context) {
59
+ let needsRedraw = false;
60
+ if (typeof (context._current_grouping) === "undefined") {
61
+ context._current_grouping = context._group_params_by;
62
+ } else if (context._current_grouping !== context._group_params_by) {
63
+ needsRedraw = true;
64
+ }
65
+ if (typeof (context._showing_columns) === "undefined") {
66
+ context._showing_columns = context.showColumns();
67
+ } else if (context._showing_columns !== context.showColumns()) {
68
+ needsRedraw = true;
69
+ }
70
+ if (typeof (context._showing_data) === "undefined") {
71
+ context._showing_data = context.showData();
72
+ } else if (context._showing_data !== context.showData()) {
73
+ needsRedraw = true;
74
+ }
75
+ return needsRedraw;
76
+ };
77
+ const camelizeString = function (str) {
78
+ const spacedText = str.split(/(?=[0-9A-Z])/).map(function (n) { return n.length > 1 ? n + " " : n; }).join("");
79
+ return spacedText.replace(/(?:^|\s)\S/g, function (a) { return a.toUpperCase(); });
80
+ };
81
+
82
+ const tableInputHtml = function (rowObj, value, widgetArr, idSuffix) {
83
+ let inputHtml = "";
84
+ let id = "te-input-" + rowObj.id + "-" + idSuffix;
85
+
86
+ let inputType;
87
+ if (typeof (rowObj.ext) !== "undefined" && typeof (rowObj.ext.inputType) !== "undefined") {
88
+ inputType = rowObj.ext.inputType;
89
+ }
90
+
91
+ if (typeof (rowObj.inputID) !== "undefined") {
92
+ id = rowObj.inputID;
93
+ }
94
+
95
+ const dataWIDs = "data-paramid='" + rowObj.id + "' data-wids='" + widgetArr.map(function (w) {
96
+ if (typeof (w.widget) === "object") {
97
+ return w.widget._id;
98
+ } else {
99
+ return w;
100
+ }
101
+ }).join(",") + "'";
102
+ switch (rowObj.type) {
103
+ case "boolean":
104
+ const checked = value ? " checked" : "";
105
+ inputHtml = "<input id='" + id + "' " + dataWIDs + " type='checkbox' class='te-checkbox te-input'" + checked + ">"; break;
106
+ case "number":
107
+ if (typeof (inputType) !== "undefined") {
108
+ if (inputType === "textarea") {
109
+ inputHtml = "<textarea id='" + id + "' class='te-textarea te-input' " + dataWIDs + ">" + value + "</textarea>";
110
+ } else if (inputType === "range") {
111
+ inputHtml = "<input id='" + id + "' class='te-input' type='range' " + dataWIDs + " value='" + value + "' min='" + rowObj.ext.min + "' max='" + rowObj.ext.max + "' step='" + rowObj.ext.step + "'>";
112
+ }
113
+ } else {
114
+ inputHtml = "<input id='" + id + "' type='text' class='te-text te-input' " + dataWIDs + " value='" + value + "'>";
115
+ }
116
+ break;
117
+ case "string":
118
+ if (typeof (inputType) !== "undefined") {
119
+ if (inputType === "textarea") {
120
+ inputHtml = "<textarea id='" + id + "' class='te-textarea te-input' " + dataWIDs + ">" + value + "</textarea>";
121
+ }
122
+ } else {
123
+ inputHtml = "<input id='" + id + "' type='text' class='te-text te-input' value='" + value + "' " + dataWIDs + ">";
124
+ }
125
+ break;
126
+ case "html-color":
127
+ const valueAttr = value === "" ? "" : " value='" + value + "'";
128
+ inputHtml = "<input id='" + id + "' type='text' class='te-html-color-input te-input' " + dataWIDs + " " + valueAttr + ">";
129
+ inputHtml += "<input type='color' class='te-html-color-button te-input' " + dataWIDs + " " + valueAttr + ">";
130
+ break;
131
+ case "set":
132
+ const options = _options(rowObj, value);
133
+ inputHtml = "<select id='" + id + "' class='te-select te-input'" + dataWIDs + ">" + options + "</select>";
134
+ break;
135
+ case "array":
136
+ inputHtml = "<textarea id='" + id + "' class='te-textarea te-input' data-type='array' " + dataWIDs + ">" + value + "</textarea>";
137
+ break;
138
+ default:
139
+ break;
140
+ }
141
+ if (typeof (rowObj.ext.saveButton) !== "undefined") {
142
+ inputHtml += "<button id='" + rowObj.ext.saveButtonID + "'>" + rowObj.ext.saveButton + "</button>";
143
+ }
144
+ return inputHtml;
145
+
146
+ function _options(obj, val) {
147
+ let options = "";
148
+ obj.set.forEach(function (s) {
149
+ const selected = s === val ? " selected" : "";
150
+ options += "<option value='" + s + "'" + selected + ">" + s + "</option>";
151
+ });
152
+ return options;
153
+ }
154
+ };
155
+
156
+ export class ThemeEditor extends HTMLWidget {
157
+ _current_grouping;
158
+ _showing_columns;
159
+ _showing_data;
160
+ _contentEditors;
161
+ _showSettings;
162
+ _defaultThemes;
163
+ _widgetObjsById;
164
+ _sharedProperties;
165
+ getThemes;
166
+ getSerials;
167
+ getDefaultThemes;
168
+ getDefaultSerials;
169
+
170
+ constructor() {
171
+ super();
172
+
173
+ this._tag = "div";
174
+ this._current_grouping = undefined;
175
+ this._showing_columns = undefined;
176
+ this._showing_data = undefined;
177
+ this.columns(["Key", "Value"]);
178
+ this._contentEditors = [];
179
+ this._showSettings = true;
180
+
181
+ this._defaultThemes = [];
182
+
183
+ this._widgetObjsById = {};
184
+ }
185
+
186
+ showSettings(_?) {
187
+ if (!arguments.length) {
188
+ return this._showSettings;
189
+ }
190
+ this._showSettings = _;
191
+ return this;
192
+ }
193
+
194
+ onChange(widget, propID) { }
195
+
196
+ enter(domNode, element) {
197
+ super.enter(domNode, element);
198
+ this._placeholderElement.style("overflow", "auto");
199
+ }
200
+
201
+ widgetProperty(widget, propID, _?) {
202
+ if (_ === undefined) {
203
+ return widget[propID]();
204
+ }
205
+ return widget[propID](_);
206
+ }
207
+
208
+ load(elmValue) { }
209
+
210
+ save(themeName) { }
211
+
212
+ needsPropTableRedraw() {
213
+ const ret = document.getElementById("te-themeEditorOptions") === null;
214
+ return ret;
215
+ }
216
+
217
+ update(domNode, element) {
218
+ super.update(domNode, element);
219
+ if (tableNeedsRedraw(this)) {
220
+ element.selectAll("#" + this._id + " > table").remove();
221
+ }
222
+ this._current_grouping = this.paramGrouping();
223
+ this._widgetObjsById[this._id] = this;
224
+ this._sharedProperties = this.findSharedProperties(this.data());
225
+
226
+ const needsPropertiesTableRedraw = this.needsPropTableRedraw();
227
+ if (needsPropertiesTableRedraw && this.showSettings()) {
228
+ const teParams = Persist.discover(this);
229
+ for (const i in teParams) {
230
+ if (teParams[i].ext.tags.indexOf(this.editorComplexity()) !== -1) {
231
+ const teParamVal = this[teParams[i].id]();
232
+ if (teParams[i].id === "loadedTheme" || teParams[i].id === "loadedSerial") {
233
+ teParams[i].inputID = "te-load-theme";
234
+ }
235
+ teParams[i].input = tableInputHtml(teParams[i], teParamVal, [this._id], this._id);
236
+ } else {
237
+ delete teParams[i];
238
+ }
239
+ }
240
+ domNode.innerHTML = this.propertiesTableHtml(teParams);
241
+ const evt = document.createEvent("Events");
242
+ evt.initEvent("TE Properties Ready", true, true);
243
+ document.dispatchEvent(evt);
244
+ }
245
+
246
+ this.buildTableObjects(domNode, this._sharedProperties);
247
+
248
+ this.initFunctionality(domNode);
249
+ }
250
+
251
+ exit(domNode, element) {
252
+ super.exit(domNode, element);
253
+ }
254
+
255
+ click(d) {
256
+ }
257
+
258
+ propertiesTableHtml(editorParams) {
259
+ const tableObj = {
260
+ id: "te-themeEditorOptions",
261
+ label: "Editor Options",
262
+ rowArr: []
263
+ };
264
+ const modeTableObj = {
265
+ id: "te-tableModeOptions",
266
+ label: this.themeMode() ? "Save/Load Theme" : "Save/Load Serial",
267
+ rowArr: []
268
+ };
269
+ for (const i in editorParams) {
270
+ if (this.themeMode()) {
271
+ if (editorParams[i].ext.tags.indexOf("Theme") === -1 && editorParams[i].ext.tags.indexOf("Serial") === -1) {
272
+ tableObj.rowArr.push({
273
+ th: camelizeString(editorParams[i].id),
274
+ td: editorParams[i].input,
275
+ trClass: "propertyRow"
276
+ });
277
+ } else if (editorParams[i].ext.tags.indexOf("Theme") !== -1) {
278
+ modeTableObj.rowArr.push({
279
+ th: camelizeString(editorParams[i].id),
280
+ td: editorParams[i].input,
281
+ trClass: "propertyRow"
282
+ });
283
+ }
284
+ } else {
285
+ if (editorParams[i].ext.tags.indexOf("Serial") === -1 && editorParams[i].ext.tags.indexOf("Theme") === -1) {
286
+ tableObj.rowArr.push({
287
+ th: camelizeString(editorParams[i].id),
288
+ td: editorParams[i].input,
289
+ trClass: "propertyRow"
290
+ });
291
+ } else if (editorParams[i].ext.tags.indexOf("Serial") !== -1) {
292
+ modeTableObj.rowArr.push({
293
+ th: camelizeString(editorParams[i].id),
294
+ td: editorParams[i].input,
295
+ trClass: "propertyRow"
296
+ });
297
+ }
298
+ }
299
+
300
+ }
301
+ let html = "";
302
+ if (tableObj.rowArr.length > 0) {
303
+ html += this.tableObjHtml(tableObj);
304
+ }
305
+ if (modeTableObj.rowArr.length > 0) {
306
+ html += this.tableObjHtml(modeTableObj);
307
+ }
308
+ return html;
309
+ }
310
+ buildTableObjects(targetElement, propObjs) {
311
+ let sectionObjs = {};
312
+ if (this.themeMode()) {
313
+ sectionObjs = {
314
+ chartColorSection: {
315
+ id: "te-colorOptions",
316
+ label: "Chart Colors",
317
+ rowObjArr: []
318
+ },
319
+ surfaceSection: {
320
+ id: "te-containerOptions",
321
+ label: "Container Styles/Colors",
322
+ rowObjArr: []
323
+ },
324
+ fontSection: {
325
+ id: "te-fontOptions",
326
+ label: "Font Styles/Colors",
327
+ rowObjArr: []
328
+ }
329
+ };
330
+ } else {
331
+ sectionObjs = {
332
+ nonSurfaceSection: {
333
+ id: "te-chartOptions",
334
+ label: "Chart Properties",
335
+ rowObjArr: []
336
+ }
337
+ };
338
+ }
339
+ for (const p in propObjs) {
340
+ if (this.themeMode()) {
341
+ if (p.toUpperCase().indexOf("FONT") !== -1 && !(propObjs[p].arr[0].widget._class.indexOf("layout_Surface") !== -1 && p.toUpperCase().indexOf("COLOR") !== -1)) {
342
+ sectionObjs["fontSection"].rowObjArr.push(propObjs[p]);
343
+ } else if (p === "paletteID") {
344
+ sectionObjs["chartColorSection"].rowObjArr.push(propObjs[p]);
345
+ } else if (propObjs[p].arr[0].widget._class.indexOf("layout_Surface") !== -1) {
346
+ sectionObjs["surfaceSection"].rowObjArr.push(propObjs[p]);
347
+ }
348
+ } else {
349
+ if (propObjs[p].arr[0].widget._class.indexOf("layout_Surface") === -1) {
350
+ sectionObjs["nonSurfaceSection"].rowObjArr.push(propObjs[p]);
351
+ }
352
+ }
353
+ }
354
+ let html = "";
355
+ for (const i in sectionObjs) {
356
+ html += this.sharedPropertyTableHtml(sectionObjs[i]);
357
+ }
358
+ targetElement.innerHTML += html;
359
+ }
360
+
361
+ initFunctionality(elm) {
362
+ const context = this;
363
+ _expandCollapse(elm);
364
+ _inputOnChange(elm);
365
+ _inputOnClick(elm);
366
+ function _inputOnClick(elm2) {
367
+ if (context.showSettings()) {
368
+ const saveBtn = document.getElementById("te-save-button");
369
+ saveBtn.onclick = function (e) {
370
+ const clickedElm: any = e.target;
371
+ const themeName = clickedElm.previousSibling.value;
372
+ if (themeName.length > 1) {
373
+ const loadSelect = document.getElementById("te-load-theme");
374
+ const loadOptions = loadSelect.getElementsByTagName("option");
375
+ let saveExists = false;
376
+ for (const i in loadOptions) {
377
+ const val = loadOptions[i].value;
378
+ if (val === themeName) {
379
+ saveExists = true;
380
+ }
381
+ }
382
+ if (!saveExists) {
383
+ loadSelect.innerHTML += "<option value='" + themeName + "'>" + themeName + "</option>";
384
+ }
385
+ clickedElm.previousSibling.value = "";
386
+ (loadSelect as any).value = themeName;
387
+ } else {
388
+ alert("Save Name cannot be empty.");
389
+ }
390
+ };
391
+ }
392
+ }
393
+ function _inputOnChange(elm2) {
394
+ const teInputs = elm2.getElementsByClassName("te-input");
395
+ for (const i in teInputs) {
396
+ if (isNaN(parseInt(i))) break;
397
+ const inputElm = teInputs[i];
398
+ const inputID = inputElm.getAttribute("id");
399
+ if (inputID === "te-load-theme") {
400
+ inputElm.onchange = function (e) {
401
+ const elm3 = e.srcElement;
402
+ context.load(elm3.value);
403
+ };
404
+ } else if (inputID !== null && inputID.indexOf("te-input-themeMode") !== -1) {
405
+ inputElm.onchange = function (e) {
406
+ const elm3 = e.srcElement;
407
+ context.themeMode(elm3.checked);
408
+
409
+ const name = document.getElementById("te-load-theme");
410
+ const nameToLoad = name !== null ? (name as any).value : "Default";
411
+ context.load(nameToLoad);
412
+ };
413
+ } else if (inputElm.tagName === "INPUT" || inputElm.tagName === "SELECT" || inputElm.tagName === "TEXTAREA") {
414
+ inputElm.onchange = function (e) {
415
+ const elm3 = e.srcElement;
416
+
417
+ let id = elm3.getAttribute("id");
418
+
419
+ if (elm3.className.split(" ").indexOf("te-html-color-button") !== -1) {
420
+ id = elm3.previousSibling.getAttribute("id");
421
+ elm3.previousSibling.value = elm3.value;
422
+ }
423
+ const elmType = elm3.getAttribute("type");
424
+ const splitId = id.split("-");
425
+ const genericId = splitId.slice(0, splitId.length - 1).join("-") + "-";
426
+
427
+ const widsStr = elm3.getAttribute("data-wids");
428
+ const paramId = elm3.getAttribute("data-paramid");
429
+ const widArr = widsStr.split(",");
430
+ widArr.forEach(function (wid) {
431
+ const individualId = genericId + wid;
432
+ const indElm = document.getElementById(individualId);
433
+ if (elmType === "checkbox") {
434
+ (indElm as any).checked = elm3.checked;
435
+ context._widgetObjsById[wid][paramId](elm3.checked);
436
+ } else if (elm3.getAttribute("data-type") === "array") {
437
+ (indElm as any).value = elm3.value;
438
+ try {
439
+ context._widgetObjsById[wid][paramId](JSON.parse(elm3.value));
440
+ } catch (e) { }
441
+ } else {
442
+ (indElm as any).value = elm3.value;
443
+ context._widgetObjsById[wid][paramId](elm3.value);
444
+
445
+ if (indElm.className.split(" ").indexOf("te-html-color-input") !== -1) {
446
+ (indElm.nextSibling as any).value = elm3.value;
447
+ } else if (indElm.className.split(" ").indexOf("te-html-color-button") !== -1) {
448
+ (indElm.previousSibling as any).value = elm3.value;
449
+ }
450
+ }
451
+ });
452
+ context.data().forEach(function (d) {
453
+ d.render();
454
+ });
455
+ };
456
+ }
457
+ }
458
+ }
459
+ function _expandCollapse(elm2) {
460
+ const tableArr = elm2.getElementsByClassName("te-section-table");
461
+ for (const i in tableArr) {
462
+ if (typeof (tableArr[i].getElementsByTagName) === "function") {
463
+ const thead = tableArr[i].getElementsByTagName("thead");
464
+ thead[0].onclick = function (e) {
465
+ let elm3 = e.toElement;
466
+ if (elm3.tagName === "TH") {
467
+ elm3 = elm3.parentElement.parentElement;
468
+ }
469
+ const parent = elm3.parentElement;
470
+ let tbodyClass = "";
471
+ if (parent.className.split(" ").indexOf("expanded") === -1) {
472
+ parent.className = "te-section-table expanded";
473
+ tbodyClass = "shown";
474
+ } else {
475
+ parent.className = "te-section-table collapsed";
476
+ tbodyClass = "hidden";
477
+ }
478
+ const tbody = parent.getElementsByTagName("tbody");
479
+ tbody[0].className = tbodyClass;
480
+ };
481
+ }
482
+ }
483
+ const sharedRowArr = elm2.getElementsByClassName("sharedPropertyRow");
484
+ for (const n in sharedRowArr) {
485
+ if (typeof (sharedRowArr[n].getElementsByClassName) === "function") {
486
+ const label = sharedRowArr[n].getElementsByClassName("te-label");
487
+ label[0].onclick = function (e) {
488
+ const elm3 = e.toElement;
489
+ const parent = elm3.parentElement;
490
+ let subRowClass = "";
491
+ if (parent.className.split(" ").indexOf("expanded") === -1) {
492
+ parent.className = "sharedPropertyRow expanded";
493
+ subRowClass = "shown";
494
+ } else {
495
+ parent.className = "sharedPropertyRow collapsed";
496
+ subRowClass = "hidden";
497
+ }
498
+ let nextSib = parent.nextSibling;
499
+ while (nextSib !== null) {
500
+ if (nextSib.className.split(" ").indexOf("sharedPropertyRow") === -1) {
501
+ nextSib.className = "propertyRow " + subRowClass;
502
+ nextSib = nextSib.nextSibling;
503
+ } else {
504
+ nextSib = null;
505
+ }
506
+ }
507
+ };
508
+ }
509
+ }
510
+ }
511
+ }
512
+ sharedPropertyTableHtml(sectionObj) {
513
+ const tableObj = {
514
+ id: sectionObj.id,
515
+ label: sectionObj.label,
516
+ rowArr: []
517
+ };
518
+ sectionObj.rowObjArr.forEach(function (rowObj) {
519
+ rowObj.arr.forEach(function (widgetObj, widgetIdx) {
520
+ if (widgetIdx === 0) {
521
+ tableObj.rowArr.push({
522
+ th: _sharedPropertyLabel(rowObj),
523
+ td: _sharedPropertyInput(rowObj),
524
+ trClass: "sharedPropertyRow collapsed"
525
+ });
526
+ }
527
+ tableObj.rowArr.push({
528
+ th: _propertyLabel(widgetObj),
529
+ td: _propertyInput(rowObj, widgetIdx),
530
+ trClass: "propertyRow hidden"
531
+ });
532
+ });
533
+ });
534
+
535
+ return this.tableObjHtml(tableObj);
536
+
537
+ function _propertyLabel(widgetObj) {
538
+ const splitClass = widgetObj.widget.classID().split("_");
539
+ const displayClass = splitClass.join("/");
540
+ return displayClass + " <i>[" + widgetObj.widget._id + "]</i>";
541
+ }
542
+ function _sharedPropertyLabel(rowObj) {
543
+ return camelizeString(rowObj.id);
544
+ }
545
+
546
+ function _propertyInput(rowObj, idx) {
547
+ const value = _value(rowObj, idx);
548
+ const html = tableInputHtml(rowObj, value, [rowObj.arr[idx]], rowObj.arr[idx].widget._id);
549
+ return html;
550
+
551
+ function _value(rowObj2, idx2) {
552
+ const value2 = rowObj2.arr[idx2].widget[rowObj2.id]();
553
+ return value2 !== null ? value2 : "";
554
+ }
555
+ }
556
+ function _sharedPropertyInput(rowObj) {
557
+ const value = _sharedValue(rowObj);
558
+ const html = tableInputHtml(rowObj, value, rowObj.arr, "shared");
559
+ return html;
560
+
561
+ function _sharedValue(rowObj2) {
562
+ const value2 = rowObj2.arr[0].widget[rowObj2.id]();
563
+ rowObj2.arr.forEach(function (w, i) {
564
+ if (value2 !== w.widget[w.id]()) {
565
+ return "";
566
+ }
567
+ });
568
+ if (value2 !== null) {
569
+ if (rowObj2.type === "array") {
570
+ return JSON.stringify(value2);
571
+ }
572
+ return value2;
573
+ }
574
+ return "";
575
+ }
576
+ }
577
+ }
578
+
579
+ tableObjHtml(tableObj) {
580
+ let html = "<table id='" + tableObj.id + "' class='te-section-table expanded'>";
581
+ html += "<thead><tr><th colspan='2'>" + tableObj.label + "</th></tr></thead>";
582
+ html += "<tbody>";
583
+ tableObj.rowArr.forEach(function (rowObj) {
584
+ html += this.tableRowObjHtml(rowObj);
585
+ }, this);
586
+ html += "</tbody>";
587
+ return html + "</table>";
588
+ }
589
+ tableRowObjHtml(rowObj) {
590
+ let html = typeof (rowObj.trClass) !== "undefined" ? "<tr class='" + rowObj.trClass + "'>" : "<tr>";
591
+ html += "<th class='te-label'>" + rowObj.th + "</th>";
592
+ html += "<td>" + rowObj.td + "</td>";
593
+ return html + "</tr>";
594
+ }
595
+
596
+ setWidgetObjsById(widgetProp) {
597
+ const context = this;
598
+ const val = widgetProp.widget[widgetProp.id]();
599
+ if (widgetProp.type === "widgetArray") {
600
+ val.forEach(function (widget) {
601
+ context._widgetObjsById[widget._id] = widget;
602
+ });
603
+ } else if (widgetProp.type === "widget" && val !== null) {
604
+ this._widgetObjsById[val._id] = val;
605
+ }
606
+ }
607
+ checkTagFilter(tagArr) {
608
+ const allowTags = ["Basic"];
609
+ let ret = false;
610
+ tagArr.forEach(function (tag) {
611
+ if (allowTags.indexOf(tag) !== -1) {
612
+ ret = true;
613
+ }
614
+ });
615
+ return ret;
616
+ }
617
+ findSharedProperties(data) {
618
+ const context = this;
619
+ let propsByID;
620
+ if (typeof (data) !== "undefined" && data.length > 0) {
621
+ let allProps = [];
622
+ propsByID = {};
623
+ const surfacePropsByID = {};
624
+ const nonSurfacePropsByID = {};
625
+ data.forEach(function (widget) {
626
+ const gpResponse = _getParams(widget, 0);
627
+ allProps = allProps.concat(gpResponse);
628
+ });
629
+ allProps.forEach(function (prop) {
630
+ if (["widget", "widgetArray"].indexOf(prop.type) !== -1) {
631
+ context.setWidgetObjsById(prop);
632
+ } else if (context.checkTagFilter(prop.ext.tags)) {
633
+ const tempIdx = prop.id;
634
+ if (prop.widget._class.indexOf("Surface") !== -1) {
635
+ if (typeof (surfacePropsByID[tempIdx]) === "undefined") {
636
+ surfacePropsByID[tempIdx] = { arr: [] };
637
+ }
638
+ surfacePropsByID[tempIdx].id = prop.id;
639
+ surfacePropsByID[tempIdx].description = prop.description;
640
+ surfacePropsByID[tempIdx].type = prop.type;
641
+ surfacePropsByID[tempIdx].set = prop.set;
642
+ surfacePropsByID[tempIdx].ext = prop.ext;
643
+ surfacePropsByID[tempIdx].arr.push(prop);
644
+ } else {
645
+ if (typeof (nonSurfacePropsByID[tempIdx]) === "undefined") {
646
+ nonSurfacePropsByID[tempIdx] = { arr: [] };
647
+ }
648
+ nonSurfacePropsByID[tempIdx].id = prop.id;
649
+ nonSurfacePropsByID[tempIdx].description = prop.description;
650
+ nonSurfacePropsByID[tempIdx].type = prop.type;
651
+ nonSurfacePropsByID[tempIdx].set = prop.set;
652
+ nonSurfacePropsByID[tempIdx].ext = prop.ext;
653
+ nonSurfacePropsByID[tempIdx].arr.push(prop);
654
+ }
655
+ if (typeof (propsByID[tempIdx]) === "undefined") {
656
+ propsByID[tempIdx] = { arr: [] };
657
+ }
658
+ propsByID[tempIdx].id = prop.id;
659
+ propsByID[tempIdx].description = prop.description;
660
+ propsByID[tempIdx].type = prop.type;
661
+ propsByID[tempIdx].set = prop.set;
662
+ propsByID[tempIdx].ext = prop.ext;
663
+ propsByID[tempIdx].arr.push(prop);
664
+ }
665
+ });
666
+ }
667
+ return propsByID;
668
+
669
+ function _getParams(widgetObj, depth) {
670
+ let retArr = [];
671
+ if (widgetObj !== null) {
672
+ const paramArr = Persist.discover(widgetObj);
673
+ paramArr.forEach(function (param, i1) {
674
+ if (typeof (param.ext.tags) !== "undefined") {
675
+ retArr.push({
676
+ id: param.id,
677
+ type: param.type,
678
+ description: param.description,
679
+ set: param.set,
680
+ ext: param.ext,
681
+ widget: widgetObj
682
+ });
683
+ }
684
+ if (param.type === "widgetArray") {
685
+ const childWidgetArray = context.widgetProperty(widgetObj, param.id);
686
+ childWidgetArray.forEach(function (childWidget) {
687
+ const cwArr = _getParams(childWidget, depth + 1);
688
+ retArr = retArr.concat(cwArr);
689
+ });
690
+ } else if (param.type === "widget") {
691
+ const childWidget = context.widgetProperty(widgetObj, param.id);
692
+ const temp = _getParams(childWidget, depth + 1);
693
+ retArr = retArr.concat(temp);
694
+ }
695
+ });
696
+ }
697
+ return retArr;
698
+ }
699
+ }
700
+ }
701
+ ThemeEditor.prototype._class += " other_ThemeEditor";
702
+
703
+ export interface ThemeEditor {
704
+ themeMode(): boolean;
705
+ themeMode(_: boolean): this;
706
+ themeMode_exists(): boolean;
707
+ saveTheme(): string;
708
+ saveTheme(_: string): this;
709
+ saveTheme_exists(): boolean;
710
+ loadedTheme(): string;
711
+ loadedTheme(_: string): this;
712
+ loadedTheme_exists(): boolean;
713
+ saveSerial(): string;
714
+ saveSerial(_: string): this;
715
+ saveSerial_exists(): boolean;
716
+ loadedSerial(): string;
717
+ loadedSerial(_: string): this;
718
+ loadedSerial_exists(): boolean;
719
+ showColumns(): boolean;
720
+ showColumns(_: boolean): this;
721
+ showColumns_exists(): boolean;
722
+ showData(): boolean;
723
+ showData(_: boolean): this;
724
+ showData_exists(): boolean;
725
+ shareCountMin(): number;
726
+ shareCountMin(_: number): this;
727
+ shareCountMin_exists(): boolean;
728
+ paramGrouping(): string;
729
+ paramGrouping(_: string): this;
730
+ paramGrouping_exists(): boolean
731
+ editorComplexity(): string;
732
+ editorComplexity(_: string): this;
733
+ editorComplexity_exists(): boolean;
734
+ sectionTitle(): string;
735
+ sectionTitle(_: string): this;
736
+ sectionTitle_exists(): boolean;
737
+ collapsibleSections(): boolean;
738
+ collapsibleSections(_: boolean): this;
739
+ collapsibleSections_exists(): boolean;
740
+ }
741
+
742
+ ThemeEditor.prototype.publish("themeMode", true, "boolean", "Edit default values", null, { tags: ["Basic"] });
743
+ ThemeEditor.prototype.publish("saveTheme", "", "string", "Save Theme", null, { tags: ["Basic", "Theme"], saveButton: "Save", saveButtonID: "te-save-button" });
744
+ ThemeEditor.prototype.publish("loadedTheme", getThemeNames(1), "set", "Loaded Theme", getThemeNames(), { tags: ["Basic", "Theme"] });
745
+ ThemeEditor.prototype.publish("saveSerial", "", "string", "Save Serial", null, { tags: ["Basic", "Serial"], saveButton: "Save", saveButtonID: "te-save-button" });
746
+ ThemeEditor.prototype.publish("loadedSerial", getSerialNames(0), "set", "Loaded Serial", getSerialNames(), { tags: ["Basic", "Serial"] });
747
+ ThemeEditor.prototype.publish("showColumns", true, "boolean", "Show Columns", null, { tags: ["Intermediate"] });
748
+ ThemeEditor.prototype.publish("showData", true, "boolean", "Show Data", null, { tags: ["Intermediate"] });
749
+ ThemeEditor.prototype.publish("shareCountMin", 1, "number", "Share Count Min", null, { tags: ["Private"] });
750
+ ThemeEditor.prototype.publish("paramGrouping", "By Param", "set", "Param Grouping", ["By Param", "By Widget"], { tags: ["Private"] });
751
+ ThemeEditor.prototype.publish("editorComplexity", "Basic", "set", "Choose what publish properties to display within the editor.", ["Basic", "Intermediate", "Advanced", "Private"], { tags: ["Private"] });
752
+ ThemeEditor.prototype.publish("sectionTitle", "", "string", "Section Title", null, { tags: ["Private"] });
753
+ ThemeEditor.prototype.publish("collapsibleSections", true, "boolean", "Collapsible Sections", null, { tags: ["Intermediate"] });
754
+
755
+ ThemeEditor.prototype.getThemes = getThemes;
756
+ ThemeEditor.prototype.getSerials = getSerials;
757
+ ThemeEditor.prototype.getDefaultThemes = getThemeNames;
758
+ ThemeEditor.prototype.getDefaultSerials = getSerialNames;