@perkyzz/emvb 0.2.1 → 0.4.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 (150) hide show
  1. package/README.md +4 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +3 -1
  4. package/src/admin/access/role.ts +9 -3
  5. package/src/admin/api.ts +17 -7
  6. package/src/admin/content-api.ts +7 -51
  7. package/src/admin/content-item.ts +22 -0
  8. package/src/admin/design-api.ts +30 -0
  9. package/src/admin/editor/A11yCopilot.tsx +126 -0
  10. package/src/admin/editor/CommandPalette.tsx +118 -0
  11. package/src/admin/editor/Editor.tsx +188 -152
  12. package/src/admin/editor/EditorOverlay.tsx +9 -1
  13. package/src/admin/editor/PerfMeter.tsx +121 -0
  14. package/src/admin/editor/ShareLink.tsx +164 -0
  15. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  16. package/src/admin/editor/Timeline.tsx +287 -0
  17. package/src/admin/editor/TopBar.tsx +4 -0
  18. package/src/admin/editor/canvas/CanvasFrame.tsx +62 -370
  19. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  20. package/src/admin/editor/canvas/SelectionOverlay.tsx +87 -47
  21. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  22. package/src/admin/editor/canvas/drop-line.ts +24 -0
  23. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  24. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  25. package/src/admin/editor/collection-previews.ts +114 -0
  26. package/src/admin/editor/editor-chrome.tsx +346 -0
  27. package/src/admin/editor/editor-commands.ts +360 -0
  28. package/src/admin/editor/editor-css.ts +5 -3
  29. package/src/admin/editor/element-chrome.ts +89 -0
  30. package/src/admin/editor/feature-css.ts +105 -0
  31. package/src/admin/editor/host.ts +35 -0
  32. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  33. package/src/admin/editor/icons/library.ts +29 -19
  34. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  35. package/src/admin/editor/live-data.tsx +71 -0
  36. package/src/admin/editor/palette-items.ts +136 -0
  37. package/src/admin/editor/palette.ts +68 -0
  38. package/src/admin/editor/panels/AddPanel.tsx +48 -68
  39. package/src/admin/editor/panels/ClassesSection.tsx +5 -1
  40. package/src/admin/editor/panels/ColorControl.tsx +2 -10
  41. package/src/admin/editor/panels/ElementPanel.tsx +74 -102
  42. package/src/admin/editor/panels/LayersPanel.tsx +72 -63
  43. package/src/admin/editor/panels/LeftPanel.tsx +4 -1
  44. package/src/admin/editor/panels/SettingsPanel.tsx +13 -0
  45. package/src/admin/editor/panels/SiteStylesDrawer.tsx +18 -10
  46. package/src/admin/editor/panels/TokenScales.tsx +168 -0
  47. package/src/admin/editor/panels/VariableSection.tsx +10 -14
  48. package/src/admin/editor/panels/inline-error.tsx +11 -0
  49. package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
  50. package/src/admin/editor/panels/settings/AudienceEditor.tsx +285 -0
  51. package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
  52. package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
  53. package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
  54. package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
  55. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  56. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  57. package/src/admin/editor/panels/settings/MotionControl.tsx +252 -0
  58. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  59. package/src/admin/editor/panels/settings/StyleRow.tsx +26 -2
  60. package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
  61. package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
  62. package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
  63. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  64. package/src/admin/editor/panels/settings/length-units.ts +16 -5
  65. package/src/admin/editor/panels/settings/style-sections.ts +7 -2
  66. package/src/admin/editor/panels/style-target.ts +105 -0
  67. package/src/admin/editor/section-templates.ts +43 -21
  68. package/src/admin/editor/shortcuts.ts +6 -1
  69. package/src/admin/editor/store.ts +10 -1
  70. package/src/admin/editor/useClipboardActions.ts +1 -1
  71. package/src/admin/editor/useEditorCommands.ts +61 -13
  72. package/src/admin/editor/useEditorData.ts +7 -1
  73. package/src/admin/editor/useEditorShortcuts.ts +30 -14
  74. package/src/admin/editor/useNodeActions.ts +44 -16
  75. package/src/admin/forms-api.ts +17 -6
  76. package/src/admin/icon-uploads-api.ts +18 -0
  77. package/src/admin/theme-api.ts +5 -18
  78. package/src/admin/ui.ts +4 -4
  79. package/src/astro/content-port.ts +24 -0
  80. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  81. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  82. package/src/astro/forms/client.ts +1 -0
  83. package/src/astro/forms-definitions.ts +24 -11
  84. package/src/astro/index.ts +1 -0
  85. package/src/astro/render-session.ts +85 -0
  86. package/src/astro/request-data.ts +109 -0
  87. package/src/astro/resolve-theme.ts +184 -64
  88. package/src/astro/resolve.ts +63 -16
  89. package/src/astro/theme-posts.ts +48 -5
  90. package/src/astro/visitor.ts +204 -0
  91. package/src/constants.ts +1 -1
  92. package/src/core/a11y/audit.ts +282 -0
  93. package/src/core/arrange.ts +150 -34
  94. package/src/core/audience/rules.ts +124 -0
  95. package/src/core/audience/variants.ts +51 -0
  96. package/src/core/canvas-styles.ts +24 -0
  97. package/src/core/clipboard.ts +11 -32
  98. package/src/core/css/generate.ts +29 -2
  99. package/src/core/css/print.ts +12 -0
  100. package/src/core/css/scope.ts +3 -3
  101. package/src/core/css/trace.ts +169 -0
  102. package/src/core/css-keywords.ts +83 -0
  103. package/src/core/data/bindings.ts +255 -0
  104. package/src/core/design/classes.ts +13 -15
  105. package/src/core/design/diff.ts +55 -0
  106. package/src/core/design/merge.ts +127 -0
  107. package/src/core/design/tokens.ts +127 -0
  108. package/src/core/design/variables.ts +25 -21
  109. package/src/core/elements/dynamic-elements.ts +117 -2
  110. package/src/core/elements/form-elements.ts +1 -0
  111. package/src/core/elements/index.ts +185 -7
  112. package/src/core/forms/binding.ts +4 -13
  113. package/src/core/history/diff.ts +152 -0
  114. package/src/core/index.ts +121 -0
  115. package/src/core/local-style.ts +27 -0
  116. package/src/core/migrate/index.ts +12 -4
  117. package/src/core/nesting.ts +4 -22
  118. package/src/core/perf/meter.ts +160 -0
  119. package/src/core/perf/scripts.ts +61 -0
  120. package/src/core/recipes/index.ts +433 -0
  121. package/src/core/record.ts +3 -0
  122. package/src/core/render/context.ts +2 -0
  123. package/src/core/render/dynamic-post.ts +1 -2
  124. package/src/core/render/form.ts +133 -10
  125. package/src/core/render/index.ts +206 -17
  126. package/src/core/render/loop.ts +54 -7
  127. package/src/core/render/pagination.ts +9 -1
  128. package/src/core/render/vnode.ts +12 -2
  129. package/src/core/sanitize/css.ts +129 -80
  130. package/src/core/sanitize/motion.ts +129 -0
  131. package/src/core/sanitize/svg.ts +8 -3
  132. package/src/core/sanitize/url.ts +10 -1
  133. package/src/core/schema/design.ts +29 -8
  134. package/src/core/schema/layout.ts +291 -169
  135. package/src/core/schema/motion.ts +14 -0
  136. package/src/core/schema/style.ts +101 -66
  137. package/src/core/share/link.ts +187 -0
  138. package/src/core/tabs/presence.ts +7 -17
  139. package/src/core/theme/dynamic.ts +242 -32
  140. package/src/core/theme/float.ts +1 -1
  141. package/src/core/theme/pagination.ts +56 -0
  142. package/src/core/tree-ops.ts +57 -0
  143. package/src/index.ts +14 -2
  144. package/src/server/design-routes.ts +4 -1
  145. package/src/server/icon-routes.ts +68 -16
  146. package/src/server/plugin.ts +8 -2
  147. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  148. package/src/admin/editor/icons/sets/lucide.json +0 -1
  149. package/src/admin/editor/icons/sets/remix.json +0 -1
  150. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -0,0 +1,127 @@
1
+ import { emptyDesign, type DesignSystem } from "../schema/design.ts";
2
+
3
+ export type DesignConflict = { kind: "variable" | "class" | "setting"; name: string };
4
+
5
+ const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
6
+
7
+ type Named = { id: string; name: string };
8
+
9
+ /**
10
+ * Replays `ours` (what this tab tried to save) onto `theirs` (what the server has now),
11
+ * starting from `base` (what this tab last loaded). A list item this tab changed is kept
12
+ * when the server still has the base copy. When both sides changed the same item, the
13
+ * server copy stays and the name is reported. Nothing is overwritten silently.
14
+ */
15
+ export function mergeDesign(
16
+ base: DesignSystem | undefined,
17
+ ours: DesignSystem,
18
+ theirs: DesignSystem,
19
+ ): { design: DesignSystem; conflicts: DesignConflict[] } {
20
+ const from = base ?? emptyDesign();
21
+ const conflicts: DesignConflict[] = [];
22
+ const design: DesignSystem = {
23
+ ...theirs,
24
+ variables: {
25
+ colors: mergeList(
26
+ from.variables.colors,
27
+ ours.variables.colors,
28
+ theirs.variables.colors,
29
+ conflicts,
30
+ "variable",
31
+ ),
32
+ fonts: mergeList(
33
+ from.variables.fonts,
34
+ ours.variables.fonts,
35
+ theirs.variables.fonts,
36
+ conflicts,
37
+ "variable",
38
+ ),
39
+ fontSizes: mergeList(
40
+ from.variables.fontSizes,
41
+ ours.variables.fontSizes,
42
+ theirs.variables.fontSizes,
43
+ conflicts,
44
+ "variable",
45
+ ),
46
+ spacings: mergeList(
47
+ from.variables.spacings,
48
+ ours.variables.spacings,
49
+ theirs.variables.spacings,
50
+ conflicts,
51
+ "variable",
52
+ ),
53
+ },
54
+ classes: mergeList(from.classes, ours.classes, theirs.classes, conflicts, "class"),
55
+ fluidRange: pickSetting(
56
+ from.fluidRange,
57
+ ours.fluidRange,
58
+ theirs.fluidRange,
59
+ conflicts,
60
+ "Fluid range",
61
+ ),
62
+ direction: pickSetting(
63
+ from.direction,
64
+ ours.direction,
65
+ theirs.direction,
66
+ conflicts,
67
+ "Direction",
68
+ ),
69
+ defaults: pickSetting(from.defaults, ours.defaults, theirs.defaults, conflicts, "Tag defaults"),
70
+ };
71
+ return { design, conflicts };
72
+ }
73
+
74
+ function mergeList<T extends Named>(
75
+ base: T[] | undefined,
76
+ ours: T[] | undefined,
77
+ theirs: T[] | undefined,
78
+ conflicts: DesignConflict[],
79
+ kind: "variable" | "class",
80
+ ): T[] {
81
+ const baseItems = base ?? [];
82
+ const ourItems = ours ?? [];
83
+ const theirItems = theirs ?? [];
84
+ const by = (list: T[]) => new Map(list.map((item) => [item.id, item]));
85
+ const baseBy = by(baseItems);
86
+ const oursBy = by(ourItems);
87
+ const theirsBy = by(theirItems);
88
+ const result: T[] = [];
89
+ const seen = new Set<string>();
90
+ const take = (id: string) => {
91
+ if (seen.has(id)) return;
92
+ seen.add(id);
93
+ const baseItem = baseBy.get(id);
94
+ const ourItem = oursBy.get(id);
95
+ const theirItem = theirsBy.get(id);
96
+ const weChanged = !same(baseItem, ourItem);
97
+ const theyChanged = !same(baseItem, theirItem);
98
+ if (!weChanged) {
99
+ if (theirItem) result.push(theirItem);
100
+ return;
101
+ }
102
+ if (!theyChanged || same(ourItem, theirItem)) {
103
+ if (ourItem) result.push(ourItem);
104
+ return;
105
+ }
106
+ conflicts.push({ kind, name: ourItem?.name ?? theirItem?.name ?? id });
107
+ if (theirItem) result.push(theirItem);
108
+ };
109
+ for (const item of theirItems) take(item.id);
110
+ for (const item of ourItems) take(item.id);
111
+ return result;
112
+ }
113
+
114
+ function pickSetting<T>(
115
+ base: T | undefined,
116
+ ours: T | undefined,
117
+ theirs: T | undefined,
118
+ conflicts: DesignConflict[],
119
+ name: string,
120
+ ): T | undefined {
121
+ const weChanged = !same(base, ours);
122
+ const theyChanged = !same(base, theirs);
123
+ if (!weChanged) return theirs;
124
+ if (!theyChanged || same(ours, theirs)) return ours;
125
+ conflicts.push({ kind: "setting", name });
126
+ return theirs;
127
+ }
@@ -0,0 +1,127 @@
1
+ import type { DesignSystem, FluidRange, LengthVariable } from "../schema/design.ts";
2
+
3
+ /** Screen widths fluid sizes grow between when the site sets none (W-316). */
4
+ export const DEFAULT_FLUID_RANGE: FluidRange = { minWidth: 360, maxWidth: 1280 };
5
+
6
+ const round = (n: number, places = 4) => Number(n.toFixed(places));
7
+
8
+ /**
9
+ * `clamp()` growing from `min` px at the range's small screen to `max` px at its large one
10
+ * (W-316), in rem so it follows the visitor's font size. Equal sizes give a plain rem value.
11
+ */
12
+ export function fluidClamp(
13
+ min: number,
14
+ max: number,
15
+ range: FluidRange = DEFAULT_FLUID_RANGE,
16
+ ): string {
17
+ const lo = Math.min(min, max);
18
+ const hi = Math.max(min, max);
19
+ if (lo === hi || range.maxWidth <= range.minWidth) return `${round(max / 16)}rem`;
20
+ const slope = (max - min) / (range.maxWidth - range.minWidth);
21
+ const intercept = min - slope * range.minWidth;
22
+ return `clamp(${round(lo / 16)}rem, ${round(intercept / 16)}rem + ${round(slope * 100)}vw, ${round(hi / 16)}rem)`;
23
+ }
24
+
25
+ /** Musical ratios type scales use, with their names (W-316). */
26
+ export const SCALE_RATIOS = [
27
+ { value: 1.125, label: "Major second · 1.125" },
28
+ { value: 1.2, label: "Minor third · 1.2" },
29
+ { value: 1.25, label: "Major third · 1.25" },
30
+ { value: 1.333, label: "Perfect fourth · 1.333" },
31
+ { value: 1.4, label: "Augmented fourth · 1.4" },
32
+ { value: 1.5, label: "Perfect fifth · 1.5" },
33
+ { value: 1.618, label: "Golden ratio · 1.618" },
34
+ ] as const;
35
+
36
+ export type ScaleInput = {
37
+ /** Body size on large screens, px. */
38
+ base: number;
39
+ ratio: number;
40
+ /** Body size on small screens, px; unset = not fluid. */
41
+ minBase?: number;
42
+ /** Ratio on small screens (usually smaller); unset = `ratio`. */
43
+ minRatio?: number;
44
+ };
45
+
46
+ const TYPE_STEPS = [
47
+ { id: "fs-xs", name: "Text XS", step: -2 },
48
+ { id: "fs-s", name: "Text S", step: -1 },
49
+ { id: "fs-m", name: "Text M", step: 0 },
50
+ { id: "fs-l", name: "Text L", step: 1 },
51
+ { id: "fs-xl", name: "Heading S", step: 2 },
52
+ { id: "fs-2xl", name: "Heading M", step: 3 },
53
+ { id: "fs-3xl", name: "Heading L", step: 4 },
54
+ { id: "fs-4xl", name: "Display", step: 5 },
55
+ ] as const;
56
+
57
+ const SPACE_STEPS = [
58
+ { id: "space-3xs", name: "Space 3XS", times: 0.25 },
59
+ { id: "space-2xs", name: "Space 2XS", times: 0.5 },
60
+ { id: "space-xs", name: "Space XS", times: 0.75 },
61
+ { id: "space-s", name: "Space S", times: 1 },
62
+ { id: "space-m", name: "Space M", times: 1.5 },
63
+ { id: "space-l", name: "Space L", times: 2 },
64
+ { id: "space-xl", name: "Space XL", times: 3 },
65
+ { id: "space-2xl", name: "Space 2XL", times: 4 },
66
+ { id: "space-3xl", name: "Space 3XL", times: 6 },
67
+ ] as const;
68
+
69
+ const valid = (n: number | undefined, lo: number, hi: number): n is number =>
70
+ typeof n === "number" && Number.isFinite(n) && n >= lo && n <= hi;
71
+
72
+ function token(id: string, name: string, max: number, min: number | undefined): LengthVariable {
73
+ const big = round(Math.min(1000, max), 2);
74
+ return {
75
+ id,
76
+ name,
77
+ value: { value: big, unit: "px" },
78
+ ...(min !== undefined && round(min, 2) !== big
79
+ ? { fluid: { min: round(Math.min(1000, min), 2), max: big } }
80
+ : {}),
81
+ };
82
+ }
83
+
84
+ /**
85
+ * A type scale from a base size and a ratio (W-316): eight sizes from Text XS to Display. With a
86
+ * small-screen base (and ratio), each size is fluid between the two.
87
+ */
88
+ export function typeScale(input: ScaleInput): LengthVariable[] {
89
+ if (!valid(input.base, 8, 64) || !valid(input.ratio, 1.01, 2)) return [];
90
+ const minBase = valid(input.minBase, 8, 64) ? input.minBase : undefined;
91
+ const minRatio = valid(input.minRatio, 1.01, 2) ? input.minRatio : input.ratio;
92
+ return TYPE_STEPS.map(({ id, name, step }) =>
93
+ token(
94
+ id,
95
+ name,
96
+ input.base * input.ratio ** step,
97
+ minBase === undefined ? undefined : minBase * minRatio ** step,
98
+ ),
99
+ );
100
+ }
101
+
102
+ /** A spacing scale from one base gap (W-316): nine steps from 3XS to 3XL; fluid like type. */
103
+ export function spaceScale(input: { base: number; minBase?: number }): LengthVariable[] {
104
+ if (!valid(input.base, 2, 64)) return [];
105
+ const minBase = valid(input.minBase, 2, 64) ? input.minBase : undefined;
106
+ return SPACE_STEPS.map(({ id, name, times }) =>
107
+ token(id, name, input.base * times, minBase === undefined ? undefined : minBase * times),
108
+ );
109
+ }
110
+
111
+ /**
112
+ * Adds generated tokens to the site's font sizes or spacing (W-316). A token whose id exists
113
+ * replaces it in place, so elements using it pick up the new size; others are appended.
114
+ */
115
+ export function applyTokens(
116
+ design: DesignSystem,
117
+ list: "fontSizes" | "spacings",
118
+ tokens: LengthVariable[],
119
+ ): DesignSystem {
120
+ const current = design.variables[list] ?? [];
121
+ const byId = new Map(tokens.map((t) => [t.id, t]));
122
+ const replaced = current.map((v) => byId.get(v.id) ?? v);
123
+ const have = new Set(current.map((v) => v.id));
124
+ const limit = list === "fontSizes" ? 50 : 100;
125
+ const added = tokens.filter((t) => !have.has(t.id)).slice(0, Math.max(0, limit - current.length));
126
+ return { ...design, variables: { ...design.variables, [list]: [...replaced, ...added] } };
127
+ }
@@ -1,9 +1,9 @@
1
1
  import type { DesignSystem } from "../schema/design.ts";
2
- import type { Layout, LayoutNode } from "../schema/layout.ts";
2
+ import type { Layout } from "../schema/layout.ts";
3
3
  import { cleanClassName } from "./classes.ts";
4
4
  import { STYLE_STATES } from "../schema/state-names.ts";
5
5
  import type { DeviceStyles, StyleProps, StyleStates } from "../schema/style.ts";
6
- import { nodeChildren, slugify, updateNode } from "../tree-ops.ts";
6
+ import { forEachNode, slugify, updateNode } from "../tree-ops.ts";
7
7
 
8
8
  export type VariableKind = "color" | "font" | "fontSize" | "spacing";
9
9
 
@@ -32,26 +32,35 @@ export function refMatchesKind(ref: VariableRefLike, kind: VariableKind): boolea
32
32
  const matches = (value: unknown, id: string, kind: VariableKind | undefined) =>
33
33
  isVariableRef(value) && value.var === id && (kind === undefined || refMatchesKind(value, kind));
34
34
 
35
- /** Nested colour refs: the box shadow (W-088), and gradient stops and the overlay (W-094). */
36
- const shadowColorMatches = (style: StyleProps, id: string, kind: VariableKind | undefined) =>
37
- matches(style.boxShadow?.color, id, kind);
35
+ const NESTED_COLOR_KEYS = new Set(["boxShadow", "iconShadow", "gradient", "overlay"]);
38
36
 
39
- function collectStyleUsages(
37
+ /** Every value that can be a variable, including nested colours (W-356). */
38
+ export function forEachStyleRef(
40
39
  style: StyleProps | undefined,
41
- id: string,
42
- kind: VariableKind | undefined,
43
- hit: (prop: string) => void,
40
+ visit: (value: unknown, path: string) => void,
44
41
  ): void {
45
42
  if (!style) return;
46
43
  for (const [prop, value] of Object.entries(style)) {
47
- if (matches(value, id, kind)) hit(prop);
44
+ if (NESTED_COLOR_KEYS.has(prop)) continue;
45
+ visit(value, prop);
48
46
  }
49
- if (shadowColorMatches(style, id, kind)) hit("boxShadow.color");
50
- if (matches(style.iconShadow?.color, id, kind)) hit("iconShadow.color");
47
+ if (style.boxShadow) visit(style.boxShadow.color, "boxShadow.color");
48
+ if (style.iconShadow) visit(style.iconShadow.color, "iconShadow.color");
51
49
  style.gradient?.stops.forEach((stop, index) => {
52
- if (matches(stop.color, id, kind)) hit(`gradient.stops.${index}`);
50
+ visit(stop.color, `gradient.stops.${index}`);
51
+ });
52
+ if (style.overlay) visit(style.overlay.color, "overlay.color");
53
+ }
54
+
55
+ function collectStyleUsages(
56
+ style: StyleProps | undefined,
57
+ id: string,
58
+ kind: VariableKind | undefined,
59
+ hit: (prop: string) => void,
60
+ ): void {
61
+ forEachStyleRef(style, (value, path) => {
62
+ if (matches(value, id, kind)) hit(path);
53
63
  });
54
- if (matches(style.overlay?.color, id, kind)) hit("overlay.color");
55
64
  }
56
65
 
57
66
  const RESPONSIVE = ["tablet", "mobile"] as const;
@@ -72,11 +81,6 @@ function collectAllUsages(
72
81
  }
73
82
  }
74
83
 
75
- function walkNodes(node: LayoutNode, visit: (node: LayoutNode) => void): void {
76
- visit(node);
77
- for (const child of nodeChildren(node)) walkNodes(child, visit);
78
- }
79
-
80
84
  /** Find every style property on `layout` that references variable `id` (optionally of `kind`). */
81
85
  export function findVariableUsages(
82
86
  layout: Layout,
@@ -84,7 +88,7 @@ export function findVariableUsages(
84
88
  kind?: VariableKind,
85
89
  ): VariableUsage[] {
86
90
  const usages: VariableUsage[] = [];
87
- walkNodes(layout.root, (node) => {
91
+ forEachNode(layout.root, (node) => {
88
92
  collectAllUsages(node, id, kind, (prop) => {
89
93
  usages.push({ nodeId: node.id, prop });
90
94
  });
@@ -123,7 +127,7 @@ function stripRefsFromStyle(
123
127
  delete next[prop];
124
128
  changed = true;
125
129
  }
126
- if (style.boxShadow && shadowColorMatches(style, id, kind)) {
130
+ if (style.boxShadow && matches(style.boxShadow.color, id, kind)) {
127
131
  const { color: _drop, ...shadow } = style.boxShadow;
128
132
  next["boxShadow"] = shadow;
129
133
  changed = true;
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ LoopEmptyNode,
2
3
  LoopNode,
3
4
  SectionNode,
4
5
  PostAuthorNode,
@@ -151,9 +152,21 @@ export const postLink: ElementDefinition<PostLinkNode> = {
151
152
  build: (_node, attrs) => ({ tag: "a", attrs: { ...attrs, href: "#" }, children: ["Post link"] }),
152
153
  };
153
154
 
155
+ /** How a Loop shows its items (W-308). */
156
+ const DISPLAY_OPTIONS = [
157
+ { value: "list", label: "List" },
158
+ { value: "grid", label: "Grid" },
159
+ { value: "cards", label: "Cards" },
160
+ ];
161
+
154
162
  export const loop: ElementDefinition<LoopNode> = {
155
163
  baseCss:
156
- ".emvb-loop{display:flex;flex-direction:column;min-width:0;gap:1rem}.emvb-loop[data-emvb-loop-empty]{min-height:48px;padding:12px;color:var(--text-color-kumo-subtle,#666);background:var(--color-kumo-tint,#eee)}",
164
+ ".emvb-loop{display:flex;flex-direction:column;min-width:0;gap:1rem}.emvb-loop[data-emvb-loop-empty]{min-height:48px;padding:12px;color:var(--text-color-kumo-subtle,#666);background:var(--color-kumo-tint,#eee)}" +
165
+ // W-308: grid and cards share one item design; phones get one column.
166
+ ".emvb-loop-grid,.emvb-loop-cards{display:grid;grid-template-columns:repeat(var(--emvb-loop-columns,3),minmax(0,1fr))}" +
167
+ ".emvb-loop-cards>.emvb-loop-item{padding:1rem;border:1px solid color-mix(in srgb,currentColor 15%,transparent);border-radius:12px;background:color-mix(in srgb,currentColor 3%,transparent)}" +
168
+ ".emvb-loop-grid>.emvb-loop-empty,.emvb-loop-cards>.emvb-loop-empty{grid-column:1/-1}" +
169
+ "@media (max-width: 767px){.emvb-loop-grid,.emvb-loop-cards{grid-template-columns:minmax(0,1fr)}}",
157
170
  defaults: () => ({ type: "loop", props: {}, children: [] }),
158
171
  descriptor: {
159
172
  type: "loop",
@@ -161,6 +174,78 @@ export const loop: ElementDefinition<LoopNode> = {
161
174
  group: "dynamic",
162
175
  defaultTab: "content",
163
176
  fields: [
177
+ {
178
+ key: "collection",
179
+ kind: "text",
180
+ label: "Collection",
181
+ optional: true,
182
+ message:
183
+ "A collection's slug, such as posts or team, lists its entries on any page. Leave it empty on an Archive part to list the archive's posts.",
184
+ },
185
+ {
186
+ key: "display",
187
+ kind: "select",
188
+ label: "Show as",
189
+ optional: true,
190
+ options: DISPLAY_OPTIONS,
191
+ },
192
+ {
193
+ key: "columns",
194
+ kind: "int",
195
+ max: 6,
196
+ label: "Columns",
197
+ optional: true,
198
+ message: "1 to 6 columns for Grid and Cards (one on phones). Leave it empty for 3.",
199
+ },
200
+ {
201
+ key: "limit",
202
+ kind: "int",
203
+ max: 50,
204
+ label: "Entries to show",
205
+ optional: true,
206
+ message: "1 to 50 entries from the collection. Leave it empty for 6.",
207
+ },
208
+ {
209
+ key: "order",
210
+ kind: "select",
211
+ label: "Order",
212
+ optional: true,
213
+ options: [
214
+ { value: "newest", label: "Newest first" },
215
+ { value: "oldest", label: "Oldest first" },
216
+ { value: "title", label: "By title" },
217
+ ],
218
+ },
219
+ {
220
+ key: "permalink",
221
+ kind: "text",
222
+ label: "Link pattern",
223
+ optional: true,
224
+ message:
225
+ "Where each entry links, e.g. /team/{slug}; {slug} and {id} are filled in. Leave it empty for /collection/{slug}.",
226
+ },
227
+ {
228
+ key: "imageField",
229
+ kind: "text",
230
+ label: "Image field",
231
+ optional: true,
232
+ message: "The field Post Image shows, e.g. photo. Leave it empty for the featured image.",
233
+ },
234
+ {
235
+ key: "excerptField",
236
+ kind: "text",
237
+ label: "Excerpt field",
238
+ optional: true,
239
+ message: "The field Post Excerpt shows, e.g. role. Leave it empty for the excerpt.",
240
+ },
241
+ {
242
+ key: "filter",
243
+ kind: "text",
244
+ label: "Only entries where",
245
+ optional: true,
246
+ message:
247
+ "field=value pairs separated by ;, e.g. category=news; team=design. A taxonomy works too. The same field twice matches either value.",
248
+ },
164
249
  {
165
250
  key: "itemPartId",
166
251
  kind: "text",
@@ -180,12 +265,33 @@ export const loop: ElementDefinition<LoopNode> = {
180
265
  },
181
266
  ],
182
267
  },
268
+ build: (node, attrs, children) => {
269
+ const display = node.props.display;
270
+ const extra = display === "grid" || display === "cards" ? ` emvb-loop-${display}` : "";
271
+ return {
272
+ tag: "div",
273
+ attrs: { ...attrs, class: `${attrs.class ?? ""}${extra}`.trim() },
274
+ children,
275
+ };
276
+ },
277
+ };
278
+
279
+ export const loopEmpty: ElementDefinition<LoopEmptyNode> = {
280
+ baseCss: ".emvb-loop-empty{display:flex;flex-direction:column;min-width:0;gap:.5rem}",
281
+ defaults: () => ({ type: "loop-empty", props: {}, children: [] }),
282
+ descriptor: {
283
+ type: "loop-empty",
284
+ name: "Empty state",
285
+ group: "dynamic",
286
+ defaultTab: "style",
287
+ fields: [],
288
+ },
183
289
  build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
184
290
  };
185
291
 
186
292
  export const pagination: ElementDefinition<PaginationNode> = {
187
293
  baseCss:
188
- ".emvb-pagination{display:flex;flex-wrap:wrap;align-items:center;gap:.5rem}.emvb-pagination a{color:inherit}.emvb-pagination a[aria-current=page]{font-weight:700;text-decoration:none}",
294
+ ".emvb-pagination{display:flex;flex-wrap:wrap;align-items:center;gap:.5rem}.emvb-pagination a{color:inherit}.emvb-pagination a[aria-current=page]{font-weight:700;text-decoration:none}.emvb-pagination-count{opacity:.75}",
189
295
  defaults: () => ({ type: "pagination", props: {} }),
190
296
  descriptor: {
191
297
  type: "pagination",
@@ -195,6 +301,15 @@ export const pagination: ElementDefinition<PaginationNode> = {
195
301
  fields: [
196
302
  { key: "prevText", kind: "text", label: "Previous text", optional: true },
197
303
  { key: "nextText", kind: "text", label: "Next text", optional: true },
304
+ { key: "showCount", kind: "boolean", label: "Show page count", optional: true },
305
+ {
306
+ key: "countText",
307
+ kind: "text",
308
+ label: "Count text",
309
+ optional: true,
310
+ message:
311
+ '{page} and {total} are filled in. EmDash 1.2 doesn\'t report a total, so the count shows "Page N" until it does.',
312
+ },
198
313
  ],
199
314
  },
200
315
  // Rendered by core/render/pagination.ts from the archive's page data (W-222).
@@ -50,6 +50,7 @@ const FORM_FIELD_CSS =
50
50
  export const form: ElementDefinition<FormNode> = {
51
51
  baseCss:
52
52
  ".emvb-form{display:flex;flex-direction:column;gap:12px;min-width:0}.emvb-form-unbound{min-height:48px;padding:12px;color:var(--text-color-kumo-subtle,#666);background:var(--color-kumo-tint,#eee)}.ec-form-hp{position:absolute;left:-9999px}" +
53
+ ":where(.emvb-form-paused){padding:12px 16px;border:1px solid rgba(128,128,128,.5);border:1px solid color-mix(in srgb,currentColor 25%,transparent);border-radius:6px}:where(.emvb-form-paused p){margin:0}" +
53
54
  FORM_FIELD_CSS,
54
55
  defaults: () => ({ type: "form", props: { formId: "" }, children: [] }),
55
56
  descriptor: fieldDescriptor("form", "Form", [