From 6928294983ed95369e299af92714b01800d9250d Mon Sep 17 00:00:00 2001 From: Matt Gibbs Date: Mon, 10 Aug 2015 11:33:46 -0400 Subject: [PATCH 1/7] Added first draft typing for Shepherd Tour library. Not all overloads are fully typed out, but this should provide user with some helpful intellisense and a few compile checks. https://github.com/HubSpot/shepherd/ --- shepherd/shepherd.d.ts | 165 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 shepherd/shepherd.d.ts diff --git a/shepherd/shepherd.d.ts b/shepherd/shepherd.d.ts new file mode 100644 index 000000000..979c7bc81 --- /dev/null +++ b/shepherd/shepherd.d.ts @@ -0,0 +1,165 @@ +declare module shepherd { + + interface ShepherdStatic { + on(eventName, handler, context?): any; + off(eventName, handler?): any; + once(eventName, handler, context?): any; + + activeTour: IShepherdTour; + Tour: IShepherdTour; + } + + interface IShepherdTourOptions { + steps?: IShepherdTourStep[]; + defaults?: IShepherdTourStepOptions; + } + + interface IShepherdTour { + new (options?: IShepherdTourOptions): IShepherdTour + + /** + * Creates a new Step object with options, and returns the Tour object for convenient chaining when creating multiple steps. If you'd like you can also just pass an options hash which includes id as a key. If the options hash doesn't include an id, one will be generated. You can also pass an existing Step instance rather than options, but note that Shepherd does not support a Step being attached to multiple Tours. + */ + addStep(id: string, options: IShepherdTourStepOptions); + addStep(id: string, options: IShepherdTourStep); + + /** + * Return a step with a specific id + */ + getById(id: string): IShepherdTourStep; + + /** + * Advance to the next step, in the order they were added + */ + next(): void; + + /** + * Show the previous step, in the order they were added + */ + back(): void; + + /** + * Trigger cancel on the current step, hiding it without advancing + */ + cancel(): void; + + /** + * Hide the current step + */ + hide(): void; + + /** + * Show the step specified by id (if it's a string), or index (if it's a number) provided. Defaults to the first step. + */ + show(): void; + show(id: number): void; + show(id: string): void; + + /** + * Show the first step and begin the tour + */ + start(): void; + + /** + * Returns the currently shown step + */ + getCurrentStep(): IShepherdTourStep; + + /** + * Bind an event + */ + on(eventName, handler, context?): any; + + /** + * Unbind an event + */ + off(eventName, handler?): any; + + /** + * Bind just the next instance of an event + */ + once(eventName, handler, context?): any; + } + + interface IShepherdTourStep { + /** + * Show this step + */ + show(): void; + + /** + * Hide this step + */ + hide(): void; + + /** + * Hide this step and trigger the cancel event + */ + cancel(): void; + + /** + * Hide this step and trigger the complete event + */ + complete(): void; + + /** + * Scroll to this step's element + */ + scrollTo(): void; + + /** + * Returns true if the step is currently shown + */ + isOpen(): boolean; + + /** + * Remove the element + */ + destroy(): void; + + /** + * Bind an event + */ + on(eventName, handler, context?): any; + + /** + * Unbind an event + */ + off(eventName, handler?): any; + + /** + * Bind just the next instance of an event + */ + once(eventName, handler, context?): any; + } + + interface IShepherdTourStepOptions { + text?: any; + title?: string; + attachTo?: any; + beforeShowPromise?: any; + classes?: any; + buttons?: IShepherdTourButton[]; + advanceOn?: any; + showCancelLink?: boolean; + scrollTo?: boolean; + when?: any; + + // TODO: Tie this in with the tether.d.ts + tetherOptions?: any; + } + + interface IShepherdTourButton { + text: string; + classes: string[]; + action?: any; + events?: any; + } + + interface IShepherdTourAttachProperties { + element: string; + on: string; + } +} + +declare var Shepherd: shepherd.ShepherdStatic; \ No newline at end of file From b39c9aba6fd1d97e47daf20ecf00acc82657371a Mon Sep 17 00:00:00 2001 From: Matt Gibbs Date: Mon, 10 Aug 2015 11:48:03 -0400 Subject: [PATCH 2/7] Added simple test from example. --- shepherd/shepherd-tests.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 shepherd/shepherd-tests.ts diff --git a/shepherd/shepherd-tests.ts b/shepherd/shepherd-tests.ts new file mode 100644 index 000000000..c1692a696 --- /dev/null +++ b/shepherd/shepherd-tests.ts @@ -0,0 +1,16 @@ +/// + +var tour = new Shepherd.Tour({ + defaults: { + classes: 'shepherd-theme-default' + } +}); + +tour.addStep('test-step', { + text: 'This is a test step being added to the test tour', + title: 'Test Step Title', + attachTo: { + element: '#button', + on: 'right' + } +}); From 0038174aaae4c7943ac93ee14ecbdf9540a2c887 Mon Sep 17 00:00:00 2001 From: Matt Gibbs Date: Mon, 10 Aug 2015 13:07:11 -0400 Subject: [PATCH 3/7] Added some typings and explicity typed :any and :void --- shepherd/shepherd.d.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/shepherd/shepherd.d.ts b/shepherd/shepherd.d.ts index 979c7bc81..cd3983a1f 100644 --- a/shepherd/shepherd.d.ts +++ b/shepherd/shepherd.d.ts @@ -1,9 +1,9 @@ declare module shepherd { interface ShepherdStatic { - on(eventName, handler, context?): any; - off(eventName, handler?): any; - once(eventName, handler, context?): any; + on(eventName: string, handler: Function, context?: any): any; + off(eventName: string, handler?: Function): any; + once(eventName: string, handler: Function, context?: any): any; activeTour: IShepherdTour; Tour: IShepherdTour; @@ -20,8 +20,8 @@ /** * Creates a new Step object with options, and returns the Tour object for convenient chaining when creating multiple steps. If you'd like you can also just pass an options hash which includes id as a key. If the options hash doesn't include an id, one will be generated. You can also pass an existing Step instance rather than options, but note that Shepherd does not support a Step being attached to multiple Tours. */ - addStep(id: string, options: IShepherdTourStepOptions); - addStep(id: string, options: IShepherdTourStep); + addStep(id: string, options: IShepherdTourStepOptions): void; + addStep(id: string, options: IShepherdTourStep): void; /** * Return a step with a specific id @@ -68,17 +68,17 @@ /** * Bind an event */ - on(eventName, handler, context?): any; + on(eventName: string, handler: Function, context?: any): any; /** * Unbind an event */ - off(eventName, handler?): any; + off(eventName: string, handler?: Function): any; /** * Bind just the next instance of an event */ - once(eventName, handler, context?): any; + once(eventName: string, handler: Function, context?: any): any; } interface IShepherdTourStep { @@ -120,17 +120,17 @@ /** * Bind an event */ - on(eventName, handler, context?): any; + on(eventName: string, handler: Function, context?: any): any; /** * Unbind an event */ - off(eventName, handler?): any; + off(eventName: string, handler?: Function): any; /** * Bind just the next instance of an event */ - once(eventName, handler, context?): any; + once(eventName: string, handler: Function, context?: any): any; } interface IShepherdTourStepOptions { From cccb1e844f35b156365b7554f1ee59e3693ae4ac Mon Sep 17 00:00:00 2001 From: Matt Gibbs Date: Mon, 10 Aug 2015 13:19:21 -0400 Subject: [PATCH 4/7] Added expected // Type definitions at top of file. --- shepherd/shepherd.d.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shepherd/shepherd.d.ts b/shepherd/shepherd.d.ts index cd3983a1f..789c836b8 100644 --- a/shepherd/shepherd.d.ts +++ b/shepherd/shepherd.d.ts @@ -1,3 +1,8 @@ +// Type definitions for Shepherd v1.1.2 +// Project: http://github.hubspot.com/shepherd/ +// Definitions by: Matt Gibbs +// Definitions: https://github.com/borisyankov/DefinitelyTyped + declare module shepherd { interface ShepherdStatic { @@ -162,4 +167,4 @@ } } -declare var Shepherd: shepherd.ShepherdStatic; \ No newline at end of file +declare var Shepherd: shepherd.ShepherdStatic; From bc9b48d674c154c6afe7898d768cefef63486e5d Mon Sep 17 00:00:00 2001 From: Matt Gibbs Date: Thu, 13 Aug 2015 10:44:49 -0400 Subject: [PATCH 5/7] Renaming shepherd file to be more specific. per pull request comment from @vvakame --- .../shepherd-tests.ts => tether-shepherd/tether-shepherd-tests.ts | 0 shepherd/shepherd.d.ts => tether-shepherd/tether-shepherd.d.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename shepherd/shepherd-tests.ts => tether-shepherd/tether-shepherd-tests.ts (100%) rename shepherd/shepherd.d.ts => tether-shepherd/tether-shepherd.d.ts (100%) diff --git a/shepherd/shepherd-tests.ts b/tether-shepherd/tether-shepherd-tests.ts similarity index 100% rename from shepherd/shepherd-tests.ts rename to tether-shepherd/tether-shepherd-tests.ts diff --git a/shepherd/shepherd.d.ts b/tether-shepherd/tether-shepherd.d.ts similarity index 100% rename from shepherd/shepherd.d.ts rename to tether-shepherd/tether-shepherd.d.ts From d513d36425fc79e50027c2635f16f675eaa1a5e5 Mon Sep 17 00:00:00 2001 From: Matt Gibbs Date: Thu, 13 Aug 2015 10:48:52 -0400 Subject: [PATCH 6/7] Refactored module to be TetherShepherd to avoid collisions --- tether-shepherd/tether-shepherd-tests.ts | 2 +- tether-shepherd/tether-shepherd.d.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tether-shepherd/tether-shepherd-tests.ts b/tether-shepherd/tether-shepherd-tests.ts index c1692a696..48bef675b 100644 --- a/tether-shepherd/tether-shepherd-tests.ts +++ b/tether-shepherd/tether-shepherd-tests.ts @@ -1,4 +1,4 @@ -/// +/// var tour = new Shepherd.Tour({ defaults: { diff --git a/tether-shepherd/tether-shepherd.d.ts b/tether-shepherd/tether-shepherd.d.ts index 789c836b8..46737222a 100644 --- a/tether-shepherd/tether-shepherd.d.ts +++ b/tether-shepherd/tether-shepherd.d.ts @@ -1,9 +1,9 @@ -// Type definitions for Shepherd v1.1.2 +// Type definitions for Tether-Shepherd v1.1.2 // Project: http://github.hubspot.com/shepherd/ // Definitions by: Matt Gibbs // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare module shepherd { +declare module TetherShepherd { interface ShepherdStatic { on(eventName: string, handler: Function, context?: any): any; @@ -167,4 +167,4 @@ } } -declare var Shepherd: shepherd.ShepherdStatic; +declare var Shepherd: TetherShepherd.ShepherdStatic; From 700e5be8e808d8423e26e4ea6d15d9562657e352 Mon Sep 17 00:00:00 2001 From: Matt Gibbs Date: Thu, 13 Aug 2015 10:54:12 -0400 Subject: [PATCH 7/7] Fixed return of addStep addStep returns the Tour for step addition chaining --- tether-shepherd/tether-shepherd.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tether-shepherd/tether-shepherd.d.ts b/tether-shepherd/tether-shepherd.d.ts index 46737222a..b632fb771 100644 --- a/tether-shepherd/tether-shepherd.d.ts +++ b/tether-shepherd/tether-shepherd.d.ts @@ -25,8 +25,8 @@ declare module TetherShepherd { /** * Creates a new Step object with options, and returns the Tour object for convenient chaining when creating multiple steps. If you'd like you can also just pass an options hash which includes id as a key. If the options hash doesn't include an id, one will be generated. You can also pass an existing Step instance rather than options, but note that Shepherd does not support a Step being attached to multiple Tours. */ - addStep(id: string, options: IShepherdTourStepOptions): void; - addStep(id: string, options: IShepherdTourStep): void; + addStep(id: string, options: IShepherdTourStepOptions): IShepherdTour; + addStep(id: string, options: IShepherdTourStep): IShepherdTour; /** * Return a step with a specific id