@bagelink/blox 1.15.174 → 1.15.178

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 (47) hide show
  1. package/dist/{PreviewApp-Dz003khp.cjs → PreviewApp-B8EmNfyH.cjs} +1 -1
  2. package/dist/{PreviewApp-CsC6qej1.js → PreviewApp-DdkAQqw2.js} +1 -1
  3. package/dist/{PreviewApp.vue_vue_type_style_index_0_lang-C1SwhjdY.js → PreviewApp.vue_vue_type_style_index_0_lang-1JKQVLm2.js} +1 -1
  4. package/dist/{PreviewApp.vue_vue_type_style_index_0_lang-BNKK7Vhs.cjs → PreviewApp.vue_vue_type_style_index_0_lang-CPBuld3j.cjs} +1 -1
  5. package/dist/components/BloxRouterView.vue.d.ts +18 -0
  6. package/dist/components/BloxRouterView.vue.d.ts.map +1 -0
  7. package/dist/composables/useData.d.ts +22 -0
  8. package/dist/composables/useData.d.ts.map +1 -0
  9. package/dist/composables/useLocaleNav.d.ts +8 -0
  10. package/dist/composables/useLocaleNav.d.ts.map +1 -1
  11. package/dist/composables/useSeo.d.ts +20 -0
  12. package/dist/composables/useSeo.d.ts.map +1 -0
  13. package/dist/content/ContentDetailHost.vue.d.ts +3 -0
  14. package/dist/content/ContentDetailHost.vue.d.ts.map +1 -0
  15. package/dist/content/defineContent.d.ts +22 -0
  16. package/dist/content/defineContent.d.ts.map +1 -0
  17. package/dist/content/useContentItem.d.ts +6 -0
  18. package/dist/content/useContentItem.d.ts.map +1 -0
  19. package/dist/content/useContentSeo.d.ts +10 -0
  20. package/dist/content/useContentSeo.d.ts.map +1 -0
  21. package/dist/{core-CbOrSpOU.js → core-Bp2bf8e4.js} +187 -33
  22. package/dist/{core-fPjj9xyJ.cjs → core-KRHc4Bob.cjs} +171 -17
  23. package/dist/core.d.ts.map +1 -1
  24. package/dist/index.cjs +121 -4
  25. package/dist/index.d.ts +12 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.mjs +141 -23
  28. package/dist/{prerender-BLECK5o5.cjs → prerender-H72-UrK4.cjs} +11 -11
  29. package/dist/{prerender-CzpA4sYd.js → prerender-NHAqrTm3.js} +11 -11
  30. package/dist/routing/withLocaleRoutes.d.ts +8 -0
  31. package/dist/routing/withLocaleRoutes.d.ts.map +1 -0
  32. package/dist/ssg/cli.cjs +1 -1
  33. package/dist/ssg/cli.mjs +1 -1
  34. package/dist/ssg/client.cjs +4 -0
  35. package/dist/ssg/client.d.ts +1 -1
  36. package/dist/ssg/client.d.ts.map +1 -1
  37. package/dist/ssg/client.mjs +4 -0
  38. package/dist/ssg/constants.d.ts +4 -0
  39. package/dist/ssg/constants.d.ts.map +1 -1
  40. package/dist/ssg/index.cjs +18 -3
  41. package/dist/ssg/index.d.ts +1 -1
  42. package/dist/ssg/index.d.ts.map +1 -1
  43. package/dist/ssg/index.mjs +20 -5
  44. package/dist/ssg/render-resolved-page.d.ts.map +1 -1
  45. package/dist/ssg/seo.d.ts +7 -0
  46. package/dist/ssg/seo.d.ts.map +1 -1
  47. package/package.json +1 -1
@@ -116,11 +116,11 @@ function useBloxEdit(configOverride) {
116
116
  }
117
117
  return { config, enabled, showEdit, studioBaseUrl, editUrl, enable, dismiss, init };
118
118
  }
119
- const _hoisted_1$2 = {
119
+ const _hoisted_1$3 = {
120
120
  key: 0,
121
121
  class: "blox-admin-bar"
122
122
  };
123
- const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
123
+ const _sfc_main$3 = /* @__PURE__ */ vue.defineComponent({
124
124
  __name: "AdminEditBar",
125
125
  props: {
126
126
  websiteId: {},
@@ -139,7 +139,7 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
139
139
  key: 0,
140
140
  to: "body"
141
141
  }, [
142
- vue.unref(showEdit) && __props.websiteId && __props.pageId ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$2, [
142
+ vue.unref(showEdit) && __props.websiteId && __props.pageId ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$3, [
143
143
  vue.createElementVNode("button", {
144
144
  type: "button",
145
145
  class: "blox-admin-btn",
@@ -261,11 +261,11 @@ const PageRenderer = vue.defineComponent({
261
261
  }
262
262
  },
263
263
  setup(props) {
264
- const registry = vue.inject(BLOX_REGISTRY_KEY, {});
264
+ const registry2 = vue.inject(BLOX_REGISTRY_KEY, {});
265
265
  return () => vue.h(
266
266
  "div",
267
267
  props.blocks.flatMap((block, i) => {
268
- const definition = registry[block.type];
268
+ const definition = registry2[block.type];
269
269
  if (!definition) return [];
270
270
  const ref = globalRefOf(block);
271
271
  if (ref) {
@@ -284,7 +284,7 @@ const PageRenderer = vue.defineComponent({
284
284
  );
285
285
  }
286
286
  });
287
- const _hoisted_1$1 = {
287
+ const _hoisted_1$2 = {
288
288
  key: 0,
289
289
  class: "blox-loading flex column h-100vh justify-content-center"
290
290
  };
@@ -300,7 +300,7 @@ const _hoisted_4 = {
300
300
  key: 0,
301
301
  class: "blox-nav-progress"
302
302
  };
303
- const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
303
+ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
304
304
  __name: "CmsPageView",
305
305
  setup(__props) {
306
306
  const route = vueRouter.useRoute();
@@ -400,7 +400,7 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
400
400
  return (_ctx, _cache) => {
401
401
  const _component_RouterLink = vue.resolveComponent("RouterLink");
402
402
  return vue.openBlock(), vue.createElementBlock("div", null, [
403
- initialLoading.value && blocks.value.length === 0 ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1, [
403
+ initialLoading.value && blocks.value.length === 0 ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$2, [
404
404
  vue.createVNode(vue.unref(vue$1.Loading))
405
405
  ])) : notFound.value ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$1, [
406
406
  _cache[0] || (_cache[0] = vue.createElementVNode("h2", null, "404", -1)),
@@ -415,7 +415,7 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
415
415
  navigating.value ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4)) : vue.createCommentVNode("", true),
416
416
  vue.createVNode(vue.unref(PageRenderer), { blocks: blocks.value }, null, 8, ["blocks"])
417
417
  ], 64)),
418
- vue.unref(adminConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$2, {
418
+ vue.unref(adminConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$3, {
419
419
  key: 4,
420
420
  "website-id": websiteId.value,
421
421
  "page-id": currentPageId.value
@@ -510,9 +510,80 @@ function installSmartLinks(router) {
510
510
  document.addEventListener("click", onClick);
511
511
  return () => document.removeEventListener("click", onClick);
512
512
  }
513
- const _hoisted_1 = ["href"];
513
+ function isServer() {
514
+ try {
515
+ if (false) ;
516
+ } catch {
517
+ }
518
+ return typeof window === "undefined";
519
+ }
520
+ function readPayload() {
521
+ const root = typeof window !== "undefined" ? window : globalThis;
522
+ const existing = root[ssg_client.BLOX_DATA_WINDOW_KEY];
523
+ if (existing && typeof existing === "object" && !Array.isArray(existing)) {
524
+ return existing;
525
+ }
526
+ const fresh = {};
527
+ root[ssg_client.BLOX_DATA_WINDOW_KEY] = fresh;
528
+ return fresh;
529
+ }
530
+ function resolveDefault(opts) {
531
+ if (typeof opts.default === "function") return opts.default();
532
+ return opts.default;
533
+ }
534
+ function useData(key, handler, opts = {}) {
535
+ const data = vue.ref(resolveDefault(opts));
536
+ const pending = vue.ref(false);
537
+ const error = vue.ref(null);
538
+ async function refresh() {
539
+ const k = vue.toValue(key);
540
+ pending.value = true;
541
+ error.value = null;
542
+ try {
543
+ const result = await handler();
544
+ data.value = result;
545
+ readPayload()[k] = result;
546
+ } catch (e) {
547
+ error.value = e instanceof Error ? e : new Error(String(e));
548
+ } finally {
549
+ pending.value = false;
550
+ }
551
+ }
552
+ function hydrateFromPayload() {
553
+ const k = vue.toValue(key);
554
+ const payload = readPayload();
555
+ if (!Object.prototype.hasOwnProperty.call(payload, k)) return false;
556
+ data.value = payload[k];
557
+ return true;
558
+ }
559
+ if (isServer()) {
560
+ vue.onServerPrefetch(() => refresh());
561
+ } else if (!hydrateFromPayload()) {
562
+ void refresh();
563
+ }
564
+ vue.watch(() => vue.toValue(key), () => {
565
+ if (!hydrateFromPayload()) void refresh();
566
+ });
567
+ return { data, pending, error, refresh };
568
+ }
569
+ function withLocaleRoutes(path, component, locales, defaultLocale) {
570
+ const normalized = path.startsWith("/") ? path : `/${path}`;
571
+ const others = locales.filter((l) => l && l !== defaultLocale);
572
+ const localePattern = others.join("|");
573
+ const routes = [
574
+ { path: normalized, component }
575
+ ];
576
+ if (localePattern) {
577
+ routes.push({
578
+ path: `/:locale(${localePattern})${normalized}`,
579
+ component
580
+ });
581
+ }
582
+ return routes;
583
+ }
584
+ const _hoisted_1$1 = ["href"];
514
585
  const _hoisted_2 = ["href"];
515
- const _sfc_main = /* @__PURE__ */ vue.defineComponent({
586
+ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
516
587
  ...{ inheritAttrs: false },
517
588
  __name: "LocaleRouterLink",
518
589
  props: {
@@ -547,7 +618,7 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
547
618
  rel: "noopener noreferrer"
548
619
  }), [
549
620
  vue.renderSlot(_ctx.$slots, "default")
550
- ], 16, _hoisted_1)) : resolved.value.kind === "special" ? (vue.openBlock(), vue.createElementBlock("a", vue.mergeProps({ key: 1 }, vue.unref(attrs), {
621
+ ], 16, _hoisted_1$1)) : resolved.value.kind === "special" ? (vue.openBlock(), vue.createElementBlock("a", vue.mergeProps({ key: 1 }, vue.unref(attrs), {
551
622
  href: resolved.value.href
552
623
  }), [
553
624
  vue.renderSlot(_ctx.$slots, "default")
@@ -560,6 +631,77 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
560
631
  };
561
632
  }
562
633
  });
634
+ const BLOX_CONTENT_ITEM_KEY = Symbol("blox-content-item");
635
+ function useContentItem() {
636
+ return vue.inject(BLOX_CONTENT_ITEM_KEY, null) ?? vue.ref(null);
637
+ }
638
+ const _hoisted_1 = {
639
+ key: 1,
640
+ class: "blox-content-detail"
641
+ };
642
+ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
643
+ __name: "ContentDetailHost",
644
+ setup(__props) {
645
+ const route = vueRouter.useRoute();
646
+ const { locale: locale2 } = useLocale();
647
+ const def = vue.computed(() => route.meta.contentDef);
648
+ const slug = vue.computed(() => String(route.params.slug ?? ""));
649
+ const { data: item } = useData(
650
+ () => {
651
+ var _a;
652
+ return `content:${((_a = def.value) == null ? void 0 : _a.collection) ?? ""}:${slug.value}:${locale2.value}`;
653
+ },
654
+ async () => {
655
+ var _a, _b;
656
+ const collection = (_a = def.value) == null ? void 0 : _a.collection;
657
+ const s = slug.value;
658
+ if (!collection || !s) return null;
659
+ const escaped = s.replace(/"/g, '\\"');
660
+ const page = await listItems(collection, {
661
+ locale: locale2.value,
662
+ q: `slug eq "${escaped}"`,
663
+ limit: 1
664
+ });
665
+ return ((_b = page.items) == null ? void 0 : _b[0]) ?? null;
666
+ },
667
+ { default: null }
668
+ );
669
+ vue.provide(BLOX_CONTENT_ITEM_KEY, item);
670
+ const Detail = vue.computed(() => {
671
+ var _a;
672
+ return (_a = def.value) == null ? void 0 : _a.component;
673
+ });
674
+ return (_ctx, _cache) => {
675
+ return Detail.value ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(Detail.value), { key: 0 })) : vue.unref(item) ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
676
+ vue.createElementVNode("pre", null, vue.toDisplayString(vue.unref(item)), 1)
677
+ ])) : vue.createCommentVNode("", true);
678
+ };
679
+ }
680
+ });
681
+ const registry = [];
682
+ function defineContent(defs) {
683
+ registry.length = 0;
684
+ registry.push(...defs);
685
+ }
686
+ function contentRoutes() {
687
+ return registry;
688
+ }
689
+ function registerContentRoutesOnRouter(router, locales, defaultLocale) {
690
+ for (const def of registry) {
691
+ const routes = withLocaleRoutes(def.route, _sfc_main, locales, defaultLocale);
692
+ routes.forEach((r, i) => {
693
+ router.addRoute({
694
+ ...r,
695
+ // Only the default-locale path gets the stable name.
696
+ name: i === 0 ? def.name : void 0,
697
+ meta: {
698
+ ...r.meta ?? {},
699
+ contentDef: def
700
+ }
701
+ });
702
+ });
703
+ }
704
+ }
563
705
  function createPathStrategy(options) {
564
706
  const { defaultLocale, supportedLocales } = options;
565
707
  let _currentLocale = defaultLocale;
@@ -757,10 +899,15 @@ class BloxInstance {
757
899
  }
758
900
  router.addRoute({
759
901
  path: "/_blox_preview",
760
- component: () => Promise.resolve().then(() => require("./PreviewApp-Dz003khp.cjs")),
902
+ component: () => Promise.resolve().then(() => require("./PreviewApp-B8EmNfyH.cjs")),
761
903
  beforeEnter: () => window.parent !== window ? true : "/"
762
904
  });
763
- router.addRoute({ path: "/:pathMatch(.*)*", component: _sfc_main$1 });
905
+ registerContentRoutesOnRouter(
906
+ router,
907
+ this._config.supportedLocales,
908
+ this._config.defaultLocale
909
+ );
910
+ router.addRoute({ path: "/:pathMatch(.*)*", component: _sfc_main$2 });
764
911
  this._routeRegistered = true;
765
912
  return this;
766
913
  }
@@ -791,7 +938,7 @@ class BloxInstance {
791
938
  app.provide(BLOX_CONFIG_KEY, this._config);
792
939
  app.provide(BLOX_LOCALE_STRATEGY_KEY, this._strategy);
793
940
  if (this._adminEdit) app.provide(BLOX_ADMIN_CONFIG_KEY, this._adminEdit);
794
- app._context.components.RouterLink = _sfc_main;
941
+ app._context.components.RouterLink = _sfc_main$1;
795
942
  }
796
943
  }
797
944
  function isBlockDefinition(value) {
@@ -809,6 +956,7 @@ function createBlox(options) {
809
956
  }
810
957
  exports.BLOX_ADMIN_CONFIG_KEY = BLOX_ADMIN_CONFIG_KEY;
811
958
  exports.BLOX_CONFIG_KEY = BLOX_CONFIG_KEY;
959
+ exports.BLOX_CONTENT_ITEM_KEY = BLOX_CONTENT_ITEM_KEY;
812
960
  exports.BLOX_GLOBAL_RESOLVER_KEY = BLOX_GLOBAL_RESOLVER_KEY;
813
961
  exports.BLOX_LOCALE_STRATEGY_KEY = BLOX_LOCALE_STRATEGY_KEY;
814
962
  exports.BLOX_REGISTRY_KEY = BLOX_REGISTRY_KEY;
@@ -816,11 +964,14 @@ exports.BloxInstance = BloxInstance;
816
964
  exports.GLOBAL_REF_KEY = GLOBAL_REF_KEY;
817
965
  exports.GlobalBlockHost = GlobalBlockHost;
818
966
  exports.PageRenderer = PageRenderer;
819
- exports._sfc_main = _sfc_main$2;
820
- exports._sfc_main$1 = _sfc_main$1;
967
+ exports._sfc_main = _sfc_main$3;
968
+ exports._sfc_main$1 = _sfc_main$2;
969
+ exports._sfc_main$2 = _sfc_main$1;
821
970
  exports.classifyLink = classifyLink;
822
971
  exports.configureApi = configureApi;
972
+ exports.contentRoutes = contentRoutes;
823
973
  exports.createBlox = createBlox;
974
+ exports.defineContent = defineContent;
824
975
  exports.getWebsiteId = getWebsiteId;
825
976
  exports.getWebsiteIdSync = getWebsiteIdSync;
826
977
  exports.globalRefOf = globalRefOf;
@@ -833,4 +984,7 @@ exports.normalizeTo = normalizeTo;
833
984
  exports.resolvePath = resolvePath;
834
985
  exports.toInternalPath = toInternalPath;
835
986
  exports.useBloxEdit = useBloxEdit;
987
+ exports.useContentItem = useContentItem;
988
+ exports.useData = useData;
836
989
  exports.useLocale = useLocale;
990
+ exports.withLocaleRoutes = withLocaleRoutes;
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAa,MAAM,KAAK,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/D,OAA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AC,GAAG,IAAI;IA+B3E,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,IAAI;IA4BnE,+EAA+E;IAC/E,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAI9C,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IA+BpC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI;CAqC9C;AAMD,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,YAAY,CAS9D"}
package/dist/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const core = require("./core-fPjj9xyJ.cjs");
4
- const PreviewApp_vue_vue_type_style_index_0_lang = require("./PreviewApp.vue_vue_type_style_index_0_lang-BNKK7Vhs.cjs");
3
+ const core = require("./core-KRHc4Bob.cjs");
4
+ const PreviewApp_vue_vue_type_style_index_0_lang = require("./PreviewApp.vue_vue_type_style_index_0_lang-CPBuld3j.cjs");
5
5
  const vue = require("vue");
6
6
  const vueRouter = require("vue-router");
7
- const pinia = require("pinia");
8
7
  const ssg_client = require("./ssg/client.cjs");
8
+ const pinia = require("pinia");
9
9
  function useGlobalBlock(blockType, loader) {
10
10
  const data = vue.ref(null);
11
11
  const loading = vue.ref(false);
@@ -42,6 +42,12 @@ function useLocaleNav() {
42
42
  const strategy = vue.inject(core.BLOX_LOCALE_STRATEGY_KEY, null);
43
43
  const router = vueRouter.useRouter();
44
44
  const { locale, currentAlternates } = core.useLocale();
45
+ const availableLocales = vue.computed(() => {
46
+ var _a;
47
+ const alts = Object.keys(currentAlternates.value ?? {});
48
+ if (alts.length) return alts;
49
+ return ((_a = strategy == null ? void 0 : strategy.locales) == null ? void 0 : _a.length) ? [...strategy.locales] : [];
50
+ });
45
51
  function switchLocale(targetLocale) {
46
52
  if (!strategy) return;
47
53
  const alts = currentAlternates.value;
@@ -56,7 +62,12 @@ function useLocaleNav() {
56
62
  const loc = String(locale.value || "").slice(0, 2).toLowerCase();
57
63
  return strategy.toPath(normalized, loc || void 0);
58
64
  }
59
- return { switchLocale, toPath, locale };
65
+ function detect(path) {
66
+ const hostname = typeof window !== "undefined" ? window.location.hostname : "";
67
+ if (!strategy) return { locale: String(locale.value || "en"), slug: path || "/" };
68
+ return strategy.detect(hostname, path);
69
+ }
70
+ return { switchLocale, toPath, locale, availableLocales, detect };
60
71
  }
61
72
  function usePageContext(key) {
62
73
  const contexts = vue.inject("contexts");
@@ -66,6 +77,101 @@ function usePageContext(key) {
66
77
  return value;
67
78
  });
68
79
  }
80
+ function isServer() {
81
+ try {
82
+ if (false) ;
83
+ } catch {
84
+ }
85
+ return typeof window === "undefined";
86
+ }
87
+ function writePayload(seo) {
88
+ const root = typeof window !== "undefined" ? window : globalThis;
89
+ if (!seo) {
90
+ delete root[ssg_client.BLOX_PAGE_SEO_WINDOW_KEY];
91
+ return;
92
+ }
93
+ root[ssg_client.BLOX_PAGE_SEO_WINDOW_KEY] = { ...seo };
94
+ }
95
+ function applyClientHead(seo) {
96
+ if (typeof document === "undefined" || !seo) return;
97
+ if (seo.title) document.title = seo.title;
98
+ const ensureMeta = (attr, key, content) => {
99
+ let el = document.head.querySelector(`meta[${attr}="${key}"]`);
100
+ if (!el) {
101
+ el = document.createElement("meta");
102
+ el.setAttribute(attr, key);
103
+ document.head.appendChild(el);
104
+ }
105
+ el.setAttribute("content", content);
106
+ };
107
+ if (seo.description) {
108
+ ensureMeta("name", "description", seo.description);
109
+ ensureMeta("property", "og:description", seo.description);
110
+ }
111
+ if (seo.title) {
112
+ ensureMeta("property", "og:title", seo.title);
113
+ }
114
+ if (seo.image) {
115
+ ensureMeta("property", "og:image", seo.image);
116
+ }
117
+ }
118
+ function useSeo(getter) {
119
+ const resolved = vue.computed(() => vue.toValue(getter) ?? null);
120
+ function sync() {
121
+ const seo = resolved.value;
122
+ writePayload(seo ?? void 0);
123
+ if (!isServer()) applyClientHead(seo ?? void 0);
124
+ }
125
+ if (isServer()) {
126
+ vue.onServerPrefetch(() => {
127
+ sync();
128
+ });
129
+ sync();
130
+ } else {
131
+ vue.watch(resolved, sync, { immediate: true, deep: true });
132
+ }
133
+ vue.onUnmounted(() => {
134
+ writePayload(void 0);
135
+ });
136
+ }
137
+ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
138
+ __name: "BloxRouterView",
139
+ setup(__props) {
140
+ return (_ctx, _cache) => {
141
+ const _component_RouterView = vue.resolveComponent("RouterView");
142
+ return vue.openBlock(), vue.createBlock(vue.Suspense, null, {
143
+ fallback: vue.withCtx(() => [
144
+ vue.renderSlot(_ctx.$slots, "fallback")
145
+ ]),
146
+ default: vue.withCtx(() => [
147
+ vue.createVNode(_component_RouterView, null, {
148
+ default: vue.withCtx(({ Component }) => [
149
+ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(Component)))
150
+ ]),
151
+ _: 1
152
+ })
153
+ ]),
154
+ _: 3
155
+ });
156
+ };
157
+ }
158
+ });
159
+ function useContentSeo(item, getter) {
160
+ const route = vueRouter.useRoute();
161
+ const { detect } = useLocaleNav();
162
+ useSeo(() => {
163
+ const base = vue.toValue(getter);
164
+ if (!base) return null;
165
+ const row = item.value;
166
+ if (!row) return base;
167
+ const locales = Array.isArray(row.available_locales) ? row.available_locales.map((l) => String(l).slice(0, 2).toLowerCase()) : [];
168
+ if (!locales.length) return base;
169
+ const bare = detect(route.path).slug || route.path || "/";
170
+ const alternates = {};
171
+ for (const loc of locales) alternates[loc] = bare;
172
+ return { ...base, alternates };
173
+ });
174
+ }
69
175
  const DEFAULT_PLAUSIBLE_HOST = "https://analytics.bagel.to";
70
176
  function injectPlausible(config) {
71
177
  if (typeof document === "undefined") return;
@@ -199,16 +305,20 @@ function buildBloxManifest(blox) {
199
305
  exports.AdminEditBar = core._sfc_main;
200
306
  exports.BLOX_ADMIN_CONFIG_KEY = core.BLOX_ADMIN_CONFIG_KEY;
201
307
  exports.BLOX_CONFIG_KEY = core.BLOX_CONFIG_KEY;
308
+ exports.BLOX_CONTENT_ITEM_KEY = core.BLOX_CONTENT_ITEM_KEY;
202
309
  exports.BLOX_GLOBAL_RESOLVER_KEY = core.BLOX_GLOBAL_RESOLVER_KEY;
203
310
  exports.BLOX_LOCALE_STRATEGY_KEY = core.BLOX_LOCALE_STRATEGY_KEY;
204
311
  exports.BloxInstance = core.BloxInstance;
205
312
  exports.CmsPageView = core._sfc_main$1;
206
313
  exports.GLOBAL_REF_KEY = core.GLOBAL_REF_KEY;
207
314
  exports.GlobalBlockHost = core.GlobalBlockHost;
315
+ exports.LocaleRouterLink = core._sfc_main$2;
208
316
  exports.PageRenderer = core.PageRenderer;
209
317
  exports.classifyLink = core.classifyLink;
210
318
  exports.configureApi = core.configureApi;
319
+ exports.contentRoutes = core.contentRoutes;
211
320
  exports.createBlox = core.createBlox;
321
+ exports.defineContent = core.defineContent;
212
322
  exports.getWebsiteId = core.getWebsiteId;
213
323
  exports.getWebsiteIdSync = core.getWebsiteIdSync;
214
324
  exports.globalRefOf = core.globalRefOf;
@@ -221,16 +331,23 @@ exports.normalizeTo = core.normalizeTo;
221
331
  exports.resolvePath = core.resolvePath;
222
332
  exports.toInternalPath = core.toInternalPath;
223
333
  exports.useBloxEdit = core.useBloxEdit;
334
+ exports.useContentItem = core.useContentItem;
335
+ exports.useData = core.useData;
224
336
  exports.useLocale = core.useLocale;
337
+ exports.withLocaleRoutes = core.withLocaleRoutes;
225
338
  exports.PreviewApp = PreviewApp_vue_vue_type_style_index_0_lang._sfc_main;
226
339
  exports.PreviewRenderer = PreviewApp_vue_vue_type_style_index_0_lang.PreviewRenderer;
227
340
  exports.sendToEditor = PreviewApp_vue_vue_type_style_index_0_lang.sendToEditor;
228
341
  exports.sendToPreview = PreviewApp_vue_vue_type_style_index_0_lang.sendToPreview;
342
+ exports.BLOX_DATA_WINDOW_KEY = ssg_client.BLOX_DATA_WINDOW_KEY;
343
+ exports.BloxRouterView = _sfc_main;
229
344
  exports.buildBloxManifest = buildBloxManifest;
230
345
  exports.createBloxApp = createBloxApp;
231
346
  exports.defineBlock = defineBlock;
232
347
  exports.injectPlausible = injectPlausible;
233
348
  exports.serializeRegistry = serializeRegistry;
349
+ exports.useContentSeo = useContentSeo;
234
350
  exports.useGlobalBlock = useGlobalBlock;
235
351
  exports.useLocaleNav = useLocaleNav;
236
352
  exports.usePageContext = usePageContext;
353
+ exports.useSeo = useSeo;
package/dist/index.d.ts CHANGED
@@ -12,6 +12,18 @@ export { useLocale } from './composables/useLocale';
12
12
  export type { Locale } from './composables/useLocale';
13
13
  export { useLocaleNav } from './composables/useLocaleNav';
14
14
  export { usePageContext } from './composables/usePageContext';
15
+ export { useData, BLOX_DATA_WINDOW_KEY } from './composables/useData';
16
+ export type { UseDataOptions, UseDataResult } from './composables/useData';
17
+ export { useSeo } from './composables/useSeo';
18
+ export type { SeoInput, SeoGetter } from './composables/useSeo';
19
+ export { withLocaleRoutes } from './routing/withLocaleRoutes';
20
+ export { default as BloxRouterView } from './components/BloxRouterView.vue';
21
+ export { default as LocaleRouterLink } from './components/LocaleRouterLink.vue';
22
+ export { defineContent, contentRoutes } from './content/defineContent';
23
+ export type { ContentRouteDef } from './content/defineContent';
24
+ export { useContentItem, BLOX_CONTENT_ITEM_KEY } from './content/useContentItem';
25
+ export type { ContentItem } from './content/useContentItem';
26
+ export { useContentSeo } from './content/useContentSeo';
15
27
  export { classifyLink, installSmartLinks, isAbsoluteExternal, isSpecialScheme, normalizeLink, normalizeTo, toInternalPath, } from './smartLinks';
16
28
  export type { LinkKind } from './smartLinks';
17
29
  export { BloxInstance, createBlox } from './core';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa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