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