@sevenfold/setto-client 0.8.4 → 0.8.5

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.
@@ -27,3 +27,18 @@ export declare function currentAdminView(): string | null;
27
27
  */
28
28
  export declare function isAdminPanelView(): boolean;
29
29
  export declare function adminRedirectUrl(): string;
30
+ /**
31
+ * The intent a visitor arrived with, carried across the sign-in.
32
+ *
33
+ * «Neste» on the preview bar means "take me to the checkout", but a visitor
34
+ * who is not signed in cannot start one — the route wants a session and proof
35
+ * the site is theirs. Sending them to /setto loses the intent, and they come
36
+ * back to the same bar and have to press it again.
37
+ *
38
+ * So the wish rides along in the query string and is honoured on the way back.
39
+ */
40
+ export declare const CHECKOUT_INTENT = "neste";
41
+ export declare function checkoutIntentUrl(): string;
42
+ export declare function wantsCheckout(): boolean;
43
+ /** The same address without the marker, so a reload does not start it twice. */
44
+ export declare function withoutCheckoutIntent(): string;
@@ -21358,6 +21358,40 @@ function useSiteAccess(supabase, session, siteId) {
21358
21358
  }, [supabase, session, siteId]);
21359
21359
  return state;
21360
21360
  }
21361
+ const SETTO_BASE = "/setto";
21362
+ function siteHomeUrl(pathname = "/") {
21363
+ const u = new URL(window.location.href);
21364
+ u.pathname = pathname;
21365
+ u.search = "";
21366
+ return u.toString();
21367
+ }
21368
+ function isAdminRoute() {
21369
+ return window.location.pathname.startsWith(SETTO_BASE);
21370
+ }
21371
+ function isAdminDeploymentView() {
21372
+ return isAdminRoute() && new URLSearchParams(window.location.search).has("deployment");
21373
+ }
21374
+ function adminViewUrl(view) {
21375
+ return `${SETTO_BASE}?view=${encodeURIComponent(view)}`;
21376
+ }
21377
+ function currentAdminView() {
21378
+ return new URLSearchParams(window.location.search).get("view");
21379
+ }
21380
+ function isAdminPanelView() {
21381
+ return isAdminDeploymentView() || isAdminRoute() && currentAdminView() !== null;
21382
+ }
21383
+ const CHECKOUT_INTENT = "neste";
21384
+ function checkoutIntentUrl() {
21385
+ return `${SETTO_BASE}?${CHECKOUT_INTENT}=1`;
21386
+ }
21387
+ function wantsCheckout() {
21388
+ return new URLSearchParams(window.location.search).get(CHECKOUT_INTENT) === "1";
21389
+ }
21390
+ function withoutCheckoutIntent() {
21391
+ const u = new URL(window.location.href);
21392
+ u.searchParams.delete(CHECKOUT_INTENT);
21393
+ return u.pathname + (u.search || "") + u.hash;
21394
+ }
21361
21395
  const PREVIEW_HOST = /(^|\.)site\.setto\.no$/i;
21362
21396
  function isPreviewHost(hostname) {
21363
21397
  return PREVIEW_HOST.test(hostname);
@@ -21394,21 +21428,8 @@ function SettoPreviewBar() {
21394
21428
  cancelled = true;
21395
21429
  };
21396
21430
  }, [onPreview, session, config.apiUrl, config.siteId]);
21397
- const state = previewBarState({
21398
- onPreview,
21399
- authLoading,
21400
- hasSession: !!session,
21401
- sitesLoaded: sites !== null,
21402
- hasCurrentSite: !!currentSite,
21403
- currentSiteIsLive: currentSite?.status === "live",
21404
- soldPublic,
21405
- paidMarker: paid
21406
- });
21407
- if (state === "hidden") return null;
21408
- const owner = state === "owner";
21409
- const name = currentSite?.display_name?.trim() || config.displayName?.trim() || config.siteId;
21410
21431
  const signIn = () => {
21411
- window.location.href = "/setto";
21432
+ window.location.href = checkoutIntentUrl();
21412
21433
  };
21413
21434
  const next = () => {
21414
21435
  if (window.parent !== window) {
@@ -21445,6 +21466,28 @@ function SettoPreviewBar() {
21445
21466
  setBusy(false);
21446
21467
  }
21447
21468
  };
21469
+ const resumed = useRef(false);
21470
+ useEffect(() => {
21471
+ if (resumed.current || !onPreview || !session || !currentSite) return;
21472
+ if (!wantsCheckout()) return;
21473
+ if (paid || currentSite.status === "live") return;
21474
+ resumed.current = true;
21475
+ window.history.replaceState(null, "", withoutCheckoutIntent());
21476
+ void publish();
21477
+ }, [onPreview, session, currentSite, paid]);
21478
+ const state = previewBarState({
21479
+ onPreview,
21480
+ authLoading,
21481
+ hasSession: !!session,
21482
+ sitesLoaded: sites !== null,
21483
+ hasCurrentSite: !!currentSite,
21484
+ currentSiteIsLive: currentSite?.status === "live",
21485
+ soldPublic,
21486
+ paidMarker: paid
21487
+ });
21488
+ if (state === "hidden") return null;
21489
+ const owner = state === "owner";
21490
+ const name = currentSite?.display_name?.trim() || config.displayName?.trim() || config.siteId;
21448
21491
  return createPortal(
21449
21492
  /*
21450
21493
  * Lifted above the editor's floating button when edit mode is on, which
@@ -21545,28 +21588,6 @@ const errorStyle$1 = {
21545
21588
  textOverflow: "ellipsis",
21546
21589
  whiteSpace: "nowrap"
21547
21590
  };
21548
- const SETTO_BASE = "/setto";
21549
- function siteHomeUrl(pathname = "/") {
21550
- const u = new URL(window.location.href);
21551
- u.pathname = pathname;
21552
- u.search = "";
21553
- return u.toString();
21554
- }
21555
- function isAdminRoute() {
21556
- return window.location.pathname.startsWith(SETTO_BASE);
21557
- }
21558
- function isAdminDeploymentView() {
21559
- return isAdminRoute() && new URLSearchParams(window.location.search).has("deployment");
21560
- }
21561
- function adminViewUrl(view) {
21562
- return `${SETTO_BASE}?view=${encodeURIComponent(view)}`;
21563
- }
21564
- function currentAdminView() {
21565
- return new URLSearchParams(window.location.search).get("view");
21566
- }
21567
- function isAdminPanelView() {
21568
- return isAdminDeploymentView() || isAdminRoute() && currentAdminView() !== null;
21569
- }
21570
21591
  const FAB_SIZE = 52;
21571
21592
  const FAB_INSET = 16;
21572
21593
  const STYLE_ID$3 = "setto-edit-layout";
@@ -26256,7 +26277,9 @@ function SiteList() {
26256
26277
  }
26257
26278
  if (currentSite) {
26258
26279
  redirectAfterSignIn.current = false;
26259
- window.location.replace(siteHomeUrl());
26280
+ window.location.replace(
26281
+ wantsCheckout() ? `${siteHomeUrl()}?${CHECKOUT_INTENT}=1` : siteHomeUrl()
26282
+ );
26260
26283
  return;
26261
26284
  }
26262
26285
  redirectAfterSignIn.current = false;