Skip to content
This repository was archived by the owner on Sep 26, 2022. It is now read-only.

Commit a981dd9

Browse files
chore: remove gumshoe
Signed-off-by: Florian-Schoenherr <[email protected]>
1 parent cc132cd commit a981dd9

File tree

5 files changed

+73
-33
lines changed

5 files changed

+73
-33
lines changed

packages/docs/src/components/doc/Layout.svelte

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,63 @@
1414
import { Divider, Icon } from 'svelte-materialify/src';
1515
import { onMount, onDestroy, tick } from 'svelte';
1616
import { mdiOpenInNew } from '@mdi/js';
17+
import { hashURL } from '../../util/stores';
18+
19+
export let title;
20+
export let description;
21+
export let keywords;
22+
export let related = null;
23+
let container;
1724
1825
onMount(() => {
19-
document.querySelectorAll('.markdown-container .heading a').forEach((a) => {
20-
if (!a.hash || !document.querySelectorAll(a.hash).length) return;
26+
const visible = [];
27+
container.querySelectorAll('.heading a').forEach((a) => {
28+
if (!a.hash) return;
2129
a.href = window.location.origin + window.location.pathname + a.hash;
22-
a.setAttribute('aria-hidden', true);
23-
a.setAttribute('tabindex', -1);
2430
});
31+
32+
const headingElements = [].slice.call(container.querySelectorAll('.heading:not(h1)'));
33+
const headings = headingElements.map((h) => h.id);
34+
35+
const io = new IntersectionObserver(
36+
(entries) => {
37+
entries.forEach((e) => {
38+
const id = e.target.id;
39+
if (e.isIntersecting) {
40+
// eslint-disable-next-line no-unused-expressions
41+
headings.indexOf(id) < headings.indexOf(visible[0]) ?
42+
visible.unshift(id) :
43+
visible.push(id);
44+
} else {
45+
const visiblePosition = visible.indexOf(id);
46+
if (visiblePosition > -1) visible.splice(visiblePosition, 1);
47+
}
48+
});
49+
const hash = visible[0];
50+
if (hash) {
51+
const oldURL = `${window.location.protocol}//${window.location.host}${window.location.pathname}`;
52+
const newURL = `${oldURL}#${hash}`;
53+
window.history.replaceState({ oldUrl: oldURL }, null, newURL);
54+
// eslint-disable-next-line no-unused-vars
55+
$hashURL = newURL;
56+
}
57+
},
58+
{ threshold: [1] },
59+
);
60+
61+
headingElements.forEach((el) => {
62+
io.observe(el);
63+
});
64+
2565
// Cheap trick to set true on initial load
2666
markdown.update((x) => !x);
67+
return () => io.disconnect();
2768
});
2869
2970
onDestroy(async () => {
3071
await tick();
3172
markdown.set(true);
3273
});
33-
34-
export let title;
35-
export let description;
36-
export let keywords;
37-
export let related = null;
3874
</script>
3975

4076
<style global>
@@ -70,7 +106,9 @@
70106
<Meta title="{title} | Svelte Materialify" {description} {keywords} />
71107

72108
<section class="markdown-container pa-4 pa-sm-6 pa-md-8">
73-
<slot />
109+
<div bind:this={container}>
110+
<slot />
111+
</div>
74112
{#if related}
75113
<RelatedPages {related} />
76114
{/if}

packages/docs/src/components/navigation/LeftNavigationDrawer.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
export let depth = 0;
1515
const offset = 1.5 ** depth * 54;
1616
17+
function equals(browserPath, navItemPath) {
18+
return browserPath === navItemPath || `${browserPath}/` === navItemPath;
19+
}
20+
1721
function expand(parent) {
1822
const found = parent.some((child) => {
1923
if (child.items) return expand(child.items);
20-
return $page.path === child.href;
24+
return equals($page.path, child.href);
2125
});
2226
if (found) activeDepth = depth;
2327
return found;
@@ -44,7 +48,7 @@
4448
<svelte:self item={children} depth={depth + 1} />
4549
{:else}
4650
<a href={children.href} sapper:prefetch>
47-
<ListItem active={children.href === $page.path}>{children.text}</ListItem>
51+
<ListItem active={equals($page.path, children.href)}>{children.text}</ListItem>
4852
</a>
4953
{/if}
5054
{/each}

packages/docs/src/components/navigation/RightNavigationDrawer.svelte

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
<script>
2-
import Gumshoe from 'gumshoejs';
32
import { onMount, tick } from 'svelte';
43
import { markdown } from '@/util/stores';
4+
import { hashURL } from '../../util/stores';
55
66
let items = [];
77
const depths = { H2: 'pl-3', H3: 'pl-6', H4: 'pl-8' };
8-
98
onMount(() => {
10-
const spy = new Gumshoe('#toc a', {
11-
events: false,
12-
offset: 128,
13-
navClass: 'active',
14-
});
15-
169
async function refresh() {
1710
const basename = `${window.location.origin + window.location.pathname}#`;
1811
items = [];
@@ -27,15 +20,13 @@
2720
});
2821
items = items;
2922
await tick();
30-
spy.setup();
3123
}
3224
3325
const unsubscribe = markdown.subscribe((loaded) => {
3426
if (loaded) refresh();
3527
});
3628
3729
return () => {
38-
spy.destroy();
3930
unsubscribe();
4031
};
4132
});
@@ -64,7 +55,7 @@
6455
<h5 class="mb-3 mt-6">Contents</h5>
6556
<ul id="toc" class="pl-4">
6657
{#each items as item}
67-
<li class="{item.class} pt-1 pb-1 text-body-2">
58+
<li class="{item.class} pt-1 pb-1 text-body-2" class:active={item.href === $hashURL}>
6859
<a href={item.href}>{item.text}</a>
6960
</li>
7061
{/each}

packages/docs/src/routes/index.svelte

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
Row,
1313
Col,
1414
Footer,
15-
Alert
15+
Alert,
1616
} from 'svelte-materialify/src';
1717
import Meta from '@/components/Meta.svelte';
18-
import { mdiSpeedometer, mdiGithub, mdiPlus, mdiCheckBold, mdiTwitter } from '@mdi/js';
18+
import { mdiSpeedometer, mdiGithub, mdiPlus, mdiTwitter } from '@mdi/js';
1919
</script>
2020

2121
<style lang="scss">
@@ -100,17 +100,20 @@
100100
<h2 class="font-weight-bold">DISCLAMER</h2>
101101
<br />
102102
<p>
103-
Svelte Materialify is soon to be deprecated is favour of <a href="https://github.com/svelterialjs/svelterial">svelterialjs</a>.
104-
My exams are still going on as they were postponed due to the increasing number of CoVID cases in
105-
my country.
103+
Svelte Materialify is soon to be deprecated is favour of <a
104+
href="https://github.com/svelterialjs/svelterial">svelterialjs</a
105+
>. My exams are still going on as they were postponed due to the increasing number
106+
of CoVID cases in my country.
106107
</p>
107108
</Alert>
108-
109+
109110
<p>
110-
I would like to apologize to <a href="https://github.com/hperrin/svelte-material-ui">Svelte Material UI</a> for
111-
posting wrong and outdated information in the comparision table. SMUI 4 is an extremely good alternative to svelte materialify
112-
while the rewrite <a href="https://github.com/svelterialjs/svelterial">Svelterial</a> is still in development.
113-
</p>
111+
I would like to apologize to <a href="https://github.com/hperrin/svelte-material-ui"
112+
>Svelte Material UI</a>
113+
for posting wrong and outdated information in the comparision table. SMUI 4 is an
114+
extremely good alternative to svelte materialify while the rewrite
115+
<a href="https://github.com/svelterialjs/svelterial">Svelterial</a> is still in development.
116+
</p>
114117
</Container>
115118

116119
<Footer class="theme--dark">

packages/docs/src/util/stores.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ export { theme };
77
const markdown = writable(false);
88

99
export { markdown };
10+
11+
const hashURL = writable(process.browser ? window.location.href : '');
12+
13+
export { hashURL };

0 commit comments

Comments
 (0)