@bagelink/blox 1.12.21 → 1.12.23
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/PreviewApp-C2T03Jm9.cjs +4 -0
- package/dist/PreviewApp-CmThrLvv.js +4 -0
- package/dist/PreviewApp.vue.d.ts.map +1 -1
- package/dist/PreviewApp.vue_vue_type_style_index_0_lang-B0N5QbfS.js +157 -0
- package/dist/PreviewApp.vue_vue_type_style_index_0_lang-BTuE4GmT.cjs +156 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/bridge.d.ts +1 -0
- package/dist/bridge.d.ts.map +1 -1
- package/dist/core-C3Iu5qa2.js +460 -0
- package/dist/core-_fnHoEZN.cjs +459 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/createBloxApp.d.ts +107 -0
- package/dist/createBloxApp.d.ts.map +1 -0
- package/dist/defineBlock.d.ts +2 -0
- package/dist/defineBlock.d.ts.map +1 -1
- package/dist/index.cjs +79 -572
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +78 -570
- package/dist/{prerender-6jE_obPj.cjs → prerender-Bi7YtzSp.cjs} +246 -6
- package/dist/prerender-D3Q4jKXm.js +522 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/ssg/cli.cjs +48 -5
- package/dist/ssg/cli.mjs +48 -5
- package/dist/ssg/client.cjs +50 -3
- package/dist/ssg/client.d.ts +2 -1
- package/dist/ssg/client.d.ts.map +1 -1
- package/dist/ssg/client.mjs +49 -2
- package/dist/ssg/cms-routes.d.ts +21 -4
- package/dist/ssg/cms-routes.d.ts.map +1 -1
- package/dist/ssg/collection-cache.d.ts +53 -0
- package/dist/ssg/collection-cache.d.ts.map +1 -0
- package/dist/ssg/constants.d.ts +4 -0
- package/dist/ssg/constants.d.ts.map +1 -1
- package/dist/ssg/createSSREntry.d.ts +73 -0
- package/dist/ssg/createSSREntry.d.ts.map +1 -0
- package/dist/ssg/index.cjs +138 -6
- package/dist/ssg/index.d.ts +10 -3
- package/dist/ssg/index.d.ts.map +1 -1
- package/dist/ssg/index.mjs +124 -12
- package/dist/ssg/prerender.d.ts +19 -1
- package/dist/ssg/prerender.d.ts.map +1 -1
- package/dist/ssg/render-resolved-page.d.ts +13 -3
- package/dist/ssg/render-resolved-page.d.ts.map +1 -1
- package/dist/ssg/seo.d.ts +66 -0
- package/dist/ssg/seo.d.ts.map +1 -0
- package/dist/style.css +20 -0
- package/dist/vite-plugin.cjs +142 -3
- package/dist/vite-plugin.d.ts +22 -21
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.mjs +142 -3
- package/package.json +4 -1
- package/dist/PreviewApp-BZNzZkit.js +0 -4
- package/dist/PreviewApp-C1WvJWI4.cjs +0 -4
- package/dist/constants-BIbQhd3z.js +0 -4
- package/dist/constants-fZvybj0k.cjs +0 -3
- package/dist/prerender-DYmDaqcz.js +0 -282
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAClE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAKnD,YAAY,EACX,cAAc,EACd,KAAK,EAEL,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,cAAc,EACd,QAAQ,EACR,eAAe,EACf,cAAc,EACd,WAAW,GACX,MAAM,aAAa,CAAA;AAIpB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACtD,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAI9E,OAAO,EAAE,OAAO,IAAI,WAAW,EAA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|
@@ -1,202 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
const BASE = "/api";
|
|
9
|
-
let _websiteName = "";
|
|
10
|
-
let _store = "";
|
|
11
|
-
let _websiteId = null;
|
|
12
|
-
function configureApi(websiteName, store) {
|
|
13
|
-
_websiteName = websiteName;
|
|
14
|
-
_store = store;
|
|
15
|
-
_websiteId = null;
|
|
16
|
-
}
|
|
17
|
-
async function request(path, { locale: locale2, params, ...opts } = {}) {
|
|
18
|
-
const url = new URL(`${BASE}${path}`, window.location.origin);
|
|
19
|
-
if (locale2) url.searchParams.set("locale", locale2);
|
|
20
|
-
if (params) {
|
|
21
|
-
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, String(v));
|
|
22
|
-
}
|
|
23
|
-
const res = await fetch(url.toString(), opts);
|
|
24
|
-
if (!res.ok) throw new Error(`API ${res.status}: ${path}`);
|
|
25
|
-
if (res.status === 204) return null;
|
|
26
|
-
return res.json();
|
|
27
|
-
}
|
|
28
|
-
async function getWebsiteId() {
|
|
29
|
-
if (_websiteId) return _websiteId;
|
|
30
|
-
const websites = await request("/cms/websites");
|
|
31
|
-
const website = websites.find((w) => w.name === _websiteName);
|
|
32
|
-
if (!website) throw new Error(`Website "${_websiteName}" not found. Run: npm run seed`);
|
|
33
|
-
_websiteId = website.id;
|
|
34
|
-
return _websiteId;
|
|
35
|
-
}
|
|
36
|
-
async function resolvePath(path, locale2) {
|
|
37
|
-
const websiteId = await getWebsiteId();
|
|
38
|
-
return request(`/cms/websites/${websiteId}/resolve-path`, {
|
|
39
|
-
locale: locale2,
|
|
40
|
-
params: { path }
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async function listItems(collection, { locale: locale2, q, offset = 0, limit = 100 } = {}) {
|
|
44
|
-
return request(`/datastore/${_store}/collections/${collection}`, {
|
|
45
|
-
locale: locale2,
|
|
46
|
-
params: { ...q ? { q } : {}, offset, limit }
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function sendToEditor(msg) {
|
|
50
|
-
window.parent.postMessage(msg, "*");
|
|
51
|
-
}
|
|
52
|
-
function sendToPreview(iframe, msg) {
|
|
53
|
-
var _a;
|
|
54
|
-
(_a = iframe.contentWindow) == null ? void 0 : _a.postMessage(msg, "*");
|
|
55
|
-
}
|
|
56
|
-
const locale = ref(localStorage.getItem("blox:locale") || "en");
|
|
57
|
-
const currentAlternates = ref({});
|
|
58
|
-
function useLocale() {
|
|
59
|
-
const dir = computed(() => locale.value === "he" || locale.value === "ar" ? "rtl" : "ltr");
|
|
60
|
-
function setLocale(l) {
|
|
61
|
-
locale.value = l;
|
|
62
|
-
localStorage.setItem("blox:locale", l);
|
|
63
|
-
document.documentElement.lang = l;
|
|
64
|
-
document.documentElement.dir = dir.value;
|
|
65
|
-
try {
|
|
66
|
-
const i18n = getI18n();
|
|
67
|
-
if (i18n == null ? void 0 : i18n.global) i18n.global.locale.value = l;
|
|
68
|
-
} catch {
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function setAlternates(alternates) {
|
|
72
|
-
currentAlternates.value = alternates;
|
|
73
|
-
}
|
|
74
|
-
return { locale, dir, setLocale, currentAlternates, setAlternates };
|
|
75
|
-
}
|
|
76
|
-
const BLOX_REGISTRY_KEY = Symbol("blox:registry");
|
|
77
|
-
const BLOX_CONFIG_KEY = Symbol("blox:config");
|
|
78
|
-
const BLOX_LOCALE_STRATEGY_KEY = Symbol("blox:locale-strategy");
|
|
79
|
-
const PageRenderer = defineComponent({
|
|
80
|
-
name: "PageRenderer",
|
|
81
|
-
props: {
|
|
82
|
-
blocks: {
|
|
83
|
-
type: Array,
|
|
84
|
-
default: () => []
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
setup(props) {
|
|
88
|
-
const registry = inject(BLOX_REGISTRY_KEY, {});
|
|
89
|
-
return () => h(
|
|
90
|
-
"div",
|
|
91
|
-
props.blocks.flatMap((block, i) => {
|
|
92
|
-
const definition = registry[block.type];
|
|
93
|
-
if (!definition) return [];
|
|
94
|
-
const props2 = { ...definition.schema.defaults, ...block.props };
|
|
95
|
-
return [h(definition.component, { key: i, ...props2 })];
|
|
96
|
-
})
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
const _hoisted_1$1 = {
|
|
101
|
-
key: 0,
|
|
102
|
-
class: "blox-loading"
|
|
103
|
-
};
|
|
104
|
-
const _hoisted_2 = {
|
|
105
|
-
key: 1,
|
|
106
|
-
class: "blox-not-found"
|
|
107
|
-
};
|
|
108
|
-
const _hoisted_3 = {
|
|
109
|
-
key: 2,
|
|
110
|
-
class: "blox-error"
|
|
111
|
-
};
|
|
112
|
-
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
113
|
-
__name: "CmsPageView",
|
|
114
|
-
setup(__props) {
|
|
115
|
-
const route = useRoute();
|
|
116
|
-
const router = useRouter();
|
|
117
|
-
const { locale: locale2, setLocale, setAlternates } = useLocale();
|
|
118
|
-
const strategy = inject(BLOX_LOCALE_STRATEGY_KEY, null);
|
|
119
|
-
const blocks = ref([]);
|
|
120
|
-
const contexts = ref({});
|
|
121
|
-
provide("contexts", contexts);
|
|
122
|
-
const loading = ref(true);
|
|
123
|
-
const notFound = ref(false);
|
|
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
|
-
}
|
|
139
|
-
async function load() {
|
|
140
|
-
var _a;
|
|
141
|
-
loading.value = true;
|
|
142
|
-
notFound.value = false;
|
|
143
|
-
error.value = null;
|
|
144
|
-
const { locale: urlLocale, slug } = strategy ? strategy.detect(typeof window !== "undefined" ? window.location.hostname : "", route.path) : { locale: locale2.value, slug: route.path || "/" };
|
|
145
|
-
if (urlLocale !== locale2.value) setLocale(urlLocale);
|
|
146
|
-
setAlternates({});
|
|
147
|
-
if (hydrateFromState(slug)) return;
|
|
148
|
-
try {
|
|
149
|
-
const resolved = await resolvePath(slug, urlLocale);
|
|
150
|
-
blocks.value = ((_a = resolved.page.content) == null ? void 0 : _a.blocks) ?? [];
|
|
151
|
-
contexts.value = resolved.contexts ?? {};
|
|
152
|
-
setAlternates(resolved.alternates ?? {});
|
|
153
|
-
} catch (e) {
|
|
154
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
155
|
-
if (msg.includes("404")) {
|
|
156
|
-
const home = strategy ? strategy.toPath("/") : "/";
|
|
157
|
-
router.replace(home);
|
|
158
|
-
} else {
|
|
159
|
-
error.value = msg;
|
|
160
|
-
}
|
|
161
|
-
} finally {
|
|
162
|
-
loading.value = false;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
load();
|
|
166
|
-
watch(() => route.path, load);
|
|
167
|
-
return (_ctx, _cache) => {
|
|
168
|
-
const _component_RouterLink = resolveComponent("RouterLink");
|
|
169
|
-
return openBlock(), createElementBlock("div", null, [
|
|
170
|
-
loading.value ? (openBlock(), createElementBlock("div", _hoisted_1$1, " Loading… ")) : notFound.value ? (openBlock(), createElementBlock("div", _hoisted_2, [
|
|
171
|
-
_cache[0] || (_cache[0] = createElementVNode("h2", null, "404", -1)),
|
|
172
|
-
createElementVNode("p", null, toDisplayString(unref(locale2) === "he" ? "הדף לא נמצא" : "Page not found"), 1),
|
|
173
|
-
createVNode(_component_RouterLink, { to: "/" }, {
|
|
174
|
-
default: withCtx(() => [
|
|
175
|
-
createTextVNode(toDisplayString(unref(locale2) === "he" ? "חזרה הביתה" : "Go home"), 1)
|
|
176
|
-
]),
|
|
177
|
-
_: 1
|
|
178
|
-
})
|
|
179
|
-
])) : error.value ? (openBlock(), createElementBlock("div", _hoisted_3, toDisplayString(error.value), 1)) : (openBlock(), createBlock(unref(PageRenderer), {
|
|
180
|
-
key: 3,
|
|
181
|
-
blocks: blocks.value
|
|
182
|
-
}, null, 8, ["blocks"]))
|
|
183
|
-
]);
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
});
|
|
1
|
+
import { B as BLOX_LOCALE_STRATEGY_KEY, u as useLocale, c as createBlox } from "./core-C3Iu5qa2.js";
|
|
2
|
+
import { d, b, _, P, a, l, r } from "./core-C3Iu5qa2.js";
|
|
3
|
+
import { _ as _2, P as P2, s, a as a2 } from "./PreviewApp.vue_vue_type_style_index_0_lang-B0N5QbfS.js";
|
|
4
|
+
import { inject, computed, createApp, markRaw } from "vue";
|
|
5
|
+
import { useRouter } from "vue-router";
|
|
6
|
+
import { createPinia } from "pinia";
|
|
7
|
+
import { installBloxStateCache, installCollectionCache } from "./ssg/client.mjs";
|
|
187
8
|
function useLocaleNav() {
|
|
188
9
|
const strategy = inject(BLOX_LOCALE_STRATEGY_KEY, null);
|
|
189
10
|
const router = useRouter();
|
|
190
|
-
const { locale
|
|
11
|
+
const { locale, currentAlternates } = useLocale();
|
|
191
12
|
function switchLocale(targetLocale) {
|
|
192
13
|
if (!strategy) return;
|
|
193
|
-
const alternateSlug =
|
|
14
|
+
const alternateSlug = currentAlternates.value[targetLocale];
|
|
194
15
|
strategy.switchTo(targetLocale, alternateSlug ?? "/", router);
|
|
195
16
|
}
|
|
196
17
|
function toPath(slug) {
|
|
197
18
|
return strategy ? strategy.toPath(slug) : slug;
|
|
198
19
|
}
|
|
199
|
-
return { switchLocale, toPath, locale
|
|
20
|
+
return { switchLocale, toPath, locale };
|
|
200
21
|
}
|
|
201
22
|
function usePageContext(key) {
|
|
202
23
|
const contexts = inject("contexts");
|
|
@@ -206,397 +27,84 @@ function usePageContext(key) {
|
|
|
206
27
|
return value;
|
|
207
28
|
});
|
|
208
29
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
get currentLocale() {
|
|
243
|
-
return _currentLocale;
|
|
244
|
-
},
|
|
245
|
-
detect(_hostname, path) {
|
|
246
|
-
const segments = path.replace(/^\//, "").split("/");
|
|
247
|
-
const first = segments[0];
|
|
248
|
-
if (supportedLocales.includes(first)) {
|
|
249
|
-
_currentLocale = first;
|
|
250
|
-
return {
|
|
251
|
-
locale: first,
|
|
252
|
-
slug: `/${segments.slice(1).join("/")}` || "/"
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
_currentLocale = defaultLocale;
|
|
256
|
-
return { locale: defaultLocale, slug: path || "/" };
|
|
257
|
-
},
|
|
258
|
-
toPath(slug) {
|
|
259
|
-
if (_currentLocale === defaultLocale) return slug || "/";
|
|
260
|
-
const s = slug || "/";
|
|
261
|
-
return s === "/" ? `/${_currentLocale}` : `/${_currentLocale}${s}`;
|
|
262
|
-
},
|
|
263
|
-
switchTo(locale2, slug, router) {
|
|
264
|
-
const s = slug || "/";
|
|
265
|
-
const target = locale2 === defaultLocale ? s : s === "/" ? `/${locale2}` : `/${locale2}${s}`;
|
|
266
|
-
router.push(target);
|
|
267
|
-
}
|
|
30
|
+
function createBloxApp(options) {
|
|
31
|
+
const {
|
|
32
|
+
rootComponent,
|
|
33
|
+
router,
|
|
34
|
+
modules,
|
|
35
|
+
websiteName,
|
|
36
|
+
store,
|
|
37
|
+
locale = "en",
|
|
38
|
+
supportedLocales = [locale],
|
|
39
|
+
apiBaseURL = "/api",
|
|
40
|
+
mount: mountTarget = "#app",
|
|
41
|
+
plugins = [],
|
|
42
|
+
globalComponents = {},
|
|
43
|
+
setup: userSetup
|
|
44
|
+
} = options;
|
|
45
|
+
installBloxStateCache();
|
|
46
|
+
let axiosInstance;
|
|
47
|
+
if (options.createApi) {
|
|
48
|
+
const result = options.createApi({ baseURL: apiBaseURL });
|
|
49
|
+
axiosInstance = result.axios;
|
|
50
|
+
}
|
|
51
|
+
const collectionInterceptor = installCollectionCache();
|
|
52
|
+
if (collectionInterceptor && axiosInstance) {
|
|
53
|
+
axiosInstance.interceptors.request.use(collectionInterceptor);
|
|
54
|
+
}
|
|
55
|
+
const app = createApp(rootComponent);
|
|
56
|
+
const bloxOpts = {
|
|
57
|
+
modules,
|
|
58
|
+
websiteName,
|
|
59
|
+
store,
|
|
60
|
+
defaultLocale: locale,
|
|
61
|
+
supportedLocales,
|
|
62
|
+
router
|
|
268
63
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const _currentLocale = locales.find((l) => localeDomains[l] === window.location.hostname) ?? locales[0] ?? "en";
|
|
274
|
-
return {
|
|
275
|
-
get locales() {
|
|
276
|
-
return locales;
|
|
277
|
-
},
|
|
278
|
-
get currentLocale() {
|
|
279
|
-
return _currentLocale;
|
|
280
|
-
},
|
|
281
|
-
detect(_hostname, path) {
|
|
282
|
-
return { locale: _currentLocale, slug: path || "/" };
|
|
283
|
-
},
|
|
284
|
-
toPath(slug) {
|
|
285
|
-
return slug || "/";
|
|
286
|
-
},
|
|
287
|
-
switchTo(locale2, slug, _router) {
|
|
288
|
-
const domain = localeDomains[locale2];
|
|
289
|
-
if (!domain) return;
|
|
290
|
-
if (locale2 === _currentLocale) {
|
|
291
|
-
_router.push(slug || "/");
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
const { protocol } = window.location;
|
|
295
|
-
const s = slug || "/";
|
|
296
|
-
window.location.href = `${protocol}//${domain}${s}`;
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
function createLocaleStrategy(options) {
|
|
301
|
-
if (options.localeStrategy === "domain" && options.localeDomains) {
|
|
302
|
-
return createDomainStrategy({ localeDomains: options.localeDomains });
|
|
303
|
-
}
|
|
304
|
-
return createPathStrategy({
|
|
305
|
-
defaultLocale: options.defaultLocale ?? "en",
|
|
306
|
-
supportedLocales: options.supportedLocales ?? []
|
|
64
|
+
const blox = createBlox(bloxOpts);
|
|
65
|
+
const pinia = createPinia();
|
|
66
|
+
pinia.use(({ store: s2 }) => {
|
|
67
|
+
s2.router = markRaw(router);
|
|
307
68
|
});
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
supportedLocales: (options == null ? void 0 : options.supportedLocales) ?? []
|
|
328
|
-
};
|
|
329
|
-
this._strategy = createLocaleStrategy(options ?? {});
|
|
330
|
-
}
|
|
331
|
-
registerModules(modules) {
|
|
332
|
-
const list = Array.isArray(modules) ? modules : Object.values(modules);
|
|
333
|
-
for (const mod of list) {
|
|
334
|
-
if (!(mod == null ? void 0 : mod.default)) continue;
|
|
335
|
-
for (const [key, value] of Object.entries(mod)) {
|
|
336
|
-
if (key === "default") continue;
|
|
337
|
-
if (value && typeof value === "object" && "label" in value) {
|
|
338
|
-
const meta = value;
|
|
339
|
-
applyDefaultsToFields(meta.schema, meta.defaults);
|
|
340
|
-
this._registry[meta.name ?? key] = {
|
|
341
|
-
component: mod.default,
|
|
342
|
-
schema: {
|
|
343
|
-
label: meta.label,
|
|
344
|
-
description: meta.description,
|
|
345
|
-
icon: meta.icon,
|
|
346
|
-
fields: meta.schema,
|
|
347
|
-
defaults: meta.defaults
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
return this;
|
|
355
|
-
}
|
|
356
|
-
registerComponents(components) {
|
|
357
|
-
for (const [key, value] of Object.entries(components)) {
|
|
358
|
-
if (!value || typeof value !== "object" && typeof value !== "function") continue;
|
|
359
|
-
if (isBlockDefinition(value)) {
|
|
360
|
-
this._registry[key] = value;
|
|
361
|
-
} else if (value.__blox) {
|
|
362
|
-
const meta = value.__blox;
|
|
363
|
-
applyDefaultsToFields(meta.schema, meta.defaults);
|
|
364
|
-
this._registry[meta.name ?? key] = {
|
|
365
|
-
component: value,
|
|
366
|
-
schema: {
|
|
367
|
-
label: meta.label,
|
|
368
|
-
description: meta.description,
|
|
369
|
-
icon: meta.icon,
|
|
370
|
-
fields: meta.schema,
|
|
371
|
-
defaults: meta.defaults
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return this;
|
|
377
|
-
}
|
|
378
|
-
registerRoutes(router) {
|
|
379
|
-
if (this._routeRegistered) return this;
|
|
380
|
-
if (this._config.supportedLocales.length > 0) {
|
|
381
|
-
const { defaultLocale } = this._config;
|
|
382
|
-
router.beforeEach((to) => {
|
|
383
|
-
const segments = to.path.replace(/^\//, "").split("/");
|
|
384
|
-
if (segments[0] === defaultLocale) {
|
|
385
|
-
const rest = segments.slice(1).join("/");
|
|
386
|
-
return { path: `/${rest}`, replace: true };
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
router.addRoute({
|
|
391
|
-
path: "/_blox_preview",
|
|
392
|
-
component: () => import("./PreviewApp-BZNzZkit.js"),
|
|
393
|
-
beforeEnter: () => window.parent !== window ? true : "/"
|
|
394
|
-
});
|
|
395
|
-
router.addRoute({ path: "/:pathMatch(.*)*", component: _sfc_main$2 });
|
|
396
|
-
this._routeRegistered = true;
|
|
397
|
-
return this;
|
|
398
|
-
}
|
|
399
|
-
install(app, options) {
|
|
400
|
-
if (options) {
|
|
401
|
-
this._config = {
|
|
402
|
-
defaultLocale: options.defaultLocale ?? this._config.defaultLocale,
|
|
403
|
-
supportedLocales: options.supportedLocales ?? this._config.supportedLocales
|
|
404
|
-
};
|
|
405
|
-
this._strategy = createLocaleStrategy({
|
|
406
|
-
...options,
|
|
407
|
-
defaultLocale: this._config.defaultLocale,
|
|
408
|
-
supportedLocales: this._config.supportedLocales
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
if (options == null ? void 0 : options.modules) this.registerModules(options.modules);
|
|
412
|
-
if (options == null ? void 0 : options.components) this.registerComponents(options.components);
|
|
413
|
-
if (options == null ? void 0 : options.router) this.registerRoutes(options.router);
|
|
414
|
-
if ((options == null ? void 0 : options.websiteName) || (options == null ? void 0 : options.store)) {
|
|
415
|
-
configureApi(options.websiteName ?? "", options.store ?? "");
|
|
416
|
-
}
|
|
417
|
-
if (options == null ? void 0 : options.defaultLocale) {
|
|
418
|
-
const { setLocale } = useLocale();
|
|
419
|
-
if (!localStorage.getItem("blox:locale")) setLocale(options.defaultLocale);
|
|
420
|
-
}
|
|
421
|
-
app.provide(BLOX_REGISTRY_KEY, this._registry);
|
|
422
|
-
app.provide(BLOX_CONFIG_KEY, this._config);
|
|
423
|
-
app.provide(BLOX_LOCALE_STRATEGY_KEY, this._strategy);
|
|
424
|
-
app.component("RouterLink", _sfc_main$1);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
function isBlockDefinition(value) {
|
|
428
|
-
return typeof value === "object" && "component" in value && "schema" in value;
|
|
429
|
-
}
|
|
430
|
-
function createBlox(options) {
|
|
431
|
-
const instance = new BloxInstance(options);
|
|
432
|
-
if ((options == null ? void 0 : options.websiteName) || (options == null ? void 0 : options.store)) {
|
|
433
|
-
configureApi(options.websiteName ?? "", options.store ?? "");
|
|
434
|
-
}
|
|
435
|
-
if (options == null ? void 0 : options.modules) instance.registerModules(options.modules);
|
|
436
|
-
if (options == null ? void 0 : options.components) instance.registerComponents(options.components);
|
|
437
|
-
if (options == null ? void 0 : options.router) instance.registerRoutes(options.router);
|
|
438
|
-
return instance;
|
|
69
|
+
blox.install(app, {});
|
|
70
|
+
app.use(pinia);
|
|
71
|
+
app.use(router);
|
|
72
|
+
for (const plugin of plugins) {
|
|
73
|
+
if (Array.isArray(plugin)) {
|
|
74
|
+
const [p, ...args] = plugin;
|
|
75
|
+
app.use(p, ...args);
|
|
76
|
+
} else {
|
|
77
|
+
app.use(plugin);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const [name, comp] of Object.entries(globalComponents)) {
|
|
81
|
+
app.component(name, comp);
|
|
82
|
+
}
|
|
83
|
+
if (userSetup) userSetup(app);
|
|
84
|
+
router.isReady().then(() => {
|
|
85
|
+
app.mount(mountTarget);
|
|
86
|
+
});
|
|
87
|
+
return { app, router, blox };
|
|
439
88
|
}
|
|
440
89
|
function defineBlock(meta) {
|
|
441
90
|
return meta;
|
|
442
91
|
}
|
|
443
|
-
const PreviewRenderer = defineComponent({
|
|
444
|
-
name: "PreviewRenderer",
|
|
445
|
-
props: {
|
|
446
|
-
blocks: {
|
|
447
|
-
type: Array,
|
|
448
|
-
default: () => []
|
|
449
|
-
},
|
|
450
|
-
selectedIndex: {
|
|
451
|
-
type: Number,
|
|
452
|
-
default: null
|
|
453
|
-
},
|
|
454
|
-
hoveredIndex: {
|
|
455
|
-
type: Number,
|
|
456
|
-
default: null
|
|
457
|
-
}
|
|
458
|
-
},
|
|
459
|
-
setup(props) {
|
|
460
|
-
const registry = inject(BLOX_REGISTRY_KEY, {});
|
|
461
|
-
const localHovered = ref(null);
|
|
462
|
-
function onBlockClick(index) {
|
|
463
|
-
sendToEditor({ type: "BLOX_BLOCK_CLICK", index });
|
|
464
|
-
}
|
|
465
|
-
function onBlockEnter(index) {
|
|
466
|
-
localHovered.value = index;
|
|
467
|
-
sendToEditor({ type: "BLOX_BLOCK_HOVER", index });
|
|
468
|
-
}
|
|
469
|
-
function onBlockLeave() {
|
|
470
|
-
localHovered.value = null;
|
|
471
|
-
sendToEditor({ type: "BLOX_BLOCK_HOVER", index: null });
|
|
472
|
-
}
|
|
473
|
-
return () => h(
|
|
474
|
-
"div",
|
|
475
|
-
{ class: "blox-preview-canvas" },
|
|
476
|
-
props.blocks.flatMap((block, i) => {
|
|
477
|
-
const definition = registry[block.type];
|
|
478
|
-
if (!definition) return [];
|
|
479
|
-
const isSelected = props.selectedIndex === i;
|
|
480
|
-
const isHovered = (props.hoveredIndex === i || localHovered.value === i) && !isSelected;
|
|
481
|
-
const { label } = definition.schema;
|
|
482
|
-
return [
|
|
483
|
-
h(
|
|
484
|
-
"div",
|
|
485
|
-
{
|
|
486
|
-
"key": i,
|
|
487
|
-
"data-blox-index": i,
|
|
488
|
-
"class": [
|
|
489
|
-
"blox-block-wrapper",
|
|
490
|
-
isSelected && "blox-block--selected",
|
|
491
|
-
isHovered && "blox-block--hovered"
|
|
492
|
-
],
|
|
493
|
-
"onClick": () => {
|
|
494
|
-
onBlockClick(i);
|
|
495
|
-
},
|
|
496
|
-
"onMouseenter": () => {
|
|
497
|
-
onBlockEnter(i);
|
|
498
|
-
},
|
|
499
|
-
"onMouseleave": onBlockLeave
|
|
500
|
-
},
|
|
501
|
-
[
|
|
502
|
-
h(definition.component, { ...definition.schema.defaults, ...block.props }),
|
|
503
|
-
h("div", { class: "blox-block-overlay" }),
|
|
504
|
-
(isSelected || isHovered) && h(
|
|
505
|
-
"div",
|
|
506
|
-
{
|
|
507
|
-
class: ["blox-block-label", isSelected && "blox-block-label--selected"]
|
|
508
|
-
},
|
|
509
|
-
label
|
|
510
|
-
)
|
|
511
|
-
]
|
|
512
|
-
)
|
|
513
|
-
];
|
|
514
|
-
})
|
|
515
|
-
);
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
const _hoisted_1 = { class: "blox-preview-root" };
|
|
519
|
-
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
520
|
-
__name: "PreviewApp",
|
|
521
|
-
setup(__props) {
|
|
522
|
-
const registry = inject(BLOX_REGISTRY_KEY, {});
|
|
523
|
-
const { setLocale } = useLocale();
|
|
524
|
-
const blocks = ref([]);
|
|
525
|
-
const contexts = ref({});
|
|
526
|
-
const selectedIndex = ref(null);
|
|
527
|
-
const hoveredIndex = ref(null);
|
|
528
|
-
provide("contexts", contexts);
|
|
529
|
-
let heightObserver = null;
|
|
530
|
-
function onMessage(event) {
|
|
531
|
-
var _a;
|
|
532
|
-
const msg = event.data;
|
|
533
|
-
switch (msg.type) {
|
|
534
|
-
case "BLOX_INIT":
|
|
535
|
-
blocks.value = ((_a = msg.page.page.content) == null ? void 0 : _a.blocks) ?? [];
|
|
536
|
-
contexts.value = msg.page.contexts ?? {};
|
|
537
|
-
setLocale(msg.locale);
|
|
538
|
-
break;
|
|
539
|
-
case "BLOX_SET_LOCALE":
|
|
540
|
-
setLocale(msg.locale);
|
|
541
|
-
break;
|
|
542
|
-
case "BLOX_SET_BLOCKS":
|
|
543
|
-
blocks.value = msg.blocks;
|
|
544
|
-
break;
|
|
545
|
-
case "BLOX_SELECT_BLOCK":
|
|
546
|
-
selectedIndex.value = msg.index;
|
|
547
|
-
if (msg.index !== null) {
|
|
548
|
-
nextTick(() => {
|
|
549
|
-
const el = document.querySelector(`[data-blox-index="${msg.index}"]`);
|
|
550
|
-
el == null ? void 0 : el.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
break;
|
|
554
|
-
case "BLOX_HOVER_BLOCK":
|
|
555
|
-
hoveredIndex.value = msg.index;
|
|
556
|
-
break;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
onMounted(() => {
|
|
560
|
-
window.addEventListener("message", onMessage);
|
|
561
|
-
heightObserver = new ResizeObserver(() => {
|
|
562
|
-
sendToEditor({ type: "BLOX_HEIGHT", height: document.body.scrollHeight });
|
|
563
|
-
});
|
|
564
|
-
heightObserver.observe(document.body);
|
|
565
|
-
sendToEditor({
|
|
566
|
-
type: "BLOX_READY",
|
|
567
|
-
registry: Object.fromEntries(Object.entries(registry).map(([key, def]) => [key, def.schema]))
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
onUnmounted(() => {
|
|
571
|
-
window.removeEventListener("message", onMessage);
|
|
572
|
-
heightObserver == null ? void 0 : heightObserver.disconnect();
|
|
573
|
-
});
|
|
574
|
-
return (_ctx, _cache) => {
|
|
575
|
-
return openBlock(), createElementBlock("div", _hoisted_1, [
|
|
576
|
-
createVNode(unref(PreviewRenderer), {
|
|
577
|
-
blocks: blocks.value,
|
|
578
|
-
"selected-index": selectedIndex.value,
|
|
579
|
-
"hovered-index": hoveredIndex.value
|
|
580
|
-
}, null, 8, ["blocks", "selected-index", "hovered-index"])
|
|
581
|
-
]);
|
|
582
|
-
};
|
|
583
|
-
}
|
|
584
|
-
});
|
|
585
92
|
export {
|
|
586
|
-
BLOX_CONFIG_KEY,
|
|
93
|
+
d as BLOX_CONFIG_KEY,
|
|
587
94
|
BLOX_LOCALE_STRATEGY_KEY,
|
|
588
|
-
BloxInstance,
|
|
589
|
-
|
|
590
|
-
PageRenderer,
|
|
591
|
-
|
|
592
|
-
PreviewRenderer,
|
|
593
|
-
configureApi,
|
|
95
|
+
b as BloxInstance,
|
|
96
|
+
_ as CmsPageView,
|
|
97
|
+
P as PageRenderer,
|
|
98
|
+
_2 as PreviewApp,
|
|
99
|
+
P2 as PreviewRenderer,
|
|
100
|
+
a as configureApi,
|
|
594
101
|
createBlox,
|
|
102
|
+
createBloxApp,
|
|
595
103
|
defineBlock,
|
|
596
|
-
listItems,
|
|
597
|
-
resolvePath,
|
|
598
|
-
sendToEditor,
|
|
599
|
-
sendToPreview,
|
|
104
|
+
l as listItems,
|
|
105
|
+
r as resolvePath,
|
|
106
|
+
s as sendToEditor,
|
|
107
|
+
a2 as sendToPreview,
|
|
600
108
|
useLocale,
|
|
601
109
|
useLocaleNav,
|
|
602
110
|
usePageContext
|