chem-generic-ui 0.1.33 → 0.1.34

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.
Files changed (48) hide show
  1. package/dist/app.js +105 -0
  2. package/dist/asserts/main.css +465 -0
  3. package/dist/asserts/main.scss +496 -0
  4. package/dist/components/admin/ElementManager.js +54 -0
  5. package/dist/components/details/GenDSDetails.js +273 -0
  6. package/dist/components/details/GenSgDetails.js +566 -0
  7. package/dist/components/dnd/DragDropItemTypes.js +20 -0
  8. package/dist/components/dnd/GenericElDropTarget.js +274 -0
  9. package/dist/components/dnd/GridDnD.js +77 -0
  10. package/dist/components/dnd/PanelDnD.js +171 -0
  11. package/dist/components/fields/ButtonConfirm.js +76 -0
  12. package/dist/components/fields/ButtonTooltip.js +88 -0
  13. package/dist/components/fields/FieldLabel.js +38 -0
  14. package/dist/components/fields/GenDSMisType.js +44 -0
  15. package/dist/components/fields/GenFormGroupCb.js +31 -0
  16. package/dist/components/fields/GenProperties.js +83 -0
  17. package/dist/components/fields/GenPropertiesFields.js +616 -0
  18. package/dist/components/flow/FlowView.js +88 -0
  19. package/dist/components/flow/FlowViewerModal.js +81 -0
  20. package/dist/components/flow/LayerNode.js +59 -0
  21. package/dist/components/layers/GenPropertiesLayer.js +280 -0
  22. package/dist/components/layers/LayerModal.js +81 -0
  23. package/dist/components/layers/LayersLayout.js +88 -0
  24. package/dist/components/models/Attachment.js +73 -0
  25. package/dist/components/models/GenericSubField.js +37 -0
  26. package/dist/components/table/DropLinkRenderer.js +55 -0
  27. package/dist/components/table/DropRenderer.js +45 -0
  28. package/dist/components/table/DropTextRenderer.js +45 -0
  29. package/dist/components/table/GenericElTableDropTarget.js +252 -0
  30. package/dist/components/table/GridBtn.js +102 -0
  31. package/dist/components/table/GridEntry.js +163 -0
  32. package/dist/components/table/SamOption.js +87 -0
  33. package/dist/components/table/SelectRenderer.js +52 -0
  34. package/dist/components/table/TableRecord.js +454 -0
  35. package/dist/components/table/UConverterRenderer.js +41 -0
  36. package/dist/components/tools/collate.js +103 -0
  37. package/dist/components/tools/orten.js +294 -0
  38. package/dist/components/tools/utils.js +593 -0
  39. package/dist/data/SystemUnits.js +588 -0
  40. package/dist/data/systemUnits.json +430 -0
  41. package/dist/index.css +13 -0
  42. package/dist/index.js +39 -0
  43. package/dist/logo.svg +1 -0
  44. package/dist/simulations/SimWF.js +123 -0
  45. package/dist/simulations/SimuDS.js +118 -0
  46. package/dist/simulations/SimuSG.js +123 -0
  47. package/package.json +5 -2
  48. package/dist/generic.js +0 -6219
@@ -0,0 +1,454 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _react = _interopRequireDefault(require("react"));
13
+
14
+ var _numeral = _interopRequireDefault(require("numeral"));
15
+
16
+ var _GenericSubField = _interopRequireDefault(require("../models/GenericSubField"));
17
+
18
+ var _GridBtn = require("./GridBtn");
19
+
20
+ var _GridEntry = require("./GridEntry");
21
+
22
+ var _UConverterRenderer = _interopRequireDefault(require("./UConverterRenderer"));
23
+
24
+ var _utils = require("../tools/utils");
25
+
26
+ var _DropRenderer = _interopRequireDefault(require("./DropRenderer"));
27
+
28
+ var _DropTextRenderer = _interopRequireDefault(require("./DropTextRenderer"));
29
+
30
+ var _DropLinkRenderer = _interopRequireDefault(require("./DropLinkRenderer"));
31
+
32
+ var _SamOption = _interopRequireDefault(require("./SamOption"));
33
+
34
+ var _DragDropItemTypes = _interopRequireDefault(require("../dnd/DragDropItemTypes"));
35
+
36
+ var _SelectRenderer = _interopRequireDefault(require("./SelectRenderer"));
37
+
38
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
+
40
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
41
+
42
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
43
+
44
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
45
+
46
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
47
+
48
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
49
+
50
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
51
+
52
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
53
+
54
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
55
+
56
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
57
+
58
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
59
+
60
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
61
+
62
+ var TableRecord = /*#__PURE__*/function (_React$Component) {
63
+ _inherits(TableRecord, _React$Component);
64
+
65
+ var _super = _createSuper(TableRecord);
66
+
67
+ function TableRecord(props) {
68
+ var _this;
69
+
70
+ _classCallCheck(this, TableRecord);
71
+
72
+ _this = _super.call(this, props);
73
+ _this.delRow = _this.delRow.bind(_assertThisInitialized(_this));
74
+ _this.addRow = _this.addRow.bind(_assertThisInitialized(_this));
75
+ _this.moveRow = _this.moveRow.bind(_assertThisInitialized(_this));
76
+ _this.onCellChange = _this.onCellChange.bind(_assertThisInitialized(_this));
77
+ _this.onSelectClick = _this.onSelectClick.bind(_assertThisInitialized(_this));
78
+ _this.onUnitClick = _this.onUnitClick.bind(_assertThisInitialized(_this));
79
+ _this.onDrop = _this.onDrop.bind(_assertThisInitialized(_this));
80
+ _this.onChk = _this.onChk.bind(_assertThisInitialized(_this));
81
+ _this.getColumns = _this.getColumns.bind(_assertThisInitialized(_this));
82
+ return _this;
83
+ }
84
+
85
+ _createClass(TableRecord, [{
86
+ key: "onCellChange",
87
+ value: function onCellChange(params) {
88
+ var e = params.e,
89
+ columnDef = params.columnDef,
90
+ rowValue = params.rowValue;
91
+ var newValue = e.target.value;
92
+ var oldValue = rowValue[columnDef.field].value;
93
+ if (oldValue === newValue) return;
94
+
95
+ if (columnDef.type === 'text') {
96
+ rowValue[columnDef.field] = newValue;
97
+ }
98
+
99
+ if (columnDef.type === 'system-defined') {
100
+ if (isNaN(newValue)) return;
101
+ rowValue[columnDef.field].value = (0, _numeral.default)(newValue).value();
102
+ }
103
+
104
+ var opt = this.props.opt;
105
+ var subVals = opt.f_obj.sub_values || [];
106
+ var idx = subVals.findIndex(function (s) {
107
+ return s.id === rowValue.id;
108
+ });
109
+ subVals.splice(idx, 1, rowValue);
110
+ opt.f_obj.sub_values = subVals;
111
+ opt.onSubChange(0, 0, opt.f_obj, true);
112
+ }
113
+ }, {
114
+ key: "onSelectClick",
115
+ value: function onSelectClick(e, subField, node) {
116
+ var data = node.data;
117
+ var opt = this.props.opt;
118
+ var subVals = opt.f_obj.sub_values || [];
119
+ var subVal = subVals.find(function (s) {
120
+ return s.id === data.id;
121
+ });
122
+ subVal[subField.id] = {
123
+ value: e ? e.value : ''
124
+ };
125
+ var idx = subVals.findIndex(function (s) {
126
+ return s.id === data.id;
127
+ });
128
+ subVals.splice(idx, 1, subVal);
129
+ opt.f_obj.sub_values = subVals;
130
+ opt.onSubChange(subField, subField.id, opt.f_obj, true);
131
+ }
132
+ }, {
133
+ key: "onUnitClick",
134
+ value: function onUnitClick(subField, node) {
135
+ var data = node.data;
136
+ var opt = this.props.opt;
137
+ var subVals = opt.f_obj.sub_values || [];
138
+ var subVal = subVals.find(function (s) {
139
+ return s.id === data.id;
140
+ });
141
+ var units = (0, _utils.genUnits)(subField.option_layers);
142
+ var uIdx = units.findIndex(function (u) {
143
+ return u.key === subVal[subField.id].value_system;
144
+ });
145
+ if (uIdx < units.length - 1) uIdx += 1;else uIdx = 0;
146
+ var vs = units.length > 0 ? units[uIdx].key : '';
147
+ var v = (0, _utils.unitConversion)(subField.option_layers, vs, subVal[subField.id].value);
148
+ subVal[subField.id] = {
149
+ value: v,
150
+ value_system: vs
151
+ };
152
+ var idx = subVals.findIndex(function (s) {
153
+ return s.id === data.id;
154
+ });
155
+ subVals.splice(idx, 1, subVal);
156
+ opt.f_obj.sub_values = subVals;
157
+ opt.onSubChange(subField, subField.id, opt.f_obj, true);
158
+ }
159
+ }, {
160
+ key: "onDrop",
161
+ value: function onDrop(targetProps, targetOpt) {
162
+ var opt = this.props.opt;
163
+ var subField = targetOpt.sField;
164
+ var subVals = opt.f_obj.sub_values || [];
165
+ var subVal = subVals.find(function (s) {
166
+ return s.id === targetOpt.data.id;
167
+ });
168
+ subVal[subField.id] = {
169
+ value: targetProps
170
+ };
171
+ var idx = subVals.findIndex(function (s) {
172
+ return s.id === targetOpt.data.id;
173
+ });
174
+ subVals.splice(idx, 1, subVal);
175
+ opt.f_obj.sub_values = subVals;
176
+ opt.onSubChange(subField, subField.id, opt.f_obj, true);
177
+ }
178
+ }, {
179
+ key: "onChk",
180
+ value: function onChk(params) {
181
+ var node = params.node,
182
+ subField = params.subField,
183
+ crOpt = params.crOpt;
184
+ var opt = this.props.opt;
185
+ var subVals = opt.f_obj.sub_values || [];
186
+ var subVal = subVals.find(function (s) {
187
+ return s.id === node.data.id;
188
+ });
189
+ node.data[subField.id].value.cr_opt = crOpt;
190
+ subVal[subField.id] = {
191
+ value: node.data[subField.id].value
192
+ };
193
+ var idx = subVals.findIndex(function (s) {
194
+ return s.id === node.data.id;
195
+ });
196
+ subVals.splice(idx, 1, subVal);
197
+ opt.f_obj.sub_values = subVals;
198
+ opt.onSubChange(subField, subField.id, opt.f_obj, true);
199
+ }
200
+ }, {
201
+ key: "getColumns",
202
+ value: function getColumns() {
203
+ var _this2 = this;
204
+
205
+ var opt = this.props.opt;
206
+ var selectOptions = opt.selectOptions;
207
+ var sValues = opt.f_obj.sub_values || [];
208
+ var columnDefs = [];
209
+ (opt.f_obj.sub_fields || []).forEach(function (sF) {
210
+ var colDef = {
211
+ type: sF.type,
212
+ headerName: sF.col_name,
213
+ field: sF.id
214
+ };
215
+ var colDefExt = [];
216
+
217
+ if (sF.type === 'text') {
218
+ colDef = Object.assign({}, colDef, {
219
+ editable: true,
220
+ onCellChange: _this2.onCellChange
221
+ });
222
+ }
223
+
224
+ if (sF.type === 'select') {
225
+ var sOptions = selectOptions[sF.option_layers] && selectOptions[sF.option_layers].options || [];
226
+ sOptions = sOptions.map(function (op) {
227
+ return {
228
+ value: op.key,
229
+ name: op.key,
230
+ label: op.label
231
+ };
232
+ });
233
+ var cellParams = {
234
+ sField: sF,
235
+ onChange: _this2.onSelectClick,
236
+ sOptions: sOptions
237
+ };
238
+ colDef = Object.assign({}, colDef, {
239
+ cellRenderer: _SelectRenderer.default,
240
+ cellParams: cellParams,
241
+ onCellChange: _this2.onCellChange
242
+ });
243
+ }
244
+
245
+ if (sF.type === 'system-defined') {
246
+ var _cellParams = {
247
+ sField: sF,
248
+ onChange: _this2.onUnitClick
249
+ };
250
+ colDef = Object.assign({}, colDef, {
251
+ cellRenderer: _UConverterRenderer.default,
252
+ cellParams: _cellParams,
253
+ onCellChange: _this2.onCellChange
254
+ });
255
+ }
256
+
257
+ if (sF.type === 'drag_molecule') {
258
+ var _cellParams2 = {
259
+ sField: sF,
260
+ opt: opt,
261
+ onChange: _this2.onDrop
262
+ };
263
+ colDef = Object.assign({}, colDef, {
264
+ cellRenderer: _DropRenderer.default,
265
+ cellParams: _cellParams2,
266
+ onCellChange: _this2.onCellChange,
267
+ width: '5vw'
268
+ });
269
+ var conf = (sF.value || '').split(';') || [];
270
+ conf.forEach(function (c) {
271
+ var attr = _utils.molOptions.find(function (m) {
272
+ return m.value === c;
273
+ });
274
+
275
+ if (attr) {
276
+ var ext = {
277
+ colId: c,
278
+ editable: false,
279
+ type: 'text',
280
+ headerName: attr.label,
281
+ cellRenderer: _DropTextRenderer.default,
282
+ cellParams: {
283
+ attr: attr,
284
+ sField: sF
285
+ }
286
+ };
287
+ colDefExt.push(ext);
288
+ }
289
+ });
290
+ }
291
+
292
+ if (sF.type === 'drag_sample') {
293
+ var sOpt = sValues.filter(function (o) {
294
+ return o[sF.id] && o[sF.id].value && o[sF.id].value.is_new;
295
+ });
296
+ var _cellParams3 = {
297
+ sField: sF,
298
+ opt: opt,
299
+ onChange: _this2.onDrop
300
+ };
301
+ colDef = Object.assign({}, colDef, {
302
+ cellRenderer: _DropRenderer.default,
303
+ cellParams: _cellParams3,
304
+ onCellChange: _this2.onCellChange,
305
+ width: '5vw'
306
+ });
307
+ var addOption = {
308
+ colId: 'sam_option',
309
+ editable: false,
310
+ type: 'text',
311
+ headerName: '',
312
+ cellRenderer: _SamOption.default,
313
+ cellParams: {
314
+ sField: sF,
315
+ onChange: _this2.onChk
316
+ },
317
+ width: '3vw'
318
+ };
319
+ if (sOpt.length > 0) colDefExt.push(addOption);
320
+ var addLink = {
321
+ colId: 'sam_link',
322
+ editable: false,
323
+ type: 'text',
324
+ headerName: 'Short label',
325
+ cellRenderer: _DropLinkRenderer.default,
326
+ cellParams: {
327
+ sField: sF
328
+ },
329
+ width: '5vw'
330
+ };
331
+ colDefExt.push(addLink);
332
+
333
+ var _conf = (sF.value || '').split(';') || [];
334
+
335
+ _conf.forEach(function (c) {
336
+ var attr = _utils.samOptions.find(function (m) {
337
+ return m.value === c;
338
+ });
339
+
340
+ if (attr) {
341
+ var ext = {
342
+ colId: c,
343
+ editable: false,
344
+ type: 'text',
345
+ headerName: attr.label,
346
+ cellRenderer: _DropTextRenderer.default,
347
+ cellParams: {
348
+ attr: attr,
349
+ sField: sF
350
+ }
351
+ };
352
+ colDefExt.push(ext);
353
+ }
354
+ });
355
+ }
356
+
357
+ columnDefs.push(colDef);
358
+ if (colDefExt.length > 0) columnDefs = columnDefs.concat(colDefExt);
359
+ });
360
+ var act = {
361
+ type: 'button',
362
+ headerName: '',
363
+ colId: opt.f_obj.field,
364
+ headerComponent: _GridBtn.AddRowBtn,
365
+ headerParams: {
366
+ addRow: this.addRow
367
+ },
368
+ cellRenderer: _GridBtn.DelRowBtn,
369
+ cellParams: {
370
+ delRow: this.delRow
371
+ },
372
+ width: 'unset'
373
+ };
374
+ columnDefs.splice(0, 0, act);
375
+ var dtype = "".concat(_DragDropItemTypes.default.GENERIC_GRID, "_").concat(opt.layer.key, "_").concat(opt.f_obj.field);
376
+ var move = {
377
+ type: 'dnd',
378
+ field: opt.f_obj.field,
379
+ headerName: '',
380
+ colId: "".concat(opt.f_obj.field, "_dnd"),
381
+ headerComponent: _GridBtn.NullRowBtn,
382
+ cellRenderer: _GridBtn.DnDRowBtn,
383
+ cellParams: {
384
+ moveRow: this.moveRow,
385
+ field: opt.f_obj.field,
386
+ type: dtype
387
+ },
388
+ width: 'unset'
389
+ };
390
+ columnDefs.splice(0, 0, move);
391
+ return columnDefs;
392
+ }
393
+ }, {
394
+ key: "moveRow",
395
+ value: function moveRow(source, target) {
396
+ var opt = this.props.opt;
397
+ var alles = opt.f_obj.sub_values;
398
+ var sid = alles.findIndex(function (e) {
399
+ return e.id === source;
400
+ });
401
+ var tid = alles.findIndex(function (e) {
402
+ return e.id === target;
403
+ });
404
+ var temp = alles[sid];
405
+ alles[sid] = alles[tid];
406
+ alles[tid] = temp;
407
+ opt.onSubChange(0, 0, opt.f_obj, true);
408
+ }
409
+ }, {
410
+ key: "delRow",
411
+ value: function delRow(rowData) {
412
+ var opt = this.props.opt;
413
+ opt.f_obj.sub_values = opt.f_obj.sub_values.filter(function (s) {
414
+ return s.id !== rowData.id;
415
+ });
416
+ opt.onSubChange(0, 0, opt.f_obj, true);
417
+ }
418
+ }, {
419
+ key: "addRow",
420
+ value: function addRow() {
421
+ var opt = this.props.opt;
422
+ var subFields = opt.f_obj.sub_fields || [];
423
+ var newSub = new _GenericSubField.default();
424
+ subFields.map(function (e) {
425
+ if (e.type === 'text') return Object.assign(newSub, _defineProperty({}, e.id, ''));
426
+ return Object.assign(newSub, _defineProperty({}, e.id, {
427
+ value: '',
428
+ value_system: e.value_system
429
+ }));
430
+ });
431
+ opt.f_obj.sub_values = opt.f_obj.sub_values || [];
432
+ opt.f_obj.sub_values.push(newSub);
433
+ opt.onSubChange(0, 0, opt.f_obj, true);
434
+ }
435
+ }, {
436
+ key: "render",
437
+ value: function render() {
438
+ var opt = this.props.opt;
439
+ if (opt.isSearchCriteria) return /*#__PURE__*/_react.default.createElement("div", null, "(This is a table)");
440
+ if ((opt.f_obj.sub_fields || []).length < 1) return null;
441
+ var columnDefs = this.getColumns();
442
+ return /*#__PURE__*/_react.default.createElement("div", null, (0, _GridEntry.ColumnHeader)(columnDefs), /*#__PURE__*/_react.default.createElement("div", null, (0, _GridEntry.NoRow)(opt.f_obj.sub_values)), /*#__PURE__*/_react.default.createElement("div", null, (opt.f_obj.sub_values || []).map(function (s) {
443
+ return (0, _GridEntry.ColumnRow)(columnDefs, s);
444
+ })));
445
+ }
446
+ }]);
447
+
448
+ return TableRecord;
449
+ }(_react.default.Component);
450
+
451
+ exports.default = TableRecord;
452
+ TableRecord.propTypes = {
453
+ opt: _propTypes.default.object.isRequired
454
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _reactBootstrap = require("react-bootstrap");
13
+
14
+ var _utils = require("../tools/utils");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ /* eslint-disable react/forbid-prop-types */
19
+ var UConverterRenderer = function UConverterRenderer(props) {
20
+ var sField = props.sField,
21
+ onChange = props.onChange,
22
+ node = props.node;
23
+ if (sField.type !== 'system-defined') return null;
24
+ var data = node.data;
25
+ return /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
26
+ key: "ucr_".concat(data.id),
27
+ active: true,
28
+ onClick: function onClick() {
29
+ return onChange(sField, node);
30
+ },
31
+ bsStyle: "success"
32
+ }, (0, _utils.genUnitSup)((0, _utils.genUnit)(sField.option_layers, data[sField.id].value_system).label) || '');
33
+ };
34
+
35
+ UConverterRenderer.propTypes = {
36
+ sField: _propTypes.default.object.isRequired,
37
+ onChange: _propTypes.default.func.isRequired,
38
+ node: _propTypes.default.object.isRequired
39
+ };
40
+ var _default = UConverterRenderer;
41
+ exports.default = _default;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _lodash = require("lodash");
9
+
10
+ var _utils = require("./utils");
11
+
12
+ var _GenericSubField = _interopRequireDefault(require("../models/GenericSubField"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
+
18
+ var collateValues = function collateValues(currentFields, previousFields, previousValues) {
19
+ var result = [];
20
+ var newSub = new _GenericSubField.default();
21
+ currentFields.map(function (e) {
22
+ return Object.assign(newSub, _defineProperty({}, e.id, ''));
23
+ });
24
+ var currentValuKeys = Object.keys(newSub);
25
+ var previousValueKeys = Object.keys(previousValues[0]);
26
+ var notInCurrent = previousValueKeys.filter(function (e) {
27
+ return !currentValuKeys.includes(e);
28
+ });
29
+ var currObj = {};
30
+ currentFields.map(function (c) {
31
+ if (c.type === 'text') return Object.assign(currObj, _defineProperty({}, c.id, ''));
32
+ return Object.assign(currObj, _defineProperty({}, c.id, {
33
+ value: '',
34
+ value_system: c.value_system
35
+ }));
36
+ });
37
+ previousValues.forEach(function (e) {
38
+ newSub = new _GenericSubField.default();
39
+ Object.assign(newSub, currObj, e);
40
+ notInCurrent.forEach(function (c) {
41
+ return delete newSub[c];
42
+ });
43
+ previousValueKeys.forEach(function (preKey) {
44
+ if (newSub[preKey] === undefined || preKey === 'id') return;
45
+ var curr = currentFields.find(function (f) {
46
+ return f.id === preKey;
47
+ });
48
+ var prev = previousFields.find(function (f) {
49
+ return f.id === preKey;
50
+ });
51
+
52
+ if (curr.type === 'drag_molecule') {
53
+ if (['text', 'system-defined', 'drag_sample'].includes(prev.type)) {
54
+ newSub[preKey] = {
55
+ value: undefined
56
+ };
57
+ }
58
+ }
59
+
60
+ if (curr.type === 'text') {
61
+ if (prev.type === 'system-defined') {
62
+ newSub[preKey] = newSub[preKey].value;
63
+ }
64
+
65
+ if (['drag_molecule', 'drag_sample'].includes(prev.type)) {
66
+ newSub[preKey] = '';
67
+ }
68
+ }
69
+
70
+ if (curr.type === 'system-defined') {
71
+ if (prev.type === 'system-defined' && curr.option_layers !== prev.option_layers) {
72
+ newSub[preKey].value_system = curr.value_system;
73
+ }
74
+
75
+ if (['text', 'drag_molecule', 'drag_sample'].includes(prev.type)) {
76
+ newSub[preKey] = {
77
+ value: '',
78
+ value_system: curr.value_system
79
+ };
80
+ }
81
+
82
+ newSub[preKey].value = (0, _utils.unitConversion)(curr.option_layer, newSub[preKey].value_system, newSub[preKey].value);
83
+ }
84
+ });
85
+ result.push(newSub);
86
+ });
87
+ return result;
88
+ };
89
+
90
+ var organizeSubValues = function organizeSubValues(cur, pre) {
91
+ var currentFields = (0, _lodash.cloneDeep)(cur.sub_fields || []);
92
+ var previousFields = (0, _lodash.cloneDeep)(pre.sub_fields || []);
93
+ var previousValues = (0, _lodash.cloneDeep)(pre.sub_values || []);
94
+
95
+ if (currentFields.length < 1 || previousFields.length < 1 || previousValues.length < 1) {
96
+ return [];
97
+ }
98
+
99
+ return collateValues(currentFields, previousFields, previousValues);
100
+ };
101
+
102
+ var _default = organizeSubValues;
103
+ exports.default = _default;