ModuleUtilities.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.RendererInput = RendererInput;
  6. exports.RendererOutput = RendererOutput;
  7. exports.Resolver = Resolver;
  8. exports.BooleanInput = exports.ObjectInput = exports.TextInput = exports.ArrayInput = exports.MakeView = exports.InputLink = exports.OutputLink = exports.OutputMarker = exports.InputMarker = exports.RemoveMarker = void 0;
  9. var _react = _interopRequireDefault(require("react"));
  10. var _Types = _interopRequireDefault(require("./Types.js"));
  11. var _Logger = _interopRequireDefault(require("../systems/Logger"));
  12. var _reactFontawesome = require("@fortawesome/react-fontawesome");
  13. var _reactMaterialize = require("react-materialize");
  14. var _reactJsonView = _interopRequireDefault(require("react-json-view"));
  15. var _Dependencies3 = _interopRequireDefault(require("../systems/Dependencies"));
  16. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  17. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  18. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
  19. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
  20. function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
  21. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
  22. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  23. 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); } }
  24. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  25. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  26. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  27. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  28. 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  29. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  30. var RemoveMarker =
  31. /*#__PURE__*/
  32. function (_React$Component) {
  33. _inherits(RemoveMarker, _React$Component);
  34. function RemoveMarker(props) {
  35. _classCallCheck(this, RemoveMarker);
  36. return _possibleConstructorReturn(this, _getPrototypeOf(RemoveMarker).call(this, props));
  37. }
  38. _createClass(RemoveMarker, [{
  39. key: "drop",
  40. value: function drop() {
  41. if (this.props.onRemove) {
  42. this.props.onRemove();
  43. }
  44. }
  45. }, {
  46. key: "render",
  47. value: function render() {
  48. var _this = this;
  49. var mode = localStorage.getItem('AdminMode');
  50. if (mode !== "admin") {
  51. return '';
  52. }
  53. return _react.default.createElement("div", {
  54. className: "btn btn-flat " + this.props.className,
  55. onClick: function onClick() {
  56. return _this.drop();
  57. }
  58. }, _react.default.createElement("div", {
  59. className: "row"
  60. }, _react.default.createElement("div", {
  61. className: "col s2"
  62. }, _react.default.createElement("div", {
  63. className: "RemoveMarker"
  64. })), _react.default.createElement("div", {
  65. className: "col s5"
  66. }, _react.default.createElement("span", null, "Remove"))));
  67. }
  68. }]);
  69. return RemoveMarker;
  70. }(_react.default.Component);
  71. exports.RemoveMarker = RemoveMarker;
  72. var InputMarker =
  73. /*#__PURE__*/
  74. function (_React$Component2) {
  75. _inherits(InputMarker, _React$Component2);
  76. function InputMarker(props) {
  77. _classCallCheck(this, InputMarker);
  78. return _possibleConstructorReturn(this, _getPrototypeOf(InputMarker).call(this, props));
  79. }
  80. _createClass(InputMarker, [{
  81. key: "drop",
  82. value: function drop() {
  83. if (!window._selectedModule) {
  84. return console.log("No selected module!");
  85. }
  86. if (this.props.onDrop) {
  87. this.props.onDrop(window._selectedModule);
  88. }
  89. }
  90. }, {
  91. key: "render",
  92. value: function render() {
  93. var _this2 = this;
  94. return _react.default.createElement("div", {
  95. className: "btn btn-flat " + (this.props.className || ''),
  96. onClick: function onClick() {
  97. return _this2.drop();
  98. },
  99. onDragOver: function onDragOver(e) {
  100. return e.preventDefault();
  101. },
  102. onDrop: function onDrop(e) {
  103. return _this2.drop();
  104. }
  105. }, _react.default.createElement("div", {
  106. className: "InputMarker"
  107. }), _react.default.createElement("span", null, this.props.name || 'No NAME'));
  108. }
  109. }]);
  110. return InputMarker;
  111. }(_react.default.Component); // Blueball Corporation Output marker handling for green light
  112. exports.InputMarker = InputMarker;
  113. var OutputMarkers = [];
  114. var OutputMarker =
  115. /*#__PURE__*/
  116. function (_React$Component3) {
  117. _inherits(OutputMarker, _React$Component3);
  118. function OutputMarker(props) {
  119. _classCallCheck(this, OutputMarker);
  120. return _possibleConstructorReturn(this, _getPrototypeOf(OutputMarker).call(this, props));
  121. }
  122. _createClass(OutputMarker, [{
  123. key: "componentDidMount",
  124. value: function componentDidMount() {
  125. OutputMarkers.push(this);
  126. }
  127. }, {
  128. key: "componentWillUnmount",
  129. value: function componentWillUnmount() {
  130. var indx = OutputMarkers.indexOf(this);
  131. if (indx > -1) OutputMarkers.splice(indx, 1);
  132. }
  133. }, {
  134. key: "drop",
  135. value: function drop(e) {
  136. e.stopPropagation();
  137. if (this.props.module) {
  138. window._selectedModule = this.props.module;
  139. OutputMarkers.map(function (marker) {
  140. return marker.forceUpdate();
  141. });
  142. } else {
  143. console.log("No module bind on this marker");
  144. }
  145. }
  146. }, {
  147. key: "_dragStart",
  148. value: function _dragStart(e) {
  149. this.drop(e);
  150. }
  151. }, {
  152. key: "render",
  153. value: function render() {
  154. var _this3 = this;
  155. var cls = this.props.module === window._selectedModule ? 'selected' : '';
  156. return _react.default.createElement("div", {
  157. className: "row left-align",
  158. style: {
  159. margin: 0
  160. }
  161. }, _react.default.createElement("div", {
  162. className: "col s2"
  163. }, _react.default.createElement("div", {
  164. className: 'OutputMarker ' + cls,
  165. onClick: function onClick(e) {
  166. return _this3.drop(e);
  167. },
  168. draggable: "true",
  169. onDragStart: function onDragStart(e) {
  170. return _this3._dragStart(e);
  171. }
  172. })), _react.default.createElement("div", {
  173. className: "col s10"
  174. }, this.props.text));
  175. }
  176. }]);
  177. return OutputMarker;
  178. }(_react.default.Component);
  179. exports.OutputMarker = OutputMarker;
  180. var OutputLink =
  181. /*#__PURE__*/
  182. function (_Dependencies) {
  183. _inherits(OutputLink, _Dependencies);
  184. function OutputLink(props) {
  185. _classCallCheck(this, OutputLink);
  186. return _possibleConstructorReturn(this, _getPrototypeOf(OutputLink).call(this, props));
  187. }
  188. _createClass(OutputLink, [{
  189. key: "drag",
  190. value: function drag() {
  191. this.LinkManager.selectOutput(this.props.output); //console.log(this.props.output);
  192. // console.log("OutputLink drop", this.props.input);
  193. if (this.props.onUpdate) this.props.onUpdate();
  194. this.forceUpdate();
  195. }
  196. }, {
  197. key: "render",
  198. value: function render() {
  199. var _this4 = this;
  200. // console.log(this.props.output)
  201. if (!this.props.output) return '';
  202. return _react.default.createElement("div", {
  203. className: "row Output"
  204. }, _react.default.createElement("div", {
  205. className: "col s2"
  206. }, _react.default.createElement("div", {
  207. className: "OutputMarker",
  208. onClick: function onClick() {
  209. return _this4.drag();
  210. },
  211. draggable: "true",
  212. onDragStart: function onDragStart() {
  213. return _this4.drag();
  214. }
  215. })), _react.default.createElement("div", {
  216. className: "col s5"
  217. }, this.props.output.name), _react.default.createElement("div", {
  218. className: "col s5"
  219. }, _react.default.createElement("button", {
  220. tabIndex: "-1",
  221. type: "button",
  222. className: "btn btn-secondary clearLinks",
  223. onClick: function onClick() {
  224. _this4.LinkManager.breakOutputLinks(_this4.props.output);
  225. _this4.forceUpdate();
  226. }
  227. }, _react.default.createElement("span", null, this.LinkManager.getOutputConnections(this.props.output).length), _react.default.createElement(_reactMaterialize.Icon, {
  228. tiny: true
  229. }, "leak_remove"))));
  230. }
  231. }]);
  232. return OutputLink;
  233. }(_Dependencies3.default);
  234. exports.OutputLink = OutputLink;
  235. var InputLink =
  236. /*#__PURE__*/
  237. function (_Dependencies2) {
  238. _inherits(InputLink, _Dependencies2);
  239. function InputLink(props) {
  240. _classCallCheck(this, InputLink);
  241. return _possibleConstructorReturn(this, _getPrototypeOf(InputLink).call(this, props));
  242. }
  243. _createClass(InputLink, [{
  244. key: "drop",
  245. value: function drop() {
  246. // console.log("Input drop", this.props.input);
  247. this.LinkManager.connectSelected(this.props.input);
  248. if (this.props.onUpdate) this.props.onUpdate();
  249. this.forceUpdate();
  250. }
  251. }, {
  252. key: "render",
  253. value: function render() {
  254. var _this5 = this;
  255. if (!this.props.input) return '';
  256. return _react.default.createElement("div", {
  257. className: "row Input"
  258. }, _react.default.createElement("div", {
  259. className: "col s2"
  260. }, _react.default.createElement("div", {
  261. className: "InputMarker",
  262. onClick: function onClick() {
  263. return _this5.drop();
  264. },
  265. onDrop: function onDrop() {
  266. return _this5.drop();
  267. }
  268. })), _react.default.createElement("div", {
  269. className: "col s5"
  270. }, this.props.input.name), _react.default.createElement("div", {
  271. className: "col s5"
  272. }, _react.default.createElement("button", {
  273. tabIndex: -1,
  274. type: "button",
  275. className: "btn btn-secondary clearLinks",
  276. onClick: function onClick() {
  277. _this5.LinkManager.breakInputLinks(_this5.props.input);
  278. _this5.forceUpdate();
  279. }
  280. }, _react.default.createElement("span", null, this.LinkManager.getInputConnections(this.props.input).length), _react.default.createElement(_reactMaterialize.Icon, {
  281. tiny: true
  282. }, "leak_remove"))));
  283. }
  284. }]);
  285. return InputLink;
  286. }(_Dependencies3.default);
  287. exports.InputLink = InputLink;
  288. var MakeView =
  289. /*#__PURE__*/
  290. function (_React$Component4) {
  291. _inherits(MakeView, _React$Component4);
  292. function MakeView(props) {
  293. var _this6;
  294. _classCallCheck(this, MakeView);
  295. _this6 = _possibleConstructorReturn(this, _getPrototypeOf(MakeView).call(this, props));
  296. _this6.state = {
  297. view: props.module.view.value || false
  298. };
  299. return _this6;
  300. }
  301. _createClass(MakeView, [{
  302. key: "setViewUrl",
  303. value: function setViewUrl(url) {
  304. //console.log(url);
  305. this.props.module._change('view', url);
  306. }
  307. }, {
  308. key: "render",
  309. value: function render() {
  310. var _this7 = this;
  311. return this.state.view ? _react.default.createElement("div", {
  312. className: "form-group"
  313. }, _react.default.createElement("label", null, "View"), _react.default.createElement("input", {
  314. type: "text",
  315. placeholder: "View",
  316. onChange: function onChange(e) {
  317. if (e.target.value === "") _this7.setViewUrl("");
  318. _this7.setState({
  319. view: e.target.value
  320. });
  321. },
  322. className: "form-control form-control-sm",
  323. value: this.state.view,
  324. onKeyPress: function onKeyPress(e) {
  325. if (e.key === "Enter") _this7.setViewUrl(_this7.state.view);
  326. }
  327. })) : _react.default.createElement("button", {
  328. className: "form-control form-control-sm",
  329. onClick: function onClick() {
  330. return _this7.setState({
  331. view: true
  332. });
  333. }
  334. }, "MakeView");
  335. }
  336. }]);
  337. return MakeView;
  338. }(_react.default.Component);
  339. exports.MakeView = MakeView;
  340. var ArrayInput =
  341. /*#__PURE__*/
  342. function (_React$Component5) {
  343. _inherits(ArrayInput, _React$Component5);
  344. function ArrayInput(props) {
  345. var _this8;
  346. _classCallCheck(this, ArrayInput);
  347. _this8 = _possibleConstructorReturn(this, _getPrototypeOf(ArrayInput).call(this, props));
  348. _this8.state = {
  349. newdata: null,
  350. text: ''
  351. };
  352. _this8.updateType(_this8.props.input.arrType);
  353. return _this8;
  354. }
  355. _createClass(ArrayInput, [{
  356. key: "updateType",
  357. value: function updateType(type) {
  358. this.Type = type;
  359. switch (this.Type) {
  360. case _Types.default.Boolean:
  361. this.ctor = BooleanInput;
  362. break;
  363. case _Types.default.Number:
  364. case _Types.default.Real:
  365. case _Types.default.Text:
  366. this.ctor = TextInput;
  367. break;
  368. case _Types.default.Object:
  369. this.ctor = ObjectInput;
  370. break;
  371. default:
  372. _Logger.default.warning("Array input with no arrType");
  373. break;
  374. }
  375. }
  376. }, {
  377. key: "remove",
  378. value: function remove(item) {
  379. var arr = _toConsumableArray(this.props.input.value);
  380. var indx = arr.indexOf(item);
  381. arr.splice(indx, 1);
  382. this.props.change(arr);
  383. }
  384. }, {
  385. key: "add",
  386. value: function add(item) {
  387. var arr = [].concat(_toConsumableArray(this.props.input.value), [item]);
  388. this.props.change(arr);
  389. }
  390. }, {
  391. key: "change",
  392. value: function change(key, item) {
  393. var arr = _toConsumableArray(this.props.input.value);
  394. arr[key] = item;
  395. this.props.change(arr);
  396. }
  397. }, {
  398. key: "render",
  399. value: function render() {
  400. var _this9 = this;
  401. var Renderer = this.ctor;
  402. return _react.default.createElement("div", {
  403. className: "form-group ArrayInput"
  404. }, _react.default.createElement("div", {
  405. className: "row"
  406. }, this.props.withoutLink ? '' : _react.default.createElement("div", {
  407. className: "col s12"
  408. }, _react.default.createElement(InputLink, {
  409. input: this.props.input
  410. })), _react.default.createElement("div", {
  411. className: "col s12"
  412. }, this.ctor ? this.props.input.value.map(function (item, key) {
  413. //console.log(item);
  414. return _react.default.createElement("div", {
  415. className: "row valign-wrapper",
  416. key: key + key
  417. }, _react.default.createElement("div", {
  418. className: "col"
  419. }, key), _react.default.createElement("div", {
  420. className: "col s11"
  421. }, _react.default.createElement(Renderer, {
  422. key: key,
  423. input: {
  424. value: item
  425. },
  426. change: function change(v) {
  427. return _this9.change(key, v);
  428. },
  429. withoutLink: true
  430. })));
  431. }) : "Cannot render this type: " + this.Type), _react.default.createElement("div", {
  432. className: "col s12"
  433. }, _react.default.createElement("div", {
  434. className: "row valign-wrapper"
  435. }, _react.default.createElement("div", {
  436. className: "col s5"
  437. }, _react.default.createElement(_reactMaterialize.Button, {
  438. onClick: function onClick() {
  439. _this9.add(_this9.state.newdata);
  440. _this9.setState({
  441. newdata: null
  442. });
  443. }
  444. }, "Add")), _react.default.createElement("div", {
  445. className: "col s7"
  446. }, _react.default.createElement(Renderer, {
  447. input: {},
  448. change: function change(newdata) {
  449. return _this9.setState({
  450. newdata: newdata
  451. });
  452. },
  453. withoutLink: true
  454. }))))));
  455. }
  456. }]);
  457. return ArrayInput;
  458. }(_react.default.Component);
  459. exports.ArrayInput = ArrayInput;
  460. var TextInput =
  461. /*#__PURE__*/
  462. function (_React$Component6) {
  463. _inherits(TextInput, _React$Component6);
  464. function TextInput(props) {
  465. _classCallCheck(this, TextInput);
  466. return _possibleConstructorReturn(this, _getPrototypeOf(TextInput).call(this, props));
  467. }
  468. _createClass(TextInput, [{
  469. key: "render",
  470. value: function render() {
  471. var _this10 = this;
  472. var random = Math.random() * 9876568;
  473. return _react.default.createElement("div", {
  474. className: "row TextInput"
  475. }, this.props.withoutLink ? '' : _react.default.createElement("div", {
  476. className: "col s12"
  477. }, _react.default.createElement(InputLink, {
  478. input: this.props.input
  479. })), _react.default.createElement("div", {
  480. className: "col " + (this.props.withoutLink ? 's12' : 's6')
  481. }, _react.default.createElement("input", {
  482. type: "text",
  483. placeholder: this.props.input.name,
  484. id: random,
  485. className: "form-control form-control-sm",
  486. tabIndex: "0",
  487. defaultValue: this.props.input.value,
  488. onBlur: function onBlur(e) {
  489. _this10.props.change(e.target.value);
  490. },
  491. onKeyPress: function onKeyPress(e) {
  492. if (e.key === "Enter") {
  493. _this10.props.change(e.target.value);
  494. }
  495. return e;
  496. }
  497. })));
  498. }
  499. }]);
  500. return TextInput;
  501. }(_react.default.Component);
  502. exports.TextInput = TextInput;
  503. var ObjectInput =
  504. /*#__PURE__*/
  505. function (_React$Component7) {
  506. _inherits(ObjectInput, _React$Component7);
  507. function ObjectInput(props) {
  508. _classCallCheck(this, ObjectInput);
  509. return _possibleConstructorReturn(this, _getPrototypeOf(ObjectInput).call(this, props));
  510. }
  511. _createClass(ObjectInput, [{
  512. key: "render",
  513. value: function render() {
  514. var _this11 = this;
  515. var obj = this.props.input.value;
  516. return _react.default.createElement("div", {
  517. className: "row ObjectInput"
  518. }, this.props.withoutLink ? '' : _react.default.createElement("div", {
  519. className: "col s12"
  520. }, _react.default.createElement("div", {
  521. className: "row"
  522. }, _react.default.createElement("div", {
  523. className: "col s10"
  524. }, _react.default.createElement(InputLink, {
  525. input: this.props.input
  526. })), _react.default.createElement("div", {
  527. className: "col s2"
  528. }, _react.default.createElement("input", {
  529. type: "text",
  530. className: "pasteField",
  531. onPaste: function onPaste(s) {
  532. var data = s.clipboardData.getData('Text');
  533. try {
  534. var r = JSON.parse(data);
  535. _this11.props.change(r);
  536. } catch (e) {
  537. return;
  538. }
  539. }
  540. })))), _react.default.createElement("div", {
  541. className: "col s12"
  542. }, _react.default.createElement(_reactJsonView.default, {
  543. src: obj,
  544. onAdd: function onAdd(add) {
  545. _this11.props.change(add.new_value);
  546. },
  547. theme: "apathy",
  548. onEdit: function onEdit(e) {
  549. return _this11.props.change(e.updated_src);
  550. },
  551. displayDataTypes: false,
  552. enableClipboard: true,
  553. collapsed: true,
  554. collapseStringsAfterLength: 7,
  555. onDelete: function onDelete(e) {
  556. return _this11.props.change(e.updated_src);
  557. }
  558. })));
  559. }
  560. }]);
  561. return ObjectInput;
  562. }(_react.default.Component);
  563. exports.ObjectInput = ObjectInput;
  564. var BooleanInput =
  565. /*#__PURE__*/
  566. function (_React$Component8) {
  567. _inherits(BooleanInput, _React$Component8);
  568. function BooleanInput(props) {
  569. _classCallCheck(this, BooleanInput);
  570. return _possibleConstructorReturn(this, _getPrototypeOf(BooleanInput).call(this, props));
  571. }
  572. _createClass(BooleanInput, [{
  573. key: "render",
  574. value: function render() {
  575. var _this12 = this;
  576. var v = this.props.input.value;
  577. return _react.default.createElement("div", {
  578. className: "row BooleanInput"
  579. }, _react.default.createElement("div", {
  580. className: "col s12"
  581. }, _react.default.createElement(InputLink, {
  582. input: this.props.input
  583. })), _react.default.createElement("div", {
  584. className: "switch col s12"
  585. }, _react.default.createElement("label", null, "Off", _react.default.createElement("input", {
  586. type: "checkbox",
  587. checked: v
  588. }), _react.default.createElement("span", {
  589. className: "lever",
  590. onClick: function onClick() {
  591. _this12.props.change(!v);
  592. }
  593. }), "On")));
  594. }
  595. }]);
  596. return BooleanInput;
  597. }(_react.default.Component);
  598. exports.BooleanInput = BooleanInput;
  599. function RendererInput(input, _change) {
  600. switch (input.type) {
  601. case _Types.default.View:
  602. break;
  603. return _react.default.createElement(MakeView, {
  604. module: this
  605. });
  606. case _Types.default.Boolean:
  607. return _react.default.createElement(BooleanInput, {
  608. input: input,
  609. change: function change(value) {
  610. return _change(input.name, value, input);
  611. }
  612. });
  613. case _Types.default.Whatever:
  614. case _Types.default.Text:
  615. case _Types.default.Number:
  616. case _Types.default.Real:
  617. return _react.default.createElement(TextInput, {
  618. input: input,
  619. change: function change(value) {
  620. return _change(input.name, value, input);
  621. }
  622. });
  623. case _Types.default.Array:
  624. return _react.default.createElement(ArrayInput, {
  625. input: input,
  626. change: function change(value) {
  627. return _change(input.name, value, input);
  628. }
  629. });
  630. case _Types.default.Object:
  631. return _react.default.createElement(ObjectInput, {
  632. input: input,
  633. change: function change(value) {
  634. return _change(input.name, value, input);
  635. }
  636. });
  637. case _Types.default.URL:
  638. break;
  639. case _Types.default.Link:
  640. return _react.default.createElement("div", {
  641. className: "row"
  642. }, _react.default.createElement("div", {
  643. className: "s6"
  644. }, _react.default.createElement(InputLink, {
  645. input: input
  646. })));
  647. default:
  648. throw new Error("Input not valid", input);
  649. break;
  650. }
  651. }
  652. function RendererOutput(output) {
  653. return _react.default.createElement("div", {
  654. className: "row"
  655. }, _react.default.createElement("div", {
  656. className: "col s6"
  657. }, _react.default.createElement(OutputLink, {
  658. output: output
  659. })));
  660. }
  661. function Resolver(input, value) {
  662. var msg = "Resolver cannot parse Input Field";
  663. switch (input.type) {
  664. case _Types.default.Object:
  665. input.value = value || input.value || {};
  666. break;
  667. case _Types.default.Boolean:
  668. if (value !== undefined && value !== null) {
  669. input.value = !!value;
  670. }
  671. break;
  672. case _Types.default.Number:
  673. try {
  674. input.value = parseInt(value === undefined || value === null ? input.value : value);
  675. } catch (e) {
  676. _Logger.default.warning(msg, {
  677. inputField: input
  678. });
  679. }
  680. break;
  681. case _Types.default.Real:
  682. try {
  683. input.value = parseFloat(value === undefined || value === null ? input.value : value);
  684. } catch (e) {
  685. _Logger.default.warning(msg, {
  686. inputField: input
  687. });
  688. }
  689. break;
  690. case _Types.default.Text:
  691. if (value !== undefined && value !== null) {
  692. input.value = value;
  693. }
  694. break;
  695. case _Types.default.Array:
  696. if (!Array.isArray(value)) {
  697. try {
  698. if (typeof value === "string") {
  699. input.value = JSON.parse(value);
  700. }
  701. } catch (e) {
  702. _Logger.default.warning(msg, {
  703. inputField: input
  704. });
  705. }
  706. } else {
  707. input.value = value;
  708. }
  709. break;
  710. default:
  711. input.value = value;
  712. break;
  713. }
  714. return input.value;
  715. }