@magicfeedback/popup-sdk 1.0.4 → 1.0.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.
package/dist/index.mjs CHANGED
@@ -1721,7 +1721,7 @@ function ensureMagicFeedbackStyles(popup) {
1721
1721
  }
1722
1722
  const link = document.createElement("link");
1723
1723
  link.rel = "stylesheet";
1724
- link.href = "https://cdn.jsdelivr.net/npm/@magicfeedback/native/dist/styles/index.css";
1724
+ link.href = "https://cdn.jsdelivr.net/npm/@magicfeedback/popup-sdk/dist/assets/style.css";
1725
1725
  link.setAttribute(DATA_ATTR, "true");
1726
1726
  popup.appendChild(link);
1727
1727
  }
@@ -1746,7 +1746,7 @@ function ensureResponsiveStyles(popup) {
1746
1746
  .deepdots-popup {
1747
1747
  width: 100% !important;
1748
1748
  max-width: 100% !important;
1749
- height: 100vh !important;
1749
+ height: 90vh !important;
1750
1750
  max-height: 100vh !important;
1751
1751
  border-radius: 0 !important;
1752
1752
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)) 16px !important;
@@ -1754,12 +1754,15 @@ function ensureResponsiveStyles(popup) {
1754
1754
  }
1755
1755
  .deepdots-popup .mf-spinner-circle { width: 32px; height: 32px; border-width: 4px; }
1756
1756
  .deepdots-popup button { font-size: 16px !important; }
1757
- .deepdots-popup-footer { flex-direction: column !important; gap: 12px !important; }
1757
+ .deepdots-popup-header button { width:48px; height:48px; }
1758
+ .deepdots-popup-header button svg { width:26px; height:26px; }
1759
+ .deepdots-popup-footer { flex-direction: column-reverse !important; gap: 12px !important; }
1758
1760
  .deepdots-popup-footer button { width: 100%; }
1759
1761
  }
1760
1762
  @media (max-width: 400px) {
1761
1763
  .deepdots-popup { padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom)) 12px !important; }
1762
- .deepdots-popup button { padding: 10px 14px !important; }
1764
+ .deepdots-popup-header button { width:48px; height:48px; }
1765
+ .deepdots-popup-header button svg { width:26px; height:26px; }
1763
1766
  }
1764
1767
  @media (orientation: landscape) and (max-height: 480px) {
1765
1768
  .deepdots-popup {
@@ -1773,6 +1776,7 @@ function ensureResponsiveStyles(popup) {
1773
1776
  }
1774
1777
  async function renderPopup(container, surveyId, productId, actions, emit, onClose) {
1775
1778
  let surveyCompletedEmitted = false;
1779
+ let stylesInjected = false;
1776
1780
  const popup = document.createElement("div");
1777
1781
  popup.className = "deepdots-popup";
1778
1782
  popup.style.cssText = `
@@ -1787,33 +1791,41 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
1787
1791
  max-width: 600px;
1788
1792
  width: 90%;
1789
1793
  min-height: 200px;
1790
- max-height: 80vh; /* l\xEDmite general del popup */
1791
- overflow: hidden; /* quita scroll del contenedor principal */
1792
1794
  `;
1793
1795
  const header = document.createElement("div");
1794
1796
  header.className = "deepdots-popup-header";
1795
- header.style.cssText = "display:flex; justify-content:flex-end; align-items:center; width:100%; margin-bottom:8px;";
1797
+ header.style.cssText = "display:flex; justify-content:flex-end; align-items:center; width:100%;";
1796
1798
  const closeBtn = document.createElement("button");
1797
1799
  closeBtn.type = "button";
1798
1800
  closeBtn.setAttribute("aria-label", "Close popup");
1799
- closeBtn.innerHTML = "×";
1801
+ closeBtn.innerHTML = `
1802
+ <svg width="28" height="28" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
1803
+ <path d="M6 6L18 18M6 18L18 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
1804
+ </svg>
1805
+ `;
1800
1806
  closeBtn.style.cssText = `
1801
1807
  background:transparent;
1802
1808
  border:none;
1803
- font-size:22px;
1804
- line-height:1;
1809
+ width:32px;
1810
+ height:32px;
1811
+ display:flex;
1812
+ align-items:center;
1813
+ justify-content:center;
1814
+ border-radius: 8px;
1805
1815
  cursor:pointer;
1806
- color:#555;
1816
+ color:#111;
1807
1817
  padding:4px;
1808
- transition: color .15s ease, transform .15s ease;
1809
- box-shadow: none;
1818
+ transition: color .15s ease, transform .15s ease, background .15s ease;
1819
+ box-shadow: none !important;
1810
1820
  `;
1811
1821
  closeBtn.onmouseenter = () => {
1812
- closeBtn.style.color = "#111";
1813
- closeBtn.style.transform = "scale(1.1)";
1822
+ closeBtn.style.color = "#000000";
1823
+ closeBtn.style.background = "rgba(0,0,0,0.06)";
1824
+ closeBtn.style.transform = "scale(1.06)";
1814
1825
  };
1815
1826
  closeBtn.onmouseleave = () => {
1816
- closeBtn.style.color = "#555";
1827
+ closeBtn.style.color = "#111";
1828
+ closeBtn.style.background = "transparent";
1817
1829
  closeBtn.style.transform = "scale(1)";
1818
1830
  };
1819
1831
  closeBtn.onclick = () => {
@@ -1824,11 +1836,20 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
1824
1836
  ensureMagicFeedbackStyles(popup);
1825
1837
  ensureSpinnerStyles(popup);
1826
1838
  ensureResponsiveStyles(popup);
1839
+ const containerContent = document.createElement("div");
1840
+ containerContent.className = "deepdots-popup-container-conetent";
1841
+ containerContent.style.cssText = `
1842
+ display:flex;
1843
+ flex-direction:column;
1844
+ padding: 0 20px 12px 20px;
1845
+ max-height: 80vh; /* l\xEDmite general del popup */
1846
+ overflow: hidden; /* quita scroll del contenedor principal */
1847
+ `;
1827
1848
  const main = document.createElement("div");
1828
1849
  main.className = "deepdots-popup-main";
1829
- main.style.cssText = "display:flex; flex-direction:column; width:100%; flex-grow:1; overflow-y:auto;";
1850
+ main.style.cssText = "display:flex; flex-direction:column; width:100%; max-height:80vh; overflow-y:auto;";
1830
1851
  const formWrapper = document.createElement("div");
1831
- formWrapper.style.cssText = "position:relative; min-height:150px; width:100%;";
1852
+ formWrapper.style.cssText = "width:100%; flex: 1 1 auto;";
1832
1853
  const spinnerEl = document.createElement("div");
1833
1854
  spinnerEl.className = "mf-spinner";
1834
1855
  spinnerEl.setAttribute("role", "status");
@@ -1845,25 +1866,84 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
1845
1866
  const footer = document.createElement("div");
1846
1867
  footer.className = "deepdots-popup-footer";
1847
1868
  footer.setAttribute("data-actions-wrapper", "true");
1848
- footer.style.cssText = "display:flex; justify-content:space-between; align-items:center; gap:8px; margin-top:24px; width:100%;";
1849
- const cancelButton = document.createElement("button");
1850
- cancelButton.textContent = actions?.decline ? actions?.decline.label : "Cancel";
1851
- cancelButton.style.cssText = `
1869
+ footer.style.cssText = "display:flex; flex-direction: row-reverse ;justify-content:space-between; align-items:center; gap:8px; margin-top:auto; width:100%; padding-top:16px;";
1870
+ const backButton = document.createElement("button");
1871
+ backButton.textContent = "Back";
1872
+ backButton.style.cssText = `
1852
1873
  background: transparent;
1853
1874
  color: #333;
1854
- border: 1px solid #ddd;
1855
- padding: 10px 16px;
1875
+ border: 1px solid #999;
1876
+ padding: 12px 24px;
1877
+ border-radius: 4px;
1878
+ cursor: pointer;
1879
+ font-size: 14px;
1880
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
1881
+ transition: filter .15s ease;
1882
+ display: inline-flex;
1883
+ align-items: center;
1884
+ justify-content: center;
1885
+ text-align: center;
1886
+ `;
1887
+ backButton.onmouseenter = () => {
1888
+ backButton.style.filter = "brightness(0.9)";
1889
+ };
1890
+ backButton.onmouseleave = () => {
1891
+ backButton.style.filter = "brightness(1)";
1892
+ };
1893
+ backButton.onclick = () => {
1894
+ emit("popup_clicked", surveyId, { action: "back" });
1895
+ formInstance?.back?.();
1896
+ };
1897
+ const startButton = document.createElement("button");
1898
+ startButton.textContent = actions?.start ? actions.start.label : "Start survey";
1899
+ startButton.style.cssText = `
1900
+ background: #1E293B;
1901
+ color: #fff;
1902
+ border: none;
1903
+ padding: 12px 24px;
1856
1904
  border-radius: 4px;
1857
1905
  cursor: pointer;
1858
1906
  font-size: 14px;
1859
- transition: background .15s ease;
1907
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
1908
+ transition: filter .15s ease;
1909
+ display: inline-flex;
1910
+ align-items: center;
1911
+ justify-content: center;
1912
+ text-align: center;
1860
1913
  `;
1861
- cancelButton.onclick = () => {
1862
- emit("popup_clicked", surveyId, { action: "cancel" });
1914
+ startButton.onclick = () => {
1915
+ emit("popup_clicked", surveyId, { action: "start_survey" });
1916
+ formInstance?.startForm?.();
1917
+ };
1918
+ const closeButton = document.createElement("button");
1919
+ closeButton.textContent = actions?.complete ? actions.complete.label : "Complete survey";
1920
+ closeButton.style.cssText = `
1921
+ background: #1E293B;
1922
+ color: #fff;
1923
+ border: none;
1924
+ padding: 12px 24px;
1925
+ border-radius: 4px;
1926
+ cursor: pointer;
1927
+ font-size: 14px;
1928
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
1929
+ transition: filter .15s ease;
1930
+ display: inline-flex;
1931
+ align-items: center;
1932
+ justify-content: center;
1933
+ text-align: center;
1934
+ `;
1935
+ closeButton.onmouseenter = () => {
1936
+ closeButton.style.filter = "brightness(0.9)";
1937
+ };
1938
+ closeButton.onmouseleave = () => {
1939
+ closeButton.style.filter = "brightness(1)";
1940
+ };
1941
+ closeButton.onclick = () => {
1942
+ emit("popup_clicked", surveyId, { action: "complete" });
1863
1943
  onClose();
1864
1944
  };
1865
1945
  const submitButton = document.createElement("button");
1866
- submitButton.textContent = actions?.accept ? actions.accept.label : "Complete Survey";
1946
+ submitButton.textContent = actions?.accept ? actions.accept.label : "Send";
1867
1947
  submitButton.style.cssText = `
1868
1948
  background: #1E293B;
1869
1949
  color: #fff;
@@ -1874,6 +1954,10 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
1874
1954
  font-size: 14px;
1875
1955
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
1876
1956
  transition: filter .15s ease;
1957
+ display: inline-flex;
1958
+ align-items: center;
1959
+ justify-content: center;
1960
+ text-align: center;
1877
1961
  `;
1878
1962
  submitButton.onclick = () => {
1879
1963
  if (!surveyCompletedEmitted) {
@@ -1881,11 +1965,55 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
1881
1965
  formInstance?.send?.();
1882
1966
  }
1883
1967
  };
1884
- footer.appendChild(cancelButton);
1968
+ backButton.style.display = "none";
1969
+ startButton.style.display = "none";
1970
+ submitButton.style.display = "none";
1971
+ closeButton.style.display = "none";
1972
+ footer.appendChild(backButton);
1973
+ footer.appendChild(closeButton);
1885
1974
  footer.appendChild(submitButton);
1975
+ footer.appendChild(startButton);
1976
+ main.appendChild(footer);
1977
+ containerContent.appendChild(main);
1978
+ function updateButtons(state) {
1979
+ backButton.style.display = "none";
1980
+ startButton.style.display = "none";
1981
+ submitButton.style.display = "none";
1982
+ closeButton.style.display = "none";
1983
+ backButton.style.width = "";
1984
+ startButton.style.width = "";
1985
+ submitButton.style.width = "";
1986
+ closeButton.style.width = "";
1987
+ switch (state) {
1988
+ case "loading":
1989
+ break;
1990
+ case "start":
1991
+ startButton.style.display = "inline-flex";
1992
+ startButton.style.width = "100%";
1993
+ break;
1994
+ case "in_progress_first":
1995
+ submitButton.style.display = "inline-flex";
1996
+ submitButton.style.width = "";
1997
+ setLoading(false);
1998
+ break;
1999
+ case "in_progress_next":
2000
+ backButton.style.display = "inline-flex";
2001
+ submitButton.style.display = "inline-flex";
2002
+ setLoading(false);
2003
+ break;
2004
+ case "completed":
2005
+ closeButton.style.display = "inline-flex";
2006
+ closeButton.style.width = "100%";
2007
+ setLoading(false);
2008
+ break;
2009
+ case "error":
2010
+ closeButton.style.display = "inline-flex";
2011
+ setLoading(false);
2012
+ break;
2013
+ }
2014
+ }
1886
2015
  popup.appendChild(header);
1887
- popup.appendChild(main);
1888
- popup.appendChild(footer);
2016
+ popup.appendChild(containerContent);
1889
2017
  container.innerHTML = "";
1890
2018
  container.appendChild(popup);
1891
2019
  container.style.display = "flex";
@@ -1894,10 +2022,16 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
1894
2022
  if (!isLoading) {
1895
2023
  formHost.style.visibility = "visible";
1896
2024
  }
1897
- cancelButton.disabled = false;
2025
+ footer.style.display = isLoading ? "none" : "flex";
2026
+ backButton.disabled = isLoading;
2027
+ startButton.disabled = isLoading;
2028
+ closeButton.disabled = isLoading;
1898
2029
  submitButton.disabled = isLoading;
1899
2030
  submitButton.style.opacity = isLoading ? "0.6" : "1";
1900
2031
  submitButton.style.cursor = isLoading ? "not-allowed" : "pointer";
2032
+ if (isLoading) {
2033
+ updateButtons("loading");
2034
+ }
1901
2035
  }
1902
2036
  setLoading(true);
1903
2037
  if (typeof window === "undefined" || typeof document === "undefined") {
@@ -1916,12 +2050,13 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
1916
2050
  addButton: false,
1917
2051
  getMetaData: true
1918
2052
  };
1919
- generateOptions.onLoadedEvent = ({ formData }) => {
2053
+ generateOptions.onLoadedEvent = ({ formData, progress }) => {
1920
2054
  try {
1921
2055
  } catch (e) {
1922
2056
  }
1923
2057
  const s = formData?.style;
1924
- if (s) {
2058
+ if (s && !stylesInjected) {
2059
+ stylesInjected = true;
1925
2060
  if (s.boxBackgroundColor) {
1926
2061
  popup.style.background = s.boxBackgroundColor;
1927
2062
  }
@@ -1932,50 +2067,66 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
1932
2067
  submitButton.style.background = s.buttonPrimaryColor;
1933
2068
  submitButton.style.border = "none";
1934
2069
  submitButton.style.color = "#fff";
2070
+ startButton.style.background = s.buttonPrimaryColor;
2071
+ startButton.style.border = "none";
2072
+ startButton.style.color = "#fff";
2073
+ closeButton.style.background = s.buttonPrimaryColor;
2074
+ closeButton.style.border = "none";
2075
+ closeButton.style.color = "#fff";
1935
2076
  }
1936
2077
  if (s.buttonSecondaryColor) {
1937
- cancelButton.style.background = "transparent";
1938
- cancelButton.style.border = `1px solid ${s.buttonSecondaryColor}`;
1939
- cancelButton.style.color = "#333";
2078
+ backButton.style.color = "#fff";
2079
+ backButton.style.border = `1px solid ${s.buttonSecondaryColor}`;
1940
2080
  }
1941
2081
  if (s.logo) {
1942
- const logoImg = document.createElement("img");
1943
- logoImg.src = s.logo;
1944
- logoImg.alt = "Logo";
1945
- logoImg.style.cssText = "max-height:40px; max-width:100%; object-fit:contain;";
1946
- if (s.logoSize) {
1947
- switch (s.logoSize) {
1948
- case "small":
1949
- logoImg.style.maxHeight = "30px";
1950
- break;
1951
- case "medium":
1952
- logoImg.style.maxHeight = "50px";
1953
- break;
1954
- case "large":
1955
- logoImg.style.maxHeight = "70px";
1956
- break;
2082
+ if (!document.getElementById("deepdots-popup-logo")) {
2083
+ const logoImg = document.createElement("img");
2084
+ logoImg.id = "deepdots-popup-logo";
2085
+ logoImg.src = s.logo;
2086
+ logoImg.alt = "Logo";
2087
+ logoImg.style.cssText = "max-height:40px; max-width:100%; object-fit:contain;";
2088
+ if (s.logoSize) {
2089
+ switch (s.logoSize) {
2090
+ case "small":
2091
+ logoImg.style.maxHeight = "30px";
2092
+ break;
2093
+ case "medium":
2094
+ logoImg.style.maxHeight = "50px";
2095
+ break;
2096
+ case "large":
2097
+ logoImg.style.maxHeight = "70px";
2098
+ break;
2099
+ }
1957
2100
  }
1958
- }
1959
- if (s.logoPosition) {
1960
- switch (s.logoPosition) {
1961
- case "left":
1962
- logoImg.style.margin = "0 16px 16px 0";
1963
- logoImg.style.display = "block";
1964
- logoImg.style.marginLeft = "0";
1965
- break;
1966
- case "right":
1967
- logoImg.style.margin = "0 0 16px 16px";
1968
- logoImg.style.display = "block";
1969
- logoImg.style.marginLeft = "auto";
1970
- break;
1971
- case "center":
1972
- logoImg.style.margin = "0 auto 16px auto";
1973
- logoImg.style.display = "block";
1974
- break;
2101
+ if (s.logoPosition) {
2102
+ switch (s.logoPosition) {
2103
+ case "left":
2104
+ logoImg.style.margin = "0 16px 42px 0";
2105
+ logoImg.style.display = "block";
2106
+ logoImg.style.marginLeft = "0";
2107
+ break;
2108
+ case "right":
2109
+ logoImg.style.margin = "0 0 42px 16px";
2110
+ logoImg.style.display = "block";
2111
+ logoImg.style.marginLeft = "auto";
2112
+ break;
2113
+ case "center":
2114
+ logoImg.style.margin = "0 auto 42px auto";
2115
+ logoImg.style.display = "block";
2116
+ break;
2117
+ }
1975
2118
  }
2119
+ containerContent.insertBefore(logoImg, main);
1976
2120
  }
1977
- popup.insertBefore(logoImg, main);
1978
2121
  }
2122
+ if (s.startMessage && s.startMessage !== "") {
2123
+ console.log(s.startMessage);
2124
+ updateButtons("start");
2125
+ } else {
2126
+ updateButtons("in_progress_first");
2127
+ }
2128
+ } else {
2129
+ updateButtons("in_progress_first");
1979
2130
  }
1980
2131
  emit("popup_clicked", surveyId, { action: "loaded" });
1981
2132
  setLoading(false);
@@ -1985,32 +2136,29 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
1985
2136
  emit("popup_clicked", surveyId, { action: "before_submit" });
1986
2137
  };
1987
2138
  generateOptions.afterSubmitEvent = ({ error, completed, total, progress }) => {
1988
- setLoading(false);
1989
2139
  if (error) {
1990
2140
  emit("popup_clicked", surveyId, { action: "submit_error", error });
2141
+ updateButtons("error");
1991
2142
  return;
1992
2143
  }
1993
2144
  if (completed) {
1994
2145
  emit("survey_completed", surveyId, { action: "completed" });
1995
2146
  surveyCompletedEmitted = true;
1996
- onClose();
2147
+ updateButtons("completed");
2148
+ return;
1997
2149
  }
1998
- if (total > 1 && progress < total) {
1999
- cancelButton.textContent = "Back";
2000
- cancelButton.onclick = () => {
2001
- emit("popup_clicked", surveyId, { action: "back" });
2002
- formInstance.back();
2003
- };
2150
+ if (total > 1 && progress > 0 && progress < total) {
2151
+ updateButtons("in_progress_next");
2152
+ } else {
2153
+ updateButtons("in_progress_first");
2004
2154
  }
2005
2155
  };
2006
2156
  generateOptions.onBackEvent = ({ progress }) => {
2007
2157
  emit("popup_clicked", surveyId, { action: "back" });
2008
2158
  if (progress === 0) {
2009
- cancelButton.textContent = actions?.decline ? actions?.decline.label : "Cancel";
2010
- cancelButton.onclick = () => {
2011
- emit("popup_clicked", surveyId, { action: "cancel" });
2012
- onClose();
2013
- };
2159
+ updateButtons("in_progress_first");
2160
+ } else {
2161
+ updateButtons("in_progress_next");
2014
2162
  }
2015
2163
  };
2016
2164
  formInstance.generate(formDivId, generateOptions).catch((err) => {