Skip to content

Commit 87d94df

Browse files
author
Quang Phan
committed
chore(toc): expose toclink parameters type in public api
1 parent c797ea8 commit 87d94df

14 files changed

Lines changed: 218 additions & 18 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@svelte-put/toc': patch
3+
---
4+
5+
expose `toclink` parameters types in build output

apps/docs/src/routes/(main)/docs/(pkg)/toc/+page.svelte

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</ConnectedListItem>
4141
<ConnectedListItem>
4242
<p>
43-
generate <code>id</code> attribute from element content,
43+
generate <code>id</code> attribute from element <code>textContent</code>,
4444
</p>
4545
</ConnectedListItem>
4646
<ConnectedListItem>
@@ -77,22 +77,20 @@
7777
</p>
7878

7979
<p class="c-callout-info">
80-
The table of contents on this documentation site is generated by <code>toc</code> itself. Check
80+
The table of contents in this documentation site is generated by <code>toc</code> itself. Check
8181
out the
8282
<ResourceLink
83-
href="https://github.com/vnphanquang/svelte-put/blob/main/apps/docs/src/routes/(main)/+layout.svelte#L223-L227"
83+
href="https://github.com/vnphanquang/svelte-put/blob/main/apps/docs/src/routes/(main)/+layout.svelte"
8484
>
85-
source code here.
86-
</ResourceLink>
85+
source code here
86+
</ResourceLink> (search for <code>tocStore</code>).
8787
</p>
8888
</section>
8989

9090
<section>
9191
<h2 id="quick-start">Quick Start</h2>
9292
<p>
93-
Given the following svelte component, let's see how <code>toc</code> searches for all headings,
94-
generates id based on <code>textContent</code>, adds anchor tag, and tracks active element on
95-
screen.
93+
Given the following svelte component, let's see how <code>toc</code> does it job.
9694
</p>
9795
<Code code={codes.quickStart.input} title="quick start - input" />
9896
<p>
@@ -263,10 +261,10 @@
263261
<Code code={codes.caveat.prefer} title="think in terms of section" icon="info" />
264262
<Code code={codes.caveat.avoid} title="rather than flat individual elements" icon="error" />
265263
<p>
266-
You might also find that when an anchor linked to a matching toc element being clicked on (to
267-
scroll to said element), the toc element might not be the active one. This is explained with
268-
with idiomatic solution in <ResourceLink id="complementary-toclink-action"
269-
>toclink</ResourceLink
264+
You might also find that when an anchor linked to its matching toc element is clicked on (to
265+
scroll to said element), <code>toc</code> might not set that element as the active one. This
266+
is explained and an idiomatic solution is provided in <ResourceLink
267+
id="complementary-toclink-action">toclink</ResourceLink
270268
>.
271269
</p>
272270
</section>
@@ -332,11 +330,12 @@
332330
<p>Regarding markup, this is essentially the same as:</p>
333331
<Code code={codes.toclink.equivalence} title="toclink - markup equivalence" />
334332
<p>
335-
However, <code>toclink</code> provides additional click listener that makes sure the toc item being
336-
clicked on will be the active one.
333+
However, <code>toclink</code> provides an additional click listener that makes sure the toc item
334+
being clicked on will be the active one.
337335
</p>
338336
<p class="c-callout-warning">
339-
This is not always guaranteed otherwise, because toc relies on
337+
This is not always guaranteed otherwise (when not using <code>toclink</code>), because toc
338+
relies on
340339
<code>IntersectionObserver</code>, and when a matching toc element is scrolled into view, the
341340
next one might already intersects with the viewport and become the active one.
342341
</p>

packages/actions/toc/api/docs/toc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Svelte action `use:toc` for building table of contents
2323
| [TocEventDetails](./toc.toceventdetails.md) | |
2424
| [TocInitEventDetails](./toc.tociniteventdetails.md) | <code>event.detail</code> of <code>on:tocinit</code> |
2525
| [TocItem](./toc.tocitem.md) | information about an extracted toc item |
26+
| [TocLinkObserveParameters](./toc.toclinkobserveparameters.md) | configure relationship between the <code>observe</code> functionality of <code>toc</code> and <code>toclink</code> |
27+
| [TocLinkParameters](./toc.toclinkparameters.md) | options to configure the behavior of the <code>toclink</code> svelte action |
2628
| [TocObserveParameters](./toc.tocobserveparameters.md) | options to config how <code>toc</code> action create <code>IntersectionObserver</code> for each matching toc element |
2729
| [TocParameters](./toc.tocparameters.md) | |
2830

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@svelte-put/toc](./toc.md) &gt; [TocLinkObserveParameters](./toc.toclinkobserveparameters.md) &gt; [attribute](./toc.toclinkobserveparameters.attribute.md)
4+
5+
## TocLinkObserveParameters.attribute property
6+
7+
boolean attribute(s) to indicate if this is linking to the active toc item
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
attribute?: string | string[] | boolean;
13+
```
14+
15+
## Remarks
16+
17+
For this to work, it is required that `tocItem` be provided or the href is in the form `'#<toc-item-id>'`
18+
19+
By default, `toclink` uses [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) . For better performance, provide `store`
20+
21+
Set `false` to disable this behavior
22+
23+
Default to: `'data-toc-link-active'`
24+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@svelte-put/toc](./toc.md) &gt; [TocLinkObserveParameters](./toc.toclinkobserveparameters.md) &gt; [enabled](./toc.toclinkobserveparameters.enabled.md)
4+
5+
## TocLinkObserveParameters.enabled property
6+
7+
whether to enable this configuration Default to: `false`
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
enabled?: boolean;
13+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@svelte-put/toc](./toc.md) &gt; [TocLinkObserveParameters](./toc.toclinkobserveparameters.md)
4+
5+
## TocLinkObserveParameters interface
6+
7+
configure relationship between the `observe` functionality of `toc` and `toclink`
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export interface TocLinkObserveParameters
13+
```
14+
15+
## Properties
16+
17+
| Property | Modifiers | Type | Description |
18+
| --- | --- | --- | --- |
19+
| [attribute?](./toc.toclinkobserveparameters.attribute.md) | | string \| string\[\] \| boolean | <i>(Optional)</i> boolean attribute(s) to indicate if this is linking to the active toc item |
20+
| [enabled?](./toc.toclinkobserveparameters.enabled.md) | | boolean | <i>(Optional)</i> whether to enable this configuration Default to: <code>false</code> |
21+
| [throttleOnClick?](./toc.toclinkobserveparameters.throttleonclick.md) | | number | <i>(Optional)</i> throttle the observe of <code>use:toc</code> on click |
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@svelte-put/toc](./toc.md) &gt; [TocLinkObserveParameters](./toc.toclinkobserveparameters.md) &gt; [throttleOnClick](./toc.toclinkobserveparameters.throttleonclick.md)
4+
5+
## TocLinkObserveParameters.throttleOnClick property
6+
7+
throttle the observe of `use:toc` on click
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
throttleOnClick?: number;
13+
```
14+
15+
## Remarks
16+
17+
This ensures that the active toc item will be the same one that this link is pointing to. Otherwise, it is not guaranteed so, because `observe` is handled with `IntersectionObserver` the next items might already comes into viewport when this link is clicked.
18+
19+
Set to 0 to disable throttling.
20+
21+
Default to: `500`
22+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@svelte-put/toc](./toc.md) &gt; [TocLinkParameters](./toc.toclinkparameters.md)
4+
5+
## TocLinkParameters interface
6+
7+
options to configure the behavior of the `toclink` svelte action
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export interface TocLinkParameters
13+
```
14+
15+
## Properties
16+
17+
| Property | Modifiers | Type | Description |
18+
| --- | --- | --- | --- |
19+
| [observe?](./toc.toclinkparameters.observe.md) | | [TocLinkObserveParameters](./toc.toclinkobserveparameters.md) \| boolean | <i>(Optional)</i> connect and reflect the <code>observe</code> functionality of <code>toc</code> |
20+
| [store?](./toc.toclinkparameters.store.md) | | [TocStore](./toc.tocstore.md) | <i>(Optional)</i> svelte store as used in <code>use:toc</code> |
21+
| [tocId?](./toc.toclinkparameters.tocid.md) | | string | <i>(Optional)</i> the ID of the toc operations. If not provided will search for the closest toc root (where <code>use:toc</code> is used) |
22+
| [tocItem?](./toc.toclinkparameters.tocitem.md) | | string \| [TocItem](./toc.tocitem.md) | <i>(Optional)</i> the matching toc item or its id to link to |
23+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@svelte-put/toc](./toc.md) &gt; [TocLinkParameters](./toc.toclinkparameters.md) &gt; [observe](./toc.toclinkparameters.observe.md)
4+
5+
## TocLinkParameters.observe property
6+
7+
connect and reflect the `observe` functionality of `toc`
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
observe?: TocLinkObserveParameters | boolean;
13+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@svelte-put/toc](./toc.md) &gt; [TocLinkParameters](./toc.toclinkparameters.md) &gt; [store](./toc.toclinkparameters.store.md)
4+
5+
## TocLinkParameters.store property
6+
7+
svelte store as used in `use:toc`
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
store?: TocStore;
13+
```
14+
15+
## Remarks
16+
17+
recommended as an optimization when `observe.current` is enabled
18+

0 commit comments

Comments
 (0)