@sevenfold/setto-client 0.8.3 → 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,15 @@ 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();
21433
+ };
21434
+ const next = () => {
21435
+ if (window.parent !== window) {
21436
+ window.parent.postMessage({ type: "setto:next", siteId: config.siteId }, "*");
21437
+ return;
21438
+ }
21439
+ signIn();
21412
21440
  };
21413
21441
  const publish = async () => {
21414
21442
  setBusy(true);
@@ -21438,6 +21466,28 @@ function SettoPreviewBar() {
21438
21466
  setBusy(false);
21439
21467
  }
21440
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;
21441
21491
  return createPortal(
21442
21492
  /*
21443
21493
  * Lifted above the editor's floating button when edit mode is on, which
@@ -21459,11 +21509,8 @@ function SettoPreviewBar() {
21459
21509
  /* @__PURE__ */ jsx("button", { type: "button", style: primaryStyle, onClick: publish, disabled: busy, children: busy ? "Åpner betaling …" : "Publiser" })
21460
21510
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
21461
21511
  /* @__PURE__ */ jsx("span", { style: dotStyle, "aria-hidden": true }),
21462
- /* @__PURE__ */ jsxs("span", { style: labelStyle, children: [
21463
- "Forhåndsvisning av ",
21464
- name
21465
- ] }),
21466
- /* @__PURE__ */ jsx("button", { type: "button", style: primaryStyle, onClick: signIn, children: "Rediger" })
21512
+ /* @__PURE__ */ jsx("span", { style: labelStyle, children: "Forhåndsvisning" }),
21513
+ /* @__PURE__ */ jsx("button", { type: "button", style: primaryStyle, onClick: next, children: "Neste" })
21467
21514
  ] })
21468
21515
  }
21469
21516
  ),
@@ -21487,7 +21534,20 @@ const barStyle = {
21487
21534
  fontFamily: 'system-ui, -apple-system, "Segoe UI", sans-serif',
21488
21535
  fontSize: 14,
21489
21536
  lineHeight: 1.3,
21490
- boxShadow: "0 18px 40px -18px rgba(0, 0, 0, 0.65)"
21537
+ boxShadow: "0 18px 40px -18px rgba(0, 0, 0, 0.65)",
21538
+ /*
21539
+ * A frosted rim, so the pill reads as an object on any page.
21540
+ *
21541
+ * The bar sits on sites Setto did not choose the colours for: on a dark hero
21542
+ * a dark pill disappears, and on a pale section its shadow is all that holds
21543
+ * it. A translucent white border with `padding-box` clipping lets the page
21544
+ * show through the rim itself, which separates the pill from either ground
21545
+ * without picking a side.
21546
+ */
21547
+ border: "5px solid rgba(255, 255, 255, 0.22)",
21548
+ backgroundClip: "padding-box",
21549
+ backdropFilter: "blur(10px)",
21550
+ WebkitBackdropFilter: "blur(10px)"
21491
21551
  };
21492
21552
  const dotStyle = {
21493
21553
  width: 7,
@@ -21528,28 +21588,6 @@ const errorStyle$1 = {
21528
21588
  textOverflow: "ellipsis",
21529
21589
  whiteSpace: "nowrap"
21530
21590
  };
21531
- const SETTO_BASE = "/setto";
21532
- function siteHomeUrl(pathname = "/") {
21533
- const u = new URL(window.location.href);
21534
- u.pathname = pathname;
21535
- u.search = "";
21536
- return u.toString();
21537
- }
21538
- function isAdminRoute() {
21539
- return window.location.pathname.startsWith(SETTO_BASE);
21540
- }
21541
- function isAdminDeploymentView() {
21542
- return isAdminRoute() && new URLSearchParams(window.location.search).has("deployment");
21543
- }
21544
- function adminViewUrl(view) {
21545
- return `${SETTO_BASE}?view=${encodeURIComponent(view)}`;
21546
- }
21547
- function currentAdminView() {
21548
- return new URLSearchParams(window.location.search).get("view");
21549
- }
21550
- function isAdminPanelView() {
21551
- return isAdminDeploymentView() || isAdminRoute() && currentAdminView() !== null;
21552
- }
21553
21591
  const FAB_SIZE = 52;
21554
21592
  const FAB_INSET = 16;
21555
21593
  const STYLE_ID$3 = "setto-edit-layout";
@@ -26239,7 +26277,9 @@ function SiteList() {
26239
26277
  }
26240
26278
  if (currentSite) {
26241
26279
  redirectAfterSignIn.current = false;
26242
- window.location.replace(siteHomeUrl());
26280
+ window.location.replace(
26281
+ wantsCheckout() ? `${siteHomeUrl()}?${CHECKOUT_INTENT}=1` : siteHomeUrl()
26282
+ );
26243
26283
  return;
26244
26284
  }
26245
26285
  redirectAfterSignIn.current = false;