@algolia/wizard 0.80.0 → 0.81.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.
Files changed (2) hide show
  1. package/dist/main.js +86 -102
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -2306,7 +2306,7 @@ async function ensureApplication(resumeAppId) {
2306
2306
  // package.json
2307
2307
  var package_default = {
2308
2308
  name: "@algolia/wizard",
2309
- version: "0.80.0",
2309
+ version: "0.81.0",
2310
2310
  description: "Magically implement Algolia functionality in your codebase",
2311
2311
  type: "module",
2312
2312
  engines: {
@@ -6435,17 +6435,12 @@ var defaultWorkflow = {
6435
6435
  id: "default",
6436
6436
  title: "Default Workflow",
6437
6437
  description: "This workflow explores your repo and implements Algolia on your behalf",
6438
+ tips: true,
6438
6439
  steps: [
6439
6440
  defineStep({
6440
6441
  id: "project-scan",
6441
6442
  title: "project scan",
6442
6443
  outputSchema: projectScanSchema,
6443
- tips: [
6444
- "apps-and-indices",
6445
- "records-are-json",
6446
- "speed",
6447
- "searchable-attributes"
6448
- ],
6449
6444
  run: (ctx) => {
6450
6445
  ctx.notify({
6451
6446
  messages: [
@@ -6481,7 +6476,6 @@ var defaultWorkflow = {
6481
6476
  id: "ingestion",
6482
6477
  title: "ingest records",
6483
6478
  outputSchema: implementSchema,
6484
- tips: ["facets", "test-relevance", "search-analytics", "recommend"],
6485
6479
  run: (ctx) => {
6486
6480
  ctx.notify({
6487
6481
  messages: [
@@ -6502,7 +6496,6 @@ var defaultWorkflow = {
6502
6496
  id: "search",
6503
6497
  title: "create search ui",
6504
6498
  outputSchema: implementSchema,
6505
- tips: ["typo-tolerance", "synonyms", "multi-index-search", "rules"],
6506
6499
  run: (ctx) => {
6507
6500
  ctx.notify({
6508
6501
  messages: ["Building your Algolia search experience\u2026"]
@@ -6513,6 +6506,7 @@ var defaultWorkflow = {
6513
6506
  defineStep({
6514
6507
  id: "review",
6515
6508
  title: "done",
6509
+ hideTips: true,
6516
6510
  outputSchema: reviewSchema,
6517
6511
  run: (ctx) => {
6518
6512
  ctx.notify({
@@ -7175,7 +7169,6 @@ var playbookWorkflow = {
7175
7169
  id: "select-index",
7176
7170
  title: "Select index",
7177
7171
  outputSchema: selectIndexSchema,
7178
- tips: ["apps-and-indices", "records-are-json", "speed"],
7179
7172
  run: (ctx) => selectIndexStep2(ctx)
7180
7173
  }),
7181
7174
  defineStep({
@@ -7183,7 +7176,6 @@ var playbookWorkflow = {
7183
7176
  title: "Confirm sample index creation",
7184
7177
  outputSchema: confirmIndexSchema,
7185
7178
  visible: false,
7186
- tips: ["apps-and-indices", "records-are-json", "speed"],
7187
7179
  run: (ctx) => confirmIndexStep(ctx)
7188
7180
  }),
7189
7181
  defineStep({
@@ -7788,7 +7780,6 @@ function Code({ children }) {
7788
7780
  // src/ui/copy/tips.ts
7789
7781
  var tips = [
7790
7782
  {
7791
- id: "apps-and-indices",
7792
7783
  title: "An Application is like your library. Indices are the books in it.",
7793
7784
  chunks: [
7794
7785
  {
@@ -7802,7 +7793,6 @@ var tips = [
7802
7793
  ]
7803
7794
  },
7804
7795
  {
7805
- id: "records-are-json",
7806
7796
  title: "A Record is a JSON object inside of an index.",
7807
7797
  chunks: [
7808
7798
  {
@@ -7836,7 +7826,6 @@ var tips = [
7836
7826
  ]
7837
7827
  },
7838
7828
  {
7839
- id: "speed",
7840
7829
  title: "Speed isn't a feature, it's our business",
7841
7830
  chunks: [
7842
7831
  {
@@ -7850,7 +7839,6 @@ var tips = [
7850
7839
  ]
7851
7840
  },
7852
7841
  {
7853
- id: "searchable-attributes",
7854
7842
  title: "Searchable attributes are your relevance dial #1",
7855
7843
  chunks: [
7856
7844
  {
@@ -7866,7 +7854,6 @@ var tips = [
7866
7854
  ]
7867
7855
  },
7868
7856
  {
7869
- id: "facets",
7870
7857
  title: "Facets aren't just filters, they help build your UI",
7871
7858
  chunks: [
7872
7859
  { type: "codeword", value: "attributesForFaceting" },
@@ -7877,7 +7864,6 @@ var tips = [
7877
7864
  ]
7878
7865
  },
7879
7866
  {
7880
- id: "test-relevance",
7881
7867
  title: "Test relevance in the dashboard before you write a line of ranking code",
7882
7868
  chunks: [
7883
7869
  {
@@ -7896,7 +7882,6 @@ var tips = [
7896
7882
  ]
7897
7883
  },
7898
7884
  {
7899
- id: "search-analytics",
7900
7885
  title: "Search Analytics helps you discover opportunities",
7901
7886
  chunks: [
7902
7887
  {
@@ -7910,7 +7895,6 @@ var tips = [
7910
7895
  ]
7911
7896
  },
7912
7897
  {
7913
- id: "typo-tolerance",
7914
7898
  title: "Your users will misspell things. Algolia already handles it.",
7915
7899
  chunks: [
7916
7900
  {
@@ -7924,7 +7908,6 @@ var tips = [
7924
7908
  ]
7925
7909
  },
7926
7910
  {
7927
- id: "synonyms",
7928
7911
  title: "Synonyms teach the engine your words",
7929
7912
  chunks: [
7930
7913
  {
@@ -7942,7 +7925,6 @@ var tips = [
7942
7925
  ]
7943
7926
  },
7944
7927
  {
7945
- id: "multi-index-search",
7946
7928
  title: "One search box, many indices",
7947
7929
  chunks: [
7948
7930
  {
@@ -7956,7 +7938,6 @@ var tips = [
7956
7938
  ]
7957
7939
  },
7958
7940
  {
7959
- id: "rules",
7960
7941
  title: "Rules let you put a thumb on the scale",
7961
7942
  chunks: [
7962
7943
  {
@@ -7974,7 +7955,6 @@ var tips = [
7974
7955
  ]
7975
7956
  },
7976
7957
  {
7977
- id: "recommend",
7978
7958
  title: "Let Algolia act as your recommendation engine",
7979
7959
  chunks: [
7980
7960
  {
@@ -7988,18 +7968,12 @@ var tips = [
7988
7968
  ]
7989
7969
  }
7990
7970
  ];
7991
- var tipsById = Object.fromEntries(
7992
- tips.map((tip) => [tip.id, tip])
7993
- );
7994
- function tipsByIds(ids) {
7995
- return ids.map((id) => tipsById[id]).filter((tip) => tip !== void 0);
7996
- }
7997
7971
 
7998
7972
  // src/ui/Tips.tsx
7999
7973
  import { jsx as jsx20, jsxs as jsxs19 } from "react/jsx-runtime";
8000
7974
  var TICK_MS = 16;
8001
7975
  var CHUNK_HOLD_MS = 2e3;
8002
- var HOLD_MS = 12e3;
7976
+ var TIP_DURATION_MS = 25e3;
8003
7977
  function TipTitle({ children }) {
8004
7978
  return /* @__PURE__ */ jsxs19(Box21, { gap: 1, children: [
8005
7979
  /* @__PURE__ */ jsx20(Text22, { color: "cyan", children: "\u2726" }),
@@ -8056,45 +8030,53 @@ function TipContent({
8056
8030
  ] }, j)) }, i)
8057
8031
  ) });
8058
8032
  }
8059
- var progress = { stepId: null, tipIndex: 0, revealed: 0 };
8033
+ var noPauseAfterText = [
8034
+ "highlight",
8035
+ "link",
8036
+ "codeword"
8037
+ ];
8038
+ function revealSchedule(tip) {
8039
+ const segments = [
8040
+ { type: "text", value: tip.title },
8041
+ ...tip.chunks
8042
+ ];
8043
+ const schedule = [];
8044
+ let at = 0;
8045
+ segments.forEach((segment, i) => {
8046
+ for (let c = 0; c < segment.value.length; c++) {
8047
+ const pause = i > 0 && c === 0 && !noPauseAfterText.includes(segment.type);
8048
+ at += pause ? CHUNK_HOLD_MS : TICK_MS;
8049
+ schedule.push(at);
8050
+ }
8051
+ });
8052
+ return schedule;
8053
+ }
8054
+ var clock = { tipIndex: 0, elapsedMs: 0, complete: false };
8060
8055
  function Tips({
8061
- stepId,
8062
- ids,
8063
- onRevealStateChange
8056
+ onRevealStateChange,
8057
+ onComplete
8064
8058
  }) {
8065
- const tips2 = tipsByIds(ids);
8066
- const resuming = progress.stepId === stepId;
8067
- if (!resuming) {
8068
- progress.stepId = stepId;
8069
- progress.tipIndex = 0;
8070
- progress.revealed = 0;
8071
- }
8072
- const [tipIndex, setTipIndex] = useState11(resuming ? progress.tipIndex : 0);
8073
- const [revealed, setRevealed] = useState11(resuming ? progress.revealed : 0);
8074
- const tip = tips2.length > 0 ? tips2[tipIndex % tips2.length] : void 0;
8075
- const contentLength = tip?.chunks.reduce((sum, c) => sum + c.value.length, 0) ?? 0;
8076
- const totalLength = (tip?.title.length ?? 0) + contentLength;
8077
- const segments = tip ? [
8078
- { type: "title", length: tip.title.length },
8079
- ...tip.chunks.map((c) => ({ type: c.type, length: c.value.length }))
8080
- ] : [];
8081
- const noPauseAfterText = [
8082
- "highlight",
8083
- "link",
8084
- "codeword"
8085
- ];
8086
- const chunkBoundaries = [];
8087
- let cumulative = 0;
8088
- for (let i = 0; i < segments.length - 1; i++) {
8089
- cumulative += segments[i].length;
8090
- const skipPause = noPauseAfterText.includes(
8091
- segments[i + 1].type
8092
- );
8093
- if (!skipPause) chunkBoundaries.push(cumulative);
8094
- }
8095
- const revealState = tips2.length === 0 ? "idle" : revealed < totalLength ? "revealing" : "revealed";
8059
+ const [position, setPosition] = useState11(() => {
8060
+ const now = Date.now();
8061
+ return {
8062
+ tipIndex: clock.tipIndex,
8063
+ startedAt: now - clock.elapsedMs,
8064
+ now,
8065
+ complete: clock.complete
8066
+ };
8067
+ });
8068
+ const tip = tips[position.tipIndex];
8069
+ const elapsedMs = position.now - position.startedAt;
8070
+ const schedule = revealSchedule(tip);
8071
+ const revealed = schedule.filter((at) => at <= elapsedMs).length;
8072
+ const fullyTyped = revealed === schedule.length;
8073
+ const nextAt = fullyTyped ? TIP_DURATION_MS : schedule[revealed];
8074
+ const midSentence = !fullyTyped && revealed > 0 && nextAt - schedule[revealed - 1] === TICK_MS;
8075
+ const revealState = position.complete ? "idle" : midSentence ? "typing" : "resting";
8096
8076
  const onRevealStateChangeRef = useRef4(onRevealStateChange);
8097
8077
  onRevealStateChangeRef.current = onRevealStateChange;
8078
+ const onCompleteRef = useRef4(onComplete);
8079
+ onCompleteRef.current = onComplete;
8098
8080
  const reportedRef = useRef4(null);
8099
8081
  useEffect3(() => {
8100
8082
  if (reportedRef.current === revealState) return;
@@ -8103,30 +8085,35 @@ function Tips({
8103
8085
  }, [revealState]);
8104
8086
  useEffect3(() => () => onRevealStateChangeRef.current?.("idle"), []);
8105
8087
  useEffect3(() => {
8106
- if (tips2.length === 0) return;
8107
- if (revealed < totalLength) {
8108
- const delay2 = chunkBoundaries.includes(revealed) ? CHUNK_HOLD_MS : TICK_MS;
8109
- const timer2 = setTimeout(() => {
8110
- setRevealed((r) => {
8111
- const next = r + 1;
8112
- progress.revealed = next;
8113
- return next;
8114
- });
8115
- }, delay2);
8116
- return () => clearTimeout(timer2);
8088
+ if (position.complete) {
8089
+ onCompleteRef.current?.();
8090
+ return;
8117
8091
  }
8118
8092
  const timer = setTimeout(() => {
8119
- setTipIndex((i) => {
8120
- const next = (i + 1) % tips2.length;
8121
- progress.tipIndex = next;
8122
- return next;
8123
- });
8124
- setRevealed(0);
8125
- progress.revealed = 0;
8126
- }, HOLD_MS);
8127
- return () => clearTimeout(timer);
8128
- }, [revealed, totalLength, tips2.length]);
8129
- if (!tip) return null;
8093
+ const now = Date.now();
8094
+ const tipComplete = now - position.startedAt >= TIP_DURATION_MS;
8095
+ if (tipComplete && position.tipIndex === tips.length - 1) {
8096
+ clock.complete = true;
8097
+ setPosition({ ...position, now, complete: true });
8098
+ return;
8099
+ }
8100
+ setPosition(
8101
+ tipComplete ? {
8102
+ tipIndex: position.tipIndex + 1,
8103
+ startedAt: now,
8104
+ now,
8105
+ complete: false
8106
+ } : { ...position, now }
8107
+ );
8108
+ }, nextAt - elapsedMs);
8109
+ return () => {
8110
+ clearTimeout(timer);
8111
+ if (clock.complete) return;
8112
+ clock.tipIndex = position.tipIndex;
8113
+ clock.elapsedMs = Date.now() - position.startedAt;
8114
+ };
8115
+ }, [position, nextAt, elapsedMs]);
8116
+ if (position.complete) return null;
8130
8117
  const titleRevealed = tip.title.slice(0, revealed);
8131
8118
  const contentRevealed = Math.max(0, revealed - tip.title.length);
8132
8119
  return /* @__PURE__ */ jsxs19(Box21, { flexDirection: "column", marginBottom: 1, gap: 1, children: [
@@ -8194,17 +8181,16 @@ function App() {
8194
8181
  const compactRun = isCompactTerminal(columns, rows);
8195
8182
  const [showLogs, setShowLogs] = useState12(false);
8196
8183
  const [tipState, setTipState] = useState12("idle");
8184
+ const [tipsComplete, setTipsComplete] = useState12(false);
8197
8185
  const finished = phase === "done" || phase === "error";
8198
8186
  const currentStep = steps[currentStepIndex];
8199
- const stepDef = workflow ? getWorkflow(workflow.id)?.steps.find((s) => s.id === currentStep?.id) : void 0;
8200
- const tipIds = stepDef?.tips ?? [];
8201
- const stepHasTips = tipIds.length > 0;
8187
+ const workflowDef = workflow ? getWorkflow(workflow.id) : void 0;
8188
+ const stepHidesTips = workflowDef?.steps.find((s) => s.id === currentStep?.id)?.hideTips === true;
8189
+ const tipsActive = workflowDef?.tips === true && !tipsComplete && !stepHidesTips;
8202
8190
  const isAwaitingUserInput = phase === "awaitingInput" && !!inputReq;
8203
- const isCommandApprovalPrompt = isAwaitingUserInput && inputReq?.promptType === "commandApproval";
8204
- const promptPending = isAwaitingUserInput && !isCommandApprovalPrompt;
8205
- const holdForTip = !compactRun && stepHasTips && promptPending && tipState === "revealing";
8206
- const showTips = !compactRun && stepHasTips && (phase === "running" && currentStep?.status === "running" && !loadingMessage && !settingUpAppId || isCommandApprovalPrompt);
8207
- const showNoticesInMain = !stepHasTips;
8191
+ const holdForTip = !compactRun && tipsActive && isAwaitingUserInput && tipState === "typing";
8192
+ const showTips = !compactRun && tipsActive && (phase === "running" && currentStep?.status === "running" && !loadingMessage && !settingUpAppId || holdForTip);
8193
+ const showNoticesInMain = !tipsActive;
8208
8194
  const showNotices = !compactRun && (!isAwaitingUserInput || holdForTip) && !review2;
8209
8195
  useInput9(
8210
8196
  (_input, key) => {
@@ -8299,12 +8285,11 @@ function App() {
8299
8285
  loadingMessage
8300
8286
  ] }) }),
8301
8287
  /* @__PURE__ */ jsx21(CliOutput, {}),
8302
- showTips && currentStep && /* @__PURE__ */ jsx21(
8288
+ showTips && /* @__PURE__ */ jsx21(
8303
8289
  Tips,
8304
8290
  {
8305
- stepId: currentStep.id,
8306
- ids: tipIds,
8307
- onRevealStateChange: setTipState
8291
+ onRevealStateChange: setTipState,
8292
+ onComplete: () => setTipsComplete(true)
8308
8293
  }
8309
8294
  ),
8310
8295
  showNoticesInMain && showNotices && /* @__PURE__ */ jsx21(Notices, { showAll: true, border: false }),
@@ -8315,8 +8300,7 @@ function App() {
8315
8300
  error
8316
8301
  ] }) })
8317
8302
  ] }),
8318
- !showNoticesInMain && showNotices && /* @__PURE__ */ jsx21(Notices, {}),
8319
- showTips && !holdForTip && /* @__PURE__ */ jsx21(PromptInput, {})
8303
+ !showNoticesInMain && showNotices && /* @__PURE__ */ jsx21(Notices, {})
8320
8304
  ]
8321
8305
  }
8322
8306
  ),
@@ -8563,7 +8547,7 @@ async function resetProjectState() {
8563
8547
  // package.json with { type: 'json' }
8564
8548
  var package_default2 = {
8565
8549
  name: "@algolia/wizard",
8566
- version: "0.80.0",
8550
+ version: "0.81.0",
8567
8551
  description: "Magically implement Algolia functionality in your codebase",
8568
8552
  type: "module",
8569
8553
  engines: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.80.0",
3
+ "version": "0.81.0",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {