@expensify/react-native-live-markdown 0.1.70 → 0.1.72
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/lib/commonjs/MarkdownTextInput.web.js +23 -17
- package/lib/commonjs/MarkdownTextInput.web.js.map +1 -1
- package/lib/commonjs/web/InputHistory.js +50 -33
- package/lib/commonjs/web/InputHistory.js.map +1 -1
- package/lib/module/MarkdownTextInput.web.js +23 -17
- package/lib/module/MarkdownTextInput.web.js.map +1 -1
- package/lib/module/web/InputHistory.js +50 -33
- package/lib/module/web/InputHistory.js.map +1 -1
- package/lib/parser/react-native-live-markdown-parser.js +15 -15
- package/lib/typescript/src/MarkdownTextInput.web.d.ts.map +1 -1
- package/lib/typescript/src/web/InputHistory.d.ts +4 -3
- package/lib/typescript/src/web/InputHistory.d.ts.map +1 -1
- package/package.json +1 -1
- package/parser/react-native-live-markdown-parser.js +15 -15
- package/src/MarkdownTextInput.web.tsx +23 -18
- package/src/web/InputHistory.ts +55 -36
|
@@ -1,87 +1,104 @@
|
|
|
1
1
|
export default class InputHistory {
|
|
2
2
|
currentText = null;
|
|
3
3
|
timeout = null;
|
|
4
|
-
constructor(depth, debounceTime = 150) {
|
|
4
|
+
constructor(depth, debounceTime = 150, startingText = '') {
|
|
5
5
|
this.depth = depth;
|
|
6
|
-
this.
|
|
6
|
+
this.items = [{
|
|
7
|
+
text: startingText,
|
|
8
|
+
cursorPosition: startingText.length
|
|
9
|
+
}];
|
|
7
10
|
this.historyIndex = 0;
|
|
8
11
|
this.debounceTime = debounceTime;
|
|
9
12
|
}
|
|
10
13
|
getCurrentItem() {
|
|
11
|
-
return this.
|
|
14
|
+
return this.items[this.historyIndex] || null;
|
|
12
15
|
}
|
|
13
16
|
setHistory(newHistory) {
|
|
14
|
-
this.
|
|
17
|
+
this.items = newHistory.slice(newHistory.length - this.depth);
|
|
15
18
|
this.historyIndex = newHistory.length - 1;
|
|
16
19
|
}
|
|
17
20
|
setHistoryIndex(index) {
|
|
18
21
|
this.historyIndex = index;
|
|
19
22
|
}
|
|
20
23
|
clear() {
|
|
21
|
-
this.
|
|
24
|
+
this.items = [];
|
|
22
25
|
this.historyIndex = 0;
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
this.currentText = text;
|
|
27
|
+
throttledAdd(text, cursorPosition) {
|
|
26
28
|
if (this.timeout) {
|
|
27
29
|
clearTimeout(this.timeout);
|
|
28
30
|
}
|
|
31
|
+
if (this.currentText === null) {
|
|
32
|
+
this.timeout = null;
|
|
33
|
+
this.add(text, cursorPosition);
|
|
34
|
+
} else {
|
|
35
|
+
this.items[this.historyIndex] = {
|
|
36
|
+
text,
|
|
37
|
+
cursorPosition
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
this.currentText = text;
|
|
29
41
|
this.timeout = setTimeout(() => {
|
|
30
|
-
if (this.currentText == null) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
this.add(this.currentText, cursorPosition);
|
|
34
42
|
this.currentText = null;
|
|
35
43
|
}, this.debounceTime);
|
|
36
44
|
}
|
|
45
|
+
stopTimeout() {
|
|
46
|
+
if (this.timeout) {
|
|
47
|
+
clearTimeout(this.timeout);
|
|
48
|
+
this.timeout = null;
|
|
49
|
+
}
|
|
50
|
+
this.currentText = null;
|
|
51
|
+
}
|
|
37
52
|
add(text, cursorPosition) {
|
|
38
|
-
if (this.
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
this.historyIndex = this.history.length - 1;
|
|
53
|
+
if (this.items.length > 0) {
|
|
54
|
+
const currentItem = this.items[this.historyIndex];
|
|
55
|
+
if (currentItem && text === currentItem.text) {
|
|
42
56
|
return;
|
|
43
57
|
}
|
|
44
58
|
}
|
|
45
|
-
if (this.historyIndex < this.
|
|
46
|
-
this.
|
|
59
|
+
if (this.historyIndex < this.items.length - 1) {
|
|
60
|
+
this.items.splice(this.historyIndex + 1);
|
|
61
|
+
this.historyIndex = this.items.length - 1;
|
|
47
62
|
}
|
|
48
|
-
this.
|
|
63
|
+
this.items.push({
|
|
49
64
|
text,
|
|
50
65
|
cursorPosition
|
|
51
66
|
});
|
|
52
|
-
if (this.
|
|
53
|
-
this.
|
|
67
|
+
if (this.items.length > this.depth) {
|
|
68
|
+
this.items.shift();
|
|
69
|
+
} else {
|
|
70
|
+
this.historyIndex += 1;
|
|
54
71
|
}
|
|
55
|
-
this.historyIndex = this.history.length - 1;
|
|
56
72
|
}
|
|
57
73
|
undo() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.timeout = null;
|
|
61
|
-
return this.history[this.historyIndex] || null;
|
|
62
|
-
}
|
|
63
|
-
if (this.history.length === 0 || this.historyIndex - 1 < 0) {
|
|
74
|
+
this.stopTimeout();
|
|
75
|
+
if (this.items.length === 0 || this.historyIndex - 1 < 0) {
|
|
64
76
|
return null;
|
|
65
77
|
}
|
|
78
|
+
const currentHistoryItem = this.items[this.historyIndex];
|
|
79
|
+
const previousHistoryItem = this.items[this.historyIndex - 1];
|
|
80
|
+
const undoItem = previousHistoryItem ? {
|
|
81
|
+
text: previousHistoryItem.text,
|
|
82
|
+
cursorPosition: Math.min(((currentHistoryItem === null || currentHistoryItem === void 0 ? void 0 : currentHistoryItem.cursorPosition) ?? 0) - (((currentHistoryItem === null || currentHistoryItem === void 0 ? void 0 : currentHistoryItem.text) ?? '').length - ((previousHistoryItem === null || previousHistoryItem === void 0 ? void 0 : previousHistoryItem.text) ?? '').length), ((previousHistoryItem === null || previousHistoryItem === void 0 ? void 0 : previousHistoryItem.text) ?? '').length)
|
|
83
|
+
} : null;
|
|
66
84
|
if (this.historyIndex > 0) {
|
|
67
85
|
this.historyIndex -= 1;
|
|
68
86
|
}
|
|
69
|
-
return
|
|
87
|
+
return undoItem;
|
|
70
88
|
}
|
|
71
89
|
redo() {
|
|
72
90
|
if (this.currentText !== null && this.timeout) {
|
|
73
|
-
|
|
74
|
-
return this.history[this.history.length - 1] || null;
|
|
91
|
+
this.stopTimeout();
|
|
75
92
|
}
|
|
76
|
-
if (this.
|
|
93
|
+
if (this.items.length === 0 || this.historyIndex + 1 > this.items.length) {
|
|
77
94
|
return null;
|
|
78
95
|
}
|
|
79
|
-
if (this.historyIndex < this.
|
|
96
|
+
if (this.historyIndex < this.items.length - 1) {
|
|
80
97
|
this.historyIndex += 1;
|
|
81
98
|
} else {
|
|
82
99
|
return null;
|
|
83
100
|
}
|
|
84
|
-
return this.
|
|
101
|
+
return this.items[this.historyIndex] || null;
|
|
85
102
|
}
|
|
86
103
|
}
|
|
87
104
|
//# sourceMappingURL=InputHistory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["InputHistory","currentText","timeout","constructor","depth","debounceTime","
|
|
1
|
+
{"version":3,"names":["InputHistory","currentText","timeout","constructor","depth","debounceTime","startingText","items","text","cursorPosition","length","historyIndex","getCurrentItem","setHistory","newHistory","slice","setHistoryIndex","index","clear","throttledAdd","clearTimeout","add","setTimeout","stopTimeout","currentItem","splice","push","shift","undo","currentHistoryItem","previousHistoryItem","undoItem","Math","min","redo"],"sourceRoot":"../../../src","sources":["web/InputHistory.ts"],"mappings":"AAKA,eAAe,MAAMA,YAAY,CAAC;EAOhCC,WAAW,GAAkB,IAAI;EAEjCC,OAAO,GAA0B,IAAI;EAIrCC,WAAWA,CAACC,KAAa,EAAEC,YAAY,GAAG,GAAG,EAAEC,YAAY,GAAG,EAAE,EAAE;IAChE,IAAI,CAACF,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACG,KAAK,GAAG,CAAC;MAACC,IAAI,EAAEF,YAAY;MAAEG,cAAc,EAAEH,YAAY,CAACI;IAAM,CAAC,CAAC;IACxE,IAAI,CAACC,YAAY,GAAG,CAAC;IACrB,IAAI,CAACN,YAAY,GAAGA,YAAY;EAClC;EAEAO,cAAcA,CAAA,EAAuB;IACnC,OAAO,IAAI,CAACL,KAAK,CAAC,IAAI,CAACI,YAAY,CAAC,IAAI,IAAI;EAC9C;EAEAE,UA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