Skip to content

Commit e4d7912

Browse files
committed
feat: link to non-leaf configuration nodes
1 parent 2a85640 commit e4d7912

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/components/ConfigNode.astro

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ const formatDefault = (value?: string): Default => {
5555

5656
const { value, inline } = formatDefault(rawValue.default);
5757
return (
58-
<div>
58+
<section id={childPath.join("_")}>
5959
{"message" in rawValue ? (
6060
<div
6161
class:list={["block", "message", rawValue.inline && "message-inline"]}
6262
style={rawValue.color ? `border-left-color: ${rawValue.color}` : undefined}
6363
set:html={render(rawValue.message)}
6464
/>
6565
) : "description" in rawValue ? (
66-
<details id={childPath.join("_")}>
67-
<summary class="line notranslate" translate="no">
66+
<details>
67+
<summary class="line line-leaf notranslate" translate="no">
6868
<span class="key key-leaf">{displayKey}</span><span class="muted">{separator}</span>{
6969
inline
7070
? (<span class="value">{value}</span><>{hasComma && <span class="muted">,</span>}</><a class="link link-inline" href={`#${childPath.join("_")}`}>#</a>)
@@ -74,17 +74,20 @@ const formatDefault = (value?: string): Default => {
7474
<div class="block" set:html={render(rawValue.description)} />
7575
</details>
7676
) : (
77-
<span class="key notranslate" translate="no">{displayKey}</span><span class="muted">{separator}</span>
77+
<div class="line notranslate" translate="no">
78+
<span class="key">{displayKey}</span><span class="muted">{separator}</span><a class="link" href={`#${childPath.join("_")}`}>#</a>
79+
</div>
7880
<Astro.self child data={rawValue} path={childPath} {lang} />
7981
)}
80-
</div>
82+
</section>
8183
);
8284
})
8385
}
8486
{json && <p class="muted">{"}"}</p>}
8587
</div>
8688

8789
<style>
90+
section:target,
8891
details:target {
8992
padding: 0.25rem 0;
9093
border-image: conic-gradient(oklch(from var(--sl-color-accent) l c h / 0.1) 0, oklch(from var(--sl-color-accent) l c h / 0.1) 0) fill 0/0/0 100vw;
@@ -100,7 +103,7 @@ const formatDefault = (value?: string): Default => {
100103
padding-left: 0;
101104
}
102105

103-
.node-json > div {
106+
.node-json > section {
104107
padding-left: 1.25rem;
105108
}
106109

@@ -112,9 +115,12 @@ const formatDefault = (value?: string): Default => {
112115
}
113116

114117
.line {
118+
word-break: break-all;
119+
}
120+
121+
.line-leaf {
115122
cursor: pointer;
116123
list-style: none;
117-
word-break: break-all;
118124
}
119125

120126
.key {
@@ -185,10 +191,16 @@ const formatDefault = (value?: string): Default => {
185191
return;
186192
}
187193

188-
const el = document.getElementById(hash) as HTMLDetailsElement | null;
189-
if (el?.tagName === "DETAILS") {
190-
el.open = true;
191-
el.scrollIntoView({ behavior: "smooth", block: "start" });
194+
const el = document.getElementById(hash);
195+
if (!el) {
196+
return;
197+
}
198+
199+
const details = el.querySelector(":scope > details") as HTMLDetailsElement | null;
200+
if (details) {
201+
details.open = true;
192202
}
203+
204+
el.scrollIntoView({ behavior: "smooth", block: "start" });
193205
});
194206
</script>

0 commit comments

Comments
 (0)