@onsvisual/svelte-components 1.1.47 → 1.1.48

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.
@@ -64,7 +64,7 @@
64
64
  */
65
65
  export let legacy = false;
66
66
  /**
67
- * Optional: Pass the "page" store from "$app/state" in SvelteKit (gets read from context by default if it exists)
67
+ * Optional: Pass the "page" state from "$app/state" in SvelteKit (gets read from context by default if it exists)
68
68
  * @type {any}
69
69
  */
70
70
  export let page = getContext("page");
@@ -81,14 +81,16 @@
81
81
 
82
82
  let el; // Header HTML element
83
83
 
84
+ let _page;
84
85
  let lang = "en";
85
86
  let baseurl = "https://www.ons.gov.uk";
86
87
  let baseother = "https://cy.ons.gov.uk";
87
88
  let path = "";
88
89
  let activeLink = null;
89
90
 
90
- function setPaths() {
91
- const url = page?.url || document.location;
91
+ function setPaths(page) {
92
+ if (!page) return;
93
+ const url = page.url;
92
94
  lang = url.host.startsWith("cy") ? "cy" : "en";
93
95
  baseurl = lang === "cy" ? "https://cy.ons.gov.uk" : "https://www.ons.gov.uk";
94
96
  baseother = lang === "cy" ? "https://www.ons.gov.uk" : "https://cy.ons.gov.uk";
@@ -115,24 +117,23 @@
115
117
  Cymraeg: "English",
116
118
  "Newid iaith i": "Change language to"
117
119
  };
118
-
119
120
  $: i18n = (text) => (lang === "cy" && texts[text] ? texts[text] : text);
120
121
 
121
122
  onMount(() => {
123
+ _page = page || { url: document?.location };
122
124
  setPaths();
123
125
 
124
126
  if ((!compact && !legacy) || (title && Array.isArray(navLinks))) {
125
- const hasBodyClass = "className" in document.body || {};
126
- const bodyClassString = document.body?.className || "";
127
+ const hasBodyClass = "className" in document?.body || {};
128
+ const bodyClassString = document?.body?.className || "";
127
129
  if (hasBodyClass && !bodyClassString.includes("ons-js-enabled"))
128
130
  document.body.className = bodyClassString + " ons-js-enabled";
129
131
  initNav(el?.parentElement || document);
130
132
  }
131
133
  });
134
+ $: setPaths(_page);
132
135
  </script>
133
136
 
134
- <svelte:window onpopstate={setPaths} />
135
-
136
137
  <header
137
138
  class="ons-header"
138
139
  class:ons-header--basic={!compact && !legacy}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "1.1.47",
3
+ "version": "1.1.48",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "npm run build:package && npm run build:docs",