rivia 0.0.10 → 0.0.11

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 (2) hide show
  1. package/dist/index.js +81 -62
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1267,7 +1267,7 @@ var RIVIA_TOUR = function() {
1267
1267
  window.sessionStorage.removeItem("rivia_tour_state");
1268
1268
  }
1269
1269
  }
1270
- function createTooltip({
1270
+ async function createTooltip({
1271
1271
  id,
1272
1272
  selector,
1273
1273
  title,
@@ -1282,7 +1282,7 @@ var RIVIA_TOUR = function() {
1282
1282
  card_next_button = true,
1283
1283
  card_skip_button = false
1284
1284
  }) {
1285
- const anchor = findBySelector(selector);
1285
+ const anchor = await findBySelector(selector);
1286
1286
  if (!anchor) return null;
1287
1287
  const tip = document.createElement("div");
1288
1288
  tip.dataset.riviaTipId = id;
@@ -1542,7 +1542,7 @@ var RIVIA_TOUR = function() {
1542
1542
  return STATE.tips;
1543
1543
  }
1544
1544
  }
1545
- function showStep(i, isPreview = false) {
1545
+ async function showStep(i, isPreview = false) {
1546
1546
  uploadVisitedPagesInBackground(STATE.tour_id, user_var12, i);
1547
1547
  console.log("Showing step", i, "of", STATE.tips.length);
1548
1548
  document.querySelectorAll("[data-rivia-tip-id]").forEach((n) => n.remove());
@@ -1578,7 +1578,7 @@ var RIVIA_TOUR = function() {
1578
1578
  if (step.card_type === "video_explainer") {
1579
1579
  if (isPreview) {
1580
1580
  console.log("Preview mode: Showing video explainer for step:", step.id);
1581
- const targetElement = findBySelector(step.selector);
1581
+ const targetElement = await findBySelector(step.selector);
1582
1582
  if (targetElement) {
1583
1583
  try {
1584
1584
  targetElement.scrollIntoView({ behavior: "smooth", block: "center", inline: "nearest" });
@@ -1606,7 +1606,7 @@ var RIVIA_TOUR = function() {
1606
1606
  console.log("Edit mode: Showing video explainer for step:", step.id);
1607
1607
  console.log("Step selector:", step.selector);
1608
1608
  if (step.selector) {
1609
- const targetElement = findBySelector(step.selector);
1609
+ const targetElement = await findBySelector(step.selector);
1610
1610
  console.log("Found target element:", targetElement, "for selector:", step.selector);
1611
1611
  if (targetElement) {
1612
1612
  console.log("Element found, scrolling into view...");
@@ -1653,7 +1653,7 @@ var RIVIA_TOUR = function() {
1653
1653
  return;
1654
1654
  }
1655
1655
  if (isPreview) {
1656
- const el = findBySelector(step.selector);
1656
+ const el = await findBySelector(step.selector);
1657
1657
  if (el) {
1658
1658
  try {
1659
1659
  el.scrollIntoView({ behavior: "smooth", block: "center", inline: "nearest" });
@@ -1696,7 +1696,7 @@ var RIVIA_TOUR = function() {
1696
1696
  return;
1697
1697
  }
1698
1698
  if (!isPreview && step.selector && !step.card_type) {
1699
- const el = findBySelector(step.selector);
1699
+ const el = await findBySelector(step.selector);
1700
1700
  if (el) {
1701
1701
  try {
1702
1702
  el.scrollIntoView({ behavior: "smooth", block: "center", inline: "nearest" });
@@ -1752,9 +1752,9 @@ var RIVIA_TOUR = function() {
1752
1752
  }
1753
1753
  }, 100);
1754
1754
  }
1755
- function createVideoUI(step) {
1755
+ async function createVideoUI(step) {
1756
1756
  console.log("Creating video UI for step:", step);
1757
- const anchor = findBySelector(step.selector);
1757
+ const anchor = await findBySelector(step.selector);
1758
1758
  console.log("Found anchor:", anchor);
1759
1759
  if (!anchor) {
1760
1760
  console.warn("Anchor not found for selector:", step.selector);
@@ -1990,7 +1990,7 @@ var RIVIA_TOUR = function() {
1990
1990
  }, 0);
1991
1991
  return videoContainer;
1992
1992
  }
1993
- function previewAnimation(selector, animationType) {
1993
+ async function previewAnimation(selector, animationType) {
1994
1994
  try {
1995
1995
  const element = document.querySelector(selector);
1996
1996
  if (!element) {
@@ -2019,16 +2019,36 @@ var RIVIA_TOUR = function() {
2019
2019
  console.warn("Error previewing animation:", err);
2020
2020
  }
2021
2021
  }
2022
- function findBySelector(selector) {
2023
- try {
2024
- return document.querySelector(selector);
2025
- } catch (e) {
2026
- console.warn("Invalid selector:", selector, e);
2027
- return null;
2028
- }
2022
+ async function findBySelector(selector) {
2023
+ return new Promise((resolve) => {
2024
+ const maxRetries = 50;
2025
+ const retryInterval = 100;
2026
+ let attempts = 0;
2027
+ const checkElement = () => {
2028
+ try {
2029
+ const element = document.querySelector(selector);
2030
+ if (element) {
2031
+ resolve(element);
2032
+ return;
2033
+ }
2034
+ } catch (e) {
2035
+ console.warn("Invalid selector:", selector, e);
2036
+ resolve(null);
2037
+ return;
2038
+ }
2039
+ attempts++;
2040
+ if (attempts < maxRetries) {
2041
+ setTimeout(checkElement, retryInterval);
2042
+ } else {
2043
+ console.warn("Element not found after retries:", selector);
2044
+ resolve(null);
2045
+ }
2046
+ };
2047
+ checkElement();
2048
+ });
2029
2049
  }
2030
- function highlightElementBySelector(selector) {
2031
- const el = findBySelector(selector);
2050
+ async function highlightElementBySelector(selector) {
2051
+ const el = await findBySelector(selector);
2032
2052
  if (!el) return;
2033
2053
  try {
2034
2054
  el.scrollIntoView({
@@ -2051,7 +2071,7 @@ var RIVIA_TOUR = function() {
2051
2071
  height: r.height + "px"
2052
2072
  });
2053
2073
  }
2054
- function previewBackdrop(selector, backdropType) {
2074
+ async function previewBackdrop(selector, backdropType) {
2055
2075
  try {
2056
2076
  let backdropOverlay = document.getElementById("rivia-backdrop-overlay");
2057
2077
  if (backdropOverlay) {
@@ -2060,7 +2080,7 @@ var RIVIA_TOUR = function() {
2060
2080
  if (backdropType === "none") {
2061
2081
  return;
2062
2082
  }
2063
- const targetElement = findBySelector(selector);
2083
+ const targetElement = await findBySelector(selector);
2064
2084
  if (!targetElement) return;
2065
2085
  const targetRect = targetElement.getBoundingClientRect();
2066
2086
  const padding = 8;
@@ -2172,7 +2192,7 @@ var RIVIA_TOUR = function() {
2172
2192
  console.warn("Error previewing backdrop:", err);
2173
2193
  }
2174
2194
  }
2175
- function showWelcomeCardPreview(step, stepIndex) {
2195
+ async function showWelcomeCardPreview(step, stepIndex) {
2176
2196
  if (!step) {
2177
2197
  console.warn("Step not found for preview");
2178
2198
  return;
@@ -2345,7 +2365,7 @@ var RIVIA_TOUR = function() {
2345
2365
  nextBtn.onmouseout = () => {
2346
2366
  nextBtn.style.background = "#2563eb";
2347
2367
  };
2348
- nextBtn.onclick = () => {
2368
+ nextBtn.onclick = async () => {
2349
2369
  const advanceAction = step.basic_advanceAction || "next button";
2350
2370
  overlay2.remove();
2351
2371
  const backdropOverlay = document.getElementById(
@@ -2363,7 +2383,7 @@ var RIVIA_TOUR = function() {
2363
2383
  STATE.tourIndex = Math.min(STATE.tourIndex + 1, STATE.tips.length - 1);
2364
2384
  if (STATE.tourIndex < STATE.tips.length) {
2365
2385
  const nextStep2 = STATE.tips[STATE.tourIndex];
2366
- const nextElement = findBySelector(nextStep2.selector);
2386
+ const nextElement = await findBySelector(nextStep2.selector);
2367
2387
  if (nextElement) {
2368
2388
  nextElement.scrollIntoView({ behavior: "smooth", block: "center" });
2369
2389
  setTimeout(() => showStep(STATE.tourIndex, true), 600);
@@ -2413,7 +2433,7 @@ var RIVIA_TOUR = function() {
2413
2433
  step.basic_advanceAction
2414
2434
  );
2415
2435
  }
2416
- function showModalDialogPreview(step, stepIndex) {
2436
+ async function showModalDialogPreview(step, stepIndex) {
2417
2437
  const existingCenteredModal = document.getElementById(
2418
2438
  "rivia-modal-dialog-preview-modal"
2419
2439
  );
@@ -2546,7 +2566,7 @@ var RIVIA_TOUR = function() {
2546
2566
  `;
2547
2567
  nextBtn.onmouseover = () => nextBtn.style.background = "#1d4ed8";
2548
2568
  nextBtn.onmouseout = () => nextBtn.style.background = "#2563eb";
2549
- nextBtn.onclick = () => {
2569
+ nextBtn.onclick = async () => {
2550
2570
  const advanceAction = step.basic_advanceAction || "next button";
2551
2571
  centeredContainer.remove();
2552
2572
  const backdropOverlay = document.getElementById(
@@ -2564,7 +2584,7 @@ var RIVIA_TOUR = function() {
2564
2584
  STATE.tourIndex = Math.min(STATE.tourIndex + 1, STATE.tips.length - 1);
2565
2585
  if (STATE.tourIndex < STATE.tips.length) {
2566
2586
  const nextStepData = STATE.tips[STATE.tourIndex];
2567
- const nextElement = findBySelector(nextStepData.selector);
2587
+ const nextElement = await findBySelector(nextStepData.selector);
2568
2588
  if (nextElement) {
2569
2589
  nextElement.scrollIntoView({ behavior: "smooth", block: "center" });
2570
2590
  setTimeout(() => showStep(STATE.tourIndex, true), 600);
@@ -2601,7 +2621,7 @@ var RIVIA_TOUR = function() {
2601
2621
  step.basic_advanceAction
2602
2622
  );
2603
2623
  }
2604
- function attachNavigationButtons(tip, i, isPreview) {
2624
+ async function attachNavigationButtons(tip, i, isPreview) {
2605
2625
  const nav = document.createElement("div");
2606
2626
  const navStyle = isPreview ? `
2607
2627
  display: flex;
@@ -2652,7 +2672,7 @@ var RIVIA_TOUR = function() {
2652
2672
  nav.appendChild(back);
2653
2673
  }
2654
2674
  if (advanceAction === "manual click") {
2655
- const targetElement = findBySelector(step.selector);
2675
+ const targetElement = await findBySelector(step.selector);
2656
2676
  if (targetElement) {
2657
2677
  attachClickListenerToElement(targetElement);
2658
2678
  }
@@ -2752,7 +2772,7 @@ var RIVIA_TOUR = function() {
2752
2772
  tip.appendChild(stepIndicator);
2753
2773
  }
2754
2774
  }
2755
- function cleanupAllOverlays() {
2775
+ async function cleanupAllOverlays() {
2756
2776
  const welcomeBackdropOverlay = document.getElementById(
2757
2777
  "rivia-welcome-backdrop-overlay"
2758
2778
  );
@@ -2792,24 +2812,8 @@ var RIVIA_TOUR = function() {
2792
2812
  svg.remove();
2793
2813
  });
2794
2814
  }
2795
- function nextStep() {
2815
+ async function nextStep() {
2796
2816
  if (STATE.tourIndex < STATE.tips.length - 1) {
2797
- let getNextStepInfo3 = function(currentIndex2) {
2798
- if (currentIndex2 >= STATE.tips.length - 1) {
2799
- return { type: "end", index: currentIndex2 };
2800
- }
2801
- const nextStep2 = STATE.tips[currentIndex2 + 1];
2802
- if (!nextStep2) return { type: "end", index: currentIndex2 };
2803
- if (nextStep2.targetUrl && nextStep2.targetUrl.trim()) {
2804
- console.log("WE reached navigation");
2805
- return { type: "navigate", index: currentIndex2 + 1, url: nextStep2.targetUrl };
2806
- }
2807
- if (isStepAvailableOnCurrentPage(nextStep2)) {
2808
- return { type: "show", index: currentIndex2 + 1 };
2809
- }
2810
- return getNextStepInfo3(currentIndex2 + 1);
2811
- };
2812
- var getNextStepInfo2 = getNextStepInfo3;
2813
2817
  const currentIndex = STATE.tourIndex;
2814
2818
  STATE.tourIndex++;
2815
2819
  const nextStepData = STATE.tips[STATE.tourIndex];
@@ -2828,7 +2832,22 @@ var RIVIA_TOUR = function() {
2828
2832
  window.location.href = navUrl;
2829
2833
  return;
2830
2834
  }
2831
- const nextStepInfo = getNextStepInfo3(currentIndex);
2835
+ async function getNextStepInfo2(currentIndex2) {
2836
+ if (currentIndex2 >= STATE.tips.length - 1) {
2837
+ return { type: "end", index: currentIndex2 };
2838
+ }
2839
+ const nextStep2 = STATE.tips[currentIndex2 + 1];
2840
+ if (!nextStep2) return { type: "end", index: currentIndex2 };
2841
+ if (nextStep2.targetUrl && nextStep2.targetUrl.trim()) {
2842
+ console.log("WE reached navigation");
2843
+ return { type: "navigate", index: currentIndex2 + 1, url: nextStep2.targetUrl };
2844
+ }
2845
+ if (isStepAvailableOnCurrentPage(nextStep2)) {
2846
+ return { type: "show", index: currentIndex2 + 1 };
2847
+ }
2848
+ return getNextStepInfo2(currentIndex2 + 1);
2849
+ }
2850
+ const nextStepInfo = getNextStepInfo2(currentIndex);
2832
2851
  if (nextStepInfo.type === "navigate") {
2833
2852
  sessionStorage.setItem("rivia_tour_state", JSON.stringify({
2834
2853
  tourIndex: nextStepInfo.index,
@@ -2850,7 +2869,7 @@ var RIVIA_TOUR = function() {
2850
2869
  endTour();
2851
2870
  }
2852
2871
  }
2853
- function getNextStepInfo(currentIndex) {
2872
+ async function getNextStepInfo(currentIndex) {
2854
2873
  if (currentIndex >= STATE.tips.length - 1) {
2855
2874
  return { type: "end", index: currentIndex };
2856
2875
  }
@@ -2864,12 +2883,12 @@ var RIVIA_TOUR = function() {
2864
2883
  }
2865
2884
  return getNextStepInfo(currentIndex + 1);
2866
2885
  }
2867
- function isStepAvailableOnCurrentPage(step) {
2886
+ async function isStepAvailableOnCurrentPage(step) {
2868
2887
  if (!step) return false;
2869
2888
  if (!step.targetUrl || !step.targetUrl.trim()) return true;
2870
2889
  return urlMatches(step.targetUrl);
2871
2890
  }
2872
- function urlMatches(pattern, currentUrl = window.location.href) {
2891
+ async function urlMatches(pattern, currentUrl = window.location.href) {
2873
2892
  if (!pattern || !pattern.trim()) return true;
2874
2893
  const cleanPattern = pattern.trim();
2875
2894
  const cleanUrl = currentUrl.trim();
@@ -2900,7 +2919,7 @@ var RIVIA_TOUR = function() {
2900
2919
  }
2901
2920
  return cleanUrl.includes(cleanPattern);
2902
2921
  }
2903
- function addTourParamsToUrl(url, tourId) {
2922
+ async function addTourParamsToUrl(url, tourId) {
2904
2923
  if (!url || !tourId) return url;
2905
2924
  try {
2906
2925
  const urlObj = new URL(url);
@@ -2910,7 +2929,7 @@ var RIVIA_TOUR = function() {
2910
2929
  return url;
2911
2930
  }
2912
2931
  }
2913
- function getPreviousStepInfo(currentIndex) {
2932
+ async function getPreviousStepInfo(currentIndex) {
2914
2933
  if (currentIndex <= 0) {
2915
2934
  return { type: "start", index: 0 };
2916
2935
  }
@@ -2924,7 +2943,7 @@ var RIVIA_TOUR = function() {
2924
2943
  }
2925
2944
  return getPreviousStepInfo(currentIndex - 1);
2926
2945
  }
2927
- function prevStep() {
2946
+ async function prevStep() {
2928
2947
  if (STATE.tourIndex > 0) {
2929
2948
  const prevInfo = getPreviousStepInfo(STATE.tourIndex);
2930
2949
  if (prevInfo.type === "start") {
@@ -2953,7 +2972,7 @@ var RIVIA_TOUR = function() {
2953
2972
  }
2954
2973
  }
2955
2974
  }
2956
- function endTour() {
2975
+ async function endTour() {
2957
2976
  console.log("Ending tour and cleaning up UI elements...");
2958
2977
  document.querySelectorAll("[data-rivia-tip-id]").forEach((n) => n.remove());
2959
2978
  STATE.tourIndex = 0;
@@ -2975,7 +2994,7 @@ var RIVIA_TOUR = function() {
2975
2994
  console.warn("Failed to end tour:", err);
2976
2995
  });
2977
2996
  }
2978
- function updateUrlStatus() {
2997
+ async function updateUrlStatus() {
2979
2998
  const urlStatus = document.getElementById("rivia-url-status");
2980
2999
  if (!urlStatus) return;
2981
3000
  const currentStep = STATE.tips[STATE.tourIndex];
@@ -2996,7 +3015,7 @@ var RIVIA_TOUR = function() {
2996
3015
  urlStatus.title = stepUrlInfo.displayText;
2997
3016
  }
2998
3017
  }
2999
- function playTour() {
3018
+ async function playTour() {
3000
3019
  if (STATE.is_completed)
3001
3020
  return;
3002
3021
  if (!STATE.tips.length) {
@@ -3050,7 +3069,7 @@ var RIVIA_TOUR = function() {
3050
3069
  }
3051
3070
  showStep(STATE.tourIndex, true);
3052
3071
  }
3053
- function cleanUrlForStorage(url) {
3072
+ async function cleanUrlForStorage(url) {
3054
3073
  if (!url || !url.trim()) return url;
3055
3074
  try {
3056
3075
  const urlObj = new URL(url);
@@ -3062,7 +3081,7 @@ var RIVIA_TOUR = function() {
3062
3081
  return url;
3063
3082
  }
3064
3083
  }
3065
- function showFeedbackCardPreview(step, stepIndex) {
3084
+ async function showFeedbackCardPreview(step, stepIndex) {
3066
3085
  if (!step) {
3067
3086
  console.warn("Step not found for preview");
3068
3087
  return;
@@ -3283,7 +3302,7 @@ var RIVIA_TOUR = function() {
3283
3302
  nextBtn.onmouseout = () => {
3284
3303
  nextBtn.style.background = "#2563eb";
3285
3304
  };
3286
- nextBtn.onclick = () => {
3305
+ nextBtn.onclick = async () => {
3287
3306
  const advanceAction = step.basic_advanceAction || "next button";
3288
3307
  overlay2.remove();
3289
3308
  const backdropOverlay = document.getElementById(
@@ -3307,7 +3326,7 @@ var RIVIA_TOUR = function() {
3307
3326
  STATE.tourIndex = Math.min(STATE.tourIndex + 1, STATE.tips.length - 1);
3308
3327
  if (STATE.tourIndex < STATE.tips.length) {
3309
3328
  const nextStep2 = STATE.tips[STATE.tourIndex];
3310
- const nextElement = findBySelector(nextStep2.selector);
3329
+ const nextElement = await findBySelector(nextStep2.selector);
3311
3330
  if (nextElement) {
3312
3331
  nextElement.scrollIntoView({ behavior: "smooth", block: "center" });
3313
3332
  setTimeout(() => showStep(STATE.tourIndex, true), 600);
@@ -3359,7 +3378,7 @@ var RIVIA_TOUR = function() {
3359
3378
  }
3360
3379
  return { loadTips, playTour, endTour, STATE };
3361
3380
  }();
3362
- function tours(tourId, userId) {
3381
+ async function tours(tourId, userId) {
3363
3382
  if (!sessionStorage.getItem("rivia_tour_state")) {
3364
3383
  RIVIA_TOUR.loadTips(tourId, userId).then(() => {
3365
3384
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rivia",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",