okno 1.0.0-beta.16 → 1.0.0-beta.17

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,9 +1,12 @@
1
1
  /**
2
2
  * Walk the project root looking for `import { foo, bar } from "okno:<kind>"`
3
- * statements and return the union of imported names. Used by both the runtime
4
- * virtual modules and the type codegen to emit placeholder exports for content
5
- * that doesn't exist yet, so a project can refer to `home.title` (and get types
6
- * for it) before any schema is scaffolded.
3
+ * (or the colon-free `okno/<kind>` token) statements and return the union of
4
+ * imported names. Used by both the runtime virtual modules and the type codegen
5
+ * to emit placeholder exports for content that doesn't exist yet, so a project
6
+ * can refer to `home.title` (and get types for it) before any schema is
7
+ * scaffolded — including for an optional/unscaffolded name (e.g. a `theme`
8
+ * global). Matches BOTH the `okno:` (Vite virtual) and `okno/` (Next/tsconfig
9
+ * paths) forms so the placeholder emits regardless of which token a page uses.
7
10
  */
8
11
  export declare function scanImports(root: string, kind: "pages" | "collections" | "globals"): Promise<Set<string>>;
9
12
  //# sourceMappingURL=scan-imports.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scan-imports.d.ts","sourceRoot":"","sources":["../../src/codegen/scan-imports.ts"],"names":[],"mappings":"AAiBA;;;;;;GAMG;AACH,wBAAsB,WAAW,CAChC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,GACvC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CA0CtB"}
1
+ {"version":3,"file":"scan-imports.d.ts","sourceRoot":"","sources":["../../src/codegen/scan-imports.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAChC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,GACvC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CA0CtB"}
@@ -20,7 +20,7 @@ const Te = /* @__PURE__ */ new Set([".astro", ".svelte", ".ts", ".tsx", ".js", "
20
20
  ".turbo"
21
21
  ]);
22
22
  async function X(e, n) {
23
- const t = new RegExp(`import\\s*\\{([^}]+)\\}\\s*from\\s*["']okno:${n}["']`, "g"), s = /* @__PURE__ */ new Set();
23
+ const t = new RegExp(`import\\s*\\{([^}]+)\\}\\s*from\\s*["']okno[:/]${n}["']`, "g"), s = /* @__PURE__ */ new Set();
24
24
  async function a(r) {
25
25
  let l;
26
26
  try {
@@ -45,7 +45,7 @@ async function X(e, n) {
45
45
  } catch {
46
46
  continue;
47
47
  }
48
- if (c.includes(`okno:${n}`))
48
+ if (!(!c.includes(`okno:${n}`) && !c.includes(`okno/${n}`)))
49
49
  for (const m of c.matchAll(t)) {
50
50
  const d = m[1] ?? "";
51
51
  for (const h of d.split(",")) {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { o as a } from "./plugin-DrRr35Ph.js";
1
+ import { o as a } from "./plugin-CPJpdY5k.js";
2
2
  export {
3
3
  a as okno
4
4
  };
@@ -6,6 +6,9 @@ export interface WithOknoOptions {
6
6
  * (App Router private folder). Default "oknoapi"; match your route file
7
7
  * `app/<apiMount>/[...okno]/route.ts`. */
8
8
  apiMount?: string;
9
+ /** The okno backend the editor talks to (`__OKNO_API_URL__`). Defaults to
10
+ * `https://api.okno.build`; point at staging for a test deploy. */
11
+ apiUrl?: string;
9
12
  }
10
13
  /** Wrap a Next config so okno's dev API is reachable and its codegen runs. The
11
14
  * user's config is preserved; okno adds the rewrite + a boot side effect. */
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/next/config.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAapD,MAAM,WAAW,eAAe;IAC/B,4EAA4E;IAC5E,GAAG,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IACvB;;+CAE2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAsBD;8EAC8E;AAC9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAE,CAAW,EAAE,OAAO,GAAE,eAAoB,GAAG,CAAC,CAuCrF"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/next/config.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AA4BpD,MAAM,WAAW,eAAe;IAC/B,4EAA4E;IAC5E,GAAG,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IACvB;;+CAE2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;wEACoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;CACf;AAiDD;8EAC8E;AAC9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAE,CAAW,EAAE,OAAO,GAAE,eAAoB,GAAG,CAAC,CA4CrF"}
@@ -1,16 +1,17 @@
1
- import { join as c, relative as E, sep as w, resolve as h } from "node:path";
2
- import { existsSync as k, watch as M, mkdirSync as A, cpSync as C } from "node:fs";
3
- import { s as g, b as R, a as N, c as P, d as F, e as I, g as L, I as T, f as $, h as B, i as D } from "../dispatch-C34WXMSB.js";
4
- import { mkdir as G, writeFile as u } from "node:fs/promises";
5
- const U = (o) => o.replaceAll(T, "__oknoSetImages(undefined)"), x = (o) => {
6
- let n = o;
7
- for (const [t, e] of Object.entries(J))
8
- n = n.replaceAll(`"${t}"`, `"./${e}"`).replaceAll(`'${t}'`, `'./${e}'`);
9
- return n;
10
- }, z = (o, n, t) => {
11
- const e = E(t, n).split(w).join("/");
12
- return o.replaceAll(n.split(w).join("/"), e);
13
- }, J = {
1
+ import { join as c, relative as N, sep as y, resolve as _, dirname as E } from "node:path";
2
+ import { existsSync as w, watch as R, readFileSync as M, mkdirSync as A, cpSync as P } from "node:fs";
3
+ import { fileURLToPath as C } from "node:url";
4
+ import { s as g, b as J, a as D, c as I, d as U, e as L, g as F, I as K, f as T, h as V, i as $ } from "../dispatch-DFdYV0q0.js";
5
+ import { mkdir as B, writeFile as f } from "node:fs/promises";
6
+ const G = (n) => n.replaceAll(K, "__oknoSetImages(undefined)"), z = (n) => {
7
+ let t = n;
8
+ for (const [o, e] of Object.entries(W))
9
+ t = t.replaceAll(`"${o}"`, `"./${e}"`).replaceAll(`'${o}'`, `'./${e}'`);
10
+ return t;
11
+ }, H = (n, t, o) => {
12
+ const e = N(o, t).split(y).join("/");
13
+ return n.replaceAll(t.split(y).join("/"), e);
14
+ }, W = {
14
15
  "okno:pages": "pages.js",
15
16
  "okno:collections": "collections.js",
16
17
  "okno:globals": "globals.js",
@@ -19,113 +20,138 @@ const U = (o) => o.replaceAll(T, "__oknoSetImages(undefined)"), x = (o) => {
19
20
  "okno:content": "content.js",
20
21
  "okno:runtime": "runtime.js"
21
22
  };
22
- async function H(o, n, t = {}) {
23
- const e = c(n, t.outDir ?? ".okno"), a = t.isBuild ?? process.env.NODE_ENV === "production";
24
- await G(e, { recursive: !0 });
25
- const [s, r, l] = await Promise.all([
26
- g(n, "pages"),
27
- g(n, "collections"),
28
- g(n, "globals")
29
- ]), [i, p, f, m] = await Promise.all([
30
- R(o, s),
31
- N(o, r, a),
32
- P(o, l),
33
- F(o)
34
- ]), v = I(o), O = $(), S = L() ?? 'throw new Error("okno: runtime/wrap.js missing — run \\`bun run build:pkg\\`")', d = (_) => z(x(U(_)), o, e);
23
+ async function x(n, t, o = {}) {
24
+ const e = c(t, o.outDir ?? ".okno"), s = o.isBuild ?? process.env.NODE_ENV === "production";
25
+ await B(e, { recursive: !0 });
26
+ const [r, i, a] = await Promise.all([
27
+ g(t, "pages"),
28
+ g(t, "collections"),
29
+ g(t, "globals")
30
+ ]), [u, l, d, m] = await Promise.all([
31
+ J(n, r),
32
+ D(n, i, s),
33
+ I(n, a),
34
+ U(n)
35
+ ]), b = L(n), j = T(), S = F() ?? 'throw new Error("okno: runtime/wrap.js missing — run \\`bun run build:pkg\\`")', p = (v) => H(z(G(v)), n, e);
35
36
  await Promise.all([
36
- u(c(e, "pages.js"), d(i)),
37
- u(c(e, "collections.js"), d(p)),
38
- u(c(e, "globals.js"), d(f)),
39
- u(c(e, "locales.js"), d(v)),
40
- u(c(e, "strings.js"), d(m)),
41
- u(c(e, "content.js"), d(O)),
42
- u(c(e, "runtime.js"), S)
37
+ f(c(e, "pages.js"), p(u)),
38
+ f(c(e, "collections.js"), p(l)),
39
+ f(c(e, "globals.js"), p(d)),
40
+ f(c(e, "locales.js"), p(b)),
41
+ f(c(e, "strings.js"), p(m)),
42
+ f(c(e, "content.js"), p(j)),
43
+ f(c(e, "runtime.js"), S)
43
44
  ]);
44
45
  }
45
- function V(o, n) {
46
- const t = c(o, "files");
47
- if (!k(t)) return;
48
- const e = c(n, "public", "okno", "files");
49
- A(e, { recursive: !0 }), C(t, e, { recursive: !0, filter: (a) => !a.endsWith(".okno-tree.json") });
46
+ function Q() {
47
+ const n = E(C(import.meta.url));
48
+ for (const t of ["../package.json", "../../package.json"])
49
+ try {
50
+ return JSON.parse(M(_(n, t), "utf-8")).version ?? "0.0.0";
51
+ } catch {
52
+ }
53
+ return "0.0.0";
54
+ }
55
+ function X(n, t) {
56
+ const o = c(n, "files");
57
+ if (!w(o)) return;
58
+ const e = c(t, "public", "okno", "files");
59
+ A(e, { recursive: !0 }), P(o, e, { recursive: !0, filter: (s) => !s.endsWith(".okno-tree.json") });
60
+ }
61
+ function Y(n) {
62
+ return {
63
+ __OKNO_API_URL__: JSON.stringify(n),
64
+ __OKNO_VERSION__: JSON.stringify(Q()),
65
+ __OKNO_IS_DEV__: JSON.stringify(!1),
66
+ __OKNO_DEMO__: JSON.stringify(!1),
67
+ __OKNO_REPO__: JSON.stringify(null)
68
+ };
69
+ }
70
+ function Z(n, t) {
71
+ return (o, e) => (o.plugins = o.plugins ?? [], o.plugins.push(new e.webpack.DefinePlugin(t)), typeof n == "function" ? n(o, e) : o);
50
72
  }
51
- function K(o, n) {
52
- const t = { source: "/__okno/api/:path*", destination: `/${n}/:path*` };
73
+ function q(n, t) {
74
+ const o = { source: "/__okno/api/:path*", destination: `/${t}/:path*` };
53
75
  return async () => {
54
- const e = typeof o == "function" ? await o() : void 0;
55
- return e ? Array.isArray(e) ? [t, ...e] : { ...e, beforeFiles: [t, ...e.beforeFiles ?? []] } : [t];
76
+ const e = typeof n == "function" ? await n() : void 0;
77
+ return e ? Array.isArray(e) ? [o, ...e] : { ...e, beforeFiles: [o, ...e.beforeFiles ?? []] } : [o];
56
78
  };
57
79
  }
58
- let y = !1;
59
- function ee(o = {}, n = {}) {
60
- const t = n.apiMount ?? "oknoapi", e = o, a = {
61
- ...e,
62
- rewrites: K(e.rewrites, t)
80
+ let O = !1;
81
+ function ae(n = {}, t = {}) {
82
+ const o = t.apiMount ?? "oknoapi", e = t.apiUrl ?? "https://api.okno.build", s = n, r = {
83
+ ...s,
84
+ rewrites: q(s.rewrites, o),
85
+ // Bake the editor's compile-time globals (webpack `next build`) so it doesn't
86
+ // throw `__OKNO_API_URL__ is not defined` on boot. (Turbopack dev has no
87
+ // DefinePlugin equivalent yet — the deployed demo is a webpack build.)
88
+ webpack: Z(s.webpack, Y(e))
63
89
  };
64
- if (!y) {
65
- y = !0;
66
- const s = process.cwd(), r = h(s, n.dir ?? "okno");
67
- if (k(r)) {
68
- const l = () => {
69
- B(r, s).catch((i) => console.warn("[okno] type codegen failed:", i)), H(r, s).catch((i) => console.warn("[okno] module codegen failed:", i));
90
+ if (!O) {
91
+ O = !0;
92
+ const i = process.cwd(), a = _(i, t.dir ?? "okno");
93
+ if (w(a)) {
94
+ const u = () => {
95
+ V(a, i).catch((l) => console.warn("[okno] type codegen failed:", l)), x(a, i).catch((l) => console.warn("[okno] module codegen failed:", l));
70
96
  try {
71
- V(r, s);
72
- } catch (i) {
73
- console.warn("[okno] media copy failed:", i);
97
+ X(a, i);
98
+ } catch (l) {
99
+ console.warn("[okno] media copy failed:", l);
74
100
  }
75
101
  };
76
- if (l(), process.env.NODE_ENV !== "production")
102
+ if (u(), process.env.NODE_ENV !== "production")
77
103
  try {
78
- M(r, { recursive: !0 }, () => l());
104
+ R(a, { recursive: !0 }, () => u());
79
105
  } catch {
80
106
  }
81
107
  }
82
108
  }
83
- return a;
109
+ return r;
84
110
  }
85
- const b = { "Content-Type": "application/json", "Cache-Control": "no-store" };
86
- function W(o) {
87
- return h(o?.root ?? process.cwd(), o?.dir ?? "okno");
111
+ const h = { "Content-Type": "application/json", "Cache-Control": "no-store" };
112
+ function ee(n) {
113
+ return _(n?.root ?? process.cwd(), n?.dir ?? "okno");
88
114
  }
89
- function j() {
90
- return new Response(JSON.stringify({ error: "Not found" }), { status: 404, headers: b });
115
+ function k() {
116
+ return new Response(JSON.stringify({ error: "Not found" }), { status: 404, headers: h });
91
117
  }
92
- async function Q(o, n) {
93
- const t = n?.params ? await n.params : void 0;
94
- if (t) {
95
- const s = t.okno ?? Object.values(t)[0];
96
- if (Array.isArray(s)) return s.join("/");
97
- if (typeof s == "string") return s;
118
+ async function ne(n, t) {
119
+ const o = t?.params ? await t.params : void 0;
120
+ if (o) {
121
+ const r = o.okno ?? Object.values(o)[0];
122
+ if (Array.isArray(r)) return r.join("/");
123
+ if (typeof r == "string") return r;
98
124
  }
99
- const e = "/__okno/api/", a = new URL(o.url).pathname.indexOf(e);
100
- return a === -1 ? null : new URL(o.url).pathname.slice(a + e.length);
125
+ const e = "/__okno/api/", s = new URL(n.url).pathname.indexOf(e);
126
+ return s === -1 ? null : new URL(n.url).pathname.slice(s + e.length);
101
127
  }
102
- function oe(o) {
103
- const n = W(o), t = async (e, a) => {
104
- const s = await Q(e, a);
105
- if (s == null) return j();
106
- let r, l = !1, i;
107
- const p = {
128
+ function ce(n) {
129
+ const t = ee(n), o = async (e, s) => {
130
+ const r = await ne(e, s);
131
+ if (r == null) return k();
132
+ let i, a = !1, u;
133
+ const l = {
108
134
  method: e.method,
109
- route: s,
135
+ route: r,
110
136
  json: async () => {
111
- if (!l) {
112
- l = !0;
137
+ if (!a) {
138
+ a = !0;
113
139
  try {
114
- r = await e.json();
140
+ i = await e.json();
115
141
  } catch {
116
- r = {};
142
+ i = {};
117
143
  }
118
144
  }
119
- return r ?? {};
145
+ return i ?? {};
120
146
  },
121
- binary: async () => (i === void 0 && (i = Buffer.from(await e.arrayBuffer())), i),
147
+ binary: async () => (u === void 0 && (u = Buffer.from(await e.arrayBuffer())), u),
122
148
  header: (m) => e.headers.get(m) ?? void 0
123
- }, f = await D(n, p);
124
- return f ? new Response(JSON.stringify(f.body), { status: f.status, headers: b }) : j();
149
+ }, d = await $(t, l);
150
+ return d ? new Response(JSON.stringify(d.body), { status: d.status, headers: h }) : k();
125
151
  };
126
- return { GET: t, POST: t };
152
+ return { GET: o, POST: o };
127
153
  }
128
154
  export {
129
- oe as createOknoRouteHandler,
130
- ee as withOkno
155
+ ce as createOknoRouteHandler,
156
+ ae as withOkno
131
157
  };