@algolia/wizard 0.4.0 → 0.5.0-rc.45.14

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.
Files changed (2) hide show
  1. package/dist/main.js +83 -30
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { render } from "ink";
5
5
 
6
6
  // src/ui/App.tsx
7
- import { Box as Box13, Text as Text13, useApp, useInput as useInput6, useWindowSize as useWindowSize6 } from "ink";
7
+ import { Box as Box13, Text as Text13, useApp, useInput as useInput6, useWindowSize as useWindowSize7 } from "ink";
8
8
 
9
9
  // src/core/store.ts
10
10
  import { create } from "zustand";
@@ -525,10 +525,20 @@ function NextAction({
525
525
  }
526
526
 
527
527
  // src/ui/SelectPrompt.tsx
528
- import { Box as Box4, Text as Text4, useInput } from "ink";
529
- import { useState as useState3 } from "react";
528
+ import { Box as Box4, Text as Text4, measureElement as measureElement2, useInput, useWindowSize as useWindowSize3 } from "ink";
529
+ import { useLayoutEffect, useRef as useRef2, useState as useState3 } from "react";
530
530
  import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
531
531
  var CANCEL = "cancel";
532
+ var ARROW_WIDTH = 4;
533
+ var COLUMN_GAP = 2;
534
+ var BAR_PADDING = 2;
535
+ function fittedWidth(node, columns) {
536
+ let left = 0;
537
+ for (let n = node; n; n = n.parentNode) {
538
+ left += n.yogaNode?.getComputedLeft() ?? 0;
539
+ }
540
+ return Math.max(Math.min(measureElement2(node).width, columns - left), 0);
541
+ }
532
542
  function SelectPrompt({
533
543
  options,
534
544
  onSelect,
@@ -553,12 +563,29 @@ function SelectPrompt({
553
563
  if (rows.length > 1) hints.push({ key: "[\u2191] [\u2193]", label: "move" });
554
564
  if (multi) hints.push({ key: "[space]", label: "select" });
555
565
  hints.push({ key: "[enter]", label: "confirm" });
556
- const labelColWidth = 6 + Math.max(0, ...rows.map((opt) => opt.length));
557
- const secondaryWidth = Math.max(
566
+ const containerRef = useRef2(null);
567
+ const { columns } = useWindowSize3();
568
+ const [width, setWidth] = useState3(columns);
569
+ useLayoutEffect(() => {
570
+ if (containerRef.current) {
571
+ setWidth(fittedWidth(containerRef.current, columns));
572
+ }
573
+ }, [columns]);
574
+ const inner = Math.max(width - BAR_PADDING, 0);
575
+ const labelWidth = Math.min(
576
+ ARROW_WIDTH + (multi ? 2 : 0) + Math.max(0, ...rows.map((opt) => opt.length)) + COLUMN_GAP,
577
+ inner
578
+ );
579
+ const badgeWidth = Math.max(
558
580
  0,
559
- ...rows.map((_, i) => secondary?.[i]?.value.length ?? 0)
581
+ ...rows.map((_, i) => {
582
+ const s = secondary?.[i];
583
+ return s?.kind === "badge" ? s.value.length : 0;
584
+ })
560
585
  );
561
- const rowWidth = labelColWidth + (secondaryWidth ? secondaryWidth + 2 : 0) + 6;
586
+ const barWidth = Math.min(labelWidth + badgeWidth + BAR_PADDING, width);
587
+ const barLabelWidth = Math.max(barWidth - BAR_PADDING - badgeWidth, 0);
588
+ const textWidth = inner - labelWidth;
562
589
  useInput((input, key) => {
563
590
  if (rows.length === 0) return;
564
591
  if (key.upArrow || input === "k") {
@@ -582,7 +609,7 @@ function SelectPrompt({
582
609
  }
583
610
  }
584
611
  });
585
- return /* @__PURE__ */ jsxs3(Box4, { flexDirection: "column", gap: 1, children: [
612
+ return /* @__PURE__ */ jsx4(Box4, { ref: containerRef, flexGrow: 1, children: /* @__PURE__ */ jsxs3(Box4, { flexDirection: "column", gap: 1, width, children: [
586
613
  error && /* @__PURE__ */ jsx4(Text4, { color: COLORS.danger, children: error }),
587
614
  messages?.map((m, i) => /* @__PURE__ */ jsx4(Text4, { color: COLORS.muted, children: m }, `msg-${i}`)),
588
615
  table && /* @__PURE__ */ jsx4(Table, { columns: table.columns, rows: table.rows }),
@@ -596,29 +623,36 @@ function SelectPrompt({
596
623
  const bullet = multi && !isCancel ? checked.has(i) ? "\u25CF " : "\u25CB " : "";
597
624
  const sec = isCancel ? void 0 : secondary?.[i];
598
625
  const labelColor = highlighted ? COLORS.highlight.fg : void 0;
599
- const label = /* @__PURE__ */ jsxs3(Text4, { color: labelColor, children: [
626
+ const label = /* @__PURE__ */ jsxs3(Text4, { color: labelColor, wrap: "truncate", children: [
600
627
  highlighted ? "\u276F " : " ",
601
628
  bullet,
602
629
  option
603
630
  ] });
631
+ const isText = sec?.kind === "text";
604
632
  return /* @__PURE__ */ jsxs3(
605
633
  Box4,
606
634
  {
607
- width: rowWidth,
635
+ width: isText ? "100%" : barWidth,
608
636
  paddingX: 1,
609
637
  paddingY: 1,
610
638
  backgroundColor: highlighted ? COLORS.highlight.bg : void 0,
611
639
  children: [
612
- sec?.kind === "text" ? /* @__PURE__ */ jsx4(Box4, { width: labelColWidth, flexShrink: 0, children: label }) : label,
613
- sec?.kind === "text" && /* @__PURE__ */ jsx4(Text4, { color: highlighted ? COLORS.primary : COLORS.muted, children: sec.value }),
614
- /* @__PURE__ */ jsx4(Box4, { flexGrow: 1 }),
615
- sec?.kind === "badge" && /* @__PURE__ */ jsx4(Text4, { color: COLORS.badge, children: sec.value })
640
+ /* @__PURE__ */ jsx4(Box4, { width: isText ? labelWidth : barLabelWidth, children: label }),
641
+ isText && textWidth > 0 && /* @__PURE__ */ jsx4(Box4, { width: textWidth, children: /* @__PURE__ */ jsx4(
642
+ Text4,
643
+ {
644
+ wrap: "truncate",
645
+ color: highlighted ? COLORS.primary : COLORS.muted,
646
+ children: sec.value
647
+ }
648
+ ) }),
649
+ sec?.kind === "badge" && /* @__PURE__ */ jsx4(Box4, { width: badgeWidth, justifyContent: "flex-end", children: /* @__PURE__ */ jsx4(Text4, { color: COLORS.badge, wrap: "truncate", children: sec.value }) })
616
650
  ]
617
651
  },
618
652
  `row-${i}`
619
653
  );
620
654
  }) }),
621
- /* @__PURE__ */ jsx4(Box4, { children: hints.map(({ key, label }, i) => /* @__PURE__ */ jsxs3(Text4, { children: [
655
+ /* @__PURE__ */ jsx4(Text4, { children: hints.map(({ key, label }, i) => /* @__PURE__ */ jsxs3(Text4, { children: [
622
656
  i > 0 ? " " : "",
623
657
  /* @__PURE__ */ jsx4(Text4, { color: COLORS.primary, children: key }),
624
658
  /* @__PURE__ */ jsxs3(Text4, { color: COLORS.dim, children: [
@@ -626,7 +660,7 @@ function SelectPrompt({
626
660
  label
627
661
  ] })
628
662
  ] }, label)) })
629
- ] });
663
+ ] }) });
630
664
  }
631
665
 
632
666
  // src/ui/PromptInput.tsx
@@ -749,7 +783,7 @@ function PromptInput() {
749
783
  // src/ui/Welcome.tsx
750
784
  import { dirname as dirname2, join as join3 } from "node:path";
751
785
  import { fileURLToPath } from "node:url";
752
- import { Box as Box6, Spacer, Text as Text6, useInput as useInput3, useWindowSize as useWindowSize3 } from "ink";
786
+ import { Box as Box6, Spacer, Text as Text6, useInput as useInput3, useWindowSize as useWindowSize4 } from "ink";
753
787
 
754
788
  // src/ui/copy/welcome.ts
755
789
  var sidebarItems = [
@@ -797,7 +831,7 @@ function SidebarItem({
797
831
  function Welcome() {
798
832
  const confirmStart = useWizard((s) => s.confirmStart);
799
833
  const openLearnMore = useWizard((s) => s.openLearnMore);
800
- const { rows } = useWindowSize3();
834
+ const { rows } = useWindowSize4();
801
835
  useInput3((input) => {
802
836
  if (input === " ") confirmStart();
803
837
  else if (input === "i") openLearnMore();
@@ -865,7 +899,7 @@ function Welcome() {
865
899
 
866
900
  // src/ui/LearnMore.tsx
867
901
  import { Fragment as Fragment2 } from "react";
868
- import { Box as Box7, Text as Text7, useInput as useInput4, useWindowSize as useWindowSize4 } from "ink";
902
+ import { Box as Box7, Text as Text7, useInput as useInput4, useWindowSize as useWindowSize5 } from "ink";
869
903
 
870
904
  // src/ui/copy/learn-more.ts
871
905
  var accessIntro = "Everything runs locally on your machine. Nothing is written or sent without an explicit yes from you.";
@@ -929,7 +963,7 @@ function NeverLine({
929
963
  function LearnMore() {
930
964
  const confirmStart = useWizard((s) => s.confirmStart);
931
965
  const backToHome = useWizard((s) => s.backToHome);
932
- const { columns } = useWindowSize4();
966
+ const { columns } = useWindowSize5();
933
967
  const dividerWidth = Math.max(0, columns - PADDING_X * 2);
934
968
  useInput4((input, key) => {
935
969
  if (key.escape) backToHome();
@@ -1142,8 +1176,8 @@ function Ribbon() {
1142
1176
  import { useState as useState6 } from "react";
1143
1177
 
1144
1178
  // src/ui/Logs.tsx
1145
- import { useLayoutEffect, useRef as useRef2, useState as useState5 } from "react";
1146
- import { Box as Box12, Text as Text12, measureElement as measureElement2, useInput as useInput5, useWindowSize as useWindowSize5 } from "ink";
1179
+ import { useLayoutEffect as useLayoutEffect2, useRef as useRef3, useState as useState5 } from "react";
1180
+ import { Box as Box12, Text as Text12, measureElement as measureElement3, useInput as useInput5, useWindowSize as useWindowSize6 } from "ink";
1147
1181
  import { jsx as jsx12, jsxs as jsxs11 } from "react/jsx-runtime";
1148
1182
  var KIND_COLOR = {
1149
1183
  tool: COLORS.primary,
@@ -1174,15 +1208,15 @@ function formatTimestamp(ms) {
1174
1208
  }
1175
1209
  function Logs() {
1176
1210
  const logs = useWizard((s) => s.logs);
1177
- const { rows, columns } = useWindowSize5();
1178
- const viewportRef = useRef2(null);
1211
+ const { rows, columns } = useWindowSize6();
1212
+ const viewportRef = useRef3(null);
1179
1213
  const [viewportHeight, setViewportHeight] = useState5(0);
1180
1214
  const [viewportWidth, setViewportWidth] = useState5(0);
1181
1215
  const [scrollOffset, setScrollOffset] = useState5(0);
1182
- const prevMaxOffsetRef = useRef2(0);
1183
- useLayoutEffect(() => {
1216
+ const prevMaxOffsetRef = useRef3(0);
1217
+ useLayoutEffect2(() => {
1184
1218
  if (!viewportRef.current) return;
1185
- const { width, height } = measureElement2(viewportRef.current);
1219
+ const { width, height } = measureElement3(viewportRef.current);
1186
1220
  setViewportHeight(height);
1187
1221
  setViewportWidth(width);
1188
1222
  }, [rows, columns, logs.length === 0]);
@@ -1197,7 +1231,7 @@ function Logs() {
1197
1231
  }
1198
1232
  const capacityAtBottom = logs.length > viewportHeight ? Math.max(viewportHeight - 1, 0) : viewportHeight;
1199
1233
  const maxOffset = Math.max(logs.length - capacityAtBottom, 0);
1200
- useLayoutEffect(() => {
1234
+ useLayoutEffect2(() => {
1201
1235
  const wasAtBottom = scrollOffset >= prevMaxOffsetRef.current;
1202
1236
  prevMaxOffsetRef.current = maxOffset;
1203
1237
  setScrollOffset((o) => wasAtBottom ? maxOffset : Math.min(o, maxOffset));
@@ -1270,7 +1304,7 @@ import { jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
1270
1304
  function App() {
1271
1305
  const { phase, error, homeScreen, currentStepIndex, steps, inputReq } = useWizard();
1272
1306
  const { exit } = useApp();
1273
- const { columns, rows } = useWindowSize6();
1307
+ const { columns, rows } = useWindowSize7();
1274
1308
  const [showLogs, setShowLogs] = useState6(false);
1275
1309
  const finished = phase === "done" || phase === "error";
1276
1310
  const currentStep = steps[currentStepIndex];
@@ -1324,6 +1358,25 @@ function App() {
1324
1358
  width: "100%",
1325
1359
  justifyContent: "space-between",
1326
1360
  children: [
1361
+ /* @__PURE__ */ jsxs12(
1362
+ Box13,
1363
+ {
1364
+ flexDirection: "column",
1365
+ paddingX: 4,
1366
+ paddingY: 2,
1367
+ width: showSidebar ? 70 : "100%",
1368
+ flexGrow: showSidebar ? 1 : 0,
1369
+ children: [
1370
+ /* @__PURE__ */ jsx13(Notices, {}),
1371
+ /* @__PURE__ */ jsx13(PromptInput, {}),
1372
+ phase === "running" && showSidebar && /* @__PURE__ */ jsx13(Box13, { marginTop: 1, children: /* @__PURE__ */ jsx13(CurrentStep, {}) }),
1373
+ phase === "error" && error && /* @__PURE__ */ jsx13(Box13, { marginTop: 1, children: /* @__PURE__ */ jsxs12(Text13, { color: COLORS.status.error, children: [
1374
+ "\u2716 ",
1375
+ error
1376
+ ] }) })
1377
+ ]
1378
+ }
1379
+ ),
1327
1380
  showLogs ? /* @__PURE__ */ jsx13(Logs, {}) : /* @__PURE__ */ jsxs12(Box13, { flexDirection: "column", paddingX: 4, paddingY: 2, width: 70, children: [
1328
1381
  /* @__PURE__ */ jsx13(Notices, {}),
1329
1382
  /* @__PURE__ */ jsx13(PromptInput, {}),
@@ -2648,7 +2701,7 @@ async function runAnalysis(mode, extraInstructions = []) {
2648
2701
  // package.json
2649
2702
  var package_default = {
2650
2703
  name: "@algolia/wizard",
2651
- version: "0.4.0",
2704
+ version: "0.5.0-rc.45.14",
2652
2705
  description: "Magically implement Algolia functionality in your codebase",
2653
2706
  type: "module",
2654
2707
  engines: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.4.0",
3
+ "version": "0.5.0-rc.45.14",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {