@ncukondo/reference-manager 0.16.0 → 0.17.0
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/chunks/{file-watcher-B_WpVHSV.js → file-watcher-CrsNHUpz.js} +81 -29
- package/dist/chunks/file-watcher-CrsNHUpz.js.map +1 -0
- package/dist/chunks/format-CduFas9k.js +934 -0
- package/dist/chunks/format-CduFas9k.js.map +1 -0
- package/dist/chunks/{index-DHgeuWGP.js → index-B4gr0P83.js} +16 -20
- package/dist/chunks/{index-DHgeuWGP.js.map → index-B4gr0P83.js.map} +1 -1
- package/dist/chunks/{index-CEYp8OSj.js → index-CfuE2EuX.js} +6 -80
- package/dist/chunks/index-CfuE2EuX.js.map +1 -0
- package/dist/chunks/{index-4SVOiraD.js → index-CqrsgD_G.js} +1026 -177
- package/dist/chunks/index-CqrsgD_G.js.map +1 -0
- package/dist/chunks/{index-Bzl4_3Ki.js → index-D_UafVdu.js} +2 -2
- package/dist/chunks/index-D_UafVdu.js.map +1 -0
- package/dist/chunks/{loader-DuhmXjiI.js → loader-BN5sS7lg.js} +2 -2
- package/dist/chunks/{loader-DuhmXjiI.js.map → loader-BN5sS7lg.js.map} +1 -1
- package/dist/chunks/{reference-select-CgM-RBIa.js → reference-select-DbnF3oWs.js} +4 -16
- package/dist/chunks/reference-select-DbnF3oWs.js.map +1 -0
- package/dist/chunks/{style-select-tmKOHx_B.js → style-select-CbV5k3AV.js} +3 -3
- package/dist/chunks/{style-select-tmKOHx_B.js.map → style-select-CbV5k3AV.js.map} +1 -1
- package/dist/cli/commands/edit.d.ts +24 -3
- package/dist/cli/commands/edit.d.ts.map +1 -1
- package/dist/cli/commands/update.d.ts +1 -1
- package/dist/cli/commands/update.d.ts.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/core/csl-json/types.d.ts +0 -12
- package/dist/core/csl-json/types.d.ts.map +1 -1
- package/dist/core/library-interface.d.ts +14 -2
- package/dist/core/library-interface.d.ts.map +1 -1
- package/dist/core/library.d.ts +10 -1
- package/dist/core/library.d.ts.map +1 -1
- package/dist/features/edit/edit-session.d.ts +4 -0
- package/dist/features/edit/edit-session.d.ts.map +1 -1
- package/dist/features/edit/edit-validator.d.ts +19 -0
- package/dist/features/edit/edit-validator.d.ts.map +1 -0
- package/dist/features/edit/field-transformer.d.ts +4 -0
- package/dist/features/edit/field-transformer.d.ts.map +1 -1
- package/dist/features/edit/index.d.ts +2 -1
- package/dist/features/edit/index.d.ts.map +1 -1
- package/dist/features/edit/json-serializer.d.ts +9 -0
- package/dist/features/edit/json-serializer.d.ts.map +1 -1
- package/dist/features/edit/validation-prompt.d.ts +17 -0
- package/dist/features/edit/validation-prompt.d.ts.map +1 -0
- package/dist/features/edit/yaml-serializer.d.ts +10 -0
- package/dist/features/edit/yaml-serializer.d.ts.map +1 -1
- package/dist/features/fulltext/index.d.ts +0 -1
- package/dist/features/fulltext/index.d.ts.map +1 -1
- package/dist/features/interactive/apps/runCiteFlow.d.ts +1 -1
- package/dist/features/interactive/apps/runCiteFlow.d.ts.map +1 -1
- package/dist/features/interactive/apps/runSearchFlow.d.ts.map +1 -1
- package/dist/features/interactive/components/SearchableMultiSelect.d.ts.map +1 -1
- package/dist/features/interactive/components/index.d.ts +1 -0
- package/dist/features/interactive/components/index.d.ts.map +1 -1
- package/dist/features/interactive/components/layout.d.ts +23 -0
- package/dist/features/interactive/components/layout.d.ts.map +1 -0
- package/dist/features/interactive/search-prompt.d.ts +2 -15
- package/dist/features/interactive/search-prompt.d.ts.map +1 -1
- package/dist/features/operations/change-details.d.ts +27 -0
- package/dist/features/operations/change-details.d.ts.map +1 -0
- package/dist/features/operations/json-output.d.ts +2 -0
- package/dist/features/operations/json-output.d.ts.map +1 -1
- package/dist/features/operations/remove.d.ts +0 -1
- package/dist/features/operations/remove.d.ts.map +1 -1
- package/dist/features/operations/update.d.ts +4 -2
- package/dist/features/operations/update.d.ts.map +1 -1
- package/dist/index.js +16 -15
- package/dist/index.js.map +1 -1
- package/dist/server.js +2 -2
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/object.d.ts +5 -0
- package/dist/utils/object.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/alternate-screen-DcxkOKfW.js +0 -19
- package/dist/chunks/alternate-screen-DcxkOKfW.js.map +0 -1
- package/dist/chunks/file-watcher-B_WpVHSV.js.map +0 -1
- package/dist/chunks/format-C6FA-7hE.js +0 -397
- package/dist/chunks/format-C6FA-7hE.js.map +0 -1
- package/dist/chunks/index-4SVOiraD.js.map +0 -1
- package/dist/chunks/index-Bzl4_3Ki.js.map +0 -1
- package/dist/chunks/index-CEYp8OSj.js.map +0 -1
- package/dist/chunks/jsx-runtime-Q5cUjSur.js +0 -322
- package/dist/chunks/jsx-runtime-Q5cUjSur.js.map +0 -1
- package/dist/chunks/reference-select-CgM-RBIa.js.map +0 -1
- package/dist/features/fulltext/manager.d.ts +0 -109
- package/dist/features/fulltext/manager.d.ts.map +0 -1
|
@@ -0,0 +1,934 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "./index-CqrsgD_G.js";
|
|
2
|
+
import { useFocus, useStdout, useInput, Box, Text } from "ink";
|
|
3
|
+
import { useState, useMemo, useEffect, useCallback } from "react";
|
|
4
|
+
const ANSI_BACKGROUND_OFFSET = 10;
|
|
5
|
+
const wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
6
|
+
const wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
7
|
+
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
8
|
+
const styles = {
|
|
9
|
+
modifier: {
|
|
10
|
+
reset: [0, 0],
|
|
11
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
12
|
+
bold: [1, 22],
|
|
13
|
+
dim: [2, 22],
|
|
14
|
+
italic: [3, 23],
|
|
15
|
+
underline: [4, 24],
|
|
16
|
+
overline: [53, 55],
|
|
17
|
+
inverse: [7, 27],
|
|
18
|
+
hidden: [8, 28],
|
|
19
|
+
strikethrough: [9, 29]
|
|
20
|
+
},
|
|
21
|
+
color: {
|
|
22
|
+
black: [30, 39],
|
|
23
|
+
red: [31, 39],
|
|
24
|
+
green: [32, 39],
|
|
25
|
+
yellow: [33, 39],
|
|
26
|
+
blue: [34, 39],
|
|
27
|
+
magenta: [35, 39],
|
|
28
|
+
cyan: [36, 39],
|
|
29
|
+
white: [37, 39],
|
|
30
|
+
// Bright color
|
|
31
|
+
blackBright: [90, 39],
|
|
32
|
+
gray: [90, 39],
|
|
33
|
+
// Alias of `blackBright`
|
|
34
|
+
grey: [90, 39],
|
|
35
|
+
// Alias of `blackBright`
|
|
36
|
+
redBright: [91, 39],
|
|
37
|
+
greenBright: [92, 39],
|
|
38
|
+
yellowBright: [93, 39],
|
|
39
|
+
blueBright: [94, 39],
|
|
40
|
+
magentaBright: [95, 39],
|
|
41
|
+
cyanBright: [96, 39],
|
|
42
|
+
whiteBright: [97, 39]
|
|
43
|
+
},
|
|
44
|
+
bgColor: {
|
|
45
|
+
bgBlack: [40, 49],
|
|
46
|
+
bgRed: [41, 49],
|
|
47
|
+
bgGreen: [42, 49],
|
|
48
|
+
bgYellow: [43, 49],
|
|
49
|
+
bgBlue: [44, 49],
|
|
50
|
+
bgMagenta: [45, 49],
|
|
51
|
+
bgCyan: [46, 49],
|
|
52
|
+
bgWhite: [47, 49],
|
|
53
|
+
// Bright color
|
|
54
|
+
bgBlackBright: [100, 49],
|
|
55
|
+
bgGray: [100, 49],
|
|
56
|
+
// Alias of `bgBlackBright`
|
|
57
|
+
bgGrey: [100, 49],
|
|
58
|
+
// Alias of `bgBlackBright`
|
|
59
|
+
bgRedBright: [101, 49],
|
|
60
|
+
bgGreenBright: [102, 49],
|
|
61
|
+
bgYellowBright: [103, 49],
|
|
62
|
+
bgBlueBright: [104, 49],
|
|
63
|
+
bgMagentaBright: [105, 49],
|
|
64
|
+
bgCyanBright: [106, 49],
|
|
65
|
+
bgWhiteBright: [107, 49]
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
Object.keys(styles.modifier);
|
|
69
|
+
const foregroundColorNames = Object.keys(styles.color);
|
|
70
|
+
const backgroundColorNames = Object.keys(styles.bgColor);
|
|
71
|
+
[...foregroundColorNames, ...backgroundColorNames];
|
|
72
|
+
function assembleStyles() {
|
|
73
|
+
const codes = /* @__PURE__ */ new Map();
|
|
74
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
75
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
76
|
+
styles[styleName] = {
|
|
77
|
+
open: `\x1B[${style[0]}m`,
|
|
78
|
+
close: `\x1B[${style[1]}m`
|
|
79
|
+
};
|
|
80
|
+
group[styleName] = styles[styleName];
|
|
81
|
+
codes.set(style[0], style[1]);
|
|
82
|
+
}
|
|
83
|
+
Object.defineProperty(styles, groupName, {
|
|
84
|
+
value: group,
|
|
85
|
+
enumerable: false
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
Object.defineProperty(styles, "codes", {
|
|
89
|
+
value: codes,
|
|
90
|
+
enumerable: false
|
|
91
|
+
});
|
|
92
|
+
styles.color.close = "\x1B[39m";
|
|
93
|
+
styles.bgColor.close = "\x1B[49m";
|
|
94
|
+
styles.color.ansi = wrapAnsi16();
|
|
95
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
96
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
97
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
98
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
99
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
100
|
+
Object.defineProperties(styles, {
|
|
101
|
+
rgbToAnsi256: {
|
|
102
|
+
value(red, green, blue) {
|
|
103
|
+
if (red === green && green === blue) {
|
|
104
|
+
if (red < 8) {
|
|
105
|
+
return 16;
|
|
106
|
+
}
|
|
107
|
+
if (red > 248) {
|
|
108
|
+
return 231;
|
|
109
|
+
}
|
|
110
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
111
|
+
}
|
|
112
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
113
|
+
},
|
|
114
|
+
enumerable: false
|
|
115
|
+
},
|
|
116
|
+
hexToRgb: {
|
|
117
|
+
value(hex) {
|
|
118
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
119
|
+
if (!matches) {
|
|
120
|
+
return [0, 0, 0];
|
|
121
|
+
}
|
|
122
|
+
let [colorString] = matches;
|
|
123
|
+
if (colorString.length === 3) {
|
|
124
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
125
|
+
}
|
|
126
|
+
const integer = Number.parseInt(colorString, 16);
|
|
127
|
+
return [
|
|
128
|
+
/* eslint-disable no-bitwise */
|
|
129
|
+
integer >> 16 & 255,
|
|
130
|
+
integer >> 8 & 255,
|
|
131
|
+
integer & 255
|
|
132
|
+
/* eslint-enable no-bitwise */
|
|
133
|
+
];
|
|
134
|
+
},
|
|
135
|
+
enumerable: false
|
|
136
|
+
},
|
|
137
|
+
hexToAnsi256: {
|
|
138
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
139
|
+
enumerable: false
|
|
140
|
+
},
|
|
141
|
+
ansi256ToAnsi: {
|
|
142
|
+
value(code) {
|
|
143
|
+
if (code < 8) {
|
|
144
|
+
return 30 + code;
|
|
145
|
+
}
|
|
146
|
+
if (code < 16) {
|
|
147
|
+
return 90 + (code - 8);
|
|
148
|
+
}
|
|
149
|
+
let red;
|
|
150
|
+
let green;
|
|
151
|
+
let blue;
|
|
152
|
+
if (code >= 232) {
|
|
153
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
154
|
+
green = red;
|
|
155
|
+
blue = red;
|
|
156
|
+
} else {
|
|
157
|
+
code -= 16;
|
|
158
|
+
const remainder = code % 36;
|
|
159
|
+
red = Math.floor(code / 36) / 5;
|
|
160
|
+
green = Math.floor(remainder / 6) / 5;
|
|
161
|
+
blue = remainder % 6 / 5;
|
|
162
|
+
}
|
|
163
|
+
const value = Math.max(red, green, blue) * 2;
|
|
164
|
+
if (value === 0) {
|
|
165
|
+
return 30;
|
|
166
|
+
}
|
|
167
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
168
|
+
if (value === 2) {
|
|
169
|
+
result += 60;
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
},
|
|
173
|
+
enumerable: false
|
|
174
|
+
},
|
|
175
|
+
rgbToAnsi: {
|
|
176
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
177
|
+
enumerable: false
|
|
178
|
+
},
|
|
179
|
+
hexToAnsi: {
|
|
180
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
181
|
+
enumerable: false
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
return styles;
|
|
185
|
+
}
|
|
186
|
+
const ansiStyles = assembleStyles();
|
|
187
|
+
function isAmbiguous(x) {
|
|
188
|
+
return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
|
|
189
|
+
}
|
|
190
|
+
function isFullWidth(x) {
|
|
191
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
192
|
+
}
|
|
193
|
+
function isWide(x) {
|
|
194
|
+
return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9776 && x <= 9783 || x >= 9800 && x <= 9811 || x === 9855 || x >= 9866 && x <= 9871 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12773 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x >= 94192 && x <= 94198 || x >= 94208 && x <= 101589 || x >= 101631 && x <= 101662 || x >= 101760 && x <= 101874 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x >= 119552 && x <= 119638 || x >= 119648 && x <= 119670 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128728 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129674 || x >= 129678 && x <= 129734 || x === 129736 || x >= 129741 && x <= 129756 || x >= 129759 && x <= 129770 || x >= 129775 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
195
|
+
}
|
|
196
|
+
function validate(codePoint) {
|
|
197
|
+
if (!Number.isSafeInteger(codePoint)) {
|
|
198
|
+
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
202
|
+
validate(codePoint);
|
|
203
|
+
if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
|
|
204
|
+
return 2;
|
|
205
|
+
}
|
|
206
|
+
return 1;
|
|
207
|
+
}
|
|
208
|
+
function isFullwidthCodePoint(codePoint) {
|
|
209
|
+
if (!Number.isInteger(codePoint)) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
return isFullWidth(codePoint) || isWide(codePoint);
|
|
213
|
+
}
|
|
214
|
+
const ESCAPES = /* @__PURE__ */ new Set([27, 155]);
|
|
215
|
+
const CODE_POINT_0 = "0".codePointAt(0);
|
|
216
|
+
const CODE_POINT_9 = "9".codePointAt(0);
|
|
217
|
+
const MAX_ANSI_SEQUENCE_LENGTH = 19;
|
|
218
|
+
const endCodesSet = /* @__PURE__ */ new Set();
|
|
219
|
+
const endCodesMap = /* @__PURE__ */ new Map();
|
|
220
|
+
for (const [start, end] of ansiStyles.codes) {
|
|
221
|
+
endCodesSet.add(ansiStyles.color.ansi(end));
|
|
222
|
+
endCodesMap.set(ansiStyles.color.ansi(start), ansiStyles.color.ansi(end));
|
|
223
|
+
}
|
|
224
|
+
function getEndCode(code) {
|
|
225
|
+
if (endCodesSet.has(code)) {
|
|
226
|
+
return code;
|
|
227
|
+
}
|
|
228
|
+
if (endCodesMap.has(code)) {
|
|
229
|
+
return endCodesMap.get(code);
|
|
230
|
+
}
|
|
231
|
+
code = code.slice(2);
|
|
232
|
+
if (code.includes(";")) {
|
|
233
|
+
code = code[0] + "0";
|
|
234
|
+
}
|
|
235
|
+
const returnValue = ansiStyles.codes.get(Number.parseInt(code, 10));
|
|
236
|
+
if (returnValue) {
|
|
237
|
+
return ansiStyles.color.ansi(returnValue);
|
|
238
|
+
}
|
|
239
|
+
return ansiStyles.reset.open;
|
|
240
|
+
}
|
|
241
|
+
function findNumberIndex(string) {
|
|
242
|
+
for (let index = 0; index < string.length; index++) {
|
|
243
|
+
const codePoint = string.codePointAt(index);
|
|
244
|
+
if (codePoint >= CODE_POINT_0 && codePoint <= CODE_POINT_9) {
|
|
245
|
+
return index;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return -1;
|
|
249
|
+
}
|
|
250
|
+
function parseAnsiCode(string, offset) {
|
|
251
|
+
string = string.slice(offset, offset + MAX_ANSI_SEQUENCE_LENGTH);
|
|
252
|
+
const startIndex = findNumberIndex(string);
|
|
253
|
+
if (startIndex !== -1) {
|
|
254
|
+
let endIndex = string.indexOf("m", startIndex);
|
|
255
|
+
if (endIndex === -1) {
|
|
256
|
+
endIndex = string.length;
|
|
257
|
+
}
|
|
258
|
+
return string.slice(0, endIndex + 1);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function tokenize(string, endCharacter = Number.POSITIVE_INFINITY) {
|
|
262
|
+
const returnValue = [];
|
|
263
|
+
let index = 0;
|
|
264
|
+
let visibleCount = 0;
|
|
265
|
+
while (index < string.length) {
|
|
266
|
+
const codePoint = string.codePointAt(index);
|
|
267
|
+
if (ESCAPES.has(codePoint)) {
|
|
268
|
+
const code = parseAnsiCode(string, index);
|
|
269
|
+
if (code) {
|
|
270
|
+
returnValue.push({
|
|
271
|
+
type: "ansi",
|
|
272
|
+
code,
|
|
273
|
+
endCode: getEndCode(code)
|
|
274
|
+
});
|
|
275
|
+
index += code.length;
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const isFullWidth2 = isFullwidthCodePoint(codePoint);
|
|
280
|
+
const character = String.fromCodePoint(codePoint);
|
|
281
|
+
returnValue.push({
|
|
282
|
+
type: "character",
|
|
283
|
+
value: character,
|
|
284
|
+
isFullWidth: isFullWidth2
|
|
285
|
+
});
|
|
286
|
+
index += character.length;
|
|
287
|
+
visibleCount += isFullWidth2 ? 2 : character.length;
|
|
288
|
+
if (visibleCount >= endCharacter) {
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return returnValue;
|
|
293
|
+
}
|
|
294
|
+
function reduceAnsiCodes(codes) {
|
|
295
|
+
let returnValue = [];
|
|
296
|
+
for (const code of codes) {
|
|
297
|
+
if (code.code === ansiStyles.reset.open) {
|
|
298
|
+
returnValue = [];
|
|
299
|
+
} else if (endCodesSet.has(code.code)) {
|
|
300
|
+
returnValue = returnValue.filter((returnValueCode) => returnValueCode.endCode !== code.code);
|
|
301
|
+
} else {
|
|
302
|
+
returnValue = returnValue.filter((returnValueCode) => returnValueCode.endCode !== code.endCode);
|
|
303
|
+
returnValue.push(code);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return returnValue;
|
|
307
|
+
}
|
|
308
|
+
function undoAnsiCodes(codes) {
|
|
309
|
+
const reduced = reduceAnsiCodes(codes);
|
|
310
|
+
const endCodes = reduced.map(({ endCode }) => endCode);
|
|
311
|
+
return endCodes.reverse().join("");
|
|
312
|
+
}
|
|
313
|
+
function sliceAnsi(string, start, end) {
|
|
314
|
+
const tokens = tokenize(string, end);
|
|
315
|
+
let activeCodes = [];
|
|
316
|
+
let position = 0;
|
|
317
|
+
let returnValue = "";
|
|
318
|
+
let include = false;
|
|
319
|
+
for (const token of tokens) {
|
|
320
|
+
if (end !== void 0 && position >= end) {
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
if (token.type === "ansi") {
|
|
324
|
+
activeCodes.push(token);
|
|
325
|
+
if (include) {
|
|
326
|
+
returnValue += token.code;
|
|
327
|
+
}
|
|
328
|
+
} else {
|
|
329
|
+
if (!include && position >= start) {
|
|
330
|
+
include = true;
|
|
331
|
+
activeCodes = reduceAnsiCodes(activeCodes);
|
|
332
|
+
returnValue = activeCodes.map(({ code }) => code).join("");
|
|
333
|
+
}
|
|
334
|
+
if (include) {
|
|
335
|
+
returnValue += token.value;
|
|
336
|
+
}
|
|
337
|
+
position += token.isFullWidth ? 2 : token.value.length;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
returnValue += undoAnsiCodes(activeCodes);
|
|
341
|
+
return returnValue;
|
|
342
|
+
}
|
|
343
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
|
344
|
+
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
345
|
+
const osc = `(?:\\u001B\\][\\s\\S]*?${ST})`;
|
|
346
|
+
const csi = "[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";
|
|
347
|
+
const pattern = `${osc}|${csi}`;
|
|
348
|
+
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
349
|
+
}
|
|
350
|
+
const regex = ansiRegex();
|
|
351
|
+
function stripAnsi(string) {
|
|
352
|
+
if (typeof string !== "string") {
|
|
353
|
+
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
354
|
+
}
|
|
355
|
+
return string.replace(regex, "");
|
|
356
|
+
}
|
|
357
|
+
const segmenter = new Intl.Segmenter();
|
|
358
|
+
const zeroWidthClusterRegex = new RegExp("^(?:\\p{Default_Ignorable_Code_Point}|\\p{Control}|\\p{Mark}|\\p{Surrogate})+$", "v");
|
|
359
|
+
const leadingNonPrintingRegex = new RegExp("^[\\p{Default_Ignorable_Code_Point}\\p{Control}\\p{Format}\\p{Mark}\\p{Surrogate}]+", "v");
|
|
360
|
+
const rgiEmojiRegex = new RegExp("^\\p{RGI_Emoji}$", "v");
|
|
361
|
+
function baseVisible(segment) {
|
|
362
|
+
return segment.replace(leadingNonPrintingRegex, "");
|
|
363
|
+
}
|
|
364
|
+
function isZeroWidthCluster(segment) {
|
|
365
|
+
return zeroWidthClusterRegex.test(segment);
|
|
366
|
+
}
|
|
367
|
+
function trailingHalfwidthWidth(segment, eastAsianWidthOptions) {
|
|
368
|
+
let extra = 0;
|
|
369
|
+
if (segment.length > 1) {
|
|
370
|
+
for (const char of segment.slice(1)) {
|
|
371
|
+
if (char >= "" && char <= "") {
|
|
372
|
+
extra += eastAsianWidth(char.codePointAt(0), eastAsianWidthOptions);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return extra;
|
|
377
|
+
}
|
|
378
|
+
function stringWidth(input, options = {}) {
|
|
379
|
+
if (typeof input !== "string" || input.length === 0) {
|
|
380
|
+
return 0;
|
|
381
|
+
}
|
|
382
|
+
const {
|
|
383
|
+
ambiguousIsNarrow = true,
|
|
384
|
+
countAnsiEscapeCodes = false
|
|
385
|
+
} = options;
|
|
386
|
+
let string = input;
|
|
387
|
+
if (!countAnsiEscapeCodes) {
|
|
388
|
+
string = stripAnsi(string);
|
|
389
|
+
}
|
|
390
|
+
if (string.length === 0) {
|
|
391
|
+
return 0;
|
|
392
|
+
}
|
|
393
|
+
let width = 0;
|
|
394
|
+
const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
|
|
395
|
+
for (const { segment } of segmenter.segment(string)) {
|
|
396
|
+
if (isZeroWidthCluster(segment)) {
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
if (rgiEmojiRegex.test(segment)) {
|
|
400
|
+
width += 2;
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
const codePoint = baseVisible(segment).codePointAt(0);
|
|
404
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
405
|
+
width += trailingHalfwidthWidth(segment, eastAsianWidthOptions);
|
|
406
|
+
}
|
|
407
|
+
return width;
|
|
408
|
+
}
|
|
409
|
+
function getIndexOfNearestSpace(string, wantedIndex, shouldSearchRight) {
|
|
410
|
+
if (string.charAt(wantedIndex) === " ") {
|
|
411
|
+
return wantedIndex;
|
|
412
|
+
}
|
|
413
|
+
const direction = shouldSearchRight ? 1 : -1;
|
|
414
|
+
for (let index = 0; index <= 3; index++) {
|
|
415
|
+
const finalIndex = wantedIndex + index * direction;
|
|
416
|
+
if (string.charAt(finalIndex) === " ") {
|
|
417
|
+
return finalIndex;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return wantedIndex;
|
|
421
|
+
}
|
|
422
|
+
function cliTruncate(text, columns, options = {}) {
|
|
423
|
+
const {
|
|
424
|
+
position = "end",
|
|
425
|
+
space = false,
|
|
426
|
+
preferTruncationOnSpace = false
|
|
427
|
+
} = options;
|
|
428
|
+
let { truncationCharacter = "…" } = options;
|
|
429
|
+
if (typeof text !== "string") {
|
|
430
|
+
throw new TypeError(`Expected \`input\` to be a string, got ${typeof text}`);
|
|
431
|
+
}
|
|
432
|
+
if (typeof columns !== "number") {
|
|
433
|
+
throw new TypeError(`Expected \`columns\` to be a number, got ${typeof columns}`);
|
|
434
|
+
}
|
|
435
|
+
if (columns < 1) {
|
|
436
|
+
return "";
|
|
437
|
+
}
|
|
438
|
+
const length = stringWidth(text);
|
|
439
|
+
if (length <= columns) {
|
|
440
|
+
return text;
|
|
441
|
+
}
|
|
442
|
+
if (columns === 1) {
|
|
443
|
+
return truncationCharacter;
|
|
444
|
+
}
|
|
445
|
+
const ANSI = {
|
|
446
|
+
ESC: 27,
|
|
447
|
+
LEFT_BRACKET: 91,
|
|
448
|
+
LETTER_M: 109
|
|
449
|
+
};
|
|
450
|
+
const isSgrParameter = (code) => code >= 48 && code <= 57 || code === 59;
|
|
451
|
+
function leadingSgrSpanEndIndex(string) {
|
|
452
|
+
let index = 0;
|
|
453
|
+
while (index + 2 < string.length && string.codePointAt(index) === ANSI.ESC && string.codePointAt(index + 1) === ANSI.LEFT_BRACKET) {
|
|
454
|
+
let j = index + 2;
|
|
455
|
+
while (j < string.length && isSgrParameter(string.codePointAt(j))) {
|
|
456
|
+
j++;
|
|
457
|
+
}
|
|
458
|
+
if (j < string.length && string.codePointAt(j) === ANSI.LETTER_M) {
|
|
459
|
+
index = j + 1;
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
return index;
|
|
465
|
+
}
|
|
466
|
+
function trailingSgrSpanStartIndex(string) {
|
|
467
|
+
let start = string.length;
|
|
468
|
+
while (start > 1 && string.codePointAt(start - 1) === ANSI.LETTER_M) {
|
|
469
|
+
let j = start - 2;
|
|
470
|
+
while (j >= 0 && isSgrParameter(string.codePointAt(j))) {
|
|
471
|
+
j--;
|
|
472
|
+
}
|
|
473
|
+
if (j >= 1 && string.codePointAt(j - 1) === ANSI.ESC && string.codePointAt(j) === ANSI.LEFT_BRACKET) {
|
|
474
|
+
start = j - 1;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
return start;
|
|
480
|
+
}
|
|
481
|
+
function appendWithInheritedStyleFromEnd(visible, suffix) {
|
|
482
|
+
const start = trailingSgrSpanStartIndex(visible);
|
|
483
|
+
if (start === visible.length) {
|
|
484
|
+
return visible + suffix;
|
|
485
|
+
}
|
|
486
|
+
return visible.slice(0, start) + suffix + visible.slice(start);
|
|
487
|
+
}
|
|
488
|
+
function prependWithInheritedStyleFromStart(prefix, visible) {
|
|
489
|
+
const end = leadingSgrSpanEndIndex(visible);
|
|
490
|
+
if (end === 0) {
|
|
491
|
+
return prefix + visible;
|
|
492
|
+
}
|
|
493
|
+
return visible.slice(0, end) + prefix + visible.slice(end);
|
|
494
|
+
}
|
|
495
|
+
if (position === "start") {
|
|
496
|
+
if (preferTruncationOnSpace) {
|
|
497
|
+
const nearestSpace = getIndexOfNearestSpace(text, length - columns + 1, true);
|
|
498
|
+
const right2 = sliceAnsi(text, nearestSpace, length).trim();
|
|
499
|
+
return prependWithInheritedStyleFromStart(truncationCharacter, right2);
|
|
500
|
+
}
|
|
501
|
+
if (space) {
|
|
502
|
+
truncationCharacter += " ";
|
|
503
|
+
}
|
|
504
|
+
const right = sliceAnsi(text, length - columns + stringWidth(truncationCharacter), length);
|
|
505
|
+
return prependWithInheritedStyleFromStart(truncationCharacter, right);
|
|
506
|
+
}
|
|
507
|
+
if (position === "middle") {
|
|
508
|
+
if (space) {
|
|
509
|
+
truncationCharacter = ` ${truncationCharacter} `;
|
|
510
|
+
}
|
|
511
|
+
const half = Math.floor(columns / 2);
|
|
512
|
+
if (preferTruncationOnSpace) {
|
|
513
|
+
const spaceNearFirstBreakPoint = getIndexOfNearestSpace(text, half);
|
|
514
|
+
const spaceNearSecondBreakPoint = getIndexOfNearestSpace(text, length - (columns - half) + 1, true);
|
|
515
|
+
return sliceAnsi(text, 0, spaceNearFirstBreakPoint) + truncationCharacter + sliceAnsi(text, spaceNearSecondBreakPoint, length).trim();
|
|
516
|
+
}
|
|
517
|
+
return sliceAnsi(text, 0, half) + truncationCharacter + sliceAnsi(text, length - (columns - half) + stringWidth(truncationCharacter), length);
|
|
518
|
+
}
|
|
519
|
+
if (position === "end") {
|
|
520
|
+
if (preferTruncationOnSpace) {
|
|
521
|
+
const nearestSpace = getIndexOfNearestSpace(text, columns - 1);
|
|
522
|
+
const left2 = sliceAnsi(text, 0, nearestSpace);
|
|
523
|
+
return appendWithInheritedStyleFromEnd(left2, truncationCharacter);
|
|
524
|
+
}
|
|
525
|
+
if (space) {
|
|
526
|
+
truncationCharacter = ` ${truncationCharacter}`;
|
|
527
|
+
}
|
|
528
|
+
const left = sliceAnsi(text, 0, columns - stringWidth(truncationCharacter));
|
|
529
|
+
return appendWithInheritedStyleFromEnd(left, truncationCharacter);
|
|
530
|
+
}
|
|
531
|
+
throw new Error(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${position}`);
|
|
532
|
+
}
|
|
533
|
+
const ITEM_HEIGHT = 3;
|
|
534
|
+
const RESERVED_LINES = 12;
|
|
535
|
+
function getTerminalHeight() {
|
|
536
|
+
return process.stdout.rows ?? 24;
|
|
537
|
+
}
|
|
538
|
+
function calculateEffectiveLimit(configLimit) {
|
|
539
|
+
const terminalHeight = getTerminalHeight();
|
|
540
|
+
const availableLines = terminalHeight - RESERVED_LINES;
|
|
541
|
+
const maxVisibleChoices = Math.max(1, Math.floor(availableLines / ITEM_HEIGHT));
|
|
542
|
+
return configLimit > 0 ? Math.min(configLimit, maxVisibleChoices) : maxVisibleChoices;
|
|
543
|
+
}
|
|
544
|
+
const SORT_OPTIONS = [
|
|
545
|
+
{ id: "updated-desc", label: "Updated (newest first)", requiresQuery: false },
|
|
546
|
+
{ id: "updated-asc", label: "Updated (oldest first)", requiresQuery: false },
|
|
547
|
+
{ id: "created-desc", label: "Created (newest first)", requiresQuery: false },
|
|
548
|
+
{ id: "created-asc", label: "Created (oldest first)", requiresQuery: false },
|
|
549
|
+
{ id: "published-desc", label: "Published (newest first)", requiresQuery: false },
|
|
550
|
+
{ id: "published-asc", label: "Published (oldest first)", requiresQuery: false },
|
|
551
|
+
{ id: "relevance", label: "Relevance", requiresQuery: true }
|
|
552
|
+
];
|
|
553
|
+
function getSortShortLabel(sortOption) {
|
|
554
|
+
switch (sortOption) {
|
|
555
|
+
case "updated-desc":
|
|
556
|
+
return "Updated ↓";
|
|
557
|
+
case "updated-asc":
|
|
558
|
+
return "Updated ↑";
|
|
559
|
+
case "created-desc":
|
|
560
|
+
return "Created ↓";
|
|
561
|
+
case "created-asc":
|
|
562
|
+
return "Created ↑";
|
|
563
|
+
case "published-desc":
|
|
564
|
+
return "Published ↓";
|
|
565
|
+
case "published-asc":
|
|
566
|
+
return "Published ↑";
|
|
567
|
+
case "relevance":
|
|
568
|
+
return "Relevance";
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
function createDateComparator(getDate, descending) {
|
|
572
|
+
return (a, b) => {
|
|
573
|
+
const dateA = getDate(a)?.getTime() ?? 0;
|
|
574
|
+
const dateB = getDate(b)?.getTime() ?? 0;
|
|
575
|
+
return descending ? dateB - dateA : dateA - dateB;
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
function sortChoices(choices, sortOption) {
|
|
579
|
+
if (sortOption === "relevance") return [...choices];
|
|
580
|
+
const sorted = [...choices];
|
|
581
|
+
const comparators = {
|
|
582
|
+
"updated-desc": createDateComparator((c) => c.updatedDate, true),
|
|
583
|
+
"updated-asc": createDateComparator((c) => c.updatedDate, false),
|
|
584
|
+
"created-desc": createDateComparator((c) => c.createdDate, true),
|
|
585
|
+
"created-asc": createDateComparator((c) => c.createdDate, false),
|
|
586
|
+
"published-desc": createDateComparator((c) => c.publishedDate, true),
|
|
587
|
+
"published-asc": createDateComparator((c) => c.publishedDate, false)
|
|
588
|
+
};
|
|
589
|
+
return sorted.sort(comparators[sortOption]);
|
|
590
|
+
}
|
|
591
|
+
function defaultFilter(query, choices) {
|
|
592
|
+
if (!query.trim()) return choices;
|
|
593
|
+
const lowerQuery = query.toLowerCase();
|
|
594
|
+
return choices.filter(
|
|
595
|
+
(choice) => choice.title.toLowerCase().includes(lowerQuery) || choice.subtitle?.toLowerCase().includes(lowerQuery) || choice.meta?.toLowerCase().includes(lowerQuery)
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
function truncate(text, maxWidth) {
|
|
599
|
+
return cliTruncate(text, maxWidth, { position: "end" });
|
|
600
|
+
}
|
|
601
|
+
function getNavigationDelta(key, input, visibleCount, maxIndex) {
|
|
602
|
+
if (key.upArrow) return -1;
|
|
603
|
+
if (key.downArrow) return 1;
|
|
604
|
+
if (key.pageUp) return -visibleCount;
|
|
605
|
+
if (key.pageDown) return visibleCount;
|
|
606
|
+
if (key.ctrl && input === "a") return -maxIndex - 1;
|
|
607
|
+
if (key.ctrl && input === "e") return maxIndex + 1;
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
function parseKeyAction(input, key, visibleCount, maxIndex) {
|
|
611
|
+
if (key.escape) return { type: "cancel" };
|
|
612
|
+
if (key.return) return { type: "submit" };
|
|
613
|
+
const navDelta = getNavigationDelta(key, input, visibleCount, maxIndex);
|
|
614
|
+
if (navDelta !== null) return { type: "navigate", delta: navDelta };
|
|
615
|
+
if (key.ctrl && input === "s") return { type: "sort" };
|
|
616
|
+
if (key.tab) return { type: "toggle" };
|
|
617
|
+
if (key.backspace || key.delete) return { type: "backspace" };
|
|
618
|
+
if (input && !key.ctrl && !key.meta) return { type: "input", char: input };
|
|
619
|
+
return { type: "none" };
|
|
620
|
+
}
|
|
621
|
+
function ChoiceItem({
|
|
622
|
+
choice,
|
|
623
|
+
isSelected,
|
|
624
|
+
isFocused,
|
|
625
|
+
contentWidth
|
|
626
|
+
}) {
|
|
627
|
+
const indent = " ";
|
|
628
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { flexDirection: "column", paddingY: 0, children: [
|
|
629
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { flexDirection: "row", children: [
|
|
630
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Box, { width: 2, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { color: "cyan", children: isFocused ? "❯" : " " }) }),
|
|
631
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Box, { width: 2, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { color: isSelected ? "green" : "gray", children: isSelected ? "◉" : "○" }) }),
|
|
632
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Box, { width: 1, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: " " }) }),
|
|
633
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: isFocused ? /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { color: "cyan", bold: true, children: truncate(choice.title, contentWidth) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { color: "blue", children: truncate(choice.title, contentWidth) }) })
|
|
634
|
+
] }),
|
|
635
|
+
choice.subtitle && /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { dimColor: true, children: [
|
|
636
|
+
indent,
|
|
637
|
+
truncate(choice.subtitle, contentWidth)
|
|
638
|
+
] }) }),
|
|
639
|
+
choice.meta && /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { dimColor: true, children: [
|
|
640
|
+
indent,
|
|
641
|
+
truncate(choice.meta, contentWidth)
|
|
642
|
+
] }) })
|
|
643
|
+
] });
|
|
644
|
+
}
|
|
645
|
+
function ScrollIndicator({
|
|
646
|
+
direction,
|
|
647
|
+
count,
|
|
648
|
+
visible
|
|
649
|
+
}) {
|
|
650
|
+
const arrow = direction === "up" ? "↑" : "↓";
|
|
651
|
+
const label = direction === "up" ? "more above" : "more below";
|
|
652
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { height: 1, children: visible && count > 0 ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { dimColor: true, children: [
|
|
653
|
+
" ",
|
|
654
|
+
arrow,
|
|
655
|
+
" ",
|
|
656
|
+
count,
|
|
657
|
+
" ",
|
|
658
|
+
label
|
|
659
|
+
] }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: " " }) });
|
|
660
|
+
}
|
|
661
|
+
function ChoiceList({
|
|
662
|
+
choices,
|
|
663
|
+
selectedIds,
|
|
664
|
+
focusIndex,
|
|
665
|
+
scrollOffset,
|
|
666
|
+
contentWidth
|
|
667
|
+
}) {
|
|
668
|
+
if (choices.length === 0) {
|
|
669
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { paddingY: 1, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { dimColor: true, children: "No results found" }) });
|
|
670
|
+
}
|
|
671
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { flexDirection: "column", children: choices.map((choice, visibleIndex) => {
|
|
672
|
+
const actualIndex = scrollOffset + visibleIndex;
|
|
673
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { flexDirection: "row", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
674
|
+
ChoiceItem,
|
|
675
|
+
{
|
|
676
|
+
choice,
|
|
677
|
+
isSelected: selectedIds.has(choice.id),
|
|
678
|
+
isFocused: actualIndex === focusIndex,
|
|
679
|
+
contentWidth
|
|
680
|
+
}
|
|
681
|
+
) }, choice.id);
|
|
682
|
+
}) });
|
|
683
|
+
}
|
|
684
|
+
function SortMenu({
|
|
685
|
+
options,
|
|
686
|
+
focusIndex,
|
|
687
|
+
currentSort
|
|
688
|
+
}) {
|
|
689
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
690
|
+
Box,
|
|
691
|
+
{
|
|
692
|
+
flexDirection: "column",
|
|
693
|
+
marginBottom: 1,
|
|
694
|
+
paddingX: 1,
|
|
695
|
+
borderStyle: "round",
|
|
696
|
+
borderColor: "yellow",
|
|
697
|
+
children: [
|
|
698
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { bold: true, color: "yellow", children: "Sort by:" }) }),
|
|
699
|
+
options.map((opt, index) => {
|
|
700
|
+
const isFocused = index === focusIndex;
|
|
701
|
+
const isCurrent = opt.id === currentSort;
|
|
702
|
+
const checkMark = isCurrent ? " ✓" : "";
|
|
703
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: isFocused ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { color: "cyan", children: [
|
|
704
|
+
"❯ ",
|
|
705
|
+
opt.label,
|
|
706
|
+
checkMark
|
|
707
|
+
] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { children: [
|
|
708
|
+
" ",
|
|
709
|
+
opt.label,
|
|
710
|
+
checkMark
|
|
711
|
+
] }) }, opt.id);
|
|
712
|
+
}),
|
|
713
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { dimColor: true, children: "↑↓:select Enter:confirm Esc:cancel" }) })
|
|
714
|
+
]
|
|
715
|
+
}
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
function SearchableMultiSelect({
|
|
719
|
+
choices,
|
|
720
|
+
filterFn = defaultFilter,
|
|
721
|
+
visibleCount: visibleCountProp,
|
|
722
|
+
onSubmit,
|
|
723
|
+
onCancel,
|
|
724
|
+
placeholder = "Type to search...",
|
|
725
|
+
header,
|
|
726
|
+
footer,
|
|
727
|
+
defaultSort = "updated-desc"
|
|
728
|
+
}) {
|
|
729
|
+
const [query, setQuery] = useState("");
|
|
730
|
+
const [selectedIds, setSelectedIds] = useState(/* @__PURE__ */ new Set());
|
|
731
|
+
const [focusIndex, setFocusIndex] = useState(0);
|
|
732
|
+
const [scrollOffset, setScrollOffset] = useState(0);
|
|
733
|
+
const [sortOption, setSortOption] = useState(defaultSort);
|
|
734
|
+
const [showSortMenu, setShowSortMenu] = useState(false);
|
|
735
|
+
const [sortMenuIndex, setSortMenuIndex] = useState(0);
|
|
736
|
+
const { isFocused } = useFocus({ autoFocus: true });
|
|
737
|
+
const { stdout } = useStdout();
|
|
738
|
+
const terminalWidth = stdout?.columns ?? 80;
|
|
739
|
+
const terminalHeight = stdout?.rows ?? 24;
|
|
740
|
+
const contentWidth = terminalWidth - 8;
|
|
741
|
+
const calculatedVisibleCount = Math.max(
|
|
742
|
+
1,
|
|
743
|
+
Math.floor((terminalHeight - RESERVED_LINES) / ITEM_HEIGHT)
|
|
744
|
+
);
|
|
745
|
+
const visibleCount = visibleCountProp ?? calculatedVisibleCount;
|
|
746
|
+
const filteredChoices = useMemo(() => filterFn(query, choices), [query, choices, filterFn]);
|
|
747
|
+
const availableSortOptions = useMemo(
|
|
748
|
+
() => SORT_OPTIONS.filter((opt) => !opt.requiresQuery || query.trim().length > 0),
|
|
749
|
+
[query]
|
|
750
|
+
);
|
|
751
|
+
const sortedChoices = useMemo(
|
|
752
|
+
() => sortOption === "relevance" ? filteredChoices : sortChoices(filteredChoices, sortOption),
|
|
753
|
+
[filteredChoices, sortOption]
|
|
754
|
+
);
|
|
755
|
+
const maxIndex = sortedChoices.length - 1;
|
|
756
|
+
useEffect(() => {
|
|
757
|
+
setFocusIndex(0);
|
|
758
|
+
setScrollOffset(0);
|
|
759
|
+
}, [query]);
|
|
760
|
+
useEffect(() => {
|
|
761
|
+
if (focusIndex < scrollOffset) {
|
|
762
|
+
setScrollOffset(focusIndex);
|
|
763
|
+
} else if (focusIndex >= scrollOffset + visibleCount) {
|
|
764
|
+
setScrollOffset(focusIndex - visibleCount + 1);
|
|
765
|
+
}
|
|
766
|
+
}, [focusIndex, scrollOffset, visibleCount]);
|
|
767
|
+
const visibleChoices = useMemo(
|
|
768
|
+
() => sortedChoices.slice(scrollOffset, scrollOffset + visibleCount),
|
|
769
|
+
[sortedChoices, scrollOffset, visibleCount]
|
|
770
|
+
);
|
|
771
|
+
const toggleSelection = useCallback(() => {
|
|
772
|
+
const currentChoice = sortedChoices[focusIndex];
|
|
773
|
+
if (!currentChoice) return;
|
|
774
|
+
setSelectedIds((prev) => {
|
|
775
|
+
const newSet = new Set(prev);
|
|
776
|
+
if (newSet.has(currentChoice.id)) {
|
|
777
|
+
newSet.delete(currentChoice.id);
|
|
778
|
+
} else {
|
|
779
|
+
newSet.add(currentChoice.id);
|
|
780
|
+
}
|
|
781
|
+
return newSet;
|
|
782
|
+
});
|
|
783
|
+
}, [sortedChoices, focusIndex]);
|
|
784
|
+
useInput(
|
|
785
|
+
(_input, key) => {
|
|
786
|
+
if (key.escape) {
|
|
787
|
+
setShowSortMenu(false);
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
if (key.return) {
|
|
791
|
+
const selected = availableSortOptions[sortMenuIndex];
|
|
792
|
+
if (selected) {
|
|
793
|
+
setSortOption(selected.id);
|
|
794
|
+
setFocusIndex(0);
|
|
795
|
+
setScrollOffset(0);
|
|
796
|
+
}
|
|
797
|
+
setShowSortMenu(false);
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
if (key.upArrow) {
|
|
801
|
+
setSortMenuIndex((prev) => Math.max(0, prev - 1));
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
if (key.downArrow) {
|
|
805
|
+
setSortMenuIndex((prev) => Math.min(availableSortOptions.length - 1, prev + 1));
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
},
|
|
809
|
+
{ isActive: isFocused && showSortMenu }
|
|
810
|
+
);
|
|
811
|
+
useInput(
|
|
812
|
+
(input, key) => {
|
|
813
|
+
const action = parseKeyAction(input, key, visibleCount, maxIndex);
|
|
814
|
+
switch (action.type) {
|
|
815
|
+
case "cancel":
|
|
816
|
+
onCancel();
|
|
817
|
+
break;
|
|
818
|
+
case "submit":
|
|
819
|
+
onSubmit(choices.filter((c) => selectedIds.has(c.id)));
|
|
820
|
+
break;
|
|
821
|
+
case "navigate":
|
|
822
|
+
setFocusIndex((prev) => Math.max(0, Math.min(maxIndex, prev + action.delta)));
|
|
823
|
+
break;
|
|
824
|
+
case "toggle":
|
|
825
|
+
toggleSelection();
|
|
826
|
+
break;
|
|
827
|
+
case "backspace":
|
|
828
|
+
setQuery((prev) => prev.slice(0, -1));
|
|
829
|
+
break;
|
|
830
|
+
case "input":
|
|
831
|
+
setQuery((prev) => prev + action.char);
|
|
832
|
+
break;
|
|
833
|
+
case "sort":
|
|
834
|
+
setSortMenuIndex(availableSortOptions.findIndex((o) => o.id === sortOption));
|
|
835
|
+
setShowSortMenu(true);
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
},
|
|
839
|
+
{ isActive: isFocused && !showSortMenu }
|
|
840
|
+
);
|
|
841
|
+
const totalItems = sortedChoices.length;
|
|
842
|
+
const showScrollIndicator = totalItems > visibleCount;
|
|
843
|
+
const footerText = footer ?? (showScrollIndicator ? `↑↓:move Tab:select ^S:sort Enter:confirm (${focusIndex + 1}/${totalItems})` : "↑↓:move Tab:select ^S:sort Enter:confirm Esc:cancel");
|
|
844
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { flexDirection: "column", paddingX: 1, children: [
|
|
845
|
+
header && /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { bold: true, color: "cyan", children: header }) }),
|
|
846
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { marginBottom: 1, paddingX: 1, borderStyle: "round", borderColor: "cyan", children: [
|
|
847
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Text, { color: "green", children: "❯ " }),
|
|
848
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: query || /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { dimColor: true, children: placeholder }) }),
|
|
849
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Text, { color: "gray", children: "▎" })
|
|
850
|
+
] }),
|
|
851
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { marginBottom: 1, paddingX: 1, justifyContent: "space-between", children: [
|
|
852
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: selectedIds.size > 0 ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { color: "yellow", children: [
|
|
853
|
+
selectedIds.size,
|
|
854
|
+
" selected / ",
|
|
855
|
+
totalItems,
|
|
856
|
+
" results"
|
|
857
|
+
] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { dimColor: true, children: [
|
|
858
|
+
totalItems,
|
|
859
|
+
" results"
|
|
860
|
+
] }) }),
|
|
861
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { dimColor: true, children: [
|
|
862
|
+
"Sort: ",
|
|
863
|
+
getSortShortLabel(sortOption)
|
|
864
|
+
] }) })
|
|
865
|
+
] }),
|
|
866
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Box, { flexDirection: "column", height: visibleCount * ITEM_HEIGHT + 2, children: showSortMenu ? /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
867
|
+
SortMenu,
|
|
868
|
+
{
|
|
869
|
+
options: availableSortOptions,
|
|
870
|
+
focusIndex: sortMenuIndex,
|
|
871
|
+
currentSort: sortOption
|
|
872
|
+
}
|
|
873
|
+
) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
874
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(ScrollIndicator, { direction: "up", count: scrollOffset, visible: showScrollIndicator }),
|
|
875
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
876
|
+
ChoiceList,
|
|
877
|
+
{
|
|
878
|
+
choices: visibleChoices,
|
|
879
|
+
selectedIds,
|
|
880
|
+
focusIndex,
|
|
881
|
+
scrollOffset,
|
|
882
|
+
contentWidth
|
|
883
|
+
}
|
|
884
|
+
),
|
|
885
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
886
|
+
ScrollIndicator,
|
|
887
|
+
{
|
|
888
|
+
direction: "down",
|
|
889
|
+
count: totalItems - scrollOffset - visibleCount,
|
|
890
|
+
visible: showScrollIndicator
|
|
891
|
+
}
|
|
892
|
+
)
|
|
893
|
+
] }) }),
|
|
894
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { dimColor: true, children: footerText }) })
|
|
895
|
+
] });
|
|
896
|
+
}
|
|
897
|
+
function formatSingleAuthor(author) {
|
|
898
|
+
if (author.literal) {
|
|
899
|
+
return author.literal;
|
|
900
|
+
}
|
|
901
|
+
if (author.family) {
|
|
902
|
+
if (author.given) {
|
|
903
|
+
const initial = author.given.charAt(0).toUpperCase();
|
|
904
|
+
return `${author.family}, ${initial}.`;
|
|
905
|
+
}
|
|
906
|
+
return author.family;
|
|
907
|
+
}
|
|
908
|
+
return "";
|
|
909
|
+
}
|
|
910
|
+
function formatAuthors(authors) {
|
|
911
|
+
if (!authors || authors.length === 0) {
|
|
912
|
+
return "";
|
|
913
|
+
}
|
|
914
|
+
if (authors.length > 3) {
|
|
915
|
+
const first = authors[0];
|
|
916
|
+
if (!first) {
|
|
917
|
+
return "";
|
|
918
|
+
}
|
|
919
|
+
return `${formatSingleAuthor(first)}, et al.`;
|
|
920
|
+
}
|
|
921
|
+
const formatted = authors.map(formatSingleAuthor);
|
|
922
|
+
if (formatted.length === 1) {
|
|
923
|
+
return formatted[0] ?? "";
|
|
924
|
+
}
|
|
925
|
+
const allButLast = formatted.slice(0, -1).join(", ");
|
|
926
|
+
const last = formatted[formatted.length - 1] ?? "";
|
|
927
|
+
return `${allButLast}, & ${last}`;
|
|
928
|
+
}
|
|
929
|
+
export {
|
|
930
|
+
SearchableMultiSelect as S,
|
|
931
|
+
calculateEffectiveLimit as c,
|
|
932
|
+
formatAuthors as f
|
|
933
|
+
};
|
|
934
|
+
//# sourceMappingURL=format-CduFas9k.js.map
|