@eventop/sdk 1.1.4 → 1.1.6

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.
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var react = require('react');
6
4
  var jsxRuntime = require('react/jsx-runtime');
7
5
 
@@ -28,202 +26,6 @@ function useFeatureScope() {
28
26
  return react.useContext(EventopFeatureScopeContext); // null is fine — steps can declare feature explicitly
29
27
  }
30
28
 
31
- function EventopTarget({
32
- children,
33
- id,
34
- name,
35
- description,
36
- navigate,
37
- navigateWaitFor,
38
- advanceOn,
39
- waitFor,
40
- ...rest
41
- }) {
42
- const registry = useRegistry();
43
- const ref = react.useRef(null);
44
- const dataAttr = `data-evtp-${id}`;
45
- const selector = `[${dataAttr}]`;
46
- react.useEffect(() => {
47
- if (!id || !name) {
48
- console.warn('[Eventop] <EventopTarget> requires id and name props.');
49
- return;
50
- }
51
- registry.registerFeature({
52
- id,
53
- name,
54
- description,
55
- selector,
56
- navigate,
57
- navigateWaitFor,
58
- waitFor,
59
- advanceOn: advanceOn ? {
60
- selector,
61
- ...advanceOn
62
- } : null
63
- });
64
- return () => registry.unregisterFeature(id);
65
- }, [id, name, description]);
66
- const child = react.Children.only(children);
67
- let wrapped;
68
- try {
69
- wrapped = /*#__PURE__*/react.cloneElement(child, {
70
- [dataAttr]: '',
71
- ref: node => {
72
- ref.current = node;
73
- const originalRef = child.ref;
74
- if (typeof originalRef === 'function') originalRef(node);else if (originalRef && 'current' in originalRef) originalRef.current = node;
75
- }
76
- });
77
- } catch {
78
- wrapped = /*#__PURE__*/jsxRuntime.jsx("span", {
79
- [dataAttr]: '',
80
- ref: ref,
81
- style: {
82
- display: 'contents'
83
- },
84
- children: child
85
- });
86
- }
87
- return /*#__PURE__*/jsxRuntime.jsx(EventopFeatureScopeContext.Provider, {
88
- value: id,
89
- children: wrapped
90
- });
91
- }
92
-
93
- function EventopStep({
94
- children,
95
- feature,
96
- index,
97
- parentStep,
98
- waitFor,
99
- advanceOn
100
- }) {
101
- const registry = useRegistry();
102
- const featureScope = useFeatureScope();
103
- const featureId = feature || featureScope;
104
- const ref = react.useRef(null);
105
- if (!featureId) {
106
- console.warn('[Eventop] <EventopStep> needs either a feature prop or an <EventopTarget> ancestor.');
107
- }
108
- if (index == null) {
109
- console.warn('[Eventop] <EventopStep> requires an index prop.');
110
- }
111
- const dataAttr = `data-evtp-step-${featureId}-${parentStep != null ? `${parentStep}-` : ''}${index}`;
112
- const selector = `[${dataAttr}]`;
113
- react.useEffect(() => {
114
- if (!featureId || index == null) return;
115
- registry.registerStep(featureId, index, parentStep ?? null, {
116
- selector,
117
- waitFor: waitFor || null,
118
- advanceOn: advanceOn ? {
119
- selector,
120
- ...advanceOn
121
- } : null
122
- });
123
- return () => registry.unregisterStep(featureId, index, parentStep ?? null);
124
- }, [featureId, index, parentStep]);
125
- const child = react.Children.only(children);
126
- let wrapped;
127
- try {
128
- wrapped = /*#__PURE__*/react.cloneElement(child, {
129
- [dataAttr]: '',
130
- ref: node => {
131
- ref.current = node;
132
- const originalRef = child.ref;
133
- if (typeof originalRef === 'function') originalRef(node);else if (originalRef && 'current' in originalRef) originalRef.current = node;
134
- }
135
- });
136
- } catch {
137
- wrapped = /*#__PURE__*/jsxRuntime.jsx("span", {
138
- [dataAttr]: '',
139
- ref: ref,
140
- style: {
141
- display: 'contents'
142
- },
143
- children: child
144
- });
145
- }
146
- return wrapped;
147
- }
148
-
149
- // ═══════════════════════════════════════════════════════════════════════════
150
- // useEventopAI
151
- //
152
- // Access the SDK programmatic API from inside any component.
153
- // Use for stepComplete(), stepFail(), open(), close() etc.
154
- //
155
- // @example
156
- // function CheckoutForm() {
157
- // const { stepComplete, stepFail } = useEventopAI();
158
- //
159
- // async function handleNext() {
160
- // const ok = await validateEmail(email);
161
- // if (ok) stepComplete();
162
- // else stepFail('Please enter a valid email address.');
163
- // }
164
- // }
165
- // ═══════════════════════════════════════════════════════════════════════════
166
-
167
- function useEventopAI() {
168
- const sdk = () => window.Eventop;
169
- return {
170
- open: () => sdk()?.open(),
171
- close: () => sdk()?.close(),
172
- cancelTour: () => sdk()?.cancelTour(),
173
- resumeTour: () => sdk()?.resumeTour(),
174
- isActive: () => sdk()?.isActive() ?? false,
175
- isPaused: () => sdk()?.isPaused() ?? false,
176
- stepComplete: () => sdk()?.stepComplete(),
177
- stepFail: msg => sdk()?.stepFail(msg),
178
- runTour: steps => sdk()?.runTour(steps)
179
- };
180
- }
181
-
182
- // ═══════════════════════════════════════════════════════════════════════════
183
- // useEventopTour
184
- //
185
- // Reactively tracks tour state so you can render your own UI.
186
- // Polls at 300ms — lightweight enough for a status indicator.
187
- //
188
- // @example
189
- // function TourBar() {
190
- // const { isActive, isPaused, resume, cancel } = useEventopTour();
191
- // if (!isActive && !isPaused) return null;
192
- // return (
193
- // <div>
194
- // {isPaused && <button onClick={resume}>Resume tour</button>}
195
- // <button onClick={cancel}>End</button>
196
- // </div>
197
- // );
198
- // }
199
- // ═══════════════════════════════════════════════════════════════════════════
200
-
201
- function useEventopTour() {
202
- const [state, setState] = react.useState({
203
- isActive: false,
204
- isPaused: false
205
- });
206
- react.useEffect(() => {
207
- const id = setInterval(() => {
208
- const sdk = window.Eventop;
209
- if (!sdk) return;
210
- const next = {
211
- isActive: sdk.isActive(),
212
- isPaused: sdk.isPaused()
213
- };
214
- setState(prev => prev.isActive !== next.isActive || prev.isPaused !== next.isPaused ? next : prev);
215
- }, 300);
216
- return () => clearInterval(id);
217
- }, []);
218
- return {
219
- ...state,
220
- resume: react.useCallback(() => window.Eventop?.resumeTour(), []),
221
- cancel: react.useCallback(() => window.Eventop?.cancelTour(), []),
222
- open: react.useCallback(() => window.Eventop?.open(), []),
223
- close: react.useCallback(() => window.Eventop?.close(), [])
224
- };
225
- }
226
-
227
29
  /**
228
30
  * FeatureRegistry
229
31
  *
@@ -400,13 +202,17 @@ function EventopProvider({
400
202
  const registry = react.useRef(createFeatureRegistry()).current;
401
203
  const sdkReady = react.useRef(false);
402
204
  const syncToSDK = react.useCallback(() => {
205
+ var _window$Eventop$_upda, _window$Eventop;
403
206
  if (!sdkReady.current || !window.Eventop) return;
404
- window.Eventop._updateConfig?.({
207
+ (_window$Eventop$_upda = (_window$Eventop = window.Eventop)._updateConfig) === null || _window$Eventop$_upda === void 0 || _window$Eventop$_upda.call(_window$Eventop, {
405
208
  features: registry.snapshot()
406
209
  });
407
210
  }, [registry]);
408
211
  react.useEffect(() => {
409
- function boot() {
212
+ // Dynamically import core.js only in the browser
213
+ async function boot() {
214
+ // Import the core SDK (this only runs on client)
215
+ await Promise.resolve().then(function () { return require('./core.cjs'); }).then(function (n) { return n.core; });
410
216
  window.Eventop.init({
411
217
  provider,
412
218
  config: {
@@ -426,9 +232,12 @@ function EventopProvider({
426
232
  const unsub = registry.subscribe(syncToSDK);
427
233
  return () => {
428
234
  unsub();
429
- window.Eventop?.cancelTour();
235
+ if (typeof window !== 'undefined') {
236
+ var _window$Eventop2;
237
+ (_window$Eventop2 = window.Eventop) === null || _window$Eventop2 === void 0 || _window$Eventop2.cancelTour();
238
+ }
430
239
  };
431
- }, []);
240
+ }, [provider, appName, assistantName, suggestions, theme, position, registry, syncToSDK]);
432
241
  const ctx = {
433
242
  registerFeature: registry.registerFeature,
434
243
  unregisterFeature: registry.unregisterFeature,
@@ -442,25 +251,243 @@ function EventopProvider({
442
251
  });
443
252
  }
444
253
 
445
- window.EventopAI = {
446
- init,
447
- open,
448
- close,
449
- cancelTour,
450
- resumeTour,
451
- stepComplete,
452
- stepFail,
453
- isActive,
454
- isPaused,
455
- runTour,
456
- _updateConfig,
457
- providers
458
- };
459
- var index = window.EventopAI;
254
+ function EventopTarget({
255
+ children,
256
+ id,
257
+ name,
258
+ description,
259
+ navigate,
260
+ navigateWaitFor,
261
+ advanceOn,
262
+ waitFor,
263
+ ...rest
264
+ }) {
265
+ const registry = useRegistry();
266
+ const ref = react.useRef(null);
267
+ const dataAttr = `data-evtp-${id}`;
268
+ const selector = `[${dataAttr}]`;
269
+ react.useEffect(() => {
270
+ if (!id || !name) {
271
+ console.warn('[Eventop] <EventopTarget> requires id and name props.');
272
+ return;
273
+ }
274
+ registry.registerFeature({
275
+ id,
276
+ name,
277
+ description,
278
+ selector,
279
+ navigate,
280
+ navigateWaitFor,
281
+ waitFor,
282
+ advanceOn: advanceOn ? {
283
+ selector,
284
+ ...advanceOn
285
+ } : null
286
+ });
287
+ return () => registry.unregisterFeature(id);
288
+ }, [id, name, description]);
289
+ const child = react.Children.only(children);
290
+ let wrapped;
291
+ try {
292
+ wrapped = /*#__PURE__*/react.cloneElement(child, {
293
+ [dataAttr]: '',
294
+ ref: node => {
295
+ ref.current = node;
296
+ const originalRef = child.ref;
297
+ if (typeof originalRef === 'function') originalRef(node);else if (originalRef && 'current' in originalRef) originalRef.current = node;
298
+ }
299
+ });
300
+ } catch {
301
+ wrapped = /*#__PURE__*/jsxRuntime.jsx("span", {
302
+ [dataAttr]: '',
303
+ ref: ref,
304
+ style: {
305
+ display: 'contents'
306
+ },
307
+ children: child
308
+ });
309
+ }
310
+ return /*#__PURE__*/jsxRuntime.jsx(EventopFeatureScopeContext.Provider, {
311
+ value: id,
312
+ children: wrapped
313
+ });
314
+ }
315
+
316
+ function EventopStep({
317
+ children,
318
+ feature,
319
+ index,
320
+ parentStep,
321
+ waitFor,
322
+ advanceOn
323
+ }) {
324
+ const registry = useRegistry();
325
+ const featureScope = useFeatureScope();
326
+ const featureId = feature || featureScope;
327
+ const ref = react.useRef(null);
328
+ if (!featureId) {
329
+ console.warn('[Eventop] <EventopStep> needs either a feature prop or an <EventopTarget> ancestor.');
330
+ }
331
+ if (index == null) {
332
+ console.warn('[Eventop] <EventopStep> requires an index prop.');
333
+ }
334
+ const dataAttr = `data-evtp-step-${featureId}-${parentStep != null ? `${parentStep}-` : ''}${index}`;
335
+ const selector = `[${dataAttr}]`;
336
+ react.useEffect(() => {
337
+ if (!featureId || index == null) return;
338
+ registry.registerStep(featureId, index, parentStep ?? null, {
339
+ selector,
340
+ waitFor: waitFor || null,
341
+ advanceOn: advanceOn ? {
342
+ selector,
343
+ ...advanceOn
344
+ } : null
345
+ });
346
+ return () => registry.unregisterStep(featureId, index, parentStep ?? null);
347
+ }, [featureId, index, parentStep]);
348
+ const child = react.Children.only(children);
349
+ let wrapped;
350
+ try {
351
+ wrapped = /*#__PURE__*/react.cloneElement(child, {
352
+ [dataAttr]: '',
353
+ ref: node => {
354
+ ref.current = node;
355
+ const originalRef = child.ref;
356
+ if (typeof originalRef === 'function') originalRef(node);else if (originalRef && 'current' in originalRef) originalRef.current = node;
357
+ }
358
+ });
359
+ } catch {
360
+ wrapped = /*#__PURE__*/jsxRuntime.jsx("span", {
361
+ [dataAttr]: '',
362
+ ref: ref,
363
+ style: {
364
+ display: 'contents'
365
+ },
366
+ children: child
367
+ });
368
+ }
369
+ return wrapped;
370
+ }
371
+
372
+ // ═══════════════════════════════════════════════════════════════════════════
373
+ // useEventopAI
374
+ //
375
+ // Access the SDK programmatic API from inside any component.
376
+ // Use for stepComplete(), stepFail(), open(), close() etc.
377
+ //
378
+ // @example
379
+ // function CheckoutForm() {
380
+ // const { stepComplete, stepFail } = useEventopAI();
381
+ //
382
+ // async function handleNext() {
383
+ // const ok = await validateEmail(email);
384
+ // if (ok) stepComplete();
385
+ // else stepFail('Please enter a valid email address.');
386
+ // }
387
+ // }
388
+ // ═══════════════════════════════════════════════════════════════════════════
389
+
390
+ function useEventopAI() {
391
+ const sdk = () => window.Eventop;
392
+ return {
393
+ open: () => {
394
+ var _sdk;
395
+ return (_sdk = sdk()) === null || _sdk === void 0 ? void 0 : _sdk.open();
396
+ },
397
+ close: () => {
398
+ var _sdk2;
399
+ return (_sdk2 = sdk()) === null || _sdk2 === void 0 ? void 0 : _sdk2.close();
400
+ },
401
+ cancelTour: () => {
402
+ var _sdk3;
403
+ return (_sdk3 = sdk()) === null || _sdk3 === void 0 ? void 0 : _sdk3.cancelTour();
404
+ },
405
+ resumeTour: () => {
406
+ var _sdk4;
407
+ return (_sdk4 = sdk()) === null || _sdk4 === void 0 ? void 0 : _sdk4.resumeTour();
408
+ },
409
+ isActive: () => {
410
+ var _sdk5;
411
+ return ((_sdk5 = sdk()) === null || _sdk5 === void 0 ? void 0 : _sdk5.isActive()) ?? false;
412
+ },
413
+ isPaused: () => {
414
+ var _sdk6;
415
+ return ((_sdk6 = sdk()) === null || _sdk6 === void 0 ? void 0 : _sdk6.isPaused()) ?? false;
416
+ },
417
+ stepComplete: () => {
418
+ var _sdk7;
419
+ return (_sdk7 = sdk()) === null || _sdk7 === void 0 ? void 0 : _sdk7.stepComplete();
420
+ },
421
+ stepFail: msg => {
422
+ var _sdk8;
423
+ return (_sdk8 = sdk()) === null || _sdk8 === void 0 ? void 0 : _sdk8.stepFail(msg);
424
+ },
425
+ runTour: steps => {
426
+ var _sdk9;
427
+ return (_sdk9 = sdk()) === null || _sdk9 === void 0 ? void 0 : _sdk9.runTour(steps);
428
+ }
429
+ };
430
+ }
431
+
432
+ // ═══════════════════════════════════════════════════════════════════════════
433
+ // useEventopTour
434
+ //
435
+ // Reactively tracks tour state so you can render your own UI.
436
+ // Polls at 300ms — lightweight enough for a status indicator.
437
+ //
438
+ // @example
439
+ // function TourBar() {
440
+ // const { isActive, isPaused, resume, cancel } = useEventopTour();
441
+ // if (!isActive && !isPaused) return null;
442
+ // return (
443
+ // <div>
444
+ // {isPaused && <button onClick={resume}>Resume tour</button>}
445
+ // <button onClick={cancel}>End</button>
446
+ // </div>
447
+ // );
448
+ // }
449
+ // ═══════════════════════════════════════════════════════════════════════════
450
+
451
+ function useEventopTour() {
452
+ const [state, setState] = react.useState({
453
+ isActive: false,
454
+ isPaused: false
455
+ });
456
+ react.useEffect(() => {
457
+ const id = setInterval(() => {
458
+ const sdk = window.Eventop;
459
+ if (!sdk) return;
460
+ const next = {
461
+ isActive: sdk.isActive(),
462
+ isPaused: sdk.isPaused()
463
+ };
464
+ setState(prev => prev.isActive !== next.isActive || prev.isPaused !== next.isPaused ? next : prev);
465
+ }, 300);
466
+ return () => clearInterval(id);
467
+ }, []);
468
+ return {
469
+ ...state,
470
+ resume: react.useCallback(() => {
471
+ var _window$Eventop;
472
+ return (_window$Eventop = window.Eventop) === null || _window$Eventop === void 0 ? void 0 : _window$Eventop.resumeTour();
473
+ }, []),
474
+ cancel: react.useCallback(() => {
475
+ var _window$Eventop2;
476
+ return (_window$Eventop2 = window.Eventop) === null || _window$Eventop2 === void 0 ? void 0 : _window$Eventop2.cancelTour();
477
+ }, []),
478
+ open: react.useCallback(() => {
479
+ var _window$Eventop3;
480
+ return (_window$Eventop3 = window.Eventop) === null || _window$Eventop3 === void 0 ? void 0 : _window$Eventop3.open();
481
+ }, []),
482
+ close: react.useCallback(() => {
483
+ var _window$Eventop4;
484
+ return (_window$Eventop4 = window.Eventop) === null || _window$Eventop4 === void 0 ? void 0 : _window$Eventop4.close();
485
+ }, [])
486
+ };
487
+ }
460
488
 
461
489
  exports.EventopAIProvider = EventopProvider;
462
490
  exports.EventopStep = EventopStep;
463
491
  exports.EventopTarget = EventopTarget;
464
- exports.default = index;
465
492
  exports.useEventopAI = useEventopAI;
466
493
  exports.useEventopTour = useEventopTour;