@saastro/studio 0.7.0 → 0.8.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/{chunk-MN3J6PBW.js → chunk-4L5C226B.js} +2 -2
- package/dist/chunk-5QZN4IGF.js +71 -0
- package/dist/chunk-5QZN4IGF.js.map +1 -0
- package/dist/{chunk-DKDGF6IQ.js → chunk-7U2GMTVW.js} +2 -2
- package/dist/chunk-FGYTDBZU.js +13812 -0
- package/dist/chunk-FGYTDBZU.js.map +1 -0
- package/dist/{chunk-ZHCSQE2N.js → chunk-JMSDBWL2.js} +2 -2
- package/dist/chunk-K7DTYPRE.js +1348 -0
- package/dist/chunk-K7DTYPRE.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-S2IKJ3QM.js +28 -0
- package/dist/chunk-S2IKJ3QM.js.map +1 -0
- package/dist/doctor.d.ts +15 -3
- package/dist/doctor.js +103 -2
- package/dist/doctor.js.map +1 -1
- package/dist/image/index.js +1 -0
- package/dist/image/index.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/integration/index.js +4 -3
- package/dist/middleware/index.js +2 -1
- package/dist/middleware/index.js.map +1 -1
- package/dist/richtext/index.d.ts +63 -0
- package/dist/richtext/index.js +18 -0
- package/dist/richtext/index.js.map +1 -0
- package/dist/vite/index.js +3 -2
- package/package.json +23 -16
- package/src/RichText.astro +70 -0
- /package/dist/{chunk-MN3J6PBW.js.map → chunk-4L5C226B.js.map} +0 -0
- /package/dist/{chunk-DKDGF6IQ.js.map → chunk-7U2GMTVW.js.map} +0 -0
- /package/dist/{chunk-ZHCSQE2N.js.map → chunk-JMSDBWL2.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/vite/meta-tag.ts
|
|
2
2
|
var STUDIO_PROTOCOL_VERSION = "2";
|
|
3
|
-
var PACKAGE_VERSION = "0.
|
|
3
|
+
var PACKAGE_VERSION = "0.8.0".length > 0 ? "0.8.0" : "0.0.0+unknown";
|
|
4
4
|
var META_TAGS = [
|
|
5
5
|
`<meta name="saastro:studio-version" content="${STUDIO_PROTOCOL_VERSION}">`,
|
|
6
6
|
`<meta name="saastro:studio-package" content="${PACKAGE_VERSION}">`
|
|
@@ -68,4 +68,4 @@ export {
|
|
|
68
68
|
buildVisibilityStyleTag,
|
|
69
69
|
injectVisibilityStyle
|
|
70
70
|
};
|
|
71
|
-
//# sourceMappingURL=chunk-
|
|
71
|
+
//# sourceMappingURL=chunk-4L5C226B.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/vite/meta-tag.ts
|
|
2
|
+
var STUDIO_PROTOCOL_VERSION = "2";
|
|
3
|
+
var PACKAGE_VERSION = "0.7.1".length > 0 ? "0.7.1" : "0.0.0+unknown";
|
|
4
|
+
var META_TAGS = [
|
|
5
|
+
`<meta name="saastro:studio-version" content="${STUDIO_PROTOCOL_VERSION}">`,
|
|
6
|
+
`<meta name="saastro:studio-package" content="${PACKAGE_VERSION}">`
|
|
7
|
+
].join("\n ");
|
|
8
|
+
function injectVersionMetaTag(html) {
|
|
9
|
+
if (html.includes("saastro:studio-version")) return html;
|
|
10
|
+
return html.replace(/<head([^>]*)>/i, `<head$1>
|
|
11
|
+
${META_TAGS}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/visibility-css.ts
|
|
15
|
+
var CONFIG_FILENAME = "studio.config.json";
|
|
16
|
+
var STYLE_ID = "saastro-studio-hidden";
|
|
17
|
+
function readVisibilityConfigSync(projectRoot = ".") {
|
|
18
|
+
try {
|
|
19
|
+
const req = globalThis.require;
|
|
20
|
+
if (typeof req !== "function") return {};
|
|
21
|
+
const fs = req("node:fs");
|
|
22
|
+
const path = req("node:path");
|
|
23
|
+
const raw = fs.readFileSync(path.resolve(projectRoot, CONFIG_FILENAME), "utf8");
|
|
24
|
+
if (!raw.trim()) return {};
|
|
25
|
+
const parsed = JSON.parse(raw);
|
|
26
|
+
if (parsed && typeof parsed === "object") return parsed;
|
|
27
|
+
return {};
|
|
28
|
+
} catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function collectHiddenFieldPrefixes(config) {
|
|
33
|
+
const set = /* @__PURE__ */ new Set();
|
|
34
|
+
for (const prefixes of Object.values(config.hidden ?? {})) {
|
|
35
|
+
if (!Array.isArray(prefixes)) continue;
|
|
36
|
+
for (const p of prefixes) {
|
|
37
|
+
if (typeof p === "string" && p.length > 0) set.add(p);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return Array.from(set).sort();
|
|
41
|
+
}
|
|
42
|
+
function buildVisibilityStyleTag(config) {
|
|
43
|
+
const prefixes = collectHiddenFieldPrefixes(config);
|
|
44
|
+
if (prefixes.length === 0) return "";
|
|
45
|
+
const rules = prefixes.map((fp) => {
|
|
46
|
+
const safe = `sec:${fp}`.replace(/["\\]/g, "\\$&");
|
|
47
|
+
return `[data-saastro="${safe}"]{display:none !important}`;
|
|
48
|
+
}).join("");
|
|
49
|
+
return `<style id="${STYLE_ID}">${rules}</style>`;
|
|
50
|
+
}
|
|
51
|
+
function injectVisibilityStyle(html, _projectRoot = ".") {
|
|
52
|
+
if (html.includes(`id="${STYLE_ID}"`)) return html;
|
|
53
|
+
let tag = "";
|
|
54
|
+
try {
|
|
55
|
+
if (typeof __SAASTRO_STUDIO_HIDDEN_TAG__ === "string") {
|
|
56
|
+
tag = __SAASTRO_STUDIO_HIDDEN_TAG__;
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
if (!tag) return html;
|
|
61
|
+
return html.replace(/<head([^>]*)>/i, `<head$1>
|
|
62
|
+
${tag}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
injectVersionMetaTag,
|
|
67
|
+
readVisibilityConfigSync,
|
|
68
|
+
buildVisibilityStyleTag,
|
|
69
|
+
injectVisibilityStyle
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=chunk-5QZN4IGF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vite/meta-tag.ts","../src/visibility-css.ts"],"sourcesContent":["/**\n * Injects two meta tags into the HTML <head>:\n * - <meta name=\"saastro:studio-version\" content=\"2\"> — protocol version\n * - <meta name=\"saastro:studio-package\" content=\"X.Y.Z\"> — npm package version\n *\n * B8 — spec v5.3 §2 bumps the postMessage protocol number to \"2\". The\n * `studio-version` field reads as the PROTOCOL version (the contract Hub\n * relies on when wiring overlay <-> host messages), not the npm package\n * version of `@saastro/studio`. The package version still ships in a\n * separate `saastro:studio-package` tag for telemetry.\n *\n * The package version comes from a tsup `define` substitution\n * (`__SAASTRO_STUDIO_VERSION__`) injected at build time. The previous\n * implementation used `createRequire(import.meta.url)` to read\n * `package.json` at runtime, but tsup's chunked output places dist\n * files at `dist/chunk-XXX.js` and `../../package.json` resolves\n * OUTSIDE the package — the require always threw and the catch fell\n * back to a hardcoded `'0.1.0'`. Build-time substitution is bullet-\n * proof regardless of how tsup chunks the bundle.\n *\n * This is separate from the auto-wrap transform hook —\n * transformIndexHtml runs on rendered HTML output, not on .astro\n * source files.\n */\n\n/**\n * postMessage protocol version. Bumped to \"2\" in spec v5.3 to add\n * `studio:sections:enumerate` + `studio:select:section` exchanges.\n * Increment when adding/changing the iframe⇄host wire format.\n */\nconst STUDIO_PROTOCOL_VERSION = '2'\n\ndeclare const __SAASTRO_STUDIO_VERSION__: string | undefined\n\nconst PACKAGE_VERSION =\n typeof __SAASTRO_STUDIO_VERSION__ === 'string' && __SAASTRO_STUDIO_VERSION__.length > 0\n ? __SAASTRO_STUDIO_VERSION__\n : '0.0.0+unknown'\n\nconst META_TAGS = [\n `<meta name=\"saastro:studio-version\" content=\"${STUDIO_PROTOCOL_VERSION}\">`,\n `<meta name=\"saastro:studio-package\" content=\"${PACKAGE_VERSION}\">`,\n].join('\\n ')\n\n/**\n * Inject the two studio meta tags into the HTML head. Idempotent —\n * skips injection if the protocol-version tag is already present\n * (matches both the new shape and the legacy single-tag shape, so\n * customer sites with old metadata aren't double-tagged on rebuild).\n */\nexport function injectVersionMetaTag(html: string): string {\n if (html.includes('saastro:studio-version')) return html\n return html.replace(/<head([^>]*)>/i, `<head$1>\\n ${META_TAGS}`)\n}\n","/**\n * Read `studio.config.json` from a project root and build the\n * `<style>` block that hides sections flagged as `hidden`.\n *\n * The config shape is the one written by the Studio Hub at publish time:\n *\n * {\n * \"hidden\": {\n * \"<pageFile>\": [\"<fieldPrefix>\", ...]\n * }\n * }\n *\n * The CSS targets the `data-saastro=\"sec:<fieldPrefix>\"` markers the\n * auto-wrap plugin emits — so hiding is \"exactly the section root,\n * nothing more\". Selectors are flattened across all `pageFile` entries:\n * Studio's `fieldPrefix` naming convention is `<sectionName>.<pageName>`\n * which keeps them unique site-wide, so this loses no precision.\n *\n * Both the Vite `transformIndexHtml` hook (static-build sites) and the\n * Astro middleware (SSR routes) call into the same helpers so the\n * injected CSS is identical regardless of render mode.\n */\n\n// **CRITICAL — DO NOT add static node:fs / node:path imports here.**\n// This module is loaded by `@saastro/studio/middleware`, which runs\n// inside Cloudflare Workers at SSR boot. CF Workers does not support\n// `node:fs` even with the `nodejs_compat` flag (sync fs I/O is\n// fundamentally incompatible with the worker model) — a top-level\n// `import { readFileSync } from 'node:fs'` causes the module to fail\n// to load with `Error: No such module \"node:fs\"`, which breaks the\n// entire middleware chain and makes Astro return 500 on every SSR\n// route.\n//\n// The `node:fs` fallback (used by `astro dev` in Node) loads via\n// dynamic import inside `readVisibilityConfig`, wrapped in try/catch.\n// Workers never reaches that path because the build-time `define`\n// (`__SAASTRO_STUDIO_HIDDEN_TAG__`) short-circuits the readFileSync\n// call entirely.\n\nconst CONFIG_FILENAME = 'studio.config.json'\nconst STYLE_ID = 'saastro-studio-hidden'\n\n/**\n * Compile-time constant injected by the `@saastro/studio` Vite plugin\n * (see `config()` hook in `vite/index.ts`). esbuild substitutes the\n * identifier at customer-bundle time with a JSON string of the\n * full `<style>` tag (or an empty string when nothing is hidden), so\n * the middleware doesn't need filesystem access at runtime — a\n * hard requirement on Cloudflare Workers, where `node:fs` is a no-op.\n *\n * Declared as a free variable on the global scope so esbuild's\n * `define` substitution recognises it as a literal-replacement\n * target. When the plugin isn't installed, the identifier remains\n * undefined and the middleware falls back to the readFileSync path\n * (works in node-based deployments).\n */\ndeclare const __SAASTRO_STUDIO_HIDDEN_TAG__: string | undefined\n\ninterface StudioConfig {\n hidden?: Record<string, string[]>\n}\n\n/**\n * Read studio.config.json from `projectRoot`. Returns an empty config\n * if the file is missing or malformed — a publish that hasn't written\n * the config yet behaves like \"nothing hidden\".\n *\n * Defaulting `projectRoot` to `'.'` lets callers omit it when they\n * cannot easily determine the resolved Vite root — `node:path.resolve`\n * resolves relative to the current working directory, which is the\n * project root in every realistic deployment of the middleware.\n */\n/**\n * Build-time-only helper. Imports `node:fs` lazily so this module\n * stays loadable on CF Workers (where `node:fs` is not available).\n * The Vite plugin (`vite/index.ts`, runs in Node) calls this during\n * `config()` to inline the visibility tag as a `define` constant.\n * The runtime middleware (`middleware/index.ts`, runs in Workers)\n * never calls it — it reads the inlined define directly.\n *\n * Returns `{}` when the file isn't there, isn't readable, or when\n * `node:fs` simply isn't available (e.g. bundled into a non-Node\n * runtime that somehow reached this branch).\n */\nexport async function readVisibilityConfig(\n projectRoot: string = '.',\n): Promise<StudioConfig> {\n try {\n const [{ readFileSync }, { resolve }] = await Promise.all([\n import('node:fs'),\n import('node:path'),\n ])\n const raw = readFileSync(resolve(projectRoot, CONFIG_FILENAME), 'utf8')\n if (!raw.trim()) return {}\n const parsed = JSON.parse(raw) as unknown\n if (parsed && typeof parsed === 'object') return parsed as StudioConfig\n return {}\n } catch {\n return {}\n }\n}\n\n/**\n * Synchronous variant kept for back-compat with callers that can't\n * await (e.g. test fixtures, legacy plugin hooks). Same lazy node:fs\n * import via `require` — works in Node CJS contexts, returns `{}`\n * on CF Workers / pure-ESM environments where `require` is undefined.\n *\n * The dynamic `globalThis.require` lookup avoids esbuild bundling the\n * module reference, which means CF Workers never throws\n * \"No such module 'node:fs'\" at import time.\n */\nexport function readVisibilityConfigSync(projectRoot: string = '.'): StudioConfig {\n try {\n const req = (globalThis as { require?: (id: string) => unknown }).require\n if (typeof req !== 'function') return {}\n const fs = req('node:fs') as { readFileSync: (p: string, e: string) => string }\n const path = req('node:path') as { resolve: (...parts: string[]) => string }\n const raw = fs.readFileSync(path.resolve(projectRoot, CONFIG_FILENAME), 'utf8')\n if (!raw.trim()) return {}\n const parsed = JSON.parse(raw) as unknown\n if (parsed && typeof parsed === 'object') return parsed as StudioConfig\n return {}\n } catch {\n return {}\n }\n}\n\n/**\n * Collect every fieldPrefix flagged as hidden across all pageFile\n * entries. Deduplicates so a prefix that appears under multiple\n * pageFiles only emits one selector.\n */\nexport function collectHiddenFieldPrefixes(config: StudioConfig): string[] {\n const set = new Set<string>()\n for (const prefixes of Object.values(config.hidden ?? {})) {\n if (!Array.isArray(prefixes)) continue\n for (const p of prefixes) {\n if (typeof p === 'string' && p.length > 0) set.add(p)\n }\n }\n return Array.from(set).sort()\n}\n\n/**\n * Build the `<style>` block. Returns an empty string when there's\n * nothing to hide so callers can no-op without conditional branching.\n */\nexport function buildVisibilityStyleTag(config: StudioConfig): string {\n const prefixes = collectHiddenFieldPrefixes(config)\n if (prefixes.length === 0) return ''\n const rules = prefixes\n .map(fp => {\n // CSS attribute-selector grammar: only `\\` and `\"` need escaping\n // inside `[attr=\"...\"]`. fieldPrefix is conventionally\n // `[a-zA-Z0-9._-]+` so this is belt-and-braces.\n const safe = `sec:${fp}`.replace(/[\"\\\\]/g, '\\\\$&')\n return `[data-saastro=\"${safe}\"]{display:none !important}`\n })\n .join('')\n return `<style id=\"${STYLE_ID}\">${rules}</style>`\n}\n\n/**\n * Inject the visibility `<style>` into an HTML document's `<head>`.\n * Idempotent: a page that already carries a `${STYLE_ID}` style is\n * returned unchanged.\n */\nexport function injectVisibilityStyle(html: string, _projectRoot: string = '.'): string {\n if (html.includes(`id=\"${STYLE_ID}\"`)) return html\n // Prefer the build-time-injected tag when the customer's Vite build\n // populated `__SAASTRO_STUDIO_HIDDEN_TAG__` via the plugin's `config`\n // hook. This is the only path that works on Cloudflare Workers, where\n // `node:fs` is a no-op. The readFileSync fallback handles node-based\n // deployments (or local `astro dev` before the plugin's define lands).\n let tag = ''\n try {\n if (typeof __SAASTRO_STUDIO_HIDDEN_TAG__ === 'string') {\n tag = __SAASTRO_STUDIO_HIDDEN_TAG__\n }\n } catch {\n // ReferenceError swallowed — identifier wasn't substituted.\n }\n // No `readFileSync` fallback in this runtime path — that branch\n // only worked on Node and breaks CF Workers (`node:fs` import\n // throws \"No such module\"). When the build-time define isn't\n // populated (e.g. someone uses the middleware without the Vite\n // plugin), the visibility CSS just isn't injected — graceful\n // degradation, the meta tag still works.\n if (!tag) return html\n return html.replace(/<head([^>]*)>/i, `<head$1>\\n ${tag}`)\n}\n"],"mappings":";AA8BA,IAAM,0BAA0B;AAIhC,IAAM,kBAC8C,QAA2B,SAAS,IAClF,UACA;AAEN,IAAM,YAAY;AAAA,EAChB,gDAAgD,uBAAuB;AAAA,EACvE,gDAAgD,eAAe;AACjE,EAAE,KAAK,MAAM;AAQN,SAAS,qBAAqB,MAAsB;AACzD,MAAI,KAAK,SAAS,wBAAwB,EAAG,QAAO;AACpD,SAAO,KAAK,QAAQ,kBAAkB;AAAA,IAAe,SAAS,EAAE;AAClE;;;ACdA,IAAM,kBAAkB;AACxB,IAAM,WAAW;AAwEV,SAAS,yBAAyB,cAAsB,KAAmB;AAChF,MAAI;AACF,UAAM,MAAO,WAAqD;AAClE,QAAI,OAAO,QAAQ,WAAY,QAAO,CAAC;AACvC,UAAM,KAAK,IAAI,SAAS;AACxB,UAAM,OAAO,IAAI,WAAW;AAC5B,UAAM,MAAM,GAAG,aAAa,KAAK,QAAQ,aAAa,eA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5
5
|
readVisibilityConfigSync
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5QZN4IGF.js";
|
|
7
7
|
import {
|
|
8
8
|
hasFrontmatterFieldPrefix,
|
|
9
9
|
resolvePageKey,
|
|
@@ -1345,4 +1345,4 @@ async function loadTsx(path) {
|
|
|
1345
1345
|
export {
|
|
1346
1346
|
studioAutoWrap
|
|
1347
1347
|
};
|
|
1348
|
-
//# sourceMappingURL=chunk-
|
|
1348
|
+
//# sourceMappingURL=chunk-7U2GMTVW.js.map
|