uncial-cms 4.0.3 → 5.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 (47) hide show
  1. package/README.md +1 -1
  2. package/dist/define-site.d.ts +13 -4
  3. package/dist/define-site.js +10 -0
  4. package/dist/editor-controller.d.ts +25 -0
  5. package/dist/editor-controller.js +174 -14
  6. package/dist/editor-session.d.ts +1 -1
  7. package/dist/editor-session.js +9 -1
  8. package/dist/image-source.d.ts +2 -1
  9. package/dist/image-source.js +19 -5
  10. package/dist/index-actions.js +3 -3
  11. package/dist/index-page.d.ts +2 -0
  12. package/dist/index-page.js +38 -20
  13. package/dist/index.d.ts +4 -3
  14. package/dist/index.js +1 -1
  15. package/dist/local/vite.d.ts +2 -0
  16. package/dist/local/vite.js +1 -1
  17. package/dist/served-url.js +2 -1
  18. package/dist/server/handlers.d.ts +45 -0
  19. package/dist/server/handlers.js +237 -0
  20. package/dist/server/index.d.ts +5 -0
  21. package/dist/server/index.js +4 -0
  22. package/dist/server/media.d.ts +69 -0
  23. package/dist/server/media.js +181 -0
  24. package/dist/server/migrations.d.ts +8 -0
  25. package/dist/server/migrations.js +47 -0
  26. package/dist/server/postgres-store.d.ts +72 -0
  27. package/dist/server/postgres-store.js +201 -0
  28. package/dist/server-forge/adapter.d.ts +17 -0
  29. package/dist/server-forge/adapter.js +95 -0
  30. package/dist/server-forge/media.d.ts +11 -0
  31. package/dist/server-forge/media.js +26 -0
  32. package/dist/server-forge/protocol.d.ts +65 -0
  33. package/dist/server-forge/protocol.js +27 -0
  34. package/dist/server-forge/session.d.ts +2 -0
  35. package/dist/server-forge/session.js +15 -0
  36. package/dist/svelte/EditorPage.svelte +217 -7
  37. package/dist/svelte/EditorPage.svelte.d.ts +6 -0
  38. package/dist/svelte/MediaLibrary.svelte +187 -0
  39. package/dist/svelte/MediaLibrary.svelte.d.ts +7 -0
  40. package/dist/svelte/index.d.ts +1 -0
  41. package/dist/svelte/index.js +1 -0
  42. package/dist/sveltekit/index.d.ts +7 -7
  43. package/dist/sveltekit/index.js +6 -6
  44. package/dist/types.d.ts +7 -1
  45. package/dist/upload-context.d.ts +2 -0
  46. package/dist/upload-context.js +4 -0
  47. package/package.json +18 -2
package/README.md CHANGED
@@ -149,7 +149,7 @@ leaving it unrouted.
149
149
  `createLocalVitePlugin` from `uncial-cms/local` is the same endpoint on its own,
150
150
  for a site that is not using `defineSite`; it takes the repository `root` and the
151
151
  repo-root-relative `permittedRoots` writes are confined to. It is serve-only and
152
- forces Vite to bind to `127.0.0.1`. Every path it takes is repo-root-relative,
152
+ binds Vite to `127.0.0.1` unless given a `host`. Every path it takes is repo-root-relative,
153
153
  exactly as the GitHub adapter addresses one. The adapter calls it at the fixed,
154
154
  development-only JSON endpoint `/__uncial-cms/local`:
155
155
 
@@ -4,7 +4,7 @@
4
4
  * production build, and a local-only site when no GitHub half is declared.
5
5
  */
6
6
  import { type DeployStatusTimings } from './deploy-status.js';
7
- import type { UncialCmsSiteConfig } from './types.js';
7
+ import type { GitHubSiteConfig, LocalSiteConfig, ServerSiteConfig, UncialCmsSiteConfig } from './types.js';
8
8
  /** The auth worker this project operates for sites using the canonical GitHub App. */
9
9
  export declare const DEFAULT_AUTH_WORKER_URL = "https://uncial-cms-auth.dflood.workers.dev";
10
10
  /** The canonical GitHub App a site installs on its repository. */
@@ -32,8 +32,8 @@ export interface SiteOptions {
32
32
  */
33
33
  deployStatus?: Partial<DeployStatusTimings>;
34
34
  }
35
- export interface Site {
36
- config: UncialCmsSiteConfig;
35
+ export interface Site<Config extends UncialCmsSiteConfig = UncialCmsSiteConfig> {
36
+ config: Config;
37
37
  /** No GitHub half was declared, so this site is only editable in development. */
38
38
  localOnly: boolean;
39
39
  autosaveMs: number | undefined;
@@ -42,4 +42,13 @@ export interface Site {
42
42
  }
43
43
  export declare function defineSite(options: SiteOptions, env?: {
44
44
  dev: boolean;
45
- }): Site;
45
+ }): Site<GitHubSiteConfig | LocalSiteConfig>;
46
+ export interface ServerSiteOptions {
47
+ /** The host endpoint serving `createServerContentHandlers`, e.g. '/dashboard/api/content'. */
48
+ apiBase: string;
49
+ mediaApiBase?: string;
50
+ /** Autosave writes only the Draft, so a server site may autosave. */
51
+ autosaveMs?: number;
52
+ }
53
+ /** A site whose content lives behind the host's own endpoints, in every build. */
54
+ export declare function defineServerSite(options: ServerSiteOptions): Site<ServerSiteConfig>;
@@ -36,3 +36,13 @@ export function defineSite(options, env = { dev: import.meta.env.DEV }) {
36
36
  deployStatusTimings: resolveDeployStatusTimings(options.deployStatus)
37
37
  };
38
38
  }
39
+ /** A site whose content lives behind the host's own endpoints, in every build. */
40
+ export function defineServerSite(options) {
41
+ return {
42
+ config: { forge: 'server', apiBase: options.apiBase, mediaApiBase: options.mediaApiBase },
43
+ localOnly: false,
44
+ autosaveMs: options.autosaveMs,
45
+ localContentDir: '',
46
+ deployStatusTimings: resolveDeployStatusTimings()
47
+ };
48
+ }
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import type { BlockRegistry, ContentDocument, ContentSchema } from 'uncial/core';
9
9
  import { type DeployStatusTimings, type Schedule } from './deploy-status.js';
10
+ import type { Action, VersionView } from './server-forge/protocol.js';
10
11
  import type { ForgeAdapter, SessionProvider, UncialCmsSiteConfig } from './types.js';
11
12
  export interface StatusView {
12
13
  text: string;
@@ -14,6 +15,12 @@ export interface StatusView {
14
15
  href?: string;
15
16
  tone: 'progress' | 'success' | 'error';
16
17
  }
18
+ /** A `server` forge record's Draft/Published state and the user's permitted actions. */
19
+ export interface RecordState {
20
+ draft: boolean;
21
+ published: boolean;
22
+ allowed: Action[];
23
+ }
17
24
  export interface DownloadPayload {
18
25
  filename: string;
19
26
  content: string;
@@ -29,6 +36,10 @@ export interface EditorPageUi {
29
36
  saveEnabled(enabled: boolean): void;
30
37
  /** Show or hide the conflict recovery banner. */
31
38
  conflictVisible(visible: boolean): void;
39
+ /** The record's state, reported by the `server` forge only. */
40
+ record?(state: RecordState): void;
41
+ /** The record moved to a new path; this controller no longer addresses it. */
42
+ moved?(path: string): void;
32
43
  }
33
44
  export interface EditorControllerOptions {
34
45
  config: UncialCmsSiteConfig;
@@ -65,6 +76,20 @@ export interface EditorController {
65
76
  downloadMyVersion(): void;
66
77
  /** Close the banner, leaving content and the save button untouched. */
67
78
  dismissConflict(): void;
79
+ /** `server` forge only: save any unsaved edit, then publish the Draft. */
80
+ publish(): Promise<void>;
81
+ /** `server` forge only: withdraw the Published copy. */
82
+ unpublish(): Promise<void>;
83
+ /** `server` forge only: delete the record (after confirm); true once deleted. */
84
+ remove(): Promise<boolean>;
85
+ /** `server` forge only: the record's Versions, newest first. */
86
+ history(): Promise<VersionView[]>;
87
+ /** `server` forge only: one Version's document, for read-only display. */
88
+ version(versionId: string): Promise<ContentDocument>;
89
+ /** `server` forge only: replace the Draft with a Version (after confirm); true once restored. */
90
+ restore(versionId: string): Promise<boolean>;
91
+ /** `server` forge only: save any unsaved edit, then move the record to `to`. */
92
+ move(to: string): Promise<void>;
68
93
  /** Forwarded editor change events. */
69
94
  documentChanged(doc: ContentDocument): void;
70
95
  isDirty(): boolean;
@@ -12,7 +12,12 @@ export function createEditorController(opts) {
12
12
  const timings = opts.timings ?? DEFAULT_DEPLOY_STATUS_TIMINGS;
13
13
  const schedule = opts.schedule ?? defaultSchedule;
14
14
  const destroyed = () => opts.isDestroyed?.() ?? false;
15
- const branch = config.forge === 'github' ? config.branch : 'the local checkout';
15
+ const server = config.forge === 'server' ? adapter : null;
16
+ const branch = config.forge === 'github'
17
+ ? config.branch
18
+ : config.forge === 'server'
19
+ ? 'the server'
20
+ : 'the local checkout';
16
21
  let session = null;
17
22
  let sha = null;
18
23
  let currentDocument = null;
@@ -21,6 +26,35 @@ export function createEditorController(opts) {
21
26
  let cancelAutosave = null;
22
27
  let saving = false;
23
28
  let saveAgain = false;
29
+ let record = null;
30
+ const showRecord = (next) => {
31
+ record = next;
32
+ ui.record?.(record);
33
+ };
34
+ const read = async () => {
35
+ if (!server)
36
+ return adapter.readFile(sourcePath);
37
+ const view = await server.getRecord(sourcePath);
38
+ return { content: JSON.stringify(view.draft ?? view.published), sha: view.etag, view };
39
+ };
40
+ const applyView = (view) => {
41
+ if (!view)
42
+ return;
43
+ showRecord({ draft: view.draft !== null, published: view.published !== null, allowed: view.allowed });
44
+ };
45
+ const showFailure = (error, fallback) => {
46
+ if (error instanceof ConflictError) {
47
+ // Do NOT touch content or dirty state: the unsaved edit must survive.
48
+ ui.conflictVisible(true);
49
+ ui.status({
50
+ tone: 'error',
51
+ text: `Save conflicted — this page changed on ${branch} since you loaded it.`
52
+ });
53
+ }
54
+ else {
55
+ ui.status({ tone: 'error', text: error instanceof Error ? error.message : fallback });
56
+ }
57
+ };
24
58
  const editingStatus = () => ui.status({ tone: 'progress', text: `Editing ${sourcePath} as ${session?.user.login ?? '…'}` });
25
59
  const stopPolling = () => {
26
60
  poll?.cancel();
@@ -58,10 +92,11 @@ export function createEditorController(opts) {
58
92
  config
59
93
  });
60
94
  ui.status({ tone: 'progress', text: 'Loading…' });
61
- const file = await adapter.readFile(sourcePath);
95
+ const file = await read();
62
96
  if (destroyed())
63
97
  return;
64
98
  sha = file.sha;
99
+ applyView(file.view);
65
100
  currentDocument = parseDocument(file.content, blocks, schema);
66
101
  ui.setDocument(currentDocument);
67
102
  dirty = false;
@@ -93,21 +128,23 @@ export function createEditorController(opts) {
93
128
  });
94
129
  sha = result.sha;
95
130
  dirty = false;
96
- startPolling(result.commitSha);
97
- }
98
- catch (error) {
99
- if (error instanceof ConflictError) {
100
- // Do NOT touch content or dirty state: the unsaved edit must survive.
101
- ui.conflictVisible(true);
102
- ui.status({
103
- tone: 'error',
104
- text: `Save conflicted — this page changed on ${branch} since you loaded it.`
105
- });
131
+ if (server && result.path && result.path !== sourcePath) {
132
+ saveAgain = false;
133
+ ui.status({ tone: 'success', text: `Draft saved · moved to ${result.path}` });
134
+ ui.moved?.(result.path);
135
+ }
136
+ else if (server) {
137
+ if (record)
138
+ showRecord({ ...record, draft: true });
139
+ ui.status({ tone: 'success', text: 'Draft saved' });
106
140
  }
107
141
  else {
108
- ui.status({ tone: 'error', text: error instanceof Error ? error.message : 'Save failed.' });
142
+ startPolling(result.commitSha);
109
143
  }
110
144
  }
145
+ catch (error) {
146
+ showFailure(error, 'Save failed.');
147
+ }
111
148
  finally {
112
149
  saving = false;
113
150
  if (!destroyed())
@@ -123,10 +160,11 @@ export function createEditorController(opts) {
123
160
  ' unless you have downloaded them.');
124
161
  if (!proceed)
125
162
  return; // Only "Reload latest" (confirmed) replaces content + sha.
126
- const file = await adapter.readFile(sourcePath);
163
+ const file = await read();
127
164
  if (destroyed())
128
165
  return;
129
166
  sha = file.sha;
167
+ applyView(file.view);
130
168
  currentDocument = parseDocument(file.content, blocks, schema);
131
169
  ui.setDocument(currentDocument);
132
170
  dirty = false;
@@ -145,6 +183,121 @@ export function createEditorController(opts) {
145
183
  const dismissConflict = () => {
146
184
  ui.conflictVisible(false);
147
185
  };
186
+ const transition = async (action) => {
187
+ if (!server || !session || sha === null)
188
+ return;
189
+ cancelPendingAutosave();
190
+ if (dirty) {
191
+ await save();
192
+ if (dirty)
193
+ return;
194
+ }
195
+ if (action === 'publish' && !record?.draft) {
196
+ ui.status({ tone: 'success', text: 'Nothing to publish · the Published copy is current' });
197
+ return;
198
+ }
199
+ ui.conflictVisible(false);
200
+ ui.saveEnabled(false);
201
+ ui.status({ tone: 'progress', text: action === 'publish' ? 'Publishing…' : 'Unpublishing…' });
202
+ try {
203
+ const view = await server[action](sourcePath, sha);
204
+ sha = view.etag;
205
+ applyView(view);
206
+ ui.status({
207
+ tone: 'success',
208
+ text: action === 'publish' ? 'Published · live now' : 'Unpublished · no longer public'
209
+ });
210
+ }
211
+ catch (error) {
212
+ showFailure(error, `${action === 'publish' ? 'Publish' : 'Unpublish'} failed.`);
213
+ }
214
+ finally {
215
+ if (!destroyed())
216
+ ui.saveEnabled(true);
217
+ }
218
+ };
219
+ const remove = async () => {
220
+ if (!server || !session || sha === null)
221
+ return false;
222
+ if (!opts.confirm(`Delete ${opts.pagePath ?? sourcePath}? This cannot be undone.`))
223
+ return false;
224
+ cancelPendingAutosave();
225
+ ui.saveEnabled(false);
226
+ ui.status({ tone: 'progress', text: 'Deleting…' });
227
+ try {
228
+ await adapter.deleteFile(sourcePath, { message: '', sha });
229
+ dirty = false;
230
+ ui.status({ tone: 'success', text: 'Deleted' });
231
+ return true;
232
+ }
233
+ catch (error) {
234
+ showFailure(error, 'Delete failed.');
235
+ if (!destroyed())
236
+ ui.saveEnabled(true);
237
+ return false;
238
+ }
239
+ };
240
+ const history = async () => (server ? server.versions(sourcePath) : []);
241
+ const version = async (versionId) => {
242
+ if (!server)
243
+ throw new Error('Versions exist on the server forge only.');
244
+ const doc = await server.getVersion(sourcePath, versionId);
245
+ return parseDocument(JSON.stringify(doc), blocks, schema);
246
+ };
247
+ const restore = async (versionId) => {
248
+ if (!server || !session || sha === null)
249
+ return false;
250
+ if (!opts.confirm('Restore this Version? It replaces the current Draft.'))
251
+ return false;
252
+ cancelPendingAutosave();
253
+ ui.conflictVisible(false);
254
+ ui.saveEnabled(false);
255
+ ui.status({ tone: 'progress', text: 'Restoring…' });
256
+ try {
257
+ const view = await server.restore(sourcePath, versionId, sha);
258
+ sha = view.etag;
259
+ applyView(view);
260
+ currentDocument = parseDocument(JSON.stringify(view.draft), blocks, schema);
261
+ ui.setDocument(currentDocument);
262
+ dirty = false;
263
+ ui.status({ tone: 'success', text: 'Version restored into the Draft' });
264
+ return true;
265
+ }
266
+ catch (error) {
267
+ showFailure(error, 'Restore failed.');
268
+ return false;
269
+ }
270
+ finally {
271
+ if (!destroyed())
272
+ ui.saveEnabled(true);
273
+ }
274
+ };
275
+ const move = async (to) => {
276
+ if (!server || !session || sha === null)
277
+ return;
278
+ cancelPendingAutosave();
279
+ if (dirty) {
280
+ await save();
281
+ if (dirty)
282
+ return;
283
+ }
284
+ ui.conflictVisible(false);
285
+ ui.saveEnabled(false);
286
+ ui.status({ tone: 'progress', text: 'Moving…' });
287
+ try {
288
+ const view = await server.move(sourcePath, to, sha);
289
+ sha = view.etag;
290
+ ui.status({ tone: 'success', text: `Moved to ${view.path}` });
291
+ ui.moved?.(view.path);
292
+ }
293
+ catch (error) {
294
+ showFailure(error, 'Move failed.');
295
+ }
296
+ finally {
297
+ if (!destroyed())
298
+ ui.saveEnabled(true);
299
+ }
300
+ };
148
301
  const documentChanged = (doc) => {
149
302
  currentDocument = doc;
150
303
  dirty = true;
@@ -162,6 +315,13 @@ export function createEditorController(opts) {
162
315
  reloadLatest,
163
316
  downloadMyVersion,
164
317
  dismissConflict,
318
+ publish: () => transition('publish'),
319
+ unpublish: () => transition('unpublish'),
320
+ remove,
321
+ history,
322
+ version,
323
+ restore,
324
+ move,
165
325
  documentChanged,
166
326
  isDirty: () => dirty,
167
327
  stop: () => {
@@ -24,7 +24,7 @@ import { type EditorController, type EditorPageUi } from './editor-controller.js
24
24
  import type { DeployStatusTimings, Schedule } from './deploy-status.js';
25
25
  import type { BlockRegistry, ContentSchema } from 'uncial/core';
26
26
  import type { ForgeAdapter, SessionProvider, UncialCmsSiteConfig } from './types.js';
27
- export type { DownloadPayload, EditorController, EditorPageUi, StatusView } from './editor-controller.js';
27
+ export type { DownloadPayload, EditorController, EditorPageUi, RecordState, StatusView } from './editor-controller.js';
28
28
  export interface CreateEditorSessionOptions {
29
29
  config: UncialCmsSiteConfig;
30
30
  /** Repo-root-relative path of the JSON document being edited. */
@@ -24,15 +24,23 @@ import { createEditorController } from './editor-controller.js';
24
24
  import { createGitHubAdapter, popupSessionProvider } from './github/index.js';
25
25
  import { createLocalAdapter } from './local/adapter.js';
26
26
  import { localSessionProvider } from './local/session.js';
27
+ import { createServerAdapter } from './server-forge/adapter.js';
28
+ import { serverSessionProvider } from './server-forge/session.js';
27
29
  export function forgeAdapter(config) {
28
30
  if (config.forge === 'github')
29
31
  return createGitHubAdapter();
30
32
  if (config.forge === 'local')
31
33
  return createLocalAdapter();
34
+ if (config.forge === 'server')
35
+ return createServerAdapter();
32
36
  throw new Error(`Unknown forge "${config.forge}".`);
33
37
  }
34
38
  export function defaultSessionProvider(config) {
35
- return config.forge === 'local' ? localSessionProvider : popupSessionProvider;
39
+ if (config.forge === 'local')
40
+ return localSessionProvider;
41
+ if (config.forge === 'server')
42
+ return serverSessionProvider;
43
+ return popupSessionProvider;
36
44
  }
37
45
  function triggerDownload(payload) {
38
46
  const blob = new Blob([payload.content], { type: payload.mimeType });
@@ -7,7 +7,8 @@ import type { UncialCmsSiteConfig } from './types.js';
7
7
  * dir's images the same way. `base` and `staticDir` are the site's build-time
8
8
  * values, which the config does not carry. A site with a rendition pipeline
9
9
  * replaces the listing with `list` (served paths) and the tile URL with
10
- * `thumbnail`.
10
+ * `thumbnail`. On a `server` forge, upload and browse go to the Media
11
+ * library at `mediaApiBase` instead.
11
12
  */
12
13
  export declare function cmsImageSource(config: UncialCmsSiteConfig, options?: {
13
14
  base?: string;
@@ -1,7 +1,8 @@
1
1
  import { resolveImageSrc } from 'uncial/render';
2
2
  import { resolveMediaDir, uploadImageAsset } from './index-actions.js';
3
3
  import { servedUrl } from './served-url.js';
4
- import { getActiveForge } from './upload-context.js';
4
+ import { listMedia, uploadMedia } from './server-forge/media.js';
5
+ import { configMediaDir, getActiveForge } from './upload-context.js';
5
6
  const IMAGE_EXTENSION = /\.(png|jpe?g|gif|webp|avif|svg)$/i;
6
7
  /**
7
8
  * The editor's image source for a CMS site: an upload is fitted under the
@@ -10,13 +11,26 @@ const IMAGE_EXTENSION = /\.(png|jpe?g|gif|webp|avif|svg)$/i;
10
11
  * dir's images the same way. `base` and `staticDir` are the site's build-time
11
12
  * values, which the config does not carry. A site with a rendition pipeline
12
13
  * replaces the listing with `list` (served paths) and the tile URL with
13
- * `thumbnail`.
14
+ * `thumbnail`. On a `server` forge, upload and browse go to the Media
15
+ * library at `mediaApiBase` instead.
14
16
  */
15
17
  export function cmsImageSource(config, options = {}) {
16
18
  const { base = '', staticDir = 'static', list } = options;
19
+ const thumbnail = options.thumbnail ?? ((src) => resolveImageSrc(src, base));
20
+ if (config.forge === 'server') {
21
+ const { mediaApiBase } = config;
22
+ if (!mediaApiBase)
23
+ return { thumbnail };
24
+ return {
25
+ upload: async (file) => (await uploadMedia(mediaApiBase, file)).url,
26
+ browse: list ??
27
+ (async () => (await listMedia(mediaApiBase, { contentType: 'image/*' })).items.map((item) => item.url)),
28
+ thumbnail
29
+ };
30
+ }
17
31
  return {
18
32
  upload: async (file) => {
19
- const result = await uploadImageAsset(file, { fit: true, mediaDir: config.mediaDir });
33
+ const result = await uploadImageAsset(file, { fit: true, mediaDir: configMediaDir(config) });
20
34
  return servedUrl({ config }, result.path, staticDir);
21
35
  },
22
36
  browse: list ?? (async () => {
@@ -25,7 +39,7 @@ export function cmsImageSource(config, options = {}) {
25
39
  throw new Error('No active editor session — open a page in the editor and sign in before choosing an image.');
26
40
  }
27
41
  // The same resolution `uploadImageAsset` commits under, so browse lists what upload wrote.
28
- const mediaDir = resolveMediaDir(config.mediaDir, forge.config.mediaDir);
42
+ const mediaDir = resolveMediaDir(configMediaDir(config), configMediaDir(forge.config));
29
43
  const entries = await forge.adapter.listDir(mediaDir);
30
44
  return entries
31
45
  .filter((entry) => entry.type === 'file' && IMAGE_EXTENSION.test(entry.path))
@@ -33,6 +47,6 @@ export function cmsImageSource(config, options = {}) {
33
47
  .sort()
34
48
  .map((path) => servedUrl({ config }, path, staticDir));
35
49
  }),
36
- thumbnail: options.thumbnail ?? ((src) => resolveImageSrc(src, base))
50
+ thumbnail
37
51
  };
38
52
  }
@@ -9,7 +9,7 @@ import { serializeDocument } from './document.js';
9
9
  import { NotFoundError } from './errors.js';
10
10
  import { fitImage } from './fit-image.js';
11
11
  import { defaultMapSourceToPath } from './paths/index.js';
12
- import { getActiveForge } from './upload-context.js';
12
+ import { configMediaDir, getActiveForge } from './upload-context.js';
13
13
  /** Seed `sourcePath` with a normalized empty document (create-mode commit). */
14
14
  export async function createPage(deps, { pagePath, sourcePath }) {
15
15
  const blocks = deps.blocks;
@@ -68,7 +68,7 @@ export async function uploadAsset(deps, file, opts) {
68
68
  }
69
69
  const ext = assetExtension(file.filename, file.contentType);
70
70
  const hash = await contentHash(file.bytes);
71
- const dir = resolveMediaDir(opts.mediaDir, opts.site?.config.mediaDir).replace(/\/+$/, '');
71
+ const dir = resolveMediaDir(opts.mediaDir, opts.site && configMediaDir(opts.site.config)).replace(/\/+$/, '');
72
72
  const path = `${dir}/${hash}.${ext}`;
73
73
  // Content-addressed: if the path already exists, the bytes are identical.
74
74
  try {
@@ -121,7 +121,7 @@ export async function uploadImageAsset(file, opts = {}) {
121
121
  if (!forge) {
122
122
  throw new Error('No active editor session — open a page in the editor and sign in before uploading.');
123
123
  }
124
- const mediaDir = resolveMediaDir(opts.mediaDir, opts.site?.config.mediaDir, forge.config.mediaDir);
124
+ const mediaDir = resolveMediaDir(opts.mediaDir, opts.site && configMediaDir(opts.site.config), configMediaDir(forge.config));
125
125
  const asset = opts.fit
126
126
  ? await fitImage(file instanceof Blob ? file : blobFromAssetFile(file), opts.fit === true ? {} : opts.fit)
127
127
  : file instanceof Blob
@@ -13,6 +13,8 @@ export interface MountIndexPageOptions {
13
13
  * '/uncial/cms-demo'. Default ''. */
14
14
  basePath?: string;
15
15
  editorStylesheets?: string[];
16
+ /** Open pages in the host's own editing view instead of the Fallback editor. */
17
+ editorHref?: (pagePath: string) => string;
16
18
  }
17
19
  export declare function mountIndexPage(target: HTMLElement, opts: MountIndexPageOptions): {
18
20
  destroy(): void;
@@ -7,23 +7,24 @@
7
7
  import { createPage, deletePage, listPages } from './index-actions.js';
8
8
  import { mountEditorPage } from './mount.js';
9
9
  import { defaultMapPathToSource, hashForPagePath, pagePathFromHash, validatePagePath } from './paths/index.js';
10
- import { createGitHubAdapter, popupSessionProvider } from './github/index.js';
11
- import { createLocalAdapter } from './local/adapter.js';
12
- import { localSessionProvider } from './local/session.js';
10
+ import { defaultSessionProvider, forgeAdapter } from './editor-session.js';
11
+ import { describeContentStatus } from './server-forge/protocol.js';
13
12
  import { UNCIAL_CMS_RUNTIME_SENTINEL } from './sentinel.js';
14
- function createAdapter(config) {
15
- if (config.forge === 'github')
16
- return createGitHubAdapter();
17
- if (config.forge === 'local')
18
- return createLocalAdapter();
19
- throw new Error(`Unknown forge "${config.forge}".`);
20
- }
21
13
  export function mountIndexPage(target, opts) {
22
14
  const { config, basePath = '' } = opts;
23
- const sessionProvider = opts.sessionProvider ?? (config.forge === 'local' ? localSessionProvider : popupSessionProvider);
24
- const locationLabel = config.forge === 'github' ? `${config.repo}@${config.branch}` : 'the local checkout';
25
- const branchLabel = config.forge === 'github' ? config.branch : 'the local checkout';
26
- const mapPathToSource = opts.mapPathToSource ?? ((path) => defaultMapPathToSource(path, config.contentDir));
15
+ const sessionProvider = opts.sessionProvider ?? defaultSessionProvider(config);
16
+ const branchLabel = config.forge === 'github'
17
+ ? config.branch
18
+ : config.forge === 'server'
19
+ ? 'the server'
20
+ : 'the local checkout';
21
+ const locationLabel = config.forge === 'github' ? `${config.repo}@${config.branch}` : branchLabel;
22
+ // A server record's path is the site path with its surrounding slashes ('/' = site root).
23
+ const mapPathToSource = opts.mapPathToSource ??
24
+ (config.forge === 'server'
25
+ ? (path) => (path === '' ? '/' : `/${path}/`)
26
+ : (path) => defaultMapPathToSource(path, config.contentDir));
27
+ const editHref = opts.editorHref ?? hashForPagePath;
27
28
  const root = document.createElement('div');
28
29
  root.className = 'uncial-cms-index';
29
30
  root.dataset.uncialCmsRuntime = UNCIAL_CMS_RUNTIME_SENTINEL;
@@ -65,13 +66,20 @@ export function mountIndexPage(target, opts) {
65
66
  // Always link the fallback editor — it works whether or not the page's
66
67
  // static variant has deployed yet.
67
68
  const edit = document.createElement('a');
68
- edit.href = hashForPagePath(page.pagePath);
69
+ edit.href = editHref(page.pagePath);
69
70
  edit.textContent = 'Edit';
70
71
  const del = document.createElement('button');
71
72
  del.type = 'button';
72
73
  del.textContent = 'Delete';
73
74
  del.addEventListener('click', () => void onDelete(page));
74
- item.append(live, ' ', edit, ' ', del);
75
+ item.append(live, ' ');
76
+ if (page.status) {
77
+ const status = document.createElement('span');
78
+ status.className = 'uncial-cms-index-status';
79
+ status.textContent = page.status;
80
+ item.append(status, ' ');
81
+ }
82
+ item.append(edit, ' ', del);
75
83
  list.append(item);
76
84
  }
77
85
  const form = document.createElement('form');
@@ -100,7 +108,13 @@ export function mountIndexPage(target, opts) {
100
108
  if (!adapter)
101
109
  return;
102
110
  setStatus('Loading pages…');
103
- const pages = await listPages(adapter, config.contentDir, opts.mapSourceToPath);
111
+ const pages = config.forge === 'server'
112
+ ? (await adapter.list()).map((record) => ({
113
+ pagePath: opts.mapSourceToPath?.(record.path) ?? record.path.replace(/^\/+|\/+$/g, ''),
114
+ sourcePath: record.path,
115
+ status: describeContentStatus(record.status)
116
+ }))
117
+ : await listPages(adapter, config.contentDir, opts.mapSourceToPath);
104
118
  if (destroyed)
105
119
  return;
106
120
  renderList(pages);
@@ -121,7 +135,10 @@ export function mountIndexPage(target, opts) {
121
135
  await createPage({ adapter, blocks: opts.blocks, schema: opts.schema, author: session.user }, { pagePath: result.path, sourcePath: mapPathToSource(result.path) });
122
136
  // Open the fallback editor immediately — the static variant only
123
137
  // appears after the next deploy.
124
- location.hash = hashForPagePath(result.path);
138
+ if (opts.editorHref)
139
+ location.assign(opts.editorHref(result.path));
140
+ else
141
+ location.hash = hashForPagePath(result.path);
125
142
  }
126
143
  catch (error) {
127
144
  message.hidden = false;
@@ -134,7 +151,8 @@ export function mountIndexPage(target, opts) {
134
151
  const onDelete = async (page) => {
135
152
  if (!adapter)
136
153
  return;
137
- const confirmed = window.confirm(`Delete ${page.sourcePath} from ${branchLabel}? This commits the deletion immediately.`);
154
+ const confirmed = window.confirm(`Delete ${page.sourcePath} from ${branchLabel}? ` +
155
+ (config.forge === 'server' ? 'This cannot be undone.' : 'This commits the deletion immediately.'));
138
156
  if (!confirmed)
139
157
  return;
140
158
  try {
@@ -206,7 +224,7 @@ export function mountIndexPage(target, opts) {
206
224
  window.addEventListener('beforeunload', onBeforeUnload);
207
225
  const load = async () => {
208
226
  setStatus('Signing in…');
209
- adapter = createAdapter(config);
227
+ adapter = forgeAdapter(config);
210
228
  session = await adapter.authenticate(config, sessionProvider);
211
229
  if (destroyed)
212
230
  return;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export type { ForgeAdapter, ForgeSession, GitHubSiteConfig, SessionProvider, UncialCmsSiteConfig } from './types.js';
2
- export { defineSite, DEFAULT_APP_SLUG, DEFAULT_AUTH_WORKER_URL, type Site, type SiteOptions } from './define-site.js';
1
+ export type { ForgeAdapter, ForgeSession, GitHubSiteConfig, ServerSiteConfig, SessionProvider, UncialCmsSiteConfig } from './types.js';
2
+ export { defineServerSite, defineSite, DEFAULT_APP_SLUG, DEFAULT_AUTH_WORKER_URL, type ServerSiteOptions, type Site, type SiteOptions } from './define-site.js';
3
3
  export { ConflictError, NotFoundError } from './errors.js';
4
4
  export { UNCIAL_CMS_RUNTIME_SENTINEL } from './sentinel.js';
5
5
  export { mountEditorPage, type MountEditorPageOptions } from './mount.js';
6
6
  export { createEditorSession, defaultSessionProvider, forgeAdapter, type CreateEditorSessionOptions } from './editor-session.js';
7
- export { createEditorController, conflictDownloadFilename, type DownloadPayload, type EditorController, type EditorControllerOptions, type EditorPageUi, type StatusView } from './editor-controller.js';
7
+ export { createEditorController, conflictDownloadFilename, type DownloadPayload, type EditorController, type EditorControllerOptions, type EditorPageUi, type RecordState, type StatusView } from './editor-controller.js';
8
8
  export { mountIndexPage, type MountIndexPageOptions } from './index-page.js';
9
9
  export { createPage, deletePage, listPages, uploadAsset, uploadImageAsset, type PageRef, type UploadAssetFile, type UploadAssetOptions, type UploadAssetResult, type UploadImageAssetOptions } from './index-actions.js';
10
10
  export { fitImage, type FitOptions, type FittedImage, type ImageEncoder, type EncodableImage } from './fit-image.js';
@@ -14,3 +14,4 @@ export { MAX_CONTENT_BYTES } from './constants.js';
14
14
  export { hashForPagePath, pagePathFromHash, validatePagePath } from './paths/index.js';
15
15
  export { parseDocument, serializeDocument, type Blocks } from './document.js';
16
16
  export { patSessionProvider, popupSessionProvider } from './github/index.js';
17
+ export type { Action, MediaItemView, MediaListView, VersionView } from './server-forge/protocol.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { defineSite, DEFAULT_APP_SLUG, DEFAULT_AUTH_WORKER_URL } from './define-site.js';
1
+ export { defineServerSite, defineSite, DEFAULT_APP_SLUG, DEFAULT_AUTH_WORKER_URL } from './define-site.js';
2
2
  export { ConflictError, NotFoundError } from './errors.js';
3
3
  export { UNCIAL_CMS_RUNTIME_SENTINEL } from './sentinel.js';
4
4
  export { mountEditorPage } from './mount.js';
@@ -4,5 +4,7 @@ export interface LocalVitePluginOptions {
4
4
  root: string;
5
5
  /** Repo-root-relative directories a request may address, as the site declares them. */
6
6
  permittedRoots: string[];
7
+ /** Vite `server.host`; defaults to loopback because the endpoint has no auth. */
8
+ host?: string | boolean;
7
9
  }
8
10
  export declare function createLocalVitePlugin(options: LocalVitePluginOptions): Plugin;
@@ -190,7 +190,7 @@ export function createLocalVitePlugin(options) {
190
190
  const watched = roots.permitted.map((permitted) => permitted.absolute);
191
191
  return {
192
192
  server: {
193
- host: '127.0.0.1',
193
+ host: options.host ?? '127.0.0.1',
194
194
  // Every write under a permitted root arrives through this plugin's
195
195
  // own endpoint, so a watcher event for one is the author's own
196
196
  // autosave landing. Watched, it makes Vite full-reload the page