@pie-lib/editable-html 10.0.0-beta.7 → 10.0.0

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 (118) hide show
  1. package/CHANGELOG.json +1 -1
  2. package/CHANGELOG.md +81 -0
  3. package/LICENSE.md +5 -0
  4. package/lib/editor.js +410 -543
  5. package/lib/editor.js.map +1 -1
  6. package/lib/index.js +200 -101
  7. package/lib/index.js.map +1 -1
  8. package/lib/parse-html.js +5 -6
  9. package/lib/parse-html.js.map +1 -1
  10. package/lib/plugins/characters/custom-popper.js +12 -2
  11. package/lib/plugins/characters/custom-popper.js.map +1 -1
  12. package/lib/plugins/characters/index.js +71 -19
  13. package/lib/plugins/characters/index.js.map +1 -1
  14. package/lib/plugins/characters/utils.js.map +1 -1
  15. package/lib/plugins/html/icons/index.js +38 -0
  16. package/lib/plugins/html/icons/index.js.map +1 -0
  17. package/lib/plugins/html/index.js +75 -0
  18. package/lib/plugins/html/index.js.map +1 -0
  19. package/lib/plugins/image/alt-dialog.js +26 -0
  20. package/lib/plugins/image/alt-dialog.js.map +1 -1
  21. package/lib/plugins/image/component.js +124 -90
  22. package/lib/plugins/image/component.js.map +1 -1
  23. package/lib/plugins/image/image-toolbar.js +45 -7
  24. package/lib/plugins/image/image-toolbar.js.map +1 -1
  25. package/lib/plugins/image/index.js +91 -113
  26. package/lib/plugins/image/index.js.map +1 -1
  27. package/lib/plugins/image/insert-image-handler.js +54 -72
  28. package/lib/plugins/image/insert-image-handler.js.map +1 -1
  29. package/lib/plugins/index.js +71 -31
  30. package/lib/plugins/index.js.map +1 -1
  31. package/lib/plugins/list/index.js +129 -58
  32. package/lib/plugins/list/index.js.map +1 -1
  33. package/lib/plugins/math/index.js +152 -118
  34. package/lib/plugins/math/index.js.map +1 -1
  35. package/lib/plugins/media/index.js +185 -168
  36. package/lib/plugins/media/index.js.map +1 -1
  37. package/lib/plugins/media/media-dialog.js +197 -110
  38. package/lib/plugins/media/media-dialog.js.map +1 -1
  39. package/lib/plugins/media/media-toolbar.js +24 -4
  40. package/lib/plugins/media/media-toolbar.js.map +1 -1
  41. package/lib/plugins/media/media-wrapper.js +65 -23
  42. package/lib/plugins/media/media-wrapper.js.map +1 -1
  43. package/lib/plugins/respArea/drag-in-the-blank/choice.js +50 -10
  44. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
  45. package/lib/plugins/respArea/drag-in-the-blank/index.js +22 -9
  46. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
  47. package/lib/plugins/respArea/explicit-constructed-response/index.js +9 -4
  48. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
  49. package/lib/plugins/respArea/icons/index.js +18 -1
  50. package/lib/plugins/respArea/icons/index.js.map +1 -1
  51. package/lib/plugins/respArea/index.js +133 -122
  52. package/lib/plugins/respArea/index.js.map +1 -1
  53. package/lib/plugins/respArea/inline-dropdown/index.js +10 -4
  54. package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
  55. package/lib/plugins/respArea/utils.js +33 -15
  56. package/lib/plugins/respArea/utils.js.map +1 -1
  57. package/lib/plugins/table/icons/index.js +7 -0
  58. package/lib/plugins/table/icons/index.js.map +1 -1
  59. package/lib/plugins/table/index.js +279 -390
  60. package/lib/plugins/table/index.js.map +1 -1
  61. package/lib/plugins/table/table-toolbar.js +47 -14
  62. package/lib/plugins/table/table-toolbar.js.map +1 -1
  63. package/lib/plugins/toolbar/default-toolbar.js +63 -51
  64. package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
  65. package/lib/plugins/toolbar/done-button.js +9 -1
  66. package/lib/plugins/toolbar/done-button.js.map +1 -1
  67. package/lib/plugins/toolbar/editor-and-toolbar.js +140 -83
  68. package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
  69. package/lib/plugins/toolbar/index.js +5 -0
  70. package/lib/plugins/toolbar/index.js.map +1 -1
  71. package/lib/plugins/toolbar/toolbar-buttons.js +39 -8
  72. package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
  73. package/lib/plugins/toolbar/toolbar.js +261 -225
  74. package/lib/plugins/toolbar/toolbar.js.map +1 -1
  75. package/lib/plugins/utils.js +16 -19
  76. package/lib/plugins/utils.js.map +1 -1
  77. package/lib/serialization.js +70 -11
  78. package/lib/serialization.js.map +1 -1
  79. package/lib/theme.js.map +1 -1
  80. package/package.json +18 -17
  81. package/src/editor.jsx +139 -434
  82. package/src/index.jsx +96 -62
  83. package/src/plugins/characters/index.jsx +17 -12
  84. package/src/plugins/html/icons/index.jsx +19 -0
  85. package/src/plugins/html/index.jsx +68 -0
  86. package/src/plugins/image/component.jsx +38 -60
  87. package/src/plugins/image/index.jsx +42 -95
  88. package/src/plugins/image/insert-image-handler.js +27 -62
  89. package/src/plugins/index.jsx +39 -21
  90. package/src/plugins/list/index.jsx +90 -62
  91. package/src/plugins/math/index.jsx +70 -93
  92. package/src/plugins/media/index.jsx +117 -146
  93. package/src/plugins/media/media-dialog.js +9 -10
  94. package/src/plugins/media/media-wrapper.jsx +27 -29
  95. package/src/plugins/respArea/drag-in-the-blank/index.jsx +4 -5
  96. package/src/plugins/respArea/explicit-constructed-response/index.jsx +1 -2
  97. package/src/plugins/respArea/index.jsx +84 -114
  98. package/src/plugins/respArea/inline-dropdown/index.jsx +2 -3
  99. package/src/plugins/respArea/utils.jsx +28 -23
  100. package/src/plugins/table/index.jsx +214 -334
  101. package/src/plugins/table/table-toolbar.jsx +4 -3
  102. package/src/plugins/toolbar/default-toolbar.jsx +30 -48
  103. package/src/plugins/toolbar/editor-and-toolbar.jsx +114 -114
  104. package/src/plugins/toolbar/toolbar.jsx +224 -254
  105. package/src/plugins/utils.js +0 -16
  106. package/src/serialization.jsx +1 -1
  107. package/lib/components.js +0 -92
  108. package/lib/components.js.map +0 -1
  109. package/lib/new-serialization.js +0 -280
  110. package/lib/new-serialization.js.map +0 -1
  111. package/lib/plugins/hotKeys/index.js +0 -60
  112. package/lib/plugins/hotKeys/index.js.map +0 -1
  113. package/lib/test-serializer.js +0 -138
  114. package/lib/test-serializer.js.map +0 -1
  115. package/src/components.js +0 -135
  116. package/src/new-serialization.jsx +0 -310
  117. package/src/plugins/hotKeys/index.js +0 -54
  118. package/src/test-serializer.js +0 -132
package/lib/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
4
5
  var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
@@ -27,139 +29,236 @@ exports["default"] = void 0;
27
29
  Object.defineProperty(exports, "htmlToValue", {
28
30
  enumerable: true,
29
31
  get: function get() {
30
- return _newSerialization.htmlToValue;
32
+ return _serialization.htmlToValue;
31
33
  }
32
34
  });
33
35
  Object.defineProperty(exports, "valueToHtml", {
34
36
  enumerable: true,
35
37
  get: function get() {
36
- return _newSerialization.valueToHtml;
38
+ return _serialization.valueToHtml;
37
39
  }
38
40
  });
41
+
39
42
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
43
+
44
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
45
+
46
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
47
+
48
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
49
+
50
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
51
+
52
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
53
+
54
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
55
+
40
56
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
41
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
42
- var _react = _interopRequireWildcard(require("react"));
43
- var _slateReact = require("slate-react");
57
+
58
+ var _react = _interopRequireDefault(require("react"));
59
+
44
60
  var _propTypes = _interopRequireDefault(require("prop-types"));
61
+
45
62
  var _editor = _interopRequireWildcard(require("./editor"));
46
- var _newSerialization = require("./new-serialization");
63
+
64
+ var _serialization = require("./serialization");
65
+
47
66
  var _parseHtml = require("./parse-html");
67
+
48
68
  var _debug = _interopRequireDefault(require("debug"));
69
+
49
70
  var _slate = require("slate");
50
- var _this = void 0;
71
+
51
72
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
73
+
52
74
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
75
+
53
76
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
77
+
54
78
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
79
+
80
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
81
+
82
+ 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; } }
83
+
55
84
  var log = (0, _debug["default"])('@pie-lib:editable-html');
56
85
  /**
57
86
  * Export lower level Editor and serialization functions.
58
87
  */
59
88
 
60
- var useConstructor = function useConstructor() {
61
- var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
62
- var _useState = (0, _react.useState)(false),
63
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
64
- hasBeenCalled = _useState2[0],
65
- setHasBeenCalled = _useState2[1];
66
- if (hasBeenCalled) {
67
- return;
89
+ /**
90
+ * Wrapper around the editor that exposes a `markup` and `onChange(markup:string)` api.
91
+ * Because of the mismatch between the markup and the `Value` we need to convert the incoming markup to a value and
92
+ * compare it. TODO: This is an interim fix, we'll need to strip back `Editor` and look how best to maintain the
93
+ * `markup` api whilst avoiding the serialization mismatch. We should be making better use of schemas w/ normalize.
94
+ */
95
+ var reduceMultipleBrs = function reduceMultipleBrs(markup) {
96
+ try {
97
+ return markup.replace(/(<br\s*\/?>){3,}/gi, '<br>');
98
+ } catch (e) {
99
+ // eslint-disable-next-line no-console
100
+ console.log("Couldn't remove <br/> tags: ", e);
68
101
  }
69
- callback();
70
- setHasBeenCalled(true);
102
+
103
+ return markup;
71
104
  };
72
- var EditableHtml = /*#__PURE__*/_react["default"].forwardRef(function (props, forwardedRef) {
73
- var _editorRef = (0, _react.useRef)(null);
74
- var rootRef = (0, _react.useRef)(null);
75
- var _useState3 = (0, _react.useState)(),
76
- _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
77
- value = _useState4[0],
78
- setValue = _useState4[1];
79
- useConstructor(function () {
80
- var v = (0, _newSerialization.htmlToValue)(props.markup);
81
- setValue(v);
82
- });
83
- var onChange = function onChange(value, done) {
84
- var html = (0, _newSerialization.valueToHtml)(value);
85
- var htmlParsed = (0, _parseHtml.parseDegrees)(html);
86
- log('value as html: ', html);
87
- if (html !== props.markup) {
88
- props.onChange(htmlParsed);
89
- }
90
- if (done) {
91
- props.onDone(htmlParsed);
92
- }
93
- };
94
- var focus = function focus(position, node) {
95
- var select = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
96
- if (_this.editorRef) {
97
- _this.editorRef.change(function (c) {
98
- var lastText = node ? c.value.document.getNextText(node.key) : c.value.document.getLastText();
99
- var editorDOM = document.querySelector("[data-key=\"".concat(_this.editorRef.value.document.key, "\"]"));
100
- if (editorDOM !== document.activeElement) {
101
- document.activeElement.blur();
102
- }
103
- c.focus();
104
- if (position === 'end' && lastText) {
105
- var _lastText$text, _lastText$text2;
106
- c.moveFocusTo(lastText.key, (_lastText$text = lastText.text) === null || _lastText$text === void 0 ? void 0 : _lastText$text.length).moveAnchorTo(lastText.key, (_lastText$text2 = lastText.text) === null || _lastText$text2 === void 0 ? void 0 : _lastText$text2.length);
107
- if (select) {
108
- var _lastText$text3;
109
- var range = _slate.Range.fromJSON({
110
- anchorKey: lastText.key,
111
- anchorOffset: 0,
112
- focusKey: lastText.key,
113
- focusOffset: (_lastText$text3 = lastText.text) === null || _lastText$text3 === void 0 ? void 0 : _lastText$text3.length,
114
- isFocused: true,
115
- isBackward: false
116
- });
117
- c.select(range);
118
- }
119
- }
120
- if (position === 'beginning' && lastText) {
121
- c.moveFocusTo(lastText.key, 0).moveAnchorTo(lastText.key, 0);
122
- }
123
- editorDOM.focus();
105
+
106
+ var EditableHtml = /*#__PURE__*/function (_React$Component) {
107
+ (0, _inherits2["default"])(EditableHtml, _React$Component);
108
+
109
+ var _super = _createSuper(EditableHtml);
110
+
111
+ function EditableHtml(props) {
112
+ var _this;
113
+
114
+ (0, _classCallCheck2["default"])(this, EditableHtml);
115
+ _this = _super.call(this, props);
116
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "runSerializationOnMarkup", function () {
117
+ if (!_this.props.markup) {
118
+ return;
119
+ }
120
+
121
+ var v = (0, _serialization.htmlToValue)(reduceMultipleBrs(_this.props.markup));
122
+
123
+ _this.setState({
124
+ value: v
124
125
  });
126
+ });
127
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChange", function (value, done) {
128
+ var html = (0, _serialization.valueToHtml)(value);
129
+ var htmlParsed = (0, _parseHtml.parseDegrees)(html);
130
+ log('value as html: ', html);
131
+
132
+ if (html !== _this.props.markup) {
133
+ _this.props.onChange(htmlParsed);
134
+ }
135
+
136
+ if (done) {
137
+ _this.props.onDone(htmlParsed);
138
+ }
139
+ });
140
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "focus", function (position, node) {
141
+ var select = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
142
+
143
+ if (_this.editorRef) {
144
+ _this.editorRef.change(function (c) {
145
+ var lastText = node ? c.value.document.getNextText(node.key) : c.value.document.getLastText();
146
+ var editorDOM = document.querySelector("[data-key=\"".concat(_this.editorRef.value.document.key, "\"]"));
147
+
148
+ if (editorDOM !== document.activeElement) {
149
+ document.activeElement.blur();
150
+ }
151
+
152
+ c.focus();
153
+
154
+ if (position === 'end' && lastText) {
155
+ var _lastText$text, _lastText$text2;
156
+
157
+ c.moveFocusTo(lastText.key, (_lastText$text = lastText.text) === null || _lastText$text === void 0 ? void 0 : _lastText$text.length).moveAnchorTo(lastText.key, (_lastText$text2 = lastText.text) === null || _lastText$text2 === void 0 ? void 0 : _lastText$text2.length);
158
+
159
+ if (select) {
160
+ var _lastText$text3;
161
+
162
+ var range = _slate.Range.fromJSON({
163
+ anchorKey: lastText.key,
164
+ anchorOffset: 0,
165
+ focusKey: lastText.key,
166
+ focusOffset: (_lastText$text3 = lastText.text) === null || _lastText$text3 === void 0 ? void 0 : _lastText$text3.length,
167
+ isFocused: true,
168
+ isBackward: false
169
+ });
170
+
171
+ c.select(range);
172
+ }
173
+ }
174
+
175
+ if (position === 'beginning' && lastText) {
176
+ c.moveFocusTo(lastText.key, 0).moveAnchorTo(lastText.key, 0);
177
+ }
178
+
179
+ editorDOM.focus();
180
+ });
181
+ }
182
+ });
183
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "finishEditing", function () {
184
+ if (_this.editorRef) {
185
+ _this.editorRef.props.onEditingDone();
186
+ }
187
+ });
188
+
189
+ var _v = (0, _serialization.htmlToValue)(props.markup);
190
+
191
+ _this.state = {
192
+ value: _v
193
+ };
194
+ return _this;
195
+ } // eslint-disable-next-line react/no-deprecated
196
+
197
+
198
+ (0, _createClass2["default"])(EditableHtml, [{
199
+ key: "componentWillReceiveProps",
200
+ value: function componentWillReceiveProps(props) {
201
+ if (!props.allowValidation && props.markup === this.props.markup) {
202
+ return;
203
+ }
204
+
205
+ var v = (0, _serialization.htmlToValue)(reduceMultipleBrs(props.markup));
206
+ var current = (0, _serialization.htmlToValue)(reduceMultipleBrs(this.props.markup));
207
+
208
+ if (v.equals && !v.equals(current)) {
209
+ this.setState({
210
+ value: v
211
+ });
212
+ }
125
213
  }
126
- };
127
- var toolbarOpts = props.toolbarOpts,
128
- error = props.error;
129
- if (toolbarOpts) {
130
- toolbarOpts.error = error;
131
- }
132
- var newProps = _objectSpread(_objectSpread({}, props), {}, {
133
- markup: null,
134
- value: value,
135
- onChange: onChange,
136
- focus: focus
137
- });
138
- return /*#__PURE__*/_react["default"].createElement(_editor["default"], (0, _extends2["default"])({}, newProps, {
139
- onRef: function onRef(ref) {
140
- if (ref) {
141
- rootRef.current = ref;
142
- if (forwardedRef) {
143
- forwardedRef(ref);
144
- }
214
+ }, {
215
+ key: "render",
216
+ value: function render() {
217
+ var _this2 = this;
218
+
219
+ var value = this.state.value;
220
+ var _this$props = this.props,
221
+ toolbarOpts = _this$props.toolbarOpts,
222
+ error = _this$props.error;
223
+
224
+ if (toolbarOpts) {
225
+ toolbarOpts.error = error;
145
226
  }
146
- },
147
- editorRef: function editorRef(ref) {
148
- return ref && (_editorRef.current = ref);
227
+
228
+ var props = _objectSpread(_objectSpread({}, this.props), {}, {
229
+ markup: null,
230
+ value: value,
231
+ onChange: this.onChange,
232
+ focus: this.focus,
233
+ runSerializationOnMarkup: this.runSerializationOnMarkup
234
+ });
235
+
236
+ return /*#__PURE__*/_react["default"].createElement(_editor["default"], (0, _extends2["default"])({
237
+ onRef: function onRef(ref) {
238
+ if (ref) {
239
+ _this2.rootRef = ref;
240
+ }
241
+ },
242
+ editorRef: function editorRef(ref) {
243
+ return ref && (_this2.editorRef = ref);
244
+ }
245
+ }, props));
149
246
  }
150
- }));
151
- });
152
- EditableHtml.propTypes = {
247
+ }]);
248
+ return EditableHtml;
249
+ }(_react["default"].Component);
250
+
251
+ exports["default"] = EditableHtml;
252
+ (0, _defineProperty2["default"])(EditableHtml, "propTypes", {
253
+ error: _propTypes["default"].any,
153
254
  onChange: _propTypes["default"].func.isRequired,
154
255
  onDone: _propTypes["default"].func,
155
- onEditor: _propTypes["default"].func,
156
256
  markup: _propTypes["default"].string.isRequired,
157
- allowValidation: _propTypes["default"].bool
158
- };
159
- EditableHtml.defaultProps = {
257
+ allowValidation: _propTypes["default"].bool,
258
+ toolbarOpts: _propTypes["default"].object
259
+ });
260
+ (0, _defineProperty2["default"])(EditableHtml, "defaultProps", {
160
261
  onDone: function onDone() {},
161
262
  allowValidation: false
162
- };
163
- var _default = EditableHtml;
164
- exports["default"] = _default;
263
+ });
165
264
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_react","_interopRequireWildcard","require","_slateReact","_propTypes","_interopRequireDefault","_editor","_newSerialization","_parseHtml","_debug","_slate","_this","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ownKeys","object","enumerableOnly","keys","getOwnPropertySymbols","symbols","filter","sym","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","log","debug","useConstructor","callback","undefined","_useState","useState","_useState2","_slicedToArray2","hasBeenCalled","setHasBeenCalled","EditableHtml","React","forwardRef","props","forwardedRef","editorRef","useRef","rootRef","_useState3","_useState4","value","setValue","v","htmlToValue","markup","onChange","done","html","valueToHtml","htmlParsed","parseDegrees","onDone","focus","position","node","select","change","c","lastText","document","getNextText","getLastText","editorDOM","querySelector","concat","activeElement","blur","_lastText$text","_lastText$text2","moveFocusTo","text","moveAnchorTo","_lastText$text3","range","Range","fromJSON","anchorKey","anchorOffset","focusKey","focusOffset","isFocused","isBackward","toolbarOpts","error","newProps","createElement","_extends2","onRef","ref","current","propTypes","PropTypes","func","isRequired","onEditor","string","allowValidation","bool","defaultProps","_default","exports"],"sources":["../src/index.jsx"],"sourcesContent":["import React, { useState, useRef, useEffect } from 'react';\nimport { useSlate } from 'slate-react';\nimport PropTypes from 'prop-types';\nimport Editor, { DEFAULT_PLUGINS, ALL_PLUGINS } from './editor';\nimport { htmlToValue, valueToHtml } from './new-serialization';\nimport { parseDegrees } from './parse-html';\nimport debug from 'debug';\nimport { Range } from 'slate';\n\nconst log = debug('@pie-lib:editable-html');\n/**\n * Export lower level Editor and serialization functions.\n */\nexport { htmlToValue, valueToHtml, Editor, DEFAULT_PLUGINS, ALL_PLUGINS };\n\nconst useConstructor = (callback = () => {}) => {\n const [hasBeenCalled, setHasBeenCalled] = useState(false);\n\n if (hasBeenCalled) {\n return;\n }\n\n callback();\n setHasBeenCalled(true);\n};\n\nconst EditableHtml = React.forwardRef((props, forwardedRef) => {\n const editorRef = useRef(null);\n const rootRef = useRef(null);\n const [value, setValue] = useState();\n\n useConstructor(() => {\n const v = htmlToValue(props.markup);\n setValue(v);\n });\n\n const onChange = (value, done) => {\n const html = valueToHtml(value);\n const htmlParsed = parseDegrees(html);\n\n log('value as html: ', html);\n\n if (html !== props.markup) {\n props.onChange(htmlParsed);\n }\n\n if (done) {\n props.onDone(htmlParsed);\n }\n };\n\n const focus = (position, node, select = false) => {\n if (this.editorRef) {\n this.editorRef.change((c) => {\n const lastText = node ? c.value.document.getNextText(node.key) : c.value.document.getLastText();\n const editorDOM = document.querySelector(`[data-key=\"${this.editorRef.value.document.key}\"]`);\n\n if (editorDOM !== document.activeElement) {\n document.activeElement.blur();\n }\n\n c.focus();\n\n if (position === 'end' && lastText) {\n c.moveFocusTo(lastText.key, lastText.text?.length).moveAnchorTo(lastText.key, lastText.text?.length);\n if (select) {\n const range = Range.fromJSON({\n anchorKey: lastText.key,\n anchorOffset: 0,\n focusKey: lastText.key,\n focusOffset: lastText.text?.length,\n isFocused: true,\n isBackward: false,\n });\n c.select(range);\n }\n }\n\n if (position === 'beginning' && lastText) {\n c.moveFocusTo(lastText.key, 0).moveAnchorTo(lastText.key, 0);\n }\n editorDOM.focus();\n });\n }\n };\n\n const { toolbarOpts, error } = props;\n\n if (toolbarOpts) {\n toolbarOpts.error = error;\n }\n\n const newProps = {\n ...props,\n markup: null,\n value,\n onChange,\n focus,\n };\n\n return (\n <Editor\n {...newProps}\n onRef={ref => {\n if (ref) {\n rootRef.current = ref;\n\n if (forwardedRef) {\n forwardedRef(ref);\n }\n }\n }}\n editorRef={ref => ref && (editorRef.current = ref)}\n />\n );\n});\n\nEditableHtml.propTypes = {\n onChange: PropTypes.func.isRequired,\n onDone: PropTypes.func,\n onEditor: PropTypes.func,\n markup: PropTypes.string.isRequired,\n allowValidation: PropTypes.bool\n};\n\nEditableHtml.defaultProps = {\n onDone: () => {},\n allowValidation: false\n};\n\nexport default EditableHtml;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAL,uBAAA,CAAAC,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAJ,sBAAA,CAAAH,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AAA8B,IAAAS,KAAA;AAAA,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAZ,wBAAAgB,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,aAAAE,OAAA,CAAAF,GAAA,yBAAAA,GAAA,uCAAAA,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,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;IACRW,MAAM,EAAE,IAAI;IACZJ,KAAK,EAALA,KAAK;IACLK,QAAQ,EAARA,QAAQ;IACRO,KAAK,EAALA;EAAK,EACN;EAED,oBACExF,MAAA,YAAAyH,aAAA,CAACnH,OAAA,WAAM,MAAAoH,SAAA,iBACDF,QAAQ;IACZG,KAAK,EAAE,SAAAA,MAAAC,GAAG,EAAI;MACZ,IAAIA,GAAG,EAAE;QACPnD,OAAO,CAACoD,OAAO,GAAGD,GAAG;QAErB,IAAItD,YAAY,EAAE;UAChBA,YAAY,CAACsD,GAAG,CAAC;QACnB;MACF;IACF,CAAE;IACFrD,SAAS,EAAE,SAAAA,UAAAqD,GAAG;MAAA,OAAIA,GAAG,KAAKrD,UAAS,CAACsD,OAAO,GAAGD,GAAG,CAAC;IAAA;EAAC,EACpD,CAAC;AAEN,CAAC,CAAC;AAEF1D,YAAY,CAAC4D,SAAS,GAAG;EACvB7C,QAAQ,EAAE8C,qBAAS,CAACC,IAAI,CAACC,UAAU;EACnC1C,MAAM,EAAEwC,qBAAS,CAACC,IAAI;EACtBE,QAAQ,EAAEH,qBAAS,CAACC,IAAI;EACxBhD,MAAM,EAAE+C,qBAAS,CAACI,MAAM,CAACF,UAAU;EACnCG,eAAe,EAAEL,qBAAS,CAACM;AAC7B,CAAC;AAEDnE,YAAY,CAACoE,YAAY,GAAG;EAC1B/C,MAAM,EAAE,SAAAA,OAAA,EAAM,CAAC,CAAC;EAChB6C,eAAe,EAAE;AACnB,CAAC;AAAC,IAAAG,QAAA,GAEarE,YAAY;AAAAsE,OAAA,cAAAD,QAAA"}
1
+ {"version":3,"sources":["../src/index.jsx"],"names":["log","reduceMultipleBrs","markup","replace","e","console","EditableHtml","props","v","setState","value","done","html","htmlParsed","onChange","onDone","position","node","select","editorRef","change","c","lastText","document","getNextText","key","getLastText","editorDOM","querySelector","activeElement","blur","focus","moveFocusTo","text","length","moveAnchorTo","range","Range","fromJSON","anchorKey","anchorOffset","focusKey","focusOffset","isFocused","isBackward","onEditingDone","state","allowValidation","current","equals","toolbarOpts","error","runSerializationOnMarkup","ref","rootRef","React","Component","PropTypes","any","func","isRequired","string","bool","object"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,wBAAN,CAAZ;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,MAAD,EAAY;AACpC,MAAI;AACF,WAAOA,MAAM,CAACC,OAAP,CAAe,oBAAf,EAAqC,MAArC,CAAP;AACD,GAFD,CAEE,OAAOC,CAAP,EAAU;AACV;AACAC,IAAAA,OAAO,CAACL,GAAR,CAAY,8BAAZ,EAA4CI,CAA5C;AACD;;AAED,SAAOF,MAAP;AACD,CATD;;IAWqBI,Y;;;;;AAenB,wBAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,iHAsBQ,YAAM;AAC/B,UAAI,CAAC,MAAKA,KAAL,CAAWL,MAAhB,EAAwB;AACtB;AACD;;AAED,UAAMM,CAAC,GAAG,gCAAYP,iBAAiB,CAAC,MAAKM,KAAL,CAAWL,MAAZ,CAA7B,CAAV;;AAEA,YAAKO,QAAL,CAAc;AAAEC,QAAAA,KAAK,EAAEF;AAAT,OAAd;AACD,KA9BkB;AAAA,iGAgCR,UAACE,KAAD,EAAQC,IAAR,EAAiB;AAC1B,UAAMC,IAAI,GAAG,gCAAYF,KAAZ,CAAb;AACA,UAAMG,UAAU,GAAG,6BAAaD,IAAb,CAAnB;AAEAZ,MAAAA,GAAG,CAAC,iBAAD,EAAoBY,IAApB,CAAH;;AAEA,UAAIA,IAAI,KAAK,MAAKL,KAAL,CAAWL,MAAxB,EAAgC;AAC9B,cAAKK,KAAL,CAAWO,QAAX,CAAoBD,UAApB;A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Types from 'prop-types';\nimport Editor, { DEFAULT_PLUGINS, ALL_PLUGINS } from './editor';\nimport { htmlToValue, valueToHtml } from './serialization';\nimport { parseDegrees } from './parse-html';\nimport debug from 'debug';\nimport { Range } from 'slate';\n\nconst log = debug('@pie-lib:editable-html');\n/**\n * Export lower level Editor and serialization functions.\n */\nexport { htmlToValue, valueToHtml, Editor, DEFAULT_PLUGINS, ALL_PLUGINS };\n\n/**\n * Wrapper around the editor that exposes a `markup` and `onChange(markup:string)` api.\n * Because of the mismatch between the markup and the `Value` we need to convert the incoming markup to a value and\n * compare it. TODO: This is an interim fix, we'll need to strip back `Editor` and look how best to maintain the\n * `markup` api whilst avoiding the serialization mismatch. We should be making better use of schemas w/ normalize.\n */\n\nconst reduceMultipleBrs = (markup) => {\n try {\n return markup.replace(/(<br\\s*\\/?>){3,}/gi, '<br>');\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(\"Couldn't remove <br/> tags: \", e);\n }\n\n return markup;\n};\n\nexport default class EditableHtml extends React.Component {\n static propTypes = {\n error: PropTypes.any,\n onChange: PropTypes.func.isRequired,\n onDone: PropTypes.func,\n markup: PropTypes.string.isRequired,\n allowValidation: PropTypes.bool,\n toolbarOpts: PropTypes.object,\n };\n\n static defaultProps = {\n onDone: () => {},\n allowValidation: false,\n };\n\n constructor(props) {\n super(props);\n const v = htmlToValue(props.markup);\n this.state = {\n value: v,\n };\n }\n\n // eslint-disable-next-line react/no-deprecated\n componentWillReceiveProps(props) {\n if (!props.allowValidation && props.markup === this.props.markup) {\n return;\n }\n\n const v = htmlToValue(reduceMultipleBrs(props.markup));\n const current = htmlToValue(reduceMultipleBrs(this.props.markup));\n\n if (v.equals && !v.equals(current)) {\n this.setState({ value: v });\n }\n }\n\n runSerializationOnMarkup = () => {\n if (!this.props.markup) {\n return;\n }\n\n const v = htmlToValue(reduceMultipleBrs(this.props.markup));\n\n this.setState({ value: v });\n };\n\n onChange = (value, done) => {\n const html = valueToHtml(value);\n const htmlParsed = parseDegrees(html);\n\n log('value as html: ', html);\n\n if (html !== this.props.markup) {\n this.props.onChange(htmlParsed);\n }\n\n if (done) {\n this.props.onDone(htmlParsed);\n }\n };\n\n focus = (position, node, select = false) => {\n if (this.editorRef) {\n this.editorRef.change((c) => {\n const lastText = node ? c.value.document.getNextText(node.key) : c.value.document.getLastText();\n const editorDOM = document.querySelector(`[data-key=\"${this.editorRef.value.document.key}\"]`);\n\n if (editorDOM !== document.activeElement) {\n document.activeElement.blur();\n }\n\n c.focus();\n\n if (position === 'end' && lastText) {\n c.moveFocusTo(lastText.key, lastText.text?.length).moveAnchorTo(lastText.key, lastText.text?.length);\n if (select) {\n const range = Range.fromJSON({\n anchorKey: lastText.key,\n anchorOffset: 0,\n focusKey: lastText.key,\n focusOffset: lastText.text?.length,\n isFocused: true,\n isBackward: false,\n });\n c.select(range);\n }\n }\n\n if (position === 'beginning' && lastText) {\n c.moveFocusTo(lastText.key, 0).moveAnchorTo(lastText.key, 0);\n }\n editorDOM.focus();\n });\n }\n };\n\n finishEditing = () => {\n if (this.editorRef) {\n this.editorRef.props.onEditingDone();\n }\n };\n\n render() {\n const { value } = this.state;\n const { toolbarOpts, error } = this.props;\n\n if (toolbarOpts) {\n toolbarOpts.error = error;\n }\n\n const props = {\n ...this.props,\n markup: null,\n value,\n onChange: this.onChange,\n focus: this.focus,\n runSerializationOnMarkup: this.runSerializationOnMarkup,\n };\n\n return (\n <Editor\n onRef={(ref) => {\n if (ref) {\n this.rootRef = ref;\n }\n }}\n editorRef={(ref) => ref && (this.editorRef = ref)}\n {...props}\n />\n );\n }\n}\n"],"file":"index.js"}
package/lib/parse-html.js CHANGED
@@ -4,14 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.parseDegrees = void 0;
7
+
7
8
  var parseDegrees = function parseDegrees(html) {
8
- return html
9
- // removes \( use case: 50°
10
- .replace(/\\[(]/g, '')
11
- // removes \) use case: 50°+m<1
12
- .replace(/\\[)]/g, '')
13
- // removes \degree use case: 50°
9
+ return html // removes \( use case: 50°
10
+ .replace(/\\[(]/g, '') // removes \) use case: 50°+m<1
11
+ .replace(/\\[)]/g, '') // removes \degree use case: 50°
14
12
  .replace(/\\degree/g, '&deg;');
15
13
  };
14
+
16
15
  exports.parseDegrees = parseDegrees;
17
16
  //# sourceMappingURL=parse-html.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-html.js","names":["parseDegrees","html","replace","exports"],"sources":["../src/parse-html.js"],"sourcesContent":["export const parseDegrees = (html) =>\n html\n // removes \\( use case: 50°\n .replace(/\\\\[(]/g, '')\n // removes \\) use case: 50°+m<1\n .replace(/\\\\[)]/g, '')\n // removes \\degree use case: 50°\n .replace(/\\\\degree/g, '&deg;');\n"],"mappings":";;;;;;AAAO,IAAMA,YAAY,GAAG,SAAfA,YAAYA,CAAIC,IAAI;EAAA,OAC/BA;EACE;EAAA,CACCC,OAAO,CAAC,QAAQ,EAAE,EAAE;EACrB;EAAA,CACCA,OAAO,CAAC,QAAQ,EAAE,EAAE;EACrB;EAAA,CACCA,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC;AAAA;AAACC,OAAA,CAAAH,YAAA,GAAAA,YAAA"}
1
+ {"version":3,"sources":["../src/parse-html.js"],"names":["parseDegrees","html","replace"],"mappings":";;;;;;;AAAO,IAAMA,YAAY,GAAG,SAAfA,YAAe,CAACC,IAAD;AAAA,SAC1BA,IAAI,CACF;AADE,GAEDC,OAFH,CAEW,QAFX,EAEqB,EAFrB,EAGE;AAHF,GAIGA,OAJH,CAIW,QAJX,EAIqB,EAJrB,EAKE;AALF,GAMGA,OANH,CAMW,WANX,EAMwB,OANxB,CAD0B;AAAA,CAArB","sourcesContent":["export const parseDegrees = (html) =>\n html\n // removes \\( use case: 50°\n .replace(/\\\\[(]/g, '')\n // removes \\) use case: 50°+m<1\n .replace(/\\\\[)]/g, '')\n // removes \\degree use case: 50°\n .replace(/\\\\degree/g, '&deg;');\n"],"file":"parse-html.js"}
@@ -1,17 +1,26 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports["default"] = void 0;
9
+
8
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
9
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
+
10
14
  var _react = _interopRequireDefault(require("react"));
15
+
11
16
  var _styles = require("@material-ui/core/styles");
17
+
12
18
  var _Popper = _interopRequireDefault(require("@material-ui/core/Popper"));
19
+
13
20
  var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
21
+
14
22
  var _excluded = ["classes", "children"];
23
+
15
24
  var styles = function styles() {
16
25
  return {
17
26
  popover: {
@@ -31,10 +40,11 @@ var styles = function styles() {
31
40
  }
32
41
  };
33
42
  };
43
+
34
44
  var CustomPopper = (0, _styles.withStyles)(styles)(function (_ref) {
35
45
  var classes = _ref.classes,
36
- children = _ref.children,
37
- props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
46
+ children = _ref.children,
47
+ props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
38
48
  return /*#__PURE__*/_react["default"].createElement(_Popper["default"], (0, _extends2["default"])({
39
49
  id: "mouse-over-popover",
40
50
  open: true,
@@ -1 +1 @@
1
- {"version":3,"file":"custom-popper.js","names":["_react","_interopRequireDefault","require","_styles","_Popper","_Typography","_excluded","styles","popover","background","padding","pointerEvents","zIndex","paper","height","width","typography","fontSize","textAlign","CustomPopper","withStyles","_ref","classes","children","props","_objectWithoutProperties2","createElement","_extends2","id","open","className","anchorOrigin","vertical","horizontal","transformOrigin","disableRestoreFocus","disableAutoFocus","root","_default","exports"],"sources":["../../../src/plugins/characters/custom-popper.js"],"sourcesContent":["import React from 'react';\nimport { withStyles } from '@material-ui/core/styles';\nimport Popper from '@material-ui/core/Popper';\nimport Typography from '@material-ui/core/Typography';\n\nconst styles = () => ({\n popover: {\n background: '#fff',\n padding: '10px',\n pointerEvents: 'none',\n zIndex: 99999,\n },\n paper: {\n padding: 20,\n height: 'auto',\n width: 'auto',\n },\n typography: {\n fontSize: 50,\n textAlign: 'center',\n },\n});\n\nconst CustomPopper = withStyles(styles)(({ classes, children, ...props }) => (\n <Popper\n id=\"mouse-over-popover\"\n open\n className={classes.popover}\n classes={{\n paper: classes.paper,\n }}\n anchorOrigin={{\n vertical: 'bottom',\n horizontal: 'left',\n }}\n transformOrigin={{\n vertical: 'top',\n horizontal: 'left',\n }}\n disableRestoreFocus\n disableAutoFocus\n {...props}\n >\n <Typography classes={{ root: classes.typography }}>{children}</Typography>\n </Popper>\n));\n\nexport default CustomPopper;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAsD,IAAAI,SAAA;AAEtD,IAAMC,MAAM,GAAG,SAATA,MAAMA,CAAA;EAAA,OAAU;IACpBC,OAAO,EAAE;MACPC,UAAU,EAAE,MAAM;MAClBC,OAAO,EAAE,MAAM;MACfC,aAAa,EAAE,MAAM;MACrBC,MAAM,EAAE;IACV,CAAC;IACDC,KAAK,EAAE;MACLH,OAAO,EAAE,EAAE;MACXI,MAAM,EAAE,MAAM;MACdC,KAAK,EAAE;IACT,CAAC;IACDC,UAAU,EAAE;MACVC,QAAQ,EAAE,EAAE;MACZC,SAAS,EAAE;IACb;EACF,CAAC;AAAA,CAAC;AAEF,IAAMC,YAAY,GAAG,IAAAC,kBAAU,EAACb,MAAM,CAAC,CAAC,UAAAc,IAAA;EAAA,IAAGC,OAAO,GAAAD,IAAA,CAAPC,OAAO;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IAAKC,KAAK,OAAAC,yBAAA,aAAAJ,IAAA,EAAAf,SAAA;EAAA,oBACpEN,MAAA,YAAA0B,aAAA,CAACtB,OAAA,WAAM,MAAAuB,SAAA;IACLC,EAAE,EAAC,oBAAoB;IACvBC,IAAI;IACJC,SAAS,EAAER,OAAO,CAACd,OAAQ;IAC3Bc,OAAO,EAAE;MACPT,KAAK,EAAES,OAAO,CAACT;IACjB,CAAE;IACFkB,YAAY,EAAE;MACZC,QAAQ,EAAE,QAAQ;MAClBC,UAAU,EAAE;IACd,CAAE;IACFC,eAAe,EAAE;MACfF,QAAQ,EAAE,KAAK;MACfC,UAAU,EAAE;IACd,CAAE;IACFE,mBAAmB;IACnBC,gBAAgB;EAAA,GACZZ,KAAK,gBAETxB,MAAA,YAAA0B,aAAA,CAACrB,WAAA,WAAU;IAACiB,OAAO,EAAE;MAAEe,IAAI,EAAEf,OAAO,CAACN;IAAW;EAAE,GAAEO,QAAqB,CACnE,CAAC;AAAA,CACV,CAAC;AAAC,IAAAe,QAAA,GAEYnB,YAAY;AAAAoB,OAAA,cAAAD,QAAA"}
1
+ {"version":3,"sources":["../../../src/plugins/characters/custom-popper.js"],"names":["styles","popover","background","padding","pointerEvents","zIndex","paper","height","width","typography","fontSize","textAlign","CustomPopper","classes","children","props","vertical","horizontal","root"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS;AAAA,SAAO;AACpBC,IAAAA,OAAO,EAAE;AACPC,MAAAA,UAAU,EAAE,MADL;AAEPC,MAAAA,OAAO,EAAE,MAFF;AAGPC,MAAAA,aAAa,EAAE,MAHR;AAIPC,MAAAA,MAAM,EAAE;AAJD,KADW;AAOpBC,IAAAA,KAAK,EAAE;AACLH,MAAAA,OAAO,EAAE,EADJ;AAELI,MAAAA,MAAM,EAAE,MAFH;AAGLC,MAAAA,KAAK,EAAE;AAHF,KAPa;AAYpBC,IAAAA,UAAU,EAAE;AACVC,MAAAA,QAAQ,EAAE,EADA;AAEVC,MAAAA,SAAS,EAAE;AAFD;AAZQ,GAAP;AAAA,CAAf;;AAkBA,IAAMC,YAAY,GAAG,wBAAWZ,MAAX,EAAmB;AAAA,MAAGa,OAAH,QAAGA,OAAH;AAAA,MAAYC,QAAZ,QAAYA,QAAZ;AAAA,MAAyBC,KAAzB;AAAA,sBACtC,gCAAC,kBAAD;AACE,IAAA,EAAE,EAAC,oBADL;AAEE,IAAA,IAAI,MAFN;AAGE,IAAA,SAAS,EAAEF,OAAO,CAACZ,OAHrB;AAIE,IAAA,OAAO,EAAE;AACPK,MAAAA,KAAK,EAAEO,OAAO,CAACP;AADR,KAJX;AAOE,IAAA,YAAY,EAAE;AACZU,MAAAA,QAAQ,EAAE,QADE;AAEZC,MAAAA,UAAU,EAAE;AAFA,KAPhB;AAWE,IAAA,eAAe,EAAE;AACfD,MAAAA,QAAQ,EAAE,KADK;AAEfC,MAAAA,UAAU,EAAE;AAFG,KAXnB;AAeE,IAAA,mBAAmB,MAfrB;AAgBE,IAAA,gBAAgB;AAhBlB,KAiBMF,KAjBN,gBAmBE,gCAAC,sBAAD;AAAY,IAAA,OAAO,EAAE;AAAEG,MAAAA,IAAI,EAAEL,OAAO,CAACJ;AAAhB;AAArB,KAAoDK,QAApD,CAnBF,CADsC;AAAA,CAAnB,CAArB;eAwBeF,Y","sourcesContent":["import React from 'react';\nimport { withStyles } from '@material-ui/core/styles';\nimport Popper from '@material-ui/core/Popper';\nimport Typography from '@material-ui/core/Typography';\n\nconst styles = () => ({\n popover: {\n background: '#fff',\n padding: '10px',\n pointerEvents: 'none',\n zIndex: 99999,\n },\n paper: {\n padding: 20,\n height: 'auto',\n width: 'auto',\n },\n typography: {\n fontSize: 50,\n textAlign: 'center',\n },\n});\n\nconst CustomPopper = withStyles(styles)(({ classes, children, ...props }) => (\n <Popper\n id=\"mouse-over-popover\"\n open\n className={classes.popover}\n classes={{\n paper: classes.paper,\n }}\n anchorOrigin={{\n vertical: 'bottom',\n horizontal: 'left',\n }}\n transformOrigin={{\n vertical: 'top',\n horizontal: 'left',\n }}\n disableRestoreFocus\n disableAutoFocus\n {...props}\n >\n <Typography classes={{ root: classes.typography }}>{children}</Typography>\n </Popper>\n));\n\nexport default CustomPopper;\n"],"file":"custom-popper.js"}