okno 1.0.0-beta.38 → 1.0.0-beta.39

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.
@@ -1,575 +0,0 @@
1
- import { join as f, extname as Q, dirname as P, relative as R, sep as K, resolve as h } from "node:path";
2
- import { existsSync as b, readFileSync as G, mkdirSync as $, writeFileSync as T, cpSync as Z } from "node:fs";
3
- import { fileURLToPath as q } from "node:url";
4
- import { r as tt, l as et, t as ot, m as nt, I as st, k as it, g as rt, n as at, s as v, b as lt, a as ct, c as ut, e as dt, d as ft, f as pt, j as M, o as A, p as mt, h as gt, i as ht } from "./dispatch-oBWbJ5Pl.js";
5
- import { simpleGit as C } from "simple-git";
6
- import "node:child_process";
7
- import "./parse-tlTHgSSs.js";
8
- function V(n, s) {
9
- const o = [
10
- 'import { __oknoWrap, __oknoLocalize, __oknoResolveRefs, __oknoResolveEnums, __oknoSetImages, __oknoSetRoutes, __oknoVisible } from "okno:runtime"',
11
- st
12
- ];
13
- return s ? (o.push(`import __schema from "${f(n, "schema.ts")}"`), o.push("__oknoSetRoutes(__schema)")) : o.push("const __schema = null"), o.push(
14
- "const __deps = { wrap: __oknoWrap, localize: __oknoLocalize, resolveRefs: __oknoResolveRefs, resolveEnums: __oknoResolveEnums, visible: __oknoVisible }"
15
- ), o;
16
- }
17
- async function _t(n, s = /* @__PURE__ */ new Set()) {
18
- return z(n, "pages", "__oknoInstantPage", s);
19
- }
20
- async function yt(n, s = /* @__PURE__ */ new Set()) {
21
- return z(n, "globals", "__oknoInstantGlobal", s);
22
- }
23
- async function z(n, s, o, t) {
24
- const c = b(f(n, "schema.ts")), p = [`import { ${o} } from "okno:instant"`, ...V(n, c)], l = /* @__PURE__ */ new Set();
25
- for (const e of await et(f(n, s))) {
26
- const i = ot(e), a = nt(e);
27
- l.add(a), p.push(
28
- `export const ${a} = ${o}("${i}", __schema?.${s}?.["${i}"]?.fields, __deps)`
29
- );
30
- }
31
- for (const e of t)
32
- l.has(e) || p.push(`export const ${e} = ${o}("${e}", undefined, __deps)`);
33
- return p.join(`
34
- `);
35
- }
36
- async function wt(n, s = /* @__PURE__ */ new Set()) {
37
- const o = b(f(n, "schema.ts")), t = ['import { __oknoInstantCollection } from "okno:instant"', ...V(n, o)], { draftsOff: c, schedulingOff: p } = tt(n), l = /* @__PURE__ */ new Set(), e = f(n, "collections");
38
- if (b(e)) {
39
- const { readdir: i } = await import("node:fs/promises"), a = await i(e, { withFileTypes: !0 });
40
- for (const m of a) {
41
- if (!m.isDirectory()) continue;
42
- const r = m.name, u = r.replace(/-/g, "_");
43
- if (l.has(u)) continue;
44
- l.add(u);
45
- const d = `{ drafts: ${!c.has(r)}, scheduling: ${!p.has(r)} }`;
46
- t.push(
47
- `export const ${u} = __oknoInstantCollection("${r}", __schema?.collections?.["${r}"]?.fields, ${d}, __deps)`
48
- );
49
- }
50
- }
51
- for (const i of s)
52
- l.has(i) || t.push(
53
- `export const ${i} = __oknoInstantCollection("${i.replace(/_/g, "-")}", undefined, { drafts: true, scheduling: true }, __deps)`
54
- );
55
- return t.join(`
56
- `);
57
- }
58
- function St(n) {
59
- const s = b(f(n, "schema.ts")), o = [
60
- 'import { __oknoInstantStrings } from "okno:instant"',
61
- 'import { __oknoMakeStrings, __oknoLocalize, __oknoExpandStrings } from "okno:runtime"'
62
- ];
63
- s && o.push(`import __schema from "${f(n, "schema.ts")}"`);
64
- const t = s ? "__schema?.strings" : "{}", c = s ? "__schema?.locales?.default" : '""';
65
- return o.push(
66
- `export const strings = __oknoInstantStrings(${t}, ${c}, { expand: __oknoExpandStrings, localize: __oknoLocalize, make: __oknoMakeStrings })`
67
- ), o.join(`
68
- `);
69
- }
70
- function bt(n) {
71
- return [
72
- 'import { __oknoInstantLoad, __oknoInstantRun } from "okno:instant"',
73
- `const URL = ${JSON.stringify(n)}`,
74
- "export const onRequest = (_context, next) => __oknoInstantLoad(URL).then((snap) => (snap ? __oknoInstantRun(snap, next) : next()))"
75
- ].join(`
76
- `);
77
- }
78
- function F(n, s, o) {
79
- n.statusCode = s, n.setHeader("Content-Type", "application/json"), n.setHeader("Cache-Control", "no-store"), n.end(JSON.stringify(o));
80
- }
81
- function kt(n) {
82
- return new Promise((s) => {
83
- let o = "";
84
- n.on("data", (t) => o += t), n.on("end", () => {
85
- try {
86
- s(o ? JSON.parse(o) : {});
87
- } catch {
88
- s({});
89
- }
90
- }), n.on("error", () => s({}));
91
- });
92
- }
93
- function Ot(n) {
94
- return new Promise((s, o) => {
95
- const t = [];
96
- n.on("data", (c) => t.push(c)), n.on("end", () => s(Buffer.concat(t))), n.on("error", o);
97
- });
98
- }
99
- function It(n, s) {
100
- if (s) {
101
- for (const o of new Set(s.modules)) {
102
- const t = n.moduleGraph.getModuleById("\0okno:" + o);
103
- t && n.moduleGraph.invalidateModule(t);
104
- }
105
- for (const o of new Set(s.files))
106
- n.moduleGraph.getModulesByFile(o)?.forEach((t) => n.moduleGraph.invalidateModule(t));
107
- }
108
- }
109
- function Et(n, s) {
110
- n.middlewares.use(async (o, t, c) => {
111
- if (!o.url?.startsWith("/__okno/api/")) return c();
112
- const p = o.url.slice(12).split("?")[0], l = {
113
- method: o.method || "GET",
114
- route: p,
115
- json: () => kt(o),
116
- binary: () => Ot(o),
117
- header: (e) => {
118
- const i = o.headers[e];
119
- return Array.isArray(i) ? i[0] : i;
120
- }
121
- };
122
- try {
123
- const e = await it(s, l);
124
- if (!e) return c();
125
- It(n, e.invalidation), F(t, e.status, e.body);
126
- } catch (e) {
127
- F(t, 500, { error: e instanceof Error ? e.message : String(e) });
128
- }
129
- });
130
- }
131
- function vt(n, s) {
132
- let o;
133
- try {
134
- o = decodeURIComponent(s);
135
- } catch {
136
- return null;
137
- }
138
- if (!o || o.includes("\0")) return null;
139
- const t = h(n, "files"), c = h(t, o);
140
- return c === t || !c.startsWith(t + K) ? null : c;
141
- }
142
- const j = "okno", Rt = {
143
- ".webp": "image/webp",
144
- ".png": "image/png",
145
- ".jpg": "image/jpeg",
146
- ".jpeg": "image/jpeg",
147
- ".gif": "image/gif",
148
- ".svg": "image/svg+xml",
149
- ".avif": "image/avif",
150
- ".ico": "image/x-icon",
151
- ".mp4": "video/mp4",
152
- ".webm": "video/webm",
153
- ".ogg": "video/ogg",
154
- ".mp3": "audio/mpeg",
155
- ".wav": "audio/wav",
156
- ".flac": "audio/flac",
157
- ".pdf": "application/pdf",
158
- ".woff2": "font/woff2",
159
- ".woff": "font/woff",
160
- ".ttf": "font/ttf",
161
- ".otf": "font/otf"
162
- };
163
- function Nt(n, s) {
164
- Et(n, s), n.middlewares.use((o, t, c) => {
165
- if (o.method !== "GET" || !o.url?.startsWith("/okno/files/")) return c();
166
- const p = o.url.slice(12).split("?")[0];
167
- if (!p) return c();
168
- const l = vt(s, p);
169
- if (!l)
170
- return t.statusCode = 403, t.end("Forbidden");
171
- if (!b(l))
172
- return t.statusCode = 404, t.end("Not found");
173
- const e = Q(l).toLowerCase();
174
- t.setHeader("Content-Type", Rt[e] || "application/octet-stream"), t.setHeader("Cache-Control", "public, max-age=3600"), t.end(G(l));
175
- }), n.middlewares.use(async (o, t, c) => {
176
- if (!o.url?.startsWith("/__okno/")) return c();
177
- const p = o.url.slice(8);
178
- t.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate"), t.setHeader("Pragma", "no-cache"), t.setHeader("Expires", "0");
179
- try {
180
- if (o.method === "GET" && p === "repo") {
181
- t.setHeader("Content-Type", "application/json");
182
- try {
183
- const l = C(n.config.root), e = (await l.remote(["get-url", "origin"]))?.toString().trim(), i = (await l.revparse(["--abbrev-ref", "HEAD"])).trim(), { owner: a, repo: m } = $t(e);
184
- return t.end(
185
- JSON.stringify({ ok: !0, owner: a, repo: m, branch: i || null, remote: e || null })
186
- );
187
- } catch (l) {
188
- return t.end(JSON.stringify({ ok: !1, error: String(l) }));
189
- }
190
- }
191
- if (o.method === "POST" && p.startsWith("mirror")) {
192
- const e = new URL(o.url, "http://localhost").searchParams.get("path");
193
- if (!e || e.includes("..") || !e.startsWith("files/"))
194
- return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
195
- const i = f(s, e);
196
- if (b(i))
197
- return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, skipped: !0 }));
198
- const a = await Mt(o);
199
- return $(P(i), { recursive: !0 }), T(i, a), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, written: e, bytes: a.length }));
200
- }
201
- if (o.method === "POST" && p === "sync") {
202
- const e = (await Ct(o))?.path;
203
- if (e) {
204
- if (e.includes("..") || e.includes("\0"))
205
- return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
206
- const r = f(s, e);
207
- try {
208
- const u = C(s);
209
- await u.fetch("origin", j);
210
- const d = (await u.revparse(["--show-toplevel"])).trim(), y = R(d, r).split(K).join("/"), _ = await u.show([`origin/${j}:${y}`]);
211
- $(P(r), { recursive: !0 }), T(r, _);
212
- } catch (u) {
213
- const d = u instanceof Error ? u.message : String(u);
214
- console.warn(
215
- `[okno] sync: could not materialize ${e} from origin/${j} — ${d.split(`
216
- `)[0]}`
217
- );
218
- }
219
- return U(n, e, r), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, invalidated: e }));
220
- }
221
- const i = C(s), a = await i.revparse(["--show-toplevel"]), m = R(a.trim(), s);
222
- try {
223
- const r = await i.pull();
224
- for (const u of r.files)
225
- if (u.startsWith(`${m}/`)) {
226
- const d = u.slice(`${m}/`.length), y = f(s, d);
227
- U(n, d, y);
228
- }
229
- return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, files: r.files }));
230
- } catch (r) {
231
- const u = r instanceof Error ? r.message : String(r);
232
- return console.warn(`[okno] sync: git pull skipped — ${u.split(`
233
- `)[0]}`), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, pullSkipped: !0, reason: u }));
234
- }
235
- }
236
- c();
237
- } catch (l) {
238
- t.statusCode = 500, t.end(JSON.stringify({ error: String(l) }));
239
- }
240
- });
241
- }
242
- function $t(n) {
243
- if (!n) return { owner: null, repo: null };
244
- const s = n.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
245
- return s ? { owner: s[1], repo: s[2] } : { owner: null, repo: null };
246
- }
247
- function Mt(n) {
248
- return new Promise((s, o) => {
249
- const t = [];
250
- n.on("data", (c) => t.push(c)), n.on("end", () => s(Buffer.concat(t))), n.on("error", o);
251
- });
252
- }
253
- function Ct(n) {
254
- return new Promise((s) => {
255
- let o = "";
256
- n.on("data", (t) => {
257
- o += t;
258
- }), n.on("end", () => {
259
- try {
260
- s(o ? JSON.parse(o) : null);
261
- } catch {
262
- s(null);
263
- }
264
- }), n.on("error", () => s(null));
265
- });
266
- }
267
- function U(n, s, o) {
268
- const t = "\0okno:";
269
- let c;
270
- if (s.startsWith("pages/") ? c = t + "pages" : s.startsWith("collections/") ? c = t + "collections" : s.startsWith("globals/") && (c = t + "globals"), c) {
271
- const p = n.moduleGraph.getModuleById(c);
272
- p && n.moduleGraph.invalidateModule(p);
273
- const l = n.moduleGraph.getModulesByFile(o);
274
- l && l.forEach((e) => {
275
- n.moduleGraph.invalidateModule(e);
276
- });
277
- }
278
- }
279
- function jt(n, s) {
280
- const o = (n.split("?")[0] ?? "").replace(/\\/g, "/"), t = s.replace(/\\/g, "/");
281
- return o === t || o.startsWith(t + "/");
282
- }
283
- function Pt(n, s) {
284
- for (const [o, t] of Object.entries(s)) {
285
- if (n === o) return t;
286
- if (n.startsWith(o + "/")) return t + n.slice(o.length);
287
- }
288
- return null;
289
- }
290
- const Tt = "okno:", O = "\0okno:", Ht = /* @__PURE__ */ new Set(["pages", "collections", "globals", "locales", "strings", "content"]), D = P(q(import.meta.url)), Gt = JSON.parse(G(h(D, "../package.json"), "utf-8")).version, x = rt(), S = h(D, "../editor"), H = h(S, "index.ts"), Bt = b(H), Wt = {
291
- "@modules": h(S, "modules"),
292
- "@lib": h(S, "lib"),
293
- "@logger": h(S, "lib/logger.svelte.ts"),
294
- "@utils": h(S, "lib/utils.ts"),
295
- "@/types": h(S, "lib/types.ts"),
296
- "@styles": h(S, "styles"),
297
- "@components": h(S, "components"),
298
- "@assets": h(S, "assets"),
299
- "@pages": h(S, "pages"),
300
- "@controllers": h(S, "controllers")
301
- };
302
- function Vt(n = {}) {
303
- const s = n.dir ?? "okno";
304
- let o, t, c = !1, p = !1;
305
- n.isEditor;
306
- let l = null;
307
- return {
308
- name: "okno",
309
- enforce: "pre",
310
- config(e, i) {
311
- const a = i.command === "serve";
312
- return p = i.command === "build", c = a && Bt && !n.builtEditor, {
313
- define: {
314
- __OKNO_API_URL__: JSON.stringify(n.apiUrl ?? "https://api.okno.build"),
315
- __OKNO_VERSION__: JSON.stringify(Gt),
316
- // True when the consumer is running `vite dev` / `astro dev` /
317
- // `sveltekit dev` — anything that serves locally. Replaced at
318
- // consumer build time so the prebuilt editor bundle can honor
319
- // the consumer's actual environment.
320
- __OKNO_IS_DEV__: JSON.stringify(a),
321
- // Public demo build: editor boots login-less, reads a static
322
- // `okno-demo.json` snapshot, no-ops writes. See docs/demo-mode.md.
323
- __OKNO_DEMO__: JSON.stringify(n.demo ?? !1),
324
- // Repo identity (`owner/repo@branch`) baked from the app's git
325
- // origin at the consumer's build time, so the deployed editor
326
- // auto-targets its repo with no picker. null outside a git
327
- // checkout → editor falls back to the picker. Dev ignores it
328
- // (runtime /__okno/repo derivation is more current).
329
- __OKNO_REPO__: JSON.stringify(ht()),
330
- // Monorepo root path: the build dir relative to the git root (e.g.
331
- // "apps/site", or "" at the repo root). Sent as X-Okno-Path so the
332
- // hosted backend reads/writes content under `<root>/okno` instead of
333
- // the repo-root `okno` — one repo, many okno projects keyed (repo, path).
334
- __OKNO_ROOT__: JSON.stringify(gt())
335
- },
336
- // Source mode (monorepo dev only): skip prebundling so saves to
337
- // `package/editor/**` propagate via HMR instead of needing
338
- // `bun run build:pkg`. The editor's internal @-aliases are NOT exposed
339
- // as a global `resolve.alias` here — that shadowed a consumer's own
340
- // identically-named tsconfig aliases (`@components`, `@lib`, …). They
341
- // are instead resolved per-importer in `resolveId`, scoped to imports
342
- // originating inside the editor source tree. See editor-aliases.ts.
343
- ...c && {
344
- optimizeDeps: { exclude: ["okno", "okno/editor"] }
345
- },
346
- server: {
347
- watch: {
348
- // Only ignore binary assets and editor-only metadata. Page/
349
- // collection/global .ts files SHOULD trigger Vite HMR — that's
350
- // how users see updates when they `git pull` content from the
351
- // drafts branch into their working tree. (Previously this list
352
- // also blocked pages/collections/globals because in DEV_MODE
353
- // the backend mirrored saves to disk, causing spurious full
354
- // reloads. In production-mode the backend never touches local
355
- // FS so blocking those is pure harm — pulls go unseen.)
356
- ignored: [`**/${s}/files/**`, `**/${s}/.okno-tree.json`]
357
- },
358
- // Source mode: the editor loads via a dynamic `import("okno/editor")`
359
- // from a separate package over `@fs`, so Vite's startup dep scan
360
- // never crawls it — its transitive deps (bits-ui, tiptap, runed…)
361
- // are discovered lazily on first import, triggering a mid-session
362
- // re-optimize that 404s the now-stale prebundled chunks. Warming the
363
- // editor entry forces that crawl at startup, so those deps land in
364
- // the first optimize pass and never re-bundle under the user.
365
- ...c && {
366
- warmup: { clientFiles: [H] }
367
- }
368
- }
369
- };
370
- },
371
- configResolved(e) {
372
- if (o = e.root, t = h(o, s), l = null, p && process.env.OKNO_INSTANT === "1")
373
- try {
374
- const i = JSON.parse(G(f(t, "project.json"), "utf-8"));
375
- i?.instant === !0 && typeof i.projectId == "string" && (l = `${(n.instantUrl ?? "https://snap.okno.build").replace(/\/$/, "")}/${i.projectId}/live.json`, console.log(`[okno] instant mode: content served from ${l}`));
376
- } catch {
377
- }
378
- },
379
- async buildStart() {
380
- if (b(t)) {
381
- if (await M(t, o), p) {
382
- const e = f(t, "files");
383
- if (b(e)) {
384
- const i = b(f(o, "static")) ? f(o, "static") : f(o, "public"), a = f(i, "okno", "files");
385
- h(a) !== h(e) && ($(a, { recursive: !0 }), Z(e, a, {
386
- recursive: !0,
387
- filter: (m) => !m.endsWith(".okno-tree.json")
388
- }));
389
- }
390
- }
391
- if (n.demo) {
392
- const e = f(o, "public");
393
- b(e) || $(e, { recursive: !0 }), T(
394
- f(e, "okno-demo.json"),
395
- JSON.stringify(mt(t))
396
- );
397
- }
398
- }
399
- },
400
- configureServer(e) {
401
- Nt(e, t);
402
- const i = (m) => {
403
- const r = R(t, m);
404
- if (r.startsWith("..") || !r.endsWith(".ts")) return;
405
- const u = r.split(/[\\/]/)[0];
406
- if (u !== "pages" && u !== "collections" && u !== "globals") return;
407
- const d = e.moduleGraph.getModuleById(O + u);
408
- d && e.moduleGraph.invalidateModule(d), e.moduleGraph.getModulesByFile(m)?.forEach((y) => e.moduleGraph.invalidateModule(y)), !A(m) && e.ws.send({ type: "full-reload" });
409
- };
410
- e.watcher.on("add", i), e.watcher.on("unlink", i), e.middlewares.use("/__okno/imports", async (m, r, u) => {
411
- if (m.method !== "GET") return u();
412
- try {
413
- const [d, y, _] = await Promise.all([
414
- v(o, "pages"),
415
- v(o, "globals"),
416
- v(o, "collections")
417
- ]);
418
- r.setHeader("Content-Type", "application/json"), r.setHeader("Cache-Control", "no-store"), r.end(JSON.stringify({
419
- pages: Array.from(d),
420
- globals: Array.from(y),
421
- collections: Array.from(_)
422
- }));
423
- } catch (d) {
424
- u(d);
425
- }
426
- });
427
- const a = "/__okno_bootstrap.js";
428
- e.middlewares.use(a, async (m, r, u) => {
429
- try {
430
- const d = await e.transformRequest("\0okno:bootstrap");
431
- if (!d) {
432
- r.statusCode = 500, r.end("okno bootstrap transform failed");
433
- return;
434
- }
435
- r.setHeader("content-type", "text/javascript"), r.end(d.code);
436
- } catch (d) {
437
- u(d);
438
- }
439
- }), e.middlewares.use((m, r, u) => {
440
- const d = "<script>window.__oknoDev=true<\/script>", y = n.demo ? "<script>window.__oknoDemo=true<\/script>" : "", _ = `${d}${y}<script type="module" src="${a}"><\/script>`, w = [];
441
- let I = null;
442
- const X = r.write.bind(r), B = r.end.bind(r), Y = r.setHeader.bind(r), W = () => {
443
- const g = r.getHeader("content-type");
444
- return typeof g == "string" && g.includes("text/html");
445
- }, J = (g, k) => Buffer.isBuffer(g) ? g : g instanceof Uint8Array ? Buffer.from(g.buffer, g.byteOffset, g.byteLength) : typeof g == "string" ? Buffer.from(g, k || "utf-8") : Buffer.from(String(g));
446
- r.write = (g, k, ...N) => (I === null && (I = W()), I ? (g && w.push(J(g, typeof k == "string" ? k : void 0)), !0) : X(g, k, ...N)), r.end = (g, k, ...N) => {
447
- if (I === null && (I = W()), !I) return B(g, k, ...N);
448
- g && w.push(J(g, typeof k == "string" ? k : void 0));
449
- let E = Buffer.concat(w).toString("utf-8");
450
- E.includes(_) || (E = E.includes("</body>") ? E.replace("</body>", `${_}</body>`) : E + _);
451
- const L = Buffer.from(E, "utf-8");
452
- if (!r.headersSent)
453
- try {
454
- Y("content-length", String(L.length));
455
- } catch {
456
- }
457
- return B(L, ...N);
458
- }, u();
459
- });
460
- },
461
- async handleHotUpdate(e) {
462
- const i = f(t, "schema.ts"), a = f(t, "users.json"), m = f(t, "permissions.ts"), r = f(t, "modules.d.ts");
463
- if (e.file === i) {
464
- await M(t, o);
465
- for (const _ of ["pages", "collections", "globals", "locales", "content", "strings"]) {
466
- const w = e.server.moduleGraph.getModuleById(O + _);
467
- w && e.server.moduleGraph.invalidateModule(w);
468
- }
469
- return [];
470
- }
471
- if (e.file === a || e.file === m || e.file === r)
472
- return [];
473
- const u = f(t, "strings.ts"), d = R(f(t, "strings"), e.file);
474
- if (e.file === u || !d.startsWith("..") && d.endsWith(".ts")) {
475
- await M(t, o);
476
- for (const _ of ["strings", "content"]) {
477
- const w = e.server.moduleGraph.getModuleById(O + _);
478
- w && e.server.moduleGraph.invalidateModule(w);
479
- }
480
- }
481
- const y = R(t, e.file);
482
- if (!y.startsWith("..") && y.endsWith(".ts")) {
483
- const _ = y.split(/[\\/]/)[0];
484
- if ((_ === "pages" || _ === "collections" || _ === "globals") && A(e.file)) {
485
- const w = e.server.moduleGraph.getModuleById(O + _);
486
- return w && e.server.moduleGraph.invalidateModule(w), [];
487
- }
488
- }
489
- },
490
- // PRODUCTION boot for index.html frameworks (plain Vite, Solid, …). In dev
491
- // the `configureServer` middleware injects the editor; that middleware never
492
- // runs in a build, so a deployed page would ship no editor. `transformIndexHtml`
493
- // fires only for frameworks whose HTML goes through Vite's index.html pipeline
494
- // — Astro/SvelteKit/Nuxt own their HTML and bypass this hook, so they wire boot
495
- // their own way (an Astro integration, a +layout import, a Nuxt client plugin).
496
- // The inline `import "okno/boot"` is a real module script, so Vite bundles it +
497
- // code-splits the editor behind boot's press-`e`/`?okno` gate.
498
- transformIndexHtml: {
499
- // `pre`, so the inline module script is present BEFORE Vite's core HTML
500
- // plugin collects + bundles page scripts — otherwise the bare
501
- // `import "okno/boot"` survives unbundled and 404s in the browser.
502
- order: "pre",
503
- handler(e) {
504
- if (p)
505
- return {
506
- html: e,
507
- tags: [
508
- {
509
- tag: "script",
510
- attrs: { type: "module" },
511
- children: 'import "okno/boot"',
512
- injectTo: "body"
513
- }
514
- ]
515
- };
516
- }
517
- },
518
- async resolveId(e, i) {
519
- if (e.startsWith(Tt))
520
- return "\0" + e;
521
- if (e.startsWith("okno/")) {
522
- const a = e.slice(5);
523
- if (Ht.has(a)) return O + a;
524
- }
525
- if (c && e === "okno/editor")
526
- return H;
527
- if (c && i && jt(i, S)) {
528
- const a = Pt(e, Wt);
529
- if (a)
530
- return (await this.resolve(a, i, { skipSelf: !0 }))?.id;
531
- }
532
- },
533
- async load(e) {
534
- if (!e.startsWith(O)) return;
535
- const i = e.slice(O.length);
536
- if (i === "runtime") {
537
- if (!x)
538
- throw new Error("okno: runtime/wrap.js missing — run `bun run build:pkg`");
539
- return x;
540
- }
541
- if (i === "instant") {
542
- const a = at();
543
- if (!a) throw new Error("okno: runtime/instant.js missing — run `bun run build:pkg`");
544
- return a;
545
- }
546
- if (i === "instant-middleware") {
547
- if (!l) throw new Error("okno: instant middleware requested outside instant mode");
548
- return bt(l);
549
- }
550
- if (i === "bootstrap")
551
- return 'import("okno/editor")';
552
- if (i === "pages") {
553
- const a = await v(o, "pages");
554
- return l ? await _t(t, a) : await lt(t, a);
555
- }
556
- if (i === "collections") {
557
- const a = await v(o, "collections");
558
- return l ? await wt(t, a) : await ct(t, a, p);
559
- }
560
- if (i === "globals") {
561
- const a = await v(o, "globals");
562
- return l ? await yt(t, a) : await ut(t, a);
563
- }
564
- if (i === "locales")
565
- return dt(t);
566
- if (i === "strings")
567
- return l ? St(t) : await ft(t);
568
- if (i === "content")
569
- return pt();
570
- }
571
- };
572
- }
573
- export {
574
- Vt as o
575
- };
@@ -1,55 +0,0 @@
1
- /**
2
- * Instant-mode runtime — the body of the `okno:instant` virtual module.
3
- *
4
- * In instant mode content is NOT baked into the build: the generated
5
- * `okno:pages` / `okno:globals` / `okno:collections` / `okno:strings` modules
6
- * export lazy proxies from this file that read the CURRENT request's snapshot
7
- * (put in AsyncLocalStorage by the injected middleware) and run the exact
8
- * same hydration pipeline the baked modules would — localize → resolve refs +
9
- * enums → wrap. Same public API, different content source. See docs/instant.md.
10
- *
11
- * Module-state discipline: `okno:runtime` (wrap.js) holds shared state (image
12
- * map, routes), so this module never imports it — the generated modules import
13
- * both and pass the wrap functions in as `deps`. One runtime instance, no
14
- * duplicated state.
15
- *
16
- * Fail-soft: no snapshot (first request ever + fetch down) → accessors render
17
- * as empty placeholders (`wrap(null)`), never a crash. Last-good snapshot is
18
- * kept across fetch failures.
19
- */
20
- type Rec = Record<string, unknown>;
21
- export type InstantSnapshot = {
22
- v: 1;
23
- version: string;
24
- schema: Rec | null;
25
- entries: Record<string, Rec>;
26
- collections: Record<string, {
27
- slug: string;
28
- record: Rec;
29
- locales?: Record<string, Rec>;
30
- }[]>;
31
- };
32
- export type InstantDeps = {
33
- wrap: (data: unknown, prefix: string, drag?: string) => any;
34
- localize: (base: unknown, overrides: Record<string, unknown>) => any;
35
- resolveRefs: (data: unknown, fields: unknown, ns: unknown, locales: string[]) => any;
36
- resolveEnums: (data: unknown, fields: unknown, locales: string[]) => any;
37
- visible: (raw: unknown, now?: number) => boolean;
38
- };
39
- /** Middleware: run `fn` (the rest of the request) with `snap` as the content. */
40
- export declare function __oknoInstantRun<T>(snap: InstantSnapshot, fn: () => T): T;
41
- export declare function __oknoInstantLoad(url: string): Promise<InstantSnapshot | null>;
42
- export declare function __oknoInstantPage(name: string, fields: unknown, deps: InstantDeps): any;
43
- export declare function __oknoInstantGlobal(name: string, fields: unknown, deps: InstantDeps): any;
44
- export declare function __oknoInstantCollection(name: string, fields: unknown, flags: {
45
- drafts: boolean;
46
- scheduling: boolean;
47
- }, deps: InstantDeps): any[];
48
- export type InstantStringsDeps = {
49
- expand: (flat: unknown) => Rec;
50
- localize: (base: unknown, overrides: Record<string, unknown>) => any;
51
- make: (data: unknown, slots: unknown, def: unknown) => any;
52
- };
53
- export declare function __oknoInstantStrings(slots: unknown, def: unknown, deps: InstantStringsDeps): any;
54
- export {};
55
- //# sourceMappingURL=instant.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instant.d.ts","sourceRoot":"","sources":["../../src/runtime/instant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAClC,MAAM,MAAM,eAAe,GAAG;IAC7B,CAAC,EAAE,CAAC,CAAA;IACJ,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,GAAG,GAAG,IAAI,CAAA;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,EAAE,CAAC,CAAA;CAC3F,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,GAAG,CAAA;IAC3D,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,GAAG,CAAA;IACpE,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,GAAG,CAAA;IACpF,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,GAAG,CAAA;IACxE,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,OAAO,CAAA;CAChD,CAAA;AAQD,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEzE;AAWD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAkBpF;AAiKD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,GAAG,CAKvF;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,GAAG,CAKzF;AAED,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,KAAK,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,EAC/C,IAAI,EAAE,WAAW,GACf,GAAG,EAAE,CAKP;AAED,MAAM,MAAM,kBAAkB,GAAG;IAChC,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,GAAG,CAAA;IAC9B,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,GAAG,CAAA;IACpE,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,GAAG,CAAA;CAC1D,CAAA;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,kBAAkB,GAAG,GAAG,CAgBhG"}