@perkyzz/emvb 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +3 -3
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +7 -7
  4. package/src/admin/editor/DialogCloseButton.tsx +16 -0
  5. package/src/admin/editor/Editor.tsx +71 -1
  6. package/src/admin/editor/FieldPreview.tsx +164 -0
  7. package/src/admin/editor/PerfMeter.tsx +3 -9
  8. package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
  9. package/src/admin/editor/ShareLink.tsx +2 -7
  10. package/src/admin/editor/ShortcutsDialog.tsx +19 -11
  11. package/src/admin/editor/Timeline.tsx +2 -7
  12. package/src/admin/editor/TopBar.tsx +32 -1
  13. package/src/admin/editor/dialogs.tsx +3 -14
  14. package/src/admin/editor/editor-chrome.tsx +8 -24
  15. package/src/admin/editor/editor-commands.ts +15 -1
  16. package/src/admin/editor/editor-css.ts +6 -2
  17. package/src/admin/editor/feature-css.ts +11 -1
  18. package/src/admin/editor/focus-when-lost.ts +23 -0
  19. package/src/admin/editor/host.ts +6 -0
  20. package/src/admin/editor/icons/IconLibraryDialog.tsx +2 -7
  21. package/src/admin/editor/palette-items.ts +17 -0
  22. package/src/admin/editor/panels/AddPanel.tsx +9 -1
  23. package/src/admin/editor/panels/ElementPanel.tsx +4 -1
  24. package/src/admin/editor/panels/LayersPanel.tsx +6 -1
  25. package/src/admin/editor/panels/LeftPanel.tsx +9 -1
  26. package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
  27. package/src/admin/editor/panels/SiteStylesDrawer.tsx +54 -10
  28. package/src/admin/editor/panels/TokenScales.tsx +16 -16
  29. package/src/admin/editor/panels/TriggersEditor.tsx +1 -1
  30. package/src/admin/editor/panels/color-space.ts +14 -26
  31. package/src/admin/editor/panels/settings/AudienceEditor.tsx +36 -39
  32. package/src/admin/editor/panels/settings/BackgroundControls.tsx +4 -5
  33. package/src/admin/editor/panels/settings/IconControls.tsx +21 -5
  34. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  35. package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
  36. package/src/admin/editor/panels/settings/length-units.ts +2 -1
  37. package/src/admin/editor/shortcuts.ts +14 -0
  38. package/src/admin/editor/useSavedSections.ts +197 -0
  39. package/src/admin/image-editor/Canvas.tsx +61 -17
  40. package/src/admin/image-editor/ImageEditorDialog.tsx +130 -1
  41. package/src/admin/image-editor/image-editor-css.ts +11 -8
  42. package/src/admin/image-editor/parts.tsx +18 -17
  43. package/src/admin/image-editor/save.ts +31 -1
  44. package/src/admin/index.tsx +5 -1
  45. package/src/admin/media-api.ts +27 -0
  46. package/src/admin/pages/AgentsPage.tsx +3 -3
  47. package/src/admin/pages/CollectionsPage.tsx +215 -0
  48. package/src/admin/pages/ThemePartList.tsx +32 -4
  49. package/src/admin/saved-sections-api.ts +51 -0
  50. package/src/admin/setup/host-collections.ts +100 -0
  51. package/src/admin/theme-api.ts +3 -2
  52. package/src/admin/ui.ts +9 -0
  53. package/src/admin/widgets/CanvasField.tsx +202 -0
  54. package/src/admin/widgets/convert-body.ts +54 -0
  55. package/src/admin/widgets/field-fetcher.ts +79 -0
  56. package/src/astro/index.ts +2 -0
  57. package/src/astro/page-count.ts +77 -0
  58. package/src/astro/popups/runtime.ts +8 -6
  59. package/src/astro/resolve-theme.ts +44 -2
  60. package/src/astro/resolve.ts +40 -4
  61. package/src/astro/responsive-images.ts +99 -0
  62. package/src/constants.ts +1 -1
  63. package/src/core/a11y/audit.ts +32 -7
  64. package/src/core/arrange.ts +21 -6
  65. package/src/core/canvas-collections.ts +20 -0
  66. package/src/core/css/print.ts +5 -0
  67. package/src/core/design/classes.ts +23 -9
  68. package/src/core/design/devices.ts +7 -13
  69. package/src/core/design/states.ts +7 -13
  70. package/src/core/elements/dynamic-elements.ts +27 -12
  71. package/src/core/elements/index.ts +1 -1
  72. package/src/core/elements/menu.ts +3 -0
  73. package/src/core/icons/animation-runs.ts +11 -0
  74. package/src/core/index.ts +22 -0
  75. package/src/core/migrate/index.ts +3 -0
  76. package/src/core/portable-text.ts +127 -0
  77. package/src/core/render/loop.ts +1 -1
  78. package/src/core/render/pagination.ts +20 -1
  79. package/src/core/sanitize/css.ts +14 -6
  80. package/src/core/saved-sections.ts +318 -0
  81. package/src/core/schema/design.ts +1 -1
  82. package/src/core/schema/layout.ts +6 -1
  83. package/src/core/schema/style.ts +4 -2
  84. package/src/core/theme/float.ts +3 -0
  85. package/src/core/theme/pagination.ts +34 -24
  86. package/src/core/theme/part-types.ts +4 -4
  87. package/src/index.ts +11 -1
  88. package/src/mcp/ports.ts +22 -1
  89. package/src/mcp/read.ts +1 -1
  90. package/src/mcp/sections.ts +183 -0
  91. package/src/mcp/tools.ts +44 -0
  92. package/src/mcp/write.ts +4 -4
  93. package/src/server/agent-settings.ts +16 -1
  94. package/src/server/hooks.ts +81 -0
  95. package/src/server/mcp-routes.ts +2 -0
  96. package/src/server/plugin.ts +34 -5
  97. package/src/server/saved-sections.ts +163 -0
@@ -2,7 +2,7 @@
2
2
  * Saving an edited picture (W-485): export settings, the output file and the `edit` record.
3
3
  * No photocn import here, so this stays testable without WebGL.
4
4
  */
5
- import { ImageEdit, type ImageEditRecipe } from "../../core/index.ts";
5
+ import { IMAGE_EDIT_RECIPE_MAX_BYTES, ImageEdit, ImageEditRecipe } from "../../core/index.ts";
6
6
  import type { ImageEditOutput } from "../../core/image-edit/schema.ts";
7
7
  import { stripJpegGps } from "./exif.ts";
8
8
 
@@ -139,3 +139,33 @@ export function savedRecipe(imageProps: Record<string, unknown>): ImageEditRecip
139
139
  const { recipe } = parsed.data;
140
140
  return Object.keys(recipe).some((k) => k !== "version" && k !== "name") ? recipe : null;
141
141
  }
142
+
143
+ /** W-862 (IE-2): the edit recipe as a JSON file, as photocn's recipe export. */
144
+ export function recipeFileText(recipe: ImageEditRecipe): string {
145
+ return `${JSON.stringify({ emvbImageRecipe: 1, photocn: PHOTOCN_VERSION, recipe }, null, 2)}\n`;
146
+ }
147
+
148
+ /** A recipe file larger than this isn't read at all (W-881). */
149
+ export const RECIPE_FILE_MAX_BYTES = IMAGE_EDIT_RECIPE_MAX_BYTES * 4;
150
+
151
+ export type RecipeFileResult = { ok: true; recipe: ImageEditRecipe } | { ok: false; error: string };
152
+
153
+ /** Reads a recipe file (ours, or a bare photocn recipe) and checks it like a saved edit. */
154
+ export function parseRecipeFile(text: string): RecipeFileResult {
155
+ const bad = { ok: false, error: "This file isn't an image edit recipe." } as const;
156
+ if (text.length > RECIPE_FILE_MAX_BYTES) return bad;
157
+ let raw: unknown;
158
+ try {
159
+ raw = JSON.parse(text);
160
+ } catch {
161
+ return bad;
162
+ }
163
+ const inner =
164
+ raw && typeof raw === "object" && "recipe" in raw ? (raw as { recipe: unknown }).recipe : raw;
165
+ const parsed = ImageEditRecipe.safeParse(inner);
166
+ if (!parsed.success) return bad;
167
+ if (new TextEncoder().encode(JSON.stringify(parsed.data)).length > IMAGE_EDIT_RECIPE_MAX_BYTES) {
168
+ return { ok: false, error: "This recipe is too large." };
169
+ }
170
+ return { ok: true, recipe: parsed.data };
171
+ }
@@ -4,19 +4,23 @@ import { defaultFetcher } from "./api.ts";
4
4
  import { EditorPage } from "./pages/EditorPage.tsx";
5
5
  import { PagesPage } from "./pages/PagesPage.tsx";
6
6
  import { AgentsPage } from "./pages/AgentsPage.tsx";
7
+ import { CollectionsPage } from "./pages/CollectionsPage.tsx";
7
8
  import { ThemeBuilderPage } from "./pages/ThemeBuilderPage.tsx";
9
+ import { CanvasField } from "./widgets/CanvasField.tsx";
8
10
  import { LayoutField } from "./widgets/LayoutField.tsx";
9
11
 
10
12
  if (typeof document !== "undefined") void installSidebarShim(document, defaultFetcher);
11
13
 
12
- /** `/pages`, `/theme` and `/agents` are declared; `/editor` renders by URL (D-024). */
14
+ /** `/pages`, `/theme`, `/agents` and `/collections` are declared; `/editor` renders by URL (D-024). */
13
15
  export const pages: PluginAdminExports["pages"] = {
14
16
  "/pages": PagesPage,
15
17
  "/theme": ThemeBuilderPage,
16
18
  "/agents": AgentsPage,
19
+ "/collections": CollectionsPage,
17
20
  "/editor": EditorPage,
18
21
  };
19
22
 
20
23
  export const fields: PluginAdminExports["fields"] = {
21
24
  layout: LayoutField,
25
+ canvas: CanvasField,
22
26
  };
@@ -12,6 +12,9 @@ export type MediaLibraryItem = {
12
12
  storageKey: string;
13
13
  status: string;
14
14
  url: string;
15
+ /** EmDash 1.4 library focal point, 0–1 (null or absent when unset). */
16
+ focalX?: number | null;
17
+ focalY?: number | null;
15
18
  };
16
19
 
17
20
  /** Shared EmDash media endpoint — same path on Node local and Cloudflare R2 (R-007). */
@@ -95,6 +98,29 @@ function fitImageSize(
95
98
  next.height = Math.max(1, Math.round(height * scale));
96
99
  }
97
100
 
101
+ const unitCoordinate = (value: unknown): value is number =>
102
+ typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
103
+
104
+ /**
105
+ * W-915: EmDash 1.4 stores a focal point per library image (0–1). A newly picked picture takes it
106
+ * as the element's focal point (0–100 %); one the editor set on this same picture is kept.
107
+ */
108
+ function libraryFocal(
109
+ next: Record<string, unknown>,
110
+ current: Record<string, unknown>,
111
+ item: MediaLibraryItem,
112
+ ): void {
113
+ const samePicture = current.src === item.url;
114
+ if (samePicture && current.focalX !== undefined) return;
115
+ if (unitCoordinate(item.focalX) && unitCoordinate(item.focalY)) {
116
+ next.focalX = Math.round(item.focalX * 100);
117
+ next.focalY = Math.round(item.focalY * 100);
118
+ } else if (!samePicture) {
119
+ delete next.focalX;
120
+ delete next.focalY;
121
+ }
122
+ }
123
+
98
124
  /** Applies a library item onto an image node's props (id, URL, alt, dimensions). */
99
125
  export function propsFromMedia(
100
126
  current: Record<string, unknown>,
@@ -108,6 +134,7 @@ export function propsFromMedia(
108
134
  delete next.edit;
109
135
  }
110
136
  fitImageSize(next, item.width, item.height);
137
+ libraryFocal(next, current, item);
111
138
  const alt = current.alt;
112
139
  if ((!alt || alt === "Image") && item.alt) next.alt = item.alt;
113
140
  else if (!alt || alt === "Image") next.alt = item.filename.replace(/\.[^.]+$/, "") || "Image";
@@ -45,7 +45,7 @@ const remoteSnippet = (endpoint: string) =>
45
45
  JSON.stringify({ mcpServers: { emvb: { url: endpoint } } }, null, 2);
46
46
 
47
47
  /** A card's heading row: an icon tile, the title and one line on what the card is for (W-477). */
48
- function SectionHead({
48
+ export function SectionHead({
49
49
  id,
50
50
  icon: SectionIcon,
51
51
  title,
@@ -74,7 +74,7 @@ function SectionHead({
74
74
  * W-756: on a phone the setup JSON scrolls sideways, and keyboard users could not reach it to
75
75
  * scroll. Focusable, and named so a screen reader says what it is.
76
76
  */
77
- const SCROLLABLE = { tabIndex: 0, role: "group" } as const;
77
+ export const SCROLLABLE = { tabIndex: 0, role: "group" } as const;
78
78
 
79
79
  export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher }) {
80
80
  const role = useRole(fetcher);
@@ -337,7 +337,7 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
337
337
  }
338
338
 
339
339
  /** UX-089: the setup JSON is meant to be pasted into an agent's config, so it copies in one click. */
340
- function CopySnippet({ text, name }: { text: string; name: string }) {
340
+ export function CopySnippet({ text, name }: { text: string; name: string }) {
341
341
  const [copied, setCopied] = useState<"yes" | "no" | null>(null);
342
342
  useEffect(() => {
343
343
  // W-777: a failed copy stays until the next click; it vanished after 2 s.
@@ -0,0 +1,215 @@
1
+ import { Badge, Banner, Button, Empty, Loader, Table } from "@cloudflare/kumo";
2
+ import {
3
+ CodeIcon,
4
+ DatabaseIcon,
5
+ LockKeyIcon,
6
+ PlusIcon,
7
+ WarningCircleIcon,
8
+ } from "@phosphor-icons/react";
9
+ import type { ReactNode } from "react";
10
+ import { useEffect, useState } from "react";
11
+ import { useRole } from "../access/role.ts";
12
+ import { defaultFetcher, type Fetcher } from "../api.ts";
13
+ import {
14
+ addCanvasField,
15
+ canvasCollectionsSnippet,
16
+ loadHostCollections,
17
+ type HostCollectionRow,
18
+ } from "../setup/host-collections.ts";
19
+ import { BUTTON, UI_CSS } from "../ui.ts";
20
+ import { CopySnippet, SCROLLABLE, SectionHead } from "./AgentsPage.tsx";
21
+ import { ListError, ListLoading } from "./list-kit.tsx";
22
+
23
+ const ADMIN_ROLE = 50;
24
+
25
+ const PAGE_CSS = `
26
+ .emvb-collections-table td:last-child, .emvb-collections-table th:last-child { text-align: end; }
27
+ .emvb-collections-slug { display: block; font-size: 12px; color: var(--text-color-kumo-subtle); font-family: var(--font-mono); }
28
+ `;
29
+
30
+ function shell(body: ReactNode, status = "ready") {
31
+ return (
32
+ <div className="emvb-pages emvb-agents" data-emvb-collections={status}>
33
+ <style data-emvb-ui="">{UI_CSS}</style>
34
+ <style>{PAGE_CSS}</style>
35
+ <div className="emvb-agents-header">
36
+ <div>
37
+ <h1 className="emvb-page-title">Host collections</h1>
38
+ <p>
39
+ Let entries in your own collections hold an EmVB layout, edited with Edit with EmVB.
40
+ </p>
41
+ </div>
42
+ </div>
43
+ {body}
44
+ </div>
45
+ );
46
+ }
47
+
48
+ function FieldBadge({ row }: { row: HostCollectionRow }) {
49
+ if (row.field === "ready") return <Badge variant="blue">Has {row.fieldSlug}</Badge>;
50
+ if (row.field === "taken") return <Badge variant="neutral">"canvas" is another field</Badge>;
51
+ return <Badge variant="neutral">No canvas field</Badge>;
52
+ }
53
+
54
+ /**
55
+ * Host collections (`/collections`, W-913): which collections can hold an EmVB layout, a button
56
+ * that adds the `emvb:canvas` field through EmDash's schema API, and the `canvasCollections`
57
+ * snippet. That option lives in astro.config and is read at start-up, so setup can't change it.
58
+ */
59
+ export function CollectionsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher }) {
60
+ const role = useRole(fetcher);
61
+ const isAdmin = role.state === "ready" && role.role >= ADMIN_ROLE;
62
+ const [state, setState] = useState<Awaited<ReturnType<typeof loadHostCollections>> | null>(null);
63
+ const [error, setError] = useState<string | null>(null);
64
+ const [attempt, setAttempt] = useState(0);
65
+ const [adding, setAdding] = useState<string | null>(null);
66
+ const [addError, setAddError] = useState<string | null>(null);
67
+
68
+ useEffect(() => {
69
+ if (!isAdmin) return;
70
+ let cancelled = false;
71
+ loadHostCollections(fetcher)
72
+ .then((next) => !cancelled && setState(next))
73
+ .catch((e: unknown) => !cancelled && setError(e instanceof Error ? e.message : String(e)));
74
+ return () => {
75
+ cancelled = true;
76
+ };
77
+ }, [fetcher, isAdmin, attempt]);
78
+
79
+ if (role.state === "loading")
80
+ return shell(<ListLoading label="Loading collections…" />, "loading");
81
+ if (!isAdmin) {
82
+ return (
83
+ <section data-emvb-access="denied">
84
+ <Empty
85
+ icon={<LockKeyIcon aria-hidden="true" />}
86
+ title="Only administrators can set up host collections"
87
+ description="Ask an administrator to add the canvas field."
88
+ />
89
+ </section>
90
+ );
91
+ }
92
+ if (error) {
93
+ return shell(
94
+ <ListError
95
+ title="Couldn't load the collections"
96
+ message={error}
97
+ onRetry={() => {
98
+ setError(null);
99
+ setAttempt((n) => n + 1);
100
+ }}
101
+ />,
102
+ "error",
103
+ );
104
+ }
105
+ if (!state) return shell(<ListLoading label="Loading collections…" />, "loading");
106
+
107
+ const add = async (slug: string) => {
108
+ setAdding(slug);
109
+ setAddError(null);
110
+ try {
111
+ await addCanvasField(fetcher, slug);
112
+ setState(await loadHostCollections(fetcher));
113
+ } catch (e) {
114
+ setAddError(e instanceof Error ? e.message : String(e));
115
+ } finally {
116
+ setAdding(null);
117
+ }
118
+ };
119
+ const snippet = canvasCollectionsSnippet(state.rows, state.canvasStyles);
120
+ const unlisted = state.rows.filter((r) => r.field === "ready" && !r.listed);
121
+
122
+ return shell(
123
+ <>
124
+ {addError && (
125
+ <Banner variant="error" icon={<WarningCircleIcon aria-hidden="true" />}>
126
+ The field wasn't added: {addError}
127
+ </Banner>
128
+ )}
129
+ <section className="emvb-surface-card emvb-agents-section" aria-labelledby="emvb-hc-list">
130
+ <SectionHead id="emvb-hc-list" icon={DatabaseIcon} title="Collections">
131
+ Adding the field changes the collection's schema; existing entries keep their content and
132
+ show it until a layout is added.
133
+ </SectionHead>
134
+ {state.rows.length === 0 ? (
135
+ <p>This site has no collections of its own yet.</p>
136
+ ) : (
137
+ // W-921: on phones the table scrolls inside the card, not the whole admin page.
138
+ <div className="emvb-agents-table" {...SCROLLABLE} aria-label="Collections">
139
+ <Table className="emvb-collections-table">
140
+ <Table.Header>
141
+ <Table.Row>
142
+ <Table.Head>Collection</Table.Head>
143
+ <Table.Head>Field</Table.Head>
144
+ <Table.Head>In canvasCollections</Table.Head>
145
+ <Table.Head>
146
+ <span className="sr-only">Action</span>
147
+ </Table.Head>
148
+ </Table.Row>
149
+ </Table.Header>
150
+ <Table.Body>
151
+ {state.rows.map((row) => (
152
+ <Table.Row key={row.slug} data-emvb-collection={row.slug}>
153
+ <Table.Cell>
154
+ {row.label}
155
+ <span className="emvb-collections-slug">{row.slug}</span>
156
+ </Table.Cell>
157
+ <Table.Cell>
158
+ <FieldBadge row={row} />
159
+ </Table.Cell>
160
+ <Table.Cell>{row.listed ? "Yes" : "Not yet"}</Table.Cell>
161
+ <Table.Cell>
162
+ {row.field === "missing" && (
163
+ <Button
164
+ size="sm"
165
+ variant="secondary"
166
+ className={BUTTON}
167
+ icon={
168
+ adding === row.slug ? (
169
+ <Loader size={14} />
170
+ ) : (
171
+ <PlusIcon aria-hidden="true" />
172
+ )
173
+ }
174
+ disabled={adding !== null}
175
+ aria-label={`Add canvas field to ${row.label}`}
176
+ onClick={() => void add(row.slug)}
177
+ >
178
+ Add canvas field
179
+ </Button>
180
+ )}
181
+ </Table.Cell>
182
+ </Table.Row>
183
+ ))}
184
+ </Table.Body>
185
+ </Table>
186
+ </div>
187
+ )}
188
+ </section>
189
+ <section className="emvb-surface-card emvb-agents-section" aria-labelledby="emvb-hc-config">
190
+ <SectionHead id="emvb-hc-config" icon={CodeIcon} title="Site config">
191
+ <code>canvasCollections</code> is an option of <code>emvb()</code> in astro.config, read
192
+ when the site starts, so EmVB can't set it from here. Paste this, then restart or redeploy
193
+ the site.
194
+ </SectionHead>
195
+ {unlisted.length > 0 && (
196
+ <Banner variant="default" data-emvb-unlisted="">
197
+ {unlisted.map((r) => r.label).join(", ")} {unlisted.length === 1 ? "has" : "have"} the
198
+ field but {unlisted.length === 1 ? "isn't" : "aren't"} listed yet: layouts there aren't
199
+ checked on save or rendered until the site config lists{" "}
200
+ {unlisted.length === 1 ? "it" : "them"}.
201
+ </Banner>
202
+ )}
203
+ <div className="emvb-agents-snippet">
204
+ <div className="emvb-agents-snippet-head">
205
+ <h3>astro.config.mjs</h3>
206
+ <CopySnippet text={snippet} name="canvasCollections config" />
207
+ </div>
208
+ <pre data-emvb-snippet="canvas-collections" {...SCROLLABLE} aria-label="Site config">
209
+ {snippet}
210
+ </pre>
211
+ </div>
212
+ </section>
213
+ </>,
214
+ );
215
+ }
@@ -29,11 +29,11 @@ const FILTERS: { value: Filter; label: string }[] = [
29
29
  { value: "header", label: "Headers" },
30
30
  { value: "footer", label: "Footers" },
31
31
  { value: "error_404", label: "Error 404" },
32
- { value: "search_results", label: "Search Results" },
33
- { value: "single_page", label: "Single Page" },
34
- { value: "single_post", label: "Single Post" },
32
+ { value: "search_results", label: "Search results" },
33
+ { value: "single_page", label: "Single page" },
34
+ { value: "single_post", label: "Single post" },
35
35
  { value: "archive", label: "Archive" },
36
- { value: "loop_item", label: "Loop Item" },
36
+ { value: "loop_item", label: "Loop item" },
37
37
  { value: "section", label: "Sections" },
38
38
  { value: "page_template", label: "Page templates" },
39
39
  { value: "popup", label: "Popups" },
@@ -80,8 +80,10 @@ function FilterTabs({
80
80
  refs.current.get(next)?.focus();
81
81
  };
82
82
 
83
+ const rowRef = useEdgeHints<HTMLDivElement>();
83
84
  return (
84
85
  <div
86
+ ref={rowRef}
85
87
  className="emvb-theme-filters"
86
88
  role="tablist"
87
89
  aria-label="Filter by type"
@@ -239,3 +241,29 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
239
241
  </>
240
242
  );
241
243
  }
244
+
245
+ /**
246
+ * W-863: marks which edges of a scrolling row hide more tabs (data-more-start / data-more-end),
247
+ * so browsers without scroll-driven animations still get the UX-038 edge fade.
248
+ */
249
+ export function useEdgeHints<T extends HTMLElement>() {
250
+ const ref = React.useRef<T>(null);
251
+ React.useEffect(() => {
252
+ const node = ref.current;
253
+ if (!node) return;
254
+ const update = () => {
255
+ const max = node.scrollWidth - node.clientWidth;
256
+ node.toggleAttribute("data-more-start", max > 1 && node.scrollLeft > 1);
257
+ node.toggleAttribute("data-more-end", max > 1 && node.scrollLeft < max - 1);
258
+ };
259
+ update();
260
+ node.addEventListener("scroll", update, { passive: true });
261
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(update);
262
+ observer?.observe(node);
263
+ return () => {
264
+ node.removeEventListener("scroll", update);
265
+ observer?.disconnect();
266
+ };
267
+ }, []);
268
+ return ref;
269
+ }
@@ -0,0 +1,51 @@
1
+ import { PLUGIN_ID } from "../constants.ts";
2
+ import type { SavedSection, SavedSectionRecord, SavedSectionSummary } from "../core/index.ts";
3
+ import { requestJson, type Fetcher } from "./api.ts";
4
+
5
+ export type { SavedSectionSummary };
6
+
7
+ const BASE = `/_emdash/api/plugins/${PLUGIN_ID}/saved-sections`;
8
+
9
+ /** My sections, newest first (W-876). */
10
+ export async function listSavedSections(fetcher: Fetcher): Promise<SavedSectionSummary[]> {
11
+ const data = await requestJson<{ items?: SavedSectionSummary[] }>(fetcher, BASE);
12
+ return data?.items ?? [];
13
+ }
14
+
15
+ /** One section, read and upgraded by the server. */
16
+ export async function getSavedSection(fetcher: Fetcher, id: string): Promise<SavedSection> {
17
+ const data = await requestJson<{ section: SavedSection }>(fetcher, `${BASE}/get`, {
18
+ method: "POST",
19
+ body: { id },
20
+ });
21
+ return data.section;
22
+ }
23
+
24
+ /** Stores a snapshot; the server checks it again whatever the browser sent. */
25
+ export async function saveSavedSection(
26
+ fetcher: Fetcher,
27
+ record: SavedSectionRecord,
28
+ ): Promise<string> {
29
+ const data = await requestJson<{ id: string }>(fetcher, `${BASE}/save`, {
30
+ method: "POST",
31
+ body: { record },
32
+ });
33
+ return data.id;
34
+ }
35
+
36
+ export async function renameSavedSection(
37
+ fetcher: Fetcher,
38
+ id: string,
39
+ name: string,
40
+ ): Promise<SavedSectionSummary> {
41
+ const data = await requestJson<{ item: SavedSectionSummary }>(fetcher, `${BASE}/rename`, {
42
+ method: "POST",
43
+ body: { id, name },
44
+ });
45
+ return data.item;
46
+ }
47
+
48
+ /** Pages that already hold a copy keep it. */
49
+ export async function deleteSavedSection(fetcher: Fetcher, id: string): Promise<void> {
50
+ await requestJson(fetcher, `${BASE}/delete`, { method: "POST", body: { id } });
51
+ }
@@ -0,0 +1,100 @@
1
+ import { PLUGIN_ID } from "../../constants.ts";
2
+ import { canvasCollectionSlugs, canvasStyleUrls } from "../../core/index.ts";
3
+ import { requestJson, type Fetcher } from "../api.ts";
4
+ import { readCollection } from "./run.ts";
5
+
6
+ const CANVAS_WIDGET = `${PLUGIN_ID}:canvas`;
7
+ const BASE = "/_emdash/api/schema/collections";
8
+
9
+ /** The field setup adds (W-913): the same JSON field the demos' `pages` collection carries. */
10
+ export const CANVAS_FIELD_BODY = {
11
+ slug: "canvas",
12
+ label: "Canvas",
13
+ type: "json",
14
+ widget: CANVAS_WIDGET,
15
+ validation: null,
16
+ } as const;
17
+
18
+ export type HostCollectionRow = {
19
+ slug: string;
20
+ label: string;
21
+ /** ready: an emvb:canvas field exists; missing: setup can add one; taken: `canvas` is another field. */
22
+ field: "ready" | "missing" | "taken";
23
+ /** The field holding the layout when ready. */
24
+ fieldSlug?: string;
25
+ /** Listed in the running site's `canvasCollections` option. */
26
+ listed: boolean;
27
+ };
28
+
29
+ type CollectionSummary = { slug: string; label?: string; hidden?: boolean };
30
+ type FieldSummary = { slug: string; type: string; widget?: string | null };
31
+
32
+ /** One row per visible host collection; EmVB's own (hidden) collections are left out. */
33
+ export function hostCollectionRows(
34
+ collections: readonly (CollectionSummary & { fields: readonly FieldSummary[] })[],
35
+ configured: readonly string[],
36
+ ): HostCollectionRow[] {
37
+ return collections
38
+ .filter((c) => !c.hidden && canvasCollectionSlugs([c.slug]).length === 1)
39
+ .map((c) => {
40
+ const canvas = c.fields.find((f) => f.type === "json" && f.widget === CANVAS_WIDGET);
41
+ const taken = c.fields.some((f) => f.slug === CANVAS_FIELD_BODY.slug);
42
+ const row: HostCollectionRow = {
43
+ slug: c.slug,
44
+ label: c.label?.trim() || c.slug,
45
+ field: canvas ? "ready" : taken ? "taken" : "missing",
46
+ listed: configured.includes(c.slug),
47
+ };
48
+ if (canvas) row.fieldSlug = canvas.slug;
49
+ return row;
50
+ });
51
+ }
52
+
53
+ /**
54
+ * The `emvb()` call for astro.config with every collection that has the field. `canvasCollections`
55
+ * is read when the site starts, so setup can only show it; the current `canvasStyles` are kept.
56
+ */
57
+ export function canvasCollectionsSnippet(
58
+ rows: readonly HostCollectionRow[],
59
+ canvasStyles: readonly string[],
60
+ ): string {
61
+ const slugs = rows.filter((r) => r.field === "ready" || r.listed).map((r) => r.slug);
62
+ const options = [
63
+ ...(canvasStyles.length > 0 ? [`canvasStyles: ${JSON.stringify(canvasStyles)}`] : []),
64
+ `canvasCollections: ${JSON.stringify(slugs)}`,
65
+ ];
66
+ return `// astro.config.mjs, in emdash({ plugins: [...] })\nemvb({ ${options.join(", ")} })`;
67
+ }
68
+
69
+ export async function loadHostCollections(fetcher: Fetcher): Promise<{
70
+ rows: HostCollectionRow[];
71
+ canvasStyles: string[];
72
+ }> {
73
+ const [list, config] = await Promise.all([
74
+ requestJson<{ items: CollectionSummary[] }>(fetcher, BASE),
75
+ requestJson<{ canvasStyles?: unknown; canvasCollections?: unknown }>(
76
+ fetcher,
77
+ `/_emdash/api/plugins/${PLUGIN_ID}/editor/config`,
78
+ ).catch(() => ({}) as { canvasStyles?: unknown; canvasCollections?: unknown }),
79
+ ]);
80
+ const visible = list.items.filter((c) => !c.hidden);
81
+ const detailed = await Promise.all(
82
+ visible.map(async (c) => ({
83
+ slug: c.slug,
84
+ label: c.label,
85
+ fields: (await readCollection(fetcher, c.slug))?.fields ?? [],
86
+ })),
87
+ );
88
+ return {
89
+ rows: hostCollectionRows(detailed, canvasCollectionSlugs(config.canvasCollections)),
90
+ canvasStyles: canvasStyleUrls(config.canvasStyles),
91
+ };
92
+ }
93
+
94
+ /** Adds the canvas field through EmDash's schema API (schema:manage, admins). */
95
+ export async function addCanvasField(fetcher: Fetcher, collection: string): Promise<void> {
96
+ await requestJson(fetcher, `${BASE}/${encodeURIComponent(collection)}/fields`, {
97
+ method: "POST",
98
+ body: CANVAS_FIELD_BODY,
99
+ });
100
+ }
@@ -158,14 +158,15 @@ function starterPartLayout(title: string, partType: ThemePartType): Layout {
158
158
 
159
159
  export async function createThemePart(
160
160
  fetcher: Fetcher,
161
- input: { title: string; slug: string; partType: ThemePartType },
161
+ input: { title: string; slug: string; partType: ThemePartType; layout?: Layout },
162
162
  ): Promise<string> {
163
163
  const body = await requestJson<{ item: ContentItem }>(fetcher, CONTENT, {
164
164
  method: "POST",
165
165
  body: {
166
166
  data: {
167
167
  title: input.title,
168
- layout: starterPartLayout(input.title, input.partType),
168
+ // W-876: a synced section starts from the element it was made from.
169
+ layout: input.layout ?? starterPartLayout(input.title, input.partType),
169
170
  part_type: input.partType,
170
171
  conditions: defaultConditionsFor(input.partType),
171
172
  triggers: defaultTriggers(),
package/src/admin/ui.ts CHANGED
@@ -213,6 +213,15 @@ export const UI_CSS = `
213
213
  mask-image: linear-gradient(to right, transparent, #000 var(--emvb-fade-start), #000 calc(100% - var(--emvb-fade-end)), transparent);
214
214
  }
215
215
  }
216
+ /* W-863: without scroll timelines (Firefox, older Safari) the row's data-more-* hints fade it. */
217
+ @supports not (animation-timeline: scroll()) {
218
+ .emvb-theme-filters[data-more-start] { --emvb-fade-start: 32px; }
219
+ .emvb-theme-filters[data-more-end] { --emvb-fade-end: 32px; }
220
+ .emvb-theme-filters[data-more-start],
221
+ .emvb-theme-filters[data-more-end] {
222
+ mask-image: linear-gradient(to right, transparent, #000 var(--emvb-fade-start), #000 calc(100% - var(--emvb-fade-end)), transparent);
223
+ }
224
+ }
216
225
 
217
226
  /* EmVB-owned dialog body (Kumo Dialog keeps host radius/shadow) */
218
227
  .emvb-dialog { display: flex; flex-direction: column; gap: 10px; }