@bagelink/blox 1.12.20 → 1.12.22
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 +32 -3
- package/dist/index.mjs +32 -3
- package/dist/ssg/client.cjs +3 -3
- package/dist/ssg/client.mjs +1 -1
- package/dist/ssg/index.cjs +15 -29
- package/dist/ssg/index.mjs +13 -28
- 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":";AAgTA,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 = "";
|
|
@@ -120,17 +121,43 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
|
|
|
120
121
|
const blocks = vue.ref([]);
|
|
121
122
|
const contexts = vue.ref({});
|
|
122
123
|
vue.provide("contexts", contexts);
|
|
123
|
-
const loading = vue.ref(true);
|
|
124
124
|
const notFound = vue.ref(false);
|
|
125
125
|
const error = vue.ref(null);
|
|
126
|
+
function tryHydrateFromState(path) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
const win = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : void 0;
|
|
129
|
+
if (!win) return false;
|
|
130
|
+
const state = win[constants.BLOX_STATE_WINDOW_KEY];
|
|
131
|
+
if (!state || typeof state !== "object") return false;
|
|
132
|
+
const entry = state[path];
|
|
133
|
+
if (!entry) return false;
|
|
134
|
+
blocks.value = ((_b = (_a = entry.page) == null ? void 0 : _a.content) == null ? void 0 : _b.blocks) ?? [];
|
|
135
|
+
contexts.value = entry.contexts ?? {};
|
|
136
|
+
setAlternates(entry.alternates ?? {});
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
const initialSlug = (() => {
|
|
140
|
+
var _a;
|
|
141
|
+
if (strategy) {
|
|
142
|
+
const hostname = typeof window !== "undefined" ? ((_a = window.location) == null ? void 0 : _a.hostname) ?? "" : "";
|
|
143
|
+
return strategy.detect(hostname, route.path).slug;
|
|
144
|
+
}
|
|
145
|
+
return route.path || "/";
|
|
146
|
+
})();
|
|
147
|
+
const ssrHydrated = tryHydrateFromState(initialSlug);
|
|
148
|
+
const loading = vue.ref(!ssrHydrated);
|
|
126
149
|
async function load() {
|
|
127
150
|
var _a;
|
|
128
151
|
loading.value = true;
|
|
129
152
|
notFound.value = false;
|
|
130
153
|
error.value = null;
|
|
131
|
-
const { locale: urlLocale, slug } = strategy ? strategy.detect(window.location.hostname, route.path) : { locale: locale2.value, slug: route.path || "/" };
|
|
154
|
+
const { locale: urlLocale, slug } = strategy ? strategy.detect(typeof window !== "undefined" ? window.location.hostname : "", route.path) : { locale: locale2.value, slug: route.path || "/" };
|
|
132
155
|
if (urlLocale !== locale2.value) setLocale(urlLocale);
|
|
133
156
|
setAlternates({});
|
|
157
|
+
if (tryHydrateFromState(slug)) {
|
|
158
|
+
loading.value = false;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
134
161
|
try {
|
|
135
162
|
const resolved = await resolvePath(slug, urlLocale);
|
|
136
163
|
blocks.value = ((_a = resolved.page.content) == null ? void 0 : _a.blocks) ?? [];
|
|
@@ -148,7 +175,9 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
|
|
|
148
175
|
loading.value = false;
|
|
149
176
|
}
|
|
150
177
|
}
|
|
151
|
-
|
|
178
|
+
if (!ssrHydrated) {
|
|
179
|
+
load();
|
|
180
|
+
}
|
|
152
181
|
vue.watch(() => route.path, load);
|
|
153
182
|
return (_ctx, _cache) => {
|
|
154
183
|
const _component_RouterLink = vue.resolveComponent("RouterLink");
|
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 = "";
|
|
@@ -118,17 +119,43 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
118
119
|
const blocks = ref([]);
|
|
119
120
|
const contexts = ref({});
|
|
120
121
|
provide("contexts", contexts);
|
|
121
|
-
const loading = ref(true);
|
|
122
122
|
const notFound = ref(false);
|
|
123
123
|
const error = ref(null);
|
|
124
|
+
function tryHydrateFromState(path) {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
const win = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : void 0;
|
|
127
|
+
if (!win) return false;
|
|
128
|
+
const state = win[BLOX_STATE_WINDOW_KEY];
|
|
129
|
+
if (!state || typeof state !== "object") return false;
|
|
130
|
+
const entry = state[path];
|
|
131
|
+
if (!entry) return false;
|
|
132
|
+
blocks.value = ((_b = (_a = entry.page) == null ? void 0 : _a.content) == null ? void 0 : _b.blocks) ?? [];
|
|
133
|
+
contexts.value = entry.contexts ?? {};
|
|
134
|
+
setAlternates(entry.alternates ?? {});
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
const initialSlug = (() => {
|
|
138
|
+
var _a;
|
|
139
|
+
if (strategy) {
|
|
140
|
+
const hostname = typeof window !== "undefined" ? ((_a = window.location) == null ? void 0 : _a.hostname) ?? "" : "";
|
|
141
|
+
return strategy.detect(hostname, route.path).slug;
|
|
142
|
+
}
|
|
143
|
+
return route.path || "/";
|
|
144
|
+
})();
|
|
145
|
+
const ssrHydrated = tryHydrateFromState(initialSlug);
|
|
146
|
+
const loading = ref(!ssrHydrated);
|
|
124
147
|
async function load() {
|
|
125
148
|
var _a;
|
|
126
149
|
loading.value = true;
|
|
127
150
|
notFound.value = false;
|
|
128
151
|
error.value = null;
|
|
129
|
-
const { locale: urlLocale, slug } = strategy ? strategy.detect(window.location.hostname, route.path) : { locale: locale2.value, slug: route.path || "/" };
|
|
152
|
+
const { locale: urlLocale, slug } = strategy ? strategy.detect(typeof window !== "undefined" ? window.location.hostname : "", route.path) : { locale: locale2.value, slug: route.path || "/" };
|
|
130
153
|
if (urlLocale !== locale2.value) setLocale(urlLocale);
|
|
131
154
|
setAlternates({});
|
|
155
|
+
if (tryHydrateFromState(slug)) {
|
|
156
|
+
loading.value = false;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
132
159
|
try {
|
|
133
160
|
const resolved = await resolvePath(slug, urlLocale);
|
|
134
161
|
blocks.value = ((_a = resolved.page.content) == null ? void 0 : _a.blocks) ?? [];
|
|
@@ -146,7 +173,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
146
173
|
loading.value = false;
|
|
147
174
|
}
|
|
148
175
|
}
|
|
149
|
-
|
|
176
|
+
if (!ssrHydrated) {
|
|
177
|
+
load();
|
|
178
|
+
}
|
|
150
179
|
watch(() => route.path, load);
|
|
151
180
|
return (_ctx, _cache) => {
|
|
152
181
|
const _component_RouterLink = resolveComponent("RouterLink");
|
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,46 +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 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
|
-
|
|
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 =
|
|
37
|
+
exports.BLOX_STATE_WINDOW_KEY = constants.BLOX_STATE_WINDOW_KEY;
|
|
52
38
|
exports.installBloxStateCache = ssg_client.installBloxStateCache;
|
|
53
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,41 +9,26 @@ 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 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
|
-
|
|
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
|
-
*
|
|
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