@perkyzz/emvb 0.0.0-stage → 0.2.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 +59 -2
- package/THIRD_PARTY_NOTICES.md +32 -0
- package/licenses/fontawesome-free.LICENSE +165 -0
- package/licenses/lucide-static.LICENSE +43 -0
- package/licenses/remixicon.LICENSE +201 -0
- package/licenses/tabler-icons.LICENSE +21 -0
- package/package.json +76 -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 +75 -0
- package/src/admin/content-api.ts +210 -0
- package/src/admin/editor/Editor.tsx +532 -0
- package/src/admin/editor/EditorOverlay.tsx +66 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +21 -0
- package/src/admin/editor/TopBar.tsx +243 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +536 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +91 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +239 -0
- package/src/admin/editor/canvas/canvas-events.ts +245 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +101 -0
- package/src/admin/editor/canvas/vnode-react.tsx +69 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +164 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +148 -0
- package/src/admin/editor/dnd/new-element.ts +107 -0
- package/src/admin/editor/editor-css.ts +625 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/host.ts +30 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
- package/src/admin/editor/icons/library.ts +243 -0
- package/src/admin/editor/icons/set-format.ts +29 -0
- package/src/admin/editor/icons/sets/fontawesome.json +1 -0
- package/src/admin/editor/icons/sets/lucide.json +1 -0
- package/src/admin/editor/icons/sets/remix.json +1 -0
- package/src/admin/editor/icons/sets/tabler.json +1 -0
- package/src/admin/editor/panels/AddPanel.tsx +146 -0
- package/src/admin/editor/panels/ClassesSection.tsx +372 -0
- package/src/admin/editor/panels/ColorControl.tsx +477 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +773 -0
- package/src/admin/editor/panels/LayersPanel.tsx +573 -0
- package/src/admin/editor/panels/LeftPanel.tsx +81 -0
- package/src/admin/editor/panels/PageSettings.tsx +255 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +113 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +548 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +214 -0
- package/src/admin/editor/panels/VariableSection.tsx +530 -0
- package/src/admin/editor/panels/color-space.ts +195 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +418 -0
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
- package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
- package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +451 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +242 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +354 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +119 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +270 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +106 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +170 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +217 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +130 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +220 -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 +563 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +171 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
- package/src/admin/editor/panels/settings/background-mode.ts +112 -0
- package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
- package/src/admin/editor/panels/settings/box-sides.ts +153 -0
- package/src/admin/editor/panels/settings/button-url.ts +27 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +53 -0
- package/src/admin/editor/panels/settings/form-names.ts +38 -0
- package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
- package/src/admin/editor/panels/settings/image-alt.ts +25 -0
- package/src/admin/editor/panels/settings/length-units.ts +116 -0
- package/src/admin/editor/panels/settings/loop-context.ts +26 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +394 -0
- package/src/admin/editor/panels/settings/svg-images.ts +14 -0
- package/src/admin/editor/panels/site-list.tsx +209 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/restore-deleted.ts +80 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +240 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +203 -0
- package/src/admin/editor/useEditorData.ts +193 -0
- package/src/admin/editor/useEditorShortcuts.ts +180 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +184 -0
- package/src/admin/editor/useSave.ts +242 -0
- package/src/admin/entry-status.ts +19 -0
- package/src/admin/forms-api.ts +73 -0
- package/src/admin/icon-uploads-api.ts +44 -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 +91 -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 +221 -0
- package/src/admin/pages/list-kit.tsx +125 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +107 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +233 -0
- package/src/admin/ui.ts +244 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +63 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
- package/src/astro/floats/index.ts +1 -0
- package/src/astro/floats/runtime.ts +78 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +126 -0
- package/src/astro/index.ts +16 -0
- package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
- package/src/astro/menu/index.ts +1 -0
- package/src/astro/menu/runtime.ts +37 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +296 -0
- package/src/astro/render.ts +108 -0
- package/src/astro/resolve-theme.ts +515 -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 +116 -0
- package/src/astro/theme-context.ts +89 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +448 -0
- package/src/core/clipboard.ts +504 -0
- package/src/core/css/generate.ts +236 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +224 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +132 -0
- package/src/core/design/variables.ts +359 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +225 -0
- package/src/core/elements/field-id.ts +6 -0
- package/src/core/elements/form-elements.ts +219 -0
- package/src/core/elements/index.ts +960 -0
- package/src/core/elements/menu.ts +190 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +45 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +380 -0
- package/src/core/limits.ts +9 -0
- package/src/core/migrate/index.ts +126 -0
- package/src/core/nesting.ts +51 -0
- package/src/core/render/context.ts +21 -0
- package/src/core/render/dynamic-post.ts +175 -0
- package/src/core/render/extras.ts +98 -0
- package/src/core/render/form.ts +235 -0
- package/src/core/render/index.ts +372 -0
- package/src/core/render/loop.ts +43 -0
- package/src/core/render/pagination.ts +76 -0
- package/src/core/render/section.ts +37 -0
- package/src/core/render/tabs.ts +76 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +771 -0
- package/src/core/sanitize/embed-url.ts +160 -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-upload.ts +203 -0
- package/src/core/sanitize/svg.ts +374 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +37 -0
- package/src/core/schema/design.ts +93 -0
- package/src/core/schema/layout.ts +1008 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +336 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +25 -0
- package/src/core/theme/conditions.ts +324 -0
- package/src/core/theme/dynamic.ts +143 -0
- package/src/core/theme/float.ts +113 -0
- package/src/core/theme/pagination.ts +97 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +81 -0
- package/src/core/theme/popup-markup.ts +41 -0
- package/src/core/theme/popup-rules.ts +62 -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 +118 -0
- package/src/server/icon-routes.ts +79 -0
- package/src/server/plugin.ts +43 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { LinkButton, Text } from "@cloudflare/kumo";
|
|
2
|
+
import { ArrowSquareOutIcon } from "@phosphor-icons/react";
|
|
3
|
+
import { summarizeLayout } from "../../core/index.ts";
|
|
4
|
+
import { PAGES_COLLECTION, PLUGIN_ID } from "../../constants.ts";
|
|
5
|
+
|
|
6
|
+
export type FieldWidgetProps = {
|
|
7
|
+
value: unknown;
|
|
8
|
+
onChange: (value: unknown) => void;
|
|
9
|
+
label: string;
|
|
10
|
+
id: string;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
options?: Record<string, unknown>;
|
|
13
|
+
minimal?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function parse(value: unknown): unknown {
|
|
17
|
+
if (typeof value !== "string") return value;
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(value) as unknown;
|
|
20
|
+
} catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The entry id from `/_emdash/admin/content/emvb_pages/<id>`; field widgets don't receive it. */
|
|
26
|
+
export function entryIdFromLocation(pathname: string): string | undefined {
|
|
27
|
+
const match = new RegExp(`/content/${PAGES_COLLECTION}/([^/?#]+)`).exec(pathname);
|
|
28
|
+
const id = match?.[1];
|
|
29
|
+
return id && id !== "new" ? decodeURIComponent(id) : undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Read-only widget for the hidden collection's `layout` field (D-019). It summarises the page and
|
|
34
|
+
* links to EmVB. It has no inputs and never calls `onChange`, so the JSON can't be hand-edited here.
|
|
35
|
+
*/
|
|
36
|
+
export function LayoutField({ value, label, id }: FieldWidgetProps) {
|
|
37
|
+
const summary = summarizeLayout(parse(value));
|
|
38
|
+
const entryId = entryIdFromLocation(window.location.pathname);
|
|
39
|
+
const href = entryId
|
|
40
|
+
? `/_emdash/admin/plugins/${PLUGIN_ID}/editor?entry=${encodeURIComponent(entryId)}`
|
|
41
|
+
: `/_emdash/admin/plugins/${PLUGIN_ID}/pages`;
|
|
42
|
+
const description = !summary
|
|
43
|
+
? "This page has no content yet."
|
|
44
|
+
: `${summary.nodes} ${summary.nodes === 1 ? "element" : "elements"} · schema ${summary.schemaVersion ?? "unknown"}`;
|
|
45
|
+
return (
|
|
46
|
+
<div
|
|
47
|
+
id={id}
|
|
48
|
+
role="group"
|
|
49
|
+
aria-label={label}
|
|
50
|
+
data-emvb-widget="layout"
|
|
51
|
+
className="flex flex-col gap-2"
|
|
52
|
+
>
|
|
53
|
+
<Text variant="secondary">{label}</Text>
|
|
54
|
+
<Text>{description}</Text>
|
|
55
|
+
<Text variant="secondary">This page is edited in EmVB.</Text>
|
|
56
|
+
<div>
|
|
57
|
+
<LinkButton
|
|
58
|
+
href={href}
|
|
59
|
+
variant="secondary"
|
|
60
|
+
icon={<ArrowSquareOutIcon aria-hidden="true" />}
|
|
61
|
+
>
|
|
62
|
+
{entryId ? "Open in EmVB" : "Go to Visual pages"}
|
|
63
|
+
</LinkButton>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { RenderedPage } from "./render.ts";
|
|
3
|
+
|
|
4
|
+
/** The resolved meta of the page (EmDash's `getSeoMeta` result fits), for blank canvas mode. */
|
|
5
|
+
interface PageMeta {
|
|
6
|
+
ogTitle?: string | null;
|
|
7
|
+
ogDescription?: string | null;
|
|
8
|
+
ogImage?: string | null;
|
|
9
|
+
canonical?: string | null;
|
|
10
|
+
robots?: string | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
page: RenderedPage;
|
|
15
|
+
/** Blank canvas mode: a whole document, without the site's layout. The slot ends the body. */
|
|
16
|
+
standalone?: boolean;
|
|
17
|
+
title?: string;
|
|
18
|
+
description?: string | null;
|
|
19
|
+
/**
|
|
20
|
+
* W-274: blank canvas mode has no site layout to print the page's SEO tags, so it prints them:
|
|
21
|
+
* canonical, robots (No index), Open Graph and Twitter card. Pass `getSeoMeta(entry, …)`.
|
|
22
|
+
*/
|
|
23
|
+
seo?: PageMeta;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const { page, standalone = false, title = "", description, seo } = Astro.props;
|
|
27
|
+
const ogTitle = seo?.ogTitle || title;
|
|
28
|
+
const ogDescription = seo?.ogDescription ?? description;
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
standalone ? (
|
|
33
|
+
<html lang="en" dir={page.dir}>
|
|
34
|
+
<head>
|
|
35
|
+
<meta charset="utf-8" />
|
|
36
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
37
|
+
<title>{title}</title>
|
|
38
|
+
{description && <meta name="description" content={description} />}
|
|
39
|
+
{seo?.robots && <meta name="robots" content={seo.robots} />}
|
|
40
|
+
{seo?.canonical && <link rel="canonical" href={seo.canonical} />}
|
|
41
|
+
{seo && <meta property="og:type" content="website" />}
|
|
42
|
+
{seo && ogTitle && <meta property="og:title" content={ogTitle} />}
|
|
43
|
+
{seo && ogDescription && <meta property="og:description" content={ogDescription} />}
|
|
44
|
+
{seo?.canonical && <meta property="og:url" content={seo.canonical} />}
|
|
45
|
+
{seo?.ogImage && <meta property="og:image" content={seo.ogImage} />}
|
|
46
|
+
{seo && (
|
|
47
|
+
<meta name="twitter:card" content={seo.ogImage ? "summary_large_image" : "summary"} />
|
|
48
|
+
)}
|
|
49
|
+
<style is:inline set:html={page.css} />
|
|
50
|
+
</head>
|
|
51
|
+
<body>
|
|
52
|
+
<Fragment set:html={page.html} />
|
|
53
|
+
<slot />
|
|
54
|
+
</body>
|
|
55
|
+
</html>
|
|
56
|
+
) : (
|
|
57
|
+
<>
|
|
58
|
+
<style is:inline set:html={page.css} />
|
|
59
|
+
<Fragment set:html={page.html} />
|
|
60
|
+
<slot />
|
|
61
|
+
</>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as EmVBFloatsRuntime } from "./EmVBFloatsRuntime.astro";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional public float runtime. Hosts load this only when
|
|
3
|
+
* `resolveThemeParts().needsFloatsRuntime` is true, so pages without a float
|
|
4
|
+
* stay free of EmVB JavaScript.
|
|
5
|
+
*
|
|
6
|
+
* Bars on the same edge stack. Their combined height is reserved as page
|
|
7
|
+
* padding so the bar does not cover the first or last content. A close button
|
|
8
|
+
* hides that float until the next visit, in sessionStorage, not a cookie.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const STORAGE_PREFIX = "emvb-float-closed:";
|
|
12
|
+
|
|
13
|
+
function closed(id: string): boolean {
|
|
14
|
+
try {
|
|
15
|
+
return sessionStorage.getItem(STORAGE_PREFIX + id) === "1";
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function rememberClosed(id: string): void {
|
|
22
|
+
try {
|
|
23
|
+
sessionStorage.setItem(STORAGE_PREFIX + id, "1");
|
|
24
|
+
} catch {
|
|
25
|
+
// private mode — the float still hides for this page
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function bars(): HTMLElement[] {
|
|
30
|
+
return [...document.querySelectorAll<HTMLElement>("[data-emvb-float]")];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Stack visible bars and reserve their height. Corners are left to CSS. */
|
|
34
|
+
function placeFloats(): void {
|
|
35
|
+
let top = 0;
|
|
36
|
+
let bottom = 0;
|
|
37
|
+
for (const el of bars()) {
|
|
38
|
+
if (el.hidden) continue;
|
|
39
|
+
const edge = el.getAttribute("data-emvb-float-edge");
|
|
40
|
+
if (edge === "top") {
|
|
41
|
+
el.style.top = `${top}px`;
|
|
42
|
+
top += el.getBoundingClientRect().height;
|
|
43
|
+
} else if (edge === "bottom") {
|
|
44
|
+
el.style.bottom = `${bottom}px`;
|
|
45
|
+
bottom += el.getBoundingClientRect().height;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const root = document.documentElement;
|
|
49
|
+
root.style.setProperty("--emvb-float-top", `${top}px`);
|
|
50
|
+
root.style.setProperty("--emvb-float-bottom", `${bottom}px`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function hide(el: HTMLElement): void {
|
|
54
|
+
const id = el.getAttribute("data-emvb-float");
|
|
55
|
+
el.hidden = true;
|
|
56
|
+
if (id) rememberClosed(id);
|
|
57
|
+
placeFloats();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Hide floats already closed this visit, then keep bars stacked. */
|
|
61
|
+
export function initFloats(): void {
|
|
62
|
+
for (const el of bars()) {
|
|
63
|
+
const id = el.getAttribute("data-emvb-float");
|
|
64
|
+
if (id && closed(id)) el.hidden = true;
|
|
65
|
+
}
|
|
66
|
+
placeFloats();
|
|
67
|
+
document.addEventListener("click", (event) => {
|
|
68
|
+
const target = event.target;
|
|
69
|
+
if (!(target instanceof Element)) return;
|
|
70
|
+
const button = target.closest("[data-emvb-float-dismiss]");
|
|
71
|
+
if (!button) return;
|
|
72
|
+
const float = button.closest<HTMLElement>("[data-emvb-float]");
|
|
73
|
+
if (!float) return;
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
hide(float);
|
|
76
|
+
});
|
|
77
|
+
window.addEventListener("resize", placeFloats);
|
|
78
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The forms plugin's client (D-015). Hosts render this only when a page `needsFormsRuntime`,
|
|
3
|
+
// so pages without forms stay zero-JS (R-031). Form elements arrive in S5.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<script>
|
|
7
|
+
import { initForms } from "@emdash-cms/plugin-forms/client";
|
|
8
|
+
initForms();
|
|
9
|
+
</script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as EmVBFormsRuntime } from "./EmVBFormsRuntime.astro";
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { PublicPluginApiRouteHandler } from "emdash/plugin-utils";
|
|
2
|
+
import {
|
|
3
|
+
isFormNode,
|
|
4
|
+
type FormDefinitions,
|
|
5
|
+
type Layout,
|
|
6
|
+
type LayoutNode,
|
|
7
|
+
type PublicFormDefinition,
|
|
8
|
+
type PublicFormField,
|
|
9
|
+
} from "../core/index.ts";
|
|
10
|
+
import { nodeChildren } from "../core/tree-ops.ts";
|
|
11
|
+
|
|
12
|
+
const FORMS_PLUGIN = "emdash-forms";
|
|
13
|
+
|
|
14
|
+
function walk(node: LayoutNode, visit: (node: LayoutNode) => void): void {
|
|
15
|
+
visit(node);
|
|
16
|
+
for (const child of nodeChildren(node)) walk(child, visit);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function formIdsInLayout(layout: Layout): string[] {
|
|
20
|
+
const ids = new Set<string>();
|
|
21
|
+
walk(layout.root, (node) => {
|
|
22
|
+
if (isFormNode(node) && node.props.formId) ids.add(node.props.formId);
|
|
23
|
+
});
|
|
24
|
+
return [...ids];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
28
|
+
!!value && typeof value === "object" && !Array.isArray(value);
|
|
29
|
+
|
|
30
|
+
const isOption = (value: unknown): value is { label: string; value: string } =>
|
|
31
|
+
isRecord(value) && typeof value.label === "string" && typeof value.value === "string";
|
|
32
|
+
|
|
33
|
+
/** Only the numbers and pattern the renderer sets on the control; the rest is dropped. */
|
|
34
|
+
function asValidation(value: unknown): PublicFormField["validation"] | undefined {
|
|
35
|
+
if (!isRecord(value)) return undefined;
|
|
36
|
+
const number = (key: string): number | undefined =>
|
|
37
|
+
typeof value[key] === "number" && Number.isFinite(value[key])
|
|
38
|
+
? (value[key] as number)
|
|
39
|
+
: undefined;
|
|
40
|
+
const validation: NonNullable<PublicFormField["validation"]> = {};
|
|
41
|
+
const minLength = number("minLength");
|
|
42
|
+
const maxLength = number("maxLength");
|
|
43
|
+
const min = number("min");
|
|
44
|
+
const max = number("max");
|
|
45
|
+
if (minLength !== undefined) validation.minLength = minLength;
|
|
46
|
+
if (maxLength !== undefined) validation.maxLength = maxLength;
|
|
47
|
+
if (min !== undefined) validation.min = min;
|
|
48
|
+
if (max !== undefined) validation.max = max;
|
|
49
|
+
if (typeof value.pattern === "string") validation.pattern = value.pattern;
|
|
50
|
+
return Object.keys(validation).length > 0 ? validation : undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A field the renderer can use, or null; options that aren't label/value text are left out. */
|
|
54
|
+
function asField(value: unknown): PublicFormField | null {
|
|
55
|
+
if (!isRecord(value) || typeof value.name !== "string") return null;
|
|
56
|
+
const field: PublicFormField = {
|
|
57
|
+
...value,
|
|
58
|
+
name: value.name,
|
|
59
|
+
type: typeof value.type === "string" ? value.type : "",
|
|
60
|
+
label: typeof value.label === "string" ? value.label : value.name,
|
|
61
|
+
required: value.required === true,
|
|
62
|
+
};
|
|
63
|
+
if (Array.isArray(value.options)) field.options = value.options.filter(isOption);
|
|
64
|
+
else delete field.options;
|
|
65
|
+
if (typeof value.placeholder !== "string") delete field.placeholder;
|
|
66
|
+
field.validation = asValidation(value.validation);
|
|
67
|
+
if (!field.validation) delete field.validation;
|
|
68
|
+
return field;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The plugin's answer as a definition the core renderer can trust. The route is another plugin's
|
|
73
|
+
* code, so missing `settings`, odd pages or fields are normalised here rather than crashing the
|
|
74
|
+
* public render (W-092).
|
|
75
|
+
*/
|
|
76
|
+
function asDefinition(payload: unknown): PublicFormDefinition | null {
|
|
77
|
+
if (!payload || typeof payload !== "object") return null;
|
|
78
|
+
const body = payload as { success?: boolean; data?: unknown };
|
|
79
|
+
const data = body.success === true ? body.data : payload;
|
|
80
|
+
if (!data || typeof data !== "object") return null;
|
|
81
|
+
const def = data as Record<string, unknown>;
|
|
82
|
+
if (!Array.isArray(def.pages)) return null;
|
|
83
|
+
const rawPages: unknown[] = Array.isArray(def.pages) ? def.pages : [];
|
|
84
|
+
const pages = rawPages.filter(isRecord).map((page) =>
|
|
85
|
+
Object.assign({}, page, {
|
|
86
|
+
fields: Array.isArray(page.fields)
|
|
87
|
+
? page.fields.map(asField).filter((field) => field !== null)
|
|
88
|
+
: [],
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
const rawSettings = isRecord(def.settings) ? def.settings : {};
|
|
92
|
+
const settings: PublicFormDefinition["settings"] = { ...rawSettings };
|
|
93
|
+
if (typeof rawSettings.submitLabel !== "string") delete settings.submitLabel;
|
|
94
|
+
if (typeof rawSettings.spamProtection !== "string") delete settings.spamProtection;
|
|
95
|
+
return { ...(def as PublicFormDefinition), pages, settings };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Loads public form definitions in-process (D-015). Missing forms are omitted. */
|
|
99
|
+
export async function loadFormDefinitions(
|
|
100
|
+
handler: PublicPluginApiRouteHandler | undefined,
|
|
101
|
+
base: URL,
|
|
102
|
+
formIds: readonly string[],
|
|
103
|
+
): Promise<FormDefinitions> {
|
|
104
|
+
const map = new Map<string, PublicFormDefinition>();
|
|
105
|
+
if (!handler || formIds.length === 0) return map;
|
|
106
|
+
await Promise.all(
|
|
107
|
+
formIds.map(async (formId) => {
|
|
108
|
+
try {
|
|
109
|
+
const request = new Request(
|
|
110
|
+
new URL(`/_emdash/api/plugins/${FORMS_PLUGIN}/definition`, base),
|
|
111
|
+
{
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: { "Content-Type": "application/json" },
|
|
114
|
+
body: JSON.stringify({ id: formId }),
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
const response = await handler(FORMS_PLUGIN, "POST", "/definition", request);
|
|
118
|
+
const def = asDefinition(response);
|
|
119
|
+
if (def) map.set(formId, def);
|
|
120
|
+
} catch {
|
|
121
|
+
// Forms plugin missing or form unknown — render without definition options.
|
|
122
|
+
}
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
return map;
|
|
126
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { default as EmVBPage } from "./EmVBPage.astro";
|
|
2
|
+
export { resolveEmVBPage, type ResolvedEmVBPage } from "./resolve.ts";
|
|
3
|
+
export {
|
|
4
|
+
resolveThemeParts,
|
|
5
|
+
type RenderedThemePart,
|
|
6
|
+
type RenderedPopup,
|
|
7
|
+
type ResolvedThemeParts,
|
|
8
|
+
} from "./resolve-theme.ts";
|
|
9
|
+
export { archivePageTitle } from "../core/index.ts";
|
|
10
|
+
export {
|
|
11
|
+
themeContextFrom,
|
|
12
|
+
themeContextFront,
|
|
13
|
+
themeContext404,
|
|
14
|
+
themeContextSearch,
|
|
15
|
+
themeContextFromContent,
|
|
16
|
+
} from "./theme-context.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as EmVBMenuRuntime } from "./EmVBMenuRuntime.astro";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional public Menu script (W-197). Menus are `<details>` disclosures and work without it;
|
|
3
|
+
* this adds Escape (it closes the open dropdown the focus or pointer is in and returns focus to
|
|
4
|
+
* that dropdown's toggle) and closes an open dropdown when focus or a click lands outside its
|
|
5
|
+
* menu item (W-254). Hosts load it when `needsMenuRuntime` is true.
|
|
6
|
+
*/
|
|
7
|
+
const OPEN = "details.emvb-menu-item__disclosure[open]";
|
|
8
|
+
|
|
9
|
+
function onKeydown(event: KeyboardEvent): void {
|
|
10
|
+
if (event.key !== "Escape" || event.defaultPrevented) return;
|
|
11
|
+
const active = document.activeElement;
|
|
12
|
+
const inside = active instanceof Element ? active.closest<HTMLDetailsElement>(OPEN) : null;
|
|
13
|
+
const target = inside ?? document.querySelector<HTMLDetailsElement>(`.emvb-menu ${OPEN}`);
|
|
14
|
+
if (!target) return;
|
|
15
|
+
target.open = false;
|
|
16
|
+
target.querySelector<HTMLElement>(":scope > summary")?.focus({ preventScroll: true });
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** W-254: an open dropdown closes once focus or a pointer press lands outside its menu item. */
|
|
21
|
+
function closeOthers(event: Event): void {
|
|
22
|
+
const target = event.target instanceof Node ? event.target : null;
|
|
23
|
+
for (const details of document.querySelectorAll<HTMLDetailsElement>(`.emvb-menu ${OPEN}`)) {
|
|
24
|
+
const item = details.closest(".emvb-menu-item") ?? details;
|
|
25
|
+
if (target && item.contains(target)) continue;
|
|
26
|
+
details.open = false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function initMenus(root: Document = document): void {
|
|
31
|
+
const marked = root.documentElement;
|
|
32
|
+
if (marked.dataset["emvbMenuReady"] === "1") return;
|
|
33
|
+
marked.dataset["emvbMenuReady"] = "1";
|
|
34
|
+
root.addEventListener("keydown", onKeydown);
|
|
35
|
+
root.addEventListener("focusin", closeOthers);
|
|
36
|
+
root.addEventListener("pointerdown", closeOthers);
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as EmVBPopupsRuntime } from "./EmVBPopupsRuntime.astro";
|