TextEditor.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _react = _interopRequireDefault(require("react"));
  7. var _modularityFront = _interopRequireDefault(require("modularity-front"));
  8. var _reactMaterialize = require("react-materialize");
  9. var _Editor = _interopRequireDefault(require("./UserInputs/Editor"));
  10. var _Embed = _interopRequireDefault(require("./UserInputs/Embed"));
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. 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); }
  13. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14. 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); } }
  15. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18. function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
  19. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  20. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  21. 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); }
  22. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  23. var Module = _modularityFront.default.Module;
  24. var TextEditor =
  25. /*#__PURE__*/
  26. function (_Module) {
  27. _inherits(TextEditor, _Module);
  28. function TextEditor(props) {
  29. var _this;
  30. _classCallCheck(this, TextEditor);
  31. _this = _possibleConstructorReturn(this, _getPrototypeOf(TextEditor).call(this, props));
  32. _this.state = {
  33. mode: false
  34. };
  35. _this.admin = _this._mode === "admin" || _this._mode === "normal";
  36. return _this;
  37. }
  38. _createClass(TextEditor, [{
  39. key: "click",
  40. value: function click() {
  41. this.setState({
  42. mode: !this.state.mode
  43. });
  44. }
  45. }, {
  46. key: "change",
  47. value: function change(v) {
  48. this.Text.update(v);
  49. this.onChange.set(v);
  50. }
  51. }, {
  52. key: "render",
  53. value: function render() {
  54. var _this2 = this;
  55. var mode = localStorage.getItem('AdminMode') === "admin";
  56. return _react.default.createElement(_react.default.Fragment, null, this.state.mode && mode ? [_react.default.createElement(_Editor.default, {
  57. data: this.Text.value,
  58. onChange: function onChange(v) {
  59. return _this2.change(v);
  60. },
  61. key: 0
  62. }), _react.default.createElement("i", {
  63. className: 'fa fa-close',
  64. onClick: function onClick() {
  65. return _this2.click();
  66. },
  67. key: 1
  68. })] : _react.default.createElement(_Embed.default, {
  69. html: this.Text.value,
  70. onClick: mode ? function () {
  71. return _this2.click();
  72. } : undefined,
  73. className: (mode ? 'pointer ' : '') + this.className.value
  74. }), _get(_getPrototypeOf(TextEditor.prototype), "render", this).call(this));
  75. }
  76. }]);
  77. return TextEditor;
  78. }(Module);
  79. TextEditor.Inputs = {
  80. "Text": {
  81. type: Module.Types.Text,
  82. defaultValue: "Sample text with <b>bold</b> and <i>Italics</i>"
  83. },
  84. "className": {
  85. type: Module.Types.Text
  86. }
  87. };
  88. TextEditor.Outputs = {
  89. "onChange": {}
  90. };
  91. TextEditor.Category = "Inputs";
  92. var _default = TextEditor;
  93. exports.default = _default;