okno 1.0.0-beta.37 → 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.
- package/dist/astro/index.d.ts +13 -0
- package/dist/astro/index.d.ts.map +1 -0
- package/dist/astro/index.js +15 -0
- package/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/modules.d.ts.map +1 -1
- package/dist/dispatch-BifB_3GO.js +955 -0
- package/dist/editor/index.js +16807 -15811
- package/dist/index.js +1 -1
- package/dist/init.d.ts +24 -4
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +167 -147
- package/dist/local/dispatch.d.ts.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/{plugin-CPb37kty.js → plugin-BdiBIiAv.js} +167 -139
- package/dist/runtime/wrap.d.ts +23 -0
- package/dist/runtime/wrap.d.ts.map +1 -1
- package/dist/runtime/wrap.js +344 -226
- package/dist/types/schema.d.ts +23 -12
- package/dist/types/schema.d.ts.map +1 -1
- package/dist/vite/index.js +1 -1
- package/dist/vite/plugin.d.ts.map +1 -1
- package/package.json +5 -1
- package/src/runtime/wrap.ts +288 -33
- package/dist/dispatch-dIjAypRM.js +0 -934
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { extname as z, join as
|
|
2
|
-
import { existsSync as O, readFileSync as U, mkdirSync as M, writeFileSync as
|
|
1
|
+
import { extname as z, join as y, dirname as T, relative as N, sep as D, resolve as g } from "node:path";
|
|
2
|
+
import { existsSync as O, readFileSync as U, mkdirSync as M, writeFileSync as I, cpSync as Y } from "node:fs";
|
|
3
3
|
import { fileURLToPath as Q } from "node:url";
|
|
4
|
-
import { k as Z, g as x, s as E, b as q, a as tt, c as et, e as ot, d as nt, f as it, j as P, l as $, m as rt, h as st, i as at } from "./dispatch-
|
|
4
|
+
import { k as Z, g as x, s as E, b as q, a as tt, c as et, e as ot, d as nt, f as it, j as P, l as $, m as rt, h as st, i as at } from "./dispatch-BifB_3GO.js";
|
|
5
5
|
import { simpleGit as R } from "simple-git";
|
|
6
6
|
import "node:child_process";
|
|
7
7
|
import "./parse-tlTHgSSs.js";
|
|
8
|
-
function F(n, r,
|
|
9
|
-
n.statusCode = r, n.setHeader("Content-Type", "application/json"), n.setHeader("Cache-Control", "no-store"), n.end(JSON.stringify(
|
|
8
|
+
function F(n, r, o) {
|
|
9
|
+
n.statusCode = r, n.setHeader("Content-Type", "application/json"), n.setHeader("Cache-Control", "no-store"), n.end(JSON.stringify(o));
|
|
10
10
|
}
|
|
11
11
|
function lt(n) {
|
|
12
12
|
return new Promise((r) => {
|
|
13
|
-
let
|
|
14
|
-
n.on("data", (t) =>
|
|
13
|
+
let o = "";
|
|
14
|
+
n.on("data", (t) => o += t), n.on("end", () => {
|
|
15
15
|
try {
|
|
16
|
-
r(
|
|
16
|
+
r(o ? JSON.parse(o) : {});
|
|
17
17
|
} catch {
|
|
18
18
|
r({});
|
|
19
19
|
}
|
|
@@ -21,36 +21,36 @@ function lt(n) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
function ct(n) {
|
|
24
|
-
return new Promise((r,
|
|
24
|
+
return new Promise((r, o) => {
|
|
25
25
|
const t = [];
|
|
26
|
-
n.on("data", (c) => t.push(c)), n.on("end", () => r(Buffer.concat(t))), n.on("error",
|
|
26
|
+
n.on("data", (c) => t.push(c)), n.on("end", () => r(Buffer.concat(t))), n.on("error", o);
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
function ut(n, r) {
|
|
30
30
|
if (r) {
|
|
31
|
-
for (const
|
|
32
|
-
const t = n.moduleGraph.getModuleById("\0okno:" +
|
|
31
|
+
for (const o of new Set(r.modules)) {
|
|
32
|
+
const t = n.moduleGraph.getModuleById("\0okno:" + o);
|
|
33
33
|
t && n.moduleGraph.invalidateModule(t);
|
|
34
34
|
}
|
|
35
|
-
for (const
|
|
36
|
-
n.moduleGraph.getModulesByFile(
|
|
35
|
+
for (const o of new Set(r.files))
|
|
36
|
+
n.moduleGraph.getModulesByFile(o)?.forEach((t) => n.moduleGraph.invalidateModule(t));
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
function dt(n, r) {
|
|
40
|
-
n.middlewares.use(async (
|
|
41
|
-
if (!
|
|
42
|
-
const
|
|
43
|
-
method:
|
|
44
|
-
route:
|
|
45
|
-
json: () => lt(
|
|
46
|
-
binary: () => ct(
|
|
40
|
+
n.middlewares.use(async (o, t, c) => {
|
|
41
|
+
if (!o.url?.startsWith("/__okno/api/")) return c();
|
|
42
|
+
const m = o.url.slice(12).split("?")[0], e = {
|
|
43
|
+
method: o.method || "GET",
|
|
44
|
+
route: m,
|
|
45
|
+
json: () => lt(o),
|
|
46
|
+
binary: () => ct(o),
|
|
47
47
|
header: (i) => {
|
|
48
|
-
const s =
|
|
48
|
+
const s = o.headers[i];
|
|
49
49
|
return Array.isArray(s) ? s[0] : s;
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
try {
|
|
53
|
-
const i = await Z(r,
|
|
53
|
+
const i = await Z(r, e);
|
|
54
54
|
if (!i) return c();
|
|
55
55
|
ut(n, i.invalidation), F(t, i.status, i.body);
|
|
56
56
|
} catch (i) {
|
|
@@ -59,14 +59,14 @@ function dt(n, r) {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
function ft(n, r) {
|
|
62
|
-
let
|
|
62
|
+
let o;
|
|
63
63
|
try {
|
|
64
|
-
|
|
64
|
+
o = decodeURIComponent(r);
|
|
65
65
|
} catch {
|
|
66
66
|
return null;
|
|
67
67
|
}
|
|
68
|
-
if (!
|
|
69
|
-
const t = g(n, "files"), c = g(t,
|
|
68
|
+
if (!o || o.includes("\0")) return null;
|
|
69
|
+
const t = g(n, "files"), c = g(t, o);
|
|
70
70
|
return c === t || !c.startsWith(t + D) ? null : c;
|
|
71
71
|
}
|
|
72
72
|
const H = "okno", pt = {
|
|
@@ -91,58 +91,58 @@ const H = "okno", pt = {
|
|
|
91
91
|
".otf": "font/otf"
|
|
92
92
|
};
|
|
93
93
|
function gt(n, r) {
|
|
94
|
-
dt(n, r), n.middlewares.use((
|
|
95
|
-
if (
|
|
96
|
-
const
|
|
97
|
-
if (!
|
|
98
|
-
const
|
|
99
|
-
if (!
|
|
94
|
+
dt(n, r), n.middlewares.use((o, t, c) => {
|
|
95
|
+
if (o.method !== "GET" || !o.url?.startsWith("/okno/files/")) return c();
|
|
96
|
+
const m = o.url.slice(12).split("?")[0];
|
|
97
|
+
if (!m) return c();
|
|
98
|
+
const e = ft(r, m);
|
|
99
|
+
if (!e)
|
|
100
100
|
return t.statusCode = 403, t.end("Forbidden");
|
|
101
|
-
if (!O(
|
|
101
|
+
if (!O(e))
|
|
102
102
|
return t.statusCode = 404, t.end("Not found");
|
|
103
|
-
const i = z(
|
|
104
|
-
t.setHeader("Content-Type", pt[i] || "application/octet-stream"), t.setHeader("Cache-Control", "public, max-age=3600"), t.end(U(
|
|
105
|
-
}), n.middlewares.use(async (
|
|
106
|
-
if (!
|
|
107
|
-
const
|
|
103
|
+
const i = z(e).toLowerCase();
|
|
104
|
+
t.setHeader("Content-Type", pt[i] || "application/octet-stream"), t.setHeader("Cache-Control", "public, max-age=3600"), t.end(U(e));
|
|
105
|
+
}), n.middlewares.use(async (o, t, c) => {
|
|
106
|
+
if (!o.url?.startsWith("/__okno/")) return c();
|
|
107
|
+
const m = o.url.slice(8);
|
|
108
108
|
t.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate"), t.setHeader("Pragma", "no-cache"), t.setHeader("Expires", "0");
|
|
109
109
|
try {
|
|
110
|
-
if (
|
|
110
|
+
if (o.method === "GET" && m === "repo") {
|
|
111
111
|
t.setHeader("Content-Type", "application/json");
|
|
112
112
|
try {
|
|
113
|
-
const
|
|
113
|
+
const e = R(n.config.root), i = (await e.remote(["get-url", "origin"]))?.toString().trim(), s = (await e.revparse(["--abbrev-ref", "HEAD"])).trim(), { owner: f, repo: a } = mt(i);
|
|
114
114
|
return t.end(
|
|
115
115
|
JSON.stringify({ ok: !0, owner: f, repo: a, branch: s || null, remote: i || null })
|
|
116
116
|
);
|
|
117
|
-
} catch (
|
|
118
|
-
return t.end(JSON.stringify({ ok: !1, error: String(
|
|
117
|
+
} catch (e) {
|
|
118
|
+
return t.end(JSON.stringify({ ok: !1, error: String(e) }));
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
if (
|
|
122
|
-
const i = new URL(
|
|
121
|
+
if (o.method === "POST" && m.startsWith("mirror")) {
|
|
122
|
+
const i = new URL(o.url, "http://localhost").searchParams.get("path");
|
|
123
123
|
if (!i || i.includes("..") || !i.startsWith("files/"))
|
|
124
124
|
return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
|
|
125
|
-
const s =
|
|
125
|
+
const s = y(r, i);
|
|
126
126
|
if (O(s))
|
|
127
127
|
return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, skipped: !0 }));
|
|
128
|
-
const f = await ht(
|
|
129
|
-
return M(T(s), { recursive: !0 }),
|
|
128
|
+
const f = await ht(o);
|
|
129
|
+
return M(T(s), { recursive: !0 }), I(s, f), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, written: i, bytes: f.length }));
|
|
130
130
|
}
|
|
131
|
-
if (
|
|
132
|
-
const i = (await yt(
|
|
131
|
+
if (o.method === "POST" && m === "sync") {
|
|
132
|
+
const i = (await yt(o))?.path;
|
|
133
133
|
if (i) {
|
|
134
134
|
if (i.includes("..") || i.includes("\0"))
|
|
135
135
|
return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
|
|
136
|
-
const u =
|
|
136
|
+
const u = y(r, i);
|
|
137
137
|
try {
|
|
138
138
|
const l = R(r);
|
|
139
139
|
await l.fetch("origin", H);
|
|
140
|
-
const
|
|
141
|
-
M(T(u), { recursive: !0 }),
|
|
140
|
+
const h = (await l.revparse(["--show-toplevel"])).trim(), p = N(h, u).split(D).join("/"), w = await l.show([`origin/${H}:${p}`]);
|
|
141
|
+
M(T(u), { recursive: !0 }), I(u, w);
|
|
142
142
|
} catch (l) {
|
|
143
|
-
const
|
|
143
|
+
const h = l instanceof Error ? l.message : String(l);
|
|
144
144
|
console.warn(
|
|
145
|
-
`[okno] sync: could not materialize ${i} from origin/${H} — ${
|
|
145
|
+
`[okno] sync: could not materialize ${i} from origin/${H} — ${h.split(`
|
|
146
146
|
`)[0]}`
|
|
147
147
|
);
|
|
148
148
|
}
|
|
@@ -153,8 +153,8 @@ function gt(n, r) {
|
|
|
153
153
|
const u = await s.pull();
|
|
154
154
|
for (const l of u.files)
|
|
155
155
|
if (l.startsWith(`${a}/`)) {
|
|
156
|
-
const
|
|
157
|
-
A(n,
|
|
156
|
+
const h = l.slice(`${a}/`.length), p = y(r, h);
|
|
157
|
+
A(n, h, p);
|
|
158
158
|
}
|
|
159
159
|
return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, files: u.files }));
|
|
160
160
|
} catch (u) {
|
|
@@ -164,8 +164,8 @@ function gt(n, r) {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
c();
|
|
167
|
-
} catch (
|
|
168
|
-
t.statusCode = 500, t.end(JSON.stringify({ error: String(
|
|
167
|
+
} catch (e) {
|
|
168
|
+
t.statusCode = 500, t.end(JSON.stringify({ error: String(e) }));
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
171
|
}
|
|
@@ -175,49 +175,49 @@ function mt(n) {
|
|
|
175
175
|
return r ? { owner: r[1], repo: r[2] } : { owner: null, repo: null };
|
|
176
176
|
}
|
|
177
177
|
function ht(n) {
|
|
178
|
-
return new Promise((r,
|
|
178
|
+
return new Promise((r, o) => {
|
|
179
179
|
const t = [];
|
|
180
|
-
n.on("data", (c) => t.push(c)), n.on("end", () => r(Buffer.concat(t))), n.on("error",
|
|
180
|
+
n.on("data", (c) => t.push(c)), n.on("end", () => r(Buffer.concat(t))), n.on("error", o);
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
function yt(n) {
|
|
184
184
|
return new Promise((r) => {
|
|
185
|
-
let
|
|
185
|
+
let o = "";
|
|
186
186
|
n.on("data", (t) => {
|
|
187
|
-
|
|
187
|
+
o += t;
|
|
188
188
|
}), n.on("end", () => {
|
|
189
189
|
try {
|
|
190
|
-
r(
|
|
190
|
+
r(o ? JSON.parse(o) : null);
|
|
191
191
|
} catch {
|
|
192
192
|
r(null);
|
|
193
193
|
}
|
|
194
194
|
}), n.on("error", () => r(null));
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
|
-
function A(n, r,
|
|
197
|
+
function A(n, r, o) {
|
|
198
198
|
const t = "\0okno:";
|
|
199
199
|
let c;
|
|
200
200
|
if (r.startsWith("pages/") ? c = t + "pages" : r.startsWith("collections/") ? c = t + "collections" : r.startsWith("globals/") && (c = t + "globals"), c) {
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
|
|
201
|
+
const m = n.moduleGraph.getModuleById(c);
|
|
202
|
+
m && n.moduleGraph.invalidateModule(m);
|
|
203
|
+
const e = n.moduleGraph.getModulesByFile(o);
|
|
204
|
+
e && e.forEach((i) => {
|
|
205
205
|
n.moduleGraph.invalidateModule(i);
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
function wt(n, r) {
|
|
210
|
-
const
|
|
211
|
-
return
|
|
210
|
+
const o = (n.split("?")[0] ?? "").replace(/\\/g, "/"), t = r.replace(/\\/g, "/");
|
|
211
|
+
return o === t || o.startsWith(t + "/");
|
|
212
212
|
}
|
|
213
213
|
function bt(n, r) {
|
|
214
|
-
for (const [
|
|
215
|
-
if (n ===
|
|
216
|
-
if (n.startsWith(
|
|
214
|
+
for (const [o, t] of Object.entries(r)) {
|
|
215
|
+
if (n === o) return t;
|
|
216
|
+
if (n.startsWith(o + "/")) return t + n.slice(o.length);
|
|
217
217
|
}
|
|
218
218
|
return null;
|
|
219
219
|
}
|
|
220
|
-
const St = "okno:", _ = "\0okno:", _t = /* @__PURE__ */ new Set(["pages", "collections", "globals", "locales", "strings", "content"]), K = T(Q(import.meta.url)), Ot = JSON.parse(U(g(K, "../package.json"), "utf-8")).version, L = x(), b = g(K, "../editor"),
|
|
220
|
+
const St = "okno:", _ = "\0okno:", _t = /* @__PURE__ */ new Set(["pages", "collections", "globals", "locales", "strings", "content"]), K = T(Q(import.meta.url)), Ot = JSON.parse(U(g(K, "../package.json"), "utf-8")).version, L = x(), b = g(K, "../editor"), j = g(b, "index.ts"), kt = O(j), vt = {
|
|
221
221
|
"@modules": g(b, "modules"),
|
|
222
222
|
"@lib": g(b, "lib"),
|
|
223
223
|
"@logger": g(b, "lib/logger.svelte.ts"),
|
|
@@ -231,13 +231,13 @@ const St = "okno:", _ = "\0okno:", _t = /* @__PURE__ */ new Set(["pages", "colle
|
|
|
231
231
|
};
|
|
232
232
|
function Tt(n = {}) {
|
|
233
233
|
const r = n.dir ?? "okno";
|
|
234
|
-
let
|
|
234
|
+
let o, t, c = !1, m = !1;
|
|
235
235
|
return n.isEditor, {
|
|
236
236
|
name: "okno",
|
|
237
237
|
enforce: "pre",
|
|
238
|
-
config(
|
|
238
|
+
config(e, i) {
|
|
239
239
|
const s = i.command === "serve";
|
|
240
|
-
return
|
|
240
|
+
return m = i.command === "build", c = s && kt && !n.builtEditor, {
|
|
241
241
|
define: {
|
|
242
242
|
__OKNO_API_URL__: JSON.stringify(n.apiUrl ?? "https://api.okno.build"),
|
|
243
243
|
__OKNO_VERSION__: JSON.stringify(Ot),
|
|
@@ -291,56 +291,56 @@ function Tt(n = {}) {
|
|
|
291
291
|
// editor entry forces that crawl at startup, so those deps land in
|
|
292
292
|
// the first optimize pass and never re-bundle under the user.
|
|
293
293
|
...c && {
|
|
294
|
-
warmup: { clientFiles: [
|
|
294
|
+
warmup: { clientFiles: [j] }
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
};
|
|
298
298
|
},
|
|
299
|
-
configResolved(
|
|
300
|
-
|
|
299
|
+
configResolved(e) {
|
|
300
|
+
o = e.root, t = g(o, r);
|
|
301
301
|
},
|
|
302
302
|
async buildStart() {
|
|
303
303
|
if (O(t)) {
|
|
304
|
-
if (await P(t,
|
|
305
|
-
const
|
|
306
|
-
if (O(
|
|
307
|
-
const i = O(
|
|
308
|
-
g(s) !== g(
|
|
304
|
+
if (await P(t, o), m) {
|
|
305
|
+
const e = y(t, "files");
|
|
306
|
+
if (O(e)) {
|
|
307
|
+
const i = O(y(o, "static")) ? y(o, "static") : y(o, "public"), s = y(i, "okno", "files");
|
|
308
|
+
g(s) !== g(e) && (M(s, { recursive: !0 }), Y(e, s, {
|
|
309
309
|
recursive: !0,
|
|
310
310
|
filter: (f) => !f.endsWith(".okno-tree.json")
|
|
311
311
|
}));
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
if (n.demo) {
|
|
315
|
-
const
|
|
316
|
-
O(
|
|
317
|
-
|
|
315
|
+
const e = y(o, "public");
|
|
316
|
+
O(e) || M(e, { recursive: !0 }), I(
|
|
317
|
+
y(e, "okno-demo.json"),
|
|
318
318
|
JSON.stringify(rt(t))
|
|
319
319
|
);
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
},
|
|
323
|
-
configureServer(
|
|
324
|
-
gt(
|
|
323
|
+
configureServer(e) {
|
|
324
|
+
gt(e, t);
|
|
325
325
|
const i = (f) => {
|
|
326
326
|
const a = N(t, f);
|
|
327
327
|
if (a.startsWith("..") || !a.endsWith(".ts")) return;
|
|
328
328
|
const u = a.split(/[\\/]/)[0];
|
|
329
329
|
if (u !== "pages" && u !== "collections" && u !== "globals") return;
|
|
330
|
-
const l =
|
|
331
|
-
l &&
|
|
330
|
+
const l = e.moduleGraph.getModuleById(_ + u);
|
|
331
|
+
l && e.moduleGraph.invalidateModule(l), e.moduleGraph.getModulesByFile(f)?.forEach((h) => e.moduleGraph.invalidateModule(h)), !$(f) && e.ws.send({ type: "full-reload" });
|
|
332
332
|
};
|
|
333
|
-
|
|
333
|
+
e.watcher.on("add", i), e.watcher.on("unlink", i), e.middlewares.use("/__okno/imports", async (f, a, u) => {
|
|
334
334
|
if (f.method !== "GET") return u();
|
|
335
335
|
try {
|
|
336
|
-
const [l,
|
|
337
|
-
E(
|
|
338
|
-
E(
|
|
339
|
-
E(
|
|
336
|
+
const [l, h, p] = await Promise.all([
|
|
337
|
+
E(o, "pages"),
|
|
338
|
+
E(o, "globals"),
|
|
339
|
+
E(o, "collections")
|
|
340
340
|
]);
|
|
341
341
|
a.setHeader("Content-Type", "application/json"), a.setHeader("Cache-Control", "no-store"), a.end(JSON.stringify({
|
|
342
342
|
pages: Array.from(l),
|
|
343
|
-
globals: Array.from(
|
|
343
|
+
globals: Array.from(h),
|
|
344
344
|
collections: Array.from(p)
|
|
345
345
|
}));
|
|
346
346
|
} catch (l) {
|
|
@@ -348,9 +348,9 @@ function Tt(n = {}) {
|
|
|
348
348
|
}
|
|
349
349
|
});
|
|
350
350
|
const s = "/__okno_bootstrap.js";
|
|
351
|
-
|
|
351
|
+
e.middlewares.use(s, async (f, a, u) => {
|
|
352
352
|
try {
|
|
353
|
-
const l = await
|
|
353
|
+
const l = await e.transformRequest("\0okno:bootstrap");
|
|
354
354
|
if (!l) {
|
|
355
355
|
a.statusCode = 500, a.end("okno bootstrap transform failed");
|
|
356
356
|
return;
|
|
@@ -359,15 +359,15 @@ function Tt(n = {}) {
|
|
|
359
359
|
} catch (l) {
|
|
360
360
|
u(l);
|
|
361
361
|
}
|
|
362
|
-
}),
|
|
363
|
-
const l = "<script>window.__oknoDev=true<\/script>",
|
|
362
|
+
}), e.middlewares.use((f, a, u) => {
|
|
363
|
+
const l = "<script>window.__oknoDev=true<\/script>", h = n.demo ? "<script>window.__oknoDemo=true<\/script>" : "", p = `${l}${h}<script type="module" src="${s}"><\/script>`, w = [];
|
|
364
364
|
let k = null;
|
|
365
|
-
const V = a.write.bind(a),
|
|
365
|
+
const V = a.write.bind(a), B = a.end.bind(a), X = a.setHeader.bind(a), G = () => {
|
|
366
366
|
const d = a.getHeader("content-type");
|
|
367
367
|
return typeof d == "string" && d.includes("text/html");
|
|
368
368
|
}, W = (d, S) => Buffer.isBuffer(d) ? d : d instanceof Uint8Array ? Buffer.from(d.buffer, d.byteOffset, d.byteLength) : typeof d == "string" ? Buffer.from(d, S || "utf-8") : Buffer.from(String(d));
|
|
369
369
|
a.write = (d, S, ...C) => (k === null && (k = G()), k ? (d && w.push(W(d, typeof S == "string" ? S : void 0)), !0) : V(d, S, ...C)), a.end = (d, S, ...C) => {
|
|
370
|
-
if (k === null && (k = G()), !k) return
|
|
370
|
+
if (k === null && (k = G()), !k) return B(d, S, ...C);
|
|
371
371
|
d && w.push(W(d, typeof S == "string" ? S : void 0));
|
|
372
372
|
let v = Buffer.concat(w).toString("utf-8");
|
|
373
373
|
v.includes(p) || (v = v.includes("</body>") ? v.replace("</body>", `${p}</body>`) : v + p);
|
|
@@ -377,57 +377,85 @@ function Tt(n = {}) {
|
|
|
377
377
|
X("content-length", String(J.length));
|
|
378
378
|
} catch {
|
|
379
379
|
}
|
|
380
|
-
return
|
|
380
|
+
return B(J, ...C);
|
|
381
381
|
}, u();
|
|
382
382
|
});
|
|
383
383
|
},
|
|
384
|
-
async handleHotUpdate(
|
|
385
|
-
const i =
|
|
386
|
-
if (
|
|
387
|
-
await P(t,
|
|
384
|
+
async handleHotUpdate(e) {
|
|
385
|
+
const i = y(t, "schema.ts"), s = y(t, "users.json"), f = y(t, "permissions.ts"), a = y(t, "modules.d.ts");
|
|
386
|
+
if (e.file === i) {
|
|
387
|
+
await P(t, o);
|
|
388
388
|
for (const p of ["pages", "collections", "globals", "locales", "content", "strings"]) {
|
|
389
|
-
const w =
|
|
390
|
-
w &&
|
|
389
|
+
const w = e.server.moduleGraph.getModuleById(_ + p);
|
|
390
|
+
w && e.server.moduleGraph.invalidateModule(w);
|
|
391
391
|
}
|
|
392
392
|
return [];
|
|
393
393
|
}
|
|
394
|
-
if (
|
|
394
|
+
if (e.file === s || e.file === f || e.file === a)
|
|
395
395
|
return [];
|
|
396
|
-
const u =
|
|
397
|
-
if (
|
|
398
|
-
await P(t,
|
|
396
|
+
const u = y(t, "strings.ts"), l = N(y(t, "strings"), e.file);
|
|
397
|
+
if (e.file === u || !l.startsWith("..") && l.endsWith(".ts")) {
|
|
398
|
+
await P(t, o);
|
|
399
399
|
for (const p of ["strings", "content"]) {
|
|
400
|
-
const w =
|
|
401
|
-
w &&
|
|
400
|
+
const w = e.server.moduleGraph.getModuleById(_ + p);
|
|
401
|
+
w && e.server.moduleGraph.invalidateModule(w);
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
|
-
const
|
|
405
|
-
if (!
|
|
406
|
-
const p =
|
|
407
|
-
if ((p === "pages" || p === "collections" || p === "globals") && $(
|
|
408
|
-
const w =
|
|
409
|
-
return w &&
|
|
404
|
+
const h = N(t, e.file);
|
|
405
|
+
if (!h.startsWith("..") && h.endsWith(".ts")) {
|
|
406
|
+
const p = h.split(/[\\/]/)[0];
|
|
407
|
+
if ((p === "pages" || p === "collections" || p === "globals") && $(e.file)) {
|
|
408
|
+
const w = e.server.moduleGraph.getModuleById(_ + p);
|
|
409
|
+
return w && e.server.moduleGraph.invalidateModule(w), [];
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
412
|
},
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
413
|
+
// PRODUCTION boot for index.html frameworks (plain Vite, Solid, …). In dev
|
|
414
|
+
// the `configureServer` middleware injects the editor; that middleware never
|
|
415
|
+
// runs in a build, so a deployed page would ship no editor. `transformIndexHtml`
|
|
416
|
+
// fires only for frameworks whose HTML goes through Vite's index.html pipeline
|
|
417
|
+
// — Astro/SvelteKit/Nuxt own their HTML and bypass this hook, so they wire boot
|
|
418
|
+
// their own way (an Astro integration, a +layout import, a Nuxt client plugin).
|
|
419
|
+
// The inline `import "okno/boot"` is a real module script, so Vite bundles it +
|
|
420
|
+
// code-splits the editor behind boot's press-`e`/`?okno` gate.
|
|
421
|
+
transformIndexHtml: {
|
|
422
|
+
// `pre`, so the inline module script is present BEFORE Vite's core HTML
|
|
423
|
+
// plugin collects + bundles page scripts — otherwise the bare
|
|
424
|
+
// `import "okno/boot"` survives unbundled and 404s in the browser.
|
|
425
|
+
order: "pre",
|
|
426
|
+
handler(e) {
|
|
427
|
+
if (m)
|
|
428
|
+
return {
|
|
429
|
+
html: e,
|
|
430
|
+
tags: [
|
|
431
|
+
{
|
|
432
|
+
tag: "script",
|
|
433
|
+
attrs: { type: "module" },
|
|
434
|
+
children: 'import "okno/boot"',
|
|
435
|
+
injectTo: "body"
|
|
436
|
+
}
|
|
437
|
+
]
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
async resolveId(e, i) {
|
|
442
|
+
if (e.startsWith(St))
|
|
443
|
+
return "\0" + e;
|
|
444
|
+
if (e.startsWith("okno/")) {
|
|
445
|
+
const s = e.slice(5);
|
|
418
446
|
if (_t.has(s)) return _ + s;
|
|
419
447
|
}
|
|
420
|
-
if (c &&
|
|
421
|
-
return
|
|
448
|
+
if (c && e === "okno/editor")
|
|
449
|
+
return j;
|
|
422
450
|
if (c && i && wt(i, b)) {
|
|
423
|
-
const s = bt(
|
|
451
|
+
const s = bt(e, vt);
|
|
424
452
|
if (s)
|
|
425
453
|
return (await this.resolve(s, i, { skipSelf: !0 }))?.id;
|
|
426
454
|
}
|
|
427
455
|
},
|
|
428
|
-
async load(
|
|
429
|
-
if (!
|
|
430
|
-
const i =
|
|
456
|
+
async load(e) {
|
|
457
|
+
if (!e.startsWith(_)) return;
|
|
458
|
+
const i = e.slice(_.length);
|
|
431
459
|
if (i === "runtime") {
|
|
432
460
|
if (!L)
|
|
433
461
|
throw new Error("okno: runtime/wrap.js missing — run `bun run build:pkg`");
|
|
@@ -436,15 +464,15 @@ function Tt(n = {}) {
|
|
|
436
464
|
if (i === "bootstrap")
|
|
437
465
|
return 'import("okno/editor")';
|
|
438
466
|
if (i === "pages") {
|
|
439
|
-
const s = await E(
|
|
467
|
+
const s = await E(o, "pages");
|
|
440
468
|
return await q(t, s);
|
|
441
469
|
}
|
|
442
470
|
if (i === "collections") {
|
|
443
|
-
const s = await E(
|
|
444
|
-
return await tt(t, s,
|
|
471
|
+
const s = await E(o, "collections");
|
|
472
|
+
return await tt(t, s, m);
|
|
445
473
|
}
|
|
446
474
|
if (i === "globals") {
|
|
447
|
-
const s = await E(
|
|
475
|
+
const s = await E(o, "globals");
|
|
448
476
|
return await et(t, s);
|
|
449
477
|
}
|
|
450
478
|
if (i === "locales")
|
package/dist/runtime/wrap.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/** Register the build-time media map (idempotent; every content module calls it
|
|
2
2
|
* with the same glob, so last-write-wins is a no-op). */
|
|
3
3
|
export declare function __oknoSetImages(map: Record<string, unknown>): void;
|
|
4
|
+
/** Register the collection route patterns from the project schema (idempotent —
|
|
5
|
+
* every content module passes the same schema). */
|
|
6
|
+
export declare function __oknoSetRoutes(schema: unknown): void;
|
|
4
7
|
/**
|
|
5
8
|
* Scheduled-publishing visibility gate. An item is visible unless its
|
|
6
9
|
* `publishAt` is still in the future or its `unpublishAt` has already passed.
|
|
@@ -116,7 +119,27 @@ export interface OknoStructureDetail {
|
|
|
116
119
|
* item's text leaves (so a new reference shows the linked item's content;
|
|
117
120
|
* block defaults are empty so the clone is just cleared). */
|
|
118
121
|
values?: Record<string, string>;
|
|
122
|
+
/** insert (references only): re-point the clone's links from the TEMPLATE
|
|
123
|
+
* item's route to the new item's. A card usually links to the item it renders
|
|
124
|
+
* (`<a href={`/ref/${ref.slug}`}>`), but that href is a plain template
|
|
125
|
+
* expression — okno never sees it as a field, so the clone would keep pointing
|
|
126
|
+
* at the neighbour it was cloned from. The editor resolves both routes from
|
|
127
|
+
* the collection's `url` pattern. */
|
|
128
|
+
href?: {
|
|
129
|
+
from: string;
|
|
130
|
+
to: string;
|
|
131
|
+
};
|
|
119
132
|
}
|
|
133
|
+
/** Escape a list path for embedding in a `data-okno(-item)` matcher regex. */
|
|
134
|
+
export declare function escapeReg(s: string): string;
|
|
135
|
+
/** The reorder unit for an element that is (or sits inside/around) a member of
|
|
136
|
+
* `list`. Exported so the editor's grip logic groups by the SAME unit the
|
|
137
|
+
* structural ops move — otherwise the grip and the move disagree. */
|
|
138
|
+
export declare function __oknoUnitOf(list: string, member: Element): HTMLElement | null;
|
|
139
|
+
/** The array index a unit carries — read from the unit itself when it holds the
|
|
140
|
+
* marker, otherwise from the boundary nested inside it. Null when the element
|
|
141
|
+
* isn't a member of `list` at all (so it can double as a membership test). */
|
|
142
|
+
export declare function __oknoUnitIndex(list: string, unit: Element): number | null;
|
|
120
143
|
/**
|
|
121
144
|
* Apply a structural op to the live DOM. Attached to `okno:structure` by
|
|
122
145
|
* `__oknoInitStructure()`. The editor calls `updateField` for its optimistic
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../src/runtime/wrap.ts"],"names":[],"mappings":"AAgCA;0DAC0D;AAC1D,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAElE;
|
|
1
|
+
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../src/runtime/wrap.ts"],"names":[],"mappings":"AAgCA;0DAC0D;AAC1D,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAElE;AAWD;oDACoD;AACpD,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CASrD;AA6BD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,GAAE,MAAmB,GAAG,OAAO,CAQ7E;AAiHD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC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