@codebards/ik-embeddable-form 0.0.2788575612-qa → 0.0.2792144458-qa

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/embed.js CHANGED
@@ -1713,10 +1713,12 @@ var IKEmbeddableFormBundle = function(exports) {
1713
1713
  privacyPolicyUrl: getPrivacyPolicyUrl()
1714
1714
  };
1715
1715
  }
1716
- function shouldShowLeftPanel(config, openConfig) {
1716
+ function shouldShowLeftPanel(config, openConfig, progressSteps, currentStepId) {
1717
1717
  var _a;
1718
1718
  if (openConfig == null ? void 0 : openConfig.hideLeftPanel) return false;
1719
1719
  if ((_a = resolveLayoutConfig(config)) == null ? void 0 : _a.hideLeftPanel) return false;
1720
+ const currentStep = progressSteps == null ? void 0 : progressSteps.find((s2) => s2.id === currentStepId);
1721
+ if (currentStep == null ? void 0 : currentStep.hideLeftPanel) return false;
1720
1722
  return !!getLeftPanel(config);
1721
1723
  }
1722
1724
  function getDisplayMode(openConfig) {
@@ -16902,7 +16904,7 @@ var IKEmbeddableFormBundle = function(exports) {
16902
16904
  }) {
16903
16905
  const leftPanel = getLeftPanel(config);
16904
16906
  const rightPanel = getRightPanel(config);
16905
- const showLeftPanel = shouldShowLeftPanel(config, openConfig);
16907
+ const showLeftPanel = shouldShowLeftPanel(config, openConfig, progressSteps, currentStepId);
16906
16908
  const showProgress = shouldShowStepper(config, openConfig, progressSteps, currentStepId);
16907
16909
  const formIntro = getFormIntro(config, openConfig);
16908
16910
  const showFormIntro = shouldShowFormIntro(config, openConfig, progressSteps, currentStepId);
@@ -22253,6 +22255,7 @@ var IKEmbeddableFormBundle = function(exports) {
22253
22255
  id: "success",
22254
22256
  type: "success",
22255
22257
  hidden: true,
22258
+ hideLeftPanel: true,
22256
22259
  title: "Registration completed!",
22257
22260
  analyticsEvents: [
22258
22261
  {
@@ -22461,7 +22464,8 @@ ${intlTelStyles}`;
22461
22464
  uuidPlacement: "path",
22462
22465
  resultParams: { tab: "resume-insights" },
22463
22466
  gateBehindGqlForm: true,
22464
- gqlGateConfig: GQL_GATE_CONFIG
22467
+ gqlGateConfig: GQL_GATE_CONFIG,
22468
+ pollResultBeforeRedirect: true
22465
22469
  },
22466
22470
  {
22467
22471
  id: "salary-analyser",
@@ -22655,6 +22659,8 @@ ${leadMagnetStyles}`;
22655
22659
  function delay(ms) {
22656
22660
  return new Promise((resolve) => setTimeout(resolve, ms));
22657
22661
  }
22662
+ class AnalysisFailedError extends Error {
22663
+ }
22658
22664
  async function pollUntilComplete(tool, uuid, api) {
22659
22665
  const deadline = Date.now() + POLL_MAX_MS;
22660
22666
  while (Date.now() < deadline) {
@@ -22670,7 +22676,7 @@ ${leadMagnetStyles}`;
22670
22676
  if (!res.ok) continue;
22671
22677
  const body = await res.json();
22672
22678
  if (body.state === "FAILED" || body.state === "ERROR") {
22673
- throw new Error("The analyser could not read that resume. Please try another file.");
22679
+ throw new AnalysisFailedError("The analyser could not read that resume. Please try another file.");
22674
22680
  }
22675
22681
  if (body.state === "COMPLETED") {
22676
22682
  return body.data ?? {};
@@ -22766,7 +22772,9 @@ ${leadMagnetStyles}`;
22766
22772
  }
22767
22773
  }
22768
22774
  function renderPendingTab(tab, tool, options = {}) {
22769
- const waitingCopy = options.gated ? `Finish signing up in the tab you came from and your results will appear here.` : `This usually takes under a minute. Please keep this tab open — your results will
22775
+ const heading = options.gated ? "Finishing up" : "Analysing your resume";
22776
+ const waitingCopy = options.gated ? `We're wrapping up your registration in the tab you came from — your results will
22777
+ appear here automatically the moment it's done.` : `This usually takes under a minute. Please keep this tab open — your results will
22770
22778
  appear here automatically.`;
22771
22779
  try {
22772
22780
  tab.document.write(`<!doctype html>
@@ -22774,7 +22782,7 @@ ${leadMagnetStyles}`;
22774
22782
  <head>
22775
22783
  <meta charset="utf-8">
22776
22784
  <meta name="viewport" content="width=device-width, initial-scale=1">
22777
- <title>Analysing your resume — ${escapeHtml(tool.copy.title)}</title>
22785
+ <title>${escapeHtml(heading)} — ${escapeHtml(tool.copy.title)}</title>
22778
22786
  <style>
22779
22787
  :root { color-scheme: light dark; }
22780
22788
  * { box-sizing: border-box; }
@@ -22799,7 +22807,7 @@ ${leadMagnetStyles}`;
22799
22807
  <body>
22800
22808
  <div class="wrap" role="status" aria-live="polite">
22801
22809
  <div class="spinner"></div>
22802
- <h1>Analysing your resume</h1>
22810
+ <h1>${escapeHtml(heading)}</h1>
22803
22811
  <p>${waitingCopy}</p>
22804
22812
  </div>
22805
22813
  </body>
@@ -22808,6 +22816,17 @@ ${leadMagnetStyles}`;
22808
22816
  } catch {
22809
22817
  }
22810
22818
  }
22819
+ function updatePendingTabMessage(tab, heading, body) {
22820
+ try {
22821
+ const h1 = tab.document.querySelector(".wrap h1");
22822
+ const p2 = tab.document.querySelector(".wrap p");
22823
+ if (h1) h1.textContent = heading;
22824
+ if (p2) p2.textContent = body;
22825
+ const [, toolName] = tab.document.title.split(" — ");
22826
+ if (toolName) tab.document.title = `${heading} — ${toolName}`;
22827
+ } catch {
22828
+ }
22829
+ }
22811
22830
  function renderFailedTab(tab, message) {
22812
22831
  try {
22813
22832
  const target = tab.document.querySelector(".wrap");
@@ -22822,24 +22841,31 @@ ${leadMagnetStyles}`;
22822
22841
  (c2) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c2]
22823
22842
  );
22824
22843
  }
22844
+ const GATE_SUBMIT_BUTTON_TESTID = "goals-details__submit-btn";
22825
22845
  function openGqlGate(options) {
22826
22846
  const { tool, identity, dataClickId, onRegistered, onDismissed } = options;
22827
22847
  const IKForm = typeof window !== "undefined" ? window.IKForm : void 0;
22828
22848
  if (!IKForm) {
22829
- onRegistered();
22849
+ onRegistered(null);
22830
22850
  return;
22831
22851
  }
22852
+ const releaseClaim = claimResultTab(tool);
22832
22853
  let settled = false;
22833
22854
  const handOffOnce = () => {
22834
22855
  if (settled) return;
22835
22856
  settled = true;
22836
22857
  IKForm.close();
22837
- onRegistered();
22858
+ onRegistered(releaseClaim());
22838
22859
  };
22839
22860
  const dismissOnce = () => {
22840
22861
  if (settled) return;
22841
- settled = true;
22842
- onDismissed == null ? void 0 : onDismissed();
22862
+ setTimeout(() => {
22863
+ var _a;
22864
+ if (settled) return;
22865
+ settled = true;
22866
+ (_a = releaseClaim()) == null ? void 0 : _a.close();
22867
+ onDismissed == null ? void 0 : onDismissed();
22868
+ }, 3e3);
22843
22869
  };
22844
22870
  IKForm.open({
22845
22871
  ...tool.gqlGateConfig,
@@ -22856,6 +22882,27 @@ ${leadMagnetStyles}`;
22856
22882
  onClose: dismissOnce
22857
22883
  });
22858
22884
  }
22885
+ function claimResultTab(tool) {
22886
+ let resultTab = null;
22887
+ let claimed = false;
22888
+ const onClick = (event) => {
22889
+ if (claimed) return;
22890
+ const onSubmitButton = event.composedPath().some((el) => el instanceof HTMLElement && el.dataset.testid === GATE_SUBMIT_BUTTON_TESTID);
22891
+ if (!onSubmitButton) return;
22892
+ claimed = true;
22893
+ resultTab = window.open("", "_blank");
22894
+ if (resultTab) {
22895
+ renderPendingTab(resultTab, tool, { gated: true });
22896
+ window.focus();
22897
+ }
22898
+ document.removeEventListener("click", onClick, true);
22899
+ };
22900
+ document.addEventListener("click", onClick, true);
22901
+ return () => {
22902
+ document.removeEventListener("click", onClick, true);
22903
+ return resultTab;
22904
+ };
22905
+ }
22859
22906
  function goToResult(url) {
22860
22907
  const tab = window.open(url, "_blank");
22861
22908
  if (!tab) window.location.href = url;
@@ -22907,6 +22954,28 @@ ${leadMagnetStyles}`;
22907
22954
  }
22908
22955
  return null;
22909
22956
  }
22957
+ async function deliverResult(tab, tool, uuid, resultUrl) {
22958
+ if (!tab || tab.closed) {
22959
+ goToResult(resultUrl);
22960
+ return;
22961
+ }
22962
+ if (tool.pollResultBeforeRedirect) {
22963
+ updatePendingTabMessage(
22964
+ tab,
22965
+ "Wrapping up your analysis",
22966
+ "Almost there — putting together your resume insights. This can take up to a minute."
22967
+ );
22968
+ try {
22969
+ await pollUntilComplete(tool, uuid, "RESUME_ANALYSIS");
22970
+ } catch (err) {
22971
+ if (err instanceof AnalysisFailedError) {
22972
+ if (!tab.closed) renderFailedTab(tab, err.message);
22973
+ return;
22974
+ }
22975
+ }
22976
+ }
22977
+ if (!tab.closed) tab.location.href = resultUrl;
22978
+ }
22910
22979
  function useUploadController(tool, surface) {
22911
22980
  const [state2, setState] = d(() => getToolState(tool.id));
22912
22981
  const [localFile, setLocalFile] = d(null);
@@ -22933,11 +23002,8 @@ ${leadMagnetStyles}`;
22933
23002
  );
22934
23003
  const submit = q$1(async () => {
22935
23004
  if (!localFile) return;
22936
- const resultTab = window.open("", "_blank");
22937
- if (resultTab) {
22938
- renderPendingTab(resultTab, tool, { gated: tool.gateBehindGqlForm });
22939
- if (tool.gateBehindGqlForm) window.focus();
22940
- }
23005
+ const resultTab = tool.gateBehindGqlForm ? null : window.open("", "_blank");
23006
+ if (resultTab) renderPendingTab(resultTab, tool);
22941
23007
  setToolState(tool.id, { status: "uploading" });
22942
23008
  try {
22943
23009
  const base64 = await fileToBase64(localFile);
@@ -22948,22 +23014,22 @@ ${leadMagnetStyles}`;
22948
23014
  const resultUrl = buildResultUrl(tool, uuid);
22949
23015
  setToolState(tool.id, { status: "done" });
22950
23016
  reportLeadMagnetClick(buildLifecycleClickId(surface, tool.id, "upload-success"));
22951
- const handOff = () => {
22952
- if (resultTab && !resultTab.closed) resultTab.location.href = resultUrl;
22953
- else goToResult(resultUrl);
22954
- };
22955
23017
  if (tool.gateBehindGqlForm) {
22956
23018
  openGqlGate({
22957
23019
  tool,
22958
23020
  identity: data,
22959
23021
  dataClickId: resolveClickId(surface, tool.id),
22960
- onRegistered: handOff,
22961
- // Abandoned the form don't leave a tab spinning on a result they will never
22962
- // be sent to.
22963
- onDismissed: () => resultTab == null ? void 0 : resultTab.close()
23022
+ // `gateTab` is whatever openGqlGate managed to claim on the submit click — null
23023
+ // if the browser refused it, in which case deliverResult's own goToResult
23024
+ // fallback tries once more and, failing that, falls back to navigating this tab.
23025
+ onRegistered: (gateTab) => {
23026
+ void deliverResult(gateTab, tool, uuid, resultUrl);
23027
+ }
22964
23028
  });
23029
+ } else if (resultTab) {
23030
+ resultTab.location.href = resultUrl;
22965
23031
  } else {
22966
- handOff();
23032
+ void deliverResult(resultTab, tool, uuid, resultUrl);
22967
23033
  }
22968
23034
  } catch (err) {
22969
23035
  const message = err instanceof Error ? err.message : "Upload failed. Please try again.";