@bagelink/blox 1.13.5 → 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 +2 -2
- package/dist/ssg/cli.mjs +2 -2
- 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/ssg/index.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { b as buildPageHead } from "../prerender-
|
|
2
|
-
import { d,
|
|
1
|
+
import { b as buildPageHead } from "../prerender-D3Q4jKXm.js";
|
|
2
|
+
import { d, c, f, g, e, h, p, a } from "../prerender-D3Q4jKXm.js";
|
|
3
|
+
import { BLOX_STATE_WINDOW_KEY, BLOX_COLLECTIONS_WINDOW_KEY, BLOX_WEBSITE_ID_WINDOW_KEY } from "./client.mjs";
|
|
3
4
|
import { getCollectionCache, getEmbeddedWebsiteId, installBloxStateCache, installCollectionCache } from "./client.mjs";
|
|
4
|
-
import {
|
|
5
|
+
import { createPinia } from "pinia";
|
|
6
|
+
import { createSSRApp, markRaw } from "vue";
|
|
7
|
+
import { c as createBlox } from "../core-CPXNfJ-Z.js";
|
|
5
8
|
async function renderBloxSsgPage(options) {
|
|
6
9
|
const {
|
|
7
10
|
url,
|
|
@@ -43,14 +46,98 @@ async function renderBloxSsgPage(options) {
|
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
}
|
|
49
|
+
let _websiteId = null;
|
|
50
|
+
function createBloxSSREntry(options) {
|
|
51
|
+
var _a;
|
|
52
|
+
const {
|
|
53
|
+
rootComponent,
|
|
54
|
+
createRouter,
|
|
55
|
+
modules,
|
|
56
|
+
websiteName,
|
|
57
|
+
store,
|
|
58
|
+
locale = "en",
|
|
59
|
+
supportedLocales = [locale],
|
|
60
|
+
plugins = [],
|
|
61
|
+
globalComponents = {}
|
|
62
|
+
} = options;
|
|
63
|
+
const apiBase = options.apiBase ?? (typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a.BAGELINK_API_URL : void 0) ?? "https://api.bagel.to";
|
|
64
|
+
async function getWebsiteId() {
|
|
65
|
+
if (_websiteId) return _websiteId;
|
|
66
|
+
const res = await fetch(`${apiBase}/cms/websites`);
|
|
67
|
+
const data = await res.json();
|
|
68
|
+
const sites = Array.isArray(data) ? data : (data == null ? void 0 : data.data) ?? [];
|
|
69
|
+
const site = sites.find((s) => s.name === websiteName);
|
|
70
|
+
if (!(site == null ? void 0 : site.id)) throw new Error(`Website "${websiteName}" not found`);
|
|
71
|
+
_websiteId = site.id;
|
|
72
|
+
return _websiteId;
|
|
73
|
+
}
|
|
74
|
+
async function fetchResolvedPage(urlPath) {
|
|
75
|
+
const websiteId = await getWebsiteId();
|
|
76
|
+
const url = `${apiBase}/cms/websites/${websiteId}/resolve-path?path=${encodeURIComponent(urlPath)}&locale=${locale}`;
|
|
77
|
+
const res = await fetch(url);
|
|
78
|
+
if (!res.ok) throw new Error(`resolve-path ${res.status}: ${urlPath}`);
|
|
79
|
+
return res.json();
|
|
80
|
+
}
|
|
81
|
+
function buildApp(url) {
|
|
82
|
+
const router = createRouter("memory", url);
|
|
83
|
+
const app = createSSRApp(rootComponent);
|
|
84
|
+
const pinia = createPinia();
|
|
85
|
+
pinia.use(({ store: s }) => {
|
|
86
|
+
s.router = markRaw(router);
|
|
87
|
+
});
|
|
88
|
+
const blox = createBlox({
|
|
89
|
+
modules,
|
|
90
|
+
websiteName,
|
|
91
|
+
store,
|
|
92
|
+
defaultLocale: locale,
|
|
93
|
+
supportedLocales,
|
|
94
|
+
router
|
|
95
|
+
});
|
|
96
|
+
for (const plugin of plugins) {
|
|
97
|
+
if (Array.isArray(plugin)) {
|
|
98
|
+
const [p2, ...args] = plugin;
|
|
99
|
+
app.use(p2, ...args);
|
|
100
|
+
} else {
|
|
101
|
+
app.use(plugin);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
blox.install(app, {});
|
|
105
|
+
app.use(pinia);
|
|
106
|
+
app.use(router);
|
|
107
|
+
for (const [name, comp] of Object.entries(globalComponents)) {
|
|
108
|
+
app.component(name, comp);
|
|
109
|
+
}
|
|
110
|
+
return { app, router };
|
|
111
|
+
}
|
|
112
|
+
async function render(url, ctx) {
|
|
113
|
+
let resolvedData = null;
|
|
114
|
+
try {
|
|
115
|
+
resolvedData = await fetchResolvedPage(url);
|
|
116
|
+
} catch (e2) {
|
|
117
|
+
console.warn(`[prerender] Could not resolve: ${url} — ${e2.message}`);
|
|
118
|
+
}
|
|
119
|
+
const { renderToString } = await import("vue/server-renderer");
|
|
120
|
+
return renderBloxSsgPage({
|
|
121
|
+
url,
|
|
122
|
+
resolvedData,
|
|
123
|
+
renderToString,
|
|
124
|
+
createAppForUrl: buildApp,
|
|
125
|
+
website: ctx.website,
|
|
126
|
+
websiteId: ctx.websiteId,
|
|
127
|
+
collections: ctx.collections
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return { render };
|
|
131
|
+
}
|
|
46
132
|
export {
|
|
47
133
|
BLOX_COLLECTIONS_WINDOW_KEY,
|
|
48
134
|
BLOX_STATE_WINDOW_KEY,
|
|
49
135
|
BLOX_WEBSITE_ID_WINDOW_KEY,
|
|
50
136
|
buildPageHead,
|
|
51
137
|
d as buildSiteHead,
|
|
52
|
-
|
|
53
|
-
|
|
138
|
+
createBloxSSREntry,
|
|
139
|
+
c as fetchCmsPrerenderPaths,
|
|
140
|
+
f as fetchCmsSiteData,
|
|
54
141
|
g as generateNetlifyRedirects,
|
|
55
142
|
e as generateRobotsTxt,
|
|
56
143
|
h as generateSitemapXml,
|
|
@@ -59,6 +146,6 @@ export {
|
|
|
59
146
|
installBloxStateCache,
|
|
60
147
|
installCollectionCache,
|
|
61
148
|
p as polyfillBloxSsgGlobals,
|
|
62
|
-
|
|
149
|
+
a as prerender,
|
|
63
150
|
renderBloxSsgPage
|
|
64
151
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prerender.d.ts","sourceRoot":"","sources":["../../src/ssg/prerender.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prerender.d.ts","sourceRoot":"","sources":["../../src/ssg/prerender.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAc1C,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAA;AAEhE,MAAM,WAAW,gBAAgB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,YAAY,CAAC,EAAE,WAAW,GAAG,WAAW,EAAE,CAAA;IAC1C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACrB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;IAC5B,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,kDAAkD;IAClD,SAAS,CAAC,EAAE,aAAa,EAAE,CAAA;IAC3B,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,aAAa;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAA;IACzC,QAAQ,EAAE,MAAM,CAAA;IAChB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;IAC5B,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CACf;AAMD,MAAM,WAAW,eAAe;IAC/B,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;IAC7D,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,SAAS,CAAC,EAC/B,IAAoB,EACpB,YAA4B,EAC5B,WAA0C,EAC1C,KAAU,EACV,KAAY,EACZ,YAAiB,EACjB,QAAgB,EAChB,QAAe,EACf,IAAY,EACZ,OAAc,EACd,SAAc,EACd,SAAc,EACd,WAAgB,GAChB,GAAE,gBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,CA4HlD"}
|
package/dist/style.css
CHANGED
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
animation: blox-nav-slide 1s ease-in-out infinite;
|
|
11
11
|
}
|
|
12
12
|
@keyframes blox-nav-slide {
|
|
13
|
-
0% {
|
|
13
|
+
0% {
|
|
14
|
+
transform: translateX(-100%);
|
|
14
15
|
}
|
|
15
|
-
100% {
|
|
16
|
+
100% {
|
|
17
|
+
transform: translateX(100%);
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
|
|
@@ -22,48 +24,5 @@
|
|
|
22
24
|
body {
|
|
23
25
|
margin: 0;
|
|
24
26
|
}
|
|
25
|
-
.blox-block-wrapper {
|
|
26
|
-
position: relative;
|
|
27
|
-
cursor: pointer;
|
|
28
|
-
}
|
|
29
|
-
.blox-block-overlay {
|
|
30
|
-
position: absolute;
|
|
31
|
-
inset: 0;
|
|
32
|
-
z-index: 10;
|
|
33
|
-
pointer-events: auto;
|
|
34
|
-
transition:
|
|
35
|
-
box-shadow 0.12s,
|
|
36
|
-
background 0.12s;
|
|
37
|
-
}
|
|
38
|
-
.blox-block--hovered .blox-block-overlay {
|
|
39
|
-
box-shadow: inset 0 0 0 2px rgba(99, 102, 241, 0.5);
|
|
40
|
-
background: rgba(99, 102, 241, 0.04);
|
|
41
|
-
}
|
|
42
|
-
.blox-block--selected .blox-block-overlay {
|
|
43
|
-
box-shadow: inset 0 0 0 3px #6366f1;
|
|
44
|
-
background: rgba(99, 102, 241, 0.06);
|
|
45
|
-
}
|
|
46
27
|
|
|
47
|
-
/*
|
|
48
|
-
.blox-block-label {
|
|
49
|
-
position: absolute;
|
|
50
|
-
top: 0;
|
|
51
|
-
left: 0;
|
|
52
|
-
z-index: 20;
|
|
53
|
-
padding: 2px 8px;
|
|
54
|
-
font-size: 11px;
|
|
55
|
-
font-family: system-ui, sans-serif;
|
|
56
|
-
font-weight: 600;
|
|
57
|
-
line-height: 20px;
|
|
58
|
-
letter-spacing: 0.02em;
|
|
59
|
-
text-transform: uppercase;
|
|
60
|
-
color: #6366f1;
|
|
61
|
-
background: rgba(99, 102, 241, 0.1);
|
|
62
|
-
border-bottom-right-radius: 4px;
|
|
63
|
-
pointer-events: none;
|
|
64
|
-
white-space: nowrap;
|
|
65
|
-
}
|
|
66
|
-
.blox-block-label--selected {
|
|
67
|
-
color: #fff;
|
|
68
|
-
background: #6366f1;
|
|
69
|
-
}
|
|
28
|
+
/* Block selection styles are applied via inline styles in PreviewRenderer */
|
package/dist/vite-plugin.cjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const node_module = require("node:module");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const process = require("node:process");
|
|
3
6
|
var comma = ",".charCodeAt(0);
|
|
4
7
|
var semicolon = ";".charCodeAt(0);
|
|
5
8
|
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
@@ -1069,8 +1072,143 @@ class MagicString {
|
|
|
1069
1072
|
return this._replaceRegexp(searchValue, replacement);
|
|
1070
1073
|
}
|
|
1071
1074
|
}
|
|
1072
|
-
function bloxPlugin() {
|
|
1073
|
-
|
|
1075
|
+
function bloxPlugin(options = {}) {
|
|
1076
|
+
const enableSSR = options.ssr ?? false;
|
|
1077
|
+
const plugins = [];
|
|
1078
|
+
if (enableSSR) {
|
|
1079
|
+
plugins.push({
|
|
1080
|
+
name: "vite-plugin-blox-ssr",
|
|
1081
|
+
enforce: "pre",
|
|
1082
|
+
config(_config, { command }) {
|
|
1083
|
+
const cwd = process.cwd();
|
|
1084
|
+
function resolveVuePaths() {
|
|
1085
|
+
const bases = [path.join(cwd, "..", "package.json"), path.join(cwd, "package.json")];
|
|
1086
|
+
for (const base of bases) {
|
|
1087
|
+
try {
|
|
1088
|
+
const req = node_module.createRequire(base);
|
|
1089
|
+
const vueEntry = req.resolve("vue");
|
|
1090
|
+
const vueDir = path.dirname(path.dirname(vueEntry));
|
|
1091
|
+
return {
|
|
1092
|
+
"vue": vueEntry,
|
|
1093
|
+
"vue/server-renderer": path.join(vueDir, "server-renderer", "index.mjs"),
|
|
1094
|
+
"@vue/server-renderer": req.resolve("@vue/server-renderer")
|
|
1095
|
+
};
|
|
1096
|
+
} catch {
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
return {};
|
|
1101
|
+
}
|
|
1102
|
+
const dedupe = [
|
|
1103
|
+
"vue",
|
|
1104
|
+
"vue-router",
|
|
1105
|
+
"@vue/runtime-core",
|
|
1106
|
+
"@vue/runtime-dom",
|
|
1107
|
+
"@vue/reactivity",
|
|
1108
|
+
"pinia"
|
|
1109
|
+
];
|
|
1110
|
+
const alias = resolveVuePaths();
|
|
1111
|
+
const ssrConfig = {
|
|
1112
|
+
resolve: {
|
|
1113
|
+
dedupe,
|
|
1114
|
+
alias
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
return ssrConfig;
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
plugins.push({
|
|
1121
|
+
name: "vite-plugin-blox-ssr-build",
|
|
1122
|
+
enforce: "pre",
|
|
1123
|
+
config(config) {
|
|
1124
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1125
|
+
if ((_a = config.build) == null ? void 0 : _a.ssr) {
|
|
1126
|
+
return {
|
|
1127
|
+
build: {
|
|
1128
|
+
rollupOptions: {
|
|
1129
|
+
input: ((_c = (_b = config.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.input) ?? "src/main.server.ts",
|
|
1130
|
+
output: ((_e = (_d = config.build) == null ? void 0 : _d.rollupOptions) == null ? void 0 : _e.output) ?? {
|
|
1131
|
+
dir: "dist/server",
|
|
1132
|
+
format: "esm"
|
|
1133
|
+
},
|
|
1134
|
+
external: [
|
|
1135
|
+
"vue",
|
|
1136
|
+
"vue-router",
|
|
1137
|
+
"vue/server-renderer",
|
|
1138
|
+
"@vue/server-renderer",
|
|
1139
|
+
...Array.isArray((_g = (_f = config.build) == null ? void 0 : _f.rollupOptions) == null ? void 0 : _g.external) ? config.build.rollupOptions.external : []
|
|
1140
|
+
]
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
return {};
|
|
1146
|
+
}
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
if (options.autoCollections ?? false) {
|
|
1150
|
+
const discoveredCollections = /* @__PURE__ */ new Map();
|
|
1151
|
+
const VIRTUAL_ID = "virtual:blox-collections";
|
|
1152
|
+
const RESOLVED_VIRTUAL_ID = `\0${VIRTUAL_ID}`;
|
|
1153
|
+
plugins.push({
|
|
1154
|
+
name: "vite-plugin-blox-collections",
|
|
1155
|
+
enforce: "pre",
|
|
1156
|
+
resolveId(id) {
|
|
1157
|
+
if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;
|
|
1158
|
+
},
|
|
1159
|
+
load(id) {
|
|
1160
|
+
if (id === RESOLVED_VIRTUAL_ID) {
|
|
1161
|
+
const entries = [...discoveredCollections.values()];
|
|
1162
|
+
return `export default ${JSON.stringify(entries)}`;
|
|
1163
|
+
}
|
|
1164
|
+
},
|
|
1165
|
+
transform(code, id) {
|
|
1166
|
+
if (!id.endsWith(".vue")) return;
|
|
1167
|
+
const namePatterns = [
|
|
1168
|
+
/collectionName\s*:\s*['"]([^'"]+)['"]/g,
|
|
1169
|
+
/collection_name\s*:\s*['"]([^'"]+)['"]/g,
|
|
1170
|
+
/collection\s*:\s*['"]([^'"]+)['"]/g
|
|
1171
|
+
];
|
|
1172
|
+
const storeRe = /store\s*:\s*['"]([^'"]+)['"]/g;
|
|
1173
|
+
const stores = [];
|
|
1174
|
+
let storeMatch;
|
|
1175
|
+
while ((storeMatch = storeRe.exec(code)) !== null) {
|
|
1176
|
+
stores.push(storeMatch[1]);
|
|
1177
|
+
}
|
|
1178
|
+
const listItemsRe = /listItems\s*\(\s*['"]([^'"]+)['"]/g;
|
|
1179
|
+
let listMatch;
|
|
1180
|
+
while ((listMatch = listItemsRe.exec(code)) !== null) {
|
|
1181
|
+
const collectionName = listMatch[1];
|
|
1182
|
+
const key = `*/${collectionName}`;
|
|
1183
|
+
if (!discoveredCollections.has(key)) {
|
|
1184
|
+
discoveredCollections.set(key, { store: "*", collection: collectionName });
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
for (const pattern of namePatterns) {
|
|
1188
|
+
let match;
|
|
1189
|
+
while ((match = pattern.exec(code)) !== null) {
|
|
1190
|
+
const collection = match[1];
|
|
1191
|
+
if (["name", "label", "icon", "description", "type"].includes(collection)) continue;
|
|
1192
|
+
const store = stores[0] ?? "*";
|
|
1193
|
+
const key = `${store}/${collection}`;
|
|
1194
|
+
if (!discoveredCollections.has(key)) {
|
|
1195
|
+
discoveredCollections.set(key, { store, collection });
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
},
|
|
1200
|
+
generateBundle() {
|
|
1201
|
+
if (discoveredCollections.size === 0) return;
|
|
1202
|
+
const entries = [...discoveredCollections.values()];
|
|
1203
|
+
this.emitFile({
|
|
1204
|
+
type: "asset",
|
|
1205
|
+
fileName: ".blox-collections.json",
|
|
1206
|
+
source: JSON.stringify(entries, null, 2)
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
plugins.push({
|
|
1074
1212
|
name: "vite-plugin-blox",
|
|
1075
1213
|
enforce: "pre",
|
|
1076
1214
|
transform(code, id) {
|
|
@@ -1163,6 +1301,7 @@ ${openTag}${remaining}${closeTag}`;
|
|
|
1163
1301
|
map: s.generateMap({ hires: true })
|
|
1164
1302
|
};
|
|
1165
1303
|
}
|
|
1166
|
-
};
|
|
1304
|
+
});
|
|
1305
|
+
return plugins;
|
|
1167
1306
|
}
|
|
1168
1307
|
exports.bloxPlugin = bloxPlugin;
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
+
export interface BloxPluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Enable SSR-aware config injection.
|
|
5
|
+
* When true, adds `resolve.dedupe`, `resolve.alias` for Vue,
|
|
6
|
+
* and SSR build rollup options automatically.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
ssr?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Enable collection auto-discovery from block source files.
|
|
12
|
+
* When true, scans `.vue` files for datastore collection references
|
|
13
|
+
* and emits a `virtual:blox-collections` module and a
|
|
14
|
+
* `.blox-collections.json` manifest in the output directory.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
autoCollections?: boolean;
|
|
18
|
+
}
|
|
2
19
|
/**
|
|
3
|
-
* Vite plugin that
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```vue
|
|
9
|
-
* <script setup lang="ts">
|
|
10
|
-
* import { defineBlock } from '@bagelink/blox'
|
|
11
|
-
* import { defineSchema, $ } from '@bagelink/vue'
|
|
12
|
-
*
|
|
13
|
-
* // Either inline:
|
|
14
|
-
* defineBlock({ name: 'hero', label: 'Hero', schema: defineSchema({ ... }) })
|
|
15
|
-
*
|
|
16
|
-
* // Or via variable (also hoisted automatically):
|
|
17
|
-
* const schema = defineSchema({ ... })
|
|
18
|
-
* defineBlock({ name: 'hero', label: 'Hero', schema })
|
|
19
|
-
*
|
|
20
|
-
* defineProps<HeroProps>()
|
|
21
|
-
* </script>
|
|
22
|
-
* ```
|
|
20
|
+
* Vite plugin that:
|
|
21
|
+
* 1. Hoists `defineBlock(...)` out of `<script setup>` into a plain `<script>` block.
|
|
22
|
+
* 2. (When `ssr: true`) Injects Vue dedupe, alias, and SSR rollup config
|
|
23
|
+
* so consumer `vite.config.ts` doesn't need any of that boilerplate.
|
|
23
24
|
*/
|
|
24
|
-
export declare function bloxPlugin(): Plugin;
|
|
25
|
+
export declare function bloxPlugin(options?: BloxPluginOptions): Plugin[];
|
|
25
26
|
//# sourceMappingURL=vite-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAA;AAM9C,MAAM,WAAW,iBAAiB;IACjC;;;;;OAKG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,EAAE,CA4SpE"}
|
package/dist/vite-plugin.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import process from "node:process";
|
|
1
4
|
var comma = ",".charCodeAt(0);
|
|
2
5
|
var semicolon = ";".charCodeAt(0);
|
|
3
6
|
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
@@ -1067,8 +1070,143 @@ class MagicString {
|
|
|
1067
1070
|
return this._replaceRegexp(searchValue, replacement);
|
|
1068
1071
|
}
|
|
1069
1072
|
}
|
|
1070
|
-
function bloxPlugin() {
|
|
1071
|
-
|
|
1073
|
+
function bloxPlugin(options = {}) {
|
|
1074
|
+
const enableSSR = options.ssr ?? false;
|
|
1075
|
+
const plugins = [];
|
|
1076
|
+
if (enableSSR) {
|
|
1077
|
+
plugins.push({
|
|
1078
|
+
name: "vite-plugin-blox-ssr",
|
|
1079
|
+
enforce: "pre",
|
|
1080
|
+
config(_config, { command }) {
|
|
1081
|
+
const cwd = process.cwd();
|
|
1082
|
+
function resolveVuePaths() {
|
|
1083
|
+
const bases = [join(cwd, "..", "package.json"), join(cwd, "package.json")];
|
|
1084
|
+
for (const base of bases) {
|
|
1085
|
+
try {
|
|
1086
|
+
const req = createRequire(base);
|
|
1087
|
+
const vueEntry = req.resolve("vue");
|
|
1088
|
+
const vueDir = dirname(dirname(vueEntry));
|
|
1089
|
+
return {
|
|
1090
|
+
"vue": vueEntry,
|
|
1091
|
+
"vue/server-renderer": join(vueDir, "server-renderer", "index.mjs"),
|
|
1092
|
+
"@vue/server-renderer": req.resolve("@vue/server-renderer")
|
|
1093
|
+
};
|
|
1094
|
+
} catch {
|
|
1095
|
+
continue;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
return {};
|
|
1099
|
+
}
|
|
1100
|
+
const dedupe = [
|
|
1101
|
+
"vue",
|
|
1102
|
+
"vue-router",
|
|
1103
|
+
"@vue/runtime-core",
|
|
1104
|
+
"@vue/runtime-dom",
|
|
1105
|
+
"@vue/reactivity",
|
|
1106
|
+
"pinia"
|
|
1107
|
+
];
|
|
1108
|
+
const alias = resolveVuePaths();
|
|
1109
|
+
const ssrConfig = {
|
|
1110
|
+
resolve: {
|
|
1111
|
+
dedupe,
|
|
1112
|
+
alias
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
return ssrConfig;
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
plugins.push({
|
|
1119
|
+
name: "vite-plugin-blox-ssr-build",
|
|
1120
|
+
enforce: "pre",
|
|
1121
|
+
config(config) {
|
|
1122
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1123
|
+
if ((_a = config.build) == null ? void 0 : _a.ssr) {
|
|
1124
|
+
return {
|
|
1125
|
+
build: {
|
|
1126
|
+
rollupOptions: {
|
|
1127
|
+
input: ((_c = (_b = config.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.input) ?? "src/main.server.ts",
|
|
1128
|
+
output: ((_e = (_d = config.build) == null ? void 0 : _d.rollupOptions) == null ? void 0 : _e.output) ?? {
|
|
1129
|
+
dir: "dist/server",
|
|
1130
|
+
format: "esm"
|
|
1131
|
+
},
|
|
1132
|
+
external: [
|
|
1133
|
+
"vue",
|
|
1134
|
+
"vue-router",
|
|
1135
|
+
"vue/server-renderer",
|
|
1136
|
+
"@vue/server-renderer",
|
|
1137
|
+
...Array.isArray((_g = (_f = config.build) == null ? void 0 : _f.rollupOptions) == null ? void 0 : _g.external) ? config.build.rollupOptions.external : []
|
|
1138
|
+
]
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
return {};
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
if (options.autoCollections ?? false) {
|
|
1148
|
+
const discoveredCollections = /* @__PURE__ */ new Map();
|
|
1149
|
+
const VIRTUAL_ID = "virtual:blox-collections";
|
|
1150
|
+
const RESOLVED_VIRTUAL_ID = `\0${VIRTUAL_ID}`;
|
|
1151
|
+
plugins.push({
|
|
1152
|
+
name: "vite-plugin-blox-collections",
|
|
1153
|
+
enforce: "pre",
|
|
1154
|
+
resolveId(id) {
|
|
1155
|
+
if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;
|
|
1156
|
+
},
|
|
1157
|
+
load(id) {
|
|
1158
|
+
if (id === RESOLVED_VIRTUAL_ID) {
|
|
1159
|
+
const entries = [...discoveredCollections.values()];
|
|
1160
|
+
return `export default ${JSON.stringify(entries)}`;
|
|
1161
|
+
}
|
|
1162
|
+
},
|
|
1163
|
+
transform(code, id) {
|
|
1164
|
+
if (!id.endsWith(".vue")) return;
|
|
1165
|
+
const namePatterns = [
|
|
1166
|
+
/collectionName\s*:\s*['"]([^'"]+)['"]/g,
|
|
1167
|
+
/collection_name\s*:\s*['"]([^'"]+)['"]/g,
|
|
1168
|
+
/collection\s*:\s*['"]([^'"]+)['"]/g
|
|
1169
|
+
];
|
|
1170
|
+
const storeRe = /store\s*:\s*['"]([^'"]+)['"]/g;
|
|
1171
|
+
const stores = [];
|
|
1172
|
+
let storeMatch;
|
|
1173
|
+
while ((storeMatch = storeRe.exec(code)) !== null) {
|
|
1174
|
+
stores.push(storeMatch[1]);
|
|
1175
|
+
}
|
|
1176
|
+
const listItemsRe = /listItems\s*\(\s*['"]([^'"]+)['"]/g;
|
|
1177
|
+
let listMatch;
|
|
1178
|
+
while ((listMatch = listItemsRe.exec(code)) !== null) {
|
|
1179
|
+
const collectionName = listMatch[1];
|
|
1180
|
+
const key = `*/${collectionName}`;
|
|
1181
|
+
if (!discoveredCollections.has(key)) {
|
|
1182
|
+
discoveredCollections.set(key, { store: "*", collection: collectionName });
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
for (const pattern of namePatterns) {
|
|
1186
|
+
let match;
|
|
1187
|
+
while ((match = pattern.exec(code)) !== null) {
|
|
1188
|
+
const collection = match[1];
|
|
1189
|
+
if (["name", "label", "icon", "description", "type"].includes(collection)) continue;
|
|
1190
|
+
const store = stores[0] ?? "*";
|
|
1191
|
+
const key = `${store}/${collection}`;
|
|
1192
|
+
if (!discoveredCollections.has(key)) {
|
|
1193
|
+
discoveredCollections.set(key, { store, collection });
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
},
|
|
1198
|
+
generateBundle() {
|
|
1199
|
+
if (discoveredCollections.size === 0) return;
|
|
1200
|
+
const entries = [...discoveredCollections.values()];
|
|
1201
|
+
this.emitFile({
|
|
1202
|
+
type: "asset",
|
|
1203
|
+
fileName: ".blox-collections.json",
|
|
1204
|
+
source: JSON.stringify(entries, null, 2)
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
plugins.push({
|
|
1072
1210
|
name: "vite-plugin-blox",
|
|
1073
1211
|
enforce: "pre",
|
|
1074
1212
|
transform(code, id) {
|
|
@@ -1161,7 +1299,8 @@ ${openTag}${remaining}${closeTag}`;
|
|
|
1161
1299
|
map: s.generateMap({ hires: true })
|
|
1162
1300
|
};
|
|
1163
1301
|
}
|
|
1164
|
-
};
|
|
1302
|
+
});
|
|
1303
|
+
return plugins;
|
|
1165
1304
|
}
|
|
1166
1305
|
export {
|
|
1167
1306
|
bloxPlugin
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bagelink/blox",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.14.0",
|
|
5
5
|
"description": "Blox page builder library for drag-and-drop page building and static data management",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Bagel Studio",
|
|
@@ -123,5 +123,8 @@
|
|
|
123
123
|
"vue": "^3.5.32",
|
|
124
124
|
"vue-router": "^4.6.3",
|
|
125
125
|
"vue-tsc": "^2.0.0"
|
|
126
|
+
},
|
|
127
|
+
"dependencies": {
|
|
128
|
+
"pinia": "^3.0.4"
|
|
126
129
|
}
|
|
127
130
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const BLOX_STATE_WINDOW_KEY = "__BLOX_STATE__";
|
|
2
|
-
const BLOX_COLLECTIONS_WINDOW_KEY = "__BLOX_COLLECTIONS__";
|
|
3
|
-
const BLOX_WEBSITE_ID_WINDOW_KEY = "__BLOX_WEBSITE_ID__";
|
|
4
|
-
export {
|
|
5
|
-
BLOX_STATE_WINDOW_KEY as B,
|
|
6
|
-
BLOX_COLLECTIONS_WINDOW_KEY as a,
|
|
7
|
-
BLOX_WEBSITE_ID_WINDOW_KEY as b
|
|
8
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const BLOX_STATE_WINDOW_KEY = "__BLOX_STATE__";
|
|
3
|
-
const BLOX_COLLECTIONS_WINDOW_KEY = "__BLOX_COLLECTIONS__";
|
|
4
|
-
const BLOX_WEBSITE_ID_WINDOW_KEY = "__BLOX_WEBSITE_ID__";
|
|
5
|
-
exports.BLOX_COLLECTIONS_WINDOW_KEY = BLOX_COLLECTIONS_WINDOW_KEY;
|
|
6
|
-
exports.BLOX_STATE_WINDOW_KEY = BLOX_STATE_WINDOW_KEY;
|
|
7
|
-
exports.BLOX_WEBSITE_ID_WINDOW_KEY = BLOX_WEBSITE_ID_WINDOW_KEY;
|