@pgy-eu/react-native-tour-guide 0.0.0-stage → 2.0.0

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.
Files changed (161) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +993 -2
  3. package/lib/commonjs/SpotlightOverlay.js +712 -0
  4. package/lib/commonjs/SpotlightOverlay.js.map +1 -0
  5. package/lib/commonjs/Tooltip.js +593 -0
  6. package/lib/commonjs/Tooltip.js.map +1 -0
  7. package/lib/commonjs/TourGuideContext.js +535 -0
  8. package/lib/commonjs/TourGuideContext.js.map +1 -0
  9. package/lib/commonjs/TourGuideOverlay.js +1173 -0
  10. package/lib/commonjs/TourGuideOverlay.js.map +1 -0
  11. package/lib/commonjs/TourTarget.js +80 -0
  12. package/lib/commonjs/TourTarget.js.map +1 -0
  13. package/lib/commonjs/accessibility.js +49 -0
  14. package/lib/commonjs/accessibility.js.map +1 -0
  15. package/lib/commonjs/dev.js +48 -0
  16. package/lib/commonjs/dev.js.map +1 -0
  17. package/lib/commonjs/events.js +56 -0
  18. package/lib/commonjs/events.js.map +1 -0
  19. package/lib/commonjs/index.js +169 -0
  20. package/lib/commonjs/index.js.map +1 -0
  21. package/lib/commonjs/package.json +1 -0
  22. package/lib/commonjs/shapes.js +158 -0
  23. package/lib/commonjs/shapes.js.map +1 -0
  24. package/lib/commonjs/storage.js +116 -0
  25. package/lib/commonjs/storage.js.map +1 -0
  26. package/lib/commonjs/themes.js +86 -0
  27. package/lib/commonjs/themes.js.map +1 -0
  28. package/lib/commonjs/types.js +6 -0
  29. package/lib/commonjs/types.js.map +1 -0
  30. package/lib/commonjs/useTourPersistence.js +135 -0
  31. package/lib/commonjs/useTourPersistence.js.map +1 -0
  32. package/lib/commonjs/useTourScroll.js +46 -0
  33. package/lib/commonjs/useTourScroll.js.map +1 -0
  34. package/lib/commonjs/utils.js +372 -0
  35. package/lib/commonjs/utils.js.map +1 -0
  36. package/lib/commonjs/validation.js +143 -0
  37. package/lib/commonjs/validation.js.map +1 -0
  38. package/lib/module/SpotlightOverlay.js +707 -0
  39. package/lib/module/SpotlightOverlay.js.map +1 -0
  40. package/lib/module/Tooltip.js +588 -0
  41. package/lib/module/Tooltip.js.map +1 -0
  42. package/lib/module/TourGuideContext.js +529 -0
  43. package/lib/module/TourGuideContext.js.map +1 -0
  44. package/lib/module/TourGuideOverlay.js +1167 -0
  45. package/lib/module/TourGuideOverlay.js.map +1 -0
  46. package/lib/module/TourTarget.js +74 -0
  47. package/lib/module/TourTarget.js.map +1 -0
  48. package/lib/module/accessibility.js +43 -0
  49. package/lib/module/accessibility.js.map +1 -0
  50. package/lib/module/dev.js +40 -0
  51. package/lib/module/dev.js.map +1 -0
  52. package/lib/module/events.js +51 -0
  53. package/lib/module/events.js.map +1 -0
  54. package/lib/module/index.js +25 -0
  55. package/lib/module/index.js.map +1 -0
  56. package/lib/module/package.json +1 -0
  57. package/lib/module/shapes.js +152 -0
  58. package/lib/module/shapes.js.map +1 -0
  59. package/lib/module/storage.js +111 -0
  60. package/lib/module/storage.js.map +1 -0
  61. package/lib/module/themes.js +81 -0
  62. package/lib/module/themes.js.map +1 -0
  63. package/lib/module/types.js +4 -0
  64. package/lib/module/types.js.map +1 -0
  65. package/lib/module/useTourPersistence.js +130 -0
  66. package/lib/module/useTourPersistence.js.map +1 -0
  67. package/lib/module/useTourScroll.js +41 -0
  68. package/lib/module/useTourScroll.js.map +1 -0
  69. package/lib/module/utils.js +361 -0
  70. package/lib/module/utils.js.map +1 -0
  71. package/lib/module/validation.js +138 -0
  72. package/lib/module/validation.js.map +1 -0
  73. package/lib/typescript/commonjs/package.json +1 -0
  74. package/lib/typescript/commonjs/src/SpotlightOverlay.d.ts +46 -0
  75. package/lib/typescript/commonjs/src/SpotlightOverlay.d.ts.map +1 -0
  76. package/lib/typescript/commonjs/src/Tooltip.d.ts +9 -0
  77. package/lib/typescript/commonjs/src/Tooltip.d.ts.map +1 -0
  78. package/lib/typescript/commonjs/src/TourGuideContext.d.ts +46 -0
  79. package/lib/typescript/commonjs/src/TourGuideContext.d.ts.map +1 -0
  80. package/lib/typescript/commonjs/src/TourGuideOverlay.d.ts +22 -0
  81. package/lib/typescript/commonjs/src/TourGuideOverlay.d.ts.map +1 -0
  82. package/lib/typescript/commonjs/src/TourTarget.d.ts +36 -0
  83. package/lib/typescript/commonjs/src/TourTarget.d.ts.map +1 -0
  84. package/lib/typescript/commonjs/src/accessibility.d.ts +22 -0
  85. package/lib/typescript/commonjs/src/accessibility.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/src/dev.d.ts +22 -0
  87. package/lib/typescript/commonjs/src/dev.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/src/events.d.ts +57 -0
  89. package/lib/typescript/commonjs/src/events.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/src/index.d.ts +21 -0
  91. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/src/shapes.d.ts +50 -0
  93. package/lib/typescript/commonjs/src/shapes.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/src/storage.d.ts +15 -0
  95. package/lib/typescript/commonjs/src/storage.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/src/themes.d.ts +10 -0
  97. package/lib/typescript/commonjs/src/themes.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/src/types.d.ts +599 -0
  99. package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
  100. package/lib/typescript/commonjs/src/useTourPersistence.d.ts +63 -0
  101. package/lib/typescript/commonjs/src/useTourPersistence.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/src/useTourScroll.d.ts +36 -0
  103. package/lib/typescript/commonjs/src/useTourScroll.d.ts.map +1 -0
  104. package/lib/typescript/commonjs/src/utils.d.ts +97 -0
  105. package/lib/typescript/commonjs/src/utils.d.ts.map +1 -0
  106. package/lib/typescript/commonjs/src/validation.d.ts +11 -0
  107. package/lib/typescript/commonjs/src/validation.d.ts.map +1 -0
  108. package/lib/typescript/module/package.json +1 -0
  109. package/lib/typescript/module/src/SpotlightOverlay.d.ts +46 -0
  110. package/lib/typescript/module/src/SpotlightOverlay.d.ts.map +1 -0
  111. package/lib/typescript/module/src/Tooltip.d.ts +9 -0
  112. package/lib/typescript/module/src/Tooltip.d.ts.map +1 -0
  113. package/lib/typescript/module/src/TourGuideContext.d.ts +46 -0
  114. package/lib/typescript/module/src/TourGuideContext.d.ts.map +1 -0
  115. package/lib/typescript/module/src/TourGuideOverlay.d.ts +22 -0
  116. package/lib/typescript/module/src/TourGuideOverlay.d.ts.map +1 -0
  117. package/lib/typescript/module/src/TourTarget.d.ts +36 -0
  118. package/lib/typescript/module/src/TourTarget.d.ts.map +1 -0
  119. package/lib/typescript/module/src/accessibility.d.ts +22 -0
  120. package/lib/typescript/module/src/accessibility.d.ts.map +1 -0
  121. package/lib/typescript/module/src/dev.d.ts +22 -0
  122. package/lib/typescript/module/src/dev.d.ts.map +1 -0
  123. package/lib/typescript/module/src/events.d.ts +57 -0
  124. package/lib/typescript/module/src/events.d.ts.map +1 -0
  125. package/lib/typescript/module/src/index.d.ts +21 -0
  126. package/lib/typescript/module/src/index.d.ts.map +1 -0
  127. package/lib/typescript/module/src/shapes.d.ts +50 -0
  128. package/lib/typescript/module/src/shapes.d.ts.map +1 -0
  129. package/lib/typescript/module/src/storage.d.ts +15 -0
  130. package/lib/typescript/module/src/storage.d.ts.map +1 -0
  131. package/lib/typescript/module/src/themes.d.ts +10 -0
  132. package/lib/typescript/module/src/themes.d.ts.map +1 -0
  133. package/lib/typescript/module/src/types.d.ts +599 -0
  134. package/lib/typescript/module/src/types.d.ts.map +1 -0
  135. package/lib/typescript/module/src/useTourPersistence.d.ts +63 -0
  136. package/lib/typescript/module/src/useTourPersistence.d.ts.map +1 -0
  137. package/lib/typescript/module/src/useTourScroll.d.ts +36 -0
  138. package/lib/typescript/module/src/useTourScroll.d.ts.map +1 -0
  139. package/lib/typescript/module/src/utils.d.ts +97 -0
  140. package/lib/typescript/module/src/utils.d.ts.map +1 -0
  141. package/lib/typescript/module/src/validation.d.ts +11 -0
  142. package/lib/typescript/module/src/validation.d.ts.map +1 -0
  143. package/llms.txt +62 -0
  144. package/package.json +281 -4
  145. package/src/SpotlightOverlay.tsx +742 -0
  146. package/src/Tooltip.tsx +638 -0
  147. package/src/TourGuideContext.tsx +644 -0
  148. package/src/TourGuideOverlay.tsx +1382 -0
  149. package/src/TourTarget.tsx +74 -0
  150. package/src/accessibility.ts +60 -0
  151. package/src/dev.ts +39 -0
  152. package/src/events.ts +76 -0
  153. package/src/index.tsx +64 -0
  154. package/src/shapes.ts +184 -0
  155. package/src/storage.ts +114 -0
  156. package/src/themes.ts +83 -0
  157. package/src/types.ts +648 -0
  158. package/src/useTourPersistence.ts +147 -0
  159. package/src/useTourScroll.ts +60 -0
  160. package/src/utils.ts +401 -0
  161. package/src/validation.ts +248 -0
@@ -0,0 +1,248 @@
1
+ import type { ResolvedTourGuideConfig, TourStep } from './types';
2
+ import { isDev, warn } from './dev';
3
+
4
+ const VALID_POSITIONS = ['top', 'bottom', 'left', 'right', 'auto'];
5
+ const VALID_MOTIONS = ['morph', 'bounce', 'fade', 'none'];
6
+
7
+ /**
8
+ * Does this value look like a React ref object (`{ current: ... }`)?
9
+ * Callback refs and bare component instances are the two things people pass by
10
+ * mistake, and both fail silently at measure time — so we detect them up front.
11
+ */
12
+ const looksLikeRef = (value: unknown): boolean =>
13
+ typeof value === 'object' && value !== null && 'current' in (value as object);
14
+
15
+ /**
16
+ * Validate tour steps and config in development and report actionable warnings.
17
+ *
18
+ * Every check here corresponds to a mistake that otherwise fails *silently* at
19
+ * runtime — the tour simply does nothing, or shows a centered tooltip with no
20
+ * explanation — which is the hardest class of bug to diagnose from the outside.
21
+ * Runs only in dev; it is a no-op in production builds.
22
+ */
23
+ export const validateTour = (steps: TourStep[], config?: ResolvedTourGuideConfig): void => {
24
+ if (!isDev()) return;
25
+
26
+ if (!Array.isArray(steps)) {
27
+ warn(
28
+ `startTour() was called with ${typeof steps} instead of an array of steps.`,
29
+ 'Pass an array: startTour([{ id, title, description }]).'
30
+ );
31
+ return;
32
+ }
33
+
34
+ if (steps.length === 0) {
35
+ warn(
36
+ 'startTour() was called with an empty steps array, so there is nothing to show.',
37
+ 'Pass at least one step, and build the array before calling startTour().'
38
+ );
39
+ return;
40
+ }
41
+
42
+ const seenIds = new Set<string>();
43
+
44
+ steps.forEach((step, index) => {
45
+ const where = `Step ${index}${step?.id ? ` ("${step.id}")` : ''}`;
46
+
47
+ if (!step || typeof step !== 'object') {
48
+ warn(
49
+ `${where} is not an object.`,
50
+ 'Each step must be an object with id, title and description.'
51
+ );
52
+ return;
53
+ }
54
+
55
+ // --- id ---
56
+ if (!step.id) {
57
+ warn(
58
+ `${where} has no "id".`,
59
+ 'Give every step a unique string id — it is used for React keys and warnings.'
60
+ );
61
+ } else if (seenIds.has(step.id)) {
62
+ warn(
63
+ `${where} reuses the id "${step.id}", which is already used by an earlier step.`,
64
+ 'Make every step id unique so steps can be told apart.'
65
+ );
66
+ } else {
67
+ seenIds.add(step.id);
68
+ }
69
+
70
+ // --- content ---
71
+ if (typeof step.title !== 'string' || step.title.length === 0) {
72
+ warn(
73
+ `${where} has no "title".`,
74
+ 'Provide a non-empty title string; it is the tooltip heading.'
75
+ );
76
+ }
77
+ if (typeof step.description !== 'string' || step.description.length === 0) {
78
+ warn(
79
+ `${where} has no "description".`,
80
+ 'Provide a non-empty description string; it is the tooltip body.'
81
+ );
82
+ }
83
+
84
+ if (step.targetRegion !== undefined) {
85
+ const r = step.targetRegion;
86
+ if (
87
+ typeof r !== 'object' ||
88
+ r === null ||
89
+ [r.x, r.y, r.width, r.height].some((v) => typeof v !== 'number' || Number.isNaN(v)) ||
90
+ r.width <= 0 ||
91
+ r.height <= 0
92
+ ) {
93
+ warn(
94
+ `${where} has an invalid targetRegion — it needs numeric x, y and positive width/height in window px.`,
95
+ 'Example: targetRegion: { x: 24, y: 120, width: 200, height: 80 }.'
96
+ );
97
+ }
98
+ if (step.targetRef !== undefined || step.targetId !== undefined) {
99
+ warn(
100
+ `${where} sets targetRegion together with targetRef/targetId — targetRegion wins and the others are ignored.`,
101
+ 'Use one targeting method per step.'
102
+ );
103
+ }
104
+ }
105
+
106
+ if (step.motion !== undefined && !VALID_MOTIONS.includes(step.motion)) {
107
+ warn(
108
+ `${where} has motion "${step.motion}", which is not valid.`,
109
+ `Use one of: ${VALID_MOTIONS.join(', ')}.`
110
+ );
111
+ }
112
+
113
+ if (step.targetRef !== undefined && step.targetId !== undefined) {
114
+ warn(
115
+ `${where} sets both targetRef and targetId — targetRef wins and targetId is ignored.`,
116
+ 'Use one or the other.'
117
+ );
118
+ }
119
+
120
+ // --- targetRef: the single most common wiring mistake ---
121
+ if (step.targetRef !== undefined && !looksLikeRef(step.targetRef)) {
122
+ warn(
123
+ `${where} has a "targetRef" that is not a ref object (received ${typeof step.targetRef}).`,
124
+ 'Pass the ref itself, not its value: targetRef={myRef} where const myRef = useRef(null). Callback refs are not supported.'
125
+ );
126
+ }
127
+
128
+ // --- tooltipPosition ---
129
+ if (step.tooltipPosition !== undefined && !VALID_POSITIONS.includes(step.tooltipPosition)) {
130
+ warn(
131
+ `${where} has tooltipPosition "${step.tooltipPosition}", which is not valid.`,
132
+ `Use one of: ${VALID_POSITIONS.join(', ')}.`
133
+ );
134
+ }
135
+
136
+ // --- numeric options ---
137
+ if (step.spotlightPadding !== undefined) {
138
+ const pads =
139
+ typeof step.spotlightPadding === 'number'
140
+ ? [step.spotlightPadding]
141
+ : Object.values(step.spotlightPadding);
142
+ if (pads.some((v) => typeof v === 'number' && v < 0)) {
143
+ warn(
144
+ `${where} has a negative spotlightPadding, which shrinks the spotlight below the target.`,
145
+ 'Use values >= 0.'
146
+ );
147
+ }
148
+ }
149
+ if (step.autoAdvance !== undefined && step.autoAdvance > 0 && step.autoAdvance < 500) {
150
+ warn(
151
+ `${where} sets autoAdvance to ${step.autoAdvance}ms, which is too fast to read.`,
152
+ 'Use at least 500ms, or 0 to disable auto-advance.'
153
+ );
154
+ }
155
+
156
+ // --- per-step scroll config ---
157
+ const stepScroll = step.scrollToTarget;
158
+ if (stepScroll && !looksLikeRef(stepScroll.scrollRef)) {
159
+ warn(
160
+ `${where} has scrollToTarget.scrollRef that is not a ref object.`,
161
+ 'Pass the ScrollView/FlatList ref itself: scrollRef={scrollViewRef}.'
162
+ );
163
+ }
164
+ if (
165
+ stepScroll?.getCurrentScrollOffset !== undefined &&
166
+ typeof stepScroll.getCurrentScrollOffset !== 'function'
167
+ ) {
168
+ warn(
169
+ `${where} has scrollToTarget.getCurrentScrollOffset that is not a function.`,
170
+ 'Pass a getter function: getCurrentScrollOffset: () => scrollY.'
171
+ );
172
+ }
173
+
174
+ // --- hiding every control on a step traps the user ---
175
+ if (step.hideNextButton && step.hideSkipButton && !step.autoAdvance) {
176
+ warn(
177
+ `${where} hides both the next and skip buttons with no autoAdvance, leaving no way to continue the tour.`,
178
+ 'Keep one of them visible, set autoAdvance, or handle advancing yourself via onSpotlightPress / backdropBehavior.'
179
+ );
180
+ }
181
+ });
182
+
183
+ if (steps.some((st) => st?.interactive) && config?.overlayMode !== 'inline') {
184
+ warn(
185
+ "A step sets interactive: true but config.overlayMode is not 'inline', so the Modal overlay will swallow the touches anyway.",
186
+ "Set overlayMode: 'inline' on the tour config to let touches reach the highlighted element."
187
+ );
188
+ }
189
+
190
+ validateConfig(config);
191
+ };
192
+
193
+ /** Validate the tour-level config. Dev only. */
194
+ const validateConfig = (config?: ResolvedTourGuideConfig): void => {
195
+ if (!config) return;
196
+
197
+ if (config.scrollRef !== undefined && !looksLikeRef(config.scrollRef)) {
198
+ warn(
199
+ `config.scrollRef is not a ref object (received ${typeof config.scrollRef}).`,
200
+ 'Pass the ref itself: scrollRef: scrollViewRef, where const scrollViewRef = useRef(null).'
201
+ );
202
+ }
203
+
204
+ if (
205
+ config.getCurrentScrollOffset !== undefined &&
206
+ typeof config.getCurrentScrollOffset !== 'function'
207
+ ) {
208
+ warn(
209
+ 'config.getCurrentScrollOffset is not a function.',
210
+ 'Pass a getter: getCurrentScrollOffset: () => scrollY.'
211
+ );
212
+ }
213
+
214
+ if (config.renderTooltip !== undefined && typeof config.renderTooltip !== 'function') {
215
+ warn(
216
+ 'config.renderTooltip is not a function.',
217
+ 'Pass a render function: renderTooltip: (props) => <MyTooltip {...props} />.'
218
+ );
219
+ }
220
+
221
+ if (config.animationDuration !== undefined && config.animationDuration < 0) {
222
+ warn(
223
+ 'config.animationDuration is negative.',
224
+ 'Use 0 to disable animation, or a positive duration in ms.'
225
+ );
226
+ }
227
+
228
+ if (config.motion !== undefined && !VALID_MOTIONS.includes(config.motion)) {
229
+ warn(
230
+ `config.motion "${config.motion}" is not valid.`,
231
+ `Use one of: ${VALID_MOTIONS.join(', ')}.`
232
+ );
233
+ }
234
+
235
+ if (
236
+ config.spotlightStyles?.maskPath !== undefined &&
237
+ typeof config.spotlightStyles.maskPath !== 'function'
238
+ ) {
239
+ warn(
240
+ 'config.spotlightStyles.maskPath is not a function.',
241
+ 'Pass a function returning an SVG subpath: maskPath: ({ bounds }) => `M…Z`.'
242
+ );
243
+ }
244
+
245
+ if (config.tooltipWidth !== undefined && config.tooltipWidth <= 0) {
246
+ warn('config.tooltipWidth must be greater than 0.', 'Remove it to use the 320px default.');
247
+ }
248
+ };