@perkyzz/emvb 0.1.0 → 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.
Files changed (153) hide show
  1. package/README.md +4 -2
  2. package/THIRD_PARTY_NOTICES.md +32 -0
  3. package/licenses/fontawesome-free.LICENSE +165 -0
  4. package/licenses/lucide-static.LICENSE +43 -0
  5. package/licenses/remixicon.LICENSE +201 -0
  6. package/licenses/tabler-icons.LICENSE +21 -0
  7. package/package.json +8 -4
  8. package/src/admin/api.ts +27 -0
  9. package/src/admin/content-api.ts +72 -9
  10. package/src/admin/editor/Editor.tsx +89 -14
  11. package/src/admin/editor/EditorOverlay.tsx +12 -0
  12. package/src/admin/editor/SmallScreenNotice.tsx +4 -3
  13. package/src/admin/editor/TopBar.tsx +76 -12
  14. package/src/admin/editor/canvas/CanvasFrame.tsx +224 -43
  15. package/src/admin/editor/canvas/DeviceBar.tsx +43 -2
  16. package/src/admin/editor/canvas/SelectionOverlay.tsx +60 -6
  17. package/src/admin/editor/canvas/canvas-events.ts +20 -7
  18. package/src/admin/editor/canvas/tab-reveal.ts +66 -0
  19. package/src/admin/editor/canvas/vnode-react.tsx +21 -1
  20. package/src/admin/editor/dialogs.tsx +39 -0
  21. package/src/admin/editor/dnd/drop-target.ts +63 -16
  22. package/src/admin/editor/dnd/new-element.ts +76 -1
  23. package/src/admin/editor/editor-css.ts +101 -15
  24. package/src/admin/editor/host.ts +30 -0
  25. package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
  26. package/src/admin/editor/icons/library.ts +243 -0
  27. package/src/admin/editor/icons/set-format.ts +29 -0
  28. package/src/admin/editor/icons/sets/fontawesome.json +1 -0
  29. package/src/admin/editor/icons/sets/lucide.json +1 -0
  30. package/src/admin/editor/icons/sets/remix.json +1 -0
  31. package/src/admin/editor/icons/sets/tabler.json +1 -0
  32. package/src/admin/editor/panels/AddPanel.tsx +7 -3
  33. package/src/admin/editor/panels/ClassesSection.tsx +44 -6
  34. package/src/admin/editor/panels/ColorControl.tsx +268 -21
  35. package/src/admin/editor/panels/ElementPanel.tsx +237 -93
  36. package/src/admin/editor/panels/LayersPanel.tsx +303 -66
  37. package/src/admin/editor/panels/LeftPanel.tsx +4 -0
  38. package/src/admin/editor/panels/PageSettings.tsx +134 -5
  39. package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
  40. package/src/admin/editor/panels/SiteStylesDrawer.tsx +158 -2
  41. package/src/admin/editor/panels/TriggersEditor.tsx +19 -2
  42. package/src/admin/editor/panels/VariableSection.tsx +47 -9
  43. package/src/admin/editor/panels/color-space.ts +195 -0
  44. package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
  45. package/src/admin/editor/panels/settings/BackgroundControls.tsx +153 -55
  46. package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
  47. package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
  48. package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
  49. package/src/admin/editor/panels/settings/ClassChipInput.tsx +104 -2
  50. package/src/admin/editor/panels/settings/DraftTextField.tsx +44 -3
  51. package/src/admin/editor/panels/settings/EffectsControls.tsx +23 -16
  52. package/src/admin/editor/panels/settings/FieldBindControl.tsx +53 -17
  53. package/src/admin/editor/panels/settings/FieldControl.tsx +129 -9
  54. package/src/admin/editor/panels/settings/FormBindControl.tsx +14 -5
  55. package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
  56. package/src/admin/editor/panels/settings/IconPicker.tsx +133 -72
  57. package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
  58. package/src/admin/editor/panels/settings/LengthRow.tsx +97 -61
  59. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +10 -4
  60. package/src/admin/editor/panels/settings/MediaPicker.tsx +4 -2
  61. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  62. package/src/admin/editor/panels/settings/StyleRow.tsx +158 -75
  63. package/src/admin/editor/panels/settings/VariableBinding.tsx +5 -1
  64. package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
  65. package/src/admin/editor/panels/settings/background-mode.ts +112 -0
  66. package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
  67. package/src/admin/editor/panels/settings/box-sides.ts +153 -0
  68. package/src/admin/editor/panels/settings/button-url.ts +27 -0
  69. package/src/admin/editor/panels/settings/class-suggest.ts +5 -3
  70. package/src/admin/editor/panels/settings/form-names.ts +38 -0
  71. package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
  72. package/src/admin/editor/panels/settings/image-alt.ts +25 -0
  73. package/src/admin/editor/panels/settings/length-units.ts +40 -7
  74. package/src/admin/editor/panels/settings/loop-context.ts +26 -0
  75. package/src/admin/editor/panels/settings/style-sections.ts +114 -11
  76. package/src/admin/editor/panels/settings/svg-images.ts +14 -0
  77. package/src/admin/editor/panels/site-list.tsx +3 -0
  78. package/src/admin/editor/restore-deleted.ts +80 -0
  79. package/src/admin/editor/shortcuts.ts +1 -1
  80. package/src/admin/editor/store.ts +35 -7
  81. package/src/admin/editor/useEditorCommands.ts +66 -5
  82. package/src/admin/editor/useEditorData.ts +29 -3
  83. package/src/admin/editor/useEditorShortcuts.ts +34 -2
  84. package/src/admin/editor/useNodeActions.ts +68 -6
  85. package/src/admin/editor/useSave.ts +60 -3
  86. package/src/admin/entry-status.ts +19 -0
  87. package/src/admin/icon-uploads-api.ts +44 -0
  88. package/src/admin/pages/PageList.tsx +22 -2
  89. package/src/admin/pages/ThemePartList.tsx +23 -4
  90. package/src/admin/pages/list-kit.tsx +52 -2
  91. package/src/admin/setup/spec.ts +7 -0
  92. package/src/admin/theme-api.ts +61 -14
  93. package/src/admin/ui.ts +17 -4
  94. package/src/astro/EmVBPage.astro +28 -2
  95. package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
  96. package/src/astro/floats/index.ts +1 -0
  97. package/src/astro/floats/runtime.ts +78 -0
  98. package/src/astro/forms-definitions.ts +22 -0
  99. package/src/astro/index.ts +1 -0
  100. package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
  101. package/src/astro/menu/index.ts +1 -0
  102. package/src/astro/menu/runtime.ts +37 -0
  103. package/src/astro/popups/runtime.ts +54 -4
  104. package/src/astro/render.ts +47 -13
  105. package/src/astro/resolve-theme.ts +164 -20
  106. package/src/astro/tabs/runtime.ts +6 -1
  107. package/src/astro/theme-context.ts +11 -3
  108. package/src/constants.ts +1 -1
  109. package/src/core/arrange.ts +98 -10
  110. package/src/core/clipboard.ts +91 -9
  111. package/src/core/css/generate.ts +21 -4
  112. package/src/core/design/classes.ts +95 -9
  113. package/src/core/design/transfer.ts +101 -2
  114. package/src/core/design/variables.ts +51 -11
  115. package/src/core/elements/dynamic-elements.ts +57 -5
  116. package/src/core/elements/field-id.ts +6 -0
  117. package/src/core/elements/form-elements.ts +23 -8
  118. package/src/core/elements/index.ts +267 -49
  119. package/src/core/elements/menu.ts +190 -0
  120. package/src/core/forms/definition.ts +11 -0
  121. package/src/core/index.ts +67 -3
  122. package/src/core/limits.ts +2 -0
  123. package/src/core/migrate/index.ts +51 -1
  124. package/src/core/nesting.ts +51 -0
  125. package/src/core/render/context.ts +7 -0
  126. package/src/core/render/dynamic-post.ts +39 -11
  127. package/src/core/render/extras.ts +22 -3
  128. package/src/core/render/form.ts +134 -36
  129. package/src/core/render/index.ts +123 -25
  130. package/src/core/render/loop.ts +10 -3
  131. package/src/core/render/pagination.ts +76 -0
  132. package/src/core/render/section.ts +5 -1
  133. package/src/core/render/tabs.ts +8 -4
  134. package/src/core/render/vnode.ts +1 -1
  135. package/src/core/sanitize/css.ts +197 -17
  136. package/src/core/sanitize/embed-url.ts +64 -7
  137. package/src/core/sanitize/svg-upload.ts +203 -0
  138. package/src/core/sanitize/svg.ts +102 -21
  139. package/src/core/schema/descriptors.ts +4 -0
  140. package/src/core/schema/design.ts +7 -2
  141. package/src/core/schema/layout.ts +210 -19
  142. package/src/core/schema/style.ts +87 -8
  143. package/src/core/tabs/presence.ts +9 -0
  144. package/src/core/theme/conditions.ts +4 -1
  145. package/src/core/theme/dynamic.ts +10 -0
  146. package/src/core/theme/float.ts +113 -0
  147. package/src/core/theme/pagination.ts +97 -0
  148. package/src/core/theme/part-types.ts +2 -0
  149. package/src/core/theme/popup-markup.ts +3 -1
  150. package/src/core/theme/popup-rules.ts +4 -3
  151. package/src/server/hooks.ts +20 -0
  152. package/src/server/icon-routes.ts +79 -0
  153. package/src/server/plugin.ts +5 -1
@@ -43,6 +43,18 @@ export function saveFailure(
43
43
  page: { slug: string; layout: Layout | null },
44
44
  ): SaveFailure {
45
45
  if (!(error instanceof ApiError) || error.status >= 500) return { status: offline };
46
+ if (error.status === 401) {
47
+ // W-205: the session ran out. The edits stay here; signing in again in another tab and
48
+ // retrying saves them.
49
+ const message = "Couldn't save. You're signed out: sign in again in another tab, then Retry.";
50
+ return { status: { kind: "error", message, retry: true } };
51
+ }
52
+ if (error.status === 404) {
53
+ // W-206: deleted (moved to Trash) while open. Restoring it keeps these edits savable.
54
+ const message =
55
+ "Couldn't save. This was moved to Trash or deleted: restore it from the Trash, then Retry.";
56
+ return { status: { kind: "error", message, retry: true } };
57
+ }
46
58
  if (error.status === 409 && error.code === "SLUG_CONFLICT") {
47
59
  return { status: fixAndSave, slugError: slugTakenMessage(page.slug), select: null };
48
60
  }
@@ -59,6 +71,13 @@ export function saveFailure(
59
71
  }
60
72
 
61
73
  export function publishFailureMessage(error: unknown): string {
74
+ if (error instanceof ApiError && error.status === 401) {
75
+ return "Couldn't publish. You're signed out: sign in again in another tab, then publish.";
76
+ }
77
+ // W-298: a 404 means the page is gone (moved to Trash while open), not a dropped connection.
78
+ if (error instanceof ApiError && error.status === 404) {
79
+ return "Couldn't publish. This was moved to Trash or deleted: restore it from the Trash, then publish.";
80
+ }
62
81
  if (error instanceof ApiError && error.status === 403) {
63
82
  return "Couldn't publish. Your role can't publish pages.";
64
83
  }
@@ -115,6 +134,11 @@ export function useSave(
115
134
  open: [{ type: "page_load" }],
116
135
  advanced: {},
117
136
  },
137
+ float: current.page.float ?? {
138
+ schemaVersion: 1,
139
+ edge: "top",
140
+ dismiss: false,
141
+ },
118
142
  layout: current.page.layout,
119
143
  },
120
144
  rev,
@@ -136,7 +160,33 @@ export function useSave(
136
160
  [fetcher, dispatch, collection],
137
161
  );
138
162
 
139
- const save = React.useCallback(() => write(latest.current.rev), [write]);
163
+ // W-199: one save at a time. A save asked for while one is in flight (Ctrl+S, autosave) runs once
164
+ // after it, with the revision that save returned, instead of racing it with a stale `_rev`
165
+ // and reporting a conflict with itself.
166
+ const inFlight = React.useRef<Promise<string | null> | null>(null);
167
+ const queued = React.useRef<Promise<string | null> | null>(null);
168
+ const start = React.useCallback(
169
+ (rev: string | null): Promise<string | null> => {
170
+ const run = write(rev).finally(() => {
171
+ if (inFlight.current === run) inFlight.current = null;
172
+ });
173
+ inFlight.current = run;
174
+ return run;
175
+ },
176
+ [write],
177
+ );
178
+ const save = React.useCallback((): Promise<string | null> => {
179
+ if (queued.current) return queued.current;
180
+ const pending = inFlight.current;
181
+ if (!pending) return start(latest.current.rev);
182
+ // The state may not have re-rendered yet, so take the new revision from the save itself.
183
+ const after = pending.then((rev) => {
184
+ queued.current = null;
185
+ return start(rev ?? latest.current.rev);
186
+ });
187
+ queued.current = after;
188
+ return after;
189
+ }, [start]);
140
190
 
141
191
  /** Conflict → Overwrite: take the stored revision and save over it. */
142
192
  const overwrite = React.useCallback(async () => {
@@ -151,8 +201,15 @@ export function useSave(
151
201
 
152
202
  const publish = React.useCallback(async (): Promise<boolean> => {
153
203
  let rev: string | null = latest.current.rev;
204
+ const pending = queued.current ?? inFlight.current;
205
+ if (pending) {
206
+ // W-199: publish the revision the running save makes, never race it.
207
+ const saved = await pending;
208
+ if (!saved) return false;
209
+ rev = saved;
210
+ }
154
211
  if (latest.current.version !== latest.current.savedVersion) {
155
- rev = await write(rev);
212
+ rev = await start(rev);
156
213
  if (!rev) return false;
157
214
  }
158
215
  try {
@@ -168,7 +225,7 @@ export function useSave(
168
225
  setStatus({ kind: "error", message: publishFailureMessage(error), retry: false });
169
226
  return false;
170
227
  }
171
- }, [fetcher, dispatch, write, collection]);
228
+ }, [fetcher, dispatch, start, collection]);
172
229
 
173
230
  return {
174
231
  status,
@@ -0,0 +1,19 @@
1
+ /**
2
+ * An entry's publish state as the editor and lists show it. A published entry with a saved draft
3
+ * on top (`draftRevisionId`) is "changed": its page still shows the last published version
4
+ * (W-190).
5
+ */
6
+ export function entryStatus(
7
+ item: { status?: string; draftRevisionId?: string | null } | undefined,
8
+ ) {
9
+ const status = item?.status ?? "draft";
10
+ return status === "published" && item?.draftRevisionId ? "changed" : status;
11
+ }
12
+
13
+ export function statusLabel(status: string): string {
14
+ if (status === "published") return "Published";
15
+ if (status === "changed") return "Changes not published";
16
+ // W-201: EmDash's scheduled publish; the page isn't live until its time.
17
+ if (status === "scheduled") return "Scheduled";
18
+ return "Draft";
19
+ }
@@ -0,0 +1,44 @@
1
+ import { PLUGIN_ID } from "../constants.ts";
2
+ import { prepareUploadedSvg, UPLOAD_SVG_MAX_BYTES, type UploadedIconItem } from "../core/index.ts";
3
+ import { requestJson, type Fetcher } from "./api.ts";
4
+
5
+ export type { UploadedIconItem };
6
+
7
+ const BASE = `/_emdash/api/plugins/${PLUGIN_ID}`;
8
+
9
+ /** EmVB's uploaded SVG icons, newest first (W-239). */
10
+ export async function listUploadedIcons(fetcher: Fetcher): Promise<UploadedIconItem[]> {
11
+ const data = await requestJson<{ items?: UploadedIconItem[] }>(fetcher, `${BASE}/icons`);
12
+ return data?.items ?? [];
13
+ }
14
+
15
+ /** A new upload, or the id of an upload that already has this SVG (W-243). */
16
+ type IconUpload = { item: UploadedIconItem; imagesLeftOut: number } | { existingId: string };
17
+
18
+ /**
19
+ * Uploads an .svg file. It is checked here first, so a refused file says why at once; the server
20
+ * sanitizes it again whatever the browser sent. `existing` names an upload that already has the
21
+ * cleaned SVG; then nothing is sent, so picking the same file twice doesn't store it twice.
22
+ */
23
+ export async function uploadIconFile(
24
+ fetcher: Fetcher,
25
+ file: File,
26
+ existing?: (svg: string) => string | undefined,
27
+ ): Promise<IconUpload> {
28
+ if (!/\.svg$/i.test(file.name) && file.type !== "image/svg+xml")
29
+ throw new Error("Choose an .svg file.");
30
+ if (file.size > UPLOAD_SVG_MAX_BYTES)
31
+ throw new Error(
32
+ `This file is ${Math.ceil(file.size / 1024)} KB. Upload an SVG up to ${UPLOAD_SVG_MAX_BYTES / 1024} KB.`,
33
+ );
34
+ const svg = await file.text();
35
+ const local = prepareUploadedSvg(svg);
36
+ if (!local.ok) throw new Error(local.message);
37
+ const existingId = existing?.(local.svg);
38
+ if (existingId) return { existingId };
39
+ return requestJson<{ item: UploadedIconItem; imagesLeftOut: number }>(
40
+ fetcher,
41
+ `${BASE}/icons/upload`,
42
+ { method: "POST", body: { name: file.name, svg } },
43
+ );
44
+ }
@@ -4,13 +4,27 @@ import * as React from "react";
4
4
  import type { Fetcher } from "../api.ts";
5
5
  import { listPages } from "../content-api.ts";
6
6
  import { editorUrl } from "../editor/exit.ts";
7
- import { EditedTime, ListError, NewButton, StatusBadge, useList } from "./list-kit.tsx";
7
+ import {
8
+ EditedTime,
9
+ ListError,
10
+ ListSearch,
11
+ matchesSearch,
12
+ NewButton,
13
+ NoMatches,
14
+ StatusBadge,
15
+ useList,
16
+ } from "./list-kit.tsx";
8
17
  import { NewPageDialog } from "./NewPageDialog.tsx";
9
18
 
10
19
  /** The Visual pages list (IA): title and slug, status, last edited; New page. */
11
20
  export function PageList({ fetcher }: { fetcher: Fetcher }) {
12
21
  const list = useList(fetcher, listPages);
13
22
  const [creating, setCreating] = React.useState(false);
23
+ const [query, setQuery] = React.useState("");
24
+ const shown =
25
+ list.state === "ready"
26
+ ? list.items.filter((page) => matchesSearch(query, page.title, `/${page.slug}`))
27
+ : [];
14
28
 
15
29
  const newPage = <NewButton label="New page" onClick={() => setCreating(true)} />;
16
30
 
@@ -35,6 +49,12 @@ export function PageList({ fetcher }: { fetcher: Fetcher }) {
35
49
  </div>
36
50
  )}
37
51
  {list.state === "ready" && list.items.length > 0 && (
52
+ <ListSearch value={query} onChange={setQuery} label="Search pages" />
53
+ )}
54
+ {list.state === "ready" && list.items.length > 0 && shown.length === 0 && (
55
+ <NoMatches query={query} />
56
+ )}
57
+ {list.state === "ready" && shown.length > 0 && (
38
58
  <div className="emvb-surface-card" data-emvb-list="pages">
39
59
  <Table data-emvb-list="pages">
40
60
  <Table.Header>
@@ -45,7 +65,7 @@ export function PageList({ fetcher }: { fetcher: Fetcher }) {
45
65
  </Table.Row>
46
66
  </Table.Header>
47
67
  <Table.Body>
48
- {list.items.map((page) => (
68
+ {shown.map((page) => (
49
69
  <Table.Row key={page.id} data-emvb-row={page.id}>
50
70
  <Table.Cell>
51
71
  <a className="emvb-row-title" href={editorUrl(page.id)}>
@@ -6,7 +6,16 @@ import { THEME_PARTS_COLLECTION } from "../../constants.ts";
6
6
  import type { Fetcher } from "../api.ts";
7
7
  import { listThemeParts, partTypeLabel } from "../theme-api.ts";
8
8
  import { editorUrl } from "../editor/exit.ts";
9
- import { EditedTime, ListError, NewButton, StatusBadge, useList } from "./list-kit.tsx";
9
+ import {
10
+ EditedTime,
11
+ ListError,
12
+ ListSearch,
13
+ matchesSearch,
14
+ NewButton,
15
+ NoMatches,
16
+ StatusBadge,
17
+ useList,
18
+ } from "./list-kit.tsx";
10
19
  import { NewThemePartDialog } from "./NewThemePartDialog.tsx";
11
20
 
12
21
  type Filter = "all" | ThemePartType;
@@ -27,6 +36,7 @@ const FILTERS: { value: Filter; label: string }[] = [
27
36
  { value: "section", label: "Sections" },
28
37
  { value: "page_template", label: "Page templates" },
29
38
  { value: "popup", label: "Popups" },
39
+ { value: "float", label: "Floats" },
30
40
  ];
31
41
 
32
42
  function countByType(items: readonly { partType: ThemePartType }[]): Map<Filter, number> {
@@ -108,6 +118,7 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
108
118
  const list = useList(fetcher, listThemeParts);
109
119
  const [creating, setCreating] = React.useState(false);
110
120
  const [filter, setFilter] = React.useState<Filter>("all");
121
+ const [query, setQuery] = React.useState("");
111
122
 
112
123
  const newPart = <NewButton label="New theme part" onClick={() => setCreating(true)} />;
113
124
 
@@ -117,6 +128,9 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
117
128
  ? list.items
118
129
  : list.items.filter((p) => p.partType === filter)
119
130
  : [];
131
+ const shown = visible.filter((p) =>
132
+ matchesSearch(query, p.title, partTypeLabel(p.partType), p.conditionsSummary),
133
+ );
120
134
 
121
135
  const emptyFilterLabel =
122
136
  filter === "all" ? "theme parts" : FILTERS.find((f) => f.value === filter)?.label.toLowerCase();
@@ -128,7 +142,10 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
128
142
  {list.state === "ready" && list.items.length > 0 && newPart}
129
143
  </div>
130
144
  {list.state === "ready" && list.items.length > 0 && (
131
- <FilterTabs filter={filter} counts={countByType(list.items)} onChange={setFilter} />
145
+ <>
146
+ <FilterTabs filter={filter} counts={countByType(list.items)} onChange={setFilter} />
147
+ <ListSearch value={query} onChange={setQuery} label="Search theme parts" />
148
+ </>
132
149
  )}
133
150
  {list.state === "loading" && <Loader />}
134
151
  {list.state === "error" && (
@@ -139,7 +156,7 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
139
156
  <Empty
140
157
  icon={<SquaresFourIcon size={32} aria-hidden="true" />}
141
158
  title="No site parts yet"
142
- description="Create a Header, Footer, content template, or Popup."
159
+ description="Create a Header, Footer, content template, Popup, or Float."
143
160
  contents={newPart}
144
161
  />
145
162
  </div>
@@ -155,6 +172,8 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
155
172
  contents={newPart}
156
173
  />
157
174
  </div>
175
+ ) : shown.length === 0 ? (
176
+ <NoMatches query={query} />
158
177
  ) : (
159
178
  <div className="emvb-surface-card" data-emvb-list="theme-parts">
160
179
  <Table data-emvb-list="theme-parts">
@@ -168,7 +187,7 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
168
187
  </Table.Row>
169
188
  </Table.Header>
170
189
  <Table.Body>
171
- {visible.map((part) => (
190
+ {shown.map((part) => (
172
191
  <Table.Row key={part.id} data-emvb-row={part.id}>
173
192
  <Table.Cell>
174
193
  <a
@@ -1,8 +1,9 @@
1
- import { Banner, Button } from "@cloudflare/kumo";
1
+ import { Banner, Button, Input } from "@cloudflare/kumo";
2
2
  import { PlusIcon, WarningCircleIcon } from "@phosphor-icons/react";
3
3
  import * as React from "react";
4
4
  import type { Fetcher } from "../api.ts";
5
5
  import { BUTTON, SOLID_PRIMARY } from "../ui.ts";
6
+ import { statusLabel } from "../entry-status.ts";
6
7
 
7
8
  type ListState<T> =
8
9
  | { state: "loading" }
@@ -59,7 +60,7 @@ export function StatusBadge({ status }: { status: string }) {
59
60
  return (
60
61
  <span className="emvb-status" data-status={status}>
61
62
  <span className="emvb-status-dot" aria-hidden="true" />
62
- {status === "published" ? "Published" : "Draft"}
63
+ {statusLabel(status)}
63
64
  </span>
64
65
  );
65
66
  }
@@ -73,3 +74,52 @@ export function EditedTime({ iso }: { iso: string }) {
73
74
  </time>
74
75
  );
75
76
  }
77
+
78
+ export const fold = (text: string) =>
79
+ text.normalize("NFD").replace(/\p{M}/gu, "").toLocaleLowerCase();
80
+
81
+ /**
82
+ * W-207: does an entry match the list search? Every word must appear in one of the fields,
83
+ * ignoring case and accents, so "about us" finds "About Us" and "/about-us".
84
+ */
85
+ export function matchesSearch(query: string, ...fields: string[]): boolean {
86
+ const haystack = fold(fields.join(" "));
87
+ return fold(query)
88
+ .split(/\s+/)
89
+ .filter(Boolean)
90
+ .every((word) => haystack.includes(word));
91
+ }
92
+
93
+ /** The search box above a list (W-207). */
94
+ export function ListSearch({
95
+ value,
96
+ onChange,
97
+ label,
98
+ }: {
99
+ value: string;
100
+ onChange: (value: string) => void;
101
+ label: string;
102
+ }) {
103
+ return (
104
+ <div className="emvb-list-search">
105
+ <Input
106
+ type="search"
107
+ id="emvb-list-search"
108
+ aria-label={label}
109
+ placeholder={label}
110
+ value={value}
111
+ maxLength={200}
112
+ onChange={(event) => onChange(event.target.value)}
113
+ />
114
+ </div>
115
+ );
116
+ }
117
+
118
+ /** Shown when a search finds nothing (W-207). */
119
+ export function NoMatches({ query }: { query: string }) {
120
+ return (
121
+ <p className="emvb-helper" role="status" data-emvb-no-matches>
122
+ Nothing matches "{query.trim()}".
123
+ </p>
124
+ );
125
+ }
@@ -97,4 +97,11 @@ export const THEME_PARTS_FIELD_SPECS: readonly FieldSpec[] = [
97
97
  validation: null,
98
98
  defaultValue: DEFAULT_THEME_TRIGGERS,
99
99
  },
100
+ {
101
+ slug: "float",
102
+ label: "Float",
103
+ type: "json",
104
+ validation: null,
105
+ defaultValue: { schemaVersion: 1, edge: "top", dismiss: false },
106
+ },
100
107
  ];
@@ -1,18 +1,22 @@
1
1
  import {
2
+ CONTENT_THEME_PART_TYPES,
2
3
  defaultConditionsFor,
4
+ defaultFloatSettings,
3
5
  defaultTriggers,
4
6
  parseThemePartType,
5
7
  starterLayout,
6
8
  THEME_PART_TYPE_LABELS,
7
9
  validateLayout,
8
10
  type ConditionsDoc,
11
+ type FloatSettings,
9
12
  type Layout,
10
13
  type ThemePartType,
11
14
  type TriggersDoc,
12
15
  } from "../core/index.ts";
13
16
  import { THEME_PARTS_COLLECTION } from "../constants.ts";
14
- import { requestJson, type Fetcher } from "./api.ts";
17
+ import { listAllItems, requestJson, type Fetcher } from "./api.ts";
15
18
  import { publishEntry } from "./content-api.ts";
19
+ import { entryStatus } from "./entry-status.ts";
16
20
 
17
21
  const CONTENT = `/_emdash/api/content/${THEME_PARTS_COLLECTION}`;
18
22
 
@@ -20,6 +24,7 @@ type RawItem = {
20
24
  id: string;
21
25
  slug?: string | null;
22
26
  status?: string;
27
+ draftRevisionId?: string | null;
23
28
  updatedAt?: string;
24
29
  data?: Record<string, unknown>;
25
30
  };
@@ -39,6 +44,7 @@ export type ThemePartDraft = {
39
44
  partType: ThemePartType;
40
45
  conditions: ConditionsDoc;
41
46
  triggers: TriggersDoc;
47
+ float: FloatSettings;
42
48
  layout: Layout | null;
43
49
  };
44
50
 
@@ -59,18 +65,43 @@ type RuleArgs = Record<string, unknown> | undefined;
59
65
 
60
66
  const arg = (args: RuleArgs, key: string) => String(args?.[key] ?? "?");
61
67
 
68
+ /**
69
+ * The names the conditions editor uses for EmDash's built-in collections and taxonomies, so the
70
+ * list reads "Visual pages", not "emvb_pages" (W-294). Others show their slug.
71
+ */
72
+ const COLLECTION_NAMES: Record<string, string> = {
73
+ pages: "Pages",
74
+ posts: "Posts",
75
+ emvb_pages: "Visual pages",
76
+ };
77
+ const TAXONOMY_NAMES: Record<string, { one: string; all: string }> = {
78
+ category: { one: "Category", all: "All categories" },
79
+ tag: { one: "Tag", all: "All tags" },
80
+ };
81
+
82
+ const collectionName = (args: RuleArgs) => {
83
+ const slug = arg(args, "collection");
84
+ return Object.hasOwn(COLLECTION_NAMES, slug) ? (COLLECTION_NAMES[slug] as string) : slug;
85
+ };
86
+
87
+ function taxonomyLabel(args: RuleArgs): string {
88
+ const slug = arg(args, "taxonomy");
89
+ const names = Object.hasOwn(TAXONOMY_NAMES, slug) ? TAXONOMY_NAMES[slug] : undefined;
90
+ if (args?.["slug"]) return `${names?.one ?? slug}: ${String(args["slug"])}`;
91
+ return names?.all ?? `All ${slug}`;
92
+ }
93
+
62
94
  /** Short labels for the Theme Builder list, keyed by `group/name`. */
63
95
  const RULE_LABELS: Record<string, (args: RuleArgs) => string> = {
64
96
  "general/entire_site": () => "Entire site",
65
97
  "singular/front": () => "Front page",
66
- "singular/not_found": () => "404",
67
- "singular/collection": (args) => `Singular: ${arg(args, "collection")}`,
68
- "singular/entry": (args) => `Entry in ${arg(args, "collection")}`,
98
+ "singular/not_found": () => "404 page",
99
+ "singular/collection": (args) => `${collectionName(args)} (all)`,
100
+ "singular/entry": (args) => `One entry in ${collectionName(args)}`,
69
101
  "singular/all": () => "All singular",
70
- "archive/collection": (args) => `Archive: ${arg(args, "collection")}`,
102
+ "archive/collection": (args) => `${collectionName(args)} archive`,
71
103
  "archive/search": () => "Search results",
72
- "archive/taxonomy": (args) =>
73
- args?.["slug"] ? `${arg(args, "taxonomy")}:${args["slug"]}` : `All ${arg(args, "taxonomy")}`,
104
+ "archive/taxonomy": taxonomyLabel,
74
105
  "archive/all": () => "All archives",
75
106
  };
76
107
 
@@ -101,20 +132,34 @@ export function summarizeConditions(raw: unknown): string {
101
132
  }
102
133
 
103
134
  export async function listThemeParts(fetcher: Fetcher): Promise<ThemePartSummary[]> {
104
- const body = await requestJson<{ items?: RawItem[] }>(
105
- fetcher,
106
- `${CONTENT}?limit=50&orderBy=updatedAt&order=desc`,
107
- );
108
- return (body?.items ?? []).map((item) => ({
135
+ const items = await listAllItems<RawItem>(fetcher, CONTENT);
136
+ return items.map((item) => ({
109
137
  id: item.id,
110
138
  title: titleOf(item),
111
139
  partType: partTypeOf(item),
112
- status: item.status ?? "draft",
140
+ status: entryStatus(item),
113
141
  updatedAt: item.updatedAt ?? "",
114
142
  conditionsSummary: summarizeConditions(item.data?.["conditions"]),
115
143
  }));
116
144
  }
117
145
 
146
+ /** Parts that are the page's main content (or become a page) keep the page's H1. */
147
+ const OWNS_PAGE_HEADING: ReadonlySet<ThemePartType> = new Set([
148
+ ...CONTENT_THEME_PART_TYPES,
149
+ "page_template",
150
+ ]);
151
+
152
+ /**
153
+ * A float, header, footer, popup, section or loop item shows on pages that have their own H1, so
154
+ * its starter heading is an H2: no second H1 and no skipped level (W-179).
155
+ */
156
+ function starterPartLayout(title: string, partType: ThemePartType): Layout {
157
+ const layout = starterLayout(title);
158
+ if (OWNS_PAGE_HEADING.has(partType)) return layout;
159
+ for (const child of layout.root.children) if (child.type === "heading") child.props.level = 2;
160
+ return layout;
161
+ }
162
+
118
163
  export async function createThemePart(
119
164
  fetcher: Fetcher,
120
165
  input: { title: string; slug: string; partType: ThemePartType },
@@ -124,10 +169,11 @@ export async function createThemePart(
124
169
  body: {
125
170
  data: {
126
171
  title: input.title,
127
- layout: starterLayout(input.title),
172
+ layout: starterPartLayout(input.title, input.partType),
128
173
  part_type: input.partType,
129
174
  conditions: defaultConditionsFor(input.partType),
130
175
  triggers: defaultTriggers(),
176
+ float: defaultFloatSettings(),
131
177
  },
132
178
  slug: input.slug,
133
179
  },
@@ -153,6 +199,7 @@ export async function saveThemePart(
153
199
  part_type: draft.partType,
154
200
  conditions: draft.conditions,
155
201
  triggers: draft.triggers,
202
+ float: draft.float,
156
203
  },
157
204
  slug: draft.slug,
158
205
  ...(rev ? { _rev: rev } : {}),
package/src/admin/ui.ts CHANGED
@@ -9,19 +9,19 @@ const solid = (color: string) =>
9
9
 
10
10
  /**
11
11
  * Kumo paints emphasis buttons with a light gradient that leaves white text below AA. EmVB
12
- * flattens it to the solid fill (DESIGN.md, contrast override). Kumo lets `style` win.
12
+ * flattens it to the solid fill (contrast override). Kumo lets `style` win.
13
13
  */
14
14
  export const SOLID_PRIMARY = solid("var(--color-kumo-brand)");
15
15
  export const SOLID_DESTRUCTIVE = solid("var(--text-color-kumo-danger)");
16
16
 
17
- /** EmVB's compact control size: 28 px and a 6 px radius (DESIGN.md). Doubled to beat utilities. */
17
+ /** EmVB's compact control size: 28 px and a 6 px radius. Doubled to beat utilities. */
18
18
  export const BUTTON = "emvb-btn";
19
19
  export const FIELD = "emvb-field";
20
20
 
21
21
  /**
22
22
  * Shared EmVB admin chrome (list pages, dialogs, setup states, conditions) plus compact
23
- * control sizing used inside the editor. Glass / elevation tokens match DESIGN.md and the
24
- * editor's mockup1 denser elevated look.
23
+ * control sizing used inside the editor. Glass / elevation tokens match the
24
+ * editor's denser elevated look.
25
25
  */
26
26
  export const UI_CSS = `
27
27
  [data-emvb-page],
@@ -46,6 +46,7 @@ export const UI_CSS = `
46
46
  }
47
47
  .emvb-mono { font-family: var(--font-mono); }
48
48
  .emvb-helper { margin: 0; font-size: 12px; line-height: 16px; color: var(--text-color-kumo-subtle); }
49
+ .emvb-helper a { color: var(--text-color-kumo-default); text-decoration: underline; text-underline-offset: 2px; }
49
50
  .emvb-inline-error { display: flex; gap: 4px; align-items: flex-start; margin: 0; font-size: 12px; line-height: 16px; color: var(--text-color-kumo-danger); }
50
51
  .emvb-status {
51
52
  display: inline-flex;
@@ -62,15 +63,20 @@ export const UI_CSS = `
62
63
  }
63
64
  .emvb-status-dot { width: 8px; height: 8px; border-radius: 9999px; background: var(--text-color-kumo-subtle); }
64
65
  .emvb-status[data-status="published"] .emvb-status-dot { background: var(--color-kumo-success); }
66
+ .emvb-status[data-status="changed"] .emvb-status-dot { background: var(--color-kumo-warning, #d97706); }
67
+ .emvb-status[data-status="scheduled"] .emvb-status-dot { background: var(--color-kumo-info, #2563eb); }
65
68
 
66
69
  /* List / setup pages */
67
70
  .emvb-pages { display: flex; flex-direction: column; gap: 16px; }
68
71
  .emvb-list-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
72
+ .emvb-list-search { max-width: 320px; margin: 12px 0; }
69
73
  .emvb-page-title { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 600; color: var(--text-color-kumo-default); }
70
74
  .emvb-row-title { color: var(--text-color-kumo-default); font-size: 14px; line-height: 20px; font-weight: 600; text-decoration: none; }
71
75
  .emvb-row-title:hover { text-decoration: underline; text-underline-offset: 2px; }
72
76
  .emvb-row-title:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 2px; border-radius: 4px; }
73
77
  .emvb-row-slug { font-family: var(--font-mono); font-size: 12px; line-height: 16px; color: var(--text-color-kumo-subtle); }
78
+ /* W-209: a long unbroken title or slug wraps instead of pushing Status and Last edited out of the card. */
79
+ .emvb-row-title, .emvb-row-slug { overflow-wrap: anywhere; }
74
80
  .emvb-tabular { font-variant-numeric: tabular-nums; color: var(--text-color-kumo-subtle); font-size: 13px; }
75
81
 
76
82
  /* Elevated EmVB-owned card chrome (lists, empty/setup shells) — not host sidebar/header */
@@ -165,6 +171,13 @@ export const UI_CSS = `
165
171
  }
166
172
  .emvb-trigger-head { display: flex; align-items: flex-end; gap: 4px; }
167
173
  .emvb-trigger-head > :first-child { flex: 1 1 auto; min-width: 0; }
174
+ /* Accordion items and Tabs panels as a list (W-130) */
175
+ .emvb-item-list { display: flex; flex-direction: column; gap: 8px; }
176
+ .emvb-item-row {
177
+ display: flex; flex-direction: column; gap: 4px; padding: 8px; border-radius: 6px;
178
+ background: var(--emvb-glass-elevated, var(--color-kumo-elevated)); box-shadow: var(--emvb-elevation-s);
179
+ }
180
+ .emvb-item-actions { display: flex; justify-content: flex-end; gap: 2px; }
168
181
  .emvb-device-fieldset { display: flex; flex-wrap: wrap; gap: 4px 16px; min-width: 0; margin: 0; padding: 0; border: 0; }
169
182
  .emvb-device-fieldset > legend { float: left; width: 100%; padding: 0; }
170
183
  .emvb-device-fieldset > .emvb-helper { width: 100%; margin: 0; }
@@ -1,25 +1,51 @@
1
1
  ---
2
2
  import type { RenderedPage } from "./render.ts";
3
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
+
4
13
  interface Props {
5
14
  page: RenderedPage;
6
15
  /** Blank canvas mode: a whole document, without the site's layout. The slot ends the body. */
7
16
  standalone?: boolean;
8
17
  title?: string;
9
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;
10
24
  }
11
25
 
12
- const { page, standalone = false, title = "", description } = Astro.props;
26
+ const { page, standalone = false, title = "", description, seo } = Astro.props;
27
+ const ogTitle = seo?.ogTitle || title;
28
+ const ogDescription = seo?.ogDescription ?? description;
13
29
  ---
14
30
 
15
31
  {
16
32
  standalone ? (
17
- <html lang="en">
33
+ <html lang="en" dir={page.dir}>
18
34
  <head>
19
35
  <meta charset="utf-8" />
20
36
  <meta name="viewport" content="width=device-width, initial-scale=1" />
21
37
  <title>{title}</title>
22
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
+ )}
23
49
  <style is:inline set:html={page.css} />
24
50
  </head>
25
51
  <body>
@@ -0,0 +1,9 @@
1
+ ---
2
+ // Optional float client. Hosts render this only when
3
+ // `resolveThemeParts().needsFloatsRuntime` so pages without a float stay zero EmVB JS.
4
+ ---
5
+
6
+ <script>
7
+ import { initFloats } from "./runtime.ts";
8
+ initFloats();
9
+ </script>
@@ -0,0 +1 @@
1
+ export { default as EmVBFloatsRuntime } from "./EmVBFloatsRuntime.astro";