@markjaquith/agency 3.9.0 → 3.9.1
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/package.json +1 -1
- package/src/utils/interactive.js +16 -4
package/package.json
CHANGED
package/src/utils/interactive.js
CHANGED
|
@@ -260,7 +260,8 @@ var InteractiveSelectPrompt = (props) => {
|
|
|
260
260
|
const dimensions = useTerminalDimensions();
|
|
261
261
|
const [query, setQuery] = createSignal("");
|
|
262
262
|
const editing = createReadlineEditing(() => input, setQuery);
|
|
263
|
-
const
|
|
263
|
+
const initialIndex = props.initialKey ? props.choices.findIndex((choice) => choice.key === props.initialKey) : 0;
|
|
264
|
+
const [selected, setSelected] = createSignal(Math.max(initialIndex, 0));
|
|
264
265
|
const choices = createMemo(() => fuzzyChoices(props.choices, query()));
|
|
265
266
|
const displaySegments = (choice) => choice.segments ?? [{
|
|
266
267
|
text: choice.label
|
|
@@ -684,6 +685,9 @@ var InteractiveTabbedPrompt = (props) => {
|
|
|
684
685
|
get emptyLabel() {
|
|
685
686
|
return tab.emptyLabel;
|
|
686
687
|
},
|
|
688
|
+
get initialKey() {
|
|
689
|
+
return tab.initialKey;
|
|
690
|
+
},
|
|
687
691
|
onTab: cycle,
|
|
688
692
|
get onDone() {
|
|
689
693
|
return props.onDone;
|
|
@@ -727,6 +731,7 @@ var createInteractiveSession = async (onCancel = () => {}, initialTabs = []) =>
|
|
|
727
731
|
let quitRequested = false;
|
|
728
732
|
let activeTab = 0;
|
|
729
733
|
let frameTabs = initialTabs;
|
|
734
|
+
const tabSelections = new Map;
|
|
730
735
|
let navigationRequested = false;
|
|
731
736
|
const navigate = (index) => {
|
|
732
737
|
activeTab = index;
|
|
@@ -901,9 +906,16 @@ var createInteractiveSession = async (onCancel = () => {}, initialTabs = []) =>
|
|
|
901
906
|
cancelled = false;
|
|
902
907
|
setNotice(message);
|
|
903
908
|
},
|
|
904
|
-
tabs: (tabs) => {
|
|
905
|
-
frameTabs = tabs
|
|
906
|
-
|
|
909
|
+
tabs: async (tabs) => {
|
|
910
|
+
frameTabs = tabs.map((tab) => ({
|
|
911
|
+
...tab,
|
|
912
|
+
initialKey: tabSelections.get(tab.id)
|
|
913
|
+
}));
|
|
914
|
+
const selected = await ask("", undefined, frameTabs);
|
|
915
|
+
const tab = frameTabs[activeTab];
|
|
916
|
+
if (selected !== null && tab?.choices.some((choice) => choice.key === selected))
|
|
917
|
+
tabSelections.set(tab.id, selected);
|
|
918
|
+
return selected;
|
|
907
919
|
},
|
|
908
920
|
text: (prompt) => ask(prompt),
|
|
909
921
|
select: (prompt, choices) => ask(prompt, choices),
|