Add type definitions
Browse files- package.json +1 -0
- src/core/element.js +0 -2
- src/core/stage.js +8 -10
- src/index.js +55 -37
- types/.todo +0 -0
- types/index.d.ts +651 -0
package.json
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
"version": "0.2.4",
|
4 |
"description": "A light-weight, no-dependency, vanilla JavaScript library to drive the user's focus across the page",
|
5 |
"main": "dist/driver.min.js",
|
|
|
6 |
"scripts": {
|
7 |
"start": "node server.js",
|
8 |
"build": "webpack --config webpack.config.prod.js"
|
|
|
3 |
"version": "0.2.4",
|
4 |
"description": "A light-weight, no-dependency, vanilla JavaScript library to drive the user's focus across the page",
|
5 |
"main": "dist/driver.min.js",
|
6 |
+
"types": "types/index.d.ts",
|
7 |
"scripts": {
|
8 |
"start": "node server.js",
|
9 |
"build": "webpack --config webpack.config.prod.js"
|
src/core/element.js
CHANGED
@@ -179,8 +179,6 @@ export default class Element {
|
|
179 |
|
180 |
/**
|
181 |
* Is called when the element is about to be highlighted
|
182 |
-
* i.e. either if overlay has started moving the highlight towards
|
183 |
-
* this element of has just decided to highlight it
|
184 |
*/
|
185 |
onHighlightStarted() {
|
186 |
if (this.options.onHighlightStarted) {
|
|
|
179 |
|
180 |
/**
|
181 |
* Is called when the element is about to be highlighted
|
|
|
|
|
182 |
*/
|
183 |
onHighlightStarted() {
|
184 |
if (this.options.onHighlightStarted) {
|
src/core/stage.js
CHANGED
@@ -39,21 +39,15 @@ export default class Stage extends Element {
|
|
39 |
}
|
40 |
}
|
41 |
|
42 |
-
removeNode() {
|
43 |
-
if (!this.node) {
|
44 |
-
return;
|
45 |
-
}
|
46 |
-
|
47 |
-
this.node.parentElement.removeChild(this.node);
|
48 |
-
}
|
49 |
-
|
50 |
/**
|
51 |
* Simply hides the stage
|
52 |
*/
|
53 |
hide() {
|
54 |
-
this.node.
|
|
|
|
|
55 |
|
56 |
-
this.
|
57 |
}
|
58 |
|
59 |
/**
|
@@ -67,6 +61,10 @@ export default class Stage extends Element {
|
|
67 |
this.node.style.right = '';
|
68 |
}
|
69 |
|
|
|
|
|
|
|
|
|
70 |
show(position) {
|
71 |
this.makeNode();
|
72 |
|
|
|
39 |
}
|
40 |
}
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
/**
|
43 |
* Simply hides the stage
|
44 |
*/
|
45 |
hide() {
|
46 |
+
if (!this.node || !this.node.parentElement) {
|
47 |
+
return;
|
48 |
+
}
|
49 |
|
50 |
+
this.node.parentElement.removeChild(this.node);
|
51 |
}
|
52 |
|
53 |
/**
|
|
|
61 |
this.node.style.right = '';
|
62 |
}
|
63 |
|
64 |
+
/**
|
65 |
+
* Shows the stage at provided position
|
66 |
+
* @param {Position} position
|
67 |
+
*/
|
68 |
show(position) {
|
69 |
this.makeNode();
|
70 |
|
src/index.js
CHANGED
@@ -60,6 +60,7 @@ export default class Driver {
|
|
60 |
/**
|
61 |
* Binds any DOM events listeners
|
62 |
* @todo: add throttling in all the listeners
|
|
|
63 |
*/
|
64 |
bind() {
|
65 |
this.window.addEventListener('resize', this.onResize, false);
|
@@ -71,6 +72,7 @@ export default class Driver {
|
|
71 |
* Removes the popover if clicked outside the highlighted element
|
72 |
* or outside the
|
73 |
* @param e
|
|
|
74 |
*/
|
75 |
onClick(e) {
|
76 |
if (!this.isActivated || !this.hasHighlightedElement()) {
|
@@ -105,9 +107,50 @@ export default class Driver {
|
|
105 |
}
|
106 |
}
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
/**
|
109 |
* Moves to the previous step if possible
|
110 |
* otherwise resets the overlay
|
|
|
111 |
*/
|
112 |
movePrevious() {
|
113 |
this.currentStep -= 1;
|
@@ -121,6 +164,7 @@ export default class Driver {
|
|
121 |
/**
|
122 |
* Moves to the next step if possible
|
123 |
* otherwise resets the overlay
|
|
|
124 |
*/
|
125 |
moveNext() {
|
126 |
this.currentStep += 1;
|
@@ -133,6 +177,7 @@ export default class Driver {
|
|
133 |
|
134 |
/**
|
135 |
* @returns {boolean}
|
|
|
136 |
*/
|
137 |
hasNextStep() {
|
138 |
return !!this.steps[this.currentStep + 1];
|
@@ -140,6 +185,7 @@ export default class Driver {
|
|
140 |
|
141 |
/**
|
142 |
* @returns {boolean}
|
|
|
143 |
*/
|
144 |
hasPreviousStep() {
|
145 |
return !!this.steps[this.currentStep - 1];
|
@@ -147,6 +193,8 @@ export default class Driver {
|
|
147 |
|
148 |
/**
|
149 |
* Resets the steps if any and clears the overlay
|
|
|
|
|
150 |
*/
|
151 |
reset(immediate = false) {
|
152 |
this.currentStep = 0;
|
@@ -157,6 +205,7 @@ export default class Driver {
|
|
157 |
/**
|
158 |
* Checks if there is any highlighted element or not
|
159 |
* @returns {boolean}
|
|
|
160 |
*/
|
161 |
hasHighlightedElement() {
|
162 |
const highlightedElement = this.overlay.getHighlightedElement();
|
@@ -166,6 +215,7 @@ export default class Driver {
|
|
166 |
/**
|
167 |
* Gets the currently highlighted element in overlay
|
168 |
* @returns {Element}
|
|
|
169 |
*/
|
170 |
getHighlightedElement() {
|
171 |
return this.overlay.getHighlightedElement();
|
@@ -174,51 +224,16 @@ export default class Driver {
|
|
174 |
/**
|
175 |
* Gets the element that was highlighted before currently highlighted element
|
176 |
* @returns {Element}
|
|
|
177 |
*/
|
178 |
getLastHighlightedElement() {
|
179 |
return this.overlay.getLastHighlightedElement();
|
180 |
}
|
181 |
|
182 |
-
/**
|
183 |
-
* Handler for the onResize DOM event
|
184 |
-
* Makes sure highlighted element stays at valid position
|
185 |
-
*/
|
186 |
-
onResize() {
|
187 |
-
if (!this.isActivated) {
|
188 |
-
return;
|
189 |
-
}
|
190 |
-
|
191 |
-
this.overlay.refresh();
|
192 |
-
}
|
193 |
-
|
194 |
-
/**
|
195 |
-
* Clears the overlay on escape key process
|
196 |
-
* @param event
|
197 |
-
*/
|
198 |
-
onKeyUp(event) {
|
199 |
-
if (!this.isActivated) {
|
200 |
-
return;
|
201 |
-
}
|
202 |
-
|
203 |
-
// If escape was pressed and it is allowed to click outside to close
|
204 |
-
if (event.keyCode === ESC_KEY_CODE && this.options.allowClose) {
|
205 |
-
this.reset();
|
206 |
-
return;
|
207 |
-
}
|
208 |
-
|
209 |
-
// Arrow keys to only perform if it is stepped introduction
|
210 |
-
if (this.steps.length !== 0) {
|
211 |
-
if (event.keyCode === RIGHT_KEY_CODE) {
|
212 |
-
this.moveNext();
|
213 |
-
} else if (event.keyCode === LEFT_KEY_CODE) {
|
214 |
-
this.movePrevious();
|
215 |
-
}
|
216 |
-
}
|
217 |
-
}
|
218 |
-
|
219 |
/**
|
220 |
* Defines steps to be highlighted
|
221 |
* @param {array} steps
|
|
|
222 |
*/
|
223 |
defineSteps(steps) {
|
224 |
this.steps = [];
|
@@ -245,6 +260,7 @@ export default class Driver {
|
|
245 |
* @param allSteps List of all the steps
|
246 |
* @param index Index of the current step
|
247 |
* @returns {null|Element}
|
|
|
248 |
*/
|
249 |
prepareElementFromStep(currentStep, allSteps = [], index = 0) {
|
250 |
let querySelector = '';
|
@@ -302,6 +318,7 @@ export default class Driver {
|
|
302 |
/**
|
303 |
* Initiates highlighting steps from first step
|
304 |
* @param {number} index at which highlight is to be started
|
|
|
305 |
*/
|
306 |
start(index = 0) {
|
307 |
if (!this.steps || this.steps.length === 0) {
|
@@ -317,6 +334,7 @@ export default class Driver {
|
|
317 |
/**
|
318 |
* Highlights the given element
|
319 |
* @param {string|{element: string, popover: {}}} selector Query selector or a step definition
|
|
|
320 |
*/
|
321 |
highlight(selector) {
|
322 |
this.isActivated = true;
|
|
|
60 |
/**
|
61 |
* Binds any DOM events listeners
|
62 |
* @todo: add throttling in all the listeners
|
63 |
+
* @private
|
64 |
*/
|
65 |
bind() {
|
66 |
this.window.addEventListener('resize', this.onResize, false);
|
|
|
72 |
* Removes the popover if clicked outside the highlighted element
|
73 |
* or outside the
|
74 |
* @param e
|
75 |
+
* @private
|
76 |
*/
|
77 |
onClick(e) {
|
78 |
if (!this.isActivated || !this.hasHighlightedElement()) {
|
|
|
107 |
}
|
108 |
}
|
109 |
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Handler for the onResize DOM event
|
113 |
+
* Makes sure highlighted element stays at valid position
|
114 |
+
* @private
|
115 |
+
*/
|
116 |
+
onResize() {
|
117 |
+
if (!this.isActivated) {
|
118 |
+
return;
|
119 |
+
}
|
120 |
+
|
121 |
+
this.overlay.refresh();
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Clears the overlay on escape key process
|
126 |
+
* @param event
|
127 |
+
* @private
|
128 |
+
*/
|
129 |
+
onKeyUp(event) {
|
130 |
+
if (!this.isActivated) {
|
131 |
+
return;
|
132 |
+
}
|
133 |
+
|
134 |
+
// If escape was pressed and it is allowed to click outside to close
|
135 |
+
if (event.keyCode === ESC_KEY_CODE && this.options.allowClose) {
|
136 |
+
this.reset();
|
137 |
+
return;
|
138 |
+
}
|
139 |
+
|
140 |
+
// Arrow keys to only perform if it is stepped introduction
|
141 |
+
if (this.steps.length !== 0) {
|
142 |
+
if (event.keyCode === RIGHT_KEY_CODE) {
|
143 |
+
this.moveNext();
|
144 |
+
} else if (event.keyCode === LEFT_KEY_CODE) {
|
145 |
+
this.movePrevious();
|
146 |
+
}
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
/**
|
151 |
* Moves to the previous step if possible
|
152 |
* otherwise resets the overlay
|
153 |
+
* @public
|
154 |
*/
|
155 |
movePrevious() {
|
156 |
this.currentStep -= 1;
|
|
|
164 |
/**
|
165 |
* Moves to the next step if possible
|
166 |
* otherwise resets the overlay
|
167 |
+
* @public
|
168 |
*/
|
169 |
moveNext() {
|
170 |
this.currentStep += 1;
|
|
|
177 |
|
178 |
/**
|
179 |
* @returns {boolean}
|
180 |
+
* @public
|
181 |
*/
|
182 |
hasNextStep() {
|
183 |
return !!this.steps[this.currentStep + 1];
|
|
|
185 |
|
186 |
/**
|
187 |
* @returns {boolean}
|
188 |
+
* @public
|
189 |
*/
|
190 |
hasPreviousStep() {
|
191 |
return !!this.steps[this.currentStep - 1];
|
|
|
193 |
|
194 |
/**
|
195 |
* Resets the steps if any and clears the overlay
|
196 |
+
* @param {boolean} immediate
|
197 |
+
* @public
|
198 |
*/
|
199 |
reset(immediate = false) {
|
200 |
this.currentStep = 0;
|
|
|
205 |
/**
|
206 |
* Checks if there is any highlighted element or not
|
207 |
* @returns {boolean}
|
208 |
+
* @public
|
209 |
*/
|
210 |
hasHighlightedElement() {
|
211 |
const highlightedElement = this.overlay.getHighlightedElement();
|
|
|
215 |
/**
|
216 |
* Gets the currently highlighted element in overlay
|
217 |
* @returns {Element}
|
218 |
+
* @public
|
219 |
*/
|
220 |
getHighlightedElement() {
|
221 |
return this.overlay.getHighlightedElement();
|
|
|
224 |
/**
|
225 |
* Gets the element that was highlighted before currently highlighted element
|
226 |
* @returns {Element}
|
227 |
+
* @public
|
228 |
*/
|
229 |
getLastHighlightedElement() {
|
230 |
return this.overlay.getLastHighlightedElement();
|
231 |
}
|
232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
/**
|
234 |
* Defines steps to be highlighted
|
235 |
* @param {array} steps
|
236 |
+
* @public
|
237 |
*/
|
238 |
defineSteps(steps) {
|
239 |
this.steps = [];
|
|
|
260 |
* @param allSteps List of all the steps
|
261 |
* @param index Index of the current step
|
262 |
* @returns {null|Element}
|
263 |
+
* @private
|
264 |
*/
|
265 |
prepareElementFromStep(currentStep, allSteps = [], index = 0) {
|
266 |
let querySelector = '';
|
|
|
318 |
/**
|
319 |
* Initiates highlighting steps from first step
|
320 |
* @param {number} index at which highlight is to be started
|
321 |
+
* @public
|
322 |
*/
|
323 |
start(index = 0) {
|
324 |
if (!this.steps || this.steps.length === 0) {
|
|
|
334 |
/**
|
335 |
* Highlights the given element
|
336 |
* @param {string|{element: string, popover: {}}} selector Query selector or a step definition
|
337 |
+
* @public
|
338 |
*/
|
339 |
highlight(selector) {
|
340 |
this.isActivated = true;
|
types/.todo
DELETED
File without changes
|
types/index.d.ts
ADDED
@@ -0,0 +1,651 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
declare module 'driver.js' {
|
2 |
+
export class Driver {
|
3 |
+
/**
|
4 |
+
* Refers to the global document object
|
5 |
+
*/
|
6 |
+
private document: Document;
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Refers to the global window object
|
10 |
+
*/
|
11 |
+
private window: Window;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* If the driver is active or not
|
15 |
+
*/
|
16 |
+
public isActivated: boolean;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Refers to the array of steps to be presented if any
|
20 |
+
*/
|
21 |
+
private steps: Array<Driver.Step>;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Refers to step index that is currently active
|
25 |
+
*/
|
26 |
+
private currentStep: number;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Refers to the overlay for the screen
|
30 |
+
*/
|
31 |
+
private overlay: Driver.Overlay;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* @param {DriverOptions} options
|
35 |
+
*/
|
36 |
+
public constructor(options?: Driver.DriverOptions);
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Does the required bindings for DOM Events
|
40 |
+
*/
|
41 |
+
private bind();
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Listener for the click event, to decide if
|
45 |
+
* to next/previous step, reset the overlay etc
|
46 |
+
* @param {Event} e
|
47 |
+
*/
|
48 |
+
private onClick(e: Event);
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Refreshes the driver and resets the position for stage
|
52 |
+
* and popover on resizing the window
|
53 |
+
*/
|
54 |
+
private onResize();
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Makes it operable with keyboard
|
58 |
+
* @param {Event} e
|
59 |
+
*/
|
60 |
+
private onKeyUp(e: Event);
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Moves to the previous step if possible
|
64 |
+
* otherwise resets the overlay
|
65 |
+
*/
|
66 |
+
public movePrevious();
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Moves to the next step if possible
|
70 |
+
* otherwise resets the overlay
|
71 |
+
*/
|
72 |
+
public moveNext();
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Checks if can be moved to next step
|
76 |
+
* @return {boolean}
|
77 |
+
*/
|
78 |
+
public hasNextStep(): boolean;
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Checks if can be moved to previous step
|
82 |
+
* @return {boolean}
|
83 |
+
*/
|
84 |
+
public hasPreviousStep(): boolean;
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Resets the steps and clears the overlay
|
88 |
+
*/
|
89 |
+
public reset();
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Checks if there is any highlighted element or not
|
93 |
+
* @return {boolean}
|
94 |
+
*/
|
95 |
+
public hasHighlightedElement(): boolean;
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Gets the currently highlighted element if any
|
99 |
+
* @return {Driver.Element}
|
100 |
+
*/
|
101 |
+
public getHighlightedElement(): Driver.Element | null;
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Gets the last highlighted element if any
|
105 |
+
* @return {Driver.Element}
|
106 |
+
*/
|
107 |
+
public getLastHighlightedElement(): Driver.Element | null;
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Defines the steps to be used in multi-step driver
|
111 |
+
* @param {Array<Driver.Step>} steps
|
112 |
+
*/
|
113 |
+
public defineSteps(steps: Array<Driver.Step>);
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Prepares {Driver.Element} from the given step definition
|
117 |
+
* @param {Driver.Step | string} step query selector or step definition for the step
|
118 |
+
* @param {Array<Driver.Step>} allSteps all the given steps
|
119 |
+
* @param {number} stepIndex array index for the current step
|
120 |
+
*/
|
121 |
+
private prepareElementFromStep(step: Driver.Step | string, allSteps: Array<Driver.Step>, stepIndex: number);
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Starts presenting the set steps from the given index
|
125 |
+
* @param {number} index
|
126 |
+
*/
|
127 |
+
public start(index?: number);
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Highlights the given element. Element can be a query selector or a step definition
|
131 |
+
* @param {string | Driver.Step} element
|
132 |
+
*/
|
133 |
+
public highlight(element: string | Driver.Step);
|
134 |
+
}
|
135 |
+
|
136 |
+
namespace Driver {
|
137 |
+
export interface Step {
|
138 |
+
/**
|
139 |
+
* Query selector representing the DOM Element
|
140 |
+
*/
|
141 |
+
element: string;
|
142 |
+
|
143 |
+
/**
|
144 |
+
* Color of stage when this step is active
|
145 |
+
* @default #ffffff
|
146 |
+
*/
|
147 |
+
stageBackground?: string;
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Options representing popover for this step
|
151 |
+
*/
|
152 |
+
popover: Driver.PopoverOptions;
|
153 |
+
}
|
154 |
+
|
155 |
+
export class Element {
|
156 |
+
/**
|
157 |
+
* Refers to the DOM element that this class wraps
|
158 |
+
*/
|
159 |
+
private node: Node | HTMLElement;
|
160 |
+
/**
|
161 |
+
* Refers to the global Document object
|
162 |
+
*/
|
163 |
+
private document: Document;
|
164 |
+
/**
|
165 |
+
* Refers to the global window object
|
166 |
+
*/
|
167 |
+
private window: Window;
|
168 |
+
/**
|
169 |
+
* Options for this element
|
170 |
+
*/
|
171 |
+
private options: Driver.ElementOptions;
|
172 |
+
/**
|
173 |
+
* Refers to the overlay that wraps the body
|
174 |
+
*/
|
175 |
+
private overlay: Driver.Overlay;
|
176 |
+
/**
|
177 |
+
* Refers to the Popover object to be displayed against this element
|
178 |
+
*/
|
179 |
+
private popover: Driver.Popover;
|
180 |
+
/**
|
181 |
+
* Refers to the stage that will be displayed behind this element
|
182 |
+
*/
|
183 |
+
private stage: Driver.Stage;
|
184 |
+
|
185 |
+
/**
|
186 |
+
* @param {HTMLElement | Node} node
|
187 |
+
* @param {Driver.DriverOptions} options
|
188 |
+
* @param {Driver.Popover} popover
|
189 |
+
* @param {Driver.Stage} stage
|
190 |
+
* @param {Driver.Overlay} overlay
|
191 |
+
* @param {Window} window
|
192 |
+
* @param {Document} document
|
193 |
+
*/
|
194 |
+
constructor(node: HTMLElement | Node,
|
195 |
+
options: Driver.DriverOptions,
|
196 |
+
popover: Driver.Popover,
|
197 |
+
stage: Driver.Stage,
|
198 |
+
overlay: Driver.Overlay,
|
199 |
+
window: Window,
|
200 |
+
document: Document);
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Gets the screen coordinates for the current DOM Element
|
204 |
+
* @return {Driver.ScreenCoordinates}
|
205 |
+
*/
|
206 |
+
public getScreenCoordinates(): Driver.ScreenCoordinates;
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Checks if the give element is in view port or not
|
210 |
+
* @return {boolean}
|
211 |
+
*/
|
212 |
+
public isInView(): boolean;
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Brings the current DOMElement in view
|
216 |
+
*/
|
217 |
+
public bringInView();
|
218 |
+
|
219 |
+
/**
|
220 |
+
* Gets the position of element on screen
|
221 |
+
* @return {Driver.Position}
|
222 |
+
*/
|
223 |
+
public getCalculatedPosition(): Driver.Position;
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Manually scrolls to current element if scrollInToView is not supported
|
227 |
+
*/
|
228 |
+
private scrollManually();
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Is called when the current element is deselected
|
232 |
+
* @param {boolean} hideStage
|
233 |
+
*/
|
234 |
+
private onDeselected(hideStage?: boolean = false);
|
235 |
+
|
236 |
+
/**
|
237 |
+
* Is called when element is about to be highlighted
|
238 |
+
*/
|
239 |
+
private onHighlightStarted();
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Is called when element has been successfully highlighted
|
243 |
+
*/
|
244 |
+
private onHighlighted();
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Shows the stage on the current element
|
248 |
+
*/
|
249 |
+
private showStage();
|
250 |
+
|
251 |
+
/**
|
252 |
+
* Hides the popover from the current element if visible
|
253 |
+
*/
|
254 |
+
private hidePopover();
|
255 |
+
|
256 |
+
/**
|
257 |
+
* Shows the popover on current element if possible
|
258 |
+
*/
|
259 |
+
private showPopover();
|
260 |
+
|
261 |
+
/**
|
262 |
+
* Gets the full page size
|
263 |
+
*/
|
264 |
+
private getFullPageSize(): Driver.ElementSize;
|
265 |
+
|
266 |
+
/**
|
267 |
+
* Checks if the current element is same as passed element
|
268 |
+
* @param {Driver.Element} element
|
269 |
+
*/
|
270 |
+
private isSame(element: Driver.Element);
|
271 |
+
|
272 |
+
/**
|
273 |
+
* Gets the node that this element refers to
|
274 |
+
* @return {Node | HTMLElement}
|
275 |
+
*/
|
276 |
+
public getNode(): Node | HTMLElement;
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Gets the size of current element
|
280 |
+
* @return {Driver.ElementSize}
|
281 |
+
*/
|
282 |
+
public getSize(): Driver.ElementSize;
|
283 |
+
}
|
284 |
+
|
285 |
+
export class Overlay {
|
286 |
+
/**
|
287 |
+
* Options to modify the overlay behavior
|
288 |
+
*/
|
289 |
+
private options: Driver.DriverOptions;
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Refers to currently highlighted element
|
293 |
+
*/
|
294 |
+
private highlightedElement: Driver.Element | null;
|
295 |
+
|
296 |
+
/**
|
297 |
+
* Refers to element highlighted before currently highlighted element
|
298 |
+
*/
|
299 |
+
private lastHighlightedElement: Driver.Element | null;
|
300 |
+
|
301 |
+
/**
|
302 |
+
* Refers to timeout handler used to animate while resetting
|
303 |
+
*/
|
304 |
+
private hideTimer: number | null;
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Refers to global object Window
|
308 |
+
*/
|
309 |
+
private window: Window;
|
310 |
+
|
311 |
+
/**
|
312 |
+
* Refers to global object Document
|
313 |
+
*/
|
314 |
+
private document: Document;
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Prepares the DOM element for overlay and appends to body
|
318 |
+
*/
|
319 |
+
private makeNode();
|
320 |
+
|
321 |
+
/**
|
322 |
+
* Highlights the given Element while resetting the existing one
|
323 |
+
* @param {Driver.Element} element
|
324 |
+
*/
|
325 |
+
public highlight(element: Driver.Element);
|
326 |
+
|
327 |
+
/**
|
328 |
+
* Shows the overlay while appending to body if it is not there already
|
329 |
+
*/
|
330 |
+
public show();
|
331 |
+
|
332 |
+
/**
|
333 |
+
* Gets the highlighted element in overlay if any
|
334 |
+
* @return {Driver.Element | null}
|
335 |
+
*/
|
336 |
+
public getHighlightedElement(): Driver.Element | null;
|
337 |
+
|
338 |
+
/**
|
339 |
+
* Gets the element highlighted before current element if any
|
340 |
+
* @return {Driver.Element | null}
|
341 |
+
*/
|
342 |
+
public getLastHighlightedElement(): Driver.Element | null;
|
343 |
+
|
344 |
+
/**
|
345 |
+
* Removes the overlay and deselects the highlighted element. Does that with animation
|
346 |
+
* by default or without animation if immediate is set to false
|
347 |
+
* @param {boolean} immediate
|
348 |
+
*/
|
349 |
+
public clear(immediate: boolean = false);
|
350 |
+
|
351 |
+
/**
|
352 |
+
* Removes the overlay node if it exists
|
353 |
+
*/
|
354 |
+
private removeNode();
|
355 |
+
|
356 |
+
/**
|
357 |
+
* Refreshes the overlay i.e. sets the size according to current window size
|
358 |
+
* And moves the highlight around if necessary
|
359 |
+
*/
|
360 |
+
public refresh();
|
361 |
+
}
|
362 |
+
|
363 |
+
export class Popover {
|
364 |
+
private node: Node | HTMLElement;
|
365 |
+
private tipNode: Node | HTMLElement;
|
366 |
+
private titleNode: Node | HTMLElement;
|
367 |
+
private descriptionNode: Node | HTMLElement;
|
368 |
+
private footerNode: Node | HTMLElement;
|
369 |
+
private nextBtnNode: Node | HTMLElement;
|
370 |
+
private prevBtnNode: Node | HTMLElement;
|
371 |
+
private closeBtnNode: Node | HTMLElement;
|
372 |
+
private window: Window;
|
373 |
+
private document: Document;
|
374 |
+
|
375 |
+
/**
|
376 |
+
* @param {Driver.PopoverOptions} options
|
377 |
+
* @param {Window} window
|
378 |
+
* @param {Document} document
|
379 |
+
*/
|
380 |
+
constructor(options: Driver.PopoverOptions,
|
381 |
+
window: Window,
|
382 |
+
document: Document);
|
383 |
+
|
384 |
+
/**
|
385 |
+
* Prepares the DOM element for popover and appends to the body
|
386 |
+
*/
|
387 |
+
private makeNode();
|
388 |
+
|
389 |
+
/**
|
390 |
+
* Hides the popover if visible
|
391 |
+
*/
|
392 |
+
public hide();
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Sets the initial state for popover before changing position
|
396 |
+
*/
|
397 |
+
private setInitialState();
|
398 |
+
|
399 |
+
/**
|
400 |
+
* Shows the popover at the given position
|
401 |
+
* @param {Driver.Position} position
|
402 |
+
*/
|
403 |
+
public show(position: Driver.Position);
|
404 |
+
|
405 |
+
/**
|
406 |
+
* Renders the buttons in the footer of the popover
|
407 |
+
*/
|
408 |
+
private renderButtons();
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Positions the popover to the left of the given element position
|
412 |
+
* @param {Driver.Position} position
|
413 |
+
*/
|
414 |
+
private positionOnLeft(position: Driver.Position);
|
415 |
+
|
416 |
+
/**
|
417 |
+
* Positions the popover to the right of the given element position
|
418 |
+
* @param {Driver.Position} position
|
419 |
+
*/
|
420 |
+
private positionOnRight(position: Driver.Position);
|
421 |
+
|
422 |
+
/**
|
423 |
+
* Positions the popover to the top of the given element position
|
424 |
+
* @param {Driver.Position} position
|
425 |
+
*/
|
426 |
+
private positionOnTop(position: Driver.Position);
|
427 |
+
|
428 |
+
/**
|
429 |
+
* Positions the popover to the bottom of the given element position
|
430 |
+
* @param {Driver.Position} position
|
431 |
+
*/
|
432 |
+
private positionOnBottom(position: Driver.Position);
|
433 |
+
|
434 |
+
/**
|
435 |
+
* Positions the popover automatically around the element position
|
436 |
+
* @param {Driver.Position} position
|
437 |
+
*/
|
438 |
+
private autoPosition(position: Driver.Position);
|
439 |
+
}
|
440 |
+
|
441 |
+
export class Stage extends Element {
|
442 |
+
private options: Driver.StageOptions;
|
443 |
+
private window: Window;
|
444 |
+
private document: Document;
|
445 |
+
|
446 |
+
/**
|
447 |
+
* @param {Driver.StageOptions} options
|
448 |
+
* @param {Window} window
|
449 |
+
* @param {Document} document
|
450 |
+
*/
|
451 |
+
constructor(options: Driver.StageOptions,
|
452 |
+
window: Window,
|
453 |
+
document: Document);
|
454 |
+
|
455 |
+
/**
|
456 |
+
* Prepares the node and appends to body if not there already
|
457 |
+
*/
|
458 |
+
private makeNode();
|
459 |
+
|
460 |
+
/**
|
461 |
+
* Hides the stage by removing the node
|
462 |
+
*/
|
463 |
+
public hide();
|
464 |
+
|
465 |
+
/**
|
466 |
+
* Sets the default properties on the node
|
467 |
+
*/
|
468 |
+
private setInitialStyle();
|
469 |
+
|
470 |
+
/**
|
471 |
+
* Shows the stage at provided position
|
472 |
+
* @param {Driver.Position} position
|
473 |
+
*/
|
474 |
+
public show(position: Driver.Position);
|
475 |
+
}
|
476 |
+
|
477 |
+
export class Position {
|
478 |
+
top: number;
|
479 |
+
left: number;
|
480 |
+
right: number;
|
481 |
+
bottom: number;
|
482 |
+
|
483 |
+
constructor({
|
484 |
+
left: number = 0,
|
485 |
+
top: number = 0,
|
486 |
+
bottom: number = 0,
|
487 |
+
right: number = 0,
|
488 |
+
} = {});
|
489 |
+
|
490 |
+
/**
|
491 |
+
* Checks if the given position is valid and can be highlighted
|
492 |
+
* @return {boolean}
|
493 |
+
*/
|
494 |
+
canHighlight(): boolean;
|
495 |
+
|
496 |
+
/**
|
497 |
+
* Checks if the given position is same as the passed position
|
498 |
+
* @param {Driver.Position} position
|
499 |
+
*/
|
500 |
+
equals(position: Driver.Position);
|
501 |
+
}
|
502 |
+
|
503 |
+
interface ScreenCoordinates {
|
504 |
+
x: number;
|
505 |
+
y: number;
|
506 |
+
}
|
507 |
+
|
508 |
+
interface ElementSize {
|
509 |
+
width: number;
|
510 |
+
height: number;
|
511 |
+
}
|
512 |
+
|
513 |
+
interface PopoverOptions {
|
514 |
+
/**
|
515 |
+
* Title for the popover
|
516 |
+
*/
|
517 |
+
title?: string;
|
518 |
+
|
519 |
+
/**
|
520 |
+
* Description for the popover
|
521 |
+
*/
|
522 |
+
description: string;
|
523 |
+
|
524 |
+
/**
|
525 |
+
* Whether to show control buttons or not
|
526 |
+
* @default true
|
527 |
+
*/
|
528 |
+
showButtons: boolean;
|
529 |
+
|
530 |
+
/**
|
531 |
+
* Text on the button in the final step
|
532 |
+
* @default 'Done'
|
533 |
+
*/
|
534 |
+
doneBtnText: string;
|
535 |
+
|
536 |
+
/**
|
537 |
+
* Text on the close button
|
538 |
+
* @default 'Close'
|
539 |
+
*/
|
540 |
+
closeBtnText: string;
|
541 |
+
|
542 |
+
/**
|
543 |
+
* Text on the next button
|
544 |
+
* @default 'Next'
|
545 |
+
*/
|
546 |
+
nextBtnText: string;
|
547 |
+
|
548 |
+
/**
|
549 |
+
* Text on the previous button
|
550 |
+
* @default 'Previous'
|
551 |
+
*/
|
552 |
+
prevBtnText: string;
|
553 |
+
}
|
554 |
+
|
555 |
+
interface DriverOptions {
|
556 |
+
/**
|
557 |
+
* Whether to animate while transitioning from one highlighted
|
558 |
+
* element to another
|
559 |
+
* @default true
|
560 |
+
*/
|
561 |
+
animate?: boolean;
|
562 |
+
|
563 |
+
/**
|
564 |
+
* Opacity for the overlay
|
565 |
+
* @default 0.75
|
566 |
+
*/
|
567 |
+
opacity?: number,
|
568 |
+
|
569 |
+
/**
|
570 |
+
* Distance of elements corner from the edges of the overlay
|
571 |
+
* @default 10
|
572 |
+
*/
|
573 |
+
padding?: number,
|
574 |
+
|
575 |
+
/**
|
576 |
+
* Options to be passed to scrollIntoView if supported by browser
|
577 |
+
* @default { behavior: 'instant', block: 'center' }
|
578 |
+
*/
|
579 |
+
scrollIntoViewOptions?: ScrollIntoViewOptions,
|
580 |
+
|
581 |
+
/**
|
582 |
+
* Clicking outside the highlighted element should reset driver or not
|
583 |
+
* @default true
|
584 |
+
*/
|
585 |
+
allowClose?: boolean,
|
586 |
+
|
587 |
+
/**
|
588 |
+
* Background color for the stage behind the highlighted element
|
589 |
+
* @default '#ffffff'
|
590 |
+
*/
|
591 |
+
stageBackground?: string,
|
592 |
+
|
593 |
+
/**
|
594 |
+
* Whether to show control buttons or not
|
595 |
+
* @default true
|
596 |
+
*/
|
597 |
+
showButtons: boolean;
|
598 |
+
|
599 |
+
/**
|
600 |
+
* Text on the button in the final step
|
601 |
+
* @default 'Done'
|
602 |
+
*/
|
603 |
+
doneBtnText: string;
|
604 |
+
|
605 |
+
/**
|
606 |
+
* Text on the close button
|
607 |
+
* @default 'Close'
|
608 |
+
*/
|
609 |
+
closeBtnText: string;
|
610 |
+
|
611 |
+
/**
|
612 |
+
* Text on the next button
|
613 |
+
* @default 'Next'
|
614 |
+
*/
|
615 |
+
nextBtnText: string;
|
616 |
+
|
617 |
+
/**
|
618 |
+
* Text on the previous button
|
619 |
+
* @default 'Previous'
|
620 |
+
*/
|
621 |
+
prevBtnText: string;
|
622 |
+
|
623 |
+
/**
|
624 |
+
* Callback to be called when element is about to be highlighted
|
625 |
+
* @param {Driver.Element} element
|
626 |
+
* @returns any
|
627 |
+
*/
|
628 |
+
onHighlightStarted: (element: Driver.Element) => void;
|
629 |
+
|
630 |
+
/**
|
631 |
+
* Callback to be called when element has been highlighted
|
632 |
+
* @param {Driver.Element} element
|
633 |
+
* @returns any
|
634 |
+
*/
|
635 |
+
onHighlighted: (element: Driver.Element) => void,
|
636 |
+
|
637 |
+
/**
|
638 |
+
* Callback to be called when element has been deselected
|
639 |
+
* @param {Driver.Element} element
|
640 |
+
* @returns any
|
641 |
+
*/
|
642 |
+
onDeselected: (element: Driver.Element) => void,
|
643 |
+
}
|
644 |
+
|
645 |
+
interface ElementOptions extends Driver.DriverOptions {
|
646 |
+
}
|
647 |
+
|
648 |
+
interface StageOptions extends ElementOptions {
|
649 |
+
}
|
650 |
+
}
|
651 |
+
}
|