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