@etsoo/shared 1.2.51 → 1.2.54
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/.github/workflows/main.yml +6 -5
- package/README.md +1 -1
- package/lib/cjs/ActionResult.d.ts +1 -1
- package/lib/cjs/ActionResult.js +3 -3
- package/lib/cjs/ArrayUtils.d.ts +1 -1
- package/lib/cjs/ArrayUtils.js +4 -4
- package/lib/cjs/ColorUtils.d.ts +1 -1
- package/lib/cjs/ColorUtils.js +2 -2
- package/lib/cjs/DataTypes.d.ts +6 -6
- package/lib/cjs/DataTypes.js +50 -51
- package/lib/cjs/DateUtils.d.ts +1 -1
- package/lib/cjs/DateUtils.js +27 -28
- package/lib/cjs/DomUtils.d.ts +3 -3
- package/lib/cjs/DomUtils.js +64 -73
- package/lib/cjs/ExtendUtils.d.ts +1 -1
- package/lib/cjs/ExtendUtils.js +6 -6
- package/lib/cjs/IActionResult.d.ts +15 -2
- package/lib/cjs/NumberUtils.d.ts +1 -1
- package/lib/cjs/NumberUtils.js +9 -9
- package/lib/cjs/StorageUtils.js +2 -2
- package/lib/cjs/Utils.d.ts +4 -4
- package/lib/cjs/Utils.js +58 -62
- package/lib/cjs/index.d.ts +22 -22
- package/lib/cjs/storage/WindowStorage.d.ts +1 -1
- package/lib/cjs/types/ContentDisposition.d.ts +2 -2
- package/lib/cjs/types/ContentDisposition.js +11 -13
- package/lib/cjs/types/EColor.js +5 -7
- package/lib/cjs/types/EHistory.d.ts +3 -3
- package/lib/cjs/types/EHistory.js +4 -4
- package/lib/cjs/types/ErrorData.d.ts +1 -1
- package/lib/cjs/types/EventClass.js +1 -1
- package/lib/mjs/ActionResult.d.ts +1 -1
- package/lib/mjs/ActionResult.js +3 -3
- package/lib/mjs/ArrayUtils.d.ts +1 -1
- package/lib/mjs/ArrayUtils.js +5 -5
- package/lib/mjs/ColorUtils.d.ts +1 -1
- package/lib/mjs/ColorUtils.js +3 -3
- package/lib/mjs/DataTypes.d.ts +6 -6
- package/lib/mjs/DataTypes.js +50 -51
- package/lib/mjs/DateUtils.d.ts +1 -1
- package/lib/mjs/DateUtils.js +27 -28
- package/lib/mjs/DomUtils.d.ts +3 -3
- package/lib/mjs/DomUtils.js +67 -76
- package/lib/mjs/ExtendUtils.d.ts +1 -1
- package/lib/mjs/ExtendUtils.js +6 -6
- package/lib/mjs/IActionResult.d.ts +15 -2
- package/lib/mjs/NumberUtils.d.ts +1 -1
- package/lib/mjs/NumberUtils.js +9 -9
- package/lib/mjs/StorageUtils.js +4 -4
- package/lib/mjs/Utils.d.ts +4 -4
- package/lib/mjs/Utils.js +61 -65
- package/lib/mjs/index.d.ts +22 -22
- package/lib/mjs/index.js +22 -22
- package/lib/mjs/storage/WindowStorage.d.ts +1 -1
- package/lib/mjs/storage/WindowStorage.js +2 -2
- package/lib/mjs/types/ContentDisposition.d.ts +2 -2
- package/lib/mjs/types/ContentDisposition.js +12 -14
- package/lib/mjs/types/EColor.js +5 -7
- package/lib/mjs/types/EHistory.d.ts +3 -3
- package/lib/mjs/types/EHistory.js +5 -5
- package/lib/mjs/types/ErrorData.d.ts +1 -1
- package/lib/mjs/types/EventClass.js +1 -1
- package/package.json +61 -63
- package/src/ActionResult.ts +23 -23
- package/src/ArrayUtils.ts +164 -172
- package/src/ColorUtils.ts +80 -82
- package/src/DataTypes.ts +745 -754
- package/src/DateUtils.ts +266 -268
- package/src/DomUtils.ts +806 -831
- package/src/ExtendUtils.ts +191 -191
- package/src/IActionResult.ts +55 -40
- package/src/Keyboard.ts +258 -258
- package/src/NumberUtils.ts +135 -135
- package/src/StorageUtils.ts +117 -117
- package/src/Utils.ts +908 -930
- package/src/index.ts +22 -22
- package/src/node/Storage.ts +53 -53
- package/src/storage/IStorage.ts +62 -62
- package/src/storage/WindowStorage.ts +140 -140
- package/src/types/ContentDisposition.ts +59 -63
- package/src/types/DataError.ts +15 -15
- package/src/types/DelayedExecutorType.ts +15 -15
- package/src/types/EColor.ts +241 -248
- package/src/types/EHistory.ts +151 -151
- package/src/types/ErrorData.ts +11 -11
- package/src/types/EventClass.ts +220 -220
- package/src/types/FormData.ts +25 -25
- package/src/types/ParsedPath.ts +5 -5
- package/tsconfig.cjs.json +16 -16
- package/tsconfig.json +16 -16
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -29
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
package/src/types/EHistory.ts
CHANGED
|
@@ -1,185 +1,185 @@
|
|
|
1
|
-
import { EventBase, EventClass } from
|
|
1
|
+
import { EventBase, EventClass } from "./EventClass";
|
|
2
2
|
|
|
3
3
|
interface EHistoryEventData {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Current index
|
|
6
|
+
*/
|
|
7
|
+
index: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
interface EHistoryNavigateEventData extends EHistoryEventData {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Delta
|
|
13
|
+
*/
|
|
14
|
+
delta: number;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
type EHistoryEventDef = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
clear: EHistoryEventData;
|
|
19
|
+
navigate: EHistoryNavigateEventData;
|
|
20
|
+
push: EHistoryEventData;
|
|
21
|
+
replace: EHistoryEventData;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
type EHistoryEventType = Exclude<keyof EHistoryEventDef,
|
|
24
|
+
type EHistoryEventType = Exclude<keyof EHistoryEventDef, "navigate">;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* ETSOO Extended history event
|
|
28
28
|
*/
|
|
29
29
|
export class EHistoryEvent extends EventBase<
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
EHistoryEventType,
|
|
31
|
+
EHistoryEventData
|
|
32
32
|
> {}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* ETSOO Extended history navigate event
|
|
36
36
|
*/
|
|
37
37
|
export class EHistoryNavigateEvent extends EventBase<
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
"navigate",
|
|
39
|
+
EHistoryNavigateEventData
|
|
40
40
|
> {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
constructor(target: {}, data: EHistoryNavigateEventData) {
|
|
42
|
+
super(target, "navigate", data);
|
|
43
|
+
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* ETSOO Extended abstract history class
|
|
48
48
|
*/
|
|
49
49
|
export abstract class EHistory<T> extends EventClass<EHistoryEventDef> {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
50
|
+
// Index
|
|
51
|
+
private _index: number = -1;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* States
|
|
55
|
+
*/
|
|
56
|
+
readonly states: T[] = [];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* States length
|
|
60
|
+
*/
|
|
61
|
+
get length() {
|
|
62
|
+
return this.states.length;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get current state index
|
|
67
|
+
*/
|
|
68
|
+
get index() {
|
|
69
|
+
return this._index;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get current state
|
|
74
|
+
*/
|
|
75
|
+
get state() {
|
|
76
|
+
if (this._index === -1) return undefined;
|
|
77
|
+
return this.states[this._index];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Constructor
|
|
82
|
+
* @param maxDepth Max depth of the history
|
|
83
|
+
*/
|
|
84
|
+
constructor(public readonly maxDepth: number = 20) {
|
|
85
|
+
super();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Back to the previous state
|
|
90
|
+
*/
|
|
91
|
+
back() {
|
|
92
|
+
this.go(-1);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Clear all states but keep event listeners
|
|
97
|
+
*/
|
|
98
|
+
clear() {
|
|
99
|
+
// https://stackoverflow.com/questions/1232040/how-do-i-empty-an-array-in-javascript
|
|
100
|
+
this.states.length = 0;
|
|
101
|
+
this._index = -1;
|
|
102
|
+
this.trigger(this.createEvent("clear", this._index));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Create event
|
|
107
|
+
* @param type Type
|
|
108
|
+
* @param index Current index
|
|
109
|
+
*/
|
|
110
|
+
protected createEvent<T extends EHistoryEventType>(type: T, index: number) {
|
|
111
|
+
return new EHistoryEvent(this, type, { index });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
protected createNavigateEvent(index: number, delta: number) {
|
|
115
|
+
return new EHistoryNavigateEvent(this, { index, delta });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Forward to the next state
|
|
120
|
+
*/
|
|
121
|
+
forward() {
|
|
122
|
+
this.go(1);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get [undo, redo] status
|
|
127
|
+
*/
|
|
128
|
+
getStatus(): [boolean, boolean] {
|
|
129
|
+
if (this.length < 2) return [false, false];
|
|
130
|
+
if (this._index <= 0) return [false, true];
|
|
131
|
+
if (this._index + 1 >= this.length) return [true, false];
|
|
132
|
+
return [true, true];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Go to the specific state
|
|
137
|
+
* @param delta A negative value moves backwards, a positive value moves forwards
|
|
138
|
+
*/
|
|
139
|
+
go(delta: number) {
|
|
140
|
+
// No data
|
|
141
|
+
if (this._index === -1) return undefined;
|
|
142
|
+
|
|
143
|
+
// New index
|
|
144
|
+
const newIndex = this._index + delta;
|
|
145
|
+
|
|
146
|
+
// Not in the range
|
|
147
|
+
if (newIndex < 0 || newIndex >= this.length) return undefined;
|
|
148
|
+
|
|
149
|
+
// Update the index
|
|
150
|
+
this._index = newIndex;
|
|
151
|
+
|
|
152
|
+
// Trigger event
|
|
153
|
+
this.trigger(this.createNavigateEvent(newIndex, delta));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Adds an entry to the history stack
|
|
158
|
+
* @param state State
|
|
159
|
+
*/
|
|
160
|
+
pushState(state: T) {
|
|
161
|
+
if (this._index >= 0) {
|
|
162
|
+
// Remove states after the index
|
|
163
|
+
this.states.splice(this._index + 1);
|
|
154
164
|
}
|
|
155
165
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
* @param state State
|
|
159
|
-
*/
|
|
160
|
-
pushState(state: T) {
|
|
161
|
-
if (this._index >= 0) {
|
|
162
|
-
// Remove states after the index
|
|
163
|
-
this.states.splice(this._index + 1);
|
|
164
|
-
}
|
|
166
|
+
this.states.push(state);
|
|
167
|
+
this._index++;
|
|
165
168
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (this.length > this.maxDepth) {
|
|
170
|
-
this.states.shift();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
this.trigger(this.createEvent('push', this._index));
|
|
169
|
+
if (this.length > this.maxDepth) {
|
|
170
|
+
this.states.shift();
|
|
174
171
|
}
|
|
175
172
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
173
|
+
this.trigger(this.createEvent("push", this._index));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Modifies the current history entry
|
|
178
|
+
* @param state State
|
|
179
|
+
*/
|
|
180
|
+
replaceState(state: T) {
|
|
181
|
+
if (this._index === -1) return;
|
|
182
|
+
this.states[this._index] = state;
|
|
183
|
+
this.trigger(this.createEvent("replace", this._index));
|
|
184
|
+
}
|
|
185
185
|
}
|
package/src/types/ErrorData.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export type ErrorType =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
| "error"
|
|
3
|
+
| "unhandledrejection"
|
|
4
|
+
| "consoleWarn"
|
|
5
|
+
| "consoleError";
|
|
6
6
|
|
|
7
7
|
export type ErrorData = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
type: ErrorType;
|
|
9
|
+
subType?: string;
|
|
10
|
+
message: string;
|
|
11
|
+
source?: string;
|
|
12
|
+
lineNo?: number;
|
|
13
|
+
colNo?: number;
|
|
14
|
+
stack?: string;
|
|
15
15
|
};
|