@onsvisual/svelte-components 1.0.35 → 1.0.37
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.
|
@@ -33,12 +33,15 @@
|
|
|
33
33
|
const observer = getContext("observer");
|
|
34
34
|
const tocId = getContext("tocId");
|
|
35
35
|
|
|
36
|
+
let section;
|
|
36
37
|
let mounted = false;
|
|
37
38
|
let observed = false;
|
|
38
39
|
|
|
39
|
-
// This
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
// This should allow the table of contents (toc) to render before hydration
|
|
41
|
+
$sections = [
|
|
42
|
+
...$sections.filter((s) => s.id !== id),
|
|
43
|
+
{ id, dataset: { title, subsection: String(subsection) } }
|
|
44
|
+
];
|
|
42
45
|
|
|
43
46
|
// This allows sections to be highlighted on the toc after hydration,
|
|
44
47
|
// and for sections to be added/removed gracefully from the DOM
|
|
@@ -39,7 +39,9 @@
|
|
|
39
39
|
*/
|
|
40
40
|
export let marginBottom = true;
|
|
41
41
|
|
|
42
|
+
let el;
|
|
42
43
|
let active;
|
|
44
|
+
let mounted = false;
|
|
43
45
|
|
|
44
46
|
setContext("tocId", id);
|
|
45
47
|
|
|
@@ -50,6 +52,7 @@
|
|
|
50
52
|
setContext("observer", observer);
|
|
51
53
|
|
|
52
54
|
function formatSections(sections) {
|
|
55
|
+
if (sections.length === 0) return [];
|
|
53
56
|
const secs = [];
|
|
54
57
|
let sec = { subsections: [] };
|
|
55
58
|
for (const section of sections) {
|
|
@@ -62,7 +65,6 @@
|
|
|
62
65
|
}
|
|
63
66
|
return [...secs, sec];
|
|
64
67
|
}
|
|
65
|
-
$: formattedSections = formatSections($sections);
|
|
66
68
|
|
|
67
69
|
onMount(() => {
|
|
68
70
|
if (!noContents) {
|
|
@@ -82,12 +84,25 @@
|
|
|
82
84
|
}
|
|
83
85
|
);
|
|
84
86
|
}
|
|
87
|
+
// The table of contents doesn't populate unless it's after the main content
|
|
88
|
+
// This is a trick to flip the order when the page hydrates
|
|
89
|
+
el.prepend(el.lastElementChild);
|
|
90
|
+
mounted = true;
|
|
85
91
|
});
|
|
86
92
|
</script>
|
|
87
93
|
|
|
88
94
|
<Container {cls} {width} {marginTop} {marginBottom}>
|
|
89
|
-
<div
|
|
90
|
-
|
|
95
|
+
<div
|
|
96
|
+
class="ons-grid ons-grid--spaced ons-grid--loose ons-js-toc-container"
|
|
97
|
+
class:flip-display-order={!mounted}
|
|
98
|
+
bind:this={el}
|
|
99
|
+
>
|
|
100
|
+
<div class="ons-nav-sections-content ons-grid__col ons-col-8@m">
|
|
101
|
+
<slot name="before" />
|
|
102
|
+
<slot />
|
|
103
|
+
<slot name="after" />
|
|
104
|
+
</div>
|
|
105
|
+
<div class="ons-nav-sections-toc ons-grid__col ons-grid__col--sticky@m ons-col-4@m">
|
|
91
106
|
<aside class="ons-table-of-contents-container" role="complementary">
|
|
92
107
|
<slot name="before-nav" />
|
|
93
108
|
{#if !noContents}
|
|
@@ -96,47 +111,50 @@
|
|
|
96
111
|
<h2 class="ons-table-of-contents__title ons-u-fs-r--b ons-u-mb-s">Contents</h2>
|
|
97
112
|
{/if}
|
|
98
113
|
<ol class="ons-list ons-u-mb-l ons-list--dashed">
|
|
99
|
-
{#
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
{/each}
|
|
128
|
-
{/if}
|
|
114
|
+
{#each formatSections($sections) as section}
|
|
115
|
+
<li class="ons-list__item">
|
|
116
|
+
{#if section.id && section.title}
|
|
117
|
+
<a
|
|
118
|
+
href="#{section.id}"
|
|
119
|
+
class="ons-list__link"
|
|
120
|
+
class:ons-table-of-contents__link-active={section.id === active}
|
|
121
|
+
>
|
|
122
|
+
{section.title}
|
|
123
|
+
</a>
|
|
124
|
+
{/if}
|
|
125
|
+
{#if section.subsections.length > 0}
|
|
126
|
+
<ol class="ons-list ons-u-mb-no ons-list--dashed">
|
|
127
|
+
{#each section.subsections as subsection}
|
|
128
|
+
<li class="ons-list__item">
|
|
129
|
+
<a
|
|
130
|
+
href="#{subsection.id}"
|
|
131
|
+
class="ons-list__link"
|
|
132
|
+
class:ons-table-of-contents__link-active={subsection.id === active}
|
|
133
|
+
>
|
|
134
|
+
{subsection.title}
|
|
135
|
+
</a>
|
|
136
|
+
</li>
|
|
137
|
+
{/each}
|
|
138
|
+
</ol>
|
|
139
|
+
{/if}
|
|
140
|
+
</li>
|
|
141
|
+
{/each}
|
|
129
142
|
</ol>
|
|
130
143
|
</nav>
|
|
131
144
|
{/if}
|
|
132
145
|
<slot name="after-nav" />
|
|
133
146
|
</aside>
|
|
134
147
|
</div>
|
|
135
|
-
<div class="ons-grid__col ons-col-8@m">
|
|
136
|
-
<slot name="before" />
|
|
137
|
-
<slot />
|
|
138
|
-
<slot name="after" />
|
|
139
|
-
</div>
|
|
140
148
|
</div>
|
|
141
149
|
<slot name="footer" />
|
|
142
150
|
</Container>
|
|
151
|
+
|
|
152
|
+
<style>
|
|
153
|
+
/* These classes force the table of contents to render on the left of the page before hydration */
|
|
154
|
+
.flip-display-order {
|
|
155
|
+
direction: rtl;
|
|
156
|
+
}
|
|
157
|
+
.flip-display-order > * {
|
|
158
|
+
direction: initial;
|
|
159
|
+
}
|
|
160
|
+
</style>
|
|
@@ -12,11 +12,11 @@ export default class NavSections extends SvelteComponentTyped<{
|
|
|
12
12
|
}, {
|
|
13
13
|
[evt: string]: CustomEvent<any>;
|
|
14
14
|
}, {
|
|
15
|
-
'before-nav': {};
|
|
16
|
-
'after-nav': {};
|
|
17
15
|
before: {};
|
|
18
16
|
default: {};
|
|
19
17
|
after: {};
|
|
18
|
+
'before-nav': {};
|
|
19
|
+
'after-nav': {};
|
|
20
20
|
footer: {};
|
|
21
21
|
}> {
|
|
22
22
|
}
|
|
@@ -38,11 +38,11 @@ declare const __propDef: {
|
|
|
38
38
|
[evt: string]: CustomEvent<any>;
|
|
39
39
|
};
|
|
40
40
|
slots: {
|
|
41
|
-
'before-nav': {};
|
|
42
|
-
'after-nav': {};
|
|
43
41
|
before: {};
|
|
44
42
|
default: {};
|
|
45
43
|
after: {};
|
|
44
|
+
'before-nav': {};
|
|
45
|
+
'after-nav': {};
|
|
46
46
|
footer: {};
|
|
47
47
|
};
|
|
48
48
|
};
|