Skip to content

Commit 4c70a9b

Browse files
authored
Merge pull request #104 from lewisl9029/esm-entry-point
2 parents 24d924f + 8ad5201 commit 4c70a9b

File tree

6 files changed

+1319
-815
lines changed

6 files changed

+1319
-815
lines changed

.babelrc

-10
This file was deleted.

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
node_modules
22
coverage
3-
lib
3+
dist
44
npm-debug.log.*
55
.DS_Store

babel.config.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = api => {
2+
const isTest = api.env('test');
3+
4+
api.cache(true);
5+
6+
const config = {
7+
presets: [
8+
[
9+
'@babel/preset-env',
10+
{
11+
targets: '> 0.5%, last 2 versions, Firefox ESR, not dead',
12+
modules: process.env.CJS || isTest ? 'commonjs' : false,
13+
},
14+
],
15+
'@babel/preset-react',
16+
],
17+
};
18+
19+
if (!isTest) {
20+
config.plugins = [['babel-plugin-add-import-extension', { extension: process.env.CJS ? 'cjs' : 'mjs' }]];
21+
}
22+
23+
return config;
24+
};

index.d.ts

+126-128
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,132 @@
1-
declare module 'intro.js-react' {
2-
import * as React from 'react';
3-
import { IntroJs, Options } from 'intro.js';
1+
import * as React from 'react';
2+
import { IntroJs, Options } from 'intro.js';
43

5-
interface Step {
6-
/**
7-
* CSS selector or element to use for the step.
8-
*/
9-
element?: string | HTMLElement | Element;
10-
/**
11-
* The tooltip content.
12-
*/
13-
intro: string | React.ReactNode;
14-
/**
15-
* Position of the tooltip.
16-
*/
17-
position?: string;
18-
/**
19-
* The tooltip title.
20-
*/
21-
title?: string
22-
/**
23-
* CSS class of the tooltip.
24-
*/
25-
tooltipClass?: string;
26-
/**
27-
* CSS class of the helperLayer.
28-
*/
29-
highlightClass?: string;
30-
}
31-
32-
interface Hint {
33-
/**
34-
* CSS selector to use for the hint.
35-
*/
36-
element: string;
37-
/**
38-
* The tooltip text.
39-
*/
40-
hint: string;
41-
/**
42-
* Position of the tooltip.
43-
*/
44-
hintPosition?: string;
45-
}
4+
interface Step {
5+
/**
6+
* CSS selector or element to use for the step.
7+
*/
8+
element?: string | HTMLElement | Element;
9+
/**
10+
* The tooltip content.
11+
*/
12+
intro: string | React.ReactNode;
13+
/**
14+
* Position of the tooltip.
15+
*/
16+
position?: string;
17+
/**
18+
* The tooltip title.
19+
*/
20+
title?: string;
21+
/**
22+
* CSS class of the tooltip.
23+
*/
24+
tooltipClass?: string;
25+
/**
26+
* CSS class of the helperLayer.
27+
*/
28+
highlightClass?: string;
29+
}
4630

47-
interface StepsProps {
48-
/**
49-
* Defines if the steps are visible or not.
50-
* @default false
51-
*/
52-
enabled?: boolean;
53-
/**
54-
* Step index to start with when showing the steps.
55-
*/
56-
initialStep: number;
57-
/**
58-
* All the steps.
59-
*/
60-
steps: Step[];
61-
/**
62-
* Callback called when the steps are disabled.
63-
* Required to force keeping track of the state when the steps are dismissed with an Intro.js event and not the
64-
* enabled prop.
65-
*/
66-
onExit(stepIndex: number): void;
67-
/**
68-
* Callback called before exiting the intro.
69-
* If you want to prevent exiting the intro, you can return false in this callback (available since intro.js 0.2.7).
70-
*/
71-
onBeforeExit?(stepIndex: number): void | false;
72-
/**
73-
* Callback called when the steps are enabled.
74-
*/
75-
onStart?(stepIndex: number): void;
76-
/**
77-
* Callback called when the current step is changed.
78-
*/
79-
onChange?(nextStepIndex: number, nextElement: Element): void;
80-
/**
81-
* Callback called before changing the current step.
82-
* If you want to prevent the transition to the next / previous step, you can return false in this callback
83-
* (available since intro.js 2.8.0).
84-
*/
85-
onBeforeChange?(nextStepIndex: number, nextElement: Element): void | false | Promise<void | false>;
86-
/**
87-
* Callback called after changing the current step.
88-
*/
89-
onAfterChange?(newStepIndex: number, newElement: Element): void;
90-
/**
91-
* Callback called if you prevented transitioning to a new step by returning false in onBeforeChange.
92-
*/
93-
onPreventChange?(stepIndex: number): void;
94-
/**
95-
* Callback called when all the steps are completed.
96-
*/
97-
onComplete?(): void;
98-
/**
99-
* Intro.js options.
100-
*/
101-
options?: Options;
102-
}
31+
interface Hint {
32+
/**
33+
* CSS selector to use for the hint.
34+
*/
35+
element: string;
36+
/**
37+
* The tooltip text.
38+
*/
39+
hint: string;
40+
/**
41+
* Position of the tooltip.
42+
*/
43+
hintPosition?: string;
44+
}
10345

104-
interface HintsProps {
105-
/**
106-
* Defines if the hints are visible or not.
107-
* @default false
108-
*/
109-
enabled?: boolean;
110-
/**
111-
* All the hints.
112-
*/
113-
hints: Hint[];
114-
/**
115-
* Callback called when a hint is clicked.
116-
*/
117-
onClick?(): void;
118-
/**
119-
* Callback called when a hint is closed.
120-
*/
121-
onClose?(): void;
122-
/**
123-
* Intro.js options.
124-
*/
125-
options?: Options;
126-
}
46+
interface StepsProps {
47+
/**
48+
* Defines if the steps are visible or not.
49+
* @default false
50+
*/
51+
enabled?: boolean;
52+
/**
53+
* Step index to start with when showing the steps.
54+
*/
55+
initialStep: number;
56+
/**
57+
* All the steps.
58+
*/
59+
steps: Step[];
60+
/**
61+
* Callback called when the steps are disabled.
62+
* Required to force keeping track of the state when the steps are dismissed with an Intro.js event and not the
63+
* enabled prop.
64+
*/
65+
onExit(stepIndex: number): void;
66+
/**
67+
* Callback called before exiting the intro.
68+
* If you want to prevent exiting the intro, you can return false in this callback (available since intro.js 0.2.7).
69+
*/
70+
onBeforeExit?(stepIndex: number): void | false;
71+
/**
72+
* Callback called when the steps are enabled.
73+
*/
74+
onStart?(stepIndex: number): void;
75+
/**
76+
* Callback called when the current step is changed.
77+
*/
78+
onChange?(nextStepIndex: number, nextElement: Element): void;
79+
/**
80+
* Callback called before changing the current step.
81+
* If you want to prevent the transition to the next / previous step, you can return false in this callback
82+
* (available since intro.js 2.8.0).
83+
*/
84+
onBeforeChange?(nextStepIndex: number, nextElement: Element): void | false | Promise<void | false>;
85+
/**
86+
* Callback called after changing the current step.
87+
*/
88+
onAfterChange?(newStepIndex: number, newElement: Element): void;
89+
/**
90+
* Callback called if you prevented transitioning to a new step by returning false in onBeforeChange.
91+
*/
92+
onPreventChange?(stepIndex: number): void;
93+
/**
94+
* Callback called when all the steps are completed.
95+
*/
96+
onComplete?(): void;
97+
/**
98+
* Intro.js options.
99+
*/
100+
options?: Options;
101+
}
127102

128-
export class Steps extends React.Component<StepsProps> {
129-
public introJs: IntroJs;
130-
public updateStepElement(stepIndex: number): void;
131-
}
103+
interface HintsProps {
104+
/**
105+
* Defines if the hints are visible or not.
106+
* @default false
107+
*/
108+
enabled?: boolean;
109+
/**
110+
* All the hints.
111+
*/
112+
hints: Hint[];
113+
/**
114+
* Callback called when a hint is clicked.
115+
*/
116+
onClick?(): void;
117+
/**
118+
* Callback called when a hint is closed.
119+
*/
120+
onClose?(): void;
121+
/**
122+
* Intro.js options.
123+
*/
124+
options?: Options;
125+
}
132126

133-
export class Hints extends React.Component<HintsProps> {}
127+
export class Steps extends React.Component<StepsProps> {
128+
public introJs: IntroJs;
129+
public updateStepElement(stepIndex: number): void;
134130
}
131+
132+
export class Hints extends React.Component<HintsProps> {}

package.json

+26-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,28 @@
22
"name": "intro.js-react",
33
"version": "0.7.1",
44
"description": "Intro.js React Wrapper",
5-
"main": "lib/index.js",
5+
"main": "dist/cjs/index.js",
6+
"module": "dist/esm/index.js",
67
"types": "index.d.ts",
8+
"exports": {
9+
"./package.json": "./package.json",
10+
".": {
11+
"import": {
12+
"types": "./dist/esm/index.d.mts",
13+
"default": "./dist/esm/index.mjs"
14+
},
15+
"default": {
16+
"types": "./dist/cjs/index.d.cts",
17+
"default": "./dist/cjs/index.cjs"
18+
}
19+
}
20+
},
721
"scripts": {
8-
"prebuild": "rimraf lib/*",
9-
"build": "babel --ignore '**/*.test.js' --out-dir lib src",
10-
"build:watch": "npm run build -- --watch",
22+
"prebuild": "rimraf dist",
23+
"build": "npm run build:cjs && npm run build:esm",
24+
"build:cjs": "CJS=true babel --ignore '**/*.test.js' --out-dir dist/cjs --out-file-extension .cjs src && cp dist/cjs/index.cjs dist/cjs/index.js && cp index.d.ts dist/cjs/index.d.cts",
25+
"build:esm": "babel --ignore '**/*.test.js' --out-dir dist/esm --out-file-extension .mjs src && cp dist/esm/index.mjs dist/esm/index.js && cp index.d.ts dist/esm/index.d.mts",
26+
"build:watch": "npm run build:esm -- --watch",
1127
"lint": "eslint src",
1228
"test": "jest",
1329
"test:watch": "jest --watch",
@@ -17,15 +33,15 @@
1733
"prepublish": "npm run build"
1834
},
1935
"devDependencies": {
20-
"@babel/cli": "7.8.4",
21-
"@babel/plugin-proposal-class-properties": "7.8.3",
22-
"@babel/plugin-proposal-object-rest-spread": "7.9.6",
23-
"@babel/preset-env": "7.9.6",
24-
"@babel/preset-react": "7.9.4",
36+
"@babel/cli": "7.21.0",
37+
"@babel/core": "^7.21.4",
38+
"@babel/preset-env": "7.21.4",
39+
"@babel/preset-react": "7.18.6",
2540
"@types/intro.js": "3.0.1",
2641
"@types/react": "17.0.4",
2742
"babel-eslint": "^7.2.3",
2843
"babel-jest": "26.0.1",
44+
"babel-plugin-add-import-extension": "^1.6.0",
2945
"coveralls": "^3.0.1",
3046
"enzyme": "^2.8.2",
3147
"eslint": "7.0.0",
@@ -79,8 +95,7 @@
7995
]
8096
},
8197
"files": [
82-
"lib",
83-
"src",
98+
"dist",
8499
"index.d.ts"
85100
]
86101
}

0 commit comments

Comments
 (0)