MCPcopy
hub / github.com/nilbuild/driver.js / drive

Function drive

src/driver.ts:240–315  ·  view source on GitHub ↗
(stepIndex: number = 0)

Source from the content-addressed store, hash-verified

238 }
239
240 function drive(stepIndex: number = 0) {
241 const steps = getConfig("steps");
242 if (!steps) {
243 console.error("No steps to drive through");
244 destroy();
245 return;
246 }
247
248 if (!steps[stepIndex]) {
249 destroy();
250
251 return;
252 }
253
254 setState("__activeOnDestroyed", document.activeElement as HTMLElement);
255 setState("activeIndex", stepIndex);
256
257 const currentStep = steps[stepIndex];
258 const hasNextStep = steps[stepIndex + 1];
259 const hasPreviousStep = steps[stepIndex - 1];
260
261 const doneBtnText = currentStep.popover?.doneBtnText || getConfig("doneBtnText") || "Done";
262 const allowsClosing = getConfig("allowClose");
263 const showProgress =
264 typeof currentStep.popover?.showProgress !== "undefined"
265 ? currentStep.popover?.showProgress
266 : getConfig("showProgress");
267 const progressText = currentStep.popover?.progressText || getConfig("progressText") || "{{current}} of {{total}}";
268 const progressTextReplaced = progressText
269 .replace("{{current}}", `${stepIndex + 1}`)
270 .replace("{{total}}", `${steps.length}`);
271
272 const configuredButtons = currentStep.popover?.showButtons || getConfig("showButtons");
273 const calculatedButtons: AllowedButtons[] = [
274 "next",
275 "previous",
276 ...(allowsClosing ? ["close" as AllowedButtons] : []),
277 ].filter(b => {
278 return !configuredButtons?.length || configuredButtons.includes(b as AllowedButtons);
279 }) as AllowedButtons[];
280
281 const onNextClick = currentStep.popover?.onNextClick || getConfig("onNextClick");
282 const onPrevClick = currentStep.popover?.onPrevClick || getConfig("onPrevClick");
283 const onCloseClick = currentStep.popover?.onCloseClick || getConfig("onCloseClick");
284
285 highlight({
286 ...currentStep,
287 popover: {
288 showButtons: calculatedButtons,
289 nextBtnText: !hasNextStep ? doneBtnText : undefined,
290 disableButtons: [...(!hasPreviousStep ? ["previous" as AllowedButtons] : [])],
291 showProgress: showProgress,
292 onNextClick: onNextClick
293 ? onNextClick
294 : () => {
295 if (!hasNextStep) {
296 destroy();
297 } else {

Callers 4

moveNextFunction · 0.85
movePreviousFunction · 0.85
moveToFunction · 0.85
driverFunction · 0.85

Calls 4

getConfigFunction · 0.90
setStateFunction · 0.90
highlightFunction · 0.90
destroyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…