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