easy-richtextarea 4.0.22 → 4.0.25

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.
@@ -26,14 +26,12 @@ import { CUT_EVENT_TYPE,
26
26
  SELECTIONCHANGE_EVENT_TYPE } from "./eventTypes";
27
27
 
28
28
  export default class RichTextarea extends Element {
29
- constructor(selector, focused, readOnly, undoBuffer, previousContent, previousSelection) {
29
+ constructor(selector, focused, readOnly, undoBuffer) {
30
30
  super(selector);
31
31
 
32
32
  this.focused = focused;
33
33
  this.readOnly = readOnly;
34
34
  this.undoBuffer = undoBuffer;
35
- this.previousContent = previousContent;
36
- this.previousSelection = previousSelection;
37
35
  }
38
36
 
39
37
  isFocused() {
@@ -48,14 +46,6 @@ export default class RichTextarea extends Element {
48
46
  return this.undoBuffer;
49
47
  }
50
48
 
51
- getPreviousContent() {
52
- return this.prevousContent;
53
- }
54
-
55
- getPreviousSelection() {
56
- return this.previousSelection;
57
- }
58
-
59
49
  setFocused(focused) {
60
50
  this.focused = focused;
61
51
  }
@@ -64,17 +54,10 @@ export default class RichTextarea extends Element {
64
54
  this.readOnly = readOnly;
65
55
  }
66
56
 
67
- setPreviousContent(previousContent) {
68
- this.previousContent = previousContent;
69
- }
70
-
71
- setPreviousSelection(previousSelection) {
72
- this.previousSelection = previousSelection;
73
- }
74
-
75
57
  intermediateHandler = (event, element, undoable = true, eventType = CHANGE_EVENT_TYPE, selectionChanged = this.hasSelectionChanged()) => {
76
58
  if (this.readOnly) {
77
- const content = this.previousContent; ///
59
+ const previousContent = this.getPreviousContent(),
60
+ content = previousContent; ///
78
61
 
79
62
  this.setContent(content);
80
63
  }
@@ -90,15 +73,19 @@ export default class RichTextarea extends Element {
90
73
 
91
74
  if (undoable) {
92
75
  if (contentChanged) {
93
- const operations = generateOperations(this.previousContent, content);
76
+ const previousContent = this.getPreviousContent(),
77
+ operations = generateOperations(previousContent, content);
94
78
 
95
79
  this.undoBuffer.addOperations(operations);
96
80
  }
97
81
  }
98
82
 
99
- this.previousContent = content; ///
83
+ const previousContent = content, ///
84
+ previousSelection = selection; ///
100
85
 
101
- this.previousSelection = selection; ///
86
+ this.setPreviousContent(previousContent);
87
+
88
+ this.setPreviousSelection(previousSelection);
102
89
  }
103
90
 
104
91
  selectChangeHandler = (event, element) => {
@@ -282,7 +269,8 @@ export default class RichTextarea extends Element {
282
269
 
283
270
  hasContentChanged() {
284
271
  const content = this.getContent(),
285
- contentPreviousContent = (content === this.previousContent),
272
+ previousContent = this.getPreviousContent(),
273
+ contentPreviousContent = (content === previousContent),
286
274
  contentChanged = !contentPreviousContent;
287
275
 
288
276
  return contentChanged;
@@ -290,7 +278,8 @@ export default class RichTextarea extends Element {
290
278
 
291
279
  hasSelectionChanged() {
292
280
  const selection = this.getSelection(),
293
- selectionPreviousSelection = selection.isEqualTo(this.previousSelection),
281
+ previousSelection = this.getPreviousSelection(),
282
+ selectionPreviousSelection = selection.isEqualTo(previousSelection),
294
283
  selectionChanged = !selectionPreviousSelection; ///
295
284
 
296
285
  return selectionChanged;
@@ -305,7 +294,9 @@ export default class RichTextarea extends Element {
305
294
  });
306
295
 
307
296
  if (setPreviousContent) {
308
- this.previousContent = content; ///
297
+ const previousContent = content; ///
298
+
299
+ this.setPreviousContent(previousContent);
309
300
  }
310
301
  }
311
302
 
@@ -319,7 +310,9 @@ export default class RichTextarea extends Element {
319
310
  domElement.setSelectionRange(selectionStart, selectionEnd);
320
311
 
321
312
  if (setPreviousSelection) {
322
- this.previousSelection = selection; ///
313
+ const previousSelection = selection; ///
314
+
315
+ this.setPreviousSelection(previousSelection);
323
316
  }
324
317
  }
325
318
 
@@ -523,6 +516,30 @@ export default class RichTextarea extends Element {
523
516
  this.removeEventListener(eventType, handler, element);
524
517
  }
525
518
 
519
+ getPreviousContent() {
520
+ const { previousContent } = this.getState();
521
+
522
+ return previousContent;
523
+ }
524
+
525
+ getPreviousSelection() {
526
+ const { previousSelection } = this.getState();
527
+
528
+ return previousSelection;
529
+ }
530
+
531
+ setPreviousContent(previousContent) {
532
+ this.updateState({
533
+ previousContent
534
+ });
535
+ }
536
+
537
+ setPreviousSelection(previousSelection) {
538
+ this.updateState({
539
+ previousSelection
540
+ });
541
+ }
542
+
526
543
  didMount() {
527
544
  const { onFind, onBlur, onFocus, onChange, onScroll } = this.properties,
528
545
  findHandler = onFind, ///
@@ -531,12 +548,7 @@ export default class RichTextarea extends Element {
531
548
  changeHandler = onChange, ///
532
549
  scrollHandler = onScroll; ///
533
550
 
534
- const content = this.getContent(),
535
- selection = this.getSelection();
536
-
537
- this.previousContent = content; ///
538
-
539
- this.previousSelection = selection; ///
551
+ this.updateInitialState();
540
552
 
541
553
  findHandler && this.onFind(findHandler, this);
542
554
 
@@ -594,6 +606,31 @@ export default class RichTextarea extends Element {
594
606
  }
595
607
  }
596
608
 
609
+ updateInitialState() {
610
+ const content = this.getContent(),
611
+ selection = this.getSelection(),
612
+ previousContent = content, ///
613
+ previousSelection = selection; ///
614
+
615
+ this.setPreviousContent(previousContent);
616
+
617
+ this.setPreviousSelection(previousSelection);
618
+ }
619
+
620
+ setInitialState() {
621
+ const previousContent = null,
622
+ previousSelection = null;
623
+
624
+ this.setState({
625
+ previousContent,
626
+ previousSelection
627
+ });
628
+ }
629
+
630
+ initialise() {
631
+ this.setInitialState();
632
+ }
633
+
597
634
  static tagName = "textarea";
598
635
 
599
636
  static ignoredProperties = [
@@ -612,9 +649,7 @@ export default class RichTextarea extends Element {
612
649
  const focused = false,
613
650
  readOnly = false,
614
651
  undoBuffer = UndoBuffer.fromNothing(),
615
- previousContent = null,
616
- previousSelection = null,
617
- richTextarea = Element.fromClass(Class, properties, focused, readOnly, undoBuffer, previousContent, previousSelection, ...remainingArguments);
652
+ richTextarea = Element.fromClass(Class, properties, focused, readOnly, undoBuffer, ...remainingArguments);
618
653
 
619
654
  return richTextarea;
620
655
  }
package/src/selection.js CHANGED
@@ -22,6 +22,12 @@ export default class Selection {
22
22
  return empty;
23
23
  }
24
24
 
25
+ getLength() {
26
+ const length = (this.endPosition - this.startPosition);
27
+
28
+ return length;
29
+ }
30
+
25
31
  isEqualTo(selection) {
26
32
  let equalTo = false;
27
33