@zzish/math-rich-input 0.1.46 → 0.1.48

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.
package/dist/index.js CHANGED
@@ -22345,36 +22345,45 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22345
22345
  }
22346
22346
  });
22347
22347
  _defineProperty(_this2, "handlePaste", function (event) {
22348
- var clipboardData = event.clipboardData || window.clipboardData;
22349
- if (clipboardData === null || clipboardData === undefined) {
22350
- console.warn("handlePaste called, but no clipboard data");
22351
- return;
22352
- }
22353
- // for (let i = 0; i < clipboardData.types.length; i++)
22354
- // console.log(
22355
- // clipboardData.types[i] +
22356
- // ": " +
22357
- // clipboardData.getData(clipboardData.types[i])
22358
- // );
22359
- var pasteHtml = clipboardData.getData("text/html");
22360
- if (pasteHtml !== null && pasteHtml.length > 0) {
22361
- // console.log("** Paste html");
22362
- // console.log(pasteHtml);
22363
- pasteHtml = sanitiseHtml(pasteHtml);
22364
- // console.log("** Santised paste html");
22365
- // console.log(pasteHtml);
22366
- _this2.insertHtml(pasteHtml);
22348
+ try {
22349
+ var clipboardData = event.clipboardData || window.clipboardData;
22350
+ if (!clipboardData) {
22351
+ return;
22352
+ }
22367
22353
  event.preventDefault();
22368
- } else {
22369
- var paste = clipboardData.getData("text");
22354
+ var pasteHtml = clipboardData.getData('text/html');
22355
+ var pasteText = clipboardData.getData('text/plain');
22370
22356
  var selection = window.getSelection();
22371
22357
  if (!selection.rangeCount) {
22372
- console.warn("handlePaste called, but unable to get selection");
22373
- return false;
22358
+ return;
22374
22359
  }
22375
- event.preventDefault();
22376
22360
  selection.deleteFromDocument();
22377
- _this2.insertRawText(paste);
22361
+ if (pasteHtml && pasteHtml.length > 0) {
22362
+ var markerId = "__PASTE_MARKER_".concat(Date.now(), "_").concat(Math.floor(Math.random() * 10000), "__");
22363
+ var markerStart = "<span id='".concat(markerId, "_START'></span>");
22364
+ var markerEnd = "<span id='".concat(markerId, "_END'></span>");
22365
+ var markedHtml = markerStart + pasteHtml + markerEnd;
22366
+ if (typeof sanitiseHtml === 'function') {
22367
+ markedHtml = sanitiseHtml(markedHtml);
22368
+ }
22369
+ _this2._pendingPasteMarkerId = markerId;
22370
+ document.execCommand('insertHTML', false, markedHtml);
22371
+ setTimeout(function () {
22372
+ try {
22373
+ var rawText = elementToMarkedRawText(_this2.editableDiv, null, -1, _this2.enableHtml());
22374
+ var nodeCounts = _this2._countNodeTypes();
22375
+ var mimeType = _this2.getMimeType(nodeCounts.html > 0, nodeCounts.math > 0);
22376
+ var cleanedRawText = removeEncodingIfPlainText(rawText, mimeType, _this2.enableHtml());
22377
+ _this2.applyChangesToComponent(cleanedRawText, mimeType, _this2._getRangeParams(), _this2.props.useExpertMode, _this2.props.selectedTab);
22378
+ } catch (err) {
22379
+ console.error(err);
22380
+ }
22381
+ }, 0);
22382
+ } else if (pasteText && pasteText.length > 0) {
22383
+ _this2.insertRawText(pasteText);
22384
+ }
22385
+ } catch (error) {
22386
+ console.error(error);
22378
22387
  }
22379
22388
  });
22380
22389
  _defineProperty(_this2, "showEquationEditor", function () {
@@ -22676,7 +22685,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22676
22685
  }
22677
22686
  });
22678
22687
  _defineProperty(_this2, "insertRawText", function (new_text) {
22679
- var selectInsertedText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
22688
+ var selectInsertedText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
22680
22689
  try {
22681
22690
  var rangeParams = _this2._getRangeParams();
22682
22691
  var node = _this2._findNodeWithIndex(rangeParams.endNodeIndex);
@@ -22739,10 +22748,11 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22739
22748
  // Preserve the selection
22740
22749
  if (lastNode) {
22741
22750
  range = range.cloneRange();
22742
- range.setStartAfter(lastNode);
22743
22751
  if (selectPastedContent) {
22744
22752
  range.setStartBefore(firstNode);
22753
+ range.setEndAfter(lastNode);
22745
22754
  } else {
22755
+ range.setStartAfter(lastNode);
22746
22756
  range.collapse(true);
22747
22757
  }
22748
22758
  sel.removeAllRanges();
@@ -22762,10 +22772,11 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22762
22772
  }
22763
22773
  });
22764
22774
  _defineProperty(_this2, "insertHtml", function (new_html) {
22775
+ var selectPastedContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
22765
22776
  try {
22766
22777
  // console.log("New html: "+new_html)
22767
22778
  // console.log("inserting: "+new_html)
22768
- _this2.pasteHtmlAtCaret(new_html, true);
22779
+ _this2.pasteHtmlAtCaret(new_html, selectPastedContent);
22769
22780
  var new_rangeParams = null;
22770
22781
  // console.log("New range params: ")
22771
22782
  try {
@@ -22988,7 +22999,8 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22988
22999
  subscript: false,
22989
23000
  superscript: false
22990
23001
  },
22991
- keyPressed: ""
23002
+ keyPressed: "",
23003
+ pendingHtmlWithMarker: null
22992
23004
  };
22993
23005
 
22994
23006
  // this.handleInput = this.handleInput.bind(this);
@@ -23150,7 +23162,24 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
23150
23162
  key: "componentDidUpdate",
23151
23163
  value: function componentDidUpdate() {
23152
23164
  try {
23153
- // console.log("componentDidUpdate")
23165
+ if (this._pendingPasteMarkerId) {
23166
+ var start = document.getElementById("".concat(this._pendingPasteMarkerId, "_START"));
23167
+ var end = document.getElementById("".concat(this._pendingPasteMarkerId, "_END"));
23168
+ if (start && end) {
23169
+ var range = document.createRange();
23170
+ range.setStartAfter(start);
23171
+ range.setEndBefore(end);
23172
+ var sel = window.getSelection();
23173
+ sel.removeAllRanges();
23174
+ sel.addRange(range);
23175
+ start.parentNode && start.parentNode.removeChild(start);
23176
+ end.parentNode && end.parentNode.removeChild(end);
23177
+ }
23178
+ this._pendingPasteMarkerId = null;
23179
+ this.setState({
23180
+ pendingHtmlWithMarker: null
23181
+ });
23182
+ }
23154
23183
  if (this.afterComponentUpdateData !== null && this.afterComponentUpdateData !== undefined && this.afterComponentUpdateData.value === this.props.value) {
23155
23184
  this._setRangeParams(this.afterComponentUpdateData.rangeParams);
23156
23185
  this.afterComponentUpdateData = null;
@@ -23241,7 +23270,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
23241
23270
  onCompositionStart: this.handleCompositionStart,
23242
23271
  onCompositionEnd: this.handleCompositionEnd,
23243
23272
  dangerouslySetInnerHTML: {
23244
- __html: html
23273
+ __html: this.state.pendingHtmlWithMarker || html
23245
23274
  },
23246
23275
  "data-placeholder": this.props.placeholder || ""
23247
23276
  }))), this.state.showEquationEditor && /*#__PURE__*/React__default["default"].createElement(EquationEditorModal, {
@@ -1,996 +1 @@
1
- *,
2
- :after,
3
- :before {
4
- -webkit-box-sizing: border-box;
5
- -moz-box-sizing: border-box;
6
- box-sizing: border-box;
7
- }
8
-
9
- .MathRichInput-Container {
10
- width: 100%;
11
- border-radius: 5px;
12
- }
13
-
14
- .MathRichInput-scrollview {
15
- position: relative;
16
- display: flex;
17
- border-radius: 5px;
18
- }
19
-
20
- .MathRichInput p {
21
- padding: 0px;
22
- margin: 0px;
23
- }
24
-
25
- .MathRichInput {
26
- font-size: 18px;
27
- padding: 10px;
28
- width: 100%;
29
- border-radius: 5px;
30
- background-color: #fff;
31
- overflow-x: scroll;
32
- overflow: overlay;
33
- }
34
-
35
- .MathRichInput:empty::before {
36
- content: attr(data-placeholder);
37
- color: #acb6c0;
38
- font-size: 15px;
39
- }
40
- .MathRichInput:empty:focus::before {
41
- content: "";
42
- }
43
-
44
- .MathRichInput:focus {
45
- outline: 0;
46
- }
47
-
48
- .MathRichInput .katex {
49
- border: 0px;
50
- }
51
-
52
- .MathRichInput .base {
53
- /* Combine the katex and base class name to ensure the whole equation is surrounded */
54
- background-color: #f0f0f0;
55
- border: 0px;
56
- border: 1px dotted #d0d0d0;
57
- border-radius: 5px;
58
- padding: 2px;
59
- margin: 0px 2px;
60
- }
61
-
62
- .katex .mathnormal {
63
- font-family: KaTeX_Math;
64
- font-style: italic;
65
- }
66
-
67
- .MathRichInput .katex-error {
68
- background-color: #f0f0f0;
69
- border: 0px;
70
- border: 1px dotted #ff8080;
71
- border-radius: 5px;
72
- padding: 2px;
73
- margin: 0px 2px;
74
- }
75
-
76
- .MathRichInput-Container {
77
- :focus-within {
78
- background-color: white;
79
- outline: 0px;
80
- /* border: 1px solid #663676; */
81
- }
82
-
83
- &.dark {
84
- :focus-within {
85
- background: none;
86
- outline: 0px;
87
- border: none;
88
- }
89
- .MathRichInput {
90
- color: white;
91
-
92
- background: none;
93
- border: none;
94
-
95
- .katex,
96
- .base {
97
- background: none;
98
- }
99
-
100
- &:focus {
101
- border: none;
102
- background: none;
103
- }
104
- }
105
- }
106
-
107
- &.question-edit-input {
108
- .MathRichInput {
109
- border-radius: 12px;
110
- font-size: 32px;
111
- font-weight: 400;
112
-
113
- &:focus {
114
- border: none;
115
- background: rgba(255, 255, 255, 0.1);
116
- }
117
- }
118
- }
119
-
120
- &.answer-edit-input {
121
- .MathRichInput {
122
- font-weight: 400;
123
- font-size: 16px;
124
- }
125
- }
126
-
127
- &.hint-input,
128
- &.explanation-input {
129
- .MathRichInput {
130
- font-weight: 400;
131
- font-size: 16px;
132
- /* text-decoration: underline dotted; */
133
- color: #322e33;
134
-
135
- .base {
136
- border: 1px dotted #322e33;
137
- }
138
- }
139
- }
140
- }
141
- .EquationEditorModal-background {
142
- position: fixed;
143
- top: 0;
144
- left: 0;
145
- width: 100%;
146
- height: 100%;
147
- background: black;
148
- z-index: 99;
149
- animation: 0.3s shade;
150
- animation-fill-mode: forwards;
151
- }
152
-
153
- @keyframes shade {
154
- 00% {
155
- opacity: 0;
156
- }
157
- 100% {
158
- opacity: 0.6;
159
- }
160
- }
161
-
162
- .EquationEditorModal {
163
- background: white;
164
- border: 1px solid #808080;
165
- border-radius: 10px;
166
- box-shadow: 0px 2px 5px 1px #a0a0a0;
167
- position: fixed;
168
- max-width: 500px;
169
- width: 98%;
170
- top: 50%;
171
- left: 50%;
172
- /* transform: translate(-50%,-50%); */
173
- z-index: 100;
174
- animation: 0.3s rise;
175
- animation-fill-mode: forwards;
176
- }
177
-
178
- @keyframes rise {
179
- 00% {
180
- transform: translate(-50%, 100%);
181
- opacity: 0;
182
- }
183
- 100% {
184
- transform: translate(-50%, -50%);
185
- opacity: 1;
186
- }
187
- }
188
-
189
- .EquationEditorModal-mobile {
190
- background: white;
191
- border: 1px solid #808080;
192
- border-radius: 10px;
193
- box-shadow: 0px 2px 5px 1px #a0a0a0;
194
- position: fixed;
195
- max-width: 500px;
196
- width: 99%;
197
- top: 0%;
198
- left: 50%;
199
- transform: translate(-50%, 1px);
200
- z-index: 100;
201
- }
202
-
203
- .EquationEditorModal .title {
204
- display: flex;
205
- justify-content: space-between;
206
- font-size: 14px;
207
- color: #404040;
208
- text-align: left;
209
- background: #e0e0e0;
210
- border: 0px;
211
- border-radius: 5px 5px 0px 0px;
212
- padding: 15px;
213
- margin: 0px;
214
- }
215
-
216
- .EquationEditorModal-mobile .title {
217
- display: flex;
218
- justify-content: space-between;
219
- font-size: 14px;
220
- color: #404040;
221
- text-align: left;
222
- background: #e0e0e0;
223
- border: 0px;
224
- border-radius: 5px 5px 0px 0px;
225
- height: 30px;
226
- padding: 15px;
227
- margin: 0px;
228
- }
229
-
230
- .expertModeSwitch {
231
- display: flex;
232
- flex-direction: row;
233
- align-items: center;
234
- }
235
-
236
- .EquationEditorModal .expertModeSwitch .switch {
237
- margin-left: 10px;
238
- }
239
-
240
- /* The switch - the box around the slider */
241
- .EquationEditorModal .switch {
242
- position: relative;
243
- display: inline-block;
244
- width: 35px;
245
- height: 22px;
246
- margin-bottom: 0;
247
- padding: 0;
248
- }
249
-
250
- /* Hide default HTML checkbox */
251
- .EquationEditorModal .switch input {
252
- opacity: 0;
253
- width: 0;
254
- height: 0;
255
- }
256
-
257
- /* The slider */
258
- .EquationEditorModal .slider {
259
- position: absolute;
260
- cursor: pointer;
261
- top: 0;
262
- left: 0;
263
- right: 0;
264
- bottom: 0;
265
- background-color: #ccc;
266
- -webkit-transition: 0.4s;
267
- transition: 0.4s;
268
- }
269
-
270
- .EquationEditorModal .slider:before {
271
- position: absolute;
272
- content: "";
273
- height: 14px;
274
- width: 14px;
275
- left: 4px;
276
- bottom: 4px;
277
- background-color: white;
278
- -webkit-transition: 0.4s;
279
- transition: 0.4s;
280
- }
281
-
282
- .EquationEditorModal input:checked + .slider {
283
- background-color: #663676;
284
- }
285
-
286
- .EquationEditorModal input:focus + .slider {
287
- box-shadow: 0 0 1px #2196f3;
288
- }
289
-
290
- .EquationEditorModal input:checked + .slider:before {
291
- -webkit-transform: translateX(13px);
292
- -ms-transform: translateX(13px);
293
- transform: translateX(13px);
294
- }
295
-
296
- /* Rounded sliders */
297
- .EquationEditorModal .slider.round {
298
- border-radius: 18px;
299
- }
300
-
301
- .EquationEditorModal .slider.round:before {
302
- border-radius: 50%;
303
- }
304
- /* Note that the top left position of the toolbar is set programatically in componentDidMount */
305
-
306
- .Toolbar {
307
- position: absolute;
308
- z-index: 10;
309
- display: flex;
310
- height: 42px;
311
- background-color: white;
312
- border: 1px solid #d0d0d0;
313
- border-radius: 5px;
314
- box-shadow: 1px 1px 5px #a0a0a0;
315
- animation: 0.5s fadeIn1;
316
- animation-fill-mode: forwards;
317
- color: black;
318
- }
319
-
320
- @keyframes fadeIn1 {
321
- 0% {
322
- opacity: 0;
323
- }
324
- 100% {
325
- opacity: 1;
326
- }
327
- }
328
-
329
- .Toolbar-button {
330
- font-family: sans-serif;
331
- font-size: 16px;
332
- width: 40px;
333
- height: 36px;
334
- background-color: white;
335
- border-radius: 5px;
336
- border: 0px;
337
- padding: 1px;
338
- margin: 2px;
339
- }
340
-
341
- .Toolbar-button:hover {
342
- color: white;
343
- background: #663676;
344
- cursor: pointer;
345
- }
346
-
347
- .Toolbar-button:active {
348
- background: #808080;
349
- color: white;
350
- cursor: pointer;
351
- }
352
-
353
- .TB-narrow {
354
- width: 30px;
355
- }
356
-
357
- .TB-wide {
358
- width: 46px;
359
- }
360
-
361
- .TB-selected {
362
- background: #d0d0d0;
363
- color: black;
364
- cursor: pointer;
365
- animation: 0.2s TB-fadeIn;
366
- animation-fill-mode: forwards;
367
- }
368
-
369
- .TB-selected:hover {
370
- color: white;
371
- background: #663676;
372
- cursor: pointer;
373
- }
374
-
375
- @keyframes TB-fadeIn {
376
- 00% {
377
- background: white;
378
- }
379
- 100% {
380
- background: #d0d0d0;
381
- }
382
- }
383
-
384
- /* Tooltip text */
385
- .Toolbar-button .tooltiptext {
386
- font-weight: normal;
387
- visibility: hidden;
388
- width: 100px;
389
- background-color: #222;
390
- color: #fff;
391
- /*font-weight: bold;*/
392
- font-size: 12px;
393
- text-align: center;
394
- padding: 4px 10px;
395
- border-radius: 6px;
396
-
397
- /* Position the tooltip text - see examples below! */
398
- position: absolute;
399
- z-index: 11;
400
- top: -90%; /* Must leave a small gap between tooltip and button */
401
- left: 50px;
402
-
403
- /* transform: translate (50%,0%); */
404
- }
405
-
406
- /* Show the tooltip text when you mouse over the tooltip container */
407
- .Toolbar-button:hover .tooltiptext {
408
- animation: 0.8s fadeIn2;
409
- animation-fill-mode: forwards;
410
- visibility: visible;
411
- /* width: 100px; */
412
- /* top: -90%; */ /* Must leave a small gap between tooltip and button */
413
- /* left: 20%; */
414
- /* margin-left: -50px; */
415
- }
416
-
417
- @keyframes fadeIn2 {
418
- 00% {
419
- opacity: 0;
420
- }
421
- 70% {
422
- opacity: 0;
423
- }
424
- 100% {
425
- visibility: visible;
426
- opacity: 0.9;
427
- }
428
- }
429
-
430
- /* .tooltip {
431
- position: relative;
432
- display: inline-block;
433
- border-bottom: 1px dotted black; /* If you want dots under the hoverable text
434
- } */
435
- /* Note that the top left position of the accent bar is set programatically in componentDidMount */
436
-
437
- .AccentBar {
438
- position: absolute;
439
- z-index: 1;
440
- width: 360px;
441
- background-color: #fff;
442
- border: 1px solid #d0d0d0;
443
- border-radius: 5px;
444
- box-shadow: 1px 1px 5px #a0a0a0;
445
- padding: 8px;
446
- animation: 0.4s fadeIn1;
447
- animation-fill-mode: forwards;
448
- color: black;
449
- }
450
-
451
- .AccentBar-compact {
452
- display: flex;
453
- position: absolute;
454
- z-index: 1;
455
- background-color: white;
456
- border: 1px solid #d0d0d0;
457
- border-radius: 5px;
458
- box-shadow: 1px 1px 5px #a0a0a0;
459
- padding: 5px;
460
- animation: 0.4s fadeIn1;
461
- animation-fill-mode: forwards;
462
- color: black;
463
- }
464
-
465
- .AccentBar-outerContainer {
466
- overflow-y: scroll;
467
- border-radius: 5px;
468
- }
469
-
470
- .AccentBar-innerContainer {
471
- height: 350px;
472
- }
473
-
474
- @keyframes fadeIn1 {
475
- 0% {
476
- opacity: 0;
477
- }
478
- 100% {
479
- opacity: 1;
480
- }
481
- }
482
-
483
- .AccentBar .symbols-grid {
484
- display: grid;
485
- grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
486
- grid-auto-rows: minmax(min-content, max-content);
487
- grid-gap: 3px;
488
- }
489
-
490
- .AccentBar .insert-grid {
491
- padding: 5px;
492
- }
493
-
494
- .AccentBar .type-a-letter {
495
- grid-column: 1/-1;
496
- color: #a0a0a0;
497
- font-family: sans-serif;
498
- font-size: 14px;
499
- font-weight: bold;
500
- height: 36px;
501
- padding-top: 12px;
502
- padding-left: 20px;
503
- }
504
-
505
- .AccentBar-button {
506
- font-family: sans-serif;
507
- font-size: 17px;
508
- width: 40px;
509
- height: 36px;
510
- background: #f4f4f4;
511
- border-radius: 5px;
512
- border: 0px;
513
- padding: 1px;
514
- }
515
-
516
- .AB-compact {
517
- margin: 0px;
518
- background: white;
519
- }
520
-
521
- .AB-narrow {
522
- width: 36px;
523
- }
524
-
525
- .AccentBar-button:hover {
526
- color: white;
527
- background: #663676;
528
- cursor: pointer;
529
- box-shadow: 1px 1px 3px #808080;
530
- animation: 2s grow;
531
- animation-fill-mode: forwards;
532
- }
533
-
534
- @keyframes grow {
535
- 00% {
536
- transform: scale(1);
537
- box-shadow: 0px 0px 0px #808080;
538
- }
539
- 10% {
540
- transform: scale(1.3);
541
- box-shadow: 1px 1px 3px #808080;
542
- }
543
- 90% {
544
- transform: scale(1.3);
545
- box-shadow: 1px 1px 3px #808080;
546
- }
547
- 100% {
548
- transform: scale(1.8);
549
- box-shadow: 1px 1px 3px #808080;
550
- }
551
- }
552
-
553
- .AccentBar-button:active {
554
- background: #808080;
555
- color: white;
556
- cursor: pointer;
557
- }
558
-
559
- .AccentBar .tabBar {
560
- background: white;
561
- text-align: left;
562
- border: 0px;
563
- padding: 10px 0;
564
- }
565
-
566
- .AccentBar .tab {
567
- font-size: 14px;
568
- font-weight: bold;
569
- color: #404040;
570
- text-align: left;
571
- border: 0px;
572
- height: 30px;
573
- padding: 2px 5px 2px 5px;
574
- margin: 2px;
575
- border-bottom: 4px solid #d0d0d0;
576
- }
577
-
578
- .AccentBar .tab:hover {
579
- cursor: pointer;
580
- }
581
-
582
- .AccentBar .tab-selected {
583
- font-size: 14px;
584
- font-weight: bold;
585
- color: #404040;
586
- text-align: left;
587
- border: 0px;
588
- height: 30px;
589
- padding: 2px 5px 2px 5px;
590
- margin: 2px;
591
- border-bottom: 4px solid #663676;
592
- }
593
-
594
- .AccentBar .section-label {
595
- grid-column: 1/-1;
596
- font-size: 13px;
597
- font-weight: bold;
598
- color: #663676;
599
- margin-top: 8px;
600
- margin-left: 8px;
601
- margin-bottom: 4px;
602
- }
603
-
604
- .AccentBar .replace-section {
605
- min-height: 70px;
606
- }
607
-
608
- .AccentBar .tabArea {
609
- animation: 0.4s fadeIn1;
610
- animation-fill-mode: forwards;
611
- }
612
- .EquationEditor {
613
- height: auto;
614
- text-align: center;
615
- }
616
-
617
- .EquationEditor .editableAndCursorButtonsWrapper {
618
- display: flex;
619
- align-items: center;
620
- justify-content: center;
621
- }
622
-
623
- .EquationEditor .editableWrapper {
624
- overflow: auto;
625
- width: 100%;
626
- }
627
-
628
- .EquationEditor .cursorButton {
629
- font-size: 14px;
630
- font-weight: bold;
631
- color: #663676;
632
- background: white;
633
- text-align: center;
634
- border: 1px solid #663676;
635
- border-radius: 5px;
636
- min-width: 40px;
637
- width: auto;
638
- height: 40px;
639
- padding: 0px;
640
- margin-top: 10px;
641
- margin-left: 15px;
642
- margin-right: 15px;
643
- /* transition: all .2s ease-in-out; */
644
- }
645
-
646
- .EquationEditor .centerBox {
647
- display: inline-block;
648
- text-align: center;
649
- }
650
-
651
- .EquationEditor .editable {
652
- /* width:auto; */
653
- text-align: left;
654
- min-height: 26px;
655
- min-width: 150px;
656
- font-size: 20px;
657
- color: #404040;
658
- border: 1px solid #b0b0b0;
659
- border-radius: 5px;
660
- /* height:36px; */
661
- padding: 7px 10px 7px 10px;
662
- margin-top: 6px;
663
- margin-bottom: 5px;
664
- }
665
-
666
- .EquationEditor .editable-placeholder {
667
- position: absolute;
668
- z-index: -1;
669
- min-height: 26px;
670
- min-width: 150px;
671
- font-size: 15px;
672
- color: grey;
673
- /* Note the x translation needs to be updatad programatically if the modal width changes */
674
- transform: translate(-12px, -36px);
675
- }
676
-
677
- .EquationEditor .editable:focus-within {
678
- border-radius: 5px;
679
- border: 1px solid #663676 !important;
680
- box-shadow: 0px 0px 0px white;
681
- /* box-shadow: inset 1px 1px 5px #a0a0a0; */
682
- }
683
-
684
- .latexInputAreaWrapper {
685
- width: auto;
686
- }
687
-
688
- .EquationEditor .katexRenderedInput {
689
- text-align: left;
690
- min-height: 30px;
691
- width: 90%;
692
- font-size: 16px;
693
- color: #404040;
694
- border: 0px solid #b0b0b0;
695
- border-radius: 5px;
696
- /* height:36px; */
697
- padding: 7px 10px 4px 10px;
698
- margin: 5px 15px;
699
- }
700
-
701
- .EquationEditor .latexInput {
702
- text-align: left;
703
- height: 88px;
704
- width: 90%;
705
- font-size: 16px;
706
- /* color: #202020; */
707
- /* background-color: #e0e0e0; */
708
- /* color: #00ff00;
709
- background-color: #202020; */
710
- color: #007000;
711
- background-color: #fff;
712
- border: 1px solid #b0b0b0;
713
- border-radius: 5px;
714
- padding: 7px 10px 5px 10px;
715
- margin-top: 10px;
716
- box-shadow: 0px 0px 0px white;
717
- }
718
-
719
- .EquationEditor .latexInput:focus {
720
- border: 1px solid #663676 !important;
721
- outline: 0;
722
- /* outline: 2px solid #663676!important; */ /* Has square corners */
723
- /* box-shadow: inset 1px 1px 5px #a0a0a0, 0px 0px 3px #663676; */
724
- }
725
-
726
- .EquationEditor .insertButton {
727
- font-size: 14px;
728
- color: white;
729
- background: #663676;
730
- text-align: left;
731
- border: 0px;
732
- border-radius: 5px;
733
- height: 36px;
734
- padding: 0px 30px;
735
- margin-top: 5px;
736
- margin-bottom: 5px;
737
- margin-left: 5px;
738
- margin-right: 5px;
739
- }
740
-
741
- .EquationEditor .cancelButton {
742
- font-size: 14px;
743
- background: white;
744
- color: #663676;
745
- text-align: left;
746
- border: 1px solid #663676;
747
- border-radius: 5px;
748
- height: 36px;
749
- padding: 0px 30px;
750
- margin-bottom: 10px;
751
- margin-left: 5px;
752
- margin-right: 5px;
753
- }
754
-
755
- .EquationEditor .insertButton:hover {
756
- color: white;
757
- background: #461656;
758
- cursor: pointer;
759
- }
760
-
761
- .EquationEditor .recentSymbols-recentText-active {
762
- font-size: 14px;
763
- font-weight: bold;
764
- color: #404040;
765
- margin-right: 10px;
766
- }
767
-
768
- .EquationEditor .recentSymbols-recentText-not-active {
769
- font-size: 14px;
770
- font-weight: bold;
771
- color: #808080;
772
- margin-top: 10px;
773
- margin-bottom: 10px;
774
- }
775
-
776
- .EquationEditor .tabBar {
777
- background: white;
778
- text-align: left;
779
- border: 0px;
780
- padding: 10px 10px 5px 20px;
781
- margin: 5px;
782
- }
783
-
784
- @media (max-width: 500px) {
785
- .EquationEditor .tabBar {
786
- padding: 5px 0;
787
- }
788
- }
789
-
790
- .EquationEditor .tab {
791
- font-size: 14px;
792
- font-weight: bold;
793
- color: #404040;
794
- text-align: left;
795
- border: 0px;
796
- height: 30px;
797
- padding: 5px 10px;
798
- margin: 5px;
799
- border-bottom: 6px solid #d0d0d0;
800
- }
801
-
802
- .EquationEditor .tab:hover {
803
- cursor: pointer;
804
- }
805
- .EquationEditor .tab-selected {
806
- font-size: 14px;
807
- font-weight: bold;
808
- color: #404040;
809
- text-align: left;
810
- border: 0px;
811
- height: 30px;
812
- padding: 5px 10px;
813
- margin: 5px;
814
- border-bottom: 6px solid #663676;
815
- }
816
-
817
- .EquationEditor .recentSymbolsButtonArea {
818
- display: flex;
819
- justify-content: flex-start;
820
- width: 486px;
821
- padding: 2px;
822
- margin: 5px;
823
- margin-left: 15px;
824
- }
825
-
826
- .EquationEditor .symbolButtonAreasOuterContainer {
827
- overflow-x: auto;
828
- }
829
-
830
- .EquationEditor .symbolButtonAreasInnerContainer {
831
- display: flex;
832
- width: 2330px;
833
- }
834
-
835
- .EquationEditor .symbolButtonArea {
836
- display: grid;
837
- grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
838
- grid-auto-rows: minmax(min-content, max-content);
839
- grid-gap: 1.5px;
840
- padding: 12px;
841
- margin: 0px;
842
- }
843
-
844
- .EquationEditor .symbolButtonArea-1 {
845
- width: 66px;
846
- }
847
-
848
- .EquationEditor .symbolButtonArea-2 {
849
- width: 108px;
850
- }
851
-
852
- .EquationEditor .symbolButtonArea-3 {
853
- width: 150px;
854
- }
855
-
856
- .EquationEditor .symbolButtonArea-4 {
857
- width: 192px;
858
- }
859
-
860
- .EquationEditor .symbolButtonArea-5 {
861
- width: 234px;
862
- }
863
-
864
- .EquationEditor .symbolButtonArea-6 {
865
- width: 276px;
866
- }
867
- /* Fixes is a katex bug where horizontal lines are not rendering */
868
- /* .frac-line {
869
- background-color: #404040;
870
- height:0.03em;
871
- }
872
- .overline-line {
873
- background-color: #404040;
874
- height:0.03em;
875
- } */
876
-
877
- .SymbolButton {
878
- display: inline-block;
879
- overflow: hidden; /* Important to fix a bug where katex renders parts of the equation outside the box */
880
- font-size: 14px;
881
- font-weight: bold;
882
- color: #202020;
883
- background: #e0e0e0;
884
- text-align: center;
885
- border: 0px;
886
- border-radius: 5px;
887
- width: 36px;
888
- height: 36px;
889
- padding: 1px;
890
- margin: 3px;
891
- margin-bottom: auto;
892
- /* transition: all .2s ease-in-out; */
893
- }
894
-
895
- .SymbolButton:hover {
896
- filter: saturate(2);
897
- color: black;
898
- /* transform: scale(1.3); */
899
- cursor: pointer;
900
- box-shadow: 1px 1px 3px #808080;
901
- animation: 2s grow;
902
- animation-fill-mode: forwards;
903
- }
904
-
905
- @keyframes grow {
906
- 00% {
907
- transform: scale(1);
908
- box-shadow: 0px 0px 0px #808080;
909
- }
910
- 10% {
911
- transform: scale(1.3);
912
- box-shadow: 1px 1px 3px #808080;
913
- }
914
- 90% {
915
- transform: scale(1.3);
916
- box-shadow: 1px 1px 3px #808080;
917
- }
918
- 100% {
919
- transform: scale(1.8);
920
- box-shadow: 1px 1px 3px #808080;
921
- }
922
- }
923
-
924
- .SymbolButton:active {
925
- background: #808080;
926
- color: white;
927
- transform: scale(1.3);
928
- cursor: pointer;
929
- }
930
-
931
- .SymbolButton-fadeIn {
932
- opacity: 1;
933
- width: 100px;
934
- height: 100px;
935
- transition: width 0.5s, height 0.5s, opacity 0.5s 0.5s;
936
- }
937
-
938
- .highlight-0 {
939
- background: #ebc9eb;
940
- /* background: #80e0e0; */
941
- }
942
- /*
943
- .highlight-1{
944
- background: #c0e0e0;
945
- }
946
- /* .highlight-2{
947
- background: #c0e0e0;
948
- } */
949
-
950
- .highlight-operators {
951
- background: #f8e8d8;
952
- }
953
-
954
- .highlight-angles {
955
- background: #cceded;
956
- }
957
-
958
- .highlight-greeklower {
959
- background: #f8e8d8;
960
- }
961
-
962
- .highlight-greekupper {
963
- background: #cceded;
964
- }
965
-
966
- .highlight-misc {
967
- background: #f8e8d8;
968
- }
969
-
970
- .highlight-sets {
971
- background: #cceded;
972
- }
973
-
974
- .highlight-chemistry {
975
- background: #f8e8d8;
976
- }
977
-
978
- .highlight-elements {
979
- background: #cceded;
980
- }
981
-
982
- .highlight-physics2 {
983
- background: #f8e8d8;
984
- }
985
-
986
- .highlight-physics3 {
987
- background: #cceded;
988
- }
989
-
990
- .highlight-expert {
991
- background: #f4d6f5;
992
- }
993
-
994
- .highlight-matrices {
995
- background: #f4d6f5;
996
- }
1
+ .SymbolButton{background:#e0e0e0;border:0;border-radius:5px;color:#202020;display:inline-block;font-size:14px;font-weight:700;height:36px;margin:3px 3px auto;overflow:hidden;padding:1px;text-align:center;width:36px}.SymbolButton:hover{animation:grow 2s;animation-fill-mode:forwards;box-shadow:1px 1px 3px grey;color:#000;cursor:pointer;filter:saturate(2)}.SymbolButton:active{background:grey;color:#fff;cursor:pointer;transform:scale(1.3)}.SymbolButton-fadeIn{height:100px;opacity:1;transition:width .5s,height .5s,opacity .5s .5s;width:100px}.highlight-0{background:#ebc9eb}.highlight-operators{background:#f8e8d8}.highlight-angles{background:#cceded}.highlight-greeklower{background:#f8e8d8}.highlight-greekupper{background:#cceded}.highlight-misc{background:#f8e8d8}.highlight-sets{background:#cceded}.highlight-chemistry{background:#f8e8d8}.highlight-elements{background:#cceded}.highlight-physics2{background:#f8e8d8}.highlight-physics3{background:#cceded}.highlight-expert,.highlight-matrices{background:#f4d6f5}.EquationEditor{height:auto;text-align:center}.EquationEditor .editableAndCursorButtonsWrapper{align-items:center;display:flex;justify-content:center}.EquationEditor .editableWrapper{overflow:auto;width:100%}.EquationEditor .cursorButton{background:#fff;border:1px solid #663676;border-radius:5px;color:#663676;font-size:14px;font-weight:700;height:40px;margin-left:15px;margin-right:15px;margin-top:10px;min-width:40px;padding:0;text-align:center;width:auto}.EquationEditor .centerBox{display:inline-block;text-align:center}.EquationEditor .editable{border:1px solid #b0b0b0;border-radius:5px;color:#404040;font-size:20px;margin-bottom:5px;margin-top:6px;min-height:26px;min-width:150px;padding:7px 10px;text-align:left}.EquationEditor .editable-placeholder{color:grey;font-size:15px;min-height:26px;min-width:150px;position:absolute;transform:translate(-12px,-36px);z-index:-1}.EquationEditor .editable:focus-within{border:1px solid #663676!important;border-radius:5px;box-shadow:0 0 0 #fff}.latexInputAreaWrapper{width:auto}.EquationEditor .katexRenderedInput{border:0 solid #b0b0b0;border-radius:5px;color:#404040;font-size:16px;margin:5px 15px;min-height:30px;padding:7px 10px 4px;text-align:left;width:90%}.EquationEditor .latexInput{background-color:#fff;border:1px solid #b0b0b0;border-radius:5px;box-shadow:0 0 0 #fff;color:#007000;font-size:16px;height:88px;margin-top:10px;padding:7px 10px 5px;text-align:left;width:90%}.EquationEditor .latexInput:focus{border:1px solid #663676!important;outline:0}.EquationEditor .insertButton{background:#663676;border:0;border-radius:5px;color:#fff;font-size:14px;height:36px;margin:5px;padding:0 30px;text-align:left}.EquationEditor .cancelButton{background:#fff;border:1px solid #663676;border-radius:5px;color:#663676;font-size:14px;height:36px;margin-bottom:10px;margin-left:5px;margin-right:5px;padding:0 30px;text-align:left}.EquationEditor .insertButton:hover{background:#461656;color:#fff;cursor:pointer}.EquationEditor .recentSymbols-recentText-active{color:#404040;font-size:14px;font-weight:700;margin-right:10px}.EquationEditor .recentSymbols-recentText-not-active{color:grey;font-size:14px;font-weight:700;margin-bottom:10px;margin-top:10px}.EquationEditor .tabBar{background:#fff;border:0;margin:5px;padding:10px 10px 5px 20px;text-align:left}@media (max-width:500px){.EquationEditor .tabBar{padding:5px 0}}.EquationEditor .tab{border:0;border-bottom:6px solid #d0d0d0;color:#404040;font-size:14px;font-weight:700;height:30px;margin:5px;padding:5px 10px;text-align:left}.EquationEditor .tab:hover{cursor:pointer}.EquationEditor .tab-selected{border:0;border-bottom:6px solid #663676;color:#404040;font-size:14px;font-weight:700;height:30px;margin:5px;padding:5px 10px;text-align:left}.EquationEditor .recentSymbolsButtonArea{display:flex;justify-content:flex-start;margin:5px 5px 5px 15px;padding:2px;width:486px}.EquationEditor .symbolButtonAreasOuterContainer{overflow-x:auto}.EquationEditor .symbolButtonAreasInnerContainer{display:flex;width:2330px}.EquationEditor .symbolButtonArea{grid-gap:1.5px;display:grid;grid-auto-rows:minmax(min-content,max-content);grid-template-columns:repeat(auto-fill,minmax(36px,1fr));margin:0;padding:12px}.EquationEditor .symbolButtonArea-1{width:66px}.EquationEditor .symbolButtonArea-2{width:108px}.EquationEditor .symbolButtonArea-3{width:150px}.EquationEditor .symbolButtonArea-4{width:192px}.EquationEditor .symbolButtonArea-5{width:234px}.EquationEditor .symbolButtonArea-6{width:276px}.EquationEditorModal-background{animation:shade .3s;animation-fill-mode:forwards;background:#000;height:100%;left:0;position:fixed;top:0;width:100%;z-index:99}@keyframes shade{00%{opacity:0}to{opacity:.6}}.EquationEditorModal{animation:rise .3s;animation-fill-mode:forwards;background:#fff;border:1px solid grey;border-radius:10px;box-shadow:0 2px 5px 1px #a0a0a0;left:50%;max-width:500px;position:fixed;top:50%;width:98%;z-index:100}@keyframes rise{00%{opacity:0;transform:translate(-50%,100%)}to{opacity:1;transform:translate(-50%,-50%)}}.EquationEditorModal-mobile{background:#fff;border:1px solid grey;border-radius:10px;box-shadow:0 2px 5px 1px #a0a0a0;left:50%;max-width:500px;position:fixed;top:0;transform:translate(-50%,1px);width:99%;z-index:100}.EquationEditorModal .title,.EquationEditorModal-mobile .title{background:#e0e0e0;border:0;border-radius:5px 5px 0 0;color:#404040;display:flex;font-size:14px;justify-content:space-between;margin:0;padding:15px;text-align:left}.EquationEditorModal-mobile .title{height:30px}.expertModeSwitch{align-items:center;display:flex;flex-direction:row}.EquationEditorModal .expertModeSwitch .switch{margin-left:10px}.EquationEditorModal .switch{display:inline-block;height:22px;margin-bottom:0;padding:0;position:relative;width:35px}.EquationEditorModal .switch input{height:0;opacity:0;width:0}.EquationEditorModal .slider{background-color:#ccc;bottom:0;cursor:pointer;left:0;position:absolute;right:0;top:0;-webkit-transition:.4s;transition:.4s}.EquationEditorModal .slider:before{background-color:#fff;bottom:4px;content:"";height:14px;left:4px;position:absolute;-webkit-transition:.4s;transition:.4s;width:14px}.EquationEditorModal input:checked+.slider{background-color:#663676}.EquationEditorModal input:focus+.slider{box-shadow:0 0 1px #2196f3}.EquationEditorModal input:checked+.slider:before{-webkit-transform:translateX(13px);-ms-transform:translateX(13px);transform:translateX(13px)}.EquationEditorModal .slider.round{border-radius:18px}.EquationEditorModal .slider.round:before{border-radius:50%}.AccentBar{padding:8px;width:360px}.AccentBar,.AccentBar-compact{animation:fadeIn1 .4s;animation-fill-mode:forwards;background-color:#fff;border:1px solid #d0d0d0;border-radius:5px;box-shadow:1px 1px 5px #a0a0a0;color:#000;position:absolute;z-index:1}.AccentBar-compact{display:flex;padding:5px}.AccentBar-outerContainer{border-radius:5px;overflow-y:scroll}.AccentBar-innerContainer{height:350px}.AccentBar .symbols-grid{grid-gap:3px;display:grid;grid-auto-rows:minmax(min-content,max-content);grid-template-columns:repeat(auto-fill,minmax(36px,1fr))}.AccentBar .insert-grid{padding:5px}.AccentBar .type-a-letter{color:#a0a0a0;font-family:sans-serif;font-size:14px;font-weight:700;grid-column:1/-1;height:36px;padding-left:20px;padding-top:12px}.AccentBar-button{background:#f4f4f4;border:0;border-radius:5px;font-family:sans-serif;font-size:17px;height:36px;padding:1px;width:40px}.AB-compact{background:#fff;margin:0}.AB-narrow{width:36px}.AccentBar-button:hover{animation:grow 2s;animation-fill-mode:forwards;background:#663676;box-shadow:1px 1px 3px grey;color:#fff;cursor:pointer}@keyframes grow{00%{box-shadow:0 0 0 grey;transform:scale(1)}10%{box-shadow:1px 1px 3px grey;transform:scale(1.3)}90%{box-shadow:1px 1px 3px grey;transform:scale(1.3)}to{box-shadow:1px 1px 3px grey;transform:scale(1.8)}}.AccentBar-button:active{background:grey;color:#fff;cursor:pointer}.AccentBar .tabBar{background:#fff;border:0;padding:10px 0;text-align:left}.AccentBar .tab{border:0;border-bottom:4px solid #d0d0d0;color:#404040;font-size:14px;font-weight:700;height:30px;margin:2px;padding:2px 5px;text-align:left}.AccentBar .tab:hover{cursor:pointer}.AccentBar .tab-selected{border:0;border-bottom:4px solid #663676;color:#404040;font-size:14px;font-weight:700;height:30px;margin:2px;padding:2px 5px;text-align:left}.AccentBar .section-label{color:#663676;font-size:13px;font-weight:700;grid-column:1/-1;margin-bottom:4px;margin-left:8px;margin-top:8px}.AccentBar .replace-section{min-height:70px}.AccentBar .tabArea{animation:fadeIn1 .4s;animation-fill-mode:forwards}.Toolbar{animation:fadeIn1 .5s;animation-fill-mode:forwards;background-color:#fff;border:1px solid #d0d0d0;border-radius:5px;box-shadow:1px 1px 5px #a0a0a0;color:#000;display:flex;height:42px;position:absolute;z-index:10}@keyframes fadeIn1{0%{opacity:0}to{opacity:1}}.Toolbar-button{background-color:#fff;border:0;border-radius:5px;font-family:sans-serif;font-size:16px;height:36px;margin:2px;padding:1px;width:40px}.Toolbar-button:hover{background:#663676;color:#fff;cursor:pointer}.Toolbar-button:active{background:grey;color:#fff;cursor:pointer}.TB-narrow{width:30px}.TB-wide{width:46px}.TB-selected{animation:TB-fadeIn .2s;animation-fill-mode:forwards;background:#d0d0d0;color:#000;cursor:pointer}.TB-selected:hover{background:#663676;color:#fff;cursor:pointer}@keyframes TB-fadeIn{00%{background:#fff}to{background:#d0d0d0}}.Toolbar-button .tooltiptext{background-color:#222;border-radius:6px;color:#fff;font-size:12px;font-weight:400;left:50px;padding:4px 10px;position:absolute;text-align:center;top:-90%;visibility:hidden;width:100px;z-index:11}.Toolbar-button:hover .tooltiptext{animation:fadeIn2 .8s;animation-fill-mode:forwards;visibility:visible}@keyframes fadeIn2{00%{opacity:0}70%{opacity:0}to{opacity:.9;visibility:visible}}*,:after,:before{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.MathRichInput-Container{border-radius:5px;width:100%}.MathRichInput-scrollview{border-radius:5px;display:flex;position:relative}.MathRichInput p{margin:0;padding:0}.MathRichInput{background-color:#fff;border-radius:5px;font-size:18px;overflow-x:scroll;overflow:overlay;padding:10px;width:100%}.MathRichInput:empty:before{color:#acb6c0;content:attr(data-placeholder);font-size:15px}.MathRichInput:empty:focus:before{content:""}.MathRichInput:focus{outline:0}.MathRichInput .katex{border:0}.MathRichInput .base{background-color:#f0f0f0;border:1px dotted #d0d0d0;border-radius:5px;margin:0 2px;padding:2px}.katex .mathnormal{font-family:KaTeX_Math;font-style:italic}.MathRichInput .katex-error{background-color:#f0f0f0;border:1px dotted #ff8080;border-radius:5px;margin:0 2px;padding:2px}.MathRichInput-Container :focus-within{background-color:#fff;outline:0}.MathRichInput-Container.dark :focus-within{background:none;border:none;outline:0}.MathRichInput-Container.dark .MathRichInput{background:none;border:none;color:#fff}.MathRichInput-Container.dark .MathRichInput .base,.MathRichInput-Container.dark .MathRichInput .katex{background:none}.MathRichInput-Container.dark .MathRichInput:focus{background:none;border:none}.MathRichInput-Container.question-edit-input .MathRichInput{border-radius:12px;font-size:32px;font-weight:400}.MathRichInput-Container.question-edit-input .MathRichInput:focus{background:hsla(0,0%,100%,.1);border:none}.MathRichInput-Container.answer-edit-input .MathRichInput{font-size:16px;font-weight:400}.MathRichInput-Container.explanation-input .MathRichInput,.MathRichInput-Container.hint-input .MathRichInput{color:#322e33;font-size:16px;font-weight:400}.MathRichInput-Container.explanation-input .MathRichInput .base,.MathRichInput-Container.hint-input .MathRichInput .base{border:1px dotted #322e33}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzish/math-rich-input",
3
- "version": "0.1.46",
3
+ "version": "0.1.48",
4
4
  "description": "React component for user to enter rich text with embedded math equations.",
5
5
  "repository": {
6
6
  "type": "git",
package/rollup.config.js CHANGED
@@ -17,9 +17,8 @@ export default {
17
17
  postcss({
18
18
  extensions: [".css"],
19
19
  plugins: [nested()], // Process nested rules
20
- extract: true, // Extract to a file
20
+ extract: "math-rich-input.css", // Extract to a file
21
21
  minimize: true, // Minimize the output
22
- output: "math-rich-input.css",
23
22
  }),
24
23
  babel({
25
24
  babelHelpers: "bundled",
@@ -166,6 +166,7 @@ export default class MathRichInput extends React.Component {
166
166
  superscript: false,
167
167
  },
168
168
  keyPressed: "",
169
+ pendingHtmlWithMarker: null,
169
170
  };
170
171
 
171
172
  // this.handleInput = this.handleInput.bind(this);
@@ -1194,38 +1195,49 @@ export default class MathRichInput extends React.Component {
1194
1195
  };
1195
1196
 
1196
1197
  handlePaste = (event) => {
1198
+ try {
1197
1199
  let clipboardData = event.clipboardData || window.clipboardData;
1198
- if (clipboardData === null || clipboardData === undefined) {
1199
- console.warn("handlePaste called, but no clipboard data");
1200
+ if (!clipboardData) {
1201
+ return;
1202
+ }
1203
+ event.preventDefault();
1204
+ let pasteHtml = clipboardData.getData('text/html');
1205
+ let pasteText = clipboardData.getData('text/plain');
1206
+ const selection = window.getSelection();
1207
+ if (!selection.rangeCount) {
1200
1208
  return;
1201
1209
  }
1202
- // for (let i = 0; i < clipboardData.types.length; i++)
1203
- // console.log(
1204
- // clipboardData.types[i] +
1205
- // ": " +
1206
- // clipboardData.getData(clipboardData.types[i])
1207
- // );
1208
- let pasteHtml = clipboardData.getData("text/html");
1209
- if (pasteHtml !== null && pasteHtml.length > 0) {
1210
- // console.log("** Paste html");
1211
- // console.log(pasteHtml);
1212
- pasteHtml = sanitiseHtml(pasteHtml);
1213
- // console.log("** Santised paste html");
1214
- // console.log(pasteHtml);
1215
- this.insertHtml(pasteHtml);
1216
- event.preventDefault();
1217
- } else {
1218
- let paste = clipboardData.getData("text");
1219
- const selection = window.getSelection();
1220
- if (!selection.rangeCount) {
1221
- console.warn("handlePaste called, but unable to get selection");
1222
- return false;
1210
+ selection.deleteFromDocument();
1211
+ if (pasteHtml && pasteHtml.length > 0) {
1212
+ const markerId = `__PASTE_MARKER_${Date.now()}_${Math.floor(Math.random()*10000)}__`;
1213
+ const markerStart = `<span id='${markerId}_START'></span>`;
1214
+ const markerEnd = `<span id='${markerId}_END'></span>`;
1215
+ let markedHtml = markerStart + pasteHtml + markerEnd;
1216
+ if (typeof sanitiseHtml === 'function') {
1217
+ markedHtml = sanitiseHtml(markedHtml);
1223
1218
  }
1224
- event.preventDefault();
1225
- selection.deleteFromDocument();
1226
- this.insertRawText(paste);
1219
+ this._pendingPasteMarkerId = markerId;
1220
+ document.execCommand('insertHTML', false, markedHtml);
1221
+ setTimeout(() => {
1222
+ try {
1223
+ const rawText = elementToMarkedRawText(this.editableDiv, null, -1, this.enableHtml());
1224
+ let nodeCounts = this._countNodeTypes();
1225
+ let mimeType = this.getMimeType(nodeCounts.html > 0, nodeCounts.math > 0);
1226
+ const cleanedRawText = removeEncodingIfPlainText(rawText, mimeType, this.enableHtml());
1227
+ this.applyChangesToComponent(cleanedRawText, mimeType, this._getRangeParams(), this.props.useExpertMode, this.props.selectedTab);
1228
+ } catch (err) {
1229
+ console.error(err);
1230
+ }
1231
+ }, 0);
1232
+ } else if (pasteText && pasteText.length > 0) {
1233
+ this.insertRawText(pasteText);
1227
1234
  }
1228
- };
1235
+ } catch (error) {
1236
+ console.error(error);
1237
+ }
1238
+ };
1239
+
1240
+
1229
1241
 
1230
1242
  componentDidMount() {
1231
1243
  try {
@@ -1251,8 +1263,24 @@ export default class MathRichInput extends React.Component {
1251
1263
  }
1252
1264
 
1253
1265
  componentDidUpdate() {
1254
- try {
1255
- // console.log("componentDidUpdate")
1266
+ try {
1267
+ if (this._pendingPasteMarkerId) {
1268
+ const start = document.getElementById(`${this._pendingPasteMarkerId}_START`);
1269
+ const end = document.getElementById(`${this._pendingPasteMarkerId}_END`);
1270
+ if (start && end) {
1271
+ const range = document.createRange();
1272
+ range.setStartAfter(start);
1273
+ range.setEndBefore(end);
1274
+ const sel = window.getSelection();
1275
+ sel.removeAllRanges();
1276
+ sel.addRange(range);
1277
+ start.parentNode && start.parentNode.removeChild(start);
1278
+ end.parentNode && end.parentNode.removeChild(end);
1279
+ }
1280
+ this._pendingPasteMarkerId = null;
1281
+ this.setState({ pendingHtmlWithMarker: null });
1282
+ }
1283
+
1256
1284
  if (
1257
1285
  this.afterComponentUpdateData !== null &&
1258
1286
  this.afterComponentUpdateData !== undefined &&
@@ -1629,7 +1657,7 @@ export default class MathRichInput extends React.Component {
1629
1657
  }
1630
1658
  };
1631
1659
 
1632
- insertRawText = (new_text, selectInsertedText = true) => {
1660
+ insertRawText = (new_text, selectInsertedText = false) => {
1633
1661
  try {
1634
1662
  let rangeParams = this._getRangeParams();
1635
1663
  let node = this._findNodeWithIndex(rangeParams.endNodeIndex);
@@ -1709,10 +1737,11 @@ export default class MathRichInput extends React.Component {
1709
1737
  // Preserve the selection
1710
1738
  if (lastNode) {
1711
1739
  range = range.cloneRange();
1712
- range.setStartAfter(lastNode);
1713
1740
  if (selectPastedContent) {
1714
1741
  range.setStartBefore(firstNode);
1742
+ range.setEndAfter(lastNode);
1715
1743
  } else {
1744
+ range.setStartAfter(lastNode);
1716
1745
  range.collapse(true);
1717
1746
  }
1718
1747
  sel.removeAllRanges();
@@ -1732,11 +1761,11 @@ export default class MathRichInput extends React.Component {
1732
1761
  }
1733
1762
  };
1734
1763
 
1735
- insertHtml = (new_html) => {
1764
+ insertHtml = (new_html, selectPastedContent = false) => {
1736
1765
  try {
1737
1766
  // console.log("New html: "+new_html)
1738
1767
  // console.log("inserting: "+new_html)
1739
- this.pasteHtmlAtCaret(new_html, true);
1768
+ this.pasteHtmlAtCaret(new_html, selectPastedContent);
1740
1769
  let new_rangeParams = null;
1741
1770
  // console.log("New range params: ")
1742
1771
  try {
@@ -2136,7 +2165,7 @@ export default class MathRichInput extends React.Component {
2136
2165
  onBlur={this.handleBlur}
2137
2166
  onCompositionStart={this.handleCompositionStart}
2138
2167
  onCompositionEnd={this.handleCompositionEnd}
2139
- dangerouslySetInnerHTML={{ __html: html }}
2168
+ dangerouslySetInnerHTML={{ __html: this.state.pendingHtmlWithMarker || html }}
2140
2169
  data-placeholder={this.props.placeholder || ""}
2141
2170
  ></span>
2142
2171
  </div>
package/dist/index.css DELETED
@@ -1 +0,0 @@
1
- .SymbolButton{background:#e0e0e0;border:0;border-radius:5px;color:#202020;display:inline-block;font-size:14px;font-weight:700;height:36px;margin:3px 3px auto;overflow:hidden;padding:1px;text-align:center;width:36px}.SymbolButton:hover{animation:grow 2s;animation-fill-mode:forwards;box-shadow:1px 1px 3px grey;color:#000;cursor:pointer;filter:saturate(2)}.SymbolButton:active{background:grey;color:#fff;cursor:pointer;transform:scale(1.3)}.SymbolButton-fadeIn{height:100px;opacity:1;transition:width .5s,height .5s,opacity .5s .5s;width:100px}.highlight-0{background:#ebc9eb}.highlight-operators{background:#f8e8d8}.highlight-angles{background:#cceded}.highlight-greeklower{background:#f8e8d8}.highlight-greekupper{background:#cceded}.highlight-misc{background:#f8e8d8}.highlight-sets{background:#cceded}.highlight-chemistry{background:#f8e8d8}.highlight-elements{background:#cceded}.highlight-physics2{background:#f8e8d8}.highlight-physics3{background:#cceded}.highlight-expert,.highlight-matrices{background:#f4d6f5}.EquationEditor{height:auto;text-align:center}.EquationEditor .editableAndCursorButtonsWrapper{align-items:center;display:flex;justify-content:center}.EquationEditor .editableWrapper{overflow:auto;width:100%}.EquationEditor .cursorButton{background:#fff;border:1px solid #663676;border-radius:5px;color:#663676;font-size:14px;font-weight:700;height:40px;margin-left:15px;margin-right:15px;margin-top:10px;min-width:40px;padding:0;text-align:center;width:auto}.EquationEditor .centerBox{display:inline-block;text-align:center}.EquationEditor .editable{border:1px solid #b0b0b0;border-radius:5px;color:#404040;font-size:20px;margin-bottom:5px;margin-top:6px;min-height:26px;min-width:150px;padding:7px 10px;text-align:left}.EquationEditor .editable-placeholder{color:grey;font-size:15px;min-height:26px;min-width:150px;position:absolute;transform:translate(-12px,-36px);z-index:-1}.EquationEditor .editable:focus-within{border:1px solid #663676!important;border-radius:5px;box-shadow:0 0 0 #fff}.latexInputAreaWrapper{width:auto}.EquationEditor .katexRenderedInput{border:0 solid #b0b0b0;border-radius:5px;color:#404040;font-size:16px;margin:5px 15px;min-height:30px;padding:7px 10px 4px;text-align:left;width:90%}.EquationEditor .latexInput{background-color:#fff;border:1px solid #b0b0b0;border-radius:5px;box-shadow:0 0 0 #fff;color:#007000;font-size:16px;height:88px;margin-top:10px;padding:7px 10px 5px;text-align:left;width:90%}.EquationEditor .latexInput:focus{border:1px solid #663676!important;outline:0}.EquationEditor .insertButton{background:#663676;border:0;border-radius:5px;color:#fff;font-size:14px;height:36px;margin:5px;padding:0 30px;text-align:left}.EquationEditor .cancelButton{background:#fff;border:1px solid #663676;border-radius:5px;color:#663676;font-size:14px;height:36px;margin-bottom:10px;margin-left:5px;margin-right:5px;padding:0 30px;text-align:left}.EquationEditor .insertButton:hover{background:#461656;color:#fff;cursor:pointer}.EquationEditor .recentSymbols-recentText-active{color:#404040;font-size:14px;font-weight:700;margin-right:10px}.EquationEditor .recentSymbols-recentText-not-active{color:grey;font-size:14px;font-weight:700;margin-bottom:10px;margin-top:10px}.EquationEditor .tabBar{background:#fff;border:0;margin:5px;padding:10px 10px 5px 20px;text-align:left}@media (max-width:500px){.EquationEditor .tabBar{padding:5px 0}}.EquationEditor .tab{border:0;border-bottom:6px solid #d0d0d0;color:#404040;font-size:14px;font-weight:700;height:30px;margin:5px;padding:5px 10px;text-align:left}.EquationEditor .tab:hover{cursor:pointer}.EquationEditor .tab-selected{border:0;border-bottom:6px solid #663676;color:#404040;font-size:14px;font-weight:700;height:30px;margin:5px;padding:5px 10px;text-align:left}.EquationEditor .recentSymbolsButtonArea{display:flex;justify-content:flex-start;margin:5px 5px 5px 15px;padding:2px;width:486px}.EquationEditor .symbolButtonAreasOuterContainer{overflow-x:auto}.EquationEditor .symbolButtonAreasInnerContainer{display:flex;width:2330px}.EquationEditor .symbolButtonArea{grid-gap:1.5px;display:grid;grid-auto-rows:minmax(min-content,max-content);grid-template-columns:repeat(auto-fill,minmax(36px,1fr));margin:0;padding:12px}.EquationEditor .symbolButtonArea-1{width:66px}.EquationEditor .symbolButtonArea-2{width:108px}.EquationEditor .symbolButtonArea-3{width:150px}.EquationEditor .symbolButtonArea-4{width:192px}.EquationEditor .symbolButtonArea-5{width:234px}.EquationEditor .symbolButtonArea-6{width:276px}.EquationEditorModal-background{animation:shade .3s;animation-fill-mode:forwards;background:#000;height:100%;left:0;position:fixed;top:0;width:100%;z-index:99}@keyframes shade{00%{opacity:0}to{opacity:.6}}.EquationEditorModal{animation:rise .3s;animation-fill-mode:forwards;background:#fff;border:1px solid grey;border-radius:10px;box-shadow:0 2px 5px 1px #a0a0a0;left:50%;max-width:500px;position:fixed;top:50%;width:98%;z-index:100}@keyframes rise{00%{opacity:0;transform:translate(-50%,100%)}to{opacity:1;transform:translate(-50%,-50%)}}.EquationEditorModal-mobile{background:#fff;border:1px solid grey;border-radius:10px;box-shadow:0 2px 5px 1px #a0a0a0;left:50%;max-width:500px;position:fixed;top:0;transform:translate(-50%,1px);width:99%;z-index:100}.EquationEditorModal .title,.EquationEditorModal-mobile .title{background:#e0e0e0;border:0;border-radius:5px 5px 0 0;color:#404040;display:flex;font-size:14px;justify-content:space-between;margin:0;padding:15px;text-align:left}.EquationEditorModal-mobile .title{height:30px}.expertModeSwitch{align-items:center;display:flex;flex-direction:row}.EquationEditorModal .expertModeSwitch .switch{margin-left:10px}.EquationEditorModal .switch{display:inline-block;height:22px;margin-bottom:0;padding:0;position:relative;width:35px}.EquationEditorModal .switch input{height:0;opacity:0;width:0}.EquationEditorModal .slider{background-color:#ccc;bottom:0;cursor:pointer;left:0;position:absolute;right:0;top:0;transition:.4s}.EquationEditorModal .slider:before{background-color:#fff;bottom:4px;content:"";height:14px;left:4px;position:absolute;transition:.4s;width:14px}.EquationEditorModal input:checked+.slider{background-color:#663676}.EquationEditorModal input:focus+.slider{box-shadow:0 0 1px #2196f3}.EquationEditorModal input:checked+.slider:before{transform:translateX(13px)}.EquationEditorModal .slider.round{border-radius:18px}.EquationEditorModal .slider.round:before{border-radius:50%}.AccentBar{padding:8px;width:360px}.AccentBar,.AccentBar-compact{animation:fadeIn1 .4s;animation-fill-mode:forwards;background-color:#fff;border:1px solid #d0d0d0;border-radius:5px;box-shadow:1px 1px 5px #a0a0a0;color:#000;position:absolute;z-index:1}.AccentBar-compact{display:flex;padding:5px}.AccentBar-outerContainer{border-radius:5px;overflow-y:scroll}.AccentBar-innerContainer{height:350px}.AccentBar .symbols-grid{grid-gap:3px;display:grid;grid-auto-rows:minmax(min-content,max-content);grid-template-columns:repeat(auto-fill,minmax(36px,1fr))}.AccentBar .insert-grid{padding:5px}.AccentBar .type-a-letter{color:#a0a0a0;font-family:sans-serif;font-size:14px;font-weight:700;grid-column:1/-1;height:36px;padding-left:20px;padding-top:12px}.AccentBar-button{background:#f4f4f4;border:0;border-radius:5px;font-family:sans-serif;font-size:17px;height:36px;padding:1px;width:40px}.AB-compact{background:#fff;margin:0}.AB-narrow{width:36px}.AccentBar-button:hover{animation:grow 2s;animation-fill-mode:forwards;background:#663676;box-shadow:1px 1px 3px grey;color:#fff;cursor:pointer}@keyframes grow{00%{box-shadow:0 0 0 grey;transform:scale(1)}10%{box-shadow:1px 1px 3px grey;transform:scale(1.3)}90%{box-shadow:1px 1px 3px grey;transform:scale(1.3)}to{box-shadow:1px 1px 3px grey;transform:scale(1.8)}}.AccentBar-button:active{background:grey;color:#fff;cursor:pointer}.AccentBar .tabBar{background:#fff;border:0;padding:10px 0;text-align:left}.AccentBar .tab{border:0;border-bottom:4px solid #d0d0d0;color:#404040;font-size:14px;font-weight:700;height:30px;margin:2px;padding:2px 5px;text-align:left}.AccentBar .tab:hover{cursor:pointer}.AccentBar .tab-selected{border:0;border-bottom:4px solid #663676;color:#404040;font-size:14px;font-weight:700;height:30px;margin:2px;padding:2px 5px;text-align:left}.AccentBar .section-label{color:#663676;font-size:13px;font-weight:700;grid-column:1/-1;margin-bottom:4px;margin-left:8px;margin-top:8px}.AccentBar .replace-section{min-height:70px}.AccentBar .tabArea{animation:fadeIn1 .4s;animation-fill-mode:forwards}.Toolbar{animation:fadeIn1 .5s;animation-fill-mode:forwards;background-color:#fff;border:1px solid #d0d0d0;border-radius:5px;box-shadow:1px 1px 5px #a0a0a0;color:#000;display:flex;height:42px;position:absolute;z-index:10}@keyframes fadeIn1{0%{opacity:0}to{opacity:1}}.Toolbar-button{background-color:#fff;border:0;border-radius:5px;font-family:sans-serif;font-size:16px;height:36px;margin:2px;padding:1px;width:40px}.Toolbar-button:hover{background:#663676;color:#fff;cursor:pointer}.Toolbar-button:active{background:grey;color:#fff;cursor:pointer}.TB-narrow{width:30px}.TB-wide{width:46px}.TB-selected{animation:TB-fadeIn .2s;animation-fill-mode:forwards;background:#d0d0d0;color:#000;cursor:pointer}.TB-selected:hover{background:#663676;color:#fff;cursor:pointer}@keyframes TB-fadeIn{00%{background:#fff}to{background:#d0d0d0}}.Toolbar-button .tooltiptext{background-color:#222;border-radius:6px;color:#fff;font-size:12px;font-weight:400;left:50px;padding:4px 10px;position:absolute;text-align:center;top:-90%;visibility:hidden;width:100px;z-index:11}.Toolbar-button:hover .tooltiptext{animation:fadeIn2 .8s;animation-fill-mode:forwards;visibility:visible}@keyframes fadeIn2{00%{opacity:0}70%{opacity:0}to{opacity:.9;visibility:visible}}*,:after,:before{box-sizing:border-box}.MathRichInput-Container{border-radius:5px;width:100%}.MathRichInput-scrollview{border-radius:5px;display:flex;position:relative}.MathRichInput p{margin:0;padding:0}.MathRichInput{background-color:#fff;border-radius:5px;font-size:18px;overflow-x:scroll;overflow:overlay;padding:10px;width:100%}.MathRichInput:empty:before{color:#acb6c0;content:attr(data-placeholder);font-size:15px}.MathRichInput:empty:focus:before{content:""}.MathRichInput:focus{outline:0}.MathRichInput .katex{border:0}.MathRichInput .base{background-color:#f0f0f0;border:1px dotted #d0d0d0;border-radius:5px;margin:0 2px;padding:2px}.katex .mathnormal{font-family:KaTeX_Math;font-style:italic}.MathRichInput .katex-error{background-color:#f0f0f0;border:1px dotted #ff8080;border-radius:5px;margin:0 2px;padding:2px}.MathRichInput-Container :focus-within{background-color:#fff;outline:0}.MathRichInput-Container.dark :focus-within{background:none;border:none;outline:0}.MathRichInput-Container.dark .MathRichInput{background:none;border:none;color:#fff}.MathRichInput-Container.dark .MathRichInput .base,.MathRichInput-Container.dark .MathRichInput .katex{background:none}.MathRichInput-Container.dark .MathRichInput:focus{background:none;border:none}.MathRichInput-Container.question-edit-input .MathRichInput{border-radius:12px;font-size:32px;font-weight:400}.MathRichInput-Container.question-edit-input .MathRichInput:focus{background:hsla(0,0%,100%,.1);border:none}.MathRichInput-Container.answer-edit-input .MathRichInput{font-size:16px;font-weight:400}.MathRichInput-Container.explanation-input .MathRichInput,.MathRichInput-Container.hint-input .MathRichInput{color:#322e33;font-size:16px;font-weight:400}.MathRichInput-Container.explanation-input .MathRichInput .base,.MathRichInput-Container.hint-input .MathRichInput .base{border:1px dotted #322e33}