@perkyzz/emvb 0.9.0 → 1.1.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 (187) hide show
  1. package/README.md +10 -1
  2. package/package.json +2 -2
  3. package/src/admin/agents-api.ts +45 -0
  4. package/src/admin/bulk-api.ts +67 -0
  5. package/src/admin/content-api.ts +10 -6
  6. package/src/admin/copy-rich-text.ts +119 -0
  7. package/src/admin/dialog-tab-wrap.ts +78 -0
  8. package/src/admin/editor/A11yCopilot.tsx +3 -1
  9. package/src/admin/editor/Editor.tsx +311 -250
  10. package/src/admin/editor/Timeline.tsx +8 -3
  11. package/src/admin/editor/TopBar.tsx +29 -7
  12. package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
  13. package/src/admin/editor/canvas/DeviceBar.tsx +31 -10
  14. package/src/admin/editor/canvas/canvas-scale.ts +3 -3
  15. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  16. package/src/admin/editor/co-design.ts +190 -0
  17. package/src/admin/editor/dnd/new-element.ts +48 -4
  18. package/src/admin/editor/editor-chrome.tsx +8 -6
  19. package/src/admin/editor/editor-commands.ts +15 -4
  20. package/src/admin/editor/editor-css.ts +2 -1
  21. package/src/admin/editor/element-chrome.ts +3 -1
  22. package/src/admin/editor/extension-manifests.ts +20 -0
  23. package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
  24. package/src/admin/editor/extensions-context.tsx +27 -0
  25. package/src/admin/editor/feature-css.ts +17 -0
  26. package/src/admin/editor/palette-items.ts +2 -2
  27. package/src/admin/editor/panels/AddPanel.tsx +31 -1
  28. package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
  29. package/src/admin/editor/panels/ClassesSection.tsx +9 -6
  30. package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
  31. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  32. package/src/admin/editor/panels/ElementPanel.tsx +68 -20
  33. package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
  34. package/src/admin/editor/panels/LayersPanel.tsx +10 -6
  35. package/src/admin/editor/panels/LeftPanel.tsx +33 -5
  36. package/src/admin/editor/panels/PageSettings.tsx +4 -0
  37. package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
  38. package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
  39. package/src/admin/editor/panels/settings/BackgroundControls.tsx +72 -15
  40. package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
  41. package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
  42. package/src/admin/editor/panels/settings/EffectsControls.tsx +183 -10
  43. package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
  44. package/src/admin/editor/panels/settings/IconControls.tsx +25 -11
  45. package/src/admin/editor/panels/settings/LengthRow.tsx +63 -19
  46. package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
  47. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +19 -1
  48. package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
  49. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
  50. package/src/admin/editor/panels/settings/StyleRow.tsx +120 -13
  51. package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
  52. package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
  53. package/src/admin/editor/panels/settings/background-mode.ts +14 -11
  54. package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
  55. package/src/admin/editor/panels/settings/box-sides.ts +22 -14
  56. package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
  57. package/src/admin/editor/panels/settings/length-units.ts +68 -4
  58. package/src/admin/editor/panels/settings/query-style.ts +3 -3
  59. package/src/admin/editor/panels/settings/style-sections.ts +52 -10
  60. package/src/admin/editor/panels/style-target.ts +22 -7
  61. package/src/admin/editor/presence.ts +60 -0
  62. package/src/admin/editor/section-templates.ts +26 -4
  63. package/src/admin/editor/store.ts +14 -4
  64. package/src/admin/editor/useCoDesign.ts +177 -0
  65. package/src/admin/editor/useEditorCommands.ts +7 -5
  66. package/src/admin/editor/useExtensions.ts +45 -0
  67. package/src/admin/editor/useNodeActions.ts +18 -7
  68. package/src/admin/editor/useProposals.ts +81 -0
  69. package/src/admin/export-api.ts +221 -0
  70. package/src/admin/index.tsx +6 -1
  71. package/src/admin/languages-api.ts +61 -0
  72. package/src/admin/pages/AgentSetup.tsx +148 -0
  73. package/src/admin/pages/AgentsPage.tsx +9 -26
  74. package/src/admin/pages/CreateDialog.tsx +15 -0
  75. package/src/admin/pages/ExportDialog.tsx +395 -0
  76. package/src/admin/pages/ImportButton.tsx +18 -0
  77. package/src/admin/pages/ImportElementorDialog.tsx +669 -0
  78. package/src/admin/pages/ImportPageLinks.tsx +86 -0
  79. package/src/admin/pages/PageList.tsx +82 -3
  80. package/src/admin/pages/ThemePartList.tsx +52 -2
  81. package/src/admin/pages/bulk.tsx +303 -0
  82. package/src/admin/pages/section-head.tsx +27 -0
  83. package/src/admin/proposals-api.ts +91 -0
  84. package/src/admin/search.ts +20 -0
  85. package/src/admin/theme-api.ts +4 -0
  86. package/src/admin/ui.ts +50 -4
  87. package/src/admin/widgets/CanvasField.tsx +8 -0
  88. package/src/admin/widgets/ConvertToRichText.tsx +136 -0
  89. package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
  90. package/src/admin/widgets/convert-body.ts +73 -2
  91. package/src/astro/content-port.ts +14 -1
  92. package/src/astro/render.ts +6 -6
  93. package/src/astro/resolve-theme.ts +25 -8
  94. package/src/astro/resolve.ts +89 -2
  95. package/src/astro/tabs/runtime.ts +16 -6
  96. package/src/constants.ts +1 -1
  97. package/src/core/a11y/audit.ts +45 -14
  98. package/src/core/arrange.ts +5 -1
  99. package/src/core/bounded-array.ts +31 -0
  100. package/src/core/clipboard.ts +9 -0
  101. package/src/core/contract.ts +305 -0
  102. package/src/core/css/generate.ts +151 -20
  103. package/src/core/css/scope.ts +10 -2
  104. package/src/core/css/trace.ts +47 -13
  105. package/src/core/css-keywords.ts +51 -1
  106. package/src/core/design/cascade.ts +12 -9
  107. package/src/core/design/classes.ts +28 -9
  108. package/src/core/design/devices.ts +89 -13
  109. package/src/core/design/states.ts +5 -3
  110. package/src/core/design/transfer.ts +5 -0
  111. package/src/core/design/variables.ts +31 -5
  112. package/src/core/elements/dynamic-elements.ts +3 -3
  113. package/src/core/elements/index.ts +73 -9
  114. package/src/core/export/runtimes.generated.ts +9 -0
  115. package/src/core/export/site.ts +562 -0
  116. package/src/core/export/zip.ts +95 -0
  117. package/src/core/extensions/define.ts +13 -0
  118. package/src/core/extensions/index.ts +41 -0
  119. package/src/core/extensions/namespace.ts +82 -0
  120. package/src/core/extensions/normalize.ts +141 -0
  121. package/src/core/extensions/placeholder.ts +41 -0
  122. package/src/core/extensions/registry.ts +94 -0
  123. package/src/core/extensions/render-ext.ts +118 -0
  124. package/src/core/extensions/safe-nodes.ts +93 -0
  125. package/src/core/extensions/schema.ts +112 -0
  126. package/src/core/extensions/types.ts +159 -0
  127. package/src/core/forms/binding.ts +1 -1
  128. package/src/core/history/diff.ts +26 -1
  129. package/src/core/import/elementor/atomic.ts +1608 -0
  130. package/src/core/import/elementor/classes.ts +127 -0
  131. package/src/core/import/elementor/context.ts +429 -0
  132. package/src/core/import/elementor/counter-steps.ts +72 -0
  133. package/src/core/import/elementor/css.ts +445 -0
  134. package/src/core/import/elementor/html.ts +500 -0
  135. package/src/core/import/elementor/index.ts +967 -0
  136. package/src/core/import/elementor/inline-marks.ts +81 -0
  137. package/src/core/import/elementor/snapshots.ts +48 -0
  138. package/src/core/import/elementor/style.ts +429 -0
  139. package/src/core/import/elementor/values.ts +241 -0
  140. package/src/core/import/elementor/widgets.ts +1897 -0
  141. package/src/core/index.ts +96 -0
  142. package/src/core/json-schema.ts +114 -0
  143. package/src/core/limits.ts +19 -0
  144. package/src/core/migrate/index.ts +6 -1
  145. package/src/core/migrate/v18.ts +222 -0
  146. package/src/core/perf/meter.ts +42 -24
  147. package/src/core/portable-text-export.ts +243 -0
  148. package/src/core/proposals-safety.ts +102 -0
  149. package/src/core/proposals.ts +357 -0
  150. package/src/core/public-attributes.ts +30 -0
  151. package/src/core/recipes/index.ts +2 -2
  152. package/src/core/render/extras.ts +3 -3
  153. package/src/core/render/index.ts +222 -23
  154. package/src/core/render/loop.ts +1 -1
  155. package/src/core/render/section.ts +4 -4
  156. package/src/core/render/tabs.ts +18 -11
  157. package/src/core/render/vnode.ts +1 -1
  158. package/src/core/sanitize/css.ts +151 -10
  159. package/src/core/sanitize/motion.ts +116 -0
  160. package/src/core/saved-sections.ts +6 -0
  161. package/src/core/schema/descriptors.ts +3 -1
  162. package/src/core/schema/design.ts +4 -3
  163. package/src/core/schema/layout.ts +92 -16
  164. package/src/core/schema/style.ts +296 -112
  165. package/src/core/search-text.ts +70 -0
  166. package/src/core/text-marks.ts +227 -0
  167. package/src/core/theme/dynamic.ts +9 -4
  168. package/src/core/theme/float.ts +2 -0
  169. package/src/core/theme/popup-rules.ts +33 -1
  170. package/src/core/translatable.ts +34 -0
  171. package/src/core/validate.ts +13 -1
  172. package/src/index.ts +24 -0
  173. package/src/mcp/errors.ts +3 -1
  174. package/src/mcp/ports.ts +67 -0
  175. package/src/mcp/prompts.ts +1 -11
  176. package/src/mcp/proposals.ts +281 -0
  177. package/src/mcp/read.ts +10 -10
  178. package/src/mcp/tools.ts +71 -3
  179. package/src/mcp/write.ts +66 -11
  180. package/src/server/agent-settings.ts +5 -1
  181. package/src/server/icon-routes.ts +52 -12
  182. package/src/server/mcp-routes.ts +15 -0
  183. package/src/server/plugin.ts +35 -2
  184. package/src/server/presence.ts +78 -0
  185. package/src/server/proposals.ts +261 -0
  186. package/src/server/requests.ts +196 -0
  187. package/src/server/tools-served.ts +45 -0
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Compile an extension's declarative prop schema into Zod, with EmVB limits on top
3
+ * (W-927). Extensions never pass us a Zod instance — only ExtensionPropSchema.
4
+ */
5
+
6
+ import { z } from "zod";
7
+ import { MAX_TEXT_LENGTH } from "../limits.ts";
8
+ import type { ExtensionPropSchema } from "./types.ts";
9
+
10
+ /** Hard caps on top of whatever the extension declares (limits may only loosen later). */
11
+ const EXT_MAX_STRING = MAX_TEXT_LENGTH;
12
+ const EXT_MAX_ARRAY = 32;
13
+ const EXT_MAX_OBJECT_KEYS = 32;
14
+ const EXT_MAX_DEPTH = 4;
15
+ const EXT_MAX_NUMBER = 1_000_000_000;
16
+
17
+ const FIELD_KINDS = new Set(["text", "textarea", "number", "int", "select", "boolean", "href"]);
18
+
19
+ export function isAllowedExtensionFieldKind(kind: string): boolean {
20
+ return FIELD_KINDS.has(kind);
21
+ }
22
+
23
+ function compileAt(schema: ExtensionPropSchema, depth: number): z.ZodType {
24
+ if (depth > EXT_MAX_DEPTH) {
25
+ return z.never();
26
+ }
27
+ switch (schema.type) {
28
+ case "string": {
29
+ const max = Math.min(schema.maxLength ?? EXT_MAX_STRING, EXT_MAX_STRING);
30
+ const min = Math.max(0, schema.minLength ?? 0);
31
+ let s = z.string().max(max);
32
+ if (min > 0) s = s.min(min);
33
+ return schema.default !== undefined ? s.default(schema.default) : s;
34
+ }
35
+ case "number": {
36
+ const min = schema.min ?? -EXT_MAX_NUMBER;
37
+ const max = Math.min(schema.max ?? EXT_MAX_NUMBER, EXT_MAX_NUMBER);
38
+ let n = z.number().min(min).max(max);
39
+ if (schema.integer) n = n.int();
40
+ return schema.default !== undefined ? n.default(schema.default) : n;
41
+ }
42
+ case "boolean": {
43
+ const b = z.boolean();
44
+ return schema.default !== undefined ? b.default(schema.default) : b;
45
+ }
46
+ case "enum": {
47
+ const values = schema.values
48
+ .filter((v) => typeof v === "string" && v.length <= 64)
49
+ .slice(0, 32);
50
+ if (values.length === 0) return z.never();
51
+ const e = z.enum(values as [string, ...string[]]);
52
+ return schema.default !== undefined && values.includes(schema.default)
53
+ ? e.default(schema.default)
54
+ : e;
55
+ }
56
+ case "array": {
57
+ const maxItems = Math.min(schema.maxItems ?? EXT_MAX_ARRAY, EXT_MAX_ARRAY);
58
+ const a = z.array(compileAt(schema.items, depth + 1)).max(maxItems);
59
+ return schema.default !== undefined ? a.default([...schema.default]) : a;
60
+ }
61
+ case "object": {
62
+ const keys = Object.keys(schema.properties).slice(0, EXT_MAX_OBJECT_KEYS);
63
+ const shape: Record<string, z.ZodType> = {};
64
+ const required = new Set(schema.required ?? []);
65
+ for (const key of keys) {
66
+ if (!/^[a-zA-Z][a-zA-Z0-9_]{0,31}$/.test(key)) continue;
67
+ const prop = schema.properties[key];
68
+ if (!prop) continue;
69
+ const compiled = compileAt(prop, depth + 1);
70
+ shape[key] = required.has(key) ? compiled : compiled.optional();
71
+ }
72
+ return z.object(shape).strict();
73
+ }
74
+ default:
75
+ return z.never();
76
+ }
77
+ }
78
+
79
+ /** Zod schema for one element's props. Unknown keys are stripped (strict object leaves). */
80
+ function compileExtensionProps(schema: ExtensionPropSchema): z.ZodType {
81
+ return compileAt(schema, 0);
82
+ }
83
+
84
+ /** Defaults implied by the schema (and any `defaults()` the extension supplies). */
85
+ export function schemaDefaults(schema: ExtensionPropSchema): Record<string, unknown> {
86
+ if (schema.type !== "object") return {};
87
+ const out: Record<string, unknown> = {};
88
+ for (const [key, prop] of Object.entries(schema.properties)) {
89
+ if ("default" in prop && prop.default !== undefined) out[key] = prop.default;
90
+ }
91
+ return out;
92
+ }
93
+
94
+ /**
95
+ * Validate untrusted stored props. On failure returns the schema defaults (so a
96
+ * bad value never reaches render) and `ok: false`.
97
+ */
98
+ export function validateExtensionProps(
99
+ schema: ExtensionPropSchema,
100
+ input: unknown,
101
+ ): { ok: true; props: Record<string, unknown> } | { ok: false; props: Record<string, unknown> } {
102
+ const compiled = compileExtensionProps(schema);
103
+ const result = compiled.safeParse(input ?? {});
104
+ if (result.success) {
105
+ const props =
106
+ result.data && typeof result.data === "object" && !Array.isArray(result.data)
107
+ ? (result.data as Record<string, unknown>)
108
+ : {};
109
+ return { ok: true, props };
110
+ }
111
+ return { ok: false, props: schemaDefaults(schema) };
112
+ }
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Extensions API v1 (W-927, D-066). Site owners register extensions through
3
+ * `emvb({ extensions: [...] })` at build time. Stored data is namespaced
4
+ * `ext:<pkg>/<name>`, validated, and render output goes through EmVB's sanitizer.
5
+ *
6
+ * Freeze rules match D-065: within extensionApi 1.x no key is removed, renamed or
7
+ * changed in meaning; additions are optional; breaking changes wait for 2.0.
8
+ */
9
+
10
+ import type { FieldDescriptor } from "../schema/descriptors.ts";
11
+ import type { LayoutNode } from "../schema/layout.ts";
12
+
13
+ /** Shipped API version. Same freeze rules as D-065 (see docs/EXTENSIONS.md). */
14
+ export const EXTENSION_API_VERSION = 1 as const;
15
+ export type ExtensionApiVersion = typeof EXTENSION_API_VERSION;
16
+
17
+ /**
18
+ * Declarative prop schema EmVB compiles to Zod. Extensions must not hand us a
19
+ * Zod instance (or any other code) as a "schema" — only this subset.
20
+ */
21
+ export type ExtensionPropSchema =
22
+ | {
23
+ type: "string";
24
+ maxLength?: number;
25
+ minLength?: number;
26
+ default?: string;
27
+ }
28
+ | {
29
+ type: "number";
30
+ min?: number;
31
+ max?: number;
32
+ integer?: boolean;
33
+ default?: number;
34
+ }
35
+ | {
36
+ type: "boolean";
37
+ default?: boolean;
38
+ }
39
+ | {
40
+ type: "enum";
41
+ values: readonly string[];
42
+ default?: string;
43
+ }
44
+ | {
45
+ type: "array";
46
+ items: ExtensionPropSchema;
47
+ maxItems?: number;
48
+ default?: readonly unknown[];
49
+ }
50
+ | {
51
+ type: "object";
52
+ properties: Readonly<Record<string, ExtensionPropSchema>>;
53
+ required?: readonly string[];
54
+ };
55
+
56
+ /** Inspector field: the same declarative kinds ElementDescriptor uses (W-021). */
57
+ export type ExtensionField = Pick<
58
+ FieldDescriptor,
59
+ "key" | "kind" | "label" | "options" | "message" | "optional" | "max" | "min"
60
+ >;
61
+
62
+ /** Context passed to an element render function (read-only source values). */
63
+ export type ExtensionRenderContext = {
64
+ /** Resolved values from this extension's sources, keyed by source name then field. */
65
+ sources: Readonly<Record<string, Readonly<Record<string, string>>>>;
66
+ };
67
+
68
+ /**
69
+ * A custom element. `name` becomes the stored type `ext:<extension.id>/<name>`.
70
+ * `render` returns EmVB layout nodes (built-in types only), never HTML strings.
71
+ */
72
+ export type ExtensionElement = {
73
+ name: string;
74
+ label: string;
75
+ /** Optional Add-panel group; defaults to "content". */
76
+ group?: "layout" | "content" | "form" | "dynamic";
77
+ schema: ExtensionPropSchema;
78
+ fields: readonly ExtensionField[];
79
+ defaults?: () => Record<string, unknown>;
80
+ render: (
81
+ props: Record<string, unknown>,
82
+ ctx: ExtensionRenderContext,
83
+ ) => LayoutNode | readonly LayoutNode[];
84
+ };
85
+
86
+ /**
87
+ * Declarative editor panel. EmVB renders it in a Kumo slot with EmVB tokens.
88
+ * Extensions may not inject global admin CSS (D-067).
89
+ */
90
+ export type ExtensionPanel = {
91
+ name: string;
92
+ label: string;
93
+ /** Short body shown in the slot (plain text; EmVB escapes it). */
94
+ description?: string;
95
+ /** Optional source name whose resolved fields are listed read-only in the panel. */
96
+ source?: string;
97
+ };
98
+
99
+ /** What a read-only data source may return (W-927). */
100
+ export type ExtensionSourceCapability = "text" | "url" | "image";
101
+
102
+ /**
103
+ * A read-only resolver. Results are treated as untrusted strings and run through
104
+ * the same cleaning path bindings use before anything renders them.
105
+ */
106
+ export type ExtensionSource = {
107
+ name: string;
108
+ label: string;
109
+ capabilities: readonly ExtensionSourceCapability[];
110
+ resolve: () => Readonly<Record<string, string>> | Promise<Readonly<Record<string, string>>>;
111
+ };
112
+
113
+ /** One extension package. `id` is the package name (unscoped), e.g. `emvb-ext-hello`. */
114
+ export type EmVBExtension = {
115
+ extensionApi: ExtensionApiVersion;
116
+ id: string;
117
+ label?: string;
118
+ elements?: readonly ExtensionElement[];
119
+ panels?: readonly ExtensionPanel[];
120
+ sources?: readonly ExtensionSource[];
121
+ };
122
+
123
+ /**
124
+ * Serializable manifest sent to the admin through `editor/config` (no functions).
125
+ * Live render/resolve functions stay in the process registry.
126
+ */
127
+ export type ExtensionElementManifest = {
128
+ type: string;
129
+ name: string;
130
+ label: string;
131
+ group: "layout" | "content" | "form" | "dynamic";
132
+ schema: ExtensionPropSchema;
133
+ fields: readonly ExtensionField[];
134
+ defaults: Record<string, unknown>;
135
+ };
136
+
137
+ export type ExtensionPanelManifest = {
138
+ id: string;
139
+ name: string;
140
+ label: string;
141
+ description?: string;
142
+ source?: string;
143
+ };
144
+
145
+ export type ExtensionSourceManifest = {
146
+ id: string;
147
+ name: string;
148
+ label: string;
149
+ capabilities: readonly ExtensionSourceCapability[];
150
+ };
151
+
152
+ export type ExtensionManifest = {
153
+ extensionApi: ExtensionApiVersion;
154
+ id: string;
155
+ label: string;
156
+ elements: readonly ExtensionElementManifest[];
157
+ panels: readonly ExtensionPanelManifest[];
158
+ sources: readonly ExtensionSourceManifest[];
159
+ };
@@ -91,7 +91,7 @@ export type RequiredFieldIssue =
91
91
  };
92
92
 
93
93
  const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "radio"]);
94
- const DEVICE_ORDER = ["desktop", "tablet", "mobile"];
94
+ const DEVICE_ORDER = ["desktop", "laptop", "tablet", "mobile"];
95
95
 
96
96
  /** Each bound field's controls, with the devices each is hidden on (itself or an ancestor). */
97
97
  type Control = { nodeId: string; hidden: Set<string>; who?: string; split?: string };
@@ -11,6 +11,8 @@ export type SectionChange = {
11
11
  kind: "added" | "removed" | "changed" | "moved" | "same";
12
12
  /** Elements inside that differ (added, removed or edited), for changed sections. */
13
13
  edits: number;
14
+ /** W-973: the page itself (its root's styles, classes and settings), not a section. */
15
+ page?: true;
14
16
  };
15
17
 
16
18
  /**
@@ -54,7 +56,7 @@ function editsBetween(before: LayoutNode, after: LayoutNode): number {
54
56
  const describe = (node: LayoutNode) => ({
55
57
  id: node.id,
56
58
  type: node.type,
57
- ...(node.label ? { label: node.label } : {}),
59
+ ...(node.editorLabel ? { label: node.editorLabel } : {}),
58
60
  });
59
61
 
60
62
  /**
@@ -68,6 +70,18 @@ export function diffSections(older: Layout, current: Layout): SectionChange[] {
68
70
  const beforeIds = new Map(before.map((node, i) => [node.id, i]));
69
71
  const afterIds = new Set(after.map((node) => node.id));
70
72
  const changes: SectionChange[] = [];
73
+ // W-973: the page's own styles (the root's style, devices, states, classes…) are listed first;
74
+ // a version that only changed those used to read as "no changes".
75
+ if (older.root.id === current.root.id && own(older.root) !== own(current.root)) {
76
+ changes.push({
77
+ id: current.root.id,
78
+ type: "container",
79
+ label: "Page styles",
80
+ kind: "changed",
81
+ edits: 1,
82
+ page: true,
83
+ });
84
+ }
71
85
  const removedAt = new Map<number, LayoutNode[]>();
72
86
  for (const [i, node] of before.entries()) {
73
87
  if (!afterIds.has(node.id)) removedAt.set(i, [...(removedAt.get(i) ?? []), node]);
@@ -149,6 +163,17 @@ export function restoreSection(
149
163
  older: Layout,
150
164
  sectionId: string,
151
165
  ): { ok: true; layout: Layout } | { ok: false; reason: string } {
166
+ // W-973: the page's own styles come back without touching its sections.
167
+ if (sectionId === older.root.id && sectionId === current.root.id) {
168
+ const { children: _old, ...settings } = older.root;
169
+ return {
170
+ ok: true,
171
+ layout: {
172
+ ...current,
173
+ root: { ...structuredClone(settings), children: current.root.children },
174
+ },
175
+ };
176
+ }
152
177
  const oldIndex = older.root.children.findIndex((n) => n.id === sectionId);
153
178
  const section = older.root.children[oldIndex];
154
179
  if (!section) return { ok: false, reason: "That section isn't in this version." };