|
3 | 3 | * |
4 | 4 | * Not a general-purpose JSON Patch implementation. Translates the well-defined path |
5 | 5 | * grammar back into DOM mutations. Used by applyPatches() for host undo (T3 mode). |
| 6 | + * |
| 7 | + * Supports only the emit subset (add/remove/replace) — move/copy/test ops and |
| 8 | + * unknown paths are silently ignored, matching the JsonPatchOp contract. |
6 | 9 | */ |
7 | 10 |
|
8 | 11 | import type { JsonPatchOp } from "../types.js"; |
@@ -164,12 +167,26 @@ function applyOne(parsed: ParsedDocument, patch: JsonPatchOp, p: ParsedPath): vo |
164 | 167 | case "metadata": { |
165 | 168 | const root = findRoot(parsed.document); |
166 | 169 | if (!root || !p.field) return; |
| 170 | + // Mirror mutate.ts: style always written; the data-* forced-override |
| 171 | + // attribute is updated only when the composition already carries it. |
167 | 172 | if (p.field === "width") { |
168 | | - if (patch.op === "remove") setElementStyles(root, { width: null }); |
169 | | - else setElementStyles(root, { width: `${patch.value}px` }); |
| 173 | + if (patch.op === "remove") { |
| 174 | + setElementStyles(root, { width: null }); |
| 175 | + root.removeAttribute("data-width"); |
| 176 | + } else { |
| 177 | + setElementStyles(root, { width: `${patch.value}px` }); |
| 178 | + if (root.hasAttribute("data-width")) root.setAttribute("data-width", String(patch.value)); |
| 179 | + } |
170 | 180 | } else if (p.field === "height") { |
171 | | - if (patch.op === "remove") setElementStyles(root, { height: null }); |
172 | | - else setElementStyles(root, { height: `${patch.value}px` }); |
| 181 | + if (patch.op === "remove") { |
| 182 | + setElementStyles(root, { height: null }); |
| 183 | + root.removeAttribute("data-height"); |
| 184 | + } else { |
| 185 | + setElementStyles(root, { height: `${patch.value}px` }); |
| 186 | + if (root.hasAttribute("data-height")) { |
| 187 | + root.setAttribute("data-height", String(patch.value)); |
| 188 | + } |
| 189 | + } |
173 | 190 | } else if (p.field === "duration") { |
174 | 191 | if (patch.op === "remove") root.removeAttribute("data-duration"); |
175 | 192 | else root.setAttribute("data-duration", String(patch.value)); |
|
0 commit comments