11
12
'use strict';
13
14
-var PooledClass = require('PooledClass');
15
-
14
var getTextContentAccessor = require('getTextContentAccessor');
15
16
/**
19
- * This helper class stores information about text content of a target node,
17
+ * This helper object stores information about text content of a target node,
18
* allowing comparison of content before and after a given event.
19
*
20
* Identify the node where selection currently begins, then observe
21
* both its text content and its current position in the DOM. Since the
22
* browser may natively replace the target node during composition, we can
23
* use its position to find its replacement.
24
+ *
25
*
27
- * @param {DOMEventTarget} root
26
*/
29
-function FallbackCompositionState(root) {
30
- this._root = root;
31
- this._startText = this.getText();
32
- this._fallbackText = null;
33
-}
27
+var compositionState = {
28
+ _root: null,
29
+ _startText: null,
30
+ _fallbackText: null,
31
+};
32
35
-Object.assign(FallbackCompositionState.prototype, {
36
- destructor: function() {
37
- this._root = null;
38
- this._startText = null;
39
- this._fallbackText = null;
33
+var FallbackCompositionState = {
34
+ initialize(nativeEventTarget) {
35
+ compositionState._root = nativeEventTarget;
36
+ compositionState._startText = FallbackCompositionState.getText();
37
+ return true;
38
},
41
-
42
- /**
43
- * Get current text of input.
44
- *
45
- * @return {string}
46
- */
47
- getText: function() {
48
- if ('value' in this._root) {
49
- return this._root.value;
50
- }
51
- return this._root[getTextContentAccessor()];
39
+ reset() {
40
+ compositionState._root = null;
41
+ compositionState._startText = null;
42
+ compositionState._fallbackText = null;
43
},
53
-
54
- /**
55
- * Determine the differing substring between the initially stored
56
- * text content and the current content.
57
- *
58
- * @return {string}
59
- */
60
- getData: function() {
61
- if (this._fallbackText) {
62
- return this._fallbackText;
44
+ getData() {
45
+ if (compositionState._fallbackText) {
46
+ return compositionState._fallbackText;
47
}
48
49
var start;
66
- var startValue = this._startText;
50
+ var startValue = compositionState._startText;
51
var startLength = startValue.length;
52
var end;
69
- var endValue = this.getText();
53
+ var endValue = FallbackCompositionState.getText();
54
var endLength = endValue.length;
55
56
for (start = 0; start < startLength; start++) {
67
}
68
69
var sliceTail = end > 1 ? 1 - end : undefined;
86
- this._fallbackText = endValue.slice(start, sliceTail);
87
- return this._fallbackText;
70
+ compositionState._fallbackText = endValue.slice(start, sliceTail);
71
+ return compositionState._fallbackText;
72
},
89
-});
90
-
91
-PooledClass.addPoolingTo(FallbackCompositionState);
73
+ getText() {
74
+ if ('value' in compositionState._root) {
75
+ return compositionState._root.value;
76
+ }
77
+ return compositionState._root[getTextContentAccessor()];
78
+ },
79
+};
80
81
module.exports = FallbackCompositionState;