@vedyua/cms 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.
- package/README.md +67 -2
- package/dist/admin-bar.d.ts +12 -0
- package/dist/admin-bar.js +94 -0
- package/dist/admin-bar.js.map +1 -0
- package/dist/admin-entry.d.ts +24 -0
- package/dist/admin-entry.js +140 -0
- package/dist/admin-entry.js.map +1 -0
- package/dist/context.d.ts +50 -0
- package/dist/context.js +260 -0
- package/dist/context.js.map +1 -0
- package/dist/cookies.d.ts +8 -0
- package/dist/cookies.js +37 -0
- package/dist/cookies.js.map +1 -0
- package/dist/define.d.ts +32 -0
- package/dist/define.js +100 -0
- package/dist/define.js.map +1 -0
- package/dist/editable-text.d.ts +20 -0
- package/dist/editable-text.js +114 -0
- package/dist/editable-text.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/next/create-api.d.ts +39 -0
- package/dist/next/create-api.js +238 -0
- package/dist/next/create-api.js.map +1 -0
- package/dist/next/index.d.ts +7 -0
- package/dist/next/index.js +7 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/save-handler.d.ts +19 -0
- package/dist/next/save-handler.js +96 -0
- package/dist/next/save-handler.js.map +1 -0
- package/dist/page-settings.d.ts +12 -0
- package/dist/page-settings.js +144 -0
- package/dist/page-settings.js.map +1 -0
- package/dist/path.d.ts +5 -0
- package/dist/path.js +38 -0
- package/dist/path.js.map +1 -0
- package/dist/server/auth-github.d.ts +24 -0
- package/dist/server/auth-github.js +112 -0
- package/dist/server/auth-github.js.map +1 -0
- package/dist/server/auth-password.d.ts +20 -0
- package/dist/server/auth-password.js +41 -0
- package/dist/server/auth-password.js.map +1 -0
- package/dist/server/auth.d.ts +45 -0
- package/dist/server/auth.js +1 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +18 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/publish-command.d.ts +37 -0
- package/dist/server/publish-command.js +170 -0
- package/dist/server/publish-command.js.map +1 -0
- package/dist/server/publish-status.d.ts +20 -0
- package/dist/server/publish-status.js +131 -0
- package/dist/server/publish-status.js.map +1 -0
- package/dist/server/publish.d.ts +25 -0
- package/dist/server/publish.js +1 -0
- package/dist/server/publish.js.map +1 -0
- package/dist/server/session.d.ts +21 -0
- package/dist/server/session.js +95 -0
- package/dist/server/session.js.map +1 -0
- package/dist/styles.css +388 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +67 -4
package/README.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@vedyua/cms`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Universal inline editor for static JSON content.
|
|
4
|
+
|
|
5
|
+
- Mark fields in markup with `<EditableText />`
|
|
6
|
+
- Auth via pluggable adapters (`passwordAuth`, `githubAuth`, `devAuth`, or your own)
|
|
7
|
+
- Save drafts to JSON files
|
|
8
|
+
- Publish via pluggable adapters (safe background rebuild)
|
|
9
|
+
|
|
10
|
+
> npm allows **private** packages only with a scope (`@vedy/...`). Unscoped names cannot use `--access restricted`.
|
|
11
|
+
|
|
12
|
+
## Install (private npm)
|
|
13
|
+
|
|
14
|
+
Create the `@vedy` org on npm (once), then:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# .npmrc
|
|
18
|
+
@vedyua:registry=https://registry.npmjs.org/
|
|
19
|
+
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
|
|
20
|
+
|
|
21
|
+
npm i @vedyua/cms
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Package exports
|
|
25
|
+
|
|
26
|
+
| Import | Purpose |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| `@vedyua/cms` | React UI + schema helpers (client-safe) |
|
|
29
|
+
| `@vedyua/cms/server` | `passwordAuth`, `commandPublish`, session store |
|
|
30
|
+
| `@vedyua/cms/next` | `createContentApi` for App Router |
|
|
31
|
+
| `@vedyua/cms/styles.css` | Admin UI styles |
|
|
32
|
+
|
|
33
|
+
## Publish (maintainers)
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm login
|
|
37
|
+
# once: create org https://www.npmjs.com/org/create → @vedyua
|
|
38
|
+
cd packages/vedy-cms
|
|
39
|
+
npm publish --access restricted
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Minimal wiring
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { createContentApi } from "@vedyua/cms/next";
|
|
46
|
+
import { commandPublish, passwordAuth } from "@vedyua/cms/server";
|
|
47
|
+
|
|
48
|
+
export const api = createContentApi({
|
|
49
|
+
config,
|
|
50
|
+
sessionSecret: process.env.CONTENT_CMS_SESSION_SECRET!,
|
|
51
|
+
publicOrigin: "https://example.com",
|
|
52
|
+
auth: passwordAuth({
|
|
53
|
+
users: [{ username: "admin", password: process.env.CONTENT_CMS_PASSWORD! }],
|
|
54
|
+
}),
|
|
55
|
+
publish: commandPublish({
|
|
56
|
+
cwd: process.cwd(),
|
|
57
|
+
command: "npm run build",
|
|
58
|
+
detached: true,
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Edit flow
|
|
64
|
+
|
|
65
|
+
1. `/admin` → sign in with username/password
|
|
66
|
+
2. Open the site for editing
|
|
67
|
+
3. Click highlighted text → **Save draft**
|
|
68
|
+
4. **Publish** → rebuild the live site
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
type AdminBarProps = {
|
|
4
|
+
/** Optional brand label shown on the left. */
|
|
5
|
+
title?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Floating toolbar for edit mode. Hides itself when `editMode` is false.
|
|
9
|
+
*/
|
|
10
|
+
declare function AdminBar({ title }: AdminBarProps): react_jsx_runtime.JSX.Element | null;
|
|
11
|
+
|
|
12
|
+
export { AdminBar, type AdminBarProps };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useContentCms } from "./context";
|
|
5
|
+
import { getDocument, listTextFields } from "./define";
|
|
6
|
+
import { PageSettingsPanel } from "./page-settings";
|
|
7
|
+
function AdminBar({ title = "Content CMS" }) {
|
|
8
|
+
const {
|
|
9
|
+
config,
|
|
10
|
+
editMode,
|
|
11
|
+
session,
|
|
12
|
+
publishEnabled,
|
|
13
|
+
dirtyCount,
|
|
14
|
+
saving,
|
|
15
|
+
publishing,
|
|
16
|
+
lastError,
|
|
17
|
+
lastPublishSha,
|
|
18
|
+
saveDrafts,
|
|
19
|
+
publish,
|
|
20
|
+
discardDrafts
|
|
21
|
+
} = useContentCms();
|
|
22
|
+
const [pageSettingsOpen, setPageSettingsOpen] = useState(false);
|
|
23
|
+
if (!editMode) return null;
|
|
24
|
+
const fields = listTextFields(config);
|
|
25
|
+
const busy = saving || publishing;
|
|
26
|
+
const logoutPath = config.logoutPath ?? "/api/content/auth/logout";
|
|
27
|
+
const seoDocumentName = config.seoDocument ?? "seo";
|
|
28
|
+
const hasPageSettings = Boolean(getDocument(config, seoDocumentName)) && (config.pages?.length ?? 0) > 0;
|
|
29
|
+
return /* @__PURE__ */ jsxs("div", { className: "scms-admin-bar", role: "region", "aria-label": "Content editor toolbar", children: [
|
|
30
|
+
/* @__PURE__ */ jsxs("div", { className: "scms-admin-bar__main", children: [
|
|
31
|
+
/* @__PURE__ */ jsxs("div", { className: "scms-admin-bar__brand", children: [
|
|
32
|
+
/* @__PURE__ */ jsx("strong", { children: title }),
|
|
33
|
+
/* @__PURE__ */ jsxs("span", { className: "scms-admin-bar__meta", children: [
|
|
34
|
+
session ? `${session.name} \xB7 ` : "",
|
|
35
|
+
fields.length,
|
|
36
|
+
" text fields \xB7 ",
|
|
37
|
+
dirtyCount > 0 ? `${dirtyCount} unsaved` : "clean",
|
|
38
|
+
lastPublishSha ? ` \xB7 published ${lastPublishSha.slice(0, 7)}` : ""
|
|
39
|
+
] })
|
|
40
|
+
] }),
|
|
41
|
+
/* @__PURE__ */ jsxs("div", { className: "scms-admin-bar__actions", children: [
|
|
42
|
+
hasPageSettings ? /* @__PURE__ */ jsx(
|
|
43
|
+
"button",
|
|
44
|
+
{
|
|
45
|
+
type: "button",
|
|
46
|
+
className: `scms-btn ${pageSettingsOpen ? "scms-btn--primary" : "scms-btn--ghost"}`,
|
|
47
|
+
onClick: () => setPageSettingsOpen((open) => !open),
|
|
48
|
+
title: "Edit title, description, favicon and SEO for pages",
|
|
49
|
+
children: "Page settings"
|
|
50
|
+
}
|
|
51
|
+
) : null,
|
|
52
|
+
/* @__PURE__ */ jsx(
|
|
53
|
+
"button",
|
|
54
|
+
{
|
|
55
|
+
type: "button",
|
|
56
|
+
className: "scms-btn scms-btn--ghost",
|
|
57
|
+
disabled: dirtyCount === 0 || busy,
|
|
58
|
+
onClick: () => discardDrafts(),
|
|
59
|
+
children: "Discard"
|
|
60
|
+
}
|
|
61
|
+
),
|
|
62
|
+
/* @__PURE__ */ jsx(
|
|
63
|
+
"button",
|
|
64
|
+
{
|
|
65
|
+
type: "button",
|
|
66
|
+
className: "scms-btn scms-btn--ghost",
|
|
67
|
+
disabled: dirtyCount === 0 || busy,
|
|
68
|
+
onClick: () => void saveDrafts(),
|
|
69
|
+
children: saving ? "Saving\u2026" : "Save draft"
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
/* @__PURE__ */ jsx(
|
|
73
|
+
"button",
|
|
74
|
+
{
|
|
75
|
+
type: "button",
|
|
76
|
+
className: "scms-btn scms-btn--primary",
|
|
77
|
+
disabled: !publishEnabled || busy,
|
|
78
|
+
onClick: () => void publish(),
|
|
79
|
+
title: !publishEnabled ? "Publish adapter is not configured" : publishing ? "Rebuild already in progress" : "Save drafts, then rebuild the site safely in the background",
|
|
80
|
+
children: publishing ? "Building\u2026" : "Publish"
|
|
81
|
+
}
|
|
82
|
+
),
|
|
83
|
+
/* @__PURE__ */ jsx("a", { className: "scms-btn scms-btn--ghost", href: logoutPath, children: "Log out" })
|
|
84
|
+
] })
|
|
85
|
+
] }),
|
|
86
|
+
pageSettingsOpen ? /* @__PURE__ */ jsx(PageSettingsPanel, { open: pageSettingsOpen, onClose: () => setPageSettingsOpen(false) }) : null,
|
|
87
|
+
lastError ? /* @__PURE__ */ jsx("p", { className: "scms-admin-bar__error", children: lastError }) : null,
|
|
88
|
+
/* @__PURE__ */ jsx("p", { className: "scms-admin-bar__hint", children: "Save writes JSON on disk. Publish rebuilds the site in the background \u2014 the live site stays up until the new build is ready; a failed build rolls back." })
|
|
89
|
+
] });
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
AdminBar
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=admin-bar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/admin-bar.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\n\nimport { useContentCms } from \"./context\";\nimport { getDocument, listTextFields } from \"./define\";\nimport { PageSettingsPanel } from \"./page-settings\";\n\nexport type AdminBarProps = {\n /** Optional brand label shown on the left. */\n title?: string;\n};\n\n/**\n * Floating toolbar for edit mode. Hides itself when `editMode` is false.\n */\nexport function AdminBar({ title = \"Content CMS\" }: AdminBarProps) {\n const {\n config,\n editMode,\n session,\n publishEnabled,\n dirtyCount,\n saving,\n publishing,\n lastError,\n lastPublishSha,\n saveDrafts,\n publish,\n discardDrafts,\n } = useContentCms();\n const [pageSettingsOpen, setPageSettingsOpen] = useState(false);\n\n if (!editMode) return null;\n\n const fields = listTextFields(config);\n const busy = saving || publishing;\n const logoutPath = config.logoutPath ?? \"/api/content/auth/logout\";\n const seoDocumentName = config.seoDocument ?? \"seo\";\n const hasPageSettings =\n Boolean(getDocument(config, seoDocumentName)) && (config.pages?.length ?? 0) > 0;\n\n return (\n <div className=\"scms-admin-bar\" role=\"region\" aria-label=\"Content editor toolbar\">\n <div className=\"scms-admin-bar__main\">\n <div className=\"scms-admin-bar__brand\">\n <strong>{title}</strong>\n <span className=\"scms-admin-bar__meta\">\n {session ? `${session.name} · ` : \"\"}\n {fields.length} text fields · {dirtyCount > 0 ? `${dirtyCount} unsaved` : \"clean\"}\n {lastPublishSha ? ` · published ${lastPublishSha.slice(0, 7)}` : \"\"}\n </span>\n </div>\n <div className=\"scms-admin-bar__actions\">\n {hasPageSettings ? (\n <button\n type=\"button\"\n className={`scms-btn ${pageSettingsOpen ? \"scms-btn--primary\" : \"scms-btn--ghost\"}`}\n onClick={() => setPageSettingsOpen((open) => !open)}\n title=\"Edit title, description, favicon and SEO for pages\"\n >\n Page settings\n </button>\n ) : null}\n <button\n type=\"button\"\n className=\"scms-btn scms-btn--ghost\"\n disabled={dirtyCount === 0 || busy}\n onClick={() => discardDrafts()}\n >\n Discard\n </button>\n <button\n type=\"button\"\n className=\"scms-btn scms-btn--ghost\"\n disabled={dirtyCount === 0 || busy}\n onClick={() => void saveDrafts()}\n >\n {saving ? \"Saving…\" : \"Save draft\"}\n </button>\n <button\n type=\"button\"\n className=\"scms-btn scms-btn--primary\"\n disabled={!publishEnabled || busy}\n onClick={() => void publish()}\n title={\n !publishEnabled\n ? \"Publish adapter is not configured\"\n : publishing\n ? \"Rebuild already in progress\"\n : \"Save drafts, then rebuild the site safely in the background\"\n }\n >\n {publishing ? \"Building…\" : \"Publish\"}\n </button>\n <a className=\"scms-btn scms-btn--ghost\" href={logoutPath}>\n Log out\n </a>\n </div>\n </div>\n {pageSettingsOpen ? (\n <PageSettingsPanel open={pageSettingsOpen} onClose={() => setPageSettingsOpen(false)} />\n ) : null}\n {lastError ? <p className=\"scms-admin-bar__error\">{lastError}</p> : null}\n <p className=\"scms-admin-bar__hint\">\n Save writes JSON on disk. Publish rebuilds the site in the background — the live site stays\n up until the new build is ready; a failed build rolls back.\n </p>\n </div>\n );\n}\n"],"mappings":";AA8CU,cACA,YADA;AA5CV,SAAS,gBAAgB;AAEzB,SAAS,qBAAqB;AAC9B,SAAS,aAAa,sBAAsB;AAC5C,SAAS,yBAAyB;AAU3B,SAAS,SAAS,EAAE,QAAQ,cAAc,GAAkB;AACjE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,cAAc;AAClB,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAS,KAAK;AAE9D,MAAI,CAAC,SAAU,QAAO;AAEtB,QAAM,SAAS,eAAe,MAAM;AACpC,QAAM,OAAO,UAAU;AACvB,QAAM,aAAa,OAAO,cAAc;AACxC,QAAM,kBAAkB,OAAO,eAAe;AAC9C,QAAM,kBACJ,QAAQ,YAAY,QAAQ,eAAe,CAAC,MAAM,OAAO,OAAO,UAAU,KAAK;AAEjF,SACE,qBAAC,SAAI,WAAU,kBAAiB,MAAK,UAAS,cAAW,0BACvD;AAAA,yBAAC,SAAI,WAAU,wBACb;AAAA,2BAAC,SAAI,WAAU,yBACb;AAAA,4BAAC,YAAQ,iBAAM;AAAA,QACf,qBAAC,UAAK,WAAU,wBACb;AAAA,oBAAU,GAAG,QAAQ,IAAI,WAAQ;AAAA,UACjC,OAAO;AAAA,UAAO;AAAA,UAAgB,aAAa,IAAI,GAAG,UAAU,aAAa;AAAA,UACzE,iBAAiB,mBAAgB,eAAe,MAAM,GAAG,CAAC,CAAC,KAAK;AAAA,WACnE;AAAA,SACF;AAAA,MACA,qBAAC,SAAI,WAAU,2BACZ;AAAA,0BACC;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,WAAW,YAAY,mBAAmB,sBAAsB,iBAAiB;AAAA,YACjF,SAAS,MAAM,oBAAoB,CAAC,SAAS,CAAC,IAAI;AAAA,YAClD,OAAM;AAAA,YACP;AAAA;AAAA,QAED,IACE;AAAA,QACJ;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,WAAU;AAAA,YACV,UAAU,eAAe,KAAK;AAAA,YAC9B,SAAS,MAAM,cAAc;AAAA,YAC9B;AAAA;AAAA,QAED;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,WAAU;AAAA,YACV,UAAU,eAAe,KAAK;AAAA,YAC9B,SAAS,MAAM,KAAK,WAAW;AAAA,YAE9B,mBAAS,iBAAY;AAAA;AAAA,QACxB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,WAAU;AAAA,YACV,UAAU,CAAC,kBAAkB;AAAA,YAC7B,SAAS,MAAM,KAAK,QAAQ;AAAA,YAC5B,OACE,CAAC,iBACG,sCACA,aACE,gCACA;AAAA,YAGP,uBAAa,mBAAc;AAAA;AAAA,QAC9B;AAAA,QACA,oBAAC,OAAE,WAAU,4BAA2B,MAAM,YAAY,qBAE1D;AAAA,SACF;AAAA,OACF;AAAA,IACC,mBACC,oBAAC,qBAAkB,MAAM,kBAAkB,SAAS,MAAM,oBAAoB,KAAK,GAAG,IACpF;AAAA,IACH,YAAY,oBAAC,OAAE,WAAU,yBAAyB,qBAAU,IAAO;AAAA,IACpE,oBAAC,OAAE,WAAU,wBAAuB,0KAGpC;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ContentEditorSession } from './context.js';
|
|
3
|
+
import { ContentConfig } from './types.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
type AdminEntryProps = {
|
|
7
|
+
config: ContentConfig;
|
|
8
|
+
session?: ContentEditorSession | null;
|
|
9
|
+
authLabel?: string;
|
|
10
|
+
/** @default "password" */
|
|
11
|
+
authKind?: "password" | "oauth" | "instant";
|
|
12
|
+
publishEnabled?: boolean;
|
|
13
|
+
/** When false, login is disabled and a setup hint is shown. @default true */
|
|
14
|
+
configured?: boolean;
|
|
15
|
+
/** Site URL opened after enabling edit mode. @default "/" */
|
|
16
|
+
siteHref?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* `/admin` landing page: login (if needed), then enter visual edit mode.
|
|
21
|
+
*/
|
|
22
|
+
declare function AdminEntry({ config, session, authLabel, authKind, publishEnabled, configured, siteHref, title, }: AdminEntryProps): react_jsx_runtime.JSX.Element;
|
|
23
|
+
|
|
24
|
+
export { AdminEntry, type AdminEntryProps };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { writeBrowserCookie } from "./cookies";
|
|
5
|
+
import { listTextFields } from "./define";
|
|
6
|
+
function AdminEntry({
|
|
7
|
+
config,
|
|
8
|
+
session = null,
|
|
9
|
+
authLabel = "Sign in",
|
|
10
|
+
authKind = "password",
|
|
11
|
+
publishEnabled = false,
|
|
12
|
+
configured = true,
|
|
13
|
+
siteHref = "/",
|
|
14
|
+
title = "Content editor"
|
|
15
|
+
}) {
|
|
16
|
+
const cookieName = config.editCookie ?? "scms_edit";
|
|
17
|
+
const seoDocument = config.seoDocument ?? "seo";
|
|
18
|
+
const fields = listTextFields(config).filter(
|
|
19
|
+
(item) => !(item.document === seoDocument && item.field.startsWith("pages."))
|
|
20
|
+
);
|
|
21
|
+
const pageCount = config.pages?.length ?? 0;
|
|
22
|
+
const loginPath = config.loginPath ?? "/api/content/auth/login";
|
|
23
|
+
const logoutPath = config.logoutPath ?? "/api/content/auth/logout";
|
|
24
|
+
const [username, setUsername] = useState("");
|
|
25
|
+
const [password, setPassword] = useState("");
|
|
26
|
+
const [busy, setBusy] = useState(false);
|
|
27
|
+
const [error, setError] = useState(null);
|
|
28
|
+
async function onPasswordLogin(event) {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
setBusy(true);
|
|
31
|
+
setError(null);
|
|
32
|
+
try {
|
|
33
|
+
const response = await fetch(loginPath, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: { "Content-Type": "application/json" },
|
|
36
|
+
body: JSON.stringify({ username, password, returnTo: "/admin" })
|
|
37
|
+
});
|
|
38
|
+
const payload = await response.json().catch(() => null);
|
|
39
|
+
if (!response.ok || !payload?.ok) {
|
|
40
|
+
throw new Error(payload?.error ?? `Login failed (${response.status})`);
|
|
41
|
+
}
|
|
42
|
+
writeBrowserCookie(cookieName, "1");
|
|
43
|
+
window.location.href = "/admin";
|
|
44
|
+
} catch (err) {
|
|
45
|
+
setError(err instanceof Error ? err.message : "Login failed");
|
|
46
|
+
} finally {
|
|
47
|
+
setBusy(false);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return /* @__PURE__ */ jsx("main", { className: "scms-admin-entry", children: /* @__PURE__ */ jsxs("div", { className: "scms-admin-entry__card", children: [
|
|
51
|
+
/* @__PURE__ */ jsx("p", { className: "scms-admin-entry__eyebrow", children: "Content CMS" }),
|
|
52
|
+
/* @__PURE__ */ jsx("h1", { children: title }),
|
|
53
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
54
|
+
"Edit marked text fields on the live site. Use ",
|
|
55
|
+
/* @__PURE__ */ jsx("strong", { children: "Page settings" }),
|
|
56
|
+
" in the top bar for title, description, favicon and SEO. Save writes JSON on disk; Publish rebuilds the site safely in the background."
|
|
57
|
+
] }),
|
|
58
|
+
/* @__PURE__ */ jsx("div", { className: "scms-admin-entry__actions", children: !configured ? null : session ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
59
|
+
/* @__PURE__ */ jsx(
|
|
60
|
+
"a",
|
|
61
|
+
{
|
|
62
|
+
className: "scms-btn scms-btn--primary",
|
|
63
|
+
href: siteHref,
|
|
64
|
+
onClick: () => writeBrowserCookie(cookieName, "1"),
|
|
65
|
+
children: "Open site for editing"
|
|
66
|
+
}
|
|
67
|
+
),
|
|
68
|
+
/* @__PURE__ */ jsx("a", { className: "scms-btn scms-btn--ghost", href: logoutPath, children: "Log out" })
|
|
69
|
+
] }) : authKind === "password" ? /* @__PURE__ */ jsxs("form", { className: "scms-login-form", onSubmit: (event) => void onPasswordLogin(event), children: [
|
|
70
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
71
|
+
/* @__PURE__ */ jsx("span", { children: "Username" }),
|
|
72
|
+
/* @__PURE__ */ jsx(
|
|
73
|
+
"input",
|
|
74
|
+
{
|
|
75
|
+
name: "username",
|
|
76
|
+
autoComplete: "username",
|
|
77
|
+
value: username,
|
|
78
|
+
onChange: (event) => setUsername(event.target.value),
|
|
79
|
+
required: true
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
] }),
|
|
83
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
84
|
+
/* @__PURE__ */ jsx("span", { children: "Password" }),
|
|
85
|
+
/* @__PURE__ */ jsx(
|
|
86
|
+
"input",
|
|
87
|
+
{
|
|
88
|
+
name: "password",
|
|
89
|
+
type: "password",
|
|
90
|
+
autoComplete: "current-password",
|
|
91
|
+
value: password,
|
|
92
|
+
onChange: (event) => setPassword(event.target.value),
|
|
93
|
+
required: true
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
] }),
|
|
97
|
+
error ? /* @__PURE__ */ jsx("p", { className: "scms-login-form__error", children: error }) : null,
|
|
98
|
+
/* @__PURE__ */ jsx("button", { className: "scms-btn scms-btn--primary", type: "submit", disabled: busy, children: busy ? "Signing in\u2026" : authLabel })
|
|
99
|
+
] }) : /* @__PURE__ */ jsx(
|
|
100
|
+
"a",
|
|
101
|
+
{
|
|
102
|
+
className: "scms-btn scms-btn--primary",
|
|
103
|
+
href: `${loginPath}?returnTo=${encodeURIComponent("/admin")}`,
|
|
104
|
+
children: authLabel
|
|
105
|
+
}
|
|
106
|
+
) }),
|
|
107
|
+
!configured ? /* @__PURE__ */ jsxs("p", { className: "scms-admin-entry__session", children: [
|
|
108
|
+
"CMS env is not configured on this server yet. Public site still works; set",
|
|
109
|
+
" ",
|
|
110
|
+
/* @__PURE__ */ jsx("code", { children: "CONTENT_CMS_SESSION_SECRET" }),
|
|
111
|
+
" and editor password to enable editing."
|
|
112
|
+
] }) : session ? /* @__PURE__ */ jsxs("p", { className: "scms-admin-entry__session", children: [
|
|
113
|
+
"Signed in as ",
|
|
114
|
+
/* @__PURE__ */ jsx("strong", { children: session.name }),
|
|
115
|
+
session.email ? ` (${session.email})` : "",
|
|
116
|
+
publishEnabled ? " \xB7 publish enabled" : " \xB7 publish adapter not configured"
|
|
117
|
+
] }) : /* @__PURE__ */ jsx("p", { className: "scms-admin-entry__session", children: "Sign in to enable editing and publishing." }),
|
|
118
|
+
/* @__PURE__ */ jsxs("section", { className: "scms-admin-entry__fields", children: [
|
|
119
|
+
/* @__PURE__ */ jsx("h2", { children: "Registered fields" }),
|
|
120
|
+
pageCount > 0 ? /* @__PURE__ */ jsxs("p", { style: { marginBottom: 12, fontSize: 13, color: "var(--scms-muted)" }, children: [
|
|
121
|
+
pageCount,
|
|
122
|
+
" pages with editable SEO (title / description / OG image)"
|
|
123
|
+
] }) : null,
|
|
124
|
+
/* @__PURE__ */ jsx("ul", { children: fields.map((item) => /* @__PURE__ */ jsxs("li", { children: [
|
|
125
|
+
/* @__PURE__ */ jsx("strong", { children: item.label }),
|
|
126
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
127
|
+
item.documentLabel,
|
|
128
|
+
" \xB7 ",
|
|
129
|
+
item.document,
|
|
130
|
+
".",
|
|
131
|
+
item.field
|
|
132
|
+
] })
|
|
133
|
+
] }, `${item.document}.${item.field}`)) })
|
|
134
|
+
] })
|
|
135
|
+
] }) });
|
|
136
|
+
}
|
|
137
|
+
export {
|
|
138
|
+
AdminEntry
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=admin-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/admin-entry.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, type FormEvent } from \"react\";\n\nimport { writeBrowserCookie } from \"./cookies\";\nimport type { ContentEditorSession } from \"./context\";\nimport { listTextFields } from \"./define\";\nimport type { ContentConfig } from \"./types\";\n\nexport type AdminEntryProps = {\n config: ContentConfig;\n session?: ContentEditorSession | null;\n authLabel?: string;\n /** @default \"password\" */\n authKind?: \"password\" | \"oauth\" | \"instant\";\n publishEnabled?: boolean;\n /** When false, login is disabled and a setup hint is shown. @default true */\n configured?: boolean;\n /** Site URL opened after enabling edit mode. @default \"/\" */\n siteHref?: string;\n title?: string;\n};\n\n/**\n * `/admin` landing page: login (if needed), then enter visual edit mode.\n */\nexport function AdminEntry({\n config,\n session = null,\n authLabel = \"Sign in\",\n authKind = \"password\",\n publishEnabled = false,\n configured = true,\n siteHref = \"/\",\n title = \"Content editor\",\n}: AdminEntryProps) {\n const cookieName = config.editCookie ?? \"scms_edit\";\n const seoDocument = config.seoDocument ?? \"seo\";\n const fields = listTextFields(config).filter(\n (item) => !(item.document === seoDocument && item.field.startsWith(\"pages.\")),\n );\n const pageCount = config.pages?.length ?? 0;\n const loginPath = config.loginPath ?? \"/api/content/auth/login\";\n const logoutPath = config.logoutPath ?? \"/api/content/auth/logout\";\n\n const [username, setUsername] = useState(\"\");\n const [password, setPassword] = useState(\"\");\n const [busy, setBusy] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n async function onPasswordLogin(event: FormEvent) {\n event.preventDefault();\n setBusy(true);\n setError(null);\n try {\n const response = await fetch(loginPath, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ username, password, returnTo: \"/admin\" }),\n });\n const payload = (await response.json().catch(() => null)) as\n | { ok?: boolean; error?: string }\n | null;\n if (!response.ok || !payload?.ok) {\n throw new Error(payload?.error ?? `Login failed (${response.status})`);\n }\n writeBrowserCookie(cookieName, \"1\");\n window.location.href = \"/admin\";\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Login failed\");\n } finally {\n setBusy(false);\n }\n }\n\n return (\n <main className=\"scms-admin-entry\">\n <div className=\"scms-admin-entry__card\">\n <p className=\"scms-admin-entry__eyebrow\">Content CMS</p>\n <h1>{title}</h1>\n <p>\n Edit marked text fields on the live site. Use <strong>Page settings</strong> in the top\n bar for title, description, favicon and SEO. Save writes JSON on disk; Publish rebuilds\n the site safely in the background.\n </p>\n\n <div className=\"scms-admin-entry__actions\">\n {!configured ? null : session ? (\n <>\n <a\n className=\"scms-btn scms-btn--primary\"\n href={siteHref}\n onClick={() => writeBrowserCookie(cookieName, \"1\")}\n >\n Open site for editing\n </a>\n <a className=\"scms-btn scms-btn--ghost\" href={logoutPath}>\n Log out\n </a>\n </>\n ) : authKind === \"password\" ? (\n <form className=\"scms-login-form\" onSubmit={(event) => void onPasswordLogin(event)}>\n <label>\n <span>Username</span>\n <input\n name=\"username\"\n autoComplete=\"username\"\n value={username}\n onChange={(event) => setUsername(event.target.value)}\n required\n />\n </label>\n <label>\n <span>Password</span>\n <input\n name=\"password\"\n type=\"password\"\n autoComplete=\"current-password\"\n value={password}\n onChange={(event) => setPassword(event.target.value)}\n required\n />\n </label>\n {error ? <p className=\"scms-login-form__error\">{error}</p> : null}\n <button className=\"scms-btn scms-btn--primary\" type=\"submit\" disabled={busy}>\n {busy ? \"Signing in…\" : authLabel}\n </button>\n </form>\n ) : (\n <a\n className=\"scms-btn scms-btn--primary\"\n href={`${loginPath}?returnTo=${encodeURIComponent(\"/admin\")}`}\n >\n {authLabel}\n </a>\n )}\n </div>\n\n {!configured ? (\n <p className=\"scms-admin-entry__session\">\n CMS env is not configured on this server yet. Public site still works; set{\" \"}\n <code>CONTENT_CMS_SESSION_SECRET</code> and editor password to enable editing.\n </p>\n ) : session ? (\n <p className=\"scms-admin-entry__session\">\n Signed in as <strong>{session.name}</strong>\n {session.email ? ` (${session.email})` : \"\"}\n {publishEnabled ? \" · publish enabled\" : \" · publish adapter not configured\"}\n </p>\n ) : (\n <p className=\"scms-admin-entry__session\">Sign in to enable editing and publishing.</p>\n )}\n\n <section className=\"scms-admin-entry__fields\">\n <h2>Registered fields</h2>\n {pageCount > 0 ? (\n <p style={{ marginBottom: 12, fontSize: 13, color: \"var(--scms-muted)\" }}>\n {pageCount} pages with editable SEO (title / description / OG image)\n </p>\n ) : null}\n <ul>\n {fields.map((item) => (\n <li key={`${item.document}.${item.field}`}>\n <strong>{item.label}</strong>\n <span>\n {item.documentLabel} · {item.document}.{item.field}\n </span>\n </li>\n ))}\n </ul>\n </section>\n </div>\n </main>\n );\n}\n"],"mappings":";AA8EQ,SAUI,UAVJ,KAEA,YAFA;AA5ER,SAAS,gBAAgC;AAEzC,SAAS,0BAA0B;AAEnC,SAAS,sBAAsB;AAoBxB,SAAS,WAAW;AAAA,EACzB;AAAA,EACA,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,aAAa;AAAA,EACb,WAAW;AAAA,EACX,QAAQ;AACV,GAAoB;AAClB,QAAM,aAAa,OAAO,cAAc;AACxC,QAAM,cAAc,OAAO,eAAe;AAC1C,QAAM,SAAS,eAAe,MAAM,EAAE;AAAA,IACpC,CAAC,SAAS,EAAE,KAAK,aAAa,eAAe,KAAK,MAAM,WAAW,QAAQ;AAAA,EAC7E;AACA,QAAM,YAAY,OAAO,OAAO,UAAU;AAC1C,QAAM,YAAY,OAAO,aAAa;AACtC,QAAM,aAAa,OAAO,cAAc;AAExC,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,EAAE;AAC3C,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,EAAE;AAC3C,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AACtC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AAEtD,iBAAe,gBAAgB,OAAkB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AA;AAAA,QAAU;AAAA,SACb,IACE;AAAA,MACJ,oBAAC,QACE,iBAAO,IAAI,CAAC,SACX,qBAAC,QACC;AAAA,4BAAC,YAAQ,eAAK,OAAM;AAAA,QACpB,qBAAC,UACE;AAAA,eAAK;AAAA,UAAc;AAAA,UAAI,KAAK;AAAA,UAAS;AAAA,UAAE,KAAK;AAAA,WAC/C;AAAA,WAJO,GAAG,KAAK,QAAQ,IAAI,KAAK,KAAK,EAKvC,CACD,GACH;AAAA,OACF;AAAA,KACF,GACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ContentConfig, ContentDocuments, TextFieldType } from './types.js';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
type ContentEditorSession = {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
email: string;
|
|
9
|
+
username?: string;
|
|
10
|
+
avatarUrl?: string;
|
|
11
|
+
provider: string;
|
|
12
|
+
};
|
|
13
|
+
type ContentCmsContextValue = {
|
|
14
|
+
config: ContentConfig;
|
|
15
|
+
editMode: boolean;
|
|
16
|
+
session: ContentEditorSession | null;
|
|
17
|
+
publishEnabled: boolean;
|
|
18
|
+
documents: ContentDocuments;
|
|
19
|
+
dirtyCount: number;
|
|
20
|
+
saving: boolean;
|
|
21
|
+
publishing: boolean;
|
|
22
|
+
lastError: string | null;
|
|
23
|
+
lastPublishSha: string | null;
|
|
24
|
+
getFieldValue: (document: string, field: string) => string;
|
|
25
|
+
setFieldValue: (document: string, field: string, value: string) => void;
|
|
26
|
+
saveDrafts: () => Promise<boolean>;
|
|
27
|
+
publish: (message?: string) => Promise<boolean>;
|
|
28
|
+
discardDrafts: () => void;
|
|
29
|
+
};
|
|
30
|
+
type ContentCmsProviderProps = {
|
|
31
|
+
config: ContentConfig;
|
|
32
|
+
documents: ContentDocuments;
|
|
33
|
+
editMode?: boolean;
|
|
34
|
+
session?: ContentEditorSession | null;
|
|
35
|
+
publishEnabled?: boolean;
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
};
|
|
38
|
+
declare function ContentCmsProvider({ config, documents: initialDocuments, editMode, session, publishEnabled, children, }: ContentCmsProviderProps): react_jsx_runtime.JSX.Element;
|
|
39
|
+
declare function useContentCms(): ContentCmsContextValue;
|
|
40
|
+
declare function useContentCmsOptional(): ContentCmsContextValue | null;
|
|
41
|
+
declare function useEditableField(document: string, field: string): {
|
|
42
|
+
enabled: boolean;
|
|
43
|
+
editMode: boolean;
|
|
44
|
+
label: string;
|
|
45
|
+
type: TextFieldType;
|
|
46
|
+
value: string;
|
|
47
|
+
setValue: (next: string) => void | undefined;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { ContentCmsProvider, type ContentCmsProviderProps, type ContentEditorSession, useContentCms, useContentCmsOptional, useEditableField };
|