@bagelink/blox 1.12.20 → 1.12.21

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.
@@ -1 +1 @@
1
- {"version":3,"file":"CmsPageView.vue.d.ts","sourceRoot":"","sources":["../src/CmsPageView.vue"],"names":[],"mappings":";AAkOA,wBAMG"}
1
+ {"version":3,"file":"CmsPageView.vue.d.ts","sourceRoot":"","sources":["../src/CmsPageView.vue"],"names":[],"mappings":";AAkRA,wBAMG"}
@@ -0,0 +1,4 @@
1
+ const BLOX_STATE_WINDOW_KEY = "__BLOX_STATE__";
2
+ export {
3
+ BLOX_STATE_WINDOW_KEY as B
4
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ const BLOX_STATE_WINDOW_KEY = "__BLOX_STATE__";
3
+ exports.BLOX_STATE_WINDOW_KEY = BLOX_STATE_WINDOW_KEY;
package/dist/index.cjs CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
6
  const vue = require("vue");
7
7
  const vueRouter = require("vue-router");
8
8
  const vue$1 = require("@bagelink/vue");
9
+ const constants = require("./constants-fZvybj0k.cjs");
9
10
  const BASE = "/api";
10
11
  let _websiteName = "";
11
12
  let _store = "";
@@ -123,14 +124,29 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
123
124
  const loading = vue.ref(true);
124
125
  const notFound = vue.ref(false);
125
126
  const error = vue.ref(null);
127
+ function hydrateFromState(path) {
128
+ var _a, _b;
129
+ const win = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : void 0;
130
+ if (!win) return false;
131
+ const state = win[constants.BLOX_STATE_WINDOW_KEY];
132
+ if (!state || typeof state !== "object") return false;
133
+ const entry = state[path];
134
+ if (!entry) return false;
135
+ blocks.value = ((_b = (_a = entry.page) == null ? void 0 : _a.content) == null ? void 0 : _b.blocks) ?? [];
136
+ contexts.value = entry.contexts ?? {};
137
+ setAlternates(entry.alternates ?? {});
138
+ loading.value = false;
139
+ return true;
140
+ }
126
141
  async function load() {
127
142
  var _a;
128
143
  loading.value = true;
129
144
  notFound.value = false;
130
145
  error.value = null;
131
- const { locale: urlLocale, slug } = strategy ? strategy.detect(window.location.hostname, route.path) : { locale: locale2.value, slug: route.path || "/" };
146
+ const { locale: urlLocale, slug } = strategy ? strategy.detect(typeof window !== "undefined" ? window.location.hostname : "", route.path) : { locale: locale2.value, slug: route.path || "/" };
132
147
  if (urlLocale !== locale2.value) setLocale(urlLocale);
133
148
  setAlternates({});
149
+ if (hydrateFromState(slug)) return;
134
150
  try {
135
151
  const resolved = await resolvePath(slug, urlLocale);
136
152
  blocks.value = ((_a = resolved.page.content) == null ? void 0 : _a.blocks) ?? [];
package/dist/index.mjs CHANGED
@@ -4,6 +4,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4
4
  import { computed, ref, defineComponent, inject, h, provide, watch, resolveComponent, createElementBlock, openBlock, createBlock, createElementVNode, createVNode, toDisplayString, unref, withCtx, createTextVNode, normalizeProps, guardReactiveProps, renderSlot, onMounted, onUnmounted, nextTick } from "vue";
5
5
  import { useRoute, useRouter, RouterLink } from "vue-router";
6
6
  import { getI18n } from "@bagelink/vue";
7
+ import { B as BLOX_STATE_WINDOW_KEY } from "./constants-BIbQhd3z.js";
7
8
  const BASE = "/api";
8
9
  let _websiteName = "";
9
10
  let _store = "";
@@ -121,14 +122,29 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
121
122
  const loading = ref(true);
122
123
  const notFound = ref(false);
123
124
  const error = ref(null);
125
+ function hydrateFromState(path) {
126
+ var _a, _b;
127
+ const win = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : void 0;
128
+ if (!win) return false;
129
+ const state = win[BLOX_STATE_WINDOW_KEY];
130
+ if (!state || typeof state !== "object") return false;
131
+ const entry = state[path];
132
+ if (!entry) return false;
133
+ blocks.value = ((_b = (_a = entry.page) == null ? void 0 : _a.content) == null ? void 0 : _b.blocks) ?? [];
134
+ contexts.value = entry.contexts ?? {};
135
+ setAlternates(entry.alternates ?? {});
136
+ loading.value = false;
137
+ return true;
138
+ }
124
139
  async function load() {
125
140
  var _a;
126
141
  loading.value = true;
127
142
  notFound.value = false;
128
143
  error.value = null;
129
- const { locale: urlLocale, slug } = strategy ? strategy.detect(window.location.hostname, route.path) : { locale: locale2.value, slug: route.path || "/" };
144
+ const { locale: urlLocale, slug } = strategy ? strategy.detect(typeof window !== "undefined" ? window.location.hostname : "", route.path) : { locale: locale2.value, slug: route.path || "/" };
130
145
  if (urlLocale !== locale2.value) setLocale(urlLocale);
131
146
  setAlternates({});
147
+ if (hydrateFromState(slug)) return;
132
148
  try {
133
149
  const resolved = await resolvePath(slug, urlLocale);
134
150
  blocks.value = ((_a = resolved.page.content) == null ? void 0 : _a.blocks) ?? [];
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const BLOX_STATE_WINDOW_KEY = "__BLOX_STATE__";
4
- function installBloxStateCache(globalKey = BLOX_STATE_WINDOW_KEY) {
3
+ const constants = require("../constants-fZvybj0k.cjs");
4
+ function installBloxStateCache(globalKey = constants.BLOX_STATE_WINDOW_KEY) {
5
5
  if (typeof window === "undefined") return;
6
6
  const state = window[globalKey];
7
7
  if (!state || typeof state !== "object" || Object.keys(state).length === 0) return;
@@ -26,5 +26,5 @@ function installBloxStateCache(globalKey = BLOX_STATE_WINDOW_KEY) {
26
26
  return originalFetch(input, init);
27
27
  };
28
28
  }
29
- exports.BLOX_STATE_WINDOW_KEY = BLOX_STATE_WINDOW_KEY;
29
+ exports.BLOX_STATE_WINDOW_KEY = constants.BLOX_STATE_WINDOW_KEY;
30
30
  exports.installBloxStateCache = installBloxStateCache;
@@ -1,4 +1,4 @@
1
- const BLOX_STATE_WINDOW_KEY = "__BLOX_STATE__";
1
+ import { B as BLOX_STATE_WINDOW_KEY } from "../constants-BIbQhd3z.js";
2
2
  function installBloxStateCache(globalKey = BLOX_STATE_WINDOW_KEY) {
3
3
  if (typeof window === "undefined") return;
4
4
  const state = window[globalKey];
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const prerender = require("../prerender-6jE_obPj.cjs");
4
+ const constants = require("../constants-fZvybj0k.cjs");
4
5
  const ssg_client = require("./client.cjs");
5
6
  async function renderBloxSsgPage(options) {
6
7
  const {
@@ -8,46 +9,31 @@ async function renderBloxSsgPage(options) {
8
9
  resolvedData,
9
10
  renderToString,
10
11
  createAppForUrl,
11
- stateWindowKey = ssg_client.BLOX_STATE_WINDOW_KEY
12
+ stateWindowKey = constants.BLOX_STATE_WINDOW_KEY
12
13
  } = options;
13
- const originalFetch = globalThis.fetch;
14
+ const g = globalThis;
15
+ const prevState = g[stateWindowKey];
14
16
  if (resolvedData != null) {
15
- globalThis.fetch = async (input, init) => {
16
- const u = String(input);
17
- if (u.includes("resolve-path")) {
18
- return new Response(JSON.stringify(resolvedData), {
19
- status: 200,
20
- headers: { "Content-Type": "application/json" }
21
- });
22
- }
23
- return originalFetch(input, init);
24
- };
17
+ g[stateWindowKey] = { [url]: resolvedData };
25
18
  }
26
19
  try {
27
- const { app: app1, router: router1 } = createAppForUrl(url);
28
- await router1.push(url);
29
- await router1.isReady();
30
- await renderToString(app1);
31
- await flushAsync();
32
- const { app: app2, router: router2 } = createAppForUrl(url);
33
- await router2.push(url);
34
- await router2.isReady();
35
- await flushAsync();
36
- const html = await renderToString(app2);
20
+ const { app, router } = createAppForUrl(url);
21
+ await router.push(url);
22
+ await router.isReady();
23
+ const html = await renderToString(app);
37
24
  const head = resolvedData != null ? `<script>window[${JSON.stringify(stateWindowKey)}]=${JSON.stringify({ [url]: resolvedData })};${"<"}/script>` : "";
38
25
  return { html, head };
39
26
  } finally {
40
- globalThis.fetch = originalFetch;
27
+ if (prevState !== void 0) {
28
+ g[stateWindowKey] = prevState;
29
+ } else {
30
+ delete g[stateWindowKey];
31
+ }
41
32
  }
42
33
  }
43
- async function flushAsync(ms = 50) {
44
- await Promise.resolve();
45
- await Promise.resolve();
46
- await new Promise((r) => setTimeout(r, ms));
47
- }
48
34
  exports.fetchCmsPrerenderPaths = prerender.fetchCmsPrerenderPaths;
49
35
  exports.polyfillBloxSsgGlobals = prerender.polyfillBloxSsgGlobals;
50
36
  exports.prerender = prerender.prerender;
51
- exports.BLOX_STATE_WINDOW_KEY = ssg_client.BLOX_STATE_WINDOW_KEY;
37
+ exports.BLOX_STATE_WINDOW_KEY = constants.BLOX_STATE_WINDOW_KEY;
52
38
  exports.installBloxStateCache = ssg_client.installBloxStateCache;
53
39
  exports.renderBloxSsgPage = renderBloxSsgPage;
@@ -1,5 +1,5 @@
1
1
  import { f, p, a } from "../prerender-DYmDaqcz.js";
2
- import { BLOX_STATE_WINDOW_KEY } from "./client.mjs";
2
+ import { B as BLOX_STATE_WINDOW_KEY } from "../constants-BIbQhd3z.js";
3
3
  import { installBloxStateCache } from "./client.mjs";
4
4
  async function renderBloxSsgPage(options) {
5
5
  const {
@@ -9,41 +9,26 @@ async function renderBloxSsgPage(options) {
9
9
  createAppForUrl,
10
10
  stateWindowKey = BLOX_STATE_WINDOW_KEY
11
11
  } = options;
12
- const originalFetch = globalThis.fetch;
12
+ const g = globalThis;
13
+ const prevState = g[stateWindowKey];
13
14
  if (resolvedData != null) {
14
- globalThis.fetch = async (input, init) => {
15
- const u = String(input);
16
- if (u.includes("resolve-path")) {
17
- return new Response(JSON.stringify(resolvedData), {
18
- status: 200,
19
- headers: { "Content-Type": "application/json" }
20
- });
21
- }
22
- return originalFetch(input, init);
23
- };
15
+ g[stateWindowKey] = { [url]: resolvedData };
24
16
  }
25
17
  try {
26
- const { app: app1, router: router1 } = createAppForUrl(url);
27
- await router1.push(url);
28
- await router1.isReady();
29
- await renderToString(app1);
30
- await flushAsync();
31
- const { app: app2, router: router2 } = createAppForUrl(url);
32
- await router2.push(url);
33
- await router2.isReady();
34
- await flushAsync();
35
- const html = await renderToString(app2);
18
+ const { app, router } = createAppForUrl(url);
19
+ await router.push(url);
20
+ await router.isReady();
21
+ const html = await renderToString(app);
36
22
  const head = resolvedData != null ? `<script>window[${JSON.stringify(stateWindowKey)}]=${JSON.stringify({ [url]: resolvedData })};${"<"}/script>` : "";
37
23
  return { html, head };
38
24
  } finally {
39
- globalThis.fetch = originalFetch;
25
+ if (prevState !== void 0) {
26
+ g[stateWindowKey] = prevState;
27
+ } else {
28
+ delete g[stateWindowKey];
29
+ }
40
30
  }
41
31
  }
42
- async function flushAsync(ms = 50) {
43
- await Promise.resolve();
44
- await Promise.resolve();
45
- await new Promise((r) => setTimeout(r, ms));
46
- }
47
32
  export {
48
33
  BLOX_STATE_WINDOW_KEY,
49
34
  f as fetchCmsPrerenderPaths,
@@ -5,8 +5,9 @@ export interface BloxSsgRouterLike {
5
5
  /**
6
6
  * Render a Blox CMS page to static HTML with embedded state.
7
7
  *
8
- * Uses a double-render + `fetch` mock strategy so that the async
9
- * `CmsPageView.load()` resolves before the final HTML is captured.
8
+ * Sets `globalThis.__BLOX_STATE__` *before* rendering so that
9
+ * `CmsPageView` can hydrate synchronously from the embedded data
10
+ * instead of waiting for an async fetch.
10
11
  *
11
12
  * Returns `{ html, head }` where `head` contains a `<script>` that sets
12
13
  * `window.__BLOX_STATE__` for zero-API-call client hydration.
@@ -1 +1 @@
1
- {"version":3,"file":"render-resolved-page.d.ts","sourceRoot":"","sources":["../../src/ssg/render-resolved-page.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE;IACtD,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,OAAO,GAAG,IAAI,CAAA;IAC5B,cAAc,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAC9C,eAAe,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK;QAAE,GAAG,EAAE,IAAI,CAAC;QAAC,MAAM,EAAE,iBAAiB,CAAA;KAAE,CAAA;IAC1E,cAAc,CAAC,EAAE,MAAM,CAAA;CACvB,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAwD3C"}
1
+ {"version":3,"file":"render-resolved-page.d.ts","sourceRoot":"","sources":["../../src/ssg/render-resolved-page.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5B;AAED;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE;IACtD,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,OAAO,GAAG,IAAI,CAAA;IAC5B,cAAc,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAC9C,eAAe,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK;QAAE,GAAG,EAAE,IAAI,CAAC;QAAC,MAAM,EAAE,iBAAiB,CAAA;KAAE,CAAA;IAC1E,cAAc,CAAC,EAAE,MAAM,CAAA;CACvB,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAqC3C"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/blox",
3
3
  "type": "module",
4
- "version": "1.12.20",
4
+ "version": "1.12.21",
5
5
  "description": "Blox page builder library for drag-and-drop page building and static data management",
6
6
  "author": {
7
7
  "name": "Bagel Studio",