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