starlight-sidebar-topics-dropdown 0.6.0 → 0.7.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # starlight-sidebar-topics-dropdown
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#138](https://github.com/trueberryless/starlight-sidebar-topics-dropdown/pull/138) [`53c2e25`](https://github.com/trueberryless/starlight-sidebar-topics-dropdown/commit/53c2e255ff5e3b742eee8037ee87ae93f0d978e8) Thanks [@trueberryless-bot](https://github.com/trueberryless-bot)! - Updates the repository links after the move from the `trueberryless-org` GitHub organization to the `trueberryless` account.
8
+
9
+ ## 0.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#129](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/129) [`068240b`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/068240bb01ce039b48652803fe5f4b15c55b59bc) Thanks [@trueberryless](https://github.com/trueberryless) and [@deining](https://github.com/deining)! - Adds support for Astro v7, drops support for Astro v6.
14
+
15
+ ⚠️ **BREAKING CHANGE:** The minimum supported version of Starlight is now `0.42.0` and the minimum supported version of Starlight Sidebar Topics is now `0.9.0`.
16
+
17
+ Please follow the [upgrade guide](https://github.com/withastro/starlight/releases/tag/%40astrojs%2Fstarlight%400.42.0) to update your project.
18
+
19
+ ### Patch Changes
20
+
21
+ - [#129](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/129) [`068240b`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/068240bb01ce039b48652803fe5f4b15c55b59bc) Thanks [@trueberryless](https://github.com/trueberryless)! - Adds a readable error message with a hint when the component is used without the [Starlight Sidebar Topics](https://starlight-sidebar-topics.netlify.app/) plugin.
22
+
23
+ - [#129](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/129) [`068240b`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/068240bb01ce039b48652803fe5f4b15c55b59bc) Thanks [@trueberryless](https://github.com/trueberryless)! - Fixes a build error on pages not associated with any topic, e.g. [excluded pages](https://starlight-sidebar-topics.netlify.app/docs/guides/excluded-pages/). The dropdown menu is no longer rendered on such pages, matching the built-in topic list of the Starlight Sidebar Topics plugin.
24
+
25
+ - [#129](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/129) [`068240b`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/068240bb01ce039b48652803fe5f4b15c55b59bc) Thanks [@trueberryless](https://github.com/trueberryless)! - Fixes an issue where the [HTML attributes](https://starlight-sidebar-topics.netlify.app/docs/configuration/#attrs) configured for a topic link were not applied to the links in the dropdown menu.
26
+
27
+ - [#129](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/129) [`068240b`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/068240bb01ce039b48652803fe5f4b15c55b59bc) Thanks [@trueberryless](https://github.com/trueberryless)! - Improves the dropdown menu accessibility by exposing its expanded state to assistive technologies, and fixes an issue where only the first dropdown menu would work when rendering multiple dropdown menus on the same page.
28
+
3
29
  ## 0.6.0
4
30
 
5
31
  ### Minor Changes
@@ -107,7 +133,7 @@
107
133
 
108
134
  ### Minor Changes
109
135
 
110
- - [#31](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/31) [`3193771`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/31937716171b020f414ece6783c17181fbd5fdcf) Thanks [@trueberryless](https://github.com/trueberryless)! - ⚠️ **BREAKING CHANGE:** The Starlight Sidebar Topics Dropdown plugin no longer provides the same ["Unnested Sidebar" configuration](https://starlight-sidebar-topics-dropdown.trueberryless.org/docs/guides/unnested-sidebar/) like before. Please adapt your `astro.config.mjs` with the up-to-date guide on [how to configure a "Unnested Sidebar"](https://starlight-sidebar-topics-dropdown.trueberryless.org/docs/guides/unnested-sidebar/#configure-an-unnested-sidebar).
136
+ - [#31](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/31) [`3193771`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/31937716171b020f414ece6783c17181fbd5fdcf) Thanks [@trueberryless](https://github.com/trueberryless)! - ⚠️ **BREAKING CHANGE:** The Starlight Sidebar Topics Dropdown plugin no longer provides the same ["Unnested Sidebar" configuration](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/blob/5034b142e08b2561813fed9553ab0ee73109d30b/docs/src/content/docs/docs/guides/unnested-sidebar.mdx) like before. Please adapt your `astro.config.mjs` with the up-to-date guide on [how to configure a "Unnested Sidebar"](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/blob/5034b142e08b2561813fed9553ab0ee73109d30b/docs/src/content/docs/docs/guides/unnested-sidebar.mdx#configure-an-unnested-sidebar).
111
137
 
112
138
  - [#31](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/31) [`db10526`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/db10526d49aab3ac8619159d40968dbc4748c9a0) Thanks [@trueberryless](https://github.com/trueberryless)! - ⚠️ **BREAKING CHANGE:** The minimum supported version of Starlight is now version `0.32.0`.
113
139
 
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present, trueberryless
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # `starlight-sidebar-topics-dropdown`
2
2
 
3
- Dropdown topic list for the Starlight Sidebar Topics plugin.
3
+ Starlight component to display the [Starlight Sidebar Topics](https://starlight-sidebar-topics.netlify.app) plugin topic list as a dropdown menu.
4
4
 
5
5
  ## Documentation
6
6
 
7
7
  Want to get started immediately?
8
8
 
9
- Check out the `starlight-sidebar-topics-dropdown` getting started guide.
9
+ Check out the [getting started guide](https://starlight-sidebar-topics-dropdown.netlify.app/docs/getting-started/).
10
10
 
11
11
  ## License
12
12
 
13
13
  Licensed under the MIT license, Copyright © trueberryless.
14
14
 
15
- See [LICENSE](/LICENSE) for more information.
15
+ See [LICENSE](https://github.com/trueberryless/starlight-sidebar-topics-dropdown/blob/main/LICENSE) for more information.
@@ -1,73 +1,70 @@
1
1
  ---
2
2
  import { Badge, Icon } from "@astrojs/starlight/components";
3
- import type { ComponentProps } from "astro/types";
4
3
 
5
- const { topics } = Astro.locals.starlightSidebarTopics;
6
- const currentTopic = topics.find((topic) => topic.isCurrent);
4
+ import { getTopicLinkAttributes, getTopicsDropdown } from "../libs/topics";
5
+
6
+ const dropdown = getTopicsDropdown(Astro.locals);
7
7
  ---
8
8
 
9
- <div class="starlight-sidebar-topics-dropdown-dropdown">
10
- <button
11
- id="starlight-sidebar-topics-dropdown-button"
12
- class="starlight-sidebar-topics-dropdown-button"
13
- >
14
- {
15
- currentTopic.icon && (
9
+ {dropdown && (
10
+ <starlight-sidebar-topics-dropdown class="starlight-sidebar-topics-dropdown-dropdown">
11
+ <button
12
+ type="button"
13
+ aria-expanded="false"
14
+ class="starlight-sidebar-topics-dropdown-button"
15
+ >
16
+ {dropdown.currentTopic.icon && (
16
17
  <div class="starlight-sidebar-topics-dropdown-button-icon">
17
- <Icon
18
- name={currentTopic.icon as ComponentProps<typeof Icon>["name"]}
19
- />
18
+ <Icon name={dropdown.currentTopic.icon} />
20
19
  </div>
21
- )
22
- }
23
- <span class="starlight-sidebar-topics-dropdown-button-label"
24
- >{currentTopic.label}</span
25
- >
26
- {
27
- currentTopic.badge && (
20
+ )}
21
+ <span class="starlight-sidebar-topics-dropdown-button-label">
22
+ {dropdown.currentTopic.label}
23
+ </span>
24
+ {dropdown.currentTopic.badge && (
28
25
  <Badge
29
26
  class="starlight-sidebar-topics-dropdown-badge"
30
- text={currentTopic.badge.text}
31
- variant={currentTopic.badge.variant}
27
+ text={dropdown.currentTopic.badge.text}
28
+ variant={dropdown.currentTopic.badge.variant}
32
29
  />
33
- )
34
- }
35
- <svg
36
- width="16"
37
- height="16"
38
- viewBox="0 0 15 15"
39
- fill="none"
40
- xmlns="http://www.w3.org/2000/svg"
41
- class="h-4 w-4 opacity-50"
42
- aria-hidden="true"
43
- ><path
44
- d="M4.93179 5.43179C4.75605 5.60753 4.75605 5.89245 4.93179 6.06819C5.10753 6.24392 5.39245 6.24392 5.56819 6.06819L7.49999 4.13638L9.43179 6.06819C9.60753 6.24392 9.89245 6.24392 10.0682 6.06819C10.2439 5.89245 10.2439 5.60753 10.0682 5.43179L7.81819 3.18179C7.73379 3.0974 7.61933 3.04999 7.49999 3.04999C7.38064 3.04999 7.26618 3.0974 7.18179 3.18179L4.93179 5.43179ZM10.0682 9.56819C10.2439 9.39245 10.2439 9.10753 10.0682 8.93179C9.89245 8.75606 9.60753 8.75606 9.43179 8.93179L7.49999 10.8636L5.56819 8.93179C5.39245 8.75606 5.10753 8.75606 4.93179 8.93179C4.75605 9.10753 4.75605 9.39245 4.93179 9.56819L7.18179 11.8182C7.35753 11.9939 7.64245 11.9939 7.81819 11.8182L10.0682 9.56819Z"
45
- fill="currentColor"
46
- fill-rule="evenodd"
47
- clip-rule="evenodd"></path></svg
48
- >
49
- </button>
30
+ )}
31
+ <svg
32
+ width="16"
33
+ height="16"
34
+ viewBox="0 0 15 15"
35
+ fill="none"
36
+ xmlns="http://www.w3.org/2000/svg"
37
+ aria-hidden="true"
38
+ >
39
+ <path
40
+ d="M4.93179 5.43179C4.75605 5.60753 4.75605 5.89245 4.93179 6.06819C5.10753 6.24392 5.39245 6.24392 5.56819 6.06819L7.49999 4.13638L9.43179 6.06819C9.60753 6.24392 9.89245 6.24392 10.0682 6.06819C10.2439 5.89245 10.2439 5.60753 10.0682 5.43179L7.81819 3.18179C7.73379 3.0974 7.61933 3.04999 7.49999 3.04999C7.38064 3.04999 7.26618 3.0974 7.18179 3.18179L4.93179 5.43179ZM10.0682 9.56819C10.2439 9.39245 10.2439 9.10753 10.0682 8.93179C9.89245 8.75606 9.60753 8.75606 9.43179 8.93179L7.49999 10.8636L5.56819 8.93179C5.39245 8.75606 5.10753 8.75606 4.93179 8.93179C4.75605 9.10753 4.75605 9.39245 4.93179 9.56819L7.18179 11.8182C7.35753 11.9939 7.64245 11.9939 7.81819 11.8182L10.0682 9.56819Z"
41
+ fill="currentColor"
42
+ fill-rule="evenodd"
43
+ clip-rule="evenodd"
44
+ ></path>
45
+ </svg>
46
+ </button>
47
+
48
+ <div class="starlight-sidebar-topics-dropdown-menu" hidden>
49
+ {dropdown.topics.map((topic) => {
50
+ const { attributes, className } = getTopicLinkAttributes(topic);
50
51
 
51
- <div
52
- id="starlight-sidebar-topics-dropdown-menu"
53
- class="starlight-sidebar-topics-dropdown-menu"
54
- hidden
55
- >
56
- {
57
- topics.map((topic) => {
58
52
  return (
59
53
  <a
54
+ {...attributes}
60
55
  href={topic.link}
61
- class:list={{
62
- "starlight-sidebar-topics-dropdown-item": true,
63
- "starlight-sidebar-topics-dropdown-current-item": topic.isCurrent,
64
- }}
56
+ class:list={[
57
+ "starlight-sidebar-topics-dropdown-item",
58
+ {
59
+ "starlight-sidebar-topics-dropdown-current-item":
60
+ topic.isCurrent,
61
+ },
62
+ className,
63
+ ]}
65
64
  >
66
65
  {topic.icon && (
67
66
  <div class="starlight-sidebar-topics-dropdown-icon">
68
- <Icon
69
- name={topic.icon as ComponentProps<typeof Icon>["name"]}
70
- />
67
+ <Icon name={topic.icon} />
71
68
  </div>
72
69
  )}
73
70
  <span class="starlight-sidebar-topics-dropdown-label">
@@ -82,10 +79,10 @@ const currentTopic = topics.find((topic) => topic.isCurrent);
82
79
  )}
83
80
  </a>
84
81
  );
85
- })
86
- }
87
- </div>
88
- </div>
82
+ })}
83
+ </div>
84
+ </starlight-sidebar-topics-dropdown>
85
+ )}
89
86
 
90
87
  <style>
91
88
  .starlight-sidebar-topics-dropdown-dropdown {
@@ -225,17 +222,6 @@ const currentTopic = topics.find((topic) => topic.isCurrent);
225
222
  padding: 0.25rem;
226
223
  }
227
224
 
228
- .starlight-sidebar-topics-dropdown-button:is(
229
- .starlight-sidebar-topics-dropdown-current,
230
- :hover,
231
- :focus-visible
232
- )
233
- .starlight-sidebar-topics-dropdown-icon {
234
- background-color: var(--sl-color-text-accent);
235
- border-color: var(--sl-color-text-accent);
236
- color: var(--sl-color-text-invert);
237
- }
238
-
239
225
  .starlight-sidebar-topics-dropdown-item:is(
240
226
  :hover,
241
227
  .starlight-sidebar-topics-dropdown-current-item
@@ -254,33 +240,54 @@ const currentTopic = topics.find((topic) => topic.isCurrent);
254
240
  }
255
241
  </style>
256
242
 
257
- <script is:inline>
258
- const dropdownButton = document.getElementById(
259
- "starlight-sidebar-topics-dropdown-button"
260
- );
261
- const dropdownMenu = document.getElementById(
262
- "starlight-sidebar-topics-dropdown-menu"
263
- );
243
+ <script>
244
+ class StarlightSidebarTopicsDropdown extends HTMLElement {
245
+ #controller = new AbortController();
264
246
 
265
- if (!dropdownButton || !dropdownMenu) {
266
- throw new Error("Dropdown elements not found");
267
- }
247
+ connectedCallback() {
248
+ const button = this.querySelector("button");
249
+ const menu = this.querySelector<HTMLElement>(
250
+ ".starlight-sidebar-topics-dropdown-menu"
251
+ );
252
+ if (!button || !menu) return;
268
253
 
269
- dropdownButton.addEventListener("click", () => {
270
- const isOpen = !dropdownMenu.hidden;
271
- dropdownMenu.hidden = isOpen;
272
- });
254
+ const { signal } = this.#controller;
273
255
 
274
- function closeDropdown(event) {
275
- if (
276
- dropdownMenu &&
277
- !dropdownMenu.contains(event.target) &&
278
- dropdownButton &&
279
- !dropdownButton.contains(event.target)
280
- ) {
281
- dropdownMenu.hidden = true;
256
+ button.addEventListener(
257
+ "click",
258
+ () =>
259
+ this.#toggle(
260
+ button,
261
+ menu,
262
+ button.getAttribute("aria-expanded") !== "true"
263
+ ),
264
+ { signal }
265
+ );
266
+
267
+ document.addEventListener(
268
+ "click",
269
+ (event) => {
270
+ if (event.target instanceof Node && this.contains(event.target))
271
+ return;
272
+ this.#toggle(button, menu, false);
273
+ },
274
+ { signal }
275
+ );
276
+ }
277
+
278
+ disconnectedCallback() {
279
+ this.#controller.abort();
280
+ this.#controller = new AbortController();
281
+ }
282
+
283
+ #toggle(button: HTMLButtonElement, menu: HTMLElement, isOpen: boolean) {
284
+ menu.hidden = !isOpen;
285
+ button.setAttribute("aria-expanded", String(isOpen));
282
286
  }
283
287
  }
284
288
 
285
- document.addEventListener("click", closeDropdown);
289
+ customElements.define(
290
+ "starlight-sidebar-topics-dropdown",
291
+ StarlightSidebarTopicsDropdown
292
+ );
286
293
  </script>
package/libs/error.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { AstroError } from "astro/errors";
2
+
3
+ const issueUrl =
4
+ "https://github.com/trueberryless/starlight-sidebar-topics-dropdown/issues/new";
5
+
6
+ export function throwPluginError(message: string, hint?: string): never {
7
+ const hintHeader = "See the error report above for more informations.";
8
+ const hintFooter = `\n\nIf you believe this is a bug, please file an issue at ${issueUrl}`;
9
+
10
+ throw new AstroError(
11
+ message,
12
+ hint ? `${hint}${hintFooter}` : `${hintHeader}${hintFooter}`
13
+ );
14
+ }
package/libs/topics.ts ADDED
@@ -0,0 +1,48 @@
1
+ import { throwPluginError } from "./error";
2
+
3
+ type SidebarTopicsData = App.Locals["starlightSidebarTopics"];
4
+
5
+ export type SidebarTopic = SidebarTopicsData["topics"][number];
6
+
7
+ export interface TopicsDropdown {
8
+ currentTopic: SidebarTopic;
9
+ topics: SidebarTopic[];
10
+ }
11
+
12
+ export function getTopicsDropdown(
13
+ locals: App.Locals
14
+ ): TopicsDropdown | undefined {
15
+ return resolveTopicsDropdown(
16
+ locals.starlightRoute.hasSidebar,
17
+ getSidebarTopicsData(locals)
18
+ );
19
+ }
20
+
21
+ export function getSidebarTopicsData(locals: App.Locals): SidebarTopicsData {
22
+ if (!("starlightSidebarTopics" in locals)) {
23
+ throwPluginError(
24
+ "The Starlight Sidebar Topics Dropdown component requires the Starlight Sidebar Topics plugin.",
25
+ "Install the `starlight-sidebar-topics` package and add the plugin to the `plugins` array of your Starlight configuration. Follow the getting started guide at https://starlight-sidebar-topics.netlify.app/docs/getting-started/ for more information."
26
+ );
27
+ }
28
+
29
+ return locals.starlightSidebarTopics;
30
+ }
31
+
32
+ export function resolveTopicsDropdown(
33
+ hasSidebar: boolean,
34
+ { isPageWithTopic, topics }: SidebarTopicsData
35
+ ): TopicsDropdown | undefined {
36
+ if (!hasSidebar || !isPageWithTopic) return;
37
+
38
+ const currentTopic = topics.find((topic) => topic.isCurrent);
39
+ if (!currentTopic) return;
40
+
41
+ return { currentTopic, topics };
42
+ }
43
+
44
+ export function getTopicLinkAttributes({ attrs }: SidebarTopic) {
45
+ const { class: className, ...attributes } = attrs ?? {};
46
+
47
+ return { attributes, className };
48
+ }
package/package.json CHANGED
@@ -1,25 +1,29 @@
1
1
  {
2
2
  "name": "starlight-sidebar-topics-dropdown",
3
- "version": "0.6.0",
4
- "description": "Dropdown topic list for the Starlight Sidebar Topics plugin.",
3
+ "version": "0.7.1",
4
+ "description": "Starlight component to display the Starlight Sidebar Topics plugin topic list as a dropdown menu.",
5
5
  "keywords": [
6
6
  "starlight",
7
7
  "component",
8
8
  "sidebar",
9
9
  "topics",
10
- "dropdown"
10
+ "dropdown",
11
+ "documentation",
12
+ "astro",
13
+ "withastro"
11
14
  ],
12
- "homepage": "https://starlight-sidebar-topics-dropdown.trueberryless.org/",
15
+ "homepage": "https://starlight-sidebar-topics-dropdown.netlify.app/",
13
16
  "bugs": {
14
- "url": "https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/issues"
17
+ "url": "https://github.com/trueberryless/starlight-sidebar-topics-dropdown/issues"
15
18
  },
16
19
  "repository": {
17
20
  "type": "git",
18
- "url": "https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown.git",
21
+ "url": "https://github.com/trueberryless/starlight-sidebar-topics-dropdown.git",
19
22
  "directory": "packages/starlight-sidebar-topics-dropdown"
20
23
  },
21
24
  "license": "MIT",
22
- "author": "trueberryless <trueberryless@gmail.com> (https://trueberryless.org)",
25
+ "author": "trueberryless <trueberryless@gmail.com> (https://felixs.dev)",
26
+ "sideEffects": false,
23
27
  "type": "module",
24
28
  "exports": {
25
29
  ".": "./index.ts",
@@ -27,14 +31,14 @@
27
31
  "./package.json": "./package.json"
28
32
  },
29
33
  "devDependencies": {
30
- "@astrojs/starlight": "^0.38.1",
31
- "astro": "^6.0.5"
34
+ "@astrojs/starlight": "^0.42.4",
35
+ "astro": "^7.3.5",
36
+ "starlight-sidebar-topics": "^0.9.0"
32
37
  },
33
38
  "peerDependencies": {
34
- "@astrojs/starlight": ">=0.38",
35
- "starlight-sidebar-topics": ">=0.7"
39
+ "@astrojs/starlight": ">=0.42.0",
40
+ "starlight-sidebar-topics": ">=0.9.0"
36
41
  },
37
- "packageManager": "pnpm@10.10.0",
38
42
  "engines": {
39
43
  "node": ">=22.12.0"
40
44
  },