@perkyzz/emvb 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 +57 -2
- package/package.json +72 -4
- package/src/admin/access/RequireEditor.tsx +39 -0
- package/src/admin/access/role.ts +36 -0
- package/src/admin/access/sidebar-shim.ts +108 -0
- package/src/admin/api.ts +48 -0
- package/src/admin/content-api.ts +147 -0
- package/src/admin/editor/Editor.tsx +457 -0
- package/src/admin/editor/EditorOverlay.tsx +54 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +20 -0
- package/src/admin/editor/TopBar.tsx +179 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +355 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +50 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +185 -0
- package/src/admin/editor/canvas/canvas-events.ts +232 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +35 -0
- package/src/admin/editor/canvas/vnode-react.tsx +49 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +125 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +101 -0
- package/src/admin/editor/dnd/new-element.ts +32 -0
- package/src/admin/editor/editor-css.ts +539 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/panels/AddPanel.tsx +142 -0
- package/src/admin/editor/panels/ClassesSection.tsx +334 -0
- package/src/admin/editor/panels/ColorControl.tsx +230 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +629 -0
- package/src/admin/editor/panels/LayersPanel.tsx +336 -0
- package/src/admin/editor/panels/LeftPanel.tsx +77 -0
- package/src/admin/editor/panels/PageSettings.tsx +126 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +101 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +392 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +197 -0
- package/src/admin/editor/panels/VariableSection.tsx +492 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +320 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +349 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +201 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +347 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +83 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +150 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +97 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +109 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +181 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +124 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +218 -0
- package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +480 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +167 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +51 -0
- package/src/admin/editor/panels/settings/length-units.ts +83 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +291 -0
- package/src/admin/editor/panels/site-list.tsx +206 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +212 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +142 -0
- package/src/admin/editor/useEditorData.ts +167 -0
- package/src/admin/editor/useEditorShortcuts.ts +148 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +122 -0
- package/src/admin/editor/useSave.ts +185 -0
- package/src/admin/forms-api.ts +73 -0
- package/src/admin/index.tsx +20 -0
- package/src/admin/media-api.ts +68 -0
- package/src/admin/pages/CreateDialog.tsx +150 -0
- package/src/admin/pages/EditorPage.tsx +57 -0
- package/src/admin/pages/NewPageDialog.tsx +83 -0
- package/src/admin/pages/NewThemePartDialog.tsx +61 -0
- package/src/admin/pages/PageList.tsx +71 -0
- package/src/admin/pages/PagesPage.tsx +25 -0
- package/src/admin/pages/SetupShell.tsx +90 -0
- package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
- package/src/admin/pages/ThemePartList.tsx +202 -0
- package/src/admin/pages/list-kit.tsx +75 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +100 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +186 -0
- package/src/admin/ui.ts +231 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +37 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +104 -0
- package/src/astro/index.ts +15 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +246 -0
- package/src/astro/render.ts +74 -0
- package/src/astro/resolve-theme.ts +371 -0
- package/src/astro/resolve.ts +65 -0
- package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
- package/src/astro/tabs/index.ts +1 -0
- package/src/astro/tabs/runtime.ts +111 -0
- package/src/astro/theme-context.ts +81 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +360 -0
- package/src/core/clipboard.ts +422 -0
- package/src/core/css/generate.ts +219 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +138 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +33 -0
- package/src/core/design/variables.ts +319 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +173 -0
- package/src/core/elements/form-elements.ts +204 -0
- package/src/core/elements/index.ts +742 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +34 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +316 -0
- package/src/core/limits.ts +7 -0
- package/src/core/migrate/index.ts +76 -0
- package/src/core/render/context.ts +14 -0
- package/src/core/render/dynamic-post.ts +147 -0
- package/src/core/render/extras.ts +79 -0
- package/src/core/render/form.ts +137 -0
- package/src/core/render/index.ts +274 -0
- package/src/core/render/loop.ts +36 -0
- package/src/core/render/section.ts +33 -0
- package/src/core/render/tabs.ts +72 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +591 -0
- package/src/core/sanitize/embed-url.ts +103 -0
- package/src/core/sanitize/escape.ts +10 -0
- package/src/core/sanitize/href.ts +6 -0
- package/src/core/sanitize/media-url.ts +7 -0
- package/src/core/sanitize/svg.ts +293 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +33 -0
- package/src/core/schema/design.ts +88 -0
- package/src/core/schema/layout.ts +817 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +257 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +16 -0
- package/src/core/theme/conditions.ts +321 -0
- package/src/core/theme/dynamic.ts +133 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +79 -0
- package/src/core/theme/popup-markup.ts +39 -0
- package/src/core/theme/popup-rules.ts +61 -0
- package/src/core/theme/triggers.ts +104 -0
- package/src/core/tree-ops.ts +139 -0
- package/src/core/validate.ts +185 -0
- package/src/index.ts +18 -0
- package/src/server/design-routes.ts +125 -0
- package/src/server/hooks.ts +98 -0
- package/src/server/plugin.ts +39 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ApiError, requestJson, type Fetcher } from "./api.ts";
|
|
2
|
+
|
|
3
|
+
export type FormListItem = { id: string; name: string; slug: string };
|
|
4
|
+
|
|
5
|
+
export type FormsCapability =
|
|
6
|
+
| { status: "ready"; forms: FormListItem[]; canList: true }
|
|
7
|
+
| { status: "manual"; canList: false }
|
|
8
|
+
| { status: "missing" };
|
|
9
|
+
|
|
10
|
+
const LIST = "/_emdash/api/plugins/emdash-forms/forms/list";
|
|
11
|
+
const DEFINITION = "/_emdash/api/plugins/emdash-forms/definition";
|
|
12
|
+
|
|
13
|
+
const manual = (): FormsCapability => ({ status: "manual", canList: false });
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether a failed definition probe still shows the forms plugin is there. A 404 is ambiguous:
|
|
17
|
+
* EmDash answers a missing plugin with `NOT_FOUND` "Plugin route not found", and the plugin
|
|
18
|
+
* answers an unknown form with `NOT_FOUND` "Form not found". Only the plugin's message counts.
|
|
19
|
+
*/
|
|
20
|
+
function probeFoundPlugin(error: unknown): boolean {
|
|
21
|
+
if (!(error instanceof ApiError)) return false;
|
|
22
|
+
if (error.status === 404) return error.message.toLowerCase().includes("form");
|
|
23
|
+
return error.status === 410 || error.status === 422;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Asks the public definition route about a form that can't exist (unknown id → the plugin's 404). */
|
|
27
|
+
async function formsPluginAnswers(fetcher: Fetcher): Promise<boolean> {
|
|
28
|
+
try {
|
|
29
|
+
await requestJson(fetcher, DEFINITION, { method: "POST", body: { id: "__emvb_probe__" } });
|
|
30
|
+
return true;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return probeFoundPlugin(error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Probe forms plugin + list (admin). Editors get manual-id fallback (D-015). */
|
|
37
|
+
export async function loadFormsCapability(fetcher: Fetcher): Promise<FormsCapability> {
|
|
38
|
+
try {
|
|
39
|
+
const data = await requestJson<{ items: FormListItem[] }>(fetcher, LIST, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
body: {},
|
|
42
|
+
});
|
|
43
|
+
const forms = (data.items ?? []).map(({ id, name, slug }) => ({ id, name, slug }));
|
|
44
|
+
return { status: "ready", canList: true, forms };
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (error instanceof ApiError && (error.status === 401 || error.status === 403)) {
|
|
47
|
+
return manual();
|
|
48
|
+
}
|
|
49
|
+
return (await formsPluginAnswers(fetcher)) ? manual() : { status: "missing" };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type DefinitionField = {
|
|
54
|
+
name: string;
|
|
55
|
+
type: string;
|
|
56
|
+
label: string;
|
|
57
|
+
required: boolean;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export async function loadFormFields(
|
|
61
|
+
fetcher: Fetcher,
|
|
62
|
+
formId: string,
|
|
63
|
+
): Promise<DefinitionField[] | null> {
|
|
64
|
+
if (!formId) return null;
|
|
65
|
+
try {
|
|
66
|
+
const data = await requestJson<{
|
|
67
|
+
pages: Array<{ fields: DefinitionField[] }>;
|
|
68
|
+
}>(fetcher, DEFINITION, { method: "POST", body: { id: formId } });
|
|
69
|
+
return data.pages.flatMap((page) => page.fields);
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PluginAdminExports } from "emdash";
|
|
2
|
+
import { installSidebarShim } from "./access/sidebar-shim.ts";
|
|
3
|
+
import { defaultFetcher } from "./api.ts";
|
|
4
|
+
import { EditorPage } from "./pages/EditorPage.tsx";
|
|
5
|
+
import { PagesPage } from "./pages/PagesPage.tsx";
|
|
6
|
+
import { ThemeBuilderPage } from "./pages/ThemeBuilderPage.tsx";
|
|
7
|
+
import { LayoutField } from "./widgets/LayoutField.tsx";
|
|
8
|
+
|
|
9
|
+
if (typeof document !== "undefined") void installSidebarShim(document, defaultFetcher);
|
|
10
|
+
|
|
11
|
+
/** `/pages` and `/theme` are declared; `/editor` renders by URL (D-024). */
|
|
12
|
+
export const pages: PluginAdminExports["pages"] = {
|
|
13
|
+
"/pages": PagesPage,
|
|
14
|
+
"/theme": ThemeBuilderPage,
|
|
15
|
+
"/editor": EditorPage,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const fields: PluginAdminExports["fields"] = {
|
|
19
|
+
layout: LayoutField,
|
|
20
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { envelopeError, readEnvelope, type Fetcher } from "./api.ts";
|
|
2
|
+
|
|
3
|
+
/** A library item as EmDash returns it from GET/POST /_emdash/api/media (with `url`). */
|
|
4
|
+
export type MediaLibraryItem = {
|
|
5
|
+
id: string;
|
|
6
|
+
filename: string;
|
|
7
|
+
mimeType: string;
|
|
8
|
+
size: number | null;
|
|
9
|
+
width: number | null;
|
|
10
|
+
height: number | null;
|
|
11
|
+
alt: string | null;
|
|
12
|
+
storageKey: string;
|
|
13
|
+
status: string;
|
|
14
|
+
url: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** Shared EmDash media endpoint — same path on Node local and Cloudflare R2 (R-007). */
|
|
18
|
+
export const MEDIA_API_PATH = "/_emdash/api/media";
|
|
19
|
+
|
|
20
|
+
/** Lists ready images from the EmDash media library (R-007). */
|
|
21
|
+
export async function listImages(
|
|
22
|
+
fetcher: Fetcher,
|
|
23
|
+
opts: { limit?: number; q?: string } = {},
|
|
24
|
+
): Promise<MediaLibraryItem[]> {
|
|
25
|
+
const params = new URLSearchParams({
|
|
26
|
+
mimeType: "image/",
|
|
27
|
+
limit: String(opts.limit ?? 50),
|
|
28
|
+
});
|
|
29
|
+
if (opts.q) params.set("q", opts.q);
|
|
30
|
+
const response = await fetcher(`${MEDIA_API_PATH}?${params}`);
|
|
31
|
+
const payload = await readEnvelope<{ items?: MediaLibraryItem[] }>(response);
|
|
32
|
+
if (!response.ok) throw envelopeError(response, payload);
|
|
33
|
+
return (payload.data?.items ?? []).filter((item) => item.status === "ready" || !item.status);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Uploads a file through EmDash's multipart media endpoint. Same path on Node (local disk)
|
|
38
|
+
* and Cloudflare (R2) — the host storage adapter differs, not this client (R-007).
|
|
39
|
+
*/
|
|
40
|
+
export async function uploadImage(
|
|
41
|
+
fetcher: Fetcher,
|
|
42
|
+
file: File,
|
|
43
|
+
meta: { width?: number; height?: number; alt?: string } = {},
|
|
44
|
+
): Promise<MediaLibraryItem> {
|
|
45
|
+
const body = new FormData();
|
|
46
|
+
body.set("file", file, file.name);
|
|
47
|
+
if (meta.width !== undefined) body.set("width", String(meta.width));
|
|
48
|
+
if (meta.height !== undefined) body.set("height", String(meta.height));
|
|
49
|
+
if (meta.alt) body.set("alt", meta.alt);
|
|
50
|
+
const response = await fetcher(MEDIA_API_PATH, { method: "POST", body });
|
|
51
|
+
const payload = await readEnvelope<{ item?: MediaLibraryItem; deduplicated?: boolean }>(response);
|
|
52
|
+
if (!response.ok || !payload.data?.item) throw envelopeError(response, payload);
|
|
53
|
+
return payload.data.item;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Applies a library item onto an image node's props (id, URL, alt, dimensions). */
|
|
57
|
+
export function propsFromMedia(
|
|
58
|
+
current: Record<string, unknown>,
|
|
59
|
+
item: MediaLibraryItem,
|
|
60
|
+
): Record<string, unknown> {
|
|
61
|
+
const next: Record<string, unknown> = { ...current, src: item.url, mediaId: item.id };
|
|
62
|
+
if (item.width) next.width = item.width;
|
|
63
|
+
if (item.height) next.height = item.height;
|
|
64
|
+
const alt = current.alt;
|
|
65
|
+
if ((!alt || alt === "Image") && item.alt) next.alt = item.alt;
|
|
66
|
+
else if (!alt || alt === "Image") next.alt = item.filename.replace(/\.[^.]+$/, "") || "Image";
|
|
67
|
+
return next;
|
|
68
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Button, Dialog, Input } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { slugify } from "../../core/index.ts";
|
|
4
|
+
import { ApiError } from "../api.ts";
|
|
5
|
+
import { slugTakenMessage } from "../editor/useSave.ts";
|
|
6
|
+
import { BUTTON, FIELD, SOLID_PRIMARY, UI_CSS } from "../ui.ts";
|
|
7
|
+
|
|
8
|
+
type FieldError = { field: "title" | "slug" | "form"; message: string };
|
|
9
|
+
|
|
10
|
+
/** Why creating failed: a taken slug belongs to the slug field, anything else to the form. */
|
|
11
|
+
function createFailure(failure: unknown, noun: string, slug: string): FieldError {
|
|
12
|
+
if (failure instanceof ApiError && failure.code === "SLUG_CONFLICT") {
|
|
13
|
+
return { field: "slug", message: slugTakenMessage(slug) };
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
field: "form",
|
|
17
|
+
message:
|
|
18
|
+
failure instanceof ApiError
|
|
19
|
+
? `Couldn't create the ${noun}. ${failure.message}`
|
|
20
|
+
: `Couldn't create the ${noun}. Check your connection and try again.`,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The New page / New theme part form (IA): title, a slug that follows `slugPrefix` + title until
|
|
26
|
+
* edited, then `create` returns the editor URL to open. `children` go above the title.
|
|
27
|
+
*/
|
|
28
|
+
export function CreateDialog({
|
|
29
|
+
name,
|
|
30
|
+
heading,
|
|
31
|
+
noun,
|
|
32
|
+
emptyTitle,
|
|
33
|
+
slugPrefix = "",
|
|
34
|
+
slugHint,
|
|
35
|
+
submitLabel,
|
|
36
|
+
create,
|
|
37
|
+
open,
|
|
38
|
+
onOpenChange,
|
|
39
|
+
children,
|
|
40
|
+
}: {
|
|
41
|
+
name: string;
|
|
42
|
+
heading: string;
|
|
43
|
+
noun: string;
|
|
44
|
+
emptyTitle: string;
|
|
45
|
+
slugPrefix?: string;
|
|
46
|
+
slugHint: string;
|
|
47
|
+
submitLabel: string;
|
|
48
|
+
create: (title: string, slug: string) => Promise<string>;
|
|
49
|
+
open: boolean;
|
|
50
|
+
onOpenChange: (open: boolean) => void;
|
|
51
|
+
children?: React.ReactNode;
|
|
52
|
+
}) {
|
|
53
|
+
const [title, setTitle] = React.useState("");
|
|
54
|
+
const [slug, setSlug] = React.useState("");
|
|
55
|
+
const [slugEdited, setSlugEdited] = React.useState(false);
|
|
56
|
+
const [error, setError] = React.useState<FieldError>();
|
|
57
|
+
const [busy, setBusy] = React.useState(false);
|
|
58
|
+
|
|
59
|
+
// A new prefix (theme part type) re-derives an untouched slug for the title typed so far.
|
|
60
|
+
const titleRef = React.useRef(title);
|
|
61
|
+
titleRef.current = title;
|
|
62
|
+
const slugEditedRef = React.useRef(slugEdited);
|
|
63
|
+
slugEditedRef.current = slugEdited;
|
|
64
|
+
React.useEffect(() => {
|
|
65
|
+
if (!slugEditedRef.current && titleRef.current) {
|
|
66
|
+
setSlug(slugify(`${slugPrefix}${titleRef.current}`));
|
|
67
|
+
}
|
|
68
|
+
}, [slugPrefix]);
|
|
69
|
+
|
|
70
|
+
const submit = async () => {
|
|
71
|
+
const cleanTitle = title.trim();
|
|
72
|
+
const cleanSlug = slugify(slug);
|
|
73
|
+
if (!cleanTitle) return setError({ field: "title", message: emptyTitle });
|
|
74
|
+
if (!cleanSlug) {
|
|
75
|
+
return setError({ field: "slug", message: "Enter a slug using letters, digits or -." });
|
|
76
|
+
}
|
|
77
|
+
setError(undefined);
|
|
78
|
+
setBusy(true);
|
|
79
|
+
try {
|
|
80
|
+
window.location.assign(await create(cleanTitle, cleanSlug));
|
|
81
|
+
} catch (failure) {
|
|
82
|
+
setBusy(false);
|
|
83
|
+
setError(createFailure(failure, noun, cleanSlug));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
89
|
+
<Dialog size="base" className="p-6">
|
|
90
|
+
<style>{UI_CSS}</style>
|
|
91
|
+
<form
|
|
92
|
+
data-emvb-dialog={name}
|
|
93
|
+
className="emvb-dialog"
|
|
94
|
+
onSubmit={(event) => {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
void submit();
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
<Dialog.Title>{heading}</Dialog.Title>
|
|
100
|
+
{children}
|
|
101
|
+
<Input
|
|
102
|
+
label="Title"
|
|
103
|
+
className={FIELD}
|
|
104
|
+
autoFocus
|
|
105
|
+
value={title}
|
|
106
|
+
error={error?.field === "title" ? error.message : undefined}
|
|
107
|
+
onChange={(event) => {
|
|
108
|
+
setTitle(event.target.value);
|
|
109
|
+
if (!slugEdited) setSlug(slugify(`${slugPrefix}${event.target.value}`));
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
<Input
|
|
113
|
+
label="Slug"
|
|
114
|
+
className={`${FIELD} emvb-mono`}
|
|
115
|
+
value={slug}
|
|
116
|
+
description={slugHint}
|
|
117
|
+
error={error?.field === "slug" ? error.message : undefined}
|
|
118
|
+
onChange={(event) => {
|
|
119
|
+
setSlugEdited(true);
|
|
120
|
+
setSlug(event.target.value);
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
{error?.field === "form" && (
|
|
124
|
+
<p className="emvb-inline-error" role="alert">
|
|
125
|
+
{error.message}
|
|
126
|
+
</p>
|
|
127
|
+
)}
|
|
128
|
+
<div className="emvb-dialog-actions">
|
|
129
|
+
<Dialog.Close
|
|
130
|
+
render={(props) => (
|
|
131
|
+
<Button {...props} variant="secondary" className={BUTTON}>
|
|
132
|
+
Cancel
|
|
133
|
+
</Button>
|
|
134
|
+
)}
|
|
135
|
+
/>
|
|
136
|
+
<Button
|
|
137
|
+
type="submit"
|
|
138
|
+
variant="primary"
|
|
139
|
+
className={BUTTON}
|
|
140
|
+
style={SOLID_PRIMARY}
|
|
141
|
+
loading={busy}
|
|
142
|
+
>
|
|
143
|
+
{submitLabel}
|
|
144
|
+
</Button>
|
|
145
|
+
</div>
|
|
146
|
+
</form>
|
|
147
|
+
</Dialog>
|
|
148
|
+
</Dialog.Root>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Empty } from "@cloudflare/kumo";
|
|
2
|
+
import { CursorClickIcon } from "@phosphor-icons/react";
|
|
3
|
+
import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
4
|
+
import { RequireEditor } from "../access/RequireEditor.tsx";
|
|
5
|
+
import { defaultFetcher, type Fetcher } from "../api.ts";
|
|
6
|
+
import { Editor } from "../editor/Editor.tsx";
|
|
7
|
+
import { PAGES_URL, THEME_URL } from "../editor/exit.ts";
|
|
8
|
+
|
|
9
|
+
function parseSearch(search: string): { entry: string | null; collection: string } {
|
|
10
|
+
const params = new URLSearchParams(search);
|
|
11
|
+
const entry = params.get("entry")?.trim() || null;
|
|
12
|
+
const raw = params.get("collection")?.trim();
|
|
13
|
+
const collection = raw === THEME_PARTS_COLLECTION ? THEME_PARTS_COLLECTION : PAGES_COLLECTION;
|
|
14
|
+
return { entry, collection };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The editor (`/editor`), exported but not declared, so it has no sidebar or palette entry (D-024). */
|
|
18
|
+
export function EditorPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher }) {
|
|
19
|
+
return (
|
|
20
|
+
<RequireEditor fetcher={fetcher}>
|
|
21
|
+
{() => {
|
|
22
|
+
const { entry, collection } = parseSearch(window.location.search);
|
|
23
|
+
return <EditorLanding fetcher={fetcher} entry={entry} collection={collection} />;
|
|
24
|
+
}}
|
|
25
|
+
</RequireEditor>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function EditorLanding({
|
|
30
|
+
fetcher,
|
|
31
|
+
entry,
|
|
32
|
+
collection,
|
|
33
|
+
}: {
|
|
34
|
+
fetcher: Fetcher;
|
|
35
|
+
entry: string | null;
|
|
36
|
+
collection: string;
|
|
37
|
+
}) {
|
|
38
|
+
if (!entry) {
|
|
39
|
+
const listUrl = collection === THEME_PARTS_COLLECTION ? THEME_URL : PAGES_URL;
|
|
40
|
+
const listLabel = collection === THEME_PARTS_COLLECTION ? "Theme Builder" : "Visual pages";
|
|
41
|
+
return (
|
|
42
|
+
<section data-emvb-page="editor">
|
|
43
|
+
<Empty
|
|
44
|
+
icon={<CursorClickIcon size={32} aria-hidden="true" />}
|
|
45
|
+
title="No page selected"
|
|
46
|
+
description={`Choose an entry to edit from ${listLabel}.`}
|
|
47
|
+
contents={<a href={listUrl}>Go to {listLabel}</a>}
|
|
48
|
+
/>
|
|
49
|
+
</section>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return (
|
|
53
|
+
<section data-emvb-page="editor" data-emvb-entry={entry} data-emvb-collection={collection}>
|
|
54
|
+
<Editor fetcher={fetcher} entryId={entry} collection={collection} />
|
|
55
|
+
</section>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Select } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { layoutFromPageTemplate, starterLayout } from "../../core/index.ts";
|
|
4
|
+
import type { Fetcher } from "../api.ts";
|
|
5
|
+
import { createPage } from "../content-api.ts";
|
|
6
|
+
import { editorUrl } from "../editor/exit.ts";
|
|
7
|
+
import { listThemeParts, themePartLayout, type ThemePartSummary } from "../theme-api.ts";
|
|
8
|
+
import { FIELD } from "../ui.ts";
|
|
9
|
+
import { CreateDialog } from "./CreateDialog.tsx";
|
|
10
|
+
|
|
11
|
+
const NONE = "__none__";
|
|
12
|
+
|
|
13
|
+
/** New page (IA): title, auto-filled editable slug, then straight into the editor. */
|
|
14
|
+
export function NewPageDialog({
|
|
15
|
+
fetcher,
|
|
16
|
+
open,
|
|
17
|
+
onOpenChange,
|
|
18
|
+
}: {
|
|
19
|
+
fetcher: Fetcher;
|
|
20
|
+
open: boolean;
|
|
21
|
+
onOpenChange: (open: boolean) => void;
|
|
22
|
+
}) {
|
|
23
|
+
const [templateId, setTemplateId] = React.useState("");
|
|
24
|
+
const [templates, setTemplates] = React.useState<ThemePartSummary[]>([]);
|
|
25
|
+
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
if (!open) return;
|
|
28
|
+
let cancelled = false;
|
|
29
|
+
void listThemeParts(fetcher)
|
|
30
|
+
.then((all) => {
|
|
31
|
+
if (!cancelled) setTemplates(all.filter((part) => part.partType === "page_template"));
|
|
32
|
+
})
|
|
33
|
+
.catch(() => {
|
|
34
|
+
if (!cancelled) setTemplates([]);
|
|
35
|
+
});
|
|
36
|
+
return () => {
|
|
37
|
+
cancelled = true;
|
|
38
|
+
};
|
|
39
|
+
}, [open, fetcher]);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<CreateDialog
|
|
43
|
+
name="new-page"
|
|
44
|
+
heading="New page"
|
|
45
|
+
noun="page"
|
|
46
|
+
emptyTitle="Enter a title for the page."
|
|
47
|
+
slugHint="The page's address on your site."
|
|
48
|
+
submitLabel="Create page"
|
|
49
|
+
open={open}
|
|
50
|
+
onOpenChange={onOpenChange}
|
|
51
|
+
create={async (title, slug) => {
|
|
52
|
+
let layout = starterLayout(title);
|
|
53
|
+
if (templateId) {
|
|
54
|
+
const source = await themePartLayout(fetcher, templateId, "page_template");
|
|
55
|
+
if (source) layout = layoutFromPageTemplate(source);
|
|
56
|
+
}
|
|
57
|
+
return editorUrl(await createPage(fetcher, { title, slug, layout }));
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
{templates.length > 0 ? (
|
|
61
|
+
<Select
|
|
62
|
+
label="Page template"
|
|
63
|
+
className={FIELD}
|
|
64
|
+
value={templateId || NONE}
|
|
65
|
+
onValueChange={(next) => {
|
|
66
|
+
if (!next || next === NONE) {
|
|
67
|
+
setTemplateId("");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
setTemplateId(next);
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
<Select.Option value={NONE}>Blank page</Select.Option>
|
|
74
|
+
{templates.map((part) => (
|
|
75
|
+
<Select.Option key={part.id} value={part.id}>
|
|
76
|
+
{part.title}
|
|
77
|
+
</Select.Option>
|
|
78
|
+
))}
|
|
79
|
+
</Select>
|
|
80
|
+
) : null}
|
|
81
|
+
</CreateDialog>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Select } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { THEME_PART_TYPES, THEME_PART_TYPE_LABELS, type ThemePartType } from "../../core/index.ts";
|
|
4
|
+
import { THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
5
|
+
import type { Fetcher } from "../api.ts";
|
|
6
|
+
import { createThemePart } from "../theme-api.ts";
|
|
7
|
+
import { editorUrl } from "../editor/exit.ts";
|
|
8
|
+
import { FIELD } from "../ui.ts";
|
|
9
|
+
import { CreateDialog } from "./CreateDialog.tsx";
|
|
10
|
+
|
|
11
|
+
const TYPES = THEME_PART_TYPES.map((value) => ({
|
|
12
|
+
value,
|
|
13
|
+
label: THEME_PART_TYPE_LABELS[value],
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
/** New theme part: type + title, then open the shared editor. */
|
|
17
|
+
export function NewThemePartDialog({
|
|
18
|
+
fetcher,
|
|
19
|
+
open,
|
|
20
|
+
onOpenChange,
|
|
21
|
+
}: {
|
|
22
|
+
fetcher: Fetcher;
|
|
23
|
+
open: boolean;
|
|
24
|
+
onOpenChange: (open: boolean) => void;
|
|
25
|
+
}) {
|
|
26
|
+
const [partType, setPartType] = React.useState<ThemePartType>("header");
|
|
27
|
+
return (
|
|
28
|
+
<CreateDialog
|
|
29
|
+
name="new-theme-part"
|
|
30
|
+
heading="New theme part"
|
|
31
|
+
noun="theme part"
|
|
32
|
+
emptyTitle="Enter a title."
|
|
33
|
+
slugPrefix={`${partType}-`}
|
|
34
|
+
slugHint="Internal id only — theme parts are not public URLs."
|
|
35
|
+
submitLabel="Create"
|
|
36
|
+
open={open}
|
|
37
|
+
onOpenChange={onOpenChange}
|
|
38
|
+
create={async (title, slug) =>
|
|
39
|
+
editorUrl(await createThemePart(fetcher, { title, slug, partType }), THEME_PARTS_COLLECTION)
|
|
40
|
+
}
|
|
41
|
+
>
|
|
42
|
+
<Select
|
|
43
|
+
label="Type"
|
|
44
|
+
className={FIELD}
|
|
45
|
+
value={partType}
|
|
46
|
+
onValueChange={(value) =>
|
|
47
|
+
setPartType(TYPES.find((option) => option.value === value)?.value ?? "header")
|
|
48
|
+
}
|
|
49
|
+
renderValue={(value: unknown) =>
|
|
50
|
+
TYPES.find((option) => option.value === value)?.label ?? String(value)
|
|
51
|
+
}
|
|
52
|
+
>
|
|
53
|
+
{TYPES.map((option) => (
|
|
54
|
+
<Select.Option key={option.value} value={option.value}>
|
|
55
|
+
{option.label}
|
|
56
|
+
</Select.Option>
|
|
57
|
+
))}
|
|
58
|
+
</Select>
|
|
59
|
+
</CreateDialog>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Empty, Loader, Table } from "@cloudflare/kumo";
|
|
2
|
+
import { FileIcon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import type { Fetcher } from "../api.ts";
|
|
5
|
+
import { listPages } from "../content-api.ts";
|
|
6
|
+
import { editorUrl } from "../editor/exit.ts";
|
|
7
|
+
import { EditedTime, ListError, NewButton, StatusBadge, useList } from "./list-kit.tsx";
|
|
8
|
+
import { NewPageDialog } from "./NewPageDialog.tsx";
|
|
9
|
+
|
|
10
|
+
/** The Visual pages list (IA): title and slug, status, last edited; New page. */
|
|
11
|
+
export function PageList({ fetcher }: { fetcher: Fetcher }) {
|
|
12
|
+
const list = useList(fetcher, listPages);
|
|
13
|
+
const [creating, setCreating] = React.useState(false);
|
|
14
|
+
|
|
15
|
+
const newPage = <NewButton label="New page" onClick={() => setCreating(true)} />;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<>
|
|
19
|
+
<div className="emvb-list-header">
|
|
20
|
+
<h1 className="emvb-page-title">Pages VisualBuilder</h1>
|
|
21
|
+
{list.state === "ready" && list.items.length > 0 && newPage}
|
|
22
|
+
</div>
|
|
23
|
+
{list.state === "loading" && <Loader />}
|
|
24
|
+
{list.state === "error" && (
|
|
25
|
+
<ListError title="Couldn't load your pages" message={list.message} />
|
|
26
|
+
)}
|
|
27
|
+
{list.state === "ready" && list.items.length === 0 && (
|
|
28
|
+
<div className="emvb-surface-card emvb-empty-shell">
|
|
29
|
+
<Empty
|
|
30
|
+
icon={<FileIcon size={32} aria-hidden="true" />}
|
|
31
|
+
title="No visual pages yet"
|
|
32
|
+
description="Create a page to start building."
|
|
33
|
+
contents={newPage}
|
|
34
|
+
/>
|
|
35
|
+
</div>
|
|
36
|
+
)}
|
|
37
|
+
{list.state === "ready" && list.items.length > 0 && (
|
|
38
|
+
<div className="emvb-surface-card" data-emvb-list="pages">
|
|
39
|
+
<Table data-emvb-list="pages">
|
|
40
|
+
<Table.Header>
|
|
41
|
+
<Table.Row>
|
|
42
|
+
<Table.Head>Title</Table.Head>
|
|
43
|
+
<Table.Head>Status</Table.Head>
|
|
44
|
+
<Table.Head>Last edited</Table.Head>
|
|
45
|
+
</Table.Row>
|
|
46
|
+
</Table.Header>
|
|
47
|
+
<Table.Body>
|
|
48
|
+
{list.items.map((page) => (
|
|
49
|
+
<Table.Row key={page.id} data-emvb-row={page.id}>
|
|
50
|
+
<Table.Cell>
|
|
51
|
+
<a className="emvb-row-title" href={editorUrl(page.id)}>
|
|
52
|
+
{page.title}
|
|
53
|
+
</a>
|
|
54
|
+
<div className="emvb-row-slug">/{page.slug}</div>
|
|
55
|
+
</Table.Cell>
|
|
56
|
+
<Table.Cell>
|
|
57
|
+
<StatusBadge status={page.status} />
|
|
58
|
+
</Table.Cell>
|
|
59
|
+
<Table.Cell>
|
|
60
|
+
<EditedTime iso={page.updatedAt} />
|
|
61
|
+
</Table.Cell>
|
|
62
|
+
</Table.Row>
|
|
63
|
+
))}
|
|
64
|
+
</Table.Body>
|
|
65
|
+
</Table>
|
|
66
|
+
</div>
|
|
67
|
+
)}
|
|
68
|
+
<NewPageDialog fetcher={fetcher} open={creating} onOpenChange={setCreating} />
|
|
69
|
+
</>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RequireEditor } from "../access/RequireEditor.tsx";
|
|
2
|
+
import { defaultFetcher, type Fetcher } from "../api.ts";
|
|
3
|
+
import { PageList } from "./PageList.tsx";
|
|
4
|
+
import { SetupShell } from "./SetupShell.tsx";
|
|
5
|
+
|
|
6
|
+
/** "Visual pages" (`/pages`): setup states, then the page list. */
|
|
7
|
+
export function PagesPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher }) {
|
|
8
|
+
return (
|
|
9
|
+
<RequireEditor fetcher={fetcher}>
|
|
10
|
+
{(role) => (
|
|
11
|
+
<SetupShell
|
|
12
|
+
fetcher={fetcher}
|
|
13
|
+
role={role}
|
|
14
|
+
page="pages"
|
|
15
|
+
title="Pages VisualBuilder"
|
|
16
|
+
keptNote="Existing pages are kept."
|
|
17
|
+
>
|
|
18
|
+
<div data-emvb-setup="ready" className="emvb-pages">
|
|
19
|
+
<PageList fetcher={fetcher} />
|
|
20
|
+
</div>
|
|
21
|
+
</SetupShell>
|
|
22
|
+
)}
|
|
23
|
+
</RequireEditor>
|
|
24
|
+
);
|
|
25
|
+
}
|