@zzish/math-rich-input 0.1.13 → 0.1.15

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
@@ -21469,7 +21469,8 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
21469
21469
  rangeParams: rangeParams
21470
21470
  });
21471
21471
 
21472
- if (_this2.undoHistory.length > MAX_HISTORY_LENGTH) _this2.undoHistory.shift(); // Call the parent handler to apply the changes
21472
+ if (_this2.undoHistory.length > MAX_HISTORY_LENGTH) _this2.undoHistory.shift();
21473
+ _this2.value = value; // Call the parent handler to apply the changes
21473
21474
 
21474
21475
  _this2.onChangeCallback({
21475
21476
  value: value,
@@ -21480,6 +21481,10 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
21480
21481
  });
21481
21482
  });
21482
21483
 
21484
+ _defineProperty(_assertThisInitialized(_this2), "getValue", function () {
21485
+ return _this2.value;
21486
+ });
21487
+
21483
21488
  _defineProperty(_assertThisInitialized(_this2), "initialiseHistory", function () {
21484
21489
  if (_this2.initialHistoryState == null) _this2.initialHistoryState = {
21485
21490
  value: _this2.props.value,
@@ -22829,7 +22834,8 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22829
22834
  superscript: false
22830
22835
  },
22831
22836
  keyPressed: ""
22832
- }; // this.handleInput = this.handleInput.bind(this);
22837
+ };
22838
+ _this2.value = ""; // this.handleInput = this.handleInput.bind(this);
22833
22839
  // this.handleKeyDown = this.handleKeyDown.bind(this);
22834
22840
  // this.handleKeyUp = this.handleKeyUp.bind(this);
22835
22841
  // Remember the last key pressed
@@ -22964,6 +22970,9 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22964
22970
  }, {
22965
22971
  key: "componentDidMount",
22966
22972
  value: function componentDidMount() {
22973
+ var onRef = this.props.onRef;
22974
+ onRef && onRef(this);
22975
+
22967
22976
  try {
22968
22977
  setupKatex();
22969
22978
  this.editableDiv.addEventListener("keydown", this.handleKeyDown);
@@ -22975,6 +22984,9 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22975
22984
  }, {
22976
22985
  key: "componentWillUnmount",
22977
22986
  value: function componentWillUnmount() {
22987
+ var onRef = this.props.onRef;
22988
+ onRef && onRef(undefined);
22989
+
22978
22990
  try {
22979
22991
  this.editableDiv.removeEventListener("keydown", this.handleKeyDown);
22980
22992
  this.editableDiv.removeEventListener("keyup", this.handleKeyUp);
@@ -69,160 +69,180 @@
69
69
  padding: 2px;
70
70
  margin: 0px 2px;
71
71
  }
72
- .EquationEditorModal-background {
73
- position: fixed;
74
- top: 0;
75
- left: 0;
76
- width: 100%;
77
- height: 100%;
78
- background: black;
79
- z-index: 99;
80
- animation: 0.3s shade;
72
+ /* Note that the top left position of the accent bar is set programatically in componentDidMount */
73
+
74
+ .AccentBar {
75
+ position: absolute;
76
+ z-index: 1;
77
+ width: 360px;
78
+ background-color: #fff;
79
+ border: 1px solid #d0d0d0;
80
+ border-radius: 5px;
81
+ box-shadow: 1px 1px 5px #a0a0a0;
82
+ padding: 8px;
83
+ animation: 0.4s fadeIn1;
81
84
  animation-fill-mode: forwards;
82
85
  }
83
86
 
84
- @keyframes shade {
85
- 00% {
86
- opacity: 0;
87
- }
88
- 100% {
89
- opacity: 0.6;
90
- }
87
+ .AccentBar-compact {
88
+ display: flex;
89
+ position: absolute;
90
+ z-index: 1;
91
+ background-color: white;
92
+ border: 1px solid #d0d0d0;
93
+ border-radius: 5px;
94
+ box-shadow: 1px 1px 5px #a0a0a0;
95
+ padding: 5px;
96
+ animation: 0.4s fadeIn1;
97
+ animation-fill-mode: forwards;
91
98
  }
92
99
 
93
- .EquationEditorModal {
94
- background: white;
95
- border: 1px solid #808080;
96
- border-radius: 10px;
97
- box-shadow: 0px 2px 5px 1px #a0a0a0;
98
- position: fixed;
99
- max-width: 500px;
100
- width: 98%;
101
- top: 50%;
102
- left: 50%;
103
- /* transform: translate(-50%,-50%); */
104
- z-index: 100;
105
- animation: 0.3s rise;
106
- animation-fill-mode: forwards;
100
+ .AccentBar-outerContainer {
101
+ overflow-y: scroll;
102
+ border-radius: 5px;
107
103
  }
108
104
 
109
- @keyframes rise {
110
- 00% {
111
- transform: translate(-50%, 100%);
105
+ .AccentBar-innerContainer {
106
+ height: 350px;
107
+ }
108
+
109
+ @keyframes fadeIn1 {
110
+ 0% {
112
111
  opacity: 0;
113
112
  }
114
113
  100% {
115
- transform: translate(-50%, -50%);
116
114
  opacity: 1;
117
115
  }
118
116
  }
119
117
 
120
- .EquationEditorModal-mobile {
121
- background: white;
122
- border: 1px solid #808080;
123
- border-radius: 10px;
124
- box-shadow: 0px 2px 5px 1px #a0a0a0;
125
- position: fixed;
126
- max-width: 500px;
127
- width: 99%;
128
- top: 0%;
129
- left: 50%;
130
- transform: translate(-50%, 1px);
131
- z-index: 100;
118
+ .AccentBar .symbols-grid {
119
+ display: grid;
120
+ grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
121
+ grid-auto-rows: minmax(min-content, max-content);
122
+ grid-gap: 3px;
132
123
  }
133
124
 
134
- .EquationEditorModal .title {
135
- display: flex;
136
- justify-content: space-between;
137
- font-size: 14px;
138
- color: #404040;
139
- text-align: left;
140
- background: #e0e0e0;
141
- border: 0px;
142
- border-radius: 5px 5px 0px 0px;
143
- padding: 15px;
144
- margin: 0px;
125
+ .AccentBar .insert-grid {
126
+ padding: 5px;
145
127
  }
146
128
 
147
- .EquationEditorModal-mobile .title {
148
- display: flex;
149
- justify-content: space-between;
129
+ .AccentBar .type-a-letter {
130
+ grid-column: 1/-1;
131
+ color: #a0a0a0;
132
+ font-family: sans-serif;
150
133
  font-size: 14px;
151
- color: #404040;
152
- text-align: left;
153
- background: #e0e0e0;
134
+ font-weight: bold;
135
+ height: 36px;
136
+ padding-top: 12px;
137
+ padding-left: 20px;
138
+ }
139
+
140
+ .AccentBar-button {
141
+ font-family: sans-serif;
142
+ font-size: 17px;
143
+ width: 40px;
144
+ height: 36px;
145
+ background: #f4f4f4;
146
+ border-radius: 5px;
154
147
  border: 0px;
155
- border-radius: 5px 5px 0px 0px;
156
- height: 30px;
157
- padding: 15px;
148
+ padding: 1px;
149
+ }
150
+
151
+ .AB-compact {
158
152
  margin: 0px;
153
+ background: white;
159
154
  }
160
155
 
161
- .EquationEditorModal .expertModeSwitch .switch {
162
- margin-left: 10px;
156
+ .AB-narrow {
157
+ width: 36px;
163
158
  }
164
159
 
165
- /* The switch - the box around the slider */
166
- .EquationEditorModal .switch {
167
- position: relative;
168
- display: inline-block;
169
- width: 35px;
170
- height: 22px;
160
+ .AccentBar-button:hover {
161
+ color: white;
162
+ background: #663676;
163
+ cursor: pointer;
164
+ box-shadow: 1px 1px 3px #808080;
165
+ animation: 2s grow;
166
+ animation-fill-mode: forwards;
171
167
  }
172
168
 
173
- /* Hide default HTML checkbox */
174
- .EquationEditorModal .switch input {
175
- opacity: 0;
176
- width: 0;
177
- height: 0;
169
+ @keyframes grow {
170
+ 00% {
171
+ transform: scale(1);
172
+ box-shadow: 0px 0px 0px #808080;
173
+ }
174
+ 10% {
175
+ transform: scale(1.3);
176
+ box-shadow: 1px 1px 3px #808080;
177
+ }
178
+ 90% {
179
+ transform: scale(1.3);
180
+ box-shadow: 1px 1px 3px #808080;
181
+ }
182
+ 100% {
183
+ transform: scale(1.8);
184
+ box-shadow: 1px 1px 3px #808080;
185
+ }
178
186
  }
179
187
 
180
- /* The slider */
181
- .EquationEditorModal .slider {
182
- position: absolute;
188
+ .AccentBar-button:active {
189
+ background: #808080;
190
+ color: white;
183
191
  cursor: pointer;
184
- top: 0;
185
- left: 0;
186
- right: 0;
187
- bottom: 0;
188
- background-color: #ccc;
189
- -webkit-transition: 0.4s;
190
- transition: 0.4s;
191
192
  }
192
193
 
193
- .EquationEditorModal .slider:before {
194
- position: absolute;
195
- content: "";
196
- height: 14px;
197
- width: 14px;
198
- left: 4px;
199
- bottom: 4px;
200
- background-color: white;
201
- -webkit-transition: 0.4s;
202
- transition: 0.4s;
194
+ .AccentBar .tabBar {
195
+ background: white;
196
+ text-align: left;
197
+ border: 0px;
198
+ padding: 10px 0;
203
199
  }
204
200
 
205
- .EquationEditorModal input:checked + .slider {
206
- background-color: #663676;
201
+ .AccentBar .tab {
202
+ font-size: 14px;
203
+ font-weight: bold;
204
+ color: #404040;
205
+ text-align: left;
206
+ border: 0px;
207
+ height: 30px;
208
+ padding: 2px 5px 2px 5px;
209
+ margin: 2px;
210
+ border-bottom: 4px solid #d0d0d0;
207
211
  }
208
212
 
209
- .EquationEditorModal input:focus + .slider {
210
- box-shadow: 0 0 1px #2196f3;
213
+ .AccentBar .tab:hover {
214
+ cursor: pointer;
211
215
  }
212
216
 
213
- .EquationEditorModal input:checked + .slider:before {
214
- -webkit-transform: translateX(13px);
215
- -ms-transform: translateX(13px);
216
- transform: translateX(13px);
217
+ .AccentBar .tab-selected {
218
+ font-size: 14px;
219
+ font-weight: bold;
220
+ color: #404040;
221
+ text-align: left;
222
+ border: 0px;
223
+ height: 30px;
224
+ padding: 2px 5px 2px 5px;
225
+ margin: 2px;
226
+ border-bottom: 4px solid #663676;
217
227
  }
218
228
 
219
- /* Rounded sliders */
220
- .EquationEditorModal .slider.round {
221
- border-radius: 18px;
229
+ .AccentBar .section-label {
230
+ grid-column: 1/-1;
231
+ font-size: 13px;
232
+ font-weight: bold;
233
+ color: #663676;
234
+ margin-top: 8px;
235
+ margin-left: 8px;
236
+ margin-bottom: 4px;
222
237
  }
223
238
 
224
- .EquationEditorModal .slider.round:before {
225
- border-radius: 50%;
239
+ .AccentBar .replace-section {
240
+ min-height: 70px;
241
+ }
242
+
243
+ .AccentBar .tabArea {
244
+ animation: 0.4s fadeIn1;
245
+ animation-fill-mode: forwards;
226
246
  }
227
247
  /* Note that the top left position of the toolbar is set programatically in componentDidMount */
228
248
 
@@ -354,180 +374,160 @@
354
374
  display: inline-block;
355
375
  border-bottom: 1px dotted black; /* If you want dots under the hoverable text
356
376
  } */
357
- /* Note that the top left position of the accent bar is set programatically in componentDidMount */
358
-
359
- .AccentBar {
360
- position: absolute;
361
- z-index: 1;
362
- width: 360px;
363
- background-color: #fff;
364
- border: 1px solid #d0d0d0;
365
- border-radius: 5px;
366
- box-shadow: 1px 1px 5px #a0a0a0;
367
- padding: 8px;
368
- animation: 0.4s fadeIn1;
369
- animation-fill-mode: forwards;
370
- }
371
-
372
- .AccentBar-compact {
373
- display: flex;
374
- position: absolute;
375
- z-index: 1;
376
- background-color: white;
377
- border: 1px solid #d0d0d0;
378
- border-radius: 5px;
379
- box-shadow: 1px 1px 5px #a0a0a0;
380
- padding: 5px;
381
- animation: 0.4s fadeIn1;
377
+ .EquationEditorModal-background {
378
+ position: fixed;
379
+ top: 0;
380
+ left: 0;
381
+ width: 100%;
382
+ height: 100%;
383
+ background: black;
384
+ z-index: 99;
385
+ animation: 0.3s shade;
382
386
  animation-fill-mode: forwards;
383
387
  }
384
388
 
385
- .AccentBar-outerContainer {
386
- overflow-y: scroll;
387
- border-radius: 5px;
389
+ @keyframes shade {
390
+ 00% {
391
+ opacity: 0;
392
+ }
393
+ 100% {
394
+ opacity: 0.6;
395
+ }
388
396
  }
389
397
 
390
- .AccentBar-innerContainer {
391
- height: 350px;
398
+ .EquationEditorModal {
399
+ background: white;
400
+ border: 1px solid #808080;
401
+ border-radius: 10px;
402
+ box-shadow: 0px 2px 5px 1px #a0a0a0;
403
+ position: fixed;
404
+ max-width: 500px;
405
+ width: 98%;
406
+ top: 50%;
407
+ left: 50%;
408
+ /* transform: translate(-50%,-50%); */
409
+ z-index: 100;
410
+ animation: 0.3s rise;
411
+ animation-fill-mode: forwards;
392
412
  }
393
413
 
394
- @keyframes fadeIn1 {
395
- 0% {
414
+ @keyframes rise {
415
+ 00% {
416
+ transform: translate(-50%, 100%);
396
417
  opacity: 0;
397
418
  }
398
419
  100% {
420
+ transform: translate(-50%, -50%);
399
421
  opacity: 1;
400
422
  }
401
423
  }
402
424
 
403
- .AccentBar .symbols-grid {
404
- display: grid;
405
- grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
406
- grid-auto-rows: minmax(min-content, max-content);
407
- grid-gap: 3px;
408
- }
409
-
410
- .AccentBar .insert-grid {
411
- padding: 5px;
425
+ .EquationEditorModal-mobile {
426
+ background: white;
427
+ border: 1px solid #808080;
428
+ border-radius: 10px;
429
+ box-shadow: 0px 2px 5px 1px #a0a0a0;
430
+ position: fixed;
431
+ max-width: 500px;
432
+ width: 99%;
433
+ top: 0%;
434
+ left: 50%;
435
+ transform: translate(-50%, 1px);
436
+ z-index: 100;
412
437
  }
413
438
 
414
- .AccentBar .type-a-letter {
415
- grid-column: 1/-1;
416
- color: #a0a0a0;
417
- font-family: sans-serif;
439
+ .EquationEditorModal .title {
440
+ display: flex;
441
+ justify-content: space-between;
418
442
  font-size: 14px;
419
- font-weight: bold;
420
- height: 36px;
421
- padding-top: 12px;
422
- padding-left: 20px;
423
- }
424
-
425
- .AccentBar-button {
426
- font-family: sans-serif;
427
- font-size: 17px;
428
- width: 40px;
429
- height: 36px;
430
- background: #f4f4f4;
431
- border-radius: 5px;
443
+ color: #404040;
444
+ text-align: left;
445
+ background: #e0e0e0;
432
446
  border: 0px;
433
- padding: 1px;
447
+ border-radius: 5px 5px 0px 0px;
448
+ padding: 15px;
449
+ margin: 0px;
434
450
  }
435
451
 
436
- .AB-compact {
452
+ .EquationEditorModal-mobile .title {
453
+ display: flex;
454
+ justify-content: space-between;
455
+ font-size: 14px;
456
+ color: #404040;
457
+ text-align: left;
458
+ background: #e0e0e0;
459
+ border: 0px;
460
+ border-radius: 5px 5px 0px 0px;
461
+ height: 30px;
462
+ padding: 15px;
437
463
  margin: 0px;
438
- background: white;
439
464
  }
440
465
 
441
- .AB-narrow {
442
- width: 36px;
466
+ .EquationEditorModal .expertModeSwitch .switch {
467
+ margin-left: 10px;
443
468
  }
444
469
 
445
- .AccentBar-button:hover {
446
- color: white;
447
- background: #663676;
448
- cursor: pointer;
449
- box-shadow: 1px 1px 3px #808080;
450
- animation: 2s grow;
451
- animation-fill-mode: forwards;
470
+ /* The switch - the box around the slider */
471
+ .EquationEditorModal .switch {
472
+ position: relative;
473
+ display: inline-block;
474
+ width: 35px;
475
+ height: 22px;
452
476
  }
453
477
 
454
- @keyframes grow {
455
- 00% {
456
- transform: scale(1);
457
- box-shadow: 0px 0px 0px #808080;
458
- }
459
- 10% {
460
- transform: scale(1.3);
461
- box-shadow: 1px 1px 3px #808080;
462
- }
463
- 90% {
464
- transform: scale(1.3);
465
- box-shadow: 1px 1px 3px #808080;
466
- }
467
- 100% {
468
- transform: scale(1.8);
469
- box-shadow: 1px 1px 3px #808080;
470
- }
478
+ /* Hide default HTML checkbox */
479
+ .EquationEditorModal .switch input {
480
+ opacity: 0;
481
+ width: 0;
482
+ height: 0;
471
483
  }
472
484
 
473
- .AccentBar-button:active {
474
- background: #808080;
475
- color: white;
485
+ /* The slider */
486
+ .EquationEditorModal .slider {
487
+ position: absolute;
476
488
  cursor: pointer;
489
+ top: 0;
490
+ left: 0;
491
+ right: 0;
492
+ bottom: 0;
493
+ background-color: #ccc;
494
+ -webkit-transition: 0.4s;
495
+ transition: 0.4s;
477
496
  }
478
497
 
479
- .AccentBar .tabBar {
480
- background: white;
481
- text-align: left;
482
- border: 0px;
483
- padding: 10px 0;
484
- }
485
-
486
- .AccentBar .tab {
487
- font-size: 14px;
488
- font-weight: bold;
489
- color: #404040;
490
- text-align: left;
491
- border: 0px;
492
- height: 30px;
493
- padding: 2px 5px 2px 5px;
494
- margin: 2px;
495
- border-bottom: 4px solid #d0d0d0;
498
+ .EquationEditorModal .slider:before {
499
+ position: absolute;
500
+ content: "";
501
+ height: 14px;
502
+ width: 14px;
503
+ left: 4px;
504
+ bottom: 4px;
505
+ background-color: white;
506
+ -webkit-transition: 0.4s;
507
+ transition: 0.4s;
496
508
  }
497
509
 
498
- .AccentBar .tab:hover {
499
- cursor: pointer;
510
+ .EquationEditorModal input:checked + .slider {
511
+ background-color: #663676;
500
512
  }
501
513
 
502
- .AccentBar .tab-selected {
503
- font-size: 14px;
504
- font-weight: bold;
505
- color: #404040;
506
- text-align: left;
507
- border: 0px;
508
- height: 30px;
509
- padding: 2px 5px 2px 5px;
510
- margin: 2px;
511
- border-bottom: 4px solid #663676;
514
+ .EquationEditorModal input:focus + .slider {
515
+ box-shadow: 0 0 1px #2196f3;
512
516
  }
513
517
 
514
- .AccentBar .section-label {
515
- grid-column: 1/-1;
516
- font-size: 13px;
517
- font-weight: bold;
518
- color: #663676;
519
- margin-top: 8px;
520
- margin-left: 8px;
521
- margin-bottom: 4px;
518
+ .EquationEditorModal input:checked + .slider:before {
519
+ -webkit-transform: translateX(13px);
520
+ -ms-transform: translateX(13px);
521
+ transform: translateX(13px);
522
522
  }
523
523
 
524
- .AccentBar .replace-section {
525
- min-height: 70px;
524
+ /* Rounded sliders */
525
+ .EquationEditorModal .slider.round {
526
+ border-radius: 18px;
526
527
  }
527
528
 
528
- .AccentBar .tabArea {
529
- animation: 0.4s fadeIn1;
530
- animation-fill-mode: forwards;
529
+ .EquationEditorModal .slider.round:before {
530
+ border-radius: 50%;
531
531
  }
532
532
  .EquationEditor {
533
533
  height: auto;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzish/math-rich-input",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "React component for user to enter rich text with embedded math equations.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -70,6 +70,7 @@ export default class MathRichInput extends React.Component {
70
70
  },
71
71
  keyPressed: "",
72
72
  };
73
+ this.value = "";
73
74
 
74
75
  // this.handleInput = this.handleInput.bind(this);
75
76
  // this.handleKeyDown = this.handleKeyDown.bind(this);
@@ -213,10 +214,15 @@ export default class MathRichInput extends React.Component {
213
214
  this.undoHistory.push({ value, mimeType, rangeParams });
214
215
  if (this.undoHistory.length > MAX_HISTORY_LENGTH) this.undoHistory.shift();
215
216
 
217
+ this.value = value;
216
218
  // Call the parent handler to apply the changes
217
219
  this.onChangeCallback({ value, mimeType }, { isExpertMode, selectedTab });
218
220
  };
219
221
 
222
+ getValue = () => {
223
+ return this.value;
224
+ };
225
+
220
226
  initialiseHistory = () => {
221
227
  if (this.initialHistoryState == null)
222
228
  this.initialHistoryState = {
@@ -1187,6 +1193,8 @@ export default class MathRichInput extends React.Component {
1187
1193
  };
1188
1194
 
1189
1195
  componentDidMount() {
1196
+ const onRef = this.props.onRef;
1197
+ onRef && onRef(this);
1190
1198
  try {
1191
1199
  setupKatex();
1192
1200
 
@@ -1198,6 +1206,8 @@ export default class MathRichInput extends React.Component {
1198
1206
  }
1199
1207
 
1200
1208
  componentWillUnmount() {
1209
+ const onRef = this.props.onRef;
1210
+ onRef && onRef(undefined);
1201
1211
  try {
1202
1212
  this.editableDiv.removeEventListener("keydown", this.handleKeyDown);
1203
1213
  this.editableDiv.removeEventListener("keyup", this.handleKeyUp);