@perkyzz/emvb 0.1.0 → 0.2.1

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 (154) hide show
  1. package/README.md +6 -4
  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 +9 -5
  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 +25 -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 +168 -24
  106. package/src/astro/tabs/runtime.ts +6 -1
  107. package/src/astro/theme-context.ts +25 -5
  108. package/src/astro/theme-posts.ts +19 -1
  109. package/src/constants.ts +1 -1
  110. package/src/core/arrange.ts +98 -10
  111. package/src/core/clipboard.ts +91 -9
  112. package/src/core/css/generate.ts +21 -4
  113. package/src/core/design/classes.ts +95 -9
  114. package/src/core/design/transfer.ts +101 -2
  115. package/src/core/design/variables.ts +51 -11
  116. package/src/core/elements/dynamic-elements.ts +57 -5
  117. package/src/core/elements/field-id.ts +6 -0
  118. package/src/core/elements/form-elements.ts +23 -8
  119. package/src/core/elements/index.ts +267 -49
  120. package/src/core/elements/menu.ts +190 -0
  121. package/src/core/forms/definition.ts +11 -0
  122. package/src/core/index.ts +67 -3
  123. package/src/core/limits.ts +2 -0
  124. package/src/core/migrate/index.ts +51 -1
  125. package/src/core/nesting.ts +51 -0
  126. package/src/core/render/context.ts +7 -0
  127. package/src/core/render/dynamic-post.ts +39 -11
  128. package/src/core/render/extras.ts +22 -3
  129. package/src/core/render/form.ts +134 -36
  130. package/src/core/render/index.ts +123 -25
  131. package/src/core/render/loop.ts +10 -3
  132. package/src/core/render/pagination.ts +76 -0
  133. package/src/core/render/section.ts +5 -1
  134. package/src/core/render/tabs.ts +8 -4
  135. package/src/core/render/vnode.ts +1 -1
  136. package/src/core/sanitize/css.ts +197 -17
  137. package/src/core/sanitize/embed-url.ts +64 -7
  138. package/src/core/sanitize/svg-upload.ts +203 -0
  139. package/src/core/sanitize/svg.ts +102 -21
  140. package/src/core/schema/descriptors.ts +4 -0
  141. package/src/core/schema/design.ts +7 -2
  142. package/src/core/schema/layout.ts +210 -19
  143. package/src/core/schema/style.ts +87 -8
  144. package/src/core/tabs/presence.ts +9 -0
  145. package/src/core/theme/conditions.ts +4 -1
  146. package/src/core/theme/dynamic.ts +10 -0
  147. package/src/core/theme/float.ts +113 -0
  148. package/src/core/theme/pagination.ts +97 -0
  149. package/src/core/theme/part-types.ts +2 -0
  150. package/src/core/theme/popup-markup.ts +3 -1
  151. package/src/core/theme/popup-rules.ts +4 -3
  152. package/src/server/hooks.ts +20 -0
  153. package/src/server/icon-routes.ts +79 -0
  154. package/src/server/plugin.ts +5 -1
@@ -1,3 +1,4 @@
1
+ import type { ArchivePagination } from "./pagination.ts";
1
2
  import type { Layout, LayoutNode } from "../schema/layout.ts";
2
3
  import { isParentNode } from "../schema/layout.ts";
3
4
  import type { VNode } from "../render/vnode.ts";
@@ -29,7 +30,16 @@ export type ThemeDynamicData = {
29
30
  sectionTemplates?: Record<string, Layout>;
30
31
  /** Section part ids already being expanded, so a section cannot include itself. */
31
32
  sectionStack?: readonly string[];
33
+ /**
34
+ * Where the nodes being rendered come from (W-250): unset for the page itself, else the synced
35
+ * section and loop item parts they were expanded from. Another layout can reuse an id.
36
+ */
37
+ idOrigin?: string;
32
38
  archiveTitle?: string;
39
+ /** Which archive page is showing, for the Pagination element (W-221). */
40
+ pagination?: ArchivePagination;
41
+ /** Set inside a Loop's item, where a Pagination would repeat once per post (W-228). */
42
+ inLoopItem?: boolean;
33
43
  };
34
44
 
35
45
  /** Editor canvas placeholders when no live post is bound. */
@@ -0,0 +1,113 @@
1
+ import { z } from "zod";
2
+ import { escapeAttr } from "../sanitize/escape.ts";
3
+ import type { DesignSystem } from "../schema/design.ts";
4
+ import type { Layout } from "../schema/layout.ts";
5
+ import type { StyleProps } from "../schema/style.ts";
6
+ import { parseDoc, type DocIssue } from "./parse-doc.ts";
7
+
8
+ const FLOAT_SCHEMA_VERSION = 1;
9
+
10
+ /** Where a float sits. Start and end follow the page's writing direction. */
11
+ export const FLOAT_EDGES = [
12
+ "top",
13
+ "bottom",
14
+ "start-top",
15
+ "end-top",
16
+ "start-bottom",
17
+ "end-bottom",
18
+ ] as const;
19
+
20
+ export type FloatEdge = (typeof FLOAT_EDGES)[number];
21
+
22
+ const FloatSettingsSchema = z.strictObject({
23
+ schemaVersion: z.literal(FLOAT_SCHEMA_VERSION),
24
+ edge: z.enum(FLOAT_EDGES),
25
+ dismiss: z.boolean(),
26
+ });
27
+
28
+ export type FloatSettings = z.infer<typeof FloatSettingsSchema>;
29
+
30
+ export type FloatValidation =
31
+ | { ok: true; settings: FloatSettings }
32
+ | { ok: false; issues: DocIssue[] };
33
+
34
+ /** A top bar, kept until the author turns on a close button. */
35
+ export function defaultFloatSettings(): FloatSettings {
36
+ return { schemaVersion: FLOAT_SCHEMA_VERSION, edge: "top", dismiss: false };
37
+ }
38
+
39
+ export function validateFloatSettings(raw: unknown): FloatValidation {
40
+ const parsed = parseDoc(raw, FloatSettingsSchema, "float", "Float settings");
41
+ return parsed.ok ? { ok: true, settings: parsed.doc } : parsed;
42
+ }
43
+
44
+ /**
45
+ * Chrome for pinned bars and corner floats. Loaded only when a float matches.
46
+ * Bars reserve their height through the two custom properties the runtime sets.
47
+ */
48
+ export const FLOAT_CHROME_CSS = `
49
+ .emvb-float{position:fixed;z-index:9000;box-sizing:border-box;max-width:100%;display:flex;align-items:flex-start;gap:.35rem}.emvb-float:hover,.emvb-float:focus-within{z-index:9001}
50
+ .emvb-float[hidden]{display:none!important}
51
+ .emvb-float--top{top:0;inset-inline:0}
52
+ .emvb-float--bottom{bottom:0;inset-inline:0}
53
+ .emvb-float--start-top{top:1rem;inset-inline-start:1rem}
54
+ .emvb-float--end-top{top:1rem;inset-inline-end:1rem}
55
+ .emvb-float--start-bottom{bottom:1rem;inset-inline-start:1rem}
56
+ .emvb-float--end-bottom{bottom:1rem;inset-inline-end:1rem}
57
+ :where(.emvb-float--surface){background:#fff;color:#0f172a;box-shadow:0 4px 16px -4px rgba(15,23,42,.25);padding:.5rem 1rem}
58
+ :where(.emvb-float--surface:is(.emvb-float--start-top,.emvb-float--end-top,.emvb-float--start-bottom,.emvb-float--end-bottom)){border-radius:.75rem;padding:.75rem 1rem}
59
+ .emvb-float__body{min-width:0;flex:1}
60
+ .emvb-float__close{flex:none;width:2rem;height:2rem;border:0;border-radius:999px;background:transparent;color:inherit;font-size:1.5rem;line-height:1;cursor:pointer}
61
+ .emvb-float__close:focus-visible{outline:2px solid #2563eb;outline-offset:2px}
62
+ html{--emvb-float-top:0px;--emvb-float-bottom:0px}
63
+ body{padding-top:var(--emvb-float-top);padding-bottom:var(--emvb-float-bottom)}
64
+ `
65
+ .replace(/\n+/g, "")
66
+ .trim();
67
+
68
+ const paintsBackground = (style: StyleProps | undefined): boolean =>
69
+ style?.backgroundColor !== undefined ||
70
+ style?.backgroundImage !== undefined ||
71
+ style?.backgroundVideo !== undefined ||
72
+ style?.gradient !== undefined;
73
+
74
+ /**
75
+ * Whether the float's outer box paints its own background (on the box, a device or one of its
76
+ * classes). Otherwise the float gets the default card surface, so its text isn't drawn over the
77
+ * page (W-171).
78
+ */
79
+ export function floatHasOwnSurface(layout: Layout, design: DesignSystem): boolean {
80
+ const root = layout.root;
81
+ const classes = (design.classes ?? []).filter((item) => root.classes?.includes(item.id));
82
+ return [root, ...classes].some(
83
+ (item) =>
84
+ paintsBackground(item.style) ||
85
+ paintsBackground(item.devices?.tablet) ||
86
+ paintsBackground(item.devices?.mobile),
87
+ );
88
+ }
89
+
90
+ /**
91
+ * Pin rendered float HTML. Not a dialog: no backdrop and no focus trap.
92
+ * A close button is present only when dismiss is on. `surface` adds the default card surface.
93
+ */
94
+ export function wrapFloatMarkup(
95
+ id: string,
96
+ title: string,
97
+ bodyHtml: string,
98
+ settings: FloatSettings,
99
+ surface = true,
100
+ ): string {
101
+ const safeId = escapeAttr(id);
102
+ const label = escapeAttr(title.trim() || "Notice");
103
+ const edge = settings.edge;
104
+ const close = settings.dismiss
105
+ ? `<button type="button" class="emvb-float__close" data-emvb-float-dismiss aria-label="Close"><span aria-hidden="true">×</span></button>`
106
+ : "";
107
+ return [
108
+ `<aside class="emvb-float emvb-float--${edge}${surface ? " emvb-float--surface" : ""}" id="emvb-float-${safeId}" data-emvb-float="${safeId}" data-emvb-float-edge="${edge}" role="region" aria-label="${label}">`,
109
+ `<div class="emvb-float__body">${bodyHtml}</div>`,
110
+ close,
111
+ `</aside>`,
112
+ ].join("");
113
+ }
@@ -0,0 +1,97 @@
1
+ import { isParentNode, type Layout, type LayoutNode } from "../schema/layout.ts";
2
+
3
+ /** Posts per archive page when the Loop has no "Posts per page" (the pre-pagination count). */
4
+ export const DEFAULT_PER_PAGE = 20;
5
+ /** Highest page number EmVB reads from `/page/N`; larger numbers are not archive pages. */
6
+ export const MAX_ARCHIVE_PAGE = 100_000;
7
+
8
+ /** Where an archive request sits: its page and whether a later page exists (W-221). */
9
+ export type ArchivePagination = {
10
+ /** 1-based page number. */
11
+ page: number;
12
+ /** True when at least one more post exists after this page. */
13
+ hasMore: boolean;
14
+ /** The archive's own path without `/page/N`, e.g. `/posts` or `/category/news`. */
15
+ basePath: string;
16
+ };
17
+
18
+ /** The URL path of page `n` of an archive; page 1 is the bare archive path (W-221). */
19
+ export function archivePagePath(basePath: string, n: number): string {
20
+ const base = basePath.replace(/\/+$/, "") || "/";
21
+ if (n <= 1) return base;
22
+ return `${base === "/" ? "" : base}/page/${n}`;
23
+ }
24
+
25
+ /**
26
+ * Splits `/posts/page/3` into the archive path and page. Null for anything that is not a
27
+ * valid page suffix (`/page/0`, `/page/01`, `/page/abc`, a page past MAX_ARCHIVE_PAGE).
28
+ * A path without `/page/N` is page 1.
29
+ */
30
+ export function splitArchivePage(path: string): { basePath: string; page: number } | null {
31
+ const match = /^(.*?)\/page\/([^/]+)$/.exec(path);
32
+ if (!match) return { basePath: path, page: 1 };
33
+ const raw = match[2] ?? "";
34
+ if (!/^[1-9]\d{0,5}$/.test(raw)) return null;
35
+ const page = Number(raw);
36
+ if (page > MAX_ARCHIVE_PAGE) return null;
37
+ return { basePath: match[1] || "/", page };
38
+ }
39
+
40
+ /** Posts per page from the first Loop in an archive layout, else DEFAULT_PER_PAGE (W-221). */
41
+ export function loopPerPage(layout: Layout): number {
42
+ let found: number | undefined;
43
+ const walk = (node: LayoutNode): void => {
44
+ if (found !== undefined) return;
45
+ if (node.type === "loop") {
46
+ const perPage = (node.props as { perPage?: unknown }).perPage;
47
+ found =
48
+ typeof perPage === "number" && Number.isInteger(perPage) && perPage >= 1 && perPage <= 50
49
+ ? perPage
50
+ : DEFAULT_PER_PAGE;
51
+ return;
52
+ }
53
+ if (isParentNode(node)) for (const child of node.children) walk(child);
54
+ };
55
+ walk(layout.root);
56
+ return found ?? DEFAULT_PER_PAGE;
57
+ }
58
+
59
+ /**
60
+ * A paged archive's title for `<title>` and headings: "Posts – page 2"; page 1 is the bare
61
+ * title (W-229).
62
+ */
63
+ export function archivePageTitle(title: string, page: number | undefined): string {
64
+ return page !== undefined && page > 1 ? `${title} – page ${page}` : title;
65
+ }
66
+
67
+ /** One entry of a Pagination bar: a page link, the current page, or a gap (W-222). */
68
+ export type PaginationItem =
69
+ | { kind: "prev" | "next"; href: string }
70
+ | { kind: "page"; n: number; href: string; current: boolean }
71
+ | { kind: "gap" };
72
+
73
+ /**
74
+ * The links a Pagination element shows. Empty when there is only one page. EmDash gives no
75
+ * total count, so the numbers run from 1 to one past the current page (when there is one),
76
+ * with a gap after 1 when the current page is far in (W-222).
77
+ */
78
+ export function paginationItems(p: ArchivePagination): PaginationItem[] {
79
+ if (p.page <= 1 && !p.hasMore) return [];
80
+ const items: PaginationItem[] = [];
81
+ const page = (n: number): PaginationItem => ({
82
+ kind: "page",
83
+ n,
84
+ href: archivePagePath(p.basePath, n),
85
+ current: n === p.page,
86
+ });
87
+ if (p.page > 1) items.push({ kind: "prev", href: archivePagePath(p.basePath, p.page - 1) });
88
+ const from = Math.max(1, p.page - 2);
89
+ if (from > 1) items.push(page(1));
90
+ if (from > 2) items.push({ kind: "gap" });
91
+ for (let n = from; n <= p.page; n++) items.push(page(n));
92
+ if (p.hasMore) {
93
+ items.push(page(p.page + 1));
94
+ items.push({ kind: "next", href: archivePagePath(p.basePath, p.page + 1) });
95
+ }
96
+ return items;
97
+ }
@@ -11,6 +11,7 @@ export const THEME_PART_TYPES = [
11
11
  "section",
12
12
  "page_template",
13
13
  "popup",
14
+ "float",
14
15
  ] as const;
15
16
 
16
17
  export type ThemePartType = (typeof THEME_PART_TYPES)[number];
@@ -52,6 +53,7 @@ export const THEME_PART_TYPE_LABELS: Record<ThemePartType, string> = {
52
53
  section: "Section",
53
54
  page_template: "Page template",
54
55
  popup: "Popup",
56
+ float: "Float",
55
57
  };
56
58
 
57
59
  export function isThemePartType(value: unknown): value is ThemePartType {
@@ -31,7 +31,9 @@ export function wrapPopupMarkup(id: string, bodyHtml: string, triggers: Triggers
31
31
  return [
32
32
  `<div class="emvb-popup" id="emvb-popup-${safeId}" data-emvb-popup="${safeId}" data-emvb-popup-config="${configJson}" hidden>`,
33
33
  `<div class="emvb-popup__backdrop" data-emvb-popup-dismiss tabindex="-1"></div>`,
34
- `<div class="emvb-popup__dialog" role="dialog" aria-modal="true" aria-labelledby="${titleId}" tabindex="-1">`,
34
+ // W-282: named "Popup" until the runtime points the name at the content's first heading;
35
+ // naming it after the whole content read every word as the dialog's name.
36
+ `<div class="emvb-popup__dialog" role="dialog" aria-modal="true" aria-label="Popup" tabindex="-1">`,
35
37
  `<button type="button" class="emvb-popup__close" data-emvb-popup-dismiss aria-label="Close"><span aria-hidden="true">×</span></button>`,
36
38
  `<div class="emvb-popup__content" id="${titleId}">${bodyHtml}</div>`,
37
39
  `</div></div>`,
@@ -12,10 +12,11 @@ export const POPUP_DEVICES = ["desktop", "tablet", "mobile"] as const;
12
12
  export type PopupDevice = (typeof POPUP_DEVICES)[number];
13
13
 
14
14
  /**
15
- * Widths that agree with `deviceForWidth` (W-096). The canvas previews tablet at 768 and mobile
16
- * at 390, with no zoom. Public CSS uses the matching max-width queries.
15
+ * Widths that agree with `deviceForWidth` (W-096). The canvas lays the page out at 1280 on
16
+ * desktop (at least), 768 on tablet and 390 on mobile, scaled to fit (W-158, D-046); Preview opens
17
+ * the same widths. Public CSS uses the matching max-width queries.
17
18
  */
18
- export const DEVICE_PREVIEW_PX = { tablet: 768, mobile: 390 } as const;
19
+ export const DEVICE_PREVIEW_PX = { desktop: 1280, tablet: 768, mobile: 390 } as const;
19
20
 
20
21
  /** Public CSS queries. Bounds match `deviceForWidth`: 767 mobile, 1024 tablet, 1025 desktop. */
21
22
  export const DEVICE_MEDIA = {
@@ -2,6 +2,8 @@ import { ContentSaveRejectedError, type ContentHookEvent, type PluginContext } f
2
2
  import {
3
3
  summarizeIssues,
4
4
  validateConditions,
5
+ validateFloatSettings,
6
+ nestingIssues,
5
7
  validateLayout,
6
8
  validateTriggers,
7
9
  } from "../core/index.ts";
@@ -38,6 +40,13 @@ const THEME_PART_FIELDS: [string, (raw: unknown) => FieldValidation][] = [
38
40
  return result.ok ? { ok: true, value: result.triggers } : result;
39
41
  },
40
42
  ],
43
+ [
44
+ "float",
45
+ (raw) => {
46
+ const result = validateFloatSettings(raw);
47
+ return result.ok ? { ok: true, value: result.settings } : result;
48
+ },
49
+ ],
41
50
  ];
42
51
 
43
52
  /**
@@ -69,6 +78,17 @@ export async function beforeSave(
69
78
  `The ${kind} layout is invalid. ${summarizeIssues(result.issues)}`,
70
79
  );
71
80
  }
81
+ // Elements in a parent the editor never allows (menu item outside a Menu, field outside a
82
+ // form…) render broken markup; refuse them with the editor's own reason (W-225).
83
+ const misplaced = nestingIssues(result.layout, 3);
84
+ if (misplaced.length > 0) {
85
+ ctx.log.warn(`emvb: ${kind} save rejected`, { pageId, code: "nesting" });
86
+ throw new ContentSaveRejectedError(
87
+ `The ${kind} layout has elements in the wrong place. ${misplaced
88
+ .map((issue) => issue.message)
89
+ .join("; ")}`,
90
+ );
91
+ }
72
92
  if (result.upgradedFrom !== result.layout.schemaVersion) {
73
93
  next = { ...(next ?? event.content), layout: result.layout };
74
94
  }
@@ -0,0 +1,79 @@
1
+ import { PluginRouteError, type PluginRoute, type RouteContext } from "emdash";
2
+ import { z } from "zod";
3
+ import {
4
+ prepareUploadedSvg,
5
+ UPLOAD_SVG_MAX_BYTES,
6
+ type UploadedIcon,
7
+ type UploadedIconItem,
8
+ } from "../core/index.ts";
9
+
10
+ /**
11
+ * Upload SVG (W-239): EmVB's own list of uploaded icons. EmDash's media library refuses
12
+ * image/svg+xml by default (it has no upload-time SVG check, so a stored SVG could carry a
13
+ * script), so EmVB keeps uploads in its plugin storage instead, already sanitized on the server.
14
+ * An Icon stores `upload:<id>` plus the SVG itself, so pages never read this list.
15
+ */
16
+
17
+ type IconStore = {
18
+ put(id: string, data: UploadedIcon): Promise<void>;
19
+ query(options?: {
20
+ orderBy?: Record<string, "asc" | "desc">;
21
+ limit?: number;
22
+ }): Promise<{ items: Array<{ id: string; data: UploadedIcon }>; hasMore: boolean }>;
23
+ };
24
+
25
+ const store = (ctx: RouteContext<unknown>) => ctx.storage["icons"] as unknown as IconStore;
26
+
27
+ /** The most recent uploads the picker lists. */
28
+ const UPLOAD_LIST_LIMIT = 100;
29
+
30
+ /** Editors and above: the uploaded icons, newest first. */
31
+ export const iconsRoute: PluginRoute = {
32
+ permission: "content:edit_any",
33
+ handler: async (ctx) => {
34
+ const page = await store(ctx).query({
35
+ orderBy: { uploadedAt: "desc" },
36
+ limit: UPLOAD_LIST_LIMIT,
37
+ });
38
+ // Only the known fields, whatever else a stored row might carry.
39
+ const items: UploadedIconItem[] = page.items.map(({ id, data }) => ({
40
+ id,
41
+ name: data.name,
42
+ svg: data.svg,
43
+ uploadedAt: data.uploadedAt,
44
+ }));
45
+ return { items };
46
+ },
47
+ };
48
+
49
+ /** A file name without its folder or extension, as the icon's label. */
50
+ export const uploadName = (name: string) =>
51
+ name
52
+ .replace(/^.*[\\/]/, "")
53
+ .replace(/\.svg$/i, "")
54
+ .trim()
55
+ .slice(0, 80) || "Uploaded icon";
56
+
57
+ const UploadInput = z.object({
58
+ name: z.string().max(255),
59
+ // A JSON string: the file plus escaping room is still bounded by the route body limit.
60
+ svg: z.string().min(1).max(UPLOAD_SVG_MAX_BYTES),
61
+ });
62
+
63
+ /** Editors and above. Sanitizes on the server, whatever the client did, then stores. */
64
+ export const iconUploadRoute: PluginRoute<z.infer<typeof UploadInput>> = {
65
+ permission: "content:edit_any",
66
+ input: UploadInput,
67
+ handler: async (ctx) => {
68
+ const prepared = prepareUploadedSvg(ctx.input.svg);
69
+ if (!prepared.ok) throw new PluginRouteError("INVALID_SVG", prepared.message, 422);
70
+ const id = crypto.randomUUID().replaceAll("-", "").slice(0, 16);
71
+ const item: UploadedIcon = {
72
+ name: uploadName(ctx.input.name),
73
+ svg: prepared.svg,
74
+ uploadedAt: new Date().toISOString(),
75
+ };
76
+ await store(ctx).put(id, item);
77
+ return { item: { id, ...item }, imagesLeftOut: prepared.imagesLeftOut };
78
+ },
79
+ };
@@ -6,6 +6,7 @@ import {
6
6
  designRoute,
7
7
  designSaveRoute,
8
8
  } from "./design-routes.ts";
9
+ import { iconUploadRoute, iconsRoute } from "./icon-routes.ts";
9
10
  import { beforeSave } from "./hooks.ts";
10
11
 
11
12
  export function createPlugin() {
@@ -13,7 +14,8 @@ export function createPlugin() {
13
14
  id: PLUGIN_ID,
14
15
  version: PLUGIN_VERSION,
15
16
  capabilities: ["content:read", "content:write"],
16
- storage: { design: { indexes: [] } },
17
+ // W-239: uploaded SVG icons (EmDash's media library refuses SVG by default).
18
+ storage: { design: { indexes: [] }, icons: { indexes: ["uploadedAt"] } },
17
19
  hooks: {
18
20
  "content:beforeSave": { handler: beforeSave, errorPolicy: "abort" },
19
21
  },
@@ -34,6 +36,8 @@ export function createPlugin() {
34
36
  "design/draft": designDraftRoute,
35
37
  "design/save": designSaveRoute,
36
38
  "design/publish": designPublishRoute,
39
+ icons: iconsRoute,
40
+ "icons/upload": iconUploadRoute,
37
41
  },
38
42
  });
39
43
  }