inlaycms 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/LICENSE +21 -0
- package/README.md +462 -2
- package/assets/admin/admin.css +2 -0
- package/assets/admin/admin.js +1 -0
- package/assets/admin/editor.js +125 -0
- package/dist/adapters/admin/activity.d.ts +17 -0
- package/dist/adapters/admin/activity.js +59 -0
- package/dist/adapters/admin/assets.d.ts +14 -0
- package/dist/adapters/admin/assets.js +64 -0
- package/dist/adapters/admin/attention.d.ts +15 -0
- package/dist/adapters/admin/attention.js +34 -0
- package/dist/adapters/admin/context.d.ts +40 -0
- package/dist/adapters/admin/context.js +142 -0
- package/dist/adapters/admin/form/walk.d.ts +61 -0
- package/dist/adapters/admin/form/walk.js +565 -0
- package/dist/adapters/admin/pages.d.ts +38 -0
- package/dist/adapters/admin/pages.js +66 -0
- package/dist/adapters/admin/publish.d.ts +12 -0
- package/dist/adapters/admin/publish.js +195 -0
- package/dist/adapters/admin/routes.d.ts +47 -0
- package/dist/adapters/admin/routes.js +255 -0
- package/dist/adapters/admin/screens/backups.d.ts +11 -0
- package/dist/adapters/admin/screens/backups.js +223 -0
- package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
- package/dist/adapters/admin/screens/dashboard.js +160 -0
- package/dist/adapters/admin/screens/editor.d.ts +67 -0
- package/dist/adapters/admin/screens/editor.js +416 -0
- package/dist/adapters/admin/screens/history.d.ts +4 -0
- package/dist/adapters/admin/screens/history.js +105 -0
- package/dist/adapters/admin/screens/lists.d.ts +4 -0
- package/dist/adapters/admin/screens/lists.js +297 -0
- package/dist/adapters/admin/screens/media.d.ts +20 -0
- package/dist/adapters/admin/screens/media.js +186 -0
- package/dist/adapters/admin/screens/pickers.d.ts +29 -0
- package/dist/adapters/admin/screens/pickers.js +134 -0
- package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
- package/dist/adapters/admin/screens/preview-pane.js +74 -0
- package/dist/adapters/admin/screens/redirects.d.ts +4 -0
- package/dist/adapters/admin/screens/redirects.js +137 -0
- package/dist/adapters/admin/screens/releases.d.ts +7 -0
- package/dist/adapters/admin/screens/releases.js +287 -0
- package/dist/adapters/admin/screens/search.d.ts +22 -0
- package/dist/adapters/admin/screens/search.js +113 -0
- package/dist/adapters/admin/screens/security.d.ts +4 -0
- package/dist/adapters/admin/screens/security.js +85 -0
- package/dist/adapters/admin/screens/users.d.ts +4 -0
- package/dist/adapters/admin/screens/users.js +330 -0
- package/dist/adapters/admin/theme.d.ts +1 -0
- package/dist/adapters/admin/theme.js +1 -0
- package/dist/adapters/admin/translations.d.ts +16 -0
- package/dist/adapters/admin/translations.js +23 -0
- package/dist/adapters/admin/upload.d.ts +8 -0
- package/dist/adapters/admin/upload.js +116 -0
- package/dist/adapters/admin/views/data-table.d.ts +82 -0
- package/dist/adapters/admin/views/data-table.js +117 -0
- package/dist/adapters/admin/views/icons.d.ts +48 -0
- package/dist/adapters/admin/views/icons.js +47 -0
- package/dist/adapters/admin/views/layout.d.ts +51 -0
- package/dist/adapters/admin/views/layout.js +145 -0
- package/dist/adapters/admin/views/sheet.d.ts +15 -0
- package/dist/adapters/admin/views/sheet.js +6 -0
- package/dist/adapters/admin/views/status.d.ts +32 -0
- package/dist/adapters/admin/views/status.js +74 -0
- package/dist/adapters/auth/handler.d.ts +10 -0
- package/dist/adapters/auth/handler.js +63 -0
- package/dist/adapters/auth/request.d.ts +8 -0
- package/dist/adapters/auth/request.js +14 -0
- package/dist/adapters/cli/bin.d.ts +2 -0
- package/dist/adapters/cli/bin.js +42 -0
- package/dist/adapters/cli/main.d.ts +7 -0
- package/dist/adapters/cli/main.js +982 -0
- package/dist/adapters/cli/remote.d.ts +52 -0
- package/dist/adapters/cli/remote.js +161 -0
- package/dist/adapters/mcp/agent-refs.d.ts +9 -0
- package/dist/adapters/mcp/agent-refs.js +25 -0
- package/dist/adapters/mcp/documents.d.ts +15 -0
- package/dist/adapters/mcp/documents.js +26 -0
- package/dist/adapters/mcp/fetch-url.d.ts +19 -0
- package/dist/adapters/mcp/fetch-url.js +244 -0
- package/dist/adapters/mcp/request-state.d.ts +15 -0
- package/dist/adapters/mcp/request-state.js +38 -0
- package/dist/adapters/mcp/results.d.ts +20 -0
- package/dist/adapters/mcp/results.js +61 -0
- package/dist/adapters/mcp/route.d.ts +34 -0
- package/dist/adapters/mcp/route.js +52 -0
- package/dist/adapters/mcp/server.d.ts +44 -0
- package/dist/adapters/mcp/server.js +49 -0
- package/dist/adapters/mcp/tools/history.d.ts +5 -0
- package/dist/adapters/mcp/tools/history.js +84 -0
- package/dist/adapters/mcp/tools/media.d.ts +5 -0
- package/dist/adapters/mcp/tools/media.js +102 -0
- package/dist/adapters/mcp/tools/publish.d.ts +5 -0
- package/dist/adapters/mcp/tools/publish.js +157 -0
- package/dist/adapters/mcp/tools/read.d.ts +5 -0
- package/dist/adapters/mcp/tools/read.js +279 -0
- package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
- package/dist/adapters/mcp/tools/redirects.js +74 -0
- package/dist/adapters/mcp/tools/write.d.ts +5 -0
- package/dist/adapters/mcp/tools/write.js +304 -0
- package/dist/adapters/site/backup-schedule.d.ts +8 -0
- package/dist/adapters/site/backup-schedule.js +31 -0
- package/dist/adapters/site/cache.d.ts +29 -0
- package/dist/adapters/site/cache.js +63 -0
- package/dist/adapters/site/context.d.ts +29 -0
- package/dist/adapters/site/context.js +278 -0
- package/dist/adapters/site/head.d.ts +23 -0
- package/dist/adapters/site/head.js +44 -0
- package/dist/adapters/site/limiter.d.ts +17 -0
- package/dist/adapters/site/limiter.js +39 -0
- package/dist/adapters/site/lock.d.ts +30 -0
- package/dist/adapters/site/lock.js +143 -0
- package/dist/adapters/site/media-routes.d.ts +4 -0
- package/dist/adapters/site/media-routes.js +55 -0
- package/dist/adapters/site/plugin.d.ts +122 -0
- package/dist/adapters/site/plugin.js +436 -0
- package/dist/adapters/site/preview.d.ts +36 -0
- package/dist/adapters/site/preview.js +82 -0
- package/dist/adapters/site/public.d.ts +6 -0
- package/dist/adapters/site/public.js +87 -0
- package/dist/adapters/site/render.d.ts +45 -0
- package/dist/adapters/site/render.js +191 -0
- package/dist/adapters/site/routes.d.ts +17 -0
- package/dist/adapters/site/routes.js +125 -0
- package/dist/adapters/site/sitemap.d.ts +10 -0
- package/dist/adapters/site/sitemap.js +10 -0
- package/dist/adapters/web.d.ts +22 -0
- package/dist/adapters/web.js +75 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +58 -0
- package/dist/core/agent/format.d.ts +62 -0
- package/dist/core/agent/format.js +211 -0
- package/dist/core/agent/schema.d.ts +6 -0
- package/dist/core/agent/schema.js +86 -0
- package/dist/core/archive.d.ts +12 -0
- package/dist/core/archive.js +72 -0
- package/dist/core/auth/auth.d.ts +4911 -0
- package/dist/core/auth/auth.js +61 -0
- package/dist/core/auth/roles.d.ts +10 -0
- package/dist/core/auth/roles.js +38 -0
- package/dist/core/auth/service.d.ts +118 -0
- package/dist/core/auth/service.js +424 -0
- package/dist/core/auth/upload-token.d.ts +8 -0
- package/dist/core/auth/upload-token.js +27 -0
- package/dist/core/backup/backup.d.ts +28 -0
- package/dist/core/backup/backup.js +126 -0
- package/dist/core/backup/restore.d.ts +41 -0
- package/dist/core/backup/restore.js +264 -0
- package/dist/core/backup/schedule.d.ts +12 -0
- package/dist/core/backup/schedule.js +29 -0
- package/dist/core/boot.d.ts +63 -0
- package/dist/core/boot.js +141 -0
- package/dist/core/check.d.ts +32 -0
- package/dist/core/check.js +111 -0
- package/dist/core/content/activity.d.ts +8 -0
- package/dist/core/content/activity.js +101 -0
- package/dist/core/content/delete.d.ts +5 -0
- package/dist/core/content/delete.js +100 -0
- package/dist/core/content/diff.d.ts +6 -0
- package/dist/core/content/diff.js +129 -0
- package/dist/core/content/dry-run.d.ts +24 -0
- package/dist/core/content/dry-run.js +69 -0
- package/dist/core/content/gaps.d.ts +25 -0
- package/dist/core/content/gaps.js +50 -0
- package/dist/core/content/hidden.d.ts +33 -0
- package/dist/core/content/hidden.js +103 -0
- package/dist/core/content/history.d.ts +15 -0
- package/dist/core/content/history.js +62 -0
- package/dist/core/content/patch.d.ts +40 -0
- package/dist/core/content/patch.js +287 -0
- package/dist/core/content/path.d.ts +6 -0
- package/dist/core/content/path.js +38 -0
- package/dist/core/content/publish.d.ts +26 -0
- package/dist/core/content/publish.js +211 -0
- package/dist/core/content/read.d.ts +99 -0
- package/dist/core/content/read.js +141 -0
- package/dist/core/content/reader.d.ts +37 -0
- package/dist/core/content/reader.js +195 -0
- package/dist/core/content/refs.d.ts +44 -0
- package/dist/core/content/refs.js +161 -0
- package/dist/core/content/release-migrations.d.ts +12 -0
- package/dist/core/content/release-migrations.js +154 -0
- package/dist/core/content/save.d.ts +25 -0
- package/dist/core/content/save.js +87 -0
- package/dist/core/content/schema.d.ts +22 -0
- package/dist/core/content/schema.js +127 -0
- package/dist/core/content/search.d.ts +8 -0
- package/dist/core/content/search.js +89 -0
- package/dist/core/content/shipped-input.d.ts +39 -0
- package/dist/core/content/shipped-input.js +221 -0
- package/dist/core/content/shipped.d.ts +112 -0
- package/dist/core/content/shipped.js +437 -0
- package/dist/core/content/slug.d.ts +23 -0
- package/dist/core/content/slug.js +182 -0
- package/dist/core/content/stats.d.ts +11 -0
- package/dist/core/content/stats.js +30 -0
- package/dist/core/content/translate.d.ts +3 -0
- package/dist/core/content/translate.js +68 -0
- package/dist/core/content/usages.d.ts +13 -0
- package/dist/core/content/usages.js +70 -0
- package/dist/core/content/validate.d.ts +21 -0
- package/dist/core/content/validate.js +124 -0
- package/dist/core/content/write.d.ts +10 -0
- package/dist/core/content/write.js +93 -0
- package/dist/core/core.d.ts +227 -0
- package/dist/core/core.js +251 -0
- package/dist/core/db/connection.d.ts +6 -0
- package/dist/core/db/connection.js +12 -0
- package/dist/core/db/migrate.d.ts +9 -0
- package/dist/core/db/migrate.js +42 -0
- package/dist/core/db/migrations/0001_content.d.ts +2 -0
- package/dist/core/db/migrations/0001_content.js +69 -0
- package/dist/core/db/migrations/0002_media.d.ts +2 -0
- package/dist/core/db/migrations/0002_media.js +26 -0
- package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
- package/dist/core/db/migrations/0003_redirects.js +19 -0
- package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
- package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
- package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
- package/dist/core/db/migrations/0005_site_lock.js +10 -0
- package/dist/core/db/migrations/0006_releases.d.ts +3 -0
- package/dist/core/db/migrations/0006_releases.js +34 -0
- package/dist/core/db/schema.d.ts +155 -0
- package/dist/core/db/schema.js +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +15 -0
- package/dist/core/export/export.d.ts +17 -0
- package/dist/core/export/export.js +185 -0
- package/dist/core/export/format.d.ts +241 -0
- package/dist/core/export/format.js +106 -0
- package/dist/core/export/import.d.ts +54 -0
- package/dist/core/export/import.js +180 -0
- package/dist/core/export/read.d.ts +16 -0
- package/dist/core/export/read.js +234 -0
- package/dist/core/export/replace.d.ts +17 -0
- package/dist/core/export/replace.js +36 -0
- package/dist/core/export/report.d.ts +55 -0
- package/dist/core/export/report.js +50 -0
- package/dist/core/export/schema.d.ts +8 -0
- package/dist/core/export/schema.js +47 -0
- package/dist/core/export/stage.d.ts +25 -0
- package/dist/core/export/stage.js +192 -0
- package/dist/core/fields/builtins.d.ts +70 -0
- package/dist/core/fields/builtins.js +335 -0
- package/dist/core/fields/define.d.ts +86 -0
- package/dist/core/fields/define.js +34 -0
- package/dist/core/fields/walk.d.ts +49 -0
- package/dist/core/fields/walk.js +270 -0
- package/dist/core/fields/widgets.d.ts +27 -0
- package/dist/core/fields/widgets.js +330 -0
- package/dist/core/fields/zod-internals.d.ts +29 -0
- package/dist/core/fields/zod-internals.js +28 -0
- package/dist/core/media/detect.d.ts +5 -0
- package/dist/core/media/detect.js +66 -0
- package/dist/core/media/labels.d.ts +6 -0
- package/dist/core/media/labels.js +17 -0
- package/dist/core/media/library.d.ts +45 -0
- package/dist/core/media/library.js +239 -0
- package/dist/core/media/store.d.ts +11 -0
- package/dist/core/media/store.js +49 -0
- package/dist/core/media/variants.d.ts +10 -0
- package/dist/core/media/variants.js +59 -0
- package/dist/core/messages/en.d.ts +1278 -0
- package/dist/core/messages/en.js +1287 -0
- package/dist/core/messages/index.d.ts +7 -0
- package/dist/core/messages/index.js +14 -0
- package/dist/core/preview.d.ts +16 -0
- package/dist/core/preview.js +42 -0
- package/dist/core/redirects/collapse.d.ts +68 -0
- package/dist/core/redirects/collapse.js +153 -0
- package/dist/core/redirects/csv.d.ts +15 -0
- package/dist/core/redirects/csv.js +68 -0
- package/dist/core/redirects/redirects.d.ts +58 -0
- package/dist/core/redirects/redirects.js +545 -0
- package/dist/core/registry/content.d.ts +26 -0
- package/dist/core/registry/content.js +9 -0
- package/dist/core/registry/define.d.ts +145 -0
- package/dist/core/registry/define.js +41 -0
- package/dist/core/registry/migration.d.ts +44 -0
- package/dist/core/registry/migration.js +4 -0
- package/dist/core/registry/registry.d.ts +18 -0
- package/dist/core/registry/registry.js +255 -0
- package/dist/core/registry/render.d.ts +98 -0
- package/dist/core/registry/render.js +1 -0
- package/dist/core/registry/route.d.ts +42 -0
- package/dist/core/registry/route.js +3 -0
- package/dist/core/release/bundle.d.ts +21 -0
- package/dist/core/release/bundle.js +252 -0
- package/dist/core/release/keys.d.ts +11 -0
- package/dist/core/release/keys.js +60 -0
- package/dist/core/release/manifest.d.ts +103 -0
- package/dist/core/release/manifest.js +138 -0
- package/dist/core/release/pack.d.ts +20 -0
- package/dist/core/release/pack.js +97 -0
- package/dist/core/release/pointer.d.ts +19 -0
- package/dist/core/release/pointer.js +53 -0
- package/dist/core/release/read.d.ts +59 -0
- package/dist/core/release/read.js +256 -0
- package/dist/core/report.d.ts +31 -0
- package/dist/core/report.js +37 -0
- package/dist/core/richtext/html.d.ts +15 -0
- package/dist/core/richtext/html.js +81 -0
- package/dist/core/richtext/markdown.d.ts +19 -0
- package/dist/core/richtext/markdown.js +951 -0
- package/dist/core/richtext/schema.d.ts +98 -0
- package/dist/core/richtext/schema.js +275 -0
- package/dist/core/site/live.d.ts +56 -0
- package/dist/core/site/live.js +145 -0
- package/dist/core/site/paths.d.ts +15 -0
- package/dist/core/site/paths.js +64 -0
- package/dist/core/site/resolve.d.ts +9 -0
- package/dist/core/site/resolve.js +202 -0
- package/dist/core/site/sitemap.d.ts +11 -0
- package/dist/core/site/sitemap.js +24 -0
- package/dist/core/site-lock/site-lock.d.ts +21 -0
- package/dist/core/site-lock/site-lock.js +65 -0
- package/dist/core/site-lock/token.d.ts +7 -0
- package/dist/core/site-lock/token.js +24 -0
- package/dist/core/theme.d.ts +22 -0
- package/dist/core/theme.js +133 -0
- package/dist/core/types.d.ts +253 -0
- package/dist/core/types.js +1 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +5 -0
- package/dist/host/activate.d.ts +53 -0
- package/dist/host/activate.js +162 -0
- package/dist/host/app.d.ts +46 -0
- package/dist/host/app.js +129 -0
- package/dist/host/bin.d.ts +5 -0
- package/dist/host/bin.js +8 -0
- package/dist/host/config.d.ts +36 -0
- package/dist/host/config.js +152 -0
- package/dist/host/dev.d.ts +10 -0
- package/dist/host/dev.js +293 -0
- package/dist/host/diff.d.ts +78 -0
- package/dist/host/diff.js +346 -0
- package/dist/host/hooks.d.ts +41 -0
- package/dist/host/hooks.js +49 -0
- package/dist/host/ipc.d.ts +123 -0
- package/dist/host/ipc.js +61 -0
- package/dist/host/preview-proxy.d.ts +24 -0
- package/dist/host/preview-proxy.js +154 -0
- package/dist/host/preview-worker.d.ts +42 -0
- package/dist/host/preview-worker.js +242 -0
- package/dist/host/primary.d.ts +38 -0
- package/dist/host/primary.js +357 -0
- package/dist/host/push.d.ts +125 -0
- package/dist/host/push.js +420 -0
- package/dist/host/serve.d.ts +16 -0
- package/dist/host/serve.js +150 -0
- package/dist/host/store.d.ts +48 -0
- package/dist/host/store.js +109 -0
- package/dist/host/worker.d.ts +67 -0
- package/dist/host/worker.js +310 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +32 -0
- package/dist/jsx/html.d.ts +16 -0
- package/dist/jsx/html.js +65 -0
- package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
- package/dist/jsx/jsx-dev-runtime.js +5 -0
- package/dist/jsx/jsx-runtime.d.ts +17 -0
- package/dist/jsx/jsx-runtime.js +41 -0
- package/dist/site.d.ts +17 -0
- package/dist/site.js +14 -0
- package/package.json +111 -3
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Schema } from 'prosemirror-model';
|
|
2
|
+
import type { ContentRef } from '../types.js';
|
|
3
|
+
export declare const RICH_TEXT_FEATURES: readonly ['heading', 'bold', 'italic', 'link', 'bulletList', 'orderedList', 'blockquote', 'image', 'hardBreak'];
|
|
4
|
+
export type RichTextFeature = (typeof RICH_TEXT_FEATURES)[number];
|
|
5
|
+
export interface RichTextOptions {
|
|
6
|
+
features: readonly RichTextFeature[];
|
|
7
|
+
headings: readonly number[];
|
|
8
|
+
}
|
|
9
|
+
export declare const DEFAULT_RICH_TEXT: RichTextOptions;
|
|
10
|
+
export type RichTextMark = {
|
|
11
|
+
type: 'link';
|
|
12
|
+
attrs: {
|
|
13
|
+
href: string;
|
|
14
|
+
} | {
|
|
15
|
+
document: string;
|
|
16
|
+
};
|
|
17
|
+
} | {
|
|
18
|
+
type: 'bold';
|
|
19
|
+
} | {
|
|
20
|
+
type: 'italic';
|
|
21
|
+
};
|
|
22
|
+
export type RichTextText = {
|
|
23
|
+
type: 'text';
|
|
24
|
+
text: string;
|
|
25
|
+
marks?: RichTextMark[];
|
|
26
|
+
};
|
|
27
|
+
export type RichTextHardBreak = {
|
|
28
|
+
type: 'hardBreak';
|
|
29
|
+
marks?: RichTextMark[];
|
|
30
|
+
};
|
|
31
|
+
export type RichTextImage = {
|
|
32
|
+
type: 'image';
|
|
33
|
+
attrs: {
|
|
34
|
+
media: string;
|
|
35
|
+
alt?: string;
|
|
36
|
+
};
|
|
37
|
+
marks?: RichTextMark[];
|
|
38
|
+
};
|
|
39
|
+
export type RichTextInline = RichTextText | RichTextHardBreak | RichTextImage;
|
|
40
|
+
export type RichTextParagraph = {
|
|
41
|
+
type: 'paragraph';
|
|
42
|
+
content?: RichTextInline[];
|
|
43
|
+
};
|
|
44
|
+
export type RichTextHeading = {
|
|
45
|
+
type: 'heading';
|
|
46
|
+
attrs: {
|
|
47
|
+
level: number;
|
|
48
|
+
};
|
|
49
|
+
content?: RichTextText[];
|
|
50
|
+
};
|
|
51
|
+
export type RichTextListItem = {
|
|
52
|
+
type: 'listItem';
|
|
53
|
+
content: [RichTextParagraph, ...RichTextBlock[]];
|
|
54
|
+
};
|
|
55
|
+
export type RichTextBulletList = {
|
|
56
|
+
type: 'bulletList';
|
|
57
|
+
content: RichTextListItem[];
|
|
58
|
+
};
|
|
59
|
+
export type RichTextOrderedList = {
|
|
60
|
+
type: 'orderedList';
|
|
61
|
+
attrs?: {
|
|
62
|
+
start: number;
|
|
63
|
+
};
|
|
64
|
+
content: RichTextListItem[];
|
|
65
|
+
};
|
|
66
|
+
export type RichTextBlockquote = {
|
|
67
|
+
type: 'blockquote';
|
|
68
|
+
content: RichTextBlock[];
|
|
69
|
+
};
|
|
70
|
+
export type RichTextBlock = RichTextParagraph | RichTextHeading | RichTextBulletList | RichTextOrderedList | RichTextBlockquote;
|
|
71
|
+
export type RichTextNode = RichTextBlock | RichTextListItem | RichTextInline;
|
|
72
|
+
export type RichTextDoc = {
|
|
73
|
+
type: 'doc';
|
|
74
|
+
content: RichTextNode[];
|
|
75
|
+
};
|
|
76
|
+
/** Tiptap's node and mark names. The mark order is the canonical order of marks on a node. */
|
|
77
|
+
export declare const richTextSchema: Schema<"blockquote" | "bulletList" | "doc" | "hardBreak" | "heading" | "image" | "listItem" | "orderedList" | "paragraph" | "text", "bold" | "italic" | "link">;
|
|
78
|
+
/**
|
|
79
|
+
* A link address rich text can hold: a safe URL without control characters, which
|
|
80
|
+
* Markdown can't carry and so wouldn't read back.
|
|
81
|
+
*/
|
|
82
|
+
export declare function isRichTextHref(href: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Validates `value` as a rich text doc allowed by `opts` and returns it
|
|
85
|
+
* normalized (see Decision 7 of the Phase 3 plan), or `{ ok: false }`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function parseRichText(value: unknown, opts: RichTextOptions): {
|
|
88
|
+
ok: true;
|
|
89
|
+
doc: RichTextDoc;
|
|
90
|
+
} | {
|
|
91
|
+
ok: false;
|
|
92
|
+
};
|
|
93
|
+
/** The doc's text: blocks joined by `\n`, a hard break as `\n`, images left out. */
|
|
94
|
+
export declare function richTextText(doc: RichTextDoc): string;
|
|
95
|
+
/** True if the doc has no non-whitespace text and no image. */
|
|
96
|
+
export declare function richTextIsBlank(doc: RichTextDoc): boolean;
|
|
97
|
+
/** `media` refs for images and `document` refs for internal links, in document order. */
|
|
98
|
+
export declare function richTextRefs(doc: RichTextDoc): ContentRef[];
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { Schema } from 'prosemirror-model';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { isSafeUrl } from '../fields/define.js';
|
|
4
|
+
import { isRecord } from '../fields/zod-internals.js';
|
|
5
|
+
export const RICH_TEXT_FEATURES = [
|
|
6
|
+
'heading',
|
|
7
|
+
'bold',
|
|
8
|
+
'italic',
|
|
9
|
+
'link',
|
|
10
|
+
'bulletList',
|
|
11
|
+
'orderedList',
|
|
12
|
+
'blockquote',
|
|
13
|
+
'image',
|
|
14
|
+
'hardBreak',
|
|
15
|
+
];
|
|
16
|
+
export const DEFAULT_RICH_TEXT = { features: RICH_TEXT_FEATURES, headings: [2, 3, 4] };
|
|
17
|
+
/** Tiptap's node and mark names. The mark order is the canonical order of marks on a node. */
|
|
18
|
+
export const richTextSchema = new Schema({
|
|
19
|
+
nodes: {
|
|
20
|
+
doc: { content: 'block*' },
|
|
21
|
+
paragraph: { group: 'block', content: 'inline*' },
|
|
22
|
+
heading: { group: 'block', content: 'text*', attrs: { level: {} } },
|
|
23
|
+
bulletList: { group: 'block', content: 'listItem+' },
|
|
24
|
+
orderedList: { group: 'block', content: 'listItem+', attrs: { start: { default: 1 } } },
|
|
25
|
+
listItem: { content: 'paragraph block*' },
|
|
26
|
+
blockquote: { group: 'block', content: 'block+' },
|
|
27
|
+
text: { group: 'inline' },
|
|
28
|
+
hardBreak: { group: 'inline', inline: true },
|
|
29
|
+
image: { group: 'inline', inline: true, attrs: { media: {}, alt: { default: null } } },
|
|
30
|
+
},
|
|
31
|
+
marks: {
|
|
32
|
+
link: { attrs: { href: { default: null }, document: { default: null } }, inclusive: false },
|
|
33
|
+
bold: {},
|
|
34
|
+
italic: {},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const NODE_FEATURE = {
|
|
38
|
+
heading: 'heading',
|
|
39
|
+
bulletList: 'bulletList',
|
|
40
|
+
orderedList: 'orderedList',
|
|
41
|
+
blockquote: 'blockquote',
|
|
42
|
+
image: 'image',
|
|
43
|
+
hardBreak: 'hardBreak',
|
|
44
|
+
};
|
|
45
|
+
const LEAVES = new Set(['text', 'hardBreak', 'image']);
|
|
46
|
+
const HEX64 = /^[0-9a-f]{64}$/;
|
|
47
|
+
const UUID = z.uuid();
|
|
48
|
+
class Rejected extends Error {
|
|
49
|
+
}
|
|
50
|
+
function reject() {
|
|
51
|
+
throw new Rejected();
|
|
52
|
+
}
|
|
53
|
+
const absent = (v) => v === undefined || v === null;
|
|
54
|
+
function attrsOf(raw) {
|
|
55
|
+
if (absent(raw.attrs))
|
|
56
|
+
return {};
|
|
57
|
+
return isRecord(raw.attrs) ? raw.attrs : reject();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A link address rich text can hold: a safe URL without control characters, which
|
|
61
|
+
* Markdown can't carry and so wouldn't read back.
|
|
62
|
+
*/
|
|
63
|
+
export function isRichTextHref(href) {
|
|
64
|
+
// eslint-disable-next-line no-control-regex
|
|
65
|
+
return isSafeUrl(href) && !/[\u0000-\u001f\u007f]/.test(href);
|
|
66
|
+
}
|
|
67
|
+
function cleanMark(raw, opts) {
|
|
68
|
+
if (!isRecord(raw) || typeof raw.type !== 'string')
|
|
69
|
+
reject();
|
|
70
|
+
const type = raw.type;
|
|
71
|
+
if (!Object.hasOwn(richTextSchema.marks, type))
|
|
72
|
+
reject();
|
|
73
|
+
if (!opts.features.includes(type))
|
|
74
|
+
reject();
|
|
75
|
+
if (type !== 'link')
|
|
76
|
+
return { type };
|
|
77
|
+
const { href, document } = attrsOf(raw);
|
|
78
|
+
if (absent(href) === absent(document))
|
|
79
|
+
reject();
|
|
80
|
+
if (!absent(href)) {
|
|
81
|
+
if (typeof href !== 'string' || !isRichTextHref(href))
|
|
82
|
+
reject();
|
|
83
|
+
return { type, attrs: { href } };
|
|
84
|
+
}
|
|
85
|
+
if (typeof document !== 'string' || !UUID.safeParse(document).success)
|
|
86
|
+
reject();
|
|
87
|
+
return { type, attrs: { document } };
|
|
88
|
+
}
|
|
89
|
+
function cleanAttrs(type, raw, opts) {
|
|
90
|
+
const attrs = attrsOf(raw);
|
|
91
|
+
if (type === 'heading') {
|
|
92
|
+
if (typeof attrs.level !== 'number' || !opts.headings.includes(attrs.level))
|
|
93
|
+
reject();
|
|
94
|
+
return { level: attrs.level };
|
|
95
|
+
}
|
|
96
|
+
if (type === 'orderedList') {
|
|
97
|
+
const start = attrs.start ?? 1;
|
|
98
|
+
if (typeof start !== 'number' || !Number.isInteger(start) || start < 0)
|
|
99
|
+
reject();
|
|
100
|
+
return start === 1 ? undefined : { start };
|
|
101
|
+
}
|
|
102
|
+
if (type === 'image') {
|
|
103
|
+
const { media, alt } = attrs;
|
|
104
|
+
if (typeof media !== 'string' || !HEX64.test(media))
|
|
105
|
+
reject();
|
|
106
|
+
if (!absent(alt) && typeof alt !== 'string')
|
|
107
|
+
reject();
|
|
108
|
+
return typeof alt === 'string' && alt !== '' ? { media, alt } : { media };
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
/** The node with its attrs, marks and text cleaned, or `null` if it is dropped. */
|
|
113
|
+
function cleanNode(raw, opts) {
|
|
114
|
+
if (!isRecord(raw) || typeof raw.type !== 'string')
|
|
115
|
+
reject();
|
|
116
|
+
const type = raw.type;
|
|
117
|
+
if (type === 'doc' || !Object.hasOwn(richTextSchema.nodes, type))
|
|
118
|
+
reject();
|
|
119
|
+
const feature = NODE_FEATURE[type];
|
|
120
|
+
if (feature !== undefined && !opts.features.includes(feature))
|
|
121
|
+
reject();
|
|
122
|
+
const out = { type };
|
|
123
|
+
const attrs = cleanAttrs(type, raw, opts);
|
|
124
|
+
if (attrs)
|
|
125
|
+
out.attrs = attrs;
|
|
126
|
+
if (!absent(raw.marks)) {
|
|
127
|
+
if (!Array.isArray(raw.marks))
|
|
128
|
+
reject();
|
|
129
|
+
if (raw.marks.length > 0)
|
|
130
|
+
out.marks = raw.marks.map((m) => cleanMark(m, opts));
|
|
131
|
+
}
|
|
132
|
+
if (type === 'text') {
|
|
133
|
+
if (typeof raw.text !== 'string')
|
|
134
|
+
reject();
|
|
135
|
+
const text = raw.text.replace(/\r\n?|\n/g, ' ');
|
|
136
|
+
if (text === '')
|
|
137
|
+
return null;
|
|
138
|
+
out.text = text;
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
if (LEAVES.has(type)) {
|
|
142
|
+
if (!absent(raw.content) && !(Array.isArray(raw.content) && raw.content.length === 0))
|
|
143
|
+
reject();
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
const content = cleanContent(raw.content, type, opts);
|
|
147
|
+
// A line break at the end of a paragraph shows nothing, and Markdown can't hold one.
|
|
148
|
+
if (type === 'paragraph')
|
|
149
|
+
while (content.length > 0 && content[content.length - 1]?.type === 'hardBreak')
|
|
150
|
+
content.pop();
|
|
151
|
+
if (content.length > 0)
|
|
152
|
+
out.content = content;
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Empty paragraphs (including ones left empty once trailing line breaks are dropped) are
|
|
157
|
+
* dropped, except a list item's first; so are blockquotes left empty.
|
|
158
|
+
*/
|
|
159
|
+
function cleanContent(raw, parent, opts) {
|
|
160
|
+
if (absent(raw))
|
|
161
|
+
return [];
|
|
162
|
+
if (!Array.isArray(raw))
|
|
163
|
+
reject();
|
|
164
|
+
const out = [];
|
|
165
|
+
for (const child of raw) {
|
|
166
|
+
const node = cleanNode(child, opts);
|
|
167
|
+
if (node === null)
|
|
168
|
+
continue;
|
|
169
|
+
const empty = node.content === undefined;
|
|
170
|
+
if (empty && node.type === 'paragraph' && !(parent === 'listItem' && out.length === 0))
|
|
171
|
+
continue;
|
|
172
|
+
if (empty && node.type === 'blockquote')
|
|
173
|
+
continue;
|
|
174
|
+
out.push(node);
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
/** ProseMirror's JSON without `null` and default attrs, in fresh objects. */
|
|
179
|
+
function stripDefaults(json) {
|
|
180
|
+
const out = { type: json.type };
|
|
181
|
+
if (isRecord(json.attrs)) {
|
|
182
|
+
const attrs = {};
|
|
183
|
+
for (const [key, value] of Object.entries(json.attrs)) {
|
|
184
|
+
if (value === null || (json.type === 'orderedList' && key === 'start' && value === 1))
|
|
185
|
+
continue;
|
|
186
|
+
attrs[key] = value;
|
|
187
|
+
}
|
|
188
|
+
if (Object.keys(attrs).length > 0)
|
|
189
|
+
out.attrs = attrs;
|
|
190
|
+
}
|
|
191
|
+
if (Array.isArray(json.content))
|
|
192
|
+
out.content = json.content.map((c) => stripDefaults(c));
|
|
193
|
+
if (typeof json.text === 'string')
|
|
194
|
+
out.text = json.text;
|
|
195
|
+
if (Array.isArray(json.marks))
|
|
196
|
+
out.marks = json.marks.map((m) => stripDefaults(m));
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Validates `value` as a rich text doc allowed by `opts` and returns it
|
|
201
|
+
* normalized (see Decision 7 of the Phase 3 plan), or `{ ok: false }`.
|
|
202
|
+
*/
|
|
203
|
+
export function parseRichText(value, opts) {
|
|
204
|
+
try {
|
|
205
|
+
if (!isRecord(value) || value.type !== 'doc')
|
|
206
|
+
return { ok: false };
|
|
207
|
+
const content = cleanContent(value.content, 'doc', opts);
|
|
208
|
+
const node = richTextSchema.nodeFromJSON({ type: 'doc', content });
|
|
209
|
+
node.check();
|
|
210
|
+
const json = stripDefaults(node.toJSON());
|
|
211
|
+
return { ok: true, doc: { type: 'doc', content: (json.content ?? []) } };
|
|
212
|
+
}
|
|
213
|
+
catch (e) {
|
|
214
|
+
if (e instanceof Rejected || e instanceof RangeError)
|
|
215
|
+
return { ok: false };
|
|
216
|
+
throw e;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const childrenOf = (node) => isRecord(node) && Array.isArray(node.content) ? node.content : [];
|
|
220
|
+
function inlineText(node) {
|
|
221
|
+
return childrenOf(node)
|
|
222
|
+
.map((c) => {
|
|
223
|
+
if (!isRecord(c))
|
|
224
|
+
return '';
|
|
225
|
+
if (c.type === 'text' && typeof c.text === 'string')
|
|
226
|
+
return c.text;
|
|
227
|
+
return c.type === 'hardBreak' ? '\n' : '';
|
|
228
|
+
})
|
|
229
|
+
.join('');
|
|
230
|
+
}
|
|
231
|
+
function blockTexts(node, out) {
|
|
232
|
+
for (const child of childrenOf(node)) {
|
|
233
|
+
if (!isRecord(child))
|
|
234
|
+
continue;
|
|
235
|
+
if (child.type === 'paragraph' || child.type === 'heading')
|
|
236
|
+
out.push(inlineText(child));
|
|
237
|
+
else
|
|
238
|
+
blockTexts(child, out);
|
|
239
|
+
}
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
/** The doc's text: blocks joined by `\n`, a hard break as `\n`, images left out. */
|
|
243
|
+
export function richTextText(doc) {
|
|
244
|
+
return blockTexts(doc, []).join('\n');
|
|
245
|
+
}
|
|
246
|
+
/** True if the doc has no non-whitespace text and no image. */
|
|
247
|
+
export function richTextIsBlank(doc) {
|
|
248
|
+
const filled = (node) => isRecord(node) &&
|
|
249
|
+
((node.type === 'text' && typeof node.text === 'string' && node.text.trim() !== '') ||
|
|
250
|
+
node.type === 'image' ||
|
|
251
|
+
childrenOf(node).some(filled));
|
|
252
|
+
return !filled(doc);
|
|
253
|
+
}
|
|
254
|
+
/** `media` refs for images and `document` refs for internal links, in document order. */
|
|
255
|
+
export function richTextRefs(doc) {
|
|
256
|
+
const out = new Map();
|
|
257
|
+
const add = (ref) => out.set(`${ref.kind}:${ref.id}`, ref);
|
|
258
|
+
const visit = (node) => {
|
|
259
|
+
if (!isRecord(node))
|
|
260
|
+
return;
|
|
261
|
+
if (Array.isArray(node.marks)) {
|
|
262
|
+
for (const mark of node.marks) {
|
|
263
|
+
if (isRecord(mark) && mark.type === 'link' && isRecord(mark.attrs) && typeof mark.attrs.document === 'string') {
|
|
264
|
+
add({ kind: 'document', id: mark.attrs.document });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (node.type === 'image' && isRecord(node.attrs) && typeof node.attrs.media === 'string') {
|
|
269
|
+
add({ kind: 'media', id: node.attrs.media });
|
|
270
|
+
}
|
|
271
|
+
childrenOf(node).forEach(visit);
|
|
272
|
+
};
|
|
273
|
+
visit(doc);
|
|
274
|
+
return [...out.values()];
|
|
275
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { DocumentsTable } from '../db/schema.js';
|
|
2
|
+
import type { TypeDef } from '../registry/define.js';
|
|
3
|
+
import type { Registry } from '../registry/registry.js';
|
|
4
|
+
import type { CoreDeps, LiveDocument, LiveState } from '../types.js';
|
|
5
|
+
export type LiveOpts = {
|
|
6
|
+
state?: LiveState;
|
|
7
|
+
};
|
|
8
|
+
/** Visible, non-deleted documents, each with its live revision (`rev_*` are `null` when it has none). */
|
|
9
|
+
export declare function liveQuery(deps: CoreDeps, state: LiveState): import("kysely").SelectQueryBuilder<{
|
|
10
|
+
documents: DocumentsTable;
|
|
11
|
+
media: import("../db/schema.js").MediaTable;
|
|
12
|
+
media_deletions: import("../db/schema.js").MediaDeletionsTable;
|
|
13
|
+
oauthClient: import("../db/schema.js").OAuthClientTable;
|
|
14
|
+
publish_events: import("../db/schema.js").PublishEventsTable;
|
|
15
|
+
redirects: import("../db/schema.js").RedirectsTable;
|
|
16
|
+
refs: import("../db/schema.js").RefsTable;
|
|
17
|
+
release_migrations: import("../db/schema.js").ReleaseMigrationsTable;
|
|
18
|
+
releases: import("../db/schema.js").ReleasesTable;
|
|
19
|
+
revisions: import("kysely").Nullable<import("../db/schema.js").RevisionsTable>;
|
|
20
|
+
site_lock: import("../db/schema.js").SiteLockTable;
|
|
21
|
+
token_cutoffs: import("../db/schema.js").TokenCutoffsTable;
|
|
22
|
+
user: import("../db/schema.js").UserTable;
|
|
23
|
+
}, "documents" | "revisions", {
|
|
24
|
+
created_at: string;
|
|
25
|
+
deleted_at: string | null;
|
|
26
|
+
edition: number | null;
|
|
27
|
+
group_id: string;
|
|
28
|
+
head_path: string | null;
|
|
29
|
+
head_rev: number | null;
|
|
30
|
+
head_slug: string | null;
|
|
31
|
+
id: string;
|
|
32
|
+
key: string | null;
|
|
33
|
+
kind: "entry" | "global" | "singleton";
|
|
34
|
+
locale: string;
|
|
35
|
+
published_path: string | null;
|
|
36
|
+
published_rev: number | null;
|
|
37
|
+
published_slug: string | null;
|
|
38
|
+
type: string;
|
|
39
|
+
} & {
|
|
40
|
+
rev_created_at: string | null;
|
|
41
|
+
rev_data: string | null;
|
|
42
|
+
rev_id: number | null;
|
|
43
|
+
}>;
|
|
44
|
+
/** The decoded, locale-prefixed site path of a document of `def` shown in `locale`. */
|
|
45
|
+
export declare function sitePath(registry: Registry, def: TypeDef, locale: string, slug: string | null, custom: string | null): string | null;
|
|
46
|
+
export declare function liveDocuments(deps: CoreDeps, groupIds: string[], locale: string, opts?: LiveOpts): Promise<Map<string, LiveDocument>>;
|
|
47
|
+
/** The live document of a singleton or global in `locale`. */
|
|
48
|
+
export declare function liveSingleton(deps: CoreDeps, type: string, locale: string, opts?: LiveOpts): Promise<LiveDocument | null>;
|
|
49
|
+
/** Live entries of `collection` in `locale`, newest group first. */
|
|
50
|
+
export declare function liveEntries(deps: CoreDeps, collection: string, locale: string, opts?: LiveOpts): Promise<LiveDocument[]>;
|
|
51
|
+
/** One item per site locale where the group is live and has a path. */
|
|
52
|
+
export declare function liveAlternates(deps: CoreDeps, groupId: string, opts?: LiveOpts): Promise<Array<{
|
|
53
|
+
locale: string;
|
|
54
|
+
path: string;
|
|
55
|
+
fallback: boolean;
|
|
56
|
+
}>>;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { documentTitle, whereVisible } from '../content/read.js';
|
|
2
|
+
import { readData } from '../content/reader.js';
|
|
3
|
+
import { routePath, singletonPath, withLocale } from './paths.js';
|
|
4
|
+
/** Visible, non-deleted documents, each with its live revision (`rev_*` are `null` when it has none). */
|
|
5
|
+
export function liveQuery(deps, state) {
|
|
6
|
+
const rev = state === 'preview' ? 'documents.head_rev' : 'documents.published_rev';
|
|
7
|
+
return deps.db
|
|
8
|
+
.selectFrom('documents')
|
|
9
|
+
.leftJoin('revisions', 'revisions.id', rev)
|
|
10
|
+
.selectAll('documents')
|
|
11
|
+
.select(['revisions.id as rev_id', 'revisions.data as rev_data', 'revisions.created_at as rev_created_at'])
|
|
12
|
+
.where('documents.deleted_at', 'is', null)
|
|
13
|
+
.$call(whereVisible(deps.registry));
|
|
14
|
+
}
|
|
15
|
+
/** The decoded, locale-prefixed site path of a document of `def` shown in `locale`. */
|
|
16
|
+
export function sitePath(registry, def, locale, slug, custom) {
|
|
17
|
+
let p = null;
|
|
18
|
+
if (def.kind === 'singleton')
|
|
19
|
+
p = singletonPath(def, locale, registry.defaultLocale);
|
|
20
|
+
else if (def.kind === 'collection') {
|
|
21
|
+
if (def.customPaths && custom !== null)
|
|
22
|
+
p = custom;
|
|
23
|
+
else if (def.route !== null && slug !== null)
|
|
24
|
+
p = routePath(def.route, slug);
|
|
25
|
+
}
|
|
26
|
+
return p === null ? null : withLocale(registry, locale, p);
|
|
27
|
+
}
|
|
28
|
+
function toLive(deps, state, locale, row, fallback) {
|
|
29
|
+
const slug = state === 'preview' ? row.head_slug : row.published_slug;
|
|
30
|
+
const custom = state === 'preview' ? row.head_path : row.published_path;
|
|
31
|
+
// Live documents feed rendering and template queries, so this is the one read that fills empty values.
|
|
32
|
+
const data = readData(deps.registry, row.type, JSON.parse(row.rev_data), { fill: true }).data;
|
|
33
|
+
return {
|
|
34
|
+
documentId: row.id,
|
|
35
|
+
groupId: row.group_id,
|
|
36
|
+
kind: row.kind,
|
|
37
|
+
type: row.type,
|
|
38
|
+
locale,
|
|
39
|
+
contentLocale: row.locale,
|
|
40
|
+
fallback,
|
|
41
|
+
path: sitePath(deps.registry, deps.registry.getType(row.type), locale, slug, custom),
|
|
42
|
+
title: documentTitle(deps, row, data, slug),
|
|
43
|
+
slug,
|
|
44
|
+
revisionId: row.rev_id,
|
|
45
|
+
updatedAt: row.rev_created_at,
|
|
46
|
+
data,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** The locales whose documents can be shown in `locale`: itself, then the default locale if fallback is on. */
|
|
50
|
+
function sourceLocales(registry, locale) {
|
|
51
|
+
if (locale === registry.defaultLocale || !registry.site.translationFallback)
|
|
52
|
+
return [locale];
|
|
53
|
+
return [locale, registry.defaultLocale];
|
|
54
|
+
}
|
|
55
|
+
function byGroup(rows) {
|
|
56
|
+
const groups = new Map();
|
|
57
|
+
for (const row of rows) {
|
|
58
|
+
let g = groups.get(row.group_id);
|
|
59
|
+
if (!g)
|
|
60
|
+
groups.set(row.group_id, (g = new Map()));
|
|
61
|
+
g.set(row.locale, row);
|
|
62
|
+
}
|
|
63
|
+
return groups;
|
|
64
|
+
}
|
|
65
|
+
/** The document a group shows in `locale`, falling back to the default locale when allowed. */
|
|
66
|
+
function pick(deps, state, locale, rows) {
|
|
67
|
+
for (const source of sourceLocales(deps.registry, locale)) {
|
|
68
|
+
const row = rows.get(source);
|
|
69
|
+
if (row && row.rev_id !== null)
|
|
70
|
+
return toLive(deps, state, locale, row, source !== locale);
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
export async function liveDocuments(deps, groupIds, locale, opts = {}) {
|
|
75
|
+
const state = opts.state ?? 'published';
|
|
76
|
+
const out = new Map();
|
|
77
|
+
const ids = [...new Set(groupIds)];
|
|
78
|
+
if (ids.length === 0 || !deps.registry.locales.includes(locale))
|
|
79
|
+
return out;
|
|
80
|
+
const rows = await liveQuery(deps, state)
|
|
81
|
+
.where('documents.group_id', 'in', ids)
|
|
82
|
+
.where('documents.locale', 'in', sourceLocales(deps.registry, locale))
|
|
83
|
+
.execute();
|
|
84
|
+
const groups = byGroup(rows);
|
|
85
|
+
for (const id of ids) {
|
|
86
|
+
const g = groups.get(id);
|
|
87
|
+
const doc = g ? pick(deps, state, locale, g) : null;
|
|
88
|
+
if (doc)
|
|
89
|
+
out.set(id, doc);
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
/** The live document of a singleton or global in `locale`. */
|
|
94
|
+
export async function liveSingleton(deps, type, locale, opts = {}) {
|
|
95
|
+
const state = opts.state ?? 'published';
|
|
96
|
+
if (deps.registry.getType(type).kind === 'collection' || !deps.registry.locales.includes(locale))
|
|
97
|
+
return null;
|
|
98
|
+
const rows = await liveQuery(deps, state)
|
|
99
|
+
.where('documents.type', '=', type)
|
|
100
|
+
.where('documents.kind', 'in', ['singleton', 'global'])
|
|
101
|
+
.where('documents.locale', 'in', sourceLocales(deps.registry, locale))
|
|
102
|
+
.execute();
|
|
103
|
+
for (const g of byGroup(rows).values()) {
|
|
104
|
+
const doc = pick(deps, state, locale, g);
|
|
105
|
+
if (doc)
|
|
106
|
+
return doc;
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
/** Live entries of `collection` in `locale`, newest group first. */
|
|
111
|
+
export async function liveEntries(deps, collection, locale, opts = {}) {
|
|
112
|
+
const state = opts.state ?? 'published';
|
|
113
|
+
const { registry } = deps;
|
|
114
|
+
if (registry.getType(collection).kind !== 'collection' || !registry.locales.includes(locale))
|
|
115
|
+
return [];
|
|
116
|
+
const rows = await liveQuery(deps, state)
|
|
117
|
+
.where('documents.type', '=', collection)
|
|
118
|
+
.where('documents.kind', '=', 'entry')
|
|
119
|
+
.where('documents.locale', 'in', [...new Set([locale, registry.defaultLocale])])
|
|
120
|
+
.execute();
|
|
121
|
+
const groups = [...byGroup(rows)].map(([groupId, g]) => ({
|
|
122
|
+
groupId,
|
|
123
|
+
createdAt: (g.get(registry.defaultLocale) ?? g.values().next().value).created_at,
|
|
124
|
+
doc: pick(deps, state, locale, g),
|
|
125
|
+
}));
|
|
126
|
+
groups.sort((a, b) => a.createdAt !== b.createdAt
|
|
127
|
+
? a.createdAt < b.createdAt ? 1 : -1
|
|
128
|
+
: a.groupId < b.groupId ? -1 : a.groupId > b.groupId ? 1 : 0);
|
|
129
|
+
return groups.flatMap((g) => (g.doc ? [g.doc] : []));
|
|
130
|
+
}
|
|
131
|
+
/** One item per site locale where the group is live and has a path. */
|
|
132
|
+
export async function liveAlternates(deps, groupId, opts = {}) {
|
|
133
|
+
const state = opts.state ?? 'published';
|
|
134
|
+
const rows = await liveQuery(deps, state).where('documents.group_id', '=', groupId).execute();
|
|
135
|
+
const g = byGroup(rows).get(groupId);
|
|
136
|
+
if (!g)
|
|
137
|
+
return [];
|
|
138
|
+
const out = [];
|
|
139
|
+
for (const locale of deps.registry.locales) {
|
|
140
|
+
const doc = pick(deps, state, locale, g);
|
|
141
|
+
if (doc && doc.path !== null)
|
|
142
|
+
out.push({ locale, path: doc.path, fallback: doc.fallback });
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SingletonDef } from '../registry/define.js';
|
|
2
|
+
import type { Registry } from '../registry/registry.js';
|
|
3
|
+
export declare const RESERVED_PATHS: readonly string[];
|
|
4
|
+
export declare function isReserved(path: string): boolean;
|
|
5
|
+
/** The decoded, slash-trimmed form of a site path, or `null` if it isn't a clean site-relative path. */
|
|
6
|
+
export declare function normalizePath(raw: string): string | null;
|
|
7
|
+
export declare function encodePath(path: string): string;
|
|
8
|
+
export declare function splitLocale(registry: Registry, path: string): {
|
|
9
|
+
locale: string;
|
|
10
|
+
rest: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function withLocale(registry: Registry, locale: string, path: string): string;
|
|
13
|
+
export declare function singletonPath(def: SingletonDef, locale: string, defaultLocale: string): string | null;
|
|
14
|
+
export declare function routeRegExp(route: string): RegExp;
|
|
15
|
+
export declare function routePath(route: string, slug: string): string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { SLUG } from '../content/schema.js';
|
|
2
|
+
export const RESERVED_PATHS = [
|
|
3
|
+
'/admin',
|
|
4
|
+
'/mcp',
|
|
5
|
+
'/media',
|
|
6
|
+
'/public',
|
|
7
|
+
'/_inlay',
|
|
8
|
+
'/api/auth',
|
|
9
|
+
'/.well-known',
|
|
10
|
+
'/sitemap.xml',
|
|
11
|
+
'/robots.txt',
|
|
12
|
+
];
|
|
13
|
+
export function isReserved(path) {
|
|
14
|
+
return RESERVED_PATHS.some((r) => path === r || path.startsWith(`${r}/`));
|
|
15
|
+
}
|
|
16
|
+
// eslint-disable-next-line no-control-regex
|
|
17
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
18
|
+
/** The decoded, slash-trimmed form of a site path, or `null` if it isn't a clean site-relative path. */
|
|
19
|
+
export function normalizePath(raw) {
|
|
20
|
+
if (!raw.startsWith('/') || raw.includes('//') || raw.includes('\\'))
|
|
21
|
+
return null;
|
|
22
|
+
let decoded;
|
|
23
|
+
try {
|
|
24
|
+
decoded = decodeURIComponent(raw);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (decoded.includes('//') || decoded.includes('\\') || CONTROL.test(decoded))
|
|
30
|
+
return null;
|
|
31
|
+
if (decoded.split('/').some((s) => s === '.' || s === '..'))
|
|
32
|
+
return null;
|
|
33
|
+
return decoded.length > 1 && decoded.endsWith('/') ? decoded.slice(0, -1) : decoded;
|
|
34
|
+
}
|
|
35
|
+
export function encodePath(path) {
|
|
36
|
+
return path.split('/').map(encodeURIComponent).join('/');
|
|
37
|
+
}
|
|
38
|
+
export function splitLocale(registry, path) {
|
|
39
|
+
const [, first = '', ...tail] = path.split('/');
|
|
40
|
+
if (first !== registry.defaultLocale && registry.locales.includes(first)) {
|
|
41
|
+
return { locale: first, rest: tail.length === 0 ? '/' : `/${tail.join('/')}` };
|
|
42
|
+
}
|
|
43
|
+
return { locale: registry.defaultLocale, rest: path };
|
|
44
|
+
}
|
|
45
|
+
export function withLocale(registry, locale, path) {
|
|
46
|
+
if (locale === registry.defaultLocale)
|
|
47
|
+
return path;
|
|
48
|
+
return path === '/' ? `/${locale}` : `/${locale}${path}`;
|
|
49
|
+
}
|
|
50
|
+
export function singletonPath(def, locale, defaultLocale) {
|
|
51
|
+
const p = def.path;
|
|
52
|
+
if (p === null || typeof p === 'string')
|
|
53
|
+
return p;
|
|
54
|
+
return p[locale] ?? p[defaultLocale] ?? null;
|
|
55
|
+
}
|
|
56
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
57
|
+
export function routeRegExp(route) {
|
|
58
|
+
const [before = '', after = ''] = route.split(':slug');
|
|
59
|
+
const slug = SLUG.source.slice(1, -1);
|
|
60
|
+
return new RegExp(`^${escapeRe(before)}(${slug})${escapeRe(after)}$`);
|
|
61
|
+
}
|
|
62
|
+
export function routePath(route, slug) {
|
|
63
|
+
return route.replace(':slug', slug);
|
|
64
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CoreDeps, RouteMatch } from '../types.js';
|
|
2
|
+
import { type LiveOpts } from './live.js';
|
|
3
|
+
/** Resolves a still-encoded URL path (no query string) to a page, a redirect or not-found. */
|
|
4
|
+
export declare function resolvePath(deps: CoreDeps, rawPath: string, opts?: LiveOpts): Promise<RouteMatch>;
|
|
5
|
+
/**
|
|
6
|
+
* What `resolvePath` answers before it looks at redirect rules (steps 1–6, then 8): a redirect rule
|
|
7
|
+
* can only fire where this is `not_found`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveWithoutRules(deps: CoreDeps, rawPath: string, opts?: LiveOpts): Promise<RouteMatch>;
|