@onsvisual/svelte-components 0.1.68 → 0.1.70

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.
@@ -8,6 +8,7 @@ export default class AnalyticsBanner extends SvelteComponentTyped<{
8
8
  analyticsProps?: any;
9
9
  hideBanner?: boolean;
10
10
  usageCookies?: boolean;
11
+ pageViewEnabled?: boolean;
11
12
  }, {
12
13
  [evt: string]: CustomEvent<any>;
13
14
  }, {}> {
@@ -23,6 +24,7 @@ declare const __propDef: {
23
24
  analyticsProps?: object;
24
25
  hideBanner?: boolean;
25
26
  usageCookies?: boolean;
27
+ pageViewEnabled?: boolean;
26
28
  };
27
29
  events: {
28
30
  [evt: string]: CustomEvent<any>;
@@ -34,6 +34,11 @@
34
34
  * @type {"wide"|"wider"}
35
35
  */
36
36
  export let width = "wide";
37
+ /**
38
+ * Enable automatic pageView event on route changes
39
+ * @type {boolean}
40
+ */
41
+ export let pageViewEnabled = true;
37
42
 
38
43
  let live; // Don't run analytics unless page is live on ONS site (re-set in the onMount function)
39
44
  let showBanner = false;
@@ -119,7 +124,7 @@
119
124
  }
120
125
  }
121
126
  }
122
- $: onPageChange($page);
127
+ $: if (pageViewEnabled) onPageChange($page);
123
128
 
124
129
  onMount(() => {
125
130
  live = true;
@@ -69,6 +69,21 @@
69
69
  const observer = writable();
70
70
  setContext("observer", observer);
71
71
 
72
+ function formatSections(sections) {
73
+ const secs = [];
74
+ let sec = { subsections: [] };
75
+ for (const section of sections) {
76
+ if (section.dataset.subsection !== "true") {
77
+ if (sec.title || sec.subsections.length > 0) secs.push(sec);
78
+ sec = { id: section.id, title: section.dataset.title, subsections: [] };
79
+ } else {
80
+ sec.subsections.push({ id: section.id, title: section.dataset.title });
81
+ }
82
+ }
83
+ return [...secs, sec];
84
+ }
85
+ $: formattedSections = formatSections($sections);
86
+
72
87
  onMount(() => {
73
88
  if (!noContents) {
74
89
  $observer = new IntersectionObserver(
@@ -113,20 +128,36 @@
113
128
  </h2>
114
129
  {/if}
115
130
  <ol class="ons-list ons-u-mb-m ons-list--dashed">
116
- {#each $sections as section}
117
- <li
118
- class="ons-list__item"
119
- class:ons-list__item-indented="{section.dataset.subsection === 'true'}"
120
- >
121
- <a
122
- href="#{section.id}"
123
- class="ons-list__link"
124
- class:ons-toc__link-active="{section.id === active}"
125
- >
126
- {section.dataset.title}
127
- </a>
128
- </li>
129
- {/each}
131
+ {#if formattedSections}
132
+ {#each formattedSections as section}
133
+ <li class="ons-list__item">
134
+ {#if section.id && section.title}
135
+ <a
136
+ href="#{section.id}"
137
+ class="ons-list__link"
138
+ class:ons-toc__link-active="{section.id === active}"
139
+ >
140
+ {section.title}
141
+ </a>
142
+ {/if}
143
+ {#if section.subsections.length > 0}
144
+ <ol class="ons-list ons-u-mb-no ons-list--dashed">
145
+ {#each section.subsections as subsection}
146
+ <li class="ons-list__item">
147
+ <a
148
+ href="#{subsection.id}"
149
+ class="ons-list__link"
150
+ class:ons-toc__link-active="{subsection.id === active}"
151
+ >
152
+ {subsection.title}
153
+ </a>
154
+ </li>
155
+ {/each}
156
+ </ol>
157
+ {/if}
158
+ </li>
159
+ {/each}
160
+ {/if}
130
161
  </ol>
131
162
  {/if}
132
163
  <slot name="after-nav" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "0.1.68",
3
+ "version": "0.1.70",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://onsvisual.github.io/svelte-components",