okno 1.0.0-beta.15 → 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-DmiwHDt_.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;AAEpD,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,CAkCrF"}
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 l, relative as E, sep as w, resolve as b } from "node:path";
2
- import { existsSync as S, watch as A } from "node:fs";
3
- import { s as g, b as M, a as C, c as R, d as N, e as P, g as F, I, f as L, h as T, i as $ } from "../dispatch-C34WXMSB.js";
4
- import { mkdir as B, writeFile as u } from "node:fs/promises";
5
- const G = (o) => o.replaceAll(I, "__oknoSetImages(undefined)"), U = (o) => {
6
- let n = o;
7
- for (const [t, e] of Object.entries(z))
8
- n = n.replaceAll(`"${t}"`, `"./${e}"`).replaceAll(`'${t}'`, `'./${e}'`);
9
- return n;
10
- }, x = (o, n, t) => {
11
- const e = E(t, n).split(w).join("/");
12
- return o.replaceAll(n.split(w).join("/"), e);
13
- }, z = {
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,102 +20,138 @@ const G = (o) => o.replaceAll(I, "__oknoSetImages(undefined)"), U = (o) => {
19
20
  "okno:content": "content.js",
20
21
  "okno:runtime": "runtime.js"
21
22
  };
22
- async function D(o, n, t = {}) {
23
- const e = l(n, t.outDir ?? ".okno"), a = t.isBuild ?? process.env.NODE_ENV === "production";
23
+ async function x(n, t, o = {}) {
24
+ const e = c(t, o.outDir ?? ".okno"), s = o.isBuild ?? process.env.NODE_ENV === "production";
24
25
  await B(e, { recursive: !0 });
25
- const [s, r, c] = await Promise.all([
26
- g(n, "pages"),
27
- g(n, "collections"),
28
- g(n, "globals")
29
- ]), [i, p, f, m] = await Promise.all([
30
- M(o, s),
31
- C(o, r, a),
32
- R(o, c),
33
- N(o)
34
- ]), k = P(o), v = L(), O = F() ?? 'throw new Error("okno: runtime/wrap.js missing — run \\`bun run build:pkg\\`")', d = (_) => x(U(G(_)), o, e);
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(l(e, "pages.js"), d(i)),
37
- u(l(e, "collections.js"), d(p)),
38
- u(l(e, "globals.js"), d(f)),
39
- u(l(e, "locales.js"), d(k)),
40
- u(l(e, "strings.js"), d(m)),
41
- u(l(e, "content.js"), d(v)),
42
- u(l(e, "runtime.js"), O)
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 J(o, n) {
46
- const t = { source: "/__okno/api/:path*", destination: `/${n}/:path*` };
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);
72
+ }
73
+ function q(n, t) {
74
+ const o = { source: "/__okno/api/:path*", destination: `/${t}/:path*` };
47
75
  return async () => {
48
- const e = typeof o == "function" ? await o() : void 0;
49
- 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];
50
78
  };
51
79
  }
52
- let j = !1;
53
- function Y(o = {}, n = {}) {
54
- const t = n.apiMount ?? "oknoapi", e = o, a = {
55
- ...e,
56
- rewrites: J(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))
57
89
  };
58
- if (!j) {
59
- j = !0;
60
- const s = process.cwd(), r = b(s, n.dir ?? "okno");
61
- if (S(r)) {
62
- const c = () => {
63
- T(r, s).catch((i) => console.warn("[okno] type codegen failed:", i)), D(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));
96
+ try {
97
+ X(a, i);
98
+ } catch (l) {
99
+ console.warn("[okno] media copy failed:", l);
100
+ }
64
101
  };
65
- if (c(), process.env.NODE_ENV !== "production")
102
+ if (u(), process.env.NODE_ENV !== "production")
66
103
  try {
67
- A(r, { recursive: !0 }, () => c());
104
+ R(a, { recursive: !0 }, () => u());
68
105
  } catch {
69
106
  }
70
107
  }
71
108
  }
72
- return a;
109
+ return r;
73
110
  }
74
- const y = { "Content-Type": "application/json", "Cache-Control": "no-store" };
75
- function H(o) {
76
- return b(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");
77
114
  }
78
- function h() {
79
- return new Response(JSON.stringify({ error: "Not found" }), { status: 404, headers: y });
115
+ function k() {
116
+ return new Response(JSON.stringify({ error: "Not found" }), { status: 404, headers: h });
80
117
  }
81
- async function V(o, n) {
82
- const t = n?.params ? await n.params : void 0;
83
- if (t) {
84
- const s = t.okno ?? Object.values(t)[0];
85
- if (Array.isArray(s)) return s.join("/");
86
- 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;
87
124
  }
88
- const e = "/__okno/api/", a = new URL(o.url).pathname.indexOf(e);
89
- 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);
90
127
  }
91
- function Z(o) {
92
- const n = H(o), t = async (e, a) => {
93
- const s = await V(e, a);
94
- if (s == null) return h();
95
- let r, c = !1, i;
96
- 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 = {
97
134
  method: e.method,
98
- route: s,
135
+ route: r,
99
136
  json: async () => {
100
- if (!c) {
101
- c = !0;
137
+ if (!a) {
138
+ a = !0;
102
139
  try {
103
- r = await e.json();
140
+ i = await e.json();
104
141
  } catch {
105
- r = {};
142
+ i = {};
106
143
  }
107
144
  }
108
- return r ?? {};
145
+ return i ?? {};
109
146
  },
110
- 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),
111
148
  header: (m) => e.headers.get(m) ?? void 0
112
- }, f = await $(n, p);
113
- return f ? new Response(JSON.stringify(f.body), { status: f.status, headers: y }) : h();
149
+ }, d = await $(t, l);
150
+ return d ? new Response(JSON.stringify(d.body), { status: d.status, headers: h }) : k();
114
151
  };
115
- return { GET: t, POST: t };
152
+ return { GET: o, POST: o };
116
153
  }
117
154
  export {
118
- Z as createOknoRouteHandler,
119
- Y as withOkno
155
+ ce as createOknoRouteHandler,
156
+ ae as withOkno
120
157
  };