@aladinbs/react-guided-tour 1.0.2 → 1.1.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 (39) hide show
  1. package/README.md +103 -1
  2. package/dist/components/ErrorBoundary.d.ts +31 -0
  3. package/dist/components/ErrorBoundary.d.ts.map +1 -0
  4. package/dist/components/Toast.d.ts +14 -0
  5. package/dist/components/Toast.d.ts.map +1 -0
  6. package/dist/components/ToastProvider.d.ts +28 -0
  7. package/dist/components/ToastProvider.d.ts.map +1 -0
  8. package/dist/components/TourOverlay.d.ts +2 -1
  9. package/dist/components/TourOverlay.d.ts.map +1 -1
  10. package/dist/components/TourPopover.d.ts +2 -1
  11. package/dist/components/TourPopover.d.ts.map +1 -1
  12. package/dist/components/TourProvider.d.ts +10 -2
  13. package/dist/components/TourProvider.d.ts.map +1 -1
  14. package/dist/components/TourRunner.d.ts +2 -1
  15. package/dist/components/TourRunner.d.ts.map +1 -1
  16. package/dist/core/TourActions.d.ts +10 -0
  17. package/dist/core/TourActions.d.ts.map +1 -1
  18. package/dist/core/TourEngine.d.ts +32 -0
  19. package/dist/core/TourEngine.d.ts.map +1 -1
  20. package/dist/hooks/useErrorHandler.d.ts +26 -0
  21. package/dist/hooks/useErrorHandler.d.ts.map +1 -0
  22. package/dist/hooks/useToastErrorHandler.d.ts +15 -0
  23. package/dist/hooks/useToastErrorHandler.d.ts.map +1 -0
  24. package/dist/hooks/useTourEngine.d.ts +4 -0
  25. package/dist/hooks/useTourEngine.d.ts.map +1 -1
  26. package/dist/hooks/useTourHighlight.d.ts +4 -0
  27. package/dist/hooks/useTourHighlight.d.ts.map +1 -1
  28. package/dist/index.d.ts +140 -6
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.esm.js +617 -144
  31. package/dist/index.esm.js.map +1 -1
  32. package/dist/index.js +641 -163
  33. package/dist/index.js.map +1 -1
  34. package/dist/integrations/TabIntegration.d.ts.map +1 -1
  35. package/dist/types/index.d.ts +7 -0
  36. package/dist/types/index.d.ts.map +1 -1
  37. package/dist/utils/positioning.d.ts +13 -0
  38. package/dist/utils/positioning.d.ts.map +1 -1
  39. package/package.json +1 -2
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import React$1, { ReactNode, Component } from 'react';
1
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
3
3
 
4
4
  interface TourStep {
5
5
  id: string;
@@ -15,6 +15,8 @@ interface TourStep {
15
15
  canSkip?: boolean;
16
16
  waitForElement?: boolean;
17
17
  waitTimeout?: number;
18
+ blockInteractions?: boolean;
19
+ clickToAdvance?: boolean;
18
20
  }
19
21
  interface TourAction {
20
22
  type: 'click' | 'navigate' | 'highlight' | 'tab-switch' | 'wizard-step' | 'custom';
@@ -52,6 +54,8 @@ interface TourConfig {
52
54
  onStepChange?: (step: TourStep, index: number) => void;
53
55
  allowKeyboardNavigation?: boolean;
54
56
  allowClickOutside?: boolean;
57
+ blockInteractions?: boolean;
58
+ clickToAdvance?: boolean;
55
59
  showProgress?: boolean;
56
60
  storage?: {
57
61
  key?: string;
@@ -120,6 +124,9 @@ interface TourEngineEvents {
120
124
  'error': {
121
125
  error: Error;
122
126
  step?: TourStep;
127
+ tourId?: string;
128
+ stepIndex?: number;
129
+ timestamp?: string;
123
130
  };
124
131
  'state-change': TourState;
125
132
  }
@@ -138,6 +145,10 @@ interface PopoverPosition {
138
145
  placement: 'top' | 'bottom' | 'left' | 'right' | 'center';
139
146
  }
140
147
 
148
+ /**
149
+ * Core tour engine that manages tour state, navigation, and lifecycle.
150
+ * Handles step progression, state persistence, and event emission.
151
+ */
141
152
  declare class TourEngine {
142
153
  private config;
143
154
  private state;
@@ -147,11 +158,29 @@ declare class TourEngine {
147
158
  private initializeState;
148
159
  getState(): TourState;
149
160
  getConfig(): TourConfig;
161
+ /**
162
+ * Starts the tour from the current step index.
163
+ */
150
164
  start(): Promise<void>;
165
+ /**
166
+ * Advances to the next step in the tour.
167
+ */
151
168
  next(): Promise<void>;
169
+ /**
170
+ * Goes back to the previous step in the tour.
171
+ */
152
172
  previous(): Promise<void>;
173
+ /**
174
+ * Navigates to a specific step by index.
175
+ */
153
176
  goToStep(index: number): Promise<void>;
177
+ /**
178
+ * Skips the current tour and marks it as skipped.
179
+ */
154
180
  skip(): Promise<void>;
181
+ /**
182
+ * Completes the tour and marks it as finished.
183
+ */
155
184
  complete(): Promise<void>;
156
185
  stop(): Promise<void>;
157
186
  getCurrentStep(): TourStep | null;
@@ -159,7 +188,13 @@ declare class TourEngine {
159
188
  isLastStep(): boolean;
160
189
  canGoNext(): boolean;
161
190
  canGoPrevious(): boolean;
191
+ /**
192
+ * Determines if the tour should be shown based on completion/skip state.
193
+ */
162
194
  shouldShowTour(): boolean;
195
+ /**
196
+ * Resets tour state and clears localStorage.
197
+ */
163
198
  resetTourState(): void;
164
199
  private waitForElement;
165
200
  private markStepCompleted;
@@ -169,15 +204,29 @@ declare class TourEngine {
169
204
  on<K extends keyof TourEngineEvents>(event: K, callback: TourEventCallback<TourEngineEvents[K]>): void;
170
205
  off<K extends keyof TourEngineEvents>(event: K, callback: TourEventCallback<TourEngineEvents[K]>): void;
171
206
  private emit;
207
+ /**
208
+ * Subscribes to tour state changes.
209
+ * Returns an unsubscribe function.
210
+ */
172
211
  subscribe(callback: (state: TourState) => void): () => void;
173
212
  }
174
213
 
214
+ /**
215
+ * Manages and executes tour actions with pluggable integration support.
216
+ * Handles clicks, navigation, and custom actions through registered integrations.
217
+ */
175
218
  declare class TourActions {
176
219
  private integrations;
177
220
  registerIntegration(integration: Integration): void;
178
221
  unregisterIntegration(name: string): void;
222
+ /**
223
+ * Executes a tour action using the appropriate integration or default handler.
224
+ */
179
225
  execute(action: TourAction, element?: HTMLElement): Promise<void>;
180
226
  private findIntegration;
227
+ /**
228
+ * Default action handler for built-in action types.
229
+ */
181
230
  private executeDefault;
182
231
  private handleClick;
183
232
  private handleNavigate;
@@ -215,6 +264,10 @@ interface UseTourEngineReturn {
215
264
  engine: TourEngine;
216
265
  actions: TourActions;
217
266
  }
267
+ /**
268
+ * Hook that creates and manages a tour engine instance.
269
+ * Provides tour control methods and state management with error handling.
270
+ */
218
271
  declare function useTourEngine(config: TourConfig): UseTourEngineReturn;
219
272
 
220
273
  interface TourContextValue extends UseTourEngineReturn {
@@ -225,31 +278,99 @@ interface TourProviderProps {
225
278
  config: TourConfig;
226
279
  children: ReactNode;
227
280
  }
228
- declare function TourProvider({ config, children }: TourProviderProps): react_jsx_runtime.JSX.Element;
281
+ /**
282
+ * Main provider component that initializes the tour system and provides context.
283
+ * Wraps the application with tour functionality.
284
+ */
285
+ declare const TourProvider: React$1.NamedExoticComponent<TourProviderProps>;
286
+ /**
287
+ * Hook to access tour functionality and state.
288
+ * Must be used within a TourProvider.
289
+ */
229
290
  declare function useTour(): TourContextValue;
230
291
 
231
292
  interface TourRunnerProps {
232
293
  className?: string;
233
294
  }
234
- declare function TourRunner({ className }: TourRunnerProps): react_jsx_runtime.JSX.Element | null;
295
+ declare const TourRunner: React$1.NamedExoticComponent<TourRunnerProps>;
235
296
 
236
297
  interface TourOverlayProps {
237
298
  className?: string;
238
299
  }
239
- declare function TourOverlay({ className }: TourOverlayProps): react_jsx_runtime.JSX.Element | null;
300
+ declare const TourOverlay: React$1.NamedExoticComponent<TourOverlayProps>;
240
301
 
241
302
  interface TourPopoverProps {
242
303
  className?: string;
243
304
  }
244
- declare function TourPopover({ className }: TourPopoverProps): react_jsx_runtime.JSX.Element | null;
305
+ declare const TourPopover: React$1.NamedExoticComponent<TourPopoverProps>;
306
+
307
+ interface ErrorInfo {
308
+ componentStack: string;
309
+ errorBoundary?: string;
310
+ errorBoundaryStack?: string;
311
+ }
312
+ interface ErrorBoundaryState {
313
+ hasError: boolean;
314
+ error: Error | null;
315
+ errorInfo: ErrorInfo | null;
316
+ }
317
+ interface ErrorBoundaryProps {
318
+ children: ReactNode;
319
+ fallback?: (error: Error, errorInfo: ErrorInfo, retry: () => void) => ReactNode;
320
+ onError?: (error: Error, errorInfo: ErrorInfo) => void;
321
+ isolate?: boolean;
322
+ }
323
+ declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
324
+ private retryTimeoutId;
325
+ constructor(props: ErrorBoundaryProps);
326
+ static getDerivedStateFromError(error: Error): Partial<ErrorBoundaryState>;
327
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
328
+ componentWillUnmount(): void;
329
+ retry: () => void;
330
+ render(): string | number | boolean | Iterable<React$1.ReactNode> | react_jsx_runtime.JSX.Element | null | undefined;
331
+ }
332
+ declare function withErrorBoundary<P extends object>(Component: React$1.ComponentType<P>, errorBoundaryProps?: Omit<ErrorBoundaryProps, 'children'>): {
333
+ (props: P): react_jsx_runtime.JSX.Element;
334
+ displayName: string;
335
+ };
245
336
 
246
337
  interface UseTourHighlightReturn {
247
338
  targetElement: HTMLElement | null;
248
339
  highlightStyle: React.CSSProperties;
249
340
  isVisible: boolean;
250
341
  }
342
+ /**
343
+ * Hook that manages element highlighting for tour steps.
344
+ * Finds target elements, positions highlights, and handles dynamic content.
345
+ */
251
346
  declare function useTourHighlight(step: TourStep | null): UseTourHighlightReturn;
252
347
 
348
+ interface ErrorHandlerOptions {
349
+ onError?: (error: Error, context?: string) => void;
350
+ logErrors?: boolean;
351
+ retryAttempts?: number;
352
+ retryDelay?: number;
353
+ }
354
+ interface UseErrorHandlerReturn {
355
+ handleError: (error: Error, context?: string) => void;
356
+ handleAsyncError: <T>(asyncFn: () => Promise<T>, context?: string, fallback?: T) => Promise<T | undefined>;
357
+ wrapFunction: <T extends (...args: unknown[]) => unknown>(fn: T, context?: string) => T;
358
+ wrapAsyncFunction: <T extends (...args: unknown[]) => Promise<unknown>>(fn: T, context?: string) => T;
359
+ }
360
+ declare function useErrorHandler(options?: ErrorHandlerOptions): UseErrorHandlerReturn;
361
+ declare function createSafeAsyncOperation<T>(operation: () => Promise<T>, options?: {
362
+ context?: string;
363
+ fallback?: T;
364
+ onError?: (error: Error) => void;
365
+ retryAttempts?: number;
366
+ retryDelay?: number;
367
+ }): () => Promise<T | undefined>;
368
+ declare function useErrorBoundary(): {
369
+ handleError: (error: Error, _errorInfo?: {
370
+ componentStack: string;
371
+ }) => never;
372
+ };
373
+
253
374
  declare class TabIntegration implements Integration {
254
375
  name: string;
255
376
  canHandle(action: TourAction): boolean;
@@ -313,14 +434,27 @@ declare class NavigationIntegration implements Integration {
313
434
  private waitForNavigation;
314
435
  }
315
436
 
437
+ /**
438
+ * Gets the absolute position of an element relative to the document.
439
+ */
316
440
  declare function getElementPosition(element: HTMLElement): ElementPosition;
441
+ /**
442
+ * Calculates the optimal position for a popover relative to a target element.
443
+ * Falls back to alternative placements if the preferred placement doesn't fit.
444
+ */
317
445
  declare function calculatePopoverPosition(targetElement: HTMLElement, popoverElement: HTMLElement, preferredPlacement?: 'top' | 'bottom' | 'left' | 'right' | 'center'): PopoverPosition;
446
+ /**
447
+ * Smoothly scrolls an element into view.
448
+ */
318
449
  declare function scrollToElement(element: HTMLElement, behavior?: ScrollBehavior): void;
450
+ /**
451
+ * Checks if an element is currently visible in the viewport.
452
+ */
319
453
  declare function isElementInViewport(element: HTMLElement): boolean;
320
454
  declare function getViewportCenter(): {
321
455
  x: number;
322
456
  y: number;
323
457
  };
324
458
 
325
- export { NavigationIntegration, TabIntegration, TourActions, TourEngine, TourOverlay, TourPopover, TourProvider, TourRunner, TourStorage, WizardIntegration, calculatePopoverPosition, getElementPosition, getViewportCenter, isElementInViewport, scrollToElement, useTour, useTourEngine, useTourHighlight };
459
+ export { ErrorBoundary, NavigationIntegration, TabIntegration, TourActions, TourEngine, TourOverlay, TourPopover, TourProvider, TourRunner, TourStorage, WizardIntegration, calculatePopoverPosition, createSafeAsyncOperation, getElementPosition, getViewportCenter, isElementInViewport, scrollToElement, useErrorBoundary, useErrorHandler, useTour, useTourEngine, useTourHighlight, withErrorBoundary };
326
460
  export type { ElementPosition, HighlightConfig, Integration, PopoverConfig, PopoverPosition, TourAction, TourConfig, TourEngineEvents, TourEventCallback, TourState, TourStep, TourTheme, UseTourEngineReturn, UseTourHighlightReturn };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAG7E,cAAc,qBAAqB,CAAC;AAGpC,YAAY,EACV,QAAQ,EACR,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,eAAe,GAChB,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,YAAY,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C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