@onsvisual/svelte-components 0.1.67 → 0.1.69

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.
@@ -54,7 +54,7 @@
54
54
 
55
55
  <section
56
56
  id="{id}"
57
- title="{title}"
57
+ data-title="{title}"
58
58
  data-type="NavSection"
59
59
  data-subsection="{subsection}"
60
60
  class="{cls}"
@@ -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.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" />
@@ -42,7 +42,7 @@
42
42
 
43
43
  <section
44
44
  id="{id}"
45
- title="{title}"
45
+ data-title="{title}"
46
46
  data-type="Tab"
47
47
  class="ons-tabs__panel"
48
48
  bind:this="{el}"
@@ -54,10 +54,10 @@
54
54
  class:ons-tab--selected="{section.id === selected}"
55
55
  data-ga="click"
56
56
  data-ga-category="tabs"
57
- data-ga-action="Show: {section.title}"
58
- data-ga-label="Show: {section.title}"
57
+ data-ga-action="Show: {section.dataset.title}"
58
+ data-ga-label="Show: {section.dataset.title}"
59
59
  aria-selected="{section.id === selected ? 'true' : 'false'}"
60
- on:click|preventDefault="{() => showSection(section.id)}">{section.title}</a
60
+ on:click|preventDefault="{() => showSection(section.id)}">{section.dataset.title}</a
61
61
  >
62
62
  </li>
63
63
  {/each}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "0.1.67",
3
+ "version": "0.1.69",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://onsvisual.github.io/svelte-components",