@astrojs/starlight 0.5.4 → 0.5.6

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,23 @@
1
1
  # @astrojs/starlight
2
2
 
3
+ ## 0.5.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#383](https://github.com/withastro/starlight/pull/383) [`0ebc47e`](https://github.com/withastro/starlight/commit/0ebc47e52dc420240c8cb724c01f98dc22bdfc60) Thanks [@delucis](https://github.com/delucis)! - Fix edge case where index files in an index directory would end up with the wrong slug
8
+
9
+ - [#373](https://github.com/withastro/starlight/pull/373) [`308b3aa`](https://github.com/withastro/starlight/commit/308b3aaeb0122af81a12514a81e160910f93d7a7) Thanks [@lorenzolewis](https://github.com/lorenzolewis)! - Fix visual overflow for wide logos
10
+
11
+ - [#385](https://github.com/withastro/starlight/pull/385) [`fb35397`](https://github.com/withastro/starlight/commit/fb35397f107f7bbb2cb4929b7837f105f565a659) Thanks [@lorenzolewis](https://github.com/lorenzolewis)! - Fix nested elements in markdown content
12
+
13
+ - [#386](https://github.com/withastro/starlight/pull/386) [`e6f6f30`](https://github.com/withastro/starlight/commit/e6f6f304437203d5ee6770092ac79063448b821f) Thanks [@huijing](https://github.com/huijing)! - Prevent search keyboard shortcuts from triggering when input elements are focused
14
+
15
+ ## 0.5.5
16
+
17
+ ### Patch Changes
18
+
19
+ - [`a161c05`](https://github.com/withastro/starlight/commit/a161c05b74d2300c1fe49bfd8e111cc45c9a5bff) Thanks [@delucis](https://github.com/delucis)! - Fix missing metadata required for `astro add` support
20
+
3
21
  ## 0.5.4
4
22
 
5
23
  ### Patch Changes
@@ -57,14 +57,11 @@ const { locale } = Astro.props;
57
57
  );
58
58
  display: grid;
59
59
  grid-template-columns:
60
- /* 1 (site title): runs up until the main content column’s left edge. */
61
- max(
62
- var(--sl-title-min-width),
63
- calc(
60
+ /* 1 (site title): runs up until the main content column’s left edge or the width of the title, whichever is the largest */
61
+ minmax(calc(
64
62
  var(--__sidebar-width) +
65
63
  max(0rem, var(--__main-column-fr) - var(--sl-nav-gap))
66
- )
67
- )
64
+ ), auto)
68
65
  /* 2 (search box): all free space that is available. */
69
66
  1fr
70
67
  /* 3 (right items): use the space that these need. */
@@ -2,7 +2,7 @@
2
2
 
3
3
  <style>
4
4
  .content
5
- > :global(
5
+ :global(
6
6
  :not(a, strong, em, del, span, input)
7
7
  + :not(a, strong, em, del, span, input, :where(.not-content *))
8
8
  ) {
@@ -96,10 +96,13 @@ const pagefindTranslations = {
96
96
 
97
97
  // Listen for `/` and `cmd + k` keyboard shortcuts.
98
98
  window.addEventListener('keydown', (e) => {
99
+ const isInput =
100
+ document.activeElement &&
101
+ ['input', 'select', 'textarea'].includes(document.activeElement.tagName.toLowerCase());
99
102
  if (e.metaKey === true && e.key === 'k') {
100
103
  dialog.open ? closeModal() : openModal();
101
104
  e.preventDefault();
102
- } else if (e.key === '/' && !dialog.open) {
105
+ } else if (e.key === '/' && !dialog.open && !isInput) {
103
106
  openModal();
104
107
  e.preventDefault();
105
108
  }
package/index.ts CHANGED
@@ -1,21 +1,16 @@
1
1
  import mdx from '@astrojs/mdx';
2
- import type {
3
- AstroConfig,
4
- AstroIntegration,
5
- AstroUserConfig,
6
- ViteUserConfig,
7
- } from 'astro';
2
+ import type { AstroIntegration, AstroUserConfig } from 'astro';
8
3
  import { spawn } from 'node:child_process';
9
- import { dirname, relative, resolve } from 'node:path';
4
+ import { dirname, relative } from 'node:path';
10
5
  import { fileURLToPath } from 'node:url';
11
6
  import { starlightAsides } from './integrations/asides';
12
7
  import { starlightSitemap } from './integrations/sitemap';
8
+ import { vitePluginStarlightUserConfig } from './integrations/virtual-user-config';
9
+ import { errorMap } from './utils/error-map';
13
10
  import {
14
- StarlightUserConfig,
15
- StarlightConfig,
16
11
  StarlightConfigSchema,
12
+ StarlightUserConfig,
17
13
  } from './utils/user-config';
18
- import { errorMap } from './utils/error-map';
19
14
 
20
15
  export default function StarlightIntegration(
21
16
  opts: StarlightUserConfig
@@ -78,47 +73,3 @@ export default function StarlightIntegration(
78
73
 
79
74
  return [starlightSitemap(userConfig), Starlight, mdx()];
80
75
  }
81
-
82
- function resolveVirtualModuleId(id: string) {
83
- return '\0' + id;
84
- }
85
-
86
- /** Expose the Starlight user config object via a virtual module. */
87
- function vitePluginStarlightUserConfig(
88
- opts: StarlightConfig,
89
- { root }: AstroConfig
90
- ): NonNullable<ViteUserConfig['plugins']>[number] {
91
- const resolveRelativeId = (id: string) =>
92
- JSON.stringify(id.startsWith('.') ? resolve(fileURLToPath(root), id) : id);
93
- const modules = {
94
- 'virtual:starlight/user-config': `export default ${JSON.stringify(opts)}`,
95
- 'virtual:starlight/project-context': `export default ${JSON.stringify({
96
- root,
97
- })}`,
98
- 'virtual:starlight/user-css': opts.customCss
99
- .map((id) => `import ${resolveRelativeId(id)};`)
100
- .join(''),
101
- 'virtual:starlight/user-images': opts.logo
102
- ? 'src' in opts.logo
103
- ? `import src from ${resolveRelativeId(opts.logo.src)}; export const logos = { dark: src, light: src };`
104
- : `import dark from ${resolveRelativeId(opts.logo.dark)}; import light from ${resolveRelativeId(opts.logo.light)}; export const logos = { dark, light };`
105
- : 'export const logos = {};',
106
- };
107
- const resolutionMap = Object.fromEntries(
108
- (Object.keys(modules) as (keyof typeof modules)[]).map((key) => [
109
- resolveVirtualModuleId(key),
110
- key,
111
- ])
112
- );
113
-
114
- return {
115
- name: 'vite-plugin-starlight-user-config',
116
- resolveId(id): string | void {
117
- if (id in modules) return resolveVirtualModuleId(id);
118
- },
119
- load(id): string | void {
120
- const resolution = resolutionMap[id];
121
- if (resolution) return modules[resolution];
122
- },
123
- };
124
- }
@@ -0,0 +1,52 @@
1
+ import type { AstroConfig, ViteUserConfig } from 'astro';
2
+ import { resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import type { StarlightConfig } from '../utils/user-config';
5
+
6
+ function resolveVirtualModuleId<T extends string>(id: T): `\0${T}` {
7
+ return `\0${id}`;
8
+ }
9
+
10
+ /** Vite plugin that exposes Starlight user config and project context via virtual modules. */
11
+ export function vitePluginStarlightUserConfig(
12
+ opts: StarlightConfig,
13
+ { root }: Pick<AstroConfig, 'root'>
14
+ ): NonNullable<ViteUserConfig['plugins']>[number] {
15
+ const resolveId = (id: string) =>
16
+ JSON.stringify(id.startsWith('.') ? resolve(fileURLToPath(root), id) : id);
17
+
18
+ /** Map of virtual module names to their code contents as strings. */
19
+ const modules = {
20
+ 'virtual:starlight/user-config': `export default ${JSON.stringify(opts)}`,
21
+ 'virtual:starlight/project-context': `export default ${JSON.stringify({ root })}`,
22
+ 'virtual:starlight/user-css': opts.customCss.map((id) => `import ${resolveId(id)};`).join(''),
23
+ 'virtual:starlight/user-images': opts.logo
24
+ ? 'src' in opts.logo
25
+ ? `import src from ${resolveId(
26
+ opts.logo.src
27
+ )}; export const logos = { dark: src, light: src };`
28
+ : `import dark from ${resolveId(opts.logo.dark)}; import light from ${resolveId(
29
+ opts.logo.light
30
+ )}; export const logos = { dark, light };`
31
+ : 'export const logos = {};',
32
+ } satisfies Record<string, string>;
33
+
34
+ /** Mapping names prefixed with `\0` to their original form. */
35
+ const resolutionMap = Object.fromEntries(
36
+ (Object.keys(modules) as (keyof typeof modules)[]).map((key) => [
37
+ resolveVirtualModuleId(key),
38
+ key,
39
+ ])
40
+ );
41
+
42
+ return {
43
+ name: 'vite-plugin-starlight-user-config',
44
+ resolveId(id): string | void {
45
+ if (id in modules) return resolveVirtualModuleId(id);
46
+ },
47
+ load(id): string | void {
48
+ const resolution = resolutionMap[id];
49
+ if (resolution) return modules[resolution];
50
+ },
51
+ };
52
+ }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
7
7
  "documentation",
8
8
  "astro",
9
- "withastro"
9
+ "withastro",
10
+ "astro-integration"
10
11
  ],
11
12
  "author": "Chris Swithinbank <swithinbank@gmail.com>",
12
13
  "license": "MIT",
@@ -31,7 +32,9 @@
31
32
  },
32
33
  "devDependencies": {
33
34
  "@types/node": "^18.16.19",
34
- "astro": "^2.8.5"
35
+ "@vitest/coverage-v8": "^0.33.0",
36
+ "astro": "^2.8.5",
37
+ "vitest": "^0.33.0"
35
38
  },
36
39
  "dependencies": {
37
40
  "@astrojs/mdx": "^0.19.7",
@@ -50,5 +53,8 @@
50
53
  "unist-util-visit": "^4.1.2",
51
54
  "vfile": "^5.3.7"
52
55
  },
53
- "scripts": {}
56
+ "scripts": {
57
+ "test": "vitest",
58
+ "test:coverage": "vitest run --coverage"
59
+ }
54
60
  }
package/style/props.css CHANGED
@@ -96,7 +96,6 @@
96
96
  --sl-nav-height: 3.5rem;
97
97
  --sl-nav-pad-x: 1rem;
98
98
  --sl-nav-pad-y: 0.75rem;
99
- --sl-title-min-width: 10rem;
100
99
  --sl-mobile-toc-height: 3rem;
101
100
  --sl-sidebar-width: 18.75rem;
102
101
  --sl-sidebar-pad-x: 1rem;
package/types.ts CHANGED
@@ -1 +1 @@
1
- export { StarlightConfig } from './utils/user-config';
1
+ export type { StarlightConfig } from './utils/user-config';
package/utils/slugs.ts CHANGED
@@ -56,7 +56,7 @@ export function slugToParam(slug: string): string | undefined {
56
56
  return slug === 'index' || slug === ''
57
57
  ? undefined
58
58
  : slug.endsWith('/index')
59
- ? slug.replace('/index', '')
59
+ ? slug.replace(/\/index$/, '')
60
60
  : slug;
61
61
  }
62
62