Skip to content

Commit f9f18c7

Browse files
Update to Shepherd 14.x
1 parent b469d33 commit f9f18c7

File tree

10 files changed

+132
-97
lines changed

10 files changed

+132
-97
lines changed

.prettierrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
3+
module.exports = {
4+
arrowParens: "always",
5+
proseWrap: "always",
6+
trailingComma: "none",
7+
singleQuote: true,
8+
};

package-lock.json

Lines changed: 35 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@angular/platform-browser-dynamic": "^19.0.0",
2626
"core-js": "^3.39.0",
2727
"rxjs": "^7.8.1",
28-
"shepherd.js": "^11.2.0",
28+
"shepherd.js": "^14.4.0",
2929
"tslib": "^2.8.0",
3030
"zone.js": "~0.15.0"
3131
},
@@ -58,6 +58,7 @@
5858
"karma-jasmine": "^5.1.0",
5959
"karma-jasmine-html-reporter": "^2.1.0",
6060
"ng-packagr": "^19.0.0",
61+
"prettier": "^3.4.2",
6162
"protractor": "~7.0.0",
6263
"release-it": "^17.10.0",
6364
"ts-node": "~10.9.2",

projects/shepherd-tester/src/app/data.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Step from 'shepherd.js/src/types/step';
1+
import { type StepOptions } from 'shepherd.js';
22

33
export const builtInButtons = {
44
cancel: {
@@ -20,15 +20,15 @@ export const builtInButtons = {
2020
}
2121
};
2222

23-
export const defaultStepOptions: Step.StepOptions = {
23+
export const defaultStepOptions: StepOptions = {
2424
classes: 'shepherd-theme-arrows custom-default-class',
2525
scrollTo: true,
2626
cancelIcon: {
2727
enabled: true
2828
}
2929
};
3030

31-
export const steps: Step.StepOptions[] = [
31+
export const steps: StepOptions[] = [
3232
{
3333
attachTo: {
3434
element: '.first-element',

projects/shepherd/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"url": "https://github.com/rwwagner90"
2121
},
2222
"dependencies": {
23-
"shepherd.js": "^11.0.0"
23+
"shepherd.js": "^14.4.0"
2424
},
2525
"peerDependencies": {
2626
"@angular/common": "^19.0.0",

projects/shepherd/src/lib/shepherd.service.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ const steps = [
2929
element: '.test-element',
3030
on: 'bottom'
3131
},
32-
buttons: [
33-
builtInButtons.cancel,
34-
builtInButtons.next
35-
],
32+
buttons: [builtInButtons.cancel, builtInButtons.next],
3633
classes: 'custom-class-name-1 custom-class-name-2',
3734
title: 'Welcome to Ember-Shepherd!',
3835
text: 'Test text',
@@ -53,7 +50,7 @@ describe('ShepherdService', () => {
5350
start() {
5451
expect(true).toBeTruthy('The tour was started');
5552
}
56-
}
53+
};
5754

5855
service.addSteps(steps);
5956

@@ -67,7 +64,10 @@ describe('ShepherdService', () => {
6764
const service: ShepherdService = TestBed.inject(ShepherdService);
6865
const mockTourObject = {
6966
start() {
70-
expect(steps[0].options.scrollToHandler()).toBe('custom scrollToHandler', 'The handler was passed through as an option on the step');
67+
expect(steps[0]?.options.scrollToHandler()).toBe(
68+
'custom scrollToHandler',
69+
'The handler was passed through as an option on the step'
70+
);
7171
}
7272
};
7373

projects/shepherd/src/lib/shepherd.service.ts

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,81 @@
11
import { Injectable } from '@angular/core';
2-
import Shepherd from 'shepherd.js';
2+
import { Tour, type TourOptions, type StepOptions } from 'shepherd.js';
33
import { elementIsHidden } from './utils/dom';
44
import { makeButton } from './utils/buttons';
5-
import Step from 'shepherd.js/src/types/step';
5+
6+
interface RequiredElement {
7+
message: string;
8+
selector: string;
9+
title: string;
10+
}
611
@Injectable({
712
providedIn: 'root'
813
})
914
export class ShepherdService {
10-
confirmCancel = false;
11-
confirmCancelMessage: string = null;
12-
defaultStepOptions: Step.StepOptions = {};
13-
errorTitle = null;
15+
confirmCancel: TourOptions['confirmCancel'] = false;
16+
confirmCancelMessage?: TourOptions['confirmCancelMessage'];
17+
defaultStepOptions: StepOptions = {};
18+
errorTitle?: string;
19+
exitOnEsc = true;
1420
isActive = false;
15-
keyboardNavigation = true;
16-
messageForUser: string = null;
21+
keyboardNavigation: TourOptions['keyboardNavigation'] = true;
22+
messageForUser: string | null = null;
1723
modal = false;
18-
requiredElements = [];
24+
requiredElements: Array<RequiredElement> = [];
1925
tourName = undefined;
20-
tourObject: Shepherd.Tour = null;
21-
exitOnEsc = true;
26+
tourObject: Tour | null = null;
2227

23-
constructor () {
24-
}
28+
constructor() {}
2529

2630
/**
2731
* Get the tour object and call back
2832
*/
2933
back() {
30-
this.tourObject.back();
34+
this.tourObject?.back();
3135
}
3236

3337
/**
3438
* Cancel the tour
3539
*/
3640
cancel() {
37-
this.tourObject.cancel();
41+
this.tourObject?.cancel();
3842
}
3943

4044
/**
4145
* Complete the tour
4246
*/
4347
complete() {
44-
this.tourObject.complete();
48+
this.tourObject?.complete();
4549
}
4650

4751
/**
4852
* Hides the current step
4953
*/
5054
hide() {
51-
this.tourObject.hide();
55+
this.tourObject?.hide();
5256
}
5357

5458
/**
5559
* Advance the tour to the next step
5660
*/
5761
next() {
58-
this.tourObject.next();
62+
this.tourObject?.next();
5963
}
6064

6165
/**
6266
* Show a specific step, by passing its id
6367
* @param id The id of the step you want to show
6468
*/
6569
show(id: string | number) {
66-
this.tourObject.show(id);
70+
this.tourObject?.show(id);
6771
}
6872

6973
/**
7074
* Start the tour
7175
*/
7276
start() {
7377
this.isActive = true;
74-
this.tourObject.start();
78+
this.tourObject?.start();
7579
}
7680

7781
/**
@@ -86,24 +90,26 @@ export class ShepherdService {
8690
* Take a set of steps and create a tour object based on the current configuration
8791
* @param steps An array of steps
8892
*/
89-
addSteps(steps: Array<Step.StepOptions>) {
93+
addSteps(steps: Array<StepOptions>) {
9094
this._initialize();
9195
const tour = this.tourObject;
9296

93-
// Return nothing if there are no steps
94-
if (!steps || !Array.isArray(steps) || steps.length === 0) {
97+
// Return nothing if there are no steps or if somehow there is no tour.
98+
if (!tour || !steps || !Array.isArray(steps) || steps.length === 0) {
9599
return;
96100
}
97101

98102
if (!this.requiredElementsPresent()) {
99103
tour.addStep({
100-
buttons: [{
101-
text: 'Exit',
102-
action: tour.cancel
103-
}],
104+
buttons: [
105+
{
106+
text: 'Exit',
107+
action: tour.cancel
108+
}
109+
],
104110
id: 'error',
105111
title: this.errorTitle,
106-
text: [this.messageForUser]
112+
text: [this.messageForUser as string]
107113
});
108114
return;
109115
}
@@ -128,7 +134,10 @@ export class ShepherdService {
128134
this.requiredElements.forEach((element) => {
129135
const selectedElement = document.querySelector(element.selector);
130136

131-
if (allElementsPresent && (!selectedElement || elementIsHidden(selectedElement))) {
137+
if (
138+
allElementsPresent &&
139+
(!selectedElement || elementIsHidden(selectedElement as HTMLElement))
140+
) {
132141
allElementsPresent = false;
133142
this.errorTitle = element.title;
134143
this.messageForUser = element.message;
@@ -142,7 +151,7 @@ export class ShepherdService {
142151
* Initializes the tour, creates a new Shepherd.Tour. sets options, and binds events
143152
*/
144153
private _initialize() {
145-
const tourObject = new Shepherd.Tour({
154+
const tourObject = new Tour({
146155
confirmCancel: this.confirmCancel,
147156
confirmCancelMessage: this.confirmCancelMessage,
148157
defaultStepOptions: this.defaultStepOptions,
@@ -155,6 +164,6 @@ export class ShepherdService {
155164
tourObject.on('complete', this.onTourFinish.bind(this, 'complete'));
156165
tourObject.on('cancel', this.onTourFinish.bind(this, 'cancel'));
157166

158-
this.tourObject = tourObject;
167+
this.tourObject = tourObject as Tour;
159168
}
160169
}

projects/shepherd/src/lib/utils/buttons.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import type { StepOptionsButton } from 'shepherd.js';
2+
import type { ShepherdService } from '../shepherd.service';
3+
4+
export type AngularShepherdButton = StepOptionsButton & {
5+
type?: 'back' | 'cancel' | 'next';
6+
};
7+
18
/**
29
* Creates a button of the specified type, with the given classes and text
310
*
@@ -6,7 +13,10 @@
613
* @param button.text The text for the button
714
* @param button.action The action to call
815
*/
9-
export function makeButton(button) {
16+
export function makeButton(
17+
this: ShepherdService,
18+
button: AngularShepherdButton
19+
) {
1020
const { classes, disabled, label, secondary, type, text } = button;
1121
const builtInButtonTypes = ['back', 'cancel', 'next'];
1222

@@ -15,7 +25,9 @@ export function makeButton(button) {
1525
}
1626

1727
if (builtInButtonTypes.indexOf(type) === -1) {
18-
throw new Error(`'type' property must be one of 'back', 'cancel', or 'next'`);
28+
throw new Error(
29+
`'type' property must be one of 'back', 'cancel', or 'next'`
30+
);
1931
}
2032

2133
return {

0 commit comments

Comments
 (0)