@canonical/summon-application 0.48.0 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/README.md +20 -26
  2. package/dist/esm/application/react/index.js +28 -1
  3. package/dist/esm/application/react/index.js.map +1 -1
  4. package/dist/esm/application/react/templates/README.md.ejs +5 -0
  5. package/dist/esm/application/react/templates/src/domains/catalog/ProductCard.tsx.ejs +2 -2
  6. package/dist/esm/application/react/templates/src/domains/dashboard/InstancesPage.tsx.ejs +1 -1
  7. package/dist/esm/application/react/templates/src/domains/dashboard/OverviewPage.tsx.ejs +6 -6
  8. package/dist/esm/application/react/templates/src/i18n/ar.ts.ejs +1 -0
  9. package/dist/esm/application/react/templates/src/i18n/config.ts +2 -2
  10. package/dist/esm/application/react/templates/src/i18n/en.ts.ejs +1 -0
  11. package/dist/esm/application/react/templates/src/i18n/fr.ts.ejs +1 -0
  12. package/dist/esm/application/react/templates/src/i18n/negotiation.test.ts +5 -5
  13. package/dist/esm/application/react/templates/src/lib/LocaleSelector/LocaleSelector.test.tsx +10 -0
  14. package/dist/esm/application/react/templates/src/lib/LocaleSelector/LocaleSelector.tsx.ejs +35 -21
  15. package/dist/esm/application/react/templates/src/lib/ThemeSelector/ServerThemeContext.ts +13 -0
  16. package/dist/esm/application/react/templates/src/lib/ThemeSelector/ThemeSelector.ssr.test.tsx.ejs +45 -0
  17. package/dist/esm/application/react/templates/src/lib/ThemeSelector/ThemeSelector.test.tsx.ejs +67 -0
  18. package/dist/esm/application/react/templates/src/lib/ThemeSelector/ThemeSelector.tsx.ejs +60 -26
  19. package/dist/esm/application/react/templates/src/lib/ThemeSelector/index.ts.ejs +4 -0
  20. package/dist/esm/application/react/templates/src/lib/TopBar/TopBar.test.tsx.ejs +7 -10
  21. package/dist/esm/application/react/templates/src/lib/TopBar/styles.css +8 -3
  22. package/dist/esm/application/react/templates/src/server/entry.tsx.ejs +23 -14
  23. package/dist/esm/application/react/templates/src/server/handlePreferenceForm.test.ts.ejs +63 -0
  24. package/dist/esm/application/react/templates/src/server/handlePreferenceForm.ts.ejs +158 -0
  25. package/dist/esm/application/react/templates/src/server/preferenceFormMiddleware.ts +42 -0
  26. package/dist/esm/application/react/templates/src/server/preview.bun.ts +5 -0
  27. package/dist/esm/application/react/templates/src/server/preview.express.ts +4 -0
  28. package/dist/esm/application/react/templates/src/server/resolveReturnTo.ts +18 -0
  29. package/dist/esm/application/react/templates/src/server/server.bun.ts.ejs +5 -0
  30. package/dist/esm/application/react/templates/src/server/server.express.ts.ejs +4 -0
  31. package/dist/esm/application/react/templates/test/e2e/servers.e2e.ts.ejs +56 -0
  32. package/dist/esm/application/react/templates/vitest.config.ts +4 -0
  33. package/dist/esm/application/svelte/index.js +226 -80
  34. package/dist/esm/application/svelte/index.js.map +1 -1
  35. package/dist/esm/application/svelte/templates/.storybook/{main.ts.ejs → main.ts} +1 -0
  36. package/dist/esm/application/svelte/templates/.storybook/preview.ts.ejs +20 -2
  37. package/dist/esm/application/svelte/templates/README.md.ejs +163 -40
  38. package/dist/esm/application/svelte/templates/biome.json.ejs +12 -0
  39. package/dist/esm/application/svelte/templates/gitignore.ejs +3 -4
  40. package/dist/esm/application/svelte/templates/package.json.ejs +54 -18
  41. package/dist/esm/application/svelte/templates/scripts/copy-icons.js +10 -0
  42. package/dist/esm/application/svelte/templates/src/app.d.ts.ejs +10 -2
  43. package/dist/esm/application/svelte/templates/src/app.html.ejs +9 -1
  44. package/dist/esm/application/svelte/templates/src/domains/account/AccountPage.svelte.ejs +18 -0
  45. package/dist/esm/application/svelte/templates/src/domains/account/LoginPage.svelte.ejs +32 -0
  46. package/dist/esm/application/svelte/templates/src/domains/account/getAuthRedirect.test.ts +18 -0
  47. package/dist/esm/application/svelte/templates/src/domains/account/getAuthRedirect.ts +18 -0
  48. package/dist/esm/application/svelte/templates/src/domains/account/guardAccount.ts +15 -0
  49. package/dist/esm/application/svelte/templates/src/domains/catalog/CatalogPage.svelte.ejs +35 -0
  50. package/dist/esm/application/svelte/templates/src/domains/catalog/ProductCard.svelte.ejs +51 -0
  51. package/dist/esm/application/svelte/templates/src/domains/catalog/ProductList.stories.svelte.ejs +110 -0
  52. package/dist/esm/application/svelte/templates/src/domains/catalog/ProductList.svelte.ejs +41 -0
  53. package/dist/esm/application/svelte/templates/src/domains/catalog/constants.ts +2 -0
  54. package/dist/esm/application/svelte/templates/src/domains/catalog/data.test.ts +19 -0
  55. package/dist/esm/application/svelte/templates/src/domains/catalog/data.ts +75 -0
  56. package/dist/esm/application/svelte/templates/src/domains/catalog/loadCatalog.ts +7 -0
  57. package/dist/esm/application/svelte/templates/src/domains/catalog/types.ts +25 -0
  58. package/dist/esm/application/svelte/templates/src/domains/contact/ContactPage.svelte.ejs +86 -0
  59. package/dist/esm/application/svelte/templates/src/domains/contact/types.ts.ejs +19 -0
  60. package/dist/esm/application/svelte/templates/src/domains/contact/validateContact.test.ts.ejs +31 -0
  61. package/dist/esm/application/svelte/templates/src/domains/contact/validateContact.ts.ejs +28 -0
  62. package/dist/esm/application/svelte/templates/src/domains/dashboard/DashboardBreadcrumbs.svelte.ejs +29 -0
  63. package/dist/esm/application/svelte/templates/src/domains/dashboard/DashboardLayout.svelte.ejs +35 -0
  64. package/dist/esm/application/svelte/templates/src/domains/dashboard/InstancesPage.svelte.ejs +245 -0
  65. package/dist/esm/application/svelte/templates/src/domains/dashboard/OverviewPage.svelte.ejs +180 -0
  66. package/dist/esm/application/svelte/templates/src/domains/dashboard/SettingsPage.svelte.ejs +103 -0
  67. package/dist/esm/application/svelte/templates/src/domains/dashboard/constants.ts.ejs +253 -0
  68. package/dist/esm/application/svelte/templates/src/domains/dashboard/createDashboardNavigation.ts.ejs +103 -0
  69. package/dist/esm/application/svelte/templates/src/domains/dashboard/createInstance.test.ts +22 -0
  70. package/dist/esm/application/svelte/templates/src/domains/dashboard/createInstance.ts +28 -0
  71. package/dist/esm/application/svelte/templates/src/domains/dashboard/projectBreadcrumbs.test.ts +78 -0
  72. package/dist/esm/application/svelte/templates/src/domains/dashboard/projectBreadcrumbs.ts +47 -0
  73. package/dist/esm/application/svelte/templates/src/domains/dashboard/selectRelativeTime.test.ts +19 -0
  74. package/dist/esm/application/svelte/templates/src/domains/dashboard/selectRelativeTime.ts +24 -0
  75. package/dist/esm/application/svelte/templates/src/domains/dashboard/styles.css +98 -0
  76. package/dist/esm/application/svelte/templates/src/domains/dashboard/types.ts.ejs +61 -0
  77. package/dist/esm/application/svelte/templates/src/domains/marketing/GuidePage.svelte.ejs +29 -0
  78. package/dist/esm/application/svelte/templates/src/domains/marketing/HomePage.svelte.ejs +47 -0
  79. package/dist/esm/application/svelte/templates/src/domains/marketing/isGuideSlug.ts +8 -0
  80. package/dist/esm/application/svelte/templates/src/formatDocumentTitle.ts.ejs +9 -0
  81. package/dist/esm/application/svelte/templates/src/hooks.server.ts.ejs +47 -9
  82. package/dist/esm/application/svelte/templates/src/i18n/ar.ts.ejs +174 -0
  83. package/dist/esm/application/svelte/templates/src/i18n/catalogs.ts +14 -0
  84. package/dist/esm/application/svelte/templates/src/i18n/config.ts +19 -0
  85. package/dist/esm/application/svelte/templates/src/i18n/en.ts.ejs +173 -0
  86. package/dist/esm/application/svelte/templates/src/i18n/fr.ts.ejs +171 -0
  87. package/dist/esm/application/svelte/templates/src/i18n/index.ts +45 -0
  88. package/dist/esm/application/svelte/templates/src/i18n/negotiation.test.ts +92 -0
  89. package/dist/esm/application/svelte/templates/src/layouts/ErrorPage.svelte.ejs +40 -0
  90. package/dist/esm/application/svelte/templates/src/layouts/PublicLayout.svelte +18 -0
  91. package/dist/esm/application/svelte/templates/src/layouts/RootLayout.svelte.ejs +43 -0
  92. package/dist/esm/application/svelte/templates/src/layouts/TopBarLayout.svelte +28 -0
  93. package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/ApplicationShell.stories.svelte +87 -0
  94. package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/ApplicationShell.svelte.ejs +60 -0
  95. package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/index.ts +2 -0
  96. package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/styles.css +43 -0
  97. package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/types.ts +23 -0
  98. package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/CanonicalLogo.svelte.ejs +27 -0
  99. package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/index.ts +2 -0
  100. package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/styles.css +31 -0
  101. package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/types.ts +15 -0
  102. package/dist/esm/application/svelte/templates/src/lib/CodeMessage/CodeMessage.svelte +18 -0
  103. package/dist/esm/application/svelte/templates/src/lib/CodeMessage/index.ts +2 -0
  104. package/dist/esm/application/svelte/templates/src/lib/CodeMessage/types.ts +14 -0
  105. package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/ExampleComponent.stories.svelte +15 -0
  106. package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/ExampleComponent.svelte +17 -0
  107. package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/index.ts +2 -0
  108. package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/styles.css +17 -0
  109. package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/types.ts +10 -0
  110. package/dist/esm/application/svelte/templates/src/lib/Icon/Icon.svelte +16 -0
  111. package/dist/esm/application/svelte/templates/src/lib/Icon/index.ts +2 -0
  112. package/dist/esm/application/svelte/templates/src/lib/Icon/types.ts +10 -0
  113. package/dist/esm/application/svelte/templates/src/lib/LazyComponent/LazyComponent.stories.svelte +19 -0
  114. package/dist/esm/application/svelte/templates/src/lib/LazyComponent/LazyComponent.svelte.ejs +29 -0
  115. package/dist/esm/application/svelte/templates/src/lib/LazyComponent/createDelayedData.ts.ejs +24 -0
  116. package/dist/esm/application/svelte/templates/src/lib/LazyComponent/index.ts +2 -0
  117. package/dist/esm/application/svelte/templates/src/lib/LazyComponent/types.ts.ejs +19 -0
  118. package/dist/esm/application/svelte/templates/src/lib/LocaleSelector/LocaleSelector.svelte.ejs +50 -0
  119. package/dist/esm/application/svelte/templates/src/lib/LocaleSelector/index.ts +2 -0
  120. package/dist/esm/application/svelte/templates/src/lib/LocaleSelector/types.ts +7 -0
  121. package/dist/esm/application/svelte/templates/src/lib/Navigation/Navigation.svelte.ejs +42 -0
  122. package/dist/esm/application/svelte/templates/src/lib/Navigation/index.ts +2 -0
  123. package/dist/esm/application/svelte/templates/src/lib/Navigation/types.ts +14 -0
  124. package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/ThemeSelector.svelte.ejs +38 -0
  125. package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/constants.ts +8 -0
  126. package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/index.ts +5 -0
  127. package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/readTheme.test.ts +13 -0
  128. package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/readTheme.ts +15 -0
  129. package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/setTheme.ts +27 -0
  130. package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/types.ts +18 -0
  131. package/dist/esm/application/svelte/templates/src/lib/TopBar/TopBar.stories.svelte.ejs +24 -0
  132. package/dist/esm/application/svelte/templates/src/lib/TopBar/TopBar.svelte.ejs +32 -0
  133. package/dist/esm/application/svelte/templates/src/lib/TopBar/index.ts +2 -0
  134. package/dist/esm/application/svelte/templates/src/lib/TopBar/styles.css +54 -0
  135. package/dist/esm/application/svelte/templates/src/lib/TopBar/types.ts +15 -0
  136. package/dist/esm/application/svelte/templates/src/lib/index.ts.ejs +16 -0
  137. package/dist/esm/application/svelte/templates/src/params/guide.ts +5 -0
  138. package/dist/esm/application/svelte/templates/src/resolveReturnTo.test.ts +27 -0
  139. package/dist/esm/application/svelte/templates/src/resolveReturnTo.ts +13 -0
  140. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+layout.svelte +8 -0
  141. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+page.server.ts +6 -0
  142. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+page.svelte +8 -0
  143. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+page.ts +6 -0
  144. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/account/+page.svelte +5 -0
  145. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/account/+page.ts +4 -0
  146. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/catalog/+page.svelte +8 -0
  147. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/catalog/+page.ts +4 -0
  148. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/contact/+page.server.ts +25 -0
  149. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/contact/+page.svelte.ejs +30 -0
  150. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/guides/[slug=guide]/+page.svelte +6 -0
  151. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/login/+page.svelte +6 -0
  152. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/+layout.svelte +9 -0
  153. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/+layout.svelte +9 -0
  154. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/+page.svelte +5 -0
  155. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/instances/+page.server.ts.ejs +28 -0
  156. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/instances/+page.svelte.ejs +19 -0
  157. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/settings/+page.server.ts +9 -0
  158. package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/settings/+page.svelte +5 -0
  159. package/dist/esm/application/svelte/templates/src/routes/+error.svelte +6 -0
  160. package/dist/esm/application/svelte/templates/src/routes/+layout.server.ts.ejs +7 -1
  161. package/dist/esm/application/svelte/templates/src/routes/+layout.svelte.ejs +18 -82
  162. package/dist/esm/application/svelte/templates/src/routes/+layout.ts.ejs +29 -0
  163. package/dist/esm/application/svelte/templates/src/routes/home/+page.ts +4 -0
  164. package/dist/esm/application/svelte/templates/src/routes/home/{+server.ts.ejs → +server.ts} +1 -0
  165. package/dist/esm/application/svelte/templates/src/routes/icons/[icon]/+server.ts +37 -0
  166. package/dist/esm/application/svelte/templates/src/routes/language/+server.ts +30 -0
  167. package/dist/esm/application/svelte/templates/src/routes/preferences/+server.ts +32 -0
  168. package/dist/esm/application/svelte/templates/src/routes/sitemap.xml/+server.ts.ejs +44 -4
  169. package/dist/esm/application/svelte/templates/src/storybook/I18nDecorator.svelte +28 -0
  170. package/dist/esm/application/svelte/templates/src/storybook/decorators.ts +12 -0
  171. package/dist/esm/application/svelte/templates/src/styles/app.css +38 -0
  172. package/dist/esm/application/svelte/templates/src/styles/index.css.ejs +25 -0
  173. package/dist/esm/application/svelte/templates/src/styles/standins/Card.css +198 -0
  174. package/dist/esm/application/svelte/templates/src/styles/standins/Icon.css +32 -0
  175. package/dist/esm/application/svelte/templates/src/styles/standins/InlineCode.css +30 -0
  176. package/dist/esm/application/svelte/templates/src/styles/standins/SidePanel.css +462 -0
  177. package/dist/esm/application/svelte/templates/src/styles/standins/Tile.css +108 -0
  178. package/dist/esm/application/svelte/templates/src/styles/standins/Timeline.css +171 -0
  179. package/dist/esm/application/svelte/templates/src/styles/standins.css.ejs +17 -0
  180. package/dist/esm/application/svelte/templates/svelte.config.js.ejs +12 -2
  181. package/dist/esm/application/svelte/templates/test/app.test.js.ejs +739 -123
  182. package/dist/esm/application/svelte/templates/test/spa.test.js.ejs +224 -0
  183. package/dist/esm/application/svelte/templates/{tsconfig.json.ejs → tsconfig.json} +2 -2
  184. package/dist/esm/application/svelte/templates/{vite.config.ts.ejs → vite.config.ts} +1 -1
  185. package/dist/esm/application/svelte/templates/vitest.config.ts +10 -0
  186. package/dist/esm/application/svelte/textHelpers.js +20 -0
  187. package/dist/esm/application/svelte/textHelpers.js.map +1 -0
  188. package/dist/esm/shared/versions.js +10 -8
  189. package/dist/esm/shared/versions.js.map +1 -1
  190. package/dist/types/application/react/index.d.ts.map +1 -1
  191. package/dist/types/application/svelte/index.d.ts.map +1 -1
  192. package/dist/types/application/svelte/textHelpers.d.ts +21 -0
  193. package/dist/types/application/svelte/textHelpers.d.ts.map +1 -0
  194. package/dist/types/shared/versions.d.ts +11 -9
  195. package/dist/types/shared/versions.d.ts.map +1 -1
  196. package/package.json +7 -7
  197. package/dist/esm/application/react/templates/src/lib/ThemeSelector/index.ts +0 -1
  198. package/dist/esm/application/svelte/templates/scripts/copy-icons.js.ejs +0 -9
  199. package/dist/esm/application/svelte/templates/src/lib/ContactExample.stories.svelte.ejs +0 -11
  200. package/dist/esm/application/svelte/templates/src/lib/ContactExample.svelte.ejs +0 -19
  201. package/dist/esm/application/svelte/templates/src/lib/DashboardNavigation.svelte.ejs +0 -17
  202. package/dist/esm/application/svelte/templates/src/lib/ProjectDanger.svelte.ejs +0 -18
  203. package/dist/esm/application/svelte/templates/src/lib/Welcome.stories.svelte.ejs +0 -5
  204. package/dist/esm/application/svelte/templates/src/lib/catalog.ts.ejs +0 -5
  205. package/dist/esm/application/svelte/templates/src/lib/contact.ts.ejs +0 -19
  206. package/dist/esm/application/svelte/templates/src/lib/i18n.ts.ejs +0 -351
  207. package/dist/esm/application/svelte/templates/src/lib/instances.ts.ejs +0 -16
  208. package/dist/esm/application/svelte/templates/src/lib/resolveReturnTo.ts.ejs +0 -11
  209. package/dist/esm/application/svelte/templates/src/lib/settings.ts.ejs +0 -28
  210. package/dist/esm/application/svelte/templates/src/routes/+error.svelte.ejs +0 -9
  211. package/dist/esm/application/svelte/templates/src/routes/+page.svelte.ejs +0 -9
  212. package/dist/esm/application/svelte/templates/src/routes/account/+page.server.ts.ejs +0 -13
  213. package/dist/esm/application/svelte/templates/src/routes/account/+page.svelte.ejs +0 -20
  214. package/dist/esm/application/svelte/templates/src/routes/catalog/+page.svelte.ejs +0 -12
  215. package/dist/esm/application/svelte/templates/src/routes/catalog/[id]/+page.server.ts.ejs +0 -8
  216. package/dist/esm/application/svelte/templates/src/routes/catalog/[id]/+page.svelte.ejs +0 -13
  217. package/dist/esm/application/svelte/templates/src/routes/catalog/[id]/+page.ts.ejs +0 -8
  218. package/dist/esm/application/svelte/templates/src/routes/contact/+page.server.ts.ejs +0 -11
  219. package/dist/esm/application/svelte/templates/src/routes/contact/+page.svelte.ejs +0 -85
  220. package/dist/esm/application/svelte/templates/src/routes/dashboard/+layout.svelte.ejs +0 -15
  221. package/dist/esm/application/svelte/templates/src/routes/dashboard/+page.server.ts.ejs +0 -5
  222. package/dist/esm/application/svelte/templates/src/routes/dashboard/+page.svelte.ejs +0 -33
  223. package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/+page.server.ts.ejs +0 -23
  224. package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/+page.svelte.ejs +0 -101
  225. package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/remove/+page.server.ts.ejs +0 -19
  226. package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/remove/+page.svelte.ejs +0 -11
  227. package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/+page.server.ts.ejs +0 -13
  228. package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/+page.svelte.ejs +0 -52
  229. package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/confirm/+page.server.ts.ejs +0 -2
  230. package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/confirm/+page.svelte.ejs +0 -13
  231. package/dist/esm/application/svelte/templates/src/routes/language/+server.ts.ejs +0 -12
  232. package/dist/esm/application/svelte/templates/src/routes/login/+page.server.ts.ejs +0 -8
  233. package/dist/esm/application/svelte/templates/src/routes/login/+page.svelte.ejs +0 -11
  234. package/dist/esm/application/svelte/templates/src/routes/preferences/+server.ts.ejs +0 -10
  235. package/dist/esm/application/svelte/templates/src/styles.css.ejs +0 -28
  236. package/dist/esm/application/svelte/templates/test/contact.browser.test.js.ejs +0 -279
@@ -1,45 +1,168 @@
1
1
  # <%= name %>
2
2
 
3
- A SvelteKit application using Canonical styles<% if (appShell) { %> and application layouts<% } %>.
3
+ A <%= spa ? "client-only" : "server-rendered" %> Svelte application built on Canonical's design system and
4
+ `@canonical/styles`, with SvelteKit for routing, loading<% if (!spa) { %>, form actions and
5
+ streaming<% } %>.
6
+
4
7
  Use `summon domain billing --framework svelte`, `summon page billing/detail
5
- --framework svelte`, and `summon wrapper settings --framework svelte` for
8
+ --framework svelte` and `summon wrapper settings --framework svelte` to add
6
9
  SvelteKit routes and wrappers.
7
10
 
8
- Run `bun install`, `bun run check`, `bun run build`, `bun run test`, and `bun run dev`.
9
- Commit the resulting lockfile and use `bun install --frozen-lockfile` in CI;
10
- without a lockfile, transitive dependencies can change between installs.
11
- Run `bun run storybook` or `bun run build:storybook` for the example stories.
12
- <% if (forms) { %>After installing a Playwright Chromium browser, run `bun run test:browser`
13
- against the built app to check contact error isolation and draft preservation<% if (appShell) { %>,
14
- instance flows, heading focus and settings confirmation<% } %>.
15
- Set `CHROMIUM_PATH` to use an existing Chromium executable.
16
- <% } %>
17
- The catalog uses local sample data. GraphQL and Relay are not included.
18
- <% if (spa) { %>
19
- This client-only application builds to `build/`. Configure the static host to
20
- serve `200.html` as the fallback for application routes. Cold requests do not
21
- receive server-rendered content or route-specific HTTP statuses.
22
- Theme, dashboard settings and demo instances use local browser storage; there are no server
23
- actions; the demo account session uses sessionStorage and is not authentication.
24
- <% } else { %>
25
- The production server is built with adapter-node; start it with `bun run preview`.
26
- Configure `HOST`, `PORT` and `ORIGIN` for deployment.
27
- Theme and locale are selected per request, and the sitemap is served at
28
- `/sitemap.xml`. The dashboard's demo cookie is not authentication.<% if (appShell && forms) { %>
29
- Instances are bounded browser-cookie demonstrations, not provisioned resources.
30
- Removal uses a separate confirmation page without JavaScript and a hydrated modal.<% } %>
31
- <% } %>
32
- <% if (appShell) { %>
33
- Pathname navigation focuses the new page heading; query-only navigation keeps Kit's
34
- normal focus behavior. The settings project confirmation is a demonstration and
35
- does not delete data. The dashboard navigation and instance creation panel use
36
- native disclosures<% if (forms) { %>; when hydrated, the creation panel opens as a side sheet<% } %>.
37
- <% } %>
38
- <% if (forms) { %>
39
- The contact form is a local validation demonstration; it does not deliver messages.
40
- It uses native controls; the field definitions live in `src/lib/contact.ts`<% if (appShell) { %>
41
- and `src/lib/settings.ts`<% } %>, next to the decoders the server and the page share.
42
- <% } %>
43
- <% if (intl && spa) { %>
44
- The static shell starts in English until the browser chooses a locale.
45
- <% } %>
11
+ ## Quick start
12
+
13
+ ```sh
14
+ bun install
15
+ bun run dev
16
+ ```
17
+
18
+ Commit the lockfile and install with `bun install --frozen-lockfile` in CI.
19
+
20
+ ## Builds
21
+
22
+ | Build | Command | Output | Serve |
23
+ | --- | --- | --- | --- |
24
+ <% if (spa) { -%>
25
+ | SPA (adapter-static) | `bun run build` | `build/` | any static host, with `200.html` as the fallback for every app route |
26
+ <% } else { -%>
27
+ | SSR (adapter-node) | `bun run build` | `build/` | `bun run preview` (`node build/index.js`; Bun runs it too) |
28
+ <% } -%>
29
+ | Storybook | `bun run build:storybook` | `storybook-static/` | any static host |
30
+
31
+ <% if (spa) { -%>
32
+ Every route renders in the browser: the theme<% if (intl) { %> and locale<% } %> come from <% if (intl) { %>their cookies
33
+ and the browser's languages<% } else { %>its cookie<% } %>, and the forms have no server to post to. A cold
34
+ request gets no route-specific HTTP status and no server-rendered content.
35
+ <% } else { -%>
36
+ Set `HOST`, `PORT` and `ORIGIN` for the SSR build as adapter-node documents.
37
+ <% } -%>
38
+
39
+ ## Testing
40
+
41
+ ```sh
42
+ bun run test:unit # Vitest, the pure modules, in Node
43
+ bun run test:browser # builds, then Playwright Chromium against the <%= spa ? "static build" : "SSR server" %>
44
+ bun run test # both
45
+ ```
46
+
47
+ The browser tests need Playwright's Chromium (`bunx playwright install
48
+ chromium`); set `CHROMIUM_PATH` to use another executable<% if (!spa) { %>, and
49
+ `SERVER_RUNTIME=bun` to run the SSR build with Bun<% } %>.
50
+
51
+ ## Project structure
52
+
53
+ ```
54
+ src/
55
+ ├── app.html The document shell
56
+ <% if (!spa) { -%>
57
+ ├── hooks.server.ts Reads the theme<% if (intl) { %> and locale<% } %> cookie<% if (intl) { %>s<% } %>; writes <html class<% if (intl) { %> lang dir<% } %>>
58
+ <% } -%>
59
+ ├── routes/
60
+ │ ├── (top-bar)/ Every page except the 404, under the top bar
61
+ │ │ ├── (public)/ The public pages, in one constrained column
62
+ <% if (appShell) { -%>
63
+ │ │ └── dashboard/ The dashboard, in the application shell
64
+ <% } -%>
65
+ <% if (!spa) { -%>
66
+ │ ├── preferences/<% if (intl) { %>, language/<% } %> The theme<% if (intl) { %> and language<% } %> form<% if (intl) { %>s<% } %>' target<% if (intl) { %>s<% } %> without JavaScript
67
+ │ ├── home/, icons/, sitemap.xml/
68
+ <% } -%>
69
+ ├── params/ Route matchers (the guide slug)
70
+ ├── layouts/ The root, top bar, public and error layouts
71
+ ├── domains/ Feature domains, each owning its pages and data
72
+ │ ├── marketing/ Home, guides
73
+ │ ├── account/ Account (demo guard), login
74
+ │ ├── catalog/ Product catalog, the data-layer example
75
+ <% if (forms) { -%>
76
+ │ ├── contact/ Contact form
77
+ <% } -%>
78
+ <% if (appShell) { -%>
79
+ │ └── dashboard/ An LXD-style application: side navigation, views,
80
+ │ <% if (forms) { %>a side panel and <% } %>a modal
81
+ <% } -%>
82
+ <% if (intl) { -%>
83
+ ├── i18n/ Locale configuration and message catalogs (en/fr/ar)
84
+ <% } -%>
85
+ ├── lib/ Shared components (TopBar<% if (appShell) { %>, ApplicationShell<% } %>, …)
86
+ <% if (intl) { -%>
87
+ ├── styles/ Application CSS, and the stand-ins' stylesheets
88
+ └── storybook/ The locale decorator every story renders in
89
+ <% } else { -%>
90
+ └── styles/ Application CSS, and the stand-ins' stylesheets
91
+ <% } -%>
92
+ ```
93
+
94
+ ### Page layouts
95
+
96
+ Layouts are route groups, so a page never renders its own frame. Every page
97
+ except the 404 sits under `(top-bar)`: a top bar with the app's name, one link
98
+ per area of the scaffold, and the theme<% if (intl) { %> and language<% } %> selector<% if (intl) { %>s<% } %>. The links are demo
99
+ navigation for exploring what the scaffold ships — replace them with your own.
100
+ <% if (appShell) { -%>
101
+ Under the top bar a page takes one of two layouts:
102
+
103
+ - `(public)` — the public pages: one constrained column.
104
+ - `dashboard` — `ApplicationShell` from `src/lib`: the design system's
105
+ `ApplicationLayout` with its `SideNavigation`. Each dashboard page renders
106
+ `ViewLayout` and `ContentLayout` inside it.
107
+
108
+ The dashboard's navigation is one tree of navigation items, built in
109
+ `src/domains/dashboard/createDashboardNavigation.ts`. The side navigation
110
+ renders it, and the breadcrumbs are projected from it.
111
+ <% } else { -%>
112
+ The public pages render under it in `(public)`, one constrained column.
113
+ <% } -%>
114
+
115
+ ## Theme<% if (intl) { %> and language<% } %>
116
+
117
+ <% if (intl) { -%>
118
+ With JavaScript, the theme and language selectors apply on change: `setTheme`
119
+ swaps the theme class on `<html>` and writes the `theme` cookie, and the locale
120
+ source re-translates the page, flips `<html lang dir>` and writes the `locale`
121
+ cookie.
122
+ <% } else { -%>
123
+ With JavaScript, the theme selector applies on change: `setTheme` swaps the
124
+ theme class on `<html>` and writes the `theme` cookie.
125
+ <% } -%>
126
+ <% if (spa) { -%>
127
+ The client-only build reads the cookie<% if (intl) { %>s<% } %> back on every load.
128
+ <% } else { -%>
129
+ Without JavaScript, each selector is a form that posts to `/preferences`<% if (intl) { %> or
130
+ `/language`<% } %>, which sets the same cookie and sends the reader back; the server then
131
+ renders the class<% if (intl) { %>, `lang` and `dir`<% } %>. The Apply buttons sit in `<noscript>`, so
132
+ they never show while JavaScript runs.
133
+
134
+ The cookies are `path=/`, `SameSite=Lax`, a one-year max age, `Secure` over
135
+ HTTPS on the server, and not `httpOnly`, so the page can overwrite what the
136
+ server set.
137
+ <% } -%>
138
+ <% if (!spa && (forms || appShell)) { -%>
139
+
140
+ ## Without JavaScript
141
+
142
+ Every form keeps working:<% if (forms) { %> contact<% if (appShell) { %> and settings<% } %> post<% if (!appShell) { %>s<% } %> to <% if (appShell) { %>their<% } else { %>its<% } %> page's action,<% } %><% if (appShell && forms) { %> the
143
+ instance panel opens through `?create=1` and creates through an action,<% } %><% if (appShell) { %> a
144
+ Details button chooses through `?selected=`, and the danger-zone Modal opens
145
+ and closes through invoker commands<% } %>.
146
+ <% if (forms) { -%>
147
+
148
+ With JavaScript, the contact form's owner checks the values with the action's
149
+ own rules, then posts them to the action through `enhance` and logs what the
150
+ action accepted.
151
+ <% } -%>
152
+ <% } -%>
153
+
154
+ ## Data
155
+
156
+ The catalog's `load` reads a page of products from local data in
157
+ `src/domains/catalog/data.ts`; replace that module with a call to a real
158
+ endpoint. GraphQL and Relay are not part of this app.
159
+
160
+ ## Gaps
161
+
162
+ `@canonical/svelte-ds-*` does not ship these blocks yet, so the app renders
163
+ their markup itself, with their stylesheets copied from the React packages into
164
+ `src/styles/standins/`: <% if (appShell) { %><% if (forms) { %>`SidePanel`, <% } %>`Card`, `Tile`, `Timeline`, `Icon` and <% } %>`InlineCode`. Swap
165
+ each for the Svelte block when it lands, and delete its stand-in stylesheet.
166
+
167
+ The account flow is a demo, not authentication; real reads and actions must
168
+ authorize at the request boundary.
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": ["@canonical/biome-config"],
3
+ "files": {
4
+ "includes": [
5
+ "!.svelte-kit",
6
+ "!build",
7
+ "!static",
8
+ "!storybook-static",
9
+ "!src/app.html"
10
+ ]
11
+ }
12
+ }
@@ -1,8 +1,7 @@
1
1
  node_modules/
2
- .svelte-kit/
3
2
  build/
3
+ .svelte-kit/
4
4
  storybook-static/
5
+ <% if (spa) { -%>
5
6
  static/icons/
6
- .env
7
- .env.*
8
- !.env.example
7
+ <% } -%>
@@ -1,40 +1,76 @@
1
1
  {
2
2
  "name": "<%= name %>",
3
- "version": "0.1.0",
4
3
  "private": true,
4
+ "version": "0.0.0",
5
5
  "type": "module",
6
+ "license": "GPL-3.0-only",
6
7
  "scripts": {
8
+ "prepare": "svelte-kit sync || echo ''",
9
+ <% if (spa) { -%>
7
10
  "dev": "node scripts/copy-icons.js && vite dev",
8
11
  "build": "node scripts/copy-icons.js && vite build",
9
- "preview": "<%= spa ? 'vite preview' : 'node build/index.js' %>",
10
- "storybook": "node scripts/copy-icons.js && storybook dev -p 6009 --no-open",
11
- "build:storybook": "node scripts/copy-icons.js && storybook build",
12
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
13
- "test": "node --test test/app.test.js"<% if (forms) { %>,
14
- "test:browser": "node --test test/contact.browser.test.js"<% } %>
12
+ "preview": "vite preview",
13
+ <% } else { -%>
14
+ "dev": "vite dev",
15
+ "build": "vite build",
16
+ "preview": "node build/index.js",
17
+ <% } -%>
18
+ "build:all": "bun run build && bun run build:storybook",
19
+ "build:storybook": "storybook build",
20
+ "storybook": "storybook dev -p 6009 --no-open",
21
+ "check": "bun run check:biome && bun run check:ts",
22
+ "check:fix": "bun run check:biome:fix && bun run check:ts",
23
+ "check:biome": "biome check",
24
+ "check:biome:fix": "biome check --write",
25
+ "check:ts": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
26
+ "test": "bun run test:unit && bun run test:browser",
27
+ "test:unit": "vitest run",
28
+ "test:browser": "bun run build && node --test test/<%= spa ? "spa" : "app" %>.test.js"
15
29
  },
16
30
  "dependencies": {
17
- "@canonical/styles": "<%= pragmaWebVersion %>",
18
31
  "@canonical/ds-assets": "<%= pragmaWebVersion %>",
19
- "@canonical/svelte-ds-global": "<%= pragmaWebVersion %>"<% if (appShell) { %>,
20
- "@canonical/svelte-ds-app": "<%= pragmaWebVersion %>"<% } %><% if (intl) { %>,
21
- "@canonical/i18n-core": "<%= pragmaWebVersion %>"<% } %>
32
+ <% if (appShell) { -%>
33
+ "@canonical/ds-types": "<%= pragmaWebVersion %>",
34
+ "@canonical/ds-utils": "<%= pragmaWebVersion %>",
35
+ <% } -%>
36
+ "@canonical/i18n-core": "<%= pragmaWebVersion %>",
37
+ "@canonical/styles": "<%= pragmaWebVersion %>",
38
+ <% if (appShell) { -%>
39
+ "@canonical/svelte-ds-app": "<%= pragmaWebVersion %>",
40
+ <% } -%>
41
+ <% if (forms) { -%>
42
+ "@canonical/svelte-ds-global": "<%= pragmaWebVersion %>",
43
+ "@canonical/svelte-ds-global-form": "<%= pragmaWebVersion %>"
44
+ <% } else { -%>
45
+ "@canonical/svelte-ds-global": "<%= pragmaWebVersion %>"
46
+ <% } -%>
22
47
  },
23
- "overrides": { "cookie": "0.7.2" },
24
48
  "devDependencies": {
25
- <% if (forms) { %> "playwright": "1.61.1",
26
- <% } %>
49
+ "@biomejs/biome": "2.6.8",
50
+ "@canonical/biome-config": "<%= pragmaVersion %>",
27
51
  "@canonical/storybook-config": "<%= pragmaWebVersion %>",
28
52
  "@storybook/addon-svelte-csf": "^5.1.3",
29
53
  "@storybook/sveltekit": "^10.6.0",
30
- "storybook": "^10.6.0",
31
- "@sveltejs/adapter-<%= spa ? 'static' : 'node' %>": "<%= spa ? '3.0.10' : '5.5.4' %>",
54
+ <% if (spa) { -%>
55
+ "@sveltejs/adapter-static": "3.0.11",
56
+ <% } else { -%>
57
+ "@sveltejs/adapter-node": "5.5.4",
58
+ <% } -%>
32
59
  "@sveltejs/kit": "2.70.3",
33
60
  "@sveltejs/vite-plugin-svelte": "7.3.1",
61
+ "@types/node": "^26.0.0",
62
+ "playwright": "^1.61.1",
63
+ "storybook": "^10.6.0",
34
64
  "svelte": "5.57.3",
35
65
  "svelte-check": "^4.4.5",
36
66
  "typescript": "~6.0.3",
37
- "vite": "8.3.5"
67
+ "vite": "8.3.5",
68
+ "vitest": "^5.0.0"
69
+ },
70
+ "overrides": {
71
+ "cookie": "0.7.2"
38
72
  },
39
- "engines": { "node": "^22.13.0 || ^24.0.0 || ^26.0.0" }
73
+ "engines": {
74
+ "node": "^22.13.0 || ^24.0.0 || ^26.0.0"
75
+ }
40
76
  }
@@ -0,0 +1,10 @@
1
+ import { cp } from "node:fs/promises";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ // The SSR build serves the design-system icons from a route; a static host has
6
+ // no routes, so the client-only build ships them as files at the same URLs.
7
+ const assets = dirname(
8
+ fileURLToPath(import.meta.resolve("@canonical/ds-assets/package.json")),
9
+ );
10
+ await cp(join(assets, "icons"), "static/icons", { recursive: true });
@@ -1,6 +1,14 @@
1
+ import type { Theme } from "./lib/ThemeSelector/index.js";
2
+
1
3
  declare global {
2
4
  namespace App {
3
- interface Locals { theme: string<% if (intl) { %>; locale: string<% } %> }
5
+ interface Locals {
6
+ /** The theme the `theme` cookie pins, if any. */
7
+ theme: Theme | undefined;
8
+ <% if (intl) { -%>
9
+ /** The locale negotiated from the `locale` cookie and Accept-Language. */
10
+ locale: string;
11
+ <% } -%>
12
+ }
4
13
  }
5
14
  }
6
- export {};
@@ -1,8 +1,16 @@
1
1
  <!doctype html>
2
- <html lang="<%= intl && !spa ? '%lang%' : 'en' %>" dir="<%= intl && !spa ? '%dir%' : 'ltr' %>" class="app comfortable <%= spa ? '' : '%theme%' %>">
2
+ <% if (spa) { -%>
3
+ <html lang="en" dir="ltr" class="app comfortable">
4
+ <% } else if (intl) { -%>
5
+ <html lang="%lang%" dir="%dir%" class="app comfortable%theme%">
6
+ <% } else { -%>
7
+ <html lang="en" dir="ltr" class="app comfortable%theme%">
8
+ <% } -%>
3
9
  <head>
4
10
  <meta charset="utf-8" />
5
11
  <meta name="viewport" content="width=device-width, initial-scale=1" />
12
+ <meta name="description" content="A Svelte application built with the Canonical design system and SvelteKit." />
13
+ <link rel="icon" type="image/png" sizes="32x32" href="https://assets.ubuntu.com/v1/be7e4cc6-COF-favicon-32x32.png" />
6
14
  %sveltekit.head%
7
15
  </head>
8
16
  <body data-sveltekit-preload-data="hover">
@@ -0,0 +1,18 @@
1
+ <script lang="ts">
2
+ import formatDocumentTitle from "../../formatDocumentTitle.js";
3
+ <% if (intl) { -%>
4
+ import { createAppTranslator, getLocaleSource } from "../../i18n/index.js";
5
+ <% } -%>
6
+ <% if (intl) { -%>
7
+
8
+ const locale = getLocaleSource();
9
+ const t = $derived(createAppTranslator($locale));
10
+ <% } -%>
11
+ </script>
12
+
13
+ <svelte:head><title>{formatDocumentTitle(<%- str("account.title", "Account") %>)}</title></svelte:head>
14
+
15
+ <section aria-labelledby="account-title">
16
+ <h1 id="account-title"><%- msg("account.heading", "Account") %></h1>
17
+ <p><%- msg("account.body", "Protected account page. You are signed in.") %></p>
18
+ </section>
@@ -0,0 +1,32 @@
1
+ <script lang="ts">
2
+ import formatDocumentTitle from "../../formatDocumentTitle.js";
3
+ <% if (intl) { -%>
4
+ import { createAppTranslator, getLocaleSource } from "../../i18n/index.js";
5
+ <% } -%>
6
+
7
+ let {
8
+ from,
9
+ }: {
10
+ /** The protected page the reader was sent here from. */
11
+ from?: string;
12
+ } = $props();
13
+ <% if (intl) { -%>
14
+
15
+ const locale = getLocaleSource();
16
+ const t = $derived(createAppTranslator($locale));
17
+ <% } -%>
18
+ </script>
19
+
20
+ <svelte:head><title>{formatDocumentTitle(<%- str("login.title", "Login") %>)}</title></svelte:head>
21
+
22
+ <section aria-labelledby="login-title">
23
+ <h1 id="login-title"><%- msg("login.heading", "Login") %></h1>
24
+ <!-- The `?auth=1` literal is markup (<code>), which a plain message string
25
+ cannot carry, so the sentence is catalogued as the fragments around it. -->
26
+ <p><%- msg("login.hintBefore", "Demo login. Add") %> <code>?auth=1</code> <%- msg("login.hintAfter", "to any protected URL to simulate authentication.") %></p>
27
+ <% if (intl) { -%>
28
+ {#if from}<p>{t("login.redirect", { from })}</p>{/if}
29
+ <% } else { -%>
30
+ {#if from}<p>{`You will be redirected to ${from} after login.`}</p>{/if}
31
+ <% } -%>
32
+ </section>
@@ -0,0 +1,18 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import getAuthRedirect from "./getAuthRedirect.js";
3
+
4
+ const url = (path: string) => new URL(path, "http://localhost");
5
+
6
+ describe("getAuthRedirect", () => {
7
+ it("sends a protected page without ?auth=1 to the login page", () => {
8
+ expect(getAuthRedirect(url("/account"))).toBe("/login?from=%2Faccount");
9
+ });
10
+
11
+ it("lets a protected page with ?auth=1 render", () => {
12
+ expect(getAuthRedirect(url("/account?auth=1"))).toBeNull();
13
+ });
14
+
15
+ it("lets a public page render", () => {
16
+ expect(getAuthRedirect(url("/catalog"))).toBeNull();
17
+ });
18
+ });
@@ -0,0 +1,18 @@
1
+ /** The pages that need the demo authentication. */
2
+ const protectedPaths = new Set(["/account"]);
3
+
4
+ /**
5
+ * The login URL to send a request for `url` to, or `null` when it may render.
6
+ * A protected page renders only with `?auth=1`: the demo stands in for real
7
+ * authentication, which a real application checks at the request boundary.
8
+ */
9
+ export default function getAuthRedirect(url: URL): string | null {
10
+ if (
11
+ !protectedPaths.has(url.pathname) ||
12
+ url.searchParams.get("auth") === "1"
13
+ ) {
14
+ return null;
15
+ }
16
+
17
+ return `/login?from=${encodeURIComponent(url.pathname)}`;
18
+ }
@@ -0,0 +1,15 @@
1
+ import { redirect } from "@sveltejs/kit";
2
+ import getAuthRedirect from "./getAuthRedirect.js";
3
+
4
+ /**
5
+ * The account route's guard: a request without the demo authentication is
6
+ * redirected to the login page with a 302, on the server and on client-side
7
+ * navigation alike.
8
+ */
9
+ export default function guardAccount({ url }: { url: URL }): void {
10
+ const location = getAuthRedirect(url);
11
+
12
+ if (location) {
13
+ redirect(302, location);
14
+ }
15
+ }
@@ -0,0 +1,35 @@
1
+ <script lang="ts">
2
+ import formatDocumentTitle from "../../formatDocumentTitle.js";
3
+ <% if (intl) { -%>
4
+ import { createAppTranslator, getLocaleSource } from "../../i18n/index.js";
5
+ <% } -%>
6
+ import { CodeMessage } from "../../lib/index.js";
7
+ import ProductList from "./ProductList.svelte";
8
+ import type { ProductPage } from "./types.js";
9
+
10
+ let {
11
+ catalog,
12
+ }: {
13
+ /** The page of products the route's `load` read. */
14
+ catalog: ProductPage;
15
+ } = $props();
16
+ <% if (intl) { -%>
17
+
18
+ const locale = getLocaleSource();
19
+ const t = $derived(createAppTranslator($locale));
20
+ <% } -%>
21
+ </script>
22
+
23
+ <svelte:head><title>{formatDocumentTitle(<%- str("catalog.title", "Catalog") %>)}</title></svelte:head>
24
+
25
+ <section aria-labelledby="catalog-title">
26
+ <h1 id="catalog-title"><%- msg("catalog.heading", "Catalog") %></h1>
27
+ <CodeMessage message=<%- attr("catalog.intro", "This page demonstrates the data layer. The page's `load` reads a page of products, `ProductList` renders it and each `ProductCard` formats its own product, from the local data in `src/domains/catalog/data.ts` — replace that module with a call to a real endpoint.") %> />
28
+ <!-- The route's `load` reads the products before rendering, so the list is
29
+ server-rendered HTML. A render error in the list shows the failure
30
+ state instead of unmounting the page. -->
31
+ <svelte:boundary>
32
+ <ProductList {catalog} />
33
+ {#snippet failed()}<p role="alert"><%- msg("catalog.error", "The catalog failed to load. Reload the page to try again.") %></p>{/snippet}
34
+ </svelte:boundary>
35
+ </section>
@@ -0,0 +1,51 @@
1
+ <script lang="ts">
2
+ <% if (intl) { -%>
3
+ import {
4
+ createAppFormatters,
5
+ createAppTranslator,
6
+ getLocaleSource,
7
+ } from "../../i18n/index.js";
8
+ <% } -%>
9
+ import type { Product } from "./types.js";
10
+
11
+ let {
12
+ product,
13
+ }: {
14
+ /** The product this card renders. */
15
+ product: Product;
16
+ } = $props();
17
+ <% if (intl) { -%>
18
+
19
+ const locale = getLocaleSource();
20
+ const t = $derived(createAppTranslator($locale));
21
+ const formatters = $derived(createAppFormatters($locale));
22
+ <% } else { -%>
23
+
24
+ const price = $derived(
25
+ new Intl.NumberFormat("en-US", {
26
+ style: "currency",
27
+ currency: product.currency,
28
+ }),
29
+ );
30
+ <% } -%>
31
+ </script>
32
+
33
+ <article aria-label={product.name}>
34
+ <h3>{product.name}</h3>
35
+ <p>{product.tagline}</p>
36
+ <% if (intl) { -%>
37
+ <p><strong>{formatters.formatCurrency(product.priceCents / 100, product.currency)}</strong> · {t("catalog.rating", { rating: formatters.formatNumber(product.rating, { minimumFractionDigits: 1, maximumFractionDigits: 1 }) })} · {product.inStock ? t("catalog.inStock") : t("catalog.outOfStock")}</p>
38
+ <% } else { -%>
39
+ <p><strong>{price.format(product.priceCents / 100)}</strong> · rated {product.rating.toFixed(1)} / 5 · {product.inStock ? "in stock" : "out of stock"}</p>
40
+ <% } -%>
41
+ </article>
42
+
43
+ <!-- @component
44
+ <% if (intl) { -%>
45
+ Renders one catalog product. Price and rating go through the locale's memoized
46
+ `Intl` formatters, so "$125.00" becomes "125,00 $US" in French without touching
47
+ the data. The name and tagline are data, not chrome, and render untranslated.
48
+ <% } else { -%>
49
+ Renders one catalog product: its name, tagline, price, rating and stock.
50
+ <% } -%>
51
+ -->