Skip to content

Commit 741062b

Browse files
Convert to ESM (#2626)
* Convert to ESM * More esm tweaks * Update rollup.config.mjs * Tweak deepmerge
1 parent 62d041c commit 741062b

File tree

16 files changed

+127
-236
lines changed

16 files changed

+127
-236
lines changed

docs-src/tutorials/01-install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ You can use jsDelivr to pull down any release from npm. For example, you could i
5252
with:
5353

5454
```html
55-
<script src="https://cdn.jsdelivr.net/npm/shepherd.js@10.0.1/dist/shepherd.min.js"></script>
55+
<script type="module" src="https://cdn.jsdelivr.net/npm/shepherd.js@10.0.1/dist/shepherd.js"></script>
5656
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/shepherd.js@10.0.1/dist/css/shepherd.css"/>
5757
```
5858

docs-src/tutorials/02-usage.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
### Rollup/Webpack Based Builds
22

3-
The latest versions of Rollup and Webpack support ES6 imports. We have an ES module
4-
exported to `dist/shepherd.esm.js`. This is also specified as `"module"` in
5-
`package.json`, which should allow you to import using standard ES import syntax.
3+
The latest versions of Rollup and Webpack support ES6 imports. Shepherd ships as an ES module
4+
which should allow you to import using standard ES import syntax.
65

76
i.e.
87

@@ -74,7 +73,7 @@ occurring in _any_ tour:
7473

7574
##### Events
7675

77-
The global Shepherd fires the following events whenever a `Tour` instance fires them. It adds to the object passed to the
76+
The global Shepherd fires the following events whenever a `Tour` instance fires them. It adds to the object passed to the
7877
event handlers a `tour` key pointing to the instance which fired the event:
7978

8079
- `complete`
@@ -88,9 +87,11 @@ event handlers a `tour` key pointing to the instance which fired the event:
8887
For multiple events, you can use something like:
8988

9089
```javascript
91-
['complete', 'cancel'].forEach(event => shepherd.on(event, () => {
92-
// some code here
93-
}));
90+
['complete', 'cancel'].forEach((event) =>
91+
shepherd.on(event, () => {
92+
// some code here
93+
})
94+
);
9495
```
9596

9697
##### Current Tour
@@ -125,22 +126,22 @@ const myTour = new Shepherd.Tour(options);
125126
- `modalContainer` An optional container element for the modal. If not set, the modal will be appended to `document.body`.
126127
- `steps`: An array of step options objects or Step instances to initialize the tour with.
127128
- `tourName`: An optional "name" for the tour. This will be appended to the the tour's
128-
dynamically generated `id` property.
129+
dynamically generated `id` property.
129130
- `useModalOverlay`: Whether or not steps should be placed above a darkened modal overlay. If true, the overlay will create an opening around the target element so that it can remain interactive.
130131

131132
##### Tour Methods
132133

133134
- `addStep(options)`: Creates a new Step object with options, and returns the `Step` instance it created. If the options hash doesn't include an `id`, one will be generated.
134-
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.
135+
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.
135136
- `addSteps([Steps])`: Add multiple steps to the tour
136137
- `getById(id)`: Return a step with a specific id
137138
- `isActive()`: Check if the tour is active
138139
- `next()`: Advance to the next step, in the order they were added
139140
- `back()`: Show the previous step, in the order they were added
140141
- `cancel()`: Trigger cancel on the current step, hiding it without advancing
141-
- `complete()`: Calls _done() triggering the `complete` event
142+
- `complete()`: Calls \_done() triggering the `complete` event
142143
- `hide()`: Hide the current step
143-
- `show([id])`: Show the step specified by id (if it's a string), or index (if it's a number) provided. Defaults to the first step.
144+
- `show([id])`: Show the step specified by id (if it's a string), or index (if it's a number) provided. Defaults to the first step.
144145
- `start()`: Show the first step and begin the tour
145146
- `getCurrentStep()`: Returns the currently shown step
146147
- `removeStep(id)`: Removes the step from the tour
@@ -169,7 +170,7 @@ created.
169170
- `Function` to be executed when the step is built. It must return one the two options above.
170171
- `title`: The step's title. It becomes an `h3` at the top of the step.
171172
- `attachTo`: The element the step should be attached to on the page. An object with properties `element` and `on`.
172-
- `element`: An element selector string, a DOM element, or a function (returning a selector, a DOM element, `null` or `undefined`).
173+
- `element`: An element selector string, a DOM element, or a function (returning a selector, a DOM element, `null` or `undefined`).
173174
- `on`: The optional direction to place the Floating UI tooltip relative to the element.
174175
- Possible string values: 'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'right', 'right-start', 'right-end', 'left', 'left-start', 'left-end'
175176

@@ -180,15 +181,16 @@ const new Step(tour, {
180181
});
181182
```
182183

183-
If you don’t specify an `attachTo` the element will appear in the middle of the screen. The same will happen if your
184+
If you don’t specify an `attachTo` the element will appear in the middle of the screen. The same will happen if your
184185
`attachTo.element` callback returns `null`, `undefined`, or a selector that does not exist in the DOM.
185186

186187
If you omit the `on` portion of `attachTo`, the element will still be highlighted, but the tooltip will appear
187188
in the middle of the screen, without an arrow pointing to the target.
188189

189190
If the element to highlight does not yet exist while instantiating tour steps, you may use lazy evaluation by supplying a function to `attachTo.element`. The function will be called in the `before-show` phase.
191+
190192
- `beforeShowPromise`: A function that returns a promise. When the promise resolves, the rest of the `show` code for
191-
the step will execute. For example:
193+
the step will execute. For example:
192194
```javascript
193195
beforeShowPromise: function() {
194196
return new Promise(function(resolve) {
@@ -210,16 +212,16 @@ the step will execute. For example:
210212
- `secondary`: A boolean, that when true, adds a `shepherd-button-secondary` class to the button
211213
- `text`: The HTML text of the button. It can also be a function that returns a string (useful with i18n solutions).
212214
- `action`: A function executed when the button is clicked on.
213-
It is automatically bound to the `tour` the step is associated with, so things like `this.next` will
214-
work inside the action. You can use action to skip steps or navigate to specific steps, with something like:
215-
```javascript
216-
action() {
217-
return this.show('some_step_name');
218-
}
219-
```
220-
- `advanceOn`: An action on the page which should advance shepherd to the next step. It should be an object with a string `selector` and an `event` name.
221-
For example: `{selector: '.some-element', event: 'click'}`. It doesn't have to be an event inside the tour, it can be any event fired on any element on the page.
222-
You can also always manually advance the Tour by calling `myTour.next()`.
215+
It is automatically bound to the `tour` the step is associated with, so things like `this.next` will
216+
work inside the action. You can use action to skip steps or navigate to specific steps, with something like:
217+
```javascript
218+
action() {
219+
return this.show('some_step_name');
220+
}
221+
```
222+
- `advanceOn`: An action on the page which should advance shepherd to the next step. It should be an object with a string `selector` and an `event` name.
223+
For example: `{selector: '.some-element', event: 'click'}`. It doesn't have to be an event inside the tour, it can be any event fired on any element on the page.
224+
You can also always manually advance the Tour by calling `myTour.next()`.
223225
- `highlightClass`: An extra class to apply to the `attachTo` element when it is highlighted (that is, when its step is active). You can then target that selector in your CSS.
224226
- `id`: The string to use as the `id` for the step. If an id is not passed one will be generated.
225227
- `modalOverlayOpeningPadding`: An amount of padding to add around the modal overlay opening
@@ -228,8 +230,9 @@ You can also always manually advance the Tour by calling `myTour.next()`.
228230
- `showOn`: A function that, when it returns true, will show the step. If it returns false, the step will be skipped.
229231
- `scrollTo`: Should the element be scrolled to when this step is shown? If true, uses the default `scrollIntoView`, if an object, passes that object as the params to `scrollIntoView` i.e. `{behavior: 'smooth', block: 'center'}`
230232
- `scrollToHandler`: A function that lets you override the default `scrollTo` behavior and define a custom action to do the scrolling,
231-
and possibly other logic.
233+
and possibly other logic.
232234
- `when`: You can define show, hide, etc events inside when. For example:
235+
233236
```javascript
234237
when: {
235238
show: function() {
@@ -265,14 +268,14 @@ Please note that `complete` and `cancel` are only ever triggered if you call the
265268

266269
### Advancing on Actions
267270

268-
You can use the `advanceOn` option, or the Next button, to advance steps. If you would like however to have a step advance on a
271+
You can use the `advanceOn` option, or the Next button, to advance steps. If you would like however to have a step advance on a
269272
complex user action, you can do the following:
270273

271274
```javascript
272275
const myStep = myTour.addStep(options);
273276

274277
yourApp.on('some-event', () => {
275-
if (myStep.isOpen()){
278+
if (myStep.isOpen()) {
276279
Shepherd.activeTour.next();
277280
}
278281
});

landing/src/layouts/MainPage.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { SITE_TITLE } from '../consts';
77
const { isHome } = Astro.props;
88
const shepherdIncludeCode = `
99
<link rel="stylesheet" href="shepherd.js/dist/css/shepherd.css"/>
10-
<script src="shepherd.js/dist/shepherd.min.js"></script>
10+
<script type="module" src="shepherd.js/dist/shepherd.js"></script>
1111
1212
`;
1313
---
@@ -177,7 +177,7 @@ const shepherdIncludeCode = `
177177
<script type="module" is:inline>
178178
'use strict';
179179

180-
import Shepherd from './node_modules/shepherd.js/dist/shepherd.esm.js';
180+
import Shepherd from './node_modules/shepherd.js/dist/shepherd.js';
181181

182182
(function () {
183183
function init() {

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
"Chuck Carpenter <chuck@shipshape.io>"
1414
],
1515
"scripts": {
16-
"build": "pnpm -F shepherd.js build",
16+
"build": "pnpm -F shepherd.js build && pnpm build:landing",
17+
"dev": "pnpm watch",
18+
"docs": "node_modules/.bin/jsdoc -c .jsdoc.js --verbose",
19+
"build:landing": "pnpm -F landing build",
1720
"lint:js": "pnpm -F '*' lint:js",
21+
"start": "pnpm watch",
1822
"test:ci": "pnpm build && pnpm test:unit:ci && pnpm test:cy:ci:chrome",
1923
"test:cy:ci:chrome": "pnpm -F cypress-tests test:ci:chrome",
2024
"test:cy:watch": "pnpm -F cypress-tests test:watch",
2125
"test:unit:ci": "pnpm -F unit-tests test:ci",
2226
"test:unit:watch": "pnpm -F unit-tests test:watch",
2327
"types:check": "pnpm -F shepherd.js types:check",
24-
"view-coverage": "pnpm -F unit-tests view-coverage"
28+
"view-coverage": "pnpm -F unit-tests view-coverage",
29+
"watch": "pnpm -F shepherd.js watch"
2530
},
2631
"devDependencies": {
2732
"@babel/core": "^7.23.5",

pnpm-lock.yaml

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

shepherd.js/package.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
],
2121
"exports": {
2222
".": {
23-
"import": "./dist/shepherd.esm.js",
2423
"default": "./dist/shepherd.js"
2524
},
2625
"./*": {
27-
"import": "./dist/*.esm.js",
2826
"types": "./dist/*.d.ts",
2927
"default": "./dist/*.js"
3028
}
@@ -37,23 +35,16 @@
3735
}
3836
},
3937
"scripts": {
40-
"build": "pnpm clean && rollup -c && pnpm postbuild",
41-
"postbuild": "pnpm build:landing",
42-
"build:landing": "pnpm -F landing build",
38+
"build": "pnpm clean && rollup -c",
4339
"clean": "rimraf ./dist",
44-
"dev": "pnpm watch",
45-
"docs": "node_modules/.bin/jsdoc -c .jsdoc.js --verbose",
4640
"esdoc": "esdoc",
4741
"lint:js": "eslint . --ext js",
48-
"rewrite-paths": "replace 'SF:.*src' 'SF:src' coverage/lcov.info",
49-
"start": "pnpm watch",
50-
"test": "pnpm lint:js && pnpm test:ci",
5142
"types:check": "pnpm tsc",
5243
"watch": "pnpm clean && rollup -c --environment DEVELOPMENT --watch"
5344
},
5445
"dependencies": {
5546
"@floating-ui/dom": "^1.5.3",
56-
"deepmerge": "^4.3.1"
47+
"deepmerge-ts": "^5.1.0"
5748
},
5849
"devDependencies": {
5950
"@babel/core": "^7.23.5",
@@ -83,7 +74,6 @@
8374
"rimraf": "^5.0.5",
8475
"rollup": "^4.12.0",
8576
"rollup-plugin-analyzer": "^4.0.0",
86-
"rollup-plugin-copy": "^3.5.0",
8777
"rollup-plugin-filesize": "^10.0.0",
8878
"rollup-plugin-license": "^3.2.0",
8979
"rollup-plugin-livereload": "^2.0.5",

0 commit comments

Comments
 (0)