@ksp-gonogo/ui-kit 1.0.0-rc.45 → 1.0.0

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/README.md CHANGED
@@ -1,33 +1,8 @@
1
1
  # @ksp-gonogo/ui-kit
2
2
 
3
- The design system behind [Gonogo](https://github.com/ksp-gonogo/gonogo), a mission-control
4
- dashboard for Kerbal Space Program. It's the same set of primitives the built-in widgets are
5
- made of, published so that widgets and Uplinks written outside the Gonogo repository look like they belong
6
- on the same screen. Compose them and your widget picks up the host's theme, spacing and type
7
- scale without you writing CSS for any of it. Import `@ksp-gonogo/ui-kit/tokens.css` once, or every
8
- colour and size is unset.
3
+ The design system behind [Gonogo](https://github.com/ksp-gonogo/gonogo), a mission control app for Kerbal Space Program. It is the set of components the app's own widgets are drawn with, published so that the widgets of an Uplink, the extension that connects a KSP mod to the app, look like they belong on the same screen. Compose them and a widget takes the host's theme, spacing and type scale without any CSS of its own.
9
4
 
10
- A widget ships inside an **Uplink**, the extension unit that pairs a KSP mod with a client
11
- bundle. This package is one of its two halves; the other is `@ksp-gonogo/sitrep-sdk`, which
12
- carries the registration and the telemetry hooks.
13
-
14
- ## The documentation lives elsewhere
15
-
16
- **[Gonogo Uplink developer documentation](https://ksp-gonogo.github.io/uplink-dev-docs/)** is the
17
- reference for this package, and for everything around it:
18
-
19
- - [the guide](https://ksp-gonogo.github.io/uplink-dev-docs/guide/), start to finish, if you have
20
- not written an Uplink before
21
- - [the ui-kit reference](https://ksp-gonogo.github.io/uplink-dev-docs/reference/ui-kit/), a page
22
- per primitive
23
-
24
- Every snippet on that site is transcluded from a source file that is compiled in CI, so a
25
- signature that drifts fails the build instead of reading correctly and being wrong. This file
26
- deliberately carries no component reference of its own: a second, unchecked copy would drift,
27
- and it did.
28
-
29
- What follows is only what you need before the docs are any use to you: how to install the
30
- package, and the three environment constraints that will otherwise stop you at the first import.
5
+ **The [Uplink developer docs](https://ksp-gonogo.github.io/uplink-dev-docs/) are the reference for this package.** The [guide](https://ksp-gonogo.github.io/uplink-dev-docs/guide/) takes you from an empty directory to an Uplink a player can install, and the [ui-kit reference](https://ksp-gonogo.github.io/uplink-dev-docs/reference/ui-kit/) has a page for each component. This page has no component reference, and holds what you need before the docs are any use: install, and what the environment must provide.
31
6
 
32
7
  ## Install
33
8
 
@@ -37,25 +12,29 @@ Until the first release, `latest` is a placeholder, so install the release candi
37
12
  npm install @ksp-gonogo/ui-kit@rc
38
13
  ```
39
14
 
40
- An Uplink installs this package together with `@ksp-gonogo/sitrep-sdk` and `@ksp-gonogo/uplink-tools`,
41
- all under the same tag, because one beside a release of another fails to resolve; `uplink-tools new`
42
- writes that set for you.
15
+ An Uplink installs this package with `@ksp-gonogo/sitrep-sdk` and `@ksp-gonogo/uplink-tools` under the same tag, at one version. The kit names the sdk of its release as an exact peer, so one beside another release fails to resolve. `uplink-tools new` writes that set for you, and [Building against a release candidate](https://ksp-gonogo.github.io/uplink-dev-docs/guide/release-candidate) covers adding it by hand.
43
16
 
44
- React 18 and styled-components 6 are peer dependencies; install them if you don't have them:
17
+ React 18 and styled-components 6 are peer dependencies:
45
18
 
46
19
  ```sh
47
20
  npm install react@^18 styled-components@^6
48
21
  ```
49
22
 
50
- They're peers rather than dependencies because there has to be exactly one copy of each in the
51
- final app. styled-components keeps its `ThemeContext` in module state, so a second copy would
52
- give your components a different context than the host's `ThemeProvider` populates, and your
53
- `theme` would come back empty. React has the same problem one layer down. As peers, they
54
- resolve to whatever the host already installed.
23
+ They are peers because the app must hold exactly one copy of each: styled-components keeps its `ThemeContext` in module state, so a second copy would not see the host's `ThemeProvider`. React 19 is not supported.
24
+
25
+ ## Entry points
55
26
 
56
- Primitives read `theme.space` and `theme.colors`, so they need a `ThemeProvider` in scope and
57
- will throw without one. Inside a Gonogo dashboard the host has already mounted it. Standing the
58
- kit up yourself, for a test or a preview outside the app:
27
+ | Entry | What it is |
28
+ |---|---|
29
+ | `@ksp-gonogo/ui-kit` | the components, hooks and the theme contract |
30
+ | `@ksp-gonogo/ui-kit/tokens.css` | the colour, spacing and type variables the components read |
31
+ | `@ksp-gonogo/ui-kit/testing` | helpers for a widget's tests, such as `expectNoA11yViolations` and `renderWidget` |
32
+ | `@ksp-gonogo/ui-kit/grid` | the dashboard grid's units |
33
+ | `@ksp-gonogo/ui-kit/guards` | checks an Uplink runs against its own source from a test file; it reads the filesystem, so it is Node only |
34
+
35
+ ## Theme and tokens
36
+
37
+ An Uplink loaded by the app already has the tokens. Outside the app, import `@ksp-gonogo/ui-kit/tokens.css` once, or every colour and size is unset. Components read `theme.space` and `theme.colors` and need a `ThemeProvider` in scope. Inside the Gonogo dashboard the host has mounted one. For a test or a preview outside the app:
59
38
 
60
39
  ```tsx
61
40
  import "@ksp-gonogo/ui-kit/tokens.css";
@@ -66,10 +45,11 @@ import { DefaultThemeProvider } from "@ksp-gonogo/ui-kit";
66
45
  </DefaultThemeProvider>;
67
46
  ```
68
47
 
69
- ## Testing with vitest: the kit must be inlined
48
+ Importing the package also types styled-components' `DefaultTheme` with the theme contract, so `theme.space.bogus` is a compile error. That is a global module augmentation, so a project that augments `DefaultTheme` itself will conflict with it.
49
+
50
+ ## Testing with vitest
70
51
 
71
- Add this to your `vitest.config.ts`, or every test file that touches the kit dies on import
72
- before a single assertion runs:
52
+ Inline the kit in `vitest.config.ts`, or every test file that touches it fails on import:
73
53
 
74
54
  ```ts
75
55
  export default defineConfig({
@@ -79,79 +59,21 @@ export default defineConfig({
79
59
  });
80
60
  ```
81
61
 
82
- Vitest hands `node_modules` dependencies to Node's ESM loader rather than transforming them, and
83
- `styled-components@6` publishes no `exports` map, only `main` (CommonJS) and `module` (ESM).
84
- Node therefore loads the CommonJS half, and its interop makes the default export the module
85
- namespace object rather than the `styled` factory. The kit evaluates `styled.span` at module
86
- scope, so you get:
62
+ The scaffold's `client/vitest.config.ts` already has it. Without it the first import fails with:
87
63
 
88
64
  ```
89
65
  TypeError: styled.span is not a function
90
66
  ```
91
67
 
92
- before any of your code runs. Inlining makes Vite process the kit itself, which honours `module`
93
- and resolves the factory. This is not specific to this kit, it is what any styled-components
94
- library needs from vitest, and it is why you will not see the problem in a monorepo where the kit
95
- is a workspace symlink: Vite never pre-bundles a linked dependency.
96
-
97
- The same setting is what the kit's `/testing`, `/render-probe` and `/page-check` entry points
98
- need, and it is the reason `expectNoA11yViolations` will otherwise appear not to exist.
99
-
100
- **Do not read a green vitest run as proof a `@ksp-gonogo` package is loadable.** Inlining also
101
- performs the module-extension search Node refuses to, so it hides an unloadable emit rather than
102
- reporting it. That is a real bug this project shipped for six weeks.
103
-
104
- ## Build against `moduleResolution: "bundler"`
105
-
106
- `deps.inline` is a bundler setting. `tsc` is not a bundler, so under
107
- `moduleResolution: "nodenext"` the missing `exports` map bites again at the type level:
108
-
109
- ```
110
- error TS2339: Property 'div' does not exist on type
111
- 'typeof import(".../styled-components/dist/index")'
112
- ```
113
-
114
- That is two lines of code with no `@ksp-gonogo` package involved:
115
- `import styled from "styled-components"` followed by `styled.div`. Nothing in this kit can fix it
116
- for you, and no shim in your own source fixes it cleanly either (unwrapping `.default` satisfies
117
- `nodenext` and then breaks `bundler`, which resolves the ESM half where the default IS the factory).
118
-
119
- So: build against `"bundler"`, which is what `@ksp-gonogo/sitrep-sdk/tsconfig.base.json` sets and
120
- why it sets it. An Uplink whose widgets use `styled` cannot pass a `nodenext` typecheck until
121
- styled-components ships an `exports` map, and that is a statement about styled-components rather
122
- than about your code.
123
-
124
- The kit's own declarations are unaffected in practice because the shipped baseline sets
125
- `skipLibCheck: true`, which suppresses errors inside `.d.ts` files. Turning it off surfaces roughly
126
- sixty of them, none actionable from a consumer's side.
127
-
128
- ## The theme is typed for you, everywhere
129
-
130
- Importing the package binds the theme contract onto styled-components' `DefaultTheme`. You get
131
- autocomplete and type errors in theme callbacks without writing your own `declare module`, so
132
- `theme.space.bogus` is a compile error rather than `any`.
133
-
134
- This is a global augmentation, it's how module augmentation works, and there's no scoped version.
135
- Importing the kit anywhere in a project types `DefaultTheme` everywhere in it. If you already
136
- augment `DefaultTheme` yourself, expect a conflict.
137
-
138
- ## One convention worth knowing
68
+ styled-components 6 publishes no `exports` map, so vitest hands it to Node's ESM loader, which takes the CommonJS build, whose default export is the module namespace and not the `styled` factory. Inlining makes Vite process the kit itself, which uses the ESM build. The kit's `/testing` entry needs the same setting.
139
69
 
140
- Widgets here carry close to no CSS of their own. Spacing, surfaces, borders and type all come
141
- from the kit, which is what keeps twenty-odd widgets from twenty-odd authors reading as one
142
- instrument panel. If you find yourself reaching for a bespoke `styled.div` to do something the
143
- kit almost does, that's usually a gap in the kit worth
144
- [raising](https://github.com/ksp-gonogo/gonogo/issues).
70
+ A green vitest run does not show that a `@ksp-gonogo` package loads in Node, because inlining also does the file-extension search Node refuses to. `uplink-tools check --only loadable` imports each entry point in a bare `node` to test that.
145
71
 
146
72
  ## Versioning
147
73
 
148
- The kit carries the Gonogo release version, the same one as `@ksp-gonogo/sitrep-sdk`,
149
- `@ksp-gonogo/uplink-tools` and the app it shipped with, and names the sdk of that release as an
150
- exact peer. Install them together at one version, and move them together.
74
+ The kit carries the Gonogo release version, the same one as `@ksp-gonogo/sitrep-sdk`, `@ksp-gonogo/uplink-tools` and the app it shipped with. What its surface promises is held by the extension API version, which the app checks before it loads an Uplink, and not by the package version. Token names are part of that surface: renaming one is a breaking change.
151
75
 
152
- What the kit's surface promises is held by the extension API version, which the app checks
153
- before it loads an Uplink, not by the package version. Token names are part of that surface,
154
- not an implementation detail: renaming one is a break.
76
+ Widgets carry almost no CSS of their own, which is what lets widgets from many authors read as one instrument panel. A gap you meet in the kit is worth [raising as an issue](https://github.com/ksp-gonogo/gonogo/issues).
155
77
 
156
78
  ## Licence
157
79