@zzish/math-rich-input 0.1.27 → 0.1.29

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.
@@ -78,136 +78,6 @@
78
78
  padding: 2px;
79
79
  margin: 0px 2px;
80
80
  }
81
- /* Note that the top left position of the toolbar is set programatically in componentDidMount */
82
-
83
- .Toolbar {
84
- position: absolute;
85
- z-index: 1;
86
- display: flex;
87
- height: 42px;
88
- background-color: white;
89
- border: 1px solid #d0d0d0;
90
- border-radius: 5px;
91
- box-shadow: 1px 1px 5px #a0a0a0;
92
- animation: 0.5s fadeIn1;
93
- animation-fill-mode: forwards;
94
- }
95
-
96
- @keyframes fadeIn1 {
97
- 0% {
98
- opacity: 0;
99
- }
100
- 100% {
101
- opacity: 1;
102
- }
103
- }
104
-
105
- .Toolbar-button {
106
- font-family: sans-serif;
107
- font-size: 16px;
108
- width: 40px;
109
- height: 36px;
110
- background-color: white;
111
- border-radius: 5px;
112
- border: 0px;
113
- padding: 1px;
114
- margin: 2px;
115
- }
116
-
117
- .Toolbar-button:hover {
118
- color: white;
119
- background: #663676;
120
- cursor: pointer;
121
- }
122
-
123
- .Toolbar-button:active {
124
- background: #808080;
125
- color: white;
126
- cursor: pointer;
127
- }
128
-
129
- .TB-narrow {
130
- width: 30px;
131
- }
132
-
133
- .TB-wide {
134
- width: 46px;
135
- }
136
-
137
- .TB-selected {
138
- background: #d0d0d0;
139
- color: black;
140
- cursor: pointer;
141
- animation: 0.2s TB-fadeIn;
142
- animation-fill-mode: forwards;
143
- }
144
-
145
- .TB-selected:hover {
146
- color: white;
147
- background: #663676;
148
- cursor: pointer;
149
- }
150
-
151
- @keyframes TB-fadeIn {
152
- 00% {
153
- background: white;
154
- }
155
- 100% {
156
- background: #d0d0d0;
157
- }
158
- }
159
-
160
- /* Tooltip text */
161
- .Toolbar-button .tooltiptext {
162
- font-weight: normal;
163
- visibility: hidden;
164
- width: 100px;
165
- background-color: #222;
166
- color: #fff;
167
- /*font-weight: bold;*/
168
- font-size: 12px;
169
- text-align: center;
170
- padding: 4px 10px;
171
- border-radius: 6px;
172
-
173
- /* Position the tooltip text - see examples below! */
174
- position: absolute;
175
- z-index: 2;
176
- top: -90%; /* Must leave a small gap between tooltip and button */
177
- left: 50px;
178
-
179
- /* transform: translate (50%,0%); */
180
- }
181
-
182
- /* Show the tooltip text when you mouse over the tooltip container */
183
- .Toolbar-button:hover .tooltiptext {
184
- animation: 0.8s fadeIn2;
185
- animation-fill-mode: forwards;
186
- visibility: visible;
187
- /* width: 100px; */
188
- /* top: -90%; */ /* Must leave a small gap between tooltip and button */
189
- /* left: 20%; */
190
- /* margin-left: -50px; */
191
- }
192
-
193
- @keyframes fadeIn2 {
194
- 00% {
195
- opacity: 0;
196
- }
197
- 70% {
198
- opacity: 0;
199
- }
200
- 100% {
201
- visibility: visible;
202
- opacity: 0.9;
203
- }
204
- }
205
-
206
- /* .tooltip {
207
- position: relative;
208
- display: inline-block;
209
- border-bottom: 1px dotted black; /* If you want dots under the hoverable text
210
- } */
211
81
  .EquationEditorModal-background {
212
82
  position: fixed;
213
83
  top: 0;
@@ -363,6 +233,136 @@
363
233
  .EquationEditorModal .slider.round:before {
364
234
  border-radius: 50%;
365
235
  }
236
+ /* Note that the top left position of the toolbar is set programatically in componentDidMount */
237
+
238
+ .Toolbar {
239
+ position: absolute;
240
+ z-index: 1;
241
+ display: flex;
242
+ height: 42px;
243
+ background-color: white;
244
+ border: 1px solid #d0d0d0;
245
+ border-radius: 5px;
246
+ box-shadow: 1px 1px 5px #a0a0a0;
247
+ animation: 0.5s fadeIn1;
248
+ animation-fill-mode: forwards;
249
+ }
250
+
251
+ @keyframes fadeIn1 {
252
+ 0% {
253
+ opacity: 0;
254
+ }
255
+ 100% {
256
+ opacity: 1;
257
+ }
258
+ }
259
+
260
+ .Toolbar-button {
261
+ font-family: sans-serif;
262
+ font-size: 16px;
263
+ width: 40px;
264
+ height: 36px;
265
+ background-color: white;
266
+ border-radius: 5px;
267
+ border: 0px;
268
+ padding: 1px;
269
+ margin: 2px;
270
+ }
271
+
272
+ .Toolbar-button:hover {
273
+ color: white;
274
+ background: #663676;
275
+ cursor: pointer;
276
+ }
277
+
278
+ .Toolbar-button:active {
279
+ background: #808080;
280
+ color: white;
281
+ cursor: pointer;
282
+ }
283
+
284
+ .TB-narrow {
285
+ width: 30px;
286
+ }
287
+
288
+ .TB-wide {
289
+ width: 46px;
290
+ }
291
+
292
+ .TB-selected {
293
+ background: #d0d0d0;
294
+ color: black;
295
+ cursor: pointer;
296
+ animation: 0.2s TB-fadeIn;
297
+ animation-fill-mode: forwards;
298
+ }
299
+
300
+ .TB-selected:hover {
301
+ color: white;
302
+ background: #663676;
303
+ cursor: pointer;
304
+ }
305
+
306
+ @keyframes TB-fadeIn {
307
+ 00% {
308
+ background: white;
309
+ }
310
+ 100% {
311
+ background: #d0d0d0;
312
+ }
313
+ }
314
+
315
+ /* Tooltip text */
316
+ .Toolbar-button .tooltiptext {
317
+ font-weight: normal;
318
+ visibility: hidden;
319
+ width: 100px;
320
+ background-color: #222;
321
+ color: #fff;
322
+ /*font-weight: bold;*/
323
+ font-size: 12px;
324
+ text-align: center;
325
+ padding: 4px 10px;
326
+ border-radius: 6px;
327
+
328
+ /* Position the tooltip text - see examples below! */
329
+ position: absolute;
330
+ z-index: 2;
331
+ top: -90%; /* Must leave a small gap between tooltip and button */
332
+ left: 50px;
333
+
334
+ /* transform: translate (50%,0%); */
335
+ }
336
+
337
+ /* Show the tooltip text when you mouse over the tooltip container */
338
+ .Toolbar-button:hover .tooltiptext {
339
+ animation: 0.8s fadeIn2;
340
+ animation-fill-mode: forwards;
341
+ visibility: visible;
342
+ /* width: 100px; */
343
+ /* top: -90%; */ /* Must leave a small gap between tooltip and button */
344
+ /* left: 20%; */
345
+ /* margin-left: -50px; */
346
+ }
347
+
348
+ @keyframes fadeIn2 {
349
+ 00% {
350
+ opacity: 0;
351
+ }
352
+ 70% {
353
+ opacity: 0;
354
+ }
355
+ 100% {
356
+ visibility: visible;
357
+ opacity: 0.9;
358
+ }
359
+ }
360
+
361
+ /* .tooltip {
362
+ position: relative;
363
+ display: inline-block;
364
+ border-bottom: 1px dotted black; /* If you want dots under the hoverable text
365
+ } */
366
366
  /* Note that the top left position of the accent bar is set programatically in componentDidMount */
367
367
 
368
368
  .AccentBar {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzish/math-rich-input",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "React component for user to enter rich text with embedded math equations.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -477,6 +477,7 @@ export default class MathRichInput extends React.Component {
477
477
  this.props.useExpertMode,
478
478
  this.props.selectedTab
479
479
  );
480
+ e.preventDefault()
480
481
  return;
481
482
  }
482
483
 
@@ -589,108 +590,25 @@ export default class MathRichInput extends React.Component {
589
590
  let index = rangeParams.startNodeIndex;
590
591
  let offset = rangeParams.startOffset;
591
592
 
592
- let new_globalOffset = rangeParams.startGlobalOffset - 1;
593
- let new_rangeParams = {
594
- startGlobalOffset: new_globalOffset,
595
- endGlobalOffset: new_globalOffset,
596
- };
597
- e.preventDefault();
598
- this._setRangeParams(new_rangeParams);
599
- return;
600
-
601
- // console.log("Old: "+index+"->"+offset)
602
-
603
- // The user shouldn't be in a katex node, but lets deal with it anyway
604
- let node = this._findNodeWithIndex(index);
605
- if (isKatexNode(node)) {
606
- console.warn("Cursor is inside katex node");
607
- let new_index = index - 1; // Jump out of the latex node
608
- let prev_node = this._findNodeWithIndex(index - 1);
609
- let new_offset = getNodeTextLength(prev_node);
610
-
611
- let new_rangeParams = {
612
- startNodeIndex: new_index,
613
- startOffset: new_offset,
614
- endNodeIndex: new_index,
615
- endOffset: new_offset,
616
- startGlobalOffset: new_globalOffset,
617
- endGlobalOffset: new_globalOffset,
618
- };
619
- this._setRangeParams(new_rangeParams);
620
- e.preventDefault();
621
- return;
622
- }
623
-
624
- if (offset > 2) return;
625
-
626
- let new_index = -1;
627
- let new_offset = -1;
628
-
629
- // Deal with case of inserted small space at start of <p> element or after katex node
630
- if (offset === 2) {
631
- new_index = index;
632
- if (this.nodeStartsWithSmallSpace(node)) {
633
- if (index > 0 && isKatexNode(this._findNodeWithIndex(index - 1)))
634
- new_offset = 1;
635
- else new_offset = 0;
636
- } else new_offset = 1;
637
- }
638
-
639
- if (offset === 1) {
640
- if (this.nodeStartsWithSmallSpace(node)) {
641
- if (index === 0) {
642
- e.preventDefault();
643
- return;
644
- }
645
- let prev_node = this._findNodeWithIndex(index - 1);
646
- if (index >= 2 && isKatexNode(prev_node)) new_index = index - 2;
647
- else new_index = index - 1;
648
-
649
- let new_node = this._findNodeWithIndex(new_index);
650
- new_offset = getNodeTextLength(new_node);
651
- } else {
652
- new_index = index;
653
- new_offset = 0;
654
- }
655
- }
656
-
657
- if (offset === 0) {
658
- let prev_node = this._findNodeWithIndex(index - 1);
659
- if (index >= 2 && isKatexNode(prev_node)) new_index = index - 2;
660
- else new_index = index - 1;
661
- let new_node = this._findNodeWithIndex(new_index);
662
- new_offset = getNodeTextLength(new_node);
663
- if (new_offset === 1) {
664
- if (this.nodeStartsWithSmallSpace(new_node)) {
665
- if (index > 0 && isKatexNode(this._findNodeWithIndex(index - 1)))
666
- new_offset = 1;
667
- else new_offset = 0;
593
+ console.log("handleKeyDownArrowLeft")
594
+ console.log(rangeParams)
595
+ let new_globalOffset = rangeParams.endGlobalOffset - 1;
596
+ let new_rangeParams = null
597
+ if (e.shiftKey && new_globalOffset > rangeParams.startGlobalOffset) {
598
+ new_rangeParams = {
599
+ startGlobalOffset: rangeParams.startGlobalOffset,
600
+ endGlobalOffset: new_globalOffset,
668
601
  }
669
- }
670
- }
671
-
672
- // Move cursor to start of field if in starting small space
673
- if (
674
- new_index === 0 &&
675
- new_offset === 1 &&
676
- this.inputStartsWithSmallSpace()
677
- ) {
678
- new_offset = 0;
679
- }
680
-
681
- if (new_index === -1 || new_offset === -1) return;
682
- else {
683
- let new_rangeParams = {
684
- startNodeIndex: new_index,
685
- startOffset: new_offset,
686
- endNodeIndex: new_index,
687
- endOffset: new_offset,
602
+ } else {
603
+ new_rangeParams = {
688
604
  startGlobalOffset: new_globalOffset,
689
605
  endGlobalOffset: new_globalOffset,
690
606
  };
691
- this._setRangeParams(new_rangeParams);
692
- e.preventDefault();
693
607
  }
608
+ console.log(new_rangeParams)
609
+ e.preventDefault();
610
+ this._setRangeParams(new_rangeParams);
611
+ return;
694
612
  };
695
613
 
696
614
  handleKeyDownArrowRight = (e) => {
@@ -699,103 +617,22 @@ export default class MathRichInput extends React.Component {
699
617
  let index = rangeParams.startNodeIndex;
700
618
  let offset = rangeParams.startOffset;
701
619
 
702
- let new_globalOffset = rangeParams.startGlobalOffset + 1;
703
- let new_rangeParams = {
704
- startGlobalOffset: new_globalOffset,
705
- endGlobalOffset: new_globalOffset,
706
- };
707
- e.preventDefault();
708
- this._setRangeParams(new_rangeParams);
709
- return;
710
-
711
- if (index < 0)
712
- // Empty input field
713
- return;
714
-
715
- let node = this._findNodeWithIndex(index);
716
- let length = getNodeTextLength(node);
717
-
718
- // The user shouldn't be in a katex node, but lets deal with it anyway
719
- if (isKatexNode(node)) {
720
- console.warn("Cursor is inside katex node");
721
- let new_index = index + 1; // Jump out of the latex node
722
- let new_offset = SMALL_SPACE_LENGTH; // As there will be a SMALL_SPACE at the start of the text node
723
-
724
- let new_rangeParams = {
725
- startNodeIndex: new_index,
726
- startOffset: new_offset,
727
- endNodeIndex: new_index,
728
- endOffset: new_offset,
620
+ let new_rangeParams = null
621
+ let new_globalOffset = rangeParams.endGlobalOffset + 1;
622
+ if (e.shiftKey && new_globalOffset > rangeParams.startGlobalOffset) {
623
+ new_rangeParams = {
624
+ startGlobalOffset: rangeParams.startGlobalOffset,
625
+ endGlobalOffset: new_globalOffset,
729
626
  };
730
- this._setRangeParams(new_rangeParams);
731
- e.preventDefault();
732
- return;
733
- }
734
-
735
- // Deal with case of inserted small space at start of <p> element
736
- if (offset === 0) {
737
- if (this.nodeStartsWithSmallSpace(node)) {
738
- // console.log("Offset = 0 and node starts with small space");
739
- let new_index = -1;
740
- let new_offset = -1;
741
-
742
- if (node.nodeValue.length > 1) {
743
- new_index = index;
744
- new_offset = SMALL_SPACE_LENGTH + 1;
745
- } else {
746
- new_index = index + 1;
747
- let next_node = this._findNodeWithIndex(new_index);
748
- if (next_node !== null) {
749
- if (isKatexNode(next_node)) {
750
- new_index = index + 2;
751
- new_offset = SMALL_SPACE_LENGTH;
752
- } else {
753
- new_index = index + 1;
754
- new_offset = 0;
755
- }
756
- } else {
757
- new_index = index;
758
- new_offset = offset;
759
- }
760
- }
761
- let new_rangeParams = {
762
- startNodeIndex: new_index,
763
- startOffset: new_offset,
764
- endNodeIndex: new_index,
765
- endOffset: new_offset,
766
- };
767
- this._setRangeParams(new_rangeParams);
768
-
769
- e.preventDefault();
770
- return;
771
- }
772
- }
773
-
774
- // If at the end of a text node
775
- if (
776
- offset === length ||
777
- (index === 0 && this.inputStartsWithSmallSpace())
778
- ) {
779
- let next_node = this._findNodeWithIndex(index + 1);
780
-
781
- // If there is no next node, then we can't move, so do the default action
782
- // If the next node is a normal node, do the default action
783
- if (next_node === null || !isKatexNode(next_node)) return;
784
-
785
- let new_index = index + 2; // Jump over the latex node
786
- let new_offset = SMALL_SPACE_LENGTH; // As there will be a SMALL_SPACE at the start of the text node
787
-
788
- let new_rangeParams = {
789
- startNodeIndex: new_index,
790
- startOffset: new_offset,
791
- endNodeIndex: new_index,
792
- endOffset: new_offset,
627
+ } else {
628
+ new_rangeParams = {
629
+ startGlobalOffset: new_globalOffset,
630
+ endGlobalOffset: new_globalOffset,
793
631
  };
794
- this._setRangeParams(new_rangeParams);
795
-
796
- e.preventDefault();
797
- return;
798
632
  }
633
+ e.preventDefault();
634
+ this._setRangeParams(new_rangeParams);
635
+ return;
799
636
  };
800
637
 
801
638
  editableDivIsPlainText = () => {
@@ -1306,13 +1143,14 @@ export default class MathRichInput extends React.Component {
1306
1143
 
1307
1144
  handleInput = (event) => {
1308
1145
  try {
1309
- // console.log("handleInput")
1146
+ console.log("handleInput")
1310
1147
  let raw_text = elementToMarkedRawText(
1311
1148
  this.editableDiv,
1312
1149
  null,
1313
1150
  0,
1314
1151
  this.enableHtml()
1315
1152
  );
1153
+ console.log("handleInput 2")
1316
1154
  const params = this._getRangeParams();
1317
1155
  if (params === null || params === undefined)
1318
1156
  console.error("Could not get range params from input field");
@@ -1351,6 +1189,7 @@ export default class MathRichInput extends React.Component {
1351
1189
 
1352
1190
  updateActiveButtons = () => {
1353
1191
  try {
1192
+ console.log("updateActiveButtons")
1354
1193
  let rangeParams = this._getRangeParams();
1355
1194
  if (rangeParams === null || rangeParams === undefined) {
1356
1195
  console.warn(
@@ -1659,6 +1498,8 @@ export default class MathRichInput extends React.Component {
1659
1498
  let start_pos = this.markedRawText.indexOf(MARK);
1660
1499
  let end_pos = this.markedRawText.indexOf(MARK, start_pos + MARK.length);
1661
1500
  let oldRangeParams = this.getOldRangeParams();
1501
+ console.log("Old range params")
1502
+ console.log(oldRangeParams)
1662
1503
 
1663
1504
  // Handle case of empty string returned
1664
1505
  if (latex === "") {
@@ -2114,14 +1955,15 @@ export default class MathRichInput extends React.Component {
2114
1955
  offset,
2115
1956
  this.enableHtml()
2116
1957
  );
1958
+
1959
+ console.log("Raw text before line insert")
1960
+ console.log(raw_text)
1961
+ console.log("Range params before line insert")
1962
+ console.log(rangeParams)
1963
+
2117
1964
  let new_raw_text = null;
2118
1965
  let new_rangeParams = { ...rangeParams };
2119
1966
 
2120
- if (new_rangeParams.startGlobalOffset) {
2121
- new_rangeParams.startGlobalOffset++;
2122
- new_rangeParams.endGlobalOffset++;
2123
- }
2124
-
2125
1967
  if (this.enableHtml()) {
2126
1968
  new_raw_text = removeMarks(
2127
1969
  insertCharacterBeforeMarks(raw_text, "</p><p>")
@@ -2133,6 +1975,11 @@ export default class MathRichInput extends React.Component {
2133
1975
  new_rangeParams.startOffset = 0;
2134
1976
  new_rangeParams.endNodeIndex = rangeParams.endNodeIndex + 1;
2135
1977
  new_rangeParams.endOffset = 0;
1978
+ if (new_rangeParams.startGlobalOffset) {
1979
+ new_rangeParams.startGlobalOffset++;
1980
+ new_rangeParams.endGlobalOffset++;
1981
+ }
1982
+
2136
1983
  } else {
2137
1984
  new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, "\n"));
2138
1985
  new_rangeParams.startOffset++;
@@ -2144,6 +1991,12 @@ export default class MathRichInput extends React.Component {
2144
1991
  this.props.mimeType,
2145
1992
  this.enableHtml()
2146
1993
  );
1994
+
1995
+ console.log("New raw text after line insert")
1996
+ console.log(new_raw_text)
1997
+ console.log("New range params after line insert")
1998
+ console.log(new_rangeParams)
1999
+
2147
2000
 
2148
2001
  this.applyChangesToComponent(
2149
2002
  new_raw_text,