@bagelink/blox 1.12.19 → 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.
- package/dist/CmsPageView.vue.d.ts.map +1 -1
- package/dist/constants-BIbQhd3z.js +4 -0
- package/dist/constants-fZvybj0k.cjs +3 -0
- package/dist/index.cjs +17 -1
- package/dist/index.mjs +17 -1
- package/dist/ssg/client.cjs +3 -3
- package/dist/ssg/client.mjs +1 -1
- package/dist/ssg/index.cjs +15 -23
- package/dist/ssg/index.mjs +13 -22
- package/dist/ssg/render-resolved-page.d.ts +3 -2
- package/dist/ssg/render-resolved-page.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CmsPageView.vue.d.ts","sourceRoot":"","sources":["../src/CmsPageView.vue"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"CmsPageView.vue.d.ts","sourceRoot":"","sources":["../src/CmsPageView.vue"],"names":[],"mappings":";AAkRA,wBAMG"}
|
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) ?? [];
|
package/dist/ssg/client.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
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;
|
package/dist/ssg/client.mjs
CHANGED
package/dist/ssg/index.cjs
CHANGED
|
@@ -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,40 +9,31 @@ async function renderBloxSsgPage(options) {
|
|
|
8
9
|
resolvedData,
|
|
9
10
|
renderToString,
|
|
10
11
|
createAppForUrl,
|
|
11
|
-
stateWindowKey =
|
|
12
|
+
stateWindowKey = constants.BLOX_STATE_WINDOW_KEY
|
|
12
13
|
} = options;
|
|
13
|
-
const
|
|
14
|
+
const g = globalThis;
|
|
15
|
+
const prevState = g[stateWindowKey];
|
|
14
16
|
if (resolvedData != null) {
|
|
15
|
-
|
|
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
|
|
28
|
-
await
|
|
29
|
-
await
|
|
30
|
-
await renderToString(
|
|
31
|
-
await new Promise((r) => setTimeout(r, 0));
|
|
32
|
-
const { app: app2, router: router2 } = createAppForUrl(url);
|
|
33
|
-
await router2.push(url);
|
|
34
|
-
await router2.isReady();
|
|
35
|
-
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);
|
|
36
24
|
const head = resolvedData != null ? `<script>window[${JSON.stringify(stateWindowKey)}]=${JSON.stringify({ [url]: resolvedData })};${"<"}/script>` : "";
|
|
37
25
|
return { html, head };
|
|
38
26
|
} finally {
|
|
39
|
-
|
|
27
|
+
if (prevState !== void 0) {
|
|
28
|
+
g[stateWindowKey] = prevState;
|
|
29
|
+
} else {
|
|
30
|
+
delete g[stateWindowKey];
|
|
31
|
+
}
|
|
40
32
|
}
|
|
41
33
|
}
|
|
42
34
|
exports.fetchCmsPrerenderPaths = prerender.fetchCmsPrerenderPaths;
|
|
43
35
|
exports.polyfillBloxSsgGlobals = prerender.polyfillBloxSsgGlobals;
|
|
44
36
|
exports.prerender = prerender.prerender;
|
|
45
|
-
exports.BLOX_STATE_WINDOW_KEY =
|
|
37
|
+
exports.BLOX_STATE_WINDOW_KEY = constants.BLOX_STATE_WINDOW_KEY;
|
|
46
38
|
exports.installBloxStateCache = ssg_client.installBloxStateCache;
|
|
47
39
|
exports.renderBloxSsgPage = renderBloxSsgPage;
|
package/dist/ssg/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { f, p, a } from "../prerender-DYmDaqcz.js";
|
|
2
|
-
import { BLOX_STATE_WINDOW_KEY } from "
|
|
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,33 +9,24 @@ async function renderBloxSsgPage(options) {
|
|
|
9
9
|
createAppForUrl,
|
|
10
10
|
stateWindowKey = BLOX_STATE_WINDOW_KEY
|
|
11
11
|
} = options;
|
|
12
|
-
const
|
|
12
|
+
const g = globalThis;
|
|
13
|
+
const prevState = g[stateWindowKey];
|
|
13
14
|
if (resolvedData != null) {
|
|
14
|
-
|
|
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
|
|
27
|
-
await
|
|
28
|
-
await
|
|
29
|
-
await renderToString(
|
|
30
|
-
await new Promise((r) => setTimeout(r, 0));
|
|
31
|
-
const { app: app2, router: router2 } = createAppForUrl(url);
|
|
32
|
-
await router2.push(url);
|
|
33
|
-
await router2.isReady();
|
|
34
|
-
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);
|
|
35
22
|
const head = resolvedData != null ? `<script>window[${JSON.stringify(stateWindowKey)}]=${JSON.stringify({ [url]: resolvedData })};${"<"}/script>` : "";
|
|
36
23
|
return { html, head };
|
|
37
24
|
} finally {
|
|
38
|
-
|
|
25
|
+
if (prevState !== void 0) {
|
|
26
|
+
g[stateWindowKey] = prevState;
|
|
27
|
+
} else {
|
|
28
|
+
delete g[stateWindowKey];
|
|
29
|
+
}
|
|
39
30
|
}
|
|
40
31
|
}
|
|
41
32
|
export {
|
|
@@ -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
|
-
*
|
|
9
|
-
* `CmsPageView
|
|
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
|
|
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