@glw907/cairn-cms 0.4.0 → 0.5.1
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 +4 -4
- package/dist/adapter.d.ts +34 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/auth/capabilities.d.ts +7 -0
- package/dist/auth/capabilities.d.ts.map +1 -0
- package/dist/auth/capabilities.js +26 -0
- package/dist/auth/config.d.ts +9 -9
- package/dist/auth/config.d.ts.map +1 -1
- package/dist/auth/config.js +5 -5
- package/dist/auth/guard.d.ts +1 -1
- package/dist/auth/guard.d.ts.map +1 -1
- package/dist/auth/guard.js +2 -2
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +1 -0
- package/dist/carta.d.ts +1 -1
- package/dist/carta.d.ts.map +1 -1
- package/dist/components/AdminLayout.svelte +74 -18
- package/dist/components/AdminLayout.svelte.d.ts +9 -0
- package/dist/components/AdminLayout.svelte.d.ts.map +1 -1
- package/dist/components/CollectionList.svelte +96 -0
- package/dist/components/CollectionList.svelte.d.ts +8 -0
- package/dist/components/CollectionList.svelte.d.ts.map +1 -0
- package/dist/components/ComponentPalette.svelte +34 -0
- package/dist/components/ComponentPalette.svelte.d.ts +9 -0
- package/dist/components/ComponentPalette.svelte.d.ts.map +1 -0
- package/dist/components/ConfirmPage.svelte +2 -2
- package/dist/components/EditPage.svelte +69 -31
- package/dist/components/EditPage.svelte.d.ts +2 -0
- package/dist/components/EditPage.svelte.d.ts.map +1 -1
- package/dist/components/LoginPage.svelte +5 -5
- package/dist/components/NavTree.svelte +128 -0
- package/dist/components/NavTree.svelte.d.ts +8 -0
- package/dist/components/NavTree.svelte.d.ts.map +1 -0
- package/dist/components/index.d.ts +3 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +3 -1
- package/dist/editor.d.ts +25 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +20 -0
- package/dist/email.js +4 -4
- package/dist/frontmatter.d.ts +3 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +16 -0
- package/dist/github.d.ts +22 -2
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +40 -5
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/nav.d.ts +58 -0
- package/dist/nav.d.ts.map +1 -0
- package/dist/nav.js +86 -0
- package/dist/render/glyph.d.ts +6 -0
- package/dist/render/glyph.d.ts.map +1 -0
- package/dist/render/glyph.js +5 -0
- package/dist/render/index.d.ts +6 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +8 -0
- package/dist/render/pipeline.d.ts +16 -0
- package/dist/render/pipeline.d.ts.map +1 -0
- package/dist/render/pipeline.js +29 -0
- package/dist/render/registry.d.ts +28 -0
- package/dist/render/registry.d.ts.map +1 -0
- package/dist/render/registry.js +11 -0
- package/dist/render/rehype-dispatch.d.ts +24 -0
- package/dist/render/rehype-dispatch.d.ts.map +1 -0
- package/dist/render/rehype-dispatch.js +86 -0
- package/dist/render/remark-directives.d.ts +4 -0
- package/dist/render/remark-directives.d.ts.map +1 -0
- package/dist/render/remark-directives.js +74 -0
- package/dist/slug.d.ts +7 -0
- package/dist/slug.d.ts.map +1 -0
- package/dist/slug.js +15 -0
- package/dist/sveltekit/index.d.ts +118 -13
- package/dist/sveltekit/index.d.ts.map +1 -1
- package/dist/sveltekit/index.js +250 -24
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -2
- package/package.json +20 -3
- package/src/lib/adapter.ts +37 -3
- package/src/lib/auth/capabilities.ts +35 -0
- package/src/lib/auth/config.ts +6 -6
- package/src/lib/auth/guard.ts +3 -3
- package/src/lib/auth/index.ts +1 -0
- package/src/lib/carta.ts +2 -2
- package/src/lib/components/AdminLayout.svelte +74 -18
- package/src/lib/components/CollectionList.svelte +96 -0
- package/src/lib/components/ComponentPalette.svelte +34 -0
- package/src/lib/components/ConfirmPage.svelte +2 -2
- package/src/lib/components/EditPage.svelte +69 -31
- package/src/lib/components/LoginPage.svelte +5 -5
- package/src/lib/components/NavTree.svelte +128 -0
- package/src/lib/components/index.ts +3 -1
- package/src/lib/editor.ts +38 -0
- package/src/lib/email.ts +4 -4
- package/src/lib/frontmatter.ts +17 -0
- package/src/lib/github.ts +38 -6
- package/src/lib/index.ts +3 -0
- package/src/lib/nav.ts +117 -0
- package/src/lib/render/glyph.ts +14 -0
- package/src/lib/render/index.ts +8 -0
- package/src/lib/render/pipeline.ts +37 -0
- package/src/lib/render/registry.ts +36 -0
- package/src/lib/render/rehype-dispatch.ts +97 -0
- package/src/lib/render/remark-directives.ts +71 -0
- package/src/lib/slug.ts +16 -0
- package/src/lib/sveltekit/index.ts +355 -37
- package/src/lib/utils.ts +2 -2
- package/dist/components/AdminList.svelte +0 -33
- package/dist/components/AdminList.svelte.d.ts +0 -10
- package/dist/components/AdminList.svelte.d.ts.map +0 -1
- package/src/lib/components/AdminList.svelte +0 -33
package/src/lib/adapter.ts
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
// This is the single seam that lets one admin surface serve different designs. A site
|
|
4
4
|
// supplies a `CairnAdapter` (see `src/lib/cairn.config.ts`) describing its backend repo,
|
|
5
5
|
// its editable collections (folder + form fields + frontmatter validator), and its preview
|
|
6
|
-
// plugin set. cairn-core never hard-codes a collection, tag, or directive
|
|
6
|
+
// plugin set. cairn-core never hard-codes a collection, tag, or directive; it reads them
|
|
7
7
|
// from the adapter. Field descriptors are plain data so a load function can hand them to
|
|
8
|
-
// the editor form across the server
|
|
8
|
+
// the editor form across the server-to-client boundary.
|
|
9
9
|
import type { PreviewPlugins } from './carta';
|
|
10
10
|
import type { RepoRef } from './github';
|
|
11
|
+
import type { ComponentRegistry } from './render';
|
|
11
12
|
|
|
12
13
|
interface FieldBase {
|
|
13
14
|
/** Frontmatter key and form input name. */
|
|
@@ -52,6 +53,13 @@ export interface CairnCollection {
|
|
|
52
53
|
/** Route `[type]` segment and list key, e.g. `posts`. */
|
|
53
54
|
type: string;
|
|
54
55
|
label: string;
|
|
56
|
+
/**
|
|
57
|
+
* Editing shape. `story` (the default when absent) is a dated feed entry; `page` is a
|
|
58
|
+
* navigation-placed entry with a path-like slug and no date emphasis. Drives the create
|
|
59
|
+
* form and the editor header. Never gates editing capability: the palette and toolbar are
|
|
60
|
+
* available to both. (Pass K, R4.)
|
|
61
|
+
*/
|
|
62
|
+
kind?: 'page' | 'story';
|
|
55
63
|
/** Repo-relative folder holding the collection's markdown files. */
|
|
56
64
|
dir: string;
|
|
57
65
|
/** Editor form fields, rendered in order. */
|
|
@@ -60,16 +68,42 @@ export interface CairnCollection {
|
|
|
60
68
|
validate(data: Record<string, unknown>, source: string): object;
|
|
61
69
|
}
|
|
62
70
|
|
|
71
|
+
/** A managed navigation menu, read from and committed to the site's YAML config file. */
|
|
72
|
+
export interface NavMenuConfig {
|
|
73
|
+
/** Repo-relative path to the site-config YAML, e.g. 'src/lib/site.config.yaml'. */
|
|
74
|
+
configPath: string;
|
|
75
|
+
/** Key within the file's `menus` map, e.g. 'primary'. */
|
|
76
|
+
menuName: string;
|
|
77
|
+
/** Sidebar/admin label for the menu. */
|
|
78
|
+
label: string;
|
|
79
|
+
/** Max nesting depth allowed in the editor (1 = flat). Defaults to 2. */
|
|
80
|
+
maxDepth?: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
63
83
|
export interface CairnAdapter {
|
|
64
84
|
/** Branding + magic-link email copy. */
|
|
65
85
|
siteName: string;
|
|
66
|
-
/** From: address for magic-link email
|
|
86
|
+
/** From: address for magic-link email (must be a domain-authenticated sender). */
|
|
67
87
|
sender: string;
|
|
68
88
|
/** The repository the admin reads content from and commits to. */
|
|
69
89
|
backend: RepoRef;
|
|
70
90
|
/** Site plugin set for the Carta preview (parity with the live render). */
|
|
71
91
|
preview: PreviewPlugins;
|
|
72
92
|
collections: CairnCollection[];
|
|
93
|
+
/**
|
|
94
|
+
* The site's component registry: the single declaration of its directive
|
|
95
|
+
* components (R10a). Rendering parity already flows through `preview`; this
|
|
96
|
+
* exposes the same registry so the editor's insert-component palette can read
|
|
97
|
+
* `registry.defs`. Optional: a site with no rich components (e.g. 907.life) may
|
|
98
|
+
* omit it or supply an empty registry.
|
|
99
|
+
*/
|
|
100
|
+
registry?: ComponentRegistry;
|
|
101
|
+
/**
|
|
102
|
+
* The navigation menu this site manages from `/admin/nav` (R3/Pass L2). The menu lives in the
|
|
103
|
+
* site's git-committed YAML config (read at build time by the layout, committed back by the
|
|
104
|
+
* editor). Omit to hide the nav surface, the same opt-in shape as `registry`.
|
|
105
|
+
*/
|
|
106
|
+
navMenu?: NavMenuConfig;
|
|
73
107
|
}
|
|
74
108
|
|
|
75
109
|
/** Look up a collection by its route segment, or undefined if the segment is unknown. */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// cairn-core: capability checks. Management surfaces gate on a capability, not on a role name,
|
|
2
|
+
// so the two-tier owner/editor model can grow finer capabilities (and a future role) additively.
|
|
3
|
+
// Creating a page and changing the nav are structural acts, so they sit with owner; editing a
|
|
4
|
+
// page's content and running the story feed are everyday editor work.
|
|
5
|
+
import { error } from '@sveltejs/kit';
|
|
6
|
+
import type { CairnUser } from './guard';
|
|
7
|
+
|
|
8
|
+
export type Capability =
|
|
9
|
+
| 'story:create'
|
|
10
|
+
| 'story:edit'
|
|
11
|
+
| 'page:edit'
|
|
12
|
+
| 'page:create'
|
|
13
|
+
| 'nav:manage'
|
|
14
|
+
| 'user:manage';
|
|
15
|
+
|
|
16
|
+
// One source of truth. `'all'` means every capability; otherwise the explicit grant list. A future
|
|
17
|
+
// `manager` role is one more row here, no call-site changes.
|
|
18
|
+
const CAPS_BY_ROLE: Record<CairnUser['role'], readonly Capability[] | 'all'> = {
|
|
19
|
+
owner: 'all',
|
|
20
|
+
editor: ['story:create', 'story:edit', 'page:edit'],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Does this user hold the capability? A signed-out (null) user holds nothing. */
|
|
24
|
+
export function can(user: CairnUser | null, cap: Capability): boolean {
|
|
25
|
+
if (!user) return false;
|
|
26
|
+
const grants = CAPS_BY_ROLE[user.role];
|
|
27
|
+
return grants === 'all' || grants.includes(cap);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Assert the capability for a route load/action: 401 when signed out, 403 when under-privileged. */
|
|
31
|
+
export function requireCapability(user: CairnUser | null, cap: Capability): CairnUser {
|
|
32
|
+
if (!user) throw error(401, 'Not signed in');
|
|
33
|
+
if (!can(user, cap)) throw error(403, 'You do not have permission to do that');
|
|
34
|
+
return user;
|
|
35
|
+
}
|
package/src/lib/auth/config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// cairn-core: the better-auth instance. Auth is engine code (engine-fat rule), so the whole
|
|
2
|
-
// config
|
|
2
|
+
// config lives here: Drizzle/D1 adapter, magic-link (POST-confirm-shaped send), admin roles.
|
|
3
3
|
// Instantiated PER REQUEST in hooks.server.ts (the D1 binding is request-scoped); the factory
|
|
4
4
|
// is cheap (no I/O at construction).
|
|
5
5
|
import { betterAuth } from 'better-auth';
|
|
@@ -14,7 +14,7 @@ import * as schema from './schema';
|
|
|
14
14
|
|
|
15
15
|
// Two-tier roles on the admin plugin's access-control system: `owner` holds every admin
|
|
16
16
|
// statement (manage editors, revoke sessions); `editor` holds none (content-only). `adminRoles`
|
|
17
|
-
// must name a role defined here, so owner
|
|
17
|
+
// must name a role defined here, so owner (not the plugin's built-in `admin`) is the gate.
|
|
18
18
|
const ac = createAccessControl(defaultStatements);
|
|
19
19
|
const owner = ac.newRole(defaultStatements);
|
|
20
20
|
const editor = ac.newRole({});
|
|
@@ -37,17 +37,17 @@ export interface AuthBranding {
|
|
|
37
37
|
sender: string;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/** The drizzle adapter result `betterAuth` consumes
|
|
40
|
+
/** The drizzle adapter result `betterAuth` consumes (same provider/schema everywhere). */
|
|
41
41
|
type DrizzleDb = Parameters<typeof drizzleAdapter>[0];
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* The shared better-auth config. Kept separate from `createAuth` so the test harness can run
|
|
45
45
|
* the EXACT plugin set (allowlist semantics, expiry, POST-confirm send) over an in-memory
|
|
46
|
-
* SQLite instead of D1. `disableSignUp:true` makes the `user` table the editor allowlist
|
|
46
|
+
* SQLite instead of D1. `disableSignUp:true` makes the `user` table the editor allowlist:
|
|
47
47
|
* magic-link never auto-creates, so the only way in is the owner-gated admin `createUser`
|
|
48
48
|
* (see auth/admins.ts). `adminRoles:['owner']` lets owners (not the default `admin` role)
|
|
49
49
|
* drive the admin API. Tokens are stored hashed and consumed atomically on first verify
|
|
50
|
-
* (better-auth GHSA-hc7v-rggr-4hvx)
|
|
50
|
+
* (better-auth GHSA-hc7v-rggr-4hvx), single-use by construction (C1).
|
|
51
51
|
*/
|
|
52
52
|
export function buildAuth(opts: {
|
|
53
53
|
database: DrizzleDb;
|
|
@@ -70,7 +70,7 @@ export function buildAuth(opts: {
|
|
|
70
70
|
sendMagicLink: async ({ email, token }, ctx) => {
|
|
71
71
|
// Allowlist gate: better-auth always fires this callback (even for unknown emails, to
|
|
72
72
|
// avoid enumeration) and only blocks user creation at verify. So gate the actual send
|
|
73
|
-
// here
|
|
73
|
+
// here. Never email a non-editor. The login UI shows neutral copy either way, so this
|
|
74
74
|
// leaks nothing; it just stops strangers receiving a dead link.
|
|
75
75
|
const existing = await ctx?.context.internalAdapter.findUserByEmail(email);
|
|
76
76
|
if (!existing?.user) return;
|
package/src/lib/auth/guard.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// cairn-core: server-side auth helpers the site route shims delegate to. Each takes the
|
|
2
|
-
// SvelteKit event
|
|
3
|
-
// `App.*` ambient types
|
|
2
|
+
// SvelteKit event, typed structurally so the package never depends on a site's generated
|
|
3
|
+
// `App.*` ambient types, plus the per-request `Auth` from `locals`.
|
|
4
4
|
import { redirect } from '@sveltejs/kit';
|
|
5
5
|
import type { Auth } from './config';
|
|
6
6
|
|
|
7
|
-
/** The session shape the whole admin reads
|
|
7
|
+
/** The session shape the whole admin reads: layout, guards, content fns, manage-editors. */
|
|
8
8
|
export interface CairnUser {
|
|
9
9
|
id: string;
|
|
10
10
|
email: string;
|
package/src/lib/auth/index.ts
CHANGED
|
@@ -4,3 +4,4 @@
|
|
|
4
4
|
export { createAuth, type Auth, type AuthEnv, type AuthBranding } from './config';
|
|
5
5
|
export { loadSession, requireSession, confirmSignIn, signOut, type CairnUser } from './guard';
|
|
6
6
|
export { adminsLoad, addAdmin, removeAdmin, setAdminRole, requireOwner, type AdminsData } from './admins';
|
|
7
|
+
export { can, requireCapability, type Capability } from './capabilities';
|
package/src/lib/carta.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// cairn-core: pure Carta options/transformer wiring for render-only preview.
|
|
2
2
|
//
|
|
3
|
-
// Plugins are passed in
|
|
3
|
+
// Plugins are passed in rather than imported; that seam is what the Pass D adapter formalises.
|
|
4
4
|
// No `carta-md` import: its index re-exports Svelte components that the node test env
|
|
5
5
|
// can't load. The Svelte component calls `new Carta(previewCartaOptions(...))` directly.
|
|
6
6
|
import type { Pluggable, Processor } from 'unified';
|
|
@@ -37,7 +37,7 @@ export function previewTransformers({ remarkPlugins, rehypePlugins }: PreviewPlu
|
|
|
37
37
|
return [...phase(remarkPlugins, 'remark'), ...phase(rehypePlugins, 'rehype')];
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/** Minimal Options subset we populate
|
|
40
|
+
/** Minimal Options subset we populate (avoids importing carta-md, which re-exports Svelte components). */
|
|
41
41
|
interface PreviewCartaOptions {
|
|
42
42
|
sanitizer: false;
|
|
43
43
|
rehypeOptions: { allowDangerousHtml: boolean };
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
// Neutral admin chrome
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// patterned on scosman/CMSaasStarter's `(admin)/(menu)` layout. The nav is data-driven and
|
|
6
|
-
// role-gated, so a new surface is one entry in `nav` (plus its route + component). Signed out
|
|
7
|
-
// (the login page lives under this layout) it falls back to a minimal centered shell.
|
|
8
|
-
// Each site's `admin/+layout.svelte` is a one-line shim that forwards `data` + `children`.
|
|
2
|
+
// Neutral admin chrome shared across sites. Signed in: DaisyUI drawer+navbar shell (sidebar
|
|
3
|
+
// pinned on desktop, slide-over on mobile). Signed out: minimal centered shell. The
|
|
4
|
+
// `cairn-admin` class on both roots scopes the "Warm Stone" theme; see the style block.
|
|
9
5
|
import type { Snippet } from 'svelte';
|
|
10
6
|
import type { CairnUser } from '../auth';
|
|
11
7
|
|
|
@@ -13,7 +9,14 @@
|
|
|
13
9
|
data,
|
|
14
10
|
children,
|
|
15
11
|
}: {
|
|
16
|
-
data: {
|
|
12
|
+
data: {
|
|
13
|
+
siteName: string;
|
|
14
|
+
user: CairnUser | null;
|
|
15
|
+
pathname: string;
|
|
16
|
+
collections: { type: string; label: string }[];
|
|
17
|
+
navMenus: { name: string; label: string }[];
|
|
18
|
+
canManageNav: boolean;
|
|
19
|
+
};
|
|
17
20
|
children: Snippet;
|
|
18
21
|
} = $props();
|
|
19
22
|
|
|
@@ -22,17 +25,22 @@
|
|
|
22
25
|
label: string;
|
|
23
26
|
icon: Snippet;
|
|
24
27
|
active: boolean;
|
|
25
|
-
/** Owner-only surface
|
|
28
|
+
/** Owner-only surface; hidden from regular editors. */
|
|
26
29
|
owner?: boolean;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
const nav = $derived<NavItem[]>([
|
|
30
|
-
{
|
|
31
|
-
href:
|
|
32
|
-
label:
|
|
33
|
+
...data.collections.map((collection) => ({
|
|
34
|
+
href: `/admin/${collection.type}`,
|
|
35
|
+
label: collection.label,
|
|
33
36
|
icon: contentIcon,
|
|
34
|
-
active:
|
|
35
|
-
|
|
37
|
+
active:
|
|
38
|
+
data.pathname === `/admin/${collection.type}` ||
|
|
39
|
+
data.pathname.startsWith(`/admin/edit/${collection.type}/`),
|
|
40
|
+
})),
|
|
41
|
+
...(data.canManageNav && data.navMenus.length
|
|
42
|
+
? [{ href: '/admin/nav', label: 'Navigation', icon: navIcon, active: data.pathname.startsWith('/admin/nav') }]
|
|
43
|
+
: []),
|
|
36
44
|
{
|
|
37
45
|
href: '/admin/admins',
|
|
38
46
|
label: 'Editors',
|
|
@@ -43,7 +51,7 @@
|
|
|
43
51
|
]);
|
|
44
52
|
const visibleNav = $derived(nav.filter((item) => !item.owner || data.user?.role === 'owner'));
|
|
45
53
|
|
|
46
|
-
// Close the slide-over after a nav tap on mobile
|
|
54
|
+
// Close the slide-over after a nav tap on mobile.
|
|
47
55
|
function closeDrawer(): void {
|
|
48
56
|
const toggle = document.getElementById('admin-drawer');
|
|
49
57
|
if (toggle instanceof HTMLInputElement) toggle.checked = false;
|
|
@@ -64,16 +72,23 @@
|
|
|
64
72
|
</svg>
|
|
65
73
|
{/snippet}
|
|
66
74
|
|
|
75
|
+
{#snippet navIcon()}
|
|
76
|
+
<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
|
|
77
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
|
78
|
+
d="M4 6h16M4 12h16M4 18h16" />
|
|
79
|
+
</svg>
|
|
80
|
+
{/snippet}
|
|
81
|
+
|
|
67
82
|
<svelte:head>
|
|
68
83
|
<meta name="robots" content="noindex, nofollow" />
|
|
69
84
|
</svelte:head>
|
|
70
85
|
|
|
71
86
|
{#if data.user}
|
|
72
|
-
<div class="drawer min-h-screen bg-base-200 lg:drawer-open" data-pagefind-ignore>
|
|
87
|
+
<div class="cairn-admin drawer min-h-screen bg-base-200 lg:drawer-open" data-pagefind-ignore>
|
|
73
88
|
<input id="admin-drawer" type="checkbox" class="drawer-toggle" />
|
|
74
89
|
|
|
75
90
|
<div class="drawer-content">
|
|
76
|
-
<!-- Mobile top bar
|
|
91
|
+
<!-- Mobile top bar; the desktop sidebar replaces this at lg. -->
|
|
77
92
|
<div class="navbar bg-base-100 lg:hidden">
|
|
78
93
|
<div class="flex-1">
|
|
79
94
|
<span class="px-2 text-xl font-bold">{data.siteName} CMS</span>
|
|
@@ -122,9 +137,50 @@
|
|
|
122
137
|
</div>
|
|
123
138
|
{:else}
|
|
124
139
|
<!-- Signed out (login page): no nav, just a centered surface. -->
|
|
125
|
-
<div class="min-h-screen bg-base-200" data-pagefind-ignore>
|
|
140
|
+
<div class="cairn-admin min-h-screen bg-base-200" data-pagefind-ignore>
|
|
126
141
|
<div class="mx-auto max-w-3xl px-4 py-8">
|
|
127
142
|
{@render children()}
|
|
128
143
|
</div>
|
|
129
144
|
</div>
|
|
130
145
|
{/if}
|
|
146
|
+
|
|
147
|
+
<style>
|
|
148
|
+
/* Warm Stone: a neutral, fully self-contained admin theme (R6), light-only. Overriding the
|
|
149
|
+
DaisyUI v5 tokens + font on this root re-skins the whole admin subtree by inheritance, so
|
|
150
|
+
the tool looks identical on every host regardless of the site's own theme. Values are OKLCH
|
|
151
|
+
(no hex/rgb, per the design-system rule). Warm-gray neutrals (hue ~75), violet accent. */
|
|
152
|
+
.cairn-admin {
|
|
153
|
+
color-scheme: light;
|
|
154
|
+
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
|
155
|
+
|
|
156
|
+
--color-base-100: oklch(98.5% 0.004 75);
|
|
157
|
+
--color-base-200: oklch(96% 0.005 75);
|
|
158
|
+
--color-base-300: oklch(92% 0.008 75);
|
|
159
|
+
--color-base-content: oklch(28% 0.012 75);
|
|
160
|
+
|
|
161
|
+
--color-primary: oklch(52% 0.20 293);
|
|
162
|
+
--color-primary-content: oklch(98% 0.012 293);
|
|
163
|
+
--color-secondary: oklch(45% 0.02 75);
|
|
164
|
+
--color-secondary-content: oklch(98% 0.004 75);
|
|
165
|
+
--color-accent: oklch(58% 0.16 300);
|
|
166
|
+
--color-accent-content: oklch(98% 0.012 300);
|
|
167
|
+
--color-neutral: oklch(32% 0.012 75);
|
|
168
|
+
--color-neutral-content: oklch(96% 0.004 75);
|
|
169
|
+
|
|
170
|
+
--color-info: oklch(60% 0.12 240);
|
|
171
|
+
--color-info-content: oklch(98% 0.01 240);
|
|
172
|
+
--color-success: oklch(58% 0.12 150);
|
|
173
|
+
--color-success-content: oklch(98% 0.01 150);
|
|
174
|
+
--color-warning: oklch(75% 0.15 70);
|
|
175
|
+
--color-warning-content: oklch(25% 0.02 70);
|
|
176
|
+
--color-error: oklch(58% 0.20 25);
|
|
177
|
+
--color-error-content: oklch(98% 0.01 25);
|
|
178
|
+
|
|
179
|
+
--radius-selector: 0.5rem;
|
|
180
|
+
--radius-field: 0.5rem;
|
|
181
|
+
--radius-box: 0.75rem;
|
|
182
|
+
--size-selector: 0.25rem;
|
|
183
|
+
--size-field: 0.25rem;
|
|
184
|
+
--border: 1px;
|
|
185
|
+
}
|
|
186
|
+
</style>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// One collection's entries: a table (title, date, draft badge) linking into the editor, plus a
|
|
3
|
+
// collapsible "New entry" form. The author types a title; the slug stem derives from it (R4) and
|
|
4
|
+
// stays editable. A story collection also collects a date, which createEntry forwards so the new
|
|
5
|
+
// entry opens with its date set. Placeholders differ by kind. The shell (AdminLayout) owns the
|
|
6
|
+
// chrome and nav; this renders only the body.
|
|
7
|
+
import type { CollectionListData } from '../sveltekit';
|
|
8
|
+
import { slugify } from '../slug';
|
|
9
|
+
|
|
10
|
+
let { data }: { data: CollectionListData } = $props();
|
|
11
|
+
|
|
12
|
+
let title = $state('');
|
|
13
|
+
let slug = $state('');
|
|
14
|
+
let slugEdited = $state(false);
|
|
15
|
+
|
|
16
|
+
// Keep the slug in sync with the title until the author edits the slug directly.
|
|
17
|
+
function onTitleInput(value: string) {
|
|
18
|
+
title = value;
|
|
19
|
+
if (!slugEdited) slug = slugify(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const slugPlaceholder = $derived(data.kind === 'page' ? 'about-us' : '2026-05-my-entry');
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<div class="flex items-center justify-between gap-4">
|
|
26
|
+
<h1 class="text-2xl font-bold">{data.label}</h1>
|
|
27
|
+
{#if data.canCreate}
|
|
28
|
+
<details class="dropdown dropdown-end">
|
|
29
|
+
<summary class="btn btn-primary btn-sm">New entry</summary>
|
|
30
|
+
<form
|
|
31
|
+
method="POST"
|
|
32
|
+
action="?/create"
|
|
33
|
+
class="dropdown-content z-10 mt-2 flex w-80 flex-col gap-2 rounded-box border border-base-300 bg-base-100 p-4 shadow"
|
|
34
|
+
>
|
|
35
|
+
<label class="flex flex-col gap-1">
|
|
36
|
+
<span class="text-sm font-medium">Title</span>
|
|
37
|
+
<input
|
|
38
|
+
type="text"
|
|
39
|
+
value={title}
|
|
40
|
+
oninput={(e) => onTitleInput(e.currentTarget.value)}
|
|
41
|
+
placeholder="A human title"
|
|
42
|
+
class="input w-full"
|
|
43
|
+
/>
|
|
44
|
+
</label>
|
|
45
|
+
|
|
46
|
+
{#if data.kind === 'story'}
|
|
47
|
+
<label class="flex flex-col gap-1">
|
|
48
|
+
<span class="text-sm font-medium">Date</span>
|
|
49
|
+
<input type="date" name="date" class="input w-full" />
|
|
50
|
+
</label>
|
|
51
|
+
{/if}
|
|
52
|
+
|
|
53
|
+
<label class="flex flex-col gap-1">
|
|
54
|
+
<span class="text-sm font-medium">Slug</span>
|
|
55
|
+
<input
|
|
56
|
+
type="text"
|
|
57
|
+
name="id"
|
|
58
|
+
required
|
|
59
|
+
bind:value={slug}
|
|
60
|
+
oninput={() => (slugEdited = true)}
|
|
61
|
+
placeholder={slugPlaceholder}
|
|
62
|
+
pattern="[a-z0-9]([a-z0-9-]*[a-z0-9])?"
|
|
63
|
+
class="input w-full"
|
|
64
|
+
/>
|
|
65
|
+
<span class="text-xs opacity-60">Lowercase letters, numbers, and hyphens. Becomes the filename.</span>
|
|
66
|
+
</label>
|
|
67
|
+
|
|
68
|
+
<button type="submit" class="btn btn-primary btn-sm">Create & edit</button>
|
|
69
|
+
</form>
|
|
70
|
+
</details>
|
|
71
|
+
{/if}
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
{#if data.formError}
|
|
75
|
+
<div class="alert alert-error mt-4"><span>{data.formError}</span></div>
|
|
76
|
+
{/if}
|
|
77
|
+
|
|
78
|
+
{#if data.error}
|
|
79
|
+
<div class="alert alert-warning mt-6">Couldn't load {data.label.toLowerCase()}: {data.error}</div>
|
|
80
|
+
{:else if data.entries.length === 0}
|
|
81
|
+
<p class="mt-6 opacity-60">No entries yet.</p>
|
|
82
|
+
{:else}
|
|
83
|
+
<ul class="menu mt-6 rounded-box border border-base-300 bg-base-100 p-2">
|
|
84
|
+
{#each data.entries as entry (entry.path)}
|
|
85
|
+
<li>
|
|
86
|
+
<a href="/admin/edit/{data.type}/{entry.id}" class="flex items-center justify-between gap-3">
|
|
87
|
+
<span class="flex items-center gap-2">
|
|
88
|
+
<span>{entry.title}</span>
|
|
89
|
+
{#if entry.draft}<span class="badge badge-warning badge-sm">Draft</span>{/if}
|
|
90
|
+
</span>
|
|
91
|
+
{#if entry.date}<span class="text-xs opacity-60">{entry.date}</span>{/if}
|
|
92
|
+
</a>
|
|
93
|
+
</li>
|
|
94
|
+
{/each}
|
|
95
|
+
</ul>
|
|
96
|
+
{/if}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// The insert-component palette (R10). Reads the site's component registry (R10a) and inserts a
|
|
3
|
+
// scaffolded directive snippet at the cursor via the `insert` callback. DaisyUI dropdown so it
|
|
4
|
+
// matches the Warm Stone admin theme. Shown only when the site supplies a non-empty registry; a
|
|
5
|
+
// plain-markdown site (e.g. 907.life) passes no registry and this renders nothing.
|
|
6
|
+
import type { ComponentRegistry } from '../render';
|
|
7
|
+
|
|
8
|
+
let { registry, insert }: { registry?: ComponentRegistry; insert: (template: string) => void } =
|
|
9
|
+
$props();
|
|
10
|
+
|
|
11
|
+
const defs = $derived(registry?.defs ?? []);
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
{#if defs.length > 0}
|
|
15
|
+
<div class="dropdown">
|
|
16
|
+
<button type="button" tabindex="0" class="btn btn-sm btn-ghost">Insert ▾</button>
|
|
17
|
+
<ul
|
|
18
|
+
class="dropdown-content menu z-10 mt-1 w-72 rounded-box border border-base-300 bg-base-100 p-2 shadow"
|
|
19
|
+
>
|
|
20
|
+
{#each defs as def (def.name)}
|
|
21
|
+
<li>
|
|
22
|
+
<button
|
|
23
|
+
type="button"
|
|
24
|
+
class="flex flex-col items-start gap-0.5"
|
|
25
|
+
onclick={() => insert(def.insertTemplate)}
|
|
26
|
+
>
|
|
27
|
+
<span class="font-medium">{def.label}</span>
|
|
28
|
+
<span class="text-xs opacity-60">{def.description}</span>
|
|
29
|
+
</button>
|
|
30
|
+
</li>
|
|
31
|
+
{/each}
|
|
32
|
+
</ul>
|
|
33
|
+
</div>
|
|
34
|
+
{/if}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
// The scanner-safe confirm surface (C2). A GET renders this static page
|
|
3
|
-
// The token rides in a hidden field; only the explicit form POST (the route's default action
|
|
2
|
+
// The scanner-safe confirm surface (C2). A GET renders this static page and consumes nothing.
|
|
3
|
+
// The token rides in a hidden field; only the explicit form POST (the route's default action,
|
|
4
4
|
// confirmSignIn) verifies it. Mail scanners GET URLs but don't submit forms, so prefetch can't
|
|
5
5
|
// burn the link. JS-free by design.
|
|
6
6
|
interface Props {
|
|
@@ -1,33 +1,55 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
// The editor: a per-field frontmatter form (driven by the adapter's `fields`)
|
|
3
|
-
// markdown editor whose preview runs the site
|
|
4
|
-
//
|
|
2
|
+
// The editor: a per-field frontmatter form (driven by the adapter's `fields`) beside a Carta
|
|
3
|
+
// markdown editor whose preview runs the site plugin set (`preview`). Content-forward layout:
|
|
4
|
+
// the editor is the prominent column, frontmatter sits in a side column (R4). A cairn control
|
|
5
|
+
// row hosts the insert-component palette (R10) and the preview toggle (R12); basic formatting
|
|
6
|
+
// stays on Carta's built-in toolbar (R11). Data comes from `editLoad` merged with the layout
|
|
7
|
+
// load (siteName); `carta-md` is a peer dependency.
|
|
5
8
|
import { onMount } from 'svelte';
|
|
6
9
|
import { Carta, MarkdownEditor } from 'carta-md';
|
|
7
10
|
import 'carta-md/default.css';
|
|
8
11
|
import { previewCartaOptions, type PreviewPlugins } from '../carta';
|
|
9
12
|
import type { CairnField } from '../adapter';
|
|
13
|
+
import type { ComponentRegistry } from '../render';
|
|
10
14
|
import type { EditData } from '../sveltekit';
|
|
15
|
+
import { cartaEditor } from '../editor';
|
|
16
|
+
import { dateInputValue } from '../frontmatter';
|
|
17
|
+
import ComponentPalette from './ComponentPalette.svelte';
|
|
11
18
|
|
|
12
|
-
let {
|
|
19
|
+
let {
|
|
20
|
+
data,
|
|
21
|
+
preview,
|
|
22
|
+
registry,
|
|
23
|
+
}: { data: EditData & { siteName: string }; preview: PreviewPlugins; registry?: ComponentRegistry } =
|
|
24
|
+
$props();
|
|
13
25
|
|
|
14
26
|
// Body is editable state; the Carta editor's preview runs the exact site plugin set, so it
|
|
15
27
|
// matches the live page. A hidden input carries the current value into the form.
|
|
16
|
-
// svelte-ignore state_referenced_locally
|
|
28
|
+
// svelte-ignore state_referenced_locally (seeding from the initial load is intended)
|
|
17
29
|
let body = $state(data.body);
|
|
18
30
|
|
|
19
|
-
// svelte-ignore state_referenced_locally
|
|
31
|
+
// svelte-ignore state_referenced_locally (the preview plugin set is fixed for the load)
|
|
20
32
|
const carta = new Carta(previewCartaOptions(preview));
|
|
33
|
+
const editor = cartaEditor(() => carta);
|
|
21
34
|
|
|
22
|
-
// Carta's MarkdownEditor must not render on the worker (it pulls Shiki). onMount fires only
|
|
23
|
-
//
|
|
24
|
-
// the kit-free equivalent of the per-site route's `$app/environment` `browser` guard.
|
|
35
|
+
// Carta's MarkdownEditor must not render on the worker (it pulls Shiki). onMount fires only in
|
|
36
|
+
// the browser, so SSR renders the plain textarea and the client swaps in the editor.
|
|
25
37
|
let mounted = $state(false);
|
|
38
|
+
|
|
39
|
+
// Preview toggle (R12), persisted per user. 'split' shows the live preview beside the editor;
|
|
40
|
+
// 'tabs' foregrounds the editor full width with the preview one click away.
|
|
41
|
+
let mode = $state<'split' | 'tabs'>('split');
|
|
26
42
|
onMount(() => {
|
|
27
43
|
mounted = true;
|
|
44
|
+
const saved = localStorage.getItem('cairn-admin:preview');
|
|
45
|
+
if (saved === 'tabs' || saved === 'split') mode = saved;
|
|
28
46
|
});
|
|
47
|
+
function togglePreview() {
|
|
48
|
+
mode = mode === 'split' ? 'tabs' : 'split';
|
|
49
|
+
localStorage.setItem('cairn-admin:preview', mode);
|
|
50
|
+
}
|
|
29
51
|
|
|
30
|
-
// svelte-ignore state_referenced_locally
|
|
52
|
+
// svelte-ignore state_referenced_locally (form defaults from the initial load)
|
|
31
53
|
const fm = data.frontmatter as Record<string, unknown>;
|
|
32
54
|
|
|
33
55
|
function fmString(key: string): string {
|
|
@@ -39,31 +61,58 @@
|
|
|
39
61
|
function fmFreeTags(key: string): string {
|
|
40
62
|
return Array.isArray(fm[key]) ? (fm[key] as unknown[]).map(String).join(', ') : '';
|
|
41
63
|
}
|
|
64
|
+
|
|
65
|
+
// Kind-aware header: a story leads with its date; a page leads with its slug/path.
|
|
66
|
+
const subtitle = $derived(
|
|
67
|
+
data.kind === 'page'
|
|
68
|
+
? `Page · ${data.path}`
|
|
69
|
+
: `${data.label} · ${dateInputValue(fm['date']) || data.path}`,
|
|
70
|
+
);
|
|
42
71
|
</script>
|
|
43
72
|
|
|
44
73
|
<svelte:head>
|
|
45
|
-
<title>Edit {data.title} · {data.siteName} CMS</title>
|
|
74
|
+
<title>{data.isNew ? `New ${data.label} entry` : `Edit ${data.title}`} · {data.siteName} CMS</title>
|
|
46
75
|
</svelte:head>
|
|
47
76
|
|
|
48
77
|
<div class="flex items-center justify-between gap-4">
|
|
49
78
|
<div>
|
|
50
|
-
<a href="/admin" class="text-sm opacity-70 hover:underline">← Back</a>
|
|
51
|
-
<h1 class="mt-1 text-2xl font-bold">{data.title}</h1>
|
|
52
|
-
<p class="text-sm opacity-60">{
|
|
79
|
+
<a href="/admin/{data.type}" class="text-sm opacity-70 hover:underline">← Back to {data.label}</a>
|
|
80
|
+
<h1 class="mt-1 text-2xl font-bold">{data.isNew ? `New ${data.label} entry` : data.title}</h1>
|
|
81
|
+
<p class="text-sm opacity-60">{subtitle}</p>
|
|
53
82
|
</div>
|
|
54
83
|
</div>
|
|
55
84
|
|
|
56
85
|
{#if data.saved}
|
|
57
|
-
<div class="alert alert-success mt-6"><span>Saved
|
|
86
|
+
<div class="alert alert-success mt-6"><span>Saved. Committed to main; the site will redeploy.</span></div>
|
|
58
87
|
{:else if data.error}
|
|
59
88
|
<div class="alert alert-error mt-6"><span>{data.error}</span></div>
|
|
60
89
|
{/if}
|
|
61
90
|
|
|
62
|
-
<form method="POST" action="/admin/save" class="mt-6 flex flex-col gap-5">
|
|
91
|
+
<form method="POST" action="/admin/save" class="mt-6 flex flex-col gap-5 lg:grid lg:grid-cols-[1fr_20rem] lg:items-start">
|
|
63
92
|
<input type="hidden" name="type" value={data.type} />
|
|
64
93
|
<input type="hidden" name="id" value={data.id} />
|
|
94
|
+
{#if data.isNew}<input type="hidden" name="new" value="1" />{/if}
|
|
95
|
+
|
|
96
|
+
<!-- Editor column (content-forward: first and widest) -->
|
|
97
|
+
<div class="flex flex-col gap-3 lg:order-1">
|
|
98
|
+
<div class="flex items-center justify-between gap-2">
|
|
99
|
+
<ComponentPalette {registry} insert={(template) => editor.insertComponent(template)} />
|
|
100
|
+
<button type="button" class="btn btn-sm btn-ghost" onclick={togglePreview}>
|
|
101
|
+
{mode === 'split' ? 'Hide preview' : 'Show preview'}
|
|
102
|
+
</button>
|
|
103
|
+
</div>
|
|
104
|
+
<div class="rounded-box border border-base-300 bg-base-100 p-2">
|
|
105
|
+
<input type="hidden" name="body" value={body} />
|
|
106
|
+
{#if mounted}
|
|
107
|
+
<MarkdownEditor {carta} bind:value={body} {mode} />
|
|
108
|
+
{:else}
|
|
109
|
+
<textarea bind:value={body} rows="20" class="textarea w-full font-mono"></textarea>
|
|
110
|
+
{/if}
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
65
113
|
|
|
66
|
-
|
|
114
|
+
<!-- Frontmatter side column -->
|
|
115
|
+
<fieldset class="grid gap-4 rounded-box border border-base-300 bg-base-100 p-6 lg:order-2">
|
|
67
116
|
{#each data.fields as field (field.name)}
|
|
68
117
|
{#if field.type === 'text' || field.type === 'date'}
|
|
69
118
|
<label class="flex flex-col gap-1">
|
|
@@ -72,7 +121,7 @@
|
|
|
72
121
|
type={field.type === 'date' ? 'date' : 'text'}
|
|
73
122
|
name={field.name}
|
|
74
123
|
required={field.required}
|
|
75
|
-
value={fmString(field.name)}
|
|
124
|
+
value={field.type === 'date' ? dateInputValue(fm[field.name]) : fmString(field.name)}
|
|
76
125
|
class="input w-full"
|
|
77
126
|
/>
|
|
78
127
|
</label>
|
|
@@ -108,18 +157,7 @@
|
|
|
108
157
|
</label>
|
|
109
158
|
{/if}
|
|
110
159
|
{/each}
|
|
111
|
-
</fieldset>
|
|
112
|
-
|
|
113
|
-
<div class="rounded-box border border-base-300 bg-base-100 p-2">
|
|
114
|
-
<input type="hidden" name="body" value={body} />
|
|
115
|
-
{#if mounted}
|
|
116
|
-
<MarkdownEditor {carta} bind:value={body} mode="tabs" />
|
|
117
|
-
{:else}
|
|
118
|
-
<textarea bind:value={body} rows="20" class="textarea w-full font-mono"></textarea>
|
|
119
|
-
{/if}
|
|
120
|
-
</div>
|
|
121
160
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
</div>
|
|
161
|
+
<button type="submit" class="btn btn-primary mt-2">{data.isNew ? 'Create & commit' : 'Save & commit'}</button>
|
|
162
|
+
</fieldset>
|
|
125
163
|
</form>
|