@canonical/summon-application 0.47.0 → 0.49.0-experimental.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 (217) hide show
  1. package/README.md +35 -4
  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 +337 -0
  34. package/dist/esm/application/svelte/index.js.map +1 -0
  35. package/dist/esm/application/svelte/templates/.storybook/main.ts +3 -0
  36. package/dist/esm/application/svelte/templates/.storybook/preview.ts.ejs +21 -0
  37. package/dist/esm/application/svelte/templates/README.md.ejs +168 -0
  38. package/dist/esm/application/svelte/templates/biome.json.ejs +12 -0
  39. package/dist/esm/application/svelte/templates/gitignore.ejs +7 -0
  40. package/dist/esm/application/svelte/templates/package.json.ejs +76 -0
  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 +14 -0
  43. package/dist/esm/application/svelte/templates/src/app.html.ejs +19 -0
  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 +51 -0
  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 +8 -0
  161. package/dist/esm/application/svelte/templates/src/routes/+layout.svelte.ejs +21 -0
  162. package/dist/esm/application/svelte/templates/src/routes/+layout.ts.ejs +30 -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 +3 -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 +47 -0
  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 +17 -0
  181. package/dist/esm/application/svelte/templates/test/app.test.js.ejs +758 -0
  182. package/dist/esm/application/svelte/templates/test/spa.test.js.ejs +224 -0
  183. package/dist/esm/application/svelte/templates/tsconfig.json +15 -0
  184. package/dist/esm/application/svelte/templates/vite.config.ts +4 -0
  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/domain/index.js +39 -5
  189. package/dist/esm/domain/index.js.map +1 -1
  190. package/dist/esm/domain/templates/Page.svelte.ejs +2 -0
  191. package/dist/esm/index.js +2 -0
  192. package/dist/esm/index.js.map +1 -1
  193. package/dist/esm/page/index.js +44 -7
  194. package/dist/esm/page/index.js.map +1 -1
  195. package/dist/esm/page/templates/Page.svelte.ejs +2 -0
  196. package/dist/esm/shared/versions.js +10 -8
  197. package/dist/esm/shared/versions.js.map +1 -1
  198. package/dist/esm/wrapper/index.js +38 -5
  199. package/dist/esm/wrapper/index.js.map +1 -1
  200. package/dist/esm/wrapper/templates/Layout.svelte.ejs +5 -0
  201. package/dist/types/application/react/index.d.ts.map +1 -1
  202. package/dist/types/application/svelte/index.d.ts +12 -0
  203. package/dist/types/application/svelte/index.d.ts.map +1 -0
  204. package/dist/types/application/svelte/textHelpers.d.ts +21 -0
  205. package/dist/types/application/svelte/textHelpers.d.ts.map +1 -0
  206. package/dist/types/domain/index.d.ts +2 -1
  207. package/dist/types/domain/index.d.ts.map +1 -1
  208. package/dist/types/index.d.ts +1 -0
  209. package/dist/types/index.d.ts.map +1 -1
  210. package/dist/types/page/index.d.ts +1 -0
  211. package/dist/types/page/index.d.ts.map +1 -1
  212. package/dist/types/shared/versions.d.ts +11 -9
  213. package/dist/types/shared/versions.d.ts.map +1 -1
  214. package/dist/types/wrapper/index.d.ts +2 -1
  215. package/dist/types/wrapper/index.d.ts.map +1 -1
  216. package/package.json +8 -8
  217. package/dist/esm/application/react/templates/src/lib/ThemeSelector/index.ts +0 -1
@@ -0,0 +1,14 @@
1
+ import type { SvelteHTMLElements } from "svelte/elements";
2
+ import type { ThemePreference } from "../ThemeSelector/index.js";
3
+
4
+ /**
5
+ * Props for `Navigation`: the page's pathname and the theme it was rendered
6
+ * with, plus the native props of the root `<nav>`.
7
+ */
8
+ export interface NavigationProps
9
+ extends Omit<SvelteHTMLElements["nav"], "children"> {
10
+ /** The current page's pathname; its link is marked as the current page. */
11
+ currentUrl: string;
12
+ /** The theme preference the page was rendered with. */
13
+ theme: ThemePreference;
14
+ }
@@ -0,0 +1,38 @@
1
+ <script lang="ts">
2
+ import { Button } from "@canonical/svelte-ds-global";
3
+ <% if (forms) { -%>
4
+ import { SelectInput } from "@canonical/svelte-ds-global-form";
5
+ <% } -%>
6
+ <% if (intl) { -%>
7
+ import { createAppTranslator, getLocaleSource } from "../../i18n/index.js";
8
+ <% } -%>
9
+ import setTheme from "./setTheme.js";
10
+ import type { ThemePreference, ThemeSelectorProps } from "./types.js";
11
+
12
+ let { preference, ...rest }: ThemeSelectorProps = $props();
13
+ <% if (intl) { -%>
14
+
15
+ const locale = getLocaleSource();
16
+ const t = $derived(createAppTranslator($locale));
17
+ <% } -%>
18
+ // The select owns the value once rendered; the prop only seeds it.
19
+ // svelte-ignore state_referenced_locally
20
+ let value = $state<string>(preference);
21
+
22
+ function handleChange() {
23
+ setTheme(value as ThemePreference);
24
+ }
25
+ </script>
26
+
27
+ <form {...rest} method="post" action="/preferences"><% if (forms) { %><SelectInput aria-label=<%- attr("theme.label", "Color theme") %> name="theme" onchange={handleChange} options={[{ value: "system", label: <%- str("theme.system", "System") %> }, { value: "light", label: <%- str("theme.light", "Light") %> }, { value: "dark", label: <%- str("theme.dark", "Dark") %> }]} bind:value /><% } else { %><select aria-label=<%- attr("theme.label", "Color theme") %> name="theme" onchange={handleChange} bind:value><option value="system"><%- msg("theme.system", "System") %></option><option value="light"><%- msg("theme.light", "Light") %></option><option value="dark"><%- msg("theme.dark", "Dark") %></option></select><% } %><noscript><Button importance="secondary" type="submit"><%- msg("preferences.apply", "Apply") %></Button></noscript></form>
28
+
29
+ <!-- @component
30
+ The colour-theme picker. With JavaScript, a change applies at once:
31
+ `setTheme` swaps the class on
32
+ `<html>` and writes the `theme` cookie. Without JavaScript, the form posts to
33
+ `/preferences`, which stores the cookie and sends the reader back, and the
34
+ server renders the theme class on `<html>`; its Apply button is in `<noscript>`,
35
+ so it never shows while JavaScript runs.
36
+
37
+ `import { ThemeSelector } from "$lib";`
38
+ -->
@@ -0,0 +1,8 @@
1
+ /** The cookie the theme preference is stored in, on the server and in the browser. */
2
+ export const THEME_COOKIE = "theme";
3
+
4
+ /** The theme cookie's lifetime, in seconds (one year). */
5
+ export const THEME_COOKIE_MAX_AGE = 31_536_000;
6
+
7
+ /** The themes that pin a colour scheme; anything else follows the system. */
8
+ export const THEMES = ["light", "dark"] as const;
@@ -0,0 +1,5 @@
1
+ export * from "./constants.js";
2
+ export { default as readTheme } from "./readTheme.js";
3
+ export { default as setTheme } from "./setTheme.js";
4
+ export { default } from "./ThemeSelector.svelte";
5
+ export type * from "./types.js";
@@ -0,0 +1,13 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import readTheme from "./readTheme.js";
3
+
4
+ describe("readTheme", () => {
5
+ it("reads a pinned theme from the cookie header", () => {
6
+ expect(readTheme("locale=fr; theme=dark")).toBe("dark");
7
+ });
8
+
9
+ it("ignores a missing or unknown theme", () => {
10
+ expect(readTheme(null)).toBeUndefined();
11
+ expect(readTheme("theme=sepia")).toBeUndefined();
12
+ });
13
+ });
@@ -0,0 +1,15 @@
1
+ import { readCookie } from "@canonical/i18n-core";
2
+ import { THEME_COOKIE, THEMES } from "./constants.js";
3
+ import type { Theme } from "./types.js";
4
+
5
+ /**
6
+ * Reads the pinned theme from a raw `Cookie` header, or `undefined` when the
7
+ * cookie is absent or holds anything but a pinned theme.
8
+ */
9
+ export default function readTheme(
10
+ cookieHeader: string | null | undefined,
11
+ ): Theme | undefined {
12
+ const value = readCookie(cookieHeader, THEME_COOKIE);
13
+
14
+ return THEMES.find((theme) => theme === value);
15
+ }
@@ -0,0 +1,27 @@
1
+ import { THEME_COOKIE, THEME_COOKIE_MAX_AGE, THEMES } from "./constants.js";
2
+ import type { ThemePreference } from "./types.js";
3
+
4
+ /**
5
+ * Applies a theme preference to the page: it swaps the theme class on
6
+ * `<html>` and stores the choice in the theme cookie, so the server renders the same theme on the next request.
7
+ * `system` removes both the class and the cookie, so the styles follow the
8
+ * reader's operating system.
9
+ *
10
+ * @note - This function is impure: it writes `document.documentElement` and
11
+ * `document.cookie`. Call it from an event handler or an effect.
12
+ */
13
+ export default function setTheme(preference: ThemePreference): void {
14
+ const { classList } = document.documentElement;
15
+
16
+ classList.remove(...THEMES);
17
+
18
+ if (preference === "system") {
19
+ // biome-ignore lint/suspicious/noDocumentCookie: the cookie is the preference's store, as in usePreferredTheme
20
+ document.cookie = `${THEME_COOKIE}=; path=/; max-age=0; SameSite=Lax`;
21
+ return;
22
+ }
23
+
24
+ classList.add(preference);
25
+ // biome-ignore lint/suspicious/noDocumentCookie: the cookie is the preference's store, as in usePreferredTheme
26
+ document.cookie = `${THEME_COOKIE}=${preference}; path=/; max-age=${THEME_COOKIE_MAX_AGE}; SameSite=Lax`;
27
+ }
@@ -0,0 +1,18 @@
1
+ import type { SvelteHTMLElements } from "svelte/elements";
2
+ import type { THEMES } from "./constants.js";
3
+
4
+ /** A theme that pins a colour scheme. */
5
+ export type Theme = (typeof THEMES)[number];
6
+
7
+ /** The theme preference: a pinned theme, or `system` to follow the reader's OS. */
8
+ export type ThemePreference = Theme | "system";
9
+
10
+ /**
11
+ * Props for `ThemeSelector`: the preference the page was rendered with, plus
12
+ * the native props of the root `<form>`.
13
+ */
14
+ export interface ThemeSelectorProps
15
+ extends Omit<SvelteHTMLElements["form"], "children" | "method" | "action"> {
16
+ /** The preference the server read from the theme cookie. */
17
+ preference: ThemePreference;
18
+ }
@@ -0,0 +1,24 @@
1
+ <script lang="ts" module>
2
+ import { defineMeta } from "@storybook/addon-svelte-csf";
3
+ import { expect, within } from "storybook/test";
4
+ import Component from "./TopBar.svelte";
5
+
6
+ const { Story } = defineMeta({
7
+ title: "common/TopBar",
8
+ component: Component,
9
+ parameters: { layout: "fullscreen" },
10
+ args: { currentUrl: "/", theme: "system" },
11
+ });
12
+ </script>
13
+
14
+ <!-- The bar every page opens with: the app's name, the demo navigation, and
15
+ the theme<% if (intl) { %> and language<% } %> selector<% if (intl) { %>s<% } %> at the end. -->
16
+ <Story
17
+ name="Default"
18
+ play={async ({ canvasElement }) => {
19
+ const canvas = within(canvasElement);
20
+
21
+ await expect(canvas.getByRole("banner")).toBeVisible();
22
+ await expect(canvas.getAllByRole("combobox")).toHaveLength(<%= intl ? 2 : 1 %>);
23
+ }}
24
+ />
@@ -0,0 +1,32 @@
1
+ <script lang="ts">
2
+ <% if (intl) { -%>
3
+ import { createAppTranslator, getLocaleSource } from "../../i18n/index.js";
4
+ <% } -%>
5
+ import Navigation from "../Navigation/index.js";
6
+ import type { TopBarProps } from "./types.js";
7
+ import "./styles.css";
8
+
9
+ const componentCssClassName = "ds top-bar";
10
+
11
+ let { currentUrl, theme, class: className, ...rest }: TopBarProps = $props();
12
+ <% if (intl) { -%>
13
+
14
+ const locale = getLocaleSource();
15
+ const t = $derived(createAppTranslator($locale));
16
+ <% } -%>
17
+ </script>
18
+
19
+ <header {...rest} class={[componentCssClassName, "surface", className]}><a class="name" aria-current={currentUrl === "/" ? "page" : undefined} href="/"><%- msg("app.name", name) %></a><Navigation {currentUrl} {theme} /></header>
20
+
21
+ <!-- @component
22
+ The bar across the top of every page: the application's name, then the demo
23
+ navigation — one link per area of the scaffold, followed by the theme<% if (intl) { %> and
24
+ language<% } %> selector<% if (intl) { %>s<% } %>. It is scaffolding for exploring what the scaffold ships;
25
+ an application replaces the links with its own.
26
+
27
+ It sits above <% if (appShell) { %>both page layouts: the public pages' constrained column and the
28
+ dashboard's application shell<% } else { %>the public pages' constrained column<% } %>. It is a `.surface`, so the selectors read the
29
+ surface channels the design system's inputs expect.
30
+
31
+ `import { TopBar } from "$lib";`
32
+ -->
@@ -0,0 +1,2 @@
1
+ export { default } from "./TopBar.svelte";
2
+ export type * from "./types.js";
@@ -0,0 +1,54 @@
1
+ @layer app {
2
+ .ds.top-bar {
3
+ /* Exactly the height the page reserves for it, border included, with the
4
+ content centred in it; on a phone it grows with its wrapped rows. */
5
+ box-sizing: border-box;
6
+ block-size: var(--top-bar-block-size, auto);
7
+ display: flex;
8
+ flex-wrap: wrap;
9
+ align-items: center;
10
+ gap: var(--container-gap-default);
11
+ padding-inline: var(--grid-margin);
12
+ border-block-end: var(--dimension-stroke-thickness-medium) solid
13
+ var(--color-border);
14
+
15
+ & > .name {
16
+ font-weight: var(--typography-heading-4-font-weight);
17
+ color: inherit;
18
+ text-decoration: none;
19
+ }
20
+
21
+ & nav {
22
+ display: flex;
23
+ flex: 1;
24
+ flex-wrap: wrap;
25
+ align-items: center;
26
+ gap: var(--container-gap-default);
27
+ }
28
+
29
+ /* The theme and language selectors sit at the end of the bar at their
30
+ own width; the input chrome otherwise fills its container, as a form
31
+ field does. Their forms take no box of their own, so each select (and
32
+ the Apply button without JavaScript) lays out as one of the bar's items. */
33
+ & nav > form {
34
+ display: contents;
35
+ }
36
+
37
+ & nav > form > .ds.input {
38
+ width: auto;
39
+ }
40
+
41
+ & nav > form:first-of-type > .ds.input {
42
+ margin-inline-start: auto;
43
+ }
44
+
45
+ /* On a phone the name takes its own row above the links. */
46
+ @media (width < 620px) {
47
+ block-size: auto;
48
+ padding-block: var(--space-100);
49
+ flex-direction: column;
50
+ align-items: stretch;
51
+ gap: var(--space-100);
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,15 @@
1
+ import type { SvelteHTMLElements } from "svelte/elements";
2
+ import type { ThemePreference } from "../ThemeSelector/index.js";
3
+
4
+ /**
5
+ * Props for `TopBar`. The bar owns its content — the application's name and
6
+ * the demo navigation — so beyond the page it is on it takes only the native
7
+ * props of its root `<header>`, which reach the element unchanged.
8
+ */
9
+ export interface TopBarProps
10
+ extends Omit<SvelteHTMLElements["header"], "children"> {
11
+ /** The current page's pathname. */
12
+ currentUrl: string;
13
+ /** The theme preference the page was rendered with. */
14
+ theme: ThemePreference;
15
+ }
@@ -0,0 +1,16 @@
1
+ <% if (appShell) { -%>
2
+ export { default as ApplicationShell } from "./ApplicationShell/index.js";
3
+ export { default as CanonicalLogo } from "./CanonicalLogo/index.js";
4
+ <% } -%>
5
+ export { default as CodeMessage } from "./CodeMessage/index.js";
6
+ export { ExampleComponent } from "./ExampleComponent/index.js";
7
+ <% if (appShell) { -%>
8
+ export { default as Icon } from "./Icon/index.js";
9
+ <% } -%>
10
+ export { default as LazyComponent } from "./LazyComponent/index.js";
11
+ <% if (intl) { -%>
12
+ export { default as LocaleSelector } from "./LocaleSelector/index.js";
13
+ <% } -%>
14
+ export { default as Navigation } from "./Navigation/index.js";
15
+ export { default as ThemeSelector } from "./ThemeSelector/index.js";
16
+ export { default as TopBar } from "./TopBar/index.js";
@@ -0,0 +1,5 @@
1
+ import type { ParamMatcher } from "@sveltejs/kit";
2
+ import isGuideSlug from "../domains/marketing/isGuideSlug.js";
3
+
4
+ /** Matches a guide slug: lowercase kebab-case, or the URL is a 404. */
5
+ export const match: ParamMatcher = isGuideSlug;
@@ -0,0 +1,27 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { resolveReturnTo } from "./resolveReturnTo.js";
3
+
4
+ const origin = "http://localhost:5180";
5
+
6
+ describe("resolveReturnTo", () => {
7
+ it("returns to a same-origin referer", () => {
8
+ expect(resolveReturnTo(`${origin}/catalog?x=1`, origin)).toBe(
9
+ `${origin}/catalog?x=1`,
10
+ );
11
+ });
12
+
13
+ it("falls back to / for another origin", () => {
14
+ expect(resolveReturnTo("https://evil.example/", origin)).toBe("/");
15
+ });
16
+
17
+ it("keeps a protocol-relative path on this origin", () => {
18
+ expect(resolveReturnTo(`${origin}//evil.example/path`, origin)).toBe(
19
+ `${origin}//evil.example/path`,
20
+ );
21
+ });
22
+
23
+ it("falls back to / without a referer or with a malformed one", () => {
24
+ expect(resolveReturnTo(null, origin)).toBe("/");
25
+ expect(resolveReturnTo("not a url", origin)).toBe("/");
26
+ });
27
+ });
@@ -0,0 +1,13 @@
1
+ /** Return to the referring page only when it is on this origin. */
2
+ export function resolveReturnTo(
3
+ referer: string | null,
4
+ origin: string,
5
+ ): string {
6
+ if (!referer) return "/";
7
+ try {
8
+ const previous = new URL(referer);
9
+ return previous.origin === origin ? previous.href : "/";
10
+ } catch {
11
+ return "/";
12
+ }
13
+ }
@@ -0,0 +1,8 @@
1
+ <script lang="ts">
2
+ import PublicLayout from "../../../layouts/PublicLayout.svelte";
3
+ import type { LayoutProps } from "./$types";
4
+
5
+ let { children }: LayoutProps = $props();
6
+ </script>
7
+
8
+ <PublicLayout>{@render children()}</PublicLayout>
@@ -0,0 +1,6 @@
1
+ import createDelayedData from "../../../lib/LazyComponent/createDelayedData.js";
2
+ import type { PageServerLoad } from "./$types";
3
+
4
+ // The promise is returned without awaiting it, so SvelteKit streams it: the
5
+ // page renders with the fallback, and the value follows in the same response.
6
+ export const load: PageServerLoad = () => ({ streamed: createDelayedData() });
@@ -0,0 +1,8 @@
1
+ <script lang="ts">
2
+ import HomePage from "../../../domains/marketing/HomePage.svelte";
3
+ import type { PageProps } from "./$types";
4
+
5
+ let { data }: PageProps = $props();
6
+ </script>
7
+
8
+ <HomePage streamed={data.streamed} />
@@ -0,0 +1,6 @@
1
+ import createDelayedData from "../../../lib/LazyComponent/createDelayedData.js";
2
+ import type { PageLoad } from "./$types";
3
+
4
+ // Without a server there is nothing to stream: the page renders the fallback
5
+ // until the promise resolves in the browser.
6
+ export const load: PageLoad = () => ({ streamed: createDelayedData() });
@@ -0,0 +1,5 @@
1
+ <script lang="ts">
2
+ import AccountPage from "../../../../domains/account/AccountPage.svelte";
3
+ </script>
4
+
5
+ <AccountPage />
@@ -0,0 +1,4 @@
1
+ import guardAccount from "../../../../domains/account/guardAccount.js";
2
+ import type { PageLoad } from "./$types";
3
+
4
+ export const load: PageLoad = guardAccount;
@@ -0,0 +1,8 @@
1
+ <script lang="ts">
2
+ import CatalogPage from "../../../../domains/catalog/CatalogPage.svelte";
3
+ import type { PageProps } from "./$types";
4
+
5
+ let { data }: PageProps = $props();
6
+ </script>
7
+
8
+ <CatalogPage catalog={data.catalog} />
@@ -0,0 +1,4 @@
1
+ import loadCatalog from "../../../../domains/catalog/loadCatalog.js";
2
+ import type { PageLoad } from "./$types";
3
+
4
+ export const load: PageLoad = loadCatalog;
@@ -0,0 +1,25 @@
1
+ import { fail } from "@sveltejs/kit";
2
+ import {
3
+ readContact,
4
+ validateContact,
5
+ } from "../../../../domains/contact/validateContact.js";
6
+ import type { Actions } from "./$types";
7
+
8
+ /**
9
+ * Validates the contact form with the rules the page checks before posting,
10
+ * and answers with the values, and the errors when it is invalid. With
11
+ * JavaScript the page posts here in place once its own check passes; without
12
+ * it the browser posts here and the page redisplays the answer.
13
+ */
14
+ export const actions: Actions = {
15
+ default: async ({ request }) => {
16
+ const values = readContact(await request.formData());
17
+ const errors = validateContact(values);
18
+
19
+ if (Object.keys(errors).length > 0) {
20
+ return fail(400, { values, errors });
21
+ }
22
+
23
+ return { values };
24
+ },
25
+ };
@@ -0,0 +1,30 @@
1
+ <script lang="ts">
2
+ <% if (spa) { -%>
3
+ import ContactPage from "../../../../domains/contact/ContactPage.svelte";
4
+ import type { ContactValues } from "../../../../domains/contact/types.js";
5
+
6
+ /** The client-only build has no action to post to: a valid submit logs. */
7
+ const logSubmitted = (values: ContactValues) =>
8
+ console.log("Form submitted:", values);
9
+ <% } else { -%>
10
+ import { fromAction } from "svelte/attachments";
11
+ import { enhance } from "$app/forms";
12
+ import ContactPage from "../../../../domains/contact/ContactPage.svelte";
13
+ import type { PageProps } from "./$types";
14
+
15
+ let { form }: PageProps = $props();
16
+
17
+ /**
18
+ * Posts the form to the action in place. Logs the values the action
19
+ * accepted, and keeps them in the form, which `enhance` would otherwise
20
+ * reset.
21
+ */
22
+ const post = fromAction(enhance, () => () => async ({ result, update }) => {
23
+ if (result.type === "success")
24
+ console.log("Form submitted:", result.data?.values);
25
+ await update({ reset: false });
26
+ });
27
+ <% } -%>
28
+ </script>
29
+
30
+ <ContactPage<% if (spa) { %> onSubmit={logSubmitted}<% } else { %> {form} {post}<% } %> />
@@ -0,0 +1,6 @@
1
+ <script lang="ts">
2
+ import { page } from "$app/state";
3
+ import GuidePage from "../../../../../domains/marketing/GuidePage.svelte";
4
+ </script>
5
+
6
+ <GuidePage slug={page.params.slug ?? ""} />
@@ -0,0 +1,6 @@
1
+ <script lang="ts">
2
+ import { page } from "$app/state";
3
+ import LoginPage from "../../../../domains/account/LoginPage.svelte";
4
+ </script>
5
+
6
+ <LoginPage from={page.url.searchParams.get("from") ?? undefined} />
@@ -0,0 +1,9 @@
1
+ <script lang="ts">
2
+ import { page } from "$app/state";
3
+ import TopBarLayout from "../../layouts/TopBarLayout.svelte";
4
+ import type { LayoutProps } from "./$types";
5
+
6
+ let { children, data }: LayoutProps = $props();
7
+ </script>
8
+
9
+ <TopBarLayout currentUrl={page.url.pathname} theme={data.theme}>{@render children()}</TopBarLayout>
@@ -0,0 +1,9 @@
1
+ <script lang="ts">
2
+ import { page } from "$app/state";
3
+ import DashboardLayout from "../../../domains/dashboard/DashboardLayout.svelte";
4
+ import type { LayoutProps } from "./$types";
5
+
6
+ let { children }: LayoutProps = $props();
7
+ </script>
8
+
9
+ <DashboardLayout currentUrl={page.url.pathname}>{@render children()}</DashboardLayout>
@@ -0,0 +1,5 @@
1
+ <script lang="ts">
2
+ import OverviewPage from "../../../domains/dashboard/OverviewPage.svelte";
3
+ </script>
4
+
5
+ <OverviewPage />
@@ -0,0 +1,28 @@
1
+ import { fail } from "@sveltejs/kit";
2
+ import createInstance from "../../../../domains/dashboard/createInstance.js";
3
+ import type { Actions } from "./$types";
4
+
5
+ /**
6
+ * The create form's fallback without JavaScript: the new instance is added to
7
+ * this response only, as the page keeps it in memory only. With JavaScript
8
+ * the page handles the submit itself.
9
+ */
10
+ export const actions: Actions = {
11
+ create: async ({ request }) => {
12
+ const created = createInstance(
13
+ Object.fromEntries(await request.formData()),
14
+ );
15
+
16
+ if (!created) {
17
+ return fail(400, {
18
+ <% if (intl) { -%>
19
+ nameError: "dashboard.instances.nameRequired" as const,
20
+ <% } else { -%>
21
+ nameError: "Instance name is required",
22
+ <% } -%>
23
+ });
24
+ }
25
+
26
+ return { created };
27
+ },
28
+ };
@@ -0,0 +1,19 @@
1
+ <script lang="ts">
2
+ <% if (!spa) { -%>
3
+ import { page } from "$app/state";
4
+ <% } -%>
5
+ import InstancesPage from "../../../../domains/dashboard/InstancesPage.svelte";
6
+ <% if (!spa && forms) { -%>
7
+ import type { PageProps } from "./$types";
8
+
9
+ let { form }: PageProps = $props();
10
+ <% } -%>
11
+ </script>
12
+
13
+ <% if (spa) { -%>
14
+ <InstancesPage />
15
+ <% } else if (forms) { -%>
16
+ <InstancesPage created={form?.created} isCreating={page.url.searchParams.get("create") === "1" || form?.nameError !== undefined} nameError={form?.nameError} selected={page.url.searchParams.get("selected") ?? undefined} />
17
+ <% } else { -%>
18
+ <InstancesPage selected={page.url.searchParams.get("selected") ?? undefined} />
19
+ <% } -%>
@@ -0,0 +1,9 @@
1
+ import type { Actions } from "./$types";
2
+
3
+ /**
4
+ * The settings form's fallback without JavaScript. Saving stores nothing, so
5
+ * the page redisplays as it was.
6
+ */
7
+ export const actions: Actions = {
8
+ save: () => ({ saved: true }),
9
+ };
@@ -0,0 +1,5 @@
1
+ <script lang="ts">
2
+ import SettingsPage from "../../../../domains/dashboard/SettingsPage.svelte";
3
+ </script>
4
+
5
+ <SettingsPage />
@@ -0,0 +1,6 @@
1
+ <script lang="ts">
2
+ import { page } from "$app/state";
3
+ import ErrorPage from "../layouts/ErrorPage.svelte";
4
+ </script>
5
+
6
+ <ErrorPage message={page.error?.message} status={page.status} />
@@ -0,0 +1,8 @@
1
+ import type { LayoutServerLoad } from "./$types";
2
+
3
+ export const load: LayoutServerLoad = ({ locals }) => ({
4
+ theme: locals.theme ?? ("system" as const),
5
+ <% if (intl) { -%>
6
+ locale: locals.locale,
7
+ <% } -%>
8
+ });
@@ -0,0 +1,21 @@
1
+ <script lang="ts">
2
+ import RootLayout from "../layouts/RootLayout.svelte";
3
+ <% if (spa) { -%>
4
+ import setTheme from "../lib/ThemeSelector/setTheme.js";
5
+ <% } -%>
6
+ import type { LayoutProps } from "./$types";
7
+
8
+ let { children<% if (intl || spa) { %>, data<% } %> }: LayoutProps = $props();
9
+ <% if (spa) { -%>
10
+
11
+ // Applies the stored theme to <html> once the page is in the browser: the
12
+ // static fallback page has no server to render the class. It runs once,
13
+ // since the stored theme only changes through the selector, which applies
14
+ // changes itself.
15
+ $effect(() => {
16
+ setTheme(data.theme);
17
+ });
18
+ <% } -%>
19
+ </script>
20
+
21
+ <RootLayout<% if (intl) { %> locale={data.locale}<% } %>>{@render children()}</RootLayout>