@krizaka/ui 4.4.0 → 4.4.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 (259) hide show
  1. package/dist/account-menu.d.ts +1 -1
  2. package/dist/account-menu.js +1 -1
  3. package/dist/account-menu.js.map +1 -1
  4. package/dist/account-settings.d.ts +1 -1
  5. package/dist/account-settings.js +13 -6
  6. package/dist/account-settings.js.map +1 -1
  7. package/dist/agenda.d.ts +1 -1
  8. package/dist/agenda.js +2 -1
  9. package/dist/agenda.js.map +1 -1
  10. package/dist/analysis-report.js +19 -11
  11. package/dist/analysis-report.js.map +1 -1
  12. package/dist/app-frame.d.ts +1 -1
  13. package/dist/app-frame.js.map +1 -1
  14. package/dist/app-header/search.js +2 -2
  15. package/dist/app-header/search.js.map +1 -1
  16. package/dist/avatar/defaults.js +3 -1
  17. package/dist/avatar/defaults.js.map +1 -1
  18. package/dist/avatar.js +3 -1
  19. package/dist/avatar.js.map +1 -1
  20. package/dist/bird-plate.js +8 -2
  21. package/dist/bird-plate.js.map +1 -1
  22. package/dist/chapter.js +7 -4
  23. package/dist/chapter.js.map +1 -1
  24. package/dist/chat.js +1 -1
  25. package/dist/chip.d.ts +1 -1
  26. package/dist/chip.js +1 -1
  27. package/dist/{chunk-SNSQLGGS.js → chunk-5VZ37TY3.js} +1 -1
  28. package/dist/{chunk-XWJDBQU7.js.map → chunk-5VZ37TY3.js.map} +1 -1
  29. package/dist/{chunk-MTVX4RRF.js → chunk-HP7BDMVK.js} +11 -3
  30. package/dist/chunk-HP7BDMVK.js.map +1 -0
  31. package/dist/{chunk-PK3L6WQT.js → chunk-LNAAWT4Y.js} +4 -2
  32. package/dist/{chunk-PK3L6WQT.js.map → chunk-LNAAWT4Y.js.map} +1 -1
  33. package/dist/{chunk-UIP3WX5O.js → chunk-MDSP7DJR.js} +2 -2
  34. package/dist/chunk-MDSP7DJR.js.map +1 -0
  35. package/dist/{chunk-IEGTRCDI.js → chunk-NQENOT6L.js} +2 -2
  36. package/dist/{chunk-IEGTRCDI.js.map → chunk-NQENOT6L.js.map} +1 -1
  37. package/dist/{chunk-FM42KOAU.js → chunk-P7AFIKWG.js} +5 -3
  38. package/dist/chunk-P7AFIKWG.js.map +1 -0
  39. package/dist/{chunk-BCD2CRFG.js → chunk-PJNR4NTS.js} +2 -2
  40. package/dist/chunk-PJNR4NTS.js.map +1 -0
  41. package/dist/{chunk-ZFR6ZNXD.js → chunk-PVQ2KKPZ.js} +1 -1
  42. package/dist/chunk-PVQ2KKPZ.js.map +1 -0
  43. package/dist/{chunk-U4XTZMB7.js → chunk-QA3WETWT.js} +1 -1
  44. package/dist/{chunk-U4XTZMB7.js.map → chunk-QA3WETWT.js.map} +1 -1
  45. package/dist/{chunk-YXETEQQJ.js → chunk-SG2RKUVJ.js} +2 -2
  46. package/dist/{chunk-EOWV6BNQ.js → chunk-TXFX4PMN.js} +4 -2
  47. package/dist/{chunk-EOWV6BNQ.js.map → chunk-TXFX4PMN.js.map} +1 -1
  48. package/dist/{chunk-XWJDBQU7.js → chunk-V5RO6JYI.js} +1 -1
  49. package/dist/{chunk-SNSQLGGS.js.map → chunk-V5RO6JYI.js.map} +1 -1
  50. package/dist/{chunk-VUD4IEVJ.js → chunk-VZ6ZALIJ.js} +1 -1
  51. package/dist/chunk-VZ6ZALIJ.js.map +1 -0
  52. package/dist/{chunk-2DHL7NJW.js → chunk-XVRKKYWU.js} +5 -3
  53. package/dist/{chunk-2DHL7NJW.js.map → chunk-XVRKKYWU.js.map} +1 -1
  54. package/dist/{chunk-CDNOT2KR.js → chunk-YTYNKMNS.js} +1 -1
  55. package/dist/chunk-YTYNKMNS.js.map +1 -0
  56. package/dist/code-block.js.map +1 -1
  57. package/dist/combobox.js +2 -2
  58. package/dist/copy-button.js +2 -2
  59. package/dist/copy-button.js.map +1 -1
  60. package/dist/data-table.js +3 -3
  61. package/dist/desktop-window.d.ts +1 -1
  62. package/dist/desktop-window.js +3 -1
  63. package/dist/desktop-window.js.map +1 -1
  64. package/dist/drop-overlay.js +8 -8
  65. package/dist/drop-overlay.js.map +1 -1
  66. package/dist/elephant.d.ts +1 -1
  67. package/dist/elephant.js.map +1 -1
  68. package/dist/embed-facade.d.ts +1 -1
  69. package/dist/embed-facade.js +3 -1
  70. package/dist/embed-facade.js.map +1 -1
  71. package/dist/engine-flow.js +7 -2
  72. package/dist/engine-flow.js.map +1 -1
  73. package/dist/entity-header.js +9 -3
  74. package/dist/entity-header.js.map +1 -1
  75. package/dist/file-upload.d.ts +1 -1
  76. package/dist/file-upload.js.map +1 -1
  77. package/dist/filter-bar.d.ts +4 -4
  78. package/dist/filter-bar.js +2 -2
  79. package/dist/flock.js +9 -6
  80. package/dist/flock.js.map +1 -1
  81. package/dist/form.d.ts +3 -3
  82. package/dist/form.js.map +1 -1
  83. package/dist/genui.js +3 -3
  84. package/dist/glossary-term.d.ts +1 -1
  85. package/dist/glossary-term.js.map +1 -1
  86. package/dist/glossary.d.ts +1 -1
  87. package/dist/glossary.js.map +1 -1
  88. package/dist/identity-card.js +1 -1
  89. package/dist/index.js +1 -1
  90. package/dist/kind-config-editor.d.ts +2 -2
  91. package/dist/kind-config-editor.js +1 -1
  92. package/dist/kind-config-editor.js.map +1 -1
  93. package/dist/kpi-explained.d.ts +1 -1
  94. package/dist/kpi-explained.js +4 -4
  95. package/dist/kpi-explained.js.map +1 -1
  96. package/dist/landing-page.js +1 -1
  97. package/dist/{lightbox-Q45BZ3HW.js → lightbox-MRB2YZEP.js} +1 -1
  98. package/dist/lightbox-MRB2YZEP.js.map +1 -0
  99. package/dist/map/cards.js +4 -2
  100. package/dist/map/cards.js.map +1 -1
  101. package/dist/map/pin.js +2 -1
  102. package/dist/map/pin.js.map +1 -1
  103. package/dist/map.d.ts +1 -1
  104. package/dist/map.js.map +1 -1
  105. package/dist/mascot-quote.js +1 -1
  106. package/dist/mascot-state.js +1 -1
  107. package/dist/mascots.js +1 -1
  108. package/dist/match-dialog.js +1 -1
  109. package/dist/motion.d.ts +1 -1
  110. package/dist/motion.js.map +1 -1
  111. package/dist/native/form.d.ts +3 -3
  112. package/dist/native/form.js.map +1 -1
  113. package/dist/native/markdown.d.ts +1 -1
  114. package/dist/native/markdown.js.map +1 -1
  115. package/dist/native/vertical-video.js.map +1 -1
  116. package/dist/native.d.ts +12 -12
  117. package/dist/native.js +12 -7
  118. package/dist/native.js.map +1 -1
  119. package/dist/nav-bar.d.ts +2 -2
  120. package/dist/nav-bar.js +1 -1
  121. package/dist/nav-bar.js.map +1 -1
  122. package/dist/next-actions.d.ts +1 -1
  123. package/dist/next-actions.js.map +1 -1
  124. package/dist/notification-preferences.d.ts +1 -1
  125. package/dist/notification-preferences.js +5 -2
  126. package/dist/notification-preferences.js.map +1 -1
  127. package/dist/page-index.js +2 -2
  128. package/dist/page-index.js.map +1 -1
  129. package/dist/product-page.js +1 -1
  130. package/dist/promo-code-field.d.ts +1 -1
  131. package/dist/promo-code-field.js.map +1 -1
  132. package/dist/qr-code.d.ts +1 -1
  133. package/dist/qr-code.js +1 -1
  134. package/dist/rail-nav.js +3 -3
  135. package/dist/rail-nav.js.map +1 -1
  136. package/dist/retro-tv.d.ts +1 -1
  137. package/dist/retro-tv.js.map +1 -1
  138. package/dist/reviews.d.ts +2 -2
  139. package/dist/reviews.js.map +1 -1
  140. package/dist/router.d.ts +1 -1
  141. package/dist/router.js +8 -8
  142. package/dist/router.js.map +1 -1
  143. package/dist/{schema-CL7t7xqb.d.ts → schema-Dd05m48Q.d.ts} +9 -9
  144. package/dist/service-card.js +22 -13
  145. package/dist/service-card.js.map +1 -1
  146. package/dist/settings-layout.js +1 -1
  147. package/dist/shop/booking.js.map +1 -1
  148. package/dist/shop/gallery.js +7 -6
  149. package/dist/shop/gallery.js.map +1 -1
  150. package/dist/shop/hero.js.map +1 -1
  151. package/dist/shop/look.d.ts +2 -2
  152. package/dist/shop/look.js +1 -1
  153. package/dist/shop/look.js.map +1 -1
  154. package/dist/shop/map-gate.d.ts +1 -1
  155. package/dist/shop/map-gate.js +2 -2
  156. package/dist/shop/map-gate.js.map +1 -1
  157. package/dist/shop/services.js.map +1 -1
  158. package/dist/shop-composer.d.ts +12 -12
  159. package/dist/shop-composer.js +27 -14
  160. package/dist/shop-composer.js.map +1 -1
  161. package/dist/shop-gallery.js +1 -1
  162. package/dist/shop.d.ts +2 -2
  163. package/dist/shop.js +2 -2
  164. package/dist/shop.js.map +1 -1
  165. package/dist/signature.js +2 -1
  166. package/dist/signature.js.map +1 -1
  167. package/dist/site-cahier.js +7 -3
  168. package/dist/site-cahier.js.map +1 -1
  169. package/dist/site-footer.js +6 -2
  170. package/dist/site-footer.js.map +1 -1
  171. package/dist/slot-picker.js +5 -2
  172. package/dist/slot-picker.js.map +1 -1
  173. package/dist/stat.js +1 -1
  174. package/dist/status-chip.d.ts +1 -1
  175. package/dist/status-chip.js.map +1 -1
  176. package/dist/tabs.js.map +1 -1
  177. package/dist/tag-input.js +2 -2
  178. package/dist/tag-selector.js +1 -1
  179. package/dist/text-style.js +4 -3
  180. package/dist/text-style.js.map +1 -1
  181. package/dist/usage.js +8 -3
  182. package/dist/usage.js.map +1 -1
  183. package/dist/versus-card.js +1 -1
  184. package/dist/versus-card.js.map +1 -1
  185. package/dist/vertical-video.js +1 -1
  186. package/dist/vertical-video.js.map +1 -1
  187. package/dist/wall.d.ts +4 -4
  188. package/dist/wall.js +1 -1
  189. package/dist/wall.js.map +1 -1
  190. package/package.json +5 -5
  191. package/registry/account-menu.json +1 -1
  192. package/registry/account-settings.json +2 -2
  193. package/registry/agenda.json +1 -1
  194. package/registry/analysis-report.json +2 -2
  195. package/registry/app-frame.json +3 -3
  196. package/registry/app-header.json +1 -1
  197. package/registry/avatar.json +1 -1
  198. package/registry/badge.json +2 -2
  199. package/registry/bird-plate.json +1 -1
  200. package/registry/chapter.json +1 -1
  201. package/registry/chip.json +1 -1
  202. package/registry/copy-button.json +1 -1
  203. package/registry/data-table.json +1 -1
  204. package/registry/desktop-window.json +1 -1
  205. package/registry/drop-overlay.json +1 -1
  206. package/registry/elephant.json +1 -1
  207. package/registry/embed-facade.json +2 -2
  208. package/registry/engine-flow.json +2 -2
  209. package/registry/entity-header.json +1 -1
  210. package/registry/file-upload.json +1 -1
  211. package/registry/filter-bar.json +1 -1
  212. package/registry/flock.json +2 -2
  213. package/registry/form.json +7 -7
  214. package/registry/glossary-term.json +1 -1
  215. package/registry/glossary.json +1 -1
  216. package/registry/index.json +7 -7
  217. package/registry/kind-config-editor.json +1 -1
  218. package/registry/kpi-explained.json +1 -1
  219. package/registry/map.json +4 -4
  220. package/registry/mascot-state.json +1 -1
  221. package/registry/mascots.json +2 -2
  222. package/registry/nav-bar.json +4 -4
  223. package/registry/next-actions.json +1 -1
  224. package/registry/notification-preferences.json +1 -1
  225. package/registry/page-index.json +1 -1
  226. package/registry/page.json +1 -1
  227. package/registry/promo-code-field.json +1 -1
  228. package/registry/qr-code.json +2 -2
  229. package/registry/rail-nav.json +3 -3
  230. package/registry/retro-tv.json +1 -1
  231. package/registry/reviews.json +1 -1
  232. package/registry/router.json +1 -1
  233. package/registry/service-card.json +1 -1
  234. package/registry/settings-layout.json +1 -1
  235. package/registry/shop-composer.json +7 -7
  236. package/registry/shop-gallery.json +1 -1
  237. package/registry/shop.json +11 -11
  238. package/registry/signature.json +1 -1
  239. package/registry/site-cahier.json +1 -1
  240. package/registry/site-footer.json +3 -3
  241. package/registry/slot-picker.json +1 -1
  242. package/registry/stat.json +1 -1
  243. package/registry/status-chip.json +1 -1
  244. package/registry/tabs.json +1 -1
  245. package/registry/text-style.json +1 -1
  246. package/registry/usage.json +2 -2
  247. package/registry/versus-card.json +1 -1
  248. package/registry/vertical-video.json +1 -1
  249. package/registry/wall.json +5 -5
  250. package/registry/waveform.json +2 -2
  251. package/dist/chunk-BCD2CRFG.js.map +0 -1
  252. package/dist/chunk-CDNOT2KR.js.map +0 -1
  253. package/dist/chunk-FM42KOAU.js.map +0 -1
  254. package/dist/chunk-MTVX4RRF.js.map +0 -1
  255. package/dist/chunk-UIP3WX5O.js.map +0 -1
  256. package/dist/chunk-VUD4IEVJ.js.map +0 -1
  257. package/dist/chunk-ZFR6ZNXD.js.map +0 -1
  258. package/dist/lightbox-Q45BZ3HW.js.map +0 -1
  259. /package/dist/{chunk-YXETEQQJ.js.map → chunk-SG2RKUVJ.js.map} +0 -0
@@ -226,11 +226,11 @@
226
226
  },
227
227
  {
228
228
  "path": "shop-composer/commands.ts",
229
- "content": "// The composer's commands (ADR-007 §5): every change of the document is a pure command on a reducer — never a mutation —\n// so undo / redo restore the exact document, and the rules of the document (a hero first, 16 sections, 24 blocks, the variants\n// of a type) hold after every step. A command that would break a rule is a no-op: the page stays valid, always.\nimport { SECTION_DEFINITIONS, sectionDefinition,type SectionType } from \"../shop/catalogue\";\nimport { SHOP_LIMITS } from \"../shop/limits\";\nimport { applyLook, type ShopLookLike } from \"../shop/look/apply-look\";\nimport type { Section, ShopPage } from \"../shop/schema\";\nimport type { LocalizedText } from \"../shop/text\";\n\ntype Rec = Record<string, unknown>;\n\nexport type Command =\n /** Adds a section (its type's default settings, the given or the default variant) at an index; a hero goes first. */\n | { type: \"addSection\"; sectionType: SectionType; key: string; variant?: string; at?: number; settings?: Rec }\n | { type: \"removeSection\"; key: string }\n /** Moves a section to an absolute index (the hero stays first: nothing goes above it). */\n | { type: \"moveSection\"; key: string; to: number }\n | { type: \"setVariant\"; key: string; variant: string }\n /** Merges into the settings. */\n | { type: \"patchSettings\"; key: string; patch: Rec }\n | { type: \"setText\"; key: string; field: \"title\" | \"lead\"; value: LocalizedText | undefined }\n | { type: \"toggleDisabled\"; key: string }\n | { type: \"setPreset\"; preset: { id: string; version: number }; density?: \"compact\" | \"airy\" | null }\n | { type: \"setDensity\"; density: \"compact\" | \"airy\" | undefined }\n /** A whole look (`look-*`): the variants of the sections, nothing of their content (`applyLook`). */\n | { type: \"applyLook\"; look: ShopLookLike }\n /** The accent within the look's tested list. */\n | { type: \"setAccent\"; accent: string | undefined }\n | { type: \"addBlock\"; key: string; blockKey: string; blockType: string; settings?: Rec; at?: number }\n | { type: \"removeBlock\"; key: string; blockKey: string }\n | { type: \"moveBlock\"; key: string; blockKey: string; to: number }\n | { type: \"patchBlock\"; key: string; blockKey: string; patch: Rec };\n\nconst clamp = (n: number, lo: number, hi: number) => Math.min(Math.max(n, lo), hi);\nconst indexOfKey = (page: ShopPage, key: string) => page.sections.findIndex((s) => s.key === key);\n\n/** The array with an item moved to an index. */\nexport function moved<T>(list: readonly T[], from: number, to: number): T[] {\n const next = [...list];\n const [item] = next.splice(from, 1);\n next.splice(clamp(to, 0, next.length), 0, item as T);\n return next;\n}\n\nfunction withSection(page: ShopPage, key: string, change: (s: Section) => Section): ShopPage {\n const i = indexOfKey(page, key);\n if (i < 0) return page;\n const next = change(page.sections[i]!);\n if (next === page.sections[i]) return page;\n const sections = [...page.sections];\n sections[i] = next;\n return { ...page, sections };\n}\n\ntype Handler<T extends Command[\"type\"]> = (page: ShopPage, cmd: Extract<Command, { type: T }>) => ShopPage;\n\nconst addSection: Handler<\"addSection\"> = (page, cmd) => {\n const def = SECTION_DEFINITIONS.find((d) => d.type === cmd.sectionType);\n if (!def || page.sections.length >= SHOP_LIMITS.sections || page.sections.some((s) => s.key === cmd.key)) return page;\n const variant = cmd.variant ?? def.defaultVariant;\n if (!(def.variants as readonly string[]).includes(variant)) return page;\n const isHero = def.type === \"hero\";\n if (isHero && page.sections.some((s) => s.type === \"hero\")) return page;\n const heroFirst = page.sections[0]?.type === \"hero\";\n const at = isHero ? 0 : clamp(cmd.at ?? page.sections.length, heroFirst ? 1 : 0, page.sections.length);\n const section = { key: cmd.key, type: def.type, variant, settings: { ...(def.settingsDefault as Rec), ...cmd.settings } } as unknown as Section;\n const sections = [...page.sections];\n sections.splice(at, 0, section);\n return { ...page, sections };\n};\n\nconst removeSection: Handler<\"removeSection\"> = (page, cmd) => {\n if (indexOfKey(page, cmd.key) < 0 || page.sections.length <= 1) return page;\n return { ...page, sections: page.sections.filter((s) => s.key !== cmd.key) };\n};\n\nconst moveSection: Handler<\"moveSection\"> = (page, cmd) => {\n const from = indexOfKey(page, cmd.key);\n if (from < 0 || page.sections[from]!.type === \"hero\") return page;\n const lo = page.sections[0]?.type === \"hero\" ? 1 : 0;\n const to = clamp(cmd.to, lo, page.sections.length - 1);\n return to === from ? page : { ...page, sections: moved(page.sections, from, to) };\n};\n\nconst setVariant: Handler<\"setVariant\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const def = sectionDefinition(s.type);\n if (s.variant === cmd.variant || !(def.variants as readonly string[]).includes(cmd.variant)) return s;\n return { ...s, variant: cmd.variant } as Section;\n });\n\n/** Whether every value of a patch is already the one the object holds. */\nconst saysNothingNew = (current: Rec, patch: Rec) => Object.entries(patch).every(([k, v]) => JSON.stringify(current[k]) === JSON.stringify(v));\n\nconst patchSettings: Handler<\"patchSettings\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const current = s.settings as Rec;\n // Nothing to say when every value is already the document's (a form that reports its first values after an undo).\n return saysNothingNew(current, cmd.patch) ? s : ({ ...s, settings: { ...current, ...cmd.patch } } as Section);\n });\n\nconst setText: Handler<\"setText\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const text = { ...(s.text ?? {}) } as Rec;\n if (cmd.value === undefined) delete text[cmd.field];\n else text[cmd.field] = cmd.value;\n const next = { ...s } as Rec;\n if (Object.keys(text).length === 0) delete next.text;\n else next.text = text;\n return next as unknown as Section;\n });\n\nconst toggleDisabled: Handler<\"toggleDisabled\"> = (page, cmd) => withSection(page, cmd.key, (s) => ({ ...s, disabled: s.disabled ? undefined : true }) as Section);\n\nconst setPreset: Handler<\"setPreset\"> = (page, cmd) => {\n if (page.preset.id === cmd.preset.id && page.preset.version === cmd.preset.version && cmd.density === undefined) return page;\n let density: Partial<Pick<ShopPage, \"density\">> = {};\n if (cmd.density === null) density = { density: undefined };\n else if (cmd.density) density = { density: cmd.density };\n return { ...page, preset: { ...cmd.preset }, ...density };\n};\n\nconst setDensity: Handler<\"setDensity\"> = (page, cmd) => (page.density === cmd.density ? page : { ...page, density: cmd.density });\n\nconst applyLookCmd: Handler<\"applyLook\"> = (page, cmd) => applyLook(page, cmd.look);\n\nconst setAccent: Handler<\"setAccent\"> = (page, cmd) => (page.accent === cmd.accent ? page : { ...page, accent: cmd.accent });\n\ntype Keyed = { key: string; type?: string; settings?: Rec };\n\nconst addBlock: Handler<\"addBlock\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const def = sectionDefinition(s.type);\n const blocks = (s.blocks ?? []) as readonly Keyed[];\n if (!(def.blockTypes as readonly string[]).includes(cmd.blockType) || blocks.length >= SHOP_LIMITS.blocks || blocks.some((b) => b.key === cmd.blockKey)) return s;\n const next = [...blocks];\n next.splice(clamp(cmd.at ?? blocks.length, 0, blocks.length), 0, { key: cmd.blockKey, type: cmd.blockType, settings: { ...cmd.settings } });\n return { ...s, blocks: next } as unknown as Section;\n });\n\nconst removeBlock: Handler<\"removeBlock\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const blocks = (s.blocks ?? []) as readonly Keyed[];\n if (!blocks.some((b) => b.key === cmd.blockKey)) return s;\n const next = blocks.filter((b) => b.key !== cmd.blockKey);\n return { ...s, blocks: next.length > 0 ? next : undefined } as unknown as Section;\n });\n\nconst moveBlock: Handler<\"moveBlock\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const blocks = (s.blocks ?? []) as readonly Keyed[];\n const from = blocks.findIndex((b) => b.key === cmd.blockKey);\n const to = clamp(cmd.to, 0, blocks.length - 1);\n return from < 0 || from === to ? s : ({ ...s, blocks: moved(blocks, from, to) } as unknown as Section);\n });\n\nconst patchBlock: Handler<\"patchBlock\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const blocks = (s.blocks ?? []) as readonly Keyed[];\n const block = blocks.find((b) => b.key === cmd.blockKey);\n if (!block || saysNothingNew(block.settings ?? {}, cmd.patch)) return s;\n return { ...s, blocks: blocks.map((b) => (b === block ? { ...b, settings: { ...b.settings, ...cmd.patch } } : b)) } as unknown as Section;\n });\n\nconst handlers: { [T in Command[\"type\"]]: Handler<T> } = {\n addSection, removeSection, moveSection, setVariant, patchSettings, setText, toggleDisabled, setPreset, setDensity, applyLook: applyLookCmd, setAccent, addBlock, removeBlock, moveBlock, patchBlock,\n};\n\n/** Applies a command to a document; returns the same object when nothing changes. */\nexport function applyCommand(page: ShopPage, cmd: Command): ShopPage {\n return (handlers[cmd.type] as (page: ShopPage, cmd: Command) => ShopPage)(page, cmd);\n}\n"
229
+ "content": "// The composer's commands (ADR-007 §5): every change of the document is a pure command on a reducer — never a mutation —\n// so undo / redo restore the exact document, and the rules of the document (a hero first, 16 sections, 24 blocks, the variants\n// of a type) hold after every step. A command that would break a rule is a no-op: the page stays valid, always.\nimport { SECTION_DEFINITIONS, sectionDefinition,type SectionType } from \"../shop/catalogue\";\nimport { SHOP_LIMITS } from \"../shop/limits\";\nimport { applyLook, type ShopLookLike } from \"../shop/look/apply-look\";\nimport type { Section, ShopPage } from \"../shop/schema\";\nimport type { LocalizedText } from \"../shop/text\";\n\ntype Rec = Record<string, unknown>;\n\nexport type Command =\n /** Adds a section (its type's default settings, the given or the default variant) at an index; a hero goes first. */\n | { type: \"addSection\"; sectionType: SectionType; key: string; variant?: string; at?: number; settings?: Rec }\n | { type: \"removeSection\"; key: string }\n /** Moves a section to an absolute index (the hero stays first: nothing goes above it). */\n | { type: \"moveSection\"; key: string; to: number }\n | { type: \"setVariant\"; key: string; variant: string }\n /** Merges into the settings. */\n | { type: \"patchSettings\"; key: string; patch: Rec }\n | { type: \"setText\"; key: string; field: \"title\" | \"lead\"; value: LocalizedText | undefined }\n | { type: \"toggleDisabled\"; key: string }\n | { type: \"setPreset\"; preset: { id: string; version: number }; density?: \"compact\" | \"airy\" | null }\n | { type: \"setDensity\"; density: \"compact\" | \"airy\" | undefined }\n /** A whole look (`look-*`): the variants of the sections, nothing of their content (`applyLook`). */\n | { type: \"applyLook\"; look: ShopLookLike }\n /** The accent within the look's tested list. */\n | { type: \"setAccent\"; accent: string | undefined }\n | { type: \"addBlock\"; key: string; blockKey: string; blockType: string; settings?: Rec; at?: number }\n | { type: \"removeBlock\"; key: string; blockKey: string }\n | { type: \"moveBlock\"; key: string; blockKey: string; to: number }\n | { type: \"patchBlock\"; key: string; blockKey: string; patch: Rec };\n\nconst clamp = (n: number, lo: number, hi: number) => Math.min(Math.max(n, lo), hi);\nconst indexOfKey = (page: ShopPage, key: string) => page.sections.findIndex((s) => s.key === key);\n\n/** The array with an item moved to an index. */\nexport function moved<T>(list: readonly T[], from: number, to: number): T[] {\n const next = [...list];\n const [item] = next.splice(from, 1);\n next.splice(clamp(to, 0, next.length), 0, item as T);\n return next;\n}\n\nfunction withSection(page: ShopPage, key: string, change: (s: Section) => Section): ShopPage {\n const i = indexOfKey(page, key);\n if (i < 0) return page;\n const next = change(page.sections[i]!);\n if (next === page.sections[i]) return page;\n const sections = [...page.sections];\n sections[i] = next;\n return { ...page, sections };\n}\n\ntype Handler<T extends Command[\"type\"]> = (page: ShopPage, cmd: Extract<Command, { type: T }>) => ShopPage;\n\nconst addSection: Handler<\"addSection\"> = (page, cmd) => {\n const def = SECTION_DEFINITIONS.find((d) => d.type === cmd.sectionType);\n if (!def || page.sections.length >= SHOP_LIMITS.sections || page.sections.some((s) => s.key === cmd.key)) return page;\n const variant = cmd.variant ?? def.defaultVariant;\n if (!(def.variants as readonly string[]).includes(variant)) return page;\n const isHero = def.type === \"hero\";\n if (isHero && page.sections.some((s) => s.type === \"hero\")) return page;\n const heroFirst = page.sections[0]?.type === \"hero\";\n const minAt = heroFirst ? 1 : 0;\n const at = isHero ? 0 : clamp(cmd.at ?? page.sections.length, minAt, page.sections.length);\n const section = { key: cmd.key, type: def.type, variant, settings: { ...(def.settingsDefault as Rec), ...cmd.settings } } as unknown as Section;\n const sections = [...page.sections];\n sections.splice(at, 0, section);\n return { ...page, sections };\n};\n\nconst removeSection: Handler<\"removeSection\"> = (page, cmd) => {\n if (indexOfKey(page, cmd.key) < 0 || page.sections.length <= 1) return page;\n return { ...page, sections: page.sections.filter((s) => s.key !== cmd.key) };\n};\n\nconst moveSection: Handler<\"moveSection\"> = (page, cmd) => {\n const from = indexOfKey(page, cmd.key);\n if (from < 0 || page.sections[from]!.type === \"hero\") return page;\n const lo = page.sections[0]?.type === \"hero\" ? 1 : 0;\n const to = clamp(cmd.to, lo, page.sections.length - 1);\n return to === from ? page : { ...page, sections: moved(page.sections, from, to) };\n};\n\nconst setVariant: Handler<\"setVariant\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const def = sectionDefinition(s.type);\n if (s.variant === cmd.variant || !(def.variants as readonly string[]).includes(cmd.variant)) return s;\n return { ...s, variant: cmd.variant } as Section;\n });\n\n/** Whether every value of a patch is already the one the object holds. */\nconst saysNothingNew = (current: Rec, patch: Rec) => Object.entries(patch).every(([k, v]) => JSON.stringify(current[k]) === JSON.stringify(v));\n\nconst patchSettings: Handler<\"patchSettings\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const current = s.settings as Rec;\n // Nothing to say when every value is already the document's (a form that reports its first values after an undo).\n return saysNothingNew(current, cmd.patch) ? s : ({ ...s, settings: { ...current, ...cmd.patch } } as Section);\n });\n\nconst setText: Handler<\"setText\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const text = { ...(s.text ?? {}) } as Rec;\n if (cmd.value === undefined) delete text[cmd.field];\n else text[cmd.field] = cmd.value;\n const next = { ...s } as Rec;\n if (Object.keys(text).length === 0) delete next.text;\n else next.text = text;\n return next as unknown as Section;\n });\n\nconst toggleDisabled: Handler<\"toggleDisabled\"> = (page, cmd) => withSection(page, cmd.key, (s) => ({ ...s, disabled: s.disabled ? undefined : true }) as Section);\n\nconst setPreset: Handler<\"setPreset\"> = (page, cmd) => {\n if (page.preset.id === cmd.preset.id && page.preset.version === cmd.preset.version && cmd.density === undefined) return page;\n let density: Partial<Pick<ShopPage, \"density\">> = {};\n if (cmd.density === null) density = { density: undefined };\n else if (cmd.density) density = { density: cmd.density };\n return { ...page, preset: { ...cmd.preset }, ...density };\n};\n\nconst setDensity: Handler<\"setDensity\"> = (page, cmd) => (page.density === cmd.density ? page : { ...page, density: cmd.density });\n\nconst applyLookCmd: Handler<\"applyLook\"> = (page, cmd) => applyLook(page, cmd.look);\n\nconst setAccent: Handler<\"setAccent\"> = (page, cmd) => (page.accent === cmd.accent ? page : { ...page, accent: cmd.accent });\n\ntype Keyed = { key: string; type?: string; settings?: Rec };\n\nconst addBlock: Handler<\"addBlock\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const def = sectionDefinition(s.type);\n const blocks = (s.blocks ?? []) as readonly Keyed[];\n if (!(def.blockTypes as readonly string[]).includes(cmd.blockType) || blocks.length >= SHOP_LIMITS.blocks || blocks.some((b) => b.key === cmd.blockKey)) return s;\n const next = [...blocks];\n next.splice(clamp(cmd.at ?? blocks.length, 0, blocks.length), 0, { key: cmd.blockKey, type: cmd.blockType, settings: { ...cmd.settings } });\n return { ...s, blocks: next } as unknown as Section;\n });\n\nconst removeBlock: Handler<\"removeBlock\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const blocks = (s.blocks ?? []) as readonly Keyed[];\n if (!blocks.some((b) => b.key === cmd.blockKey)) return s;\n const next = blocks.filter((b) => b.key !== cmd.blockKey);\n return { ...s, blocks: next.length > 0 ? next : undefined } as unknown as Section;\n });\n\nconst moveBlock: Handler<\"moveBlock\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const blocks = (s.blocks ?? []) as readonly Keyed[];\n const from = blocks.findIndex((b) => b.key === cmd.blockKey);\n const to = clamp(cmd.to, 0, blocks.length - 1);\n return from < 0 || from === to ? s : ({ ...s, blocks: moved(blocks, from, to) } as unknown as Section);\n });\n\nconst patchBlock: Handler<\"patchBlock\"> = (page, cmd) =>\n withSection(page, cmd.key, (s) => {\n const blocks = (s.blocks ?? []) as readonly Keyed[];\n const block = blocks.find((b) => b.key === cmd.blockKey);\n if (!block || saysNothingNew(block.settings ?? {}, cmd.patch)) return s;\n return { ...s, blocks: blocks.map((b) => (b === block ? { ...b, settings: { ...b.settings, ...cmd.patch } } : b)) } as unknown as Section;\n });\n\nconst handlers: { [T in Command[\"type\"]]: Handler<T> } = {\n addSection, removeSection, moveSection, setVariant, patchSettings, setText, toggleDisabled, setPreset, setDensity, applyLook: applyLookCmd, setAccent, addBlock, removeBlock, moveBlock, patchBlock,\n};\n\n/** Applies a command to a document; returns the same object when nothing changes. */\nexport function applyCommand(page: ShopPage, cmd: Command): ShopPage {\n return (handlers[cmd.type] as (page: ShopPage, cmd: Command) => ShopPage)(page, cmd);\n}\n"
230
230
  },
231
231
  {
232
232
  "path": "shop-composer/composer.tsx",
233
- "content": "\"use client\";\n\n// Our own shop composer (ADR-007 §5): three panes on a laptop — the outline of the sections, the live preview of the product's own\n// public page, the inspector of the selected section — and two steps on a phone (the list, then the section; the preview behind a\n// « View » button). Every change is a command on a reducer (⌘Z / ⇧⌘Z, 100 steps), saved to the draft after 800 ms of calm; « Publish »\n// shows what changes and refuses while a setting is invalid. Every action has a keyboard path. No third-party editor: Puck was weighed\n// and not adopted (the model is a list, not a canvas).\nimport { Button } from \"@krizaka/ui/button\";\nimport { Dialog } from \"@krizaka/ui/dialog\";\nimport { RadioGroup } from \"@krizaka/ui/radio-group\";\nimport * as React from \"react\";\n\nimport { cn } from \"../cn\";\nimport { SECTION_DEFINITIONS, type SectionType } from \"../shop/catalogue\";\nimport { postToPreview } from \"../shop/preview\";\nimport { parseShopPage, type ShopPage } from \"../shop/schema\";\nimport { type Command } from \"./commands\";\nimport { type DiffEntry, diffPages } from \"./diff\";\nimport { canRedo, canUndo, createHistory, type History, redo, run, undo } from \"./history\";\nimport { Inspector } from \"./inspector\";\nimport { newKey } from \"./keys\";\nimport { LookPicker } from \"./look-picker\";\nimport { defaultShopComposerMessages, fill, type ShopComposerMessages } from \"./messages\";\nimport { Outline, sectionLabel } from \"./outline\";\n\n/** How long the draft waits for calm before it is saved. */\n// @fixed: ADR-007 §5 — the autosave debounce of the editor, 800 ms; not a shop setting.\nexport const AUTOSAVE_MS = 800;\n\nexport type ShopComposerPreset = {\n id: string;\n version: number;\n name: string;\n density: \"compact\" | \"airy\";\n variants: Readonly<Record<string, string>>;\n /** A look's (`look-*`): the accent it starts with and the tested list the owner chooses from. Presets without a list are trade presets (the « Style » select). */\n accent?: string;\n accents?: readonly string[];\n};\n\nexport type ShopComposerProps = {\n /** The draft to edit. The composer keeps its own history from it. */\n value: ShopPage;\n /** Change it to load another document (another draft): the history and the selection start again. */\n resetKey?: string | number;\n /** Called with a valid draft after 800 ms without a change: save it. A rejection says « Not saved ». */\n onChange?: (page: ShopPage) => void | Promise<void>;\n /** Called with the draft once the person confirmed the diff. */\n onPublish: (page: ShopPage) => void | Promise<void>;\n /** The discard of the draft (the product asks first, in its own dialog). Absent: no such button. */\n onDiscard?: () => void;\n /** What is live now, for the diff of « Publish ». Absent: the document the composer was opened with. */\n published?: ShopPage;\n /** The page of the product, in an iframe: its own route with `?draft=<id>`. Its origin is the bridge's. */\n previewUrl: string;\n /** The look presets of the shop's trade. */\n presets: readonly ShopComposerPreset[];\n /** The section types the trade does not use: folded under « … » in the catalogue. */\n foldedTypes?: readonly SectionType[];\n /** The words, translated. Default: English. */\n messages?: ShopComposerMessages;\n /** Classes merged on the root (its height: `h-[100dvh]`). */\n className?: string;\n};\n\ntype State = { history: History; epoch: number };\ntype Action = { type: \"run\"; cmd: Command; merge?: string } | { type: \"undo\" } | { type: \"redo\" } | { type: \"reset\"; page: ShopPage };\n\nfunction reducer(state: State, a: Action): State {\n switch (a.type) {\n case \"run\": {\n const history = run(state.history, a.cmd, a.merge);\n return history === state.history ? state : { ...state, history };\n }\n case \"undo\": {\n const history = undo(state.history);\n return history === state.history ? state : { history, epoch: state.epoch + 1 };\n }\n case \"redo\": {\n const history = redo(state.history);\n return history === state.history ? state : { history, epoch: state.epoch + 1 };\n }\n case \"reset\":\n return { history: createHistory(a.page), epoch: state.epoch + 1 };\n }\n}\n\nfunction PreviewFrame({ src, title, phone, frame }: { src: string; title: string; phone: boolean; frame: React.Ref<HTMLIFrameElement> }) {\n return (\n <div className=\"flex h-full min-h-0 justify-center overflow-auto bg-surface-2 p-3\">\n <iframe ref={frame} src={src || undefined} title={title} data-device={phone ? \"phone\" : \"desktop\"} className={phone ? \"h-full min-h-[34rem] w-[390px] max-w-full rounded-xl border border-border-default bg-surface-0\" : \"h-full min-h-[34rem] w-full rounded-xl border border-border-default bg-surface-0\"} />\n </div>\n );\n}\n\n/** The shop composer. */\nexport function ShopComposer({ value, resetKey, onChange, onPublish, onDiscard, published, previewUrl, presets, foldedTypes = [], messages = defaultShopComposerMessages, className }: ShopComposerProps) {\n const m = messages;\n const [{ history, epoch }, dispatch] = React.useReducer(reducer, value, (v): State => ({ history: createHistory(v), epoch: 0 }));\n const page = history.present;\n const [baseline, setBaseline] = React.useState(published ?? value);\n const [selected, setSelected] = React.useState<string | null>(page.sections[0]?.key ?? null);\n const [step, setStep] = React.useState<\"list\" | \"section\">(\"list\");\n const [live, setLive] = React.useState(\"\");\n const [status, setStatus] = React.useState<\"idle\" | \"saving\" | \"saved\" | \"error\">(\"idle\");\n const [adding, setAdding] = React.useState(false);\n const [publishing, setPublishing] = React.useState(false);\n const [device, setDevice] = React.useState<\"phone\" | \"desktop\">(\"desktop\");\n const [previewOpen, setPreviewOpen] = React.useState(false);\n const [invalid, setInvalid] = React.useState<ReadonlySet<string>>(new Set());\n const [focusRequest, setFocusRequest] = React.useState<{ key: string } | null>(null);\n const frame = React.useRef<HTMLIFrameElement | null>(null);\n const origin = React.useMemo(() => {\n try {\n return new URL(previewUrl, typeof location === \"undefined\" ? undefined : location.href).origin;\n } catch {\n return \"\";\n }\n }, [previewUrl]);\n\n // A `data:` or `about:` preview has an opaque origin (« null »): nothing can be addressed to it.\n const hasOrigin = origin !== \"\" && origin !== \"null\";\n\n // A new document from outside (another draft): history and selection start again.\n const first = React.useRef(true);\n const saved = React.useRef(page);\n React.useEffect(() => {\n if (first.current) {\n first.current = false;\n return;\n }\n saved.current = value;\n dispatch({ type: \"reset\", page: value });\n setInvalid(new Set());\n setBaseline(published ?? value);\n setSelected(value.sections[0]?.key ?? null);\n // eslint-disable-next-line react-hooks/exhaustive-deps -- only a new `resetKey` reloads the document\n }, [resetKey]);\n\n const parsed = React.useMemo(() => parseShopPage(page), [page]);\n const looks = React.useMemo(() => presets.filter((p) => p.id.startsWith(\"look-\")), [presets]);\n const styles = React.useMemo(() => presets.filter((p) => !p.id.startsWith(\"look-\")), [presets]);\n const announce = React.useCallback((message: string) => setLive((prev) => (prev === message ? message + String.fromCodePoint(0x200b) : message)), []);\n const exec = React.useCallback((cmd: Command, merge?: string) => dispatch({ type: \"run\", cmd, merge }), []);\n const selectedSection = page.sections.find((s) => s.key === selected) ?? null;\n const selectedIndex = selectedSection ? page.sections.indexOf(selectedSection) : -1;\n\n // Autosave to the draft: a valid document, after a calm of 800 ms; the preview refreshes once it is saved.\n React.useEffect(() => {\n if (page === saved.current || !parsed.ok || !onChange) return;\n const timer = setTimeout(async () => {\n setStatus(\"saving\");\n try {\n await onChange(page);\n saved.current = page;\n setStatus(\"saved\");\n if (hasOrigin) postToPreview(frame.current?.contentWindow, origin, { source: \"krizaka-shop-composer\", type: \"refresh\" });\n } catch {\n setStatus(\"error\");\n }\n }, AUTOSAVE_MS);\n return () => clearTimeout(timer);\n }, [page, parsed.ok, onChange, origin, hasOrigin]);\n\n // The preview follows the selection: outline and scroll.\n React.useEffect(() => {\n if (selected && hasOrigin) postToPreview(frame.current?.contentWindow, origin, { source: \"krizaka-shop-composer\", type: \"scroll\", key: selected });\n }, [selected, origin, hasOrigin]);\n\n const select = (key: string) => {\n setSelected(key);\n setStep(\"section\");\n };\n\n const addSection = (type: SectionType) => {\n const def = SECTION_DEFINITIONS.find((d) => d.type === type)!;\n const preferred = presets.find((p) => p.id === page.preset.id)?.variants[type];\n const variant = preferred && (def.variants as readonly string[]).includes(preferred) ? preferred : undefined;\n const key = newKey(\"s\");\n const at = type === \"hero\" ? 0 : page.sections.length;\n exec({ type: \"addSection\", sectionType: type, key, variant, at });\n setAdding(false);\n setSelected(key);\n setFocusRequest({ key });\n announce(fill(m.announceAdded, { name: m.sectionNames[type], n: at + 1 }));\n };\n\n // Undo and redo hand the form a document it did not write: what it said was invalid is no longer true.\n const step_ = (direction: \"undo\" | \"redo\") => {\n dispatch({ type: direction });\n setInvalid(new Set());\n announce(direction === \"undo\" ? m.announceUndone : m.announceRedone);\n };\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (!(e.metaKey || e.ctrlKey) || e.key.toLowerCase() !== \"z\") return;\n const el = e.target as HTMLElement;\n if (el.closest(\"input, textarea, select, [contenteditable=true]\")) return;\n e.preventDefault();\n step_(e.shiftKey ? \"redo\" : \"undo\");\n };\n\n const changes: DiffEntry[] = publishing ? diffPages(baseline, page) : [];\n const nameOfKey = (key: string) => {\n const i = page.sections.findIndex((s) => s.key === key);\n if (i >= 0) return sectionLabel(page.sections, i, m);\n const was = baseline.sections.findIndex((s) => s.key === key);\n return was >= 0 ? sectionLabel(baseline.sections, was, m) : key;\n };\n const problems = [\n ...[...invalid].filter((key) => page.sections.some((s) => s.key === key)).map((key) => ({ key, text: fill(m.problemIn, { name: nameOfKey(key) }) })),\n ...(!parsed.ok ? parsed.issues.map((i) => ({ key: i.path, text: `${i.path}: ${i.message}` })) : []),\n ];\n const describe = (d: DiffEntry): string => {\n const name = \"key\" in d ? nameOfKey(d.key) : \"\";\n const t = m.diff[d.kind];\n switch (d.kind) {\n case \"moved\": return fill(t, { name, from: d.from + 1, to: d.to + 1 });\n case \"variant\": return fill(t, { name, from: m.variantNames[`${d.type}.${d.from}`] ?? d.from, to: m.variantNames[`${d.type}.${d.to}`] ?? d.to });\n case \"preset\": return fill(t, { from: presets.find((p) => p.id === d.from)?.name ?? d.from, to: presets.find((p) => p.id === d.to)?.name ?? d.to });\n case \"density\": return fill(t, { from: d.from ?? \"—\", to: d.to ?? \"—\" });\n default: return fill(t, { name });\n }\n };\n\n const status_ = status === \"saving\" ? m.saving : status === \"saved\" ? m.saved : status === \"error\" ? m.saveFailed : \"\";\n\n return (\n <div className={cn(\"kz-composer flex min-h-0 flex-col gap-3\", className)} onKeyDown={onKeyDown} data-step={step}>\n <header className=\"flex flex-wrap items-center gap-2 border-b border-border-subtle pb-2\">\n <h2 className=\"m-0 me-auto text-base font-semibold text-fg\">{m.title}</h2>\n <span role=\"status\" aria-live=\"polite\" className=\"text-xs text-fg-secondary\">{status_}</span>\n <Button variant=\"ghost\" size=\"sm\" disabled={!canUndo(history)} onClick={() => step_(\"undo\")} aria-keyshortcuts=\"Control+Z Meta+Z\">{m.undo}</Button>\n <Button variant=\"ghost\" size=\"sm\" disabled={!canRedo(history)} onClick={() => step_(\"redo\")} aria-keyshortcuts=\"Control+Shift+Z Meta+Shift+Z\">{m.redo}</Button>\n {onDiscard && <Button variant=\"ghost\" size=\"sm\" onClick={onDiscard}>{m.discard}</Button>}\n <Button variant=\"secondary\" size=\"sm\" className=\"lg:hidden\" onClick={() => setPreviewOpen(true)}>{m.viewPreview}</Button>\n <Button variant=\"primary\" size=\"sm\" onClick={() => setPublishing(true)}>{m.publish}</Button>\n </header>\n {/* One polite live region says every move, add, remove, undo. */}\n <p role=\"status\" aria-live=\"polite\" className=\"sr-only\">{live}</p>\n\n <div className=\"grid min-h-0 flex-1 gap-4 lg:grid-cols-[18rem_minmax(0,1fr)_24rem]\">\n <aside aria-label={m.sections} className={cn(\"flex min-h-0 flex-col gap-4 overflow-y-auto\", step === \"section\" && \"hidden lg:flex\")}>\n <Outline sections={page.sections} selected={selected} onSelect={select} run={exec} messages={m} announce={announce} onAdd={() => setAdding(true)} focusRequest={focusRequest} />\n <details className=\"rounded-lg border border-border-default p-3\" open>\n <summary className=\"min-h-9 cursor-pointer text-sm font-semibold text-fg\">{m.look}</summary>\n <div className=\"mt-2 grid gap-3\">\n {looks.length > 0 && <LookPicker looks={looks} page={page} messages={m} run={exec} announce={announce} />}\n {styles.length > 0 && <label className=\"grid gap-1 text-xs font-semibold text-fg-secondary\">\n {m.preset}\n <select\n className=\"min-h-10 rounded-md border border-border-control bg-surface-1 px-2 text-sm font-normal text-fg\"\n value={page.preset.id}\n onChange={(e) => {\n const p = presets.find((x) => x.id === e.target.value);\n if (p) exec({ type: \"setPreset\", preset: { id: p.id, version: p.version }, density: null });\n }}\n >\n {styles.map((p) => <option key={p.id} value={p.id}>{p.name}</option>)}\n </select>\n </label>}\n <RadioGroup.Root label={m.density} variant=\"segmented\" value={page.density ?? presets.find((p) => p.id === page.preset.id)?.density ?? \"compact\"} onValueChange={(d) => exec({ type: \"setDensity\", density: d as \"compact\" | \"airy\" })}>\n <RadioGroup.Segment value=\"compact\">{m.densityCompact}</RadioGroup.Segment>\n <RadioGroup.Segment value=\"airy\">{m.densityAiry}</RadioGroup.Segment>\n </RadioGroup.Root>\n </div>\n </details>\n </aside>\n\n <section aria-label={m.preview} className=\"hidden min-h-0 flex-col gap-2 lg:flex\">\n <RadioGroup.Root label={m.preview} variant=\"segmented\" value={device} onValueChange={(d) => setDevice(d as \"phone\" | \"desktop\")} className=\"self-start\">\n <RadioGroup.Segment value=\"desktop\">{m.desktop}</RadioGroup.Segment>\n <RadioGroup.Segment value=\"phone\">{m.phone}</RadioGroup.Segment>\n </RadioGroup.Root>\n <PreviewFrame src={previewUrl} title={m.previewTitle} phone={device === \"phone\"} frame={frame} />\n </section>\n\n <aside aria-label={m.inspector} className={cn(\"flex min-h-0 flex-col gap-4 overflow-y-auto\", step === \"list\" && \"hidden lg:flex\")}>\n <Button variant=\"ghost\" size=\"sm\" className=\"self-start lg:hidden\" onClick={() => setStep(\"list\")}>← {m.backToSections}</Button>\n {selectedSection ? (\n <Inspector\n section={selectedSection}\n name={sectionLabel(page.sections, selectedIndex, m)}\n messages={m}\n run={exec}\n epoch={epoch}\n announce={announce}\n onInvalid={(key, bad) => setInvalid((prev) => { const next = new Set(prev); if (bad) next.add(key); else next.delete(key); return next.size === prev.size && next.has(key) === prev.has(key) ? prev : next; })}\n preset={page.preset.id}\n density={page.density}\n />\n ) : (\n <p className=\"m-0 text-sm text-fg-secondary\">{m.noSelection}</p>\n )}\n </aside>\n </div>\n\n <Dialog.Root open={adding} onOpenChange={setAdding}>\n <Dialog.Content closeLabel={m.cancel}>\n <Dialog.Header>\n <Dialog.Title>{m.addSection}</Dialog.Title>\n <Dialog.Description>{m.addSectionHint}</Dialog.Description>\n </Dialog.Header>\n <Dialog.Body>\n {[SECTION_DEFINITIONS.filter((d) => !foldedTypes.includes(d.type)), SECTION_DEFINITIONS.filter((d) => foldedTypes.includes(d.type))].map((group, g) => {\n const list = (\n <ul className=\"m-0 grid list-none gap-1 p-0\">\n {group.map((d) => (\n <li key={d.type}>\n <Button variant=\"ghost\" className=\"w-full justify-start\" disabled={d.type === \"hero\" && page.sections.some((s) => s.type === \"hero\")} onClick={() => addSection(d.type)}>\n {m.sectionNames[d.type]}\n </Button>\n </li>\n ))}\n </ul>\n );\n return group.length === 0 ? null : g === 0 ? <React.Fragment key={g}>{list}</React.Fragment> : <details key={g} className=\"mt-3\"><summary className=\"min-h-9 cursor-pointer text-sm text-fg-secondary\">…</summary>{list}</details>;\n })}\n </Dialog.Body>\n </Dialog.Content>\n </Dialog.Root>\n\n <Dialog.Root open={publishing} onOpenChange={setPublishing}>\n <Dialog.Content closeLabel={m.cancel}>\n <Dialog.Header>\n <Dialog.Title>{m.publishTitle}</Dialog.Title>\n <Dialog.Description>{m.publishWhat}</Dialog.Description>\n </Dialog.Header>\n <Dialog.Body>\n {problems.length > 0 && (\n <div role=\"alert\" className=\"mb-3 rounded-md border border-border-control bg-surface-2 p-3\">\n <p className=\"m-0 text-sm font-semibold text-fg\">{fill(m.problemsTitle, { n: problems.length })}</p>\n <ul className=\"m-0 mt-1 list-disc ps-5 text-sm text-fg-secondary\">{problems.map((p) => <li key={p.key}>{p.text}</li>)}</ul>\n </div>\n )}\n {changes.length === 0 ? (\n <p className=\"m-0 text-sm text-fg-secondary\">{m.publishNothing}</p>\n ) : (\n <ul className=\"m-0 list-disc ps-5 text-sm text-fg\">{changes.map((d, i) => <li key={i}>{describe(d)}</li>)}</ul>\n )}\n </Dialog.Body>\n <Dialog.Footer>\n <Dialog.Close asChild><Button variant=\"ghost\">{m.cancel}</Button></Dialog.Close>\n <Button variant=\"primary\" disabled={problems.length > 0 || !parsed.ok} onClick={async () => { await onPublish(page); setBaseline(page); setPublishing(false); }}>{m.publishConfirm}</Button>\n </Dialog.Footer>\n </Dialog.Content>\n </Dialog.Root>\n\n <Dialog.Root open={previewOpen} onOpenChange={setPreviewOpen}>\n <Dialog.Content closeLabel={m.closePreview} size=\"lg\">\n <Dialog.Header><Dialog.Title>{m.preview}</Dialog.Title></Dialog.Header>\n <Dialog.Body className=\"p-0\">\n {previewOpen && <PreviewFrame src={previewUrl} title={m.previewTitle} phone frame={frame} />}\n </Dialog.Body>\n </Dialog.Content>\n </Dialog.Root>\n </div>\n );\n}\n"
233
+ "content": "\"use client\";\n\n// Our own shop composer (ADR-007 §5): three panes on a laptop — the outline of the sections, the live preview of the product's own\n// public page, the inspector of the selected section — and two steps on a phone (the list, then the section; the preview behind a\n// « View » button). Every change is a command on a reducer (⌘Z / ⇧⌘Z, 100 steps), saved to the draft after 800 ms of calm; « Publish »\n// shows what changes and refuses while a setting is invalid. Every action has a keyboard path. No third-party editor: Puck was weighed\n// and not adopted (the model is a list, not a canvas).\nimport { Button } from \"@krizaka/ui/button\";\nimport { Dialog } from \"@krizaka/ui/dialog\";\nimport { RadioGroup } from \"@krizaka/ui/radio-group\";\nimport * as React from \"react\";\n\nimport { cn } from \"../cn\";\nimport { SECTION_DEFINITIONS, type SectionType } from \"../shop/catalogue\";\nimport { postToPreview } from \"../shop/preview\";\nimport { parseShopPage, type ShopPage } from \"../shop/schema\";\nimport { type Command } from \"./commands\";\nimport { type DiffEntry, diffPages } from \"./diff\";\nimport { canRedo, canUndo, createHistory, type History, redo, run, undo } from \"./history\";\nimport { Inspector } from \"./inspector\";\nimport { newKey } from \"./keys\";\nimport { LookPicker } from \"./look-picker\";\nimport { defaultShopComposerMessages, fill, type ShopComposerMessages } from \"./messages\";\nimport { Outline, sectionLabel } from \"./outline\";\n\n/** How long the draft waits for calm before it is saved. */\n// @fixed: ADR-007 §5 — the autosave debounce of the editor, 800 ms; not a shop setting.\nexport const AUTOSAVE_MS = 800;\n\nexport type ShopComposerPreset = {\n id: string;\n version: number;\n name: string;\n density: \"compact\" | \"airy\";\n variants: Readonly<Record<string, string>>;\n /** A look's (`look-*`): the accent it starts with and the tested list the owner chooses from. Presets without a list are trade presets (the « Style » select). */\n accent?: string;\n accents?: readonly string[];\n};\n\nexport type ShopComposerProps = {\n /** The draft to edit. The composer keeps its own history from it. */\n value: ShopPage;\n /** Change it to load another document (another draft): the history and the selection start again. */\n resetKey?: string | number;\n /** Called with a valid draft after 800 ms without a change: save it. A rejection says « Not saved ». */\n onChange?: (page: ShopPage) => void | Promise<void>;\n /** Called with the draft once the person confirmed the diff. */\n onPublish: (page: ShopPage) => void | Promise<void>;\n /** The discard of the draft (the product asks first, in its own dialog). Absent: no such button. */\n onDiscard?: () => void;\n /** What is live now, for the diff of « Publish ». Absent: the document the composer was opened with. */\n published?: ShopPage;\n /** The page of the product, in an iframe: its own route with `?draft=<id>`. Its origin is the bridge's. */\n previewUrl: string;\n /** The look presets of the shop's trade. */\n presets: readonly ShopComposerPreset[];\n /** The section types the trade does not use: folded under « … » in the catalogue. */\n foldedTypes?: readonly SectionType[];\n /** The words, translated. Default: English. */\n messages?: ShopComposerMessages;\n /** Classes merged on the root (its height: `h-[100dvh]`). */\n className?: string;\n};\n\ntype State = { history: History; epoch: number };\ntype Action = { type: \"run\"; cmd: Command; merge?: string } | { type: \"undo\" } | { type: \"redo\" } | { type: \"reset\"; page: ShopPage };\n\nfunction reducer(state: State, a: Action): State {\n switch (a.type) {\n case \"run\": {\n const history = run(state.history, a.cmd, a.merge);\n return history === state.history ? state : { ...state, history };\n }\n case \"undo\": {\n const history = undo(state.history);\n return history === state.history ? state : { history, epoch: state.epoch + 1 };\n }\n case \"redo\": {\n const history = redo(state.history);\n return history === state.history ? state : { history, epoch: state.epoch + 1 };\n }\n case \"reset\":\n return { history: createHistory(a.page), epoch: state.epoch + 1 };\n }\n}\n\nfunction PreviewFrame({ src, title, phone, frame }: Readonly<{ src: string; title: string; phone: boolean; frame: React.Ref<HTMLIFrameElement> }>) {\n return (\n <div className=\"flex h-full min-h-0 justify-center overflow-auto bg-surface-2 p-3\">\n <iframe ref={frame} src={src || undefined} title={title} data-device={phone ? \"phone\" : \"desktop\"} className={phone ? \"h-full min-h-[34rem] w-[390px] max-w-full rounded-xl border border-border-default bg-surface-0\" : \"h-full min-h-[34rem] w-full rounded-xl border border-border-default bg-surface-0\"} />\n </div>\n );\n}\n\n/** The shop composer. */\nexport function ShopComposer({ value, resetKey, onChange, onPublish, onDiscard, published, previewUrl, presets, foldedTypes = [], messages = defaultShopComposerMessages, className }: Readonly<ShopComposerProps>) {\n const m = messages;\n const [{ history, epoch }, dispatch] = React.useReducer(reducer, value, (v): State => ({ history: createHistory(v), epoch: 0 }));\n const page = history.present;\n const [baseline, setBaseline] = React.useState(published ?? value);\n const [selected, setSelected] = React.useState<string | null>(page.sections[0]?.key ?? null);\n const [step, setStep] = React.useState<\"list\" | \"section\">(\"list\");\n const [live, setLive] = React.useState(\"\");\n const [status, setStatus] = React.useState<\"idle\" | \"saving\" | \"saved\" | \"error\">(\"idle\");\n const [adding, setAdding] = React.useState(false);\n const [publishing, setPublishing] = React.useState(false);\n const [device, setDevice] = React.useState<\"phone\" | \"desktop\">(\"desktop\");\n const [previewOpen, setPreviewOpen] = React.useState(false);\n const [invalid, setInvalid] = React.useState<ReadonlySet<string>>(new Set());\n const [focusRequest, setFocusRequest] = React.useState<{ key: string } | null>(null);\n const frame = React.useRef<HTMLIFrameElement | null>(null);\n const origin = React.useMemo(() => {\n try {\n return new URL(previewUrl, typeof location === \"undefined\" ? undefined : location.href).origin;\n } catch {\n return \"\";\n }\n }, [previewUrl]);\n\n // A `data:` or `about:` preview has an opaque origin (« null »): nothing can be addressed to it.\n const hasOrigin = origin !== \"\" && origin !== \"null\";\n\n // A new document from outside (another draft): history and selection start again.\n const first = React.useRef(true);\n const saved = React.useRef(page);\n React.useEffect(() => {\n if (first.current) {\n first.current = false;\n return;\n }\n saved.current = value;\n dispatch({ type: \"reset\", page: value });\n setInvalid(new Set());\n setBaseline(published ?? value);\n setSelected(value.sections[0]?.key ?? null);\n // eslint-disable-next-line react-hooks/exhaustive-deps -- only a new `resetKey` reloads the document\n }, [resetKey]);\n\n const parsed = React.useMemo(() => parseShopPage(page), [page]);\n const looks = React.useMemo(() => presets.filter((p) => p.id.startsWith(\"look-\")), [presets]);\n const styles = React.useMemo(() => presets.filter((p) => !p.id.startsWith(\"look-\")), [presets]);\n const announce = React.useCallback((message: string) => setLive((prev) => (prev === message ? message + String.fromCodePoint(0x200b) : message)), []);\n const exec = React.useCallback((cmd: Command, merge?: string) => dispatch({ type: \"run\", cmd, merge }), []);\n const selectedSection = page.sections.find((s) => s.key === selected) ?? null;\n const selectedIndex = selectedSection ? page.sections.indexOf(selectedSection) : -1;\n\n // Autosave to the draft: a valid document, after a calm of 800 ms; the preview refreshes once it is saved.\n React.useEffect(() => {\n if (page === saved.current || !parsed.ok || !onChange) return;\n const timer = setTimeout(async () => {\n setStatus(\"saving\");\n try {\n await onChange(page);\n saved.current = page;\n setStatus(\"saved\");\n if (hasOrigin) postToPreview(frame.current?.contentWindow, origin, { source: \"krizaka-shop-composer\", type: \"refresh\" });\n } catch {\n setStatus(\"error\");\n }\n }, AUTOSAVE_MS);\n return () => clearTimeout(timer);\n }, [page, parsed.ok, onChange, origin, hasOrigin]);\n\n // The preview follows the selection: outline and scroll.\n React.useEffect(() => {\n if (selected && hasOrigin) postToPreview(frame.current?.contentWindow, origin, { source: \"krizaka-shop-composer\", type: \"scroll\", key: selected });\n }, [selected, origin, hasOrigin]);\n\n const select = (key: string) => {\n setSelected(key);\n setStep(\"section\");\n };\n\n const addSection = (type: SectionType) => {\n const def = SECTION_DEFINITIONS.find((d) => d.type === type)!;\n const preferred = presets.find((p) => p.id === page.preset.id)?.variants[type];\n const variant = preferred && (def.variants as readonly string[]).includes(preferred) ? preferred : undefined;\n const key = newKey(\"s\");\n const at = type === \"hero\" ? 0 : page.sections.length;\n exec({ type: \"addSection\", sectionType: type, key, variant, at });\n setAdding(false);\n setSelected(key);\n setFocusRequest({ key });\n announce(fill(m.announceAdded, { name: m.sectionNames[type], n: at + 1 }));\n };\n\n // Undo and redo hand the form a document it did not write: what it said was invalid is no longer true.\n const step_ = (direction: \"undo\" | \"redo\") => {\n dispatch({ type: direction });\n setInvalid(new Set());\n announce(direction === \"undo\" ? m.announceUndone : m.announceRedone);\n };\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (!(e.metaKey || e.ctrlKey) || e.key.toLowerCase() !== \"z\") return;\n const el = e.target as HTMLElement;\n if (el.closest(\"input, textarea, select, [contenteditable=true]\")) return;\n e.preventDefault();\n step_(e.shiftKey ? \"redo\" : \"undo\");\n };\n\n const changes: DiffEntry[] = publishing ? diffPages(baseline, page) : [];\n const nameOfKey = (key: string) => {\n const i = page.sections.findIndex((s) => s.key === key);\n if (i >= 0) return sectionLabel(page.sections, i, m);\n const was = baseline.sections.findIndex((s) => s.key === key);\n return was >= 0 ? sectionLabel(baseline.sections, was, m) : key;\n };\n const problems = [\n ...[...invalid].filter((key) => page.sections.some((s) => s.key === key)).map((key) => ({ key, text: fill(m.problemIn, { name: nameOfKey(key) }) })),\n ...(!parsed.ok ? parsed.issues.map((i) => ({ key: i.path, text: `${i.path}: ${i.message}` })) : []),\n ];\n const describe = (d: DiffEntry): string => {\n const name = \"key\" in d ? nameOfKey(d.key) : \"\";\n const t = m.diff[d.kind];\n switch (d.kind) {\n case \"moved\": return fill(t, { name, from: d.from + 1, to: d.to + 1 });\n case \"variant\": return fill(t, { name, from: m.variantNames[`${d.type}.${d.from}`] ?? d.from, to: m.variantNames[`${d.type}.${d.to}`] ?? d.to });\n case \"preset\": return fill(t, { from: presets.find((p) => p.id === d.from)?.name ?? d.from, to: presets.find((p) => p.id === d.to)?.name ?? d.to });\n case \"density\": return fill(t, { from: d.from ?? \"—\", to: d.to ?? \"—\" });\n default: return fill(t, { name });\n }\n };\n\n let status_ = \"\";\n if (status === \"saving\") status_ = m.saving;\n else if (status === \"saved\") status_ = m.saved;\n else if (status === \"error\") status_ = m.saveFailed;\n\n return (\n <div className={cn(\"kz-composer flex min-h-0 flex-col gap-3\", className)} onKeyDown={onKeyDown} data-step={step}>\n <header className=\"flex flex-wrap items-center gap-2 border-b border-border-subtle pb-2\">\n <h2 className=\"m-0 me-auto text-base font-semibold text-fg\">{m.title}</h2>\n <span role=\"status\" aria-live=\"polite\" className=\"text-xs text-fg-secondary\">{status_}</span>\n <Button variant=\"ghost\" size=\"sm\" disabled={!canUndo(history)} onClick={() => step_(\"undo\")} aria-keyshortcuts=\"Control+Z Meta+Z\">{m.undo}</Button>\n <Button variant=\"ghost\" size=\"sm\" disabled={!canRedo(history)} onClick={() => step_(\"redo\")} aria-keyshortcuts=\"Control+Shift+Z Meta+Shift+Z\">{m.redo}</Button>\n {onDiscard && <Button variant=\"ghost\" size=\"sm\" onClick={onDiscard}>{m.discard}</Button>}\n <Button variant=\"secondary\" size=\"sm\" className=\"lg:hidden\" onClick={() => setPreviewOpen(true)}>{m.viewPreview}</Button>\n <Button variant=\"primary\" size=\"sm\" onClick={() => setPublishing(true)}>{m.publish}</Button>\n </header>\n {/* One polite live region says every move, add, remove, undo. */}\n <p role=\"status\" aria-live=\"polite\" className=\"sr-only\">{live}</p>\n\n <div className=\"grid min-h-0 flex-1 gap-4 lg:grid-cols-[18rem_minmax(0,1fr)_24rem]\">\n <aside aria-label={m.sections} className={cn(\"flex min-h-0 flex-col gap-4 overflow-y-auto\", step === \"section\" && \"hidden lg:flex\")}>\n <Outline sections={page.sections} selected={selected} onSelect={select} run={exec} messages={m} announce={announce} onAdd={() => setAdding(true)} focusRequest={focusRequest} />\n <details className=\"rounded-lg border border-border-default p-3\" open>\n <summary className=\"min-h-9 cursor-pointer text-sm font-semibold text-fg\">{m.look}</summary>\n <div className=\"mt-2 grid gap-3\">\n {looks.length > 0 && <LookPicker looks={looks} page={page} messages={m} run={exec} announce={announce} />}\n {styles.length > 0 && <label className=\"grid gap-1 text-xs font-semibold text-fg-secondary\">\n {m.preset}\n <select\n className=\"min-h-10 rounded-md border border-border-control bg-surface-1 px-2 text-sm font-normal text-fg\"\n value={page.preset.id}\n onChange={(e) => {\n const p = presets.find((x) => x.id === e.target.value);\n if (p) exec({ type: \"setPreset\", preset: { id: p.id, version: p.version }, density: null });\n }}\n >\n {styles.map((p) => <option key={p.id} value={p.id}>{p.name}</option>)}\n </select>\n </label>}\n <RadioGroup.Root label={m.density} variant=\"segmented\" value={page.density ?? presets.find((p) => p.id === page.preset.id)?.density ?? \"compact\"} onValueChange={(d) => exec({ type: \"setDensity\", density: d as \"compact\" | \"airy\" })}>\n <RadioGroup.Segment value=\"compact\">{m.densityCompact}</RadioGroup.Segment>\n <RadioGroup.Segment value=\"airy\">{m.densityAiry}</RadioGroup.Segment>\n </RadioGroup.Root>\n </div>\n </details>\n </aside>\n\n <section aria-label={m.preview} className=\"hidden min-h-0 flex-col gap-2 lg:flex\">\n <RadioGroup.Root label={m.preview} variant=\"segmented\" value={device} onValueChange={(d) => setDevice(d as \"phone\" | \"desktop\")} className=\"self-start\">\n <RadioGroup.Segment value=\"desktop\">{m.desktop}</RadioGroup.Segment>\n <RadioGroup.Segment value=\"phone\">{m.phone}</RadioGroup.Segment>\n </RadioGroup.Root>\n <PreviewFrame src={previewUrl} title={m.previewTitle} phone={device === \"phone\"} frame={frame} />\n </section>\n\n <aside aria-label={m.inspector} className={cn(\"flex min-h-0 flex-col gap-4 overflow-y-auto\", step === \"list\" && \"hidden lg:flex\")}>\n <Button variant=\"ghost\" size=\"sm\" className=\"self-start lg:hidden\" onClick={() => setStep(\"list\")}>← {m.backToSections}</Button>\n {selectedSection ? (\n <Inspector\n section={selectedSection}\n name={sectionLabel(page.sections, selectedIndex, m)}\n messages={m}\n run={exec}\n epoch={epoch}\n announce={announce}\n onInvalid={(key, bad) =>\n setInvalid((prev) => {\n const next = new Set(prev);\n if (bad) {\n next.add(key);\n } else {\n next.delete(key);\n }\n return next.size === prev.size && next.has(key) === prev.has(key) ? prev : next;\n })\n }\n preset={page.preset.id}\n density={page.density}\n />\n ) : (\n <p className=\"m-0 text-sm text-fg-secondary\">{m.noSelection}</p>\n )}\n </aside>\n </div>\n\n <Dialog.Root open={adding} onOpenChange={setAdding}>\n <Dialog.Content closeLabel={m.cancel}>\n <Dialog.Header>\n <Dialog.Title>{m.addSection}</Dialog.Title>\n <Dialog.Description>{m.addSectionHint}</Dialog.Description>\n </Dialog.Header>\n <Dialog.Body>\n {[\n { key: \"open\", group: SECTION_DEFINITIONS.filter((d) => !foldedTypes.includes(d.type)) },\n { key: \"folded\", group: SECTION_DEFINITIONS.filter((d) => foldedTypes.includes(d.type)) },\n ].map(({ key: groupKey, group }) => {\n const list = (\n <ul className=\"m-0 grid list-none gap-1 p-0\">\n {group.map((d) => (\n <li key={d.type}>\n <Button variant=\"ghost\" className=\"w-full justify-start\" disabled={d.type === \"hero\" && page.sections.some((s) => s.type === \"hero\")} onClick={() => addSection(d.type)}>\n {m.sectionNames[d.type]}\n </Button>\n </li>\n ))}\n </ul>\n );\n if (group.length === 0) return null;\n if (groupKey === \"open\") return <React.Fragment key={groupKey}>{list}</React.Fragment>;\n return <details key={groupKey} className=\"mt-3\"><summary className=\"min-h-9 cursor-pointer text-sm text-fg-secondary\">…</summary>{list}</details>;\n })}\n </Dialog.Body>\n </Dialog.Content>\n </Dialog.Root>\n\n <Dialog.Root open={publishing} onOpenChange={setPublishing}>\n <Dialog.Content closeLabel={m.cancel}>\n <Dialog.Header>\n <Dialog.Title>{m.publishTitle}</Dialog.Title>\n <Dialog.Description>{m.publishWhat}</Dialog.Description>\n </Dialog.Header>\n <Dialog.Body>\n {problems.length > 0 && (\n <div role=\"alert\" className=\"mb-3 rounded-md border border-border-control bg-surface-2 p-3\">\n <p className=\"m-0 text-sm font-semibold text-fg\">{fill(m.problemsTitle, { n: problems.length })}</p>\n <ul className=\"m-0 mt-1 list-disc ps-5 text-sm text-fg-secondary\">{problems.map((p) => <li key={p.key}>{p.text}</li>)}</ul>\n </div>\n )}\n {changes.length === 0 ? (\n <p className=\"m-0 text-sm text-fg-secondary\">{m.publishNothing}</p>\n ) : (\n <ul className=\"m-0 list-disc ps-5 text-sm text-fg\">{changes.map((d) => <li key={\"key\" in d ? `${d.kind}:${d.key}` : d.kind}>{describe(d)}</li>)}</ul>\n )}\n </Dialog.Body>\n <Dialog.Footer>\n <Dialog.Close asChild><Button variant=\"ghost\">{m.cancel}</Button></Dialog.Close>\n <Button variant=\"primary\" disabled={problems.length > 0 || !parsed.ok} onClick={async () => { await onPublish(page); setBaseline(page); setPublishing(false); }}>{m.publishConfirm}</Button>\n </Dialog.Footer>\n </Dialog.Content>\n </Dialog.Root>\n\n <Dialog.Root open={previewOpen} onOpenChange={setPreviewOpen}>\n <Dialog.Content closeLabel={m.closePreview} size=\"lg\">\n <Dialog.Header><Dialog.Title>{m.preview}</Dialog.Title></Dialog.Header>\n <Dialog.Body className=\"p-0\">\n {previewOpen && <PreviewFrame src={previewUrl} title={m.previewTitle} phone frame={frame} />}\n </Dialog.Body>\n </Dialog.Content>\n </Dialog.Root>\n </div>\n );\n}\n"
234
234
  },
235
235
  {
236
236
  "path": "shop-composer/diff.ts",
@@ -250,7 +250,7 @@
250
250
  },
251
251
  {
252
252
  "path": "shop-composer/inspector.tsx",
253
- "content": "\"use client\";\n\n// The inspector (ADR-007 §5): for the selected section, the variant as a radio group of live thumbnails, the settings as a form\n// generated from the zod schema of its type, the owner's own words (title and line, in each language), and the blocks as a\n// sortable list (Move up / Move down, no drag needed). The look of the whole page is the first tab's concern: see `LookPanel`.\nimport { Button } from \"@krizaka/ui/button\";\nimport { RadioGroup } from \"@krizaka/ui/radio-group\";\nimport * as React from \"react\";\n\nimport { sectionDefinition } from \"../shop/catalogue\";\nimport type { Section } from \"../shop/schema\";\nimport type { Command } from \"./commands\";\nimport { newKey } from \"./keys\";\nimport { fill, type ShopComposerMessages } from \"./messages\";\nimport { SettingsForm } from \"./settings-form\";\nimport { SectionThumbnail } from \"./thumbnails\";\n\nexport type InspectorProps = {\n section: Section;\n name: string;\n messages: ShopComposerMessages;\n run: (cmd: Command, merge?: string) => void;\n /** Bumped when the document changes from outside the form (undo, redo): the settings form remounts. */\n epoch: number;\n announce: (message: string) => void;\n onInvalid: (key: string, invalid: boolean) => void;\n /** The page's look, so a thumbnail wears it. */\n preset?: string;\n density?: \"compact\" | \"airy\";\n};\n\nfunction Words({ section, m, run }: Pick<InspectorProps, \"section\" | \"run\"> & { m: ShopComposerMessages }) {\n const id = React.useId();\n const text = section.text ?? {};\n const field = (name: \"title\" | \"lead\", label: string) => (\n <fieldset className=\"m-0 grid gap-1.5 border-0 p-0\">\n <legend className=\"mb-1 text-xs font-semibold text-fg-secondary\">{label}</legend>\n {([\"fr\", \"en\"] as const).map((lang) => (\n <div key={lang} className=\"flex flex-col gap-1\">\n <label htmlFor={`${id}-${name}-${lang}`} className=\"text-xs text-fg-secondary\">{lang === \"fr\" ? m.french : m.english}</label>\n <input\n id={`${id}-${name}-${lang}`}\n className=\"min-h-10 rounded-md border border-border-control bg-surface-1 px-3 text-sm text-fg focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring\"\n maxLength={600}\n value={text[name]?.[lang] ?? \"\"}\n onChange={(e) => {\n const next = { ...(text[name] ?? {}), [lang]: e.target.value || undefined };\n const empty = !next.fr && !next.en;\n run({ type: \"setText\", key: section.key, field: name, value: empty ? undefined : next }, `text:${section.key}:${name}:${lang}`);\n }}\n />\n </div>\n ))}\n </fieldset>\n );\n return (\n <section aria-label={m.words} className=\"grid gap-3\">\n <h3 className=\"m-0 text-sm font-semibold text-fg\">{m.words}</h3>\n {field(\"title\", m.titleField)}\n {field(\"lead\", m.leadField)}\n </section>\n );\n}\n\nfunction Blocks({ section, m, run, announce }: Pick<InspectorProps, \"section\" | \"run\" | \"announce\"> & { m: ShopComposerMessages }) {\n const def = sectionDefinition(section.type);\n const blocks = ((section.blocks ?? []) as { key: string; type: string }[]);\n if (def.blockTypes.length === 0) return null;\n const label = (b: { type: string }, i: number) => `${m.blockNames[b.type] ?? b.type} ${i + 1}`;\n const move = (i: number, to: number) => {\n const b = blocks[i]!;\n if (to < 0 || to >= blocks.length) return;\n run({ type: \"moveBlock\", key: section.key, blockKey: b.key, to });\n announce(fill(m.announceMoved, { name: label(b, i), n: to + 1, total: blocks.length }));\n };\n return (\n <section aria-label={m.blocks} className=\"grid gap-2\">\n <h3 className=\"m-0 text-sm font-semibold text-fg\">{m.blocks}</h3>\n {blocks.length > 0 && (\n <ol className=\"m-0 grid list-none gap-1 p-0\">\n {blocks.map((b, i) => (\n <li key={b.key} className=\"flex items-center gap-1 rounded-md border border-border-default bg-surface-1 ps-3\">\n <span className=\"min-w-0 flex-1 truncate text-sm text-fg\">{label(b, i)}</span>\n <Button size=\"sm\" variant=\"ghost\" disabled={i === 0} aria-label={`${m.moveUp}: ${label(b, i)}`} onClick={() => move(i, i - 1)}>↑</Button>\n <Button size=\"sm\" variant=\"ghost\" disabled={i === blocks.length - 1} aria-label={`${m.moveDown}: ${label(b, i)}`} onClick={() => move(i, i + 1)}>↓</Button>\n <Button size=\"sm\" variant=\"ghost\" aria-label={fill(m.removeBlock, { name: label(b, i) })} onClick={() => run({ type: \"removeBlock\", key: section.key, blockKey: b.key })}>×</Button>\n </li>\n ))}\n </ol>\n )}\n <div className=\"flex flex-wrap gap-2\">\n {def.blockTypes.map((type) => (\n <Button key={type} size=\"sm\" variant=\"outline\" onClick={() => run({ type: \"addBlock\", key: section.key, blockKey: newKey(\"b\"), blockType: type, settings: defaultBlockSettings(type) })}>\n {m.addBlock} · {m.blockNames[type] ?? type}\n </Button>\n ))}\n </div>\n </section>\n );\n}\n\n/** The first settings of a new block: what its schema needs to be valid (a product then fills the references). */\nfunction defaultBlockSettings(type: string): Record<string, unknown> {\n switch (type) {\n case \"fact\": return { kind: \"open-now\" };\n case \"note\": return { text: \"…\" };\n case \"flyer\": return { text: \"…\" };\n case \"photo\": return { mediaId: \"\" };\n case \"service\": return { serviceId: \"\" };\n case \"member\": return { memberId: \"\" };\n case \"reel\": return { platform: \"tiktok\", url: \"https://\" };\n case \"link\": return { platform: \"instagram\", url: \"https://\" };\n case \"question\": return { question: {}, answer: {} };\n default: return {};\n }\n}\n\nexport function Inspector({ section, name, messages: m, run, epoch, announce, onInvalid, preset, density }: InspectorProps) {\n const def = sectionDefinition(section.type);\n const label = React.useId();\n return (\n <div className=\"flex min-w-0 flex-col gap-6\">\n <section aria-labelledby={label} className=\"grid gap-2\">\n <h3 id={label} className=\"m-0 text-sm font-semibold text-fg\">{m.variant}</h3>\n {/* The thumbnail is a section: it holds links and buttons, so it sits beside the radio, never inside it. */}\n <RadioGroup.Root label={`${name}: ${m.variant}`} value={section.variant} onValueChange={(variant) => run({ type: \"setVariant\", key: section.key, variant })} className=\"grid grid-cols-1 gap-2 sm:grid-cols-2\">\n {def.variants.map((variant) => (\n <div\n key={variant}\n role=\"presentation\"\n data-checked={section.variant === variant ? \"\" : undefined}\n onClick={() => run({ type: \"setVariant\", key: section.key, variant })}\n className=\"grid cursor-pointer gap-2 rounded-lg border border-border-default bg-surface-1 p-2 data-[checked]:border-accent data-[checked]:bg-accent-soft\"\n >\n <SectionThumbnail type={section.type} variant={variant} preset={preset} density={density} />\n <RadioGroup.Item value={variant}>{m.variantNames[`${section.type}.${variant}`] ?? variant}</RadioGroup.Item>\n </div>\n ))}\n </RadioGroup.Root>\n </section>\n <SettingsForm\n key={`${section.key}:${epoch}`}\n section={section}\n messages={m}\n onValid={(settings) => run({ type: \"patchSettings\", key: section.key, patch: settings }, `settings:${section.key}`)}\n onInvalid={(invalid) => onInvalid(section.key, invalid)}\n />\n <Blocks section={section} m={m} run={run} announce={announce} />\n <Words section={section} m={m} run={run} />\n </div>\n );\n}\n"
253
+ "content": "\"use client\";\n\n// The inspector (ADR-007 §5): for the selected section, the variant as a radio group of live thumbnails, the settings as a form\n// generated from the zod schema of its type, the owner's own words (title and line, in each language), and the blocks as a\n// sortable list (Move up / Move down, no drag needed). The look of the whole page is the first tab's concern: see `LookPanel`.\nimport { Button } from \"@krizaka/ui/button\";\nimport { RadioGroup } from \"@krizaka/ui/radio-group\";\nimport * as React from \"react\";\n\nimport { sectionDefinition } from \"../shop/catalogue\";\nimport type { Section } from \"../shop/schema\";\nimport type { Command } from \"./commands\";\nimport { newKey } from \"./keys\";\nimport { fill, type ShopComposerMessages } from \"./messages\";\nimport { SettingsForm } from \"./settings-form\";\nimport { SectionThumbnail } from \"./thumbnails\";\n\nexport type InspectorProps = {\n section: Section;\n name: string;\n messages: ShopComposerMessages;\n run: (cmd: Command, merge?: string) => void;\n /** Bumped when the document changes from outside the form (undo, redo): the settings form remounts. */\n epoch: number;\n announce: (message: string) => void;\n onInvalid: (key: string, invalid: boolean) => void;\n /** The page's look, so a thumbnail wears it. */\n preset?: string;\n density?: \"compact\" | \"airy\";\n};\n\nfunction Words({ section, m, run }: Pick<InspectorProps, \"section\" | \"run\"> & { m: ShopComposerMessages }) {\n const id = React.useId();\n const text = section.text ?? {};\n const field = (name: \"title\" | \"lead\", label: string) => (\n <fieldset className=\"m-0 grid gap-1.5 border-0 p-0\">\n <legend className=\"mb-1 text-xs font-semibold text-fg-secondary\">{label}</legend>\n {([\"fr\", \"en\"] as const).map((lang) => (\n <div key={lang} className=\"flex flex-col gap-1\">\n <label htmlFor={`${id}-${name}-${lang}`} className=\"text-xs text-fg-secondary\">{lang === \"fr\" ? m.french : m.english}</label>\n <input\n id={`${id}-${name}-${lang}`}\n className=\"min-h-10 rounded-md border border-border-control bg-surface-1 px-3 text-sm text-fg focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring\"\n maxLength={600}\n value={text[name]?.[lang] ?? \"\"}\n onChange={(e) => {\n const next = { ...(text[name] ?? {}), [lang]: e.target.value || undefined };\n const empty = !next.fr && !next.en;\n run({ type: \"setText\", key: section.key, field: name, value: empty ? undefined : next }, `text:${section.key}:${name}:${lang}`);\n }}\n />\n </div>\n ))}\n </fieldset>\n );\n return (\n <section aria-label={m.words} className=\"grid gap-3\">\n <h3 className=\"m-0 text-sm font-semibold text-fg\">{m.words}</h3>\n {field(\"title\", m.titleField)}\n {field(\"lead\", m.leadField)}\n </section>\n );\n}\n\nfunction Blocks({ section, m, run, announce }: Pick<InspectorProps, \"section\" | \"run\" | \"announce\"> & { m: ShopComposerMessages }) {\n const def = sectionDefinition(section.type);\n const blocks = ((section.blocks ?? []) as { key: string; type: string }[]);\n if (def.blockTypes.length === 0) return null;\n const label = (b: { type: string }, i: number) => `${m.blockNames[b.type] ?? b.type} ${i + 1}`;\n const move = (i: number, to: number) => {\n const b = blocks[i]!;\n if (to < 0 || to >= blocks.length) return;\n run({ type: \"moveBlock\", key: section.key, blockKey: b.key, to });\n announce(fill(m.announceMoved, { name: label(b, i), n: to + 1, total: blocks.length }));\n };\n return (\n <section aria-label={m.blocks} className=\"grid gap-2\">\n <h3 className=\"m-0 text-sm font-semibold text-fg\">{m.blocks}</h3>\n {blocks.length > 0 && (\n <ol className=\"m-0 grid list-none gap-1 p-0\">\n {blocks.map((b, i) => (\n <li key={b.key} className=\"flex items-center gap-1 rounded-md border border-border-default bg-surface-1 ps-3\">\n <span className=\"min-w-0 flex-1 truncate text-sm text-fg\">{label(b, i)}</span>\n <Button size=\"sm\" variant=\"ghost\" disabled={i === 0} aria-label={`${m.moveUp}: ${label(b, i)}`} onClick={() => move(i, i - 1)}>↑</Button>\n <Button size=\"sm\" variant=\"ghost\" disabled={i === blocks.length - 1} aria-label={`${m.moveDown}: ${label(b, i)}`} onClick={() => move(i, i + 1)}>↓</Button>\n <Button size=\"sm\" variant=\"ghost\" aria-label={fill(m.removeBlock, { name: label(b, i) })} onClick={() => run({ type: \"removeBlock\", key: section.key, blockKey: b.key })}>×</Button>\n </li>\n ))}\n </ol>\n )}\n <div className=\"flex flex-wrap gap-2\">\n {def.blockTypes.map((type) => (\n <Button key={type} size=\"sm\" variant=\"outline\" onClick={() => run({ type: \"addBlock\", key: section.key, blockKey: newKey(\"b\"), blockType: type, settings: defaultBlockSettings(type) })}>\n {m.addBlock} · {m.blockNames[type] ?? type}\n </Button>\n ))}\n </div>\n </section>\n );\n}\n\n/** The first settings of a new block: what its schema needs to be valid (a product then fills the references). */\nfunction defaultBlockSettings(type: string): Record<string, unknown> {\n switch (type) {\n case \"fact\": return { kind: \"open-now\" };\n case \"note\": return { text: \"…\" };\n case \"flyer\": return { text: \"…\" };\n case \"photo\": return { mediaId: \"\" };\n case \"service\": return { serviceId: \"\" };\n case \"member\": return { memberId: \"\" };\n case \"reel\": return { platform: \"tiktok\", url: \"https://\" };\n case \"link\": return { platform: \"instagram\", url: \"https://\" };\n case \"question\": return { question: {}, answer: {} };\n default: return {};\n }\n}\n\nexport function Inspector({ section, name, messages: m, run, epoch, announce, onInvalid, preset, density }: Readonly<InspectorProps>) {\n const def = sectionDefinition(section.type);\n const label = React.useId();\n return (\n <div className=\"flex min-w-0 flex-col gap-6\">\n <section aria-labelledby={label} className=\"grid gap-2\">\n <h3 id={label} className=\"m-0 text-sm font-semibold text-fg\">{m.variant}</h3>\n {/* The thumbnail is a section: it holds links and buttons, so it sits beside the radio, never inside it. */}\n <RadioGroup.Root label={`${name}: ${m.variant}`} value={section.variant} onValueChange={(variant) => run({ type: \"setVariant\", key: section.key, variant })} className=\"grid grid-cols-1 gap-2 sm:grid-cols-2\">\n {def.variants.map((variant) => (\n <div\n key={variant}\n role=\"presentation\"\n data-checked={section.variant === variant ? \"\" : undefined}\n onClick={() => run({ type: \"setVariant\", key: section.key, variant })}\n className=\"grid cursor-pointer gap-2 rounded-lg border border-border-default bg-surface-1 p-2 data-[checked]:border-accent data-[checked]:bg-accent-soft\"\n >\n <SectionThumbnail type={section.type} variant={variant} preset={preset} density={density} />\n <RadioGroup.Item value={variant}>{m.variantNames[`${section.type}.${variant}`] ?? variant}</RadioGroup.Item>\n </div>\n ))}\n </RadioGroup.Root>\n </section>\n <SettingsForm\n key={`${section.key}:${epoch}`}\n section={section}\n messages={m}\n onValid={(settings) => run({ type: \"patchSettings\", key: section.key, patch: settings }, `settings:${section.key}`)}\n onInvalid={(invalid) => onInvalid(section.key, invalid)}\n />\n <Blocks section={section} m={m} run={run} announce={announce} />\n <Words section={section} m={m} run={run} />\n </div>\n );\n}\n"
254
254
  },
255
255
  {
256
256
  "path": "shop-composer/keys.ts",
@@ -258,7 +258,7 @@
258
258
  },
259
259
  {
260
260
  "path": "shop-composer/look-picker.tsx",
261
- "content": "// The look of the page (folioviv#478): a radio group of the six looks as swatches (name, the look's own surface and its accent\n// chips), then the accent within the chosen look's tested list. It applies to the draft only; publishing goes through the diff.\nimport { RadioGroup } from \"@krizaka/ui/radio-group\";\n\nimport { cn } from \"../cn\";\nimport type { ShopPage } from \"../shop/schema\";\nimport type { Command } from \"./commands\";\nimport type { ShopComposerPreset } from \"./composer\";\nimport { fill, type ShopComposerMessages } from \"./messages\";\n\nexport type LookPickerProps = {\n looks: readonly ShopComposerPreset[];\n page: ShopPage;\n messages: ShopComposerMessages;\n run: (cmd: Command) => void;\n announce: (message: string) => void;\n};\n\n/** The accent chips of a look, drawn by its own tokens. */\nfunction Chips({ look }: { look: ShopComposerPreset }) {\n return (\n <span aria-hidden className=\"inline-flex gap-1\">\n {(look.accents ?? [look.accent ?? \"krizaka\"]).map((a) => (\n <span key={a} data-shop-preset={look.id} data-shop-accent={a} className=\"kz-look-chip\">\n <i />\n </span>\n ))}\n </span>\n );\n}\n\nexport function LookPicker({ looks, page, messages: m, run, announce }: LookPickerProps) {\n const current = looks.find((l) => l.id === page.preset.id);\n const accents = current?.accents ?? [];\n return (\n <div className=\"grid gap-3\">\n <RadioGroup.Root\n label={m.lookChoice}\n variant=\"cards\"\n value={current?.id ?? \"\"}\n onValueChange={(id) => {\n const look = looks.find((l) => l.id === id);\n if (!look) return;\n run({ type: \"applyLook\", look });\n announce(fill(m.lookApplied, { name: look.name }));\n }}\n className=\"grid-cols-2\"\n >\n {looks.map((l) => (\n <RadioGroup.Card key={l.id} value={l.id}>\n <span data-shop-preset={l.id} className={cn(\"kz-look-swatch\", \"w-full justify-between\")}>\n <span className=\"text-sm font-semibold\">{l.name}</span>\n <Chips look={l} />\n </span>\n </RadioGroup.Card>\n ))}\n </RadioGroup.Root>\n {accents.length > 1 && (\n <RadioGroup.Root label={m.accentChoice} variant=\"buttons\" value={page.accent ?? current?.accent ?? accents[0]} onValueChange={(a) => run({ type: \"setAccent\", accent: a === current?.accent ? undefined : a })}>\n {accents.map((a) => (\n <RadioGroup.Button key={a} value={a}>\n {m.accentNames[a] ?? a}\n </RadioGroup.Button>\n ))}\n </RadioGroup.Root>\n )}\n </div>\n );\n}\n"
261
+ "content": "// The look of the page (folioviv#478): a radio group of the six looks as swatches (name, the look's own surface and its accent\n// chips), then the accent within the chosen look's tested list. It applies to the draft only; publishing goes through the diff.\nimport { RadioGroup } from \"@krizaka/ui/radio-group\";\n\nimport { cn } from \"../cn\";\nimport type { ShopPage } from \"../shop/schema\";\nimport type { Command } from \"./commands\";\nimport type { ShopComposerPreset } from \"./composer\";\nimport { fill, type ShopComposerMessages } from \"./messages\";\n\nexport type LookPickerProps = {\n looks: readonly ShopComposerPreset[];\n page: ShopPage;\n messages: ShopComposerMessages;\n run: (cmd: Command) => void;\n announce: (message: string) => void;\n};\n\n/** The accent chips of a look, drawn by its own tokens. */\nfunction Chips({ look }: Readonly<{ look: ShopComposerPreset }>) {\n return (\n <span aria-hidden className=\"inline-flex gap-1\">\n {(look.accents ?? [look.accent ?? \"krizaka\"]).map((a) => (\n <span key={a} data-shop-preset={look.id} data-shop-accent={a} className=\"kz-look-chip\">\n <i />\n </span>\n ))}\n </span>\n );\n}\n\nexport function LookPicker({ looks, page, messages: m, run, announce }: Readonly<LookPickerProps>) {\n const current = looks.find((l) => l.id === page.preset.id);\n const accents = current?.accents ?? [];\n return (\n <div className=\"grid gap-3\">\n <RadioGroup.Root\n label={m.lookChoice}\n variant=\"cards\"\n value={current?.id ?? \"\"}\n onValueChange={(id) => {\n const look = looks.find((l) => l.id === id);\n if (!look) return;\n run({ type: \"applyLook\", look });\n announce(fill(m.lookApplied, { name: look.name }));\n }}\n className=\"grid-cols-2\"\n >\n {looks.map((l) => (\n <RadioGroup.Card key={l.id} value={l.id}>\n <span data-shop-preset={l.id} className={cn(\"kz-look-swatch\", \"w-full justify-between\")}>\n <span className=\"text-sm font-semibold\">{l.name}</span>\n <Chips look={l} />\n </span>\n </RadioGroup.Card>\n ))}\n </RadioGroup.Root>\n {accents.length > 1 && (\n <RadioGroup.Root label={m.accentChoice} variant=\"buttons\" value={page.accent ?? current?.accent ?? accents[0]} onValueChange={(a) => run({ type: \"setAccent\", accent: a === current?.accent ? undefined : a })}>\n {accents.map((a) => (\n <RadioGroup.Button key={a} value={a}>\n {m.accentNames[a] ?? a}\n </RadioGroup.Button>\n ))}\n </RadioGroup.Root>\n )}\n </div>\n );\n}\n"
262
262
  },
263
263
  {
264
264
  "path": "shop-composer/messages.ts",
@@ -270,15 +270,15 @@
270
270
  },
271
271
  {
272
272
  "path": "shop-composer/outline.tsx",
273
- "content": "\"use client\";\n\n// The outline (ADR-007 §5): the sections in order — name, the variant as a mono note, a visibility switch, a menu. Drag is an\n// extra the page does not need: the path is the keyboard — focus a row, `Alt+↑` / `Alt+↓` (or the row's menu: Move up, Move\n// down, Move to top). Every move is announced (« Reviews moved to position 3 of 8 ») and focus stays on the moved row.\nimport { Button } from \"@krizaka/ui/button\";\nimport { DropdownMenu } from \"@krizaka/ui/dropdown-menu\";\nimport { Switch } from \"@krizaka/ui/switch\";\nimport * as React from \"react\";\n\nimport type { Section } from \"../shop/schema\";\nimport type { Command } from \"./commands\";\nimport { fill, type ShopComposerMessages } from \"./messages\";\n\nexport type OutlineProps = {\n sections: readonly Section[];\n selected: string | null;\n onSelect: (key: string) => void;\n run: (cmd: Command, merge?: string) => void;\n messages: ShopComposerMessages;\n announce: (message: string) => void;\n onAdd: () => void;\n /** A request to focus a row (a new section): a new object each time; consumed once, after the render that drew the row. */\n focusRequest?: { key: string } | null;\n};\n\n/** « Photos », « Photos 2 » when a type appears twice. */\nexport function sectionLabel(sections: readonly Section[], index: number, messages: ShopComposerMessages): string {\n const s = sections[index]!;\n const same = sections.filter((x) => x.type === s.type);\n const base = messages.sectionNames[s.type];\n return same.length > 1 ? `${base} ${same.indexOf(s) + 1}` : base;\n}\n\nconst ICON = \"h-4 w-4\";\n\nexport function Outline({ sections, selected, onSelect, run, messages: m, announce, onAdd, focusRequest }: OutlineProps) {\n const rows = React.useRef(new Map<string, HTMLButtonElement>());\n // After a move (or a menu action) the moved row keeps the focus: the DOM may have reordered under it. A request is consumed once —\n // never on the next change of the document, which may be typing somewhere else.\n const wanted = React.useRef<string | null>(null);\n const [tick, setTick] = React.useState(0);\n const want = (key: string) => {\n wanted.current = key;\n setTick((t) => t + 1);\n };\n React.useLayoutEffect(() => {\n if (focusRequest) wanted.current = focusRequest.key;\n }, [focusRequest]);\n React.useLayoutEffect(() => {\n const key = wanted.current;\n wanted.current = null;\n if (key) rows.current.get(key)?.focus();\n }, [tick, focusRequest]);\n\n const move = (index: number, to: number) => {\n const s = sections[index]!;\n const name = sectionLabel(sections, index, m);\n const lo = sections[0]?.type === \"hero\" ? 1 : 0;\n const clamped = Math.min(Math.max(to, lo), sections.length - 1);\n if (s.type === \"hero\" || clamped === index) {\n announce(fill(m.announceCannotMove, { name }));\n return;\n }\n run({ type: \"moveSection\", key: s.key, to: clamped });\n want(s.key);\n announce(fill(m.announceMoved, { name, n: clamped + 1, total: sections.length }));\n };\n\n const onKeyDown = (e: React.KeyboardEvent, index: number) => {\n if (e.altKey && (e.key === \"ArrowUp\" || e.key === \"ArrowDown\")) {\n e.preventDefault();\n move(index, index + (e.key === \"ArrowUp\" ? -1 : 1));\n } else if (!e.altKey && (e.key === \"ArrowUp\" || e.key === \"ArrowDown\")) {\n const next = sections[index + (e.key === \"ArrowUp\" ? -1 : 1)];\n if (next) {\n e.preventDefault();\n rows.current.get(next.key)?.focus();\n }\n }\n };\n\n return (\n <nav aria-label={m.sections} className=\"flex min-h-0 flex-col gap-3\">\n <ol className=\"m-0 flex list-none flex-col gap-1 p-0\">\n {sections.map((s, i) => {\n const name = sectionLabel(sections, i, m);\n const isHero = s.type === \"hero\";\n const lo = sections[0]?.type === \"hero\" ? 1 : 0;\n return (\n <li key={s.key} data-selected={selected === s.key ? \"\" : undefined} data-disabled={s.disabled ? \"\" : undefined} className=\"flex items-center gap-1 rounded-lg border border-transparent data-[selected]:border-accent data-[selected]:bg-accent-soft\">\n <button\n type=\"button\"\n ref={(el) => {\n if (el) rows.current.set(s.key, el);\n else rows.current.delete(s.key);\n }}\n aria-current={selected === s.key ? \"true\" : undefined}\n aria-keyshortcuts=\"Alt+ArrowUp Alt+ArrowDown\"\n onClick={() => onSelect(s.key)}\n onKeyDown={(e) => onKeyDown(e, i)}\n className=\"flex min-h-11 min-w-0 flex-1 flex-col items-start justify-center rounded-lg px-3 py-1.5 text-start focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring\"\n >\n <span className=\"flex w-full items-baseline gap-2\">\n <span className={s.disabled ? \"truncate text-sm font-semibold text-fg-secondary line-through decoration-1\" : \"truncate text-sm font-semibold text-fg\"}>{name}</span>\n {s.disabled && <span className=\"font-mono text-[11px] text-fg-secondary\">{m.hiddenNote}</span>}\n </span>\n <span className=\"font-mono text-xs text-fg-secondary\">{m.variantNames[`${s.type}.${s.variant}`] ?? s.variant}</span>\n </button>\n <Switch\n size=\"sm\"\n label={fill(m.toggleVisible, { name })}\n checked={!s.disabled}\n onCheckedChange={(on) => {\n run({ type: \"toggleDisabled\", key: s.key });\n announce(fill(on ? m.announceShown : m.announceHidden, { name }));\n }}\n />\n <DropdownMenu.Root>\n <DropdownMenu.Trigger asChild>\n <Button variant=\"ghost\" size=\"icon\" aria-label={fill(m.sectionMenu, { name })}>\n <svg viewBox=\"0 0 16 16\" className={ICON} fill=\"currentColor\" aria-hidden>\n <circle cx=\"8\" cy=\"3\" r=\"1.4\" />\n <circle cx=\"8\" cy=\"8\" r=\"1.4\" />\n <circle cx=\"8\" cy=\"13\" r=\"1.4\" />\n </svg>\n </Button>\n </DropdownMenu.Trigger>\n <DropdownMenu.Content\n onCloseAutoFocus={(e) => {\n e.preventDefault();\n rows.current.get(s.key)?.focus();\n }}\n >\n <DropdownMenu.Item disabled={isHero || i <= lo} onSelect={() => move(i, i - 1)}>{m.moveUp}</DropdownMenu.Item>\n <DropdownMenu.Item disabled={isHero || i >= sections.length - 1} onSelect={() => move(i, i + 1)}>{m.moveDown}</DropdownMenu.Item>\n <DropdownMenu.Item disabled={isHero || i <= lo} onSelect={() => move(i, lo)}>{m.moveTop}</DropdownMenu.Item>\n <DropdownMenu.Separator />\n <DropdownMenu.Item\n tone=\"danger\"\n disabled={sections.length <= 1}\n onSelect={() => {\n run({ type: \"removeSection\", key: s.key });\n announce(fill(m.announceRemoved, { name }));\n const next = sections[i + 1] ?? sections[i - 1];\n if (next) want(next.key);\n }}\n >\n {m.remove}\n </DropdownMenu.Item>\n </DropdownMenu.Content>\n </DropdownMenu.Root>\n </li>\n );\n })}\n </ol>\n <Button variant=\"outline\" onClick={onAdd}>{m.addSection}</Button>\n </nav>\n );\n}\n"
273
+ "content": "\"use client\";\n\n// The outline (ADR-007 §5): the sections in order — name, the variant as a mono note, a visibility switch, a menu. Drag is an\n// extra the page does not need: the path is the keyboard — focus a row, `Alt+↑` / `Alt+↓` (or the row's menu: Move up, Move\n// down, Move to top). Every move is announced (« Reviews moved to position 3 of 8 ») and focus stays on the moved row.\nimport { Button } from \"@krizaka/ui/button\";\nimport { DropdownMenu } from \"@krizaka/ui/dropdown-menu\";\nimport { Switch } from \"@krizaka/ui/switch\";\nimport * as React from \"react\";\n\nimport type { Section } from \"../shop/schema\";\nimport type { Command } from \"./commands\";\nimport { fill, type ShopComposerMessages } from \"./messages\";\n\nexport type OutlineProps = {\n sections: readonly Section[];\n selected: string | null;\n onSelect: (key: string) => void;\n run: (cmd: Command, merge?: string) => void;\n messages: ShopComposerMessages;\n announce: (message: string) => void;\n onAdd: () => void;\n /** A request to focus a row (a new section): a new object each time; consumed once, after the render that drew the row. */\n focusRequest?: { key: string } | null;\n};\n\n/** « Photos », « Photos 2 » when a type appears twice. */\nexport function sectionLabel(sections: readonly Section[], index: number, messages: ShopComposerMessages): string {\n const s = sections[index]!;\n const same = sections.filter((x) => x.type === s.type);\n const base = messages.sectionNames[s.type];\n return same.length > 1 ? `${base} ${same.indexOf(s) + 1}` : base;\n}\n\nconst ICON = \"h-4 w-4\";\n\nexport function Outline({ sections, selected, onSelect, run, messages: m, announce, onAdd, focusRequest }: Readonly<OutlineProps>) {\n const rows = React.useRef(new Map<string, HTMLButtonElement>());\n // After a move (or a menu action) the moved row keeps the focus: the DOM may have reordered under it. A request is consumed once —\n // never on the next change of the document, which may be typing somewhere else.\n const wanted = React.useRef<string | null>(null);\n const [tick, setTick] = React.useState(0);\n const want = (key: string) => {\n wanted.current = key;\n setTick((t) => t + 1);\n };\n React.useLayoutEffect(() => {\n if (focusRequest) wanted.current = focusRequest.key;\n }, [focusRequest]);\n React.useLayoutEffect(() => {\n const key = wanted.current;\n wanted.current = null;\n if (key) rows.current.get(key)?.focus();\n }, [tick, focusRequest]);\n\n const move = (index: number, to: number) => {\n const s = sections[index]!;\n const name = sectionLabel(sections, index, m);\n const lo = sections[0]?.type === \"hero\" ? 1 : 0;\n const clamped = Math.min(Math.max(to, lo), sections.length - 1);\n if (s.type === \"hero\" || clamped === index) {\n announce(fill(m.announceCannotMove, { name }));\n return;\n }\n run({ type: \"moveSection\", key: s.key, to: clamped });\n want(s.key);\n announce(fill(m.announceMoved, { name, n: clamped + 1, total: sections.length }));\n };\n\n const onKeyDown = (e: React.KeyboardEvent, index: number) => {\n if (e.altKey && (e.key === \"ArrowUp\" || e.key === \"ArrowDown\")) {\n e.preventDefault();\n move(index, index + (e.key === \"ArrowUp\" ? -1 : 1));\n } else if (!e.altKey && (e.key === \"ArrowUp\" || e.key === \"ArrowDown\")) {\n const next = sections[index + (e.key === \"ArrowUp\" ? -1 : 1)];\n if (next) {\n e.preventDefault();\n rows.current.get(next.key)?.focus();\n }\n }\n };\n\n return (\n <nav aria-label={m.sections} className=\"flex min-h-0 flex-col gap-3\">\n <ol className=\"m-0 flex list-none flex-col gap-1 p-0\">\n {sections.map((s, i) => {\n const name = sectionLabel(sections, i, m);\n const isHero = s.type === \"hero\";\n const lo = sections[0]?.type === \"hero\" ? 1 : 0;\n return (\n <li key={s.key} data-selected={selected === s.key ? \"\" : undefined} data-disabled={s.disabled ? \"\" : undefined} className=\"flex items-center gap-1 rounded-lg border border-transparent data-[selected]:border-accent data-[selected]:bg-accent-soft\">\n <button\n type=\"button\"\n ref={(el) => {\n if (el) rows.current.set(s.key, el);\n else rows.current.delete(s.key);\n }}\n aria-current={selected === s.key ? \"true\" : undefined}\n aria-keyshortcuts=\"Alt+ArrowUp Alt+ArrowDown\"\n onClick={() => onSelect(s.key)}\n onKeyDown={(e) => onKeyDown(e, i)}\n className=\"flex min-h-11 min-w-0 flex-1 flex-col items-start justify-center rounded-lg px-3 py-1.5 text-start focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring\"\n >\n <span className=\"flex w-full items-baseline gap-2\">\n <span className={s.disabled ? \"truncate text-sm font-semibold text-fg-secondary line-through decoration-1\" : \"truncate text-sm font-semibold text-fg\"}>{name}</span>\n {s.disabled && <span className=\"font-mono text-[11px] text-fg-secondary\">{m.hiddenNote}</span>}\n </span>\n <span className=\"font-mono text-xs text-fg-secondary\">{m.variantNames[`${s.type}.${s.variant}`] ?? s.variant}</span>\n </button>\n <Switch\n size=\"sm\"\n label={fill(m.toggleVisible, { name })}\n checked={!s.disabled}\n onCheckedChange={(on) => {\n run({ type: \"toggleDisabled\", key: s.key });\n announce(fill(on ? m.announceShown : m.announceHidden, { name }));\n }}\n />\n <DropdownMenu.Root>\n <DropdownMenu.Trigger asChild>\n <Button variant=\"ghost\" size=\"icon\" aria-label={fill(m.sectionMenu, { name })}>\n <svg viewBox=\"0 0 16 16\" className={ICON} fill=\"currentColor\" aria-hidden>\n <circle cx=\"8\" cy=\"3\" r=\"1.4\" />\n <circle cx=\"8\" cy=\"8\" r=\"1.4\" />\n <circle cx=\"8\" cy=\"13\" r=\"1.4\" />\n </svg>\n </Button>\n </DropdownMenu.Trigger>\n <DropdownMenu.Content\n onCloseAutoFocus={(e) => {\n e.preventDefault();\n rows.current.get(s.key)?.focus();\n }}\n >\n <DropdownMenu.Item disabled={isHero || i <= lo} onSelect={() => move(i, i - 1)}>{m.moveUp}</DropdownMenu.Item>\n <DropdownMenu.Item disabled={isHero || i >= sections.length - 1} onSelect={() => move(i, i + 1)}>{m.moveDown}</DropdownMenu.Item>\n <DropdownMenu.Item disabled={isHero || i <= lo} onSelect={() => move(i, lo)}>{m.moveTop}</DropdownMenu.Item>\n <DropdownMenu.Separator />\n <DropdownMenu.Item\n tone=\"danger\"\n disabled={sections.length <= 1}\n onSelect={() => {\n run({ type: \"removeSection\", key: s.key });\n announce(fill(m.announceRemoved, { name }));\n const next = sections[i + 1] ?? sections[i - 1];\n if (next) want(next.key);\n }}\n >\n {m.remove}\n </DropdownMenu.Item>\n </DropdownMenu.Content>\n </DropdownMenu.Root>\n </li>\n );\n })}\n </ol>\n <Button variant=\"outline\" onClick={onAdd}>{m.addSection}</Button>\n </nav>\n );\n}\n"
274
274
  },
275
275
  {
276
276
  "path": "shop-composer/settings-form.tsx",
277
- "content": "\"use client\";\n\n// The settings of a section, as a form generated from the zod schema of its type (ADR-007 §5): the form is `@krizaka/ui/form`\n// (TanStack Form behind the facade), the fields are the ones the schema describes (`fields.ts`). Every valid change is committed to\n// the document at once (so undo and the preview follow); an invalid value is said next to its field, stays in the field, and is\n// reported to the composer, which refuses to publish until it is fixed.\nimport { createKrizakaForm, FormField, Switch, TextArea, TextField, useFormContext } from \"@krizaka/ui/form\";\nimport { RadioGroup } from \"@krizaka/ui/radio-group\";\nimport * as React from \"react\";\n\nimport { type SectionDefinition, sectionDefinition } from \"../shop/catalogue\";\nimport type { Section } from \"../shop/schema\";\nimport { describeSettings, type FieldSpec } from \"./fields\";\nimport type { ShopComposerMessages } from \"./messages\";\n\ntype Factory = ReturnType<typeof createKrizakaForm>;\n// One form per section type, defined once (schema + defaults), as the facade asks.\nconst factories = new Map<string, Factory>();\nfunction factoryFor(def: SectionDefinition): Factory {\n let f = factories.get(def.type);\n if (!f) {\n f = createKrizakaForm({ schema: def.settings as never, defaultValues: def.settingsDefault as never }) as unknown as Factory;\n factories.set(def.type, f);\n }\n return f;\n}\n\nconst nameOf = (m: ShopComposerMessages, key: string) => m.settingNames[key] ?? key;\nconst optionName = (m: ShopComposerMessages, o: string | number) => m.optionNames[String(o)] ?? String(o);\n\nfunction Choice({ spec, m }: { spec: Extract<FieldSpec, { kind: \"choice\" }>; m: ShopComposerMessages }) {\n return (\n <FormField name={spec.name}>\n {(f) => (\n <div className=\"grid gap-1.5\">\n <span aria-hidden className=\"text-xs font-semibold text-fg-secondary\">{nameOf(m, spec.name)}</span>\n <RadioGroup.Root label={nameOf(m, spec.name)} variant=\"segmented\" value={String(f.value)} onValueChange={(v) => f.setValue(spec.options.find((o) => String(o) === v))} onBlur={f.onBlur}>\n {spec.options.map((o) => (\n <RadioGroup.Segment key={String(o)} value={String(o)}>{optionName(m, o)}</RadioGroup.Segment>\n ))}\n </RadioGroup.Root>\n </div>\n )}\n </FormField>\n );\n}\n\nfunction Multi({ spec, m }: { spec: Extract<FieldSpec, { kind: \"multi\" }>; m: ShopComposerMessages }) {\n return (\n <FormField name={spec.name}>\n {(f) => {\n const value = (f.value as string[] | undefined) ?? [];\n return (\n <fieldset className=\"m-0 flex flex-col gap-1.5 border-0 p-0\">\n <legend className=\"mb-1 text-xs font-semibold text-fg-secondary\">{nameOf(m, spec.name)}</legend>\n {spec.options.map((o) => (\n <label key={o} className=\"flex min-h-9 items-center gap-2 text-sm text-fg\">\n <input\n type=\"checkbox\"\n className=\"h-4 w-4 accent-accent\"\n checked={value.includes(o)}\n onChange={(e) => f.setValue(e.target.checked ? [...value, o] : value.filter((x) => x !== o))}\n />\n {optionName(m, o)}\n </label>\n ))}\n </fieldset>\n );\n }}\n </FormField>\n );\n}\n\nfunction Field({ spec, m }: { spec: FieldSpec; m: ShopComposerMessages }) {\n switch (spec.kind) {\n case \"choice\":\n return <Choice spec={spec} m={m} />;\n case \"multi\":\n return <Multi spec={spec} m={m} />;\n case \"toggle\":\n return <Switch name={spec.name} label={nameOf(m, spec.name)} />;\n case \"text\":\n return <TextField name={spec.name} label={nameOf(m, spec.name)} />;\n case \"localized\":\n return (\n <div className=\"flex flex-col gap-2\">\n <TextArea name={`${spec.name}.fr`} label={`${nameOf(m, spec.name)} — ${m.french}`} rows={3} maxLength={600} />\n <TextArea name={`${spec.name}.en`} label={`${nameOf(m, spec.name)} — ${m.english}`} rows={3} maxLength={600} />\n </div>\n );\n }\n}\n\n/** What the schema is asked: an emptied text is an absent setting (an optional id), an emptied language an absent language. */\nfunction normalise(values: unknown): unknown {\n if (Array.isArray(values)) return values;\n if (typeof values !== \"object\" || values === null) return values;\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(values)) {\n if (v === \"\") continue;\n const inner = typeof v === \"object\" && v !== null && !Array.isArray(v) ? normalise(v) : v;\n out[k] = inner;\n }\n return out;\n}\n\n/** Reports the form's values: a valid set goes to `onValid`, an invalid one to `onInvalid` (and never reaches the document). */\nfunction Commit({ def, onValid, onInvalid }: { def: SectionDefinition; onValid: (settings: Record<string, unknown>) => void; onInvalid: (invalid: boolean) => void }) {\n const { api } = useFormContext();\n const latest = React.useRef({ onValid, onInvalid });\n React.useEffect(() => {\n latest.current = { onValid, onInvalid };\n });\n React.useEffect(() => {\n const sub = (api.store as { subscribe: (cb: () => void) => unknown }).subscribe(() => {\n const result = def.settings.safeParse(normalise(api.state.values));\n latest.current.onInvalid(!result.success);\n if (result.success) latest.current.onValid(result.data as Record<string, unknown>);\n });\n return () => {\n const s = sub as { unsubscribe?: () => void } | (() => void);\n if (typeof s === \"function\") s();\n else s?.unsubscribe?.();\n };\n }, [api, def]);\n return null;\n}\n\nexport type SettingsFormProps = {\n section: Section;\n messages: ShopComposerMessages;\n /** A valid set of settings: the composer commits it. */\n onValid: (settings: Record<string, unknown>) => void;\n /** Whether the form holds a value the schema refuses (publish waits). */\n onInvalid: (invalid: boolean) => void;\n};\n\n/** The form of a section's settings: remount it (a `key`) when the document is changed from outside (undo, redo). */\nexport function SettingsForm({ section, messages: m, onValid, onInvalid }: SettingsFormProps) {\n const def = sectionDefinition(section.type);\n const factory = factoryFor(def);\n const form = factory.useForm({ defaultValues: section.settings as never }) as unknown as { Form: (p: { \"aria-label\": string; className?: string; children: React.ReactNode }) => React.ReactElement };\n const specs = describeSettings(def.settings);\n if (specs.length === 0) return null;\n return (\n <form.Form aria-label={m.settings} className=\"flex flex-col gap-4\">\n {specs.map((spec) => (\n <Field key={spec.name} spec={spec} m={m} />\n ))}\n <Commit def={def} onValid={onValid} onInvalid={onInvalid} />\n </form.Form>\n );\n}\n"
277
+ "content": "\"use client\";\n\n// The settings of a section, as a form generated from the zod schema of its type (ADR-007 §5): the form is `@krizaka/ui/form`\n// (TanStack Form behind the facade), the fields are the ones the schema describes (`fields.ts`). Every valid change is committed to\n// the document at once (so undo and the preview follow); an invalid value is said next to its field, stays in the field, and is\n// reported to the composer, which refuses to publish until it is fixed.\nimport { createKrizakaForm, FormField, Switch, TextArea, TextField, useFormContext } from \"@krizaka/ui/form\";\nimport { RadioGroup } from \"@krizaka/ui/radio-group\";\nimport * as React from \"react\";\n\nimport { type SectionDefinition, sectionDefinition } from \"../shop/catalogue\";\nimport type { Section } from \"../shop/schema\";\nimport { describeSettings, type FieldSpec } from \"./fields\";\nimport type { ShopComposerMessages } from \"./messages\";\n\ntype Factory = ReturnType<typeof createKrizakaForm>;\n// One form per section type, defined once (schema + defaults), as the facade asks.\nconst factories = new Map<string, Factory>();\nfunction factoryFor(def: SectionDefinition): Factory {\n let f = factories.get(def.type);\n if (!f) {\n f = createKrizakaForm({ schema: def.settings as never, defaultValues: def.settingsDefault as never }) as unknown as Factory;\n factories.set(def.type, f);\n }\n return f;\n}\n\nconst nameOf = (m: ShopComposerMessages, key: string) => m.settingNames[key] ?? key;\nconst optionName = (m: ShopComposerMessages, o: string | number) => m.optionNames[String(o)] ?? String(o);\n\nfunction Choice({ spec, m }: Readonly<{ spec: Extract<FieldSpec, { kind: \"choice\" }>; m: ShopComposerMessages }>) {\n return (\n <FormField name={spec.name}>\n {(f) => (\n <div className=\"grid gap-1.5\">\n <span aria-hidden className=\"text-xs font-semibold text-fg-secondary\">{nameOf(m, spec.name)}</span>\n <RadioGroup.Root label={nameOf(m, spec.name)} variant=\"segmented\" value={String(f.value)} onValueChange={(v) => f.setValue(spec.options.find((o) => String(o) === v))} onBlur={f.onBlur}>\n {spec.options.map((o) => (\n <RadioGroup.Segment key={String(o)} value={String(o)}>{optionName(m, o)}</RadioGroup.Segment>\n ))}\n </RadioGroup.Root>\n </div>\n )}\n </FormField>\n );\n}\n\nfunction Multi({ spec, m }: Readonly<{ spec: Extract<FieldSpec, { kind: \"multi\" }>; m: ShopComposerMessages }>) {\n return (\n <FormField name={spec.name}>\n {(f) => {\n const value = (f.value as string[] | undefined) ?? [];\n return (\n <fieldset className=\"m-0 flex flex-col gap-1.5 border-0 p-0\">\n <legend className=\"mb-1 text-xs font-semibold text-fg-secondary\">{nameOf(m, spec.name)}</legend>\n {spec.options.map((o) => (\n <label key={o} className=\"flex min-h-9 items-center gap-2 text-sm text-fg\">\n <input\n type=\"checkbox\"\n className=\"h-4 w-4 accent-accent\"\n checked={value.includes(o)}\n onChange={(e) => f.setValue(e.target.checked ? [...value, o] : value.filter((x) => x !== o))}\n />\n {optionName(m, o)}\n </label>\n ))}\n </fieldset>\n );\n }}\n </FormField>\n );\n}\n\nfunction Field({ spec, m }: Readonly<{ spec: FieldSpec; m: ShopComposerMessages }>) {\n switch (spec.kind) {\n case \"choice\":\n return <Choice spec={spec} m={m} />;\n case \"multi\":\n return <Multi spec={spec} m={m} />;\n case \"toggle\":\n return <Switch name={spec.name} label={nameOf(m, spec.name)} />;\n case \"text\":\n return <TextField name={spec.name} label={nameOf(m, spec.name)} />;\n case \"localized\":\n return (\n <div className=\"flex flex-col gap-2\">\n <TextArea name={`${spec.name}.fr`} label={`${nameOf(m, spec.name)} — ${m.french}`} rows={3} maxLength={600} />\n <TextArea name={`${spec.name}.en`} label={`${nameOf(m, spec.name)} — ${m.english}`} rows={3} maxLength={600} />\n </div>\n );\n }\n}\n\n/** What the schema is asked: an emptied text is an absent setting (an optional id), an emptied language an absent language. */\nfunction normalise(values: unknown): unknown {\n if (Array.isArray(values)) return values;\n if (typeof values !== \"object\" || values === null) return values;\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(values)) {\n if (v === \"\") continue;\n const inner = typeof v === \"object\" && v !== null && !Array.isArray(v) ? normalise(v) : v;\n out[k] = inner;\n }\n return out;\n}\n\n/** Reports the form's values: a valid set goes to `onValid`, an invalid one to `onInvalid` (and never reaches the document). */\nfunction Commit({ def, onValid, onInvalid }: { def: SectionDefinition; onValid: (settings: Record<string, unknown>) => void; onInvalid: (invalid: boolean) => void }) {\n const { api } = useFormContext();\n const latest = React.useRef({ onValid, onInvalid });\n React.useEffect(() => {\n latest.current = { onValid, onInvalid };\n });\n React.useEffect(() => {\n const sub = (api.store as { subscribe: (cb: () => void) => unknown }).subscribe(() => {\n const result = def.settings.safeParse(normalise(api.state.values));\n latest.current.onInvalid(!result.success);\n if (result.success) latest.current.onValid(result.data as Record<string, unknown>);\n });\n return () => {\n const s = sub as { unsubscribe?: () => void } | (() => void);\n if (typeof s === \"function\") s();\n else s?.unsubscribe?.();\n };\n }, [api, def]);\n return null;\n}\n\nexport type SettingsFormProps = {\n section: Section;\n messages: ShopComposerMessages;\n /** A valid set of settings: the composer commits it. */\n onValid: (settings: Record<string, unknown>) => void;\n /** Whether the form holds a value the schema refuses (publish waits). */\n onInvalid: (invalid: boolean) => void;\n};\n\n/** The form of a section's settings: remount it (a `key`) when the document is changed from outside (undo, redo). */\nexport function SettingsForm({ section, messages: m, onValid, onInvalid }: Readonly<SettingsFormProps>) {\n const def = sectionDefinition(section.type);\n const factory = factoryFor(def);\n const form = factory.useForm({ defaultValues: section.settings as never }) as unknown as { Form: (p: { \"aria-label\": string; className?: string; children: React.ReactNode }) => React.ReactElement };\n const specs = describeSettings(def.settings);\n if (specs.length === 0) return null;\n return (\n <form.Form aria-label={m.settings} className=\"flex flex-col gap-4\">\n {specs.map((spec) => (\n <Field key={spec.name} spec={spec} m={m} />\n ))}\n <Commit def={def} onValid={onValid} onInvalid={onInvalid} />\n </form.Form>\n );\n}\n"
278
278
  },
279
279
  {
280
280
  "path": "shop-composer/thumbnails.tsx",
281
- "content": "\"use client\";\n\n// The variant picker's thumbnails (ADR-007 §5): the section itself, drawn with demo data at the scale of a card — not a screenshot,\n// so a new variant or a new preset needs no new picture, and each thumbnail wears the page's look (the preset applies around it).\nimport * as React from \"react\";\n\nimport { Button } from \"../button/button\";\nimport { BookingSection } from \"../shop/booking/booking\";\nimport { BulletinSection } from \"../shop/bulletin/bulletin\";\nimport type { SectionType } from \"../shop/catalogue\";\nimport { demoSalon } from \"../shop/demo\";\nimport { FaqSection } from \"../shop/faq/faq\";\nimport { ShopFrame } from \"../shop/frame\";\nimport { GallerySection } from \"../shop/gallery/gallery\";\nimport { HeroSection } from \"../shop/hero/hero\";\nimport { PoliciesSection } from \"../shop/policies/policies\";\nimport { ReviewsSection } from \"../shop/reviews/reviews\";\nimport { ServicesSection } from \"../shop/services/services\";\nimport { SocialSection } from \"../shop/social/social\";\nimport { StorySection } from \"../shop/story/story\";\nimport { TeamSection } from \"../shop/team/team\";\nimport { VideoSection } from \"../shop/video/video\";\nimport { VisitSection } from \"../shop/visit/visit\";\n\nconst shop = demoSalon;\nconst play = { tiktok: \"Play\", \"youtube-shorts\": \"Play\", instagram: \"Play\" } as const;\nconst reel = { id: \"r\", platform: \"tiktok\" as const, url: \"https://www.tiktok.com/@salon/video/7000000000000000000\", title: \"Reel\" };\nconst summary = {\n score: 4.7, count: 38, distribution: [0, 1, 2, 7, 28] as [number, number, number, number, number],\n scoreText: \"4.7 / 5\", countText: \"38 reviews\", summaryText: \"4.7 out of 5, 38 reviews\", starText: (s: number, n: number) => `${s} stars: ${n}`,\n};\nconst review = { id: \"a\", author: \"Nadia F.\", date: \"October 2026\", dateTime: \"2026-10\", service: \"Cut and blow-dry\", rating: 5, ratingText: \"5 out of 5\", text: \"The best blow-dry in the neighbourhood, simply.\" };\n\n/** The section as it looks with demo data, in the variant asked. */\nfunction Demo({ type, variant }: { type: SectionType; variant: string }): React.ReactNode {\n const v = variant as never;\n switch (type) {\n case \"hero\":\n return <HeroSection variant={v} title={shop.name} eyebrow={shop.eyebrow} lead={shop.promise} cover={shop.cover} actions={<Button variant=\"primary\">Book</Button>} tv={{ poster: shop.cover.src, title: \"Latest video\" } as never} />;\n case \"services\":\n return <ServicesSection variant={v} title=\"Services\" services={shop.services} chooseLabel=\"Choose\" popularLabel=\"Popular\" />;\n case \"booking\":\n return variant === \"sticky\" ? <div className=\"flex items-center justify-center border-t border-border-default bg-surface-1 p-4\"><Button variant=\"primary\" size=\"lg\">Book</Button></div> : <BookingSection variant={v} label=\"Next free times\" times={shop.times} href=\"#\" actionLabel=\"Book\" title=\"Ready when you are\" body=\"A few taps.\" />;\n case \"gallery\":\n return <GallerySection variant={v} title=\"Photos\" label=\"Photos\" photos={shop.photos} sign={shop.name} />;\n case \"video\":\n return <VideoSection variant={v} title=\"Latest\" reels={[reel, { ...reel, id: \"r2\" }]} playLabels={play} />;\n case \"reviews\":\n return <ReviewsSection variant={v} title=\"Reviews\" summary={summary} reviews={[review, { ...review, id: \"b\", author: \"Léo P.\" }]} />;\n case \"bulletin\":\n return <BulletinSection variant={v} title=\"News\" today=\"2026-10-27\" flyers={[{ id: \"f\", text: \"Closed on Monday the 3rd: see you on Tuesday!\", signature: \"Jade\" }]} />;\n case \"team\":\n return <TeamSection variant={v} title=\"Team\" members={shop.team.map((t) => ({ id: t.id, name: t.name, role: \"Stylist\" }))} />;\n case \"visit\":\n return <VisitSection variant={v} title=\"Visit\" hours={shop.hours} status={shop.status} hoursLabel=\"Hours\" address={shop.address} phone={{ href: \"tel:5145550110\", label: shop.phone }} map={{ label: \"Map\", center: [-73.58, 45.48], showLabel: \"Show the map\" }} />;\n case \"story\":\n return <StorySection variant={v} title=\"Our story\" quote=\"Cuts that last, advice that is honest.\" body=\"Three friends opened the salon in 2019, on the corner where the old bakery stood.\" owner={{ name: \"Jade\" }} />;\n case \"social\":\n return <SocialSection variant={v} title=\"Follow us\" links={[{ id: \"a\", platform: \"instagram\", url: \"https://instagram.com/salon\" }, { id: \"b\", platform: \"tiktok\", url: \"https://tiktok.com/@salon\" }]} playLabels={play} />;\n case \"faq\":\n return <FaqSection title=\"Questions\" questions={[{ id: \"q\", question: \"Do I need to book?\", answer: \"Yes, pick a time online.\" }, { id: \"q2\", question: \"Can I cancel?\", answer: \"Up to 24 hours before.\" }]} />;\n case \"policies\":\n return <PoliciesSection title=\"Policies\" items={[{ id: \"p\", term: \"Cancellation\", details: \"Free up to 24 h before\" }, { id: \"p2\", term: \"Prices\", details: \"Before taxes\" }]} />;\n }\n}\n\nexport type SectionThumbnailProps = {\n /** The section type. */\n type: SectionType;\n /** Its variant: one of the type's. */\n variant: string;\n /** The look preset the page wears (`salon-vitrine`): the thumbnail wears it too. */\n preset?: string;\n /** The page's spacing. @default \"compact\" */\n density?: \"compact\" | \"airy\";\n};\n\n/** A picture of a section: 160 × 96 px of a 960 px page, inert and hidden from assistive technology. */\nexport function SectionThumbnail({ type, variant, preset, density }: SectionThumbnailProps) {\n return (\n <div aria-hidden inert className=\"kz-shop-thumb\" data-thumb={`${type}.${variant}`}>\n <div className=\"kz-shop-thumb-inner\">\n <ShopFrame preset={preset} density={density ?? \"compact\"}>\n <Demo type={type} variant={variant} />\n </ShopFrame>\n </div>\n </div>\n );\n}\n"
281
+ "content": "\"use client\";\n\n// The variant picker's thumbnails (ADR-007 §5): the section itself, drawn with demo data at the scale of a card — not a screenshot,\n// so a new variant or a new preset needs no new picture, and each thumbnail wears the page's look (the preset applies around it).\nimport * as React from \"react\";\n\nimport { Button } from \"../button/button\";\nimport { BookingSection } from \"../shop/booking/booking\";\nimport { BulletinSection } from \"../shop/bulletin/bulletin\";\nimport type { SectionType } from \"../shop/catalogue\";\nimport { demoSalon } from \"../shop/demo\";\nimport { FaqSection } from \"../shop/faq/faq\";\nimport { ShopFrame } from \"../shop/frame\";\nimport { GallerySection } from \"../shop/gallery/gallery\";\nimport { HeroSection } from \"../shop/hero/hero\";\nimport { PoliciesSection } from \"../shop/policies/policies\";\nimport { ReviewsSection } from \"../shop/reviews/reviews\";\nimport { ServicesSection } from \"../shop/services/services\";\nimport { SocialSection } from \"../shop/social/social\";\nimport { StorySection } from \"../shop/story/story\";\nimport { TeamSection } from \"../shop/team/team\";\nimport { VideoSection } from \"../shop/video/video\";\nimport { VisitSection } from \"../shop/visit/visit\";\n\nconst shop = demoSalon;\nconst play = { tiktok: \"Play\", \"youtube-shorts\": \"Play\", instagram: \"Play\" } as const;\nconst reel = { id: \"r\", platform: \"tiktok\" as const, url: \"https://www.tiktok.com/@salon/video/7000000000000000000\", title: \"Reel\" };\nconst summary = {\n score: 4.7, count: 38, distribution: [0, 1, 2, 7, 28] as [number, number, number, number, number],\n scoreText: \"4.7 / 5\", countText: \"38 reviews\", summaryText: \"4.7 out of 5, 38 reviews\", starText: (s: number, n: number) => `${s} stars: ${n}`,\n};\nconst review = { id: \"a\", author: \"Nadia F.\", date: \"October 2026\", dateTime: \"2026-10\", service: \"Cut and blow-dry\", rating: 5, ratingText: \"5 out of 5\", text: \"The best blow-dry in the neighbourhood, simply.\" };\n\n/** The section as it looks with demo data, in the variant asked. */\nfunction Demo({ type, variant }: Readonly<{ type: SectionType; variant: string }>): React.ReactNode {\n const v = variant as never;\n switch (type) {\n case \"hero\":\n return <HeroSection variant={v} title={shop.name} eyebrow={shop.eyebrow} lead={shop.promise} cover={shop.cover} actions={<Button variant=\"primary\">Book</Button>} tv={{ poster: shop.cover.src, title: \"Latest video\" } as never} />;\n case \"services\":\n return <ServicesSection variant={v} title=\"Services\" services={shop.services} chooseLabel=\"Choose\" popularLabel=\"Popular\" />;\n case \"booking\":\n return variant === \"sticky\" ? <div className=\"flex items-center justify-center border-t border-border-default bg-surface-1 p-4\"><Button variant=\"primary\" size=\"lg\">Book</Button></div> : <BookingSection variant={v} label=\"Next free times\" times={shop.times} href=\"#\" actionLabel=\"Book\" title=\"Ready when you are\" body=\"A few taps.\" />;\n case \"gallery\":\n return <GallerySection variant={v} title=\"Photos\" label=\"Photos\" photos={shop.photos} sign={shop.name} />;\n case \"video\":\n return <VideoSection variant={v} title=\"Latest\" reels={[reel, { ...reel, id: \"r2\" }]} playLabels={play} />;\n case \"reviews\":\n return <ReviewsSection variant={v} title=\"Reviews\" summary={summary} reviews={[review, { ...review, id: \"b\", author: \"Léo P.\" }]} />;\n case \"bulletin\":\n return <BulletinSection variant={v} title=\"News\" today=\"2026-10-27\" flyers={[{ id: \"f\", text: \"Closed on Monday the 3rd: see you on Tuesday!\", signature: \"Jade\" }]} />;\n case \"team\":\n return <TeamSection variant={v} title=\"Team\" members={shop.team.map((t) => ({ id: t.id, name: t.name, role: \"Stylist\" }))} />;\n case \"visit\":\n return <VisitSection variant={v} title=\"Visit\" hours={shop.hours} status={shop.status} hoursLabel=\"Hours\" address={shop.address} phone={{ href: \"tel:5145550110\", label: shop.phone }} map={{ label: \"Map\", center: [-73.58, 45.48], showLabel: \"Show the map\" }} />;\n case \"story\":\n return <StorySection variant={v} title=\"Our story\" quote=\"Cuts that last, advice that is honest.\" body=\"Three friends opened the salon in 2019, on the corner where the old bakery stood.\" owner={{ name: \"Jade\" }} />;\n case \"social\":\n return <SocialSection variant={v} title=\"Follow us\" links={[{ id: \"a\", platform: \"instagram\", url: \"https://instagram.com/salon\" }, { id: \"b\", platform: \"tiktok\", url: \"https://tiktok.com/@salon\" }]} playLabels={play} />;\n case \"faq\":\n return <FaqSection title=\"Questions\" questions={[{ id: \"q\", question: \"Do I need to book?\", answer: \"Yes, pick a time online.\" }, { id: \"q2\", question: \"Can I cancel?\", answer: \"Up to 24 hours before.\" }]} />;\n case \"policies\":\n return <PoliciesSection title=\"Policies\" items={[{ id: \"p\", term: \"Cancellation\", details: \"Free up to 24 h before\" }, { id: \"p2\", term: \"Prices\", details: \"Before taxes\" }]} />;\n }\n}\n\nexport type SectionThumbnailProps = {\n /** The section type. */\n type: SectionType;\n /** Its variant: one of the type's. */\n variant: string;\n /** The look preset the page wears (`salon-vitrine`): the thumbnail wears it too. */\n preset?: string;\n /** The page's spacing. @default \"compact\" */\n density?: \"compact\" | \"airy\";\n};\n\n/** A picture of a section: 160 × 96 px of a 960 px page, inert and hidden from assistive technology. */\nexport function SectionThumbnail({ type, variant, preset, density }: Readonly<SectionThumbnailProps>) {\n return (\n <div aria-hidden inert className=\"kz-shop-thumb\" data-thumb={`${type}.${variant}`}>\n <div className=\"kz-shop-thumb-inner\">\n <ShopFrame preset={preset} density={density ?? \"compact\"}>\n <Demo type={type} variant={variant} />\n </ShopFrame>\n </div>\n </div>\n );\n}\n"
282
282
  }
283
283
  ],
284
284
  "dependencies": [
@@ -146,7 +146,7 @@
146
146
  },
147
147
  {
148
148
  "path": "shop-gallery/lightbox.tsx",
149
- "content": "\"use client\";\n\n// The lightbox: loaded as a lazy chunk, only once a photo is opened. A Dialog (focus trapped, Escape, scroll lock), arrow\n// keys and a horizontal swipe, the photo at full resolution and its alt text as the caption.\nimport * as React from \"react\";\n\nimport { IconButton } from \"../button/button\";\nimport { Dialog } from \"../dialog\";\nimport type { ShopGalleryLabels } from \"./labels\";\nimport type { ShopGalleryPhoto } from \"./shop-gallery\";\n\nconst SWIPE = 50;\n\nfunction Arrow({ dir }: { dir: \"left\" | \"right\" }) {\n return (\n <svg viewBox=\"0 0 24 24\" className=\"h-4 w-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <path d={dir === \"left\" ? \"m15 6-6 6 6 6\" : \"m9 6 6 6-6 6\"} />\n </svg>\n );\n}\n\nexport type ShopGalleryLightboxProps = {\n photos: readonly ShopGalleryPhoto[];\n index: number;\n onIndexChange: (index: number) => void;\n onClose: () => void;\n label: string;\n labels: ShopGalleryLabels;\n /** Where focus goes back to when it closes. */\n returnFocus: () => HTMLElement | null;\n};\n\nexport default function ShopGalleryLightbox({ photos, index, onIndexChange, onClose, label, labels, returnFocus }: ShopGalleryLightboxProps) {\n const total = photos.length;\n const photo = photos[index];\n const startX = React.useRef<number | null>(null);\n const go = (to: number) => onIndexChange(((to % total) + total) % total);\n if (!photo) return null;\n const preload = [photos[(index + 1) % total], photos[(index - 1 + total) % total]];\n return (\n <Dialog.Root open onOpenChange={(open) => !open && onClose()}>\n <Dialog.Content\n closeLabel={labels.close}\n size=\"lg\"\n className=\"kz-sg-lightbox sm:max-w-5xl\"\n onCloseAutoFocus={(event) => {\n const target = returnFocus();\n if (target) {\n event.preventDefault();\n target.focus();\n }\n }}\n onKeyDown={(event) => {\n if (event.key === \"ArrowLeft\") go(index - 1);\n else if (event.key === \"ArrowRight\") go(index + 1);\n }}\n >\n <style>{`.kz-sg-stage{touch-action:pan-y}.kz-sg-lightbox img{user-select:none;-webkit-user-drag:none}@media (prefers-reduced-motion:no-preference){.kz-sg-photo{animation:kz-sg-in .22s ease-out}}@keyframes kz-sg-in{from{opacity:.4}to{opacity:1}}`}</style>\n <Dialog.Header>\n <Dialog.Title className=\"sr-only\">{labels.title(label)}</Dialog.Title>\n <p className=\"m-0 text-sm text-fg-secondary\" aria-live=\"polite\">{labels.position(index + 1, total)}</p>\n </Dialog.Header>\n <Dialog.Body className=\"flex flex-col gap-3\">\n <div\n className=\"kz-sg-stage relative flex items-center justify-center\"\n onTouchStart={(event) => {\n startX.current = event.touches[0]?.clientX ?? null;\n }}\n onTouchEnd={(event) => {\n const from = startX.current;\n const to = event.changedTouches[0]?.clientX;\n startX.current = null;\n if (from === null || to === undefined) return;\n if (to - from <= -SWIPE) go(index + 1);\n else if (to - from >= SWIPE) go(index - 1);\n }}\n >\n <img\n key={photo.id}\n src={photo.fullSrc ?? photo.src}\n srcSet={photo.fullSrcSet ?? photo.srcSet}\n sizes={photo.fullSrcSet ?? photo.srcSet ? \"(min-width: 64rem) 64rem, 100vw\" : undefined}\n alt={photo.alt}\n decoding=\"async\"\n className=\"kz-sg-photo max-h-[68dvh] w-full rounded-lg object-contain\"\n />\n {total > 1 && (\n <>\n <IconButton label={labels.previous} variant=\"secondary\" shape=\"pill\" className=\"absolute left-2 top-1/2 -translate-y-1/2\" onClick={() => go(index - 1)}>\n <Arrow dir=\"left\" />\n </IconButton>\n <IconButton label={labels.next} variant=\"secondary\" shape=\"pill\" className=\"absolute right-2 top-1/2 -translate-y-1/2\" onClick={() => go(index + 1)}>\n <Arrow dir=\"right\" />\n </IconButton>\n </>\n )}\n </div>\n <Dialog.Description className=\"m-0 min-h-5 text-center\">{photo.alt}</Dialog.Description>\n <div hidden aria-hidden>\n {preload.map((p) => p && p.id !== photo.id && <img key={p.id} src={p.fullSrc ?? p.src} alt=\"\" />)}\n </div>\n </Dialog.Body>\n </Dialog.Content>\n </Dialog.Root>\n );\n}\n"
149
+ "content": "\"use client\";\n\n// The lightbox: loaded as a lazy chunk, only once a photo is opened. A Dialog (focus trapped, Escape, scroll lock), arrow\n// keys and a horizontal swipe, the photo at full resolution and its alt text as the caption.\nimport * as React from \"react\";\n\nimport { IconButton } from \"../button/button\";\nimport { Dialog } from \"../dialog\";\nimport type { ShopGalleryLabels } from \"./labels\";\nimport type { ShopGalleryPhoto } from \"./shop-gallery\";\n\nconst SWIPE = 50;\n\nfunction Arrow({ dir }: Readonly<{ dir: \"left\" | \"right\" }>) {\n return (\n <svg viewBox=\"0 0 24 24\" className=\"h-4 w-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n <path d={dir === \"left\" ? \"m15 6-6 6 6 6\" : \"m9 6 6 6-6 6\"} />\n </svg>\n );\n}\n\nexport type ShopGalleryLightboxProps = {\n photos: readonly ShopGalleryPhoto[];\n index: number;\n onIndexChange: (index: number) => void;\n onClose: () => void;\n label: string;\n labels: ShopGalleryLabels;\n /** Where focus goes back to when it closes. */\n returnFocus: () => HTMLElement | null;\n};\n\nexport default function ShopGalleryLightbox({ photos, index, onIndexChange, onClose, label, labels, returnFocus }: Readonly<ShopGalleryLightboxProps>) {\n const total = photos.length;\n const photo = photos[index];\n const startX = React.useRef<number | null>(null);\n const go = (to: number) => onIndexChange(((to % total) + total) % total);\n if (!photo) return null;\n const preload = [photos[(index + 1) % total], photos[(index - 1 + total) % total]];\n return (\n <Dialog.Root open onOpenChange={(open) => !open && onClose()}>\n <Dialog.Content\n closeLabel={labels.close}\n size=\"lg\"\n className=\"kz-sg-lightbox sm:max-w-5xl\"\n onCloseAutoFocus={(event) => {\n const target = returnFocus();\n if (target) {\n event.preventDefault();\n target.focus();\n }\n }}\n onKeyDown={(event) => {\n if (event.key === \"ArrowLeft\") go(index - 1);\n else if (event.key === \"ArrowRight\") go(index + 1);\n }}\n >\n <style>{`.kz-sg-stage{touch-action:pan-y}.kz-sg-lightbox img{user-select:none;-webkit-user-drag:none}@media (prefers-reduced-motion:no-preference){.kz-sg-photo{animation:kz-sg-in .22s ease-out}}@keyframes kz-sg-in{from{opacity:.4}to{opacity:1}}`}</style>\n <Dialog.Header>\n <Dialog.Title className=\"sr-only\">{labels.title(label)}</Dialog.Title>\n <p className=\"m-0 text-sm text-fg-secondary\" aria-live=\"polite\">{labels.position(index + 1, total)}</p>\n </Dialog.Header>\n <Dialog.Body className=\"flex flex-col gap-3\">\n <div\n className=\"kz-sg-stage relative flex items-center justify-center\"\n onTouchStart={(event) => {\n startX.current = event.touches[0]?.clientX ?? null;\n }}\n onTouchEnd={(event) => {\n const from = startX.current;\n const to = event.changedTouches[0]?.clientX;\n startX.current = null;\n if (from === null || to === undefined) return;\n if (to - from <= -SWIPE) go(index + 1);\n else if (to - from >= SWIPE) go(index - 1);\n }}\n >\n <img\n key={photo.id}\n src={photo.fullSrc ?? photo.src}\n srcSet={photo.fullSrcSet ?? photo.srcSet}\n sizes={photo.fullSrcSet ?? photo.srcSet ? \"(min-width: 64rem) 64rem, 100vw\" : undefined}\n alt={photo.alt}\n decoding=\"async\"\n className=\"kz-sg-photo max-h-[68dvh] w-full rounded-lg object-contain\"\n />\n {total > 1 && (\n <>\n <IconButton label={labels.previous} variant=\"secondary\" shape=\"pill\" className=\"absolute left-2 top-1/2 -translate-y-1/2\" onClick={() => go(index - 1)}>\n <Arrow dir=\"left\" />\n </IconButton>\n <IconButton label={labels.next} variant=\"secondary\" shape=\"pill\" className=\"absolute right-2 top-1/2 -translate-y-1/2\" onClick={() => go(index + 1)}>\n <Arrow dir=\"right\" />\n </IconButton>\n </>\n )}\n </div>\n <Dialog.Description className=\"m-0 min-h-5 text-center\">{photo.alt}</Dialog.Description>\n <div hidden aria-hidden>\n {preload.map((p) => p && p.id !== photo.id && <img key={p.id} src={p.fullSrc ?? p.src} alt=\"\" />)}\n </div>\n </Dialog.Body>\n </Dialog.Content>\n </Dialog.Root>\n );\n}\n"
150
150
  },
151
151
  {
152
152
  "path": "shop-gallery/meta.ts",