@interactive-inc/emdash-plugins 0.0.0-stage → 0.1.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.
Files changed (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +201 -2
  3. package/dist/builder/admin/get-editor-page-id.d.ts +3 -0
  4. package/dist/builder/admin/get-editor-page-id.d.ts.map +1 -0
  5. package/dist/builder/admin/get-editor-page-id.js +8 -0
  6. package/dist/builder/admin/get-editor-page-id.js.map +1 -0
  7. package/dist/builder/admin/get-page-preview.d.ts +7 -0
  8. package/dist/builder/admin/get-page-preview.d.ts.map +1 -0
  9. package/dist/builder/admin/get-page-preview.js +27 -0
  10. package/dist/builder/admin/get-page-preview.js.map +1 -0
  11. package/dist/builder/astro.d.ts +5 -0
  12. package/dist/builder/astro.d.ts.map +1 -0
  13. package/dist/builder/astro.js +56 -0
  14. package/dist/builder/astro.js.map +1 -0
  15. package/dist/builder/catalog.d.ts +1232 -0
  16. package/dist/builder/catalog.d.ts.map +1 -0
  17. package/dist/builder/catalog.js +111 -0
  18. package/dist/builder/catalog.js.map +1 -0
  19. package/dist/builder/constants.d.ts +5 -0
  20. package/dist/builder/constants.d.ts.map +1 -0
  21. package/dist/builder/constants.js +5 -0
  22. package/dist/builder/constants.js.map +1 -0
  23. package/dist/builder/document.d.ts +74 -0
  24. package/dist/builder/document.d.ts.map +1 -0
  25. package/dist/builder/document.js +172 -0
  26. package/dist/builder/document.js.map +1 -0
  27. package/dist/builder/extensions.d.ts +32 -0
  28. package/dist/builder/extensions.d.ts.map +1 -0
  29. package/dist/builder/extensions.js +30 -0
  30. package/dist/builder/extensions.js.map +1 -0
  31. package/dist/builder/list-limits.d.ts +7 -0
  32. package/dist/builder/list-limits.d.ts.map +1 -0
  33. package/dist/builder/list-limits.js +8 -0
  34. package/dist/builder/list-limits.js.map +1 -0
  35. package/dist/builder/middleware.d.ts +2 -0
  36. package/dist/builder/middleware.d.ts.map +1 -0
  37. package/dist/builder/middleware.js +13 -0
  38. package/dist/builder/middleware.js.map +1 -0
  39. package/dist/builder/motion-directive.d.ts +14 -0
  40. package/dist/builder/motion-directive.d.ts.map +1 -0
  41. package/dist/builder/motion-directive.js +14 -0
  42. package/dist/builder/motion-directive.js.map +1 -0
  43. package/dist/builder/motion-tokens.d.ts +114 -0
  44. package/dist/builder/motion-tokens.d.ts.map +1 -0
  45. package/dist/builder/motion-tokens.js +25 -0
  46. package/dist/builder/motion-tokens.js.map +1 -0
  47. package/dist/builder/options.d.ts +14 -0
  48. package/dist/builder/options.d.ts.map +1 -0
  49. package/dist/builder/options.js +20 -0
  50. package/dist/builder/options.js.map +1 -0
  51. package/dist/builder/plugin.d.ts +6 -0
  52. package/dist/builder/plugin.d.ts.map +1 -0
  53. package/dist/builder/plugin.js +15 -0
  54. package/dist/builder/plugin.js.map +1 -0
  55. package/dist/builder/portable-text.d.ts +9 -0
  56. package/dist/builder/portable-text.d.ts.map +1 -0
  57. package/dist/builder/portable-text.js +58 -0
  58. package/dist/builder/portable-text.js.map +1 -0
  59. package/dist/builder/resolve-page.d.ts +28 -0
  60. package/dist/builder/resolve-page.d.ts.map +1 -0
  61. package/dist/builder/resolve-page.js +99 -0
  62. package/dist/builder/resolve-page.js.map +1 -0
  63. package/dist/builder/runtime.d.ts +4 -0
  64. package/dist/builder/runtime.d.ts.map +1 -0
  65. package/dist/builder/runtime.js +99 -0
  66. package/dist/builder/runtime.js.map +1 -0
  67. package/dist/builder/safe-url.d.ts +3 -0
  68. package/dist/builder/safe-url.d.ts.map +1 -0
  69. package/dist/builder/safe-url.js +21 -0
  70. package/dist/builder/safe-url.js.map +1 -0
  71. package/dist/builder/server/load-page.d.ts +18 -0
  72. package/dist/builder/server/load-page.d.ts.map +1 -0
  73. package/dist/builder/server/load-page.js +37 -0
  74. package/dist/builder/server/load-page.js.map +1 -0
  75. package/dist/builder/server/page-response.d.ts +10 -0
  76. package/dist/builder/server/page-response.d.ts.map +1 -0
  77. package/dist/builder/server/page-response.js +12 -0
  78. package/dist/builder/server/page-response.js.map +1 -0
  79. package/package.json +95 -3
  80. package/src/builder/PageDocument.astro +27 -0
  81. package/src/builder/PageShell.astro +15 -0
  82. package/src/builder/StaticPageShell.astro +11 -0
  83. package/src/builder/admin/get-editor-page-id.ts +8 -0
  84. package/src/builder/admin/get-page-preview.ts +28 -0
  85. package/src/builder/admin/managed-page-field.tsx +4 -0
  86. package/src/builder/admin/page-preview-field.tsx +53 -0
  87. package/src/builder/admin/page-preview-frame.tsx +67 -0
  88. package/src/builder/admin.tsx +5 -0
  89. package/src/builder/astro.ts +53 -0
  90. package/src/builder/catalog.ts +117 -0
  91. package/src/builder/constants.ts +4 -0
  92. package/src/builder/document.ts +137 -0
  93. package/src/builder/extensions.ts +46 -0
  94. package/src/builder/island.tsx +8 -0
  95. package/src/builder/list-limits.ts +10 -0
  96. package/src/builder/middleware.ts +10 -0
  97. package/src/builder/motion-directive.ts +19 -0
  98. package/src/builder/motion-site.tsx +15 -0
  99. package/src/builder/motion-tokens.ts +40 -0
  100. package/src/builder/options.ts +20 -0
  101. package/src/builder/pages/[...slug].astro +11 -0
  102. package/src/builder/pages/preview/[id].astro +14 -0
  103. package/src/builder/plugin.ts +17 -0
  104. package/src/builder/portable-content.tsx +17 -0
  105. package/src/builder/portable-text.ts +63 -0
  106. package/src/builder/renderer.tsx +16 -0
  107. package/src/builder/resolve-page.ts +90 -0
  108. package/src/builder/reveal.tsx +321 -0
  109. package/src/builder/runtime.ts +92 -0
  110. package/src/builder/safe-url.ts +13 -0
  111. package/src/builder/server/load-page.ts +45 -0
  112. package/src/builder/server/page-response.ts +15 -0
  113. package/src/builder/site-view.tsx +60 -0
  114. package/src/builder/styles/site.css +1 -0
  115. package/src/builder/virtual.d.ts +13 -0
@@ -0,0 +1,18 @@
1
+ import { type BuilderOptions } from '../options.ts';
2
+ import type { ComponentExtensions } from '../extensions.ts';
3
+ import { type PageDocument, type PageState } from '../document.ts';
4
+ import { type ResolvedView } from '../resolve-page.ts';
5
+ export type LoadedPage = {
6
+ id: string;
7
+ title: string;
8
+ description: string;
9
+ slug: string;
10
+ document: PageDocument;
11
+ state: PageState;
12
+ /** What the page renders; the only page data that reaches the browser. */
13
+ view: ResolvedView;
14
+ isPreview: boolean;
15
+ };
16
+ /** All reads go through EmDash's published-entry and scoped preview checks. */
17
+ export declare function loadPage(identifier: string, input?: BuilderOptions, components?: ComponentExtensions): Promise<LoadedPage | null>;
18
+ //# sourceMappingURL=load-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-page.d.ts","sourceRoot":"","sources":["../../../src/builder/server/load-page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAoB,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAErF,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEpE,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,SAAS,CAAC;IACjB,0EAA0E;IAC1E,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,+EAA+E;AAC/E,wBAAsB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,GAAE,cAAmB,EAAE,UAAU,GAAE,mBAAwB,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAwB/I"}
@@ -0,0 +1,37 @@
1
+ import { resolveOptions } from "../options.js";
2
+ import { getEmDashCollection, getEmDashEntry } from 'emdash';
3
+ import { validateDocument } from "../document.js";
4
+ import { defaultListItems } from "../list-limits.js";
5
+ import { resolvePage } from "../resolve-page.js";
6
+ /** All reads go through EmDash's published-entry and scoped preview checks. */
7
+ export async function loadPage(identifier, input = {}, components = {}) {
8
+ const options = resolveOptions(input);
9
+ const { entry, error, isPreview } = await getEmDashEntry(options.collection, identifier);
10
+ if (error)
11
+ throw new Error('Could not load page');
12
+ if (!entry)
13
+ return null;
14
+ const validated = validateDocument(entry.data.document, components);
15
+ if (!validated.success)
16
+ throw new Error('Stored page JSON is invalid');
17
+ const document = validated.document;
18
+ const title = typeof entry.data.title === 'string' ? entry.data.title : '';
19
+ const description = typeof entry.data.description === 'string' ? entry.data.description : '';
20
+ const slug = typeof entry.data.slug === 'string' ? entry.data.slug : identifier;
21
+ const data = Object.fromEntries(await Promise.all(Object.entries(document.data ?? {}).map(async ([name, query]) => {
22
+ if (query.id) {
23
+ const result = await getEmDashEntry(query.collection, query.id);
24
+ if (result.error)
25
+ throw new Error(`Could not load data source ${name}`);
26
+ return [name, result.entry ? { ...result.entry.data, id: result.entry.id } : null];
27
+ }
28
+ const result = await getEmDashCollection(query.collection, { limit: query.limit ?? defaultListItems });
29
+ if (result.error)
30
+ throw new Error(`Could not load data source ${name}`);
31
+ return [name, result.entries.map(item => ({ ...item.data, id: item.id }))];
32
+ })));
33
+ const state = { page: { title, description, slug }, data };
34
+ const view = resolvePage(document, state, components, { motion: options.motion });
35
+ return { id: entry.id, title, description, slug, document, state, view, isPreview };
36
+ }
37
+ //# sourceMappingURL=load-page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-page.js","sourceRoot":"","sources":["../../../src/builder/server/load-page.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,10 @@
1
+ import { type LoadedPage } from './load-page.ts';
2
+ import type { BuilderOptions } from '../options.ts';
3
+ import type { ComponentExtensions } from '../extensions.ts';
4
+ type Result = {
5
+ page: LoadedPage | null;
6
+ status: number;
7
+ };
8
+ export declare function pageResponse(identifier: string, options?: BuilderOptions, components?: ComponentExtensions): Promise<Result>;
9
+ export {};
10
+ //# sourceMappingURL=page-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-response.d.ts","sourceRoot":"","sources":["../../../src/builder/server/page-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,KAAK,MAAM,GAAG;IAAE,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1D,wBAAsB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,EAAE,UAAU,GAAE,mBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ1I"}
@@ -0,0 +1,12 @@
1
+ import { loadPage } from "./load-page.js";
2
+ export async function pageResponse(identifier, options = {}, components = {}) {
3
+ try {
4
+ const page = await loadPage(identifier, options, components);
5
+ return { page, status: page ? 200 : 404 };
6
+ }
7
+ catch (error) {
8
+ console.error('[emdash-plugins/builder] Page resolution failed', error);
9
+ return { page: null, status: 503 };
10
+ }
11
+ }
12
+ //# sourceMappingURL=page-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-response.js","sourceRoot":"","sources":["../../../src/builder/server/page-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmB,MAAM,gBAAgB,CAAC;AAM3D,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,UAAkB,EAAE,UAA0B,EAAE,EAAE,aAAkC,EAAE;IACvH,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;IAC5C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,iDAAiD,EAAE,KAAK,CAAC,CAAC;QACxE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IACrC,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,98 @@
1
1
  {
2
2
  "name": "@interactive-inc/emdash-plugins",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "EmDash plugins by Interactive Inc. builder: chat-authored json-render pages, MCP tools and previews",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/interactive-inc/emdash-plugins.git",
9
+ "directory": "packages/emdash-plugins"
10
+ },
11
+ "keywords": [
12
+ "emdash",
13
+ "emdash-plugin",
14
+ "astro",
15
+ "json-render",
16
+ "mcp",
17
+ "page-builder"
18
+ ],
19
+ "type": "module",
20
+ "exports": {
21
+ "./builder": {
22
+ "types": "./dist/builder/plugin.d.ts",
23
+ "default": "./dist/builder/plugin.js"
24
+ },
25
+ "./builder/astro": {
26
+ "types": "./dist/builder/astro.d.ts",
27
+ "default": "./dist/builder/astro.js"
28
+ },
29
+ "./builder/server": {
30
+ "types": "./dist/builder/server/page-response.d.ts",
31
+ "default": "./dist/builder/server/page-response.js"
32
+ },
33
+ "./builder/document": {
34
+ "types": "./dist/builder/document.d.ts",
35
+ "default": "./dist/builder/document.js"
36
+ },
37
+ "./builder/catalog": {
38
+ "types": "./dist/builder/catalog.d.ts",
39
+ "default": "./dist/builder/catalog.js"
40
+ },
41
+ "./builder/runtime": {
42
+ "types": "./dist/builder/runtime.d.ts",
43
+ "default": "./dist/builder/runtime.js"
44
+ },
45
+ "./builder/renderer": "./src/builder/renderer.tsx",
46
+ "./builder/admin": "./src/builder/admin.tsx",
47
+ "./builder/PageShell.astro": "./src/builder/PageShell.astro",
48
+ "./builder/styles.css": "./src/builder/styles/site.css",
49
+ "./builder/middleware": {
50
+ "types": "./dist/builder/middleware.d.ts",
51
+ "default": "./dist/builder/middleware.js"
52
+ },
53
+ "./builder/extensions": {
54
+ "types": "./dist/builder/extensions.d.ts",
55
+ "default": "./dist/builder/extensions.js"
56
+ }
57
+ },
58
+ "dependencies": {
59
+ "@json-render/core": "0.21.3",
60
+ "@json-render/react": "0.21.3",
61
+ "@portabletext/react": "^6.0.0",
62
+ "@portabletext/types": "^4.0.2",
63
+ "motion": "14.9.1",
64
+ "zod": "4.6.7"
65
+ },
66
+ "peerDependencies": {
67
+ "astro": "^7.4.2",
68
+ "emdash": "^1.3.1",
69
+ "react": "^19.2.4",
70
+ "react-dom": "^19.2.4"
71
+ },
72
+ "files": [
73
+ "dist",
74
+ "src",
75
+ "README.md",
76
+ "LICENSE"
77
+ ],
78
+ "sideEffects": [
79
+ "**/*.css",
80
+ "**/*.astro"
81
+ ],
82
+ "engines": {
83
+ "node": ">=22.23.4"
84
+ },
85
+ "publishConfig": {
86
+ "access": "public"
87
+ },
88
+ "devDependencies": {
89
+ "@types/jsdom": "^30.0.0",
90
+ "jsdom": "^30.1.3"
91
+ },
92
+ "scripts": {
93
+ "build": "tsc -p tsconfig.build.json",
94
+ "check": "tsc --noEmit -p tsconfig.json",
95
+ "test": "sh scripts/test.sh",
96
+ "test:integration": "tsx --experimental-test-module-mocks --test \"tests/*/integration/*.test.ts\" \"tests/*/integration/*.test.tsx\""
97
+ }
6
98
  }
@@ -0,0 +1,27 @@
1
+ ---
2
+ import type { LoadedPage } from './server/load-page.ts';
3
+ import './styles/site.css';
4
+
5
+ type Props = { page: LoadedPage | null; status: number; previewRoute?: boolean };
6
+ const { page, status, previewRoute = false } = Astro.props;
7
+ const preview = previewRoute || page?.isPreview;
8
+ const title = page?.title ?? (status === 404 ? 'ページが見つかりません' : 'ページを表示できません');
9
+ ---
10
+ <!doctype html>
11
+ <html lang="ja">
12
+ <head>
13
+ <meta charset="utf-8" />
14
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
15
+ <title>{title}</title>
16
+ {page?.description && <meta name="description" content={page.description} />}
17
+ {(preview || status !== 200) && <meta name="robots" content="noindex, nofollow" />}
18
+ <slot name="head" />
19
+ </head>
20
+ <body class={preview ? 'is-preview' : undefined}>
21
+ {preview && <aside class="preview-banner" role="status">プレビュー — 保存済みの内容を表示しています</aside>}
22
+ <main>
23
+ {page ? <slot /> :
24
+ <div class="error-page"><p class="error-code">{status}</p><h1>{title}</h1><p>{status === 404 ? 'URLをご確認ください。' : '少し時間をおいて、もう一度お試しください。'}</p><a href="/">ホームへ</a></div>}
25
+ </main>
26
+ </body>
27
+ </html>
@@ -0,0 +1,15 @@
1
+ ---
2
+ import components from 'virtual:emdash-plugins/builder/extensions';
3
+ import PageDocument from './PageDocument.astro';
4
+ import SiteIsland from './island.tsx';
5
+ import { ResolvedSite } from './site-view.tsx';
6
+ import type { LoadedPage } from './server/load-page.ts';
7
+
8
+ // Components come from builderIntegration() so the static page and the island always render the same ones.
9
+ type Props = { page: LoadedPage | null; status: number; previewRoute?: boolean };
10
+ const view = Astro.props.page?.view;
11
+ ---
12
+ <PageDocument {...Astro.props}>
13
+ <Fragment slot="head">{view?.motion && <noscript><style is:inline>[data-motion]{opacity:1!important;transform:none!important;animation:none!important}</style></noscript>}</Fragment>
14
+ {view && (view.motion ? <SiteIsland client:builder-motion view={view} /> : <ResolvedSite view={view} components={components} />)}
15
+ </PageDocument>
@@ -0,0 +1,11 @@
1
+ ---
2
+ import components from 'virtual:emdash-plugins/builder/extensions';
3
+ import PageDocument from './PageDocument.astro';
4
+ import { ResolvedSite } from './site-view.tsx';
5
+ import type { LoadedPage } from './server/load-page.ts';
6
+
7
+ // The routes' shell with motion: false. It never imports the island, so the build emits no page script.
8
+ type Props = { page: LoadedPage | null; status: number; previewRoute?: boolean };
9
+ const view = Astro.props.page?.view;
10
+ ---
11
+ <PageDocument {...Astro.props}>{view && <ResolvedSite view={view} components={components} />}</PageDocument>
@@ -0,0 +1,8 @@
1
+ /** Resolve only saved Pages entries; new-entry and unrelated editors have no preview. */
2
+ export const getEditorPageId = (pathname: string, collection = 'pages'): string | null => {
3
+ const match = /^(?:\/_emdash\/admin)?\/content\/([^/]+)\/([^/]+)\/?$/.exec(pathname);
4
+
5
+ if (!match || match[1] !== collection || match[2] === 'new') return null;
6
+
7
+ return match[2];
8
+ };
@@ -0,0 +1,28 @@
1
+ import { z } from 'zod';
2
+ import { pluginId } from '../constants.ts';
3
+
4
+ const previewResponse = z.object({ success: z.literal(true), data: z.object({ url: z.string() }) });
5
+
6
+ /** Only the authenticated EmDash route can issue the page-scoped preview token. */
7
+ export const getPagePreview = async (id: string, signal: AbortSignal, previewPath = '/preview'): Promise<string> => {
8
+ const response = await fetch(`/_emdash/api/plugins/${pluginId}/preview`, {
9
+ method: 'POST', credentials: 'same-origin', signal,
10
+ headers: { 'Content-Type': 'application/json', 'X-EmDash-Request': '1' },
11
+ body: JSON.stringify({ id }),
12
+ });
13
+ const parsed = previewResponse.safeParse(await response.json());
14
+
15
+ if (!response.ok || !parsed.success) throw new Error('プレビューを読み込めませんでした。もう一度お試しください。');
16
+
17
+ const value = parsed.data.data.url;
18
+ const url = new URL(value, 'https://builder.invalid');
19
+ if (!value.startsWith(`${previewPath}/`) || url.origin !== 'https://builder.invalid' || !url.pathname.startsWith(`${previewPath}/`) || !url.searchParams.get('_preview')) throw new Error('プレビューURLが不正です。');
20
+ return value;
21
+ };
22
+
23
+ export async function getPreviewConfiguration(signal: AbortSignal): Promise<{ collection: string; previewPath: string }> {
24
+ const response = await fetch(`/_emdash/api/plugins/${pluginId}/configuration`, { credentials: 'same-origin', signal, headers: { 'X-EmDash-Request': '1' } });
25
+ const result = z.object({ success: z.literal(true), data: z.object({ collection: z.string().regex(/^[a-z][a-z0-9_]*$/), previewPath: z.string().regex(/^(?:\/[a-zA-Z0-9_-]+)+$/) }) }).safeParse(await response.json());
26
+ if (!response.ok || !result.success) throw new Error('プレビュー設定を読み込めませんでした。');
27
+ return result.data.data;
28
+ }
@@ -0,0 +1,4 @@
1
+ /** Chat-authored metadata stays in EmDash's form state without a manual editor. */
2
+ export function ManagedPageField() {
3
+ return null;
4
+ }
@@ -0,0 +1,53 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { getEditorPageId } from './get-editor-page-id.ts';
3
+ import { getPagePreview, getPreviewConfiguration } from './get-page-preview.ts';
4
+ import { PagePreviewFrame } from './page-preview-frame.tsx';
5
+
6
+ type Props = { value: unknown };
7
+ type Configuration = Awaited<ReturnType<typeof getPreviewConfiguration>>;
8
+ type Load<T> = { status: 'pending' } | { status: 'success'; data: T } | { status: 'error'; message: string };
9
+
10
+ const errorMessage = (error: unknown) => error instanceof Error ? error.message : 'プレビューを読み込めませんでした。';
11
+
12
+ /**
13
+ * Replace the internal document field with a saved-draft preview.
14
+ * Uses only React and the browser so the plugin does not share EmDash's internal TanStack instances.
15
+ */
16
+ export function PagePreviewField(props: Props) {
17
+ const [configuration, setConfiguration] = useState<Load<Configuration>>({ status: 'pending' });
18
+ const [preview, setPreview] = useState<Load<string>>({ status: 'pending' });
19
+ const pathname = typeof window === 'undefined' ? '' : window.location.pathname;
20
+ const pageId = configuration.status === 'success' ? getEditorPageId(pathname, configuration.data.collection) : null;
21
+ const previewPath = configuration.status === 'success' ? configuration.data.previewPath : undefined;
22
+ const valueKey = JSON.stringify(props.value ?? null);
23
+
24
+ useEffect(() => {
25
+ const controller = new AbortController();
26
+ getPreviewConfiguration(controller.signal).then(
27
+ data => setConfiguration({ status: 'success', data }),
28
+ error => { if (!controller.signal.aborted) setConfiguration({ status: 'error', message: errorMessage(error) }); },
29
+ );
30
+ return () => controller.abort();
31
+ }, []);
32
+
33
+ useEffect(() => {
34
+ if (pageId === null) return;
35
+ const controller = new AbortController();
36
+ setPreview({ status: 'pending' });
37
+ getPagePreview(pageId, controller.signal, previewPath).then(
38
+ data => setPreview({ status: 'success', data }),
39
+ error => { if (!controller.signal.aborted) setPreview({ status: 'error', message: errorMessage(error) }); },
40
+ );
41
+ return () => controller.abort();
42
+ }, [pageId, previewPath, valueKey]);
43
+
44
+ if (configuration.status === 'error') return <p role="alert">{configuration.message}</p>;
45
+ if (configuration.status === 'pending') return <p role="status">プレビューを読み込んでいます…</p>;
46
+ if (pageId === null) return <p>ページの作成・変更はチャットで行ってください。保存したページを開くと、ここで確認して公開できます。</p>;
47
+
48
+ return <section aria-label="ページプレビュー">
49
+ {preview.status === 'pending' && <p role="status">プレビューを読み込んでいます…</p>}
50
+ {preview.status === 'error' && <p role="alert">{preview.message}</p>}
51
+ {preview.status === 'success' && <PagePreviewFrame url={preview.data} />}
52
+ </section>;
53
+ }
@@ -0,0 +1,67 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+
3
+ type Props = { url: string };
4
+
5
+ const initialHeight = 480;
6
+ // Upper bound guards against content that grows with the frame (for example 100vh sections).
7
+ const maxHeight = 20000;
8
+
9
+ /**
10
+ * Allow same-origin styles while leaving scripts and forms disabled.
11
+ * The admin page measures the same-origin document and sizes the frame to fit it.
12
+ */
13
+ export function PagePreviewFrame(props: Props) {
14
+ const frame = useRef<HTMLIFrameElement>(null);
15
+ const [height, setHeight] = useState<number | null>(null);
16
+
17
+ useEffect(() => {
18
+ const element = frame.current;
19
+ if (!element) return;
20
+ let observer: ResizeObserver | null = null;
21
+ let frameHeight = 0;
22
+ let lastGrowth = 0;
23
+ let repeatedGrowth = 0;
24
+
25
+ const measure = () => {
26
+ const document = element.contentDocument;
27
+ if (!document?.documentElement) return;
28
+ const next = Math.min(maxHeight, Math.ceil(document.documentElement.scrollHeight));
29
+ const growth = next - frameHeight;
30
+ // Content tied to the viewport (vh units) grows by the same amount after every resize; stop following it.
31
+ repeatedGrowth = growth > 0 && growth === lastGrowth ? repeatedGrowth + 1 : 0;
32
+ lastGrowth = growth;
33
+ if (repeatedGrowth >= 3) { observer?.disconnect(); return; }
34
+ if (next === frameHeight) return;
35
+ frameHeight = next;
36
+ setHeight(next);
37
+ };
38
+ const attach = () => {
39
+ observer?.disconnect();
40
+ frameHeight = 0; lastGrowth = 0; repeatedGrowth = 0;
41
+ setHeight(null);
42
+ try {
43
+ const body = element.contentDocument?.body;
44
+ if (!body) return;
45
+ measure();
46
+ observer = new ResizeObserver(measure);
47
+ observer.observe(body);
48
+ } catch {
49
+ // A cross-origin preview cannot be measured; keep the fixed fallback height.
50
+ }
51
+ };
52
+
53
+ element.addEventListener('load', attach);
54
+ if (element.contentDocument?.readyState === 'complete') attach();
55
+ return () => { element.removeEventListener('load', attach); observer?.disconnect(); };
56
+ }, [props.url]);
57
+
58
+ return <iframe
59
+ ref={frame}
60
+ title="ページの下書きプレビュー"
61
+ src={props.url}
62
+ sandbox="allow-same-origin"
63
+ referrerPolicy="no-referrer"
64
+ scrolling={height === null ? 'auto' : 'no'}
65
+ style={{ display: 'block', width: '100%', height: height ?? initialHeight, border: '1px solid var(--color-kumo-line, #d1d5db)', borderRadius: 8, background: '#fff' }}
66
+ />;
67
+ }
@@ -0,0 +1,5 @@
1
+ import { PagePreviewField } from './admin/page-preview-field.tsx';
2
+ import { ManagedPageField } from './admin/managed-page-field.tsx';
3
+
4
+ /** EmDash's native field widgets keep storage and publication in the host editor. */
5
+ export const fields = { 'page-preview': PagePreviewField, managed: ManagedPageField };
@@ -0,0 +1,53 @@
1
+ import type { AstroIntegration } from 'astro';
2
+ import { resolveOptions, type BuilderOptions } from './options.ts';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ const packageName = '@interactive-inc/emdash-plugins';
6
+ // The page island imports these from the package's own source; prebundling them avoids hundreds of dev requests.
7
+ const islandDependencies = ['motion/react', '@json-render/react', '@json-render/core', '@portabletext/react', 'zod'];
8
+ const virtualModules = ['config', 'extensions', 'runtime', 'page-shell'].map(name => `virtual:emdash-plugins/builder/${name}`);
9
+ const runtime = `${packageName}/builder/runtime`;
10
+ // Astro and route sources ship uncompiled, next to the compiled dist/builder.
11
+ const source = (path: string) => fileURLToPath(new URL(`../../src/builder/${path}`, import.meta.url));
12
+
13
+ /** Serves builderPlugin()'s runtime, checks both received the same options, and adds the page routes. */
14
+ export function builderIntegration(input: BuilderOptions = {}): AstroIntegration {
15
+ const options = resolveOptions(input);
16
+ return {
17
+ name: '@interactive-inc/emdash-plugins/builder',
18
+ hooks: {
19
+ 'astro:config:setup': setup => {
20
+ const extensionModule = options.componentsModule ? fileURLToPath(new URL(options.componentsModule, setup.config.root)) : null;
21
+ setup.updateConfig({ vite: {
22
+ plugins: [{
23
+ name: 'emdash-plugins:builder',
24
+ // Before Vite's resolver, so EmDash's import of the plain runtime reaches the options check too.
25
+ enforce: 'pre',
26
+ resolveId(id, importer) {
27
+ if (virtualModules.includes(id)) return `\0${id}`;
28
+ if (id === runtime && importer !== '\0virtual:emdash-plugins/builder/runtime') return '\0virtual:emdash-plugins/builder/runtime';
29
+ },
30
+ load(id) {
31
+ if (id === '\0virtual:emdash-plugins/builder/config') return `export default ${JSON.stringify(options)};`;
32
+ if (id === '\0virtual:emdash-plugins/builder/extensions') {
33
+ // Without motion no page hydrates, so host components stay out of the browser bundle.
34
+ const browser = this.environment?.config.consumer === 'client';
35
+ return extensionModule && (options.motion || !browser) ? `export { default } from ${JSON.stringify(extensionModule)};` : 'export default {};';
36
+ }
37
+ if (id === '\0virtual:emdash-plugins/builder/runtime') return `import { createPlugin as create } from '${runtime}'; import components from 'virtual:emdash-plugins/builder/extensions'; export function createPlugin(options) { if (JSON.stringify(options) !== ${JSON.stringify(JSON.stringify(options))}) throw new Error('builderPlugin and builderIntegration must use the same options'); return create(options, components); }`;
38
+ // Astro builds every island an imported .astro file contains, whichever branch renders.
39
+ if (id === '\0virtual:emdash-plugins/builder/page-shell') return `export { default } from ${JSON.stringify(source(options.motion ? 'PageShell.astro' : 'StaticPageShell.astro'))};`;
40
+ },
41
+ }],
42
+ // One copy of React and Motion for the island; an externalized Motion would load a second React.
43
+ ssr: { noExternal: [packageName, 'motion', 'framer-motion', 'motion-dom', 'motion-utils'] },
44
+ optimizeDeps: { include: islandDependencies.map(name => `${packageName} > ${name}`) },
45
+ } });
46
+ setup.addClientDirective({ name: 'builder-motion', entrypoint: fileURLToPath(new URL('./motion-directive.js', import.meta.url)) });
47
+ setup.addMiddleware({ entrypoint: '@interactive-inc/emdash-plugins/builder/middleware', order: 'post' });
48
+ setup.injectRoute({ pattern: `${options.basePath}/[...slug]`, entrypoint: source('pages/[...slug].astro'), prerender: false });
49
+ setup.injectRoute({ pattern: `${options.previewPath}/[id]`, entrypoint: source('pages/preview/[id].astro'), prerender: false });
50
+ },
51
+ },
52
+ };
53
+ }
@@ -0,0 +1,117 @@
1
+ import { defineCatalog } from '@json-render/core';
2
+ import { schema } from '@json-render/react/schema';
3
+ import { z } from 'zod';
4
+ import { resolveOptions, type ResolvedOptions } from './options.ts';
5
+ import { defaultListItems } from './list-limits.ts';
6
+ import { maxMotionElements, motionTokens } from './motion-tokens.ts';
7
+
8
+ const text = z.string().max(20000);
9
+ const spacing = z.enum(['none', 'sm', 'md', 'lg', 'xl']);
10
+ const alignment = z.enum(['start', 'center', 'end']);
11
+
12
+ const tokens = <T extends object>(value: T) => Object.keys(value) as [Extract<keyof T, string>, ...Extract<keyof T, string>[]];
13
+ const motionShape = {
14
+ effect: z.enum(tokens(motionTokens.effect), { error: issue => issue.input === undefined ? 'effect is required' : undefined }),
15
+ delay: z.enum(tokens(motionTokens.delay)).optional(),
16
+ duration: z.enum(tokens(motionTokens.duration)).optional(),
17
+ };
18
+ const motionError = (allowed: string[]) => ({ error: (issue: z.core.$ZodRawIssue) => {
19
+ if (issue.code === 'invalid_type') return 'motion must be an object such as {"effect":"fade-up"}';
20
+ if (issue.code !== 'unrecognized_keys') return undefined;
21
+ if (issue.keys.includes('stagger') && !allowed.includes('stagger')) return 'stagger works only on Stack and Grid';
22
+ return `unknown motion setting ${issue.keys.join(', ')}; allowed: ${allowed.join(', ')}`;
23
+ } });
24
+ /** Entrance motion that plays once when the element first enters the viewport. */
25
+ export const motionSchema = z.strictObject(motionShape, motionError(['effect', 'delay', 'duration']))
26
+ .describe('Plays once when the element first enters the viewport.');
27
+ /** On Stack and Grid, stagger keeps the container still and reveals its direct children in turn. */
28
+ export const groupMotionSchema = z.strictObject({ ...motionShape, stagger: z.enum(tokens(motionTokens.stagger)).optional() }, motionError(['effect', 'delay', 'duration', 'stagger']))
29
+ .describe('Plays once when the element first enters the viewport. With stagger the container stays still and its direct children reveal in turn.');
30
+ export type AuthoredMotion = z.infer<typeof groupMotionSchema>;
31
+ const motion = motionSchema.optional();
32
+ const groupMotion = groupMotionSchema.optional();
33
+
34
+ export const componentProps = {
35
+ // Section stays still as a full-width band and anchor target, so it has no motion.
36
+ Section: z.object({ tone: z.enum(['default', 'muted', 'accent', 'dark']).optional(), spacing: spacing.optional(), id: z.string().regex(/^[a-z][a-z0-9-]*$/).optional() }),
37
+ Container: z.object({ width: z.enum(['narrow', 'normal', 'wide']).optional(), motion }),
38
+ Stack: z.object({ direction: z.enum(['vertical', 'horizontal']).optional(), gap: spacing.optional(), align: alignment.optional(), motion: groupMotion }),
39
+ Grid: z.object({ columns: z.number().int().min(1).max(4).optional(), gap: spacing.optional(), motion: groupMotion }),
40
+ Heading: z.object({ text, level: z.enum(['h1', 'h2', 'h3', 'h4']).optional(), size: z.enum(['sm', 'md', 'lg', 'xl']).optional(), align: alignment.optional(), motion }),
41
+ Text: z.object({ text, tone: z.enum(['default', 'muted']).optional(), size: z.enum(['sm', 'md', 'lg']).optional(), align: alignment.optional(), motion }),
42
+ Link: z.object({ label: text, href: z.string().max(2000), variant: z.enum(['text', 'primary', 'secondary']).optional(), motion }),
43
+ Image: z.object({ src: z.string().max(2000), alt: z.string().max(1000), ratio: z.enum(['auto', 'square', 'landscape', 'portrait']).optional(), motion }),
44
+ Card: z.object({ tone: z.enum(['default', 'muted']).optional(), motion }),
45
+ Badge: z.object({ text: z.string().max(200), motion }),
46
+ Divider: z.object({ motion }),
47
+ PortableText: z.object({ value: z.array(z.looseObject({ _type: z.string(), _key: z.string().optional() })).max(500), motion }),
48
+ } as const;
49
+
50
+ const descriptions: Record<keyof typeof componentProps, string> = {
51
+ Section: 'Full-width page section with a background tone. Use id for anchor links. Sections do not move; animate their content.',
52
+ Container: 'Centers content and limits width.',
53
+ Stack: 'Vertical or wrapping horizontal arrangement. motion.stagger reveals each child in turn.',
54
+ Grid: 'Responsive grid; columns collapse on small screens. Supports repeat for lists. motion.stagger reveals each item in turn.',
55
+ Heading: 'Semantic heading. Use one h1 per page.',
56
+ Text: 'Plain text paragraph. HTML is never executed.',
57
+ Link: 'Navigation link or call-to-action. Only safe URLs are rendered.',
58
+ Image: 'Image from an HTTPS or same-origin URL. Always provide alt text.',
59
+ Card: 'A bordered content container.',
60
+ Badge: 'A short eyebrow or category label.',
61
+ Divider: 'Horizontal separator.',
62
+ PortableText: 'EmDash rich text rendered as React elements, without raw HTML.',
63
+ };
64
+ const containers = new Set(['Section', 'Container', 'Stack', 'Grid', 'Card']);
65
+ const shapes: Record<string, z.ZodObject> = componentProps;
66
+ /** Built-in components whose schema lists motion; their root element moves. */
67
+ export const motionComponentNames = new Set(Object.keys(shapes).filter(name => Object.hasOwn(shapes[name]!.shape, 'motion')));
68
+ /** Built-in components whose motion may stagger their children. */
69
+ export const staggerComponentNames = new Set(Object.keys(shapes).filter(name => shapes[name]!.shape.motion === groupMotion));
70
+
71
+ export const catalog = defineCatalog(schema, {
72
+ components: {
73
+ Section: { props: componentProps.Section, description: descriptions.Section, slots: ['default'] },
74
+ Container: { props: componentProps.Container, description: descriptions.Container, slots: ['default'] },
75
+ Stack: { props: componentProps.Stack, description: descriptions.Stack, slots: ['default'] },
76
+ Grid: { props: componentProps.Grid, description: descriptions.Grid, slots: ['default'] },
77
+ Heading: { props: componentProps.Heading, description: descriptions.Heading },
78
+ Text: { props: componentProps.Text, description: descriptions.Text },
79
+ Link: { props: componentProps.Link, description: descriptions.Link },
80
+ Image: { props: componentProps.Image, description: descriptions.Image },
81
+ Card: { props: componentProps.Card, description: descriptions.Card, slots: ['default'] },
82
+ Badge: { props: componentProps.Badge, description: descriptions.Badge },
83
+ Divider: { props: componentProps.Divider, description: descriptions.Divider },
84
+ PortableText: { props: componentProps.PortableText, description: descriptions.PortableText },
85
+ },
86
+ actions: {},
87
+ });
88
+
89
+ export const componentNames = Object.keys(componentProps);
90
+ export const containerNames = containers;
91
+ export const componentSchemas = Object.fromEntries(Object.entries(componentProps).map(([name, props]) => [name, z.toJSONSchema(props)]));
92
+
93
+ const list = (value: object) => Object.keys(value).map(name => `"${name}"`).join('|');
94
+ const motionGuide = `Motion (optional): add props.motion = {effect, delay?, duration?} to ${[...motionComponentNames].join(', ')}, or to a custom component whose schema lists motion.
95
+ effect: ${list(motionTokens.effect)}; delay: ${list(motionTokens.delay)}; duration: ${list(motionTokens.duration)}.
96
+ Each element plays once when it first enters the viewport; elements on the first screen play as soon as the page is ready. Order siblings with delay.
97
+ For lists put stagger: ${list(motionTokens.stagger)} on a Stack or Grid. The container stays still and its direct children, including every repeated item, reveal in turn, so those children must not have their own motion.
98
+ Never put motion on a Section, on an element that contains a Section, or inside an element that already moves. motion is a literal object, never a $state/$item binding; there are no custom timings, easing, CSS or scripts. At most ${maxMotionElements} elements may move per page: each staggered child and each repeated copy counts, and a list repeats up to its limit (${defaultListItems} when unset).
99
+ Visitors who prefer reduced motion, views without JavaScript and the admin preview show the final static page, so every page must read well without motion.`;
100
+
101
+ /** The MCP guide reflects the host's configured collection and routes. */
102
+ export function createPageGuide(options: ResolvedOptions = resolveOptions()): string {
103
+ return `Build pages as a versioned document: {version:1,spec:{root,elements},theme?,data?}.
104
+ Elements are {type,props,children?}. Only the supplied catalog components are allowed.
105
+ Bind props with {"$state":"/page/title"}, {"$state":"/data/article/title"}, or {"$item":"title"} inside a repeat.
106
+ Use {"$template":"/blog/\${slug}"} inside a repeat. A repeat is {statePath:"/data/posts",key:"id"} on a container; its statePath names a list query, one without id.
107
+ A visible condition is a boolean or {"$state":"/data/article/image"}.
108
+ Data sources are named EmDash queries: {posts:{collection:"posts",limit:6}} or {article:{collection:"posts",id:"my-slug"}}.
109
+ All data reads use EmDash public/preview rules. A page preview token does not grant access to unrelated drafts.
110
+ Theme: {accent:"#hex",background:"#hex",foreground:"#hex",font:"sans"|"serif",radius:"none"|"sm"|"lg"}.
111
+ Use ${options.homeSlug} as the home-page slug. Other page slugs form their URL. Save using core content_create/content_update on collection ${options.collection}, with data:{title,description?,document}. Keep _rev for updates and publication.
112
+ Public pages use the prefix ${options.basePath || '/'}; signed previews use ${options.previewPath}.
113
+ Use the builder validate tool before saving and preview before publishing. Never store executable code, arbitrary CSS, or fetch URLs.
114
+ ${options.motion ? motionGuide : 'Motion is disabled on this site; omit props.motion.'}`;
115
+ }
116
+
117
+ export const pageGuide = createPageGuide();
@@ -0,0 +1,4 @@
1
+ /** Stable plugin identity. Widget names, MCP scopes and plugin API routes derive from this ID. */
2
+ export const pluginId = 'builder';
3
+ /** Kept equal to package.json by tests/builder/constants.test.ts. */
4
+ export const pluginVersion = '0.1.0';