@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,12 +1,13 @@
1
- import { fieldByName, type FormDefinitions } from "../forms/definition.ts";
1
+ import { fieldByName, type FormDefinitions, type PublicFormField } from "../forms/definition.ts";
2
2
  import type { FormNode, LayoutNode } from "../schema/layout.ts";
3
3
  import type { ThemeDynamicData } from "../theme/dynamic.ts";
4
+ import { nodeChildren } from "../tree-ops.ts";
4
5
  import type { RenderContext } from "./context.ts";
5
6
  import type { VNode } from "./vnode.ts";
6
7
 
7
8
  export const FORMS_SUBMIT_PATH = "/_emdash/api/plugins/emdash-forms/submit";
8
9
 
9
- const honeypot = (formId: string): VNode => ({
10
+ const honeypot = (inputId: string): VNode => ({
10
11
  tag: "div",
11
12
  attrs: {
12
13
  class: "ec-form-hp",
@@ -15,14 +16,14 @@ const honeypot = (formId: string): VNode => ({
15
16
  children: [
16
17
  {
17
18
  tag: "label",
18
- attrs: { for: `${formId}-_hp` },
19
+ attrs: { for: inputId },
19
20
  children: ["Leave blank"],
20
21
  },
21
22
  {
22
23
  tag: "input",
23
24
  attrs: {
24
25
  type: "text",
25
- id: `${formId}-_hp`,
26
+ id: inputId,
26
27
  name: "_hp",
27
28
  tabindex: "-1",
28
29
  autocomplete: "off",
@@ -33,6 +34,16 @@ const honeypot = (formId: string): VNode => ({
33
34
  });
34
35
 
35
36
  /** An EmDash Forms markup shell (D-006) around the form's fields; unbound forms only preview in the editor. */
37
+ /** The text of the form's first Submit button, as the page renders it. */
38
+ function firstSubmitLabel(nodes: readonly LayoutNode[]): string | undefined {
39
+ for (const child of nodes) {
40
+ if (child.type === "submit") return (child.props as { label?: string }).label ?? "Submit";
41
+ const found = firstSubmitLabel(nodeChildren(child));
42
+ if (found !== undefined) return found;
43
+ }
44
+ return undefined;
45
+ }
46
+
36
47
  export function renderForm(
37
48
  node: FormNode,
38
49
  attrs: Record<string, string>,
@@ -53,7 +64,12 @@ export function renderForm(
53
64
  children: ["Bind a form in settings to preview it here."],
54
65
  };
55
66
  }
56
- const submitLabel = ctx.definitions.get(formId)?.settings.submitLabel ?? "Submit";
67
+ // W-203: the forms client puts this label back on the button after each submit, so it must be
68
+ // the label the page shows, not the form definition's.
69
+ const submitLabel =
70
+ firstSubmitLabel(node.children) ??
71
+ ctx.definitions.get(formId)?.settings.submitLabel ??
72
+ "Submit";
57
73
  const page: VNode = {
58
74
  tag: "div",
59
75
  attrs: { "data-page": "0" },
@@ -68,12 +84,17 @@ export function renderForm(
68
84
  action: FORMS_SUBMIT_PATH,
69
85
  "data-ec-form": "",
70
86
  "data-form-id": formId,
87
+ // W-297: the forms client checks each control itself and writes the message next to the
88
+ // field, as the server's errors are; without this the browser's bubble would come first.
89
+ novalidate: "",
71
90
  "data-submit-label": submitLabel,
72
91
  },
73
92
  children: [
74
93
  page,
75
94
  { tag: "input", attrs: { type: "hidden", name: "formId", value: formId }, children: [] },
76
- honeypot(formId),
95
+ // One id per form element, so the same form placed twice keeps unique ids (W-187), also
96
+ // when one form element renders twice, from a synced section or a loop item (W-249).
97
+ honeypot(ctx.uniqueId(`emvb-hp-${node.id}`)),
77
98
  {
78
99
  tag: "div",
79
100
  attrs: { class: "ec-form-status", "data-form-status": "", "aria-live": "polite" },
@@ -94,44 +115,121 @@ function replaceChildren(vnode: VNode, match: (node: VNode) => boolean, children
94
115
  };
95
116
  }
96
117
 
97
- /** Fills a select or radio field with the options of the first bound form definition that has it. */
118
+ /** Applies `edit` to every element node in the tree, children first. */
119
+ function mapNodes(vnode: VNode, edit: (node: VNode) => VNode): VNode {
120
+ return edit({
121
+ ...vnode,
122
+ children: vnode.children.map((child) =>
123
+ typeof child === "string" ? child : mapNodes(child, edit),
124
+ ),
125
+ });
126
+ }
127
+
128
+ /** Definition types a Text input can take on; the rest stay `text`. */
129
+ const INPUT_TYPES = new Set(["email", "tel", "url", "number", "date"]);
130
+ const LENGTH_TYPES = new Set(["text", "email", "tel", "url", "textarea"]);
131
+ const isControl = (node: VNode) =>
132
+ ["input", "select", "textarea"].includes(node.tag) && node.attrs.type !== "hidden";
133
+
134
+ /**
135
+ * W-297: what the forms plugin's own embed puts on a control: the input type (so phones show the
136
+ * right keyboard), `required`, and the length, range and pattern limits, plus a visible mark on
137
+ * the label. Without them the forms client found nothing to check before sending.
138
+ */
139
+ function withFieldMeta(vnode: VNode, node: LayoutNode, meta: PublicFormField): VNode {
140
+ const type = node.type === "text-input" && INPUT_TYPES.has(meta.type) ? meta.type : undefined;
141
+ const rules = meta.validation ?? {};
142
+ const kind = type ?? (node.type === "textarea" ? "textarea" : meta.type);
143
+ const limits: Record<string, string> = {};
144
+ if (node.type === "text-input" || node.type === "textarea") {
145
+ if (LENGTH_TYPES.has(kind)) {
146
+ if (rules.minLength !== undefined) limits.minlength = String(rules.minLength);
147
+ if (rules.maxLength !== undefined) limits.maxlength = String(rules.maxLength);
148
+ }
149
+ if (kind === "number") {
150
+ if (rules.min !== undefined) limits.min = String(rules.min);
151
+ if (rules.max !== undefined) limits.max = String(rules.max);
152
+ }
153
+ if (node.type === "text-input" && kind !== "number" && kind !== "date" && rules.pattern) {
154
+ limits.pattern = rules.pattern;
155
+ }
156
+ }
157
+ const mark: VNode = {
158
+ tag: "span",
159
+ attrs: { class: "emvb-form-required", "aria-hidden": "true" },
160
+ children: [" *"],
161
+ };
162
+ return mapNodes(vnode, (child) => {
163
+ if (isControl(child)) {
164
+ return {
165
+ ...child,
166
+ attrs: {
167
+ ...child.attrs,
168
+ ...(type ? { type } : {}),
169
+ ...(meta.required ? { required: "" } : {}),
170
+ ...limits,
171
+ },
172
+ };
173
+ }
174
+ if (!meta.required || child.tag !== "label") return child;
175
+ if (child.attrs.class === "emvb-form-label") {
176
+ return { ...child, children: [...child.children, mark] };
177
+ }
178
+ // The checkbox label wraps the input and the label text; the mark follows the text.
179
+ if (child.attrs.class === "emvb-form-checkbox-label") {
180
+ return {
181
+ ...child,
182
+ children: child.children.map((part) => (typeof part === "string" ? `${part} *` : part)),
183
+ };
184
+ }
185
+ return child;
186
+ });
187
+ }
188
+
189
+ /** Fills a field from the first bound form definition that has it: options, type, limits. */
98
190
  export function withFieldOptions(
99
191
  vnode: VNode,
100
192
  node: LayoutNode,
101
193
  definitions: FormDefinitions,
102
194
  ): VNode {
103
- if (node.type !== "select" && node.type !== "radio") return vnode;
104
- const field = (node.props as { field: string }).field;
195
+ const field = (node.props as { field?: unknown }).field;
196
+ if (typeof field !== "string") return vnode;
105
197
  for (const definition of definitions.values()) {
106
198
  const meta = fieldByName(definition, field);
107
199
  if (!meta) continue;
108
- if (!meta.options?.length) return vnode;
109
- if (node.type === "select") {
110
- return replaceChildren(vnode, (child) => child.tag === "select", [
111
- { tag: "option", attrs: { value: "" }, children: ["Choose…"] },
112
- ...meta.options.map((option): VNode => ({
113
- tag: "option",
114
- attrs: { value: option.value },
115
- children: [option.label],
116
- })),
117
- ]);
118
- }
119
- return replaceChildren(
120
- vnode,
121
- (child) => child.tag === "fieldset" && (child.attrs.class ?? "").includes("emvb-radio-group"),
122
- meta.options.map((option) => ({
123
- tag: "label",
124
- attrs: { class: "emvb-form-radio-label" },
125
- children: [
126
- {
127
- tag: "input",
128
- attrs: { type: "radio", name: field, value: option.value },
129
- children: [],
130
- },
131
- ` ${option.label}`,
132
- ],
133
- })),
134
- );
200
+ return withFieldMeta(withOptions(vnode, node, meta), node, meta);
135
201
  }
136
202
  return vnode;
137
203
  }
204
+
205
+ /** A select or radio field filled with the definition's options. */
206
+ function withOptions(vnode: VNode, node: LayoutNode, meta: PublicFormField): VNode {
207
+ const field = meta.name;
208
+ if ((node.type !== "select" && node.type !== "radio") || !meta.options?.length) return vnode;
209
+ if (node.type === "select") {
210
+ return replaceChildren(vnode, (child) => child.tag === "select", [
211
+ { tag: "option", attrs: { value: "" }, children: ["Choose…"] },
212
+ ...meta.options.map((option): VNode => ({
213
+ tag: "option",
214
+ attrs: { value: option.value },
215
+ children: [option.label],
216
+ })),
217
+ ]);
218
+ }
219
+ return replaceChildren(
220
+ vnode,
221
+ (child) => child.tag === "fieldset" && (child.attrs.class ?? "").includes("emvb-radio-group"),
222
+ meta.options.map((option) => ({
223
+ tag: "label",
224
+ attrs: { class: "emvb-form-radio-label" },
225
+ children: [
226
+ {
227
+ tag: "input",
228
+ attrs: { type: "radio", name: field, value: option.value },
229
+ children: [],
230
+ },
231
+ ` ${option.label}`,
232
+ ],
233
+ })),
234
+ );
235
+ }
@@ -1,8 +1,9 @@
1
1
  import { generateCss } from "../css/generate.ts";
2
2
  import { cssScopeToken, scopeAttribute, scopeCss, scopeWrapperCss } from "../css/scope.ts";
3
3
  import { ELEMENTS } from "../elements/index.ts";
4
+ import { controlId } from "../elements/field-id.ts";
4
5
  import { layoutHasForm } from "../forms/binding.ts";
5
- import { layoutHasTabs } from "../tabs/presence.ts";
6
+ import { layoutHasMenuDropdown, layoutHasTabs } from "../tabs/presence.ts";
6
7
  import type { DesignSystem } from "../schema/design.ts";
7
8
  import {
8
9
  isFormNode,
@@ -12,12 +13,14 @@ import {
12
13
  isTabsNode,
13
14
  type Layout,
14
15
  type LayoutNode,
16
+ type PaginationNode,
15
17
  } from "../schema/layout.ts";
16
18
  import {
17
19
  cssLength,
18
20
  stateDeclarations,
19
21
  styleClassName,
20
22
  styleDeclarations,
23
+ withInheritedLayers,
21
24
  type Declaration,
22
25
  type StateDeclarations,
23
26
  } from "../sanitize/css.ts";
@@ -30,6 +33,7 @@ import type { RenderContext, RenderMode } from "./context.ts";
30
33
  import { isDynamicPostNode, renderDynamicPost } from "./dynamic-post.ts";
31
34
  import { renderForm, withFieldOptions } from "./form.ts";
32
35
  import { renderLoop } from "./loop.ts";
36
+ import { renderPagination } from "./pagination.ts";
33
37
  import { renderSection } from "./section.ts";
34
38
  import { renderTabs } from "./tabs.ts";
35
39
  import { serialize, type VNode } from "./vnode.ts";
@@ -55,6 +59,10 @@ export type RenderResult = {
55
59
  css: string;
56
60
  needsFormsRuntime: boolean;
57
61
  needsTabsRuntime: boolean;
62
+ /** A Menu has a dropdown: hosts load `EmVBMenuRuntime` (W-197). */
63
+ needsMenuRuntime: boolean;
64
+ /** The site's text direction when set in Site styles, for the host's `<html dir>` (W-230). */
65
+ dir?: "ltr" | "rtl" | "auto";
58
66
  warnings: RenderWarning[];
59
67
  };
60
68
 
@@ -83,6 +91,55 @@ function videoPreview(node: LayoutNode, attrs: Record<string, string>): VNode |
83
91
  * Renders a validated layout to lean HTML and CSS (R-031, R-032). Walks defensively: unknown types
84
92
  * render nothing publicly and a placeholder in the editor (R-033); unsafe style values are dropped.
85
93
  */
94
+ /** `grid-template-columns` for a whole column count from 1 to 12; anything else emits nothing. */
95
+ const gridTracks = (columns: unknown): Declaration[] =>
96
+ typeof columns === "number" && Number.isInteger(columns) && columns >= 1 && columns <= 12
97
+ ? [{ property: "grid-template-columns", value: `repeat(${columns}, minmax(0, 1fr))` }]
98
+ : [];
99
+
100
+ /** A node with at least one child; tolerant of a malformed node without a children array. */
101
+ const hasChildren = (node: LayoutNode): boolean => {
102
+ const children: unknown = (node as { children?: unknown }).children;
103
+ return Array.isArray(children) && children.length > 0;
104
+ };
105
+
106
+ /** A short, stable hash of a node origin, for its suffixed rule id (W-250). */
107
+ function originHash(origin: string): string {
108
+ let hash = 0x811c9dc5;
109
+ for (let i = 0; i < origin.length; i += 1) {
110
+ hash ^= origin.charCodeAt(i);
111
+ hash = Math.imul(hash, 0x01000193) >>> 0;
112
+ }
113
+ return hash.toString(36);
114
+ }
115
+
116
+ /** Form fields whose control carries an `emvb-field-<id>` HTML id (W-187). */
117
+ const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "radio"]);
118
+
119
+ const ID_ATTRS = ["id", "for", "aria-controls", "aria-labelledby", "aria-describedby"] as const;
120
+
121
+ /** Rewrites `base` (or `base-…`) to `next` in the id and id-reference attributes of a subtree. */
122
+ function renameIds(vnode: VNode, base: string, next: string): VNode {
123
+ const attrs = { ...vnode.attrs };
124
+ for (const key of ID_ATTRS) {
125
+ const value = attrs[key];
126
+ if (value === undefined) continue;
127
+ attrs[key] = value
128
+ .split(" ")
129
+ .map((ref) =>
130
+ ref === base || ref.startsWith(`${base}-`) ? next + ref.slice(base.length) : ref,
131
+ )
132
+ .join(" ");
133
+ }
134
+ return {
135
+ ...vnode,
136
+ attrs,
137
+ children: vnode.children.map((child) =>
138
+ typeof child === "string" ? child : renameIds(child, base, next),
139
+ ),
140
+ };
141
+ }
142
+
86
143
  export function renderPage(
87
144
  layout: Layout,
88
145
  design: DesignSystem,
@@ -111,6 +168,10 @@ export function renderPage(
111
168
  const knownVariables = new Set(design.variables.colors.map((c) => c.id));
112
169
  let backgroundVideo = false;
113
170
 
171
+ const domIds = new Map<string, number>();
172
+ // W-253: runtimes follow what renders, including synced section and loop item contents,
173
+ // which the page's own layout doesn't hold.
174
+ const rendered = { form: false, tabs: false, menuDropdown: false };
114
175
  const ctx: RenderContext = {
115
176
  mode,
116
177
  definitions: opts.formDefinitions ?? new Map(),
@@ -118,6 +179,20 @@ export function renderPage(
118
179
  nodes
119
180
  .map((child) => visit(child, false, dynamic))
120
181
  .filter((child): child is VNode => child !== undefined),
182
+ uniqueId: (base) => {
183
+ const count = (domIds.get(base) ?? 0) + 1;
184
+ domIds.set(base, count);
185
+ return count === 1 ? base : `${base}-r${count}`;
186
+ },
187
+ };
188
+
189
+ // W-250: the first origin (page, synced section, loop item part) to use each element id.
190
+ const idOrigins = new Map<string, string>();
191
+ /** The id in `.emvb-e-<id>`: suffixed when another layout already used this id here. */
192
+ const ruleIdFor = (id: string, origin: string): string => {
193
+ const first = idOrigins.get(id);
194
+ if (first === undefined) idOrigins.set(id, origin);
195
+ return first === undefined || first === origin ? id : `${id}-o${originHash(origin)}`;
121
196
  };
122
197
 
123
198
  const nodeAttrs = (
@@ -125,6 +200,7 @@ export function renderPage(
125
200
  isRoot: boolean,
126
201
  id: string | undefined,
127
202
  nodeId: string,
203
+ ruleId: string | undefined,
128
204
  ): Record<string, string> => {
129
205
  const classes = [...(isRoot ? ["emvb-root"] : []), `emvb-${node.type}`];
130
206
  for (const classId of node.classes ?? []) {
@@ -132,8 +208,13 @@ export function renderPage(
132
208
  if (name) classes.push(name);
133
209
  }
134
210
  const { declarations, rejected } = styleDeclarations(node.style);
135
- const tablet = styleDeclarations(node.devices?.tablet);
136
- const mobile = styleDeclarations(node.devices?.mobile);
211
+ // W-210: a device that sets one background layer keeps the layers it inherits.
212
+ const base = node.style ?? {};
213
+ const tabletStyle = node.devices?.tablet;
214
+ const tablet = styleDeclarations(withInheritedLayers(tabletStyle, base));
215
+ const mobile = styleDeclarations(
216
+ withInheritedLayers(node.devices?.mobile, { ...base, ...tabletStyle }),
217
+ );
137
218
  for (const key of [...rejected, ...tablet.rejected, ...mobile.rejected]) {
138
219
  warnings.push({ nodeId, code: "rejected-style", detail: key });
139
220
  }
@@ -141,19 +222,18 @@ export function renderPage(
141
222
  const height = cssLength((node as { props: { height: unknown } }).props.height);
142
223
  if (height) declarations.push({ property: "height", value: height });
143
224
  }
225
+ if (node.type === "layout-section") {
226
+ // The inner box's width (W-156): full width, or a length; unset keeps the 1140 px default.
227
+ const props = (node as { props: { contentWidth?: unknown; fullWidth?: unknown } }).props;
228
+ const width = props.fullWidth === true ? "none" : cssLength(props.contentWidth);
229
+ if (width) declarations.push({ property: "--emvb-content-width", value: width });
230
+ }
144
231
  if (node.type === "grid") {
145
- const columns = (node as { props: { columns: unknown } }).props.columns;
146
- if (
147
- typeof columns === "number" &&
148
- Number.isInteger(columns) &&
149
- columns >= 1 &&
150
- columns <= 12
151
- ) {
152
- declarations.push({
153
- property: "grid-template-columns",
154
- value: `repeat(${columns}, minmax(0, 1fr))`,
155
- });
156
- }
232
+ const props = (node as { props: Record<string, unknown> }).props;
233
+ declarations.push(...gridTracks(props["columns"]));
234
+ // Tablet and mobile counts go in their media queries (W-139).
235
+ tablet.declarations.unshift(...gridTracks(props["columnsTablet"]));
236
+ mobile.declarations.unshift(...gridTracks(props["columnsMobile"]));
157
237
  }
158
238
  const states = stateDeclarations(node.states);
159
239
  for (const key of states.rejected) {
@@ -169,10 +249,13 @@ export function renderPage(
169
249
  tablet.declarations.length > 0 ||
170
250
  mobile.declarations.length > 0 ||
171
251
  (hiddenOn?.length ?? 0) > 0;
172
- if (id && (declarations.length > 0 || Object.keys(states.states).length > 0 || responsive)) {
173
- classes.push(`emvb-e-${id}`);
252
+ if (
253
+ ruleId &&
254
+ (declarations.length > 0 || Object.keys(states.states).length > 0 || responsive)
255
+ ) {
256
+ classes.push(`emvb-e-${ruleId}`);
174
257
  localRules.push({
175
- id,
258
+ id: ruleId,
176
259
  declarations,
177
260
  states: states.states,
178
261
  tablet: tablet.declarations,
@@ -183,6 +266,8 @@ export function renderPage(
183
266
  const attrs: Record<string, string> = { class: classes.join(" "), ...customAttributes(node) };
184
267
  if (mode === "editor" && id) attrs["data-emvb-id"] = id;
185
268
  if (node.htmlId && HTML_ID.test(node.htmlId)) attrs.id = node.htmlId;
269
+ // W-230: the site's text direction on the root, also a fallback when the host's <html> has none.
270
+ if (isRoot && design.direction) attrs.dir = design.direction;
186
271
  return attrs;
187
272
  };
188
273
 
@@ -204,10 +289,17 @@ export function renderPage(
204
289
  };
205
290
  }
206
291
  usedTypes.add(type);
207
- const attrs = nodeAttrs(node, isRoot, id, nodeId);
292
+ if (isFormNode(node) && node.props.formId.trim()) rendered.form = true;
293
+ if (isTabsNode(node)) rendered.tabs = true;
294
+ if (type === "menu-item" && hasChildren(node)) rendered.menuDropdown = true;
295
+ const ruleId = id === undefined ? undefined : ruleIdFor(id, dynamic?.idOrigin ?? "");
296
+ const attrs = nodeAttrs(node, isRoot, id, nodeId, ruleId);
208
297
  const def = ELEMENTS[type as keyof typeof ELEMENTS];
209
298
  if (isFormNode(node)) return finish(node, renderForm(node, attrs, ctx, dynamic));
210
299
  if (isLoopNode(node)) return finish(node, renderLoop(node, attrs, ctx, dynamic));
300
+ if (node.type === "pagination") {
301
+ return finish(node, renderPagination(node as PaginationNode, attrs, dynamic, mode));
302
+ }
211
303
  if (isSectionNode(node)) return finish(node, renderSection(node, attrs, ctx, dynamic));
212
304
  if (isDynamicPostNode(node)) {
213
305
  return finish(
@@ -223,10 +315,14 @@ export function renderPage(
223
315
  const preview = videoPreview(node, attrs);
224
316
  if (preview) return finish(node, preview);
225
317
  }
226
- return finish(
227
- node,
228
- withFieldOptions(def.build(node as never, attrs, []), node, ctx.definitions),
229
- );
318
+ const built = withFieldOptions(def.build(node as never, attrs, []), node, ctx.definitions);
319
+ return finish(node, FIELD_TYPES.has(type) && id ? uniqueField(built, controlId(id)) : built);
320
+ }
321
+
322
+ /** W-249: a field rendered again (synced section, loop item) moves its control to a new id. */
323
+ function uniqueField(vnode: VNode, base: string): VNode {
324
+ const unique = ctx.uniqueId(base);
325
+ return unique === base ? vnode : renameIds(vnode, base, unique);
230
326
  }
231
327
 
232
328
  function videoOf(node: LayoutNode): string | undefined {
@@ -267,8 +363,10 @@ export function renderPage(
267
363
  vnode,
268
364
  html: scope ? `<div ${scopeAttribute(scope)}>${html}</div>` : html,
269
365
  css: scope ? scopeWrapperCss() + scopeCss(css, scope) : css,
270
- needsFormsRuntime: layoutHasForm(layout),
271
- needsTabsRuntime: layoutHasTabs(layout),
366
+ needsFormsRuntime: rendered.form || layoutHasForm(layout),
367
+ needsTabsRuntime: rendered.tabs || layoutHasTabs(layout),
368
+ needsMenuRuntime: rendered.menuDropdown || layoutHasMenuDropdown(layout),
369
+ ...(design.direction ? { dir: design.direction } : {}),
272
370
  warnings,
273
371
  };
274
372
  }
@@ -16,20 +16,27 @@ export function renderLoop(
16
16
  const templateLayout =
17
17
  itemPartId && dynamic?.loopTemplates ? dynamic.loopTemplates[itemPartId] : undefined;
18
18
  const templateNodes: LayoutNode[] = templateLayout ? templateLayout.root.children : node.children;
19
- if (posts.length === 0) {
19
+ // Editor mode always has a sample post, so an empty item template would paint a zero-height box.
20
+ if (posts.length === 0 || (ctx.mode === "editor" && templateNodes.length === 0)) {
20
21
  if (ctx.mode !== "editor") return undefined;
21
22
  return {
22
23
  tag: "div",
23
24
  attrs: { ...attrs, "data-emvb-loop-empty": "" },
24
- children: ["Loop — add posts on the public archive to see items."],
25
+ children: ["Choose a Loop Item, or add elements here to design the item."],
25
26
  };
26
27
  }
27
28
  const children: VNode[] = [];
29
+ // Items don't get the archive's page data: a Pagination belongs after the Loop (W-228).
30
+ const { pagination: _pagination, ...rest } = dynamic ?? {};
31
+ // A loop item part is another layout, so its ids may match the page's (W-250).
32
+ const itemDynamic = templateLayout
33
+ ? { ...rest, idOrigin: `${rest.idOrigin ?? ""}/l:${itemPartId}` }
34
+ : rest;
28
35
  for (const post of posts) {
29
36
  children.push({
30
37
  tag: "div",
31
38
  attrs: { class: "emvb-loop-item", "data-emvb-loop-item": post.id },
32
- children: ctx.children(templateNodes, { ...dynamic, post }),
39
+ children: ctx.children(templateNodes, { ...itemDynamic, post, inLoopItem: true }),
33
40
  });
34
41
  }
35
42
  return ELEMENTS.loop.build(node as never, attrs, children);
@@ -0,0 +1,76 @@
1
+ import type { PaginationNode } from "../schema/layout.ts";
2
+ import type { ThemeDynamicData } from "../theme/dynamic.ts";
3
+ import { paginationItems, type ArchivePagination } from "../theme/pagination.ts";
4
+ import type { VNode } from "./vnode.ts";
5
+
6
+ /** What the editor canvas shows: page 2 of several, links going nowhere (W-222). */
7
+ const EDITOR_SAMPLE: ArchivePagination = { page: 2, hasMore: true, basePath: "/posts" };
8
+
9
+ const label = (text: string | undefined, fallback: string) => text?.trim() || fallback;
10
+
11
+ /**
12
+ * Previous, page numbers and Next as plain links in a `nav` (W-222). No JS. Nothing on the page
13
+ * when there is no archive page data or only one page; the editor shows a sample.
14
+ */
15
+ export function renderPagination(
16
+ node: PaginationNode,
17
+ attrs: Record<string, string>,
18
+ dynamic: ThemeDynamicData | undefined,
19
+ mode: "editor" | "public",
20
+ ): VNode | undefined {
21
+ const editor = mode === "editor";
22
+ // Inside a Loop's item it would repeat once per post; it goes after the Loop (W-228).
23
+ if (dynamic?.inLoopItem) {
24
+ if (!editor) return undefined;
25
+ return {
26
+ tag: "div",
27
+ attrs: { ...attrs, "data-emvb-pagination-empty": "" },
28
+ children: ["Put Pagination after the Loop, not inside its item."],
29
+ };
30
+ }
31
+ const data = dynamic?.pagination ?? (editor ? EDITOR_SAMPLE : undefined);
32
+ if (!data) return undefined;
33
+ const items = paginationItems(data);
34
+ if (items.length === 0) {
35
+ if (!editor) return undefined;
36
+ return {
37
+ tag: "div",
38
+ attrs: { ...attrs, "data-emvb-pagination-empty": "" },
39
+ children: ["Pagination shows when the archive has more than one page."],
40
+ };
41
+ }
42
+ const href = (path: string) => (editor ? "#" : path);
43
+ const children: VNode[] = items.map((item): VNode => {
44
+ switch (item.kind) {
45
+ case "prev":
46
+ return {
47
+ tag: "a",
48
+ attrs: { class: "emvb-pagination-prev", href: href(item.href), rel: "prev" },
49
+ children: [label(node.props.prevText, "Previous")],
50
+ };
51
+ case "next":
52
+ return {
53
+ tag: "a",
54
+ attrs: { class: "emvb-pagination-next", href: href(item.href), rel: "next" },
55
+ children: [label(node.props.nextText, "Next")],
56
+ };
57
+ case "gap":
58
+ return {
59
+ tag: "span",
60
+ attrs: { class: "emvb-pagination-gap", "aria-hidden": "true" },
61
+ children: ["…"],
62
+ };
63
+ default:
64
+ return {
65
+ tag: "a",
66
+ attrs: {
67
+ class: "emvb-pagination-page",
68
+ href: href(item.href),
69
+ ...(item.current ? { "aria-current": "page" } : {}),
70
+ },
71
+ children: [String(item.n)],
72
+ };
73
+ }
74
+ });
75
+ return { tag: "nav", attrs: { ...attrs, "aria-label": "Pagination" }, children };
76
+ }
@@ -28,6 +28,10 @@ export function renderSection(
28
28
  return { tag: "div", attrs, children: ["Synced section"] };
29
29
  }
30
30
  const templateNodes = template.root.children;
31
- const next: ThemeDynamicData = { ...dynamic, sectionStack: [...stack, partId] };
31
+ const next: ThemeDynamicData = {
32
+ ...dynamic,
33
+ sectionStack: [...stack, partId],
34
+ idOrigin: `${dynamic?.idOrigin ?? ""}/s:${partId}`,
35
+ };
32
36
  return ELEMENTS.section.build(node as never, attrs, ctx.children(templateNodes, next));
33
37
  }
@@ -1,10 +1,9 @@
1
+ import { MAX_TABS } from "../limits.ts";
1
2
  import { isTabPanelNode, type TabsNode } from "../schema/layout.ts";
2
3
  import type { ThemeDynamicData } from "../theme/dynamic.ts";
3
4
  import type { RenderContext } from "./context.ts";
4
5
  import type { VNode } from "./vnode.ts";
5
6
 
6
- const MAX_TABS = 12;
7
-
8
7
  /** CSS-only tabs (radio inputs and labels) that the optional tabs script enhances. */
9
8
  export function renderTabs(
10
9
  node: TabsNode,
@@ -14,7 +13,7 @@ export function renderTabs(
14
13
  dynamic: ThemeDynamicData | undefined,
15
14
  ): VNode {
16
15
  const panels = node.children.filter(isTabPanelNode).slice(0, MAX_TABS);
17
- const group = `emvb-tabs-${id ?? "x"}`;
16
+ const group = ctx.uniqueId(`emvb-tabs-${id ?? "x"}`);
18
17
  const inputs: VNode[] = [];
19
18
  const labels: VNode[] = [];
20
19
  const panelNodes: VNode[] = [];
@@ -63,7 +62,12 @@ export function renderTabs(
63
62
  ...inputs,
64
63
  {
65
64
  tag: "div",
66
- attrs: { class: "emvb-tab-list", role: "tablist", "aria-orientation": "horizontal" },
65
+ // W-275: a tablist needs tabs (axe aria-required-children); Tabs with no panels yet get
66
+ // a plain box.
67
+ attrs:
68
+ labels.length > 0
69
+ ? { class: "emvb-tab-list", role: "tablist", "aria-orientation": "horizontal" }
70
+ : { class: "emvb-tab-list" },
67
71
  children: labels,
68
72
  },
69
73
  { tag: "div", attrs: { class: "emvb-tab-panels" }, children: panelNodes },
@@ -68,7 +68,7 @@ const TAGS = new Set([
68
68
  const VOID = new Set(["hr", "img", "input"]);
69
69
  // iframe/video are not void — they need closing tags.
70
70
  const ATTR_NAME =
71
- /^(?:class|id|href|src|alt|width|height|loading|decoding|role|type|checked|target|rel|aria-[a-z][a-z0-9-]*|title|allow|referrerpolicy|preload|controls|allowfullscreen|xmlns|viewBox|fill|stroke|stroke-width|stroke-linecap|stroke-linejoin|stroke-dasharray|stroke-opacity|fill-opacity|opacity|transform|focusable|d|cx|cy|r|x|y|x1|y1|x2|y2|points|rx|ry|xlink:href|preserveAspectRatio|gradientUnits|gradientTransform|offset|stop-color|stop-opacity|clipPathUnits|maskUnits|maskContentUnits|patternUnits|patternContentUnits|patternTransform|markerUnits|markerWidth|markerHeight|refX|refY|orient|font-size|font-family|font-weight|text-anchor|dominant-baseline|dx|dy|clip-path|method|action|name|value|placeholder|for|tabindex|autocomplete|open|datetime|muted|loop|playsinline|autoplay|data-[a-z][a-z0-9-]*)$/;
71
+ /^(?:class|id|href|src|alt|width|height|loading|decoding|fetchpriority|dir|role|type|checked|target|rel|aria-[a-z][a-z0-9-]*|title|allow|referrerpolicy|preload|controls|allowfullscreen|xmlns|viewBox|fill|stroke|stroke-width|stroke-linecap|stroke-linejoin|stroke-dasharray|stroke-opacity|fill-opacity|opacity|transform|focusable|d|cx|cy|r|x|y|x1|y1|x2|y2|points|rx|ry|xlink:href|preserveAspectRatio|gradientUnits|gradientTransform|offset|stop-color|stop-opacity|clipPathUnits|maskUnits|maskContentUnits|patternUnits|patternContentUnits|patternTransform|markerUnits|markerWidth|markerHeight|refX|refY|orient|font-size|font-family|font-weight|text-anchor|dominant-baseline|dx|dy|clip-path|method|action|name|value|placeholder|for|tabindex|autocomplete|open|datetime|muted|loop|playsinline|autoplay|required|novalidate|minlength|maxlength|min|max|pattern|data-[a-z][a-z0-9-]*)$/;
72
72
 
73
73
  export const isAllowedTag = (tag: string) => TAGS.has(tag);
74
74
  export const isAllowedAttr = (name: string) => ATTR_NAME.test(name);