@aquera/nile-elements 0.0.128 → 0.0.129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent nile-elements following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "nile-elements",
6
- "version": "0.0.128",
6
+ "version": "0.0.129",
7
7
  "main": "dist/src/index.js",
8
8
  "type": "module",
9
9
  "module": "dist/src/index.js",
@@ -17,8 +17,8 @@ export const styles = css`
17
17
  .introjs-tooltip {
18
18
  background-color: var(--nile-tour-background-color, #000);
19
19
  color: var(--nile-tour-text-color, #fff);
20
- width: 300px;
21
- max-width: 300px;
20
+ width: 300px;
21
+ max-width: 300px;
22
22
  }
23
23
 
24
24
  .introjs-arrow.bottom {
@@ -42,11 +42,9 @@ export const styles = css`
42
42
  }
43
43
 
44
44
  .introjs-arrow.right-bottom {
45
- border-right-color: var(--nile-tour-background-color, #000) !important;
45
+ border-left-color: var(--nile-tour-background-color, #000) !important;
46
46
  }
47
47
 
48
-
49
-
50
48
  .introjs-button {
51
49
  background: none;
52
50
  border: none;
@@ -84,23 +82,61 @@ export const styles = css`
84
82
  gap: 10px;
85
83
  }
86
84
 
87
- .introjs-helperNumberLayer{
88
- display: none;
85
+ .introjs-helperNumberLayer {
86
+ display: none;
89
87
  }
90
88
 
91
- .introjs-bullets{
92
- display: none;
93
-
89
+ .introjs-bullets {
90
+ display: none;
94
91
  }
95
92
 
96
93
  .introjs-skipbutton {
97
- display: none;
94
+ display: none;
95
+ }
96
+
97
+ .introjs-prev-button {
98
+ color: #c7ced4;
99
+ }
98
100
 
101
+ .introjs-helperLayer {
102
+ display: none;
103
+ pointer-events: none;
99
104
  }
100
105
 
106
+ .introjs-overlay {
107
+ display: none;
108
+ pointer-events: none;
109
+ }
101
110
 
102
- .introjs-prev-button {
103
- color: #C7CED4;
111
+ .introjs-step-counter {
112
+ margin-right: auto; /* Push buttons to the opposite side */
113
+ font-size: 14px;
114
+ color: #ffffff;
115
+ padding: 0 10px;
116
+ display: flex;
117
+ align-items: center;
118
+ }
119
+
120
+ @keyframes shake {
121
+ 0% {
122
+ transform: translateX(0);
123
+ }
124
+ 25% {
125
+ transform: translateX(-5px);
126
+ }
127
+ 50% {
128
+ transform: translateX(5px);
129
+ }
130
+ 75% {
131
+ transform: translateX(-5px);
132
+ }
133
+ 100% {
134
+ transform: translateX(0);
135
+ }
136
+ }
137
+
138
+ .introjs-shake {
139
+ animation: shake 0.5s ease infinite; /* Repeats continuously */
104
140
  }
105
141
  `;
106
142
 
@@ -1,119 +1,182 @@
1
- /**
2
- * Copyright Aquera Inc 2023
3
- *
4
- * This source code is licensed under the BSD-3-Clause license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
1
  import { LitElement, html, CSSResultArray, TemplateResult, property } from 'lit-element';
9
2
  import { customElement } from 'lit/decorators.js';
10
3
  import { styles } from './nile-tour.css';
11
- import NileElement from '../internal/nile-element';
12
4
  import introJs from 'intro.js';
13
- // import 'intro.js/introjs.css';
14
5
 
15
6
  /**
16
7
  * Nile tour component.
17
8
  *
18
9
  * @tag nile-tour
19
- *
20
10
  */
21
11
  @customElement('nile-tour')
22
- export class NileTour extends NileElement {
23
- // Define the type of tourInstance using ReturnType<typeof introJs>
24
- private tourInstance: ReturnType<typeof introJs> | null = null;
25
-
26
- /**
27
- * The steps for the tour.
28
- */
29
- @property({ type: Array })
30
- steps: Array<{
31
- stepNo: number;
32
- element: string;
33
- title: string;
34
- content: string;
35
- position: "top" | "left" | "right" | "bottom";
36
- beforeChange?: () => Promise<boolean> | boolean;
37
- afterChange?: () => Promise<void> | void;
38
- }> = [];
39
-
40
- public static get styles(): CSSResultArray {
41
- return [styles];
42
- }
43
-
44
- createRenderRoot() {
45
- return this;
46
- }
47
-
48
- constructor() {
49
- super();
50
- }
51
-
52
- /**
53
- * Initializes and starts the Intro.js tour.
54
- */
55
- public startTour(): void {
56
- const introSteps = this.steps.map((step) => ({
57
- element: document.querySelector(step.element) as HTMLElement | null,
58
- intro: step.content,
59
- title: step.title,
60
- position: step.position,
61
- beforeChange: step.beforeChange,
62
- afterChange: step.afterChange,
63
- })).filter((step) => step.element !== null); // Filter out steps with null elements
64
-
65
- this.tourInstance = introJs().setOptions({
66
- steps: introSteps,
67
- nextLabel: "<button class='introjs-button introjs-next-button'>Next</button>",
68
- prevLabel: "<button class='introjs-button introjs-prev-button'>Prev</button>",
69
- showButtons: true,
70
- showStepNumbers: true,
71
- });
72
-
73
- // Handle beforeChange
74
- this.tourInstance.onbeforechange(async (targetElement) => {
75
- const currentStepIndex = this.tourInstance?._currentStep ?? 0;
76
- const currentStep = this.steps[currentStepIndex];
77
-
78
- if (currentStep?.beforeChange) {
79
- const result = await currentStep.beforeChange();
80
- return result === true; // Proceed only if `true` is returned
81
- }
82
-
83
- return true; // Proceed if no beforeChange function is provided
84
- });
85
-
86
- // Handle afterChange
87
- this.tourInstance.onafterchange((targetElement) => {
88
- const currentStepIndex = this.tourInstance?._currentStep ?? 0;
89
- const currentStep = this.steps[currentStepIndex];
90
-
91
- if (currentStep?.afterChange) {
92
- currentStep.afterChange();
93
- }
94
- });
95
-
96
- this.tourInstance.start();
97
- }
98
-
99
- /**
100
- * Render method
101
- * @slot This is a slot test
102
- */
103
- public render(): TemplateResult {
104
- return html`
105
- <style>
106
- ${styles.cssText}
107
- </style>
108
- <slot></slot>
109
- `;
110
- }
12
+ export class NileTour extends LitElement {
13
+ private tourInstance: ReturnType<typeof introJs> | null = null;
14
+
15
+ /**
16
+ * The steps for the tour.
17
+ */
18
+ @property({ type: Array })
19
+ steps: Array<{
20
+ stepNo: number;
21
+ element: string;
22
+ title: string;
23
+ content: string;
24
+ position: "top" | "left" | "right" | "bottom";
25
+ beforeChange?: () => Promise<boolean> | boolean;
26
+ afterChange?: () => Promise<void> | void;
27
+ }> = [];
28
+
29
+ /**
30
+ * JSON string for steps.
31
+ */
32
+ @property({ type: String })
33
+ stepsJson: string = '';
34
+
35
+ /**
36
+ * Whether to show the backdrop overlay.
37
+ */
38
+ @property({ type: Boolean })
39
+ showBackdrop: boolean = false;
40
+
41
+ /**
42
+ * Whether to disable interaction during the tour.
43
+ */
44
+ @property({ type: Boolean })
45
+ disableInteraction: boolean = false;
46
+
47
+ public static get styles(): CSSResultArray {
48
+ return [styles];
49
+ }
50
+
51
+ createRenderRoot() {
52
+ return this;
53
+ }
54
+
55
+ constructor() {
56
+ super();
57
+ }
58
+
59
+ updated(changedProperties: Map<string | number | symbol, unknown>): void {
60
+ if (changedProperties.has('stepsJson')) {
61
+ this.parseStepsJson();
62
+ }
63
+ super.updated(changedProperties);
64
+ }
65
+
66
+ /**
67
+ * Parses the JSON string and updates the steps array.
68
+ */
69
+ private parseStepsJson(): void {
70
+ if (this.stepsJson) {
71
+ try {
72
+ const parsedSteps = JSON.parse(this.stepsJson);
73
+ if (Array.isArray(parsedSteps)) {
74
+ this.steps = parsedSteps;
75
+ } else {
76
+ console.error('Invalid JSON: Expected an array');
77
+ }
78
+ } catch (error) {
79
+ console.error('Failed to parse stepsJson:', error);
80
+ }
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Initializes and starts the Intro.js tour.
86
+ */
87
+ public startTour(): void {
88
+ console.log('start of tour');
89
+ const introSteps = this.steps
90
+ .map((step) => ({
91
+ element: document.querySelector(`[data-tour="${step.element}"]`) as HTMLElement | null,
92
+ intro: step.content,
93
+ title: step.title,
94
+ position: step.position,
95
+ beforeChange: step.beforeChange,
96
+ afterChange: step.afterChange,
97
+ }))
98
+ .filter((step) => step.element !== null);
99
+
100
+ this.tourInstance = introJs().setOptions({
101
+ steps: introSteps,
102
+ nextLabel: "<button class='introjs-button introjs-next-button'>Next</button>",
103
+ prevLabel: "<button class='introjs-button introjs-prev-button'>Prev</button>",
104
+ overlayOpacity: 0,
105
+ disableInteraction: this.disableInteraction,
106
+ showButtons: true,
107
+ showStepNumbers: false,
108
+ exitOnOverlayClick: false,
109
+ });
110
+
111
+ this.tourInstance.onbeforechange(async (targetElement) => {
112
+ const currentStepIndex = this.tourInstance?._currentStep ?? 0;
113
+ const currentStep = this.steps[currentStepIndex];
114
+
115
+ if (currentStep?.beforeChange) {
116
+ const result = await currentStep.beforeChange();
117
+ if (!result) {
118
+ this.shakeTooltip();
119
+ return false;
120
+ }
121
+ }
122
+ return true;
123
+ });
124
+
125
+ this.tourInstance.onafterchange((targetElement) => {
126
+ const currentStepIndex = this.tourInstance?._currentStep ?? 0;
127
+ const currentStep = this.steps[currentStepIndex];
128
+
129
+ if (currentStep?.afterChange) {
130
+ currentStep.afterChange();
131
+ }
132
+ });
133
+
134
+ // Update step counter on change
135
+ this.tourInstance.onchange((targetElement) => {
136
+ const currentStep = this.tourInstance?._currentStep ?? 0;
137
+ const totalSteps = this.steps.length;
138
+ const tooltip = document.querySelector('.introjs-tooltip');
139
+ if (tooltip) {
140
+ const navBar = tooltip.querySelector('.introjs-tooltipbuttons');
141
+ if (navBar) {
142
+ let stepCounter = navBar.querySelector('.introjs-step-counter') as HTMLElement;
143
+ if (!stepCounter) {
144
+ stepCounter = document.createElement('div');
145
+ stepCounter.className = 'introjs-step-counter';
146
+ navBar.insertBefore(stepCounter, navBar.firstChild);
147
+ }
148
+ stepCounter.textContent = `${currentStep + 1} of ${totalSteps}`;
149
+ }
150
+ }
151
+ });
152
+
153
+ this.tourInstance.start();
154
+ }
155
+
156
+ private shakeTooltip(): void {
157
+ const tooltip = document.querySelector('.introjs-tooltip');
158
+ if (tooltip) {
159
+ tooltip.classList.add('introjs-shake');
160
+ setTimeout(() => {
161
+ tooltip.classList.remove('introjs-shake');
162
+ }, 1500);
163
+ }
164
+ }
165
+
166
+ public render(): TemplateResult {
167
+ return html`
168
+ <style>
169
+ ${styles.cssText}
170
+ </style>
171
+ <slot></slot>
172
+ `;
173
+ }
111
174
  }
112
175
 
113
176
  export default NileTour;
114
177
 
115
178
  declare global {
116
- interface HTMLElementTagNameMap {
117
- 'nile-tour': NileTour;
118
- }
179
+ interface HTMLElementTagNameMap {
180
+ 'nile-tour': NileTour;
181
+ }
119
182
  }
@@ -3728,11 +3728,25 @@
3728
3728
  },
3729
3729
  {
3730
3730
  "name": "nile-tour",
3731
- "description": "Nile tour component.\n\nAttributes:\n\n * `steps` {`{ stepNo: number; element: string; title: string; content: string; position: \"top\" | \"bottom\" | \"right\" | \"left\"; beforeChange?: (() => boolean | Promise<boolean>) | undefined; afterChange?: (() => void | Promise<...>) | undefined; }[]`} - The steps for the tour.\n\nProperties:\n\n * `tourInstance` - \n\n * `steps` {`{ stepNo: number; element: string; title: string; content: string; position: \"top\" | \"bottom\" | \"right\" | \"left\"; beforeChange?: (() => boolean | Promise<boolean>) | undefined; afterChange?: (() => void | Promise<...>) | undefined; }[]`} - The steps for the tour.\n\n * `BUBBLES` {`boolean`} - \n\n * `COMPOSED` {`boolean`} - \n\n * `CANCELABLE` {`boolean`} - ",
3731
+ "description": "Nile tour component.\n\nAttributes:\n\n * `steps` {`{ stepNo: number; element: string; title: string; content: string; position: \"top\" | \"bottom\" | \"right\" | \"left\"; beforeChange?: (() => boolean | Promise<boolean>) | undefined; afterChange?: (() => void | Promise<...>) | undefined; }[]`} - The steps for the tour.\n\n * `stepsJson` {`string`} - JSON string for steps.\n\n * `showBackdrop` {`boolean`} - Whether to show the backdrop overlay.\n\n * `disableInteraction` {`boolean`} - Whether to disable interaction during the tour.\n\nProperties:\n\n * `tourInstance` - \n\n * `steps` {`{ stepNo: number; element: string; title: string; content: string; position: \"top\" | \"bottom\" | \"right\" | \"left\"; beforeChange?: (() => boolean | Promise<boolean>) | undefined; afterChange?: (() => void | Promise<...>) | undefined; }[]`} - The steps for the tour.\n\n * `stepsJson` {`string`} - JSON string for steps.\n\n * `showBackdrop` {`boolean`} - Whether to show the backdrop overlay.\n\n * `disableInteraction` {`boolean`} - Whether to disable interaction during the tour.",
3732
3732
  "attributes": [
3733
3733
  {
3734
3734
  "name": "steps",
3735
3735
  "description": "`steps` {`{ stepNo: number; element: string; title: string; content: string; position: \"top\" | \"bottom\" | \"right\" | \"left\"; beforeChange?: (() => boolean | Promise<boolean>) | undefined; afterChange?: (() => void | Promise<...>) | undefined; }[]`} - The steps for the tour.\n\nProperty: steps\n\nDefault: "
3736
+ },
3737
+ {
3738
+ "name": "stepsJson",
3739
+ "description": "`stepsJson` {`string`} - JSON string for steps.\n\nProperty: stepsJson\n\nDefault: "
3740
+ },
3741
+ {
3742
+ "name": "showBackdrop",
3743
+ "description": "`showBackdrop` {`boolean`} - Whether to show the backdrop overlay.\n\nProperty: showBackdrop\n\nDefault: false",
3744
+ "valueSet": "v"
3745
+ },
3746
+ {
3747
+ "name": "disableInteraction",
3748
+ "description": "`disableInteraction` {`boolean`} - Whether to disable interaction during the tour.\n\nProperty: disableInteraction\n\nDefault: false",
3749
+ "valueSet": "v"
3736
3750
  }
3737
3751
  ]
3738
3752
  },