@usethrottle/builder-react 0.3.1 → 0.4.0

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.
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all2) => {
7
+ for (var name in all2)
8
+ __defProp(target, name, { get: all2[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/interactions/runtime.ts
21
+ var runtime_exports = {};
22
+ __export(runtime_exports, {
23
+ startRuntime: () => startRuntime
24
+ });
25
+ module.exports = __toCommonJS(runtime_exports);
26
+ var UNITS = [86400, 3600, 60, 1];
27
+ var KEYS = ["d", "h", "m", "s"];
28
+ var NAMES = ["days", "hours", "minutes", "seconds"];
29
+ var holds = 0;
30
+ var stop;
31
+ var seen = /* @__PURE__ */ new WeakSet();
32
+ var autoplay = /* @__PURE__ */ new Map();
33
+ var all = (selector) => Array.from(document.querySelectorAll(selector));
34
+ var reduced = () => window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
35
+ function selectTab(list, index, focus = false) {
36
+ const tabs = Array.from(list.querySelectorAll("[role=tab]"));
37
+ tabs.forEach((tab, i) => {
38
+ const on = i === index;
39
+ tab.setAttribute("aria-selected", String(on));
40
+ tab.tabIndex = on ? 0 : -1;
41
+ const panel = document.getElementById(tab.getAttribute("aria-controls") ?? "");
42
+ if (panel !== null) panel.hidden = !on;
43
+ if (on && focus) tab.focus();
44
+ });
45
+ }
46
+ function slideTo(root, step) {
47
+ const track = root.querySelector(".tb-car-track");
48
+ if (track === null || track.clientWidth === 0) return;
49
+ const count = track.children.length;
50
+ const at = Math.round(track.scrollLeft / track.clientWidth) + step;
51
+ const loop = root.hasAttribute("data-b-loop");
52
+ const to = at >= count ? loop ? 0 : count - 1 : at < 0 ? loop ? count - 1 : 0 : at;
53
+ track.scrollTo?.({ left: to * track.clientWidth, behavior: reduced() ? "auto" : "smooth" });
54
+ }
55
+ var carousels = /* @__PURE__ */ new WeakMap();
56
+ function setupCarousel(root) {
57
+ const every = Number(root.getAttribute("data-b-autoplay"));
58
+ const pause = root.querySelector("[data-b-act=pause]");
59
+ if (!(every > 0) || reduced() || pause === null) return;
60
+ pause.hidden = false;
61
+ let state = carousels.get(root);
62
+ if (state === void 0) {
63
+ const own = state = { hold: 0 };
64
+ carousels.set(root, own);
65
+ const set = (bit, on) => void (own.hold = on ? own.hold | bit : own.hold & ~bit);
66
+ root.addEventListener("mouseenter", () => set(1, true));
67
+ root.addEventListener("mouseleave", () => set(1, false));
68
+ root.addEventListener("focusin", () => set(2, true));
69
+ root.addEventListener("focusout", () => set(2, false));
70
+ pause.addEventListener("click", () => {
71
+ set(4, (own.hold & 4) === 0);
72
+ pause.textContent = own.hold & 4 ? "Play" : "Pause";
73
+ });
74
+ }
75
+ const shared = state;
76
+ autoplay.set(root, window.setInterval(() => shared.hold === 0 && slideTo(root, 1), every));
77
+ }
78
+ function remaining(el) {
79
+ return Math.max(0, Math.floor((Number(el.getAttribute("data-b-cd")) - Date.now()) / 1e3));
80
+ }
81
+ function tick(el, minute) {
82
+ let left = remaining(el);
83
+ const parts = [];
84
+ KEYS.forEach((key, i) => {
85
+ const out = el.querySelector(`[data-u=${key}]`);
86
+ if (out === null) return;
87
+ const value = Math.floor(left / UNITS[i]);
88
+ left -= value * UNITS[i];
89
+ out.textContent = String(value).padStart(2, "0");
90
+ parts.push(`${String(value)} ${out.nextElementSibling?.textContent || NAMES[i]}`);
91
+ });
92
+ const live = el.querySelector("[data-b-live]");
93
+ if (live !== null && minute) live.textContent = parts.join(", ");
94
+ if (remaining(el) === 0) {
95
+ el.setAttribute("data-b-ended", "");
96
+ const text = el.querySelector(".tb-b-cd-ended");
97
+ if (text !== null) text.hidden = false;
98
+ if (el.getAttribute("data-b-expired") === "hide") el.hidden = true;
99
+ }
100
+ }
101
+ function scan() {
102
+ autoplay.forEach((id, root) => {
103
+ if (!root.isConnected) {
104
+ window.clearInterval(id);
105
+ autoplay.delete(root);
106
+ }
107
+ });
108
+ document.documentElement.setAttribute("data-b-js", "");
109
+ const fresh = (selector) => all(selector).filter((el) => !seen.has(el) && seen.add(el));
110
+ fresh("[data-b-tabs]").forEach((list) => selectTab(list, 0));
111
+ fresh("[data-b-car]").forEach((root) => setupCarousel(root));
112
+ const counts = fresh("[data-b-cd]");
113
+ counts.forEach((el) => tick(el, true));
114
+ const targets = fresh("[data-b-entrance]");
115
+ if (targets.length === 0) return;
116
+ if (typeof IntersectionObserver === "undefined") targets.forEach((el) => el.setAttribute("data-b-in", ""));
117
+ else {
118
+ const watch = new IntersectionObserver(
119
+ (entries) => entries.forEach((entry) => {
120
+ if (!entry.isIntersecting) return;
121
+ entry.target.setAttribute("data-b-in", "");
122
+ watch.unobserve(entry.target);
123
+ })
124
+ );
125
+ targets.forEach((el) => watch.observe(el));
126
+ }
127
+ }
128
+ var shown = (el) => el !== null && el.getClientRects().length > 0;
129
+ function goAnchor(name) {
130
+ if (name === "" || shown(document.getElementById(name))) return false;
131
+ const copy = all("[data-b-anchor]").find((el) => el.getAttribute("data-b-anchor") === name && shown(el));
132
+ copy?.scrollIntoView();
133
+ return copy !== void 0;
134
+ }
135
+ var decoded = (hash) => {
136
+ try {
137
+ return decodeURIComponent(hash.slice(1));
138
+ } catch {
139
+ return "";
140
+ }
141
+ };
142
+ var onHash = () => void goAnchor(decoded(location.hash));
143
+ function onClick(event) {
144
+ const target = event.target;
145
+ const href = target?.closest('a[href^="#"]')?.getAttribute("href");
146
+ if (href && !event.defaultPrevented && !event.button && !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) && goAnchor(decoded(href))) {
147
+ event.preventDefault();
148
+ history.pushState(null, "", href);
149
+ }
150
+ const tab = target?.closest("[role=tab]");
151
+ const list = tab?.closest("[data-b-tabs]");
152
+ if (tab && list) return selectTab(list, Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab));
153
+ const button = target?.closest("[data-b-act]");
154
+ const act = button?.getAttribute("data-b-act");
155
+ const root = button?.closest("[data-b-car]");
156
+ if (root && (act === "prev" || act === "next")) slideTo(root, act === "next" ? 1 : -1);
157
+ }
158
+ function onKey(event) {
159
+ const tab = event.target?.closest("[role=tab]");
160
+ const list = tab?.closest("[data-b-tabs]");
161
+ if (!tab || !list) return;
162
+ const count = list.querySelectorAll("[role=tab]").length;
163
+ const at = Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab);
164
+ const to = event.key === "ArrowRight" ? (at + 1) % count : event.key === "ArrowLeft" ? (at + count - 1) % count : event.key === "Home" ? 0 : event.key === "End" ? count - 1 : -1;
165
+ if (to < 0) return;
166
+ event.preventDefault();
167
+ selectTab(list, to, true);
168
+ }
169
+ function startRuntime() {
170
+ if (typeof document === "undefined") return () => void 0;
171
+ const first = holds++ === 0;
172
+ if (first) {
173
+ document.addEventListener("click", onClick);
174
+ document.addEventListener("keydown", onKey);
175
+ window.addEventListener("hashchange", onHash);
176
+ let beat = 0;
177
+ const clock = window.setInterval(() => {
178
+ const minute = ++beat % 60 === 0;
179
+ all("[data-b-cd]:not([data-b-ended])").forEach((el) => tick(el, minute));
180
+ }, 1e3);
181
+ let queued = false;
182
+ const watcher = new MutationObserver(() => {
183
+ if (queued) return;
184
+ queued = true;
185
+ void Promise.resolve().then(() => {
186
+ queued = false;
187
+ if (holds > 0) scan();
188
+ });
189
+ });
190
+ watcher.observe(document.documentElement, { childList: true, subtree: true });
191
+ stop = () => {
192
+ document.removeEventListener("click", onClick);
193
+ document.removeEventListener("keydown", onKey);
194
+ window.removeEventListener("hashchange", onHash);
195
+ window.clearInterval(clock);
196
+ watcher.disconnect();
197
+ autoplay.forEach((id) => window.clearInterval(id));
198
+ autoplay.clear();
199
+ seen = /* @__PURE__ */ new WeakSet();
200
+ };
201
+ }
202
+ scan();
203
+ if (first) onHash();
204
+ return () => {
205
+ if (--holds === 0) stop?.();
206
+ };
207
+ }
@@ -0,0 +1,186 @@
1
+ // src/interactions/runtime.ts
2
+ var UNITS = [86400, 3600, 60, 1];
3
+ var KEYS = ["d", "h", "m", "s"];
4
+ var NAMES = ["days", "hours", "minutes", "seconds"];
5
+ var holds = 0;
6
+ var stop;
7
+ var seen = /* @__PURE__ */ new WeakSet();
8
+ var autoplay = /* @__PURE__ */ new Map();
9
+ var all = (selector) => Array.from(document.querySelectorAll(selector));
10
+ var reduced = () => window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
11
+ function selectTab(list, index, focus = false) {
12
+ const tabs = Array.from(list.querySelectorAll("[role=tab]"));
13
+ tabs.forEach((tab, i) => {
14
+ const on = i === index;
15
+ tab.setAttribute("aria-selected", String(on));
16
+ tab.tabIndex = on ? 0 : -1;
17
+ const panel = document.getElementById(tab.getAttribute("aria-controls") ?? "");
18
+ if (panel !== null) panel.hidden = !on;
19
+ if (on && focus) tab.focus();
20
+ });
21
+ }
22
+ function slideTo(root, step) {
23
+ const track = root.querySelector(".tb-car-track");
24
+ if (track === null || track.clientWidth === 0) return;
25
+ const count = track.children.length;
26
+ const at = Math.round(track.scrollLeft / track.clientWidth) + step;
27
+ const loop = root.hasAttribute("data-b-loop");
28
+ const to = at >= count ? loop ? 0 : count - 1 : at < 0 ? loop ? count - 1 : 0 : at;
29
+ track.scrollTo?.({ left: to * track.clientWidth, behavior: reduced() ? "auto" : "smooth" });
30
+ }
31
+ var carousels = /* @__PURE__ */ new WeakMap();
32
+ function setupCarousel(root) {
33
+ const every = Number(root.getAttribute("data-b-autoplay"));
34
+ const pause = root.querySelector("[data-b-act=pause]");
35
+ if (!(every > 0) || reduced() || pause === null) return;
36
+ pause.hidden = false;
37
+ let state = carousels.get(root);
38
+ if (state === void 0) {
39
+ const own = state = { hold: 0 };
40
+ carousels.set(root, own);
41
+ const set = (bit, on) => void (own.hold = on ? own.hold | bit : own.hold & ~bit);
42
+ root.addEventListener("mouseenter", () => set(1, true));
43
+ root.addEventListener("mouseleave", () => set(1, false));
44
+ root.addEventListener("focusin", () => set(2, true));
45
+ root.addEventListener("focusout", () => set(2, false));
46
+ pause.addEventListener("click", () => {
47
+ set(4, (own.hold & 4) === 0);
48
+ pause.textContent = own.hold & 4 ? "Play" : "Pause";
49
+ });
50
+ }
51
+ const shared = state;
52
+ autoplay.set(root, window.setInterval(() => shared.hold === 0 && slideTo(root, 1), every));
53
+ }
54
+ function remaining(el) {
55
+ return Math.max(0, Math.floor((Number(el.getAttribute("data-b-cd")) - Date.now()) / 1e3));
56
+ }
57
+ function tick(el, minute) {
58
+ let left = remaining(el);
59
+ const parts = [];
60
+ KEYS.forEach((key, i) => {
61
+ const out = el.querySelector(`[data-u=${key}]`);
62
+ if (out === null) return;
63
+ const value = Math.floor(left / UNITS[i]);
64
+ left -= value * UNITS[i];
65
+ out.textContent = String(value).padStart(2, "0");
66
+ parts.push(`${String(value)} ${out.nextElementSibling?.textContent || NAMES[i]}`);
67
+ });
68
+ const live = el.querySelector("[data-b-live]");
69
+ if (live !== null && minute) live.textContent = parts.join(", ");
70
+ if (remaining(el) === 0) {
71
+ el.setAttribute("data-b-ended", "");
72
+ const text = el.querySelector(".tb-b-cd-ended");
73
+ if (text !== null) text.hidden = false;
74
+ if (el.getAttribute("data-b-expired") === "hide") el.hidden = true;
75
+ }
76
+ }
77
+ function scan() {
78
+ autoplay.forEach((id, root) => {
79
+ if (!root.isConnected) {
80
+ window.clearInterval(id);
81
+ autoplay.delete(root);
82
+ }
83
+ });
84
+ document.documentElement.setAttribute("data-b-js", "");
85
+ const fresh = (selector) => all(selector).filter((el) => !seen.has(el) && seen.add(el));
86
+ fresh("[data-b-tabs]").forEach((list) => selectTab(list, 0));
87
+ fresh("[data-b-car]").forEach((root) => setupCarousel(root));
88
+ const counts = fresh("[data-b-cd]");
89
+ counts.forEach((el) => tick(el, true));
90
+ const targets = fresh("[data-b-entrance]");
91
+ if (targets.length === 0) return;
92
+ if (typeof IntersectionObserver === "undefined") targets.forEach((el) => el.setAttribute("data-b-in", ""));
93
+ else {
94
+ const watch = new IntersectionObserver(
95
+ (entries) => entries.forEach((entry) => {
96
+ if (!entry.isIntersecting) return;
97
+ entry.target.setAttribute("data-b-in", "");
98
+ watch.unobserve(entry.target);
99
+ })
100
+ );
101
+ targets.forEach((el) => watch.observe(el));
102
+ }
103
+ }
104
+ var shown = (el) => el !== null && el.getClientRects().length > 0;
105
+ function goAnchor(name) {
106
+ if (name === "" || shown(document.getElementById(name))) return false;
107
+ const copy = all("[data-b-anchor]").find((el) => el.getAttribute("data-b-anchor") === name && shown(el));
108
+ copy?.scrollIntoView();
109
+ return copy !== void 0;
110
+ }
111
+ var decoded = (hash) => {
112
+ try {
113
+ return decodeURIComponent(hash.slice(1));
114
+ } catch {
115
+ return "";
116
+ }
117
+ };
118
+ var onHash = () => void goAnchor(decoded(location.hash));
119
+ function onClick(event) {
120
+ const target = event.target;
121
+ const href = target?.closest('a[href^="#"]')?.getAttribute("href");
122
+ if (href && !event.defaultPrevented && !event.button && !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) && goAnchor(decoded(href))) {
123
+ event.preventDefault();
124
+ history.pushState(null, "", href);
125
+ }
126
+ const tab = target?.closest("[role=tab]");
127
+ const list = tab?.closest("[data-b-tabs]");
128
+ if (tab && list) return selectTab(list, Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab));
129
+ const button = target?.closest("[data-b-act]");
130
+ const act = button?.getAttribute("data-b-act");
131
+ const root = button?.closest("[data-b-car]");
132
+ if (root && (act === "prev" || act === "next")) slideTo(root, act === "next" ? 1 : -1);
133
+ }
134
+ function onKey(event) {
135
+ const tab = event.target?.closest("[role=tab]");
136
+ const list = tab?.closest("[data-b-tabs]");
137
+ if (!tab || !list) return;
138
+ const count = list.querySelectorAll("[role=tab]").length;
139
+ const at = Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab);
140
+ const to = event.key === "ArrowRight" ? (at + 1) % count : event.key === "ArrowLeft" ? (at + count - 1) % count : event.key === "Home" ? 0 : event.key === "End" ? count - 1 : -1;
141
+ if (to < 0) return;
142
+ event.preventDefault();
143
+ selectTab(list, to, true);
144
+ }
145
+ function startRuntime() {
146
+ if (typeof document === "undefined") return () => void 0;
147
+ const first = holds++ === 0;
148
+ if (first) {
149
+ document.addEventListener("click", onClick);
150
+ document.addEventListener("keydown", onKey);
151
+ window.addEventListener("hashchange", onHash);
152
+ let beat = 0;
153
+ const clock = window.setInterval(() => {
154
+ const minute = ++beat % 60 === 0;
155
+ all("[data-b-cd]:not([data-b-ended])").forEach((el) => tick(el, minute));
156
+ }, 1e3);
157
+ let queued = false;
158
+ const watcher = new MutationObserver(() => {
159
+ if (queued) return;
160
+ queued = true;
161
+ void Promise.resolve().then(() => {
162
+ queued = false;
163
+ if (holds > 0) scan();
164
+ });
165
+ });
166
+ watcher.observe(document.documentElement, { childList: true, subtree: true });
167
+ stop = () => {
168
+ document.removeEventListener("click", onClick);
169
+ document.removeEventListener("keydown", onKey);
170
+ window.removeEventListener("hashchange", onHash);
171
+ window.clearInterval(clock);
172
+ watcher.disconnect();
173
+ autoplay.forEach((id) => window.clearInterval(id));
174
+ autoplay.clear();
175
+ seen = /* @__PURE__ */ new WeakSet();
176
+ };
177
+ }
178
+ scan();
179
+ if (first) onHash();
180
+ return () => {
181
+ if (--holds === 0) stop?.();
182
+ };
183
+ }
184
+ export {
185
+ startRuntime
186
+ };
package/dist/next.cjs CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkIDGSPYRHcjs = require('./chunk-IDGSPYRH.cjs');
7
+ var _chunk54BG5PPMcjs = require('./chunk-54BG5PPM.cjs');
8
8
 
9
9
  // src/next/index.ts
10
10
  var _react = require('react');
@@ -55,7 +55,7 @@ function createBuilderPage(options) {
55
55
  const slug = slugOf(options, params);
56
56
  const currency = await currencyOf(options, params);
57
57
  const { currency: _currency, ...rest } = options;
58
- const loaded = await _chunkIDGSPYRHcjs.loadBuilderPage.call(void 0, {
58
+ const loaded = await _chunk54BG5PPMcjs.loadBuilderPage.call(void 0, {
59
59
  ...rest,
60
60
  slug,
61
61
  locale: await localeOf(options, params),
@@ -75,12 +75,12 @@ function createBuilderPage(options) {
75
75
  const params = await props.params;
76
76
  const slug = slugOf(options, params);
77
77
  const locale = await localeOf(options, params);
78
- const client = _chunkIDGSPYRHcjs.clientOf.call(void 0, options);
78
+ const client = _chunk54BG5PPMcjs.clientOf.call(void 0, options);
79
79
  try {
80
- const bundle = await _chunkIDGSPYRHcjs.getBundle.call(void 0, { client, locale, page: slug, slots: options.slots });
80
+ const bundle = await _chunk54BG5PPMcjs.getBundle.call(void 0, { client, locale, page: slug, slots: options.slots });
81
81
  const page = bundle.page;
82
- if (page === void 0 || _chunkIDGSPYRHcjs.isRedirect.call(void 0, page)) return {};
83
- return _chunkIDGSPYRHcjs.metadataOf.call(void 0, page, {
82
+ if (page === void 0 || _chunk54BG5PPMcjs.isRedirect.call(void 0, page)) return {};
83
+ return _chunk54BG5PPMcjs.metadataOf.call(void 0, page, {
84
84
  settings: bundle.site.settings,
85
85
  mediaOrigin: _nullishCoalesce(options.mediaOrigin, () => ( "")),
86
86
  storeUrl: options.storeUrl,
package/dist/next.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { Metadata } from 'next';
3
- import { C as ClientOptions, W as WidgetPack, P as PagePathResolver } from './seo-Dz439Jlk.cjs';
3
+ import { C as ClientOptions, W as WidgetPack, P as PagePathResolver } from './seo-CNZ9DrlU.cjs';
4
4
  import '@usethrottle/builder-schema';
5
5
  import '@usethrottle/builder';
6
6
 
package/dist/next.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { Metadata } from 'next';
3
- import { C as ClientOptions, W as WidgetPack, P as PagePathResolver } from './seo-Dz439Jlk.js';
3
+ import { C as ClientOptions, W as WidgetPack, P as PagePathResolver } from './seo-CNZ9DrlU.js';
4
4
  import '@usethrottle/builder-schema';
5
5
  import '@usethrottle/builder';
6
6
 
package/dist/next.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  isRedirect,
5
5
  loadBuilderPage,
6
6
  metadataOf
7
- } from "./chunk-LXBCOZP2.js";
7
+ } from "./chunk-4EGFSBVT.js";
8
8
 
9
9
  // src/next/index.ts
10
10
  import { createElement } from "react";
@@ -1,5 +1,5 @@
1
1
  import { ComponentType, ReactNode } from 'react';
2
- import { WidgetDefinition, WidgetNode, SettingValue, DataSourceDescriptor, PageDocument, FrozenAsset } from '@usethrottle/builder-schema';
2
+ import { WidgetDefinition, WidgetNode, SettingValue, DataSourceDescriptor, PageDocument, FrozenAsset, SavedSectionsAnswer, CodeRuntimeAnswer } from '@usethrottle/builder-schema';
3
3
  import { BuilderClient, BuilderBundle } from '@usethrottle/builder';
4
4
 
5
5
  /** A count of rendered nodes with a ceiling. One per custom widget render. */
@@ -28,6 +28,13 @@ type WidgetRenderProps = {
28
28
  /** Resolved data by the widget's named inputs. Absent until a perShopper source has resolved in the browser. */
29
29
  data: Record<string, unknown>;
30
30
  editMode: boolean;
31
+ /** False in the editor's edit mode: draw the widget static (no ticking, no script). Absent means true. */
32
+ interactive?: boolean | undefined;
33
+ /** Set inside a per-device copy of a section: a nested renderer continues the parent's id scope (composites). */
34
+ idScope?: {
35
+ vpath: string;
36
+ dupe: boolean;
37
+ } | undefined;
31
38
  locale: string;
32
39
  /** The only origin a media `src` may be on; pass it to `AssetImage`. */
33
40
  mediaOrigin: string;
@@ -93,6 +100,10 @@ type LoadedPage = {
93
100
  initialData: DataMap;
94
101
  /** The page's other fields as the read API sent them (seo, description, ...). */
95
102
  meta: Record<string, unknown>;
103
+ /** The published saved sections the page references. */
104
+ savedSections?: SavedSectionsAnswer | undefined;
105
+ /** Whether the store runs code widgets and where their scripts come from. */
106
+ code?: CodeRuntimeAnswer | undefined;
96
107
  };
97
108
  type LoadedRedirect = {
98
109
  kind: 'redirect';
@@ -103,6 +114,10 @@ type LoadedPart = {
103
114
  document: PageDocument;
104
115
  assets: PageAssets;
105
116
  initialData: DataMap;
117
+ /** The published saved sections the document references. */
118
+ savedSections?: SavedSectionsAnswer | undefined;
119
+ /** Whether the store runs code widgets and where their scripts come from. */
120
+ code?: CodeRuntimeAnswer | undefined;
106
121
  };
107
122
  /**
108
123
  * The store's site design, read once per request. `unavailable` means the
@@ -1,5 +1,5 @@
1
1
  import { ComponentType, ReactNode } from 'react';
2
- import { WidgetDefinition, WidgetNode, SettingValue, DataSourceDescriptor, PageDocument, FrozenAsset } from '@usethrottle/builder-schema';
2
+ import { WidgetDefinition, WidgetNode, SettingValue, DataSourceDescriptor, PageDocument, FrozenAsset, SavedSectionsAnswer, CodeRuntimeAnswer } from '@usethrottle/builder-schema';
3
3
  import { BuilderClient, BuilderBundle } from '@usethrottle/builder';
4
4
 
5
5
  /** A count of rendered nodes with a ceiling. One per custom widget render. */
@@ -28,6 +28,13 @@ type WidgetRenderProps = {
28
28
  /** Resolved data by the widget's named inputs. Absent until a perShopper source has resolved in the browser. */
29
29
  data: Record<string, unknown>;
30
30
  editMode: boolean;
31
+ /** False in the editor's edit mode: draw the widget static (no ticking, no script). Absent means true. */
32
+ interactive?: boolean | undefined;
33
+ /** Set inside a per-device copy of a section: a nested renderer continues the parent's id scope (composites). */
34
+ idScope?: {
35
+ vpath: string;
36
+ dupe: boolean;
37
+ } | undefined;
31
38
  locale: string;
32
39
  /** The only origin a media `src` may be on; pass it to `AssetImage`. */
33
40
  mediaOrigin: string;
@@ -93,6 +100,10 @@ type LoadedPage = {
93
100
  initialData: DataMap;
94
101
  /** The page's other fields as the read API sent them (seo, description, ...). */
95
102
  meta: Record<string, unknown>;
103
+ /** The published saved sections the page references. */
104
+ savedSections?: SavedSectionsAnswer | undefined;
105
+ /** Whether the store runs code widgets and where their scripts come from. */
106
+ code?: CodeRuntimeAnswer | undefined;
96
107
  };
97
108
  type LoadedRedirect = {
98
109
  kind: 'redirect';
@@ -103,6 +114,10 @@ type LoadedPart = {
103
114
  document: PageDocument;
104
115
  assets: PageAssets;
105
116
  initialData: DataMap;
117
+ /** The published saved sections the document references. */
118
+ savedSections?: SavedSectionsAnswer | undefined;
119
+ /** Whether the store runs code widgets and where their scripts come from. */
120
+ code?: CodeRuntimeAnswer | undefined;
106
121
  };
107
122
  /**
108
123
  * The store's site design, read once per request. `unavailable` means the
package/dist/server.cjs CHANGED
@@ -12,25 +12,29 @@
12
12
 
13
13
 
14
14
 
15
- var _chunkIDGSPYRHcjs = require('./chunk-IDGSPYRH.cjs');
15
+ var _chunk54BG5PPMcjs = require('./chunk-54BG5PPM.cjs');
16
16
 
17
17
  // src/server/load-site.ts
18
18
  var _builder = require('@usethrottle/builder');
19
19
  async function loadSite(options) {
20
20
  const { locale, slots = [], packs = [], page, mediaOrigin = "", currency } = options;
21
- const client = _chunkIDGSPYRHcjs.clientOf.call(void 0, options);
21
+ const client = _chunk54BG5PPMcjs.clientOf.call(void 0, options);
22
22
  let bundle;
23
23
  try {
24
- bundle = await _chunkIDGSPYRHcjs.getBundle.call(void 0, { client, locale, slots, page });
24
+ bundle = await _chunk54BG5PPMcjs.getBundle.call(void 0, { client, locale, slots, page });
25
25
  } catch (error) {
26
26
  if (!(error instanceof _builder.BuilderUnavailableError) || client.mode === "build") throw error;
27
- _chunkIDGSPYRHcjs.warnOnce.call(void 0, "site-unavailable", `The Builder could not be read (${error.reason}); the store renders without its Builder header, footer and slots`);
27
+ _chunk54BG5PPMcjs.warnOnce.call(void 0, "site-unavailable", `The Builder could not be read (${error.reason}); the store renders without its Builder header, footer and slots`);
28
28
  return { status: "unavailable", locale };
29
29
  }
30
- const registry = _chunkIDGSPYRHcjs.createRendererRegistry.call(void 0, packs);
30
+ const registry = _chunk54BG5PPMcjs.createRendererRegistry.call(void 0, packs);
31
31
  const names = Object.keys(bundle.slots);
32
- const documents = [bundle.header.document, bundle.footer.document, ...names.map((n) => bundle.slots[n].document)];
33
- const data = await _chunkIDGSPYRHcjs.staticDataFor.call(void 0, documents, registry, locale, currency);
32
+ const withShared = (loaded) => ({
33
+ ...loaded,
34
+ ...(_nullishCoalesce(loaded.savedSections, () => ( bundle.savedSections))) === void 0 ? {} : { savedSections: _nullishCoalesce(loaded.savedSections, () => ( bundle.savedSections)) }
35
+ });
36
+ const documents = [bundle.header, bundle.footer, ...names.map((n) => bundle.slots[n])].map(withShared);
37
+ const data = await _chunk54BG5PPMcjs.staticDataFor.call(void 0, documents, registry, locale, currency);
34
38
  return {
35
39
  status: "ok",
36
40
  locale,
@@ -38,9 +42,9 @@ async function loadSite(options) {
38
42
  siteVersion: bundle.site.siteVersion,
39
43
  mediaOrigin,
40
44
  settings: bundle.site.settings,
41
- header: _chunkIDGSPYRHcjs.partOf.call(void 0, bundle.header, data),
42
- footer: _chunkIDGSPYRHcjs.partOf.call(void 0, bundle.footer, data),
43
- slots: Object.fromEntries(names.map((name) => [name, _chunkIDGSPYRHcjs.partOf.call(void 0, bundle.slots[name], data)]))
45
+ header: _chunk54BG5PPMcjs.partOf.call(void 0, bundle.header, data, bundle),
46
+ footer: _chunk54BG5PPMcjs.partOf.call(void 0, bundle.footer, data, bundle),
47
+ slots: Object.fromEntries(names.map((name) => [name, _chunk54BG5PPMcjs.partOf.call(void 0, bundle.slots[name], data, bundle)]))
44
48
  };
45
49
  }
46
50
 
@@ -48,13 +52,13 @@ async function loadSite(options) {
48
52
 
49
53
  async function builderSitemap(options) {
50
54
  if (options.client === void 0 && (options.builderKey === void 0 || options.builderKey === "")) {
51
- _chunkIDGSPYRHcjs.warnOnce.call(void 0, "sitemap-no-key", "builderSitemap has no builderKey (is THROTTLE_BUILDER_KEY set?); the sitemap leaves out the Builder pages");
55
+ _chunk54BG5PPMcjs.warnOnce.call(void 0, "sitemap-no-key", "builderSitemap has no builderKey (is THROTTLE_BUILDER_KEY set?); the sitemap leaves out the Builder pages");
52
56
  return [];
53
57
  }
54
- const client = _chunkIDGSPYRHcjs.clientOf.call(void 0, options);
55
- const origin = _chunkIDGSPYRHcjs.originOf.call(void 0, options.storeUrl);
58
+ const client = _chunk54BG5PPMcjs.clientOf.call(void 0, options);
59
+ const origin = _chunk54BG5PPMcjs.originOf.call(void 0, options.storeUrl);
56
60
  if (origin === void 0) {
57
- _chunkIDGSPYRHcjs.warnOnce.call(void 0, "sitemap-origin", "builderSitemap needs a storeUrl (https://shop.example.com) that is an http(s) origin. The Builder does not publish the store URL.");
61
+ _chunk54BG5PPMcjs.warnOnce.call(void 0, "sitemap-origin", "builderSitemap needs a storeUrl (https://shop.example.com) that is an http(s) origin. The Builder does not publish the store URL.");
58
62
  return [];
59
63
  }
60
64
  const locale = _nullishCoalesce(options.locale, () => ( "en"));
@@ -62,16 +66,16 @@ async function builderSitemap(options) {
62
66
  const pages = await client.pages.list();
63
67
  const { settings } = await client.site({ locale });
64
68
  const indexable = await withoutNoindex(client, pages, locale);
65
- const { list } = _chunkIDGSPYRHcjs.siteLocales.call(void 0, settings);
69
+ const { list } = _chunk54BG5PPMcjs.siteLocales.call(void 0, settings);
66
70
  const prefixes = options.localeRoute !== true ? [void 0] : list.length > 0 ? list : [locale];
67
71
  return indexable.flatMap((page) => {
68
- const path = _chunkIDGSPYRHcjs.pagePathOf.call(void 0, settings, page, options.pagePath);
72
+ const path = _chunk54BG5PPMcjs.pagePathOf.call(void 0, settings, page, options.pagePath);
69
73
  if (path === null) return [];
70
- return prefixes.map((prefix) => ({ url: `${origin}${_chunkIDGSPYRHcjs.localized.call(void 0, path, prefix)}`, lastModified: new Date(page.updatedAt) }));
74
+ return prefixes.map((prefix) => ({ url: `${origin}${_chunk54BG5PPMcjs.localized.call(void 0, path, prefix)}`, lastModified: new Date(page.updatedAt) }));
71
75
  });
72
76
  } catch (error) {
73
77
  if (!(error instanceof _builder.BuilderUnavailableError) || client.mode === "build") throw error;
74
- _chunkIDGSPYRHcjs.warnOnce.call(void 0, "sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
78
+ _chunk54BG5PPMcjs.warnOnce.call(void 0, "sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
75
79
  return [];
76
80
  }
77
81
  }
@@ -85,14 +89,14 @@ async function withoutNoindex(client, pages, locale) {
85
89
  slice.map(
86
90
  (page) => client.pages.get(page.slug, { locale }).catch((error) => {
87
91
  if (error instanceof _builder.BuilderNotFoundError) return "gone";
88
- _chunkIDGSPYRHcjs.warnOnce.call(void 0, "sitemap-page-read", `A page could not be read for the sitemap (${error instanceof Error ? error.message : "unknown error"}); it stays listed`);
92
+ _chunk54BG5PPMcjs.warnOnce.call(void 0, "sitemap-page-read", `A page could not be read for the sitemap (${error instanceof Error ? error.message : "unknown error"}); it stays listed`);
89
93
  return void 0;
90
94
  })
91
95
  )
92
96
  );
93
97
  slice.forEach((page, index) => {
94
98
  const answer = answers[index];
95
- if (answer === "gone" || answer !== void 0 && (_chunkIDGSPYRHcjs.isRedirect.call(void 0, answer) || _chunkIDGSPYRHcjs.pageSeoOf.call(void 0, answer).noindex)) skip.add(page.slug);
99
+ if (answer === "gone" || answer !== void 0 && (_chunk54BG5PPMcjs.isRedirect.call(void 0, answer) || _chunk54BG5PPMcjs.pageSeoOf.call(void 0, answer).noindex)) skip.add(page.slug);
96
100
  });
97
101
  }
98
102
  return pages.filter((page) => !skip.has(page.slug));
@@ -100,7 +104,7 @@ async function withoutNoindex(client, pages, locale) {
100
104
 
101
105
  // src/server/static-params.ts
102
106
  async function builderStaticParams(options) {
103
- const client = _chunkIDGSPYRHcjs.clientOf.call(void 0, options);
107
+ const client = _chunk54BG5PPMcjs.clientOf.call(void 0, options);
104
108
  if (client.mode !== "build")
105
109
  throw new TypeError(
106
110
  'builderStaticParams generates every page of a frozen release: give it a client made with createBuilderClient({ mode: "build" }). A live store keeps its pages dynamic.'
@@ -119,4 +123,4 @@ async function builderStaticParams(options) {
119
123
 
120
124
 
121
125
 
122
- exports.BuilderNotFoundError = _builder.BuilderNotFoundError; exports.BuilderUnavailableError = _builder.BuilderUnavailableError; exports.builderSitemap = builderSitemap; exports.builderStaticParams = builderStaticParams; exports.getBundle = _chunkIDGSPYRHcjs.getBundle; exports.loadBuilderPage = _chunkIDGSPYRHcjs.loadBuilderPage; exports.loadSite = loadSite;
126
+ exports.BuilderNotFoundError = _builder.BuilderNotFoundError; exports.BuilderUnavailableError = _builder.BuilderUnavailableError; exports.builderSitemap = builderSitemap; exports.builderStaticParams = builderStaticParams; exports.getBundle = _chunk54BG5PPMcjs.getBundle; exports.loadBuilderPage = _chunk54BG5PPMcjs.loadBuilderPage; exports.loadSite = loadSite;