@reliverse/relinka 1.1.4 → 1.1.6
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/dist-npm/components/anykey/index.js +77 -57
- package/dist-npm/components/block/block.js +61 -48
- package/dist-npm/components/checkbox/index.js +211 -178
- package/dist-npm/components/confirm/confirm-main.js +122 -86
- package/dist-npm/components/confirm/confirm-three.js +27 -24
- package/dist-npm/components/confirm/index.js +45 -36
- package/dist-npm/components/core/Separator.js +17 -15
- package/dist-npm/components/core/create-prompt.js +124 -101
- package/dist-npm/components/core/errors.js +15 -19
- package/dist-npm/components/core/hook-engine.js +120 -91
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +6 -16
- package/dist-npm/components/core/lines.js +54 -45
- package/dist-npm/components/core/make-theme.js +30 -21
- package/dist-npm/components/core/position.js +23 -27
- package/dist-npm/components/core/promise-polyfill.js +14 -11
- package/dist-npm/components/core/screen-manager.js +74 -59
- package/dist-npm/components/core/theme.js +32 -22
- package/dist-npm/components/core/use-effect.js +15 -9
- package/dist-npm/components/core/use-keypress.js +23 -19
- package/dist-npm/components/core/use-memo.js +16 -10
- package/dist-npm/components/core/use-pagination.js +32 -33
- package/dist-npm/components/core/use-prefix.js +38 -40
- package/dist-npm/components/core/use-ref.js +5 -2
- package/dist-npm/components/core/use-state.js +23 -15
- package/dist-npm/components/core/useKeyPress.js +17 -14
- package/dist-npm/components/core/usePromptState.js +14 -8
- package/dist-npm/components/core/utils.js +16 -7
- package/dist-npm/components/date/date.js +204 -168
- package/dist-npm/components/editor/index.js +92 -71
- package/dist-npm/components/expand/index.js +124 -96
- package/dist-npm/components/figures/index.js +294 -283
- package/dist-npm/components/input/index.js +87 -61
- package/dist-npm/components/input/text-main.js +124 -86
- package/dist-npm/components/input/text.js +28 -24
- package/dist-npm/components/instance/basic.js +25 -17
- package/dist-npm/components/instance/browser.js +18 -14
- package/dist-npm/components/instance/reporter/basic.js +65 -46
- package/dist-npm/components/instance/reporter/browser.js +47 -44
- package/dist-npm/components/instance/reporter/fancy.js +96 -83
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +62 -52
- package/dist-npm/components/mono/monoTwo.js +49 -35
- package/dist-npm/components/multiselect/group-multiselect.js +71 -55
- package/dist-npm/components/multiselect/multi-select-two.js +130 -98
- package/dist-npm/components/multiselect/multi-select.js +49 -43
- package/dist-npm/components/multiselect/multiselect-main.js +146 -120
- package/dist-npm/components/multiselect/num-multi-select.js +130 -98
- package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
- package/dist-npm/components/next-steps/next-steps.js +25 -24
- package/dist-npm/components/number/index.js +112 -78
- package/dist-npm/components/number/number-main.js +2 -96
- package/dist-npm/components/password/index.js +73 -54
- package/dist-npm/components/password/password-main.js +2 -120
- package/dist-npm/components/password/password-three.js +30 -26
- package/dist-npm/components/progressbar/ProgressBar.js +64 -45
- package/dist-npm/components/progressbar/helper.js +40 -33
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +44 -29
- package/dist-npm/components/prompts/index.js +45 -45
- package/dist-npm/components/prompts/prompt.js +260 -211
- package/dist-npm/components/prompts/promptTwo.js +605 -561
- package/dist-npm/components/prompts/relinka.js +295 -237
- package/dist-npm/components/range/range.js +294 -247
- package/dist-npm/components/rawlist/index.js +107 -87
- package/dist-npm/components/results/results.js +37 -31
- package/dist-npm/components/search/index.js +193 -148
- package/dist-npm/components/select/index.js +186 -148
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +5 -125
- package/dist-npm/components/select/select-key.js +25 -24
- package/dist-npm/components/select/select-main.js +133 -109
- package/dist-npm/components/select/select-three.js +36 -32
- package/dist-npm/components/select/select-two.js +87 -95
- package/dist-npm/components/spinner/index.js +136 -107
- package/dist-npm/components/st-end/end.d.ts +1 -1
- package/dist-npm/components/st-end/end.js +26 -35
- package/dist-npm/components/st-end/start.d.ts +1 -1
- package/dist-npm/components/st-end/start.js +15 -30
- package/dist-npm/components/toggle/index.js +137 -113
- package/dist-npm/components/visual/animate/animate.js +10 -53
- package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
- package/dist-npm/mod.js +2 -1
- package/dist-npm/testing/index.js +83 -58
- package/dist-npm/types/general.d.ts +2 -1
- package/dist-npm/types/general.js +1 -0
- package/dist-npm/types/index.js +3 -2
- package/dist-npm/types/keypress.js +36 -35
- package/dist-npm/types/readline.js +1 -0
- package/dist-npm/types/relinka.js +1 -0
- package/dist-npm/types/utils.js +1 -0
- package/dist-npm/utils/box.js +137 -135
- package/dist-npm/utils/color.js +74 -65
- package/dist-npm/utils/colorize.js +156 -124
- package/dist-npm/utils/component.js +657 -532
- package/dist-npm/utils/constants.js +63 -64
- package/dist-npm/utils/core.js +3 -2
- package/dist-npm/utils/decoder.js +223 -244
- package/dist-npm/utils/error.js +9 -4
- package/dist-npm/utils/errors.js +4 -14
- package/dist-npm/utils/format.js +24 -19
- package/dist-npm/utils/keypress.js +414 -316
- package/dist-npm/utils/log.js +15 -11
- package/dist-npm/utils/mapping.js +52 -45
- package/dist-npm/utils/messages.js +183 -183
- package/dist-npm/utils/platforms.js +20 -16
- package/dist-npm/utils/prompt-tmp.js +286 -235
- package/dist-npm/utils/prompt-two.js +286 -235
- package/dist-npm/utils/readline.js +7 -5
- package/dist-npm/utils/skeleton.js +170 -130
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +58 -44
- package/dist-npm/utils/terminal.js +34 -23
- package/dist-npm/utils/tree.js +41 -30
- package/dist-npm/utils/types.js +1 -0
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +44 -36
- package/package.json +20 -28
|
@@ -1,109 +1,138 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
AsyncLocalStorage,
|
|
3
|
+
AsyncResource,
|
|
4
|
+
} from 'node:async_hooks';
|
|
5
|
+
import {
|
|
6
|
+
HookError,
|
|
7
|
+
ValidationError,
|
|
8
|
+
} from './errors.js';
|
|
9
|
+
|
|
10
|
+
const isFn = (a) => typeof a === 'function';
|
|
3
11
|
const hookStorage = new AsyncLocalStorage();
|
|
12
|
+
|
|
4
13
|
function createStore(rl) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const store = {
|
|
15
|
+
rl,
|
|
16
|
+
hooks: [],
|
|
17
|
+
hooksCleanup: [],
|
|
18
|
+
hooksEffect: [],
|
|
19
|
+
index: 0,
|
|
20
|
+
handleChange() {},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return store;
|
|
15
24
|
}
|
|
25
|
+
|
|
16
26
|
export function withHooks(rl, cb) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
const store = createStore(rl);
|
|
28
|
+
|
|
29
|
+
return hookStorage.run(store, () => {
|
|
30
|
+
function cycle(render) {
|
|
31
|
+
store.handleChange = () => {
|
|
32
|
+
store.index = 0;
|
|
33
|
+
render();
|
|
34
|
+
};
|
|
35
|
+
store.handleChange();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return cb(cycle);
|
|
39
|
+
});
|
|
28
40
|
}
|
|
41
|
+
|
|
29
42
|
function getStore() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
const store = hookStorage.getStore();
|
|
44
|
+
|
|
45
|
+
if (!store) {
|
|
46
|
+
throw new HookError('[Relinka] Hook functions can only be called from within a prompt');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return store;
|
|
37
50
|
}
|
|
51
|
+
|
|
38
52
|
export function readline() {
|
|
39
|
-
|
|
53
|
+
return getStore().rl;
|
|
40
54
|
}
|
|
55
|
+
|
|
41
56
|
export function withUpdates(fn) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
const wrapped = (...args) => {
|
|
58
|
+
const store = getStore();
|
|
59
|
+
let shouldUpdate = false;
|
|
60
|
+
const oldHandleChange = store.handleChange;
|
|
61
|
+
|
|
62
|
+
store.handleChange = () => {
|
|
63
|
+
shouldUpdate = true;
|
|
64
|
+
};
|
|
65
|
+
const returnValue = fn(...args);
|
|
66
|
+
|
|
67
|
+
if (shouldUpdate) {
|
|
68
|
+
oldHandleChange();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
store.handleChange = oldHandleChange;
|
|
72
|
+
return returnValue;
|
|
48
73
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
oldHandleChange();
|
|
52
|
-
}
|
|
53
|
-
store.handleChange = oldHandleChange;
|
|
54
|
-
return returnValue;
|
|
55
|
-
};
|
|
56
|
-
return AsyncResource.bind(wrapped);
|
|
74
|
+
|
|
75
|
+
return AsyncResource.bind(wrapped);
|
|
57
76
|
}
|
|
77
|
+
|
|
58
78
|
export function withPointer(cb) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
const store = getStore();
|
|
80
|
+
const {index} = store;
|
|
81
|
+
const pointer = {
|
|
82
|
+
get() {
|
|
83
|
+
return store.hooks[index];
|
|
84
|
+
},
|
|
85
|
+
set(value) {
|
|
86
|
+
store.hooks[index] = value;
|
|
87
|
+
},
|
|
88
|
+
initialized: index in store.hooks,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const returnValue = cb(pointer);
|
|
92
|
+
|
|
93
|
+
store.index++;
|
|
94
|
+
return returnValue;
|
|
73
95
|
}
|
|
96
|
+
|
|
74
97
|
export function handleChange() {
|
|
75
|
-
|
|
98
|
+
getStore().handleChange();
|
|
76
99
|
}
|
|
100
|
+
|
|
77
101
|
export const effectScheduler = {
|
|
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
|
-
|
|
102
|
+
queue(cb) {
|
|
103
|
+
const store = getStore();
|
|
104
|
+
const {index} = store;
|
|
105
|
+
|
|
106
|
+
store.hooksEffect.push(() => {
|
|
107
|
+
store.hooksCleanup[index]?.();
|
|
108
|
+
const cleanFn = cb(readline());
|
|
109
|
+
|
|
110
|
+
if (cleanFn != null && !isFn(cleanFn)) {
|
|
111
|
+
throw new ValidationError('useEffect return value must be a cleanup function or nothing.');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
store.hooksCleanup[index] = cleanFn;
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
run() {
|
|
118
|
+
const store = getStore();
|
|
119
|
+
|
|
120
|
+
withUpdates(() => {
|
|
121
|
+
for (const effect of store.hooksEffect) {
|
|
122
|
+
effect();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
store.hooksEffect.length = 0;
|
|
126
|
+
})();
|
|
127
|
+
},
|
|
128
|
+
clearAll() {
|
|
129
|
+
const store = getStore();
|
|
130
|
+
|
|
131
|
+
for (const cleanFn of store.hooksCleanup) {
|
|
132
|
+
cleanFn?.();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
store.hooksEffect.length = 0;
|
|
136
|
+
store.hooksCleanup.length = 0;
|
|
137
|
+
},
|
|
109
138
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
1
|
+
export * from './key.js';
|
|
2
|
+
export * from './errors.js';
|
|
3
|
+
export {usePrefix} from './use-prefix.js';
|
|
4
|
+
export {useState} from './use-state.js';
|
|
5
|
+
export {useEffect} from './use-effect.js';
|
|
6
|
+
export {useMemo} from './use-memo.js';
|
|
7
|
+
export {useRef} from './use-ref.js';
|
|
8
|
+
export {useKeypress} from './use-keypress.js';
|
|
9
|
+
export {makeTheme} from './make-theme.js';
|
|
10
|
+
export {usePagination} from './use-pagination.js';
|
|
11
|
+
export {createPrompt} from './create-prompt.js';
|
|
12
|
+
export {Separator} from './Separator.js';
|
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
export const isUpKey = (key) => (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
);
|
|
7
|
-
export const isDownKey = (key) => (
|
|
8
|
-
|
|
9
|
-
key.name === "down" ||
|
|
10
|
-
key.name === "j" ||
|
|
11
|
-
key.ctrl && key.name === "n"
|
|
12
|
-
);
|
|
13
|
-
export const isSpaceKey = (key) => key.name === "space";
|
|
14
|
-
export const isBackspaceKey = (key) => key.name === "backspace";
|
|
15
|
-
export const isNumberKey = (key) => "123456789".includes(key.name);
|
|
16
|
-
export const isEnterKey = (key) => key.name === "enter" || key.name === "return";
|
|
1
|
+
export const isUpKey = (key) => (key.name === 'up' || key.name === 'k' || key.ctrl && key.name === 'p');
|
|
2
|
+
export const isDownKey = (key) => (key.name === 'down' || key.name === 'j' || key.ctrl && key.name === 'n');
|
|
3
|
+
export const isSpaceKey = (key) => key.name === 'space';
|
|
4
|
+
export const isBackspaceKey = (key) => key.name === 'backspace';
|
|
5
|
+
export const isNumberKey = (key) => '123456789'.includes(key.name);
|
|
6
|
+
export const isEnterKey = (key) => key.name === 'enter' || key.name === 'return';
|
|
@@ -1,52 +1,61 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {breakLines} from './utils.js';
|
|
2
|
+
|
|
2
3
|
function split(content, width) {
|
|
3
|
-
|
|
4
|
+
return breakLines(content, width).split('\n');
|
|
4
5
|
}
|
|
6
|
+
|
|
5
7
|
function rotate(count, items) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const max = items.length;
|
|
9
|
+
const offset = (count % max + max) % max;
|
|
10
|
+
|
|
11
|
+
return [
|
|
12
|
+
...items.slice(offset),
|
|
13
|
+
...items.slice(0, offset),
|
|
14
|
+
];
|
|
9
15
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
|
|
17
|
+
export function lines({items, width, renderItem, active, position: requested, pageSize}) {
|
|
18
|
+
const layouts = items.map((item, index) => ({
|
|
19
|
+
item,
|
|
20
|
+
index,
|
|
21
|
+
isActive: index === active,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
const layoutsInPage = rotate(active - requested, layouts).slice(0, pageSize);
|
|
25
|
+
const renderItemAt = (index) => layoutsInPage[index] == null ? [] : split(renderItem(layoutsInPage[index]), width);
|
|
26
|
+
const pageBuffer = Array.from({
|
|
27
|
+
length: pageSize,
|
|
28
|
+
});
|
|
29
|
+
const activeItem = renderItemAt(requested).slice(0, pageSize);
|
|
30
|
+
const position = pageSize >= requested + activeItem.length ? requested : pageSize - activeItem.length;
|
|
31
|
+
|
|
32
|
+
pageBuffer.splice(position, activeItem.length, ...activeItem);
|
|
33
|
+
let bufferPointer = position + activeItem.length;
|
|
34
|
+
let layoutPointer = requested + 1;
|
|
35
|
+
|
|
36
|
+
while (bufferPointer < pageSize && layoutPointer < layoutsInPage.length) {
|
|
37
|
+
for (const line of renderItemAt(layoutPointer)) {
|
|
38
|
+
pageBuffer[bufferPointer++] = line;
|
|
39
|
+
if (bufferPointer >= pageSize) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
layoutPointer++;
|
|
37
45
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
|
|
47
|
+
bufferPointer = position - 1;
|
|
48
|
+
layoutPointer = requested - 1;
|
|
49
|
+
while (bufferPointer >= 0 && layoutPointer >= 0) {
|
|
50
|
+
for (const line of renderItemAt(layoutPointer).reverse()) {
|
|
51
|
+
pageBuffer[bufferPointer--] = line;
|
|
52
|
+
if (bufferPointer < 0) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
layoutPointer--;
|
|
48
58
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return pageBuffer.filter((line) => typeof line === "string");
|
|
59
|
+
|
|
60
|
+
return pageBuffer.filter((line) => typeof line === 'string');
|
|
52
61
|
}
|
|
@@ -1,28 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {defaultTheme} from './theme.js';
|
|
2
|
+
|
|
2
3
|
function isPlainObject(value) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
if (typeof value !== 'object' || value === null) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let proto = value;
|
|
9
|
+
|
|
10
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
11
|
+
proto = Object.getPrototypeOf(proto);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return Object.getPrototypeOf(value) === proto;
|
|
11
15
|
}
|
|
16
|
+
|
|
12
17
|
function deepMerge(...objects) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
for (const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
const output = {};
|
|
19
|
+
|
|
20
|
+
for (const obj of objects) {
|
|
21
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
22
|
+
const prevValue = output[key];
|
|
23
|
+
output[key] = isPlainObject(prevValue) && isPlainObject(value) ? deepMerge(prevValue, value) : value;
|
|
24
|
+
}
|
|
18
25
|
}
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
|
|
27
|
+
return output;
|
|
21
28
|
}
|
|
29
|
+
|
|
22
30
|
export function makeTheme(...themes) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
const themesToMerge = [
|
|
32
|
+
defaultTheme,
|
|
33
|
+
...themes.filter((theme) => theme != null),
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
return deepMerge(...themesToMerge);
|
|
28
37
|
}
|
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
export function finite({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return middle;
|
|
1
|
+
export function finite({active, pageSize, total}) {
|
|
2
|
+
const middle = Math.floor(pageSize / 2);
|
|
3
|
+
|
|
4
|
+
if (total <= pageSize || active < middle) {
|
|
5
|
+
return active;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (active >= total - middle) {
|
|
9
|
+
return active + pageSize - total;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return middle;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return Math.min(Math.floor(pageSize / 2), pointer + active - lastActive);
|
|
27
|
-
}
|
|
28
|
-
return pointer;
|
|
14
|
+
|
|
15
|
+
export function infinite({active, lastActive, total, pageSize, pointer}) {
|
|
16
|
+
if (total <= pageSize) {
|
|
17
|
+
return active;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (lastActive < active && pageSize > active - lastActive) {
|
|
21
|
+
return Math.min(Math.floor(pageSize / 2), pointer + active - lastActive);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return pointer;
|
|
29
25
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export class PromisePolyfill extends Promise {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
static withResolver() {
|
|
3
|
+
let resolve;
|
|
4
|
+
let reject;
|
|
5
|
+
const promise = new Promise((res, rej) => {
|
|
6
|
+
resolve = res;
|
|
7
|
+
reject = rej;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
promise,
|
|
12
|
+
resolve,
|
|
13
|
+
reject,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
13
16
|
}
|